- From the Data section of the Toolbox, click DataGridView and click the
form
- In the Properties window, change its characteristics as follows:
DataSource: dsModels
DataMember: Models
- Under the Properties window, click Edit Columns... and change the columns
as follows:
Selected Columns: |
HeaderText |
DataPropertyName |
ColumnType |
DataSource |
DisplayMember |
Make |
Make |
Make |
DataGridViewComboBoxColumn |
dsMakes |
Make.MakeName |
Model |
Model |
Model |
|
|
|
- Click OK
- Design the form as follows:
|
Control |
Text |
Name |
Additional Properties |
DataGridView |
|
|
dgvStudents |
Anchor: Top, Bottom, Left, Right |
Button |
|
Close |
btnClose |
Anchor: Bottom, Right |
|
- To create a new form, in the Solution Explorer, right-click
CollegeParkAutoParts2 -> Add -> Windows Form...
- Set the Name to AutoParts and click Add
- Display the list of models form
- Click dsMakes
- Press and hold Shift
- Click dsModels
- Release Shift
- Press Ctrl + C
- Display the auto parts form
- Right-click its body and click Paste
- Display the ItemsCategories form
- Right-click dsCategories and click Copy
- Display the AutoParts form
- Right-click its body and click Paste
- From the Data section of the Toolbox, click DataSet and click the form
- In the Add Dataset dialog box, click the Untyped dataset radio button and
click OK
- In the Properties window, change the characteristics of the data set as
follows:
DataSetName: StoreItems
(Name): dsStoreItems
- Click Tables and click its ellipsis button
- In the Properties list, change the characteristics of the table as
follows:
TableName: StoreItem
(Name): tblStoreItem
- Click Columns and click its ellipsis button
- In the Columns Collection Editor, click Add continuously and create the
columns as follows:
ColumnName |
(Name) |
PartNumber |
colPartNumber |
Year |
colYear |
Make |
colMake |
Model |
colModel |
Category |
colCategory |
PartName |
colPartName |
UnitPrice |
colUnitPrice |
- Click Close and click Close
- From the Data section of the Toolbox, click DataGridView and click the form
- In the Properties window, change its characteristics as follows:
DataSource: dsStoreItems
DataMember: StoreItems
- Under the Properties window, click Edit Columns... and change the columns
as follows:
Selected Columns: |
HeaderText |
DataPropertyName |
ColumnType |
DataSource |
DisplayMember |
Width |
Part # |
Part # |
PartNumber |
|
|
|
50 |
Year |
Year |
Year |
|
|
|
40 |
Make |
Make |
Make |
DataGridViewComboBoxColumn |
dsMakes |
Make.MakeName |
85 |
Model |
Model |
Model |
DataGridViewComboBoxColumn |
dsModels |
CarModel.Model |
130 |
Category |
Category |
Category |
DataGridViewComboBoxColumn |
dsCategories |
Category.CategoryName |
120 |
Part Name |
Part Name |
PartName |
|
|
|
185 |
Unit Price |
Unit Price |
UnitPrice |
|
|
|
65 |
- Click OK
- Design the form as follows:
|
Control |
Text |
Name |
Other Properties |
DataGridView |
|
dgvStoreItems |
DataSource: dsStoreItems
DataMember: AutoPart
Anchor: Top, Bottom, Left, Right |
Button |
New Make... |
btnNewMake |
Anchor: Bottom, Left |
Button |
New Model... |
btnNewModel |
Anchor: Bottom, Left |
Button |
New Category... |
btnNewCategory |
Anchor: Bottom, Left |
Button |
Close |
btnClose |
Anchor: Bottom, Right |
|
- Right-click the form and click View Code
- In the Class Name combo box, select btnNewMake
- In the Method Name combo box, select Click and change the file as follows:
Imports System.IO
Public Class AutoParts
Private Sub btnNewMakeClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnNewMake.Click
Dim frmMakes As CarMakes = New CarMakes
frmMakes.ShowDialog()
End Sub
End Class
- In the Class Name combo box, select btnNewModel
- In the Method Name combo box, select Click and implement the event as follows:
Private Sub btnNewModelClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnNewModel.Click
Dim frmModels As CarModels = New CarModels
frmModels.ShowDialog()
End Sub
- In the Class Name combo box, select btnNewCategory
- In the Method Name combo box, select Click and implement the event as follows:
Private Sub btnNewCategoryClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnNewCategory.Click
Dim frmCategories As ItemsCategories = New ItemsCategories
frmCategories.ShowDialog()
End Sub
- In the Solution Explorer, right-click Central.vb and click View Code
- In the Class Name combo box, select btnNewAutoPart
- In the Method Name combo box, select Click and implement its event as follows:
Private Sub btnNewAutoPartClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnNewAutoPart.Click
Dim frmParts As AutoParts = New AutoParts
frmParts.ShowDialog()
End Sub
- Execute the application and make sure the forms and dialog boxes display
- Close the forms and return to your programming environment
Practical Learning: Saving the Records of a Data Set
|
|
- In the Solution Explorer, right-click ItemsCategories.vb and click View
Code
- In the Class Name combo box, select btnClose
- In the Method Name combo box, select Click and implement the event as follows:
Imports System.IO
Public Class ItemsCategories
Private Sub btnCloseClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnClose.Click
Dim FolderName As String = "C:\College Park Auto Parts"
' If this directory doesn't exist, create it
Directory.CreateDirectory(FolderName)
dsCategories.WriteXml(FolderName & "\categories.xml")
Close()
End Sub
End Class
- In the Solution Explorer, right-click CarMakes.vb and click View Code
- In the Class Name combo box, select btnClose button
- In the Method Name combo box, select Click and implement the event as follows:
Imports System.IO
Public Class CarMakes
Private Sub btnCloseClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnClose.Click
Dim FolderName As String = "C:\College Park Auto Parts"
' If this directory doesn't exist, create it
Directory.CreateDirectory(FolderName)
dsMakes.WriteXml(FolderName & "\makes.xml")
Close()
End Sub
End Class
- In the Solution Explorer, right-click CarModels.vb and click View Code
- In the Class Name combo box, select btnClose button
- In the Method Name combo box, select Click and implement the event as follows:
Imports System.IO
Public Class CarModels
Private Sub btnCloseClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnClose.Click
Dim FolderName As String = "C:\College Park Auto Parts"
' If this directory doesn't exist, create it
Directory.CreateDirectory(FolderName)
dsModels.WriteXml(FolderName & "\models.xml")
Close()
End Sub
End Class
- In the Solution Explorer, right-click AutoParts.vb and click View Code
- In the Class Name combo box, select btnClose button
- In the Method Name combo box, select Click and implement its event as follows:
Private Sub btnCloseClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnClose.Click
Dim FolderName As String = "C:\College Park Auto Parts"
' If this directory doesn't exist, create it
Directory.CreateDirectory(FolderName)
dsStoreItems.WriteXml(FolderName & "\StoreItems.xml")
Close()
End Sub
- Save all
Practical Learning: Opening the Records for a Data Set
|
|
- In the Solution Explorer, right-click ItemsCategories.vb and click View
Code
- In the Class Name combo box, select (ItemsCategories Events)
- In the Method Name combo box, select Load and
implement the event as follows:
Private Sub ItemsCategoriesLoad(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles Me.Load
Dim Filename As String = "C:\College Park Auto Parts\categories.xml"
If File.Exists(Filename) Then
dsCategories.ReadXml(Filename)
End If
End Sub
- In the Solution Explorer, right-click CarMakes.vb and click View Code
- In the Class Name combo box, select (CarMakes Events)
- In the Method Name combo box, select Load and implement the event as follows:
Private Sub CarMakesLoad(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles Me.Load
Dim Filename As String = "C:\College Park Auto Parts\makes.xml"
If File.Exists(Filename) Then
dsMakes.ReadXml(Filename)
End If
End Sub
- In the Solution Explorer, right-click CarModels.vb and click View Code
- In the Class Name combo box, select (CarModels Events)
- In the Method Name combo box, select Load and implement the event as follows:
Private Sub CarModelsLoad(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles Me.Load
Dim Filename As String = "C:\College Park Auto Parts\makes.xml"
If File.Exists(Filename) Then
dsMakes.ReadXml(Filename)
End If
Filename = "C:\College Park Auto Parts\models.xml"
If File.Exists(Filename) Then
dsModels.ReadXml(Filename)
End If
End Sub
- In the Solution Explorer, right-click AutoParts.vb and click View Code
- In the Class Name combo box, select (AutoParts Events)
- In the Method Name combo box, select Load and implement the event as
follows:
Private Sub AutoPartsLoad(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles Me.Load
Dim Filename As String = "C:\College Park Auto Parts\StoreItems.xml"
If File.Exists(Filename) Then
dsStoreItems.ReadXml(Filename)
End If
End Sub
- In the Class Name combo box, select (AutoParts Events)
- In the Method Name combo box, select Activated and
implement the event as follows:
Private Sub AutoPartsActivated(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles Me.Activated
Dim Filename As String = "C:\College Park Auto Parts\makes.xml"
If File.Exists(Filename) Then
dsMakes.ReadXml(Filename)
End If
Filename = "C:\College Park Auto Parts\models.xml"
If File.Exists(Filename) Then
dsModels.ReadXml(Filename)
End If
Filename = "C:\College Park Auto Parts\categories.xml"
If File.Exists(Filename) Then
dsCategories.ReadXml(Filename)
End If
End Sub
- Execute the application
- Click the New Auto Part button and click the New Make button
- Create a few makes as follows:
Acura |
Toyota |
Buick |
Dodge |
Honda |
Volvo |
- Click the New Model button and create a few models as follows:
Acura |
MDX 3.5 4WD |
Dodge |
Caravan SE L4 2.4 |
Ford |
Escort SE L4 2.0 |
Toyota |
Rav4 2WD/4-Door |
Honda |
Civic 1.7 EX 4DR |
Ford |
Taurus LX V6 3.0 |
Honda |
Accord 2.3 LX 4DR |
- Click the New Category button and create a few categories as follows:
Exhaust |
Air Intake |
Cooling System |
Engine Electrical |
- Close the form(s) and return to your
programming environment
Practical Learning: Getting the Values of a Data Set
|
|
-
In the Solution Explorer, Double-click Central.vb
- From the Data section of the Toolbox, click DataSet and click the form
- In the Add Dataset dialog box, click the Untyped dataset radio button and
click OK
- In the Properties window, change the characteristics of the data set as
follows:
DataSetName: StoreItems
(Name): dsStoreItems
- Click Tables and click its ellipsis button
- In the Properties list, change the characteristics of the table as
follows:
TableName: AutoPart
(Name): tblAutoPart
- Click Columns and click its ellipsis button
- In the Columns Collection Editor, click Add continuously and create the
columns as follows:
ColumnName |
(Name) |
PartNumber |
colPartNumber |
Year |
colYear |
Make |
colMake |
Model |
colModel |
Category |
colCategory |
PartName |
colPartName |
UnitPrice |
colUnitPrice |
- Click Close and click Close
-
Right-click the form and click View Code
-
In the top section of the file, import the System.IO and the System.Xml
namespaces
Imports System.IO
Imports System.Xml
Public Class Central
-
In the bottom section of the file, just above the End Class line, create a
procedure as follows:
Private Sub ShowAutoParts()
Dim Years As Integer
tvwAutoParts.Nodes.Clear()
Dim RootReceipts As TreeNode =
tvwAutoParts.Nodes.Add("College Park Auto-Parts",
"College Park Auto-Parts", 0, 1)
' Show the years nodes
For Years = DateTime.Today.Year + 1 To 1960 Step -1
RootReceipts.Nodes.Add(CStr(Years), CStr(Years), 2, 3)
Next
tvwAutoParts.SelectedNode = RootReceipts
' Expand the root node
tvwAutoParts.ExpandAll()
' This is the file that holds the list of store items on sale
Dim Filename As String = "C:\College Park Auto Parts\StoreItems.xml"
If File.Exists(Filename) Then
dsStoreItems.ReadXml(Filename)
' Add the makes to the years
For Each NodeYear As TreeNode In RootReceipts.Nodes
Dim ListOfMakes As List(Of String) = New List(Of String)()
For Each row As DataRow In tblAutoPart.Rows
If NodeYear.Text = row("Year") Then
If Not ListOfMakes.Contains(row("Make")) Then
ListOfMakes.Add(row("Make"))
End If
End If
Next
For Each strMake As String In ListOfMakes
NodeYear.Nodes.Add(strMake, strMake, 4, 5)
Next
Next
' Add the models to the makes
For Each NodeYear As TreeNode In RootReceipts.Nodes
For Each NodeMake As TreeNode In NodeYear.Nodes
Dim ListOfModels As List(Of String) = New List(Of String)
For Each row As DataRow In tblAutoPart.Rows
If (NodeYear.Text = row("Year")) And
(NodeMake.Text = row("Make")) Then
If Not ListOfModels.Contains(row("Model")) Then
ListOfModels.Add(row("Model"))
End If
End If
Next
For Each strModel As String In ListOfModels
NodeMake.Nodes.Add(strModel, strModel, 6, 7)
Next
Next
Next
' Show the categories nodes
For Each NodeYear As TreeNode In RootReceipts.Nodes
For Each NodeMake As TreeNode In NodeYear.Nodes
For Each NodeModel As TreeNode In NodeMake.Nodes
Dim ListOfCategories As List(Of String) = New List(Of String)
For Each row As DataRow In tblAutoPart.Rows
If (NodeYear.Text = row("Year")) And
(NodeMake.Text = row("Make")) And
(NodeModel.Text = row("Model")) Then
If Not ListOfCategories.Contains(row("Category")) Then
ListOfCategories.Add(row("Category"))
End If
End If
Next
For Each strCategory As String In ListOfCategories
NodeModel.Nodes.Add(strCategory, strCategory, 8, 9)
Next
Next
Next
Next
End If
End Sub
- In the Class Name combo box, select (Central Events)
-
In the Method Name combo box, select Load and implement the event as follows:
Private Sub CentralLoad(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles Me.Load
ShowAutoParts()
btnNewCustomerOrderClick(sender, e)
End Sub
- In the Class Name combo box, select txtPartNumber
- In the Method Name combo box, select Leave and
implement the event as follows:
Private Sub txtPartNumberLeave(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles txtPartNumber.Leave
For Each row As DataRow In tblAutoPart.Rows
If row("PartNumber") = txtPartNumber.Text Then
txtPartName.Text = row("PartName")
txtUnitPrice.Text = row("UnitPrice")
txtQuantity.Text = "0"
txtSubTotal.Text = "0.00"
End If
Next
End Sub
- In the Class Name combo box, select btnAdd
- In the Method Name combo box, select Click and implement the event as follows:
Private Sub btnAddClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnAdd.Click
If txtPartNumber.Text.Length = 0 Then
MsgBox("There is no part to be added to the order")
Exit Sub
End If
Dim lviSelectedPart As ListViewItem =
New ListViewItem(txtPartNumber.Text)
lviSelectedPart.SubItems.Add(txtPartName.Text)
lviSelectedPart.SubItems.Add(txtUnitPrice.Text)
lviSelectedPart.SubItems.Add(txtQuantity.Text)
lviSelectedPart.SubItems.Add(txtSubTotal.Text)
lvwSelectedParts.Items.Add(lviSelectedPart)
CalculateOrder()
End Sub
- In the Class Name combo box, select btnNewCustomerOrder
- In the Method Name combo box, select Click and implement the event as follows:
Private Sub btnNewCustomerOrderClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnNewCustomerOrder.Click
' Create a default receipt number and set it to 0
Dim ReceiptNumber As Integer = 0
' This is the name of the file that holds the customers' receipts
Dim Filename As String = "C:\College Park Auto Parts\receipts.xml"
Dim DOMReceipts As XmlDocument = New XmlDocument
' If the file exists, open it
If File.Exists(Filename) Then
DOMReceipts.Load(Filename)
' After opening the file, get a reference to its root
Dim RootReceipts As XmlElement = DOMReceipts.DocumentElement
' Get a list of the receipt numbers
Dim ListOfReceiptNumbers As XmlNodeList =
RootReceipts.GetElementsByTagName("ReceiptNumber")
' If there are receipts already, get the last receipt number
' and set it as the current receipt number
ReceiptNumber = CInt(ListOfReceiptNumbers(
ListOfReceiptNumbers.Count - 1).InnerText)
End If
' Initialize a new customer number with default values
txtSave.Text = CStr(ReceiptNumber + 1)
txtTaxRate.Text = "5.75"
txtTaxAmount.Text = "0.00"
txtPartsTotal.Text = "0.00"
txtOrderTotal.Text = "0.00"
lvwSelectedParts.Items.Clear()
End Sub
- In the Class Name combo box, select tvwAutoParts
-
In the Method Name combo box, select NodeMouseClick and implement the event as follows:
Private Sub tvwAutoPartsNodeMouseClick(ByVal sender As Object,
ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs)
Handles tvwAutoParts.NodeMouseClick
' Get a reference to the node that was clicked
Dim nodClicked As TreeNode = e.Node
' If the user clicked the category of a part,
' Then clear the Available Parts list view
If nodClicked.Level = 4 Then
lvwAutoParts.Items.Clear()
End If
Try
' Check each record in the list/table of auto parts
For Each Record As DataRow In tblAutoPart.Rows
' If you find a record that corresponds to the
' category, make, model, and year that the clerk clicked ...
If (Record("Category") = nodClicked.Text) And
(Record("Model") = nodClicked.Parent.Text) And
(Record("Make") = nodClicked.Parent.Parent.Text) And
(Record("Year") = nodClicked.Parent.Parent.Parent.Text) Then
' ... get that auto part and display it
' in the Available Parts list view
Dim lviAutoPart As ListViewItem =
New ListViewItem(CStr(Record("PartNumber")))
lviAutoPart.SubItems.Add(Record("PartName"))
lviAutoPart.SubItems.Add(Record("UnitPrice"))
lvwAutoParts.Items.Add(lviAutoPart)
End If
Next
Catch Exc As NullReferenceException
' If there is no such a part, don't do nothin'
End Try
End Sub
- In the Class Name combo box, select btnSave
- In the Method Name combo box, select Click and implement the event as follows:
Private Sub btnSaveClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnSave.Click
' This is the file that holds the receipts
Dim Filename As String = "C:\College Park Auto Parts\receipts.xml"
' Get a reference to the root
Dim DOMReceipts As XmlDocument = New XmlDocument
' We will create a list of all the parts
' that the customer wants to purchase
Dim strParts As String = ""
For Each lviPart As ListViewItem In lvwSelectedParts.Items
strParts = strParts &
"<Part>" &
"<PartNumber>" & lviPart.SubItems(0).Text & "</PartNumber>" &
"<PartName>" & lviPart.SubItems(1).Text & "</PartName>" &
"<UnitPrice>" & lviPart.SubItems(2).Text & "</UnitPrice>" &
"<Quantity>" & lviPart.SubItems(3).Text & "</Quantity>" &
"<SubTotal>" & lviPart.SubItems(4).Text & "</SubTotal>" &
"</Part>"
Next
' If this is the first customer order, ...
If Not File.Exists(Filename) Then
' If this is the first receipt to be created,
' set the receipt number to 1
' and create the structure of the document
DOMReceipts.LoadXml("<?xml version=""1.0"" encoding=""utf-8""?>" &
"<CustomersOrders>" &
"<Receipt>" &
"<ReceiptNumber>1</ReceiptNumber>" & strParts &
"<PartsTotal>" & txtPartsTotal.Text &
"</PartsTotal><TaxRate>" & txtTaxRate.Text &
"</TaxRate><TaxAmount>" & txtTaxAmount.Text &
"</TaxAmount><OrderTotal>" & txtOrderTotal.Text &
"</OrderTotal></Receipt></CustomersOrders>")
' Save the XML file
DOMReceipts.Save(Filename)
' Reset the customer order
txtSave.Text = "2"
txtOpen.Text = "1"
txtTaxRate.Text = "5.75"
txtTaxAmount.Text = "0.00"
txtPartsTotal.Text = "0.00"
txtOrderTotal.Text = "0.00"
lvwSelectedParts.Items.Clear()
' If this is not the first customer order, ...
Else ' if File.Exists(Filename) Then
Dim NodeCustomerOrder As XmlNode = Nothing
' We will use a receipt number for each receipt
Dim ReceiptNumber As Integer = CInt(txtSave.Text)
' If at least one receipt had previously been created,
' then open the XML file that holds the receipts
' Store the XML file structure into the DOM
DOMReceipts.Load(Filename)
' Get a reference to the root element
Dim RootCustomersOrders As XmlElement = DOMReceipts.DocumentElement
' Get a list of the receipt numbers
Dim ListOfReceipts As XmlNodeList =
RootCustomersOrders.GetElementsByTagName("Receipt")
' Check each receipt
For Each NodeCurrentReceipt As XmlNode In ListOfReceipts
' Look for a receipt that has the same number
' as in the Save text box
If NodeCurrentReceipt("ReceiptNumber").InnerText = txtSave.Text Then
' If you find it, reserve it
NodeCustomerOrder = NodeCurrentReceipt
Exit For
End If
Next
' Locate the last receipt number
ReceiptNumber = CInt(txtSave.Text)
' Create an element named Receipt
Dim ElementReceipt As XmlElement = DOMReceipts.CreateElement("Receipt")
Dim strReceipt As String =
"<ReceiptNumber>" & ReceiptNumber.ToString() &
"</ReceiptNumber>" & strParts &
"<PartsTotal>" & txtPartsTotal.Text &
"</PartsTotal><TaxRate>" & txtTaxRate.Text &
"</TaxRate><TaxAmount>" & txtTaxAmount.Text &
"</TaxAmount><OrderTotal>" & txtOrderTotal.Text &
"</OrderTotal>"
' Create the XML code of the new element
ElementReceipt.InnerXml = strReceipt
' If this is a new customer order
If NodeCustomerOrder Is Nothing Then
' Add the new receipt to the file
DOMReceipts.DocumentElement.AppendChild(ElementReceipt)
' If the customer order existed already, we will only update it
Else ' if NodeCustomerOrder <> nothing then
' Replace the existing customer order with the current one
DOMReceipts.DocumentElement.ReplaceChild(
ElementReceipt, NodeCustomerOrder)
End If
' Save the XML file
DOMReceipts.Save(Filename)
' Reset the customer order
btnNewCustomerOrderClick(sender, e)
End If
End Sub
- In the Class Name combo box, select btnOpen
- In the Method Name combo box, select Click and implement the event as follows:
Private Sub btnOpenClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnOpen.Click
Dim DOMReceipts As XmlDocument = New XmlDocument
Dim Filename As String = "C:\College Park Auto Parts\receipts.xml"
' Check that the file exists. If so, open it
If File.Exists(Filename) Then
' This variable will allow us to know if we have the receipt number
Dim Found As Boolean = False
' Empty the list of selected parts
lvwSelectedParts.Items.Clear()
' After opening the XML file, store it in the DOM
DOMReceipts.Load(Filename)
' Get a reference to the root element
Dim RootReceipts As XmlElement = DOMReceipts.DocumentElement
' Get a list of the receipts in the file
Dim ListOfReceipts As XmlNodeList =
RootReceipts.GetElementsByTagName("Receipt")
' Check each receipt
For Each nodReceipt As XmlNode In ListOfReceipts
' Look for an receipt that has the same number
' as on the Open text box
If nodReceipt("ReceiptNumber").InnerText = txtOpen.Text Then
' If you find it, make a note
Found = True
txtOpen.Text = nodReceipt("ReceiptNumber").InnerText
txtSave.Text = nodReceipt("ReceiptNumber").InnerText
' Retrieve the values of the receipt
' and display them on the form
Try
For Each nodeReceipt As XmlNode In nodReceipt.ChildNodes
Dim Node As XmlNode = nodeReceipt.NextSibling.ChildNodes(0)
Dim lviReceipt As ListViewItem = New ListViewItem(Node.InnerText)
lviReceipt.SubItems.Add(Node.NextSibling.InnerText)
lviReceipt.SubItems.Add(Node.NextSibling.NextSibling.InnerText)
lviReceipt.SubItems.Add(Node.NextSibling.NextSibling.NextSibling.InnerText)
lviReceipt.SubItems.Add(Node.NextSibling.NextSibling.NextSibling.NextSibling.InnerText)
lvwSelectedParts.Items.Add(lviReceipt)
Next
txtPartsTotal.Text = nodReceipt("PartsTotal").InnerText
txtTaxRate.Text = nodReceipt("TaxRate").InnerText
txtTaxAmount.Text = nodReceipt("TaxAmount").InnerText
txtOrderTotal.Text = nodReceipt("OrderTotal").InnerText
Catch Exc As NullReferenceException
End Try
End If
Next
' If the receipt was not found, let the user know
If Found = False Then
MsgBox("There is no customer order with that receipt number")
txtSave.Text = txtOpen.Text
End If
' IF the XML file was not found, let the user know
Else
MsgBox("The file " + Filename + " was not found")
End If
End Sub
- Save the file
- Display the Central form and double-click an unoccupied area of its body
- Add a call to the Click event of the New Customer Order button as follows:
Private Sub CentralLoad(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles Me.Load
ShowAutoParts()
btnNewCustomerOrderClick(sender, e)
End Sub
- Return to the Central form and double-click the Close button
- Implement the event as follows:
Private Sub btnCloseClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnClose.Click
End
End Sub
- Execute the application
- Click the New Auto Part button and use the
Part Editor to create a few parts
- Close the Part Editor
- Create a few customer part orders and save them:
- Close the forms and return to your programming environment
- Execute the application again and open a previously saved order
- Close the forms and return to your programming environment
- Open the CollegeParkAutoParts2 application from this lesson
- Create a Part Editor form and design it as follows:
- Add a context menu for the Available Parts list view with the items:
Select, Edit..., and Delete
- Configure the context menu so that
- If the user clicks Select, the behavior would be the same as if the
user had double-clicked the item
- If the user clicks Edit..., the Part Editor dialog box would display
with the part in it. The user can then edit any part (year, make, model,
category, part name, or unit price) except the part number. Then the
user can save the changed part
- If the user clicks Delete, a message box would warn the user and ask
for confirmation with Yes/No answers. If the user clicks Yes, the part
would be deleted from the AutoParts list
- Configure the application so that the user can open an order, add new
parts to it, or delete parts from it, then save the order
- Extend the application so that the store can also sell items that are, or
are not, car-related, such as books, t-shirts, cleaning items, maintenance
items (steering oils, brake oils, etc), license plates, etc. Every item in
the store should have an item number. The user can enter that item number in
the Part # text box and press Tab or Enter. The corresponding item would
then be retrieved from the database and displayed on the form. If there is
no item with that number, a message box should let the user know
|