PrinterHelper.cs
2.4 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
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
{
public Asa.PrintLabel print;
ZebraPrinterHelper.ZebraManger zebraManger;
string Port;
public PrinterHelper()
{
print = new Asa.PrintLabel(Application.StartupPath + "\\Label", 300);
}
public static CustPrinterStatus LastPrintStatus = CustPrinterStatus.Unknown;
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 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(() =>
{
bool rtn = zebraManger.IsLabelOnPeeler;
if(rtn)
{
LastPrintStatus = CustPrinterStatus.HasLabel;
}
else
{
LastPrintStatus = CustPrinterStatus.NoLabel;
}
return (rtn, "");
});
}
}
public enum CustPrinterStatus
{
Unknown,
NoLabel,
HasLabel,
}
}