Advertisement
willeds

Untitled

Apr 5th, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 16.45 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Net.Security
  3. Imports System.Net.WebRequestMethods
  4. Imports System.Runtime.Remoting
  5. Imports System.Windows.Forms.LinkLabel
  6. Imports File = System.IO.File
  7.  
  8. Public Class mytimetable
  9.     Private Sub myStaff_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  10.         StartPosition = FormStartPosition.CenterScreen
  11.         fillGrid(dgv_timetable, fileLoc_timetable)
  12.  
  13.         ' Sets the colours of the items
  14.         txt_timetableID.BackColor = gray
  15.         DTP_timetableDate.BackColor = gray
  16.         txt_shiftID1.BackColor = gray
  17.         txt_shiftID2.BackColor = gray
  18.         txt_shiftID3.BackColor = gray
  19.         txt_shiftID4.BackColor = gray
  20.         txt_shiftID5.BackColor = gray
  21.         txt_staffID1.BackColor = gray
  22.         txt_staffID2.BackColor = gray
  23.         txt_staffID3.BackColor = gray
  24.         txt_staffID4.BackColor = gray
  25.         txt_staffID5.BackColor = gray
  26.         txt_staffname1.BackColor = gray
  27.         txt_staffname2.BackColor = gray
  28.         txt_staffname3.BackColor = gray
  29.         txt_staffname4.BackColor = gray
  30.         txt_staffname5.BackColor = gray
  31.         txt_start1.BackColor = gray
  32.         txt_start2.BackColor = gray
  33.         txt_start3.BackColor = gray
  34.         txt_start4.BackColor = gray
  35.         txt_start5.BackColor = gray
  36.         txt_end1.BackColor = gray
  37.         txt_end2.BackColor = gray
  38.         txt_end3.BackColor = gray
  39.         txt_end4.BackColor = gray
  40.         txt_end5.BackColor = gray
  41.     End Sub
  42.  
  43.     Private Sub fillText(ByVal rowIndex As Integer)
  44.         txt_timetableID.Text = dgv_timetable.Rows(rowIndex).Cells(0).Value
  45.         If Not dgv_timetable.Rows(rowIndex).Cells(1).Value = DateTime.MinValue Then
  46.             ' avoids crashes by not putting empty date into DateTimePicker
  47.             DTP_timetableDate.Value = dgv_timetable.Rows(rowIndex).Cells(1).Value
  48.         End If
  49.  
  50.         ' Fills the text boxes
  51.  
  52.         txt_shiftID1.Text = dgv_timetable.Rows(rowIndex).Cells(2).Value
  53.         txt_shiftID2.Text = dgv_timetable.Rows(rowIndex).Cells(3).Value
  54.         txt_shiftID3.Text = dgv_timetable.Rows(rowIndex).Cells(4).Value
  55.         txt_shiftID4.Text = dgv_timetable.Rows(rowIndex).Cells(5).Value
  56.         txt_shiftID5.Text = dgv_timetable.Rows(rowIndex).Cells(6).Value
  57.         txt_staffID1.Text = FindField(fileLoc_Shift, txt_shiftID1.Text, 2)
  58.         txt_staffID2.Text = FindField(fileLoc_Shift, txt_shiftID2.Text, 2)
  59.         txt_staffID3.Text = FindField(fileLoc_Shift, txt_shiftID3.Text, 2)
  60.         txt_staffID4.Text = FindField(fileLoc_Shift, txt_shiftID4.Text, 2)
  61.         txt_staffID5.Text = FindField(fileLoc_Shift, txt_shiftID5.Text, 2)
  62.         txt_staffname1.Text = Decryption(FindField(fileLoc_Staff, txt_staffID1.Text, 1))
  63.         txt_staffname2.Text = Decryption(FindField(fileLoc_Staff, txt_staffID2.Text, 1))
  64.         txt_staffname3.Text = Decryption(FindField(fileLoc_Staff, txt_staffID3.Text, 1))
  65.         txt_staffname4.Text = Decryption(FindField(fileLoc_Staff, txt_staffID4.Text, 1))
  66.         txt_staffname5.Text = Decryption(FindField(fileLoc_Staff, txt_staffID5.Text, 1))
  67.         txt_start1.Text = FindField(fileLoc_Shift, txt_shiftID1.Text, 3)
  68.         txt_start2.Text = FindField(fileLoc_Shift, txt_shiftID2.Text, 3)
  69.         txt_start3.Text = FindField(fileLoc_Shift, txt_shiftID3.Text, 3)
  70.         txt_start4.Text = FindField(fileLoc_Shift, txt_shiftID4.Text, 3)
  71.         txt_start5.Text = FindField(fileLoc_Shift, txt_shiftID5.Text, 3)
  72.         txt_end1.Text = FindField(fileLoc_Shift, txt_shiftID1.Text, 4)
  73.         txt_end2.Text = FindField(fileLoc_Shift, txt_shiftID2.Text, 4)
  74.         txt_end3.Text = FindField(fileLoc_Shift, txt_shiftID3.Text, 4)
  75.         txt_end4.Text = FindField(fileLoc_Shift, txt_shiftID4.Text, 4)
  76.         txt_end5.Text = FindField(fileLoc_Shift, txt_shiftID5.Text, 4)
  77.  
  78.  
  79.  
  80.     End Sub
  81.  
  82.  
  83.  
  84.  
  85.     Private Sub clearText()
  86.  
  87.         ' Clears text boxes
  88.  
  89.         txt_timetableID.Text = ""
  90.         DTP_timetableDate.CustomFormat = " "
  91.         txt_shiftID1.Text = ""
  92.         txt_shiftID2.Text = ""
  93.         txt_shiftID3.Text = ""
  94.         txt_shiftID4.Text = ""
  95.         txt_shiftID5.Text = ""
  96.         txt_staffID1.Text = ""
  97.         txt_staffID2.Text = ""
  98.         txt_staffID3.Text = ""
  99.         txt_staffID4.Text = ""
  100.         txt_staffID5.Text = ""
  101.         txt_staffname1.Text = ""
  102.         txt_staffname2.Text = ""
  103.         txt_staffname3.Text = ""
  104.         txt_staffname4.Text = ""
  105.         txt_staffname5.Text = ""
  106.         txt_start1.Text = ""
  107.         txt_start2.Text = ""
  108.         txt_start3.Text = ""
  109.         txt_start4.Text = ""
  110.         txt_start5.Text = ""
  111.         txt_end1.Text = ""
  112.         txt_end2.Text = ""
  113.         txt_end3.Text = ""
  114.         txt_end4.Text = ""
  115.         txt_end5.Text = ""
  116.     End Sub
  117.  
  118.     'Navigation
  119.     Private dgvNavigator As New DataGridViewNavigator()
  120.     Private Sub btn_first_Click(sender As Object, e As EventArgs) Handles btn_first.Click
  121.         dgvNavigator.SelectFirst(dgv_timetable)
  122.         fillText(dgvNavigator.CurrentIndex)
  123.     End Sub
  124.  
  125.     Private Sub btn_previous_Click(sender As Object, e As EventArgs) Handles btn_previous.Click
  126.         dgvNavigator.SelectPrevious(dgv_timetable)
  127.         fillText(dgvNavigator.CurrentIndex)
  128.     End Sub
  129.  
  130.     Private Sub btn_next_Click(sender As Object, e As EventArgs) Handles btn_next.Click
  131.         dgvNavigator.SelectNext(dgv_timetable)
  132.         fillText(dgvNavigator.CurrentIndex)
  133.     End Sub
  134.  
  135.     Private Sub btn_last_Click(sender As Object, e As EventArgs) Handles btn_last.Click
  136.         dgvNavigator.SelectLast(dgv_timetable)
  137.         fillText(dgvNavigator.CurrentIndex)
  138.     End Sub
  139.     '----------------------------------------------------------------------------------------------'
  140.     Private Sub btn_add_Click(sender As Object, e As EventArgs) Handles btn_add.Click
  141.         clearText()
  142.         Dim newID As Integer = AddRecord(fileLoc_timetable)
  143.         txt_timetableID.Text = newID
  144.  
  145.         Dim newshiftID As Integer = AddRecord(fileLoc_Shift)
  146.         txt_shiftID1.Text = newshiftID
  147.         txt_shiftID2.Text = newshiftID + 1
  148.         txt_shiftID3.Text = newshiftID + 2
  149.         txt_shiftID4.Text = newshiftID + 3
  150.         txt_shiftID5.Text = newshiftID + 4
  151.  
  152.     End Sub
  153.  
  154.     Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
  155.         If Check() = False Then
  156.             Return
  157.         End If
  158.  
  159.         Dim timetableID As String = txt_timetableID.Text
  160.  
  161.         Dim newShift1 As String = txt_shiftID1.Text
  162.         Dim newShift2 As String = txt_shiftID2.Text
  163.         Dim newShift3 As String = txt_shiftID3.Text
  164.         Dim newShift4 As String = txt_shiftID4.Text
  165.         Dim newShift5 As String = txt_shiftID5.Text
  166.  
  167.         Dim StaffID1 As String = txt_staffID1.Text
  168.         Dim StaffID2 As String = txt_staffID2.Text
  169.         Dim StaffID3 As String = txt_staffID3.Text
  170.         Dim StaffID4 As String = txt_staffID4.Text
  171.         Dim StaffID5 As String = txt_staffID5.Text
  172.  
  173.  
  174.  
  175.         Dim shiftID1 As String = shiftCreate(newShift1, timetableID, StaffID1, txt_start1.Text, txt_end1.Text)
  176.         Dim shiftID2 As String = shiftCreate(newShift2, timetableID, StaffID2, txt_start2.Text, txt_end2.Text)
  177.         Dim shiftID3 As String = shiftCreate(newShift3, timetableID, StaffID3, txt_start3.Text, txt_end3.Text)
  178.         Dim shiftID4 As String = shiftCreate(newShift4, timetableID, StaffID4, txt_start4.Text, txt_end4.Text)
  179.         Dim shiftID5 As String = shiftCreate(newShift5, timetableID, StaffID5, txt_start5.Text, txt_end5.Text)
  180.  
  181.  
  182.  
  183.         If UniqueCheck(timetableID, fileLoc_timetable) Then
  184.             Dim newtimetable As String = txt_timetableID.Text & "," & DTP_timetableDate.Value.Date & "," & newShift1 & "," & newShift2 & "," & newShift3 & "," & newShift4 & "," & newShift5
  185.             SaveRecord(fileLoc_timetable, newtimetable)
  186.             fillGrid(dgv_timetable, fileLoc_timetable)
  187.         Else
  188.             MsgBox("ID is not unique.")
  189.         End If
  190.  
  191.     End Sub
  192.  
  193.     Private Function Check()
  194.         If txt_timetableID.Text = "" Then
  195.             MsgBox("please enter an timetable ID")
  196.             Return False
  197.         End If
  198.  
  199.         If IntCheck(txt_timetableID.Text) Then
  200.         Else
  201.             Return False
  202.         End If
  203.  
  204.         If Not (IntCheck(txt_shiftID1.Text) AndAlso IntCheck(txt_shiftID2.Text) AndAlso IntCheck(txt_shiftID3.Text) AndAlso IntCheck(txt_shiftID4.Text) AndAlso IntCheck(txt_shiftID5.Text)) Then
  205.             MsgBox("Please enter valid Shift IDs for all shifts")
  206.             Return False
  207.         End If
  208.  
  209.  
  210.         Return True
  211.     End Function
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.     Private Function shiftCreate(ByVal shiftID As String, ByVal timetableID As String, Optional staffID As String = "", Optional ShiftStart As String = "", Optional ShiftEnd As String = "")
  220.  
  221.         If shiftCheck(shiftID, timetableID, staffID, ShiftStart, ShiftEnd) = False Then
  222.             Return False
  223.         End If
  224.  
  225.  
  226.  
  227.  
  228.         Dim newShift As String = shiftID & "," & timetableID & "," & staffID & "," & ShiftStart & "," & ShiftEnd
  229.         SaveRecord(fileLoc_Shift, newShift)
  230.         Return newShift
  231.  
  232.     End Function
  233.  
  234.  
  235.     Private Function shiftCheck(ByVal shiftID As String, ByVal timetableID As String, Optional staffID As String = "", Optional ShiftStart As String = "", Optional ShiftEnd As String = "")
  236.  
  237.  
  238.         If Not IntCheck(shiftID) Then
  239.             Return False
  240.         End If
  241.  
  242.         If Not IntCheck(timetableID) Then
  243.             Return False
  244.         End If
  245.  
  246.         If Not staffID = "" Then
  247.             BinSearch(staffID, fileLoc_Staff, 0)
  248.         End If
  249.  
  250.  
  251.  
  252.         If Not ShiftStart = "" AndAlso Not ShiftEnd = "" Then
  253.  
  254.             Dim partStart() As String = ShiftStart.Split(":")
  255.             Dim partEnd() As String = ShiftEnd.Split(":")
  256.  
  257.             IntCheck(partStart(0))
  258.             IntCheck(partStart(1))
  259.  
  260.             IntCheck(partEnd(0))
  261.             IntCheck(partEnd(1))
  262.  
  263.             Dim hourStart As Integer = CInt(partStart(0))
  264.             Dim minuteStart As Integer = CInt(partStart(1))
  265.             If hourStart < 0 Or hourStart > 24 Then
  266.                 MsgBox("invalid Hour")
  267.                 Return False
  268.             End If
  269.  
  270.             If minuteStart < 0 Or minuteStart > 60 Then
  271.                 MsgBox("invalid minute")
  272.                 Return False
  273.             End If
  274.  
  275.             Dim hourEnd As Integer = CInt(partEnd(0))
  276.             Dim minuteEnd As Integer = CInt(partEnd(1))
  277.             If hourEnd < 0 Or hourEnd > 24 Then
  278.                 MsgBox("invalid Hour")
  279.                 Return False
  280.             End If
  281.  
  282.             If minuteEnd < 0 Or minuteEnd > 60 Then
  283.                 MsgBox("invalid minute")
  284.                 Return False
  285.             End If
  286.  
  287.             If hourStart > hourEnd Then
  288.                 Return False
  289.             End If
  290.  
  291.             If hourStart = hourEnd Then
  292.                 If minuteStart > minuteEnd Then
  293.                     Return False
  294.                 End If
  295.             End If
  296.  
  297.  
  298.  
  299.         End If
  300.  
  301.         If Not staffID = "" Then
  302.             If BinSearch(staffID, fileLoc_Staff, 0) = False Then
  303.                 Return False
  304.  
  305.             End If
  306.         End If
  307.         Return True
  308.     End Function
  309.  
  310.  
  311.     Private Sub btn_edit_Click(sender As Object, e As EventArgs) Handles btn_edit.Click
  312.         If Check() = False Then
  313.             Return
  314.         End If
  315.  
  316.         Dim ID As Integer = txt_timetableID.Text
  317.         Dim ServiceUse As Integer = FindField(fileLoc_timetable, txt_timetableID.Text, 8)
  318.         Dim newValues As String = txt_timetableID.Text & "," & DTP_timetableDate.Value.Date & "," & txt_shiftID1.Text & "," & txt_shiftID2.Text & "," & txt_shiftID3.Text & "," & txt_shiftID4.Text & "," & txt_shiftID5.Text
  319.         EditRecord(ID, newValues, fileLoc_timetable)
  320.         fillGrid(dgv_timetable, fileLoc_timetable)
  321.  
  322.  
  323.         Dim Shift1 As String = txt_shiftID1.Text
  324.         Dim Shift2 As String = txt_shiftID2.Text
  325.         Dim Shift3 As String = txt_shiftID3.Text
  326.         Dim Shift4 As String = txt_shiftID4.Text
  327.         Dim Shift5 As String = txt_shiftID5.Text
  328.  
  329.         Dim StaffID1 As String = txt_staffID1.Text
  330.         Dim StaffID2 As String = txt_staffID2.Text
  331.         Dim StaffID3 As String = txt_staffID3.Text
  332.         Dim StaffID4 As String = txt_staffID4.Text
  333.         Dim StaffID5 As String = txt_staffID5.Text
  334.  
  335.  
  336.  
  337.         shiftCheck(txt_shiftID1.Text, txt_timetableID.Text, StaffID1, txt_start1.Text, txt_end1.Text)
  338.         Dim newShift1 As String = txt_shiftID1.Text & "," & txt_timetableID.Text & "," & StaffID1 & "," & txt_start1.Text & "," & txt_end1.Text
  339.         EditRecord(txt_shiftID1.Text, newShift1, fileLoc_Shift)
  340.  
  341.         shiftCheck(txt_shiftID2.Text, txt_timetableID.Text, StaffID2, txt_start2.Text, txt_end2.Text)
  342.         Dim newShift2 As String = txt_shiftID2.Text & "," & txt_timetableID.Text & "," & StaffID2 & "," & txt_start2.Text & "," & txt_end2.Text
  343.         EditRecord(txt_shiftID2.Text, newShift2, fileLoc_Shift)
  344.  
  345.         shiftCheck(txt_shiftID3.Text, txt_timetableID.Text, StaffID3, txt_start3.Text, txt_end3.Text)
  346.         Dim newShift3 As String = txt_shiftID3.Text & "," & txt_timetableID.Text & "," & StaffID3 & "," & txt_start3.Text & "," & txt_end3.Text
  347.         EditRecord(txt_shiftID3.Text, newShift3, fileLoc_Shift)
  348.  
  349.         shiftCheck(txt_shiftID4.Text, txt_timetableID.Text, StaffID4, txt_start4.Text, txt_end4.Text)
  350.         Dim newShift4 As String = txt_shiftID4.Text & "," & txt_timetableID.Text & "," & StaffID4 & "," & txt_start4.Text & "," & txt_end4.Text
  351.         EditRecord(txt_shiftID4.Text, newShift4, fileLoc_Shift)
  352.  
  353.         shiftCheck(txt_shiftID5.Text, txt_timetableID.Text, StaffID5, txt_start5.Text, txt_end5.Text)
  354.         Dim newShift5 As String = txt_shiftID5.Text & "," & txt_timetableID.Text & "," & StaffID5 & "," & txt_start5.Text & "," & txt_end5.Text
  355.         EditRecord(txt_shiftID5.Text, newShift5, fileLoc_Shift)
  356.  
  357.     End Sub
  358.     Private Sub btn_delete_Click(sender As Object, e As EventArgs) Handles btn_delete.Click
  359.         If txt_timetableID.Text = "" Then
  360.             Return
  361.         End If
  362.         Dim appID As Integer = txt_timetableID.Text
  363.         DeleteRecord(dgv_timetable, fileLoc_timetable, appID)
  364.  
  365.  
  366.  
  367.         fillGrid(dgv_timetable, fileLoc_timetable)
  368.     End Sub
  369.  
  370.     Private Sub btn_menu_Click(sender As Object, e As EventArgs) Handles btn_menu.Click
  371.         Me.Visible = False
  372.         myMenu.Visible = True
  373.     End Sub
  374.  
  375.  
  376.  
  377.  
  378.  
  379.     ' Takes the when a box is clicked or ID is placed to put the staff name from the staff text file
  380.     Private Sub txt_staffname1_Click(sender As Object, e As EventArgs) Handles txt_staffname1.Click
  381.         txt_staffname1.Text = Decryption(FindField(fileLoc_Staff, txt_staffID1.Text, 1))
  382.     End Sub
  383.  
  384.     Private Sub txt_staffname2_Click(sender As Object, e As EventArgs) Handles txt_staffname1.Click
  385.         txt_staffname2.Text = Decryption(FindField(fileLoc_Staff, txt_staffID2.Text, 1))
  386.     End Sub
  387.     Private Sub txt_staffname3_Click(sender As Object, e As EventArgs) Handles txt_staffname1.Click
  388.         txt_staffname3.Text = Decryption(FindField(fileLoc_Staff, txt_staffID3.Text, 1))
  389.     End Sub
  390.     Private Sub txt_staffname4_Click(sender As Object, e As EventArgs) Handles txt_staffname1.Click
  391.         txt_staffname4.Text = Decryption(FindField(fileLoc_Staff, txt_staffID4.Text, 1))
  392.     End Sub
  393.     Private Sub txt_staffname5_Click(sender As Object, e As EventArgs) Handles txt_staffname1.Click
  394.         txt_staffname5.Text = Decryption(FindField(fileLoc_Staff, txt_staffID5.Text, 1))
  395.     End Sub
  396.  
  397.     Private Sub txt_staffID1_TextChanged(sender As Object, e As EventArgs) Handles txt_staffID1.TextChanged
  398.         txt_staffname1.Text = Decryption(FindField(fileLoc_Staff, txt_staffID1.Text, 1))
  399.     End Sub
  400.  
  401.     Private Sub txt_staffID2_TextChanged(sender As Object, e As EventArgs) Handles txt_staffID2.TextChanged
  402.         txt_staffname2.Text = Decryption(FindField(fileLoc_Staff, txt_staffID2.Text, 1))
  403.     End Sub
  404.  
  405.     Private Sub txt_staffID3_TextChanged(sender As Object, e As EventArgs) Handles txt_staffID3.TextChanged
  406.         txt_staffname3.Text = Decryption(FindField(fileLoc_Staff, txt_staffID3.Text, 1))
  407.     End Sub
  408.  
  409.     Private Sub txt_staffID4_TextChanged(sender As Object, e As EventArgs) Handles txt_staffID4.TextChanged
  410.         txt_staffname4.Text = Decryption(FindField(fileLoc_Staff, txt_staffID4.Text, 1))
  411.     End Sub
  412.  
  413.     Private Sub txt_staffID5_TextChanged(sender As Object, e As EventArgs) Handles txt_staffID5.TextChanged
  414.         txt_staffname5.Text = Decryption(FindField(fileLoc_Staff, txt_staffID5.Text, 1))
  415.     End Sub
  416. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement