?? frmgoods.frm
字號:
VERSION 5.00
Begin VB.Form frmGoods
BorderStyle = 1 'Fixed Single
Caption = "商品管理"
ClientHeight = 4455
ClientLeft = 45
ClientTop = 330
ClientWidth = 6930
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
ScaleHeight = 4455
ScaleWidth = 6930
StartUpPosition = 1 '所有者中心
Begin VB.Frame Frame1
Height = 4545
Left = 0
TabIndex = 9
Top = -90
Width = 6930
Begin VB.TextBox txt
Height = 270
Index = 2
Left = 3120
MaxLength = 50
TabIndex = 2
Top = 1170
Width = 1155
End
Begin VB.TextBox txt
Height = 660
Index = 4
Left = 1260
MaxLength = 500
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 6
Top = 3105
Width = 5250
End
Begin VB.TextBox txt
Height = 660
Index = 3
Left = 1260
MaxLength = 500
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 5
Top = 2334
Width = 5250
End
Begin VB.ComboBox cbo
Height = 300
Index = 1
Left = 1260
Style = 2 'Dropdown List
TabIndex = 4
Top = 1935
Width = 5250
End
Begin VB.ComboBox cbo
Height = 300
Index = 0
Left = 1260
Style = 2 'Dropdown List
TabIndex = 3
Top = 1545
Width = 5250
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "取消(&C)"
Height = 375
Left = 5325
TabIndex = 8
Top = 3960
Width = 1080
End
Begin VB.CommandButton cmdGoods
Caption = "添加(&A)"
Height = 375
Left = 4020
TabIndex = 7
Top = 3960
Width = 1080
End
Begin VB.PictureBox picTitle
Appearance = 0 'Flat
BackColor = &H00808080&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 360
Left = 30
ScaleHeight = 360
ScaleWidth = 6870
TabIndex = 12
TabStop = 0 'False
Top = 90
Width = 6870
Begin VB.Label lblTitle
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "添加商品"
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 210
Left = 255
TabIndex = 13
Top = 90
Width = 900
End
End
Begin VB.TextBox txt
Height = 270
Index = 1
Left = 1260
TabIndex = 1
Text = "0"
Top = 1176
Width = 1155
End
Begin VB.TextBox txt
Height = 270
Index = 0
Left = 1260
MaxLength = 50
TabIndex = 0
Top = 810
Width = 5250
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "商品備注"
Height = 180
Index = 6
Left = 450
TabIndex = 18
Top = 3150
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "商品介紹"
Height = 180
Index = 5
Left = 450
TabIndex = 17
Top = 2400
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "供貨商"
Height = 180
Index = 4
Left = 450
TabIndex = 16
Top = 2016
Width = 540
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "商品類型"
Height = 180
Index = 3
Left = 450
TabIndex = 15
Top = 1634
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "單位"
Height = 180
Index = 2
Left = 2700
TabIndex = 14
Top = 1215
Width = 360
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "庫存數(shù)量"
Height = 180
Index = 1
Left = 450
TabIndex = 11
Top = 1252
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "商品名稱"
Height = 180
Index = 0
Left = 450
TabIndex = 10
Top = 870
Width = 720
End
End
End
Attribute VB_Name = "frmGoods"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Goods As clsGoods '商品對象
'驗(yàn)證用戶輸入的有效性
Private Function IsOK() As Boolean
'除介紹和備注外的項(xiàng)目必須全部填寫
If cbo(0).Text = "" Or cbo(1).Text = "" Or txt(0) = "" Or txt(1) = "" Or txt(2) = "" Then
MsgBox "除介紹和備注外,請把所有項(xiàng)目填寫完整!", vbInformation
Exit Function
End If
'庫存數(shù)量必須為數(shù)字
If Not IsNumeric(txt(1)) Then
MsgBox "庫存數(shù)量不是數(shù)字,請重新填寫!", vbInformation
txt(1).SetFocus
Exit Function
End If
'返回函數(shù)值
IsOK = True
End Function
Private Sub cmdGoods_Click()
'用戶輸入無效則退出該過程的執(zhí)行
If Not IsOK Then Exit Sub
'初始化商品對象
Set Goods = New clsGoods
With Goods
'為商品對象的屬性賦值
.GoodsName = Trim(txt(0))
.Amount = Val(txt(1))
.UnitName = Trim(txt(2))
.TypeId = cbo(0).ItemData(cbo(0).ListIndex)
.SupplierID = cbo(1).ItemData(cbo(1).ListIndex)
.Introduce = IIf(Trim(txt(3)) = "", "無", RTrim(txt(3)))
.Remark = IIf(Trim(txt(4)) = "", "無", RTrim(txt(4)))
'根據(jù)cmdGoods的Caption屬性修改或添加商品對象
Select Case cmdGoods.Caption
Case "修改(&M)": UpdateGoods '修改商品對象
Case Else: AddNewGoods '添加商品對象
End Select
End With
txt(0).SetFocus
End Sub
'更新商品對象
Private Sub UpdateGoods()
Dim UpdateResult As gxcUpdate '更新結(jié)果
'指定商品對象的ID屬性
Goods.ID = Me.Tag
'更新商品對象并返回更新結(jié)果
UpdateResult = Goods.Update
Dim Goodses As New clsGoodses '商品對象集
'按照編號查詢更新后的商品對象
Goodses.Query Goods.ID
'同步更新列表視圖并彈出提示消息框
ProcUpdateResult UpdateResult, Goodses.Item(1)
End Sub
'添加商品對象
Private Sub AddNewGoods()
Dim AddNewResult As gxcAddNew '添加結(jié)果
'添加商品對象并返回添加結(jié)果
AddNewResult = Goods.AddNew
'添加成功之后的操作
If AddNewResult = AddNewOK Then
txt(0) = "": txt(1) = "0": txt(2) = "": txt(3) = "": txt(4) = ""
Dim Goodses As New clsGoodses '商品對象集
'按照編號查詢剛添加的商品對象
Goodses.Query Goods.ID
'當(dāng)前操作處于瀏覽商品信息狀態(tài),則在列表視圖上添加商品信息
If CurrentOperation = BrowseGoods Then ShowObjInLvw Goodses.Item(1)
MsgBox "添加成功!", vbInformation
Exit Sub
End If
'添加失敗后的操作(消息框提示用戶)
ProcAddNewResult AddNewResult
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim GoodsTypes As New clsGoodsTypes '商品類型對象集
Dim Suppliers As New clsSuppliers '供貨商對象集
Dim i As Long
'檢索所有商品類型
GoodsTypes.Query
'將商品類型名稱和編號添加到組合框
For i = 1 To GoodsTypes.Count
cbo(0).AddItem GoodsTypes.Item(i).TypeName
cbo(0).ItemData(i - 1) = GoodsTypes.Item(i).ID
Next i
'檢索所有供貨商
Suppliers.Query
'將供貨商名稱和編號添加到組合框
For i = 1 To Suppliers.Count
cbo(1).AddItem Suppliers.Item(i).SupplierName
cbo(1).ItemData(i - 1) = Suppliers.Item(i).ID
Next i
End Sub
'文本框獲得焦點(diǎn)時(shí)選中所有文字
Private Sub txt_GotFocus(Index As Integer)
txt(Index).SelStart = 0 '選中文字的起始位置
txt(Index).SelLength = Len(txt(Index)) '選中文字的長度
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -