Public Class tblschedule
    Dim SelectedUserId = 0
  

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

        myInsert("INSERT INTO `tblschedule`(`SUBJECT`, `AY`, `SEMESTER`, `UNIT`, `SCHEDULE`, `TIME`, `TEACHERID`, `GRADE` , `SECTION`) VALUES ( '" & txtsub.Text & "', '" & txtsy.Text & "','" & txtsem.Text & "', '" & txtunit.Text & "', '" & txtsched.Text & "', '" & cbtime.Text & "', '" & cbteachersname.SelectedValue & "', '" & ComboBox1.Text & "', '" & ComboBox2.Text & "')")
        mySelectQuery("SELECT s.`ID`, s.`SUBJECT`, s.`AY`, s.`SEMESTER`, s.`UNIT`, s.`SCHEDULE`, s.`TIME`, t.TEACHERSNAME, s.`GRADE`, s.`SECTION` FROM `tblschedule` s LEFT JOIN tblteachers t on s.`TEACHERID` = t.TEACHERSID")
        LoadData(DGV, "Sched")
      
        Checkresult("add")

    End Sub

    Private Sub tblschedule_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        mySelectQuery("SELECT s.`ID`, s.`SUBJECT`, s.`AY`, s.`SEMESTER`, s.`UNIT`, s.`SCHEDULE`, s.`TIME`, t.TEACHERSNAME, s.`GRADE`, s.`SECTION` FROM `tblschedule` s LEFT JOIN tblteachers t on s.`TEACHERID` = t.TEACHERSID")
        LoadData(DGV, "Sched")

        mySelectQuery("SELECT `TEACHERSID`, `TEACHERSNAME` FROM `tblteachers`")
        fillcombo(cbteachersname, "TEACHERSNAME", "TEACHERSID")

        mySelectQuery(" SELECT `STUDENTID`,`GRADE` FROM `tblstudents` GROUP BY `GRADE`")

        'mySelectQuery("SELECT `STUDENTID`,`GRADE` MAX(`STUDENTID`) FROM `tblstudents`")
        ' mySelectQuery("SELECT `GRADE` FROM `tblstudents` GROUP BY `GRADE` ORDER BY `GRADE` ASC")

        'mySelectQuery("SELECT `STUDENTID`,`GRADE` FROM `tblstudents`")
        fillcombo(ComboBox1, "GRADE", "STUDENTID")

        mySelectQuery("SELECT `STUDENTID`,`SECTION` FROM `tblstudents` GROUP BY `SECTION`")
        fillcombo(ComboBox2, "SECTION", "STUDENTID")

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        myUpdate("UPDATE `tblschedule` SET `ID`='" & SelectedUserId & "', `SUBJECT`='" & txtsub.Text & "',`AY`='" & txtsy.Text & "',`SEMESTER`='" & txtsem.Text & "',`UNIT`='" & txtunit.Text & "',`SCHEDULE`='" & txtsched.Text & "' WHERE `ID`=" & SelectedUserId)
        mySelectQuery("SELECT s.`ID`, s.`SUBJECT`, s.`AY`, s.`SEMESTER`, s.`UNIT`, s.`SCHEDULE`, s.`TIME`, t.TEACHERSNAME, s.`GRADE` , s.`SECTION` FROM `tblschedule` s LEFT JOIN tblteachers t on s.`TEACHERID` = t.TEACHERSID")
        LoadData(DGV, "Sched")
     
        Checkresult("Update")
    End Sub

   

    Private Sub DGV_CellClick1(sender As Object, e As DataGridViewCellEventArgs) Handles DGV.CellClick
        SelectedUserId = DGV.CurrentRow.Cells(0).Value
        txtsub.Text = DGV.CurrentRow.Cells(1).Value

        txtsy.Text = DGV.CurrentRow.Cells(2).Value
        txtsem.Text = DGV.CurrentRow.Cells(3).Value
        txtunit.Text = DGV.CurrentRow.Cells(4).Value
        txtsched.Text = DGV.CurrentRow.Cells(5).Value
        cbtime.Text = DGV.CurrentRow.Cells(6).Value
        cbteachersname.Text = DGV.CurrentRow.Cells(7).Value
        ComboBox1.Text = DGV.CurrentRow.Cells(8).Value
        ComboBox2.Text = DGV.CurrentRow.Cells(9).Value

    End Sub

   

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        myDelete("DELETE FROM `tblschedule` WHERE `ID`=" & SelectedUserId)
        mySelectQuery("SELECT s.`ID`, s.`SUBJECT`, s.`AY`, s.`SEMESTER`, s.`UNIT`, s.`SCHEDULE`, s.`TIME`, t.TEACHERSNAME, s.`GRADE`, s.`SECTION` FROM `tblschedule` s LEFT JOIN tblteachers t on s.`TEACHERID` = t.TEACHERSID")
        LoadData(DGV, "Sched")
       
    End Sub

  
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Me.Close()
    End Sub

    Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter

    End Sub

    Private Sub DGV_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DGV.CellContentClick

    End Sub
End Class