Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub btnPISubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPISubmit.Click
- 'check if txtbox is empty
- If Not (txtPIStudNo.Text = "" Or txtPILname.Text = "" Or txtPIFname.Text = "" Or txtPIMname.Text = "" Or cboPSCourse.SelectedItem = "") Then
- Dim msg As MsgBoxResult = MsgBox("Are you sure you want to save?", MsgBoxStyle.YesNo) 'Prompt for saving
- 'Check user choice
- If msg = MsgBoxResult.Yes Then ' If Yes
- 'Check for valid student number
- If txtPIStudNo.TextLength = 7 Then
- Dim strLname As String = StrConv(txtPILname.Text, VbStrConv.ProperCase)
- Dim strFname As String = StrConv(txtPIFname.Text, VbStrConv.ProperCase)
- Dim strMname As String = StrConv(txtPIMname.Text, VbStrConv.ProperCase)
- 'Execute SQL statements
- Dim connPIcmd As New SqlCommand("SELECT s.Stud_Number, p.Prob_Type, p.School_Year FROM Student_Information s" & _
- " INNER JOIN Academic_Probation p ON s.Stud_Number = p.Stud_Number" _
- & " WHERE s.Stud_Number = " & Convert.ToInt32(txtPIStudNo.Text) & _
- "ORDER BY p.Prob_Type DESC", connMain.Conn)
- Dim connPIdr As SqlDataReader = connPIcmd.ExecuteReader()
- 'Check if student has record
- If connPIdr.HasRows = 0 Then
- 'Change SQL statement
- connPIcmd.CommandText = "INSERT INTO Student_Information(Stud_Number, Stud_Fname," _
- & "Stud_Lname, Stud_Mname, Stud_Course, Stud_YearLevel) VALUES (" _
- & Convert.ToInt32(txtPIStudNo.Text) & ",'" & strLname & _
- "','" & strFname & "','" & strMname & "','" & _
- cboPICourse.SelectedItem & "','" & cboPIYearLvl.Text & "')"
- connPIdr.Close() 'Close reader
- connPIcmd.ExecuteNonQuery()
- Dim strProbLvl As String = ""
- Dim intProbIndex As Integer = cboPIProbLvl.SelectedIndex
- If intProbIndex = 0 Then
- strProbLvl = "FAP"
- ElseIf intProbIndex = 1 Then
- strProbLvl = "SAP"
- Else
- strProbLvl = "TAP"
- End If
- 'Change SQL statement
- connPIcmd.CommandText = "INSERT INTO Academic_Probation(Prob_Type, School_Year, Prob_Reason, Stud_Number) VALUES ('" _
- & strProbLvl & "','SY" & cboPISY.Text & cboPISem.Text & " Sem" & _
- "','" & txtPIReason.Text & "'," & Convert.ToInt32(txtPIStudNo.Text) & ")"
- connPIdr.Close()
- connPIcmd.ExecuteNonQuery()
- MsgBox("The database has been updated.", MsgBoxStyle.Information) 'Display info msg
- Else
- If connPIdr.Read Then
- 'Check Probation Level
- If (connPIdr.GetString(1) = "FAP" And cboPIProbLvl.SelectedIndex = 0) Or (connPIdr.GetString(1) = "SAP" And cboPIProbLvl.SelectedIndex = 0) _
- Or (connPIdr.GetString(1) = "TAP" And cboPIProbLvl.SelectedIndex = 0) Then
- MsgBox("The probation information is already in the database. Please try again.", MsgBoxStyle.Exclamation)
- Else
- Dim strProbLvl As String = ""
- Dim intProbIndex As Integer = cboPIProbLvl.SelectedIndex
- If intProbIndex = 0 Then
- strProbLvl = "FAP"
- ElseIf intProbIndex = 1 Then
- strProbLvl = "SAP"
- Else
- strProbLvl = "TAP"
- End If
- 'Change SQL statement
- connPIcmd.CommandText = "INSERT INTO Academic_Probation(Prob_Type, School_Year, Prob_Reason, Stud_Number) VALUES ('" _
- & strProbLvl & "','SY" & cboPISY.Text & cboPISem.Text & "Sem" & _
- "','" & txtPIReason.Text & "'," & Convert.ToInt32(txtPIStudNo.Text) & ")"
- connPIdr.Close()
- connPIcmd.ExecuteNonQuery()
- MsgBox("The database has been updated.", MsgBoxStyle.Information) 'Display info msg
- End If
- End If
- connPIdr.Close() 'Close reader
- End If
- 'Reset Insert GUI
- txtPIStudNo.Text = ""
- txtPILname.Text = ""
- txtPIFname.Text = ""
- txtPIMname.Text = ""
- cboPSCourse.SelectedItem = ""
- txtPIReason.Text = ""
- txtPIStudNo.Focus()
- cboPISY.SelectedIndex = 0
- cboPISem.SelectedIndex = 0
- cboPIYearLvl.SelectedIndex = 0
- cboPIProbLvl.SelectedIndex = 0
- Else
- MsgBox("Invalid student number. Please try again.", MsgBoxStyle.Exclamation) 'Displat error msg
- 'Reset txtPIStudNo
- txtPIStudNo.Text = ""
- txtPIStudNo.Focus()
- End If
- ElseIf msg = MsgBoxResult.No Then 'If No
- txtPIStudNo.Focus() 'set focus to txtPIStudNo
- End If
- Else
- MsgBox("Please fill in the required fields.", MsgBoxStyle.Exclamation) 'display error msg
- 'check which txtbox to set focus
- If txtPIStudNo.Text = "" Then
- txtPIStudNo.Focus()
- ElseIf txtPILname.Text = "" Then
- txtPILname.Focus()
- ElseIf txtPIFname.Text = "" Then
- txtPIFname.Focus()
- ElseIf txtPIMname.Text = "" Then
- txtPIMname.Focus()
- ElseIf cboPSCourse.SelectedItem = "" Then
- cboPSCourse.Focus()
- End If
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement