📄 lres.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 = "lres"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'1 lid Int 线路编号
'2 rid Int 餐厅编号
'3 rType Tinyint 用餐类型(0-早餐,1-正餐)
'4 rTimes Tinyint 用餐次数
Public lid As Long
Public rid As Long
Public rType As Integer
Public rTimes As Integer
Public Sub Init()
lid = 0
rid = 0
rType = 0
rTimes = 0
End Sub
'删除指定线路的所有用餐信息
Public Sub DeleteLine(ByVal Tmplid As Long)
DB_Connect
SqlStmt = "DELETE FROM lres WHERE lid=" + Trim(Tmplid)
OdbcExt (SqlStmt)
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
End Sub
'删除指定线路用餐信息
Public Sub Delete(ByVal Tmplid As Long, _
ByVal TmpRid As Long, _
ByVal TmpType As Integer)
DB_Connect
SqlStmt = "DELETE FROM lres WHERE lid=" + Trim(Tmplid) _
+ " And rid=" + Trim(TmpRid) + " And rType=" _
+ Trim(TmpType)
OdbcExt (SqlStmt)
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
End Sub
Public Function In_DB(ByVal Tmplid As Long, _
ByVal TmpRid As Long, _
ByVal TmpType As Integer) As Boolean
DB_Connect
SqlStmt = "SELECT * FROM lres WHERE lid=" + Trim(Tmplid) _
+ " And rid=" + Trim(TmpRid) + " And rType=" _
+ Trim(TmpType)
OdbcExt (SqlStmt)
If SQLFetch(Hstmt) <> SQL_NO_DATA_FOUND Then
In_DB = True
Else
In_DB = False
End If
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Function
Public Sub Insert()
DB_Connect
SqlStmt = "INSERT INTO lres VALUES(" + Trim(lid) + "," _
+ Trim(rid) + "," + Trim(rType) + "," + Trim(rTimes) + ")"
OdbcExt (SqlStmt)
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Sub
'判断指定的餐厅信息是否在线路中
Public Function ResInLine(ByVal TmpRid As Long) As Long
DB_Connect
SqlStmt = "SELECT lid FROM lres WHERE rid=" _
+ Trim(TmpRid)
OdbcExt (SqlStmt)
If SQLFetch(Hstmt) <> SQL_NO_DATA_FOUND Then
ColVal = String(400, 0)
Rc = SQLGetData(Hstmt, 1, 1, ColVal, Len(ColVal), pcblen)
ResInLine = Val(ColVal)
Else
ResInLine = 0
End If
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Function
Public Function SumPrice(ByVal Tmplid As Long) As Single
SumPrice = SumPrice1(Tmplid) + SumPrice2(Tmplid)
End Function
Public Function SumPrice1(ByVal Tmplid As Long) As Single
DB_Connect
SqlStmt = "SELECT Sum(r.Breakfast*l.rtimes) FROM lres l, Restaurant r" _
+ " WHERE l.lid=" + Trim(Tmplid) + " And l.rid=r.rid And l.rType=1"
OdbcExt (SqlStmt)
If SQLFetch(Hstmt) = SQL_NO_DATA_FOUND Then
SumPrice1 = 0
Else
ColVal = String(40, 0)
Rc = SQLGetData(Hstmt, 1, 1, ColVal, Len(ColVal), pcblen)
SumPrice1 = Val(ColVal)
End If
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Function
Public Function SumPrice2(ByVal Tmplid As Long) As Single
DB_Connect
SqlStmt = "SELECT Sum(r.Dinner*l.rtimes) FROM lres l, Restaurant r" _
+ " WHERE l.lid=" + Trim(Tmplid) + " And l.rid=r.rid And l.rType=2"
OdbcExt (SqlStmt)
If SQLFetch(Hstmt) = SQL_NO_DATA_FOUND Then
SumPrice2 = 0
Else
ColVal = String(40, 0)
Rc = SQLGetData(Hstmt, 1, 1, ColVal, Len(ColVal), pcblen)
SumPrice2 = Val(ColVal)
End If
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Function
Public Sub Update(ByVal Orilid As Long, _
ByVal Oririd As Long, _
ByVal OriType As Long)
DB_Connect
SqlStmt = "UPDATE lres SET rid=" + Trim(rid) _
+ ", rType=" + Trim(rType) + ", rTimes=" _
+ Trim(rTimes) + " WHERE lid=" + Trim(Orilid) _
+ " And rid=" + Trim(Oririd) + " And rType=" _
+ Trim(OriType)
OdbcExt (SqlStmt)
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -