C # Call Blade Small ticket printer

Source: Internet
Author: User
Tags dname key string

public static bool Print (int orderId, string ordertime) {bool b = true; String cut = ((char) 29). ToString () + ((char) 86). ToString () + ((char) 1). ToString () + ((char) 49).            ToString ();//Send paper cut instruction//byte[] Byte_cut = System.Text.Encoding.Default.GetBytes (cut); string font = ((char) 1D). ToString () + ((char) 21). ToString () + ((char) 01). ToString () + ((char) 10). ToString ();//Text size byte[] fonts = new byte[] {2, 0};//1d 21 Select font byte[] temp = new byte[ 9,};//1d 21 Select font size, 0x01 magnify one times byte[] bty_tmp = new byte[] {29, 86, 1, 49};//cut paper byte[] Intern Al = System.Text.Encoding.Default.GetBytes (((char) 27). ToString () + ((char) 64).            ToString ());//Initialize printer System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient ();            System.Net.Sockets.NetworkStream stream = null;            Int32 port = 9100; String ipprint = configurationmanager.connectionstrings["Printip"]. Connectionstring;//Gets the printer name string ipprint = "192.168.0.77";                String Ipprint =common.comm.readxml ("/xml/setting.xml", "Printip");//Read the XML's IP try { Client.                Connect ("192.168.1.77", port); Client.                Connect (Ipprint, Port); stream = client.                GetStream (); Whether to write if (!stream) is supported.                CanWrite) {b = false;                } byte[] data; By dish type and time, number, à la carte, order ordering notes Group query string sql_query = "Select Tname,typeid,dname,uname,d.addtime,d.remark,count (  fname) Fnum "+" from "+" P_orderdetailinfo d,p_orderinfo o, p_deskinfo desk, P_foodinfo F,  P_foodtype t,users u "+" where d.orderid=o.id and D.foodid=f.id and O.deskid=desk.id and F.typeid=t.id and  U.id=d.userid "+" and o.id= "+ OrderId +" and d.addtime= ' "+ ordertime +" ' + "GROUP BY Tname,typeId,d.remark,dname,uname,d.addtime ";                String sql_detail = ""; DataTable dt = Dbsqlhelper.executedataset (CommandType.Text, Sql_query).                Tables[0];                DataTable dt_detail = null; if (dt. Rows.Count > 0) {for (int i = 0; i < dt. Rows.Count; i++) {//Current menu information for this order Sql_detail = "Select Fname,count (Fnam e) fnum,f.id, userid,d.remark from "+" P_orderdetailinfo d,p_foodinfo F "+" where D.foodid=f.id and typeid= "+ dt. rows[i]["typeID"] + "and d.addtime=" + Ordertime + "' and orderid=" + orderid + "GROUP by fname,f.id, Userid,d.remark"                        ; Dt_detail = Dbsqlhelper.executedataset (CommandType.Text, Sql_detail).                        Tables[0]; Stream.                        Write (Internal, 0, internal.length); Stream. Write (fonts, 0, fonts. LENGTH);//Set Font strEam. Write (temp, 0, temp. LENGTH);//Set Font Size--key string outPut = "-" + dt. rows[i]["Tname"] + "-\n" + dt. rows[i]["dname" + "\ t à la carte-" + dt.                        rows[i]["uname"] + "\ n--------------------\ n"; for (int j = 0; J < Dt_detail. Rows.Count; J + +) {outPut + = "\ n" +dt_detail. rows[j]["fname"] + "\ T" + dt_detail.                            rows[j]["Fnum"]; if (Dt_detail. rows[j]["Remark"]. ToString () = "") {OutPut + = "*" + dt_detail. rows[j]["Remark"] + "\ n";//Menu "taste" remarks} updatestatus (Orderid.tostrin g (), Dt_detail. rows[j]["id"]. ToString (), ordertime);//Modify the print status} outPut + = "\ n" + DateTime.Now + "\n\n\n                        \n\n\n ";                        data = data = System.Text.Encoding.Default.GetBytes (OutPut); Stream. Write (data, 0, data. Length);//Output Text = ""; A classified print is emptied when it is finished. Cut the paper//stream.                        Write (Internal, 0, internal.length);                        data = System.Text.Encoding.Default.GetBytes (cut); Stream. Write (data, 0, data.                        Length); Stream. Write (bty_tmp, 0, Bty_tmp.                        Length);                    Bty_tmp = new byte[] {29, 86, 1, 49};                    }//data = System.Text.Encoding.Default.GetBytes (cut); Stream. Write (bty_tmp, 0, Bty_tmp.                    Length); Stream. Write (bty_tmp, 0, Bty_tmp.                Length); }//-----------------} catch {//printer is out of paper or tray open, no exception occurs, no special generation                Data is not lost.                           b = false; } finally {stream.                Close (); Stream.                Dispose (); Client.            Close ();        } return B; }

  

The 2-year-old catering program has been running for more than 1 years in some restaurants.

For thermal-sensitive blade printers,

Use in supermarkets, restaurants and other needs of small tickets to print the occasion.

When you finish printing, the paper is automatically cut.

There is a typesetting problem, the alignment is not very strict.

Http://www.cnblogs.com/chenqilong/archive/2013/04/18/3028358.html

C # Call Blade Small ticket printer

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.