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

📄 student.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 = "student"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Public student_Id As Long
Public student_Name As String
Public student_Sex As String
Public born_date As Date
Public class_no As Integer
Public tele_number As String
Public ru_date As Date
Public address As String
Public comment As String
Public State As String
Public oper_flag As String

Private Sub Class_Initialize()
  student_Id = 0
  student_Name = ""
  student_Sex = ""
  born_date = CDate("01-jan-00")
  class_no = 0
  tele_number = ""
  ru_date = CDate("01-jan-00")
  address = ""
  comment = ""
  State = 0 'init state
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 student_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("student_id")) = Me.student_Id Then
           Me.State = 1 '有用户存在
           Me.born_date = tmp_res.Fields("born_date")
           Me.address = tmp_res.Fields("address")
           Me.student_Name = tmp_res.Fields("student_name")
           Me.comment = tmp_res.Fields("comment")
           Me.ru_date = tmp_res.Fields("ru_date")
           Me.tele_number = tmp_res.Fields("tele_number")
           Me.student_Id = tmp_res.Fields("student_id")
           Exit Sub
        Else
           tmp_res.MoveNext
        End If
     Wend
  Else
  End If
  
End If
  
End Sub

'删除数据
Public Sub delete(ByVal TmpEmpId As Long)
  Dim SQLstmt As String    '存放SQL语句的字符串
  Dim msg_error As String

  If db.db_state > 0 Then
  
     SQLstmt = "DELETE FROM student_info  WHERE student_id=  " + CStr(Me.student_Id)  '执行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 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 student_info  Values(" & Me.student_Id & ",'" & Me.student_Name & "','" & Me.student_Sex & "','" & Me.born_date & "'," & Me.class_no & "," & Me.tele_number & ","
          SQLstmt = SQLstmt + "'" + CStr(Me.ru_date) + "','" + Me.address + "','" + Me.comment + "')"
          MsgBox SQLstmt
          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

Public Sub update() 'update all field of a record
  Dim SQLstmt As String    '存放SQL语句的字符串
 Dim msg_error As String
 
  If db.db_state > 0 Then
  
     SQLstmt = "update student_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


⌨️ 快捷键说明

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