日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 人文社科 > 生活经验 >内容正文

生活经验

c# 小票打印机打条形码_C#打印小票自带条形码打印

發(fā)布時(shí)間:2023/11/27 生活经验 58 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c# 小票打印机打条形码_C#打印小票自带条形码打印 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

private void btnReceipts_Click(object sender, EventArgs e)

{

string sheet_no = this.dgvOrders.SelectedRows[0].Cells[0].Value.ToString();

jzPrint(sheet_no);

}

private void jzPrint(string sheet_no)

{

//第三部,進(jìn)行打印

System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();

PrintDialog1.AllowSomePages = true;

PrintDialog1.ShowHelp = true;

PrintDialog1.Document = docToPrint;

this.docToPrint.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(docToPrint_PrintPage);

// 調(diào)用PrintDialog的ShowDialog函數(shù)顯示打印對(duì)話框

PrintDocument printDocument = new PrintDocument();

printDocument.PrintPage += new PrintPageEventHandler(this.docToPrint_PrintPage);

PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();

printPreviewDialog.Document = printDocument;

try

{

printPreviewDialog.ShowDialog();

}

catch (Exception excep)

{

MessageBox.Show(excep.Message, "打印出錯(cuò)", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

//DialogResult result = PrintDialog1.ShowDialog();

//if (result == DialogResult.OK)// 彈出設(shè)置打印機(jī),如果不需要設(shè)置,第三部可簡(jiǎn)寫為 docToPrint.Print(); 則開始進(jìn)行打印了

//{

// // 開始打印

// docToPrint.Print();

//}

}

private void docToPrint_PrintPage(object sender, PrintPageEventArgs e)

{

string sheet_no = this.dgvOrders.SelectedRows[0].Cells[0].Value.ToString();// "WX-2016323163452";

string text = null;

// 信息頭

string strTou = string.Empty;

System.Drawing.Font printFont = new System.Drawing.Font

("Arial", 8, System.Drawing.FontStyle.Regular);

System.Drawing.Font printFont1 = new System.Drawing.Font

("Arial", 11, System.Drawing.FontStyle.Regular);

text = GetTicketString(sheet_no);

string body = text;

// 獲取信息頭

strTou = text.Substring(0, 40);

//信息其他部分

text = text.Substring(40, (text.Length - 40));

// 設(shè)置信息打印格式

e.Graphics.DrawString(strTou, printFont1, System.Drawing.Brushes.Black, 5, 5);

e.Graphics.DrawString(text, printFont, System.Drawing.Brushes.Black, 10, 5);

//獲取當(dāng)前貼圖的Height

float now_x = e.Graphics.MeasureString(body, printFont).Height;

//條形碼打印

BarCode.Code128 c = new BarCode.Code128();

Bitmap bit = c.GetCodeImage(sheet_no, BarCode.Code128.Encode.Code128A);

e.Graphics.DrawImage(bit, 10, 5 + now_x, 220, 50);

//客戶簽字生成

StringBuilder foot = new StringBuilder();

foot.Append("-----------------------------------------------------\n");

foot.Append("客戶簽名:\n");

foot.Append(" \n");

foot.Append(" \n");

foot.Append(" \n");

foot.Append("-----------------------------------------------------");

e.Graphics.DrawString(foot.ToString(), printFont, System.Drawing.Brushes.Black, 10, 60 + now_x);

}

private string GetTicketString(string sheet_no)

{

string sql_order = string.Format(@"select a.sheet_no,a.orderman,a.ordertel,a.oper_date,

sum(a.real_qty) as real_qty,sum((a.price*a.real_qty)) as amt,

sum(a.Fact_real_qty) as Fact_real_qty,sum(a.Fact_Total) as fact_amt,

(sum( a.price*a.real_qty) - sum(a.Fact_Total)) as diff,

(case when isnull(a.status,9) = 0 then '未發(fā)貨' when a.status = 1 then '已發(fā)貨' when a.status = 2 then '已取消' when a.status = 3 then '發(fā)貨中' else '' end) as status,(case isnull(a.pay_type,0) when 1 then '儲(chǔ)值卡支付' when 2 then '微信支付' else '線下支付' end) as pay_type,

(case when isnull(a.deal_type,1) = 1 then '送貨上門' else '門店自提' end) as deal_type,

(case when isnull(a.paystatus,0) = 1 then '已支付' else '未支付' end) as paystatus,ISNULL(send_address,address) as send_address,memo

FROM t_order_bill_weixin a left join t_sys_operator o on o.oper_id=a.modify_oper

where a.sheet_no='{0}'

group by a.sheet_no,a.orderman,a.ordertel,a.oper_date,a.branch_no,a.status,pay_type,deal_type,send_address,memo,

address,paystatus,o.oper_name,a.dealtime

", sheet_no);

DataTable dt = Query.ProcessSql(sql_order, Common.PublicDAL.DbName);

//收銀打印

//string path = Application.StartupPath.ToString() + "\\ticket.txt";//exe程序所在的路徑

StringBuilder sw = new StringBuilder();

sw.Append(" 蘇州萬(wàn)家生鮮 \n");

sw.Append(" \n");

sw.Append(" \n");

sw.Append("訂單編號(hào):" + dt.Rows[0]["sheet_no"].ToString() + "\n");

sw.Append("支付方式:" + dt.Rows[0]["pay_type"].ToString() + "\n");

sw.Append("成交時(shí)間:" + dt.Rows[0]["oper_date"].ToString() + "\n");

sw.Append("客戶姓名:" + dt.Rows[0]["orderman"].ToString() + "\n");

sw.Append("客戶電話:" + dt.Rows[0]["ordertel"].ToString() + "\n");

sw.Append("客戶地址:" + dt.Rows[0]["send_address"].ToString() + "\n");

sw.Append("訂單備注:" + dt.Rows[0]["memo"].ToString() + "\n");

sw.Append("-----------------------------------------------------" + "\n");

string sql_order_details = string.Format(@"select item_name, real_qty,price,(real_qty*price) as total from t_order_bill_weixin where sheet_no='{0}' ", sheet_no);

DataTable dt_details = Query.ProcessSql(sql_order_details, Common.PublicDAL.DbName);

//sw.Append("物品 數(shù)量 單價(jià)(¥)");

sw.Append("品名 單價(jià) 數(shù)量 金額 " + "\n");

sw.Append("-----------------------------------------------------" + "\n");

int nums = 20;

int prices = 12;

decimal total = 0;

for (int i = 0; i < dt.Rows.Count; i++)

{

string name = dt_details.Rows[i]["item_name"].ToString();//獲取該行的物品名稱

string num = dt_details.Rows[i]["real_qty"].ToString();//數(shù)量

string price = dt_details.Rows[i]["price"].ToString();//單價(jià)

total += Convert.ToDecimal(num) * Convert.ToDecimal(price);

int numlength = System.Text.Encoding.Default.GetBytes(num).Length;

if (numlength < nums)

{

num = AddSpace(num, nums - numlength);

}

int pricelength = System.Text.Encoding.Default.GetBytes(price).Length;

if (pricelength < prices)

{

price = AddSpace(price, prices - pricelength);

}

sw.Append(name + "\n");

sw.Append(" " + Convert.ToDecimal(price).ToString("#0.00") + " " + Convert.ToDecimal(num).ToString("#0.00") + " " + (Convert.ToDecimal(price) * Convert.ToDecimal(num)).ToString("#0.00") + " " + "\n");

}

sw.Append("-----------------------------------------------------" + "\n");

sw.Append(" 總數(shù):" + dt.Rows.Count + "\n");

//計(jì)算合計(jì)金額:

sw.Append(" 合計(jì):" + total.ToString("#0.00") + "\n");//合計(jì)金額

sw.Append(" 現(xiàn)金:" + total.ToString("#0.00") + "\n");//實(shí)收現(xiàn)金

sw.Append(" 找贖:" + 0 + "\n");//實(shí)收現(xiàn)金

sw.Append(" \t\t" + "\n");

sw.Append("---------------------配送留存---------------------------" + "\n");

sw.Append("運(yùn)單號(hào):" + dt.Rows[0]["sheet_no"].ToString() + "\n");

return sw.ToString();

}

#region 該函數(shù)動(dòng)態(tài)添加空格,對(duì)齊小票

public string AddSpace(string text, int length)

{

text = text.PadRight(length, ' ');

return text;

}

#endregion

總結(jié)

以上是生活随笔為你收集整理的c# 小票打印机打条形码_C#打印小票自带条形码打印的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。