|
|
|
|
|
|
|
using AksWebBrowser.Common;
|
|
|
|
using AKSWebBrowser.Commen;
|
|
|
|
using CPF.Windows;
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace AksWebBrowser.Devices
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 打印票据
|
|
|
|
/// </summary>
|
|
|
|
public class PrintPJ
|
|
|
|
{
|
|
|
|
public static int m_iInit = -1; //打印机初始化状态
|
|
|
|
public static int m_iStatus = -1; //打印机状态
|
|
|
|
//语言版本 Language
|
|
|
|
public static int m_lcLanguage = 0;
|
|
|
|
private readonly string comAddr;
|
|
|
|
private readonly int port;
|
|
|
|
/// <summary>
|
|
|
|
/// 通过注入的方式传递
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="com"></param>
|
|
|
|
/// <param name="port"></param>
|
|
|
|
public PrintPJ(string com, int port)
|
|
|
|
{
|
|
|
|
this.comAddr = com;
|
|
|
|
this.port = port;
|
|
|
|
}
|
|
|
|
|
|
|
|
//打印小票
|
|
|
|
public int SendPrint(string ph, string ddrs, string qrcode, string ywmc)
|
|
|
|
{
|
|
|
|
m_iStatus = LibPrint.GetStatus();
|
|
|
|
if (m_iStatus == 0)//打印机已连接
|
|
|
|
{
|
|
|
|
return Print(ph, ddrs, qrcode, ywmc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
CheckAndOpenSerialPort();
|
|
|
|
if (m_iInit == 0)
|
|
|
|
{
|
|
|
|
return Print(ph, ddrs, qrcode, ywmc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//打印未连接
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 打印模板
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="ph">排号</param>
|
|
|
|
/// <param name="ddrs">等待人数</param>
|
|
|
|
/// <param name="qrcode">二维码</param>
|
|
|
|
/// <param name="ywmc">业务名称</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public int Print(string ph, string ddrs, string qrcode, string ywmc)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string txt = string.Format(" 您预约办理的{0}业务-,排号为:", ywmc);
|
|
|
|
LibPrint.SetClean();
|
|
|
|
LibPrint.SetReadZKmode(0);
|
|
|
|
LibPrint.SetAlignment(0);
|
|
|
|
LibPrint.SetSizetext(2, 1);
|
|
|
|
LibPrint.SetLinespace(20);
|
|
|
|
LibPrint.PrintString(Encoding.GetEncoding("gb2312").GetBytes(txt), 0);
|
|
|
|
LibPrint.PrintFeedDot(0);
|
|
|
|
|
|
|
|
//排号
|
|
|
|
LibPrint.SetAlignment(1);
|
|
|
|
LibPrint.SetBold(1);
|
|
|
|
LibPrint.SetSizetext(2, 2);
|
|
|
|
LibPrint.PrintString(Encoding.GetEncoding("gb2312").GetBytes(ph), 0);
|
|
|
|
|
|
|
|
LibPrint.SetAlignment(0);
|
|
|
|
LibPrint.SetBold(0);
|
|
|
|
LibPrint.SetSizetext(2, 1);
|
|
|
|
LibPrint.PrintFeedDot(10);
|
|
|
|
|
|
|
|
//等候
|
|
|
|
txt = string.Format("您前面有 {0} 人等候,注意业务窗口的呼叫号码信息。过号请重新取号。", ddrs);
|
|
|
|
LibPrint.PrintString(Encoding.GetEncoding("gb2312").GetBytes(txt), 1);
|
|
|
|
LibPrint.PrintFeedDot(60);
|
|
|
|
|
|
|
|
//二维码
|
|
|
|
LibPrint.SetClean();
|
|
|
|
LibPrint.SetCommandmode(10);
|
|
|
|
LibPrint.SetAlignment(1);
|
|
|
|
LibPrint.SetLeftmargin(-40);
|
|
|
|
LibPrint.PrintQrcode(Encoding.GetEncoding("gb2312").GetBytes(qrcode), 0, 8, 1);
|
|
|
|
LibPrint.PrintRemainQR();
|
|
|
|
LibPrint.PrintFeedDot(80);
|
|
|
|
|
|
|
|
//时间
|
|
|
|
LibPrint.SetClean();
|
|
|
|
LibPrint.SetSizetext(0, 0);
|
|
|
|
LibPrint.SetAlignment(2);
|
|
|
|
LibPrint.PrintString(Encoding.GetEncoding("gb2312").GetBytes(DateTime.Now.ToLocalTime().ToString()), 1);
|
|
|
|
LibPrint.PrintFeedDot(155);
|
|
|
|
LibPrint.PrintCutpaper(0);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
//Log.Error("票据打印失败:" + ex.Message);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//开启打印
|
|
|
|
public void CheckAndOpenSerialPort()
|
|
|
|
{
|
|
|
|
//关闭打印机
|
|
|
|
try { LibPrint.SetClose(); } catch (Exception ex) { Console.WriteLine("打印机未开启:" + ex.Message); }
|
|
|
|
try
|
|
|
|
{
|
|
|
|
byte[] cDevname = Encoding.UTF8.GetBytes(comAddr);
|
|
|
|
int iBaudrate = port;
|
|
|
|
//打开连接
|
|
|
|
m_iInit = LibPrint.SetDevname(3,"", 0);
|
|
|
|
if (m_iInit == 0)
|
|
|
|
{
|
|
|
|
// // Log.Info("热敏打印机已连接");
|
|
|
|
//初始化打印机
|
|
|
|
m_iInit = LibPrint.SetInit();
|
|
|
|
if (m_iInit == 0)
|
|
|
|
{
|
|
|
|
// // Log.Info("初始化成功");
|
|
|
|
LibPrint.SetCommandmode(3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// // Log.Info("初始化失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) { Console.WriteLine("票据打印机初始化异常:" + ex.Message); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LibPrint
|
|
|
|
{
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetInit", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetInit();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetUsbportauto", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetUsbportauto();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetClean", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetClean();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetClose", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetClose();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetAlignment", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetAlignment(int iAlignment);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetAlignmentLeftRight", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetAlignmentLeftRight(int iAlignment);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetBold", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetBold(int iBold);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetCommandmode", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetCommandmode(int iMode);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetLinespace", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetLinespace(int iLinespace);
|
|
|
|
//设置设备名称(Linux)
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetDevname", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetDevname(int iDevtype, string cDevname, int iBaudrate);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintString", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintString(byte[] strData, int iImme);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintFeedline", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintFeedline(int iLine);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintSelfcheck", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintSelfcheck();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "GetStatus", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int GetStatus();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "GetStatusspecial", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int GetStatusspecial();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintCutpaper", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintCutpaper(int iMode);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetSizetext", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetSizetext(int iHeight, int iWidth);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetSizechinese", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetSizechinese(int iHeight, int iWidth, int iUnderline, int iChinesetype);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetItalic", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetItalic(int iItalic);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintDiskbmpfile", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintDiskbmpfile(StringBuilder strData);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintDiskimgfile", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintDiskimgfile(StringBuilder strData);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintQrcode", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintQrcode(byte[] strData, int iLmargin, int iMside, int iRound);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintRemainQR", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintRemainQR();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetLeftmargin", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetLeftmargin(int iLmargin);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "GetProductinformation", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int GetProductinformation(int Fstype, byte[] FIDdata, int iFidlen);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintTransmit", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintTransmit(byte[] strCmd, int iLength);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "GetTransmit", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int GetTransmit(byte[] strCmd, int iLength, byte[] bRecv, int iRelen);
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintFeedDot", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintFeedDot(int Lnumber);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintChargeRow", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintChargeRow();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetSpacechar", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetSpacechar(int iSpace);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetSizechar", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetSizechar(int iHeight, int iWidth, int iUnderline, int iAsciitype);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetRotate", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetRotate(int iRotate);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetDirection", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetDirection(int iDirection);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetWhitemodel", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetWhitemodel(int iWhite);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetUnderline", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetUnderline(int underline);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintNextHT", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintNextHT();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetHTseat", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetHTseat(byte[] bHTseat, int iLength);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetCodepage", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetCodepage(int country, int CPnumber);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "Print1Dbar", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int Print1Dbar(int iWidth, int iHeight, int iHrisize, int iHriseat, int iCodetype, StringBuilder strData);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetPagemode", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetPagemode(int iMode, int Xrange, int Yrange);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetPagestartposition", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetPagestartposition(int Xdot, int Ydot);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetPagedirection", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetPagedirection(int iDirection);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintPagedata", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintPagedata();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetReadZKmode", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetReadZKmode(int mode);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetNvbmp", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetNvbmp(int iNums, StringBuilder strPath);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintNvbmp", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintNvbmp(int iNvindex, int iMode);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetPrintIDorName", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetPrintIDorName(StringBuilder strIDorNAME);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "GetPrintIDorName", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int GetPrintIDorName(StringBuilder strIDorNAME);
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintMarkcutpaper", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintMarkcutpaper(int iMode);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetTraceLog", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetTraceLog(int iLog);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintPdf417", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintPdf417(int iDotwidth, int iDotheight, int iDatarows, int iDatacolumns, StringBuilder strData);
|
|
|
|
|
|
|
|
//旋转模式
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetRotation_Intomode", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetRotation_Intomode();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "SetRotation_Leftspace", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int SetRotation_Leftspace(int iLeftspace);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintRotation_Sendcode", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintRotation_Sendcode(int leftspace, int iWidth, int iHeight, int iCodetype, StringBuilder strData);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintRotation_Sendtext", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintRotation_Sendtext(StringBuilder strData, int iImme);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintRotation_Changeline", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintRotation_Changeline();
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintRotation_Data", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintRotation_Data();
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintPDF_CCCB", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintPDF_CCCB(StringBuilder strData);
|
|
|
|
|
|
|
|
[DllImport("libmsprintsdk", EntryPoint = "PrintDataMatrix", CharSet = CharSet.Ansi)]
|
|
|
|
public static extern int PrintDataMatrix(StringBuilder strData, int iSize);
|
|
|
|
}
|
|
|
|
}
|