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);

//获取当前贴图的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 '未发货' 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# 小票打印机打条形码_C#打印小票自带条形码打印相关推荐

  1. php调用云打印,打印小票

    在开发的过程中,遇到商家需要类似美团接单功能,当收到订单时,要用小票打印机,提示收到新的订单,并且打印,现在以蕊烨xp-c58h(4G)打印机为测试机,使用php后台调用 1.访问蕊烨云开发后台,注册 ...

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

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

  3. c#endread怎么打印出来_C# 小票打印机 ESC命令行方式打印

    private void btnPrinter_Click(object sender, EventArgs e) { #region ESC 热敏图像点阵像素点读取打印 //Bitmap bitma ...

  4. 转:C#并口热敏小票打印机打印位图

    最近一直在研究并口小票打印机打印图片问题,这也是第一次和硬件打交道,不过还好,最终成功了. 这是DEMO的窗体: 下面是打印所需要调用的代码: [html] view plain copy class ...

  5. C# 热敏打印机 小票打印机 打印图片

    最近一直在研究并口小票打印机打印图片问题,这也是第一次和硬件打交道,不过还好,最终成功了. 这是DEMO的窗体: 下面是打印所需要调用的代码: class LptControl { private s ...

  6. C#并口热敏小票打印机打印位图

    C#并口热敏小票打印机打印位图 原文:C#并口热敏小票打印机打印位图 最近一直在研究并口小票打印机打印图片问题,这也是第一次和硬件打交道,不过还好,最终成功了. 这是DEMO的窗体: 下面是打印所需要 ...

  7. php自动打印小票_错题打印机哪个品牌质量好?【2020双12】错题打印机品牌排行...

    2020年11月22日更新: 帮帮机销量3天增加1万: 帮帮机D1目前京东促销99元,击穿行业底价! 本文目录: 什么是错题打印机? 错题打印机能用普通纸吗,耗材贵吗? 高性价比错题打印机参数对比 1 ...

  8. 京瓷1110打印自检页_如何修改小票打印机、厨房打印机IP地址

    如何修改小票打印机.厨房打印机IP地址 在商业收银活动中,小票打印机是必不可少的设备,不管超市收银系统还是餐饮收银系统,都是常用设备.易坏设备,刚开业时购买的成套的收银设备,商家一般都给设置好小票机, ...

  9. 微信小程序调用小票打印机实现打印订单

    随着微信小程序的出现,微信已经完全占据了我们的生活,智能化互联网时代的到来,带给我们的便利我想不用说大家都是深有体会,随着小程序的火爆,随之带动着用户对打印的需求,那么,微信小程序是如何对接打印机的呢 ...

  10. python调用小票打印机_PyQt5中使用Qprinter打印热敏小票

    在<PyQt5中使用QWebChannel和内嵌网页进行js交互>一文中,我记录了如何使用QWebchannel与内嵌网页进行js交互,其根本目标在于使用Qt5调起打印机服务.在这篇文章中 ...

最新文章

  1. django安装mysql驱动_django安装mysql驱动
  2. 【存储知识学习】第四章-七种RAID-《大话存储》阅读笔记
  3. 关于mingw编译Qt时无法编译opengl es2(ANGLE)版本的问题
  4. python坐标怎么打_python导入坐标点的操作方法
  5. Shell 脚本编程之基础
  6. [转载] 大数据分析Python For循环教程
  7. python 数据库查询结果_python 数据库查询结果
  8. 理解 Delphi 的类(十) - 深入方法[2] - 参数分割
  9. Linux 命令(32)—— grep 命令
  10. eclipse中使用maven插件的时候,运行tomcat7:run的时候报错
  11. webpack的安装和执行
  12. excel常用函数汇总 excel最常用的八个函数 excel自动求减
  13. iOS面试题大全(附带答案)
  14. 数据表多次更新插入重复数据去重SQL
  15. html网页头部图片,网页头图设计技巧
  16. [计算机网络-03] 数据链路层
  17. 利用tcp三次握手,使用awl伪装MAC地址进行多线程SYN洪水攻击
  18. Win10电脑创建本地网站
  19. 用了都说好的Python专属无广告视频播放器,良心到想为它疯狂打call
  20. UPC10525: Dove 打扑克

热门文章

  1. 2022-2028年中国塑料导爆管行业市场调查研究及前瞻分析报告
  2. 卷积核输出特征图大小的计算 深度学习
  3. eclipse中导入web项目详细配置
  4. Jackson、FastJson快速入门(整合SpringMVC)
  5. 来谈谈Servlet~~
  6. 深度学习编译器综述The Deep Learning Compiler
  7. 云端一体全栈解决方案
  8. Camera Lens Coating
  9. PyTorch全连接ReLU网络
  10. 实时实例分割的Deep Snake:CVPR2020论文点评