Home

MS Visual C++ .NET Applications: Georgetown Cleaning Services

 

Introduction to Serialization

 

Cleaning Order Processing

To process an order, we will use the same approach as for the Georgetown Cleaning Services application to calculation the cost of a cleaning order

When an order has been processed, we will let the user save it. To make this useful and convenient, we will save cleaning orders for each day in a common file but we will give the user the opportunity to save the order for another day. To implement this behavior, we will use the serialization of an ArrayList object which itself will use a whole cleaning order stored in a variable.

Practical Learning Practical Learning: Creating a Serializable Class

  1. To add a new project, on the main menu, click File -> Add Project -> New Project...
  2. In the Project Types list of the Add New Project dialog box, make sure Visual C++ Projects is selected
    In the Templates list, click Class Library (.NET)
  3. Set the Name to GCSOrder
  4. Click OK
  5. In the Solution Explorer, double-click GCSOrder.h
  6. Change the file as follows:
     
    // GCSOrder.h
    
    #pragma once
    
    using namespace System;
    
    namespace GCSOrder
    {
    	[Serializable]
    	public __gc class CleaningOrder
    	{
    	private:
    		String  *_orderNbr;
    		String  *_custName;
    		String  *_custPhone;
    		DateTime _dteLeft;
    		DateTime _tmeLeft;
    		DateTime _dtePicked;
    		DateTime _tmePicked;
    		double   _shtPrice;
    		int      _shtQty;
    		double   _shtTotal;
    		double   _pntPrice;
    		int      _pntQty;
    		double   _pntTotal;
    		String  *_item1Name;
    		double   _item1Price;
    		int      _item1Qty;
    		double   _item1Total;
    		String  *_item2Name;
    		double   _item2Price;
    		int      _item2Qty;
    		double   _item2Total;
    		String  *_item3Name;
    		double   _item3Price;
    		int      _item3Qty;
    		double   _item3Total;
    		String  *_item4Name;
    		double   _item4Price;
    		int      _item4Qty;
    		double   _item4Total;
    		double   _cleanTotal;
    		double   _taxRate;
    		double   _taxAmt;
    		double   _orderTotal;
    
    	public:
    		CleaningOrder()
    		{
    			_orderNbr   = S"010119000";
    			_custName   = S"Unknown";
    			_custPhone  = S"N/A";
    			_dteLeft    = DateTime::Today;
    			_tmeLeft    = DateTime::Now;
    			_dtePicked  = DateTime::Today;;
    			_tmePicked  = DateTime::Now;
    			_shtPrice   = 0.95;
    			_shtQty     = 0;
    			_shtTotal   = 0.00;
    			_pntPrice   = 1.75;
    			_pntQty     = 0;
    			_pntTotal   = 0.00;
    			_item1Price = 0;
    			_item1Qty   = 0;
    			_item1Total = 0.00;
    			_item2Price = 0.00;
    			_item2Qty   = 0;
    			_item2Total = 0.00;
    			_item3Price = 0.00;
    			_item3Qty   = 0;
    			_item3Total = 0.00;
    			_item4Price = 0.00;
    			_item4Qty   = 0;
    			_item4Total = 0.00;
    			_cleanTotal = 0.00;
    			_taxRate    = 5.75;
    			_taxAmt     = 0.00;
    			_orderTotal = 0.00;
    		}
    
    	public:
    		__property String *get_CleaningNumber()
    		{
    			return _orderNbr;
    		}
    		__property void set_CleaningNumber(String *nbr)
    		{
    			_orderNbr = nbr;
    		}
    
    		__property String *get_CustomerName()
    		{
    			return _custName;
    		}
    		__property void set_CustomerName(String *strCustName)
    		{
    			_custName = strCustName;
    		}
    
    		__property String *get_CustomerPhone()
    		{
    			return _custPhone;
    		}
    		__property void set_CustomerPhone(String *strCustPhone)
    		{
    			_custPhone = strCustPhone;
    		}
    
    		__property DateTime get_DateLeft()
    		{
    			return _dteLeft;
    		}
    
    		__property void set_DateLeft(DateTime dteLeft)
    		{
    			_dteLeft = dteLeft;
    		}
    
    		__property DateTime get_TimeLeft()
    		{
    			return _tmeLeft;
    		}
    
    		__property void set_TimeLeft(DateTime tmeLeft)
    		{
    			_tmeLeft = tmeLeft;
    		}
    
    		__property DateTime get_DatePickedUp()
    		{
    			return _dtePicked;
    		}
    
    		__property void set_DatePickedUp(DateTime dtePicked)
    		{
    			_dtePicked = dtePicked;
    		}
    
    		__property DateTime get_TimePickedUp()
    		{
    			return _tmePicked;
    		}
    
    		__property void set_TimePickedUp(DateTime tmePicked)
    		{
    			_tmePicked = tmePicked;
    		}
    		
    		__property double get_ShirtUnitPrice()
    		{
    			return _shtPrice;
    		}
    		
    		__property void set_ShirtUnitPrice(double price)
    		{
    			_shtPrice = price;
    		}
    
    		__property int get_ShirtQuantity()
    		{
    			return _shtQty;
    		}
    		__property void set_ShirtQuantity(int qty)
    		{
    			_shtQty = qty;
    		}
    
    		__property double get_ShirtSubTotal()
    		{
    			return _shtTotal;
    		}
    		__property void set_ShirtSubTotal(double subTotal)
    		{
    			_shtTotal = subTotal;
    		}
    		
    		__property double get_PantsUnitPrice()
    		{
    			return _pntPrice;
    		}
    		
    		__property void set_PantsUnitPrice(double price)
    		{
    			_pntPrice = price;
    		}
    
    		__property int get_PantsQuantity()
    		{
    			return _pntQty;
    		}
    		__property void set_PantsQuantity(int qty)
    		{
    			_pntQty = qty;
    		}
    
    		__property double get_PantsSubTotal()
    		{
    			return _pntTotal;
    		}
    		__property void set_PantsSubTotal(double subTotal)
    		{
    			_pntTotal = subTotal;
    		}
    
    		__property String* get_Item1Name()
    		{
    			return _item1Name;
    		}
    		
    		__property void set_Item1Name(String *name)
    		{
    			_item1Name = name;
    		}
    		
    		__property double get_Item1UnitPrice()
    		{
    			return _item1Price;
    		}
    		
    		__property void set_Item1UnitPrice(double price)
    		{
    			_item1Price = price;
    		}
    
    		__property int get_Item1Quantity()
    		{
    			return _item1Qty;
    		}
    		__property void set_Item1Quantity(int qty)
    		{
    			_item1Qty = qty;
    		}
    
    		__property double get_Item1SubTotal()
    		{
    			return _item1Total;
    		}
    		__property void set_Item1SubTotal(double subTotal)
    		{
    			_item1Total = subTotal;
    		}
    
    		__property String* get_Item2Name()
    		{
    			return _item2Name;
    		}
    		
    		__property void set_Item2Name(String *name)
    		{
    			_item2Name = name;
    		}
    		
    		__property double get_Item2UnitPrice()
    		{
    			return _item2Price;
    		}
    		
    		__property void set_Item2UnitPrice(double price)
    		{
    			_item2Price = price;
    		}
    
    		__property int get_Item2Quantity()
    		{
    			return _item2Qty;
    		}
    		__property void set_Item2Quantity(int qty)
    		{
    			_item2Qty = qty;
    		}
    
    		__property double get_Item2SubTotal()
    		{
    			return _item2Total;
    		}
    		__property void set_Item2SubTotal(double subTotal)
    		{
    			_item2Total = subTotal;
    		}
    
    		__property String* get_Item3Name()
    		{
    			return _item3Name;
    		}
    		
    		__property void set_Item3Name(String *name)
    		{
    			_item3Name = name;
    		}
    		
    		__property double get_Item3UnitPrice()
    		{
    			return _item3Price;
    		}
    		
    		__property void set_Item3UnitPrice(double price)
    		{
    			_item3Price = price;
    		}
    
    		__property int get_Item3Quantity()
    		{
    			return _item3Qty;
    		}
    		__property void set_Item3Quantity(int qty)
    		{
    			_item3Qty = qty;
    		}
    
    		__property double get_Item3SubTotal()
    		{
    			return _item3Total;
    		}
    		__property void set_Item3SubTotal(double subTotal)
    		{
    			_item3Total = subTotal;
    		}
    
    		__property String* get_Item4Name()
    		{
    			return _item4Name;
    		}
    		__property void set_Item4Name(String *name)
    		{
    			_item4Name = name;
    		}
    		
    		__property double get_Item4UnitPrice()
    		{
    			return _item4Price;
    		}
    		
    		__property void set_Item4UnitPrice(double price)
    		{
    			_item4Price = price;
    		}
    
    		__property int get_Item4Quantity()
    		{
    			return _item4Qty;
    		}
    		__property void set_Item4Quantity(int qty)
    		{
    			_item4Qty = qty;
    		}
    
    		__property double get_Item4SubTotal()
    		{
    			return _item4Total;
    		}
    		__property void set_Item4SubTotal(double subTotal)
    		{
    			_item4Total = subTotal;
    		}
    
    		__property double get_CleaningTotal()
    		{
    			return _cleanTotal;
    		}
    		__property void set_CleaningTotal(double total)
    		{
    			_cleanTotal = total;
    		}
    
    		__property double get_TaxRate()
    		{
    			return _taxRate;
    		}
    		__property void set_TaxRate(double tax)
    		{
    			_taxRate = tax;
    		}
    		
    		__property double get_TaxAmount()
    		{
    			return _taxAmt;
    		}
    		__property void set_TaxAmount(double amt)
    		{
    			_taxAmt = amt;
    		}
    		__property double get_OrderTotal()
    		{
    			return _orderTotal;
    		}
    		__property void set_OrderTotal(double total)
    		{
    			_orderTotal = total;
    		}
    	};
    }
  7. To create the library, in the Solution Explorer, right-click the GCSOrder node and click Build
  8. To get a reference of this library to the project, in Solution Explorer, under GCS3, right-click References and click Add Reference...
    In the Project property page, make sure the GCSOrder project is selected
  9. Click Select and click OK
  10. Display the New Cleaning Order form and double-click an unoccupied area of its body
  11. Implement the Load event as follows:
     
    #pragma once
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    
    
    namespace GCS3
    {
    	. . . No Change
    			
    	
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container* components;
    		ArrayList *CleaningItems;
    
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			. . . No Change
    			
    
    		}		
    	private: System::Void btnClose_Click(System::Object *  sender, System::EventArgs *  e)
    			 {
    				 Close();
    			 }
    
    private: System::Void NewCleaningOrder_Load(System::Object *  sender, System::EventArgs *  e)
    		 {
    			 CleaningItems = new ArrayList;
    		 }
    
    };
    }
  12. Return to the New Cleaning Order form and double the Save button
  13. In the top section of the file, type the following:
     
    #pragma once
    
    #using <System.Runtime.Serialization.Formatters.Soap.dll>
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::IO;
    using namespace System::Runtime::Serialization::Formatters::Soap;
  14. Implement the event as follows:
     
    private: System::Void btnSave_Click(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( this->txtCustomerName->Text->Equals(S"") )
    	 {
    		 MessageBox::Show(S"A cleaning order must have a name for the customer");
    		 this->txtCustomerName->Focus();
    		 return;
    	 }
    
    	 // Just in case the user forgot to calculate the order, do it now
    	 this->btnCalculate_Click(sender, e);
    
    	 // Create the name of the file to save the current cleaning order
    	 DateTime dteProcessed = this->dtpDateProcessed->Value;
    	 int day   = dteProcessed.Day;
    	 int month = dteProcessed.Month;
    	 int year  = dteProcessed.Year;
    
    	 String *strDay = day.ToString();
    	 if( day < 10 )
    		 strDay = String::Concat(S"0", day.ToString());
    
    	 String *strMonth = month.ToString();
    	 if( month < 10 )
    		 strMonth = String::Concat(S"0", month.ToString());
    
    	 String *strFilename = String::Concat(strDay, strMonth, year.ToString(), S".gcs");
    			 
    	 GCSOrder::CleaningOrder *order = new GCSOrder::CleaningOrder();
    	 order->CustomerName = this->txtCustomerName->Text;
    	 order->CustomerPhone = this->txtCustomerPhone->Text;
    	 order->DateLeft = this->dtpDateLeft->Value;
    	 order->TimeLeft = this->dtpTimeLeft->Value;
    	 order->DatePickedUp = this->dtpDateExpected->Value;
    	 order->TimePickedUp = this->dtpTimeExpected->Value;
    	 order->ShirtUnitPrice = this->txtShirtsUnitPrice->Text->ToDouble(0);
    	 order->ShirtQuantity  = this->txtShirtsQuantity->Text->ToInt32(0);
    	 order->ShirtSubTotal  = this->txtShirtsSubTotal->Text->ToDouble(0);
    	 order->PantsUnitPrice = this->txtPantsUnitPrice->Text->ToDouble(0);
    	 order->PantsQuantity  = this->txtPantsQuantity->Text->ToInt32(0);
    	 order->PantsSubTotal  = this->txtPantsSubTotal->Text->ToDouble(0);
    	 order->Item1Name      = this->cboItem1->Text;
    	 order->Item1UnitPrice = this->txtItem1UnitPrice->Text->ToDouble(0);
    	 order->Item1Quantity  = this->txtItem1Quantity->Text->ToInt32(0);
    	 order->Item1SubTotal  = this->txtItem1SubTotal->Text->ToDouble(0);
    	 order->Item2Name      = this->cboItem2->Text;
    	 order->Item2UnitPrice = this->txtItem2UnitPrice->Text->ToDouble(0);
    	 order->Item2Quantity  = this->txtItem2Quantity->Text->ToInt32(0);
    	 order->Item2SubTotal  = this->txtItem2SubTotal->Text->ToDouble(0);
    	 order->Item3Name      = this->cboItem3->Text;
    	 order->Item3UnitPrice = this->txtItem3UnitPrice->Text->ToDouble(0);
    	 order->Item3Quantity  = this->txtItem3Quantity->Text->ToInt32(0);
    	 order->Item3SubTotal  = this->txtItem3SubTotal->Text->ToDouble(0);
    	 order->Item4Name      = this->cboItem4->Text;
    	 order->Item4UnitPrice = this->txtItem4UnitPrice->Text->ToDouble(0);
    	 order->Item4Quantity  = this->txtItem4Quantity->Text->ToInt32(0);
    	 order->Item4SubTotal  = this->txtItem4SubTotal->Text->ToDouble(0);
    	 order->CleaningTotal  = this->txtCleaningTotal->Text->ToDouble(0);
    	 order->TaxRate        = this->txtTaxRate->Text->ToDouble(0);
    	 order->TaxAmount      = this->txtTaxAmount->Text->ToDouble(0);
    	 order->OrderTotal     = this->txtOrderTotal->Text->ToDouble(0);
    	 this->CleaningItems->Add(order);
    
    FileStream *gcsStream = new FileStream(strFilename, FileMode::OpenOrCreate, FileAccess::Write, FileShare::Write);
    	 SoapFormatter *gcsSoap = new SoapFormatter();
    
    	 gcsSoap->Serialize(gcsStream, this->CleaningItems);
    	 gcsStream->Close();
    
    	 this->btnNewOrder_Click(sender, e);
    }
  15. Execute the application
  16. Process a few orders and save each
     
  17. Close the forms and return to your programming environment
  18. Display the Cleaning Orders form. Right-click the form and click View Code
  19. In the top section of the file, type the following:
     
    #pragma once
    
    #using <System.Runtime.Serialization.Formatters.Soap.dll>
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::IO;
    using namespace System::Runtime::Serialization::Formatters::Soap;
  20. In the class, declare a pointer to ArrayList and name it CleaningItems:
     
    private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container* components;
    		ArrayList *CleaningItems;
    		int CurrentPosition;
  21. Display the Cleaning Orders form and double- click an empty area of its body
  22. Implement the event as follows:
     
    private: System::Void CleaningOrders_Load(System::Object *  sender, System::EventArgs *  e)
    {
    	 CleaningItems = new ArrayList();
    	 CurrentPosition = 0;
    }
  23. Return to the Cleaning Orders form and double-click the top DateTimePicker control
  24. Implement its ValueChanged event as follows:
     
    private: System::Void dtpDateProcessed_ValueChanged(System::Object *  sender, System::EventArgs *  e)
    {
    	 DateTime dteSelected = this->dtpDateProcessed->Value;
    	 int day   = dteSelected.Day;
    	 int month = dteSelected.Month;
    	 int year  = dteSelected.Year;
    	 SoapFormatter *gcsSoap = new SoapFormatter();
    
    	 String *strDay = day.ToString();
    	 if( day < 10 )
    		 strDay = String::Concat(S"0", day.ToString());
    
    	 String *strMonth = month.ToString();
    	 if( month < 10 )
    		 strMonth = String::Concat(S"0", month.ToString());
    
    	 String *strFilename = String::Concat(strDay, strMonth, year.ToString(), S".gcs");
    			 
    	 if( File::Exists(strFilename) )
    	 {
    FileStream *gcsStream = new FileStream(strFilename, FileMode::Open, FileAccess::Read, FileShare::Read);
    		 CleaningItems = dynamic_cast<ArrayList *>(gcsSoap->Deserialize(gcsStream));
    
    		 gcsStream->Close();
    		 this->btnFirst_Click(sender, e);
    	 }
    }
  25. Return to the Cleaning Orders form. Double-click the First button and implement its Click event as follows:
     
    private: System::Void btnFirst_Click(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( this->CleaningItems->Count == 0 )
    		 return;
    			 
    	 CurrentPosition = 0;
    	 GCSOrder::CleaningOrder *order = new GCSOrder::CleaningOrder();
    
    	 order = dynamic_cast<GCSOrder::CleaningOrder *>(this->CleaningItems->Item[0]);
    	 this->txtCustomerName->Text = order->CustomerName;
    	 this->txtCustomerPhone->Text = order->CustomerPhone;
    	 this->dtpDateLeft->Value = order->DateLeft;
    	 this->dtpTimeLeft->Value = order->TimeLeft;
    	 this->dtpDatePickedUp->Value = order->DatePickedUp;
    	 this->dtpTimePickedUp->Value = order->TimePickedUp;
    	 this->txtShirtsUnitPrice->Text = order->ShirtUnitPrice.ToString(S"F");
    	 this->txtShirtsQuantity->Text  = order->ShirtQuantity.ToString(S"F");
    	 this->txtShirtsSubTotal->Text  = order->ShirtSubTotal.ToString(S"F");
    	 this->txtPantsUnitPrice->Text  = order->PantsUnitPrice.ToString(S"F");
    	 this->txtPantsQuantity->Text   = order->PantsQuantity.ToString(S"F");
    	 this->txtPantsSubTotal->Text   = order->PantsSubTotal.ToString(S"F");
    	 this->txtItem1Name->Text       = order->Item1Name;
    	 this->txtItem1UnitPrice->Text  = order->Item1UnitPrice.ToString(S"F");
    	 this->txtItem1Quantity->Text   = order->Item1Quantity.ToString(S"F");
    	 this->txtItem1SubTotal->Text   = order->Item1SubTotal.ToString(S"F");
    	 this->txtItem2Name->Text       = order->Item2Name;
    	 this->txtItem2UnitPrice->Text  = order->Item2UnitPrice.ToString(S"F");
    	 this->txtItem2Quantity->Text   = order->Item2Quantity.ToString(S"F");
    	 this->txtItem2SubTotal->Text   = order->Item2SubTotal.ToString(S"F");
    	 this->txtItem3Name->Text       = order->Item3Name;
    	 this->txtItem3UnitPrice->Text  = order->Item3UnitPrice.ToString(S"F");
    	 this->txtItem3Quantity->Text   = order->Item3Quantity.ToString(S"F");
    	 this->txtItem3SubTotal->Text   = order->Item3SubTotal.ToString(S"F");
    	 this->txtItem4Name->Text       = order->Item4Name;
    	 this->txtItem4UnitPrice->Text  = order->Item4UnitPrice.ToString(S"F");
    	 this->txtItem4Quantity->Text   = order->Item4Quantity.ToString(S"F");
    	 this->txtItem4SubTotal->Text   = order->Item4SubTotal.ToString(S"F");
    	 this->txtCleaningTotal->Text   = order->CleaningTotal.ToString(S"F");
    	 this->txtTaxRate->Text         = order->TaxRate.ToString(S"F");
    	 this->txtTaxAmount->Text       = order->TaxAmount.ToString(S"F");
    	 this->txtOrderTotal->Text      = order->OrderTotal.ToString(S"F");
    }
  26. Return to the Cleaning Orders form. Double-click the Previous button and implement its Click event as follows:
     
    private: System::Void btnPrevious_Click(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( this->CleaningItems->Count == 0 )
    		 return;
    			 
    	 if( CurrentPosition == 0 )
    		 return;
    	 else
    	 {
    		 CurrentPosition--;
    		 GCSOrder::CleaningOrder *order = new GCSOrder::CleaningOrder();
    
    	 order = dynamic_cast<GCSOrder::CleaningOrder *>(this->CleaningItems->Item[CurrentPosition]);
    	 this->txtCustomerName->Text = order->CustomerName;
    	 this->txtCustomerPhone->Text = order->CustomerPhone;
    	 this->dtpDateLeft->Value = order->DateLeft;
    	 this->dtpTimeLeft->Value = order->TimeLeft;
    	 this->dtpDatePickedUp->Value = order->DatePickedUp;
    	 this->dtpTimePickedUp->Value = order->TimePickedUp;
    	 this->txtShirtsUnitPrice->Text = order->ShirtUnitPrice.ToString(S"F");
    	 this->txtShirtsQuantity->Text  = order->ShirtQuantity.ToString(S"F");
    	 this->txtShirtsSubTotal->Text  = order->ShirtSubTotal.ToString(S"F");
    	 this->txtPantsUnitPrice->Text  = order->PantsUnitPrice.ToString(S"F");
    	 this->txtPantsQuantity->Text   = order->PantsQuantity.ToString(S"F");
    	 this->txtPantsSubTotal->Text   = order->PantsSubTotal.ToString(S"F");
    	 this->txtItem1Name->Text       = order->Item1Name;
    	 this->txtItem1UnitPrice->Text  = order->Item1UnitPrice.ToString(S"F");
    	 this->txtItem1Quantity->Text   = order->Item1Quantity.ToString(S"F");
    	 this->txtItem1SubTotal->Text   = order->Item1SubTotal.ToString(S"F");
    	 this->txtItem2Name->Text       = order->Item2Name;
    	 this->txtItem2UnitPrice->Text  = order->Item2UnitPrice.ToString(S"F");
    	 this->txtItem2Quantity->Text   = order->Item2Quantity.ToString(S"F");
    	 this->txtItem2SubTotal->Text   = order->Item2SubTotal.ToString(S"F");
    	 this->txtItem3Name->Text       = order->Item3Name;
    	 this->txtItem3UnitPrice->Text  = order->Item3UnitPrice.ToString(S"F");
    	 this->txtItem3Quantity->Text   = order->Item3Quantity.ToString(S"F");
    	 this->txtItem3SubTotal->Text   = order->Item3SubTotal.ToString(S"F");
    	 this->txtItem4Name->Text       = order->Item4Name;
    	 this->txtItem4UnitPrice->Text  = order->Item4UnitPrice.ToString(S"F");
    	 this->txtItem4Quantity->Text   = order->Item4Quantity.ToString(S"F");
    	 this->txtItem4SubTotal->Text   = order->Item4SubTotal.ToString(S"F");
    	 this->txtCleaningTotal->Text   = order->CleaningTotal.ToString(S"F");
    	 this->txtTaxRate->Text         = order->TaxRate.ToString(S"F");
    	 this->txtTaxAmount->Text       = order->TaxAmount.ToString(S"F");
    	 this->txtOrderTotal->Text      = order->OrderTotal.ToString(S"F");
    	 }
    }
  27. Return to the Cleaning Orders form. Double-click the Next button and implement its Click event as follows:
     
    private: System::Void btnNext_Click(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( this->CleaningItems->Count == 0 )
    		 return;
    			 
    	 if( CurrentPosition == (this->CleaningItems->Count) )
    		 return;
    	 else
    	 {
    		 CurrentPosition++;
    		 GCSOrder::CleaningOrder *order = new GCSOrder::CleaningOrder();
    
    	 order = dynamic_cast<GCSOrder::CleaningOrder *>(this->CleaningItems->Item[CurrentPosition]);
    	 this->txtCustomerName->Text = order->CustomerName;
    	 this->txtCustomerPhone->Text = order->CustomerPhone;
    	 this->dtpDateLeft->Value = order->DateLeft;
    	 this->dtpTimeLeft->Value = order->TimeLeft;
    	 this->dtpDatePickedUp->Value = order->DatePickedUp;
    	 this->dtpTimePickedUp->Value = order->TimePickedUp;
    	 this->txtShirtsUnitPrice->Text = order->ShirtUnitPrice.ToString(S"F");
    	 this->txtShirtsQuantity->Text  = order->ShirtQuantity.ToString(S"F");
    	 this->txtShirtsSubTotal->Text  = order->ShirtSubTotal.ToString(S"F");
    	 this->txtPantsUnitPrice->Text  = order->PantsUnitPrice.ToString(S"F");
    	 this->txtPantsQuantity->Text   = order->PantsQuantity.ToString(S"F");
    	 this->txtPantsSubTotal->Text   = order->PantsSubTotal.ToString(S"F");
    	 this->txtItem1Name->Text       = order->Item1Name;
    	 this->txtItem1UnitPrice->Text  = order->Item1UnitPrice.ToString(S"F");
    	 this->txtItem1Quantity->Text   = order->Item1Quantity.ToString(S"F");
    	 this->txtItem1SubTotal->Text   = order->Item1SubTotal.ToString(S"F");
    	 this->txtItem2Name->Text       = order->Item2Name;
    	 this->txtItem2UnitPrice->Text  = order->Item2UnitPrice.ToString(S"F");
    	 this->txtItem2Quantity->Text   = order->Item2Quantity.ToString(S"F");
    	 this->txtItem2SubTotal->Text   = order->Item2SubTotal.ToString(S"F");
    	 this->txtItem3Name->Text       = order->Item3Name;
    	 this->txtItem3UnitPrice->Text  = order->Item3UnitPrice.ToString(S"F");
    	 this->txtItem3Quantity->Text   = order->Item3Quantity.ToString(S"F");
    	 this->txtItem3SubTotal->Text   = order->Item3SubTotal.ToString(S"F");
    	 this->txtItem4Name->Text       = order->Item4Name;
    	 this->txtItem4UnitPrice->Text  = order->Item4UnitPrice.ToString(S"F");
    	 this->txtItem4Quantity->Text   = order->Item4Quantity.ToString(S"F");
    	 this->txtItem4SubTotal->Text   = order->Item4SubTotal.ToString(S"F");
    	 this->txtCleaningTotal->Text   = order->CleaningTotal.ToString(S"F");
    	 this->txtTaxRate->Text         = order->TaxRate.ToString(S"F");
    	 this->txtTaxAmount->Text       = order->TaxAmount.ToString(S"F");
    	 this->txtOrderTotal->Text      = order->OrderTotal.ToString(S"F");
    	 }
    }
  28. Return to the Cleaning Orders form. Double-click the Last button and implement its Click event as follows:
     
    private: System::Void btnLast_Click(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( this->CleaningItems->Count == 0 )
    		 return;
    			 
    	 CurrentPosition = CleaningItems->Count;
    	 GCSOrder::CleaningOrder *order = new GCSOrder::CleaningOrder();
    
    order = dynamic_cast<GCSOrder::CleaningOrder *>(this->CleaningItems->Item[CurrentPosition]);
    	 this->txtCustomerName->Text    = order->CustomerName;
    	 this->txtCustomerPhone->Text   = order->CustomerPhone;
    	 this->dtpDateLeft->Value       = order->DateLeft;
    	 this->dtpTimeLeft->Value       = order->TimeLeft;
    	 this->dtpDatePickedUp->Value   = order->DatePickedUp;
    	 this->dtpTimePickedUp->Value   = order->TimePickedUp;
    	 this->txtShirtsUnitPrice->Text = order->ShirtUnitPrice.ToString(S"F");
    	 this->txtShirtsQuantity->Text  = order->ShirtQuantity.ToString(S"F");
    	 this->txtShirtsSubTotal->Text  = order->ShirtSubTotal.ToString(S"F");
    	 this->txtPantsUnitPrice->Text  = order->PantsUnitPrice.ToString(S"F");
    	 this->txtPantsQuantity->Text   = order->PantsQuantity.ToString(S"F");
    	 this->txtPantsSubTotal->Text   = order->PantsSubTotal.ToString(S"F");
    	 this->txtItem1Name->Text       = order->Item1Name;
    	 this->txtItem1UnitPrice->Text  = order->Item1UnitPrice.ToString(S"F");
    	 this->txtItem1Quantity->Text   = order->Item1Quantity.ToString(S"F");
    	 this->txtItem1SubTotal->Text   = order->Item1SubTotal.ToString(S"F");
    	 this->txtItem2Name->Text       = order->Item2Name;
    	 this->txtItem2UnitPrice->Text  = order->Item2UnitPrice.ToString(S"F");
    	 this->txtItem2Quantity->Text   = order->Item2Quantity.ToString(S"F");
    	 this->txtItem2SubTotal->Text   = order->Item2SubTotal.ToString(S"F");
    	 this->txtItem3Name->Text       = order->Item3Name;
    	 this->txtItem3UnitPrice->Text  = order->Item3UnitPrice.ToString(S"F");
    	 this->txtItem3Quantity->Text   = order->Item3Quantity.ToString(S"F");
    	 this->txtItem3SubTotal->Text   = order->Item3SubTotal.ToString(S"F");
    	 this->txtItem4Name->Text       = order->Item4Name;
    	 this->txtItem4UnitPrice->Text  = order->Item4UnitPrice.ToString(S"F");
    	 this->txtItem4Quantity->Text   = order->Item4Quantity.ToString(S"F");
    	 this->txtItem4SubTotal->Text   = order->Item4SubTotal.ToString(S"F");
    	 this->txtCleaningTotal->Text   = order->CleaningTotal.ToString(S"F");
    	 this->txtTaxRate->Text         = order->TaxRate.ToString(S"F");
    	 this->txtTaxAmount->Text       = order->TaxAmount.ToString(S"F");
    	 this->txtOrderTotal->Text      = order->OrderTotal.ToString(S"F");
    }
  29. Execute the application and try opening previous created orders
 

Previous Copyright © 2004-2012, FunctionX