📄 train.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 = "Train"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'1 Tid Int 火车编号
'2 Tno Varchar 20 车次名称
'3 Sstation Varchar 40 始发站
'4 Estation Varchar 40 抵达站
'5 Stime Varchar 40 开车时间
'6 Etime Varchar 40 抵达时间
'7 PriceYz Decimal 7,2 硬座报价
'8 PriceRz Decimal 7,2 软座报价
'9 PriceYw Decimal 7,2 硬卧报价
'10 PriceRw Decimal 7,2 软卧报价
'11 Input_time Char 17 录入日期和时间
Public Tid As Long
Public Tno As String
Public Sstation As String
Public Estation As String
Public Stime As String
Public Etime As String
Public PriceYz As Single
Public PriceRz As Single
Public PriceYw As String
Public PriceRw As Single
Public Input_time As String
Public Sub Init()
Tid = 0
Tno = ""
Sstation = ""
Estation = ""
Stime = ""
Etime = ""
PriceYz = 0
PriceRz = 0
PriceYw = 0
PriceRw = 0
Input_time = ""
End Sub
Public Sub Delete(ByVal TmpTid As Long)
DB_Connect
SqlStmt = "DELETE FROM Train WHERE Tid=" + Trim(TmpTid)
OdbcExt (SqlStmt)
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
End Sub
Public Function GetInfo(ByVal TmpTid As Long) As Boolean
Tid = TmpTid
DB_Connect
SqlStmt = "SELECT * FROM Train WHERE Tid=" + Trim(TmpTid)
OdbcExt (SqlStmt)
If SQLFetch(Hstmt) = SQL_NO_DATA_FOUND Then
GetInfo = False
Init
Else
ColVal = String(400, 0)
Rc = SQLGetData(Hstmt, 2, 1, ColVal, Len(ColVal), pcblen)
Tno = TrimStr(ColVal)
ColVal = String(400, 0)
Rc = SQLGetData(Hstmt, 3, 1, ColVal, Len(ColVal), pcblen)
Sstation = TrimStr(ColVal)
ColVal = String(400, 0)
Rc = SQLGetData(Hstmt, 4, 1, ColVal, Len(ColVal), pcblen)
Estation = TrimStr(ColVal)
ColVal = String(400, 0)
Rc = SQLGetData(Hstmt, 5, 1, ColVal, Len(ColVal), pcblen)
Stime = TrimStr(ColVal)
ColVal = String(400, 0)
Rc = SQLGetData(Hstmt, 6, 1, ColVal, Len(ColVal), pcblen)
Etime = TrimStr(ColVal)
ColVal = String(40, 0)
Rc = SQLGetData(Hstmt, 7, 1, ColVal, Len(ColVal), pcblen)
PriceYz = Val(ColVal)
ColVal = String(40, 0)
Rc = SQLGetData(Hstmt, 8, 1, ColVal, Len(ColVal), pcblen)
PriceRz = Val(ColVal)
ColVal = String(4000, 0)
Rc = SQLGetData(Hstmt, 9, 1, ColVal, Len(ColVal), pcblen)
PriceYw = Val(ColVal)
ColVal = String(4000, 0)
Rc = SQLGetData(Hstmt, 10, 1, ColVal, Len(ColVal), pcblen)
PriceRw = Val(ColVal)
ColVal = String(40, 0)
Rc = SQLGetData(Hstmt, 11, 1, ColVal, Len(ColVal), pcblen)
Input_time = TrimStr(ColVal)
GetInfo = True
End If
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Function
Public Function GetId(ByVal TmpTno As String, _
ByVal TmpSstation As String, _
ByVal TmpEstation As String) As Long
DB_Connect
SqlStmt = "SELECT * FROM Train WHERE Tno='" + Trim(TmpTno) _
+ "' And Sstation='" + Trim(TmpSstation) _
+ "' And Estation='" + Trim(TmpEstation) + "'"
OdbcExt (SqlStmt)
If SQLFetch(Hstmt) <> SQL_NO_DATA_FOUND Then
ColVal = String(40, 0)
Rc = SQLGetData(Hstmt, 1, 1, ColVal, Len(ColVal), pcblen)
GetId = Val(ColVal)
Else
GetId = 0
End If
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Function
Public Function In_DB(ByVal TmTno As String, _
ByVal TmpSstation As String, _
ByVal TmpEstation As String) As Boolean
DB_Connect
SqlStmt = "SELECT * FROM Train WHERE Tno='" + Trim(TmTno) _
+ "' And Sstation='" + Trim(TmpSstation) _
+ "' And Estation='" + Trim(TmpEstation) + "'"
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()
dd = Date
dd = Format(dd, "yyyy-mm-dd")
t = Time
tt = Format(tt, "hh:mm")
DB_Connect
SqlStmt = "INSERT INTO Train (Tno, Sstation, Estation, Stime," _
+ " Etime, PriceYz, PriceRz, PriceYw, PriceRw, Input_time)" _
+ " VALUES('" + Trim(Tno) + "','" + Trim(Sstation) _
+ "','" + Trim(Estation) + "','" + Trim(Stime) _
+ "','" + Trim(Etime) + "'," + Trim(PriceYz) _
+ "," + Trim(PriceRz) + "," + Trim(PriceYw) _
+ "," + Trim(PriceRw) + ",'" + dd + " " + tt + "')"
OdbcExt (SqlStmt)
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Sub
Public Sub LoadTno(ByVal TmpSstation As String, _
ByVal TmpEstation As String)
Dim i As Integer
Erase ArrTno
ReDim ArrTno(0)
DB_Connect
SqlStmt = "SELECT Tno FROM Train WHERE Sstation='" _
+ Trim(TmpSstation) + "' And Estation='" _
+ Trim(TmpEstation) + "' ORDER BY Tno"
OdbcExt (SqlStmt)
i = 0
Do While SQLFetch(Hstmt) <> SQL_NO_DATA_FOUND
ColVal = String(400, 0)
Rc = SQLGetData(Hstmt, 1, 1, ColVal, Len(ColVal), pcblen)
ReDim Preserve ArrTno(i + 1)
ArrTno(i) = TrimStr(ColVal)
i = i + 1
Loop
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Sub
Public Sub Update(ByVal OriId As String)
dd = Date
dd = Format(dd, "yyyy-mm-dd")
t = Time
tt = Format(tt, "hh:mm")
DB_Connect
SqlStmt = "UPDATE Train SET Tno='" + Trim(Tno) _
+ "',Sstation='" + Trim(Sstation) + "',Estation='" _
+ Trim(Estation) + "', Stime='" + Trim(Stime) _
+ "', Etime='" + Trim(Etime) + "', PriceYz=" _
+ Trim(PriceYz) + ", PriceRz=" + Trim(PriceRz) _
+ ", PriceYw=" + Trim(PriceYw) + ", PriceRw=" _
+ Trim(PriceRw) + ", Input_time='" _
+ Trim(dd) + " " + Trim(tt) + "' WHERE Tid=" _
+ Trim(OriId)
OdbcExt (SqlStmt)
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -