VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsStudentSubjects"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Dim mrs As New ADODB.Recordset
Dim msql As String
Public Sub DisplayStudentSubjects(lstSubject As ListView, SearchCourse As String, SearchYearlevel As String, SearchSemester As String)
Dim lstItem As ListItem, a As Integer
If rs.State = adStateOpen Then rs.Close
If SearchCourse <> "" Then
    msql = " SELECT Subject.SubjectCode, Subject.SubjectName" & _
           " From Subject" & _
           " Where Subject.CourseName='" & SearchCourse & "' and Subject.YearLevel='" & SearchYearlevel & "' and Subject.Semester='" & SearchSemester & "'" & _
           " GROUP BY Subject.SubjectCode, Subject.SubjectName" & _
           " ORDER BY Subject.SubjectName;"
Else
    msql = " SELECT Subject.SubjectCode, Subject.SubjectName" & _
           " From Subject" & _
           " GROUP BY Subject.SubjectCode, Subject.SubjectName" & _
           " ORDER BY Subject.SubjectName;"
End If
 rs.Open msql, conn
   lstSubject.ListItems.Clear
   Do While Not rs.EOF
    a = a + 1
        Set lstItem = lstSubject.ListItems.Add(, , a)
            lstItem.SubItems(1) = rs(0).Value
            lstItem.SubItems(2) = rs(1).Value
            rs.MoveNext
            Loop
End Sub
Sub SaveStudentSubjects(lstSubjects As ListView, StudID As String, Course As String, Yearlevel As String, Semester As String, StudName As String)
 Dim a As Integer
        If rs.State = adStateOpen Then rs.Close
        msql = " Select * From StudentSubjects Where Subjects='" & lstSubjects.SelectedItem.ListSubItems(2) & "'"
        rs.Open msql, conn
        If rs.RecordCount >= 1 Then
        MsgBox "Error subject already taken.", vbCritical, ""
        Exit Sub
        End If
       
           ' For a = 1 To lstSubjects.ListItems.Count
            rs.AddNew
                rs!StudID = StudID
                rs!Course = Course
                rs!sYear = Yearlevel
                rs!Semester = Semester
                rs!Subjects = lstSubjects.SelectedItem.ListSubItems(2)
                rs!StudName = StudName
                'rs!Subjects = lstSubjects.ListItems(a).SubItems(2)
                'rs!Checked = lstSubjects.ListItems(a).Checked = True
                'rs!Checked = lstSubjects.SelectedItem.Checked = True
                rs.Update
      '  Next
      MsgBox " Record(s) updated.", vbInformation, ""
      'If rs.State = adStateOpen Then rs.Close
           ' msql = " Select * From StudentSubjects Where Subjects='" & lstSubjects.ListItems(a).SubItems(1) & "'"
           ' If rs.State = adStateOpen Then rs.Close
            'If rs.RecordCount >= 1 Then
            ' MsgBox "Error subject already taken.", vbInformation, ""
            '  Exit Sub
            '  End If
            ' rs.Open msql, conn
             ' rs.Open msql, conn
         '   If rs.State = adStateOpen Then rs.Close
         '   msql = " Select * From StudentSubjects"
         '   If rs.State = adStateOpen Then rs.Close
            '    rs.Open msql, conn
End Sub
Public Sub GetStudentSubjects(lstSubject As ListView, StudID As String)
Dim lstItem As ListItem, a As Integer
If rs.State = adStateOpen Then rs.Close
    msql = " SELECT StudentSubjects.Subjects" & _
           " From StudentSubjects" & _
           " Where  studid='" & StudID & "'" & _
           " GROUP BY StudentSubjects.Subjects" & _
           " ORDER BY StudentSubjects.Subjects;"
 rs.Open msql, conn
   lstSubject.ListItems.Clear
   Do While Not rs.EOF
    a = a + 1
        Set lstItem = lstSubject.ListItems.Add(, , a)
            lstItem.SubItems(1) = rs(0).Value
            'lstItem.SubItems(2) = rs(1).Value
            rs.MoveNext
            Loop
End Sub
Sub SaveStudentSubjectsToStudentGrade(lstSubjects As ListView, StudID As String, Course As String, Yearlevel As String, Semester As String, StudName As String)
 Dim a As Integer
        If rs.State = adStateOpen Then rs.Close
        msql = " Select * From StudentGrade Where Subjects='" & lstSubjects.SelectedItem.ListSubItems(2) & "'"
        rs.Open msql, conn
        If rs.RecordCount >= 1 Then
        'MsgBox "Error subject already taken.", vbCritical, ""
        Exit Sub
        End If
        rs.AddNew
                rs!StudID = StudID
                rs!Course = Course
                rs!sYear = Yearlevel
                rs!Semester = Semester
                rs!Subjects = lstSubjects.SelectedItem.ListSubItems(2)
                rs!Grade = 0
                rs!StudName = StudName
        rs.Update
End Sub

