⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmaddcoop.vb

📁 <Visual Basic 数据库开发实例精粹(第二版)>一书首先介绍了Visual Basic(简称VB)开发的技巧和重点技术
💻 VB
📖 第 1 页 / 共 2 页
字号:
    '
    'imglistTask
    '
    Me.imglistTask.ImageSize = New System.Drawing.Size(16, 16)
    Me.imglistTask.ImageStream = CType(resources.GetObject("imglistTask.ImageStream"), System.Windows.Forms.ImageListStreamer)
    Me.imglistTask.TransparentColor = System.Drawing.Color.Transparent
    '
    'lnkOK
    '
    Me.lnkOK.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
    Me.lnkOK.ImageIndex = 1
    Me.lnkOK.ImageList = Me.imglistTask
    Me.lnkOK.Location = New System.Drawing.Point(16, 68)
    Me.lnkOK.Name = "lnkOK"
    Me.lnkOK.Size = New System.Drawing.Size(88, 16)
    Me.lnkOK.TabIndex = 1
    Me.lnkOK.TabStop = True
    Me.lnkOK.Text = "确定"
    Me.lnkOK.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'lnkModify
    '
    Me.lnkModify.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
    Me.lnkModify.ImageIndex = 0
    Me.lnkModify.ImageList = Me.imglistTask
    Me.lnkModify.Location = New System.Drawing.Point(16, 40)
    Me.lnkModify.Name = "lnkModify"
    Me.lnkModify.Size = New System.Drawing.Size(88, 16)
    Me.lnkModify.TabIndex = 0
    Me.lnkModify.TabStop = True
    Me.lnkModify.Text = "修改"
    Me.lnkModify.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'frmAddCoop
    '
    Me.AcceptButton = Me.lnkOK
    Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
    Me.BackColor = System.Drawing.SystemColors.Window
    Me.CancelButton = Me.lnkCancel
    Me.ClientSize = New System.Drawing.Size(578, 335)
    Me.Controls.Add(Me.XPanderList1)
    Me.Controls.Add(Me.fraCoop)
    Me.Cursor = System.Windows.Forms.Cursors.Default
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
    Me.Location = New System.Drawing.Point(184, 250)
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.Name = "frmAddCoop"
    Me.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.ShowInTaskbar = False
    Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
    Me.Text = "添加合作信息"
    Me.fraCoop.ResumeLayout(False)
    Me.XPanderList1.ResumeLayout(False)
    Me.XPander1.ResumeLayout(False)
    Me.ResumeLayout(False)

  End Sub
#End Region



  Private m_bOK As Boolean '确定用户按了m_bOK还是CANCEL按钮 
  Private m_dmCooperation As New clientMgrBusiness.CooperateDataModel '合作信息对象 
  Private m_dmViewType As clientMgrBusiness.dmViewType '显式模式 
  Private m_dmClient As New clientMgrBusiness.ClientDataModel  '合作者(客户)

  '显式模式
  Public ReadOnly Property ViewType() As clientMgrBusiness.dmViewType
    Get
      ViewType = m_dmViewType
    End Get
  End Property

  Private Sub lnkOK_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkOK.LinkClicked
    m_bOK = True

    '检测输入有效性
    If Not CheckValid() Then
      Return
    End If

    '如果是新增状态,则新建立一个“客户信息”对象
    If m_dmViewType = dmViewType.vtadd Then m_dmCooperation = New CooperateDataModel

    '给“客户信息”对象赋值
    SaveValue()

    Me.Hide()
  End Sub

  Private Sub lnkModify_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkModify.LinkClicked
    m_dmViewType = clientMgrBusiness.dmViewType.vtModify
    SetStatus()
  End Sub

  Private Overloads Sub lnkCancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkCancel.LinkClicked
    '按了取消按钮
    m_bOK = False
    Me.Hide()
  End Sub

  '根据对话框状态,确定显示内容
  Private Sub SetStatus()
    txtCoopMsg.BorderStyle = BorderStyle.Fixed3D
    txtCoopMsg.BackColor = Color.White
    txtCoopMsg.ReadOnly = False
    txtCoopMsg.ScrollBars = ScrollBars.Vertical
    dtpCoopDate.Enabled = True
    ctbSatisfaction.Enabled = True
    lnkModify.Enabled = False

    '设置控件默认值
    SetDefaultValue()

    '根据对话框状态,确定控件状态
    Select Case m_dmViewType
      Case clientMgrBusiness.dmViewType.vtadd '添加
        lnkCancel.Visible = True
        lnkOK.Text = "确定"
        Me.Text = "添加合作信息"
      Case clientMgrBusiness.dmViewType.vtModify '修改
        lnkCancel.Visible = True
        lnkOK.Text = "保存"
        Me.Text = "修改合作信息"
      Case clientMgrBusiness.dmViewType.vtInfo '查看
        lnkModify.Enabled = True
        lnkCancel.Visible = False
        lnkOK.Text = "关闭"
        Me.Text = "查看合作信息"

        txtCoopMsg.BorderStyle = BorderStyle.None
        txtCoopMsg.BackColor = Me.BackColor
        txtCoopMsg.ReadOnly = True
        txtCoopMsg.ScrollBars = ScrollBars.None
        dtpCoopDate.Enabled = False
        ctbSatisfaction.Enabled = False
      Case Else
    End Select

  End Sub

  '根据传入的模式显示对话框,并传出数据
  Public Function RetriveCoop(ByRef dmCoop As clientMgrBusiness.CooperateDataModel, ByVal eViewType As clientMgrBusiness.dmViewType, ByVal dmClient As clientMgrBusiness.ClientDataModel) As Boolean
    m_dmCooperation = dmCoop

    m_dmViewType = eViewType '对话框状态
    '保存客户信息
    m_dmClient = dmClient

    SetStatus() '根据新增或编辑状态设置显示内容

    m_bOK = False
    '显示对话框
    Me.ShowDialog()
    If m_bOK = False Then Exit Function

    '传出对象
    dmCoop = m_dmCooperation
    RetriveCoop = True
    Me.Close()
  End Function

  '设置控件默认值 
  Private Sub SetDefaultValue()
    Dim ctl As System.Windows.Forms.Control

    If m_dmCooperation Is Nothing Then
      For Each ctl In Controls
        If TypeOf ctl Is System.Windows.Forms.TextBox Then
          ctl.Text = ""
        End If
      Next ctl
    Else
      With m_dmCooperation
        txtCoopMsg.Text = .Remark
        dtpCoopDate.Value = .CooperateDate
        ctbSatisfaction.Value = .Satisfaction
      End With
    End If

  End Sub

  '检测输入有效性 
  Private Function CheckValid() As Boolean
    If txtCoopMsg.Text = "" Then
      MsgBox("请填写合作信息", MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation)
      CheckValid = False
    Else
      CheckValid = True
    End If
  End Function

  '保存用户输入到合作信息对象m_dmCooperation 
  Private Sub SaveValue()

    With m_dmCooperation
      .ClientID = m_dmClient.ID
      .ClientName = m_dmClient.Name
      .CooperateDate = dtpCoopDate.Value.Date
      .Satisfaction = ctbSatisfaction.Value
      .Remark = Trim(txtCoopMsg.Text)
    End With

  End Sub


  Private Sub ctbSatisfaction_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ctbSatisfaction.ValueChanged
    ToolTip1.SetToolTip(ctbSatisfaction, ctbSatisfaction.Value)
  End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -