FormPhoneBook.vb

 Public Class FormPhoneBook


#Region "Objects/Variables"

    Private contact As Contacts = New Contacts()
    Private fullName As String = ""

#End Region

#Region "User's Defined Methods"

    Friend Sub ShowContacts(ByVal showAll As Boolean, ByVal searchString As String)
        Me.contact.ShowData(Me.listView1, Me.linkLabel1, showAll, searchString)
        Me.SetConrols()
    End Sub

    Private Sub ShowData(ByVal sender As Object, ByVal e As EventArgs) Handles conRefresh.Click, btnRefresh.Click
        Me.ShowContacts(True, "")
    End Sub

    Private Sub InsertData(ByVal sender As Object, ByVal e As EventArgs) Handles conAdd.Click, btnAdd.Click
        FormEntry.loadOptions(Me.contact.ID, True)
    End Sub

    Private Sub EditData(ByVal sender As Object, ByVal e As EventArgs) Handles conEdit.Click, btnEdit.Click
        If (Me.listView1.SelectedItems.Count > 0) Then
            FormEntry.loadOptions(Me.contact.ID, False)
        Else
            MessageBox.Show("Please select an item to edit.", "Phone Book", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub DeleteData(ByVal sender As Object, ByVal e As EventArgs) Handles conDelete.Click, btnDelete.Click
        If Me.listView1.Items.Count > 0 Then
            If MessageBox.Show(InfoMessage.M_CONFIRM_DELETE & Me.fullName & "?", InfoMessage.C_CONFIRM_DELETE, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                Me.contact.DeleteData(Me.fullName)
            End If
        Else
            MessageBox.Show("Please select an item to delete.", "Phone Book", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub SetConrols()
        If Me.listView1.Items.Count > 0 Then
            Me.MyControls(True)
        Else
            Me.stRecord.Text = "0 of 0"
            Me.MyControls(False)
        End If

        Me.stTotal.Text = "Total: " & Me.listView1.Items.Count
    End Sub

    Private Sub MyControls(ByVal activate As Boolean)
        'Update
        Me.btnEdit.Enabled = activate
        Me.conEdit.Enabled = activate
        'Delete
        Me.btnDelete.Enabled = activate
        Me.conDelete.Enabled = activate
    End Sub

#End Region

    Private Sub aboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles aboutToolStripMenuItem.Click
        FormAbout.ShowDialog()
    End Sub

    Private Sub FormPhoneBook_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Location = My.MySettings.Default.Location
        Me.WindowState = My.MySettings.Default.WindowState
        Me.Size = My.MySettings.Default.Size
        If My.MySettings.Default.ShowPix Then
            FormPix.Show()
            Me.ToolStripMenuItem1.Checked = True
        Else
            Me.ToolStripMenuItem1.Checked = False
        End If
        Dim c As Customize = New Customize(Me.listView1)
        Me.ShowContacts(True, "")
    End Sub

    Private Sub listView1_ItemSelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles listView1.ItemSelectionChanged
        Me.fullName = e.Item.SubItems(2).Text
        Me.contact = New Contacts(Convert.ToInt32(e.Item.SubItems(1).Text))
        Me.contact.ID = Convert.ToInt32(e.Item.SubItems(1).Text)
        Me.contact.ShowImage(Me.contact.ID)
        If Not FormPix.IsDisposed Then FormPix.picBox.Image = Me.contact.Picture
        Me.stRecord.Text = "Record " & (e.ItemIndex + 1) & " of " & Me.listView1.Items.Count
    End Sub

    Private Sub listView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listView1.DoubleClick
        If Me.listView1.SelectedItems.Count > 0 Then FormEntry.loadOptions(Me.contact.ID, False)
    End Sub

    Private Sub linkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles linkLabel1.LinkClicked
        Me.ShowContacts(True, "")
    End Sub

    Private Sub listView1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listView1.Resize
        Dim c As Customize = New Customize(Me.listView1)
    End Sub

    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        If txtSearch.StartSearch Then Me.ShowContacts(False, Me.txtSearch.Text)
    End Sub

    Private Sub conClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles conClose.Click
        Me.Dispose()
    End Sub

    Private Sub txtSearch_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSearch.KeyDown
        If e.KeyCode = Keys.F5 Then
            Me.ShowContacts(True, "")
        ElseIf (e.KeyCode = Keys.Down) Then
            If Me.listView1.Items.Count > 0 Then
                Me.listView1.Select()
                Me.listView1.TopItem.Selected = True
            End If
        End If
    End Sub

    Private Sub listView1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles listView1.KeyDown
        If Me.listView1.SelectedItems.Count > 0 Then
            If (e.KeyCode = Keys.Enter) Then
                Me.conEdit.PerformClick()
            End If
        ElseIf e.KeyCode = Keys.Delete Then
            Me.conDelete.PerformClick()
        End If
    End Sub

    Private Sub FormPhoneBook_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        My.MySettings.Default.Location = Me.Location
        My.MySettings.Default.WindowState = Me.WindowState
        My.MySettings.Default.Size = Me.Size
        My.MySettings.Default.ShowPix = Me.ToolStripMenuItem1.Checked
        My.MySettings.Default.Save()
    End Sub

    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        If Me.ToolStripMenuItem1.Checked Then
            FormPix.Show()
        Else
            FormPix.Close()
        End If
    End Sub

    Private Sub FormPhoneBook_LocationChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LocationChanged
        FormPix.Location = New System.Drawing.Point(Me.Location.X + Me.Width, Me.Location.Y)
    End Sub
End Class

Project Homepage: