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

📄 addcontact.vb

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

Public Class AddContact

    Private groupEntry As FriendGroupClass = Nothing

    Sub New()
        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()
        ' 在 InitializeComponent() 调用之后添加任何初始化。
    End Sub

    Sub New(ByVal group As FriendGroupClass)
        InitializeComponent()
        Me.groupEntry = group
    End Sub

    Private Sub AddContact_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try
            Bind_txtFriendGroupId()
            If (groupEntry IsNot Nothing) Then

                If (Me.txtFriendGroupId.Items.Count > 0) Then
                    Me.txtFriendGroupId.SelectedValue = groupEntry.ID
                End If

            End If
        Catch ex As Exception
            lblmessage.Text = ex.Message
        End Try

    End Sub

    Private Sub Bind_txtFriendGroupId()
        Try
            Dim Result As List(Of FriendGroupClass) = FriendGroupClass.GetAllFriendGroup()
            txtFriendGroupId.DisplayMember = "GroupName"
            txtFriendGroupId.ValueMember = "ID"
            txtFriendGroupId.DataSource = Result
        Catch ex As Exception
            lblmessage.Text = ex.Message
        End Try
    End Sub

    Private Sub btnAddContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddContact.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
            If (AddressBook.InsertAddressBook(entry)) Then
                MessageBox.Show("添加成功", "添加联系人")
            Else
                MessageBox.Show("添加失败", "添加联系人")
            End If

        Catch ex As Exception
            lblmessage.Text = ex.Message
        End Try

    End Sub
End Class

⌨️ 快捷键说明

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