Advertisement
Lewisg005

Untitled

Mar 28th, 2024
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 5.22 KB | Source Code | 0 0
  1. Imports System.Data.OleDb
  2. Public Class FrmForm
  3.  
  4.     Private Sub FrmForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.         'this loads all of the data from tblForms and displays it in a table in dgvForm
  6.        LoadFormData()
  7.  
  8.     End Sub
  9.  
  10.     Private Sub dgvForm_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvForm.CellClick
  11.         Dim thisrow As Integer = e.RowIndex
  12.         'when a cell is clicked all of the data from that row will be displayed in the text boxes
  13.        cmbFormName.Text = dgvForm.Item(0, thisrow).Value
  14.         txtFormTutor.Text = dgvForm.Item(1, thisrow).Value
  15.         txtFormRoom.Text = dgvForm.Item(2, thisrow).Value
  16.         txtTutorEmail.Text = dgvForm.Item(3, thisrow).Value
  17.  
  18.     End Sub
  19.     Sub LoadFormData()
  20.         'this loads all of the data from tblForms and displays it in a table in dgvForm
  21.        SQL = "SELECT * FROM TblForm;"
  22.         Cmd = New OleDbCommand(SQL, Con)
  23.         Dim SQLResults As DataTable = PerformCRUD(Cmd)
  24.         dgvForm.DataSource = SQLResults
  25.  
  26.     End Sub
  27.     Sub CancelConfirmButtonsReset()
  28.         'this resets the form back to how it was when first loaded
  29.  
  30.         txtFormRoom.Enabled = False
  31.         txtFormTutor.Enabled = False
  32.         txtTutorEmail.Enabled = False
  33.         cmbFormName.Enabled = False
  34.        
  35.         dgvForm.Enabled = True
  36.         btnEdit.Enabled = True
  37.         btnAdd.Enabled = True
  38.         btnConfirm.Enabled = False
  39.         btnCancel.Enabled = False
  40.         btnAddConfirm.Enabled = False
  41.         btnAddCancle.Enabled = False
  42.  
  43.     End Sub
  44.  
  45.     Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
  46.         'enables all of the text boxes so that the data in them can be edited
  47.        txtFormRoom.Enabled = True
  48.         txtFormTutor.Enabled = True
  49.         txtTutorEmail.Enabled = True
  50.         cmbFormName.Enabled = True
  51.  
  52.         btnEdit.Enabled = False
  53.         btnAdd.Enabled = False
  54.         btnConfirm.Enabled = True
  55.         btnCancel.Enabled = True
  56.     End Sub
  57.  
  58.     Private Sub btnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirm.Click
  59.         'this will update the database with the info typed in for the form with the corresponding form name to the one selected
  60.        SQL = "UPDATE TblForm SET FormTutor = '" & txtFormTutor.Text & "', FormRoom = '" & txtFormRoom.Text & "', TutorEmail = '" & txtTutorEmail.Text & "' WHERE FormName = '" & cmbFormName.Text & "';"
  61.         Cmd = New OleDbCommand(SQL, Con)
  62.         Dim SQLResults As DataTable = PerformCRUD(Cmd)
  63.         'reloads form so new data is shown
  64.        LoadFormData()
  65.         'resets form
  66.        CancelConfirmButtonsReset()
  67.     End Sub
  68.  
  69.     Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
  70.         CancelConfirmButtonsReset()
  71.     End Sub
  72.  
  73.     Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  74.         'enabes and clears text boxes so a new form can be entered
  75.        txtFormRoom.Enabled = True
  76.         txtFormTutor.Enabled = True
  77.         txtTutorEmail.Enabled = True
  78.         cmbFormName.Enabled = True
  79.  
  80.         btnEdit.Enabled = False
  81.         btnAdd.Enabled = False
  82.         btnAddConfirm.Enabled = True
  83.         btnAddCancle.Enabled = True
  84.         dgvForm.Enabled = False
  85.         cmbFormName.Text = ""
  86.         txtFormRoom.Text = ""
  87.         txtFormTutor.Text = ""
  88.         txtTutorEmail.Text = ""
  89.  
  90.     End Sub
  91.  
  92.     Private Sub btnAddConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddConfirm.Click
  93.         'adds a new record to the database with the values typed in the text boxes
  94.        SQL = "INSERT INTO TblForm VALUES ('" & cmbFormName.Text & "', '" & txtFormTutor.Text & "', '" & txtFormRoom.Text & "', '" & txtTutorEmail.Text & "');"
  95.         Cmd = New OleDbCommand(SQL, Con)
  96.         Dim SQLResults As DataTable = PerformCRUD(Cmd)
  97.         LoadFormData()
  98.         CancelConfirmButtonsReset()
  99.  
  100.     End Sub
  101.  
  102.     Private Sub btnAddCancle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCancle.Click
  103.         CancelConfirmButtonsReset()
  104.     End Sub
  105.  
  106.     Private Sub btnDeleteForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteForm.Click
  107.         '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
  108.        If cmbFormName.Text <> "" Then
  109.             Dim UserResponse As MsgBoxResult = MsgBox("Are you sure that you want to delete the Form: " & cmbFormName.Text, MsgBoxStyle.YesNo, "Delete Record?")
  110.             If UserResponse = vbYes Then
  111.                 SQL = "DELETE * FROM tblForm WHERE FormName = '" & cmbFormName.Text & "';"
  112.                 Cmd = New OleDbCommand(SQL, Con)
  113.                 Dim SQLResults As DataTable = PerformCRUD(Cmd)
  114.  
  115.                 LoadFormData()
  116.  
  117.             End If
  118.         End If
  119.     End Sub
  120.  
  121.     Private Sub btnback_Click(sender As Object, e As EventArgs) Handles btnback.Click
  122.  
  123.         frmAdmin.Show()
  124.         Me.Hide()
  125.  
  126.  
  127.     End Sub
  128. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement