?? 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 + -