📄 frmclient.vb
字号:
If GetCoopFromListView(tlvCoop, dmCoop) <> "" Then
Exit Sub
End If
'更新数据库
Dim ErrMsg As String
Dim coopObj As New clientMgrBusiness.Cooperate
ErrMsg = coopObj.Delete(dmCoop.ID)
If ErrMsg = "" Then
tlvCoop.SelectedItems(0).Remove()
Else
MsgBox(ErrMsg, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly)
End If
End Sub
'修改合作
Private Sub btnModifyCoop_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnModifyCoop.Click
Dim dmCoop As New clientMgrBusiness.CooperateDataModel
'获取选中的合作记录
If GetCoopFromListView(tlvCoop, dmCoop) <> "" Then Exit Sub
'显示对话框
Dim frm As New frmAddCoop
If frm.RetriveCoop(dmCoop, clientMgrBusiness.dmViewType.vtModify, m_dmClient) = False Then Exit Sub
'更新数据库
Dim ErrMsg As String
Dim coopObj As New clientMgrBusiness.Cooperate
ErrMsg = coopObj.Update(dmCoop)
If ErrMsg = "" Then
AddCooperateToListView(dmCoop, tlvCoop, True)
Else
MsgBox(ErrMsg, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly)
End If
End Sub
Private Sub tlvCoop_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tlvCoop.DoubleClick
If tlvCoop.SelectedItems.Count > 0 _
And ViewType <> dmViewType.vtInfo Then
btnCoopInfo_Click(btnCoopInfo, New System.EventArgs)
End If
End Sub
Private Sub tlvCoop_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tlvCoop.SelectedIndexChanged
UpdateCooperateCmdUI()
End Sub
#End Region
#Region "窗体消息响应"
Private Sub btnCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnCancel.Click
'按了取消按钮
m_bOK = False
Me.Hide()
End Sub
Private Sub btnModifyInfo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnModifyInfo.Click
m_dmViewType = clientMgrBusiness.dmViewType.vtModify
SetStatus()
UpdateCooperateCmdUI()
End Sub
Private Sub OKButton_Click(ByVal eventSender As System.Object, _
ByVal eventArgs As System.EventArgs) Handles btnOK.Click
If m_dmViewType = dmViewType.vtInfo Then
Me.Hide()
Exit Sub
End If
'检查输入出境否合法
If CheckValid() = False Then
Exit Sub
End If
m_bOK = True
'如果是新增状态,则新建立一个“人员”对象
If m_dmViewType = clientMgrBusiness.dmViewType.vtadd Then
m_dmClient = New clientMgrBusiness.ClientDataModel
End If
'给“人员”对象赋值
SaveValue()
Me.Hide()
End Sub
Private Sub frmClient_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If m_dmClient Is Nothing Then
mdlListView.InitCooperateListview(tlvCoop)
Else
mdlListView.CooperatesToListView(m_dmClient.ID, tlvCoop)
End If
UpdateCooperateCmdUI()
End Sub
#End Region
Private Sub dtpBirthday_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpBirthday.ValueChanged
txtAge.Text = Year(Today) - dtpBirthday.Value.Year
End Sub
Private Sub txtAge_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtAge.TextChanged
dtpBirthday.Value.AddYears(-Val(txtAge.Text))
End Sub
'弹出客户信息管理对话框,初始化对话框数据显示
Public Function RetriveClient(ByRef dmClient As ClientDataModel, ByVal eViewType As dmViewType, Optional ByRef nTypeID As Integer = -1) As Boolean
m_dmClient = dmClient
If nTypeID = -1 And (Not dmClient Is Nothing) Then
m_iTypeId = dmClient.TypeID
Else
m_iTypeId = nTypeID
End If
m_dmViewType = eViewType '对话框状态
SetStatus() '根据新增或编辑状态设置显示内容
m_bOK = False
Me.ShowDialog()
If m_bOK = False Then Return False
'传出对象
dmClient = m_dmClient
Me.Close()
Return True
End Function
#Region "显示窗体过程实用函数"
'递归设计控件的显示状态
Private Sub SetControlStatus(ByRef topControl As Control, ByVal bLocked As Boolean)
Dim ctl As System.Windows.Forms.Control
For Each ctl In topControl.Controls
If TypeOf (ctl) Is System.Windows.Forms.TextBox Then
Dim txt As TextBox = ctl
txt.ReadOnly = bLocked
If bLocked Then
txt.BorderStyle = BorderStyle.None
txt.BackColor = txt.Parent.BackColor
Else
txt.BorderStyle = BorderStyle.Fixed3D
txt.BackColor = Color.White
End If
End If
If TypeOf (ctl) Is TreeCombo Then
Dim cbo As TreeCombo = ctl
cbo.ReadOnly = bLocked
cbo.Enabled = Not bLocked
End If
If TypeOf (ctl) Is RadioButton Then
Dim rdi As RadioButton = ctl
rdi.Enabled = Not bLocked
End If
'递归循环其子控件中的相关控件
SetControlStatus(ctl, bLocked)
Next ctl
End Sub
'根据对话框的显示方式来确定显示的数据
Private Sub SetStatus()
Dim bLocked As Boolean = False
btnOK.Visible = True
btnCancel.Text = "取消"
btnModifyInfo.Visible = False
'设置控件默认值
SetDefaultValue()
Dim bEnabled As Boolean = True
Select Case m_dmViewType
Case clientMgrBusiness.dmViewType.vtadd '添加客户
'操作按钮可用性设置
btnOK.Text = "确定"
Me.Text = "添加客户"
bEnabled = True
Case clientMgrBusiness.dmViewType.vtModify '修改客户信息
btnOK.Text = "保存"
Me.Text = "修改客户信息"
bEnabled = True
Case clientMgrBusiness.dmViewType.vtInfo '查看客户信息
bLocked = True
btnModifyInfo.Visible = True
btnOK.Visible = False
btnCancel.Text = "关闭"
Me.Text = "查看客户信息"
bEnabled = False
Case Else
End Select
Me.dtpBirthday.Enabled = bEnabled
Me.ctbFriendly.Enabled = bEnabled
Me.ctbImportance.Enabled = bEnabled
Me.ctbSatisfaction.Enabled = bEnabled
chkBirthdayWarn.Enabled = bEnabled
btnModifyCoop.Visible = bEnabled
btnAddCoop.Visible = bEnabled
btnDelCoop.Visible = bEnabled
btnCoopInfo.Visible = bEnabled
'根据显示状态不同设置文本框风格
SetControlStatus(Me, bLocked)
End Sub
Private Sub ClearTextbox(ByRef topControl As Control)
Dim ctl As System.Windows.Forms.Control
For Each ctl In topControl.Controls
If TypeOf (ctl) Is System.Windows.Forms.TextBox Then
ctl.Text = ""
End If
'递归清空其子控件中的Textbox
ClearTextbox(ctl)
Next ctl
End Sub
'选种组合框中的树结点,也可以放到TypesToTreeView去实现
Private Sub SelectNode(ByVal iTypeid As Integer, ByVal nodes As TreeNodeCollection)
Dim node As TreeNode
For Each node In nodes
If node.Tag = iTypeid Then
tcboClientType.TreeDropDown.SelectedNode = node
Return
Else
SelectNode(iTypeid, node.Nodes)
End If
Next
End Sub
Private Sub SetDefaultValue()
'添加所有的客户类型到组合框
mdlTreeView.TypesToTreeView(tcboClientType.TreeDropDown, False)
If tcboClientType.TreeDropDown.Tag = m_iTypeId Then
tcboClientType.TreeDropDown.SelectedNode = tcboClientType.TreeDropDown.Nodes(0)
Else
SelectNode(m_iTypeId, tcboClientType.TreeDropDown.Nodes)
End If
If m_dmClient Is Nothing Then
'如果m_dmClient没有被实例化,则清空所有文本框
ClearTextbox(Me)
Me.dtpBirthday.Value = Today
Else
'将m_dmClient中的数据写入文本框
With m_dmClient
txtName.Text = .Name
txtMobile.Text = .Mobile
txtEmail.Text = .Email
txtName.Text = .Name '客户名称
txtAge.Text = .Age '客户年龄
If .Sex = clientMgrBusiness.dmSex.Male Then '性别
rdiMale.Checked = True
Else
rdiFemale.Checked = True
End If
tcboClientType.Text = .TypeName '客户类型名称
tcboClientType.Value = .TypeName
txtMobile.Text = .Mobile '手机
txtEmail.Text = .Email 'E-mail
txtOfficePhone.Text = .OfficePhone '办公室电话
txtHomePhone.Text = .HomePhone '宅电
txtFax.Text = .Fax '传真
txtHomeAdr.Text = .HomeAddress '家庭住址
txtMailAdr.Text = .MailAddress '通讯地址
txtZipCode.Text = .ZipCode '邮编
dtpBirthday.Value = .Birthday '生日
chkBirthdayWarn.CheckState = IIf(.BirthdayWarn, 1, 0) '是不启用生日提醒
txtWork.Text = .Job '职业
txtPosition.Text = .JobPosition '职位
txtCompany.Text = .Company '公司
txtCompanySite.Text = .CompanySite '公司网址
txtSelfSite.Text = .SelfSite '个人网址
txtLikes.Text = .Likes '喜好
txtHate.Text = .Hates '厌恶
txtRemark.Text = .Remark '备注
ctbImportance.Value = .Importance '重要度
ctbFriendly.Value = .Friendly '友好度
ctbSatisfaction.Value = .Satisfaction '满意度
'显示所有的合作信息
ListAllCooperates(tlvCoop, .ID)
End With
End If
End Sub
#End Region
#Region "关闭窗体/保存信息实用函数"
Private Function CheckValid() As Boolean
If txtName.Text = "" _
Or ((Not rdiMale.Checked) And (Not rdiFemale.Checked)) _
Or tcboClientType.Text = "" _
Or txtMobile.Text = "" _
Or txtEmail.Text = "" Then
MsgBox("请填写表格中的必填信息", MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation)
Return False
End If
If tcboClientType.TreeDropDown.SelectedNode Is Nothing Then
MsgBox("请选择客户类型", MsgBoxStyle.OKOnly + M
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -