urgent!!!!!!!!!!

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 1
Reputation: pardesi is an unknown quantity at this point 
Solved Threads: 0
pardesi pardesi is offline Offline
Newbie Poster

urgent!!!!!!!!!!

 
0
  #1
Sep 7th, 2008
how can i set that it will count also from the label that "how many rentals are overdue"
  1. Structure rental
  2. Dim rentalid As Integer
  3. Dim familyname As String
  4. Dim Firstname As String
  5. Dim dateborrowed As Date
  6. Dim duedate As Date
  7. Public Overrides Function ToString() As String
  8. Return " " & rentalid.ToString() & " " & familyname & " " & _
  9. Firstname & " " & " " & dateborrowed & " " & duedate & vbNewLine
  10. End Function
  11. End Structure
  12.  
  13. Dim rentals(99) As rental 'memory locations for 100 (integer+integer) values
  14. Dim rentalcount As Integer = 0
  15. Dim overduerentalcount As Integer = 0
  16. Dim currentfile As String = ""
  17. Dim indexOfSelectedrental As Integer
  18. Dim indexofoverduerentals As Integer
  19.  
  20. Private Sub btnAddRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddRecord.Click
  21. Try
  22. 'validate rentalid
  23. If Not isValidID(txtRentalId.Text, 100000) Then
  24. MsgBox("Invalid Rental Id-Please Enter the validId")
  25. txtRentalId.SelectAll()
  26. txtRentalId.Focus()
  27. ElseIf isduplicateID(txtRentalId.Text) Then
  28. MsgBox("This rental is already issued.Please re-enter the RentalId")
  29. txtRentalId.SelectAll()
  30. txtRentalId.Focus()
  31. 'validate date borrowed
  32. ElseIf Not isvaliddateborrowed(Date.Parse(dtpDateBorrowed.Text)) Then
  33. MsgBox("Please re-enter the Date Borrowed")
  34. 'validate due date
  35. ElseIf Not isvalidDueDate(Date.Parse(dtpDueDate.Text), Date.Parse(dtpDateBorrowed.Text)) Then
  36. MsgBox("Please re-enter the valid Due Date")
  37. Else
  38. 'good data
  39. rentalcount += 1
  40. 'store the two parts of the rental
  41. Dim temp As rental
  42. temp.rentalid = CInt(txtRentalId.Text)
  43. temp.familyname = txtFamilyName.Text
  44. temp.Firstname = txtFirstName.Text
  45. temp.dateborrowed = Date.Parse(dtpDateBorrowed.Text)
  46. temp.duedate = Date.Parse(dtpDueDate.Text)
  47.  
  48.  
  49. Dim place As Integer = correctplace(temp) 'these 2 lines store the new rental
  50. lblOverdueRentals.Text = " "
  51. InsertAt(place, temp) 'into the array in ascending order of rentalId
  52. 'display all rentals
  53. displayallrentals()
  54. 'reset the fields
  55. txtRentalId.Clear()
  56. txtFamilyName.Clear()
  57. txtFirstName.Clear()
  58. dtpDateBorrowed.Value = Today
  59. dtpDueDate.Value = Today
  60. txtRentalId.Focus()
  61.  
  62. End If
  63. Catch ex As Exception
  64. MsgBox("Bad Data : " & ex.Message & vbNewLine & "Please Start Again")
  65. txtRentalId.SelectAll()
  66. txtRentalId.Focus()
  67. End Try
  68.  
  69. End Sub
  70. #Region "displays"
  71. 'DISPLAY OVERDUE RENTALS IN THE LABEL
  72.  
  73. Sub displayOverduerentals(ByVal overduerental As rental, ByVal daysoverdue As Integer)
  74.  
  75. lblOverdueRentals.Text &= overduerental.rentalid.ToString() _
  76. & " " & _
  77. overduerental.duedate.ToString("d") & _
  78. " " & daysoverdue.ToString & vbNewLine
  79.  
  80.  
  81. End Sub
  82. Sub DisplayInListBox()
  83. lstRentals.Items.Clear()
  84. For i As Integer = 0 To rentalcount - 1
  85. lstRentals.Items.Add(rentals(i))
  86. Next
  87.  
  88. displayallrentals()
  89.  
  90. End Sub
  91.  
  92. #End Region
  93.  
  94.  
  95. #Region "validation"
  96.  
  97. Function isValidID(ByVal input As String, ByVal min As Integer) As Boolean
  98. Return IsNumeric(input) AndAlso isValidID(CDbl(input), min)
  99. End Function
  100. Function isvalidID(ByVal number As Double, ByVal min As Integer) As Boolean
  101. Return isinteger(number) AndAlso number >= min AndAlso number <= 999999
  102. End Function
  103. Function isinteger(ByVal number As Double) As Boolean
  104. Return CInt(number) = number
  105. End Function
  106. Function isduplicateID(ByVal input As String) As Boolean
  107. For i As Integer = 0 To rentalcount - 1
  108. If CInt(input) = rentals(i).rentalid Then
  109. Return True
  110. End If
  111. Next
  112.  
  113. Return False
  114. End Function
  115. Function isvaliddateborrowed(ByVal dateEntered As Date)
  116. Dim daysTimeSpan As TimeSpan = dateEntered.Subtract(Today)
  117. Return daysTimeSpan.TotalDays <= 2 AndAlso daysTimeSpan.TotalDays >= -2
  118. End Function
  119. Function isvalidDueDate(ByVal duedate As Date, ByVal dateborrowed As Date)
  120. Dim daysTimesspanborrow As TimeSpan = duedate.Subtract(Today)
  121. Return daysTimesspanborrow.TotalDays <= 21 AndAlso daysTimesspanborrow.TotalDays >= -2 AndAlso _
  122. duedate.Subtract(dateborrowed).TotalDays >= 0
  123. End Function
  124. #End Region
  125.  
  126. #Region "insert into array logic"
  127. Public Function correctplace(ByVal newrental As rental) As Integer
  128. For i As Integer = 0 To rentalcount - 1 'search the array from position 0
  129. 'loop until rentalId is < rentalId of array item already stored
  130. If newrental.rentalid < rentals(i).rentalid Then
  131. correctplace = i
  132. Exit Function
  133. End If
  134. Next
  135. correctplace = rentalcount - 1
  136. End Function
  137.  
  138. Public Sub InsertAt(ByVal place As Integer, ByVal temp As rental)
  139. For i As Integer = rentalcount - 1 To place + 1 Step -1
  140. rentals(i) = rentals(i - 1)
  141. Next
  142. 'insert where it belongs
  143. rentals(place) = temp
  144. End Sub
  145. Public Sub DeleteFromArray(ByVal indexOfRentalToDelete As Integer)
  146. For i As Integer = indexOfRentalToDelete To rentalcount - 1
  147. rentals(i) = rentals(i + 1)
  148. Next
  149. rentalcount -= 1
  150. End Sub
  151.  
  152. #End Region
  153. Sub displayallrentals()
  154. lstRentals.Items.Clear()
  155. lblOverdueRentals.Text = " "
  156. 'for each item in array add item to listbox and label if is overdue
  157. For i = 0 To rentalcount - 1
  158. lstRentals.Items.Add(rentals(i))
  159.  
  160. Dim daysOverdue As TimeSpan = Today.Subtract(rentals(i).duedate)
  161. If daysOverdue.TotalDays > 0 Then
  162. displayOverduerentals(rentals(i), daysOverdue.TotalDays)
  163.  
  164. End If
  165.  
  166. Next
  167.  
  168. lblOverdueRentals.Text &= overduerentalcount.ToString & " rentals overdue"
  169.  
  170.  
  171. End Sub
  172.  
  173. #Region "file handling"
  174.  
  175. Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOpen.Click
  176. If dlgOpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then
  177. loadfromdiskfile(dlgOpenFile.FileName)
  178. displayallrentals()
  179. txtRentalId.SelectAll()
  180. txtRentalId.Focus()
  181. End If
  182. End Sub
  183. Private Sub loadfromdiskfile(ByVal filename As String)
  184. currentfile = filename
  185. FileOpen(1, filename, OpenMode.Input)
  186. Input(1, rentalcount)
  187. For i As Integer = 0 To rentalcount - 1
  188. Input(1, rentals(i).rentalid)
  189. Input(1, rentals(i).duedate)
  190. Next
  191. FileClose(1)
  192. End Sub
  193.  
  194. Private Sub SaveToDiskFile(ByVal filename As String)
  195. currentfile = filename
  196. FileOpen(1, filename, OpenMode.Output)
  197. Write(1, rentalcount)
  198. For i As Integer = 0 To rentalcount - 1
  199. Write(1, rentals(i).rentalid)
  200. Write(1, rentals(i).duedate)
  201. Next
  202. FileClose(1)
  203. End Sub
  204. Sub DoSaveAs()
  205. If dlgSaveFile.ShowDialog = Windows.Forms.DialogResult.OK Then
  206. SaveToDiskFile(dlgSaveFile.FileName)
  207. End If
  208. End Sub
  209. Private Sub mnuFileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileSave.Click
  210. If currentfile = "" Then
  211. doSaveAs()
  212. Else
  213. SaveToDiskFile(currentfile)
  214. End If
  215. End Sub
  216. #End Region
Last edited by cscgal; Sep 7th, 2008 at 12:23 pm. Reason: Fixed code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC