Click here to Skip to main content
15,896,153 members
Articles / Database Development / SQL Server

A guide to using Paneled Forms, Multi-Splash Screens, SQL Express, and many more in Windows Application Development

Rate me:
Please Sign up or sign in to vote.
4.62/5 (46 votes)
19 Sep 2005CPOL16 min read 109.3K   2.5K   102  
A quick hands-on application to guide you in using paneled forms, multi-splash screens, SQL Express, and many more....
Public Class ctrlAddNewEntry

#Region "Event Handlers"
    Private Sub btnGoMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoMain.Click
        backToMain()
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        lblNewEntry.Text = ""
        clearTextBoxes()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If txtName.Text.CompareTo("") = 0 Or txtName.Text Is Nothing Then
            lblNewEntry.Text = "Name is required!!!"
        Else
            Dim nameEntry As String = txtName.Text.Trim()
            Dim startChar As String = nameEntry.Chars(0).ToString()
            nameEntry = nameEntry.Remove(0, 1)
            nameEntry = startChar.ToUpper() + nameEntry
            Dim success As Boolean = DataLayer.insertAddressBook(nameEntry, txtAddress.Text.Trim(), txtPhone.Text.Trim(), txtCell.Text.Trim(), txtMail.Text.Trim(), drpCategory.SelectedValue)
            If success Then
                lblNewEntry.Text = "Entry successfully created for: " + txtName.Text.Trim()
                clearTextBoxes()
            Else
                lblNewEntry.Text = "Errors encountered during creation of entry in records for: " + txtName.Text.Trim()
            End If
        End If
    End Sub

    Private Sub ctrlAddNewEntry_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Enter
        Try
            Dim dsCategory As Data.DataSet = DataLayer.selectCategory()
            If dsCategory.Tables("category").Rows.Count > 0 Then
                With drpCategory
                    .DataSource = dsCategory.Tables("category")
                    .DisplayMember = "Title"
                    .ValueMember = "CategoryID"
                End With
                lblNewEntry.Text = ""
            Else
                MessageBox.Show("No categories defined. Please add some categories to the Address Book.")
                backToMain()
            End If
        Catch ex As Exception
            MessageBox.Show("Error!!! An Error occured while communicating with Database. Please verify if SQL Express is running and restart application.", "Communication Error")
            Application.Exit()
        End Try
    End Sub

    Private Sub drpCategory_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles drpCategory.KeyPress
        drpCategory.SelectedText = drpCategory.SelectedItem
        e.Handled = True
    End Sub
#End Region

#Region "Shared Functions"
    Public Sub backToMain()
        Dim tempObject As New ctrlMain
        Me.ParentForm.Controls.Item("myPanel").Controls.Add(tempObject)
        Me.ParentForm.Controls.Item("myPanel").Controls.RemoveAt(0)
    End Sub

    Public Sub clearTextBoxes()
        txtName.Text = ""
        txtAddress.Text = ""
        txtPhone.Text = ""
        txtCell.Text = ""
        txtMail.Text = ""
    End Sub
#End Region
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Pakistan Pakistan
I am currently working as a Senior Software Developer (.Net) in Premier POS, Inc. Focused mainly on Windows Application Development, i am now looking for inspiration to work on Windows Presentation Foundation.

Comments and Discussions