a(cboMerchName.ListIndex) '商品类型Id
.MerchName = cboMerchName.Text
.RegDate = dtpRegDate.Value
.OperatorId = m_Account '操作者账号
End With
End Sub
'取消按钮
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim opMerch As New clsOpMerch
opMerch.FillCombo cboMerchName
End Sub
'确定按钮
Private Sub OKButton_Click()
OK = True
'检测输入有效性
If Not CheckValid Then Exit Sub
'如果是新增状态,则初始化一个数据对象
If m_ViewType = vtadd Then Set m_obj = New clsDispose
'保存用户输入
SaveValue
Me.Hide
End Sub
3:供应商表:
代码分析:
Option Explicit
Private OK As Boolean '确定用户按了OK还是CANCEL按钮
Private m_obj As clsProvider '数据对象,用来存储用户输入数据
Public m_ViewType As gxcViewType '显示状态,指添加还是修改
'根据是“新增”还是修改,确定显示内容
Private Sub SetStatus()
'设置控件默认值
Call SetDefaultValue
'设置状态
Select Case m_ViewType
Case vtadd '添加
CancelButton.Visible = True
OKButton.Caption = "确定"
Case vtModify '修改
CancelButton.Visible = True
OKButton.Caption = "保存"
Case vtInfo '查看
CancelButton.Visible = False
OKButton.Caption = "关闭"
End Select
End Sub
'打开对话框,并传出用户输入数据
Public Function ShowDlg(ByRef obj As Object, _
ByVal eViewType As gxcViewType) As Boolean
'保存数据
Set m_obj = obj '用户输入数据存放于此对象中
m_ViewType = eViewType '对话框状态
'根据新增、编辑或查看设置显示内容
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 = .ProviderName
txtIntro.Text = .Introduce
txtRemark.Text = .Remark
End With
End If
End Sub
'检查输入有效性
Private Function CheckValid() As Boolean
If txtName.Text = "" _