Home

XML Example Application: FunDS (Fun Department Store)

   

Introduction

XML provide effective and wonderful means to create a database repository. XML by itself doesn't create or save records. It only defines how datashould be stored. On the other hand, another language, a library, or a programming environment can be used to create, save, or maintain data (for example, editing or deleting records).

We are going to create an example database application for a department store. We will name the business as FunDS, which stands for Fun Department Store.

The Employees

Naturally, we need people who can run the business.

Practical LearningPractical Learning: Introducing the Application

  1. Start a text editor such as Notepad and type the following:
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class EmployeeNew
        Inherits Form
    
        Private lblEmployeeNumber As Label
        Public txtEmployeeNumber As TextBox
        Private lblFirstName As Label
        Public txtFirstName As TextBox
        Private lblLastName As Label
        Public txtLastName As TextBox
        Private lblAddress As Label
        Public txtAddress As TextBox
        Private lblCity As Label
        Public txtCity As TextBox
        Private lblCounty As Label
        Public txtCounty As TextBox
        Private lblState As Label
        Public txtState As TextBox
        Private lblZIPCode As Label
        Public txtZIPCode As TextBox
        Private lblMaritalStatus As Label
        Public cbxMaritalsStatus As ComboBox
        Private lblExemptions As Label
        Public txtExemptions As TextBox
        Private lblHourlySalary As Label
        Public txtHourlySalary As TextBox
        Private WithEvents btnOK As Button
        Private WithEvents btnCancel As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            ' Label: Employee Number
            lblEmployeeNumber = New Label()
            lblEmployeeNumber.AutoSize = True
            lblEmployeeNumber.Location = New System.Drawing.Point(13, 18)
            lblEmployeeNumber.TabIndex = 0
            lblEmployeeNumber.Text = "Employee #:"
            Controls.Add(lblEmployeeNumber)
    
            ' Text Box: Employee Number
            txtEmployeeNumber = New TextBox()
            txtEmployeeNumber.Location = New System.Drawing.Point(94, 16)
            txtEmployeeNumber.Size = New System.Drawing.Size(88, 20)
            txtEmployeeNumber.TabIndex = 1
            Controls.Add(txtEmployeeNumber)
    
            ' Label: First Name
            lblFirstName = New Label()
            lblFirstName.AutoSize = True
            lblFirstName.Location = New System.Drawing.Point(13, 49)
            lblFirstName.TabIndex = 2
            lblFirstName.Text = "First Name:"
            Controls.Add(lblFirstName)
    
            ' Text Box: First Name
            txtFirstName = New TextBox()
            txtFirstName.Location = New System.Drawing.Point(94, 46)
            txtFirstName.Size = New System.Drawing.Size(88, 20)
            txtFirstName.TabIndex = 3
            Controls.Add(txtFirstName)
    
            ' Label: Last Name
            lblLastName = New Label()
            lblLastName.AutoSize = True
            lblLastName.Location = New System.Drawing.Point(195, 49)
            lblLastName.TabIndex = 4
            lblLastName.Text = "Last Name:"
            Controls.Add(lblLastName)
    
            ' Text Box: Last Name
            txtLastName = New TextBox()
            txtLastName.Location = New System.Drawing.Point(276, 46)
            txtLastName.Size = New System.Drawing.Size(88, 20)
            txtLastName.TabIndex = 5
            Controls.Add(txtLastName)
    
            ' Label: Address
            lblAddress = New Label()
            lblAddress.AutoSize = True
            lblAddress.Location = New System.Drawing.Point(13, 75)
            lblAddress.TabIndex = 6
            lblAddress.Text = "Address:"
            Controls.Add(lblAddress)
    
            ' Text Box: Address
            txtAddress = New TextBox()
            txtAddress.Location = New System.Drawing.Point(94, 72)
            txtAddress.Size = New System.Drawing.Size(270, 20)
            txtAddress.TabIndex = 7
            Controls.Add(txtAddress)
    
            ' Label: City
            lblCity = New Label()
            lblCity.AutoSize = True
            lblCity.Location = New System.Drawing.Point(13, 101)
            lblCity.TabIndex = 8
            lblCity.Text = "City:"
            Controls.Add(lblCity)
    
            ' Text Box: City
            txtCity = New TextBox()
            txtCity.Location = New System.Drawing.Point(94, 98)
            txtCity.Size = New System.Drawing.Size(270, 20)
            txtCity.TabIndex = 9
            Controls.Add(txtCity)
    
            ' Label: County
            lblCounty = New Label()
            lblCounty.AutoSize = True
            lblCounty.Location = New System.Drawing.Point(13, 127)
            lblCounty.TabIndex = 10
            lblCounty.Text = "County:"
            Controls.Add(lblCounty)
    
            ' Text Box: County
            txtCounty = New TextBox()
            txtCounty.Location = New System.Drawing.Point(94, 124)
            txtCounty.Size = New System.Drawing.Size(88, 20)
            txtCounty.TabIndex = 11
            Controls.Add(txtCounty)
    
            ' Label: State
            lblState = New Label()
            lblState.AutoSize = True
            lblState.Location = New System.Drawing.Point(195, 127)
            lblState.TabIndex = 12
            lblState.Text = "State:"
            Controls.Add(lblState)
    
            ' Text Box: State
            txtState = New TextBox()
            txtState.Location = New System.Drawing.Point(276, 124)
            txtState.Size = New System.Drawing.Size(88, 20)
            txtState.TabIndex = 13
            Controls.Add(txtState)
    
            ' Label: ZIP Code
            lblZIPCode = New Label()
            lblZIPCode.AutoSize = True
            lblZIPCode.Location = New System.Drawing.Point(13, 153)
            lblZIPCode.TabIndex = 14
            lblZIPCode.Text = "ZIP Code:"
            Controls.Add(lblZIPCode)
    
            ' Text Box: ZIP Code
            txtZIPCode = New TextBox()
            txtZIPCode.Location = New System.Drawing.Point(94, 150)
            txtZIPCode.Size = New System.Drawing.Size(88, 20)
            txtZIPCode.TabIndex = 15
            Controls.Add(txtZIPCode)
    
            ' Label: Marital Status
            lblMaritalStatus = New Label()
            lblMaritalStatus.AutoSize = True
            lblMaritalStatus.Location = New System.Drawing.Point(195, 153)
            lblMaritalStatus.TabIndex = 16
            lblMaritalStatus.Text = "Marital Status:"
            Controls.Add(lblMaritalStatus)
    
            ' Combo Box: Maritals Status
            cbxMaritalsStatus = New ComboBox()
            cbxMaritalsStatus.Items.AddRange(New Object() {"Single", "Married"})
            cbxMaritalsStatus.Location = New System.Drawing.Point(276, 150)
            cbxMaritalsStatus.Size = New System.Drawing.Size(88, 21)
            cbxMaritalsStatus.TabIndex = 17
            Controls.Add(cbxMaritalsStatus)
    
            ' Label: Exemptions
            lblExemptions = New Label()
            lblExemptions.AutoSize = True
            lblExemptions.Location = New System.Drawing.Point(13, 179)
            lblExemptions.TabIndex = 18
            lblExemptions.Text = "Exemptions:"
            Controls.Add(lblExemptions)
    
            ' Text Box: Exemptions
            txtExemptions = New TextBox()
            txtExemptions.Location = New System.Drawing.Point(94, 176)
            txtExemptions.Size = New System.Drawing.Size(88, 20)
            txtExemptions.TabIndex = 19
            txtExemptions.Text = "0"
            txtExemptions.TextAlign = HorizontalAlignment.Right
            Controls.Add(txtExemptions)
    
            ' Label: Hourly Salary
            lblHourlySalary = New Label()
            lblHourlySalary.AutoSize = True
            lblHourlySalary.Location = New System.Drawing.Point(195, 180)
            lblHourlySalary.TabIndex = 20
            lblHourlySalary.Text = "Hourly Salary:"
            Controls.Add(lblHourlySalary)
    
            ' Text Box: Hourly Salary
            txtHourlySalary = New TextBox()
            txtHourlySalary.Location = New System.Drawing.Point(276, 177)
            txtHourlySalary.Size = New System.Drawing.Size(88, 20)
            txtHourlySalary.TabIndex = 21
            Controls.Add(txtHourlySalary)
    
            ' Button: OK
            btnOK = New Button()
            btnOK.DialogResult = DialogResult.OK
            btnOK.Location = New System.Drawing.Point(202, 220)
            btnOK.Size = New System.Drawing.Size(75, 23)
            btnOK.TabIndex = 22
            btnOK.Text = "OK"
            Controls.Add(btnOK)
    
            ' Button: Cancel
            btnCancel = New Button()
            btnCancel.DialogResult = DialogResult.Cancel
            btnCancel.Location = New System.Drawing.Point(288, 220)
            btnCancel.Size = New System.Drawing.Size(75, 23)
            btnCancel.TabIndex = 23
            btnCancel.Text = "Cancel"
            Controls.Add(btnCancel)
    
            ' Form: New Employee
            AcceptButton = btnOK
            CancelButton = btnCancel
            ClientSize = New System.Drawing.Size(388, 260)
            FormBorderStyle = FormBorderStyle.FixedDialog
            MaximizeBox = False
            MinimizeBox = False
            StartPosition = FormStartPosition.CenterScreen
            Text = "Fun Department Store - New Employee"
        End Sub
    
    End Class
  2. To save and start a new file, on the main menu, click File -> New
  3. When asked whether you want to save, click Save
  4. In the top combo box, select and display the C: drive
  5. Click the New Folder button
  6. Type FunDS1 and press Enter twice to display it in the top combo box
  7. Change the Save As Type combo box to All Files
  8. Set the File Name to EmployeeNew.vb
  9. Click Save
  10. In the empty document, type the following:
    Imports System
    Imports System.IO
    Imports System.Xml
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class EmployeeEditor
        Inherits Form
    
        Private lblEmployeeNumber As Label
        Public txtEmployeeNumber As TextBox
        Private WithEvents btnFind As Button
        Private lblFirstName As Label
        Public txtFirstName As TextBox
        Private lblLastName As Label
        Public txtLastName As TextBox
        Private lblAddress As Label
        Public txtAddress As TextBox
        Private lblCity As Label
        Public txtCity As TextBox
        Private lblCounty As Label
        Public txtCounty As TextBox
        Private lblState As Label
        Public txtState As TextBox
        Private lblZIPCode As Label
        Public txtZIPCode As TextBox
        Private lblMaritalStatus As Label
        Public cbxMaritalsStatus As ComboBox
        Private lblExemptions As Label
        Public txtExemptions As TextBox
        Private lblHourlySalary As Label
        Public txtHourlySalary As TextBox
        Private WithEvents btnSubmit As Button
        Private WithEvents btnClose As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            ' Label: Employee Number
            lblEmployeeNumber = New Label()
            lblEmployeeNumber.AutoSize = True
            lblEmployeeNumber.Location = New System.Drawing.Point(13, 18)
            lblEmployeeNumber.TabIndex = 0
            lblEmployeeNumber.Text = "Employee #:"
            Controls.Add(lblEmployeeNumber)
    
            ' Text Box: Employee Number
            txtEmployeeNumber = New TextBox()
            txtEmployeeNumber.Location = New System.Drawing.Point(94, 16)
            txtEmployeeNumber.Size = New System.Drawing.Size(88, 20)
            txtEmployeeNumber.TabIndex = 1
            Controls.Add(txtEmployeeNumber)
    
            ' Button: Find
            btnFind = New Button()
            btnFind.Location = New System.Drawing.Point(201, 18)
            btnFind.Size = New System.Drawing.Size(75, 23)
            btnFind.TabIndex = 2
            btnFind.Text = "Find"
            Controls.Add(btnFind)
    
            ' Label: First Name
            lblFirstName = New Label()
            lblFirstName.AutoSize = True
            lblFirstName.Location = New System.Drawing.Point(13, 49)
            lblFirstName.TabIndex = 5
            lblFirstName.Text = "First Name:"
            Controls.Add(lblFirstName)
    
            ' Text Box: First Name
            txtFirstName = New TextBox()
            txtFirstName.Location = New System.Drawing.Point(94, 46)
            txtFirstName.Size = New System.Drawing.Size(88, 20)
            txtFirstName.TabIndex = 6
            Controls.Add(txtFirstName)
    
            ' Label: Last Name
            lblLastName = New Label()
            lblLastName.AutoSize = True
            lblLastName.Location = New System.Drawing.Point(195, 49)
            lblLastName.TabIndex = 7
            lblLastName.Text = "Last Name:"
            Controls.Add(lblLastName)
    
            ' Text Box: Last Name
            txtLastName = New TextBox()
            txtLastName.Location = New System.Drawing.Point(276, 46)
            txtLastName.Size = New System.Drawing.Size(88, 20)
            txtLastName.TabIndex = 8
            Controls.Add(txtLastName)
    
            ' Label: Address
            lblAddress = New Label()
            lblAddress.AutoSize = True
            lblAddress.Location = New System.Drawing.Point(13, 75)
            lblAddress.TabIndex = 9
            lblAddress.Text = "Address:"
            Controls.Add(lblAddress)
    
            ' Text Box: Address
            txtAddress = New TextBox()
            txtAddress.Location = New System.Drawing.Point(94, 72)
            txtAddress.Size = New System.Drawing.Size(270, 20)
            txtAddress.TabIndex = 10
            Controls.Add(txtAddress)
    
            ' Label: City
            lblCity = New Label()
            lblCity.AutoSize = True
            lblCity.Location = New System.Drawing.Point(13, 101)
            lblCity.TabIndex = 11
            lblCity.Text = "City:"
            Controls.Add(lblCity)
    
            ' Text Box: City
            txtCity = New TextBox()
            txtCity.Location = New System.Drawing.Point(94, 98)
            txtCity.Size = New System.Drawing.Size(270, 20)
            txtCity.TabIndex = 12
            Controls.Add(txtCity)
    
            ' Label: County
            lblCounty = New Label()
            lblCounty.AutoSize = True
            lblCounty.Location = New System.Drawing.Point(13, 127)
            lblCounty.TabIndex = 13
            lblCounty.Text = "County:"
            Controls.Add(lblCounty)
    
            ' Text Box: County
            txtCounty = New TextBox()
            txtCounty.Location = New System.Drawing.Point(94, 124)
            txtCounty.Size = New System.Drawing.Size(88, 20)
            txtCounty.TabIndex = 14
            Controls.Add(txtCounty)
    
            ' Label: State
            lblState = New Label()
            lblState.AutoSize = True
            lblState.Location = New System.Drawing.Point(195, 127)
            lblState.TabIndex = 15
            lblState.Text = "State:"
            Controls.Add(lblState)
    
            ' Text Box: State
            txtState = New TextBox()
            txtState.Location = New System.Drawing.Point(276, 124)
            txtState.Size = New System.Drawing.Size(88, 20)
            txtState.TabIndex = 16
            Controls.Add(txtState)
    
            ' Label: ZIP Code
            lblZIPCode = New Label()
            lblZIPCode.AutoSize = True
            lblZIPCode.Location = New System.Drawing.Point(13, 153)
            lblZIPCode.TabIndex = 17
            lblZIPCode.Text = "ZIP Code:"
            Controls.Add(lblZIPCode)
    
            ' Text Box: ZIP Code
            txtZIPCode = New TextBox()
            txtZIPCode.Location = New System.Drawing.Point(94, 150)
            txtZIPCode.Size = New System.Drawing.Size(88, 20)
            txtZIPCode.TabIndex = 18
            Controls.Add(txtZIPCode)
    
            ' Label: Marital Status
            lblMaritalStatus = New Label()
            lblMaritalStatus.AutoSize = True
            lblMaritalStatus.Location = New System.Drawing.Point(195, 153)
            lblMaritalStatus.TabIndex = 19
            lblMaritalStatus.Text = "Marital Status:"
            Controls.Add(lblMaritalStatus)
    
            ' Combo Box: MaritalsStatus
            cbxMaritalsStatus = New ComboBox()
            cbxMaritalsStatus.Items.AddRange(New Object() {"Single", "Married"})
            cbxMaritalsStatus.Location = New System.Drawing.Point(276, 150)
            cbxMaritalsStatus.Size = New System.Drawing.Size(88, 21)
            cbxMaritalsStatus.TabIndex = 20
            Controls.Add(cbxMaritalsStatus)
    
            ' Label: Exemptions
            lblExemptions = New Label()
            lblExemptions.AutoSize = True
            lblExemptions.Location = New System.Drawing.Point(13, 179)
            lblExemptions.TabIndex = 21
            lblExemptions.Text = "Exemptions:"
            Controls.Add(lblExemptions)
    
            ' Text Box: Exemptions
            txtExemptions = New TextBox()
            txtExemptions.Location = New System.Drawing.Point(94, 176)
            txtExemptions.Size = New System.Drawing.Size(88, 20)
            txtExemptions.TabIndex = 22
            txtExemptions.Text = "0"
            txtExemptions.TextAlign = HorizontalAlignment.Right
            Controls.Add(txtExemptions)
    
            ' Label: Hourly Salary
            lblHourlySalary = New Label()
            lblHourlySalary.AutoSize = True
            lblHourlySalary.Location = New System.Drawing.Point(195, 180)
            lblHourlySalary.TabIndex = 23
            lblHourlySalary.Text = "Hourly Salary:"
            Controls.Add(lblHourlySalary)
    
            ' Text Box: Hourly Salary
            txtHourlySalary = New TextBox()
            txtHourlySalary.Location = New System.Drawing.Point(276, 177)
            txtHourlySalary.Size = New System.Drawing.Size(88, 20)
            txtHourlySalary.TabIndex = 24
            Controls.Add(txtHourlySalary)
    
            ' Button: Submit
            btnSubmit = New Button()
            btnSubmit.Location = New System.Drawing.Point(207, 218)
            btnSubmit.Size = New System.Drawing.Size(84, 23)
            btnSubmit.TabIndex = 3
            btnSubmit.Text = "Submit"
            Controls.Add(btnSubmit)
    
            ' Button: Close
            btnClose = New Button()
            btnClose.Location = New System.Drawing.Point(297, 218)
            btnClose.Size = New System.Drawing.Size(75, 23)
            btnClose.TabIndex = 4
            btnClose.Text = "Close"
            Controls.Add(btnClose)
    
            ' Form: Employee Editor
            ClientSize = New System.Drawing.Size(394, 259)
            FormBorderStyle = FormBorderStyle.FixedDialog
            MaximizeBox = False
            MinimizeBox = False
            StartPosition = FormStartPosition.CenterScreen
            Text = "Fun Department Store: Employee Editor"
        End Sub
    
        Private Sub btnFindClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnFind.Click
            Dim employeeFound As Boolean = False
            Dim xdEmployees As XmlDocument = New XmlDocument()
            Dim strEmployeesFile As String = "C:\Fun Department Store1\Employees.xml"
    
            If String.IsNullOrEmpty(txtEmployeeNumber.Text) Then
                MsgBox("You must enter an employee number.",
                       MsgBoxStyle.OKOnly Or MsgBoxStyle.Information,
                       "FunDS - Employees Records")
                Exit Sub
            End If
    
            If File.Exists(strEmployeesFile) Then
                Using fsEmployees As FileStream = New FileStream(strEmployeesFile, FileMode.Open, FileAccess.Read)
                    xdEmployees.Load(fsEmployees)
    
                    Dim xnlEmployees As XmlNodeList = xdEmployees.GetElementsByTagName("EmployeeNumber")
    
                    For Each xnEmployee As XmlNode In xnlEmployees
                        If xnEmployee.InnerText = txtEmployeeNumber.Text Then
                            txtFirstName.Text = xnEmployee.NextSibling.InnerText ' First Name
                            txtLastName.Text = xnEmployee.NextSibling.NextSibling.InnerText ' Last Name
                            txtAddress.Text = xnEmployee.NextSibling.NextSibling.NextSibling.InnerText ' Address
                            txtCity.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' City
                            txtCounty.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' County
                            txtState.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' State
                            txtZIPCode.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' ZIP Code
                            cbxMaritalsStatus.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' Marital Status
                            txtExemptions.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' Exemptions
                            txtHourlySalary.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' Hourly Salary
    
                            employeeFound = True
                        End If
                    Next
    
                    If employeeFound = False Then
                        MsgBox("There is no staff member with that employee number.",
                               MsgBoxStyle.OKOnly Or MsgBoxStyle.Information,
                               "FunDS - Employees Records")
                        Exit Sub
                    End If
                End Using
            End If
        End Sub
    
        Private Sub btnSubmitClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
            Dim xdEmployees As XmlDocument = New XmlDocument()
            Dim strEmployeesFile As String = "C:\Fun Department Store1\Employees.xml"
    
            If String.IsNullOrEmpty(txtEmployeeNumber.Text) Then
                MsgBox("You must enter an employee number.",
                       MsgBoxStyle.OKOnly Or MsgBoxStyle.Information,
                       "FunDS - Employees Records")
                Exit Sub
            End If
    
            If File.Exists(strEmployeesFile) Then
                Using fsEmployees As FileStream = New FileStream(strEmployeesFile, FileMode.Open, FileAccess.Read)
                    xdEmployees.Load(fsEmployees)
    
                    Dim xnlEmployees As XmlNodeList = xdEmployees.GetElementsByTagName("EmployeeNumber")
    
                    For Each xnEmployee As XmlNode In xnlEmployees
                        If xnEmployee.InnerText = txtEmployeeNumber.Text Then
                            xnEmployee.ParentNode.InnerXml = "<EmployeeNumber>" & txtEmployeeNumber.Text & "</EmployeeNumber>" &
                                                             "<FirstName>" & txtFirstName.Text & "</FirstName>" &
                                                             "<LastName>" & txtLastName.Text & "</LastName>" &
                                                             "<Address>" & txtAddress.Text & "</Address>" &
                                                             "<City>" & txtCity.Text & "</City>" &
                                                             "<County>" & txtCounty.Text & "</County>" &
                                                             "<State>" & txtState.Text & "</State>" &
                                                             "<ZIPCode>" & txtZIPCode.Text & "</ZIPCode>" &
                                                             "<MaritalStatus>" & cbxMaritalsStatus.Text & "</MaritalStatus>" &
                                                             "<Exemptions>" & txtExemptions.Text & "</Exemptions>" &
                                                             "<HourlySalary>" & txtHourlySalary.Text & "</HourlySalary>"
                            Exit For
                        End If
                    Next
                End Using
    
                Using fsEmployees As FileStream = New FileStream(strEmployeesFile, FileMode.Create, FileAccess.Write)
                    xdEmployees.Save(fsEmployees)
    
                    MsgBox("The employee's record has been updated.",
                           MsgBoxStyle.OKOnly Or MsgBoxStyle.Information,
                           "FunDS - Employees Records")
                End Using
            End If
    
            Close()
        End Sub
    
        Private Sub btnCloseClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
            Close()
        End Sub
    
    End Class
  11. To save and start a new filew, on the main menu, click File -> New
  12. When asked whether you want to save, click Save
  13. Make sure the FunDS1 folder is displaying in the top combo box. Set the Save As Type combo box to All Files
  14. Set the File Name to EmployeeEditor.vb
  15. Click Save
  16. In the empty document, type the following:
    Imports System
    Imports System.IO
    Imports System.Xml
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class Employees
        Inherits Form
    
        Private colEmployeeNumber As ColumnHeader
        Private colFirstName As ColumnHeader
        Private colLastName As ColumnHeader
        Private colAddress As ColumnHeader
        Private colCity As ColumnHeader
        Private colCounty As ColumnHeader
        Private colState As ColumnHeader
        Private colZIPCode As ColumnHeader
        Private colMaritalStatus As ColumnHeader
        Private colExemptions As ColumnHeader
        Private colHourlySalary As ColumnHeader
        Private WithEvents lvwEmployees As ListView
    
        Private lblNumberOfEmployees As Label
        Private txtNumberOfEmployees As TextBox
        Private WithEvents btnNewEmployee As Button
        Private WithEvents btnClose As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            ' Column: Employee Number
            colEmployeeNumber = New ColumnHeader()
            colEmployeeNumber.Text = "Employee #"
            colEmployeeNumber.Width = 70
    
            ' Column: First Name
            colFirstName = New ColumnHeader()
            colFirstName.Text = "First Name"
            colFirstName.Width = 65
    
            ' Column: Last Name
            colLastName = New ColumnHeader()
            colLastName.Text = "Last Name"
            colLastName.Width = 70
    
            ' Column: Address
            colAddress = New ColumnHeader()
            colAddress.Text = "Address"
            colAddress.Width = 125
    
            ' Column: City
            colCity = New ColumnHeader()
            colCity.Text = "City"
            colCity.Width = 75
    
            ' Column: Username
            colCounty = New ColumnHeader()
            colCounty.Text = "County"
    
            ' Column: State
            colState = New ColumnHeader()
            colState.Text = "State"
            colState.Width = 40
    
            ' Column: ZIP Code
            colZIPCode = New ColumnHeader()
            colZIPCode.Text = "ZIP Code"
    
            ' Column: Marital Status
            colMaritalStatus = New ColumnHeader()
            colMaritalStatus.Text = "Marital Status"
            colMaritalStatus.Width = 80
    
            ' Column: Exemptions
            colExemptions = New ColumnHeader()
            colExemptions.Text = "Exemptions"
            colExemptions.TextAlign = HorizontalAlignment.Right
            colExemptions.Width = 70
    
            ' Column: Hourly Salary
            colHourlySalary = New ColumnHeader()
            colHourlySalary.Text = "Salary"
            colHourlySalary.TextAlign = HorizontalAlignment.Right
            colHourlySalary.Width = 45
    
            ' List View: Employees
            lvwEmployees = New ListView()
            lvwEmployees.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
            lvwEmployees.Columns.AddRange(new ColumnHeader() {
                colEmployeeNumber, colFirstName, colLastName,
                colAddress, colCity, colCounty, colState, colZIPCode,
            colMaritalStatus, colExemptions, colHourlySalary })
            lvwEmployees.FullRowSelect = True
            lvwEmployees.GridLines = True
            lvwEmployees.Location = New System.Drawing.Point(16, 12)
            lvwEmployees.Size = New System.Drawing.Size(785, 125)
            lvwEmployees.View = View.Details
    
            ' Label: NumberOfEmployees
            lblNumberOfEmployees = New Label()
            lblNumberOfEmployees.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
            lblNumberOfEmployees.AutoSize = True
            lblNumberOfEmployees.Location = New Point(12, 158)
            lblNumberOfEmployees.Size = New System.Drawing.Size(113, 13)
            lblNumberOfEmployees.Text = "Number of Employees:"
    
            ' Text Box: NumberOfEmployees
            txtNumberOfEmployees = New TextBox()
            txtNumberOfEmployees.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
            txtNumberOfEmployees.Location = New Point(131, 155)
            txtNumberOfEmployees.Size = New System.Drawing.Size(60, 20)
            txtNumberOfEmployees.TextAlign = HorizontalAlignment.Right
    
            ' Button: NewEmployee
            btnNewEmployee = New Button()
            btnNewEmployee.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
            btnNewEmployee.Location = New Point(564, 153)
            btnNewEmployee.Size = New System.Drawing.Size(109, 23)
            btnNewEmployee.Text = "New Employee ..."
    
            ' Button: Close
            btnClose = New Button()
            btnClose.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
            btnClose.Location = New Point(679, 153)
            btnClose.Size = New System.Drawing.Size(75, 23)
            btnClose.Text = "Close"
    
            ' Form: Employees
            ClientSize = New System.Drawing.Size(820, 185)
            Controls.Add(lvwEmployees)
            Controls.Add(txtNumberOfEmployees)
            Controls.Add(lblNumberOfEmployees)
            Controls.Add(btnNewEmployee)
            Controls.Add(btnClose)
    
            MaximizeBox = False
            StartPosition = FormStartPosition.CenterScreen
            Text = "FunDS - Employees"
        End Sub
    
        Private Sub ShowEmployees()
            Dim xdEmployees As XmlDocument = New XmlDocument()
            Dim strEmployeesFile As String = "C:\Fun Department Store1\Employees.xml"
    
            If File.Exists(strEmployeesFile) Then
                lvwEmployees.Items.Clear()
                Using fsEmployees As FileStream = New FileStream(strEmployeesFile, FileMode.Open, FileAccess.Read)
                    xdEmployees.Load(fsEmployees)
    
                    Dim xnlEmployees As XmlNodeList = xdEmployees.GetElementsByTagName("EmployeeNumber")
    
                    For Each xnEmployee As XmlNode In xnlEmployees
                        Dim lviEmployee As ListViewItem = New ListViewItem(xnEmployee.InnerText) ' Employee Number
                        lviEmployee.SubItems.Add(xnEmployee.NextSibling.InnerText) ' First Name
                        lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.InnerText) ' Last Name
                        lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.NextSibling.InnerText) ' Address
                        lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' City
                        lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' County
                        lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' State
                        lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' ZIP Code
                        lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' Marital Status
                        lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' Exemptions
                        lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' Hourly Salary
    
                        lvwEmployees.Items.Add(lviEmployee)
                    Next
    
                    txtNumberOfEmployees.Text = xnlEmployees.Count.ToString()
                End Using
            End If
        End Sub
    
        Private Sub EmployeesLoad(ByVal sender As Object, ByVal e As EventArgs) Handles me.Load
            ShowEmployees()
        End Sub
    
        Private Sub btnNewEmployeeClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnNewEmployee.Click
            Dim strEmployeeNumber As String
            Dim strFirstName As String
            Dim strLastName As String
            Dim strCounty As String
            Dim strAddress As String
            Dim strCity As String
            Dim strState As String
            Dim strZIPCode As String
            Dim strMaritalStatus As String
            Dim iExemptions As Integer
            Dim dblHourlySalary As Double
    
            Dim en As EmployeeNew = New EmployeeNew()
            Dim rndEmployeeNumber As Random = New Random()
            Dim xdEmployees As XmlDocument = New XmlDocument()
            Dim strEmployeesFile As String = "C:\Fun Department Store1\Employees.xml"
    
            en.txtEmployeeNumber.Text = CStr(rndEmployeeNumber.Next(100000, 999999))
    
            If en.ShowDialog() = DialogResult.OK Then
                strEmployeeNumber = en.txtEmployeeNumber.Text
                strFirstName = en.txtFirstName.Text
                strLastName = en.txtLastName.Text
                strMaritalStatus = en.cbxMaritalsStatus.Text
                iExemptions = CInt(en.txtExemptions.Text)
                strAddress = en.txtAddress.Text
                strCity = en.txtCity.Text
                strCounty = en.txtCounty.Text
                strState = en.txtState.Text
                strZIPCode = en.txtZIPCode.Text
                dblHourlySalary = CDbl(en.txtHourlySalary.Text)
    
                If Not File.Exists(strEmployeesFile) Then
                    xdEmployees.LoadXml("<?xml version=""1.0"" encoding=""utf-8""?>" &
                                        "<Employees></Employees>")
                    xdEmployees.Save(strEmployeesFile)
                End If
    
                xdEmployees.Load(strEmployeesFile)
    
                Dim elmXML As XmlElement = xdEmployees.CreateElement("Employee")
                ' Create the XML code of the child element of Employee
                dim strNewEmployee as string= "<EmployeeNumber>" & strEmployeeNumber & "</EmployeeNumber>" &
                                        "<FirstName>" & strFirstName & "</FirstName>" &
                                        "<LastName>" & strLastName & "</LastName>" &
                                        "<Address>" & strAddress & "</Address>" &
                                        "<City>" & strCity & "</City>" &
                                        "<County>" & strCounty & "</County>" &
                                        "<State>" & strState & "</State>" &
                                        "<ZIPCode>" & strZIPCode & "</ZIPCode>" &
                                        "<MaritalStatus>" & strMaritalStatus & "</MaritalStatus>" &
                                        "<Exemptions>" & iExemptions & "</Exemptions>" &
                                        "<HourlySalary>" & dblHourlySalary & "</HourlySalary>"
                elmXML.InnerXml = strNewEmployee
                ' Append the new element as a child of employees
                xdEmployees.DocumentElement.AppendChild(elmXML)
    
                ' Save the XML file
                xdEmployees.Save(strEmployeesFile)
    
                ShowEmployees()
            End If
        End Sub
    
        Private Sub lvwEmployeesDoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles lvwEmployees.DoubleClick
            Dim ee As EmployeeEditor = New EmployeeEditor()
            Dim xdEmployees As XmlDocument = New XmlDocument()
            Dim strEmployeesFile As String = "C:\Fun Department Store1\Employees.xml"
    
            If lvwEmployees.Items.Count <= 0 Then
                Exit Sub
            End If
    
            Using fsEmployees As FileStream = New FileStream(strEmployeesFile, FileMode.Open, FileAccess.Read)
                xdEmployees.Load(fsEmployees)
    
                Dim xnlEmployees As XmlNodeList = xdEmployees.GetElementsByTagName("EmployeeNumber")
    
                For Each xnEmployee As XmlNode In xnlEmployees
                    If xnEmployee.InnerText = lvwEmployees.SelectedItems(0).Text Then
                        ee.txtEmployeeNumber.Text = xnEmployee.InnerText '
                        ee.txtFirstName.Text = xnEmployee.NextSibling.InnerText ' First Name
                        ee.txtLastName.Text = xnEmployee.NextSibling.NextSibling.InnerText ' Last Name
                        ee.txtAddress.Text = xnEmployee.NextSibling.NextSibling.NextSibling.InnerText ' Address
                        ee.txtCity.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' City
                        ee.txtCounty.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' County
                        ee.txtState.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' State
                        ee.txtZIPCode.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' ZIP Code
                        ee.cbxMaritalsStatus.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' Marital Status
                        ee.txtExemptions.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' Exemptions
                        ee.txtHourlySalary.Text = xnEmployee.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText ' Hourly Salary
                    End If
                Next
            End Using
    
            ee.ShowDialog()
            ShowEmployees()
        End Sub
    
        Private Sub btnCloseClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
            Close()
        End Sub
    
    End Class
  17. To save, on the main menu, click File -> New
  18. When asked whether you want to save, click Save
  19. Make sure the FunDS1 folder is displaying in the top combo box and change the Save As Type to All Files
  20. Set the File Name to Employees.vb
  21. Click Save

Handling Store Items

Items (such as clothing, jewelry, and accessories, etc) are the basis of the business. For our database, the three most important pieces of information about each item are the item number (which must be unique for each item), a name or short description, and a price. Other pieces of information we will consider for some items are the manufacturer, the category, and the subcategory. We will also apply a discount rate to some items.

Practical LearningPractical Learning: Creating Store Items

  1. In the empty document, type the following:
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class Manufacturer
        Inherits Form
    
        Private lblManufacturer As Label
        Public txtManufacturer As TextBox
        Private WithEvents btnOK As Button
        Private WithEvents btnCancel As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
    
        Private Sub InitializeComponent()
            ' Label: Manufacturer
            lblManufacturer = New Label()
            lblManufacturer.AutoSize = True
            lblManufacturer.Location = New System.Drawing.Point(21, 20)
            lblManufacturer.TabIndex = 0
            lblManufacturer.Text = "Manufacturer:"
            Controls.Add(lblManufacturer)
    
            ' Text Box: Manufacturer
            txtManufacturer = New TextBox()
            txtManufacturer.Location = New System.Drawing.Point(100, 17)
            txtManufacturer.Size = New System.Drawing.Size(156, 20)
            txtManufacturer.TabIndex = 1
            Controls.Add(txtManufacturer)
    
            ' Button: OK
            btnOK = New Button()
            btnOK.DialogResult = DialogResult.OK
            btnOK.Location = New System.Drawing.Point(100, 53)
            btnOK.Size = New System.Drawing.Size(75, 23)
            btnOK.TabIndex = 3
            btnOK.Text = "OK"
            Controls.Add(btnOK)
    
            ' Button: Cancel
            btnCancel = New Button()
            btnCancel.DialogResult = DialogResult.Cancel
            btnCancel.Location = New System.Drawing.Point(181, 53)
            btnCancel.Size = New System.Drawing.Size(75, 23)
            btnCancel.TabIndex = 2
            btnCancel.Text = "Cancel"
            Controls.Add(btnCancel)
    
            ' Dialog Box: Manufacturer
            AcceptButton = btnOK
            CancelButton = btnCancel
            ClientSize = New System.Drawing.Size(276, 92)
            FormBorderStyle = FormBorderStyle.FixedDialog
            MaximizeBox = False
            MinimizeBox = False
            ShowInTaskbar = False
            Text = "FunDS - Manufacturer"
            StartPosition = FormStartPosition.CenterScreen
        End Sub
    
    End Class
  2. To save and start a new file, on the main menu, click File -> New
  3. When asked whether you want save, click Yes (or Save)
  4. In the top combo box, make sure FunDS1 is selected. Set the name to Manufacturer.vb
  5. Change the Save As Type to All Files
  6. Click Save
  7. In the empty document, type the following:
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class Category
        Inherits Form
    
        Private WithEvents btnOK As Button
        Private WithEvents btnCancel As Button
        Private lblCategory As Label
        Public txtCategory As TextBox
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            ' Label: Category
            lblCategory = New Label()
            lblCategory.AutoSize = True
            lblCategory.Location = New System.Drawing.Point(21, 20)
            lblCategory.TabIndex = 4
            lblCategory.Text = "Category:"
            Controls.Add(lblCategory)
    
            ' Text Box: Category
            txtCategory = New TextBox()
            txtCategory.Location = New System.Drawing.Point(100, 17)
            txtCategory.Size = New System.Drawing.Size(156, 20)
            txtCategory.TabIndex = 5
            Controls.Add(txtCategory)
    
            ' Button: OK
            btnOK = New Button()
            btnOK.DialogResult = DialogResult.OK
            btnOK.Location = New System.Drawing.Point(100, 53)
            btnOK.Size = New System.Drawing.Size(75, 23)
            btnOK.TabIndex = 7
            btnOK.Text = "OK"
            btnOK.UseVisualStyleBackColor = True
            Controls.Add(btnOK)
    
            ' Button: Cancel
            btnCancel = New Button()
            btnCancel.DialogResult = DialogResult.Cancel
            btnCancel.Location = New System.Drawing.Point(181, 53)
            btnCancel.Size = New System.Drawing.Size(75, 23)
            btnCancel.TabIndex = 6
            btnCancel.Text = "Cancel"
            Controls.Add(btnCancel)
    
            ' Dialog Box: Category
            AcceptButton = btnOK
            CancelButton = btnCancel
            ClientSize = New System.Drawing.Size(276, 93)
            FormBorderStyle = FormBorderStyle.FixedDialog
            MaximizeBox = False
            MinimizeBox = False
            ShowInTaskbar = False
            StartPosition = FormStartPosition.CenterScreen
            Text = "FunDS - Category"
        End Sub
    
    End Class
  8. To save and start a new file, on the main menu, click File -> New
  9. When asked whether you want to save, click Save
  10. Make sure FunDS1 is selected in the top combo box and set the File Name to Category.vb
  11. Set the Save As Type combo box to All Files
  12. Click Save
  13. In the empty document, type the following:
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class SubCategory
        Inherits Form
    
        Private lblSubCategory As Label
        Public txtSubCategory As TextBox
        Private WithEvents btnOK As Button
        Private WithEvents btnCancel As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            lblSubCategory = New Label()
            lblSubCategory.AutoSize = True
            lblSubCategory.Location = New System.Drawing.Point(21, 20)
            lblSubCategory.TabIndex = 0
            lblSubCategory.Text = "Sub-Category:"
            Controls.Add(lblSubCategory)
    
            txtSubCategory = New TextBox()
            txtSubCategory.Location = New System.Drawing.Point(100, 17)
            txtSubCategory.Size = New System.Drawing.Size(156, 20)
            txtSubCategory.TabIndex = 1
            Controls.Add(txtSubCategory)
    
            btnOK = New Button()
            btnOK.DialogResult = DialogResult.OK
            btnOK.Location = New System.Drawing.Point(100, 53)
            btnOK.Size = New System.Drawing.Size(75, 23)
            btnOK.TabIndex = 2
            btnOK.Text = "OK"
            Controls.Add(btnOK)
    
            btnCancel = New Button()
            btnCancel.DialogResult = DialogResult.Cancel
            btnCancel.Location = New System.Drawing.Point(181, 53)
            btnCancel.Size = New System.Drawing.Size(75, 23)
            btnCancel.TabIndex = 3
            btnCancel.Text = "Cancel"
            Controls.Add(btnCancel)
    
            AcceptButton = btnOK
            CancelButton = btnCancel
            ClientSize = New System.Drawing.Size(276, 93)
            FormBorderStyle = FormBorderStyle.FixedDialog
            MaximizeBox = False
            MinimizeBox = False
            ShowInTaskbar = False
            StartPosition = FormStartPosition.CenterScreen
            Text = "FunDS - Sub-Category"
        End Sub
    
    End Class
  14. To save and start a new file, on the main menu, click File -> New
  15. When asked whether you want to save, click Save
  16. In the top combo box, make sure the FunDS1 folder is selected. Set the Save As Type combo box to All Files
  17. Set the File Name to SubCategory.vb
  18. Click Save
  19. In the empty document, type the following:
    Imports System
    Imports System.IO
    Imports System.Xml
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class StoreItemNew
        Inherits Form
    
        Private lblItemNumber As Label
        Public txtItemNumber As TextBox
        Private lblManufacturer As Label
        Public cbxManufacturers As ComboBox
        Private WithEvents btnNewManufacturer As Button
        Private lblCategory As Label
        Private lblSubCategory As Label
        Private lblUnitPrice As Label
        Private lblDiscountRate As Label
        Private lblDiscountPercent As Label
        Private WithEvents btnNewCategory As Button
        Private WithEvents btnNewSubCategory As Button
        Private WithEvents btnSubmit As Button
        Private WithEvents btnClose As Button
        Public cbxCategories As ComboBox
        Public cbxSubCategories As ComboBox
        Private lblItemName As Label
        Public txtItemName As TextBox
        Private lblItemSize As Label
        Public txtItemSize As TextBox
        Public txtUnitPrice As TextBox
        Public txtDiscountRate As TextBox
        Private WithEvents btnReset As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            lblItemNumber = New Label()
            lblItemNumber.AutoSize = True
            lblItemNumber.Location = New Point(17, 24)
            lblItemNumber.TabIndex = 2
            lblItemNumber.Text = "Item Number:"
            Controls.Add(lblItemNumber)
    
            ' Label: Item Number
            txtItemNumber = New TextBox()
            txtItemNumber.Location = New Point(96, 21)
            txtItemNumber.Size = New System.Drawing.Size(94, 20)
            txtItemNumber.TabIndex = 3
            Controls.Add(txtItemNumber)
    
            ' Label: Manufacturer
            lblManufacturer = New Label()
            lblManufacturer.AutoSize = True
            lblManufacturer.Location = New Point(17, 54)
            lblManufacturer.TabIndex = 6
            lblManufacturer.Text = "Manufacturer:"
            Controls.Add(lblManufacturer)
    
            ' Combo Box: Manufacturers
            cbxManufacturers = New ComboBox()
            cbxManufacturers.DropDownStyle = ComboBoxStyle.DropDownList
            cbxManufacturers.FormattingEnabled = True
            cbxManufacturers.Location = New Point(96, 50)
            cbxManufacturers.Size = New System.Drawing.Size(200, 21)
            cbxManufacturers.TabIndex = 7
            Controls.Add(cbxManufacturers)
    
            ' Button: New Manufacturer
            btnNewManufacturer = New Button()
            btnNewManufacturer.Location = New Point(302, 50)
            btnNewManufacturer.Size = New System.Drawing.Size(50, 23)
            btnNewManufacturer.TabIndex = 21
            btnNewManufacturer.Text = "New..."
            Controls.Add(btnNewManufacturer)
    
            ' Label: Category
            lblCategory = New Label()
            lblCategory.AutoSize = True
            lblCategory.Location = New Point(17, 82)
            lblCategory.TabIndex = 8
            lblCategory.Text = "Category:"
            Controls.Add(lblCategory)
    
            ' Combo Box: Categories
            cbxCategories = New ComboBox()
            cbxCategories.DropDownStyle = ComboBoxStyle.DropDownList
            cbxCategories.FormattingEnabled = True
            cbxCategories.Location = New Point(96, 79)
            cbxCategories.Size = New System.Drawing.Size(200, 21)
            cbxCategories.TabIndex = 9
            Controls.Add(cbxCategories)
    
            ' Button: New Category
            btnNewCategory = New Button()
            btnNewCategory.Location = New Point(302, 79)
            btnNewCategory.Size = New System.Drawing.Size(50, 23)
            btnNewCategory.TabIndex = 22
            btnNewCategory.Text = "New..."
            Controls.Add(btnNewCategory)
    
            ' Label: Sub-Category
            lblSubCategory = New Label()
            lblSubCategory.AutoSize = True
            lblSubCategory.Location = New Point(17, 113)
            lblSubCategory.TabIndex = 10
            lblSubCategory.Text = "Sub-Category:"
            Controls.Add(lblSubCategory)
    
            ' Combo Box: Sub-Categories
            cbxSubCategories = New ComboBox()
            cbxSubCategories.DropDownStyle = ComboBoxStyle.DropDownList
            cbxSubCategories.FormattingEnabled = True
            cbxSubCategories.Location = New Point(96, 109)
            cbxSubCategories.Size = New System.Drawing.Size(200, 21)
            cbxSubCategories.TabIndex = 11
            Controls.Add(cbxSubCategories)
    
            ' Button: New Sub-Category
            btnNewSubCategory = New Button()
            btnNewSubCategory.Location = New Point(302, 109)
            btnNewSubCategory.Size = New System.Drawing.Size(50, 23)
            btnNewSubCategory.TabIndex = 23
            btnNewSubCategory.Text = "New..."
            Controls.Add(btnNewSubCategory)
    
            ' Label: Item Name
            lblItemName = New Label()
            lblItemName.AutoSize = True
            lblItemName.Location = New Point(17, 142)
            lblItemName.TabIndex = 12
            lblItemName.Text = "Item Name:"
            Controls.Add(lblItemName)
    
            ' Text Box: Item Name
            txtItemName = New TextBox()
            txtItemName.Location = New Point(96, 139)
            txtItemName.Size = New System.Drawing.Size(256, 20)
            txtItemName.TabIndex = 13
            Controls.Add(txtItemName)
    
            ' Label: Item Size
            lblItemSize = New Label()
            lblItemSize.AutoSize = True
            lblItemSize.Location = New Point(17, 172)
            lblItemSize.TabIndex = 14
            lblItemSize.Text = "Item Size:"
            Controls.Add(lblItemSize)
    
            ' Text Box: Item Size
            txtItemSize = New TextBox()
            txtItemSize.Location = New Point(96, 169)
            txtItemSize.Size = New System.Drawing.Size(256, 20)
            txtItemSize.TabIndex = 15
            Controls.Add(txtItemSize)
    
            ' Label: Unit Price
            lblUnitPrice = New Label()
            lblUnitPrice.AutoSize = True
            lblUnitPrice.Location = New Point(17, 201)
            lblUnitPrice.TabIndex = 16
            lblUnitPrice.Text = "Unit Price:"
            Controls.Add(lblUnitPrice)
    
            ' Text Box: Unit Price
            txtUnitPrice = New TextBox()
            txtUnitPrice.Location = New Point(96, 198)
            txtUnitPrice.Size = New System.Drawing.Size(94, 20)
            txtUnitPrice.TabIndex = 17
            txtUnitPrice.Text = "0.00"
            txtUnitPrice.TextAlign = HorizontalAlignment.Right
            Controls.Add(txtUnitPrice)
    
            ' Label: Discount Rate
            lblDiscountRate = New Label()
            lblDiscountRate.AutoSize = True
            lblDiscountRate.Location = New Point(200, 201)
            lblDiscountRate.Size = New System.Drawing.Size(78, 13)
            lblDiscountRate.TabIndex = 18
            lblDiscountRate.Text = "Discount Rate:"
            Controls.Add(lblDiscountRate)
    
            ' Text Box: Discount Rate
            txtDiscountRate = New TextBox()
            txtDiscountRate.Location = New Point(284, 198)
            txtDiscountRate.Size = New System.Drawing.Size(47, 20)
            txtDiscountRate.TabIndex = 19
            txtDiscountRate.Text = "0.00"
            txtDiscountRate.TextAlign = HorizontalAlignment.Right
            Controls.Add(txtDiscountRate)
    
            ' Label: Discount Percent
            lblDiscountPercent = New Label()
            lblDiscountPercent.AutoSize = True
            lblDiscountPercent.Location = New Point(334, 201)
            lblDiscountPercent.TabIndex = 20
            lblDiscountPercent.Text = "%"
            Controls.Add(lblDiscountPercent)
    
            ' Button: Submit
            btnSubmit = New Button()
            btnSubmit.Location = New Point(113, 236)
            btnSubmit.Size = New System.Drawing.Size(75, 23)
            btnSubmit.TabIndex = 25
            btnSubmit.Text = "Submit"
            Controls.Add(btnSubmit)
    
            ' Button: Reset
            btnReset = New Button()
            btnReset.Location = New Point(194, 236)
            btnReset.Size = New System.Drawing.Size(75, 23)
            btnReset.TabIndex = 26
            btnReset.Text = "Reset"
            Controls.Add(btnReset)
    
            ' Button: Close
            btnClose = New Button()
            btnClose.Location = New Point(275, 236)
            btnClose.Size = New System.Drawing.Size(75, 23)
            btnClose.TabIndex = 24
            btnClose.Text = "Close"
            Controls.Add(btnClose)
    
            ' Dialog Box: New Store Item
            ClientSize = New System.Drawing.Size(372, 280)
            FormBorderStyle = FormBorderStyle.FixedDialog
            MaximizeBox = False
            MinimizeBox = False
            ShowInTaskbar = False
            StartPosition = FormStartPosition.CenterScreen
            Text = "FunDS - New Store Item"
        End Sub
    
        Private Sub PopulateStoreItem()
            Dim rndNumber As Random = New Random()
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems.xml"
    
            ' Set some default values on the New Store Item dialog box before the user opens it
            ' Create a random item number. The user can change it if necessary
            txtItemNumber.Text = CStr(rndNumber.Next(100000, 999999))
    
            cbxManufacturers.Items.Clear()
            cbxCategories.Items.Clear()
            cbxSubCategories.Items.Clear()
    
            If File.Exists(strStoreItemsFile) Then
                Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Open, FileAccess.Read)
                    xdStoreItems.Load(fsStoreItems)
    
                    Dim xnlCategories As XmlNodeList = xdStoreItems.SelectNodes("/StoreItems/StoreItem/Category")
                    Dim xnlSubCategories As XmlNodeList = xdStoreItems.SelectNodes("/StoreItems/StoreItem/SubCategory")
                    Dim xnlManufacturers As XmlNodeList = xdStoreItems.SelectNodes("/StoreItems/StoreItem/Manufacturer")
    
                    For Each xnManufacturer As XmlNode In xnlManufacturers
                        If Not cbxManufacturers.Items.Contains(xnManufacturer.InnerText) Then
                            cbxManufacturers.Items.Add(xnManufacturer.InnerText)
                        End If
                    Next
    
                    For Each xnCategory As XmlNode In xnlCategories
                        If Not cbxCategories.Items.Contains(xnCategory.InnerText) Then
                            cbxCategories.Items.Add(xnCategory.InnerText)
                        End If
                    next
    
                    For Each xnSubCategory As XmlNode In xnlSubCategories
                        If Not cbxSubCategories.Items.Contains(xnSubCategory.InnerText) Then
                            cbxSubCategories.Items.Add(xnSubCategory.InnerText)
                        End If
                    Next
    
                    cbxManufacturers.Sorted = True
                    cbxCategories.Sorted = True
                    cbxSubCategories.Sorted = True
    
                    cbxManufacturers.Text = "N/A"
                    cbxCategories.Text = "N/A"
                    cbxSubCategories.Text = "N/A"
                    txtItemName.Text = ""
                    txtItemSize.Text = ""
                    txtUnitPrice.Text = "0.00"
                    txtDiscountRate.Text = ""
                End Using
            End If
        End Sub
    
        Private Sub StoreItemLoad(ByVal sender As Object, ByVal e As EventArgs) Handles me.load
            PopulateStoreItem()
        End Sub
    
        Private Sub btnNewManufacturerClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnNewManufacturer.Click
            ' bool ManufacturerFound = false
            Dim man As Manufacturer = New Manufacturer()
    
            ' Show the New Manufacturer dialog box.
            ' Find out if the user clicked OK after using the dialog box
            If man.ShowDialog() = DialogResult.OK Then
                ' If the user clicked OK...
                ' ... if the Manufacturer text box was empty, do nothing
                If String.IsNullOrEmpty(man.txtManufacturer.Text) Then
                    MsgBox("You must enter a manufacturer's name.",
                           MsgBoxStyle.OKOnly Or MsgBoxStyle.Information,
                           "FunDS - Employees Records")
                    Exit Sub
                Else
                    If Not cbxManufacturers.Items.Contains(man.txtManufacturer.Text) Then
                        cbxManufacturers.Items.Add(man.txtManufacturer.Text)
                        cbxManufacturers.Text = man.txtManufacturer.Text
                    End If
                End If
            End If
        End Sub
    
        Private Sub btnNewCategoryClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnNewCategory.Click
            Dim cat As Category = New Category()
    
            If cat.ShowDialog() = DialogResult.OK Then
                If String.IsNullOrEmpty(cat.txtCategory.Text) Then
                    MsgBox("You must enter a category's name.",
                           MsgBoxStyle.OKOnly Or MsgBoxStyle.Information,
                           "FunDS - Employees Records")
                    Exit Sub
                Else
                    If Not cbxCategories.Items.Contains(cat.txtCategory.Text) Then
                        cbxCategories.Items.Add(cat.txtCategory.Text)
                        cbxCategories.Text = cat.txtCategory.Text
                    End If
                End If
            End If
        End Sub
    
        Private Sub btnNewSubCategoryClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnNewSubCategory.Click
            Dim sc As SubCategory = New SubCategory()
    
            If sc.ShowDialog() = DialogResult.OK Then
                If String.IsNullOrEmpty(sc.txtSubCategory.Text) Then
                    MsgBox("You must enter a sub-category's name.",
                           MsgBoxStyle.OKOnly Or MsgBoxStyle.Information,
                           "FunDS - Employees Records")
                    Exit Sub
                Else
                    If Not cbxSubCategories.Items.Contains(sc.txtSubCategory.Text) Then
                        cbxSubCategories.Items.Add(sc.txtSubCategory.Text)
                        cbxSubCategories.Text = sc.txtSubCategory.Text
                    End If
                End If
            End If
        End Sub
    
        Private Sub btnResetClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
            PopulateStoreItem()
        End Sub
    
        Private Sub btnSubmitClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems.xml"
    
            If String.IsNullOrEmpty(txtItemNumber.Text) Then
                MsgBox("You must provide at least an item number.",
                           MsgBoxStyle.OKOnly Or MsgBoxStyle.Information,
                           "FunDS - Employees Records")
                Exit Sub
            ElseIf (String.IsNullOrEmpty(txtItemName.Text)) Then
                MsgBox("You must specify the name of the item or a (short) description.",
                           MsgBoxStyle.OKOnly Or MsgBoxStyle.Information,
                           "FunDS - Employees Records")
                Exit Sub
            End If
    
            If Not File.Exists(strStoreItemsFile) Then
                Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Create, FileAccess.Write)
                xdStoreItems.LoadXml("<?xml version=""1.0"" encoding=""utf-8""?>" &
                                     "<StoreItems></StoreItems>")
                    xdStoreItems.Save(fsStoreItems)
                End Using
            End If
    
            Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Open, FileAccess.Read)
                xdStoreItems.Load(fsStoreItems)
            End Using
    
            Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Create, FileAccess.Write)
                Dim xeStoreItem As XmlElement = xdStoreItems.CreateElement("StoreItem")
                xeStoreItem.InnerXml = "<ItemNumber>" & txtItemNumber.Text & "</ItemNumber>" &
                                       "<Manufacturer>" & cbxManufacturers.Text & "</Manufacturer>" &
                                       "<Category>" & cbxCategories.Text & "</Category>" &
                                       "<SubCategory>" & cbxSubCategories.Text & "</SubCategory>" &
                                       "<ItemName>" & txtItemName.Text & "</ItemName>" &
                                       "<ItemSize>" & txtItemSize.Text & "</ItemSize>" &
                                       "<UnitPrice>" & txtUnitPrice.Text & "</UnitPrice>" &
                                       "<DiscountRate>" & txtDiscountRate.Text & "</DiscountRate>"
    
                xdStoreItems.DocumentElement.AppendChild(xeStoreItem)
    
                xdStoreItems.Save(fsStoreItems)
            End Using
    
            PopulateStoreItem()
        End Sub
    
        Private Sub btnCloseClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
            Close()
        End Sub
    
    End Class
  20. On the main menu, click File -> New
  21. When asked whether you want to save, click Save
  22. In the top combo box, make sure FunDS1 is selected Set the Save As Type combo box to All Files
  23. Set the File Name to StoreItemNew.vb
  24. Click Save

Editing a Store Item

Editing an item consists of changing any of its aspects. Since this is an XML-based application, you can simply open a file in a text editor and change anything. As for us, we will provide a form that can be used to enter an item number and click a button to find it. If the item is found, the employee can make any changes, and save it.

Practical LearningPractical Learning: Editing a Store Item

  1. In the empty document, type the following:
    Imports System
    Imports System.IO
    Imports System.Xml
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class StoreItemEditor
        Inherits Form
    
        Private lblItemNumber As Label
        Public txtItemNumber As TextBox
        Private WithEvents btnFind As Button
        Private lblManufacturer As Label
        Public cbxManufacturers As ComboBox
        Private WithEvents btnNewManufacturer As Button
        Private lblCategory As Label
        Public cbxCategories As ComboBox
        Private WithEvents btnNewCategory As Button
        Private lblSubCategory As Label
        Public cbxSubCategories As ComboBox
        Private WithEvents btnNewSubCategory As Button
        Private lblItemName As Label
        Public txtItemName As TextBox
        Private lblItemSize As Label
        Public txtItemSize As TextBox
        Private lblUnitPrice As Label
        Public txtUnitPrice As TextBox
        Private lblDiscountRate As Label
        Public txtDiscountRate As TextBox
        Private lblDiscountPercent As Label
        Private WithEvents btnUpdate As Button
        Private WithEvents btnClose As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            ' Label: Item Number
            lblItemNumber = New Label()
            lblItemNumber.AutoSize = True
            lblItemNumber.Location = New Point(17, 24)
            lblItemNumber.TabIndex = 2
            lblItemNumber.Text = "Item Number:"
            Controls.Add(lblItemNumber)
    
            txtItemNumber = New TextBox()
            txtItemNumber.Location = New Point(96, 21)
            txtItemNumber.Size = New System.Drawing.Size(75, 20)
            txtItemNumber.TabIndex = 3
            Controls.Add(txtItemNumber)
    
            ' Button: New Find
            btnFind = New Button()
            btnFind.Location = New Point(180, 20)
            btnFind.Size = New System.Drawing.Size(50, 23)
            btnFind.TabIndex = 21
            btnFind.Text = "Find"
            Controls.Add(btnFind)
    
            ' Label: Manufacturer
            lblManufacturer = New Label()
            lblManufacturer.AutoSize = True
            lblManufacturer.Location = New Point(17, 54)
            lblManufacturer.TabIndex = 6
            lblManufacturer.Text = "Manufacturer:"
            Controls.Add(lblManufacturer)
    
            ' Combo Box: Manufacturers
            cbxManufacturers = New ComboBox()
            cbxManufacturers.Location = New Point(96, 50)
            cbxManufacturers.Size = New System.Drawing.Size(200, 21)
            cbxManufacturers.TabIndex = 7
            cbxManufacturers.Sorted = True
            Controls.Add(cbxManufacturers)
    
            ' Button: New Manufacturer
            btnNewManufacturer = New Button()
            btnNewManufacturer.Location = New Point(302, 49)
            btnNewManufacturer.Size = New System.Drawing.Size(50, 23)
            btnNewManufacturer.TabIndex = 21
            btnNewManufacturer.Text = "New..."
            Controls.Add(btnNewManufacturer)
    
            ' Label: Category
            lblCategory = New Label()
            lblCategory.AutoSize = True
            lblCategory.Location = New Point(17, 82)
            lblCategory.TabIndex = 8
            lblCategory.Text = "Category:"
            Controls.Add(lblCategory)
    
            ' Combo Box: Categories
            cbxCategories = New ComboBox()
            cbxCategories.Location = New Point(96, 79)
            cbxCategories.Size = New System.Drawing.Size(200, 21)
            cbxCategories.TabIndex = 9
            cbxCategories.Sorted = True
            Controls.Add(cbxCategories)
    
            ' Button: New Category
            btnNewCategory = New Button()
            btnNewCategory.Location = New Point(302, 77)
            btnNewCategory.Size = New System.Drawing.Size(50, 23)
            btnNewCategory.TabIndex = 22
            btnNewCategory.Text = "New..."
            Controls.Add(btnNewCategory)
    
            ' Label: Sub-Category
            lblSubCategory = New Label()
            lblSubCategory.AutoSize = True
            lblSubCategory.Location = New Point(17, 113)
            lblSubCategory.TabIndex = 10
            lblSubCategory.Text = "Sub-Category:"
            Controls.Add(lblSubCategory)
    
            ' Combo Box: Sub-Categories
            cbxSubCategories = New ComboBox()
            cbxSubCategories.Location = New Point(96, 109)
            cbxSubCategories.Size = New System.Drawing.Size(200, 21)
            cbxSubCategories.TabIndex = 11
            cbxSubCategories.Sorted = True
            Controls.Add(cbxSubCategories)
    
            ' Button: New Sub-Category
            btnNewSubCategory = New Button()
            btnNewSubCategory.Location = New Point(302, 107)
            btnNewSubCategory.Size = New System.Drawing.Size(50, 23)
            btnNewSubCategory.TabIndex = 23
            btnNewSubCategory.Text = "New..."
            Controls.Add(btnNewSubCategory)
    
            ' Label: Item Name
            lblItemName = New Label()
            lblItemName.AutoSize = True
            lblItemName.Location = New Point(17, 142)
            lblItemName.TabIndex = 12
            lblItemName.Text = "Item Name:"
            Controls.Add(lblItemName)
    
            ' Text Box: Item Name
            txtItemName = New TextBox()
            txtItemName.Location = New Point(96, 139)
            txtItemName.Size = New System.Drawing.Size(256, 20)
            txtItemName.TabIndex = 13
            Controls.Add(txtItemName)
    
            ' Label: Item Size
            lblItemSize = New Label()
            lblItemSize.AutoSize = True
            lblItemSize.Location = New Point(17, 172)
            lblItemSize.TabIndex = 14
            lblItemSize.Text = "Item Size:"
            Controls.Add(lblItemSize)
    
            ' Text Box: Item Size
            txtItemSize = New TextBox()
            txtItemSize.Location = New Point(96, 169)
            txtItemSize.Size = New System.Drawing.Size(256, 20)
            txtItemSize.TabIndex = 15
            Controls.Add(txtItemSize)
    
            ' Label: Unit Price
            lblUnitPrice = New Label()
            lblUnitPrice.AutoSize = True
            lblUnitPrice.Location = New Point(17, 201)
            lblUnitPrice.TabIndex = 16
            lblUnitPrice.Text = "Unit Price:"
            Controls.Add(lblUnitPrice)
    
            ' Text Box: Unit Price
            txtUnitPrice = New TextBox()
            txtUnitPrice.Location = New Point(96, 198)
            txtUnitPrice.Size = New System.Drawing.Size(94, 20)
            txtUnitPrice.TabIndex = 17
            txtUnitPrice.Text = "0.00"
            txtUnitPrice.TextAlign = HorizontalAlignment.Right
            Controls.Add(txtUnitPrice)
    
            ' Label: Discount Rate
            lblDiscountRate = New Label()
            lblDiscountRate.AutoSize = True
            lblDiscountRate.Location = New Point(200, 201)
            lblDiscountRate.Size = New System.Drawing.Size(78, 13)
            lblDiscountRate.TabIndex = 18
            lblDiscountRate.Text = "Discount Rate:"
            Controls.Add(lblDiscountRate)
    
            ' Text Box: Discount Rate
            txtDiscountRate = New TextBox()
            txtDiscountRate.Location = New Point(284, 198)
            txtDiscountRate.Size = New System.Drawing.Size(47, 20)
            txtDiscountRate.TabIndex = 19
            txtDiscountRate.Text = "0.00"
            txtDiscountRate.TextAlign = HorizontalAlignment.Right
            Controls.Add(txtDiscountRate)
    
            ' Label: Discount Percent
            lblDiscountPercent = New Label()
            lblDiscountPercent.AutoSize = True
            lblDiscountPercent.Location = New Point(334, 201)
            lblDiscountPercent.TabIndex = 20
            lblDiscountPercent.Text = "%"
            Controls.Add(lblDiscountPercent)
    
            ' Button: Update
            btnUpdate = New Button()
            btnUpdate.Location = New Point(196, 231)
            btnUpdate.Size = New System.Drawing.Size(75, 23)
            btnUpdate.TabIndex = 25
            btnUpdate.Text = "Update"
            Controls.Add(btnUpdate)
    
            ' Button: Close
            btnClose = New Button()
            btnClose.Location = New Point(275, 231)
            btnClose.Size = New System.Drawing.Size(75, 23)
            btnClose.TabIndex = 24
            btnClose.Text = "Close"
            Controls.Add(btnClose)
    
            ' Dialog Box: New Store Item
            ClientSize = New System.Drawing.Size(372, 276)
            FormBorderStyle = FormBorderStyle.FixedDialog
            MaximizeBox = False
            MinimizeBox = False
            ShowInTaskbar = False
            StartPosition = FormStartPosition.CenterScreen
            Text = "FunDS - Edit Store Item"
        End Sub
    
        Private Sub PopulateStoreItem()
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems.xml"
    
            cbxManufacturers.Items.Clear()
            cbxCategories.Items.Clear()
            cbxSubCategories.Items.Clear()
    
            If File.Exists(strStoreItemsFile) Then
                Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Open, FileAccess.Read)
                    xdStoreItems.Load(fsStoreItems)
    
                    Dim xnlCategories As XmlNodeList = xdStoreItems.SelectNodes("/StoreItems/StoreItem/Category")
                    Dim xnlSubCategories As XmlNodeList = xdStoreItems.SelectNodes("/StoreItems/StoreItem/SubCategory")
                    Dim xnlManufacturers As XmlNodeList = xdStoreItems.SelectNodes("/StoreItems/StoreItem/Manufacturer")
    
                    For Each xnManufacturer As XmlNode In xnlManufacturers
                        If Not cbxManufacturers.Items.Contains(xnManufacturer.InnerText) Then
                            cbxManufacturers.Items.Add(xnManufacturer.InnerText)
                        End If
                    Next
    
                    For Each xnCategory As XmlNode In xnlCategories
                        If Not cbxCategories.Items.Contains(xnCategory.InnerText) Then
                            cbxCategories.Items.Add(xnCategory.InnerText)
                        End If
                    Next
    
                    For Each xnSubCategory As XmlNode In xnlSubCategories
                        If Not cbxSubCategories.Items.Contains(xnSubCategory.InnerText) Then
                            cbxSubCategories.Items.Add(xnSubCategory.InnerText)
                        End If
                    Next
                End Using
            End If
        End Sub
    
        Private Sub StoreItemLoad(ByVal sender As Object, ByVal e As EventArgs) Handles me.load
            PopulateStoreItem()
        End Sub
    
        Private Sub btnNewManufacturerClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnNewManufacturer.Click
            Dim man As Manufacturer = New Manufacturer()
    
            ' Show the New Manufacturer dialog box.
            ' Find out if the user clicked OK after using the dialog box
            If man.ShowDialog() = DialogResult.OK Then
                ' If the user clicked OK...
                ' ... if the Manufacturer text box was empty, do nothing
                If String.IsNullOrEmpty(man.txtManufacturer.Text) Then
                    MsgBox("You must enter a manufacturer's name.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                    Exit Sub
                Else
                    If Not cbxManufacturers.Items.Contains(man.txtManufacturer.Text) Then
                        cbxManufacturers.Items.Add(man.txtManufacturer.Text)
                        cbxManufacturers.Text = man.txtManufacturer.Text
                    End If
                End If
            End If
        End Sub
    
        Private Sub btnNewCategoryClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnNewCategory.Click
            Dim cat As Category = New Category()
    
            If cat.ShowDialog() = DialogResult.OK Then
                If String.IsNullOrEmpty(cat.txtCategory.Text) Then
                    MsgBox("You must enter a category's name.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                    Exit Sub
                Else
                    If Not cbxCategories.Items.Contains(cat.txtCategory.Text) Then
                        cbxCategories.Items.Add(cat.txtCategory.Text)
                        cbxCategories.Text = cat.txtCategory.Text
                    End If
                End If
            End If
        End Sub
    
        Private Sub btnNewSubCategoryClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnNewSubCategory.Click
    
            Dim sc As SubCategory = New SubCategory()
    
            If sc.ShowDialog() = DialogResult.OK Then
                If String.IsNullOrEmpty(sc.txtSubCategory.Text) Then
                    MsgBox("You must enter a sub-category's name.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                    Exit Sub
                Else
                    If Not cbxSubCategories.Items.Contains(sc.txtSubCategory.Text) Then
                        cbxSubCategories.Items.Add(sc.txtSubCategory.Text)
                        cbxSubCategories.Text = sc.txtSubCategory.Text
                    End If
                End If
            End If
        End Sub
    
        Private Sub btnFindClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnFind.Click
            Dim itemFound As Boolean = False
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems.xml"
    
            If String.IsNullOrEmpty(txtItemNumber.Text) Then
                MsgBox("You must provide an item number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                Exit Sub
            End If
    
            If File.Exists(strStoreItemsFile) Then
                Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Open, FileAccess.Read)
                    xdStoreItems.Load(fsStoreItems)
    
                    Dim xnlStoreItems As XmlNodeList = xdStoreItems.GetElementsByTagName("ItemNumber")
    
                    For Each xnStoreItem As XmlNode In xnlStoreItems
                        If xnStoreItem.InnerText = txtItemNumber.Text Then
                            itemFound = True
                            cbxManufacturers.Text = xnStoreItem.NextSibling.InnerText
                            cbxCategories.Text = xnStoreItem.NextSibling.NextSibling.InnerText
                            cbxSubCategories.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.InnerText
                            txtItemName.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                            txtItemSize.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                            txtUnitPrice.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                            txtDiscountRate.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
    
                            Exit Sub
                        End If
                    Next
    
                    If itemFound = False Then
                        MsgBox("There is no item with that number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                    End If
                End Using
            End If
        End Sub
    
        Private Sub btnUpdateClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
            Dim itemFound As Boolean = False
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems.xml"
    
            If String.IsNullOrEmpty(txtItemNumber.Text) Then
                MsgBox("You must provide an item number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                Exit Sub
            End If
    
            If File.Exists(strStoreItemsFile) Then
                xdStoreItems.Load(strStoreItemsFile)
    
                Dim xnlStoreItems As XmlNodeList = xdStoreItems.GetElementsByTagName("ItemNumber")
    
                For Each xnStoreItem As XmlNode In xnlStoreItems
                    If xnStoreItem.InnerText = txtItemNumber.Text Then
                        itemFound = True
                        xnStoreItem.ParentNode.InnerXml = "<ItemNumber>" & txtItemNumber.Text & "</ItemNumber>" &
                                                          "<Manufacturer>" & cbxManufacturers.Text & "</Manufacturer>" &
                                                          "<Category>" & cbxCategories.Text & "</Category>" &
                                                          "<SubCategory>" & cbxSubCategories.Text & "</SubCategory>" &
                                                          "<ItemName>" & txtItemName.Text & "</ItemName>" &
                                                          "<ItemSize>" & txtItemSize.Text & "</ItemSize>" &
                                                          "<UnitPrice>" & txtUnitPrice.Text & "</UnitPrice>" &
                                                          "<DiscountRate>" & txtDiscountRate.Text & "</DiscountRate>"
                        Exit For
                    End If
                Next
    
                If (itemFound = True) Then
                    xdStoreItems.Save(strStoreItemsFile)
                    MsgBox("The store item has been updated.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
    
                    PopulateStoreItem()
                    txtItemNumber.Text = ""
                End If
            End If
        End Sub
    
        Private Sub btnCloseClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
            Close()
        End Sub
  2. On the main menu, click File -> New
  3. When asked whether you want to save, click Save
  4. In the top combo box, make sure the FunDS1 folder is displaying, Set the Save As Type to All Files
  5. Set the name to StoreItemEditor.vb
  6. Click Save

Deleting a Store Item

To make sure we cover most aspects of data maintenance are covered, we will give the company the ability to delete an item from the inventory.

Practical LearningPractical Learning: Deleting an Item

  1. In the empty document, type the following:
    Imports System
    Imports System.IO
    Imports System.Xml
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class StoreItemDelete
        Inherits Form
    
        Private lblItemNumber As Label
        Public txtItemNumber As TextBox
        Private WithEvents btnFind As Button
        Private lblManufacturer As Label
        Public txtManufacturer As TextBox
        Private lblCategory As Label
        Public txtCategory As TextBox
        Private lblSubCategory As Label
        Public txtSubCategory As TextBox
        Private lblItemName As Label
        Public txtItemName As TextBox
        Private lblItemSize As Label
        Public txtItemSize As TextBox
        Private lblUnitPrice As Label
        Public txtUnitPrice As TextBox
        Private lblDiscountRate As Label
        Public txtDiscountRate As TextBox
        Private lblDiscountPercent As Label
        Private WithEvents btnDelete As Button
        Private WithEvents btnClose As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            ' Label: Item Number
            lblItemNumber = New Label()
            lblItemNumber.AutoSize = True
            lblItemNumber.Location = New Point(17, 24)
            lblItemNumber.TabIndex = 0
            lblItemNumber.Text = "Item Number:"
            Controls.Add(lblItemNumber)
    
            txtItemNumber = New TextBox()
            txtItemNumber.Location = New Point(96, 21)
            txtItemNumber.Size = New System.Drawing.Size(75, 20)
            txtItemNumber.TabIndex = 1
            Controls.Add(txtItemNumber)
    
            ' Button: New Find
            btnFind = New Button()
            btnFind.Location = New Point(180, 20)
            btnFind.Size = New System.Drawing.Size(50, 23)
            btnFind.TabIndex = 2
            btnFind.Text = "Find"
            Controls.Add(btnFind)
    
            ' Label: Manufacturer
            lblManufacturer = New Label()
            lblManufacturer.AutoSize = True
            lblManufacturer.Location = New Point(17, 54)
            lblManufacturer.TabIndex = 5
            lblManufacturer.Text = "Manufacturer:"
            Controls.Add(lblManufacturer)
    
            ' Combo Box: Manufacturers
            txtManufacturer = New TextBox()
            txtManufacturer.Location = New Point(96, 50)
            txtManufacturer.Size = New System.Drawing.Size(200, 21)
            txtManufacturer.TabIndex = 6
            Controls.Add(txtManufacturer)
    
            ' Label: Category
            lblCategory = New Label()
            lblCategory.AutoSize = True
            lblCategory.Location = New Point(17, 82)
            lblCategory.TabIndex = 7
            lblCategory.Text = "Category:"
            Controls.Add(lblCategory)
    
            ' Combo Box: Categories
            txtCategory = New TextBox()
            txtCategory.Location = New Point(96, 79)
            txtCategory.Size = New System.Drawing.Size(200, 21)
            txtCategory.TabIndex = 8
            Controls.Add(txtCategory)
    
            ' Label: Sub-Category
            lblSubCategory = New Label()
            lblSubCategory.AutoSize = True
            lblSubCategory.Location = New Point(17, 113)
            lblSubCategory.TabIndex = 9
            lblSubCategory.Text = "Sub-Category:"
            Controls.Add(lblSubCategory)
    
            ' Combo Box: Sub-Categories
            txtSubCategory = New TextBox()
            txtSubCategory.Location = New Point(96, 109)
            txtSubCategory.Size = New System.Drawing.Size(200, 21)
            txtSubCategory.TabIndex = 10
            Controls.Add(txtSubCategory)
    
            ' Label: Item Name
            lblItemName = New Label()
            lblItemName.AutoSize = True
            lblItemName.Location = New Point(17, 142)
            lblItemName.TabIndex = 11
            lblItemName.Text = "Item Name:"
            Controls.Add(lblItemName)
    
            ' Text Box: Item Name
            txtItemName = New TextBox()
            txtItemName.Location = New Point(96, 139)
            txtItemName.Size = New System.Drawing.Size(256, 20)
            txtItemName.TabIndex = 12
            Controls.Add(txtItemName)
    
            ' Label: Item Size
            lblItemSize = New Label()
            lblItemSize.AutoSize = True
            lblItemSize.Location = New Point(17, 172)
            lblItemSize.TabIndex = 13
            lblItemSize.Text = "Item Size:"
            Controls.Add(lblItemSize)
    
            ' Text Box: Item Size
            txtItemSize = New TextBox()
            txtItemSize.Location = New Point(96, 169)
            txtItemSize.Size = New System.Drawing.Size(256, 20)
            txtItemSize.TabIndex = 14
            Controls.Add(txtItemSize)
    
            ' Label: Unit Price
            lblUnitPrice = New Label()
            lblUnitPrice.AutoSize = True
            lblUnitPrice.Location = New Point(17, 201)
            lblUnitPrice.TabIndex = 15
            lblUnitPrice.Text = "Unit Price:"
            Controls.Add(lblUnitPrice)
    
            ' Text Box: Unit Price
            txtUnitPrice = New TextBox()
            txtUnitPrice.Location = New Point(96, 198)
            txtUnitPrice.Size = New System.Drawing.Size(94, 20)
            txtUnitPrice.TabIndex = 16
            txtUnitPrice.Text = "0.00"
            txtUnitPrice.TextAlign = HorizontalAlignment.Right
            Controls.Add(txtUnitPrice)
    
            ' Label: Discount Rate
            lblDiscountRate = New Label()
            lblDiscountRate.AutoSize = True
            lblDiscountRate.Location = New Point(200, 201)
            lblDiscountRate.Size = New System.Drawing.Size(78, 13)
            lblDiscountRate.TabIndex = 17
            lblDiscountRate.Text = "Discount Rate:"
            Controls.Add(lblDiscountRate)
    
            ' Text Box: Discount Rate
            txtDiscountRate = New TextBox()
            txtDiscountRate.Location = New Point(284, 198)
            txtDiscountRate.Size = New System.Drawing.Size(47, 20)
            txtDiscountRate.TabIndex = 18
            txtDiscountRate.Text = "0.00"
            txtDiscountRate.TextAlign = HorizontalAlignment.Right
            Controls.Add(txtDiscountRate)
    
            ' Label: Discount Percent
            lblDiscountPercent = New Label()
            lblDiscountPercent.AutoSize = True
            lblDiscountPercent.Location = New Point(334, 201)
            lblDiscountPercent.TabIndex = 19
            lblDiscountPercent.Text = "%"
            Controls.Add(lblDiscountPercent)
    
            ' Button: Delete
            btnDelete = New Button()
            btnDelete.Location = New Point(196, 231)
            btnDelete.Size = New System.Drawing.Size(75, 23)
            btnDelete.TabIndex = 3
            btnDelete.Text = "Delete"
            Controls.Add(btnDelete)
    
            ' Button: Close
            btnClose = New Button()
            btnClose.Location = New Point(275, 231)
            btnClose.Size = New System.Drawing.Size(75, 23)
            btnClose.TabIndex = 4
            btnClose.Text = "Close"
            Controls.Add(btnClose)
    
            ' Dialog Box: New Store Item
            ClientSize = New System.Drawing.Size(372, 276)
            FormBorderStyle = FormBorderStyle.FixedDialog
            MaximizeBox = False
            MinimizeBox = False
            ShowInTaskbar = False
            StartPosition = FormStartPosition.CenterScreen
            Text = "FunDS - Store Item Deletion"
        End Sub
    
        Private Sub btnFindClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnFind.Click
            Dim itemFound As Boolean = False
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems.xml"
    
            If String.IsNullOrEmpty(txtItemNumber.Text) Then
                MsgBox("You must provide an item number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                Exit Sub
            End If
    
            If File.Exists(strStoreItemsFile) Then
                Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Open, FileAccess.Read)
                    xdStoreItems.Load(fsStoreItems)
    
                    Dim xnlStoreItems As XmlNodeList = xdStoreItems.GetElementsByTagName("ItemNumber")
    
                    For Each xnStoreItem As XmlNode In xnlStoreItems
                        If xnStoreItem.InnerText = txtItemNumber.Text Then
                            itemFound = True
                            txtManufacturer.Text = xnStoreItem.NextSibling.InnerText
                            txtCategory.Text = xnStoreItem.NextSibling.NextSibling.InnerText
                            txtSubCategory.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.InnerText
                            txtItemName.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                            txtItemSize.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                            txtUnitPrice.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                            txtDiscountRate.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
    
                            Exit Sub
                        End If
                    Next
    
                    If itemFound = False Then
                        MsgBox("There is no item with that number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                    End If
                End Using
            End If
        End Sub
    
        Private Sub btnDeleteClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnDelete.Click
            Dim itemFound As Boolean = False
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems.xml"
    
            If String.IsNullOrEmpty(txtItemNumber.Text) Then
                MsgBox("You must provide an item number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                Exit Sub
            End If
    
            If File.Exists(strStoreItemsFile) Then
                Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Open, FileAccess.Read)
                    xdStoreItems.Load(fsStoreItems)
    
                    Dim xnlStoreItems As XmlNodeList = xdStoreItems.GetElementsByTagName("ItemNumber")
    
                    For Each xnStoreItem As XmlNode In xnlStoreItems
                        If xnStoreItem.InnerText = txtItemNumber.Text Then
                            itemFound = True
                            xdStoreItems.DocumentElement.RemoveChild(xnStoreItem.ParentNode)
                            Exit For
                        End If
                    Next
                End Using
    
                If itemFound = True Then
                    Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Create, FileAccess.Write)
                        xdStoreItems.Save(fsStoreItems)
                        MsgBox("The store item has been deleted.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                    End Using
    
                    txtItemNumber.Text = ""
                    txtManufacturer.Text = ""
                    txtCategory.Text = ""
                    txtSubCategory.Text = ""
                    txtItemName.Text = ""
                    txtItemSize.Text = ""
                    txtUnitPrice.Text = "0.00"
                    txtDiscountRate.Text = "0.00"
                End If
            End If
        End Sub
    
        Private Sub btnCloseClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
            Close()
        End Sub
    
    End Class
  2. On the main menu, click File -> New
  3. When asked whether you want to save, click Save
  4. In the top combo box, make sure the FunDS1 folder is displaying, Set the Save As Type to All Files
  5. Set the File Name to StoreItemDelete.vb
  6. Click Save
  7. In the empty document, type the following:
    Imports System
    Imports System.IO
    Imports System.Xml
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class StoreItems
        Inherits Form
    
        Private colStoreItemID As ColumnHeader
        Private colItemNumber As ColumnHeader
        Private colManufacturer As ColumnHeader
        Private colCategory As ColumnHeader
        Private colSubCategory As ColumnHeader
        Private colItemName As ColumnHeader
        Private colItemSize As ColumnHeader
        Private colUnitPrice As ColumnHeader
        Private colDiscountRate As ColumnHeader
        Private colDiscountAmount As ColumnHeader
        Private colMarkedPrice As ColumnHeader
        Private WithEvents lvwStoreItems As ListView
        Private lblNumberOfItems As Label
        Private txtNumberOfItems As TextBox
        Private WithEvents btnNewStoreItem As Button
        Private WithEvents btnEditStoreItem As Button
        Private WithEvents btnDeleteStoreItem As Button
        Private WithEvents btnClose As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            ' Column: umn: Store Item ID
            colStoreItemID = New ColumnHeader()
            colStoreItemID.Text = "Item ID"
            colStoreItemID.Width = 50
    
            ' Column: umn: Item Number
            colItemNumber = New ColumnHeader()
            colItemNumber.Text = "Item #"
            colItemNumber.TextAlign = HorizontalAlignment.Center
    
            ' Column: umn: Manufacturer
            colManufacturer = New ColumnHeader()
            colManufacturer.Text = "Manufacturer"
            colManufacturer.Width = 130
    
            ' Column: umn: Category
            colCategory = New ColumnHeader()
            colCategory.Text = "Category"
            colCategory.Width = 70
    
            ' Column: umn: Sub-Category
            colSubCategory = New ColumnHeader()
            colSubCategory.Text = "Sub-Category"
            colSubCategory.Width = 80
    
            ' Column: umn: Item Name
            colItemName = New ColumnHeader()
            colItemName.Text = "Item Name"
            colItemName.Width = 300
    
            ' Column: umn: Item Size
            colItemSize = New ColumnHeader()
            colItemSize.Text = "Size"
            colItemSize.Width = 80
    
            ' Column: umn: Unit Price
            colUnitPrice = New ColumnHeader()
            colUnitPrice.Text = "Unit Price"
            colUnitPrice.TextAlign = HorizontalAlignment.Right
    
            ' Column: umn: Discount Rate
            colDiscountRate = New ColumnHeader()
            colDiscountRate.Text = "Disc Rate"
            colDiscountRate.TextAlign = HorizontalAlignment.Right
            colDiscountRate.Width = 60
    
            ' Column: umn: Discount Amount
            colDiscountAmount = New ColumnHeader()
            colDiscountAmount.Text = "Disc Amt"
            colDiscountAmount.TextAlign = HorizontalAlignment.Right
    
            ' Column: umn: Marked Price
            colMarkedPrice = New ColumnHeader()
            colMarkedPrice.Text = "Marked Price"
            colMarkedPrice.TextAlign = HorizontalAlignment.Right
            colMarkedPrice.Width = 75
    
            lvwStoreItems = New ListView()
            lvwStoreItems.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
            lvwStoreItems.Columns.AddRange(new ColumnHeader() {
                colStoreItemID,     colItemNumber, colManufacturer,
                colCategory, colSubCategory, colItemName, colItemSize,
            colUnitPrice, colDiscountRate, colDiscountAmount, colMarkedPrice })
            lvwStoreItems.FullRowSelect = True
            lvwStoreItems.GridLines = True
            lvwStoreItems.Location = New Point(15, 15)
            lvwStoreItems.Size = New System.Drawing.Size(1050, 340)
            lvwStoreItems.TabIndex = 3
            lvwStoreItems.View = View.Details
    
            lblNumberOfItems = New Label()
            lblNumberOfItems.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
            lblNumberOfItems.AutoSize = True
            lblNumberOfItems.Location = New Point(15, 370)
            lblNumberOfItems.TabIndex = 6
            lblNumberOfItems.Text = "Number of Items:"
    
            ' Text Box: Number of Items
            txtNumberOfItems = New TextBox()
            txtNumberOfItems.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
            txtNumberOfItems.Location = New Point(111, 368)
            txtNumberOfItems.Size = New System.Drawing.Size(60, 20)
            txtNumberOfItems.TabIndex = 7
            txtNumberOfItems.TextAlign = HorizontalAlignment.Right
    
            btnNewStoreItem = New Button()
            btnNewStoreItem.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
            btnNewStoreItem.Location = New Point(530, 366)
            btnNewStoreItem.Size = New System.Drawing.Size(125, 32)
            btnNewStoreItem.TabIndex = 5
            btnNewStoreItem.Text = "New Store Item ..."
    
            ' Button: Edit Item
            btnEditStoreItem = New Button()
            btnEditStoreItem.Location = New Point(659, 366)
            btnEditStoreItem.Size = New System.Drawing.Size(125, 32)
            btnEditStoreItem.Text = "Edit Store Item..."
            btnEditStoreItem.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
    
            ' Button: Remove Item
            btnDeleteStoreItem = New Button()
            btnDeleteStoreItem.Location = New Point(792, 366)
            btnDeleteStoreItem.Size = New System.Drawing.Size(125, 32)
            btnDeleteStoreItem.Text = "Delete Store Item..."
            btnDeleteStoreItem.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
    
            btnClose = New Button()
            btnClose.Location = New Point(922, 366)
            btnClose.Size = New System.Drawing.Size(125, 32)
            btnClose.TabIndex = 4
            btnClose.Text = "Close"
            btnClose.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
    
            ClientSize = New System.Drawing.Size(1080, 410)
    
            Controls.Add(txtNumberOfItems)
            Controls.Add(lblNumberOfItems)
            Controls.Add(btnNewStoreItem)
            Controls.Add(btnEditStoreItem)
            Controls.Add(btnDeleteStoreItem)
            Controls.Add(btnClose)
            Controls.Add(lvwStoreItems)
    
            StartPosition = FormStartPosition.CenterScreen
            Text = "Fun Department Store - Store Items"
        End Sub
    
        Private Sub ShowStoreItems()
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems.xml"
    
            If File.Exists(strStoreItemsFile) Then
                lvwStoreItems.Items.Clear()
    
                Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Open, FileAccess.Read)
                    xdStoreItems.Load(fsStoreItems)
    
                    Dim itemName As String = ""
                    Dim itemSize As String = ""
                    Dim strDiscountRate As String = ""
                    Dim itemNumber As String = ""
                    Dim manufacturer As String = ""
                    Dim category As String = ""
                    Dim subCategory As String = ""
                    Dim unitPrice As Double = 0.0
                    Dim discountRate As Double = 0.0
                    Dim discountAmount As Double = 0.0
                    Dim markedPrice As Double = 0.0
    
                    Dim xnlStoreItems As XmlNodeList = xdStoreItems.GetElementsByTagName("ItemNumber")
    
                    Dim i = 1
    
                    For Each xnStoreItem As XmlNode In xnlStoreItems
                        itemNumber = xnStoreItem.InnerText
                        manufacturer = xnStoreItem.NextSibling.InnerText
                        category = xnStoreItem.NextSibling.NextSibling.InnerText
                        subCategory = xnStoreItem.NextSibling.NextSibling.NextSibling.InnerText
                        itemName = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                        itemSize = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                        unitPrice = CDbl(xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText)
                        strDiscountRate = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
    
                        If (String.IsNullOrEmpty(strDiscountRate)) Then
                            discountRate = 0.0
                            discountAmount = 0.0
                            markedPrice = unitPrice
                        Else
                            discountRate = CDbl(strDiscountRate) / 100.0
                            discountAmount = unitPrice * discountRate
                            markedPrice = unitPrice - discountAmount
                        End If
    
                        Dim lviStoreItem As ListViewItem = New ListViewItem(CStr(i))
                        lviStoreItem.SubItems.Add(itemNumber) ' Item Number
                        lviStoreItem.SubItems.Add(manufacturer) ' Manufacturer
                        lviStoreItem.SubItems.Add(category) ' Category
                        lviStoreItem.SubItems.Add(subCategory) ' Sub-Category
                        lviStoreItem.SubItems.Add(itemName) ' Item Name
                        lviStoreItem.SubItems.Add(itemSize) ' Item Size
                        lviStoreItem.SubItems.Add(FormatNumber(unitPrice))
    
                        If discountRate = 0.0 Then
                            lviStoreItem.SubItems.Add("") ' Discount Rate
                            lviStoreItem.SubItems.Add("") ' Discount Amount
                            lviStoreItem.SubItems.Add(FormatNumber(unitPrice)) ' Marked Price
                        Else
                            lviStoreItem.SubItems.Add(FormatNumber(discountRate * 100) & "%")
                            lviStoreItem.SubItems.Add(FormatNumber(discountAmount))
                            lviStoreItem.SubItems.Add(FormatNumber(markedPrice)) ' Marked Price
                        End If
    
                        lvwStoreItems.Items.Add(lviStoreItem)
                        i = i + 1
                    Next
    
                    txtNumberOfItems.Text = xnlStoreItems.Count.ToString()
                End Using
            End If
        End Sub
    
        Private Sub StoreItemsLoad(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            ShowStoreItems()
        End Sub
    
        Private Sub btnNewStoreItemClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnNewStoreItem.Click
            Dim sin As StoreItemNew = New StoreItemNew()
            sin.ShowDialog()
    
            ShowStoreItems()
        End Sub
    
        Private Sub btnEditStoreItemClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnEditStoreItem.Click
            Dim sie As StoreItemEditor = New StoreItemEditor()
            sie.ShowDialog()
    
            ShowStoreItems()
        End Sub
    
        Private Sub btnDeleteStoreItemClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnDeleteStoreItem.Click
            Dim sid As StoreItemDelete = New StoreItemDelete()
            sid.ShowDialog()
    
            ShowStoreItems()
        End Sub
    
    
        Private Sub lvwStoreItemsDoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles lvwStoreItems.DoubleClick
            Dim sie As StoreItemEditor = New StoreItemEditor()
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems.xml"
    
            If lvwStoreItems.Items.Count <= 0 Then
                Exit Sub
            End If
    
            Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Open, FileAccess.Read)
                xdStoreItems.Load(fsStoreItems)
    
                Dim xnlStoreItems As XmlNodeList = xdStoreItems.GetElementsByTagName("ItemNumber")
    
                For Each xnStoreItem As XmlNode In xnlStoreItems
                    If xnStoreItem.InnerText = lvwStoreItems.SelectedItems(0).SubItems(1).Text Then
                        sie.txtItemNumber.Text = xnStoreItem.InnerText
                        sie.cbxManufacturers.Text = xnStoreItem.NextSibling.InnerText
                        sie.cbxCategories.Text = xnStoreItem.NextSibling.NextSibling.InnerText
                        sie.cbxSubCategories.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.InnerText
                        sie.txtItemName.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                        sie.txtItemSize.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                        sie.txtUnitPrice.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                        sie.txtDiscountRate.Text = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                    End If
                Next
            End Using
    
            sie.ShowDialog()
            ShowStoreItems()
        End Sub
        Private Sub btnCloseClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
            Close()
        End Sub
  8. On the main menu, click File -> New
  9. When asked whether you want to save, click Save
  10. In the top combo box, make sure the FunDS1 folder is displaying, Set the Save As Type to All Files
  11. Set the File Name to Inventory.vb
  12. Save the file
 
   
 

The Point of Sale

A poinit of sale is the workstation where customers purchases are handled. Point of sales used to be a big issue. You had to purchase special machines and have a special setup. Although you still need setup, you can build the whole thing yourself (but we will not discuss all of that this time).

In our application, when a customer brings one or more items to check out, the cashier (or employee) will enter each item number in a text box and press enter. This will display information about the item, including the discount if any. The employee will do this for all items brought by the customer. The employee will also have the ability to remove an item. When all items have been entered, the employee can save the order and start another order or purchase.

Practical LearningPractical Learning: Creating a Point of Sale Tool

  1. In the empty document, type the following code:
    Imports System
    Imports System.IO
    Imports System.Xml
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class NewShoppingSession
        Inherits Form
    
        Private lblItemNumberSelected As Label
        Private WithEvents txtItemNumberSelected As TextBox
        Private lblReceiptNumber As Label
        Private txtReceiptNumber As TextBox
    
        Private colItemNumber As ColumnHeader
        Private colItemName As ColumnHeader
        Private colItemSize As ColumnHeader
        Private colUnitPrice As ColumnHeader
        Private colDiscountRate As ColumnHeader
        Private colDiscountAmount As ColumnHeader
        Private colSalePrice As ColumnHeader
        Private lvwSoldItems As ListView
    
        Private lblEmployeeNumber As Label
        Private WithEvents txtEmployeeNumber As TextBox
        Private dtpSaleDate As DateTimePicker
        Private lblSaleTime As Label
        Private WithEvents txtAmountTendered As TextBox
        Private lblTendered As Label
        Private txtChange As TextBox
        Private lblChange As Label
        Private txtOrderTotal As TextBox
        Private lblOrderTotal As Label
        Private txtEmployeeName As TextBox
        Private WithEvents btnSubmit As Button
        Private WithEvents btnReset As Button
        Private txtItemNumberRemove As TextBox
        Private lblItemNumberToRemove As Label
        Private WithEvents btnRemoveItem As Button
        Private WithEvents btnClose As Button
    
        Private WithEvents tmrDateTime As Timer
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            ' Label: Item Number to Add
            lblItemNumberSelected = New Label()
            lblItemNumberSelected.AutoSize = True
            lblItemNumberSelected.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblItemNumberSelected.Location = New Point(16, 22)
            lblItemNumberSelected.TabIndex = 2
            lblItemNumberSelected.Text = "Item # to Add:"
    
            ' Text Box: Item Number to Add
            txtItemNumberSelected = New TextBox()
            txtItemNumberSelected.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtItemNumberSelected.Location = New Point(235, 18)
            txtItemNumberSelected.Size = New System.Drawing.Size(155, 41)
            txtItemNumberSelected.TabIndex = 3
    
            ' Label: Receipt Number
            lblReceiptNumber = New Label()
            lblReceiptNumber.AutoSize = True
            lblReceiptNumber.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblReceiptNumber.Location = New Point(1081, 22)
            lblReceiptNumber.TabIndex = 5
            lblReceiptNumber.Text = "Receipt #:"
            Controls.Add(lblReceiptNumber)
    
            ' Text Box: Receipt Number
            txtReceiptNumber = New TextBox()
            txtReceiptNumber.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtReceiptNumber.Location = New Point(1260, 18)
            txtReceiptNumber.Size = New System.Drawing.Size(105, 41)
            txtReceiptNumber.TabIndex = 6
            txtReceiptNumber.Text = "000000"
            Controls.Add(txtReceiptNumber)
    
            ' Column: umn: Item Number
            colItemNumber = New ColumnHeader()
            colItemNumber.Text = "Item #"
            colItemNumber.Width = 100
    
            ' Column: umn: Item Name
            colItemName = New ColumnHeader()
            colItemName.Text = "Item Name/Description"
            colItemName.Width = 610
    
            ' Column: umn: Item Size
            colItemSize = New ColumnHeader()
            colItemSize.Text = "Size"
            colItemSize.Width = 150
    
            ' Column: umn: Unit Price
            colUnitPrice = New ColumnHeader()
            colUnitPrice.Text = "Unit Price"
            colUnitPrice.TextAlign = HorizontalAlignment.Right
            colUnitPrice.Width = 140
    
            ' Column: umn: Discount Rate
            colDiscountRate = New ColumnHeader()
            colDiscountRate.Text = "Dscnt Rt"
            colDiscountRate.TextAlign = HorizontalAlignment.Right
            colDiscountRate.Width = 120
    
            ' Column: umn: Discount Amount
            colDiscountAmount = New ColumnHeader()
            colDiscountAmount.Text = "Dscnt Amt"
            colDiscountAmount.TextAlign = HorizontalAlignment.Right
            colDiscountAmount.Width = 140
    
            ' Column: umn: Sale Price
            colSalePrice = New ColumnHeader()
            colSalePrice.Text = "Sale Price"
            colSalePrice.TextAlign = HorizontalAlignment.Right
            colSalePrice.Width = 130
    
            ' List View: Selected Items
            lvwSoldItems = New ListView()
            lvwSoldItems.Columns.AddRange(new ColumnHeader() {
                colItemNumber, colItemName, colItemSize, colUnitPrice,
            colDiscountRate, colDiscountAmount, colSalePrice })
            lvwSoldItems.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lvwSoldItems.FullRowSelect = True
            lvwSoldItems.GridLines = True
            lvwSoldItems.Location = New Point(16, 71)
            lvwSoldItems.Size = New System.Drawing.Size(1424, 321)
            lvwSoldItems.TabIndex = 8
            lvwSoldItems.View = View.Details
    
            ' Date/Time Picker: Sale Date
            dtpSaleDate = New DateTimePicker()
            dtpSaleDate.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            dtpSaleDate.Location = New Point(16, 469)
            dtpSaleDate.Size = New System.Drawing.Size(402, 39)
            dtpSaleDate.TabIndex = 9
    
            lblSaleTime = New Label()
            lblSaleTime.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblSaleTime.Location = New Point(429, 469)
            lblSaleTime.Text = "Sale Time"
            lblSaleTime.Size = New System.Drawing.Size(177, 39)
            lblSaleTime.TabIndex = 11
    
            ' Label: Tendered
            lblTendered = New Label()
            lblTendered.AutoSize = True
            lblTendered.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblTendered.Location = New Point(1089, 449)
            lblTendered.TabIndex = 15
            lblTendered.Text = "Tendered:"
    
            ' Text Box: Amount Tendered
            txtAmountTendered = New TextBox()
            txtAmountTendered.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtAmountTendered.Location = New Point(1278, 445)
            txtAmountTendered.Size = New System.Drawing.Size(130, 41)
            txtAmountTendered.TabIndex = 14
            txtAmountTendered.Text = "0.00"
            txtAmountTendered.TextAlign = HorizontalAlignment.Right
    
            ' Label: Item Number to Remove
            lblItemNumberToRemove = New Label()
            lblItemNumberToRemove.AutoSize = True
            lblItemNumberToRemove.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblItemNumberToRemove.Location = New Point(16, 416)
            lblItemNumberToRemove.TabIndex = 18
            lblItemNumberToRemove.Text = "Item # to Remove:"
    
            ' Text Box: Item Number to Remove
            txtItemNumberRemove = New TextBox()
            txtItemNumberRemove.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtItemNumberRemove.Location = New Point(290, 412)
            txtItemNumberRemove.Size = New System.Drawing.Size(155, 41)
            txtItemNumberRemove.TabIndex = 19
    
            ' Button: Remove Item
            btnRemoveItem = New Button()
            btnRemoveItem.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnRemoveItem.Location = New Point(451, 408)
            btnRemoveItem.Size = New System.Drawing.Size(155, 46)
            btnRemoveItem.TabIndex = 20
            btnRemoveItem.Text = "Remove"
    
            ' Label: Order Total
            lblOrderTotal = New Label()
            lblOrderTotal.AutoSize = True
            lblOrderTotal.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblOrderTotal.Location = New Point(1089, 401)
            lblOrderTotal.TabIndex = 12
            lblOrderTotal.Text = "Order Total:"
            txtEmployeeNumber = New TextBox()
            txtEmployeeName = New TextBox()
            btnSubmit = New Button()
            btnReset = New Button()
            btnClose = New Button()
    
            ' Text Box: Order Total
            txtOrderTotal = New TextBox()
            txtOrderTotal.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtOrderTotal.Location = New Point(1278, 396)
            txtOrderTotal.Size = New System.Drawing.Size(130, 41)
            txtOrderTotal.TabIndex = 13
            txtOrderTotal.Text = "0.00"
            txtOrderTotal.TextAlign = HorizontalAlignment.Right
    
            ' Label: Change
            lblChange = New Label()
            lblChange.AutoSize = True
            lblChange.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblChange.Location = New Point(1089, 496)
            lblChange.TabIndex = 16
            lblChange.Text = "Change:"
    
            ' Text Box: Change
            txtChange = New TextBox()
            txtChange.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtChange.Location = New Point(1278, 492)
            txtChange.Size = New System.Drawing.Size(129, 41)
            txtChange.TabIndex = 17
            txtChange.Text = "0.00"
            txtChange.TextAlign = HorizontalAlignment.Right
    
            ' Label: Employee Number
            lblEmployeeNumber = New Label()
            lblEmployeeNumber.AutoSize = True
            lblEmployeeNumber.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblEmployeeNumber.Location = New Point(10, 558)
            lblEmployeeNumber.TabIndex = 0
            lblEmployeeNumber.Text = "Employee #:"
    
            ' Text Box: Employee Number
            txtEmployeeNumber.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtEmployeeNumber.Location = New Point(206, 554)
            txtEmployeeNumber.Size = New System.Drawing.Size(155, 41)
            txtEmployeeNumber.TabIndex = 1
    
            ' Text Box: Employee Name
            txtEmployeeName.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtEmployeeName.Location = New Point(370, 554)
            txtEmployeeName.Size = New System.Drawing.Size(499, 41)
            txtEmployeeName.TabIndex = 7
    
            ' Button: Reset
            btnReset.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnReset.Location = New Point(923, 551)
            btnReset.Size = New System.Drawing.Size(168, 46)
            btnReset.TabIndex = 10
            btnReset.Text = "Reset"
    
            ' Button: Submit
            btnSubmit.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnSubmit.Location = New Point(1097, 551)
            btnSubmit.Size = New System.Drawing.Size(177, 46)
            btnSubmit.TabIndex = 4
            btnSubmit.Text = "Submit"
    
            ' Button: Close
            btnClose.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnClose.Location = New Point(1281, 551)
            btnClose.Size = New System.Drawing.Size(129, 46)
            btnClose.TabIndex = 21
            btnClose.Text = "Close"
    
            tmrDateTime = New Timer()
            tmrDateTime.Interval = 20
            tmrDateTime.Enabled = True
    
            ClientSize = New System.Drawing.Size(1454, 611)
            Controls.Add(btnClose)
            Controls.Add(btnRemoveItem)
            Controls.Add(txtItemNumberRemove)
            Controls.Add(lblItemNumberToRemove)
            Controls.Add(btnReset)
            Controls.Add(btnSubmit)
            Controls.Add(txtEmployeeName)
            Controls.Add(txtOrderTotal)
            Controls.Add(lblOrderTotal)
            Controls.Add(txtChange)
            Controls.Add(lblChange)
            Controls.Add(txtAmountTendered)
            Controls.Add(lblTendered)
            Controls.Add(lblSaleTime)
            Controls.Add(dtpSaleDate)
            Controls.Add(txtEmployeeNumber)
            Controls.Add(lblEmployeeNumber)
            Controls.Add(lvwSoldItems)
            Controls.Add(txtItemNumberSelected)
            Controls.Add(lblItemNumberSelected)
            MaximizeBox = False
            MinimizeBox = False
            StartPosition = FormStartPosition.CenterScreen
            Text = "Fun Department Store - New Shopping Session"
        End Sub
    
        Private Sub txtItemNumberKeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles txtItemNumberSelected.KeyUp
            Dim itemFound As Boolean = False
            Dim dblTotal = 0.0
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems.xml"
    
            If e.KeyCode = Keys.Enter Then
                If String.IsNullOrEmpty(txtItemNumberSelected.Text) Then
                    MsgBox("You must enter an item number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                    Exit Sub
                Else
                    If File.Exists(strStoreItemsFile) Then
                        Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Open, FileAccess.Read)
                            xdStoreItems.Load(fsStoreItems)
                            Dim itemNumber As String
                            Dim itemName As String
                            Dim itemSize As String
                            Dim strDiscountRate As String
                            Dim unitPrice As Double
                            Dim discountRate As Double
                            Dim discountAmount As Double
                            Dim salePrice As Double
    
                            Dim xnlStoreItems As XmlNodeList = xdStoreItems.GetElementsByTagName("ItemNumber")
    
                            For Each xnStoreItem As XmlNode In xnlStoreItems
                                If xnStoreItem.InnerText = txtItemNumberSelected.Text Then
                                    itemFound = True
    
                                    itemNumber = xnStoreItem.InnerText
                                    itemName = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                                    itemSize = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                                    unitPrice = CDbl(xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText)
                                    strDiscountRate = xnStoreItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
    
                                    If (String.IsNullOrEmpty(strDiscountRate)) Then ' Or (CDbl(strDiscountRate) <= 0.0) Then
                                        discountRate = 0.0
                                        discountAmount = 0.0
                                        salePrice = unitPrice
                                    Else
                                        discountRate = CDbl(strDiscountRate) / 100.0
                                        discountAmount = unitPrice * discountRate
                                        salePrice = unitPrice - discountAmount
                                    End If
    
                                    Dim lviStoreItem As ListViewItem = New ListViewItem(itemNumber) ' Item Number
                                    lviStoreItem.SubItems.Add(itemName) ' Item Name
                                    lviStoreItem.SubItems.Add(itemSize) ' Item Size
                                    lviStoreItem.SubItems.Add(FormatNumber(unitPrice))
    
                                    If (discountRate = 0.0) Then
                                        lviStoreItem.SubItems.Add("") ' Discount Rate
                                        lviStoreItem.SubItems.Add("") ' Discount Amount
                                        lviStoreItem.SubItems.Add(FormatNumber(unitPrice)) ' Unit Price
                                    Else
                                        lviStoreItem.SubItems.Add(FormatNumber(discountRate * 100) & "%")
                                        lviStoreItem.SubItems.Add(FormatNumber(discountAmount))
                                        lviStoreItem.SubItems.Add(FormatNumber(salePrice))
                                    End If
    
                                    lvwSoldItems.Items.Add(lviStoreItem)
                                End If
                            Next
    
                            txtItemNumberSelected.Text = ""
    
                            If (itemFound = False) Then
                                MsgBox("There is no item with that item number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                            End If
    
                            If lvwSoldItems.Items.Count > 0 Then
                                For Each lviStoreItem As ListViewItem In lvwSoldItems.Items
                                    dblTotal = dblTotal + CDbl(lviStoreItem.SubItems(6).Text)
                                Next
    
                                txtOrderTotal.Text = FormatNumber(dblTotal)
                            End If
                        End Using
                    End If
                End If
            End If
        End Sub
    
        Private Sub ShoppingSessionLoad(ByVal sender As Object, ByVal e As EventArgs) Handles me.load
            btnResetClick(sender, e)
        End Sub
    
        Private Sub txtEmployeeNumberLeave(ByVal sender As Object, ByVal e As EventArgs) Handles txtEmployeeNumber.Leave
            Dim employeeFound As Boolean = False
            Dim xdEmployees As XmlDocument = New XmlDocument()
            Dim strEmployeesFile As String = "C:\Fun Department Store1\Employees.xml"
    
            If String.IsNullOrEmpty(txtEmployeeNumber.Text) Then
                Exit Sub
            Else
                If File.Exists(strEmployeesFile) Then
                    Using fsEmployees As FileStream = New FileStream(strEmployeesFile, FileMode.Open, FileAccess.Read)
                        xdEmployees.Load(fsEmployees)
    
                        Dim xnlEmployees As XmlNodeList = xdEmployees.GetElementsByTagName("EmployeeNumber")
    
                        For Each xnEmployee As XmlNode In xnlEmployees
                            If txtEmployeeNumber.Text = xnEmployee.InnerText Then
                                employeeFound = True
                                txtEmployeeName.Text = String.Concat(xnEmployee.NextSibling.NextSibling.InnerText, ", ", xnEmployee.NextSibling.InnerText)
                            End If
                        Next
    
                        If employeeFound = False Then
                            MsgBox("There is no employee with that number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                        End If
                    End Using
                End If
            End If
        End Sub
    
        Private Sub txtAmountTenderedKeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles txtAmountTendered.KeyUp
            Dim orderTotal = 0.0
            Dim amountTendered = 0.0
            Dim change = 0.0
    
            If (e.KeyCode = Keys.Tab) Or (e.KeyCode = Keys.Enter) Then
                If String.IsNullOrEmpty(txtOrderTotal.Text) Then
                    Exit Sub
                ElseIf String.IsNullOrEmpty(txtAmountTendered.Text) Then
                    Exit Sub
                Else
                    orderTotal = CDbl(txtOrderTotal.Text)
                    amountTendered = CDbl(txtAmountTendered.Text)
                    change = amountTendered - orderTotal
    
                    txtChange.Text = FormatNumber(change)
                End If
            End If
        End Sub
    
        Private Sub txtAmountTenderedLeave(ByVal sender As Object, ByVal e As EventArgs) Handles txtAmountTendered.Leave
            Dim orderTotal = 0.0
            Dim amountTendered = 0.0
            Dim change = 0.0
    
            If String.IsNullOrEmpty(txtOrderTotal.Text) Then
                Exit Sub
            ElseIf String.IsNullOrEmpty(txtAmountTendered.Text) Then
                Exit Sub
            Else
                orderTotal = CDbl(txtOrderTotal.Text)
                amountTendered = CDbl(txtAmountTendered.Text)
                change = amountTendered - orderTotal
    
                txtChange.Text = FormatNumber(change)
            End If
        End Sub
    
        Private Sub btnRemoveItemClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnRemoveItem.Click
            Dim dblTotal = 0.0
            Dim itemFound As Boolean = False
    
            If lvwSoldItems.Items.Count = 0 Then
                MsgBox("The list view is empty.",MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                Exit Sub
            ElseIf (String.IsNullOrEmpty(txtItemNumberRemove.Text)) Then
                MsgBox("You must enter an item number and that exists in the list view.",
                       MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                Exit Sub
            Else
                For Each lviStoreItem In lvwSoldItems.Items
                    If lviStoreItem.SubItems(0).Text = txtItemNumberRemove.Text Then
                        itemFound = True
                        lvwSoldItems.Items.Remove(lviStoreItem)
                    End If
                Next
    
                If itemFound = False Then
                    MsgBox("That item number is not in the list view.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                    Exit Sub
                End If
    
                If lvwSoldItems.Items.Count > 0 Then
                    For Each lviStoreItem As ListViewItem In lvwSoldItems.Items
                        dblTotal = dblTotal + CDbl(lviStoreItem.SubItems(6).Text)
    
                        txtOrderTotal.Text = FormatNumber(dblTotal)
                        txtAmountTendered.Text = "0.00"
                        txtChange.Text = "0.00"
                    Next
                Else
                    txtOrderTotal.Text = "0.00"
                    txtAmountTendered.Text = "0.00"
                    txtChange.Text = "0.00"
                End If
    
                txtItemNumberRemove.Text = ""
            End If
        End Sub
    
        Private Sub btnResetClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
            Dim iReceiptNumber = 100000
            Dim xdStoreSales = New XmlDocument()
            Dim strStoreSalesFile = "C:\Fun Department Store1\StoreSales.xml"
    
            If File.Exists(strStoreSalesFile) Then
                Using fsStoreSales = New FileStream(strStoreSalesFile, FileMode.Open, FileAccess.Read)
                    xdStoreSales.Load(fsStoreSales)
    
                    Dim xnlStoreSales = xdStoreSales.GetElementsByTagName("ReceiptNumber")
    
                    For Each xnStoreSale In xnlStoreSales
                        iReceiptNumber = CInt(xnStoreSale.InnerText)
                    Next
                End Using
            End If
    
            txtReceiptNumber.Text = (iReceiptNumber + 1).ToString()
            txtItemNumberSelected.Text = ""
            lvwSoldItems.Items.Clear()
            txtItemNumberRemove.Text = ""
            dtpSaleDate.Value = DateTime.Now
            lblSaleTime.Text = DateTime.Now.ToString()
            txtEmployeeNumber.Text = ""
            txtEmployeeName.Text = ""
            txtOrderTotal.Text = "0.00"
            txtAmountTendered.Text = "0.00"
            txtChange.Text = "0.00"
        End Sub
    
        Private Sub btnSubmitClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
            Dim iSoldItemID = 0
            Dim xdSoldItems = New XmlDocument()
            Dim xdStoreSales = New XmlDocument()
            Dim xdStoreItems As XmlDocument = New XmlDocument()
            Dim strSoldItemsFile = "C:\Fun Department Store1\SoldItems.xml"
            Dim strStoreSalesFile = "C:\Fun Department Store1\StoreSales.xml"
            Dim strStoreItemsFile As String = "C:\Fun Department Store1\StoreItems1.xml"
    
            If lvwSoldItems.Items.Count = 0 Then
                MsgBox("There is no customer order to save.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                Exit Sub
            End If
    
            If Not File.Exists(strStoreSalesFile) Then
                Using fsStoreSales = New FileStream(strStoreSalesFile, FileMode.Create, FileAccess.Write)
                    xdStoreSales.LoadXml("<?xml version=""1.0"" encoding=""utf-8""?>" &
                                         "<StoreSales></StoreSales>")
                    xdStoreSales.Save(fsStoreSales)
                End Using
            End If
    
            Using fsStoreSales = New FileStream(strStoreSalesFile, FileMode.Open, FileAccess.Read)
                xdStoreSales.Load(fsStoreSales)
            End Using
    
            Using fsStoreSales = New FileStream(strStoreSalesFile, FileMode.Create, FileAccess.Write)
                Dim xeStoreSale = xdStoreSales.CreateElement("StoreSale")
                xeStoreSale.InnerXml = "<ReceiptNumber>" & txtReceiptNumber.Text & "</ReceiptNumber>" &
                                       "<EmployeeNumber>" & txtEmployeeNumber.Text & "</EmployeeNumber>" &
                                       "<SaleDate>" & dtpSaleDate.Value.ToShortDateString() & "</SaleDate>" &
                                       "<SaleTime>" & lblSaleTime.Text & "</SaleTime>" &
                                       "<OrderTotal>" & txtOrderTotal.Text & "</OrderTotal>" &
                                       "<AmountTendered>" & txtAmountTendered.Text & "</AmountTendered>" &
                                       "<Change>" & txtChange.Text & "</Change>"
                xdStoreSales.DocumentElement.AppendChild(xeStoreSale)
    
                xdStoreSales.Save(fsStoreSales)
            End Using
    
            If Not File.Exists(strSoldItemsFile) Then
                Using fsSoldItems = New FileStream(strSoldItemsFile, FileMode.Create, FileAccess.Write)
                    xdSoldItems.LoadXml("<?xml version=""1.0"" encoding=""utf-8""?>" &
                                        "<SoldItems></SoldItems>")
                    xdSoldItems.Save(fsSoldItems)
                End Using
            End If
    
            Using fsSoldItems = New FileStream(strSoldItemsFile, FileMode.Open, FileAccess.Read)
                xdSoldItems.Load(fsSoldItems)
                Dim xnlSoldItems = xdSoldItems.GetElementsByTagName("SoldItemID")
    
                For Each xnSoldItem In xnlSoldItems
                    iSoldItemID = CInt(xnSoldItem.InnerText)
                Next
            End Using
    
            iSoldItemID = iSoldItemID + 1
    
            Using fsSoldItems = New FileStream(strSoldItemsFile, FileMode.Create, FileAccess.Write)
                For Each lviSoldItem In lvwSoldItems.Items
                    Dim xeSoldItem = xdSoldItems.CreateElement("SoldItem")
                    xeSoldItem.InnerXml = "<SoldItemID>" & iSoldItemID.ToString() & "</SoldItemID>" &
                                          "<ReceiptNumber>" & txtReceiptNumber.Text & "</ReceiptNumber>" &
                                          "<ItemNumber>" & lviSoldItem.SubItems(0).Text & "</ItemNumber>" &
                                          "<ItemName>" & lviSoldItem.SubItems(1).Text & "</ItemName>" &
                                          "<ItemSize>" & lviSoldItem.SubItems(2).Text & "</ItemSize>" &
                                          "<UnitPrice>" & lviSoldItem.SubItems(3).Text & "</UnitPrice>" &
                                          "<DiscountRate>" & lviSoldItem.SubItems(4).Text & "</DiscountRate>" &
                                          "<DiscountAmount>" & lviSoldItem.SubItems(5).Text & "</DiscountAmount>" &
                                          "<SalePrice>" & lviSoldItem.SubItems(6).Text & "</SalePrice>"
                    xdSoldItems.DocumentElement.AppendChild(xeSoldItem)
                    iSoldItemID = iSoldItemID + 1
                Next
    
                xdSoldItems.Save(fsSoldItems)
    
                MsgBox("The customer's order has been saved.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
            End Using
    
            If File.Exists(strStoreItemsFile) Then
                Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Open, FileAccess.Read)
                    xdStoreItems.Load(fsStoreItems)
    
                    Dim xnlStoreItems As XmlNodeList = xdStoreItems.GetElementsByTagName("ItemNumber")
    
                    ' Remove the items of the list view from the StoreItems table
                    For Each lviStoreItem In lvwSoldItems.Items
                        For Each xnStoreItem As XmlNode In xnlStoreItems
                            If xnStoreItem.InnerText = lviStoreItem.SubItems(0).Text Then
                                xdStoreItems.DocumentElement.RemoveChild(xnStoreItem.ParentNode)
                            End If
                        Next
                    Next
                End Using
    
                Using fsStoreItems As FileStream = New FileStream(strStoreItemsFile, FileMode.Create, FileAccess.Write)
                    xdStoreItems.Save(fsStoreItems)
                End Using
            End If
    
            btnResetClick(sender, e)
        End Sub
    
        Private Sub btnCloseClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
            Close()
        End Sub
    
        Private Sub tmrDateTimeTick(ByVal sender As Object, ByVal e As EventArgs) Handles tmrDateTime.Tick
            dtpSaleDate.Value = DateTime.Today
            lblSaleTime.Text = DateTime.Now.ToLongTimeString()
        End Sub
    End Class
  2. On the main menu, click File -> New
  3. When asked whether you want to save, click Save
  4. In the top combo box, make sure the FunDS1 folder is displaying, Set the Save As Type to All Files
  5. Set the File Name to PointOfSale.vb
  6. Click Save

Reviewing a Shopping Session

Some time to time, the company management must review store sales. Also, a customer may come with a complaint about anything. The first thing to do is to review a customer order. To handle this, we will create a form in which a user can enter a receipt number and click a button to locate its record. If the purchase is found, the form will display (that's all we will do at this time; otherwise, there are many actions that can be taken such as deleting an items from the receipt (and re-imbursing the customer) and putting the information about the returned item to another list, etc).

Practical LearningPractical Learning: Reviewing a Shopping Session

  1. In the empty document, type the following:
    Imports System
    Imports System.IO
    Imports System.Xml
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class ShoppingSessionReview
        Inherits Form
    
        Private lblReceiptNumber As Label
        Private txtReceiptNumber As TextBox
        Private WithEvents btnFind As Button
        Private colItemNumber As ColumnHeader
        Private colItemName As ColumnHeader
        Private colItemSize As ColumnHeader
        Private colUnitPrice As ColumnHeader
        Private colDiscountRate As ColumnHeader
        Private colDiscountAmount As ColumnHeader
        Private colSalePrice As ColumnHeader
        Private lvwSoldItems As ListView
    
        Private WithEvents txtEmployeeNumber As TextBox
        Private lblEmployeeNumber As Label
        Private dtpSaleDate As DateTimePicker
        Private lblSaleTime As Label
        Private txtAmountTendered As TextBox
        Private lblTendered As Label
        Private txtChange As TextBox
        Private lblChange As Label
        Private txtOrderTotal As TextBox
        Private lblOrderTotal As Label
        Private txtEmployeeName As TextBox
        Private WithEvents btnClose As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            ' Label: Receipt Number
            lblReceiptNumber = New Label()
            lblReceiptNumber.AutoSize = True
            lblReceiptNumber.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblReceiptNumber.Location = New Point(16, 22)
            lblReceiptNumber.Text = "Receipt #:"
    
            ' Text Box: Receipt Number
            txtReceiptNumber = New TextBox()
            txtReceiptNumber.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtReceiptNumber.Location = New Point(180, 18)
            txtReceiptNumber.Size = New System.Drawing.Size(105, 41)
    
            ' Button: Find
            btnFind = New Button()
            btnFind.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnFind.Location = New Point(295, 16)
            btnFind.Size = New System.Drawing.Size(150, 46)
            btnFind.Text = "Find"
            Controls.Add(btnFind)
    
            ' Column: umn: Item Number
            colItemNumber = New ColumnHeader()
            colItemNumber.Text = "Item #"
            colItemNumber.Width = 100
    
            ' Column: umn: Item Name
            colItemName = New ColumnHeader()
            colItemName.Text = "Item Name/Description"
            colItemName.Width = 610
    
            ' Column: umn: Item Size
            colItemSize = New ColumnHeader()
            colItemSize.Text = "Size"
            colItemSize.Width = 150
    
            ' Column: umn: Unit Price
            colUnitPrice = New ColumnHeader()
            colUnitPrice.Text = "Unit Price"
            colUnitPrice.TextAlign = HorizontalAlignment.Right
            colUnitPrice.Width = 140
    
            ' Column: umn: Discount Rate
            colDiscountRate = New ColumnHeader()
            colDiscountRate.Text = "Dscnt Rt"
            colDiscountRate.TextAlign = HorizontalAlignment.Right
            colDiscountRate.Width = 120
    
            ' Column: umn: Discount Amount
            colDiscountAmount = New ColumnHeader()
            colDiscountAmount.Text = "Dscnt Amt"
            colDiscountAmount.TextAlign = HorizontalAlignment.Right
            colDiscountAmount.Width = 140
    
            ' Column: umn: Sale Price
            colSalePrice = New ColumnHeader()
            colSalePrice.Text = "Sale Price"
            colSalePrice.TextAlign = HorizontalAlignment.Right
            colSalePrice.Width = 130
    
            ' List View: Selected Items
            lvwSoldItems = New ListView()
            lvwSoldItems.Columns.AddRange(new ColumnHeader() {
                colItemNumber, colItemName, colItemSize, colUnitPrice,
            colDiscountRate, colDiscountAmount, colSalePrice })
            lvwSoldItems.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lvwSoldItems.FullRowSelect = True
            lvwSoldItems.GridLines = True
            lvwSoldItems.Location = New Point(16, 71)
            lvwSoldItems.Size = New System.Drawing.Size(1424, 321)
            lvwSoldItems.View = View.Details
    
            ' Date/Time Picker: Sale Date
            dtpSaleDate = New DateTimePicker()
            dtpSaleDate.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            dtpSaleDate.Location = New Point(16, 469)
            dtpSaleDate.Size = New System.Drawing.Size(402, 39)
    
            lblSaleTime = New Label()
            lblSaleTime.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblSaleTime.Location = New Point(429, 469)
            lblSaleTime.Text = "Sale Time"
            lblSaleTime.Size = New System.Drawing.Size(177, 39)
    
            ' Label: Tendered
            lblTendered = New Label()
            lblTendered.AutoSize = True
            lblTendered.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblTendered.Location = New Point(1089, 449)
            lblTendered.Text = "Tendered:"
    
            ' Text Box: Amount Tendered
            txtAmountTendered = New TextBox()
            txtAmountTendered.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtAmountTendered.Location = New Point(1278, 445)
            txtAmountTendered.Size = New System.Drawing.Size(130, 41)
            txtAmountTendered.Text = "0.00"
            txtAmountTendered.TextAlign = HorizontalAlignment.Right
    
            ' Label: Order Total
            lblOrderTotal = New Label()
            lblOrderTotal.AutoSize = True
            lblOrderTotal.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblOrderTotal.Location = New Point(1089, 401)
            lblOrderTotal.Text = "Order Total:"
    
            ' Text Box: Order Total
            txtOrderTotal = New TextBox()
            txtOrderTotal.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtOrderTotal.Location = New Point(1278, 396)
            txtOrderTotal.Size = New System.Drawing.Size(130, 41)
            txtOrderTotal.Text = "0.00"
            txtOrderTotal.TextAlign = HorizontalAlignment.Right
    
            ' Label: Change
            lblChange = New Label()
            lblChange.AutoSize = True
            lblChange.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblChange.Location = New Point(1089, 496)
            lblChange.Text = "Change:"
    
            ' Text Box: Change
            txtChange = New TextBox()
            txtChange.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtChange.Location = New Point(1278, 492)
            txtChange.Size = New System.Drawing.Size(129, 41)
            txtChange.Text = "0.00"
            txtChange.TextAlign = HorizontalAlignment.Right
    
            ' Label: Employee Number
            lblEmployeeNumber = New Label()
            lblEmployeeNumber.AutoSize = True
            lblEmployeeNumber.Font = New System.Drawing.Font("Georgia", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            lblEmployeeNumber.Location = New Point(10, 558)
            lblEmployeeNumber.Text = "Employee #:"
    
            ' Text Box: Employee Number
            txtEmployeeNumber = New TextBox()
            txtEmployeeNumber.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtEmployeeNumber.Location = New Point(206, 554)
            txtEmployeeNumber.Size = New System.Drawing.Size(155, 41)
    
            ' Text Box: Employee Name
            txtEmployeeName = New TextBox()
            txtEmployeeName.Font = New System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            txtEmployeeName.Location = New Point(370, 554)
            txtEmployeeName.Size = New System.Drawing.Size(499, 41)
            txtEmployeeName.TabIndex = 7
    
            ' Button: Close
            btnClose = New Button()
            btnClose.Font = New System.Drawing.Font("Times New Roman", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnClose.Location = New Point(1281, 551)
            btnClose.Size = New System.Drawing.Size(129, 46)
            btnClose.Text = "Close"
            Controls.Add(btnClose)
    
            ClientSize = New System.Drawing.Size(1454, 611)
            Controls.Add(txtReceiptNumber)
            Controls.Add(lblReceiptNumber)
            Controls.Add(txtEmployeeName)
            Controls.Add(txtOrderTotal)
            Controls.Add(lblOrderTotal)
            Controls.Add(txtChange)
            Controls.Add(lblChange)
            Controls.Add(txtAmountTendered)
            Controls.Add(lblTendered)
            Controls.Add(lblSaleTime)
            Controls.Add(dtpSaleDate)
            Controls.Add(txtEmployeeNumber)
            Controls.Add(lblEmployeeNumber)
            Controls.Add(lvwSoldItems)
            MaximizeBox = False
            MinimizeBox = False
            StartPosition = FormStartPosition.CenterScreen
            Text = "FunDS - Shopping Session"
        End Sub
    
        Private Sub btnFindClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnFind.Click
            Dim receiptFound = False
            Dim xdSoldItems = New XmlDocument()
            Dim xdStoreSales = New XmlDocument()
            Dim strSoldItemsFile = "C:\Fun Department Store1\SoldItems.xml"
            Dim strStoreSalesFile = "C:\Fun Department Store1\StoreSales.xml"
    
            If String.IsNullOrEmpty(txtReceiptNumber.Text) Then
                MsgBox("You must enter a receipt number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                Exit Sub
            End If
    
            If File.Exists(strStoreSalesFile) Then
                Using fsStoreSales = New FileStream(strStoreSalesFile, FileMode.Open, FileAccess.Read)
                    xdStoreSales.Load(fsStoreSales)
    
                    Dim xnlStoreSales = xdStoreSales.GetElementsByTagName("ReceiptNumber")
    
                    For Each xnStoreSale In xnlStoreSales
                        If xnStoreSale.InnerText = txtReceiptNumber.Text Then
                            receiptFound = True
    
                            txtEmployeeNumber.Text = xnStoreSale.NextSibling.InnerText
                            dtpSaleDate.Value = DateTime.Parse(xnStoreSale.NextSibling.NextSibling.InnerText)
                            lblSaleTime.Text = xnStoreSale.NextSibling.NextSibling.NextSibling.InnerText
                            txtOrderTotal.Text = xnStoreSale.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                            txtAmountTendered.Text = xnStoreSale.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
                            txtChange.Text = xnStoreSale.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
    
                            txtEmployeeNumberLeave(sender, e)
                        End If
                    Next
                End Using
            End If
    
            If File.Exists(strSoldItemsFile) Then
                Using fsSoldItems = New FileStream(strSoldItemsFile, FileMode.Open, FileAccess.Read)
                    xdSoldItems.Load(fsSoldItems)
                    Dim xnlSoldItems = xdSoldItems.GetElementsByTagName("ReceiptNumber")
    
                    lvwSoldItems.Items.Clear()
    
                    For Each xnSoldItem In xnlSoldItems
                        If xnSoldItem.InnerText = txtReceiptNumber.Text Then
    
                            Dim lviStoreItem As ListViewItem = New ListViewItem(CStr(xnSoldItem.NextSibling.InnerText)) ' Item Number
                            lviStoreItem.SubItems.Add(xnSoldItem.NextSibling.NextSibling.InnerText) ' Item Name
                            lviStoreItem.SubItems.Add(xnSoldItem.NextSibling.NextSibling.NextSibling.InnerText) ' Item Size
                            lviStoreItem.SubItems.Add(xnSoldItem.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' Unit Price
                            lviStoreItem.SubItems.Add(xnSoldItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' Discount Rate
                            lviStoreItem.SubItems.Add(xnSoldItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' Discount Amount
                            lviStoreItem.SubItems.Add(xnSoldItem.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) ' Sale Price
    
                            lvwSoldItems.Items.Add(lviStoreItem)
                        End If
                    Next
                End Using
            End If
    
            If receiptFound = False Then
                MsgBox("There is no sale order with that receipt number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                Exit Sub
            End If
        End Sub
    
        Private Sub ResetForm()
            txtReceiptNumber.Text = ""
            lvwSoldItems.Items.Clear()
            dtpSaleDate.Value = DateTime.Now
            lblSaleTime.Text = DateTime.Now.ToString()
            txtEmployeeNumber.Text = ""
            txtEmployeeName.Text = ""
            txtOrderTotal.Text = "0.00"
            txtAmountTendered.Text = "0.00"
            txtChange.Text = "0.00"
        End Sub
    
        Private Sub txtEmployeeNumberLeave(ByVal sender As Object, ByVal e As EventArgs) Handles txtEmployeeNumber.Leave
            Dim employeeFound As Boolean = False
            Dim xdEmployees As XmlDocument = New XmlDocument()
            Dim strEmployeesFile As String = "C:\Fun Department Store1\Employees.xml"
    
            If String.IsNullOrEmpty(txtEmployeeNumber.Text) Then
                Exit Sub
            Else
                If File.Exists(strEmployeesFile) Then
                    Using fsEmployees As FileStream = New FileStream(strEmployeesFile, FileMode.Open, FileAccess.Read)
                        xdEmployees.Load(fsEmployees)
    
                        Dim xnlEmployees As XmlNodeList = xdEmployees.GetElementsByTagName("EmployeeNumber")
    
                        For Each xnEmployee As XmlNode In xnlEmployees
                            If txtEmployeeNumber.Text = xnEmployee.InnerText Then
                                employeeFound = True
                                txtEmployeeName.Text = String.Concat(xnEmployee.NextSibling.NextSibling.InnerText, ", ", xnEmployee.NextSibling.InnerText)
                            End If
                        Next
    
                        If employeeFound = False Then
                            MsgBox("There is no employee with that number.", MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, "FunDS - Employees Records")
                        End If
                    End Using
                End If
            End If
        End Sub
    
        Private Sub btnCloseClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
            Close()
        End Sub
    End Class
  2. On the main menu, click File -> New
  3. When asked whether you want to save, click Save
  4. In the top combo box, make sure the FunDS1 folder is displaying, Set the Save As Type to All Files
  5. Set the File Name to ShoppingSessionReview.vb
  6. Click Save

A Switchboard

A switchboard serves as the central point of an application. It holds a list of the forms used in an application.

Practical LearningPractical Learning: Creating a Switchboard

  1. In the empty document, type the following:
    Imports System
    Imports System.IO
    Imports System.Xml
    Imports System.Drawing
    Imports System.Windows.Forms
    
    Public Class FunDS
        Inherits Form
    
        Private WithEvents btnNewShoppingSession As Button
        Private WithEvents btnStoreItems As Button
        Private WithEvents btnShoppingSessionReview As Button
        Private WithEvents btnNewStoreItem As Button
        Private WithEvents btnEmployees As Button
        Private WithEvents btnEditStoreItem As Button
        Private WithEvents btnNewEmployee As Button
        Private WithEvents btnDeleteStoreItem As Button
        Private WithEvents btnClose As Button
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub InitializeComponent()
            ' Button: New Shopping Session
            btnNewShoppingSession = New Button()
            btnNewShoppingSession.Font = New System.Drawing.Font("Palatino Linotype", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnNewShoppingSession.Location = New Point(22, 22)
            btnNewShoppingSession.Size = New System.Drawing.Size(478, 67)
            btnNewShoppingSession.Text = "New Shopping Session ..."
            Controls.Add(btnNewShoppingSession)
    
            ' Button: Store Items
            btnStoreItems = New Button()
            btnStoreItems.Font = New System.Drawing.Font("Palatino Linotype", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnStoreItems.Location = New Point(518, 22)
            btnStoreItems.Size = New System.Drawing.Size(478, 67)
            btnStoreItems.Text = "Store Items ..."
            Controls.Add(btnStoreItems)
    
            ' Button: Shopping Session  Review
            btnShoppingSessionReview = New Button()
            btnShoppingSessionReview.Font = New System.Drawing.Font("Palatino Linotype", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnShoppingSessionReview.Location = New Point(22, 108)
            btnShoppingSessionReview.Size = New System.Drawing.Size(478, 67)
            btnShoppingSessionReview.Text = "Shopping Session Review ..."
            Controls.Add(btnShoppingSessionReview)
    
            ' Button: New Store Item
            btnNewStoreItem = New Button()
            btnNewStoreItem.Font = New System.Drawing.Font("Palatino Linotype", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnNewStoreItem.Location = New Point(518, 108)
            btnNewStoreItem.Size = New System.Drawing.Size(478, 67)
            btnNewStoreItem.Text = "New Store Item ..."
            Controls.Add(btnNewStoreItem)
    
            ' Button: Employees
            btnEmployees = New Button()
            btnEmployees.Font = New System.Drawing.Font("Palatino Linotype", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnEmployees.Location = New Point(22, 194)
            btnEmployees.Size = New System.Drawing.Size(478, 67)
            btnEmployees.Text = "Employees ..."
            Controls.Add(btnEmployees)
    
            ' Button: Edit Store Item
            btnEditStoreItem = New Button()
            btnEditStoreItem.Font = New System.Drawing.Font("Palatino Linotype", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnEditStoreItem.Location = New Point(518, 194)
            btnEditStoreItem.Size = New System.Drawing.Size(478, 67)
            btnEditStoreItem.Text = "Edit Store Item ..."
            Controls.Add(btnEditStoreItem)
    
            ' Button: New Employee
            btnNewEmployee = New Button()
            btnNewEmployee.Font = New System.Drawing.Font("Palatino Linotype", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnNewEmployee.Location = New Point(22, 283)
            btnNewEmployee.Size = New System.Drawing.Size(478, 67)
            btnNewEmployee.Text = "New Employee ..."
            Controls.Add(btnNewEmployee)
    
            ' Button: Delete Stote Item
            btnDeleteStoreItem = New Button()
            btnDeleteStoreItem.Font = New System.Drawing.Font("Palatino Linotype", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnDeleteStoreItem.Location = New Point(518, 283)
            btnDeleteStoreItem.Size = New System.Drawing.Size(478, 67)
            btnDeleteStoreItem.Text = "Delete Stote Item ..."
            Controls.Add(btnDeleteStoreItem)
    
            ' Button: Close
            btnClose = New Button()
            btnClose.Font = New System.Drawing.Font("Palatino Linotype", 27.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0)
            btnClose.Location = New Point(22, 374)
            btnClose.Size = New System.Drawing.Size(974, 67)
            btnClose.Text = "Close"
            Controls.Add(btnClose)
    
            ' Form: Fun Department Store
            ClientSize = New System.Drawing.Size(1018, 463)
            StartPosition = FormStartPosition.CenterScreen
            Text = "FunDS - Fun Department Store"
        End Sub
    
        Private Sub FunDSLoad(ByVal sender As Object, ByVal e As EventArgs)
            Directory.CreateDirectory("C:\Fun Department Store1")
        End Sub
    
        Private Sub btnNewShoppingSessionClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewShoppingSession.Click
            Dim nss As NewShoppingSession = New NewShoppingSession()
            nss.Show()
        End Sub
    
        Private Sub btnStoreItemsClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStoreItems.Click
            Dim sis As StoreItems = New StoreItems()
            sis.Show()
        End Sub
    
        Private Sub btnShoppingSessionReviewClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShoppingSessionReview.Click
            Dim ssr As ShoppingSessionReview = New ShoppingSessionReview()
            ssr.Show()
        End Sub
    
        Private Sub btnNewStoreItemClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewStoreItem.Click
            Dim sin As StoreItemNew = New StoreItemNew()
            sin.ShowDialog()
        End Sub
    
        Private Sub btnEmployeesClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEmployees.Click
            Dim clerks As Employees = New Employees()
            clerks.Show()
        End Sub
    
        Private Sub btnEditStoreItemClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEditStoreItem.Click
            Dim sie = New StoreItemEditor()
            sie.ShowDialog()
        End Sub
    
        Private Sub btnNewEmployeeClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewEmployee.Click
            Dim strEmployeeNumber As String
            Dim strFirstName As String
            Dim strLastName As String
            Dim strCounty As String
            Dim strAddress As String
            Dim strCity As String
            Dim strState As String
            Dim strZIPCode As String
            Dim strMaritalStatus As String
            Dim iExemptions As Integer
            Dim dblHourlySalary As Double
    
            Dim en As EmployeeNew = New EmployeeNew()
            Dim rndEmployeeNumber As Random = New Random()
            Dim xdEmployees As XmlDocument = New XmlDocument()
            Dim strEmployeesFile As String = "C:\Fun Department Store1\Employees.xml"
    
            en.txtEmployeeNumber.Text = CStr(rndEmployeeNumber.Next(100000, 999999))
    
            If en.ShowDialog() = DialogResult.OK Then
                strEmployeeNumber = en.txtEmployeeNumber.Text
                strFirstName = en.txtFirstName.Text
                strLastName = en.txtLastName.Text
                strMaritalStatus = en.cbxMaritalsStatus.Text
                iExemptions = CInt(en.txtExemptions.Text)
                strAddress = en.txtAddress.Text
                strCity = en.txtCity.Text
                strCounty = en.txtCounty.Text
                strState = en.txtState.Text
                strZIPCode = en.txtZIPCode.Text
                dblHourlySalary = CDbl(en.txtHourlySalary.Text)
    
                If Not File.Exists(strEmployeesFile) Then
                                  xdEmployees.LoadXml("<?xml version=""1.0"" encoding=""utf-8""?>" &
                                                     "<Employees></Employees>")
                    xdEmployees.Save(strEmployeesFile)
                End If
    
                xdEmployees.Load(strEmployeesFile)
    
                Dim elmXML As XmlElement = xdEmployees.CreateElement("Employee")
                ' Create the XML code of the child element of Employee
                dim strNewEmployee as string= "<EmployeeNumber>" & strEmployeeNumber & "</EmployeeNumber>" &
                                              "<FirstName>" & strFirstName & "</FirstName>" &
                                              "<LastName>" & strLastName & "</LastName>" &
                                              "<Address>" & strAddress & "</Address>" &
                                              "<City>" & strCity & "</City>" &
                                              "<County>" & strCounty & "</County>" &
                                              "<State>" & strState & "</State>" &
                                              "<ZIPCode>" & strZIPCode & "</ZIPCode>" &
                                              "<MaritalStatus>" & strMaritalStatus & "</MaritalStatus>" &
                                              "<Exemptions>" & iExemptions & "</Exemptions>" &
                                              "<HourlySalary>" & dblHourlySalary & "</HourlySalary>"
                elmXML.InnerXml = strNewEmployee
                ' Append the new element as a child of employees
                xdEmployees.DocumentElement.AppendChild(elmXML)
    
                ' Save the XML file
                xdEmployees.Save(strEmployeesFile)
            End If
        End Sub
    
        Private Sub btnDeleteStoreItemClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnDeleteStoreItem.Click
            Dim sid = New StoreItemDelete()
            sid.ShowDialog()
        End Sub
    
        Private Sub btnCloseClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
            Close()
        End Sub
    
        <STAThread>
        Public Shared Function Main() As Integer
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            Application.Run(New FunDS())
    
            Return 0
        End Function
    
    End Class
  2. On the main menu, click File -> Exit
  3. When asked whether you want to save, click Save
  4. In the top combo box, make sure the FunDS1 folder is displaying, Set the Save As Type to All Files
  5. Set the File Name to FunDS.vb
  6. Click Save

Building the Application

To build this project, you can use the compiler provides in Microsoft Windows and from the Command Prompt.

Practical LearningPractical Learning: Creating a Switchboard

  1. Display the Command Prompt (Start -> (All) Programs -> Accessories -> Command Prompt)
  2. Type CD\ and press Enter to access the root
  3. Type CD FunDS1 and press Enter to access the folder for the current project
  4. To build the project, type the following code:
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc /t:winexe FunDS.cs EmployeeNew.cs EmployeeEditor.cs Employees.cs Manufacturer.cs Category.cs SubCategory.cs StoreItemNew.cs StoreItemEditor.cs StoreItemDelete.cs Inventory.cs PointOfSale.cs ShoppingSessionReview.cs
  5. Press Enter

Application Testing

If you want to test the application, use the following values.

 
 
   
                  

Practical LearningPractical Learning: Testing the Application

  1. At the Command Prompt, type FunDS and press Enter
  2. On the FunDS switchboard, click the New Employee button to open its dialog box
  3. Fill the controls with the following values:
    Employee #: 941148
    First Name: Catherine
    Last Name: Watts
    Address: 4242 Sightings Str
    City: Baltimore
    Country: Baltimore
    State: MD
    ZIP Code: 21205
    Marital Status: Married
    Exemptions: 3
    Hourly Salary: 38.85
  4. Click OK
  5. On the switchboard, click the New Store Item... button
  6. Create items as follows (create the manufacturers, the categories, and the sub-categories by clicking the corresponding buttons):
     
    Item # Manufacturer Category Sub-Category Item Name Item Size Unit Price Discount Rate
    177314 Ralph Lauren Girls Shirts Girls 2-6X Short-Sleeved Mesh Polo Shirt 3T 34.95  
    729530 Kenneth Cole Women Dresses Three-Quarter Sleeved Dress M 164.5 50
    307368 Polo Ralph Lauren Men Pants Classic Straight-Leg Jeans 30W - 29L 84.85 15
    220573 Nautica Baby Girls   Baby Girls 12-24 Months Lace Two-Piece Set 12M 40  
    806888 Guess Girls Dresses Girls 2-6X Denim Print Ruffled Dress 2T 34.95  
    683079 Anne Klein Women Skirts Pencil Skirt 2 54  
    848428 Ralph Lauren Boys Sweaters Boys 2-7 Long-Sleeved Cable Crewneck T-Shirt 4 55  
    683626 Ralph Lauren Women Dresses Structured Scoopneck Ponte Dress 0 195 60
  7. Close the New Store Item dialog box
  8. On the switchboard, click the New Shopping Session button
  9. Set the employee number as 941148 and press Tab
  10. In the Item # To Add text box, type 848428 and press Enter
  11. Type 729530 and press Enter
  12. In the Tendered text box, enter 200 and press Enter:

    Fun Department Store - New Shopping Session

  13. Click Submit
  14. Start a new shopping session with employee number as 941148 and press Tab
  15. Add the shopping items with the following numbers: 683626, 307368, 683079, and 806888
  16. In the Item # to Remove text box, type 683079

    Fun Department Store - New Shopping Session

  17. Click Remove
  18. In the Tendered text box, type 200 and press Enter

    Fun Department Store - New Shopping Session

  19. Click Submit
  20. Close the New Shopping Session form
  21. On the Switchboard, click the Shopping Session Review button
  22. In the Receipt Number text box, type 100001 and click Find

    Fun Department Store - Shopping Session Review

  23. Closse the Shopping Session Review form
  24. On the switchboard, click the Employees button
  25. Use the New Employee button to create a few records as follows:
     
    Employee # First Name Last Name Address City Country State ZIP Code Marital Status Exemptions Hourly Salary
    952748 David Evans 5102 Piedmont Rd Silver Spring Montgomery MD 20910 Single 0 17.25
    606384 Robert Gibson 10324 Marina Ave College Park Prince George MD 20742 Single 1 22.25
  26. Close the Employees form
  27. Click the New Shopping Session button and create a new shopping session as follows:
     
    Employee # Item # Tendered
    606384 177314 50
  28. Click Submit
  29. Close the New Shopping Session form
  30. Click the Employees button and create a few emplyees records as follows:
     
    Employee # First Name Last Name Address City Country State ZIP Code Marital Status Exemptions Hourly Salary
    428041 Jeannine Hewsen  2418 Woodwell Rd Rockville Montgomery MD 20850 Married 2 34.05
    172847 Carl Lowry 7447 Emiry Str Alexandria (Independent) VA 22314 Single 2 26.85
    927048 Henry Meuer 802 Wheeler St York York PA 17401 Married 0 8.95
    837405 Herbert Mann  6218 Willimon Ave Wilmington New Castle DE 19801 Married 2 14.75
  31. Close the Employees form
  32. On the switchboard, click the Store Items button
  33. Click New Store Item...
  34. Create items as follows:
     
    Item # Manufacturer Category Sub-Category Item Name Item Size Unit Price Discount Rate
    580040 Cole Haan Women Handbags Victoria Zip-Top Tote Bag   298  
    795081 Lauren by Ralph Lauren Men Pants Mid-Weight Flat-Front Wool Trouser Pants 36W 32L 65 25
    948596 Tommy Hilfiger Men Shirts Texture Oxford Slim Fit Long Sleeve Dress Shirt 17 - 34/35 47.75  
    360825 Lauren by Ralph Lauren Women Accessories Printed Silk Scarf   45  
    383511 Calvin Klein Men Pants Straight Leg Jean in Black Wash 32/30 45  
    294148 Lauren by Ralph Lauren Men Pants Mid-Weight Flat-Front Wool Trouser Pants 36W 29L 65  
    559717 Guess Girls Dresses Girls 2-6X Denim Print Ruffled Dress 3T 34.95  
    830486 AK Anne Klein Women Skirts Seamless Textured Pencil Skirt S 65.95  
  35. Close the New Store Item dialog box
  36. Close the Store Items form
  37. Click the New Shopping Session button and create a new shopping session as follows:
     
    Employee # Item # Tendered
    428041 683079  
      360825  
      830486  
      383511  
      948596 260
  38. Close the New Shopping Session form
  39. On the Switchboard, click the Shopping Session Review button
  40. In the Receipt Number text box, type 100003 and click Find

    Fun Department Store - Shopping Session Review

  41. Close the form and close Microsoft Access

Previous Copyright © 2015 FunctionX Next