VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsSection"
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 AddSection(ID As String, Lno As String, Sname As String)
If rs.State = adStateOpen Then rs.Close
msql = " Select * From Sections Where SectionNumber='" & ID & "'"
rs.Open msql, conn
If rs.RecordCount >= 1 Then
MsgBox "Duplicate ID.Please enter valid ID number.", vbCritical, ""
Exit Sub
End If
With rs
    .AddNew
    !SectionNumber = ID
    !LevelNumber = Lno
    !SectionName = Sname
    .Update
End With
MsgBox "New entry successfully saved to the record.", vbInformation
End Sub
Public Sub UpdateSection(ID As String, Lno As String, Sname As String, OldID As String)
If rs.State = adStateOpen Then rs.Close
msql = " Update Sections set SectionNumber='" & ID & "',LevelNumber='" & Lno & "',Sectionname='" & Sname & "' Where sectionnumber='" & OldID & "'"
rs.Open msql, conn
MsgBox "Record(s) Updated", vbInformation, ""
End Sub
Public Sub DeleteSection(ID As String)
If rs.State = adStateOpen Then rs.Close
msql = " Delete * From Sections Where SectionNumber='" & ID & "'"
rs.Open msql, conn
MsgBox "Record(s) Deleted", vbInformation, ""
End Sub
Public Sub DisplaySection(lstSection As ListView, SearchValue As String)
Dim lstItem As ListItem, a As Integer
If rs.State = adStateOpen Then rs.Close
If SearchValue <> "" Then
    msql = " SELECT Sections.SectionNumber, Sections.LevelNumber, Sections.SectionName" & _
           " From Sections" & _
           " Where Sections.SectionName like '" & SearchValue & "'" & _
           " GROUP BY Sections.SectionNumber, Sections.LevelNumber, Sections.SectionName" & _
           " ORDER BY Sections.SectionNumber;"

Else
        msql = " SELECT Sections.SectionNumber, Sections.LevelNumber, Sections.SectionName" & _
           " From Sections" & _
           " GROUP BY Sections.SectionNumber, Sections.LevelNumber, Sections.SectionName" & _
           " ORDER BY Sections.SectionNumber;"

   End If
   rs.Open msql, conn
   lstSection.ListItems.Clear
   Do While Not rs.EOF
    a = a + 1
        Set lstItem = lstSection.ListItems.Add(, , a)
            lstItem.SubItems(1) = rs(0).Value
            lstItem.SubItems(2) = rs(1).Value
            lstItem.SubItems(3) = rs(2).Value
            rs.MoveNext
            Loop
            


End Sub
Function GetID() As String
If rs.State = adStateOpen Then rs.Close
msql = " SELECT Max(Sections.SectionNumber) AS MaxOfSectionNumber" & _
" FROM Sections;"
rs.Open msql, conn
If IsNull(rs(0).Value) Then
GetID = Format(1, "00000")
Else
GetID = Format(rs(0).Value + 1, "00000")
End If

End Function
Public Sub DisplaySectionByYear(lstSection As ListView, sYear As Integer)
Dim lstItem As ListItem, a As Integer
If rs.State = adStateOpen Then rs.Close

    msql = " SELECT Sections.SectionNumber, Sections.LevelNumber, Sections.SectionName, Sections.MinAve, Sections.MaxAve, Sections.Allowed" & _
           " From Sections" & _
           " Where Sections.LevelNumber = " & sYear & "" & _
           " GROUP BY Sections.SectionNumber, Sections.LevelNumber, Sections.SectionName, Sections.MinAve, Sections.MaxAve, Sections.Allowed" & _
           " ORDER BY Sections.SectionNumber;"


   rs.Open msql, conn
   lstSection.ListItems.Clear
   Do While Not rs.EOF
    a = a + 1
        Set lstItem = lstSection.ListItems.Add(, , a)
            lstItem.SubItems(1) = rs(0).Value
            lstItem.SubItems(2) = rs(1).Value
            lstItem.SubItems(3) = rs(2).Value
            lstItem.SubItems(4) = rs(3).Value
            lstItem.SubItems(5) = rs(4).Value
            lstItem.SubItems(6) = rs(5).Value
            rs.MoveNext
            Loop
            


End Sub
