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

📄 addressbook.vb

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

Public Class AddressBook

    Private m_ID As Integer
    Public Property ID() As Integer
        Get
            Return m_ID
        End Get
        Set(ByVal value As Integer)
            m_ID = value
        End Set
    End Property

    Private m_FriendName As String
    Public Property FriendName() As String
        Get
            Return m_FriendName
        End Get
        Set(ByVal value As String)
            m_FriendName = value
        End Set
    End Property


    Private m_TEL As String
    Public Property TEL() As String
        Get
            Return m_TEL
        End Get
        Set(ByVal value As String)
            m_TEL = value
        End Set
    End Property

    Private m_MobilePhone As String
    Public Property MobilePhone() As String
        Get
            Return m_MobilePhone
        End Get
        Set(ByVal value As String)
            m_MobilePhone = value
        End Set
    End Property

    Private m_Email As String
    Public Property Email() As String
        Get
            Return m_Email
        End Get
        Set(ByVal value As String)
            m_Email = value
        End Set
    End Property

    Private m_Address As String
    Public Property Address() As String
        Get
            Return m_Address
        End Get
        Set(ByVal value As String)
            m_Address = value
        End Set
    End Property

    Private m_FriendGroupId As Integer
    Public Property FriendGroupId() As Integer
        Get
            Return m_FriendGroupId
        End Get
        Set(ByVal value As Integer)
            m_FriendGroupId = value
        End Set
    End Property

    Private m_FriendGroupName As String
    Public Property FriendGroupName() As String
        Get
            Return m_FriendGroupName
        End Get
        Set(ByVal value As String)
            m_FriendGroupName = value
        End Set
    End Property

    Private Shared Function GetEntry(ByVal odr As OleDbDataReader) As AddressBook

        Dim entry As AddressBook = New AddressBook()
        Try
            entry.ID = odr.GetInt32(0)
            entry.FriendName = odr.GetString(1)

            If (odr.IsDBNull(2)) Then
                entry.TEL = String.Empty
            Else
                entry.TEL = odr.GetString(2)
            End If

            entry.MobilePhone = odr.GetString(3)

            If (odr.IsDBNull(4)) Then
                entry.Email = String.Empty
            Else
                entry.Email = odr.GetString(4)
            End If

            If (odr.IsDBNull(5)) Then
                entry.Address = String.Empty
            Else
                entry.Address = odr.GetString(5)
            End If

            entry.FriendGroupId = odr.GetInt32(6)
            entry.FriendGroupName = odr.GetString(7)
        Catch ex As Exception
            Throw ex
        End Try
        Return entry

    End Function


    ''' <summary>
    ''' 添加通讯录联系人
    ''' </summary>
    ''' <param name="entry"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function InsertAddressBook(ByRef entry As AddressBook) As Boolean

        Try
            Using conn As OleDbConnection = New OleDbConnection(Common.StrConn)
                Using cmd As OleDbCommand = conn.CreateCommand
                    cmd.CommandText = "insert into addressbook(FriendName,TEL,MobilePhone,Email,Address,FriendGroupId) values(?,?,?,?,?,?)"
                    cmd.Parameters.Add("@FriendName", OleDbType.VarChar).Value = entry.FriendName
                    cmd.Parameters.Add("@TEL", OleDbType.VarChar).Value = IIf(entry.TEL = Nothing, System.DBNull.Value, entry.TEL)
                    cmd.Parameters.Add("@MobilePhone", OleDbType.VarChar).Value = entry.MobilePhone
                    cmd.Parameters.Add("@Email", OleDbType.VarChar).Value = IIf(entry.Email = Nothing, System.DBNull.Value, entry.Email)
                    cmd.Parameters.Add("@Address", OleDbType.VarChar).Value = IIf(entry.Address = Nothing, System.DBNull.Value, entry.Address)
                    cmd.Parameters.Add("@FriendGroupId", OleDbType.Integer).Value = entry.FriendGroupId
                    conn.Open()
                    Return cmd.ExecuteNonQuery() > -1
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try

    End Function

    ''' <summary>
    ''' 删除指定的联系人
    ''' </summary>
    ''' <param name="contactID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function DeleteContact(ByVal contactID As Integer) As Boolean
        Try
            Using conn As OleDbConnection = New OleDbConnection(Common.StrConn)
                Using cmd As OleDbCommand = conn.CreateCommand
                    cmd.CommandText = "delete from addressbook where [id]=?"
                    cmd.Parameters.Add("@id", OleDbType.Integer).Value = contactID
                    conn.Open()
                    Return cmd.ExecuteNonQuery() > -1
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    ''' <summary>
    ''' 更新指定的联系人信息
    ''' </summary>
    ''' <param name="entry"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function UpdateAddressbook(ByRef entry As AddressBook) As Boolean

        Try
            Using conn As OleDbConnection = New OleDbConnection(Common.StrConn)
                Using cmd As OleDbCommand = conn.CreateCommand
                    cmd.CommandText = "update addressbook set FriendName=?,TEL=?,MobilePhone=?,Email=?,Address=?,FriendGroupId=? where [id]=?"
                    cmd.Parameters.Add("@FriendName", OleDbType.VarChar).Value = entry.FriendName
                    cmd.Parameters.Add("@TEL", OleDbType.VarChar).Value = IIf(entry.TEL = Nothing, System.DBNull.Value, entry.TEL)
                    cmd.Parameters.Add("@MobilePhone", OleDbType.VarChar).Value = entry.MobilePhone
                    cmd.Parameters.Add("@Email", OleDbType.VarChar).Value = IIf(entry.Email = Nothing, System.DBNull.Value, entry.Email)
                    cmd.Parameters.Add("@Address", OleDbType.VarChar).Value = IIf(entry.Address = Nothing, System.DBNull.Value, entry.Address)
                    cmd.Parameters.Add("@FriendGroupId", OleDbType.Integer).Value = entry.FriendGroupId
                    cmd.Parameters.Add("@id", OleDbType.Integer).Value = entry.ID
                    conn.Open()
                    Return cmd.ExecuteNonQuery() > -1
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try

    End Function


    ''' <summary>
    ''' 获取指定组的联系人
    ''' </summary>
    ''' <param name="GroupID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetAddressbookByGroupId(ByVal GroupID As Integer) As List(Of AddressBook)

        Dim result As List(Of AddressBook) = New List(Of AddressBook)
        Try
            Using conn As OleDbConnection = New OleDbConnection(Common.StrConn)
                Using cmd As OleDbCommand = conn.CreateCommand()
                    cmd.CommandText = "SELECT ad.*,gr.groupname from addressbook ad inner join friendgroup gr on ad.friendgroupid=gr.[id] where ad.friendgroupid=?"
                    cmd.Parameters.Add("@friendgroupid", OleDbType.Integer).Value = GroupID
                    conn.Open()
                    Using odr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
                        If (odr.HasRows) Then
                            While (odr.Read())
                                result.Add(GetEntry(odr))
                            End While
                        End If
                    End Using
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return result

    End Function

    ''' <summary>
    ''' 获取指定编号的联系人信息
    ''' </summary>
    ''' <param name="contactId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetAddressbookById(ByVal contactId As Integer) As AddressBook

        Dim result As AddressBook = Nothing
        Try
            Using conn As OleDbConnection = New OleDbConnection(Common.StrConn)
                Using cmd As OleDbCommand = conn.CreateCommand()
                    cmd.CommandText = "SELECT ad.*,gr.groupname from addressbook ad inner join friendgroup gr on ad.friendgroupid=gr.[id] where ad.id=?"
                    cmd.Parameters.Add("@friendgroupid", OleDbType.Integer).Value = contactId
                    conn.Open()
                    Using odr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.SingleRow)
                        If (odr.HasRows) Then
                            odr.Read()
                            result = GetEntry(odr)
                        End If
                    End Using
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return result

    End Function



End Class

⌨️ 快捷键说明

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