MainMachine _Printer.cs
3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
partial class MainMachine
{
//Asa.PrintLabel PrintBean = null;
public void InitPrint()
{
//RobotManage.PrintBean = new Asa.PrintLabel(Application.StartupPath + "\\Label");
RobotManage.PrintBean.PrintStatusChanged += Print_PrintStatusChanged;
/*
System.Drawing.Printing.PrintDocument print = new System.Drawing.Printing.PrintDocument();
string sDefault = print.PrinterSettings.PrinterName;//默认打印机名
LogUtil.info("PrintLabel 本机默认打印机:" + sDefault);
int index = 1;
foreach (string sPrint in System.Drawing.Printing.PrinterSettings.InstalledPrinters)//获取所有打印机名称
{
LogUtil.info("PrintLabel 打印机_" + index + "_名称:" + sPrint);
index++;
}*/
}
public Asa.PrintLabel.PrinterStatus LastPrintStatus = Asa.PrintLabel.PrinterStatus.Unknown;
void Print_PrintStatusChanged(Asa.PrintLabel.PrinterStatus sta, string msg)
{
if (sta.Equals(LastPrintStatus).Equals(false))
{
LogUtil.info("PrintLabel 收到打印机新状态:【" + sta + "】【" + msg + "】,替换原来的状态【" + LastPrintStatus + "】 ");
}
else
{
if (sta == Asa.PrintLabel.PrinterStatus.Idle) {
Task.Run(()=> {
while (true)
{
if (LabelMoveInfo.IsStep(MoveStep.Lbl_WaitPrint))
{
LabelMoveInfo.NextMoveStep(MoveStep.Lbl_Printted);
break;
}
Task.Delay(500).Wait();
}
});
}
LogUtil.info(" PrintLabel 收到打印机新状态:【" + sta + "】【" + msg + "】,与之前状态一样 ");
}
LastPrintStatus = sta;
}
public string LastPrintLabel="";
void StartPrintLabel(string wareCode, string wareCount, string FactoryCode = "")
{
try
{
LastPrintStatus= Asa.PrintLabel.PrinterStatus.Unknown;
LogUtil.info("调用 PrintLabel 打印标签 StartPrintLabel ,[" + wareCode + "] [" + wareCount + "] 开始");
Dictionary<string, string> text = new Dictionary<string, string>();
text.Add("Code", wareCode);
text.Add("Count", wareCount);
text.Add("DateTime", System.DateTime.Now.ToString("F"));
text.Add("FactoryCode", FactoryCode);
LastPrintLabel = wareCode;
RobotManage.PrintBean.Print(text);
LogUtil.info("PrintLabel 打印标签 StartPrintLabel 结束 ");
}
catch (Exception ex)
{
LogUtil.error("PrintLabel 打印标签 StartPrintLabel 错误:" + ex.ToString());
}
}
public Task DoPrint(string aaa) {
return Task.Run(() =>
{
StartPrintLabel(aaa, aaa, aaa);
});
}
}
}