Initial commit

This commit is contained in:
Rumperuu 2014-01-15 16:18:42 +00:00
commit c42d5896ea
39 changed files with 6278 additions and 0 deletions

View file

@ -0,0 +1,145 @@
Imports MySql.Data.MySqlClient
Public Class frmAddStudent
'Declares the variable used for generating the username of the new student
Dim Uname As String
'Declares the variable used for getting the image of the new student
Dim Filepath As String
'Subroutine runs when the form loads
Private Sub frmAddStudent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Establishes the connection to the database
OpenDB()
'Indicates that no picture has been selected
picPic.Tag = 0
End Sub
'Subroutine runs when the student first name text box is clicked
Private Sub txtStudentFirstName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtStudentFirstName.Click
'Blanks out the text box
txtStudentFirstName.Text = ""
End Sub
'Subroutine runs when the student last name text box is clicked
Private Sub txtStudentLastName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtStudentLastName.Click
'Blanks out the text box
txtStudentLastName.Text = ""
End Sub
'Subroutine runs when the add student button is clicked
Private Sub btnAddStudent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddStudent.Click
'Declares the variable used for getting the result of the message box
Dim Result As MsgBoxResult
'Declares the variable used for detecting invalid data entry
Dim Errors As String = ""
'Assembles an error report if any invalid data entry detected
If txtStudentFirstName.Text = "" Then
Errors = Errors & "No first name input" & vbCrLf
End If
If txtStudentLastName.Text = "" Then
Errors = Errors & "No last name input" & vbCrLf
End If
If cmboYear.Text = "" Then
Errors = Errors & "No year selected" & vbCrLf
End If
If cmboForm.Text = "" Then
Errors = Errors & "No form selected" & vbCrLf
End If
If picPic.Tag = 0 Then
Errors = Errors & "No picture input" & vbCrLf
End If
Dim sql As String
Dim dbcomm As MySqlCommand
Dim dbread As MySqlDataReader
'If no invalid data entry is detected...
If Errors = "" Then
'Runs the username generation subroutine
Username()
'Displays a validation message box before saving the data to the database
Result = MsgBox("Are you sure all these details are correct? Remember, spelling is vital." & vbCrLf & vbCrLf & "Details:" & vbCrLf & txtStudentFirstName.Text & " " & txtStudentLastName.Text & vbCrLf & cmboYear.SelectedItem & cmboForm.SelectedItem, MsgBoxStyle.YesNo)
'If the data is approved by the user...
If Result = MsgBoxResult.Yes Then
'Builds SQL query to execute
sql = "INSERT INTO `cl51-ben`.`tblstudents` (`Fname`, `Lname`, `Username`, `Password`, `FormNum`, `FormLetter`) VALUES ('" & txtStudentFirstName.Text & "', '" & txtStudentLastName.Text & "', '" & Uname & "', 'password', '" & cmboYear.SelectedItem & "', '" & cmboForm.SelectedItem & "');"
dbcomm = New MySqlCommand(sql, DBConn)
dbread = dbcomm.ExecuteReader()
dbread.Close()
'Creates the wins and losses text file for the student
Dim file As System.IO.FileStream
file = System.IO.File.Create(Uname & ".txt")
'Copies the image to the folder for student images and renames it to the new student's username
My.Computer.FileSystem.CopyFile(Filepath, Uname & ".jpg", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
End If
'If any invalid data entry is detected...
Else
'Displays a message box with any detected invalid data entry
MsgBox("Invalid input:" & vbCrLf & vbCrLf & Errors)
End If
End Sub
'Subroutine runs when called in the add teacher button sub
Sub Username()
'Declares the variable used to get the first letter of the new teacher's first name
Dim L1 As String = Mid(txtStudentFirstName.Text, 1, 1)
'Declares the variable used to get the first letter of the new teacher's last name
Dim L2 As String = Mid(txtStudentLastName.Text, 1, 1)
'Declares the variable used to get the numbers at the end of the new teacher's username
Dim Numbers As Integer = 11
Dim sql As String
Dim dbcomm As MySqlCommand
Dim dbread As MySqlDataReader
'Assembles the beginning and middle of the username
Uname = "95" & L1 & L2
'Builds SQL query to execute
sql = "SELECT * FROM tblstudents WHERE Username='" & Uname & Numbers & "'"
dbcomm = New MySqlCommand(sql, DBConn)
dbread = dbcomm.ExecuteReader()
'Fills the various properties of the LoggedInStudent object with their respective values from the database
While dbread.Read
dbread.Close()
'Increases the numbers on the end of the username
Numbers = Numbers + 1
'Opens a new recordset to check if the new username isn't taken
sql = "SELECT * FROM tblstudents WHERE Username='" & Uname & Numbers & "'"
dbcomm = New MySqlCommand(sql, DBConn)
dbread = dbcomm.ExecuteReader()
End While
dbread.Close()
'Assembles the username
Uname = Uname & Numbers
End Sub
'Subroutine runs when the browse pic button is clicked
Private Sub btnBrowsePic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowsePic.Click
'Sets the filter of the browse window to only allow image files
diaPic.Filter = "Image Files|*.jpg;*.gif;*.bmp;*.png;*.jpeg|All Files|*.*"
'Sets the starting directory of the browse window to the C: drive
diaPic.InitialDirectory = "C:\"
'Sets the filter index of the browse window
diaPic.FilterIndex = 1
'Sets the title of the browse window
diaPic.Title = "Open File"
'If okay button of browse window is clicked...
If (diaPic.ShowDialog() = Windows.Forms.DialogResult.OK) Then
'Sets filepath to image
Filepath = diaPic.FileName
'Sets displayed image to selected image file
picPic.Image = Image.FromFile(Filepath)
'Sets picture box tag to indicate that a picture has been selected
picPic.Tag = 1
End If
End Sub
End Class

View file

@ -0,0 +1,57 @@
Imports MySql.Data.MySqlClient
Public Class frmAddSubject
'Subroutine runs when the form loads
Private Sub frmAddSubject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Establishes the connection to the database
OpenDB()
End Sub
'Subroutine runs when the add subject button is clicked
Private Sub btnAddSubject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSubject.Click
'Declares the variable used for detecting invalid data entry
Dim Errors As String = ""
'Declares the variable used for getting the result of the message box
Dim Result As MsgBoxResult
Dim sql As String
Dim dbcomm As MySqlCommand
Dim dbread As MySqlDataReader
'Assembles an error report if any invalid data entry detected
If txtSubjectName.Text = "" Then
Errors = Errors & "No subject name input" & vbCrLf
End If
'If no invalid data entry is detected...
If Errors = "" Then
'Displays a validation message box before saving the data to the database
Result = MsgBox("Are you sure all these details are correct? Remember, spelling is vital." & vbCrLf & vbCrLf & "Details:" & vbCrLf & txtSubjectName.Text, MsgBoxStyle.YesNo)
'If the data is approved by the user...
If Result = MsgBoxResult.Yes Then
'Builds SQL query to execute
sql = "INSERT INTO `cl51-ben`.`tblsubjects` (`Subject`) VALUES ('" & txtSubjectName.Text & "');"
dbcomm = New MySqlCommand(sql, DBConn)
dbread = dbcomm.ExecuteReader()
dbread.Close()
'Creates the topics text file for the subject
Dim file As System.IO.FileStream
file = System.IO.File.Create(txtSubjectName.Text & "Topics.txt")
file.Close()
End If
'If any invalid data entry is detected...
Else
'Displays a message box with any detected invalid data entry
MsgBox("Invalid input:" & vbCrLf & vbCrLf & Errors)
End If
End Sub
'Subroutine runs when the subject name text box is clicked
Private Sub txtSubjectName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSubjectName.Click
'Blanks out the text box
txtSubjectName.Text = ""
End Sub
End Class

View file

@ -0,0 +1,139 @@
Imports MySql.Data.MySqlClient
Public Class frmAddTeacher
'Declares the variable used for generating the username of the new student
Dim Uname As String
'Declares the variable used for getting the image of the new student
Dim Filepath As String
'Subroutine runs when the form loads
Private Sub frmAddTeacher_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Establishes the connection to the database
OpenDB()
'Indicates that no picture has been selected
picPic.Tag = 0
End Sub
'Subroutine runs when the teacher first name text box is clicked
Private Sub txtTeacherFirstName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTeacherFirstName.Click
'Blanks out the text box
txtTeacherFirstName.Text = ""
End Sub
'Subroutine runs when the teacher last name text box is clicked
Private Sub txtTeacherLastName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTeacherLastName.Click
'Blanks out the text box
txtTeacherLastName.Text = ""
End Sub
'Subroutine runs when the add teacher button is clicked
Private Sub btnAddTeacher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTeacher.Click
'Declares the variable used for getting the result of the message box
Dim Result As MsgBoxResult
'Declares the variable used for detecting invalid data entry
Dim Errors As String = ""
'Assembles an error report if any invalid data entry detected
If txtTeacherFirstName.Text = "" Then
Errors = Errors & "No first name input" & vbCrLf
End If
If txtTeacherLastName.Text = "" Then
Errors = Errors & "No last name input" & vbCrLf
End If
If picPic.Tag = 0 Then
Errors = Errors & "No picture input" & vbCrLf
End If
Dim sql As String
Dim dbcomm As MySqlCommand
Dim dbread As MySqlDataReader
'If no invalid data entry is detected...
If Errors = "" Then
'Runs the username generation subroutine
Username()
'Displays a validation message box before saving the data to the database
Result = MsgBox("Are you sure all these details are correct? Remember, spelling is vital." & vbCrLf & vbCrLf & "Details:" & vbCrLf & txtTeacherFirstName.Text & " " & txtTeacherLastName.Text, MsgBoxStyle.YesNo)
'If the data is approved by the user...
If Result = MsgBoxResult.Yes Then
'Builds SQL query to execute
sql = "INSERT INTO `cl51-ben`.`tblteachers` (`Fname`, `Lname`, `Username`, `Password`) VALUES ('" & txtTeacherFirstName.Text & "', '" & txtTeacherLastName.Text & "', '" & Uname & "', 'password');"
dbcomm = New MySqlCommand(sql, DBConn)
dbread = dbcomm.ExecuteReader()
dbread.Close()
'Creates the question creation text file for the teacher
Dim file As System.IO.FileStream
file = System.IO.File.Create(Uname & ".txt")
'Copies the image to the folder for student images and renames it to the new student's username
My.Computer.FileSystem.CopyFile(Filepath, Uname & ".jpg", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
End If
'If any invalid data entry is detected...
Else
'Displays a message box with any detected invalid data entry
MsgBox("Invalid input:" & vbCrLf & vbCrLf & Errors)
End If
End Sub
'Subroutine runs when called in the add teacher button sub
Sub Username()
'Declares the variable used to get the first letter of the new teacher's first name
Dim L1 As String = Mid(txtTeacherFirstName.Text, 1, 1)
'Declares the variable used to get the first letter of the new teacher's last name
Dim L2 As String = Mid(txtTeacherLastName.Text, 1, 1)
'Declares the variable used to get the numbers at the end of the new teacher's username
Dim Numbers As Integer = 11
Dim sql As String
Dim dbcomm As MySqlCommand
Dim dbread As MySqlDataReader
'Assembles the beginning and middle of the username
Uname = "st" & L1 & L2
'Builds SQL query to execute
sql = "SELECT * FROM tblteachers WHERE Username='" & Uname & Numbers & "'"
dbcomm = New MySqlCommand(sql, DBConn)
dbread = dbcomm.ExecuteReader()
'Fills the various properties of the LoggedInStudent object with their respective values from the database
While dbread.Read
dbread.Close()
'Increases the numbers on the end of the username
Numbers = Numbers + 1
'Opens a new recordset to check if the new username isn't taken
sql = "SELECT * FROM tblteachers WHERE Username='" & Uname & Numbers & "'"
dbcomm = New MySqlCommand(sql, DBConn)
dbread = dbcomm.ExecuteReader()
End While
dbread.Close()
'Assembles the username
Uname = Uname & Numbers
End Sub
'Subroutine runs when the browse pic button is clicked
Private Sub btnBrowsePic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowsePic.Click
'Sets the filter of the browse window to only allow image files
diaPic.Filter = "Image Files|*.jpg;*.gif;*.bmp;*.png;*.jpeg|All Files|*.*"
'Sets the starting directory of the browse window to the C: drive
diaPic.InitialDirectory = "C:\"
'Sets the filter index of the browse window
diaPic.FilterIndex = 1
'Sets the title of the browse window
diaPic.Title = "Open File"
'If okay button of browse window is clicked...
If (diaPic.ShowDialog() = Windows.Forms.DialogResult.OK) Then
'Sets filepath to image
Filepath = diaPic.FileName
'Sets displayed image to selected image file
picPic.Image = Image.FromFile(Filepath)
'Sets picture box tag to indicate that a picture has been selected
picPic.Tag = 1
End If
End Sub
End Class

View file

@ -0,0 +1,79 @@
Imports MySql.Data.MySqlClient
Public Class frmAddTopic
'Subroutine runs when the form loads
Private Sub frmAddTopic_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Establishes the connection to the database
OpenDB()
'Runs the form population subroutine
Populate()
End Sub
'Subroutine runs when the add topic button is clicked
Private Sub btnAddTopic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTopic.Click
'Runs the form population subroutine
CheckValid()
End Sub
'Subroutine runs when called in the form load sub
Sub Populate()
Dim sql As String
Dim dbcomm As MySqlCommand
Dim dbread As MySqlDataReader
'Builds SQL query to execute
sql = "SELECT * FROM tblsubjects"
dbcomm = New MySqlCommand(sql, DBConn)
dbread = dbcomm.ExecuteReader()
'Fills the various properties of the LoggedInStudent object with their respective values from the database
While dbread.Read
'Populates the subject combobox with data
cmboSubject.Items.Add(dbread("Subject"))
End While
dbread.Close()
End Sub
'Subroutine runs when called in the add topic button sub
Sub CheckValid()
'Declares the variable used for getting the result of the message box
Dim Result As MsgBoxResult
'Declares the variable used for detecting invalid data entry
Dim Errors As String = ""
'Assembles an error report if any invalid data entry detected
If cmboSubject.Text = "" Then
Errors = Errors & "No subject selected" & vbCrLf
End If
If cmboYear.Text = "" Then
Errors = Errors & "No year selected" & vbCrLf
End If
If txtTopic.Text = "" Then
Errors = Errors & "No topic input" & vbCrLf
End If
'If no invalid data entry is detected...
If Errors = "" Then
'Displays a validation message box before saving the data to the database
Result = MsgBox("Are you sure all these details are correct? Remember, spelling is vital." & vbCrLf & vbCrLf & "Details:" & vbCrLf & cmboSubject.SelectedItem & " (" & cmboYear.SelectedItem & ")" & vbCrLf & txtTopic.Text, MsgBoxStyle.YesNo)
'If the data is approved by the user...
If Result = MsgBoxResult.Yes Then
'Declares the variable used for writing to the text file
Dim writer As System.IO.StreamWriter
'Gets the filepath to the selected subject's topic text file, creating it if it doesn't exist
writer = My.Computer.FileSystem.OpenTextFileWriter(cmboSubject.Text & "Topics.txt", True)
'Adds the new topic to the selected subject's topics text file
writer.WriteLine(txtTopic.Text & " (" & cmboYear.Text & ")")
'Saves the text file
writer.Close()
End If
'If any invalid data entry is detected...
Else
'Displays a message box with any detected invalid data entry
MsgBox("Invalid input:" & vbCrLf & vbCrLf & Errors)
End If
End Sub
End Class

View file

@ -0,0 +1,26 @@
Public Class frmFTSMsg
'Subroutine runs when the yes button is clicked
Private Sub btnYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYes.Click
'Closes the login form
frmLogin.Close()
'Opens the first-time setup form
frmFirstTimeSetup.Show()
'Closes this form
Me.Close()
End Sub
'Subroutine runs when the no button is clicked
Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click
'Declares the variable used for writing to the text file
Dim writer As System.IO.StreamWriter
'Gets the filepath to the first-time setup text file
writer = My.Computer.FileSystem.OpenTextFileWriter("FTS.txt", False)
'Amends the text file to indicate that the first-time setup has been run
writer.WriteLine("1")
'Saves the log file
writer.Close()
'Closes this form
Me.Close()
End Sub
End Class

View file

@ -0,0 +1,44 @@
Public Class frmFirstTimeSetup
'Subroutine runs when the add subject button is clicked
Private Sub btnAddSubject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSubject.Click
'Opens the add subject form
frmAddSubject.Show()
End Sub
'Subroutine runs when the add topic button is clicked
Private Sub btnAddTopic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTopic.Click
'Opens the add topic form
frmAddTopic.Show()
End Sub
'Subroutine runs when the add teacher button is clicked
Private Sub btnAddTeacher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTeacher.Click
'Opens the add teacher form
frmAddTeacher.Show()
End Sub
'Subroutine runs when the add student button is clicked
Private Sub btnAddStudent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddStudent.Click
'Opens the add student form
frmAddStudent.Show()
End Sub
'Subroutine runs when the done button is clicked
Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
'Declares the variable used for writing to the text file
Dim writer As System.IO.StreamWriter
'Gets the filepath to the first-time setup text file
writer = My.Computer.FileSystem.OpenTextFileWriter("FTS.txt", False)
'Amends the text file to indicate that the first-time setup has been run
writer.WriteLine("1")
'Saves the log file
writer.Close()
'Opens the login form
frmLogin.Show()
'Closes this form
Me.Close()
End Sub
End Class