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`")
        fillcombo(ComboBox1, "GRADE", "STUDENTID")

        mySelectQuery("SELECT `STUDENTID`,`SECTION` FROM `tblstudents`")
        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(3).Value
        txtsem.Text = DGV.CurrentRow.Cells(4).Value
        txtunit.Text = DGV.CurrentRow.Cells(5).Value
        txtsched.Text = DGV.CurrentRow.Cells(6).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

  
End Class