主要是通过XML文件做模板来实现打印;
模板如下:1<?xml version="1.0" encoding="utf-8" ?>
2<!--
3说明:
4justification
5center 中间对齐
6right 右对齐
7left 左对齐
8style
90 正常
101 倍宽
112 倍高
123 四倍角
13
14color
150 黑色
161 红色
17-->
18<root>
19<template id="OCT01" name="一卡通储值卡发卡凭证">
20<title text="一卡通发卡凭证" style="2" color="0" justification="center"/>
21<body>
22<item text="用户卡号:" value="CardSerialNumber" style="0" color="0"></item>
23<item text="卡片类型:" value="productName" style="0" color="0"></item>
24<item text="卡有效期:" value="productValidityEndDate" style="0" color="0"></item>
25<item text="发卡押金:" value="carddepositvalue" style="0" color="0"></item>
26<item text="交易时间:" value="transactionTime" style="0" color="0"></item>
27<item text="网点编号:" value="NetStationID" style="0" color="1"></item>
28<item text="操作员ID:" value="staffId" style="0" color="0"></item>
29</body>
30</template>
31<template id="OCT02" name="一卡通储值卡发卡凭证">
32<title text="充值凭证" style="2" color="0" justification="center"/>
33<body>
34<item text="用户卡号:" value="CardSerialNumber" style="0" color="0"></item>
35<item text="卡片类型:" value="productName" style="0" color="0"></item>
36<item text="卡有效期:" value="productValidityEndDate" style="0" color="0"></item>
37<item text="充值前余额:" value="balance2" style="0" color="0"></item>
38<item text="充值金额:" value="revalue" style="0" color="0"></item>
39<item text="充值后金额:" value="balance" style="0" color="0"></item>
40<item text="交易时间:" value="transactionTime" style="0" color="0"></item>
41<item text="网点编号:" value="NetStationID" style="0" color="0"></item>
42<item text="操作员ID:" value="staffId" style="0" color="0"></item>
43</body>
44</template>
45
46
47<template id="ACC01" name="一票通储值卡发卡凭证">
48<title text="一票通发卡凭证" style="2" color="0" justification="center"/>
49<body>
50<item text="用户卡号:" value="otherCardSerialNumber" style="0" color="0"></item>
51<item text="车票种类:" value="productName" style="0" color="0"></item>
52<item text="卡有效期:" value="ValidityEndDate" style="0" color="0"></item>
53<item text="发卡押金:" value="carddepositvalue" style="0" color="0"></item>
54<item text="交易时间:" value="transactionTime" style="0" color="0"></item>
55<item text="车站名称:" value="stationName" style="0" color="0"></item>
56<item text="设备编号:" value="deviceId" style="0" color="0"></item>
57<item text="操作员ID:" value="staffId" style="0" color="0"></item>
58</body>
59</template>
60<template id="ACC02" name="一票通储值卡发卡凭证">
61<title text="充值凭证" style="2" color="0" justification="center"/>
62<body>
63<item text="用户卡号:" value="otherCardSerialNumber" style="0" color="0"></item>
64<item text="车票种类:" value="productName" style="0" color="0"></item>
65<item text="卡有效期:" value="ValidityEndDate" style="0" color="0"></item>
66<item text="充值前金额:" value="" style="0" color="0"></item>
67<item text="充值金额:" value="" style="0" color="0"></item>
68<item text="充值后金额:" value="" style="0" color="0"></item>
69<item text="交易时间:" value="transactionTime" style="0" color="0"></item>
70<item text="车站名称:" value="stationName" style="0" color="0"></item>
71<item text="设备编号:" value="deviceId" style="0" color="0"></item>
72<item text="操作员ID:" value="staffId" style="0" color="0"></item>
73</body>
74</template>
75</root>
一、创建的打印类:Printer.cs1二、PrinterCommand.cs类using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO.Ports;
5
6namespace BOM.NewUI.PrinterManager
7![]()
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace BOM.NewUI.PrinterManager
6![]()
三、串口类SerialPortInfo.cs1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO.Ports;
5
6namespace BOM.NewUI.PrinterManager
7![]()
四、配置信息类ConfigManager.cs1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Xml;
5using System.IO.Ports;
6
7namespace BOM.NewUI.PrinterManager
8![]()
五、利用模板获取变量值 Templete.cs1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Xml;
5using System.IO.Ports;
6using System.Windows.Forms;
7
8namespace BOM.NewUI.PrinterManager
9![]()
六、打印调用BOMPrinter.cs1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO.Ports;
5using System.IO;
6
7namespace BOM.NewUI.PrinterManager
8![]()
七、配置文件PrinterConfig.xml1<?xml version="1.0" encoding="utf-8" ?>
2<SerialPortInfo>
3<printer name="发票打印机">
4<printertype>TM-U220B</printertype>
5<porttype>串口</porttype>
6<portname>COM5</portname>
7<baudrate>9600</baudrate>
8<parity>None</parity>
9<databits>8</databits>
10<stopbits>One</stopbits>
11</printer>
12<printer name="票据打印机">
13<printertype>TM-U220B</printertype>
14<porttype>串口</porttype>
15<portname>COM2</portname>
16<baudrate>9600</baudrate>
17<parity>None</parity>
18<databits>8</databits>
19<stopbits>One</stopbits>
20</printer>
21</SerialPortInfo>
通过以后的工作后,若以后需要增加一些票据的话,只需在相应在XML文件中添加相应的模板信息再,再在Templete.cs文件中给啬的变量付值 ,就可以实现了。
相关文章: