打印到dotmatrix打印机 [英] print to dotmatrix printer
问题描述
请帮助我先生,
我对这个打印很新...
我需要直接打印到dotmatrix打印机,其内容来自datagridview
我怎么能实现这个?
例如:
SuperMarket >
invoiceNo:1 invoiceDate:25/6/2013
信用卡/现金客户:Crazy Twister
------------ --------------------------------------------------
SlNo项目数量总费用
1 a 10 5 5o
2
------------------------------------------------- -------------
grandTotal 50
谢谢
请帮忙我先生
谢谢inadvance
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
推荐答案
试试 C#中的线程打印机类 [ ^ ]。
使用此MSKB代码将原始打印机命令发送到点阵打印机 http://support.microsoft.com/kb/322091 [ ^ ]
确保根据支持的语言发送正确的命令您的打印机可能是ESC / P但请与您的打印机制造商联系。
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.
可能是此代码可以帮助您
may be this code helps you
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;
}
}
这篇关于打印到dotmatrix打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!