winfrom小票打印代码
来源:互联网 发布:淘宝csv数据包上传 编辑:程序博客网 时间:2024/04/30 05:04
/// <summary>
/// 打印事件
/// </summary>
private void SmallTicketPrint()
{
PrintDialog PrintDialog1 = new PrintDialog();
PrintDocument docToPrint = new PrintDocument();
docToPrint.PrintPage += new PrintPageEventHandler(PrintEventPage);
PrintDialog1.AllowSomePages = true;
PrintDialog1.ShowHelp = true;
PrintDialog1.Document = docToPrint;//把PrintDialog的Document属性设为上面配置好的PrintDocument的实例
PrintController printController = new StandardPrintController();
docToPrint.PrintController = printController;
DialogResult result = PrintDialog1.ShowDialog();//调用PrintDialog的ShowDialog函数显示打印对话框
//for (int i = 0; i < smallTicketPrintList.Count; i++) //连续打印
//{
// count = i;
//If the result is OK then print the document.
if (result == DialogResult.OK)
{
docToPrint.Print();//开始打印
}
//}
}
/// <summary>
/// 打印排版
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void PrintEventPage(object sender, PrintPageEventArgs e)
{
Font titleFont = new Font("宋体", 14, FontStyle.Bold);//标题字体
Font title1Font = new Font("宋体", 9, FontStyle.Bold);//标题字体
Font fntTxt = new Font("宋体", 7, FontStyle.Regular); //正文文字
Font contentTxt = new Font("宋体", 8, FontStyle.Regular); //正文文字
Brush brush = new SolidBrush(Color.Black);//画刷
Pen pen = new Pen(Color.Black); //线条颜色
StringFormat centerFormat = new StringFormat();
centerFormat.Alignment = StringAlignment.Center; //居中
StringFormat rightFormat = new StringFormat();
rightFormat.Alignment = StringAlignment.Far; //靠右
string dataType = string.Empty;
if (comboBox2.SelectedItem != null) dataType = comboBox2.SelectedItem.ToString();
try
{
//new RectangleF(x坐标, y坐标, 行宽度, 行高度)
e.Graphics.DrawString(dataType, titleFont, brush, new RectangleF(0, 10, 186, 30), centerFormat); //标题
e.Graphics.DrawString("-----------------------------", titleFont, brush, new RectangleF(0, 30, 186, 30), centerFormat);
e.Graphics.DrawString("商户存根", title1Font, brush, new RectangleF(0, 50, 186, 30), rightFormat); //副标题数据
e.Graphics.DrawString("商户名称(MERCHANT NAME)", fntTxt, brush, new RectangleF(0, 70, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].RetailerName, contentTxt, brush, new RectangleF(0, 85, 186, 30));
e.Graphics.DrawString("POS标记(POS TAG)", fntTxt, brush, new RectangleF(0, 115, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].POSSN, contentTxt, brush, new RectangleF(0, 128, 186, 30));
e.Graphics.DrawString("会员卡号(MEMBER CARD)", fntTxt, brush, new RectangleF(0, 145, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].CardNo, contentTxt, brush, new RectangleF(0, 160, 186, 30));
e.Graphics.DrawString("会员(MEMBER)", contentTxt, brush, new RectangleF(0, 175, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].MemberMobile.Cover(), contentTxt, brush, new RectangleF(0, 175, 186, 30), rightFormat);
e.Graphics.DrawString("交易类型(TRANS TYPE)", contentTxt, brush, new RectangleF(0, 190, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].TradeTitle.Substring(smallTicketPrintList[count].TradeTitle.Length - 2, 2), contentTxt, brush, new RectangleF(0, 190, 186, 30), rightFormat);
e.Graphics.DrawString("金额(AMOUNT)", contentTxt, brush, new RectangleF(0, 205, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].TotalAmt.ToString(), contentTxt, brush, new RectangleF(0, 205, 186, 30), rightFormat);
e.Graphics.DrawString("积分抵扣(POINTS DEDUCTED)", contentTxt, brush, new RectangleF(0, 220, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].RebatePaid.ToString(), contentTxt, brush, new RectangleF(0, 220, 186, 30), rightFormat);
e.Graphics.DrawString("实付金额(PAID AMOUNT)", contentTxt, brush, new RectangleF(0, 235, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].CashPaid.ToString(), contentTxt, brush, new RectangleF(0, 235, 186, 30), rightFormat);
e.Graphics.DrawString("积分奖励(REWARDS POINTS)", contentTxt, brush, new RectangleF(0, 250, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].RewardAmount.ToString(), contentTxt, brush, new RectangleF(0, 250, 186, 30), rightFormat);
e.Graphics.DrawString("-----------------------------", titleFont, brush, new RectangleF(0, 265, 186, 30));
e.Graphics.DrawString("账户余额(BALANCE)", contentTxt, brush, new RectangleF(0, 290, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].CashBalance.ToString(), contentTxt, brush, new RectangleF(0, 290, 186, 30), rightFormat);
e.Graphics.DrawString("账户积分(POITNTS)", contentTxt, brush, new RectangleF(0, 305, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].RebateBalance.ToString(), contentTxt, brush, new RectangleF(0, 305, 186, 30), rightFormat);
e.Graphics.DrawString("订单单号(ORDER NUMBER)", fntTxt, brush, new RectangleF(0, 325, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].CaseNo, contentTxt, brush, new RectangleF(0, 340, 186, 30));
e.Graphics.DrawString("日期/时间(DATE/TIME)", fntTxt, brush, new RectangleF(0, 360, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].TradeDatetime.ToString("yyyy/MM/dd HH:mm:ss"), contentTxt, brush, new RectangleF(0, 375, 186, 30));
e.Graphics.DrawString("持卡人签名(CARDHOLDER SIGNATURE)", fntTxt, brush, new RectangleF(0, 390, 186, 30));
e.Graphics.DrawString("-----------------------------", titleFont, brush, new RectangleF(0, 430, 186, 30));
e.Graphics.DrawString("本人确认以上交易同意将其计入本卡账户", fntTxt, brush, new RectangleF(0, 455, 186, 30));
e.Graphics.DrawString("I ACKNOWLEDGE SATISFACTORY RECEIPT", fntTxt, brush, new RectangleF(0, 470, 186, 30));
e.Graphics.DrawString("OF RELATIVE COODS/SERVICE", fntTxt, brush, new RectangleF(0, 485, 186, 30));
}
catch
{
MessageBox.Show(this, "数据库连接错误,打印失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
/// 打印事件
/// </summary>
private void SmallTicketPrint()
{
PrintDialog PrintDialog1 = new PrintDialog();
PrintDocument docToPrint = new PrintDocument();
docToPrint.PrintPage += new PrintPageEventHandler(PrintEventPage);
PrintDialog1.AllowSomePages = true;
PrintDialog1.ShowHelp = true;
PrintDialog1.Document = docToPrint;//把PrintDialog的Document属性设为上面配置好的PrintDocument的实例
PrintController printController = new StandardPrintController();
docToPrint.PrintController = printController;
DialogResult result = PrintDialog1.ShowDialog();//调用PrintDialog的ShowDialog函数显示打印对话框
//for (int i = 0; i < smallTicketPrintList.Count; i++) //连续打印
//{
// count = i;
//If the result is OK then print the document.
if (result == DialogResult.OK)
{
docToPrint.Print();//开始打印
}
//}
}
/// <summary>
/// 打印排版
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void PrintEventPage(object sender, PrintPageEventArgs e)
{
Font titleFont = new Font("宋体", 14, FontStyle.Bold);//标题字体
Font title1Font = new Font("宋体", 9, FontStyle.Bold);//标题字体
Font fntTxt = new Font("宋体", 7, FontStyle.Regular); //正文文字
Font contentTxt = new Font("宋体", 8, FontStyle.Regular); //正文文字
Brush brush = new SolidBrush(Color.Black);//画刷
Pen pen = new Pen(Color.Black); //线条颜色
StringFormat centerFormat = new StringFormat();
centerFormat.Alignment = StringAlignment.Center; //居中
StringFormat rightFormat = new StringFormat();
rightFormat.Alignment = StringAlignment.Far; //靠右
string dataType = string.Empty;
if (comboBox2.SelectedItem != null) dataType = comboBox2.SelectedItem.ToString();
try
{
//new RectangleF(x坐标, y坐标, 行宽度, 行高度)
e.Graphics.DrawString(dataType, titleFont, brush, new RectangleF(0, 10, 186, 30), centerFormat); //标题
e.Graphics.DrawString("-----------------------------", titleFont, brush, new RectangleF(0, 30, 186, 30), centerFormat);
e.Graphics.DrawString("商户存根", title1Font, brush, new RectangleF(0, 50, 186, 30), rightFormat); //副标题数据
e.Graphics.DrawString("商户名称(MERCHANT NAME)", fntTxt, brush, new RectangleF(0, 70, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].RetailerName, contentTxt, brush, new RectangleF(0, 85, 186, 30));
e.Graphics.DrawString("POS标记(POS TAG)", fntTxt, brush, new RectangleF(0, 115, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].POSSN, contentTxt, brush, new RectangleF(0, 128, 186, 30));
e.Graphics.DrawString("会员卡号(MEMBER CARD)", fntTxt, brush, new RectangleF(0, 145, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].CardNo, contentTxt, brush, new RectangleF(0, 160, 186, 30));
e.Graphics.DrawString("会员(MEMBER)", contentTxt, brush, new RectangleF(0, 175, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].MemberMobile.Cover(), contentTxt, brush, new RectangleF(0, 175, 186, 30), rightFormat);
e.Graphics.DrawString("交易类型(TRANS TYPE)", contentTxt, brush, new RectangleF(0, 190, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].TradeTitle.Substring(smallTicketPrintList[count].TradeTitle.Length - 2, 2), contentTxt, brush, new RectangleF(0, 190, 186, 30), rightFormat);
e.Graphics.DrawString("金额(AMOUNT)", contentTxt, brush, new RectangleF(0, 205, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].TotalAmt.ToString(), contentTxt, brush, new RectangleF(0, 205, 186, 30), rightFormat);
e.Graphics.DrawString("积分抵扣(POINTS DEDUCTED)", contentTxt, brush, new RectangleF(0, 220, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].RebatePaid.ToString(), contentTxt, brush, new RectangleF(0, 220, 186, 30), rightFormat);
e.Graphics.DrawString("实付金额(PAID AMOUNT)", contentTxt, brush, new RectangleF(0, 235, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].CashPaid.ToString(), contentTxt, brush, new RectangleF(0, 235, 186, 30), rightFormat);
e.Graphics.DrawString("积分奖励(REWARDS POINTS)", contentTxt, brush, new RectangleF(0, 250, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].RewardAmount.ToString(), contentTxt, brush, new RectangleF(0, 250, 186, 30), rightFormat);
e.Graphics.DrawString("-----------------------------", titleFont, brush, new RectangleF(0, 265, 186, 30));
e.Graphics.DrawString("账户余额(BALANCE)", contentTxt, brush, new RectangleF(0, 290, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].CashBalance.ToString(), contentTxt, brush, new RectangleF(0, 290, 186, 30), rightFormat);
e.Graphics.DrawString("账户积分(POITNTS)", contentTxt, brush, new RectangleF(0, 305, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].RebateBalance.ToString(), contentTxt, brush, new RectangleF(0, 305, 186, 30), rightFormat);
e.Graphics.DrawString("订单单号(ORDER NUMBER)", fntTxt, brush, new RectangleF(0, 325, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].CaseNo, contentTxt, brush, new RectangleF(0, 340, 186, 30));
e.Graphics.DrawString("日期/时间(DATE/TIME)", fntTxt, brush, new RectangleF(0, 360, 186, 30));
e.Graphics.DrawString(smallTicketPrintList[count].TradeDatetime.ToString("yyyy/MM/dd HH:mm:ss"), contentTxt, brush, new RectangleF(0, 375, 186, 30));
e.Graphics.DrawString("持卡人签名(CARDHOLDER SIGNATURE)", fntTxt, brush, new RectangleF(0, 390, 186, 30));
e.Graphics.DrawString("-----------------------------", titleFont, brush, new RectangleF(0, 430, 186, 30));
e.Graphics.DrawString("本人确认以上交易同意将其计入本卡账户", fntTxt, brush, new RectangleF(0, 455, 186, 30));
e.Graphics.DrawString("I ACKNOWLEDGE SATISFACTORY RECEIPT", fntTxt, brush, new RectangleF(0, 470, 186, 30));
e.Graphics.DrawString("OF RELATIVE COODS/SERVICE", fntTxt, brush, new RectangleF(0, 485, 186, 30));
}
catch
{
MessageBox.Show(this, "数据库连接错误,打印失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
0 0
- winfrom小票打印代码
- 小票打印代码
- WinFrom开发小技巧
- winfrom 小技巧
- winfrom个人小闹钟
- winfrom小知识点
- winfrom生成图片 打印一体
- 百度翻译新API C#代码(winfrom,webform....)小程序
- [小技巧]winfrom使用多线程
- POS小票打印
- POS小票打印
- c#小票打印
- 打印小票
- 小票乱码打印
- 蓝牙打印小票
- 打印小票
- 打印小票
- 购物小票打印
- 【Hibernate】——一对一关联映射
- 630A
- Vue.js 快速搭建
- 任意两不同坐标系的相互转换
- ElasticSearch 疯狂学习 第三季(自学)
- winfrom小票打印代码
- python使用rabbitmq实例二,工作队列
- Centos下安装JDK
- Java特殊重写overwrite
- 安卓开发操作状态栏的工具类
- H264码流结构分析
- python使用rabbitmq实例三,交换机
- js高级程序设计笔记3--继承
- 通过React.cloneElement给所有子元素添加属性