xml software

Upload: deract

Post on 30-May-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 XML Software

    1/21

    XML-Based Applications: College Park

    Auto-ShopIntroduction

    As always mentioned, XML provides the ability to store information as regular text sothat the same information can be accessed from completely independent applications.This provides tremendous opportunities in the areas of storage and sharing of data. Tomake it even more useful, the .NET Framework provides full support for the DocumentObject Model (DOM) of XML through various classes.

    In this exercise, we are going to create an application used by a car repair business.To use it, an employee of the business can open a form to process a customer's work

    order. During this, the employee can enter the customer, the information about the carto be fixed, and a text description of the problem.

    Practical Learning: Starting the Exercise

    1. Start Microsoft Visual C# and create a new Windows Forms Application named

    CPAS2

    2. To add another form, on the main menu, click Project -> Add Windows Form...

    3. Set the Name to InfoCenter and click Open

    4. To create a data set, in the Toolbox, click the Data button, then click DataSet,and click the form

    5. In the Add Dataset dialog box, click the Untyped dataset radio button

    6. Click OK7. While the new dataSet1 button is selected, in the Properties window, set its

    (Name) to dsWorkorders and set its DataSetName to Workorders

  • 8/14/2019 XML Software

    2/21

    8. To create the necessary structure of a work order, while the DataSet object is stillselected, in the Properties window, click Tables and click its ellipsis button

    9. In the Tables Collection Editor, click Add

    10.Set the (Name) to tblWorkorder and set the TableName to Workorder

    11.Set its Modifiers to Public12. To create the columns, in the Workorder Properties section, click Columns and

    click its ellipsis button

    13. In the Columns Collection Editor, click Add

    14.Set the properties as follows:

    (Name): colCustomerNameColumnName: CustomerName

    Modifiers: Public

    15. In the same way, create the other columns as follows:

    (Name) ColumnName DataType Modifiers

    colCustomerName CustomerName System.String Public

    colAddress Address System.String Public

    colCity City System.String Public

    colState State System.String Public

    colZIPCode ZIPCode System.String Public

    colMake Make System.String Public

    colModel Model System.String Public

    colCarYear CarYear System.String Public

    colProblem Problem System.String Public

    colPartName1 PartName1 System.String Public

    colUnitPrice1 UnitPrice1 System.Double Public

    colQuantity1 Quantity1 System.Int16 Public

    colSubTotal1 SubTotal1 System.Double Public

    colPartName2 PartName2 System.String Public

    colUnitPrice2 UnitPrice2 System.Double Public

    colQuantity2 Quantity2 System.Int16 Public

    colSubTotal2 SubTotal2 System.Double Public

    colPartName3 PartName3 System.String Public

    colUnitPrice3 UnitPrice3 System.Double Public

    colQuantity3 Quantity3 System.Int16 Public

    colSubTotal3 SubTotal3 System.Double Public

    colPartName4 PartName4 System.String Public

    colUnitPrice4 UnitPrice4 System.Double Public

    colQuantity4 Quantity4 System.Int16 Public

    colSubTotal4 SubTotal4 System.Double Public

    colPartName5 PartName5 System.String Public

    colUnitPrice5 UnitPrice5 System.Double Public

    colQuantity5 Quantity5 System.Int16 Public

    colSubTotal5 SubTotal5 System.Double Public

    colJobPerformed1 JobPerformed1 System.String Public

    colJobPrice1 JobPrice1 System.Double Public

    colJobPerformed2 JobPerformed2 System.String Public

  • 8/14/2019 XML Software

    3/21

    colJobPrice2 JobPrice2 System.Double Public

    colJobPerformed3 JobPerformed3 System.String Public

    colJobPrice3 JobPrice3 System.Double Public

    colJobPerformed4 JobPerformed4 System.String Public

    colJobPrice4 JobPrice4 System.Double Public

    colJobPerformed5 JobPerformed5 System.String Public

    colJobPrice5 JobPrice5 System.Double Public

    colTotalParts TotalParts System.Double Public

    colTotalLabor TotalLabor System.Double Public

    colTaxRate TaxRate System.Double Public

    colTaxAmount TaxAmount System.Double Public

    colTotalOrder TotalOrder System.Double Public

    colRecommendations Recommendations System.Double Public

    16.Click Close twice

    17. To add another form, on the main menu, click Project -> Add Windows Form...

    18. In the Templates list, click Windows Form (.NET)

    19.Set the Name to NewWorkorder and click Open

    20.Design the form as follows:

  • 8/14/2019 XML Software

    4/21

    Control Name Text Other Properties

    GroupBox Customer and Car Information

    Label Customer Name:

    TextBox txtCustomerName

    Label Address

    TextBox txtAddress

    Label City:

    TextBox txtCity

    Label State:

    TextBox txtState

    Label ZIP Code:

    TextBox txtZIPCode TextAlign: Right

    Label Make / Model:

    TextBox txtMake

    TextBox txtModel

    Label Year:

    TextBox txtCarYear TextAlign: Right

    Label Problem Description:

    TextBox txtProblem

    GroupBox Parts Used

    Label Part Name

    Label Unit Price

    Label Qty

    Label Sub Total

    TextBox txtPartName1TextBox txtUnitPrice1 0.00 TextAlign: Right

    TextBox txtQuantity1 0 TextAlign: Right

    TextBox txtSubTotal1 0.00TextAlign: RightEnabled: False

    TextBox txtPartName2

    TextBox txtUnitPrice2 0.00 TextAlign: Right

    TextBox txtQuantity2 0 TextAlign: Right

    TextBox txtSubTotal2 0.00TextAlign: Right

    Enabled: False

    TextBox txtPartName3

    TextBox txtUnitPrice3 0.00 TextAlign: Right

    TextBox txtQuantity3 0 TextAlign: Right

    TextBox txtSubTotal3 0.00TextAlign: RightEnabled: False

    TextBox txtPartName4

    TextBox txtUnitPrice4 0.00 TextAlign: Right

    TextBox txtQuantity4 0 TextAlign: Right

    TextBox txtSubTotal4 0.00TextAlign: RightEnabled: False

    TextBox txtPartName5

    TextBox txtUnitPrice5 0.00 TextAlign: RightTextBox txtQuantity5 0 TextAlign: Right

    TextBox txtSubTotal5 0.00TextAlign: RightEnabled: False

    GroupBox Jobs Performed

    Label Price

    TextBox txtJobPerformed1

  • 8/14/2019 XML Software

    5/21

    21.Save all

    22. Press Ctrl + A to select everything

    23. Press Ctrl + C to copy everything

    24. To add another form, on the main menu, click Project -> Add Windows Form...

    25. In the Templates list, click Windows Form (.NET)

    26.Set the Name to Workorders and click Open

    27. Enlarge the form as much as possible, then right-click it and click Paste

    28.Adjust the design of the form as follows

    ex ox x o er orme

    TextBox txtJobPrice2 0.00 TextAlign: Right

    TextBox txtJobPerformed3

    TextBox txtJobPrice3 0.00 TextAlign: Right

    TextBox txtJobPerformed4

    TextBox txtJobPrice4 0.00 TextAlign: Right

    TextBox txtJobPerformed5

    TextBox txtJobPrice5 0.00 TextAlign: Right

    GroupBox Recommendations to Customer

    TextBox txtRecommendationsMultiline: True

    ScrollBars: Vertical

    GroupBox Order Summary

    Button btnCalculateOrder Calculate Order

    Label Total Parts:

    TextBox txtTotalParts 0.00 TextAlign: Right

    Label Total Labor:

    TextBox txtTotalLabor 0.00 TextAlign: Right

    Label Tax Rate:

    TextBox txtTaxRate 7.75 TextAlign: Right

    Label %

    Label Tax Amount:

    TextBox txtTaxAmount 0.00 TextAlign: Right

    Label Total Order:

    TextBox txtTotalOrder 0.00 TextAlign: Right

    Label Order Date:

    DateTimePicker dtpOrderDateFormat: CustomCustomFormat: ddddd MMM yyyy

    Button btnSaveOrderSave this Order in the AboveDate and Start New One

    Button btnResetOrder Reset Order

    Button btnPreview Print Preview

    Button btnClose Close

    FormCancelButton:btnClose

  • 8/14/2019 XML Software

    6/21

    Control Name Text Other Properties

    GroupBox Customer and Car Information

    Label Customer Name:

    TextBox txtCustomerName

    Label Address

    TextBox txtAddress

    Label City:

    TextBox txtCity

    Label State:

    TextBox txtState

    Label ZIP Code:

    TextBox txtZIPCode TextAlign: Right

    Label Make / Model:

    TextBox txtMake

    TextBox txtModel

    Label Year:

    TextBox txtCarYear TextAlign: Right

    Label Problem Description:

    TextBox txtProblem

    GroupBox Parts Used

    Label Part Name

    Label Unit Price

    Label Qty

    Label Sub Total

    TextBox txtPartName1

    TextBox txtUnitPrice1 0.00 TextAlign: Right

    TextBox txtQuantity1 0 TextAlign: Right

    TextBox txtSubTotal1 0.00TextAlign: RightEnabled: False

  • 8/14/2019 XML Software

    7/21

    29.Save all

    30.Display the first or main form (Form1.h [Design]) and design it as follows:

    Control Name Text

    Button btnNewOrder Create New WorkorderButton btnOpenOrders Open Previous Workorders

    Button btnClose Close

    31.Double-click the Create New Workorder button

    32.Return to the form and double-click the Open Previous Workorders button

    33.Return to the form and double-click the Close button

    34. Implement the Click events as follows:

    private void btnNewOrder_Click(object sender, System.EventArgs e)

    {NewWorkorder frmOrder = new NewWorkorder();frmOrder.ShowDialog();

    }

    private void btnOpenOrders_Click(object sender, System.EventArgs e){

    Workorders frmOrders = new Workorders();frmOrders.ShowDialog();

    }

    private void btnClose_Click(object sender, System.EventArgs e){

    Close();}

    35. Execute the application to test it

    Calculating the Order

    When a car has been fixed, an employee can complete the form with what was done. A section

    of the form allows the employee to enter the names, prices, and quantities of parts that wereused to fix the car. Each part is entered but its name, a unit price, and a quantity; then, a subtotal of each part must be calculated.

    Besides the parts used, the employee must also list the types of repairs that were performedand their costs. This also allows the customer to know what was done.

    Once the parts information and the jobs performed have been entered, the order can becalculated to know the total the customer will pay.

  • 8/14/2019 XML Software

    8/21

    Practical Learning: Starting the Exercise

    1. Display the New Work Order form. Double-click the Reset Order button andimplement its Click event as follows:

    private void btnResetOrder_Click(object sender, System.EventArgs e){

    this.txtCustomerName.Text = "";this.txtAddress.Text = "";this.txtCity.Text = "";this.txtState.Text = "";this.txtZIPCode.Text = "";this.txtMake.Text = "";this.txtModel.Text = "";this.txtCarYear.Text = "";this.txtProblem.Text = "";

    this.txtPartName1.Text = "";

    this.txtUnitPrice1.Text = "0.00";this.txtQuantity1.Text = "0";this.txtSubTotal1.Text = "0.00";this.txtPartName2.Text = "";this.txtUnitPrice2.Text = "0.00";this.txtQuantity2.Text = "0";this.txtSubTotal2.Text = "0.00";this.txtPartName3.Text = "";this.txtUnitPrice3.Text = "0.00";this.txtQuantity3.Text = "0";this.txtSubTotal3.Text = "0.00";this.txtPartName4.Text = "";this.txtUnitPrice4.Text = "0.00";

    this.txtQuantity4.Text = "0";this.txtSubTotal4.Text = "0.00";this.txtPartName5.Text = "";this.txtUnitPrice5.Text = "0.00";this.txtQuantity5.Text = "0";this.txtSubTotal5.Text = "0.00";

    this.txtJobPerformed1.Text = "";this.txtJobPrice1.Text = "0.00";this.txtJobPerformed2.Text = "";this.txtJobPrice2.Text = "0.00";this.txtJobPerformed3.Text = "";this.txtJobPrice3.Text = "0.00";

    this.txtJobPerformed4.Text = "";this.txtJobPrice4.Text = "0.00";this.txtJobPerformed5.Text = "";this.txtJobPrice5.Text = "0.00";

    this.txtTotalParts.Text = "0.00";this.txtTotalLabor.Text = "0.00";this.txtTaxRate.Text = "7.75";this.txtTaxAmount.Text = "0.00";this.txtTotalOrder.Text = "0.00";

    this.txtRecommendations.Text = "";this.txtCustomerName.Focus();

    }2. Double-click the Calculate Order button and implement its Click event as follows:

    private void btnCalculateOrder_Click(object sender, System.EventArgs e){

  • 8/14/2019 XML Software

    9/21

    decimal part1UnitPrice = 0.00M,part1SubTotal = 0.00M,part2UnitPrice = 0.00M,part2SubTotal = 0.00M,part3UnitPrice = 0.00M,part3SubTotal = 0.00M,

    part4UnitPrice = 0.00M,part4SubTotal = 0.00M,

    part5UnitPrice = 0.00M,part5SubTotal = 0.00M,totalParts = 0.00M;

    int part1Quantity = 0, part2Quantity = 0, part3Quantity = 0,part4Quantity = 0, part5Quantity = 0;

    decimal job1Price = 0.00M,job2Price = 0.00M,job3Price = 0.00M,job4Price = 0.00M,job5Price = 0.00M;

    decimal totalLabor = 0.00M;

    decimal taxRate = 0.00M, taxAmount = 0.00M, totalOrder = 0.00M;

    // Don't charge a part unless it is clearly identifiedif( this.txtPartName1.Text == "" ){

    this.txtUnitPrice1.Text = "0.00";this.txtQuantity1.Text = "0";this.txtSubTotal1.Text = "0.00";part1UnitPrice = 0.00M;

    }else{

    try

    { part1UnitPrice =decimal.Parse(this.txtUnitPrice1.Text);

    }catch(FormatException ){

    MessageBox.Show("Invalid Unit Price");this.txtUnitPrice1.Text = "0.00";this.txtUnitPrice1.Focus();

    }

    try{

    part1Quantity =int.Parse(this.txtQuantity1.Text);}catch(FormatException ){

    MessageBox.Show("Invalid Quantity");this.txtQuantity1.Text = "0";this.txtQuantity1.Focus();

    }}

    if( this.txtPartName2.Text == "" ){

    this.txtUnitPrice2.Text = "0.00";this.txtQuantity2.Text = "0";this.txtSubTotal2.Text = "0.00";part2UnitPrice = 0.00M;

    }else

  • 8/14/2019 XML Software

    10/21

    {try{

    part2UnitPrice =decimal.Parse(this.txtUnitPrice2.Text);

    }

    catch(FormatException ){

    MessageBox.Show("Invalid Unit Price");this.txtUnitPrice2.Text = "0.00";this.txtUnitPrice2.Focus();

    }

    try{

    part2Quantity =int.Parse(this.txtQuantity2.Text);

    }catch(FormatException )

    { MessageBox.Show("Invalid Quantity");this.txtQuantity2.Text = "0";this.txtQuantity2.Focus();

    }}

    if( this.txtPartName3.Text == "" ){

    this.txtUnitPrice3.Text = "0.00";this.txtQuantity3.Text = "0";this.txtSubTotal3.Text = "0.00";part3UnitPrice = 0.00M;

    }else{

    try{

    part3UnitPrice =decimal.Parse(this.txtUnitPrice3.Text);

    }catch(FormatException ){

    MessageBox.Show("Invalid Unit Price");this.txtUnitPrice3.Text = "0.00";this.txtUnitPrice3.Focus();

    }

    try{

    part3Quantity =int.Parse(this.txtQuantity3.Text);

    }catch(FormatException ){

    MessageBox.Show("Invalid Quantity");this.txtQuantity3.Text = "0";this.txtQuantity3.Focus();

    }}

    if( this.txtPartName4.Text == "" ){

    this.txtUnitPrice4.Text = "0.00";this.txtQuantity4.Text = "0";

  • 8/14/2019 XML Software

    11/21

    this.txtSubTotal4.Text = "0.00";part4UnitPrice = 0.00M;

    }else{

    try

    {part4UnitPrice =

    decimal.Parse(this.txtUnitPrice4.Text);}catch(FormatException ){

    MessageBox.Show("Invalid Unit Price");this.txtUnitPrice4.Text = "0.00";this.txtUnitPrice4.Focus();

    }

    try{

    part4Quantity =int.Parse(this.txtQuantity4.Text);}catch(FormatException ){

    MessageBox.Show("Invalid Quantity");this.txtQuantity4.Text = "0";this.txtQuantity4.Focus();

    }}

    if( this.txtPartName5.Text == "" ){

    this.txtUnitPrice5.Text = "0.00";this.txtQuantity5.Text = "0";this.txtSubTotal5.Text = "0.00";part5UnitPrice = 0.00M;

    }else{

    try{

    part5UnitPrice =decimal.Parse(this.txtUnitPrice5.Text);

    }catch(FormatException )

    { MessageBox.Show("Invalid Unit Price");this.txtUnitPrice5.Text = "0.00";this.txtUnitPrice5.Focus();

    }

    try{

    part5Quantity =int.Parse(this.txtQuantity5.Text);

    }catch(FormatException ){

    MessageBox.Show("Invalid Quantity");this.txtQuantity5.Text = "0";this.txtQuantity5.Focus();

    }}

  • 8/14/2019 XML Software

    12/21

    // Don't bill the customer for a job that is not specifiedif( this.txtJobPerformed1.Text == "" ){

    this.txtJobPrice1.Text = "0.00";job1Price = 0.00M;

    }

    else{

    try{

    job1Price =decimal.Parse(this.txtJobPrice1.Text);

    }catch(FormatException ){

    MessageBox.Show("Invalid Job Price");this.txtJobPrice1.Text = "0.00";this.txtJobPrice1.Focus();

    }

    } if( this.txtJobPerformed2.Text == "" ){

    this.txtJobPrice2.Text = "0.00";job2Price = 0.00M;

    }else{

    try{

    job2Price =decimal.Parse(this.txtJobPrice2.Text);

    }catch(FormatException ){

    MessageBox.Show("Invalid Job Price");this.txtJobPrice2.Text = "0.00";this.txtJobPrice2.Focus();

    }}

    if( this.txtJobPerformed3.Text == "" ){

    this.txtJobPrice3.Text = "0.00";job3Price = 0.00M;

    }else{

    try{

    job3Price =decimal.Parse(this.txtJobPrice3.Text);

    }catch(FormatException ){

    MessageBox.Show("Invalid Job Price");this.txtJobPrice3.Text = "0.00";this.txtJobPrice3.Focus();

    }}

    if( this.txtJobPerformed4.Text == "" ){

    this.txtJobPrice4.Text = "0.00";

  • 8/14/2019 XML Software

    13/21

    job4Price = 0.00M;}else{

    try{

    job4Price =decimal.Parse(this.txtJobPrice4.Text);

    }catch(FormatException ){

    MessageBox.Show("Invalid Job Price");this.txtJobPrice4.Text = "0.00";this.txtJobPrice4.Focus();

    }}

    if( this.txtJobPerformed5.Text == "" ){

    this.txtJobPrice5.Text = "0.00";job5Price = 0.00M;}else{

    try{

    job5Price =decimal.Parse(this.txtJobPrice5.Text);

    }catch(FormatException ){

    MessageBox.Show("Invalid Job Price");

    this.txtJobPrice5.Text = "0.00";this.txtJobPrice5.Focus();}

    }

    part1SubTotal = part1UnitPrice * part1Quantity;part2SubTotal = part2UnitPrice * part2Quantity;part3SubTotal = part3UnitPrice * part3Quantity;part4SubTotal = part4UnitPrice * part4Quantity;part5SubTotal = part5UnitPrice * part5Quantity;

    this.txtSubTotal1.Text = part1SubTotal.ToString("F");this.txtSubTotal2.Text = part2SubTotal.ToString("F");

    this.txtSubTotal3.Text = part3SubTotal.ToString("F");this.txtSubTotal4.Text = part4SubTotal.ToString("F");this.txtSubTotal5.Text = part5SubTotal.ToString("F");

    totalParts = part1SubTotal + part2SubTotal + part3SubTotal +part4SubTotal + part5SubTotal;

    totalLabor = job1Price + job2Price + job3Price +

    job4Price + job5Price;

    try{

    taxRate = decimal.Parse(this.txtTaxRate.Text);}catch(FormatException ){

    MessageBox.Show("Invalid Tax Rate");this.txtTaxRate.Text = "7.75";this.txtTaxRate.Focus();

  • 8/14/2019 XML Software

    14/21

    }

    decimal totalPartsAndLabor = totalParts + totalLabor;taxAmount = totalPartsAndLabor * taxRate / 100;totalOrder = totalPartsAndLabor + taxAmount;

    this.txtTotalParts.Text = totalParts.ToString("F");this.txtTotalLabor.Text = totalLabor.ToString("F");this.txtTaxAmount.Text = taxAmount.ToString("F");this.txtTotalOrder.Text = totalOrder.ToString("F");

    }

    3. Execute the application to test it and fill the form with a record

    4. Click the Calculate Order button

    5. Close the form and return to your programming environment

    Saving the Customer Order

    Once a work order has been completed, it can be saved. There are various ways you cansolve this. One of the easiest ways would consist of saving each order directly in its ownfile. The problem is that this would create too many files, especially if this business issuccessful. Another easy solution would consist of directly saving all orders of onecustomer in a particular file. This is suitable if the business deals with regularly returningcustomers, which is not always the case. Overall, you should provide as much flexibilityas possible. To make our application useful, we will allow the user to save an order to a

    file that whose name is after the day this order was placed. We will prompt the user so heor she can change the name of the file if necessary. When saving an order, if there is no

    order with that name, we will create a new XML file and store the order in it. If a filealready exists under that name, then we will add the current order as part of the file. Thatway, all orders of a certain date can be saved in the same file, making it possible toretrieve the list of repairs that were completed on a certain day.]

    Practical Learning: Saving a Work Order

    1. Display the New Workorder form (NewWorkorder.cs [Design]))

    2. Double-click the Save this Order button

    3. In the top section of the file, under the other using lines, type the following:

    using System;using System.Drawing;using System.Collections;

    using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.IO;using System.Xml;

    4. Implement the event as follows:

  • 8/14/2019 XML Software

    15/21

    private void btnSaveOrder_Click(object sender, System.EventArgs e){

    // Get the date that the Order Date displaysDateTime tmeToday = this.dtpOrderDate.Value;int day = tmeToday.Day;int month = tmeToday.Month;

    int year = tmeToday.Year;string[] strMonth = { "Jan", "Feb", "Mar", "Apr",

    "May", "Jun", "Jul", "Aug","Sep", "Oct", "Nov", "Dec" };

    string strFilename = day.ToString() +strMonth[month-1] +

    year.ToString() + ".xml";

    // Get a reference to the Data Center because// that's where the DataSet object residesInfoCenter frmData = new InfoCenter();

    // If the file exists already, open it

    if( File.Exists(strFilename) )frmData.dsWorkorders.ReadXml(strFilename);

    // Create a new record for the Workorder tableDataRow rowNewOrder =

    frmData.dsWorkorders.Tables["Workorder"].NewRow();

    rowNewOrder["CustomerName"] =this.txtCustomerName.Text;

    rowNewOrder["Addres"] = this.txtAddress.Text;rowNewOrder["City"] = this.txtCity.Text;rowNewOrder["State"] = this.txtState.Text;rowNewOrder["ZIPCode"] = this.txtZIPCode.Text;

    rowNewOrder["Make"] = this.txtMake.Text;rowNewOrder["Model"] = this.txtModel.Text;rowNewOrder["CarYear"] = this.txtCarYear.Text;rowNewOrder["Problem"] = this.txtProblem.Text;

    rowNewOrder["PartName1"] = this.txtPartName1.Text;rowNewOrder["UnitPrice1"] = this.txtUnitPrice1.Text;rowNewOrder["Quantity1"] = this.txtQuantity1.Text;rowNewOrder["SubTotal1"] = this.txtSubTotal1.Text;

    rowNewOrder["PartName2"] = this.txtPartName2.Text;rowNewOrder["UnitPrice2"] = this.txtUnitPrice2.Text;rowNewOrder["Quantity2"] = this.txtQuantity2.Text;

    rowNewOrder["SubTotal2"] = this.txtSubTotal2.Text;

    rowNewOrder["PartName3"] = this.txtPartName3.Text;rowNewOrder["UnitPrice3"] = this.txtUnitPrice3.Text;rowNewOrder["Quantity3"] = this.txtQuantity3.Text;rowNewOrder["SubTotal3"] = this.txtSubTotal3.Text;

    rowNewOrder["PartName4"] = this.txtPartName4.Text;rowNewOrder["UnitPrice4"] = this.txtUnitPrice4.Text;rowNewOrder["Quantity4"] = this.txtQuantity4.Text;rowNewOrder["SubTotal4"] = this.txtSubTotal4.Text;

    rowNewOrder["PartName5"] = this.txtPartName5.Text;

    rowNewOrder["UnitPrice5"] = this.txtUnitPrice5.Text;rowNewOrder["Quantity5"] = this.txtQuantity5.Text;rowNewOrder["SubTotal5"] = this.txtSubTotal5.Text;

    rowNewOrder["JobPerformed1"] =this.txtJobPerformed1.Text;

  • 8/14/2019 XML Software

    16/21

    rowNewOrder["JobPrice1"] = this.txtJobPrice1.Text;rowNewOrder["JobPerformed2"] =

    this.txtJobPerformed2.Text;rowNewOrder["JobPrice2"] = this.txtJobPrice2.Text;rowNewOrder["JobPerformed3"] =

    this.txtJobPerformed3.Text;rowNewOrder["JobPrice3"] = this.txtJobPrice3.Text;rowNewOrder["JobPerformed4"] =

    this.txtJobPerformed4.Text;rowNewOrder["JobPrice4"] = this.txtJobPrice4.Text;rowNewOrder["JobPerformed5"] =

    this.txtJobPerformed5.Text;rowNewOrder["JobPrice5"] = this.txtJobPrice5.Text;

    rowNewOrder["Recommendation"] =this.txtRecommendations.Text;

    rowNewOrder["TotalPart"] = this.txtTotalParts.Text;rowNewOrder["TotalLabor"] = this.txtTotalLabor.Text;rowNewOrder["TaxRate"] = this.txtTaxRate.Text;rowNewOrder["TaxAmount"] = this.txtTaxAmount.Text;rowNewOrder["TotalOrder"] = this.txtTotalOrder.Text;

    // Add the new record to the AvailableItems table

    frmData.dsWorkorders.Tables["Workorder"].Rows.Add(rowNewOrder);

    // Update the XML filefrmData.dsWorkorders.WriteXml(strFilename);

    // Reset the controls in case the user wants to add

    another recordthis.btnResetOrder_Click(sender, e);

    }}

    5. Execute the application to test it

    6. Create a new record then click Calculate Order and save the order

    7. Create another order, calculate it and save it

    8. Close the form and return to your programming environment

    Opening Customers' Orders

    It is typical for a business to sell many products on the same way, just as is usualfor a repair business to perform various transactions on the same day. Whenaddressing the ability to save work orders, we allowed the user to save many ordersof a typical day in the same file. In the same way, we will allow the user to open afile that contains all orders placed on a certain day. This would allow themanagement to review daily easily.

    Practical Learning: Opening and Reviewing Daily Orders

    1. Display the Workorders form

    2. In the Data section of the Toolbox, click DataSet and click the form

    3. In the Add Dataset dialog box, click the Untyped Dataset radio button and click OK

  • 8/14/2019 XML Software

    17/21

    4. Change its properties as follows:

    (Name): dsDailyOrdersDataSetName: DailyOrders

    5. Right-click the form and click View Code

    6. In the top section of the file, type the following:

    using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.IO;using System.Xml;

    7. Return to the form and double-click the Display Orders button

    8. Implement the event as follows:

    private void btnOpen_Click(object sender, System.EventArgs e){

    // Get the date that the Order Date displaysDateTime tmeToday = this.dtpOrderDate.Value;int day = tmeToday.Day;int month = tmeToday.Month;int year = tmeToday.Year;string[] strMonth = { "Jan", "Feb", "Mar", "Apr",

    "May", "Jun", "Jul", "Aug","Sep", "Oct", "Nov", "Dec" };string strFilename = day.ToString() +

    strMonth[month-1] +year.ToString() +

    ".xml";// If the file exists already, open itif( File.Exists(strFilename) ){// Get a reference to the object that holds the daily repairs

    InfoCenter frmInfo = new InfoCenter();// Empty the local data set of any data. This is required if// we want the user to be able to open different daily sets of

    repairsthis.dsDailyOrders.Clear();

    // Refresh or initialize the local set with the information

    // stored centrallythis.dsDailyOrders = frmInfo.dsWorkorders;

    // Open the set of orders placed on the day selecteddsDailyOrders.ReadXml(strFilename);

    // Because a control can be bound anew every time the user opens anew set

    // Unbind each control to refresh ittxtCustomerName.DataBindings.Clear();txtAddress.DataBindings.Clear();txtCity.DataBindings.Clear();txtState.DataBindings.Clear();

    txtZIPCode.DataBindings.Clear();txtMake.DataBindings.Clear();txtModel.DataBindings.Clear();txtCarYear.DataBindings.Clear();txtProblem.DataBindings.Clear();

  • 8/14/2019 XML Software

    18/21

    txtPartName1.DataBindings.Clear();txtUnitPrice1.DataBindings.Clear();txtQuantity1.DataBindings.Clear();txtSubTotal1.DataBindings.Clear();txtPartName2.DataBindings.Clear();txtUnitPrice2.DataBindings.Clear();

    txtQuantity2.DataBindings.Clear();txtSubTotal2.DataBindings.Clear();txtPartName3.DataBindings.Clear();txtUnitPrice3.DataBindings.Clear();txtQuantity3.DataBindings.Clear();txtSubTotal3.DataBindings.Clear();txtPartName4.DataBindings.Clear();txtUnitPrice4.DataBindings.Clear();txtQuantity4.DataBindings.Clear();txtSubTotal4.DataBindings.Clear();txtPartName5.DataBindings.Clear();txtUnitPrice5.DataBindings.Clear();txtQuantity5.DataBindings.Clear();

    txtSubTotal5.DataBindings.Clear();txtJobPerformed1.DataBindings.Clear();txtJobPrice1.DataBindings.Clear();txtJobPerformed2.DataBindings.Clear();txtJobPrice2.DataBindings.Clear();txtJobPerformed3.DataBindings.Clear();txtJobPrice3.DataBindings.Clear();txtJobPerformed4.DataBindings.Clear();txtJobPrice4.DataBindings.Clear();txtJobPerformed5.DataBindings.Clear();txtJobPrice5.DataBindings.Clear();txtRecommendations.DataBindings.Clear();txtTotalParts.DataBindings.Clear();

    txtTotalLabor.DataBindings.Clear();txtTaxRate.DataBindings.Clear();txtTaxAmount.DataBindings.Clear();txtTotalOrder.DataBindings.Clear();

    // Bind each control with data gotten from the newly opened filetxtCustomerName.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.CustomerName")); txtAddress.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.Addres"));txtCity.DataBindings.Add(new System.Windows.Forms.Binding("Text",dsDailyOrders, "Workorder.City"));

    txtState.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.State"));

    txtZIPCode.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.ZIPCode"));

    txtMake.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.Make"));

    txtModel.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.Model"));

    txtCarYear.DataBindings.Add(new

    System.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.CarYear"));txtProblem.DataBindings.Add(new

    System.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.Problem"));

    txtPartName1.DataBindings.Add(new

  • 8/14/2019 XML Software

    19/21

    System.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.PartName1"));

    txtUnitPrice1.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.UnitPrice1"));

    txtQuantity1.DataBindings.Add(new

    System.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.Quantity1"));

    txtSubTotal1.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.SubTotal1"));

    txtPartName2.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.PartName2"));

    txtUnitPrice2.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.UnitPrice2"));

    txtQuantity2.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,

    "Workorder.Quantity2"));txtSubTotal2.DataBindings.Add(new

    System.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.SubTotal2"));

    txtPartName3.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.PartName3"));

    txtUnitPrice3.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.UnitPrice3"));

    txtQuantity3.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.Quantity3"));

    txtSubTotal3.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.SubTotal3"));

    txtPartName4.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.PartName4"));

    txtUnitPrice4.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.UnitPrice4"));

    txtQuantity4.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.Quantity4"));

    txtSubTotal4.DataBindings.Add(new

    System.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.SubTotal4"));txtPartName5.DataBindings.Add(new

    System.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.PartName5"));

    txtUnitPrice5.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.UnitPrice5"));

    txtQuantity5.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.Quantity5"));

    txtSubTotal5.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,

    "Workorder.SubTotal5"));txtJobPerformed1.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.JobPerformed1"));

    txtJobPrice1.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,

  • 8/14/2019 XML Software

    20/21

    "Workorder.JobPrice1"));txtJobPerformed2.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.JobPerformed2"));

    txtJobPrice2.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,

    "Workorder.JobPrice2"));txtJobPerformed3.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.JobPerformed3"));

    txtJobPrice3.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.JobPrice3"));txtJobPerformed4.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.JobPerformed4"));

    txtJobPrice4.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.JobPrice4"));

    txtJobPerformed5.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.JobPerformed5"));

    txtJobPrice5.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.JobPrice5"));txtRecommendations.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.Recommendation"));

    txtTotalParts.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.TotalPart"));

    txtTotalLabor.DataBindings.Add(new

    System.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.TotalLabor"));txtTaxRate.DataBindings.Add(new

    System.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.TaxRate"));

    txtTaxAmount.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.TaxAmount"));

    txtTotalOrder.DataBindings.Add(newSystem.Windows.Forms.Binding("Text", dsDailyOrders,"Workorder.TotalOrder"));

    }else // If there is no data, let the user know

    MessageBox.Show(String.Concat("No workorderavailable for ", this.dtpOrderDate.Value.ToString()));}}

    9. Return to the Workorders form. Double-click the First button and implement

    its Click event as follows:

    private void btnFirst_Click(object sender, System.EventArgs e){

    this.BindingContext[dsDailyOrders, "Workorder"].Position = 0;}

    10.Return to the Workorders form. Double-click the Previous button and implement

    its Click event as follows:

  • 8/14/2019 XML Software

    21/21

    private void btnPrevious_Click(object sender, System.EventArgs e){

    this.BindingContext[dsDailyOrders, "Workorder"].Position =this.BindingContext[dsDailyOrders,

    "Workorder"].Position - 1;}

    11.Return to the Workorders form. Double-click the Next button and implement

    its Click event as follows:

    private void btnNext_Click(object sender, System.EventArgs e){

    this.BindingContext[dsDailyOrders, "Workorder"].Position =this.BindingContext[dsDailyOrders,

    "Workorder"].Position + 1;}

    12.Return to the Workorders form. Double-click the Last button and implement

    its Click event as follows:

    private void btnLast_Click(object sender, System.EventArgs e){

    this.BindingContext[dsDailyOrders, "Workorder"].Position =this.BindingContext[dsDailyOrders,

    "Workorder"].Count - 1;}

    13.Display the Workorders form and try opening a previously saved order

    14.Close the forms