PrinterHelper.cs
2.6 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
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
public class PrinterHelper
{
private Asa.PrintLabel print;
ZebraPrinterHelper.ZebraManger zebraManger;
string Port;
public PrinterHelper() {
print = new Asa.PrintLabel(Application.StartupPath + "\\Label", 300);
}
public bool Connection(string port) {
Port = port;
//zebraManger = new ZebraPrinterHelper.ZebraManger(Port, ZebraPrinterHelper.ConnectionType.Network);
zebraManger = new ZebraPrinterHelper.ZebraManger("", ZebraPrinterHelper.ConnectionType.UsbDirect);
if (!zebraManger.Connection(out string msg))
{
LogUtil.error(msg);
return false;
}
else
{
print = new Asa.PrintLabel(Application.StartupPath + "\\Label", zebraManger.PrinterDPI);
return true;
}
}
public void Close() {
zebraManger.Close();
}
public void EditLabel() {
print.EditLabel();
}
public string[] GetLabelList() {
return print.GetLabelName();
}
public Task<(bool,string)> PrintLabel(ReelParam reel)
{
return Task.Run(() =>
{
string labelname = Setting_Init.Printer_Labelname;
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("RI", reel.ReeID);
data.Add("PN", reel.PN);
data.Add("QTY", reel.QTY.ToString());
data.Add("datetime", DateTime.Now.ToString());
LogUtil.info($"打印标签:{reel.ToDetailStr()}");
var result = Print(labelname, data, out string msg);
Task.Delay(500).Wait();
return (result,msg);
});
}
bool Print(string labelname,Dictionary<string, string> data,out string msg) {
print.LoadLabel(labelname);
var bmp = print.PrintPreview(data);
if (!zebraManger.PrintImage(bmp, out msg))
{
LogUtil.error(msg);
return false;
}
bmp.Dispose();
return true;
}
public Task<(bool, string)> IsLabelOnPeeler()
{
return Task.Run(() =>
{
return (zebraManger.IsLabelOnPeeler,"");
});
}
}
}