An@nd Rajan10
может быть этот код вам поможет
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;
}
}