Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub btnCIInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCIInsert.Click
- If txtCIStudNo.Text = "" Or txtCILname.Text = "" Or txtCIFname.Text = "" Then
- MsgBox("Please fill in the required fields.", MsgBoxStyle.Exclamation)
- 'focus on the correct field
- If txtCIStudNo.Text = "" Then
- txtCIStudNo.Focus()
- ElseIf txtCIFname.Text = "" Then
- txtCIFname.Focus()
- ElseIf txtCILname.Text = "" Then
- txtCILname.Focus()
- End If
- Else
- 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 txtCIStudNo.TextLength = 7 Then
- Dim dteSession As String = dtpCIInsert.Value.Date
- Dim strLname As String = StrConv(txtCILname.Text, VbStrConv.ProperCase)
- Dim strFname As String = StrConv(txtCIFname.Text, VbStrConv.ProperCase)
- Dim intStudNo As Integer = Convert.ToInt32(txtCIStudNo.Text)
- 'Execute SQL statements
- Dim connCIcmd As New SqlCommand("SELECT Stud_Number FROM Student_Information WHERE Stud_Number = " _
- & intStudNo, connMain.Conn)
- Dim connCIdr As SqlDataReader = connCIcmd.ExecuteReader
- 'Check if student has record
- If connCIdr.HasRows = 0 Then
- MsgBox("The student doesn't exist in the database.", MsgBoxStyle.Exclamation)
- Else
- connCIcmd.CommandText = "SELECT Stud_Number, Coun_Date FROM Counseling WHERE Stud_Number = " _
- & intStudNo & " AND Coun_Date = '" & dteSession & "'"
- connCIdr.Close()
- Dim connCIdr2 As SqlDataReader = connCIcmd.ExecuteReader
- If connCIdr2.HasRows = 0 Then
- 'Change SQL statement
- connCIcmd.CommandText = "INSERT INTO Counseling(Coun_Lname, Coun_Fname, Coun_Date, Stud_Number)" _
- & "VALUES('" & strLname & "','" & strFname & "','" & dteSession & "'," _
- & intStudNo & ")"
- connCIdr2.Close() 'Close reader
- connCIcmd.ExecuteNonQuery()
- MsgBox("The database has been updated.", MsgBoxStyle.Information)
- calCSCalendar.Dates.Clear()
- calCSCalendar_Populate()
- 'reset fields
- txtCIStudNo.Text = ""
- txtCILname.Text = ""
- txtCIFname.Text = ""
- txtCIStudNo.Focus()
- Else
- MsgBox("The counseling information already exist.", MsgBoxStyle.Exclamation)
- End If
- End If
- Else
- MsgBox("Invalid student number. Please try again.", MsgBoxStyle.Exclamation) 'Displat error msg
- 'Reset txtPIStudNo
- txtCIStudNo.Text = ""
- txtCIStudNo.Focus()
- End If
- ElseIf msg = MsgBoxResult.No Then 'If No
- txtCIStudNo.Focus() 'set focus to txtPIStudNo
- End If
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement