Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Public Class myTreatment
- Private Sub mytreatment_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- StartPosition = FormStartPosition.CenterScreen
- fillGrid(dgv_treatment, fileLoc_treatment)
- txt_treatmentID.BackColor = gray
- txt_productID.BackColor = gray
- txt_treatmentName.BackColor = gray
- txt_price.BackColor = gray
- txt_product.BackColor = gray
- txt_time.BackColor = gray
- txt_treatmentDesc.BackColor = gray
- End Sub
- Private Sub fillText(ByVal rowIndex As Integer)
- txt_treatmentID.Text = dgv_treatment.Rows(rowIndex).Cells(0).Value
- txt_productID.Text = dgv_treatment.Rows(rowIndex).Cells(1).Value
- txt_treatmentName.Text = dgv_treatment.Rows(rowIndex).Cells(2).Value
- txt_price.Text = dgv_treatment.Rows(rowIndex).Cells(3).Value
- txt_product.Text = FindField(fileLoc_Product, txt_productID.Text, 2)
- txt_time.Text = dgv_treatment.Rows(rowIndex).Cells(4).Value
- txt_treatmentDesc.Text = dgv_treatment.Rows(rowIndex).Cells(5).Value
- End Sub
- Private Sub clearText()
- txt_treatmentID.Text = ""
- txt_productID.Text = ""
- txt_treatmentName.Text = ""
- txt_price.Text = ""
- txt_product.Text = ""
- txt_time.Text = ""
- txt_treatmentDesc.Text = ""
- End Sub
- 'Navigation
- Private dgvNavigator As New DataGridViewNavigator()
- Private Sub btn_first_Click(sender As Object, e As EventArgs) Handles btn_first.Click
- dgvNavigator.SelectFirst(dgv_treatment)
- fillText(dgvNavigator.CurrentIndex)
- End Sub
- Private Sub btn_previous_Click(sender As Object, e As EventArgs) Handles btn_previous.Click
- dgvNavigator.SelectPrevious(dgv_treatment)
- fillText(dgvNavigator.CurrentIndex)
- End Sub
- Private Sub btn_next_Click(sender As Object, e As EventArgs) Handles btn_next.Click
- dgvNavigator.SelectNext(dgv_treatment)
- fillText(dgvNavigator.CurrentIndex)
- End Sub
- Private Sub btn_last_Click(sender As Object, e As EventArgs) Handles btn_last.Click
- dgvNavigator.SelectLast(dgv_treatment)
- fillText(dgvNavigator.CurrentIndex)
- End Sub
- '----------------------------------------------------------------------------------------------'
- Private Sub btn_add_Click(sender As Object, e As EventArgs) Handles btn_add.Click
- clearText()
- Dim newID As Integer = AddRecord(fileLoc_treatment)
- txt_treatmentID.Text = newID
- End Sub
- Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
- If Check() = False Then
- Return
- End If
- Dim treatmentID As Integer = txt_treatmentID.Text
- If UniqueCheck(treatmentID, fileLoc_treatment) Then
- Dim newValus As String = (txt_treatmentID.Text + "," + txt_productID.Text + "," + txt_treatmentName.Text + "," + txt_price.Text + "," + txt_time.Text + "," + txt_treatmentDesc.Text)
- SaveRecord(fileLoc_treatment, newValus)
- fillGrid(dgv_treatment, fileLoc_treatment)
- Else
- MsgBox("ID is not unique.")
- End If
- 'check presence of supplier ID in Supplier ID file
- End Sub
- Private Function Check()
- ' Presence check for the treatment ID
- If txt_treatmentID.Text = "" Then
- MsgBox("Please enter a treatment ID")
- Return False
- End If
- ' Integer check on the treatment ID
- If Not IntCheck(txt_treatmentID.Text) Then
- MsgBox("Please enter a valid treatment ID")
- Return False
- End If
- ' Integer check on the product ID
- If Not IntCheck(txt_productID.Text) Then
- MsgBox("Please enter a valid Product ID")
- Return False
- End If
- ' Verifying the product ID
- Dim productID As Integer = txt_productID.Text
- If BinSearch(productID, fileLoc_Product, 0) = False Then
- MsgBox("invalid Product ID")
- Return False
- End If
- ' Length (and presence) check on the treatment name
- If txt_treatmentName.Text.Length < 2 Or txt_treatmentName.Text.Length > 20 Then
- MsgBox("treatment name invalid, must be between 3 and 19 characters")
- Return False
- End If
- ' Integer check on the price to avoid crash when converting
- IntCheck(txt_price.Text)
- Dim Price As Integer = txt_price.Text
- If Price < 0 Or Price > 200 Then
- MsgBox("Invalid Price, must be between 0 and 200 (pounds)")
- Return False
- End If
- ' Integer time on the price to avoid crash when converting
- IntCheck(txt_time.Text)
- Dim Time As Integer = txt_time.Text
- If Time < 0 Or Time > 200 Then
- MsgBox("Service time invalid, must be between 0 and 200 (minutes)")
- Return False
- End If
- ' Length (and presence) check on the treatment description
- If txt_treatmentDesc.Text.Length < 10 Or txt_treatmentDesc.Text.Length > 200 Then
- MsgBox("Invalid service description, must be between 0 and 200 characters")
- Return False
- End If
- Return True
- End Function
- Private Sub btn_edit_Click(sender As Object, e As EventArgs) Handles btn_edit.Click
- ' Checks data to ensure validity
- If Check() = False Then
- Return
- End If
- Dim ID As Integer = txt_treatmentID.Text
- Dim newValues As String = (txt_treatmentID.Text + "," + txt_productID.Text + "," + txt_treatmentName.Text + "," + txt_price.Text + "," + txt_time.Text + "," + txt_treatmentDesc.Text)
- EditRecord(ID, newValues, fileLoc_treatment)
- fillGrid(dgv_treatment, fileLoc_treatment)
- End Sub
- Private Sub btn_delete_Click(sender As Object, e As EventArgs) Handles btn_delete.Click
- If txt_treatmentID.Text = "" Then
- MsgBox("Please enter a treatment ID")
- Return
- End If
- Dim treatmentID As Integer = txt_treatmentID.Text
- DeleteRecord(dgv_treatment, fileLoc_treatment, treatmentID)
- fillGrid(dgv_treatment, fileLoc_treatment)
- End Sub
- Private Sub btn_menu_Click(sender As Object, e As EventArgs) Handles btn_menu.Click
- Me.Visible = False
- myMenu.Visible = True
- End Sub
- Private Sub txt_productID_TextChanged(sender As Object, e As EventArgs) Handles txt_productID.TextChanged
- txt_product.Text = FindField(fileLoc_Product, txt_productID.Text, 2)
- End Sub
- ' Sorts
- ' Treatment ID Ascending/Descending
- ' Product ID Ascending/Descending
- ' Price Ascending/Descending
- ' Time Ascending/Descending
- Private Sub btn_TreIdAsc_Click(sender As Object, e As EventArgs) Handles btn_TreIdAsc.Click
- AscSort(fileLoc_treatment, 0)
- fillGrid(dgv_treatment, fileLoc_treatment)
- End Sub
- Private Sub btn_TreIdDesc_Click(sender As Object, e As EventArgs) Handles btn_TreIdDesc.Click
- DescSort(fileLoc_treatment, 0)
- fillGrid(dgv_treatment, fileLoc_treatment)
- End Sub
- Private Sub btn_prodAsc_Click(sender As Object, e As EventArgs) Handles btn_prodAsc.Click
- AscSort(fileLoc_treatment, 1)
- fillGrid(dgv_treatment, fileLoc_treatment)
- End Sub
- Private Sub btn_prodDesc_Click(sender As Object, e As EventArgs) Handles btn_prodDesc.Click
- DescSort(fileLoc_treatment, 1)
- fillGrid(dgv_treatment, fileLoc_treatment)
- End Sub
- Private Sub btn_priAsc_Click(sender As Object, e As EventArgs) Handles btn_priAsc.Click
- AscSort(fileLoc_treatment, 3)
- fillGrid(dgv_treatment, fileLoc_treatment)
- End Sub
- Private Sub btn_priDesc_Click(sender As Object, e As EventArgs) Handles btn_priDesc.Click
- DescSort(fileLoc_treatment, 3)
- fillGrid(dgv_treatment, fileLoc_treatment)
- End Sub
- Private Sub btn_timeAsc_Click(sender As Object, e As EventArgs) Handles btn_timeAsc.Click
- AscSort(fileLoc_treatment, 4)
- fillGrid(dgv_treatment, fileLoc_treatment)
- End Sub
- Private Sub btn_timeDesc_Click(sender As Object, e As EventArgs) Handles btn_timeDesc.Click
- DescSort(fileLoc_treatment, 4)
- fillGrid(dgv_treatment, fileLoc_treatment)
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Me.Visible = False
- myService.Visible = True
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement