Click here to Skip to main content
15,909,332 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
pls help me sir,
iam new to this printing...
I need to directly print to a dotmatrix printer where the contents are from a datagridview
how can i acheive this?

eg:

SuperMarket
invoiceNo:1 invoiceDate:25/6/2013
Credit/Cash Customer:Crazy Twister
--------------------------------------------------------------
SlNo Item Qty Rate total
1 a 10 5 5o
2

--------------------------------------------------------------
grandTotal 50
Thanks

Please help me sir
Thanks inadvance
Posted

 
Share this answer
 
Comments
crazytwister 14-Dec-13 4:10am    
it just says about a textfile print,bt i need to print from a datagrid view
Use this MSKB code to send raw printer commands to the dot matrix printer http://support.microsoft.com/kb/322091[^]
Be sure you send the correct commands based on the language supported by your printer that it's likely to be ESC/P but check this with your printer manufacturer.
 
Share this answer
 
may be this code helps you

C#
class clsPrintSettings
       {
           // Printing commands are depends on the Dotmatrix printer that we are using

           System.IO.StreamWriter rdr;
           private string Bold_On = "";
           private string Bold_Off = "";
           private string Width_On = ""; //Chr(27) + Chr(87) + Chr(49) 'W1
           private string Width_Off = "";
           public string BillType;
           public string BillNo;
           public string BillDt;
           public string tran_type;
           public string Discount;
           public string bill_amt;
           public string NetAmount;
           public string reciept_amount;
           public decimal MRPTotal = 0, SavedTotal = 0;
           public decimal count;
           public System.Data.DataTable dt_print;

           public clsPrintSettings()
           {
               rdr = new System.IO.StreamWriter("bill.txt");
           }
           public void Close()
           {
               rdr.Close();
           }
           public void PrintHeader()
           {
               rdr.WriteLine(Bold_On + "HotelApps, KERALA" + Bold_Off);
               PrintLine();
               rdr.WriteLine("Bill NO   : " + BillNo);
               rdr.WriteLine("Bill Date : " + BillDt);
               PrintLine();
               rdr.WriteLine(Bold_On + Width_On + BillType + Width_Off + Bold_Off);
               PrintLine();
           }

           public void PrintDetails()
           {
               rdr.WriteLine("   SLNo  |     Item Name |     Quantity  |       Amount  |        Total  |");
               int i;
               PrintLine();
               for (i = 0; i < count - 1; i++)
               {
                   rdr.Write("{0,10}", GetFormatedText(dt_print.Rows[i][0].ToString(), 10) + "|");
                   rdr.Write("{0,16}", GetFormatedText(dt_print.Rows[i][1].ToString(), 10) + "|");
                   rdr.Write("{0,16}", GetFormatedText(dt_print.Rows[i][2].ToString(), 10) + "|");
                   rdr.Write("{0,16}", GetFormatedText(dt_print.Rows[i][3].ToString(), 10) + "|");
                   rdr.Write("{0,16}", GetFormatedText(dt_print.Rows[i][4].ToString(), 10) + "|");
                   rdr.WriteLine("");
               }
           }

           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 < 3; nos++)
                       Cont = Cont + " ";
               }
               return (Cont);
           }

           public void PrintFooter()
           {
               PrintLine();
               rdr.WriteLine();
               rdr.WriteLine("                                                 Total          : " + bill_amt);
               rdr.WriteLine("                                                 Discount       : " + Discount);
               rdr.WriteLine("                                                 Net Amount     : " + NetAmount);
               rdr.WriteLine("                                                 Reciept Amount : " + reciept_amount);
               rdr.WriteLine();
               PrintLine();
               rdr.WriteLine("Transaction Type : " + tran_type);
               PrintLine();
               rdr.WriteLine("Thank You");
               PrintLine();
           }

           public void PrintLine()
           {
               int i;
               string Lstr = "";
               for (i = 1; i <= 75; i++)
               {
                   Lstr = Lstr + "-";
               }
               rdr.WriteLine(Lstr);
           }

           public void SkipLine(int LineNos)
           {
               int i;
               for (i = 1; i <= 5; i++)
               {
                   rdr.WriteLine("");
               }
           }
       }

       private void PrintBill()
       {
           if (MessageBox.Show("Do You want to Print the Bill", "Sales Bill", MessageBoxButtons.OKCancel) == DialogResult.OK)
           {
               clsPrintSettings obj = new clsPrintSettings();
               obj.BillType = "RECIEPT";
               obj.BillNo = lbl_bill_no1.Text;
               obj.BillDt = lbl_bill_date.Text;
               obj.tran_type = comboBox1.Text;
               obj.bill_amt = txt_bill_amt.Text;
               obj.Discount = txt_discount.Text;
               obj.NetAmount = txt_net_amt.Text;
               obj.reciept_amount = txt_reci_amt.Text;
               DataTable dt1_print = new DataTable();
               dt1_print.Columns.Add(new DataColumn("SLNo", typeof(string)));
               dt1_print.Columns.Add(new DataColumn("Item_Name", typeof(string)));
               dt1_print.Columns.Add(new DataColumn("Quantity", typeof(string)));
               dt1_print.Columns.Add(new DataColumn("Amount", typeof(string)));
               dt1_print.Columns.Add(new DataColumn("Total", typeof(string)));
               DataRow newrow = dt1_print.NewRow();
               obj.count = dgrid_kot_entry.RowCount;
               for (int i = 0; i < dgrid_kot_entry.RowCount - 1; i++)
               {
                   DataRow dr = dt1_print.NewRow();
                   dr["SLNo"] = dgrid_kot_entry.Rows[i].Cells[0].Value;
                   dr["Item_Name"] = dgrid_kot_entry.Rows[i].Cells[2].Value;
                   dr["Quantity"] = dgrid_kot_entry.Rows[i].Cells[3].Value;
                   dr["Amount"] = dgrid_kot_entry.Rows[i].Cells[4].Value;
                   dr["Total"] = dgrid_kot_entry.Rows[i].Cells[5].Value;
                   dt1_print.Rows.Add(dr);
               }
               obj.dt_print = dt1_print;
               obj.PrintHeader();
               obj.PrintDetails();
               obj.PrintFooter();
               obj.SkipLine(3);
               obj.Close();
               obj = null;
           }
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900