This document discusses printing bills from a .NET application to a dot matrix printer. It provides code for a PrintSettings class that handles printing formatting and contains methods for printing the header, details, and footer sections of a bill. The bill data is retrieved from a database and written to a text file. A batch file is also created to print the text file to the default printer port.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
DOS Like Printing in C# .Net On Dotmatrix Printers
This document discusses printing bills from a .NET application to a dot matrix printer. It provides code for a PrintSettings class that handles printing formatting and contains methods for printing the header, details, and footer sections of a bill. The bill data is retrieved from a database and written to a text file. A batch file is also created to print the text file to the default printer port.
Original Title
Vb.net - DOS Like Printing in c# .Net on Dotmatrix Printers
This document discusses printing bills from a .NET application to a dot matrix printer. It provides code for a PrintSettings class that handles printing formatting and contains methods for printing the header, details, and footer sections of a bill. The bill data is retrieved from a database and written to a text file. A batch file is also created to print the text file to the default printer port.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
Download as txt, pdf, or txt
0 ratings0% found this document useful (0 votes)
1K views5 pages
DOS Like Printing in C# .Net On Dotmatrix Printers
This document discusses printing bills from a .NET application to a dot matrix printer. It provides code for a PrintSettings class that handles printing formatting and contains methods for printing the header, details, and footer sections of a bill. The bill data is retrieved from a database and written to a text file. A batch file is also created to print the text file to the default printer port.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
Download as txt, pdf, or txt
You are on page 1of 5
DOS like printing in c# .
net on dotmatrix printers
http://www.dotnetspider.com/resources/40152-DOS-like-printing-c-net-dotmatrix-pr inters.aspx Here am using a clsPrintSettings class , which contains all print related method s Bill is generated from the database and write it to text file Code For Printing Class public class clsPrintSettings { // Printing commands are depends on the Dotmatrix printer that we are using System.IO.StreamWriter rdr; private string Bold_On = "_G"; private string Bold_Off = "_H"; private string Width_On = "_W1"; //Chr(27) + Chr(87) + Chr(49) ' W1 private string Width_Off = "_W0"; //Public Const Compress_On = "¤" 'Chr(15) '¤" //Public Const Compress_Off = "_" 'Chr(18) '_ private string ELITE_PITCH = "_M"; private string Compress_On = "_ð ; //Chr(15) '¤" private string Compress_Off = "_"; private int ColWidth=60; public string BillType; public string BillNo; public string BillDt; public string Clerk; public string ClientName=""; public decimal Discount; public decimal TotalAmt; public decimal NetAmount; public decimal MRPTotal=0,SavedTotal=0; public System.Data.DataTable dt; public clsPrintSettings() { rdr=new System.IO.StreamWriter("bill.txt"); //rdr.AutoFlush(); } public void Close() { rdr.Close(); } public void PrintHeader() { //PrintLine(); rdr.WriteLine(Bold_On + "ABC SUPER MARKET, KERALA" + Bol d_Off); rdr.WriteLine("KGST : 23040117 DT 1/1/2001"); rdr.WriteLine("CST : 23040117 DT 1/1/2001"); PrintLine(); rdr.WriteLine(Bold_On + Width_On + BillType + Width_Off + Bold_Off ); PrintLine(); rdr.WriteLine("Customer : " +ClientName); PrintLine(); } public void PrintDetails() { rdr.WriteLine("SLNo |Name |Qty|MRP |Ra te |T.Amt |Value "); int i; PrintLine(); for(i=0;i { rdr.Write("{0,-4}",GetFormatedText(Convert.ToStr ing(i+1),5)+ "|" ); rdr.Write("{0,-20}", GetFormatedText(dt.Rows[i]. ItemArray[1].ToString(),21) + "|"); rdr.Write("{0,-2}",GetFormatedText(Convert.ToStr ing(Math.Round(Convert.ToDecimal(dt.Rows[i].ItemArray[2].ToString()),0)),3)+ "|" ); rdr.Write("{0,-6}",GetFormatedText(Convert.ToStr ing(Math.Round(Convert.ToDecimal(dt.Rows[i].ItemArray[3].ToString()),2)),6)+ "|" ); rdr.Write("{0,-6}",GetFormatedText(Convert.ToStr ing(Math.Round(Convert.ToDecimal(dt.Rows[i].ItemArray[4].ToString()),2)),6)+ "|" ); rdr.Write("{0,-6}",GetFormatedText(Convert.ToStr ing(Math.Round(Convert.ToDecimal(dt.Rows[i].ItemArray[5].ToString()),2)),6)+ "|" ); rdr.Write("{0,-6}",GetFormatedText(Convert.ToStr ing(Math.Round(Convert.ToDecimal(dt.Rows[i].ItemArray[6].ToString()),2)),6)+ "") ; rdr.WriteLine(""); MRPTotal= MRPTotal+ (Convert.ToDecimal(dt.Rows[i ].ItemArray[2].ToString())*Convert.ToDecimal(dt.Rows[i].ItemArray[3].ToString()) ); } } private string GetFormatedText(string Cont,int Length) { int rLoc=Length-Cont.Length; if(rLoc<0) { Cont =Cont.Substring(0,Length); } else { int nos; for(nos=0;nos Cont =Co nt + " "; } return(Cont); } private string GetRightFormatedText(string Cont,int Length) { int rLoc=Length-Cont.Length; if(rLoc<0) { Cont =Cont.Substring(0,Length); } else { int nos; string space=""; for(nos=0;nos space += " "; Cont = space + Cont; } return(Cont); } private string GetCenterdFormatedText(string Cont,int Length) { int rLoc=Length-Cont.Length; if(rLoc<0) { Cont =Cont.Substring(0,Length); } else { int nos; string space=""; for(nos=0;nos space += " "; Cont = space + Cont; } return(Cont); } public void PrintFooter() { PrintLine(); rdr.WriteLine(" Tot al : " + Math.Round(TotalAmt,2).ToString() ); rdr.WriteLine(" Dis count : " + Math.Round(Discount,2).ToString() ); rdr.WriteLine(" Net Amount : " + Math.Round(NetAmount,2).ToString() ); Miscellaneous.NumToString objMisc=new Miscellaneous.NumT oString(); SavedTotal=MRPTotal-TotalAmt; rdr.WriteLine(Compress_On + "You Have Saved Rs. " + Math .Round(SavedTotal,2).ToString() + Compress_Off); PrintLine(); rdr.WriteLine("Clerk : " + Clerk); rdr.WriteLine("Counter : " + clsSystem.MyCounter.ToStrin g()); rdr.WriteLine(); rdr.WriteLine("Please check your items before leavining the counter"); rdr.WriteLine("Goods once sold will not be taken back"); // PrintLine(); } public void PrintLine() { int i; string Lstr=""; for(i=1;i { Lstr=Lstr +"-"; } rdr.WriteLine(Lstr); } public void SkipLine(int LineNos) { int i; for(i=1;i { rdr.WriteLine(""); } } public void ReverseSkip(int LineNos) { int i; for(i=1;i { rdr.WriteLine(Convert.ToChar(27) + "j" + Convert .ToChar(36 * LineNos)); } } public void PrintBuffer() { System.Diagnostics.Process.Start("bill.bat"); } }