⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.cls

📁 VB类实现学生信息管理系统
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "class"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Public class_no As Integer 'eg 0401 04年1班
Public Grade As String
Public director As String '对应username 班主任名
Public classroom As String '教室号
Public State As Integer
Public oper_flag As String

Public Function valid() As Boolean
 valid = True
 
 If Not isnumber(class_no) Then
 valid = False
 End If
 
End Function
Private Sub Class_Initialize()
  class_no = 0
  Grade = ""
  director = "admin" '缺省由admin托管
  classroom = ""
  State = 0
  oper_flag = ""
End Sub


Public Sub query()
  Dim SQLstmt As String    '存放SQL语句的字符串
  Dim msg_error As String
  Dim tmp_res As ADODB.Recordset
  
  If db.db_state > 0 Then
  
    SQLstmt = "select * FROM class_info " '执行SQL语句"
    Set tmp_res = db.ExecuteSQL(SQLstmt, msg_error)
    
    Me.State = 2 '假定没有班级存在
    
    
    If InStr(msg_error, "query_ok") > 0 Then 'have record
        While (tmp_res.EOF = False)
          If Trim(tmp_res.Fields("director")) = login_user.user_Id Or login_user.user_Id = "admin" Then '只有对应的班主任或是admin才能访问
              If Trim(tmp_res.Fields("class_no")) = Me.class_no Then 'exist same class_no
                     Me.State = 1 '有班级存在
                     Me.class_no = tmp_res.Fields("class_no")
                     Me.Grade = tmp_res.Fields("grade")
                     Me.director = tmp_res("director")
                     Me.classroom = tmp_res.Fields("classroom_no")
                     Exit Sub
              Else
                tmp_res.MoveNext
              End If
          Else '没有访问权限,退出
             Exit Sub
          End If
        Wend
    Else 'no record in database
    End If
   
 End If
 
     Set tmp_res = Nothing

End Sub

Public Sub delete()
  Dim SQLstmt As String    '存放SQL语句的字符串
  Dim msg_error As String
 
  If db.db_state > 0 Then
  
     SQLstmt = "DELETE FROM class_info  WHERE class_no=  " + CStr(Me.class_no)  '执行SQL语句
  
     Call db.ExecuteSQL(SQLstmt, msg_error)
    
     If InStr(msg_error, "delete_ok") > 0 Then
        Me.oper_flag = "delete ok"
     Else
        Me.oper_flag = "delete error"
     End If
    
  
  End If
End Sub

Public Sub update()
 Dim SQLstmt As String    '存放SQL语句的字符串
 Dim msg_error As String
 
  If db.db_state > 0 Then
  
     SQLstmt = "update class_info set grade= '" + CStr(Me.Grade) + "',classroom_no='" + CStr(Me.classroom) + "'" '执行SQL语句
     SQLstmt = SQLstmt + "where class_no=" + CStr(Me.class_no)
     Call db.ExecuteSQL(SQLstmt, msg_error)
    
     If InStr(msg_error, "update_ok") > 0 Then
        Me.oper_flag = "update ok"
     Else
        Me.oper_flag = "update error"
     End If
    
  
  End If
End Sub
Public Sub insert()
  Dim SQLstmt As String    '存放SQL语句的字符串
  Dim msg_error As String
  Dim tmp_res As ADODB.Recordset

If db.db_state > 0 Then '数据库是否打开
      query
       If Me.State = 2 Then 'unexisted,add it to database
          
          SQLstmt = "Insert Into class_info  Values(" & Me.class_no & ",'" & Me.Grade & "','" & login_user.user_Id & "','" & Me.classroom & "')"
          Call db.ExecuteSQL(SQLstmt, msg_error)
          
          If InStr(msg_error, "insert_ok") > 0 Then
             oper_flag = "insert_ok"
          Else
             oper_flag = "insert_error"
          End If
          
       End If
End If
 
  Set tmp_res = Nothing

End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -