A simple program for printing small tickets for supermarket shopping is recorded

Source: Internet
Author: User
I made two versions of the supermarket shopping invoice printing program, and made a record
1. the C/S sample is as follows:

Enter the product code and press enter to call the product information. displayed in the following DataGridView, the number in the DataGridView can be modified. The total number below will be automatically calculated, then print
The procedure for printing a shopping invoice is as follows:
# Region checkout and printing functions
Private void jzPrint ()
{
If (maid. Count = 0)
{
MessageBox. Show ("no shopping data, no cash register and printing available! ");
Return;
}
If (textBox3.Text. Trim () = "")
{
MessageBox. Show ("the payment amount is not entered, and you cannot print the cash register! ");
Return;
}
// Cash register Printing

String operuser = "open-air"; // cashier's name. It should be the name of the cashier.

# Region Step 1: first write this order into the database table
// Writing data to the database is relatively simple,
For (int I = 0; I <dataGridView1.Rows. Count; I ++)
{
String name = maid [I]. Cells ["ProName"]. Value. ToString (). Trim (); // get the item name for this row
String num = maid [I]. Cells ["ProNum"]. Value. ToString (). Trim (); // quantity
String price = maid [I]. Cells ["ProPrice"]. Value. ToString (). Trim (); // unit price
String bm = maid [I]. Cells ["bianma"]. Value. ToString ();
// String SQL = "insert into T_Order ()";
// SqlHelper. ExecuteNonQuery (

}
# Endregion
String path = Application. StartupPath. ToString () + "\ ticket.txt"; // path of the exe program

# Region Step 2: generate a txt file in the format of the customer's shopping order to facilitate step 3 Printing
StreamWriter sw = new StreamWriter (path, true );
String day = DateTime. Now. ToString ("yyyyMMdd ");
String time = DateTime. Now. ToString ();
# Region ticket basic format
******************* *****//
// Xinyijia supermarket //
// Welcome to xinyijia supermarket //
////
////
// Item quantity unit price (¥ )//
//---------------------------------------------------//
// Series Hongshan tea hard box 3 45.8 //
// Doraemon camera bag 5 25.8 //
// Doraemon camera bag 5 25.8 //
// Doraemon camera bag 5 25.8 //
// Doraemon camera bag 5 25.8 //
// Doraemon camera bag 5 25.8 //
// Doraemon camera bag 5 25.8 //
// Doraemon camera bag 5 25.8 //
//--------------------------------------------------//
// Total: 35 //
// In total: 350 //
// Cash: 355.9 //
// Redemption: 15 //
////
////
////
// Date/time 2009/10/25 14:25:15 //
// Service Hotline: 0755-25145252 //
//************************************** ************//
# Endregion
# Region spell out the ticket format
Sw. WriteLine ("xinyijia supermarket \ t ");
Sw. WriteLine ("\ t ");
Sw. WriteLine ("Welcome to xinyijia supermarket \ t ");
Sw. WriteLine ("");
Sw. WriteLine ("");
Sw. WriteLine ("");
Sw. WriteLine ("item quantity unit price (¥ )");
Sw. WriteLine ("-----------------------------------------------------");
Int nums = 20;
Int prices = 12;

# Region
For (int I = 0; I <dataGridView1.Rows. Count; I ++)
{
String name = maid [I]. Cells ["ProName"]. Value. ToString (). Trim (); // get the item name for this row
String num = maid [I]. Cells ["ProNum"]. Value. ToString (). Trim (); // quantity
String price = maid [I]. Cells ["ProPrice"]. Value. ToString (). Trim (); // unit price

Int numlength = System. Text. Encoding. Default. GetBytes (num). Length;
If (numlength <nums)
{
Num = AddSpace (num, nums-numlength );
}

Int pricelength = System. Text. Encoding. Default. GetBytes (price). Length;
If (pricelength <prices)
{
Price = AddSpace (price, prices-pricelength );
}
Sw. WriteLine (name );
Sw. WriteLine ("" + num + "" + price );

}
# Endregion
Sw. WriteLine ("-----------------------------------------------------");
Sw. WriteLine ("Total:" + lbnum. Text. ToString ());
// Calculate the total amount:
Decimal oldmoney = Convert. ToDecimal (textBox1.Text );
Decimal newmoney = 0;

Newmoney = oldmoney;

Sw. WriteLine ("Total:" + newmoney. ToString (); // total amount
Sw. WriteLine ("Cash:" + textBox3.Text. Trim (); // pay-as-you-go
Sw. WriteLine ("redemption:" + textBox4.Text. Trim (); // pay-as-you-go
Sw. WriteLine ("\ t ");
Sw. WriteLine ("\ t ");
Sw. WriteLine ("date/time" + DateTime. Now. ToString ("yyyy/MM/dd HH: mm: ss "));
Sw. WriteLine ("");
Sw. WriteLine ("Service Hotline: 0755-12435682 ");
Sw. Close ();
# Endregion
# Endregion
# Print the third part of region
System. Windows. Forms. PrintDialog PrintDialog1 = new PrintDialog ();
PrintDialog1.AllowSomePages = true;
PrintDialog1.ShowHelp = true;

// Set the Document attribute of PrintDialog to the configured PrintDocument instance
PrintDialog1.Document = docToPrint; // This is a component name printed in the toolbox.
This.doc ToPrint. PrintPage + = new System. Drawing. Printing. PrintPageEventHandler (docToPrint_PrintPage );

// Call the ShowDialog function of PrintDialog to display the Print dialog box.
DialogResult result = PrintDialog1.ShowDialog ();

If (result = DialogResult. OK) // The printer is displayed. if you do not need to set the printer, the third part can be abbreviated as docToPrint. Print ().
{
// Start printing
DocToPrint. Print ();

}
# Endregion
If (File. Exists (path ))
{
File. Delete (path );
}
}
# Endregion
II. B/S sample:

B/S is similar to C/S

The complete program is as follows:/Files/ggbbeyou/supermarket shopping coupon .rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.