📄 frmcustman.frm
字号:
Dim OriType As String
Private Sub Loadtype()
Dim i As Integer
i = 0
MyCust.Loadtype
ComboType.Clear
i = 0
Do While Arr_CustType(i) <> ""
ComboType.AddItem Arr_CustType(i)
i = i + 1
Loop
'设置ComboType的显示值,
If OriType = "" Then
'如果没有原值,则显示第1条记录值
If ComboType.ListCount > 0 Then
ComboType.ListIndex = 0
End If
Else
'将显示值恢复为原有数据
If InCombo(OriType, ComboType) = True Then
ComboType.Text = OriType
Else
If ComboType.ListCount > 0 Then
ComboType.ListIndex = 0
End If
End If
End If
End Sub
Private Sub Refresh_Customer()
Dim TmpSource As String '保存SQL语句的变量
'设置查询语句,WHERE CustType='" + Trim(ComboType.Text) + "'"
'表示根据当前选择的客户类别选择客户记录
TmpSource = "SELECT CustType, Idtype As 证件类型, CustId As 证件编号, CustName As 客户姓名," _
+ " OrgName As 客户单位, Sex As 性别, CustFrom As 国籍户籍, CustLevel As 客户等级," _
+ " Job As 职务, Office As 单位电话, Mobile As 移动电话, Home As 家庭电话, " _
+ " Address As 家庭住址, Postcode As 邮政编码 FROM Customer" _
+ " WHERE CustType='" + Trim(ComboType.Text) + "'"
'ComboSearch组合框中定义了查询的条件,ComboSearch.ListIndex=0时显示指定客户类别下所有记录
'ComboSearch.ListIndex>0时,需要指定查询条件
Select Case ComboSearch.ListIndex
Case 1 '按单位查询
TmpSource = TmpSource + " And OrgName LIKE '%" + Trim(txtSearch) + "%'"
Case 2 '按姓名查询
TmpSource = TmpSource + " And CustName LIKE '%" + Trim(txtSearch) + "%'"
Case 3 '按地址查询
TmpSource = TmpSource + " And Address LIKE '%" + Trim(txtSearch) + "%'"
Case 4 '按其他查询
TmpSource = TmpSource + " And Mobile LIKE '%" + Trim(txtSearch) + "%'"
'TmpSource = TmpSource + " And (Office LIKE '%" + Trim(txtSearch) + "%' OR" _
+ " Mobile LIKE '%" + Trim(txtSearch) + "%' OR Home LIKE '%" _
+ Trim(txtSearch) + "%')"
Case 5 '按身份证查询
TmpSource = TmpSource + " And CustId LIKE '%" + Trim(txtSearch) + "%'"
End Select
'设置ADO控件的数据源
Adodc1.ConnectionString = Conn
Adodc1.RecordSource = TmpSource
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Width = 0 '客户类型
DataGrid1.Columns(1).Width = 1000 '证件类型
DataGrid1.Columns(2).Width = 2000
DataGrid1.Columns(3).Width = 1000 '客户姓名
DataGrid1.Columns(4).Width = 1000
DataGrid1.Columns(5).Width = 600 '性别
DataGrid1.Columns(6).Width = 1300 '国籍户籍
DataGrid1.Columns(7).Width = 1000 '客户等
DataGrid1.Columns(8).Width = 1000 '职务
DataGrid1.Columns(9).Width = 1000 '单位电话
DataGrid1.Columns(10).Width = 1000 '移动电话
DataGrid1.Columns(11).Width = 1000 '家庭电话
End Sub
Private Sub Cmd_Add_Click()
'保存原客户类别
OriType = ComboType.Text
'对FrmCustEdit窗体对象进行初始化
With FrmCustEdit
.Option1.Value = True
.ComboIdtype.ListIndex = 0
.ComboLevel.ListIndex = 0
.Modify = False
.Show 1
End With
'因为删除客户可能导致客户类别变化,需要重新装入客户类别
Loadtype
'刷新显示
Refresh_Customer
End Sub
Private Sub Cmd_Close_Click()
Unload Me
End Sub
Private Sub Cmd_Del_Click()
'判断是否选择了要删除的记录
If Adodc1.Recordset.EOF = True Then
MsgBox "请选择要删除的记录"
Exit Sub
End If
'保存原客户类别
OriType = ComboType.Text
'要求用户确认删除
If MsgBox("是否删除当前记录", vbYesNo, "请确认") = vbYes Then
MyCust.Delete (Adodc1.Recordset.Fields(2))
Refresh_Customer
End If
'因为删除客户可能导致客户类别变化,需要重新装入客户类别
Loadtype
End Sub
Private Sub Cmd_Modi_Click()
'判断是否选择了要修改的记录
If Adodc1.Recordset.EOF = True Then
MsgBox "请选择要修改的记录"
Exit Sub
End If
'保存原客户类别
OriType = ComboType.Text
'对FrmCustEdit窗体对象进行初始化
With FrmCustEdit
.ComboCustType.Text = ComboType.Text '客户类别
.txtOrgName = Trim(Adodc1.Recordset.Fields(4)) '客户单位
.txtName = Trim(Adodc1.Recordset.Fields(3)) '姓名
If Trim(Adodc1.Recordset.Fields(5)) = "男" Then '性别
.Option1.Value = True
Else
.Option2.Value = True
End If
If Trim(Adodc1.Recordset.Fields(6)) <> "" Then
.txtFrom = Trim(Adodc1.Recordset.Fields(6)) '国籍户籍
End If
'客户等级
If InCombo(Trim(Adodc1.Recordset.Fields(7)), .ComboLevel) = True Then
.ComboLevel = Trim(Adodc1.Recordset.Fields(7))
End If
'证件类型
If InCombo(Trim(Adodc1.Recordset.Fields(1)), .ComboIdtype) = True Then
.ComboIdtype = Trim(Adodc1.Recordset.Fields(1))
End If
'证件编号
.OriCustId = Trim(Adodc1.Recordset.Fields(2))
.txtCustId = Trim(Adodc1.Recordset.Fields(2))
'邮政编码
If Trim(Adodc1.Recordset.Fields(13)) <> "" Then
.txtPostcode = Trim(Adodc1.Recordset.Fields(13))
End If
'通信地址
If Trim(Adodc1.Recordset.Fields(12)) <> "" Then
.txtAddr = Trim(Adodc1.Recordset.Fields(12))
End If
'单位电话
If Trim(Adodc1.Recordset.Fields(9)) <> "" Then
.txtOffice = Trim(Adodc1.Recordset.Fields(9))
End If
'移动电话
If Trim(Adodc1.Recordset.Fields(10)) <> "" Then
.txtMobile = Trim(Adodc1.Recordset.Fields(10))
End If
'家庭电话
If Trim(Adodc1.Recordset.Fields(11)) <> "" Then
.txtHome = Trim(Adodc1.Recordset.Fields(11))
End If
'职务
If Trim(Adodc1.Recordset.Fields(8)) <> "" Then
.txtJob = Trim(Adodc1.Recordset.Fields(8))
End If
'设置修改状态
.Modify = True
.Show 1
End With
'因为删除客户可能导致客户类别变化,需要重新装入客户类别
Loadtype
'刷新显示
Refresh_Customer
End Sub
Private Sub Cmd_Search_Click()
Refresh_Customer
End Sub
Private Sub ComboSearch_Click()
If ComboSearch.ListIndex = 0 Then
'选择显示全部内容时,将查询文本框和按钮隐藏
txtSearch = ""
txtSearch.Visible = False
Cmd_Search.Visible = False
Else
'选择显示指定查询结果时,将查询文本框和按钮设置为可见
txtSearch.Visible = True
Cmd_Search.Visible = True
End If
End Sub
Private Sub ComboType_Click()
Refresh_Customer
End Sub
Private Sub Command1_Click()
If Adodc1.Recordset.EOF = True Then
MsgBox "请选择要修改的记录"
Exit Sub
End If
With FrmOrderRoomEdit
.lblCid.Caption = Trim(Adodc1.Recordset.Fields(2))
.lblCname.Caption = Trim(Adodc1.Recordset.Fields(3))
.lblCtype.Caption = Trim(Adodc1.Recordset.Fields(0))
.lblOrderDate = Date
.lblEmpName = CurUser.EmpName
.Show 1
End With
End Sub
Private Sub Command2_Click()
If Adodc1.Recordset.EOF = True Then
MsgBox "请选择要修改的记录"
Exit Sub
End If
With FrmRegEdit
.lblCid.Caption = Trim(Adodc1.Recordset.Fields(2))
.lblCname.Caption = Trim(Adodc1.Recordset.Fields(3))
.lblCtype.Caption = Trim(Adodc1.Recordset.Fields(0))
.lblEmpName = CurUser.EmpName
.Show 1
End With
End Sub
Private Sub Form_Load()
'装入客户类别数据
Loadtype
'设置查询条件
ComboSearch.ListIndex = 0
'设置数据源的查询条件,并刷新显示
Refresh_Customer
End Sub
Private Sub txtSearch_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Refresh_Customer
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -