📄 papers.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 = "Papers"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Public PaperId As Integer '试卷号INT
Public PaperName As String '试卷名 50
Public UserName As String '创建者 15
Public Header As String '标题 50
Public Describe As String '备注 100
Public Classname As String '20
Public Sub Init()
PaperId = -1
PaperName = ""
UserName = ""
Header = ""
Describe = ""
Classname = ""
End Sub
'删除
Public Sub Delete(ByVal TmpId As Long)
DB_Connect
SqlStmt = "DELETE FROM Papers WHERE PaperId=" + Trim(Str(TmpId))
OdbcExt (SqlStmt)
rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Sub
Public Sub GetInfo(ByVal TmpId As Long)
PaperId = TmpId
DB_Connect
SqlStmt = "SELECT * FROM Papers WHERE PaperId=" + Trim(Str(TmpId))
OdbcExt (SqlStmt)
If SQLFetch(Hstmt) <> SQL_NO_DATA_FOUND Then
'读取试卷名称
ColVal = String(400, 0)
rc = SQLGetData(Hstmt, 2, 1, ColVal, Len(ColVal), pcblen)
PaperName = TrimStr(ColVal)
'读取试卷创建者名
ColVal = String(400, 0)
rc = SQLGetData(Hstmt, 3, 1, ColVal, Len(ColVal), pcblen)
UserName = TrimStr(ColVal)
'读取试卷标题
ColVal = String(400, 0)
rc = SQLGetData(Hstmt, 4, 1, ColVal, Len(ColVal), pcblen)
Header = TrimStr(ColVal)
'读取试卷描述
ColVal = String(400, 0)
rc = SQLGetData(Hstmt, 5, 1, ColVal, Len(ColVal), pcblen)
Describe = TrimStr(ColVal)
'读取所属课程
ColVal = String(400, 0)
rc = SQLGetData(Hstmt, 6, 1, ColVal, Len(ColVal), pcblen)
Classname = TrimStr(ColVal)
Else
Init
End If
rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Sub
Public Function GetNewId() As Long
Dim TmpId As Long
'连接数据库
DB_Connect
'设置要执行的SQL语句
SqlStmt = "SELECT PaperId FROM Papers ORDER BY PaperId"
'执行SQL语句
OdbcExt (SqlStmt)
'读取SELECT语句返回的查询结果
i = 1
Do While SQLFetch(Hstmt) <> SQL_NO_DATA_FOUND
ColVal = String(40, 0)
rc = SQLGetData(Hstmt, 1, 1, ColVal, Len(ColVal), pcblen)
TmpId = Val(ColVal)
If TmpId = i Then
i = i + 1
Else
GetNewId = i
rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
Exit Function
End If
Loop
rc = SQLFreeStmt(Hstmt, SQL_DROP)
'断开与数据库的连接
DB_Disconnect
'将得到的新编号作为函数的返回值
GetNewId = i
End Function
Public Function Insert() As Long
Dim PaperId As Long
'生成新的编号
PaperId = GetNewId
DB_Connect
SqlStmt = "INSERT INTO Papers VALUES('" + Trim(Str(PaperId)) + "','" _
+ Trim(PaperName) + "','" + Trim(UserName) _
+ "','" + Trim(Header) + "','" _
+ Trim(Describe) _
+ "','" + Trim(Classname) + "')"
OdbcExt (SqlStmt)
rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
Insert = ClassId
End Function
'更新数据
Public Sub Update(ByVal TmpId As Long)
DB_Connect
SqlStmt = "UPDATE Papers SET PaperName='" + Trim(PaperName) _
+ "',UserName='" + Trim(UserName) _
+ "',Header='" + Trim(Header) _
+ "',Describe='" + Trim(Describe) _
+ "' WHERE PaperId=" + Trim(Str(TmpId))
OdbcExt (SqlStmt)
rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -