Advertisement
willeds

Untitled

Apr 5th, 2024
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.90 KB | None | 0 0
  1. Public Class myStaff
  2.  
  3.  
  4.     Private Sub myStaff_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  5.         fillGrid(dgv_staff, fileLoc_Staff)
  6.         StartPosition = FormStartPosition.CenterScreen
  7.  
  8.         txt_staffID.BackColor = gray
  9.         txt_forename.BackColor = gray
  10.         txt_surname.BackColor = gray
  11.         txt_password.BackColor = gray
  12.         txt_accessLevel.BackColor = gray
  13.         txt_phoneNumber.BackColor = gray
  14.         txt_postcode.BackColor = gray
  15.         txt_address.BackColor = gray
  16.         DTP_DoB.BackColor = gray
  17.     End Sub
  18.  
  19.     Private Sub fillText(ByVal rowIndex As Integer)
  20.         txt_staffID.Text = dgv_staff.Rows(rowIndex).Cells(0).Value
  21.         txt_forename.Text = Decryption(dgv_staff.Rows(rowIndex).Cells(1).Value)
  22.         txt_surname.Text = Decryption(dgv_staff.Rows(rowIndex).Cells(2).Value)
  23.         txt_password.Text = Decryption(dgv_staff.Rows(rowIndex).Cells(3).Value)
  24.         txt_accessLevel.Text = Decryption(dgv_staff.Rows(rowIndex).Cells(4).Value)
  25.         txt_phoneNumber.Text = Decryption(dgv_staff.Rows(rowIndex).Cells(5).Value)
  26.         txt_postcode.Text = Decryption(dgv_staff.Rows(rowIndex).Cells(6).Value)
  27.         txt_address.Text = Decryption(dgv_staff.Rows(rowIndex).Cells(7).Value)
  28.         DTP_DoB.Value = dgv_staff.Rows(rowIndex).Cells(8).Value
  29.     End Sub
  30.  
  31.     Private Sub clearText()
  32.         txt_staffID.Text = ""
  33.         txt_forename.Text = ""
  34.         txt_surname.Text = ""
  35.         txt_password.Text = ""
  36.         txt_accessLevel.Text = ""
  37.         txt_phoneNumber.Text = ""
  38.         txt_postcode.Text = ""
  39.         txt_address.Text = ""
  40.         DTP_DoB.CustomFormat = " "
  41.     End Sub
  42.  
  43.     'Navigation
  44.     Private dgvNavigator As New DataGridViewNavigator()
  45.     Private Sub btn_first_Click(sender As Object, e As EventArgs) Handles btn_first.Click
  46.         dgvNavigator.SelectFirst(dgv_staff)
  47.         fillText(dgvNavigator.CurrentIndex)
  48.     End Sub
  49.  
  50.     Private Sub btn_previous_Click(sender As Object, e As EventArgs) Handles btn_previous.Click
  51.         dgvNavigator.SelectPrevious(dgv_staff)
  52.         fillText(dgvNavigator.CurrentIndex)
  53.     End Sub
  54.  
  55.     Private Sub btn_next_Click(sender As Object, e As EventArgs) Handles btn_next.Click
  56.         dgvNavigator.SelectNext(dgv_staff)
  57.         fillText(dgvNavigator.CurrentIndex)
  58.     End Sub
  59.  
  60.     Private Sub btn_last_Click(sender As Object, e As EventArgs) Handles btn_last.Click
  61.         dgvNavigator.SelectLast(dgv_staff)
  62.         fillText(dgvNavigator.CurrentIndex)
  63.     End Sub
  64.     '----------------------------------------------------------------------------------------------'
  65.     Private Sub btn_add_Click(sender As Object, e As EventArgs) Handles btn_add.Click
  66.         clearText()
  67.         Dim newID As Integer = AddRecord(fileLoc_Staff)
  68.         txt_staffID.Text = newID
  69.     End Sub
  70.  
  71.     Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
  72.         'Checks the data before attempting to save it to file
  73.         If Check() = False Then
  74.             Return
  75.         End If
  76.  
  77.  
  78.         Dim staffID As Integer = txt_staffID.Text
  79.         Dim password As String = Encryption(txt_password.Text)
  80.  
  81.         If UniqueCheck(staffID, fileLoc_Staff) Then
  82.             Dim newValues As String = txt_staffID.Text + "," + Encryption(txt_forename.Text) + "," + Encryption(txt_surname.Text) + "," + password + "," + Encryption(txt_accessLevel.Text) + "," + Encryption(txt_phoneNumber.Text) + "," + Encryption(txt_postcode.Text) + "," + Encryption(txt_address.Text) + "," + DTP_DoB.Value
  83.             ' Adds the data from the text boxes, encrypting where possible
  84.             SaveRecord(fileLoc_Staff, newValues)
  85.             fillGrid(dgv_staff, fileLoc_Staff)
  86.         Else
  87.             MsgBox("ID is not unique.")
  88.         End If
  89.  
  90.  
  91.  
  92.     End Sub
  93.  
  94.     Private Function Check()
  95.  
  96.         ' Presence check on staff ID
  97.         If txt_staffID.Text = "" Then
  98.             MsgBox("please enter a staff ID")
  99.             Return False
  100.         End If
  101.  
  102.         ' Integer check on staff ID
  103.         If Not IntCheck(txt_staffID.Text) Then
  104.             MsgBox("Non integer input in staff ID textbox")
  105.             Return False
  106.         End If
  107.  
  108.         If txt_forename.Text.Length < 3 Or txt_forename.Text.Length > 20 Then
  109.             'Length Check on forename also acts as a presence check
  110.             MsgBox("Forename entered invalid, must be between 3 and 20 characters")
  111.             Return False
  112.         End If
  113.  
  114.         If txt_surname.Text.Length < 3 Or txt_surname.Text.Length > 20 Then
  115.             'Length Check on surname also acts as a presence check
  116.             MsgBox("Surname entered invalid, must be between 3 and 20 characters")
  117.             Return False
  118.         End If
  119.  
  120.         'password
  121.         'want to contain. capital,lower case, number at least 7 letters
  122.  
  123.         If txt_password.Text.Length < 7 Then
  124.             MsgBox("password must be at least 7 characters")
  125.             Return False
  126.         End If
  127.  
  128.         Dim passwordArray() As Char = txt_password.Text.ToCharArray
  129.         Dim upper As Boolean = False
  130.         Dim lower As Boolean = False
  131.         Dim number As Boolean = False
  132.         ' Each of the conditions  are set to false, only satisfied when a character ticks one off, all must be true when the character array is finished being searched
  133.         For Each c As Char In passwordArray
  134.             If Char.IsUpper(c) Then
  135.                 upper = True
  136.             End If
  137.             If Char.IsLower(c) Then
  138.                 lower = True
  139.             End If
  140.             If Char.IsNumber(c) Then
  141.                 number = True
  142.             End If
  143.         Next
  144.  
  145.         If Not (upper = True AndAlso lower = True AndAlso number = True) Then
  146.             MsgBox("invalid password, must contain, An upper case character, A lower case character and a number")
  147.             Return False
  148.         End If
  149.  
  150.  
  151.         If Not IntCheck(txt_accessLevel.Text) Then
  152.             Return False
  153.         End If
  154.  
  155.         ' Checks the access level is within the bounds of the system
  156.         If txt_accessLevel.Text < 0 Or txt_accessLevel.Text > 4 Then
  157.             MsgBox("invalid access level, must be between 0 and 4")
  158.             Return False
  159.         End If
  160.  
  161.         ' checks the phone number is an integer
  162.         If Not IntCheck(txt_phoneNumber.Text) Then
  163.             MsgBox("invalid phone number, must only contain numbers")
  164.             Return False
  165.         End If
  166.  
  167.         ' After checking its an integer, it checks the length of the number
  168.         If txt_phoneNumber.Text.Length <> 11 Then
  169.             MsgBox("invalid phone number, must be 11 digits long")
  170.             Return False
  171.         End If
  172.  
  173.  
  174.         'PostCode not checked
  175.  
  176.         ' Length check also acts as a presence check
  177.         If txt_address.Text.Length < 2 Or txt_address.Text.Length > 255 Then
  178.             MsgBox("Address entered invalid, must be between 3 and 255 characters")
  179.             Return False
  180.         End If
  181.  
  182.         Return True
  183.  
  184.         'Date of birth not checked
  185.     End Function
  186.  
  187.     Private Sub btn_edit_Click(sender As Object, e As EventArgs) Handles btn_edit.Click
  188.         ' Checks new data to ensure valid data only
  189.         If Check() = False Then
  190.             Return
  191.         End If
  192.         ' Compiles a string of the new data, and edits the existing record with the corresponding ID
  193.         Dim ID As Integer = txt_staffID.Text
  194.         Dim newValues As String = txt_staffID.Text & "," & Encryption(txt_forename.Text) & "," & Encryption(txt_surname.Text) & "," & Encryption(txt_password.Text) & "," & Encryption(txt_accessLevel.Text) & "," & Encryption(txt_phoneNumber.Text) & "," & Encryption(txt_postcode.Text) & "," & Encryption(txt_address.Text) & "," & DTP_DoB.Value.ToString()
  195.         EditRecord(ID, newValues, fileLoc_Staff)
  196.         fillGrid(dgv_staff, fileLoc_Staff)
  197.     End Sub
  198.  
  199.     Private Sub btn_delete_Click(sender As Object, e As EventArgs) Handles btn_delete.Click
  200.         ' Presence checks staff ID textbox to avoid crash
  201.         If txt_staffID.Text = "" Then
  202.             MsgBox("No staff ID given, please try again")
  203.             Return
  204.         End If
  205.         Dim staffID As Integer = txt_staffID.Text
  206.         DeleteRecord(dgv_staff, fileLoc_Staff, staffID)
  207.         fillGrid(dgv_staff, fileLoc_Staff)
  208.     End Sub
  209.  
  210.  
  211.     ' Takes user back to main menu, doesn't delete non saved inputs
  212.     Private Sub btn_menu_Click(sender As Object, e As EventArgs) Handles btn_menu.Click
  213.         Me.Visible = False
  214.         myMenu.Visible = True
  215.     End Sub
  216.  
  217.     ' Sorts
  218.     ' Staff ID Ascending
  219.     ' Staff ID Descending
  220.     Private Sub btn_staffIdAsc_Click(sender As Object, e As EventArgs) Handles btn_staffIdAsc.Click
  221.         AscSort(fileLoc_Staff, 0)
  222.         fillGrid(dgv_staff, fileLoc_Staff)
  223.     End Sub
  224.  
  225.     Private Sub btn_staffIdDesc_Click(sender As Object, e As EventArgs) Handles btn_staffIdDesc.Click
  226.         DescSort(fileLoc_Staff, 0)
  227.         fillGrid(dgv_staff, fileLoc_Staff)
  228.     End Sub
  229.  
  230.  
  231. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement