?? product.cls
字號(hào):
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "Product"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'1 ProId Int 產(chǎn)品編號(hào)
'2 ProName Varchar 50 產(chǎn)品名稱
'4 ProStyle Varchar 50 產(chǎn)品規(guī)格
'5 ProUnit Varchar 10 計(jì)量單位
'6 ProPrice Decimal 15,2 參考價(jià)格
Public ProId As Long
Public ProName As String
Public ProStyle As String
Public ProUnit As String
Public ProPrice As Single
Public Sub Init()
ProId = 0
ProName = ""
ProStyle = ""
ProUnit = ""
ProPrice = 0
End Sub
'刪除Product數(shù)據(jù)
Public Sub Delete(ByVal TmpProId As Long)
DB_Connect
SqlStmt = "Delete FROM Product "
OdbcExt (SqlStmt)
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Sub
Public Function GetName(ByVal TmpProId As Long) As String
If TmpProId <= 0 Then
GetName = ""
Exit Function
End If
DB_Connect
SqlStmt = "SELECT ProName FROM Product WHERE ProId=" + Trim(Str(TmpProId))
OdbcExt (SqlStmt)
If SQLFetch(Hstmt) = SQL_NO_DATA_FOUND Then
GetName = ""
Exit Function
Else
ColVal = String(100, 0)
Rc = SQLGetData(Hstmt, 1, 1, ColVal, Lench(ColVal), pcblench)
GetName = TrimStr(ColVal)
End If
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Function
Public Function GetId(ByVal TmpName As String) As Long
If TmpName = "" Then
GetId = 0
Exit Function
End If
DB_Connect
SqlStmt = "SELECT ProId FROM Product WHERE ProName='" _
+ Trim(TmpName) + "'"
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 GetInfo(ByVal TmpProId As Long) As Boolean
If TmpProId <= 0 Then
Init
GetInfo = False
Exit Function
End If
ProId = TmpProId
DB_Connect
SqlStmt = "SELECT * FROM Product WHERE ProId=" + Trim(Str(TmpProId))
OdbcExt (SqlStmt)
If SQLFetch(Hstmt) = SQL_NO_DATA_FOUND Then
GetInfo = False
Exit Function
Else
ColVal = String(400, 0)
Rc = SQLGetData(Hstmt, 2, 1, ColVal, Lench(ColVal), pcblench)
ProName = TrimStr(ColVal)
ColVal = String(400, 0)
Rc = SQLGetData(Hstmt, 4, 1, ColVal, Lench(ColVal), pcblench)
ProStyle = TrimStr(ColVal)
ColVal = String(400, 0)
Rc = SQLGetData(Hstmt, 5, 1, ColVal, Lench(ColVal), pcblench)
ProUnit = TrimStr(ColVal)
ColVal = String(40, 0)
Rc = SQLGetData(Hstmt, 6, 1, ColVal, Lench(ColVal), pcblench)
ProPrice = Val(ColVal)
End If
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
GetInfo = True
DB_Disconnect
End Function
Public Function In_DB(ByVal TmpProName As String) As Boolean
DB_Connect
SqlStmt = "SELECT ProId FROM Product WHERE ProName='" + Trim(TmpProName) + "'"
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()
ProId = GetNewId
'連接數(shù)據(jù)庫
DB_Connect
'設(shè)置Insert語句
SqlStmt = "INSERT INTO Product (ProName, " _
+ " ProUnit, ProPrice )" _
+ " Values('" + Trim(ProName) + "'," _
+ "'" + Trim(ProUnit) + "'," _
+ " " + Trim(ProPrice) + ")"
'執(zhí)行SQL語句
OdbcExt (SqlStmt)
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
'斷開與數(shù)據(jù)庫的連接
DB_Disconnect
'Insert = ProId
End Sub
Public Sub Load_by_Type(ByVal TmpTypeId As Integer)
Dim i As Integer
'初始化部門數(shù)組
Erase Arr_Product
ReDim Arr_Product(0)
DB_Connect
SqlStmt = "SELECT ProName FROM Product ORDER BY ProName"
OdbcExt (SqlStmt)
i = 0
Do Until SQLFetch(Hstmt) = SQL_NO_DATA_FOUND
'讀取部門編號(hào)
ColVal = String(40, 0)
Rc = SQLGetData(Hstmt, 1, 1, ColVal, Len(ColVal), pcblen)
ReDim Preserve Arr_Product(i + 1)
Arr_Product(i) = TrimStr(ColVal)
i = i + 1
Loop
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Sub
Public Function HaveType(ByVal TmpTypeId As Long) As Boolean
DB_Connect
SqlStmt = "SELECT ProId FROM Product WHERE TypeId=" + Trim(TmpTypeId)
OdbcExt (SqlStmt)
If SQLFetch(Hstmt) <> SQL_NO_DATA_FOUND Then
HaveType = True
Else
HaveType = False
End If
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
DB_Disconnect
End Function
Public Sub Update(ByVal OriProId As Integer)
'連接數(shù)據(jù)庫
DB_Connect
'設(shè)置Update語句
SqlStmt = "Update Product Set ProName='" + Trim(ProName) _
+ "',ProUnit='" + Trim(ProUnit) _
+ "',ProPrice=" + Trim(ProPrice) + _
" WHERE ProId=" + Trim(Str(OriProId))
'執(zhí)行SQL語句
OdbcExt (SqlStmt)
Rc = SQLFreeStmt(Hstmt, SQL_DROP)
'斷開與數(shù)據(jù)庫的連接
DB_Disconnect
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -