Home

File-Based Applications

 

Data Input and Output

 

Introduction

 

Data input, also referred to as data entry, consists of entering the values into the application. The user does it mainly using the keyboard and the mouse. As we reviewed the Windows controls, there are various types of objects you can use to assist the user. One of the suggestions you should follow is that you should make the user's job as easy as you can.

Because users of a database are not expected to do any heavy word processing. This means that typing speed is not among their strongest points. Instead, when choosing the Windows controls for your application, you should select the most appropriate one for a particular piece of information.

Printing

Data output consists of retrieving information from a database. Besides opening the objects, such as the forms, that hold the information of a database, users also regular want to print. In fact, in some businesses, the customers require to have a printed copy of their transaction. Therefore, if you are in the habit of neglecting to configuring printing in your Windows applications, for a database, you should (strongly) loose the habit and provide your users with the ability to print the data of your application.

If you are creating a file-based application, you can use the various printing classes of the .NET Framework. Unfortunately, there is no environment inside the Microsoft Visual Studio 2005 that can assist you to visually design a report. You must manually draw everything.

Practical Learning: Printing

  1. From the Printing section of the Toolbox, click PrintDocument and click the form
  2. While the new control is still selected, in the Properties window, click the Properties button, click (Name), type docPrint and press Enter
  3. Under the form, double-click docPrint and implement its event as follows:
     
    System::Void docPrint_PrintPage(System::Object^  sender, 
    	System::Drawing::Printing::PrintPageEventArgs^  e)
    {
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 2), 60, 90, 720, 90);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1), 60, 93, 720, 93);
    
        String ^ strDisplay = L"Georgetown Dry Cleaning Services";
        System::Drawing::Font ^ fntString = 
    	gcnew System::Drawing::Font(L"Times New Roman", 28,
                    FontStyle::Bold);
        e->Graphics->DrawString(strDisplay, fntString,
                    Brushes::Black, 80, 100);
    
        strDisplay = L"Customer Cleaning Order";
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 18,
                    FontStyle::Bold);
        e->Graphics->DrawString(strDisplay, fntString,
                    Brushes::Black, 220, 150);
    
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1), 60, 184, 720, 184);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 2), 60, 188, 720, 188);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 12,
                    FontStyle::Bold);
        e->Graphics->DrawString(L"", fntString,
                    Brushes::Black, 80, 200);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 12,
                    FontStyle::Bold);
        e->Graphics->DrawString(L"Customer Identification:  ", fntString,
                    Brushes::Black, 100, 220);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 12,
                    FontStyle::Regular);
        e->Graphics->DrawString(txtCustomerName->Text+ L"  -  " +
                                      txtCustomerPhone->Text, fntString,
                                      Brushes::Black, 300, 220); ;
    
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1), 100, 240, 700, 240);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Bold);
        e->Graphics->DrawString(L"Date Left:        ", fntString,
                                      Brushes::Black, 100, 260);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Regular);
    
        e->Graphics->DrawString(dtpDateLeft->Value.ToString(L"D"), fntString,
                                      Brushes::Black, 300, 260);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1), 100, 280, 700, 280);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Bold);
        e->Graphics->DrawString(L"Time Left: ", fntString,
                                      Brushes::Black, 500, 260);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Regular);
        e->Graphics->DrawString(dtpTimeLeft->Value.ToString(L"t"), fntString,
                                      Brushes::Black, 620, 260);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman",
    					12, FontStyle::Bold);
        e->Graphics->DrawString(L"Date Expected:    ", fntString,
                    Brushes::Black, 100, 300);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Regular);
        e->Graphics->DrawString(dtpDateExpected->Value.ToString(L"D"),
    			  fntString, Brushes::Black, 300, 300);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Bold);
        e->Graphics->DrawString(L"Time Expected: ", fntString,
                                      Brushes::Black, 500, 300);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Regular);
        e->Graphics->DrawString(dtpTimeExpected->Value.ToString(L"t"),
    			  fntString, Brushes::Black, 620, 300);
    
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 2), 100, 320, 700, 320);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Bold);
        e->Graphics->DrawString(L"Item Type",
                                      fntString, Brushes::Black, 140, 350);
        e->Graphics->DrawString(L"Unit Price",
                                      fntString, Brushes::Black, 300, 350);
        e->Graphics->DrawString(L"Quantity",
                                      fntString, Brushes::Black, 405, 350);
        e->Graphics->DrawString(L"Sub-Total",
                                      fntString, Brushes::Black, 500, 350);
    
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 2), 140, 370, 640, 370);
    
        StringFormat ^ fmtString = gcnew StringFormat;
        fmtString->Alignment = StringAlignment::Far;
    
        e->Graphics->DrawString(L"Shirts",
                                      fntString, Brushes::Black, 150, 380);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Regular);
        e->Graphics->DrawString(txtUnitPriceShirts->Text, fntString,
                    Brushes::Black, 350, 380, fmtString);
        e->Graphics->DrawString(txtQuantityShirts->Text, fntString,
                    Brushes::Black, 440, 380, fmtString);
        e->Graphics->DrawString(txtSubTotalShirts->Text, fntString,
                    Brushes::Black, 550, 380, fmtString);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1), 140, 400, 640, 400);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Bold);
        e->Graphics->DrawString(L"Pants",
                                      fntString, Brushes::Black, 150, 410);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Regular);
        e->Graphics->DrawString(txtUnitPricePants->Text, fntString,
                    Brushes::Black, 350, 410, fmtString);
        e->Graphics->DrawString(txtQuantityPants->Text, fntString,
                    Brushes::Black, 440, 410, fmtString);
        e->Graphics->DrawString(txtSubTotalPants->Text, fntString,
                    Brushes::Black, 550, 410, fmtString);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1), 140, 430, 640, 430);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Bold);
        e->Graphics->DrawString(cbxItem1->Text,
                                      fntString, Brushes::Black, 150, 440);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Regular);
        e->Graphics->DrawString(txtUnitPriceItem1->Text, fntString,
                    Brushes::Black, 350, 440, fmtString);
        e->Graphics->DrawString(txtQuantityItem1->Text, fntString,
                    Brushes::Black, 440, 440, fmtString);
        e->Graphics->DrawString(txtSubTotalItem1->Text, fntString,
                    Brushes::Black, 550, 440, fmtString);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1), 140, 460, 640, 460);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Bold);
        e->Graphics->DrawString(cbxItem2->Text,
                                      fntString, Brushes::Black, 150, 470);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Regular);
        e->Graphics->DrawString(txtUnitPriceItem2->Text, fntString,
                    Brushes::Black, 350, 470, fmtString);
        e->Graphics->DrawString(txtQuantityItem2->Text, fntString,
                    Brushes::Black, 440, 470, fmtString);
        e->Graphics->DrawString(txtSubTotalItem2->Text, fntString,
                    Brushes::Black, 550, 470, fmtString);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1), 140, 490, 640, 490);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Bold);
        e->Graphics->DrawString(cbxItem3->Text,
                                      fntString, Brushes::Black, 150, 500);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Regular);
        e->Graphics->DrawString(txtUnitPriceItem3->Text, fntString,
                    Brushes::Black, 350, 500, fmtString);
        e->Graphics->DrawString(txtQuantityItem3->Text, fntString,
                    Brushes::Black, 440, 500, fmtString);
        e->Graphics->DrawString(txtSubTotalItem3->Text, fntString,
                    Brushes::Black, 550, 500, fmtString);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1), 140, 520, 640, 520);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Bold);
        e->Graphics->DrawString(cbxItem4->Text,
                    fntString, Brushes::Black, 150, 530);
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 
    		12, FontStyle::Regular);
        e->Graphics->DrawString(txtUnitPriceItem4->Text, fntString,
                    Brushes::Black, 350, 530, fmtString);
        e->Graphics->DrawString(txtQuantityItem4->Text, fntString,
                    Brushes::Black, 440, 530, fmtString);
        e->Graphics->DrawString(txtSubTotalItem4->Text, fntString,
                    Brushes::Black, 550, 530, fmtString);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 2), 140, 550, 640, 550);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman", 12,
    					FontStyle::Bold);
        e->Graphics->DrawString(L"Order Summary", fntString,
                              Brushes::Black, 260, 600);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 2), 220, 620, 560, 620);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman",
    					10, FontStyle::Bold);
        e->Graphics->DrawString(L"Cleaning Total:", fntString,
                              Brushes::Black, 260, 630);
        fntString = gcnew System::Drawing::Font(L"Times New Roman",
    					10, FontStyle::Regular);
        e->Graphics->DrawString(txtCleaningTotal->Text, fntString,
                              Brushes::Black, 440, 630, fmtString);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1),
    			220, 650, 520, 650);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman",
    					10, FontStyle::Bold);
        e->Graphics->DrawString(L"Tax Rate:", fntString,
                              Brushes::Black, 260, 660);
        fntString = gcnew System::Drawing::Font(L"Times New Roman",
    					10, FontStyle::Regular);
        e->Graphics->DrawString(txtTaxRate->Text, fntString,
                              Brushes::Black, 440, 660, fmtString);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1),
    			220, 680, 520, 680);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman",
    					10, FontStyle::Bold);
        e->Graphics->DrawString(L"Tax Amount:", fntString,
                              Brushes::Black, 260, 690);
        fntString = gcnew System::Drawing::Font(L"Times New Roman",
    					10, FontStyle::Regular);
        e->Graphics->DrawString(txtTaxAmount->Text, fntString,
                    	  Brushes::Black, 440, 690, fmtString);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 1),
    			220, 710, 520, 710);
    
        fntString = gcnew System::Drawing::Font(L"Times New Roman",
    					10, FontStyle::Bold);
        e->Graphics->DrawString(L"Net Price:", fntString,
                    Brushes::Black, 260, 720);
        fntString = gcnew System::Drawing::Font(L"Times New Roman",
    					10, FontStyle::Regular);
        e->Graphics->DrawString(txtNetPrice->Text, fntString,
                    Brushes::Black, 440, 720, fmtString);
        e->Graphics->DrawLine(gcnew Pen(Color::Black, 2),
    			200, 740, 560, 740);
    }
  4. Return to the form
  5. From the Printing section of the Toolbox, click PrintDialog and click the form
  6. In the Properties window, change its Name to dlgPrint
  7. Still in the Properties windows, set its Document property to docPrint
  8. On the main menu of the form, click File and double-click Print
  9. Implement the event as follows:
     
    System::Void mnuFilePrint_Click(System::Object^  sender, 
    			System::EventArgs^  e)
    {
        if (dlgPrint->ShowDialog() == System::Windows::Forms::DialogResult::OK)
            docPrint->Print();
    }
  10. Return to the form
  11. From the Printing section of the Toolbox, click PrintPreviewDialog and click the form
  12. In the Properties window, change its Name to dlgPrintPreview
  13. Still in the Properties windows, set its Document property to docPrint
  14. On the main menu of the form, click File and double-click Print Preview
  15. Implement the event as follows:
     
    System::Void mnuFilePrintPreview_Click(System::Object^  sender, 
    			System::EventArgs^  e)
    {
         dlgPrintPreview->ShowDialog();
    }
  16. Return to the form
  17. On the main menu of the form, click File and double-click Exit
  18. Implement the event as follows:
     
    System::Void mnuFileExit_Click(System::Object^  sender, 
    			System::EventArgs^  e)
    {
        Close();
    }
  19. Execute the application
  20. Open an existing cleaning order and print preview it
     
    Georgetown Dry Cleaner
  21. Close the form and return to your programming environment
Files
File-Based Application
Georgetown Dry Cleaning Services

 

 
 
     
 

Previous Copyright © 2009-2010 FunctionX, Inc. Home