home *** CD-ROM | disk | FTP | other *** search
/ Mastering Web Site Development / Microsoft Mastering Web Site Development (Microsoft) (1997).iso / Labs / Lab09 / drop.cls < prev    next >
Encoding:
Visual Basic class definition  |  1997-04-24  |  2.0 KB  |  75 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Obj"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Const MAXCLASSES = 6
  11. Function ClassCompleted(conn As ADODB.Connection, lngStudentID As Long, strClassID As String) As Boolean
  12.     Dim rsEnrollment As Object
  13.     Dim strSQL As String
  14.     
  15.     'Student cannot drop a class if the class is completed
  16.     'In other words, it has a grade
  17.     strSQL = "select classid,studentid,grade from enrollment where studentid = " & lngStudentID & " AND classid ='" & strClassID & "'"
  18.     Set rsEnrollment = conn.Execute(strSQL)
  19.     
  20.     'Check for no records even existing
  21.     If rsEnrollment.BOF And rsEnrollment.EOF Then
  22.        ClassCompleted = False
  23.        Exit Function
  24.     End If
  25.     
  26.     'Check for a non-null grade
  27.     If Not IsNull(rsEnrollment.Fields("Grade")) Then
  28.         ClassCompleted = True
  29.     Else
  30.         ClassCompleted = False
  31.     End If
  32.     rsEnrollment.Close
  33. End Function
  34. Public Function Drop(ByVal lngStudentID As Long, ByVal strClassID As String) As Integer
  35.     Dim ctxObject As ObjectContext
  36.     Dim conn As ADODB.Connection
  37.     Dim strSQL As String
  38.     
  39.     On Error GoTo ErrorHandler
  40.  
  41.     ' Get the Context Object
  42.  
  43.     Set conn = CreateObject("ADODB.connection")
  44.  
  45.     'Open connection with State University Database
  46.     conn.Open "DSN=StateU;UID=sa;PWD=;"
  47.  
  48.     'Check business rule
  49.     'Make sure class isn't already completed
  50.     'In which case student cannot drop
  51.     If ClassCompleted(conn, lngStudentID, strClassID) Then
  52.         Drop = 1
  53.  
  54.         Exit Function
  55.     End If
  56.  
  57.     'Perform the work of dropping the student from the class
  58.     strSQL = "DELETE FROM enrollment where ClassID ='" & strClassID & "' AND Studentid =" & lngStudentID
  59.     conn.Execute strSQL
  60.  
  61.     'Close the connection
  62.     conn.Close
  63.  
  64.     'Work completed Successfully
  65.  
  66.     Exit Function
  67.  
  68. ErrorHandler:
  69.     Drop = 1
  70.     'Abort if any errors occurred
  71.  
  72.  
  73. End Function
  74.  
  75.