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

📄 vcard.vb

📁 通过串口发送短信的模块,采用vb.net编写
💻 VB
📖 第 1 页 / 共 2 页
字号:
Namespace SMS

    Public Class vCard

        ' Specs can be found at: http://www.imc.org/pdi/pdiproddev.html
        Public Title As String = ""  'Mr., Mrs., Ms., Dr.
        Public FirstName As String = ""
        Public MiddleName As String = ""
        Public LastName As String = ""
        Public Suffix As String = "" 'I, II, Jr., Sr.
        Public FormattedName As String = ""
        Public Nickname As String = ""
        Public Organization As String = ""           ' MS Outlook calls this Company
        Public OrganizationalUnit As String = ""     ' MS Outlook calls this Department
        Public Role As String = ""                    ' MS Outlook calls this the profession
        Public JobTitle As String = ""
        Public Note As String = ""
        Public Birthday As Date

        'Collections
        Public URLs As New vURLs()
        Public Emails As New vEmails()
        Public Telephones As New vTelephones()
        Public Addresses As New vAddresss()

        Public LastModified As Date

        Public Overrides Function ToString() As String
            Dim result As New System.Text.StringBuilder()
            result.AppendFormat("//SCKE2 BEGIN:VCARD{0}", System.Environment.NewLine)
            result.AppendFormat("VERSION:2.1{0}", System.Environment.NewLine)
            result.AppendFormat("N:{0};{1};{2};{3};{4}{5}", LastName, FirstName, MiddleName, Title, Suffix, System.Environment.NewLine)
            If IsNotBlank(FormattedName) Then result.AppendFormat("FN:{0}{1}", FormattedName, System.Environment.NewLine)
            If IsNotBlank(Nickname) Then result.AppendFormat("NICKNAME:{0}{1}", Nickname, System.Environment.NewLine)
            If Birthday > Date.MinValue Then result.AppendFormat("BDAY:{0}{1}", Birthday.ToUniversalTime.ToString("yyyyMMdd"), System.Environment.NewLine)
            If IsNotBlank(Note) Then result.AppendFormat("NOTE;ENCODING=QUOTED-PRINTABLE:{0}{1}", Note.Replace(System.Environment.NewLine, "=0D=0A"), System.Environment.NewLine)
            result.AppendFormat("ORG:{0};{1}{2}", Organization, OrganizationalUnit, System.Environment.NewLine)
            If IsNotBlank(JobTitle) Then result.AppendFormat("TITLE:{0}{1}", JobTitle, System.Environment.NewLine)
            If IsNotBlank(Role) Then result.AppendFormat("ROLE:{0}{1}", Role, System.Environment.NewLine)
            result.Append(Emails.ToString())
            result.Append(Telephones.ToString())
            result.Append(URLs.ToString())
            result.Append(Addresses.ToString())
            result.AppendFormat("REV:{0}{1}", LastModified.ToUniversalTime.ToString("yyyyMMdd\THHmmss\Z"), System.Environment.NewLine)
            result.AppendFormat("END:VCARD{0}", System.Environment.NewLine)
            Return result.ToString
        End Function

        Public Class vEmails
            ' The first thing to do when building a CollectionBase class is to inherit from System.Collections.CollectionBase
            Inherits System.Collections.CollectionBase

            Public Overloads Function Add(ByVal Value As vEmail) As vEmail
                ' After you inherit the CollectionBase class, you can access an intrinsic object
                ' called InnerList that represents your collection. InnerList is of type ArrayList.
                If Value.Preferred Then
                    Dim item As vEmail
                    For Each item In Me.InnerList
                        item.Preferred = False
                    Next
                End If
                Me.InnerList.Add(Value)
                Return Value
            End Function

            Public Overloads Function Item(ByVal Index As Integer) As vEmail
                ' To retrieve an item from the InnerList, pass the index of that item to the .Item property.
                Return CType(Me.InnerList.Item(Index), vEmail)
            End Function

            Public Overloads Sub Remove(ByVal Index As Integer)
                ' This Remove expects an index.
                Dim cust As vEmail

                cust = CType(Me.InnerList.Item(Index), vEmail)
                If Not cust Is Nothing Then
                    Me.InnerList.Remove(cust)
                End If
            End Sub

            Public Overrides Function ToString() As String
                Dim result As New System.Text.StringBuilder()
                Dim item As vEmail
                For Each item In Me.InnerList
                    result.AppendFormat("{0}", item.ToString)
                Next
                Return result.ToString
            End Function
        End Class

        Public Class vEmail
            Public Preferred As Boolean
            Public EmailAddress As String = ""
            Public Type As String = "INTERNET"

            Public Sub New(ByVal Email As String)
                EmailAddress = Email
            End Sub

            Public Sub New(ByVal Email As String, ByVal IsPreferred As Boolean)
                EmailAddress = Email
                Preferred = IsPreferred
            End Sub

            Public Overrides Function ToString() As String
                Dim result As New System.Text.StringBuilder()
                result.Append("EMAIL")
                If Preferred Then result.Append(";PREF")
                result.AppendFormat(";{0}", Type.ToUpper)
                result.AppendFormat(":{0}{1}", EmailAddress, System.Environment.NewLine)
                Return result.ToString
            End Function
        End Class

        Public Class vURLs
            ' The first thing to do when building a CollectionBase class is to inherit from System.Collections.CollectionBase
            Inherits System.Collections.CollectionBase

            Public Overloads Function Add(ByVal Value As vURL) As vURL
                ' After you inherit the CollectionBase class, you can access an intrinsic object
                ' called InnerList that represents your collection. InnerList is of type ArrayList.
                If Value.Preferred Then
                    Dim item As vURL
                    For Each item In Me.InnerList
                        Value.Preferred = False
                    Next
                End If
                Me.InnerList.Add(Value)
                Return Value
            End Function

            Public Overloads Function Item(ByVal Index As Integer) As vURL
                ' To retrieve an item from the InnerList, pass the index of that item to the .Item property.
                Return CType(Me.InnerList.Item(Index), vURL)
            End Function

            Public Overloads Sub Remove(ByVal Index As Integer)
                ' This Remove expects an index.
                Dim cust As vURL

                cust = CType(Me.InnerList.Item(Index), vURL)
                If Not cust Is Nothing Then
                    Me.InnerList.Remove(cust)
                End If
            End Sub

            Public Overrides Function ToString() As String
                Dim result As New System.Text.StringBuilder()
                Dim item As vURL
                For Each item In Me.InnerList
                    result.AppendFormat("{0}", item.ToString)
                Next
                Return result.ToString
            End Function
        End Class

        Public Class vURL
            Public Preferred As Boolean
            Public URL As String = ""
            Public Location As vLocations = vLocations.WORK       'MS Outlook shows the WORK location on the contact form front page

            Public Sub New(ByVal NewURL As String)
                URL = NewURL
            End Sub

            Public Sub New(ByVal NewURL As String, ByVal IsPreffered As Boolean)
                URL = NewURL
                Preferred = IsPreffered
            End Sub

            Public Overrides Function ToString() As String
                Dim result As New System.Text.StringBuilder()
                result.Append("URL")
                If Preferred Then result.Append(";PREF")
                If Not IsNothing(Location) Then result.AppendFormat(";{0}", Location.ToString.ToUpper)
                result.AppendFormat(":{0}{1}", URL, System.Environment.NewLine)
                Return result.ToString
            End Function
        End Class

        Public Class vTelephones
            ' The first thing to do when building a CollectionBase class is to inherit from System.Collections.CollectionBase
            Inherits System.Collections.CollectionBase

⌨️ 快捷键说明

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