?? frmmerch.frm
字號:
VERSION 5.00
Begin VB.Form frmMerch
BorderStyle = 3 'Fixed Dialog
Caption = "商品信息"
ClientHeight = 4710
ClientLeft = 2760
ClientTop = 3750
ClientWidth = 6675
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4710
ScaleWidth = 6675
ShowInTaskbar = 0 'False
Begin VB.Frame fraMerch
Caption = "商品信息"
Height = 3615
Left = 240
TabIndex = 8
Top = 240
Width = 6015
Begin VB.TextBox txtStorage
Height = 350
Left = 1080
MaxLength = 8
TabIndex = 2
Text = "txtStorage"
Top = 1230
Width = 735
End
Begin VB.ComboBox cboUnit
Height = 300
ItemData = "frmMerch.frx":0000
Left = 2280
List = "frmMerch.frx":0007
Style = 2 'Dropdown List
TabIndex = 3
Top = 1275
Width = 1335
End
Begin VB.ComboBox cboType
Height = 300
Left = 1080
Style = 2 'Dropdown List
TabIndex = 1
Top = 795
Width = 1815
End
Begin VB.TextBox txtName
Height = 350
Left = 1080
MaxLength = 18
TabIndex = 0
Text = "txtName"
Top = 270
Width = 2535
End
Begin VB.TextBox txtIntro
Height = 735
Left = 1080
MaxLength = 255
MultiLine = -1 'True
TabIndex = 4
Text = "frmMerch.frx":0012
Top = 1755
Width = 4695
End
Begin VB.TextBox txtRemark
Height = 735
Left = 1080
MaxLength = 255
MultiLine = -1 'True
TabIndex = 5
Text = "frmMerch.frx":001D
Top = 2640
Width = 4695
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "庫存量"
Height = 180
Left = 240
TabIndex = 13
Top = 1320
Width = 540
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "商品類型"
Height = 180
Left = 240
TabIndex = 12
Top = 840
Width = 720
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "商品介紹"
Height = 180
Left = 240
TabIndex = 11
Top = 1800
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "商品名"
Height = 180
Left = 240
TabIndex = 10
Top = 360
Width = 540
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "備注"
Height = 180
Left = 240
TabIndex = 9
Top = 2880
Width = 360
End
End
Begin VB.CommandButton OKButton
Caption = "確定"
Height = 330
Left = 3720
TabIndex = 6
Top = 4080
Width = 1215
End
Begin VB.CommandButton CancelButton
Caption = "取消"
Height = 330
Left = 5160
TabIndex = 7
Top = 4080
Width = 1215
End
End
Attribute VB_Name = "frmMerch"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private OK As Boolean '確定用戶按了OK還是CANCEL按鈕
Private m_obj As clsMerch '數據對象,用來存儲用戶輸入數據
Public m_ViewType As gxcViewType '顯示狀態,指添加還是修改
Private m_TypeId As Long '商品類型
'根據是“新增”還是修改,確定顯示內容
Private Sub SetStatus()
'設置控件默認值
Call SetDefaultValue
'設置狀態
Select Case m_ViewType
Case vtadd '添加
CancelButton.Visible = True
OKButton.Caption = "確定"
Case vtModify '修改
CancelButton.Visible = True
OKButton.Caption = "保存"
End Select
End Sub
'打開對話框,并傳出用戶輸入數據
Public Function ShowDlg(ByRef obj As Object, _
ByVal eViewType As gxcViewType, _
Optional nTypeId As Long = -1) As Boolean
'保存數據
Set m_obj = obj '用戶輸入數據存放于此對象中
m_ViewType = eViewType '對話框狀態
If nTypeId = -1 And (Not m_obj Is Nothing) Then
m_TypeId = m_obj.TypeId
Else
m_TypeId = nTypeId
End If
'根據新增、編輯或查看設置顯示內容
SetStatus
'顯示對話框
OK = False
Me.Show vbModal
If OK = False Then
ShowDlg = False
Exit Function
End If
'保存數據
Set obj = m_obj
'返回并釋放對話框
ShowDlg = True
Unload Me
End Function
'設置控件默認值
Private Sub SetDefaultValue()
Dim ctl As Control
Dim i As Integer
'如果是新增,則清空所有文本框
'此處判斷 m_obj為空與判斷m_ViewType = vtAdd等效,但更安全
If m_obj Is Nothing Then
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
ctl.Text = ""
End If
Next
Else '用傳入對象的值更新數據
With m_obj
txtName.Text = .MerchName
txtStorage.Text = .Storage
cboUnit.ListIndex = 0
txtIntro.Text = .Introduce
txtRemark.Text = .Remark
For i = 0 To cboType.ListCount - 1
If cboType.ItemData(i) = m_TypeId Then
cboType.ListIndex = i '商品類型Id
Exit For
End If
Next i
End With
End If
End Sub
'檢查輸入有效性
Private Function CheckValid() As Boolean
If txtName.Text = "" _
Or txtIntro.Text = "" _
Or txtRemark.Text = "" Then
MsgBox "請填寫完畢以上各項內容"
CheckValid = False
Exit Function
End If
If cboType.Text = "" Then
MsgBox "請填寫完畢以上各項內容"
CheckValid = False
Exit Function
End If
If Not IsNumeric(txtStorage.Text) Then
MsgBox "庫存量請輸入數字"
Exit Function
End If
CheckValid = True
End Function
'保存數據
Private Sub SaveValue()
'給“成員變量”對象賦值
With m_obj
'注意以下利用RealString函數替換去除輸入中的單引號
.MerchName = RealString(txtName.Text)
.Remark = RealString(txtRemark.Text)
.Storage = RealString(txtStorage.Text)
.Introduce = RealString(txtIntro.Text)
.TypeId = cboType.ItemData(cboType.ListIndex) '商品類型Id
.TypeName = cboType.Text
End With
End Sub
'取消按鈕
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim opMType As New clsOpMType
opMType.FillCombo cboType
End Sub
'確定按鈕
Private Sub OKButton_Click()
OK = True
'檢測輸入有效性
If Not CheckValid Then Exit Sub
'如果是新增狀態,則初始化一個數據對象
If m_ViewType = vtadd Then Set m_obj = New clsMerch
'保存用戶輸入
SaveValue
Me.Hide
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -