Advertisement
UsernameHere1

Untitled

Feb 21st, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.61 KB | None | 0 0
  1. Imports System.IO 'import the input and output features
  2. Public Class DueDates 'due dates form
  3.     Dim lineCount As Integer 'The full amount of records in the file
  4.     Dim rowIndex As Integer 'The currently selected row of the datagrid
  5.     Private Sub fillGrid() 'fills the datagrud
  6.         Dim encryption As New clsEncryption 'instantiate the encryption class
  7.         Dim validation As New clsValidation 'instantiate the validation class
  8.         Dim record1 As String 'record for individual borrowings
  9.         Dim fields1() As String 'fields in the record
  10.         Dim record2 As String 'record for borrowing data
  11.         Dim fields2() As String 'fields in the record
  12.         Dim validated As Boolean = True 'is data validated
  13.         Dim searchID As String 'ID being searched for
  14.         Dim searchBorrowingID As String 'borrowingID being searched for
  15.         lineCount = 0
  16.         If validation.presenceCheck(txt_customerID.Text) = True And txt_customerID.Text <> "CustomerID" Then 'validation
  17.             searchID = txt_customerID.Text
  18.         Else
  19.             validated = False 'validation not met
  20.         End If
  21.         If validated = True Then 'if validation met
  22.             Dim sr1 As New StreamReader("individualBorrowings.txt") 'stream reader of individual borrowings
  23.             While sr1.Peek() >= 0 'check every indvidual borrowing for ones with the correct customerID to get a borrowing ID
  24.                 record1 = encryption.decrypt(sr1.ReadLine) 'decrypt record from file
  25.                 fields1 = record1.Split(",") 'fields in record
  26.                 If fields1(1) = searchID Then 'if the search ID is the record ID
  27.                     searchBorrowingID = fields1(0) 'store the borrowingID
  28.                     Dim sr2 As New StreamReader("borrowingData.txt") 'Stream reader of the borrowingData file
  29.                     While sr2.Peek() >= 0 'display the details of the borrowingID
  30.                         record2 = encryption.decrypt(sr2.ReadLine) 'decrypt record
  31.                         fields2 = record2.Split(",") 'split record into fields
  32.                         If fields2(0) = searchBorrowingID Then 'if the borrowingID is found
  33.                             Dim index = dgv_dueDates.Rows.Add 'the next row to add to
  34.                             dgv_dueDates.Rows(index).SetValues(fields2) 'set the row
  35.                             lineCount = lineCount + 1 'increment the linecount to show all rows that have been stored
  36.                         End If
  37.                     End While
  38.                     sr2.Close() 'close the stream reader
  39.                 End If
  40.             End While
  41.             sr1.Close() 'close the stream writer
  42.             dgv_dueDates.RowHeadersVisible = False 'Removes the symbols by the rows
  43.             dgv_dueDates.ClearSelection() 'Removes the blue selection box
  44.             dgv_dueDates.Rows(lineCount - 1).Selected = True 'select the final record in the datagrid
  45.             rowIndex = lineCount - 1
  46.         Else
  47.             MsgBox("Must meet validation requirements") 'notify user
  48.         End If
  49.         txt_customerID.Text = "CustomerID" 'reset text boxes
  50.     End Sub
  51.     Private Sub DueDates_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  52.         Me.CenterToScreen() 'centre form to screen
  53.         Dim startupPath As String 'stores the location the program is running
  54.         startupPath = Application.StartupPath
  55.         pbx_logo.ImageLocation = startupPath & "\PennardLibraryLogo.png" 'set image locations
  56.         pbx_back.ImageLocation = startupPath & "\Arrow.png"
  57.         If levelOfAccess = 3 Then
  58.             Me.BackColor = Color.FromArgb(247, 220, 143) 'For admins use yellow
  59.         End If
  60.         If levelOfAccess = 2 Then
  61.             Me.BackColor = Color.FromArgb(140, 227, 245) 'For librarians use a blue background instead of the standard green
  62.         End If
  63.         If levelOfAccess = 1 Then
  64.             Me.BackColor = Color.FromArgb(163, 255, 166) 'For customers use standard green
  65.         End If
  66.     End Sub
  67.     Private Sub pbx_back_Click(sender As Object, e As EventArgs) Handles pbx_back.Click
  68.         Dim MainMenu As New MainMenu 'instantiate the main menu form
  69.         MainMenu.Show() 'show the new form
  70.         Me.Close()  'close the current form
  71.     End Sub
  72.     Private Sub pbx_back_MouseHover(sender As Object, e As EventArgs) Handles pbx_back.MouseHover
  73.         Dim startupPath As String 'stores the location the program is running
  74.         startupPath = Application.StartupPath
  75.         pbx_back.ImageLocation = startupPath & "\ArrowRollover.png" 'rollover image
  76.     End Sub
  77.  
  78.     Private Sub pbx_back_MouseLeave(sender As Object, e As EventArgs) Handles pbx_back.MouseLeave
  79.         Dim startupPath As String 'stores the location the program is running
  80.         startupPath = Application.StartupPath
  81.         pbx_back.ImageLocation = startupPath & "\Arrow.png" 'rollover image
  82.     End Sub
  83.  
  84.     Private Sub btn_view_Click(sender As Object, e As EventArgs) Handles btn_view.Click
  85.         fillGrid() 'fill the data grid
  86.     End Sub
  87.  
  88.     Private Sub txt_customerID_MouseClick(sender As Object, e As MouseEventArgs) Handles txt_customerID.MouseClick
  89.         If txt_customerID.Text = "CustomerID" Then 'if the text is the starting text
  90.             txt_customerID.Text = "" 'clear the textbox
  91.         End If
  92.     End Sub
  93.     Private Sub btn_first_Click(sender As Object, e As EventArgs) Handles btn_first.Click
  94.         dgv_dueDates.ClearSelection()
  95.         dgv_dueDates.Rows(0).Selected = True 'gp back to the first record
  96.         rowIndex = 0
  97.     End Sub
  98.  
  99.     Private Sub btn_previous_Click(sender As Object, e As EventArgs) Handles btn_previous.Click
  100.         dgv_dueDates.ClearSelection()
  101.         If rowIndex = 0 Then
  102.             MsgBox("You are already looking at the first record")
  103.         Else
  104.             rowIndex = rowIndex - 1
  105.             dgv_dueDates.Rows(rowIndex).Selected = True 'go one record back unless you are at the fist one already
  106.         End If
  107.     End Sub
  108.  
  109.     Private Sub btn_next_Click(sender As Object, e As EventArgs) Handles btn_next.Click
  110.         dgv_dueDates.ClearSelection()
  111.         If rowIndex = lineCount - 1 Then
  112.             MsgBox("You are already looking at the last record")
  113.         Else
  114.             rowIndex = rowIndex + 1
  115.             dgv_dueDates.Rows(rowIndex).Selected = True 'go on record forwards unless you are at the last one already
  116.         End If
  117.     End Sub
  118.  
  119.     Private Sub btn_last_Click(sender As Object, e As EventArgs) Handles btn_last.Click
  120.         dgv_dueDates.ClearSelection()
  121.         dgv_dueDates.Rows(lineCount - 1).Selected = True 'go to the last record stored
  122.         rowIndex = lineCount - 1
  123.     End Sub
  124. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement