Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
刘韬
/
PrintLabel
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 1a83758c
由
刘韬
编写于
2023-08-02 16:47:46 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
21403dfb
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
65 行增加
和
28 行删除
ZebraPrinterHelper/ZebraManger.cs
ZebraPrinterHelper/ZebraManger.cs
查看文件 @
1a83758
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.Drawing
;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Linq
;
...
@@ -92,10 +93,15 @@ namespace ZebraPrinterHelper
...
@@ -92,10 +93,15 @@ namespace ZebraPrinterHelper
msg
=
""
;
msg
=
""
;
try
try
{
{
Debug
.
WriteLine
(
"Connection1"
);
printerConnection
=
GetConnection
();
printerConnection
=
GetConnection
();
Debug
.
WriteLine
(
"Connection2"
);
printerConnection
.
Open
();
printerConnection
.
Open
();
Debug
.
WriteLine
(
"Connection3"
);
PrinterDPI
=
GetPrinterDPI
();
PrinterDPI
=
GetPrinterDPI
();
Debug
.
WriteLine
(
"Connection4"
);
printer
=
ZebraPrinterFactory
.
GetInstance
(
printerConnection
);
printer
=
ZebraPrinterFactory
.
GetInstance
(
printerConnection
);
Debug
.
WriteLine
(
"Connection5"
);
return
true
;
return
true
;
}
}
catch
(
ConnectionException
e
)
catch
(
ConnectionException
e
)
...
@@ -108,15 +114,19 @@ namespace ZebraPrinterHelper
...
@@ -108,15 +114,19 @@ namespace ZebraPrinterHelper
}
}
catch
(
IOException
e
)
catch
(
IOException
e
)
{
{
msg
=
"Image Error"
+
e
.
Message
;
msg
=
"Image Error
:
"
+
e
.
Message
;
}
}
catch
(
ZebraIllegalArgumentException
e
)
catch
(
ZebraIllegalArgumentException
e
)
{
{
msg
=
"Illegal Arguments"
+
e
.
Message
;
msg
=
"Illegal Arguments
:
"
+
e
.
Message
;
}
}
catch
(
ArgumentException
e
)
catch
(
ArgumentException
e
)
{
{
msg
=
"Invalid File Path"
+
e
.
Message
;
msg
=
"Invalid File Path:"
+
e
.
Message
;
}
catch
(
Exception
e
)
{
msg
=
"Exception:"
+
e
.
Message
;
}
}
finally
finally
{
{
...
@@ -165,26 +175,36 @@ namespace ZebraPrinterHelper
...
@@ -165,26 +175,36 @@ namespace ZebraPrinterHelper
/// <param name="msg">错误消息</param>
/// <param name="msg">错误消息</param>
/// <param name="checkPeeler">是否检查剥离器</param>
/// <param name="checkPeeler">是否检查剥离器</param>
/// <returns>是否成功</returns>
/// <returns>是否成功</returns>
public
bool
PrintImage
(
Bitmap
bmp
,
out
string
msg
,
bool
checkPeeler
)
public
bool
PrintImage
(
Bitmap
bmp
,
out
string
msg
,
bool
checkPeeler
,
bool
checkstatus
=
true
)
{
return
PrintImage
(
bmp
,
bmp
.
Width
,
bmp
.
Height
,
out
msg
,
checkPeeler
,
checkstatus
);
}
public
bool
PrintImage
(
Bitmap
bmp
,
int
width
,
int
height
,
out
string
msg
,
bool
checkPeeler
,
bool
checkstatus
=
true
)
{
{
if
(!
CheckAndGetStatus
(
out
PrinterStatus
status
,
out
msg
))
msg
=
""
;
return
false
;
Debug
.
WriteLine
(
"StartPrintImage"
);
if
(
status
.
labelsRemainingInBatch
>
0
)
if
(
checkstatus
)
CancelAll
();
if
(!
status
.
isReadyToPrint
)
{
{
string
[]
printerStatusString
=
new
PrinterStatusMessages
(
status
).
GetStatusMessage
();
if
(!
CheckAndGetStatus
(
out
PrinterStatus
status
,
out
msg
))
return
false
;
Debug
.
WriteLine
(
"CheckAndGetStatus"
);
if
(
status
.
labelsRemainingInBatch
>
0
)
CancelAll
();
Debug
.
WriteLine
(
"labelsRemainingInBatch"
);
if
(!
status
.
isReadyToPrint
)
{
string
[]
printerStatusString
=
new
PrinterStatusMessages
(
status
).
GetStatusMessage
();
msg
=
string
.
Join
(
"\r\n"
,
printerStatusString
);
msg
=
string
.
Join
(
"\r\n"
,
printerStatusString
);
return
false
;
return
false
;
}
}
if
(
checkPeeler
&&
IsLabelOnPeeler
)
Debug
.
WriteLine
(
"isReadyToPrint"
);
{
if
(
checkPeeler
&&
IsLabelOnPeeler
)
msg
=
"上一个标签尚未移走"
;
{
return
false
;
msg
=
"上一个标签尚未移走"
;
return
false
;
}
Debug
.
WriteLine
(
"IsLabelOnPeeler"
);
}
}
try
try
{
{
//var width = bmp.Width * ((double)PrinterDPI / 300);
//var width = bmp.Width * ((double)PrinterDPI / 300);
...
@@ -192,6 +212,7 @@ namespace ZebraPrinterHelper
...
@@ -192,6 +212,7 @@ namespace ZebraPrinterHelper
//var db = GetReducedImage(bmp, (int)width, (int)height);
//var db = GetReducedImage(bmp, (int)width, (int)height);
//db.Save("temp.bmp");
//db.Save("temp.bmp");
ZebraImageI
image
=
ZebraImageFactory
.
GetImage
(
bmp
);
ZebraImageI
image
=
ZebraImageFactory
.
GetImage
(
bmp
);
Debug
.
WriteLine
(
"ZebraImageFactory.GetImage"
);
printer
.
PrintImage
(
image
,
0
,
0
,
(
int
)
bmp
.
Width
,
(
int
)
bmp
.
Height
,
false
);
printer
.
PrintImage
(
image
,
0
,
0
,
(
int
)
bmp
.
Width
,
(
int
)
bmp
.
Height
,
false
);
return
true
;
return
true
;
}
}
...
@@ -209,11 +230,15 @@ namespace ZebraPrinterHelper
...
@@ -209,11 +230,15 @@ namespace ZebraPrinterHelper
}
}
catch
(
ZebraIllegalArgumentException
e
)
catch
(
ZebraIllegalArgumentException
e
)
{
{
msg
=
"Illegal Arguments"
+
e
.
ToString
();
msg
=
"Illegal Arguments
:
"
+
e
.
ToString
();
}
}
catch
(
ArgumentException
e
)
catch
(
ArgumentException
e
)
{
{
msg
=
"Invalid File Path"
+
e
.
ToString
();
msg
=
"Invalid File Path:"
+
e
.
ToString
();
}
catch
(
Exception
e
)
{
msg
=
"Exception:"
+
e
.
Message
;
}
}
finally
finally
{
{
...
@@ -235,18 +260,25 @@ namespace ZebraPrinterHelper
...
@@ -235,18 +260,25 @@ namespace ZebraPrinterHelper
return
false
;
return
false
;
}
}
}
}
Debug
.
WriteLine
(
"StartGetStatus"
);
status
=
GetStatus
();
status
=
GetStatus
();
if
(
status
==
null
)
if
(
status
==
null
)
{
{
Close
(
);
Debug
.
WriteLine
(
"GetStatusAgain"
);
ReTryCount
++
;
status
=
GetStatus
()
;
if
(
ReTryCount
>
3
)
if
(
status
==
null
)
{
{
msg
=
"连接打印机失败"
;
Close
();
return
false
;
ReTryCount
++;
if
(
ReTryCount
>
3
)
{
msg
=
"连接打印机失败"
;
return
false
;
}
goto
ReTry
;
}
}
goto
ReTry
;
}
}
Debug
.
WriteLine
(
"isPaused"
);
ReTryCount
=
0
;
ReTryCount
=
0
;
if
(
status
.
isPaused
)
if
(
status
.
isPaused
)
{
{
...
@@ -380,8 +412,10 @@ namespace ZebraPrinterHelper
...
@@ -380,8 +412,10 @@ namespace ZebraPrinterHelper
/// <returns></returns>
/// <returns></returns>
public
PrinterStatus
GetStatus
()
public
PrinterStatus
GetStatus
()
{
{
if
(
printerConnection
==
null
||
!
printerConnection
.
Connected
)
if
(
printerConnection
==
null
||
!
printerConnection
.
Connected
)
{
{
Debug
.
WriteLine
(
"ReConnection"
);
if
(!
Connection
(
out
string
m
))
if
(!
Connection
(
out
string
m
))
{
{
//msg = m;
//msg = m;
...
@@ -390,12 +424,15 @@ namespace ZebraPrinterHelper
...
@@ -390,12 +424,15 @@ namespace ZebraPrinterHelper
}
}
try
try
{
{
Debug
.
WriteLine
(
"GetCurrentStatus"
);
return
printer
.
GetCurrentStatus
();
return
printer
.
GetCurrentStatus
();
//ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(printer);
//ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(printer);
//Debug.WriteLine("linkOsPrinter:"+ linkOsPrinter==null);
//return (linkOsPrinter != null) ? linkOsPrinter.GetCurrentStatus() : printer.GetCurrentStatus();
//return (linkOsPrinter != null) ? linkOsPrinter.GetCurrentStatus() : printer.GetCurrentStatus();
}
}
catch
catch
(
Exception
ex
)
{
{
Debug
.
WriteLine
(
"GetCurrentStatusError:"
+
ex
);
return
null
;
return
null
;
}
}
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论