0% found this document useful (0 votes)
28 views

Genman: Imports Public Class Dim As Dim As Dim As Private Sub As Object As Handles New With

This code defines a class called GenMan that connects to a MySQL database called class_scheduler. It contains methods for adding, editing, and deleting records from the scheduler table. When the add button is clicked, it inserts data from textboxes into the table. When the edit button is clicked, it updates an existing record based on the textbox values. When the delete button is clicked, it removes a record based on the ID. It also populates a dropdown from the subj41 table and displays the selected subject name in a textbox.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Genman: Imports Public Class Dim As Dim As Dim As Private Sub As Object As Handles New With

This code defines a class called GenMan that connects to a MySQL database called class_scheduler. It contains methods for adding, editing, and deleting records from the scheduler table. When the add button is clicked, it inserts data from textboxes into the table. When the edit button is clicked, it updates an existing record based on the textbox values. When the delete button is clicked, it removes a record based on the ID. It also populates a dropdown from the subj41 table and displays the selected subject name in a textbox.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Imports MySql.Data.

MySqlClient
Public Class GenMan
Dim MysqlConn As MySqlConnection
Dim Command As MySqlCommand
Dim RD As MySqlDataReader
Private Sub addx_Click(sender As Object, e As EventArgs) Handles addx.Click
MysqlConn = New MySqlConnection With {
.ConnectionString =
"server=localhost;userid=root;password=Obitus@85;database=class_scheduler"
}
Dim RD As MySqlDataReader

Try
MysqlConn.Open()

Dim que As String

que =
"INSERT INTO class_scheduler.scheduler
(Department,Section_Year,Section,Class_Subject,Subject_Type,Subject_Typenum,Professors_Na
me,Room,Start_Time,End_Time,Day_Name,Semester,School_Year)
VALUES('" + tdep.Text + "','" + tsecsy.Text + "','" + tsec.Text +
"','" + tsub.Text + "','" + tsubt.Text + "','" + tsubtn.Text + "','" + tprof.Text + "','"
+ trm.Text + "','" + tts.Text + "','" + tte.Text + "','" + tdy.Text + "','" + tsem.Text +
"','" + tsy.Text + "')"

Command = New MySqlCommand(que, MysqlConn)


RD = Command.ExecuteReader

MessageBox.Show("Data has been succesfully added.")

MysqlConn.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub

Private Sub GenSch_Load(sender As Object, e As EventArgs) Handles MyBase.Load


MysqlConn = New MySqlConnection With {.ConnectionString =
"server=localhost;userid=root;password=Obitus@85;database=class_scheduler"
}
Dim RD As MySqlDataReader

Try
MysqlConn.Open()

Dim query As String

query = "select * from class_scheduler.subj41"

Command = New MySqlCommand(query, MysqlConn)


RD = Command.ExecuteReader
While RD.Read
Dim Subj = RD.GetString("sub_name")
ComboBox1.Items.Add(Subj)
End While

MysqlConn.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub

Private Sub editx_Click(sender As Object, e As EventArgs) Handles editx.Click

sav.Visible = True

End Sub

Private Sub sav_Click(sender As Object, e As EventArgs) Handles sav.Click


MysqlConn = New MySqlConnection With {
.ConnectionString =
"server=localhost;userid=root;password=Obitus@85;database=class_scheduler"
}
Dim RD As MySqlDataReader

Try
MysqlConn.Open()

Dim edque As String

edque = "update class_scheduler.scheduler set idOSF='" & tid.Text &


"',Department='" & tdep.Text & "',Section_Year='" & tsecsy.Text & "',
Section='" & tsec.Text & "',Class_Subject='" & tsub.Text & "',Subject_Type='"
& tsubt.Text & "',Subject_Typenum='" & tsubtn.Text & "',
Professors_Name='" & tprof.Text & "',Room='" & trm.Text & "',Start_Time='" &
tts.Text & "',End_Time='" & tte.Text & "',Day_Name='" & tdy.Text & "'
,Semester='" & tsem.Text & "',School_Year='" & tsy.Text & "' where (idOSF='"
& tid.Text & "')"

Command = New MySqlCommand(edque, MysqlConn)


RD = Command.ExecuteReader

MessageBox.Show("Data has been succesfully modified.")

MysqlConn.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub

Private Sub dltx_Click(sender As Object, e As EventArgs) Handles dltx.Click


MysqlConn = New MySqlConnection With {
.ConnectionString =
"server=localhost;userid=root;password=Obitus@85;database=class_scheduler"
}
Dim RD As MySqlDataReader

Try
MysqlConn.Open()

Dim edque As String

edque = "delete from class_scheduler.scheduler where (idOSF='" & tid.Text &


"')"

Command = New MySqlCommand(edque, MysqlConn)


RD = Command.ExecuteReader

MessageBox.Show("Data has been succesfully deleted.")

MysqlConn.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Home.Show()
Me.Hide()

End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles


ComboBox1.SelectedIndexChanged
MysqlConn = New MySqlConnection With {.ConnectionString =
"server=localhost;userid=root;password=Obitus@85;database=class_scheduler"
}
Dim RD As MySqlDataReader

Try
MysqlConn.Open()

Dim query As String

query = "select * from class_scheduler.subj41 where sub_name = '" +


ComboBox1.Text + "'"

Command = New MySqlCommand(query, MysqlConn)


RD = Command.ExecuteReader
While RD.Read
tsub.Text = RD.GetString("sub_name")
End While

MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub

Private Sub Label10_Click(sender As Object, e As EventArgs) Handles Label10.Click

End Sub

Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles


tsubt.TextChanged

End Sub
End Class

You might also like