📄 inventoryitem.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 = "InventoryItem"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'保持属性值的局部变量
Private m_Id As Long '局部复制
Private m_Inventor As TInventor '局部复制
Private m_Quantity As Double '局部复制
Private m_Cost As Double '局部复制
Private m_Price As Double '局部复制
Private m_IsChange As Boolean
Public Function Save(ByRef pConn As ADODB.Connection, ByVal MainId As Long) As Boolean
If m_IsChange = False And m_Inventor.IsChange = False Then
If m_Id > 0 Then
Save = True
Else
Save = False
End If
Exit Function
End If
If m_Inventor.Id < 0 Or m_Price <= 0 Then
Save = False
Exit Function
End If
Dim SaveComString As String
Dim comm As ADODB.Command
If m_Id > 0 Then
SaveComString = "UPDATE WorkSub_2 SET InvId=" & CStr(m_Inventor.Id) & ",Quantity=" _
& CStr(m_Quantity) & ", Cost=" & CStr(m_Cost) & ",Price=" & CStr(m_Price) _
& " WHERE AutoId=" & CStr(m_Id)
Else
SaveComString = "INSERT INTO WorkSub_2 (MainId,InvId,Quantity,Cost,Price) VALUES (" _
& CStr(MainId) & "," & CStr(m_Inventor.Id) & "," & CStr(m_Quantity) & "," & CStr(m_Cost) _
& "," & CStr(m_Price) & ")"
End If
On Error GoTo RepSave
Set comm = New ADODB.Command
Set comm.ActiveConnection = pConn
'MsgBox SaveComString
comm.CommandType = adCmdText
comm.CommandText = SaveComString & vbNullString
comm.Execute , , adExecuteNoRecords
If m_Id < 0 Then
Dim re As ADODB.Recordset
Set re = pConn.Execute("SELECT MAX(AutoId) FROM WorkSub_1")
m_Id = re.Fields(0)
Set re = Nothing
End If
Set comm = Nothing
m_IsChange = False
Exit Function
RepSave:
MsgBox "数据保存错误", vbCritical Or vbOKOnly, "错误"
Set comm = Nothing
Save = False
End Function
Public Property Let Price(ByVal vData As Double)
If vData > 0 Then
m_Price = vData
m_Cost = m_Price / m_Quantity
m_IsChange = True
End If
End Property
Public Property Get Price() As Double
Price = m_Price
End Property
Public Property Let Cost(ByVal vData As Double)
If vData > 0 Then
m_Cost = vData
m_Price = m_Cost * m_Quantity
m_IsChange = True
End If
End Property
Public Property Get Cost() As Double
Cost = m_Cost
End Property
Public Property Let Quantity(ByVal vData As Double)
If vData > 0 Then
m_Quantity = vData
If m_Cost > 0 Then
m_Price = m_Cost * m_Quantity
Else
If m_Price > 0 Then
m_Cost = m_Price / m_Quantity
End If
End If
m_IsChange = True
End If
End Property
Public Property Get Quantity() As Double
Quantity = m_Quantity
End Property
Public Property Set Inventor(ByRef vData As TInventor)
Set m_Inventor = vData
End Property
Public Property Get Inventor() As TInventor
Set Inventor = m_Inventor
End Property
Public Property Let Id(ByVal vData As Long)
m_Id = vData
End Property
Public Property Get Id() As Long
Id = m_Id
End Property
Private Sub Class_Initialize()
Set m_Inventor = New TInventor
ClearData
End Sub
Public Sub ClearData()
m_Inventor.ClearData
m_Id = -1
m_Quantity = 0
m_Cost = 0
m_Price = 0
m_IsChange = False
End Sub
Private Sub Class_Terminate()
Set m_Inventor = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -