Advertisement
PiToLoKo

Untitled

Jun 30th, 2014
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 28.43 KB | None | 0 0
  1.  
  2.     #Region " Contacts "
  3.      
  4.     #Region " Examples (Normal usage)"
  5.      
  6.     ' Create a new list of contacts
  7.     ' Dim Contacts As List(Of Contact) = New List(Of Contact)
  8.     ' Or load ContactList from previous serialized file
  9.     ' Dim Contacts As List(Of Contact) = ContactSerializer.Deserialize("C:\Contacts.bin")
  10.      
  11.     ' Set a variable to store the current contact position
  12.     ' Dim CurrentPosition As Integer = 0
  13.      
  14.     ' Create a new contact
  15.     ' Dim CurrentContact As Contact = New Contact With { _
  16.     '     .Name = "Manolo", _
  17.     '     .Surname = "El del Bombo", _
  18.     '     .Country = "Spain", _
  19.     '     .City = "Valencia", _
  20.     '     .Street = "Av. Mestalla", _
  21.     '     .ZipCode = "42731", _
  22.     '     .Phone = "96.XXX.XX.XX", _
  23.     '     .CellPhone = "651.XXX.XXX", _
  24.     '     .Email = "ManoloToLoko@Gmail.com"}
  25.      
  26.     ' Add a contact to contacts list
  27.     ' Contacts.Add(CurrentContact)
  28.      
  29.     ' Update the CurrentPosition index value
  30.     ' CurrentPosition = Contacts.IndexOf(CurrentContact)
  31.      
  32.     #End Region
  33.      
  34.     #Region " Examples (Generic functions) "
  35.      
  36.      
  37.     ' Examples:
  38.     '
  39.     ' -----------------
  40.     ' Add a new contact
  41.     ' -----------------
  42.     ' Contact.Add_Contact(ContactList, "Manolo", "El del Bombo", "Spain", "Valencia", "Av. Mestalla", "42731", "96.XXX.XX.XX", "651.XXX.XXX", "ManoloToLoko@Gmail.com")
  43.     '
  44.     '
  45.     ' -----------------------------------------------------------------
  46.     ' Load a contact from an existing contacts list into TextBox Fields
  47.     ' -----------------------------------------------------------------
  48.     ' Contact.Load_Contact(ContactList, 0, TextBox_Name, textbox_surName, TextBox_Country, textbox_City, TextBox_Street, TextBox_ZipCode, TextBox_Phone, TextBox_CellPhone, TextBox_email)
  49.     '
  50.     '
  51.     ' ----------------------------------
  52.     ' Load a contact into TextBox Fields
  53.     ' ----------------------------------
  54.     ' Contact.Load_Contact(Contact, TextBox_Name, textbox_surName, TextBox_Country, textbox_City, TextBox_Street, TextBox_ZipCode, TextBox_Phone, TextBox_CellPhone, TextBox_email)
  55.     '
  56.     '
  57.     ' ---------------------------------
  58.     ' Load a contact list into ListView
  59.     ' ---------------------------------
  60.     ' Contact.Load_ContactList_Into_ListView(ContactList, ListView1)
  61.     '
  62.     '
  63.     ' -------------------------------------
  64.     ' Load a contact list into DataGrivView
  65.     ' -------------------------------------
  66.     ' Contact.Load_ContactList_Into_DataGrivView(ContactList, DataGrivView1)
  67.     '
  68.     '
  69.     ' -------------------------------------------
  70.     ' Load a contacts list from a serialized file
  71.     ' -------------------------------------------
  72.     ' Dim ContactList As List(Of Contact) = Contact.Load_ContactList("C:\Contacts.bin")
  73.     '
  74.     '
  75.     ' -----------------------------------------------------------------------
  76.     ' Find the first occurrence of a contact name in a existing contacts list
  77.     ' -----------------------------------------------------------------------
  78.     ' Dim ContactFound As Contact = Contact.Match_Contact_Name_FirstOccurrence(ContactList, "Manolo")
  79.     '
  80.     '
  81.     ' ----------------------------------------------------------------------
  82.     ' Find all the occurrences of a contact name in a existing contacts list
  83.     ' ----------------------------------------------------------------------
  84.     ' Dim ContactsFound As List(Of Contact) = Contact.Match_Contact_Name(ContactList, "Manolo")
  85.     '
  86.     '
  87.     ' -------------------------------------------------------------
  88.     ' Remove a contact from a Contact List giving the contact index
  89.     ' -------------------------------------------------------------
  90.     ' Remove_Contact(ContactList, 0)
  91.     '
  92.     '
  93.     ' -------------------------------------------------------
  94.     ' Remove a contact from a Contact List giving the contact
  95.     ' -------------------------------------------------------
  96.     ' Remove_Contact(ContactList, MyContact)
  97.     '
  98.     '
  99.     ' -------------------------
  100.     ' Save the contacts to file
  101.     ' -------------------------
  102.     ' Contact.Save_ContactList(ContactList, "C:\Contacts.bin")
  103.     '
  104.     '
  105.     ' -------------------------
  106.     ' Sort the contacts by name
  107.     ' -------------------------
  108.     ' Dim SorteredContacts As List(Of Contact) = Contact.Sort_ContactList_By_Name(ContactList, Contact.ContactSortMode.Ascending)
  109.     '
  110.     '
  111.     ' --------------------------------------------------------------------
  112.     ' Get a formatted string containing the details of an existing contact
  113.     ' --------------------------------------------------------------------
  114.     ' MsgBox(Contact.Get_Contact_Details(ContactList, 0))
  115.     ' MsgBox(Contact.Get_Contact_Details(CurrentContact))
  116.     '    
  117.     '
  118.     ' ----------------------------------------------------------------------------------
  119.     ' Copy to clipboard a formatted string containing the details of an existing contact
  120.     ' ----------------------------------------------------------------------------------
  121.     ' Contact.Copy_Contact_Details_To_Clipboard(ContactList, 0)
  122.     ' Contact.Copy_Contact_Details_To_Clipboard(CurrentContact)
  123.      
  124.      
  125.     #End Region
  126.      
  127.     <Serializable()> _
  128.     Public Class Contact
  129.      
  130.        Public Enum ContactSortMode As Short
  131.            Ascending = 0
  132.            Descending = 1
  133.        End Enum
  134.      
  135.     #Region "Member Variables"
  136.      
  137.        Private mId As System.Guid = Nothing
  138.        Private mName As String = String.Empty
  139.        Private mSurname As String = String.Empty
  140.        Private mCountry As String = String.Empty
  141.        Private mCity As String = String.Empty
  142.        Private mStreet As String = String.Empty
  143.        Private mZip As String = String.Empty
  144.        Private mPhone As String = String.Empty
  145.        Private mCellPhone As String = String.Empty
  146.        Private mEmail As String = String.Empty
  147.      
  148.     #End Region
  149.      
  150.     #Region "Constructor"
  151.      
  152.        Public Sub New()
  153.            mId = Guid.NewGuid()
  154.        End Sub
  155.      
  156.      
  157.        Public Sub New(ByVal ID As System.Guid)
  158.            mId = ID
  159.        End Sub
  160.      
  161.     #End Region
  162.      
  163.     #Region "Properties"
  164.      
  165.        Public Property Name() As String
  166.            Get
  167.                Return mName
  168.            End Get
  169.            Set(ByVal value As String)
  170.                mName = value
  171.            End Set
  172.        End Property
  173.      
  174.        Public Property Surname() As String
  175.            Get
  176.                Return mSurname
  177.            End Get
  178.            Set(ByVal value As String)
  179.                mSurname = value
  180.            End Set
  181.        End Property
  182.      
  183.        Public Property Street() As String
  184.            Get
  185.                Return mStreet
  186.            End Get
  187.            Set(ByVal value As String)
  188.                mStreet = value
  189.            End Set
  190.        End Property
  191.      
  192.        Public Property City() As String
  193.            Get
  194.                Return mCity
  195.            End Get
  196.            Set(ByVal value As String)
  197.                mCity = value
  198.            End Set
  199.        End Property
  200.      
  201.        Public Property Country() As String
  202.            Get
  203.                Return mCountry
  204.            End Get
  205.            Set(ByVal value As String)
  206.                mCountry = value
  207.            End Set
  208.        End Property
  209.      
  210.        Public Property ZipCode() As String
  211.            Get
  212.                Return mZip
  213.            End Get
  214.            Set(ByVal value As String)
  215.                mZip = value
  216.            End Set
  217.        End Property
  218.      
  219.        Public Property Email() As String
  220.            Get
  221.                Return mEmail
  222.            End Get
  223.            Set(ByVal value As String)
  224.                mEmail = value
  225.            End Set
  226.        End Property
  227.      
  228.        Public Property Phone() As String
  229.            Get
  230.                Return mPhone
  231.            End Get
  232.            Set(ByVal value As String)
  233.                mPhone = value
  234.            End Set
  235.        End Property
  236.      
  237.        Public Property CellPhone() As String
  238.            Get
  239.                Return mCellPhone
  240.            End Get
  241.            Set(ByVal value As String)
  242.                mCellPhone = value
  243.            End Set
  244.        End Property
  245.      
  246.     #End Region
  247.      
  248.     #Region " ContactSerializer "
  249.      
  250.        Public Class ContactSerializer
  251.      
  252.            ''' <summary>
  253.            ''' Serialize a contact list into a contacts file.
  254.            ''' </summary>
  255.            ''' <param name="ContactList"></param>
  256.            ''' <param name="FilePath"></param>
  257.            ''' <remarks></remarks>
  258.            Public Shared Sub Save(ByVal ContactList As List(Of Contact), _
  259.                                        ByVal FilePath As String)
  260.      
  261.                Dim fs As IO.FileStream = Nothing
  262.                Dim formatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
  263.      
  264.                Try
  265.                    fs = New IO.FileStream(FilePath, IO.FileMode.OpenOrCreate)
  266.                    formatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
  267.                    formatter.Serialize(fs, ContactList)
  268.      
  269.                Catch ex As Exception
  270.      
  271.                    MessageBox.Show(String.Format("{0}:{1}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace), _
  272.                                    "Error", _
  273.                                    MessageBoxButtons.OK, _
  274.                                    MessageBoxIcon.Error)
  275.      
  276.                Finally
  277.                    If fs IsNot Nothing Then fs.Dispose()
  278.      
  279.                End Try
  280.      
  281.            End Sub
  282.      
  283.            ''' <summary>
  284.            ''' Deserialize an existing file into a contact list.
  285.            ''' </summary>
  286.            ''' <param name="FilePath"></param>
  287.            ''' <returns></returns>
  288.            ''' <remarks></remarks>
  289.            Public Shared Function Load(ByVal FilePath As String) As List(Of Contact)
  290.      
  291.                Dim fs As IO.FileStream = Nothing
  292.                Dim formatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
  293.      
  294.                Try
  295.                    fs = New IO.FileStream(FilePath, IO.FileMode.Open)
  296.                    formatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
  297.                    Return formatter.Deserialize(fs)
  298.      
  299.                Catch ex As Exception
  300.      
  301.                    MessageBox.Show(String.Format("{0}:{1}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace), _
  302.                                    "Error", _
  303.                                    MessageBoxButtons.OK, _
  304.                                    MessageBoxIcon.Error)
  305.                    Return Nothing
  306.      
  307.                Finally
  308.                    If fs IsNot Nothing Then fs.Dispose()
  309.      
  310.                End Try
  311.      
  312.            End Function
  313.      
  314.        End Class
  315.      
  316.     #End Region
  317.      
  318.     #Region " Generic Functions "
  319.      
  320.        ' Formatted String of contact detailed information
  321.        Shared ReadOnly DetailsFormat As String = _
  322.        "Name.....: {1}{0}Surname..: {2}{0}Country..: {3}{0}City.....: {4}{0}Street...: {5}{0}Zipcode..: {6}{0}Phone....: {7}{0}CellPhone: {8}{0}Email....: {9}"
  323.      
  324.        ''' <summary>
  325.        ''' Add a new contact into a existing contacts list.
  326.        ''' </summary>
  327.        Public Shared Sub Add_Contact(ByVal ContactList As List(Of Contact), _
  328.                               ByVal Name As String, _
  329.                               ByVal Surname As String, _
  330.                               ByVal Country As String, _
  331.                               ByVal City As String, _
  332.                               ByVal Street As String, _
  333.                               ByVal ZipCode As String, _
  334.                               ByVal Phone As String, _
  335.                               ByVal CellPhone As String, _
  336.                               ByVal Email As String)
  337.      
  338.            ContactList.Add(New Contact With { _
  339.                            .Name = Name, _
  340.                            .Surname = Surname, _
  341.                            .Country = Country, _
  342.                            .City = City, _
  343.                            .Street = Street, _
  344.                            .ZipCode = ZipCode, _
  345.                            .Phone = Phone, _
  346.                            .CellPhone = CellPhone, _
  347.                            .Email = Email _
  348.                        })
  349.      
  350.        End Sub
  351.      
  352.        ''' <summary>
  353.        ''' Remove a contact from an existing contacts list.
  354.        ''' </summary>
  355.        Public Shared Sub Remove_Contact(ByVal ContactList As List(Of Contact), ByVal ContactIndex As Integer)
  356.            ContactList.RemoveAt(ContactIndex)
  357.        End Sub
  358.      
  359.        ''' <summary>
  360.        ''' Remove a contact from an existing contacts list.
  361.        ''' </summary>
  362.        Public Shared Sub Remove_Contact(ByVal ContactList As List(Of Contact), ByVal Contact As Contact)
  363.            ContactList.Remove(Contact)
  364.        End Sub
  365.      
  366.        ''' <summary>
  367.        ''' Find the first occurrence of a contact name in an existing contacts list.
  368.        ''' </summary>
  369.        Public Shared Function Match_Contact_Name_FirstOccurrence(ByVal ContactList As List(Of Contact), ByVal Name As String) As Contact
  370.      
  371.            Return ContactList.Find(Function(contact) contact.Name.ToLower.StartsWith(Name.ToLower) _
  372.                                    OrElse contact.Name.ToLower.Contains(Name.ToLower))
  373.        End Function
  374.      
  375.        ''' <summary>
  376.        ''' Find all the occurrences of a contact name in a existing contacts list.
  377.        ''' </summary>
  378.        Public Shared Function Match_Contact_Name(ByVal ContactList As List(Of Contact), ByVal Name As String) As List(Of Contact)
  379.      
  380.            Return ContactList.FindAll(Function(contact) contact.Name.ToLower.StartsWith(Name.ToLower) _
  381.                                       OrElse contact.Name.ToLower.Contains(Name.ToLower))
  382.      
  383.        End Function
  384.      
  385.        ''' <summary>
  386.        ''' Load a contact from an existing contacts list into textbox fields.
  387.        ''' </summary>
  388.        Public Shared Sub Load_Contact(ByVal ContactList As List(Of Contact), _
  389.                                ByVal ContactIndex As Integer, _
  390.                                ByVal TextBox_Name As TextBox, _
  391.                                ByVal TextBox_Surname As TextBox, _
  392.                                ByVal TextBox_Country As TextBox, _
  393.                                ByVal TextBox_City As TextBox, _
  394.                                ByVal TextBox_Street As TextBox, _
  395.                                ByVal TextBox_Zipcode As TextBox, _
  396.                                ByVal TextBox_Phone As TextBox, _
  397.                                ByVal TextBox_CellPhone As TextBox, _
  398.                                ByVal TextBox_Email As TextBox)
  399.      
  400.            TextBox_Name.Text = ContactList.Item(ContactIndex).Name
  401.            TextBox_Surname.Text = ContactList.Item(ContactIndex).Surname
  402.            TextBox_Country.Text = ContactList.Item(ContactIndex).Country
  403.            TextBox_City.Text = ContactList.Item(ContactIndex).City
  404.            TextBox_Street.Text = ContactList.Item(ContactIndex).Street
  405.            TextBox_Zipcode.Text = ContactList.Item(ContactIndex).ZipCode
  406.            TextBox_Phone.Text = ContactList.Item(ContactIndex).Phone
  407.            TextBox_CellPhone.Text = ContactList.Item(ContactIndex).CellPhone
  408.            TextBox_Email.Text = ContactList.Item(ContactIndex).Email
  409.      
  410.        End Sub
  411.      
  412.        ''' <summary>
  413.        ''' Load a contact into textbox fields.
  414.        ''' </summary>
  415.        Public Shared Sub Load_Contact(ByVal Contact As Contact, _
  416.                                ByVal TextBox_Name As TextBox, _
  417.                                ByVal TextBox_Surname As TextBox, _
  418.                                ByVal TextBox_Country As TextBox, _
  419.                                ByVal TextBox_City As TextBox, _
  420.                                ByVal TextBox_Street As TextBox, _
  421.                                ByVal TextBox_Zipcode As TextBox, _
  422.                                ByVal TextBox_Phone As TextBox, _
  423.                                ByVal TextBox_CellPhone As TextBox, _
  424.                                ByVal TextBox_Email As TextBox)
  425.      
  426.            TextBox_Name.Text = Contact.Name
  427.            TextBox_Surname.Text = Contact.Surname
  428.            TextBox_Country.Text = Contact.Country
  429.            TextBox_City.Text = Contact.City
  430.            TextBox_Street.Text = Contact.Street
  431.            TextBox_Zipcode.Text = Contact.ZipCode
  432.            TextBox_Phone.Text = Contact.Phone
  433.            TextBox_CellPhone.Text = Contact.CellPhone
  434.            TextBox_Email.Text = Contact.Email
  435.      
  436.        End Sub
  437.      
  438.        ''' <summary>
  439.        ''' Seriale a contacts list to a file.
  440.        ''' </summary>
  441.        Public Shared Sub Save_ContactList(ByVal ContactList As List(Of Contact), ByVal FilePath As String)
  442.      
  443.            Contact.ContactSerializer.Save(ContactList, FilePath)
  444.      
  445.        End Sub
  446.      
  447.        ''' <summary>
  448.        ''' Load a contacts list from a serialized file.
  449.        ''' </summary>
  450.        Public Shared Function Load_ContactList(ByVal FilePath As String) As List(Of Contact)
  451.      
  452.            Return Contact.ContactSerializer.Load(FilePath)
  453.      
  454.        End Function
  455.      
  456.        ''' <summary>
  457.        ''' Reorder the contacts of a Contacts List by the Name field.
  458.        ''' </summary>
  459.        Public Shared Function Sort_ContactList_By_Name(ByVal ContactList As List(Of Contact), _
  460.                                                  ByVal ContactSortMode As Contact.ContactSortMode) As List(Of Contact)
  461.      
  462.            Return If(ContactSortMode = Contact.ContactSortMode.Ascending, _
  463.                      ContactList.OrderBy(Function(contact) contact.Name).ToList(), _
  464.                      ContactList.OrderByDescending(Function(contact) contact.Name).ToList())
  465.      
  466.        End Function
  467.      
  468.        ''' <summary>
  469.        ''' Reorder the contacts of a Contacts List by the Surname field.
  470.        ''' </summary>
  471.        Public Shared Function Sort_ContactList_By_Surname(ByVal ContactList As List(Of Contact), _
  472.                                                     ByVal ContactSortMode As Contact.ContactSortMode) As List(Of Contact)
  473.      
  474.            Return If(ContactSortMode = Contact.ContactSortMode.Ascending, _
  475.                      ContactList.OrderBy(Function(contact) contact.Surname).ToList(), _
  476.                      ContactList.OrderByDescending(Function(contact) contact.Surname).ToList())
  477.      
  478.        End Function
  479.      
  480.        ''' <summary>
  481.        ''' Reorder the contacts of a Contacts List by the Country field.
  482.        ''' </summary>
  483.        Public Shared Function Sort_ContactList_By_Country(ByVal ContactList As List(Of Contact), _
  484.                                                     ByVal ContactSortMode As Contact.ContactSortMode) As List(Of Contact)
  485.      
  486.            Return If(ContactSortMode = Contact.ContactSortMode.Ascending, _
  487.                      ContactList.OrderBy(Function(contact) contact.Country).ToList(), _
  488.                      ContactList.OrderByDescending(Function(contact) contact.Country).ToList())
  489.      
  490.        End Function
  491.      
  492.        ''' <summary>
  493.        ''' Reorder the contacts of a Contacts List by the City field.
  494.        ''' </summary>
  495.        Public Shared Function Sort_ContactList_By_City(ByVal ContactList As List(Of Contact), _
  496.                                                  ByVal ContactSortMode As Contact.ContactSortMode) As List(Of Contact)
  497.      
  498.            Return If(ContactSortMode = Contact.ContactSortMode.Ascending, _
  499.                      ContactList.OrderBy(Function(contact) contact.City).ToList(), _
  500.                      ContactList.OrderByDescending(Function(contact) contact.City).ToList())
  501.      
  502.        End Function
  503.      
  504.        ''' <summary>
  505.        ''' Reorder the contacts of a Contacts List by the Street field.
  506.        ''' </summary>
  507.        Public Shared Function Sort_ContactList_By_Street(ByVal ContactList As List(Of Contact), _
  508.                                                    ByVal ContactSortMode As Contact.ContactSortMode) As List(Of Contact)
  509.      
  510.            Return If(ContactSortMode = Contact.ContactSortMode.Ascending, _
  511.                      ContactList.OrderBy(Function(contact) contact.Street).ToList(), _
  512.                      ContactList.OrderByDescending(Function(contact) contact.Street).ToList())
  513.      
  514.        End Function
  515.      
  516.        ''' <summary>
  517.        ''' Reorder the contacts of a Contacts List by the Zipcode field.
  518.        ''' </summary>
  519.        Public Shared Function Sort_ContactList_By_Zipcode(ByVal ContactList As List(Of Contact), _
  520.                                                     ByVal ContactSortMode As Contact.ContactSortMode) As List(Of Contact)
  521.      
  522.            Return If(ContactSortMode = Contact.ContactSortMode.Ascending, _
  523.                      ContactList.OrderBy(Function(contact) contact.ZipCode).ToList(), _
  524.                      ContactList.OrderByDescending(Function(contact) contact.ZipCode).ToList())
  525.      
  526.        End Function
  527.      
  528.        ''' <summary>
  529.        ''' Reorder the contacts of a Contacts List by the Phone field.
  530.        ''' </summary>
  531.        Public Shared Function Sort_ContactList_By_Phone(ByVal ContactList As List(Of Contact), _
  532.                                                   ByVal ContactSortMode As Contact.ContactSortMode) As List(Of Contact)
  533.      
  534.            Return If(ContactSortMode = Contact.ContactSortMode.Ascending, _
  535.                      ContactList.OrderBy(Function(contact) contact.Phone).ToList(), _
  536.                      ContactList.OrderByDescending(Function(contact) contact.Phone).ToList())
  537.      
  538.        End Function
  539.      
  540.        ''' <summary>
  541.        ''' Reorder the contacts of a Contacts List by the CellPhone field.
  542.        ''' </summary>
  543.        Public Shared Function Sort_ContactList_By_CellPhone(ByVal ContactList As List(Of Contact), _
  544.                                                       ByVal ContactSortMode As Contact.ContactSortMode) As List(Of Contact)
  545.      
  546.            Return If(ContactSortMode = Contact.ContactSortMode.Ascending, _
  547.                      ContactList.OrderBy(Function(contact) contact.CellPhone).ToList(), _
  548.                      ContactList.OrderByDescending(Function(contact) contact.CellPhone).ToList())
  549.      
  550.        End Function
  551.      
  552.        ''' <summary>
  553.        ''' Reorder the contacts of a Contacts List by the Email field.
  554.        ''' </summary>
  555.        Public Shared Function Sort_ContactList_By_Email(ByVal ContactList As List(Of Contact), _
  556.                                                   ByVal ContactSortMode As Contact.ContactSortMode) As List(Of Contact)
  557.      
  558.            Return If(ContactSortMode = Contact.ContactSortMode.Ascending, _
  559.                      ContactList.OrderBy(Function(contact) contact.Email).ToList(), _
  560.                      ContactList.OrderByDescending(Function(contact) contact.Email).ToList())
  561.      
  562.        End Function
  563.      
  564.        ''' <summary>
  565.        ''' Get a formatted string containing the details of an existing contact.
  566.        ''' </summary>
  567.        Public Shared Function Get_Contact_Details(ByVal ContactList As List(Of Contact), ByVal ContactIndex As Integer) As String
  568.      
  569.            Return String.Format(DetailsFormat, _
  570.                                 Environment.NewLine, _
  571.                                 ContactList.Item(ContactIndex).Name, _
  572.                                 ContactList.Item(ContactIndex).Surname, _
  573.                                 ContactList.Item(ContactIndex).Country, _
  574.                                 ContactList.Item(ContactIndex).City, _
  575.                                 ContactList.Item(ContactIndex).Street, _
  576.                                 ContactList.Item(ContactIndex).ZipCode, _
  577.                                 ContactList.Item(ContactIndex).Phone, _
  578.                                 ContactList.Item(ContactIndex).CellPhone, _
  579.                                 ContactList.Item(ContactIndex).Email)
  580.      
  581.        End Function
  582.      
  583.        ''' <summary>
  584.        ''' Get a formatted string containing the details of an existing contact.
  585.        ''' </summary>
  586.        Public Shared Function Get_Contact_Details(ByVal Contact As Contact) As String
  587.      
  588.            Return String.Format(DetailsFormat, _
  589.                                 Environment.NewLine, _
  590.                                 Contact.Name, _
  591.                                 Contact.Surname, _
  592.                                 Contact.Country, _
  593.                                 Contact.City, _
  594.                                 Contact.Street, _
  595.                                 Contact.ZipCode, _
  596.                                 Contact.Phone, _
  597.                                 Contact.CellPhone, _
  598.                                 Contact.Email)
  599.      
  600.        End Function
  601.      
  602.        ''' <summary>
  603.        ''' Copy to clipboard a formatted string containing the details of an existing contact.
  604.        ''' </summary>
  605.        Public Shared Sub Copy_Contact_Details_To_Clipboard(ByVal ContactList As List(Of Contact), ByVal ContactIndex As Integer)
  606.      
  607.            Clipboard.SetText(String.Format(DetailsFormat, _
  608.                              Environment.NewLine, _
  609.                              ContactList.Item(ContactIndex).Name, _
  610.                              ContactList.Item(ContactIndex).Surname, _
  611.                              ContactList.Item(ContactIndex).Country, _
  612.                              ContactList.Item(ContactIndex).City, _
  613.                              ContactList.Item(ContactIndex).Street, _
  614.                              ContactList.Item(ContactIndex).ZipCode, _
  615.                              ContactList.Item(ContactIndex).Phone, _
  616.                              ContactList.Item(ContactIndex).CellPhone, _
  617.                              ContactList.Item(ContactIndex).Email))
  618.      
  619.        End Sub
  620.      
  621.        ''' <summary>
  622.        ''' Copy to clipboard a formatted string containing the details of an existing contact.
  623.        ''' </summary>
  624.        Public Shared Sub Copy_Contact_Details_To_Clipboard(ByVal Contact As Contact)
  625.      
  626.            Clipboard.SetText(String.Format(DetailsFormat, _
  627.                              Environment.NewLine, _
  628.                              Contact.Name, _
  629.                              Contact.Surname, _
  630.                              Contact.Country, _
  631.                              Contact.City, _
  632.                              Contact.Street, _
  633.                              Contact.ZipCode, _
  634.                              Contact.Phone, _
  635.                              Contact.CellPhone, _
  636.                              Contact.Email))
  637.      
  638.        End Sub
  639.      
  640.        ''' <summary>
  641.        ''' Load an existing contacts list into a ListView.
  642.        ''' </summary>
  643.        Public Shared Sub Load_ContactList_Into_ListView(ByVal ContactList As List(Of Contact), _
  644.                                                         ByVal Listview As ListView)
  645.      
  646.            Listview.Items.AddRange( _
  647.                           ContactList _
  648.                           .Select(Function(Contact) _
  649.                                   New ListViewItem(New String() { _
  650.                                                                    Contact.Name, _
  651.                                                                    Contact.Surname, _
  652.                                                                    Contact.Country, _
  653.                                                                    Contact.City, _
  654.                                                                    Contact.Street, _
  655.                                                                    Contact.ZipCode, _
  656.                                                                    Contact.Phone, _
  657.                                                                    Contact.CellPhone, _
  658.                                                                    Contact.Email _
  659.                                                                 })).ToArray())
  660.      
  661.        End Sub
  662.      
  663.        ''' <summary>
  664.        ''' Load an existing contacts list into a DataGridView.
  665.        ''' </summary>
  666.        Public Shared Sub Load_ContactList_Into_DataGridView(ByVal ContactList As List(Of Contact), _
  667.                                                             ByVal DataGridView As DataGridView)
  668.      
  669.            DataGridView.DataSource = ContactList
  670.            ' Sortered:
  671.            ' DataGridView.DataSource = (From Contact In ContactList Order By Contact.Name Ascending Select Contact).ToList
  672.      
  673.        End Sub
  674.      
  675.      
  676.     #End Region
  677.      
  678.     End Class
  679.      
  680.     #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement