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){//第三部,进行打印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);// 调用PrintDialog的ShowDialog函数显示打印对话框 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, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);}//DialogResult result = PrintDialog1.ShowDialog();//if (result == DialogResult.OK)// 弹出设置打印机,如果不需要设置,第三部可简写为   docToPrint.Print(); 则开始进行打印了//{//    // 开始打印 //    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));// 设置信息打印格式 e.Graphics.DrawString(strTou, printFont1, System.Drawing.Brushes.Black, 5, 5);e.Graphics.DrawString(text, printFont, System.Drawing.Brushes.Black, 10, 5);//获取当前贴图的Heightfloat 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 '未发货' when a.status = 1 then '已发货' when a.status = 2 then '已取消' when a.status = 3 then '发货中' else '' end) as status,(case isnull(a.pay_type,0) when  1 then '储值卡支付'  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("               苏州万家生鲜        \n");sw.Append("                                                \n");sw.Append("                                                \n");sw.Append("订单编号:" + dt.Rows[0]["sheet_no"].ToString() + "\n");sw.Append("支付方式:" + dt.Rows[0]["pay_type"].ToString() + "\n");sw.Append("成交时间:" + 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("物品               数量                  单价(¥)");sw.Append("品名               单价       数量       金额       " + "\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();//数量string price = dt_details.Rows[i]["price"].ToString();//单价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("                  总数:" + dt.Rows.Count + "\n");//计算合计金额:  sw.Append("                  合计:" + total.ToString("#0.00") + "\n");//合计金额sw.Append("                  现金:" + total.ToString("#0.00") + "\n");//实收现金sw.Append("                  找赎:" + 0 + "\n");//实收现金sw.Append("                                         \t\t" + "\n");sw.Append("---------------------配送留存---------------------------" + "\n");sw.Append("运单号:" + dt.Rows[0]["sheet_no"].ToString() + "\n");return sw.ToString();}#region 该函数动态添加空格,对齐小票public string AddSpace(string text, int length){text = text.PadRight(length, ' ');return text;}#endregion

C#打印小票自带条形码打印相关推荐

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

    private void btnReceipts_Click(object sender, EventArgs e) { string sheet_no = this.dgvOrders.Select ...

  2. C#打印小票(连续自动打印)

    #自动打印小票 方法一(后端生产打印代码) 注意前端需要引用(LodopFuncs.js,JsBarcode.all.min.js,jquery.js)当然还有安装打印机驱动还有Lodop的驱动 前端 ...

  3. java 打印 小票_java 调收银机打印小票

    public class MyPrint implementsPrintable{static Logger log = Logger.getLogger(MyPrint.class);//业务类 U ...

  4. Web使用热敏打印小票(IE环境)

    概述 在html页下使用Epson P60II 热敏纸下打印小票,使用的打印方案为调用window.print(). 代码实现 1.定义窗体,设置宽度和高度 <body onload=" ...

  5. Android集成佳博热敏打印机打印小票功能

    一.说明 最近公司项目需要做打印机打印小票功能,首先公司买了一个佳博小票打印机作为测试用机.然后在开发的过程中也遇到一些坑,在此记录一下. 二.集成过程 1. 下载开发文档 首先需要去其官网下载SDK ...

  6. flutter 打印小票

    Flutter 打印小票可以通过使用打印插件实现. 例如,可以使用 flutter_blue,它是一个蓝牙插件,可以用于与蓝牙打印机通信. 您可以在 pubspec.yaml 文件中声明对插件的依赖, ...

  7. C# 收银机顾显(客显)及打印小票(58热敏打印机)

    最近做winform收银机,设计顾显及打印小票总结. 1.顾显(串口COM1) 只涉及到总计,所以只是简单的功能. public static ClientDisplayResult Display( ...

  8. c# 小票机打印二维条码_C# winform 使用rdlc打印小票其中包含动态显示多条形码的解决方法...

    前言 最近做一个项目就是winform程序去控制设备,通过modbus-rtu协议去通讯.做的过程中上位机还牵扯到与其他系统对接的问题,当对接好其他系统数据后将数据打印出一个小票,上位机端用seria ...

  9. 自己整理出来的java实现打印机打印小票

    //实现Printable接口 用于创建打印内容 public class UserTicket implements Printable {private String name1;private ...

最新文章

  1. Dijkstra的算法
  2. Imagine dragons Dream中文歌词
  3. Jquery怎样返回上一页
  4. 计算机系统结构教程卷子,计算机系统结构试卷试题.docx
  5. python新手小项目实例-有没有简单一点的 Python 小例子或小项目?
  6. LeetCode-7.整数反转(越界问题)
  7. 【ubuntu操作系统】ubuntu系统下第一个C语言程序
  8. 在centos中如何用yum安装最新的yum源
  9. 字体的基础知识:中文字体区分练习
  10. 使用机器学习算法打造一个简单的“微博指数”
  11. Ubuntu下使用“Windows徽标键+R”打开终端
  12. [附案例]如何运营私域流量,提升用户终身价值,降低整体获客成本?
  13. 31、OPNET信道模型概述
  14. 傻白入门芯片设计,三大基本定律(十)
  15. wxpython下载安装过程
  16. 问卷生成选项,选项排序,设定答案
  17. ScrollView 嵌套 RecyclerView 高度自适应遇到的问题
  18. 深入理解JAVA虚拟机学习笔记11——JDK可视化工具-VisualVM以及案例分析
  19. 应该怎样读书,应该读什么书. 我阅读的经历与心得
  20. Android手机凡客项目介绍

热门文章

  1. 如何有效的快速处理恶意差评?
  2. 探究App推广之路:流量思维永不死 ☞ iphone中App store上架优化建议
  3. 专为《巫师3》打造 次世代RedEngine 3引擎公布
  4. 判断当前是在ie还是谷歌
  5. 爬取网易云某歌曲所有评论,并输出词云图
  6. 解读手机拍照的各个参数(延时摄影)
  7. addon游戏_MOD Herobrine Addon
  8. 【读书随记】周末充电,学习Java更轻松(文末送书)
  9. Win10如何用命令打开控制面板
  10. 2020年保育员(中级)多少分及格及保育员(中级)模拟考试系统