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

📄 managercontact.vb

📁 用GSM模块发送短信,是个发送短信的平台
💻 VB
字号:
Imports System.Collections.Generic
Imports System.Text
Imports System.Text.RegularExpressions
Public Class ManagerContact

    Private Sub ManagerContact_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            '绑定分组下拉框
            Bind_groupCombobox()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' 绑定分组
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Bind_groupCombobox()
        Try
            groupCombobox.DisplayMember = "GroupName"
            groupCombobox.ValueMember = "ID"
            groupCombobox.DataSource = FriendGroupClass.GetAllFriendGroup()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "错误")
        End Try
    End Sub

    ''' <summary>
    ''' 绑定联系人
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Bind_contactList(ByVal groupID As Integer)
        Try
            Dim result As System.Collections.Generic.List(Of AddressBook) = AddressBook.GetAddressbookByGroupId(groupID)
            contactList.DataSource = result
            contactList.DisplayMember = "FriendName"
            contactList.ValueMember = "ID"
        Catch ex As Exception
            MessageBox.Show(ex.Message, "错误")
        End Try
    End Sub

    Private Sub groupCombobox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles groupCombobox.SelectedIndexChanged

        Try
            Bind_contactList(CType(groupCombobox.SelectedValue, Integer))
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        If (contactList.SelectedIndex > -1) Then
            Dim contactId As Integer = CType(contactList.SelectedValue, Integer)
            Dim entry As AddressBook = AddressBook.GetAddressbookById(contactId)
            If (entry IsNot Nothing) Then

                '绑定所属分组
                Bind_txtFriendGroupId()

                txtFriendName.Text = entry.FriendName
                txtTEL.Text = entry.TEL
                txtMobilePhone.Text = entry.MobilePhone
                txtEmail.Text = entry.Email
                txtAddress.Text = entry.Address
                txtFriendGroupId.SelectedValue = entry.FriendGroupId

            End If
        End If
    End Sub

    ''' <summary>
    ''' 绑定所属分组
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Bind_txtFriendGroupId()
        Try
            txtFriendGroupId.DisplayMember = "GroupName"
            txtFriendGroupId.ValueMember = "ID"
            txtFriendGroupId.DataSource = FriendGroupClass.GetAllFriendGroup()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "错误")
        End Try
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Try

            Dim FriendName As String = txtFriendName.Text.Trim()
            If (String.IsNullOrEmpty(FriendName)) Then
                MessageBox.Show("姓名必须填写", "提示")
                Exit Sub
            End If

            Dim MobilePhone As String = txtMobilePhone.Text.Trim()
            If (String.IsNullOrEmpty(MobilePhone)) Then
                MessageBox.Show("手机号码必须填写", "提示")
                Exit Sub
            End If

            Dim FriendGroupId As Integer = txtFriendGroupId.SelectedIndex
            If (FriendGroupId = -1) Then
                MessageBox.Show("请选择所属分组", "提示")
                Exit Sub
            End If

            'Dim strExpress As String = "^(13[0-9]|15[0|3|6|8|9])\d{8}$"
            'If (Regex.IsMatch(MobilePhone, strExpress) = False) Then
            '    MessageBox.Show("手机号码格式错误", "提示")
            '    Exit Sub
            'End If

            Dim entry As AddressBook = New AddressBook()
            entry.FriendName = FriendName
            entry.TEL = IIf(String.IsNullOrEmpty(txtTEL.Text.Trim()), Nothing, txtTEL.Text.Trim())
            entry.MobilePhone = MobilePhone
            entry.Email = IIf(String.IsNullOrEmpty(txtEmail.Text.Trim()), Nothing, txtEmail.Text.Trim())
            entry.Address = IIf(String.IsNullOrEmpty(txtAddress.Text.Trim()), Nothing, txtAddress.Text.Trim())
            entry.FriendGroupId = txtFriendGroupId.SelectedValue
            entry.ID = CType(contactList.SelectedValue, Integer)

            If (AddressBook.UpdateAddressbook(entry)) Then
                MessageBox.Show("保存成功", "修改联系人信息")
            Else
                MessageBox.Show("修改信息失败", "修改联系人信息")
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, "错误")
        End Try

    End Sub

    ''' <summary>
    ''' 删除联系人
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnDeleteContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteContact.Click
        Try
            If (contactList.SelectedIndex > -1) Then

                Dim result As DialogResult = MessageBox.Show("确定要删除联系人吗?", "删除联系人", MessageBoxButtons.YesNo)
                If (result = Windows.Forms.DialogResult.Yes) Then

                    Dim contactId As Integer = CType(contactList.SelectedValue, Integer)
                    If (AddressBook.DeleteContact(contactId)) Then

                        '清除修改区域中的数据

                        txtFriendName.Text = String.Empty
                        txtTEL.Text = String.Empty
                        txtMobilePhone.Text = String.Empty
                        txtEmail.Text = String.Empty
                        txtAddress.Text = String.Empty
                        txtFriendGroupId.SelectedIndex = -1

                        MessageBox.Show("删除联系人成功", "删除联系人")
                    Else
                        MessageBox.Show("删除联系人失败", "删除联系人")
                    End If
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "错误")
        End Try
    End Sub
End Class

⌨️ 快捷键说明

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