Advertisement
willeds

Untitled

Apr 5th, 2024
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.21 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Runtime.Remoting
  3.  
  4. Public Class myService
  5.     Private Sub myService_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  6.         fillGrid(dgv_service, FileLoc_Service)
  7.         StartPosition = FormStartPosition.CenterScreen
  8.  
  9.         txt_serviceID.BackColor = gray
  10.         txt_productID.BackColor = gray
  11.         txt_serviceName.BackColor = gray
  12.         txt_price.BackColor = gray
  13.         txt_product.BackColor = gray
  14.         txt_time.BackColor = gray
  15.         txt_serviceDesc.BackColor = gray
  16.  
  17.     End Sub
  18.  
  19.     Private Sub fillText(ByVal rowIndex As Integer)
  20.         txt_serviceID.Text = dgv_service.Rows(rowIndex).Cells(0).Value
  21.         txt_serviceName.Text = dgv_service.Rows(rowIndex).Cells(2).Value
  22.         txt_productID.Text = dgv_service.Rows(rowIndex).Cells(1).Value
  23.         txt_price.Text = dgv_service.Rows(rowIndex).Cells(3).Value
  24.         txt_product.Text = FindField(fileLoc_Product, txt_productID.Text, 2)
  25.         txt_time.Text = dgv_service.Rows(rowIndex).Cells(4).Value
  26.         txt_serviceDesc.Text = dgv_service.Rows(rowIndex).Cells(5).Value
  27.     End Sub
  28.  
  29.     Private Sub clearText()
  30.         txt_serviceID.Text = ""
  31.         txt_productID.Text = ""
  32.         txt_serviceName.Text = ""
  33.         txt_price.Text = ""
  34.         txt_product.Text = ""
  35.         txt_time.Text = ""
  36.         txt_serviceDesc.Text = ""
  37.     End Sub
  38.  
  39.     'Navigation
  40.     Private dgvNavigator As New DataGridViewNavigator()
  41.     Private Sub btn_first_Click(sender As Object, e As EventArgs) Handles btn_first.Click
  42.         dgvNavigator.SelectFirst(dgv_service)
  43.         fillText(dgvNavigator.CurrentIndex)
  44.     End Sub
  45.  
  46.     Private Sub btn_previous_Click(sender As Object, e As EventArgs) Handles btn_previous.Click
  47.         dgvNavigator.SelectPrevious(dgv_service)
  48.         fillText(dgvNavigator.CurrentIndex)
  49.     End Sub
  50.  
  51.     Private Sub btn_next_Click(sender As Object, e As EventArgs) Handles btn_next.Click
  52.         dgvNavigator.SelectNext(dgv_service)
  53.         fillText(dgvNavigator.CurrentIndex)
  54.     End Sub
  55.  
  56.     Private Sub btn_last_Click(sender As Object, e As EventArgs) Handles btn_last.Click
  57.         dgvNavigator.SelectLast(dgv_service)
  58.         fillText(dgvNavigator.CurrentIndex)
  59.     End Sub
  60.     '----------------------------------------------------------------------------------------------'
  61.     Private Sub btn_add_Click(sender As Object, e As EventArgs) Handles btn_add.Click
  62.         clearText()
  63.         Dim newID As Integer = AddRecord(FileLoc_Service)
  64.         txt_serviceID.Text = newID
  65.     End Sub
  66.  
  67.     Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
  68.  
  69.         If Check() = False Then
  70.             Return
  71.  
  72.         End If
  73.  
  74.  
  75.  
  76.  
  77.  
  78.         Dim serviceID As Integer = txt_serviceID.Text
  79.  
  80.         If UniqueCheck(serviceID, FileLoc_Service) Then
  81.             Dim newservice As String = (txt_serviceID.Text + "," + txt_productID.Text + "," + txt_serviceName.Text + "," + txt_price.Text + "," + txt_time.Text + "," + txt_serviceDesc.Text)
  82.             SaveRecord(FileLoc_Service, newservice)
  83.             fillGrid(dgv_service, FileLoc_Service)
  84.         Else
  85.             MsgBox("ID is not unique.")
  86.         End If
  87.         'check presence of supplier ID in Supplier ID file
  88.     End Sub
  89.  
  90.     Private Function Check()
  91.  
  92.         ' Presence check on the service ID textbox
  93.         If txt_serviceID.Text = "" Then
  94.             MsgBox("Please enter a service ID")
  95.             Return False
  96.         End If
  97.  
  98.         ' Checks that the ID entered is an integer
  99.         If Not IntCheck(txt_serviceID.Text) Then
  100.             MsgBox("Please enter a valid service ID")
  101.             Return False
  102.         End If
  103.  
  104.         ' Checks that the product ID is an integer
  105.         If Not IntCheck(txt_productID.Text) Then
  106.             MsgBox("Please enter a valid Product ID")
  107.             Return False
  108.         End If
  109.  
  110.         ' After checking that it is an integer, it is converted to a variable that is an integer, checking first avoids crashes
  111.         Dim productID As Integer = txt_productID.Text
  112.         If BinSearch(productID, fileLoc_Product, 0) = False Then
  113.             MsgBox("invalid Product ID")
  114.             Return False
  115.         End If
  116.  
  117.         ' Checks the legnth of the services name, must be within the boundaries
  118.         If txt_serviceName.Text.Length < 3 Or txt_serviceName.Text.Length > 20 Then
  119.             MsgBox("Service name invalid, must be between 3 and 20 characters")
  120.             Return False
  121.         End If
  122.  
  123.         ' Checks that the price is an integer before attempting to convert
  124.         IntCheck(txt_price.Text)
  125.         Dim Price As Integer = txt_price.Text
  126.         If Price < 0 Or Price > 200 Then
  127.             MsgBox("Invalid Price, must be between 0 and 200 (pounds)")
  128.             Return False
  129.         End If
  130.  
  131.         ' Checks that the time is an integer before attempting to convert
  132.         IntCheck(txt_time.Text)
  133.         Dim Time As Integer = txt_time.Text
  134.         If Time < 0 Or Time > 200 Then
  135.             MsgBox("Service time invalid, must be between 0 and 200 (minutes)")
  136.             Return False
  137.         End If
  138.  
  139.         ' Sets a boundary for the lengths of service description
  140.         If txt_serviceDesc.Text.Length < 0 Or txt_serviceDesc.Text.Length > 200 Then
  141.             MsgBox("Invalid service description, must be between 0 and 200 characters")
  142.             Return False
  143.         End If
  144.  
  145.         Return True
  146.  
  147.     End Function
  148.  
  149.  
  150.  
  151.  
  152.     Private Sub btn_edit_Click(sender As Object, e As EventArgs) Handles btn_edit.Click
  153.         If Check() = False Then
  154.             Return
  155.         End If
  156.         ' Checks new data before making adjustments
  157.         Dim ID As Integer = txt_serviceID.Text
  158.         Dim newValues As String = (txt_serviceID.Text + "," + txt_productID.Text + "," + txt_serviceName.Text + "," + txt_price.Text + "," + txt_time.Text + "," + txt_serviceDesc.Text)
  159.         EditRecord(ID, newValues, FileLoc_Service)
  160.         fillGrid(dgv_service, FileLoc_Service)
  161.     End Sub
  162.  
  163.     Private Sub btn_delete_Click(sender As Object, e As EventArgs) Handles btn_delete.Click
  164.         If IntCheck(txt_serviceID.Text) = False Then
  165.             Return
  166.  
  167.         End If
  168.         Dim serviceID As Integer = txt_serviceID.Text
  169.         DeleteRecord(dgv_service, FileLoc_Service, serviceID)
  170.         fillGrid(dgv_service, FileLoc_Service)
  171.     End Sub
  172.  
  173.  
  174.  
  175.  
  176.     Private Sub btn_menu_Click(sender As Object, e As EventArgs) Handles btn_menu.Click
  177.         Me.Visible = False
  178.         myMenu.Visible = True
  179.     End Sub
  180.  
  181.     Private Sub btn_SerIdAsc_Click(sender As Object, e As EventArgs) Handles btn_SerIdAsc.Click
  182.         AscSort(FileLoc_Service, 0)
  183.         fillGrid(dgv_service, FileLoc_Service)
  184.     End Sub
  185.  
  186.     Private Sub btn_SerIdDesc_Click(sender As Object, e As EventArgs) Handles btn_SerIdDesc.Click
  187.         DescSort(FileLoc_Service, 0)
  188.         fillGrid(dgv_service, FileLoc_Service)
  189.     End Sub
  190.  
  191.     Private Sub btn_prodAsc_Click(sender As Object, e As EventArgs) Handles btn_prodAsc.Click
  192.         AscSort(FileLoc_Service, 1)
  193.         fillGrid(dgv_service, FileLoc_Service)
  194.     End Sub
  195.  
  196.     Private Sub btn_prodDesc_Click(sender As Object, e As EventArgs) Handles btn_prodDesc.Click
  197.         DescSort(FileLoc_Service, 1)
  198.         fillGrid(dgv_service, FileLoc_Service)
  199.     End Sub
  200.  
  201.     Private Sub btn_priAsc_Click(sender As Object, e As EventArgs) Handles btn_priAsc.Click
  202.         AscSort(FileLoc_Service, 3)
  203.         fillGrid(dgv_service, FileLoc_Service)
  204.     End Sub
  205.  
  206.     Private Sub btn_priDesc_Click(sender As Object, e As EventArgs) Handles btn_priDesc.Click
  207.         DescSort(FileLoc_Service, 3)
  208.         fillGrid(dgv_service, FileLoc_Service)
  209.     End Sub
  210.  
  211.     Private Sub btn_timeAsc_Click(sender As Object, e As EventArgs) Handles btn_timeAsc.Click
  212.         AscSort(FileLoc_Service, 4)
  213.         fillGrid(dgv_service, FileLoc_Service)
  214.     End Sub
  215.  
  216.     Private Sub btn_timeDesc_Click(sender As Object, e As EventArgs) Handles btn_timeDesc.Click
  217.         DescSort(FileLoc_Service, 4)
  218.         fillGrid(dgv_service, FileLoc_Service)
  219.     End Sub
  220.  
  221.     Private Sub txt_productID_TextChanged(sender As Object, e As EventArgs) Handles txt_productID.TextChanged
  222.         txt_product.Text = FindField(fileLoc_Product, txt_productID.Text, 2)
  223.     End Sub
  224. End Class
  225.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement