Sei sulla pagina 1di 26

Example Application:

Georgetown Dry Cleaner

Introduction
This is a sample application that demonstrates how to create a file-based database.

This application is a dry cleaning business. To start, a customer would bring clothes to the
store. The clerk registers the customer's information (name and phone number) and the
clothes he or she brought. Other pieces of information are entered such as the date and the
time the clothes were brought. To motivate customers, this store cleans the clothes the same
day if the customer brings them before 9AM.

To make it a little complete, this application includes the ability to print.

Windows Controls:
Label
Text Box
Group Box
Menu Strip
Combo Box
Print Dialog
Print Document
Masked Text Box
Print Preview Dialog

Practical Learning: Creating the Application


1. Start Microsoft Visual C#
2. Create a Windows Application named GeorgetownDryCleaner1
3. In the Solution Explorer, right-click Form1.cs and click Rename
4. Type Central.cs and press Enter
5. From the Menus & Toolbars section of the Toolbox, click MenuStrip and click the form
6. While the menu strip is still selected, in the Properties window, click (Name) and type mnuMain
7. Under the Properties window, click Insert Standard Items
8. On the form, click Help and press Delete
9. Click Tools and press Delete
10. Click Edit and press Delete
11. Click File, click Save As and press Delete
12. Using the Properties window, change the names of the menu items as follows:

Text New Name


&File mnuFile
&New mnuFileNew
&Open mnuFileOpen
&Save mnuFileSave
&Print mnuFilePrint
Print Pre&view mnuFilePrintPreview

13. Design the form as follows:


Control Name Text Additional Properties
Order
GroupBox
Identification

Label &Receipt #:

TextBox txtReceiptNumber 1000 TextAlign: Right

Customer
Label
Name:

TextBox txtCustomerName

Customer
Label
Phone:

TextBox txtCustomerPhone
Label Date Left:

DateTimePicker dtpDateLeft

Label Time Left:

DateTimePicker dtpTimeLeft Format: Time

Date
Label
Expected:

DateTimePicker dtpDateExpected

Time
Label
Expected:

DateTimePicker dtpTimeExpected Format: Time

Order
Label
&Status:

ComboBox cbxOrderStatus

D&ate Picked
Label
Up:

DateTimePicker dtpDatePickedUp

Time Pic&kep
Label
Up:

DateTimePicker dtpTimePickedUp

Order
GroupBox
Processing

Label Item Type

Label Unit Price

Label Qty

Label Sub Total

Label Shirts

TextBox txtShirtsUnitPrice 1.25 TextAlign: Right

TextBox txtShirtsQuantity 0 TextAlign: Right

TextBox txtShirtsSubTotal 0.00 TextAlign: Right

Label Pants
TextBox txtPantsUnitPrice 1.95 TextAlign: Right

TextBox txtPantsQuantity TextAlign: Right

TextBox txtPantsSubTotal 0.00 TextAlign: Right

Items:
None
Women Suit
Dress
Regular Skirt
Skirt With Hook
Men's Suit 2Pc
ComboBox cbxItem1 None
Men's Suit 3Pc
Sweaters
Silk Shirt
Tie
Coat
Jacket
Swede

TextBox txtItem1UnitPrice 0.00 TextAlign: Right

TextBox txtItem1Quantity 0 TextAlign: Right

TextBox txtItem1SubTotal 0.00 TextAlign: Right

Items:
None
Women Suit
Dress
Regular Skirt
Skirt With Hook
Men's Suit 2Pc
ComboBox cbxItem2 None
Men's Suit 3Pc
Sweaters
Silk Shirt
Tie
Coat
Jacket
Swede

TextBox txtItem2UnitPrice 0.00 TextAlign: Right

TextBox txtItem2Quantity 0 TextAlign: Right

TextBox txtItem2SubTotal 0.00 TextAlign: Right

Items:
None
ComboBox cbxItem3 None
Women Suit
Dress
Regular Skirt
Skirt With Hook
Men's Suit 2Pc
Men's Suit 3Pc
Sweaters
Silk Shirt
Tie
Coat
Jacket
Swede

TextBox txtItem3UnitPrice 0.00 TextAlign: Right

TextBox txtItem3Quantity 0 TextAlign: Right

TextBox txtItem3SubTotal 0.00 TextAlign: Right

Items:
None
Women Suit
Dress
Regular Skirt
Skirt With Hook
Men's Suit 2Pc
ComboBox cbxItem4 None
Men's Suit 3Pc
Sweaters
Silk Shirt
Tie
Coat
Jacket
Swede

TextBox txtItem4UnitPrice 0.00 TextAlign: Right

TextBox txtItem4Quantity 0 TextAlign: Right

TextBox txtItem4SubTotal 0.00 TextAlign: Right

Order
GroupBox
Summary
Cleaning
Label
Total:

TextBox txtCleaningTotal 0.00 TextAlign: Right

Label Tax Rate:

TextBox txtTaxRate 7.75 TextAlign: Right

Label %
Label Tax Amount:

TextBox txtTaxAmount 0.00 TextAlign: Right

Label Net Total:

TextBox txtNetPrice 0.00 TextAlign: Right

14. Double-click the Time Left control and implement its ValueChanged event as follows:

private void dtpTimeLeft_ValueChanged(object sender, EventArgs e)


{
var dateLeft = this.dtpDateLeft.Value;
var timeLeft = this.dtpTimeLeft.Value;
var time9AM = new 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 = new DateTime(dateLeft.Year,
dateLeft.Month,
dateLeft.Day, 17, 0,
0);
}
else
{
// If the clothes were left after 9AM,
// then they will be available the following business morning
at 8AM
// If the following day is Sunday,
// then they will be ready the following Monday
if (dateLeft.DayOfWeek == DayOfWeek.Saturday)
{
dtpDateExpected.Value = dateLeft.AddDays(2.00D);
dtpTimeExpected.Value = new DateTime(dateLeft.Year,
dateLeft.Month,
dateLeft.Day + 2, 8,
0, 0);
}
else
{
dtpDateExpected.Value = new DateTime(dateLeft.Year,
dateLeft.Month,
dateLeft.Day + 1);
dtpTimeExpected.Value = new DateTime(dateLeft.Year,
dateLeft.Month,
dateLeft.Day + 1, 8,
0, 0);
}
}
}

15. Return to the form


16. On the main menu of the form, click File and double-click New
17. Implement the event as follows:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace GeorgetownDryCleaner1
{
public partial class Central : Form
{
int iFilename;
bool IsNewCleaningOrder;
string Filename;

public Central()
{
InitializeComponent();
}

private void dtpTimeLeft_ValueChanged(object sender,


EventArgs e)
{
. . . No Change
}

private void mnuFileNew_Click(object sender, EventArgs e)


{
// We will store our files in the following folder
var strDirectory = @"C:\Georgetown Dry Cleaner\Receipts";

var dirInfo = Directory.CreateDirectory(strDirectory);

// Get the list of files, if any, from our directory


var fleList = dirInfo.GetFiles();

// If there is no file in the directory,


// then we will use 1000 as the first file name
if (fleList.Length == 0)
{
iFilename = 1000;
}
else // If there was at least one file in the directory
{
// Get a reference to the last file
FileInfo fleLast = fleList[fleList.Length - 1];
// Get the name of the last file without its
extension
string fwe =

Path.GetFileNameWithoutExtension(fleLast.FullName);
// Increment the name of the file by 1
try
{
iFilename = int.Parse(fwe) + 1;
}
catch (FormatException)
{
}
}

// Update our global name of the file


Filename = strDirectory + "\\" + iFilename.ToString() +
".gcs";
txtReceiptNumber.Text = iFilename.ToString();

txtCustomerName.Text = "";
txtCustomerPhone.Text = "";
dtpDateLeft.Value = DateTime.Today;
dtpTimeLeft.Value = DateTime.Today;
dtpDateExpected.Value = DateTime.Today;
dtpTimeExpected.Value = DateTime.Today;

cbxStatus.Text = "Not Yet Ready";


dtpDatePickedUp.Value = DateTime.Today;
dtpTimePickedUp.Value = DateTime.Today;

txtUnitPriceShirts.Text = "1.25";
txtQuantityShirts.Text = "0";
txtSubTotalShirts.Text = "0.00";
txtUnitPricePants.Text = "1.95";
txtQuantityPants.Text = "0";
txtSubTotalPants.Text = "0.00";
cbxItem1.Text = "None";
txtUnitPriceItem1.Text = "0.00";
txtQuantityItem1.Text = "0";
txtSubTotalItem1.Text = "0.00";
cbxItem2.Text = "None";
txtUnitPriceItem2.Text = "0.00";
txtQuantityItem2.Text = "0";
txtSubTotalItem2.Text = "0.00";
cbxItem3.Text = "None";
txtUnitPriceItem3.Text = "0.00";
txtQuantityItem3.Text = "0";
txtSubTotalItem3.Text = "0.00";
cbxItem4.Text = "None";
txtUnitPriceItem4.Text = "0.00";
txtQuantityItem4.Text = "0";
txtSubTotalItem4.Text = "0.00";

txtCleaningTotal.Text = "0.00";
txtTaxRate.Text = "7.75";
txtTaxAmount.Text = "0.00";
txtCleaningTotal.Text = "0.00";

txtCustomerName.Focus();
}
}
}

18. Return to the form


19. Click the unit price text box that corresponds to the shirts
20. In the Properties window, click the Events button and double-click Leave
21. Implement the event as follows:

internal void SaveCleaningOrder()


{
// We will store our files in the following folder
string strDirectory = @"C:\Georgetown Dry Cleaner\Receipts";
DirectoryInfo dirInfo = Directory.CreateDirectory(strDirectory);

// Get the list of files, if any, from our directory


FileInfo[] fleList = dirInfo.GetFiles();

// If this is a new cleaning order,


// get ready to create a name for the file
if (IsNewCleaningOrder == true)
{
// If there is no file in the directory,
// then we will use 1000 as the first file name
if (fleList.Length == 0)
{
iFilename = 1000;
}
else // If there was at least one file in the directory
{
// Get a reference to the last file
FileInfo fleLast = fleList[fleList.Length - 1];
// Get the name of the last file without its extension
string fwe =
Path.GetFileNameWithoutExtension(fleLast.FullName);
// Increment the name of the file by 1
iFilename = int.Parse(fwe) + 1;
}

// Update our global name of the file


Filename = strDirectory + "\\" + iFilename.ToString() +
".gcs";
txtReceiptNumber.Text = iFilename.ToString();

IsNewCleaningOrder = false;
} // If a cleaning order was already opened, we will simply
update it
else
Filename = @"C:\Georgetown Dry Cleaner\Receipts\" +
txtReceiptNumber.Text + ".gcs";

StreamWriter stmGCS = new StreamWriter(Filename);

try
{
stmGCS.WriteLine(txtCustomerName.Text);
stmGCS.WriteLine(txtCustomerPhone.Text);
stmGCS.WriteLine(dtpDateLeft.Value.ToString("D"));
stmGCS.WriteLine(dtpTimeLeft.Value.ToString("t"));
stmGCS.WriteLine(dtpDateExpected.Value.ToString("D"));
stmGCS.WriteLine(dtpTimeExpected.Value.ToString("t"));

stmGCS.WriteLine(cbxStatus.Text);
stmGCS.WriteLine(dtpDatePickedUp.Value.ToString("D"));
stmGCS.WriteLine(dtpTimePickedUp.Value.ToString("t"));

stmGCS.WriteLine(txtUnitPriceShirts.Text);
stmGCS.WriteLine(txtQuantityShirts.Text);
stmGCS.WriteLine(txtSubTotalShirts.Text);
stmGCS.WriteLine(txtUnitPricePants.Text);
stmGCS.WriteLine(txtQuantityPants.Text);
stmGCS.WriteLine(txtSubTotalPants.Text);

stmGCS.WriteLine(cbxItem1.Text);
stmGCS.WriteLine(txtUnitPriceItem1.Text);
stmGCS.WriteLine(txtQuantityItem1.Text);
stmGCS.WriteLine(txtSubTotalItem1.Text);

stmGCS.WriteLine(cbxItem2.Text);
stmGCS.WriteLine(txtUnitPriceItem2.Text);
stmGCS.WriteLine(txtQuantityItem2.Text);
stmGCS.WriteLine(txtSubTotalItem2.Text);

stmGCS.WriteLine(cbxItem3.Text);
stmGCS.WriteLine(txtUnitPriceItem3.Text);
stmGCS.WriteLine(txtQuantityItem3.Text);
stmGCS.WriteLine(txtSubTotalItem3.Text);

stmGCS.WriteLine(cbxItem4.Text);
stmGCS.WriteLine(txtUnitPriceItem4.Text);
stmGCS.WriteLine(txtQuantityItem4.Text);
stmGCS.WriteLine(txtSubTotalItem4.Text);

stmGCS.WriteLine(txtCleaningTotal.Text);
stmGCS.WriteLine(txtTaxRate.Text);
stmGCS.WriteLine(txtTaxAmount.Text);
stmGCS.WriteLine(txtNetPrice.Text);
}
finally
{
stmGCS.Close();
}
}
private void txtUnitPriceShirts_Leave(object sender, EventArgs e)
{
decimal unitPriceShirts = 0.00M, unitPricePants = 0.00M,
unitPriceItem1 = 0.00M, unitPriceItem2 = 0.00M,
unitPriceItem3 = 0.00M, unitPriceItem4 = 0.00M;
decimal subTotalShirts = 0.00M, subTotalPants = 0.00M,
subTotalItem1 = 0.00M, subTotalItem2 = 0.00M,
subTotalItem3 = 0.00M, subTotalItem4 = 0.00M;
int qtyShirts = 1, qtyPants = 1, qtyItem1 = 1,
qtyItem2 = 1, qtyItem3 = 1, qtyItem4 = 4;
decimal cleaningTotal = 0.00M, taxRate = 0.00M,
taxAmount = 0.00M, netPrice = 0.00M;

// Retrieve the unit price of this item


// Just in case the user types an invalid value,
// we are using a try...catch
try
{
unitPriceShirts =
decimal.Parse(this.txtUnitPriceShirts.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered for the price of " +
"shirts is not valid" +
"\nPlease try again");
return;
}

// Retrieve the number of this item


// Just in case the user types an invalid value,
// we are using a try...catch
try
{
qtyShirts = int.Parse(this.txtQuantityShirts.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered for the number of " +
"shirts is not valid" +
"\nPlease try again");
return;
}

try
{
unitPricePants = decimal.Parse(this.txtUnitPricePants.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered for the price of " +
"pants is not valid" +
"\nPlease try again");
return;
}
try
{
qtyPants = int.Parse(this.txtQuantityPants.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered for the number of " +
"pants is not valid" +
"\nPlease try again");
return;
}

if( (cbxItem1.Text == "None") ||


(cbxItem1.Text == "") )
{
qtyItem1 = 0;
unitPriceItem1 = 0.00M;
}
else
{
try
{
unitPriceItem1 =
decimal.Parse(this.txtUnitPriceItem1.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered for the price is not
valid" +
"\nPlease try again");
return;
}

try
{
qtyItem1 = int.Parse(this.txtQuantityItem1.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered is not valid" +
"\nPlease try again");
return;
}
}

if( (cbxItem2.Text == "None") ||


(cbxItem2.Text == "") )
{
qtyItem2 = 0;
unitPriceItem2 = 0.00M;
}
else
{
try
{
unitPriceItem2 =
decimal.Parse(this.txtUnitPriceItem2.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered for " +
"the price is not valid" +
"\nPlease try again");
return;
}

try
{
qtyItem2 = int.Parse(this.txtQuantityItem2.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered is not valid" +
"\nPlease try again");
return;
}
}

if( (cbxItem3.Text == "None") ||


(cbxItem3.Text == "") )
{
qtyItem3 = 0;
unitPriceItem3 = 0.00M;
}
else
{
try
{
unitPriceItem3 =
decimal.Parse(this.txtUnitPriceItem3.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered for the " +
"price is not valid" +
"\nPlease try again");
return;
}

try
{
qtyItem3 = int.Parse(this.txtQuantityItem3.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered is not valid" +
"\nPlease try again");
return;
}
}

if ((cbxItem4.Text == "None") || (cbxItem4.Text == ""))


{
qtyItem4 = 0;
unitPriceItem4 = 0.00M;
}
else
{
try
{
unitPriceItem4 =
decimal.Parse(this.txtUnitPriceItem4.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered for the price is not
valid" +
"\nPlease try again");
return;
}
try
{
qtyItem4 = int.Parse(this.txtQuantityItem4.Text);
}
catch (FormatException)
{
MessageBox.Show("The value you entered is not valid" +
"\nPlease try again");
return;
}
}

// Calculate the sub-total for this item


subTotalShirts = qtyShirts * unitPriceShirts;
subTotalPants = qtyPants * unitPricePants;
subTotalItem1 = qtyItem1 * unitPriceItem1;
subTotalItem2 = qtyItem2 * unitPriceItem2;
subTotalItem3 = qtyItem3 * unitPriceItem3;
subTotalItem4 = qtyItem4 * unitPriceItem4;

// Calculate the total based on sub-totals


cleaningTotal = subTotalShirts + subTotalPants +
subTotalItem1 +
subTotalItem2 + subTotalItem3 + subTotalItem4;

taxRate = decimal.Parse(this.txtTaxRate.Text);
// Calculate the amount owed for the taxes
taxAmount = cleaningTotal * taxRate / 100;
// Add the tax amount to the total order
netPrice = cleaningTotal + taxAmount;

// Display the sub-total in the corresponding text box


txtSubTotalShirts.Text = subTotalShirts.ToString("F");
txtSubTotalPants.Text = subTotalPants.ToString("F");
txtSubTotalItem1.Text = subTotalItem1.ToString("F");
txtSubTotalItem2.Text = subTotalItem2.ToString("F");
txtSubTotalItem3.Text = subTotalItem3.ToString("F");
txtSubTotalItem4.Text = subTotalItem4.ToString("F");
txtCleaningTotal.Text = cleaningTotal.ToString("F");
txtTaxAmount.Text = taxAmount.ToString("F");
txtNetPrice.Text = netPrice.ToString("F");

SaveCleaningOrder();
}

22. Return to the form, click File and double-click Save


23. Implement the event as follows:

private void mnuFileSave_Click(object sender, EventArgs e)


{
SaveCleaningOrder();
}

24. Return to the form


25. Click the unit price text box that corresponds to the pants
26. Press and hold Shift
27. Click the unit price text boxes for item 1, item 2, item 3, and item 4
28. Click each text box under the Qty label
29. Click the Tax Rate text box
30. Release Shift
31. In the Events section of the Properties window, click Leave, click the arrow of its combo box and sele
txtUnitPriceShirts_Leave
32. Execute the application
33. Create a cleaning order
34. Click New and create a few more cleaning orders
35. Close the form and return to your programming environment
36. On the form, click File and double-click Open
37. Implement the event as follows:

private void mnuFileOpen_Click(object sender, EventArgs e)


{
if (txtReceiptNumber.Text == "")
return;
else
{
try
{
IsNewCleaningOrder = false;
Filename =
@"C:\Georgetown Dry Cleaner\Receipts\" +
txtReceiptNumber.Text + ".gcs";

StreamReader rdrGCS = new StreamReader(Filename);


try
{
txtCustomerName.Text = rdrGCS.ReadLine();
txtCustomerPhone.Text = rdrGCS.ReadLine();
dtpDateLeft.Value =
DateTime.Parse(rdrGCS.ReadLine());
dtpTimeLeft.Value =
DateTime.Parse(rdrGCS.ReadLine());
dtpDateExpected.Value =
DateTime.Parse(rdrGCS.ReadLine());
dtpTimeExpected.Value =
DateTime.Parse(rdrGCS.ReadLine());

cbxStatus.Text = rdrGCS.ReadLine();
dtpDatePickedUp.Value =
DateTime.Parse(rdrGCS.ReadLine());
dtpTimePickedUp.Value =
DateTime.Parse(rdrGCS.ReadLine());

txtUnitPriceShirts.Text = rdrGCS.ReadLine();
txtQuantityShirts.Text = rdrGCS.ReadLine();
txtSubTotalShirts.Text = rdrGCS.ReadLine();
txtUnitPricePants.Text = rdrGCS.ReadLine();
txtQuantityPants.Text = rdrGCS.ReadLine();
txtSubTotalPants.Text = rdrGCS.ReadLine();

cbxItem1.Text = rdrGCS.ReadLine();
txtUnitPriceItem1.Text = rdrGCS.ReadLine();
txtQuantityItem1.Text = rdrGCS.ReadLine();
txtSubTotalItem1.Text = rdrGCS.ReadLine();

cbxItem2.Text = rdrGCS.ReadLine();
txtUnitPriceItem2.Text = rdrGCS.ReadLine();
txtQuantityItem2.Text = rdrGCS.ReadLine();
txtSubTotalItem2.Text = rdrGCS.ReadLine();

cbxItem3.Text = rdrGCS.ReadLine();
txtUnitPriceItem3.Text = rdrGCS.ReadLine();
txtQuantityItem3.Text = rdrGCS.ReadLine();
txtSubTotalItem3.Text = rdrGCS.ReadLine();

cbxItem4.Text = rdrGCS.ReadLine();
txtUnitPriceItem4.Text = rdrGCS.ReadLine();
txtQuantityItem4.Text = rdrGCS.ReadLine();
txtSubTotalItem4.Text = rdrGCS.ReadLine();

txtCleaningTotal.Text = rdrGCS.ReadLine();
txtTaxRate.Text = rdrGCS.ReadLine();
txtTaxAmount.Text = rdrGCS.ReadLine();
txtNetPrice.Text = rdrGCS.ReadLine();
}
finally
{
rdrGCS.Close();
}
}
catch (FileNotFoundException)
{
MessageBox.Show("There is no cleaning order " +
"with that receipt number");
}
}
}

38. Execute the application


39. Type 1001 for the receipt number and, on the main menu of the form, click File -> Open
40. Close the form and return to your programming environment
41. Display the form
42. In the combo box on top of the form, select Central and click the Events button
43. Double-click and implement the event as follows:

private void Central_Load(object sender, EventArgs e)


{
mnuFileNew_Click(sender, e);
}

44. Return to the form


45. On the form, click the Customer Name text box
46. In the Events section of the Properties window, double-click Leave and implement its event as follow

private void txtCustomerName_Leave(object sender, EventArgs e)


{
if (txtCustomerName.Modified == true)
SaveCleaningOrder();
}

47. Return to the form


48. On the form, click the Customer Phone text box
49. In the Events section of the Properties window, double-click Leave and implement its event as follow

private void txtCustomerPhone_Leave(object sender, EventArgs e)


{
if (txtCustomerPhone.Modified == true)
SaveCleaningOrder();
}

50. Execute the application and create a few cleaning orders


51. Close the form and return to your programming environment
52. From the Printing section of the Toolbox, click PrintDocument and click the form
53. While the new control is still selected, in the Properties window, click the Properties button, click (Na
type docPrint and press Enter
54. Under the form, double-click docPrint and implement its event as follows:
private void docPrint_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawLine(new Pen(Color.Black, 2), 60, 90, 720, 90);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 60, 93, 720, 93);

string strDisplay = "Georgetown Dry Cleaning Services";


System.Drawing.Font fntString = new Font("Times New Roman", 28,
FontStyle.Bold);
e.Graphics.DrawString(strDisplay, fntString,
Brushes.Black, 80, 100);

strDisplay = "Customer Cleaning Order";


fntString = new System.Drawing.Font("Times New Roman", 18,
FontStyle.Bold);
e.Graphics.DrawString(strDisplay, fntString,
Brushes.Black, 220, 150);

e.Graphics.DrawLine(new Pen(Color.Black, 1), 60, 184, 720, 184);


e.Graphics.DrawLine(new Pen(Color.Black, 2), 60, 188, 720, 188);

fntString = new System.Drawing.Font("Times New Roman", 12,


FontStyle.Bold);
e.Graphics.DrawString("", fntString,
Brushes.Black, 80, 200);

fntString = new System.Drawing.Font("Times New Roman", 12,


FontStyle.Bold);
e.Graphics.DrawString("Customer Identification: ", fntString,
Brushes.Black, 100, 220);
fntString = new System.Drawing.Font("Times New Roman", 12,
FontStyle.Regular);
e.Graphics.DrawString(txtCustomerName.Text + " - " +
txtCustomerPhone.Text, fntString,
Brushes.Black, 300, 220); ;

e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 240, 700, 240);

fntString = new Font("Times New Roman", 12, FontStyle.Bold);


e.Graphics.DrawString("Date Left: ", fntString,
Brushes.Black, 100, 260);
fntString = new Font("Times New Roman", 12, FontStyle.Regular);

e.Graphics.DrawString(dtpDateLeft.Value.ToString("D"), fntString,
Brushes.Black, 300, 260);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 280, 700, 280);

fntString = new Font("Times New Roman", 12, FontStyle.Bold);


e.Graphics.DrawString("Time Left: ", fntString,
Brushes.Black, 500, 260);
fntString = new Font("Times New Roman", 12, FontStyle.Regular);
e.Graphics.DrawString(dtpTimeLeft.Value.ToString("t"), fntString,
Brushes.Black, 620, 260);

fntString = new System.Drawing.Font("Times New Roman",


12, FontStyle.Bold);
e.Graphics.DrawString("Date Expected: ", fntString,
Brushes.Black, 100, 300);
fntString = new Font("Times New Roman", 12, FontStyle.Regular);
e.Graphics.DrawString(dtpDateExpected.Value.ToString("D"),
fntString, Brushes.Black, 300, 300);

fntString = new Font("Times New Roman", 12, FontStyle.Bold);


e.Graphics.DrawString("Time Expected: ", fntString,
Brushes.Black, 500, 300);
fntString = new Font("Times New Roman", 12, FontStyle.Regular);
e.Graphics.DrawString(dtpTimeExpected.Value.ToString("t"),
fntString, Brushes.Black, 620, 300);

e.Graphics.DrawLine(new Pen(Color.Black, 2), 100, 320, 700, 320);

fntString = new Font("Times New Roman", 12, FontStyle.Bold);


e.Graphics.DrawString("Item Type",
fntString, Brushes.Black, 140,
350);
e.Graphics.DrawString("Unit Price",
fntString, Brushes.Black, 300,
350);
e.Graphics.DrawString("Quantity",
fntString, Brushes.Black, 405,
350);
e.Graphics.DrawString("Sub-Total",
fntString, Brushes.Black, 500,
350);

e.Graphics.DrawLine(new Pen(Color.Black, 2), 140, 370, 640, 370);

StringFormat fmtString = new StringFormat();


fmtString.Alignment = StringAlignment.Far;

e.Graphics.DrawString("Shirts",
fntString, Brushes.Black, 150,
380);
fntString = new Font("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(new Pen(Color.Black, 1), 140, 400, 640, 400);

fntString = new Font("Times New Roman", 12, FontStyle.Bold);


e.Graphics.DrawString("Pants",
fntString, Brushes.Black, 150,
410);
fntString = new Font("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(new Pen(Color.Black, 1), 140, 430, 640, 430);

fntString = new Font("Times New Roman", 12, FontStyle.Bold);


e.Graphics.DrawString(cbxItem1.Text,
fntString, Brushes.Black, 150,
440);
fntString = new Font("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(new Pen(Color.Black, 1), 140, 460, 640, 460);

fntString = new Font("Times New Roman", 12, FontStyle.Bold);


e.Graphics.DrawString(cbxItem2.Text,
fntString, Brushes.Black, 150,
470);
fntString = new Font("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(new Pen(Color.Black, 1), 140, 490, 640, 490);

fntString = new Font("Times New Roman", 12, FontStyle.Bold);


e.Graphics.DrawString(cbxItem3.Text,
fntString, Brushes.Black, 150,
500);
fntString = new Font("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(new Pen(Color.Black, 1), 140, 520, 640, 520);

fntString = new Font("Times New Roman", 12, FontStyle.Bold);


e.Graphics.DrawString(cbxItem4.Text,
fntString, Brushes.Black, 150, 530);
fntString = new Font("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(new Pen(Color.Black, 2), 140, 550, 640, 550);

fntString = new System.Drawing.Font("Times New Roman", 12,


FontStyle.Bold);
e.Graphics.DrawString("Order Summary", fntString,
Brushes.Black, 260, 600);
e.Graphics.DrawLine(new Pen(Color.Black, 2), 220, 620, 560, 620);

fntString = new System.Drawing.Font("Times New Roman",


10, FontStyle.Bold);
e.Graphics.DrawString("Cleaning Total:", fntString,
Brushes.Black, 260, 630);
fntString = new System.Drawing.Font("Times New Roman",
10, FontStyle.Regular);
e.Graphics.DrawString(txtCleaningTotal.Text, fntString,
Brushes.Black, 440, 630, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1),
220, 650, 520, 650);

fntString = new System.Drawing.Font("Times New Roman",


10, FontStyle.Bold);
e.Graphics.DrawString("Tax Rate:", fntString,
Brushes.Black, 260, 660);
fntString = new System.Drawing.Font("Times New Roman",
10, FontStyle.Regular);
e.Graphics.DrawString(txtTaxRate.Text, fntString,
Brushes.Black, 440, 660, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1),
220, 680, 520, 680);

fntString = new System.Drawing.Font("Times New Roman",


10, FontStyle.Bold);
e.Graphics.DrawString("Tax Amount:", fntString,
Brushes.Black, 260, 690);
fntString = new System.Drawing.Font("Times New Roman",
10, FontStyle.Regular);
e.Graphics.DrawString(txtTaxAmount.Text, fntString,
Brushes.Black, 440, 690, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1),
220, 710, 520, 710);

fntString = new System.Drawing.Font("Times New Roman",


10, FontStyle.Bold);
e.Graphics.DrawString("Net Price:", fntString,
Brushes.Black, 260, 720);
fntString = new System.Drawing.Font("Times New Roman",
10, FontStyle.Regular);
e.Graphics.DrawString(txtNetPrice.Text, fntString,
Brushes.Black, 440, 720, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 2),
200, 740, 560, 740);
}

55. Return to the form


56. From the Printing section of the Toolbox, click PrintDialog and click the form
57. In the Properties window, change its Name to dlgPrint
58. Still in the Properties windows, set its Document property to docPrint
59. On the main menu of the form, click File and double-click Print
60. Implement the event as follows:

private void mnuFilePrint_Click(object sender, EventArgs e)


{
if (dlgPrint.ShowDialog() == DialogResult.OK)
docPrint.Print();
}

61. Return to the form


62. From the Printing section of the Toolbox, click PrintPreviewDialog and click the form
63. In the Properties window, change its Name to dlgPrintPreview
64. Still in the Properties windows, set its Document property to docPrint
65. On the main menu of the form, click File and double-click Print Preview
66. Implement the event as follows:

private void mnuFilePrintPreview_Click(object sender, EventArgs e)


{
dlgPrintPreview.ShowDialog();
}

67. Return to the form


68. On the main menu of the form, click File and double-click Exit
69. Implement the event as follows:

private void exitToolStripMenuItem_Click(object sender, EventArgs e)


{
Close();
}

70. Execute the application


71. Open an existing cleaning order and print preview it
72. Close the form and return to your programming environment

Potrebbero piacerti anche