Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.OleDb
- Public Class FrmForm
- Private Sub FrmForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'this loads all of the data from tblForms and displays it in a table in dgvForm
- LoadFormData()
- End Sub
- Private Sub dgvForm_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvForm.CellClick
- Dim thisrow As Integer = e.RowIndex
- 'when a cell is clicked all of the data from that row will be displayed in the text boxes
- cmbFormName.Text = dgvForm.Item(0, thisrow).Value
- txtFormTutor.Text = dgvForm.Item(1, thisrow).Value
- txtFormRoom.Text = dgvForm.Item(2, thisrow).Value
- txtTutorEmail.Text = dgvForm.Item(3, thisrow).Value
- End Sub
- Sub LoadFormData()
- 'this loads all of the data from tblForms and displays it in a table in dgvForm
- SQL = "SELECT * FROM TblForm;"
- Cmd = New OleDbCommand(SQL, Con)
- Dim SQLResults As DataTable = PerformCRUD(Cmd)
- dgvForm.DataSource = SQLResults
- End Sub
- Sub CancelConfirmButtonsReset()
- 'this resets the form back to how it was when first loaded
- txtFormRoom.Enabled = False
- txtFormTutor.Enabled = False
- txtTutorEmail.Enabled = False
- cmbFormName.Enabled = False
- dgvForm.Enabled = True
- btnEdit.Enabled = True
- btnAdd.Enabled = True
- btnConfirm.Enabled = False
- btnCancel.Enabled = False
- btnAddConfirm.Enabled = False
- btnAddCancle.Enabled = False
- End Sub
- Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
- 'enables all of the text boxes so that the data in them can be edited
- txtFormRoom.Enabled = True
- txtFormTutor.Enabled = True
- txtTutorEmail.Enabled = True
- cmbFormName.Enabled = True
- btnEdit.Enabled = False
- btnAdd.Enabled = False
- btnConfirm.Enabled = True
- btnCancel.Enabled = True
- End Sub
- Private Sub btnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirm.Click
- 'this will update the database with the info typed in for the form with the corresponding form name to the one selected
- SQL = "UPDATE TblForm SET FormTutor = '" & txtFormTutor.Text & "', FormRoom = '" & txtFormRoom.Text & "', TutorEmail = '" & txtTutorEmail.Text & "' WHERE FormName = '" & cmbFormName.Text & "';"
- Cmd = New OleDbCommand(SQL, Con)
- Dim SQLResults As DataTable = PerformCRUD(Cmd)
- 'reloads form so new data is shown
- LoadFormData()
- 'resets form
- CancelConfirmButtonsReset()
- End Sub
- Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
- CancelConfirmButtonsReset()
- End Sub
- Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
- 'enabes and clears text boxes so a new form can be entered
- txtFormRoom.Enabled = True
- txtFormTutor.Enabled = True
- txtTutorEmail.Enabled = True
- cmbFormName.Enabled = True
- btnEdit.Enabled = False
- btnAdd.Enabled = False
- btnAddConfirm.Enabled = True
- btnAddCancle.Enabled = True
- dgvForm.Enabled = False
- cmbFormName.Text = ""
- txtFormRoom.Text = ""
- txtFormTutor.Text = ""
- txtTutorEmail.Text = ""
- End Sub
- Private Sub btnAddConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddConfirm.Click
- 'adds a new record to the database with the values typed in the text boxes
- SQL = "INSERT INTO TblForm VALUES ('" & cmbFormName.Text & "', '" & txtFormTutor.Text & "', '" & txtFormRoom.Text & "', '" & txtTutorEmail.Text & "');"
- Cmd = New OleDbCommand(SQL, Con)
- Dim SQLResults As DataTable = PerformCRUD(Cmd)
- LoadFormData()
- CancelConfirmButtonsReset()
- End Sub
- Private Sub btnAddCancle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCancle.Click
- CancelConfirmButtonsReset()
- End Sub
- Private Sub btnDeleteForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteForm.Click
- 'asks if the user is sure they want to delete the form selected, if they say yes that form will be deleted from the database
- If cmbFormName.Text <> "" Then
- Dim UserResponse As MsgBoxResult = MsgBox("Are you sure that you want to delete the Form: " & cmbFormName.Text, MsgBoxStyle.YesNo, "Delete Record?")
- If UserResponse = vbYes Then
- SQL = "DELETE * FROM tblForm WHERE FormName = '" & cmbFormName.Text & "';"
- Cmd = New OleDbCommand(SQL, Con)
- Dim SQLResults As DataTable = PerformCRUD(Cmd)
- LoadFormData()
- End If
- End If
- End Sub
- Private Sub btnback_Click(sender As Object, e As EventArgs) Handles btnback.Click
- frmAdmin.Show()
- Me.Hide()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement