Home

Georgetown Cleaning Services

 

The Data View

In a database environment, a query is a list of values created from another list. For example, a query can be created from a table by isolating records that follow a criterion. The .NET Framework supports queries through the DataView class. With a DataView object, you can create a selected list of records and you can then perform all types of regular operations of a database object, including:

  • Sorting Records
  • Filtering Records
  • Creating a new record
  • Updating one or more existing records

To create a DataView object, you can first declare a pointer to DataView. If you are working in Microsoft Visual Studio, in the Data section of the Toolbox, you can click the DataView button and click a container such as a form. After creating a DataView object, to perform a desired operation on it, you can use the SQL.

 

Practical Learning Practical Learning: Creating the Application

  1. Start Microsoft Visual Studio .NET or Visual C++ .NET and create a Windows Forms Application named GCS3
  2. Design it as follows:
     
    Control Name Text Additional Properties
    GroupBox GroupBox   Order Identification  
    Label Label   Customer Name:  
    TextBox TextBox txtCustomerName    
    Label Label   Customer Phone:  
    TextBox TextBox txtCustomerPhone    
    Label Label   Date Left:  
    DateTimePicker DateTimePicker dtpDateLeft   Format: Custom
    Custom Format: dddd MMM dd, yyyy
    Label Label   Time Left:  
    DateTimePicker DateTimePicker dtpTimeLeft   Format: Time
    Label Label   Date Expected:  
    DateTimePicker DateTimePicker dtpDateExpected   Format: Custom
    Custom Format: dddd MMM dd, yyyy
    Label     Time Expected:  
    DateTimePicker DateTimePicker dtpTimeExpected   Format: Time
    GroupBox GroupBox   Order Processing  
    Label Label   Item Type  
    Label Label   Unit Price  
    Label Label   Qty  
    Label Label   Sub Total  
    Label Label   Shirts  
    TextBox TextBox txtShirtsUnitPrice 0.95 TextAlign: Right
    TextBox TextBox txtShirtsQuantity 0 TextAlign: Right
    Button Button btnCalcShirts   Image: SubTotal.ico
    TextBox TextBox txtShirtsSubTotal 0.00 TextAlign: Right
    Label Label   Pants  
    TextBox TextBox txtPantsUnitPrice 1.75 TextAlign: Right
    TextBox TextBox txtPantsQuantity   TextAlign: Right
    Button Button btnCalcPants   Image: SubTotal.ico
    TextBox TextBox txtPantsSubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cboItem1 None  
    TextBox TextBox txtItem1UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem1Quantity 0 TextAlign: Right
    Button Button btnCalcItem1   Image: SubTotal.ico
    TextBox TextBox txtItem1SubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cboItem2 None  
    TextBox TextBox txtItem2UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem2Quantity 0 TextAlign: Right
    Button Button btnCalcItem2   Image: SubTotal.ico
    TextBox TextBox txtItem2SubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cboItem3 None  
    TextBox TextBox txtItem3UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem3Quantity 0 TextAlign: Right
    Button Button btnCalcItem3   Image: SubTotal.ico
    TextBox TextBox txtItem3SubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cboItem4 None  
    TextBox TextBox txtItem4UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem4Quantity 0 TextAlign: Right
    Button Button btnCalcItem4   Image: SubTotal.ico
    TextBox TextBox txtItem4SubTotal 0.00 TextAlign: Right
    GroupBox GroupBox   Order Summary  
    Label Label   Cleaning Total:  
    TextBox TextBox txtOrderTotal 0.00 TextAlign: Right
    Label Label   Tax Rate:  
    TextBox TextBox txtTaxRate 5.75 TextAlign: Right
    Label Label   %  
    Label Label   Tax Amount:  
    TextBox TextBox txtTaxAmount 0.00 TextAlign: Right
    Label Label   Order Total:  
    TextBox TextBox txtOrderTotal 0.00 TextAlign: Right
    Button Button btnReset Reset  
    Button Button btnSave Save  
    Label Label   Enter Receipt Number:  
    TextBox TextBox txtReceiptNumber 0  
    Button Button btnOpen Open  
    Button Button btnClose Close  
  3. Click each combo box. Access its Items property and fill it up as follows:
     
  4. Click OK and save All
  5. On the Toolbox, click Data, click SqlDataAdapter and click an unoccupied area of the form
  6. In the first page of the Data Adapter Configuration Wizard, click Next
  7. In the second page of the wizard, click the arrow of the combo box. If you see a string that contains gcs, click it, and go to the next point.
    If you don't see gcs in the list, click New Connection...
    1. In the 1 combo box, select the server or type its name
    2. In the 2 section, click the Use Windows NT Integrated Security radio button
    3. In the 3 combo box, select the gcs database:
       
    4. Click OK
  8. Click Next
  9. Accept the Use New SQL Statement option and click Next
  10. Click Query Builder...
  11. In the Add Table dialog box, make sure CleaningOrders is selected. Click Add and click Close
  12. Click the *(All Columns) check box and click OK
  13. Click Next
     
  14. Click Finish
  15. On the main menu, click Data -> Generate Dataset...
  16. In the Generate Dataset dialog box, click the New radio button
  17. Set the name to dsCleaningOrders and click OK
  18. In the Data section of the Toolbox, click DataView and click the form
  19. In the Properties window, change its values as follows:
    (Name): dvwCleaningOrder
    Table: dsCleaningOrders1.CleaningOrders
  20. Right-click the form and click View Code
  21. Declare a private Boolean variable named IsNewOrder
     
    bool IsNewOrder;
  22. Return to the form, double-click an unoccupied area of the form to generate its Load event and implement it as follows:
     
    private: System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)
    {
    	 IsNewOrder = true;
    	 this->sqlDataAdapter1->Fill(this->dsCleaningOrders1);
    }
  23. Return to the form, double-click the Reset button and implement its Click event as follows:
     
    private: System::Void btnReset_Click(System::Object *  sender, System::EventArgs *  e)
    {
    	 IsNewOrder = true;
    
    	 this->txtCustomerName->Text = S"";
    	 this->txtCustomerPhone->Text = S"";
    	 this->dtpDateLeft->Value = DateTime::Today;
    	 this->dtpTimeLeft->Value = DateTime::Now;
    	 this->dtpDateExpected->Value = DateTime::Today;
    	 this->dtpTimeExpected->Value = DateTime::Now;
    
    	 this->txtShirtsUnitPrice->Text = S"0.95";
    	 this->txtShirtsQuantity->Text = S"0";
    	 this->txtShirtsSubTotal->Text = S"0.00";
    	 this->txtPantsUnitPrice->Text = S"1.95";
    	 this->txtPantsQuantity->Text  = S"0";
    	 this->txtPantsSubTotal->Text  = S"0.00";
    
    	 this->cboItem1->SelectedIndex = 0;
    	 this->txtItem1UnitPrice->Text = S"0.00";
    	 this->txtItem1Quantity->Text  = S"0";
    	 this->txtItem1SubTotal->Text  = S"0.00";
    
    	 this->cboItem2->SelectedIndex = 0;
    	 this->txtItem2UnitPrice->Text = S"0.00";
    	 this->txtItem2Quantity->Text  = S"0";
    	 this->txtItem2SubTotal->Text  = S"0.00";
    
    	 this->cboItem3->SelectedIndex = 0;
    	 this->txtItem3UnitPrice->Text = S"0.00";
    	 this->txtItem3Quantity->Text  = S"0";
    	 this->txtItem3SubTotal->Text  = S"0.00";
    
    	 this->cboItem4->SelectedIndex = 0;
    	 this->txtItem4UnitPrice->Text = S"0.00";
    	 this->txtItem4Quantity->Text  = S"0";
    	 this->txtItem4SubTotal->Text  = S"0.00";
    
    	 this->txtCleaningTotal->Text = S"0.00";
    	 this->txtTaxRate->Text = S"5.75";
    	 this->txtTaxAmount->Text = S"0.00";
    	 this->txtOrderTotal->Text = S"0.00";
             this->txtReceiptNumber->Text = S"0";
    	 this->txtCustomerName->Focus();
    }
  24. In the Class View, expand GCS3 followed by GCS3 and Form1
  25. Right-click Form1 -> Add -> Add Function...
  26. Set the characteristics as follows:
    Return Type: void
    Function Name: CalculateCleaningOrder
    Access: private
  27. Click Finish and implement the method as follows:
     
    void CalculateCleaningOrder(void)
    {
    	double unitPriceShirts = 0.95, unitPricePants = 1.75, unitPrice1 = 0.00,
    		   unitPrice2 = 0.00, unitPrice3 = 0.00, unitPrice4 = 0.00;
    	 int qtyShirts = 1, qtyPants = 1, quantity1 = 1,
    	     quantity2 = 1, quantity3 = 1, quantity4 = 1;
    	double subTotalShirts = 0, subTotalPants = 0, subTotal1 = 0,
    		   subTotal2 = 0, subTotal3 = 0, subTotal4;
    
    	double cleaningTotal = 0.00, taxRate = 5.75,
    		   taxAmount = 0.00, orderTotal = 0.00;
    
    	 // Retrieve the unit price of this item
    	 // Just in case the user types an invalid value, we are using a try...catch
    	 try {
    		 unitPriceShirts = this->txtShirtsUnitPrice->Text->ToDouble(0);
    	 }
    	 catch(FormatException *)
    	 {
    	MessageBox::Show(S"The value you entered for the price of shirts is not valid"
    			              S"\nPlease try again");
    	 }
    
    	 // Retrieve the number of this item
    	 // Just in case the user types an invalid value, we are using a try...catch
    	 try {
    		 qtyShirts  = this->txtShirtsQuantity->Text->ToInt16(0);
    	 }
    	 catch(FormatException *)
    	 {
    	 MessageBox::Show(S"The value you entered for the number of shirts is not valid"
    			              S"\nPlease try again");
    	 }
    
    	 // Calculate the sub-total for this item
    	 subTotalShirts  = unitPriceShirts * qtyShirts;
    
    	 // Display the sub-total in the corresponding text box
    	 this->txtShirtsSubTotal->Text = subTotalShirts.ToString(S"F");
    
    	try {
    		unitPricePants = this->txtPantsUnitPrice->Text->ToDouble(0);
    	}
    	catch(FormatException *)
    	{
    	MessageBox::Show(S"The value you entered for the price of pants is not valid"
    			             S"\nPlease try again");
    	}
    
    	try {
    		qtyPants  = this->txtPantsQuantity->Text->ToInt16(0);
    	}
    	catch(FormatException *)
    	{
    	MessageBox::Show(S"The value you entered for the number of pants is not valid"
    			             S"\nPlease try again");
    	}
    
    	subTotalPants  = unitPricePants * qtyPants;
    	this->txtPantsSubTotal->Text = subTotalPants.ToString("F");
    
    	try {
    		unitPrice1 = this->txtItem1UnitPrice->Text->ToDouble(0);
    	}
    	catch(FormatException *)
    	{
    		MessageBox::Show(S"The value you entered for the price is not valid"
    			             S"\nPlease try again");
    	}
    
    	try {
    		quantity1  = this->txtItem1Quantity->Text->ToInt16(0);
    	}
    	catch(FormatException *)
    	{
    		MessageBox::Show(S"The value you entered is not valid"
    			             S"\nPlease try again");
    	}
    
    	subTotal1  = unitPrice1 * quantity1;
    	this->txtItem1SubTotal->Text = subTotal1.ToString("F");
    
    	try {
    		unitPrice2 = this->txtItem2UnitPrice->Text->ToDouble(0);
    	}
    	catch(FormatException *)
    	{
    		MessageBox::Show(S"The value you entered for the price is not valid"
    			             S"\nPlease try again");
    	}
    
    	try {
    		quantity2  = this->txtItem2Quantity->Text->ToInt16(0);
    	}
    	catch(FormatException *)
    	{
    		MessageBox::Show(S"The value you entered is not valid"
    			             S"\nPlease try again");
    	}
    
    	subTotal2  = quantity2 * unitPrice2;
    	this->txtItem2SubTotal->Text = subTotal2.ToString("F");
    
    	try {
    		quantity3  = this->txtItem3Quantity->Text->ToInt16(0);
    	}
    	catch(FormatException *)
    	{
    		MessageBox::Show(S"The value you entered is not valid"
    			             S"\nPlease try again");
    	}
    
    	try {
    		unitPrice3 = this->txtItem3UnitPrice->Text->ToDouble(0);
    	}
    	catch(FormatException *)
    	{
    		MessageBox::Show(S"The value you entered for the price is not valid"
    			             S"\nPlease try again");
    	}
    
    	subTotal3  = quantity3 * unitPrice3;
    	this->txtItem3SubTotal->Text = subTotal3.ToString("F");
    
    	try {
    		unitPrice4 = this->txtItem4UnitPrice->Text->ToDouble(0);
    	}
    	catch(FormatException *)
    	{
    		MessageBox::Show(S"The value you entered for the price is not valid"
    			             S"\nPlease try again");
    	}
    	try {
    		quantity4  = this->txtItem4Quantity->Text->ToInt16(0);
    	}
    	catch(FormatException *)
    	{
    		MessageBox::Show(S"The value you entered is not valid"
    			             S"\nPlease try again");
    	}
    
    	subTotal4  = quantity4 * unitPrice4;
    	this->txtItem4SubTotal->Text = subTotal4.ToString("F");
    
    	// Calculate the total
    	cleaningTotal = subTotalShirts + subTotalPants + subTotal1 +
    		         subTotal2 + subTotal3 + subTotal4;
    
    	// Retrieve the value of the tax rate
    	try {
    		taxRate = this->txtTaxRate->Text->ToDouble(0);
    	}
    	catch(FormatException *)
    	{
    		MessageBox::Show(S"The tax rate you entered is invalid"
    			             S"\nPlease try again");
    	}
    
    	// Calculate the amount owed for the taxes
    	taxAmount = cleaningTotal * taxRate / 100;
    	// Add the tax amount to the total order
    	orderTotal  = cleaningTotal + taxAmount;
    			
    	// Display the values of the order summary
    	this->txtCleaningTotal->Text = cleaningTotal.ToString(S"F");
    	this->txtTaxAmount->Text  = taxAmount.ToString(S"F");
    	this->txtOrderTotal->Text   = orderTotal.ToString(S"F");
    }
  28. Return to the form and double-click the Save button
  29. In the top section of the file, under the other using namespace lines, type:

    using namespace System::Data::SqlClient;
  30. Implement its event as follows:
     
    private: System::Void btnSave_Click(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( IsNewOrder == true )
    	 {
    	 String *strInsert = String::Concat(S"INSERT INTO CleaningOrders(",
                                    S"CustomerName, CustomerPhone, DateLeft, ",
    				S"TimeLeft, DateExpected, TimeExpected, ",
    				S"ShirtsUnitPrice, ShirtsQuantity, ",
    				S"ShirtsSubTotal, PantsUnitPrice, ",
    				S"PantsQuantity, PantsSubTotal, Item1Name, ",
    				S"Item1UnitPrice, Item1Quantity, ",
    				S"Item1SubTotal, Item2Name, Item2UnitPrice, ",
    				S"Item2Quantity, Item2SubTotal, Item3Name, ",
                                    S"Item3UnitPrice, Item3Quantity, ",
    				S"Item3SubTotal, Item4Name, Item4UnitPrice, ",
    				S"Item4Quantity, Item4SubTotal, CleaningTotal, ",
    				S"TaxRate, TaxAmount, OrderTotal) VALUES(",
                                    S"'",    txtCustomerName->Text,
    				S"', '", txtCustomerPhone->Text,
    				S"', '", dtpDateLeft->Value,
    				S"', '", dtpTimeLeft->Value,
    				S"', '", dtpDateExpected->Value,
    				S"', '", dtpTimeExpected->Value,
    				S"', '", txtShirtsUnitPrice->Text->ToDouble(0),
    				S"', '", txtShirtsQuantity->Text,
    				S"', '", txtShirtsSubTotal->Text->ToDouble(0),
    				S"', '", txtPantsUnitPrice->Text->ToDouble(0),
    				S"', '", txtPantsQuantity->Text->ToInt16(0),
    				S"', '", txtPantsSubTotal->Text->ToDouble(0),
    				S"', '", cboItem1->Text,
    				S"', '", txtItem1UnitPrice->Text->ToDouble(0),
    				S"', '", txtItem1Quantity->Text->ToInt16(0),
    				S"', '", txtItem1SubTotal->Text->ToDouble(0),
    				S"', '", cboItem2->Text,
    				S"', '", txtItem2UnitPrice->Text->ToDouble(0),
    				S"', '", txtItem2Quantity->Text->ToInt16(0),
    				S"', '", txtItem2SubTotal->Text->ToDouble(0),
    				S"', '", cboItem3->Text,
    				S"', '", txtItem3UnitPrice->Text->ToDouble(0),
    				S"', '", txtItem3Quantity->Text->ToInt16(0),
    				S"', '", txtItem3SubTotal->Text->ToDouble(0),
    				S"', '", cboItem4->Text,
    				S"', '", txtItem4UnitPrice->Text->ToDouble(0),
    				S"', '", txtItem4Quantity->Text->ToInt16(0),
    				S"', '", txtItem4SubTotal->Text->ToDouble(0),
    				S"', '", txtCleaningTotal->Text->ToDouble(0),
    				S"', '", txtTaxRate->Text->ToDouble(0),
    				S"', '", txtTaxAmount->Text->ToDouble(0),
    				S"', '", txtOrderTotal->Text->ToDouble(0), S"');");
    
    	 SqlCommand    *cmdDatabase = new SqlCommand(strInsert, sqlConnection1);
    
    	 sqlConnection1->Open();
    
    	 cmdDatabase->ExecuteNonQuery();
    	 sqlConnection1->Close();
    
    	 this->btnReset_Click(sender, e);
    	}
    }
  31. Display the form and double-click the Open button
  32. Implement the event as follows:
     
    private: System::Void btnOpen_Click(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( this->txtReceiptNumber->Text->Equals(S"") )
    	 {
    		 MessageBox::Show(S"Please enter a receipt number");
    		 this->txtReceiptNumber->Focus();
    		 return;
    	 }
    
    	 int iReceiptNumber = this->txtReceiptNumber->Text->ToInt32(0);
    
    	 this->sqlDataAdapter1->Fill(this->dsCleaningOrders1);
    this->dvwCleaningOrder->RowFilter = String::Concat(S"CleaningOrderID = '", iReceiptNumber.ToString(), "'");
    
    	 this->txtCustomerName->DataBindings->Clear();
    	 this->txtCustomerPhone->DataBindings->Clear();
    	 this->dtpDateLeft->DataBindings->Clear();
    	 this->dtpTimeLeft->DataBindings->Clear();
    	 this->dtpDateExpected->DataBindings->Clear();
    	 this->dtpTimeExpected->DataBindings->Clear();
    	 this->txtShirtsUnitPrice->DataBindings->Clear();
    	 this->txtShirtsQuantity->DataBindings->Clear(); 
    this->txtShirtsSubTotal->DataBindings->Clear();
    this->txtPantsUnitPrice->DataBindings->Clear();
    this->txtPantsQuantity->DataBindings->Clear();
    this->txtPantsSubTotal->DataBindings->Clear(); 
    this->cboItem1->DataBindings->Clear(); 
    this->txtItem1UnitPrice->DataBindings->Clear(); 
     this->txtItem1Quantity->DataBindings->Clear(); 
     this->txtItem1SubTotal->DataBindings->Clear(); 
     this->cboItem2->DataBindings->Clear(); 
     this->txtItem2UnitPrice->DataBindings->Clear(); 
     this->txtItem2Quantity->DataBindings->Clear(); 
     this->txtItem2SubTotal->DataBindings->Clear(); 
     this->cboItem3->DataBindings->Clear(); 
     this->txtItem3UnitPrice->DataBindings->Clear(); 
     this->txtItem3Quantity->DataBindings->Clear(); 
     this->txtItem3SubTotal->DataBindings->Clear(); 
     this->cboItem4->DataBindings->Clear(); 
     this->txtItem4UnitPrice->DataBindings->Clear(); 
     this->txtItem4Quantity->DataBindings->Clear(); 
     this->txtItem4SubTotal->DataBindings->Clear(); 
     this->txtCleaningTotal->DataBindings->Clear(); 
     this->txtTaxRate->DataBindings->Clear(); 
     this->txtTaxAmount->DataBindings->Clear(); 
     this->txtOrderTotal->DataBindings->Clear();
    
    	 this->txtCustomerName->DataBindings->Add(S"Text", this->dvwCleaningOrder, "CustomerName");
    	 this->txtCustomerPhone->DataBindings->Add(S"Text", this->dvwCleaningOrder, "CustomerPhone");
    	 this->dtpDateLeft->DataBindings->Add("Value", this->dvwCleaningOrder, "DateLeft");
    	 this->dtpTimeLeft->DataBindings->Add("Value", this->dvwCleaningOrder, "TimeLeft");
    	 this->dtpDateExpected->DataBindings->Add("Value", this->dvwCleaningOrder, "DateExpected");
    	 this->dtpTimeExpected->DataBindings->Add("Value", this->dvwCleaningOrder, "TimeExpected");
    	 this->txtShirtsUnitPrice->DataBindings->Add(S"Text", this->dvwCleaningOrder, "ShirtsUnitPrice");
    	 this->txtShirtsQuantity->DataBindings->Add(S"Text", this->dvwCleaningOrder, "ShirtsQuantity");
    	 this->txtShirtsSubTotal->DataBindings->Add(S"Text", this->dvwCleaningOrder, "ShirtsSubTotal");
    	 this->txtPantsUnitPrice->DataBindings->Add(S"Text", this->dvwCleaningOrder, "PantsUnitPrice");
    	 this->txtPantsQuantity->DataBindings->Add(S"Text", this->dvwCleaningOrder, "PantsQuantity");
    	 this->txtPantsSubTotal->DataBindings->Add(S"Text", this->dvwCleaningOrder, "PantsSubTotal");
    	 this->cboItem1->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item1Name");
    	 this->txtItem1UnitPrice->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item1UnitPrice");
    	 this->txtItem1Quantity->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item1Quantity");
    	 this->txtItem1SubTotal->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item1SubTotal");
    	 this->cboItem2->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item2Name");
    	 this->txtItem2UnitPrice->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item2UnitPrice");
    	 this->txtItem2Quantity->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item2Quantity");
    	 this->txtItem2SubTotal->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item2SubTotal");
    	 this->cboItem3->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item3Name");
    	 this->txtItem3UnitPrice->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item3UnitPrice");
    	 this->txtItem3Quantity->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item3Quantity");
    	 this->txtItem3SubTotal->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item3SubTotal");
    	 this->cboItem4->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item4Name");
    	 this->txtItem4UnitPrice->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item4UnitPrice");
    	 this->txtItem4Quantity->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item4Quantity");
    	 this->txtItem4SubTotal->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"Item4SubTotal");
    	 this->txtCleaningTotal->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"CleaningTotal");
    	 this->txtTaxRate->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"TaxRate");
    	 this->txtTaxAmount->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"TaxAmount");
    	 this->txtOrderTotal->DataBindings->Add(S"Text", this->dvwCleaningOrder, S"OrderTotal");
    
    	 IsNewOrder = false;
    }
  33. In the Class View, right-click Form1 -> Add -> Add Function...
  34. Set the characteristics as follows:
    Return Type: void
    Function Name: UpdateCleaningOrder
    Access: private
     
  35. Click Finish and implement the event as follows:
     
    // This method is used to update an existing record if the user changes any of its values
    void UpdateCleaningOrder(void)
    {
    	 // Find out if this is a new, usually started as blank, order
    	 // If it is, trust that the user will save it by clicking the Save button
    	 // If it's not, then, if the user changed the string that was in the
    	 // Customer Name text box, update the current record
    	 if( IsNewOrder == false )
    	 {
    	 String *strUpdate = String::Concat(S"UPDATE CleaningOrders ",
                           S"SET CustomerName = '",  this->txtCustomerName->Text, S"', ",
    		S"CustomerPhone = '",  this->txtCustomerPhone->Text, S"', ",
    		S"DateLeft = '", this->dtpDateLeft->Value.ToString(), S"', ",
    		S"TimeLeft = '", this->dtpTimeLeft->Value.ToString(), S"', ",
    		S"DateExpected = '", this->dtpDateExpected->Value.ToString(), S"', ",
    		S"TimeExpected = '", this->dtpTimeExpected->Value.ToString(), S"', ",
    		S"ShirtsUnitPrice = '", this->txtShirtsUnitPrice->Text, S"', ",
    		S"ShirtsQuantity = '", this->txtShirtsQuantity->Text, S"', ",
    		S"ShirtsSubTotal = '", this->txtShirtsSubTotal->Text, S"', ",
    		S"PantsUnitPrice = '", this->txtPantsUnitPrice->Text, S"', ",
    		S"PantsQuantity = '", this->txtPantsQuantity->Text, S"', ",
    		S"PantsSubTotal = '", this->txtPantsSubTotal->Text, S"', ",
    		S"Item1Name = '", this->cboItem1->Text, S"', ",
    		S"Item1UnitPrice = '", this->txtItem1UnitPrice->Text, S"', ",
    		S"Item1Quantity = '", this->txtItem1Quantity->Text, S"', ",
    		S"Item1SubTotal = '", this->txtItem1SubTotal->Text, S"', ",
    		S"Item2Name = '", this->cboItem2->Text, S"', ",
    		S"Item2UnitPrice = '", this->txtItem2UnitPrice->Text, S"', ",
    		S"Item2Quantity = '", this->txtItem2Quantity->Text, S"', ",
    		S"Item2SubTotal = '", this->txtItem2SubTotal->Text, S"', ",
    		S"Item3Name = '", this->cboItem3->Text, S"', ",
    		S"Item3UnitPrice = '", this->txtItem3UnitPrice->Text, S"', ",
    		S"Item3Quantity = '", this->txtItem3Quantity->Text, S"', ",
    		S"Item3SubTotal = '", this->txtItem3SubTotal->Text, S"', ",
    		S"Item4Name = '", this->cboItem4->Text, S"', ",
    		S"Item4UnitPrice = '", this->txtItem4UnitPrice->Text, S"', ",
    		S"Item4Quantity = '", this->txtItem4Quantity->Text, S"', ",
    		S"Item4SubTotal = '", this->txtItem4SubTotal->Text, S"', ",
    		S"CleaningTotal = '", this->txtCleaningTotal->Text, S"', ",
    		S"TaxRate = '", this->txtTaxRate->Text, S"', ",
    		S"TaxAmount = '", this->txtTaxAmount->Text, S"', ",
    		S"OrderTotal = '", this->txtOrderTotal->Text, S"' ",
    		S"WHERE CleaningOrderID = '",
    		this->txtReceiptNumber->Text, S"';");
    
    	 SqlCommand    *cmdDatabase = new SqlCommand(strUpdate, sqlConnection1);
    
    	 sqlConnection1->Open();
    
    	 cmdDatabase->ExecuteNonQuery();
    	 sqlConnection1->Close();
    	 }
    }
  36. Return to the form and click the Customer Name text box
  37. In the Properties window, click the Events button and double-click Leave
  38. Implement its event as follows:
     
    System::Void txtCustomerName_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( IsNewOrder == false )
    	 {
    		UpdateCleaningOrder();
    	 }
    }
  39. Return to the form and click the Customer Phone text box
  40. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtCustomerPhone_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( IsNewOrder == false )
    	 {
    		UpdateCleaningOrder();
    	 }
    }
  41. Return to the form and double-click the Date Left date time picker control
  42. Implement its ValueChanged event as follows:
     
    System::Void dtpDateLeft_ValueChanged(System::Object *  sender, System::EventArgs *  e)
    {
    	 DateTime dateLeft = this->dtpDateLeft->Value;
    	 DateTime timeLeft = this->dtpTimeLeft->Value;
    	 DateTime time9AM  = DateTime(timeLeft.Year, timeLeft.Month, timeLeft.Day, 9, 0, 0);
    
    	 // If the customer leaves clothes before 9AM...
    	 if( timeLeft <= time9AM )
    	 {
    		 // ... then they should be ready the same day after 5PM
    		 this->dtpDateExpected->Value = dateLeft;
     this->dtpTimeExpected->Value = DateTime(dateLeft.Year, dateLeft.Month, dateLeft.Day, 17, 0, 0);
    	 }
    	 else
    	 {
     // If the clothese were left after 9AM, they will be availablethe following morning at 8AM
    	 this->dtpDateExpected->Value = DateTime(dateLeft.Year, dateLeft.Month, dateLeft.Day + 1); 
     this->dtpTimeExpected->Value = DateTime(dateLeft.Year, dateLeft.Month, dateLeft.Day + 1, 8, 0, 0);
    	 }
    	
    	 if( IsNewOrder == false )
    	 {
    		UpdateCleaningOrder();
    	 }
    }
  43. Return to the form and double-click the Time Left date time picker control
  44. Implement its ValueChanged event as follows:
     
    System::Void dtpTimeLeft_ValueChanged(System::Object *  sender, System::EventArgs *  e)
    {
    	 DateTime dateLeft = this->dtpDateLeft->Value;
    	 DateTime timeLeft = this->dtpTimeLeft->Value;
    	 DateTime time9AM  = DateTime(timeLeft.Year, timeLeft.Month, timeLeft.Day, 9, 0, 0);
    
    	 // If the customer leaves clothes before 9AM...
    	 if( timeLeft <= time9AM )
    	 {
    		 // ... then they should be ready the same day after 5PM
    		 this->dtpDateExpected->Value = dateLeft;
     this->dtpTimeExpected->Value = DateTime(dateLeft.Year, dateLeft.Month, dateLeft.Day, 17, 0, 0);
    	 }
    	 else
    	 {
     // If the clothese were left after 9AM, they will be availablethe following morning at 8AM
     this->dtpDateExpected->Value = DateTime(dateLeft.Year, dateLeft.Month, dateLeft.Day + 1); 
    this->dtpTimeExpected->Value = DateTime(dateLeft.Year, dateLeft.Month, dateLeft.Day + 1, 8, 0, 0);
    	 }
    	
    	 if( IsNewOrder == false )
    	 {
    		 UpdateCleaningOrder();
    	 }
    }
  45. Return to the form and double-click the Date Expected date time picker control
  46. Implement its ValueChanged event as follows:
     
    System::Void dtpDateExpected_ValueChanged(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( IsNewOrder == false )
    	 	 UpdateCleaningOrder();
    }
  47. Return to the form and double-click the Time Expected date time picker control
  48. Implement its ValueChanged event as follows:
     
    System::Void dtpTimeExpected_ValueChanged(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( IsNewOrder == false )
    	 	UpdateCleaningOrder();
    }
  49. Return to the form and click the Unit Price text box corresponding to the Shirts
  50. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtShirtsUnitPrice_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  51. Return to the form and click the Qty text box corresponding to the Shirts
  52. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtShirtsQuantity_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  53. Return to the form and click the Unit Price text box corresponding to the Pants
  54. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtPantsUnitPrice_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  55. Return to the form and click the Qty text box corresponding to the Pants
  56. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtPantsQuantity_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  57. Return to the form and double-click the first combo box under Pants
  58. Implement its event as follows:
     
    System::Void cboItem1_SelectedIndexChanged(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( this->cboItem1->Text->Equals(S"None") )
    	 {
    		 this->txtItem1UnitPrice->Text = S"0.00";
    		 this->txtItem1Quantity->Text  = S"0";
    		 this->txtItem1SubTotal->Text  = S"0.00";
    	 }
    
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  59. Return to the form and click the Unit Price text box corresponding to the first combo box
  60. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtItem1UnitPrice_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  61. Return to the form and click the Qty text box corresponding to the first combo box
  62. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtItem1Quantity_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  63. Return to the form and double-click the second combo box under Pants
  64. Implement its event as follows:
     
    System::Void cboItem2_SelectedIndexChanged(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( this->cboItem2->Text->Equals(S"None") )
    	 {
    		 this->txtItem2UnitPrice->Text = S"0.00";
    		 this->txtItem2Quantity->Text  = S"0";
    		 this->txtItem2SubTotal->Text  = S"0.00";
    	 }
    
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  65. Return to the form and click the Unit Price text box corresponding to the second combo box
  66. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtItem2UnitPrice_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  67. Return to the form and click the Qty text box corresponding to the second combo box
  68. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtItem2Quantity_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  69. Return to the form and double-click the third combo box under Pants
  70. Implement its event as follows:
     
    System::Void cboItem3_SelectedIndexChanged(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( this->cboItem3->Text->Equals(S"None") )
    	 {
    		 this->txtItem3UnitPrice->Text = S"0.00";
    		 this->txtItem3Quantity->Text  = S"0";
    		 this->txtItem3SubTotal->Text  = S"0.00";
    	 }
    
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  71. Return to the form and click the Unit Price text box corresponding to the third combo box
  72. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtItem3UnitPrice_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  73. Return to the form and click the Qty text box corresponding to the third combo box
  74. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtItem3Quantity_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  75. Return to the form and double-click the fourth combo box under Pants
  76. Implement its event as follows:
     
    System::Void cboItem4_SelectedIndexChanged(System::Object *  sender, System::EventArgs *  e)
    {
    	 if( this->cboItem4->Text->Equals(S"None") )
    	 {
    		 this->txtItem4UnitPrice->Text = S"0.00";
    		 this->txtItem4Quantity->Text  = S"0";
    		 this->txtItem4SubTotal->Text  = S"0.00";
    	 }
    
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  77. Return to the form and click the Unit Price text box corresponding to the fourth combo box
  78. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtItem4UnitPrice_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  79. Return to the form and click the Qty text box corresponding to the fourth combo box
  80. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtItem4Quantity_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  81. Return to the form and click the Tax Rate text box
  82. In the Events section of the Properties window, double-click Leave and implement its event as follows:
     
    System::Void txtTaxRate_Leave(System::Object *  sender, System::EventArgs *  e)
    {
    	 CalculateCleaningOrder();
    
    	 if( IsNewOrder == false )
    		 UpdateCleaningOrder();
    }
  83. Display the form and double-click the Close button
  84. Implement its event as follows:
     
    System::Void btnClose_Click(System::Object *  sender, System::EventArgs *  e)
    {
    	 Close();
    }
  85. Execute the application and create a few cleaning orders
     
  86. Close the form
  87. Execute the application again and try opening a cleaning order whose receipt number is 1001, then 1002, then 1003
  88. Close the form

Previous Copyright © 2005-2016, FunctionX