You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
426 lines
18 KiB
C#
426 lines
18 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using demo.ClassHelper.RandomOperate;
|
|
using System.Threading;
|
|
using demo.ClassHelper.MsgBox;
|
|
using System.Windows.Forms;
|
|
using demo.ExternalDevices;
|
|
|
|
namespace demo
|
|
{
|
|
class PrintLabel
|
|
{
|
|
private static PrintLabel m_instance = new PrintLabel();
|
|
/// <summary>
|
|
/// 创建一个静态实例
|
|
/// </summary>
|
|
public static PrintLabel Instance
|
|
{
|
|
get { return m_instance; }
|
|
}
|
|
|
|
//public static string emsTxt = null;
|
|
|
|
public static bool CreateEmsTxt(PostInfo postInfo, ref string emsTxt)
|
|
{
|
|
bool ret = false;
|
|
try
|
|
{
|
|
emsTxt += "#!A1" + "\r\n";
|
|
emsTxt += "#IMSR100/151" + "\r\n";
|
|
emsTxt += "#HV90" + "\r\n";
|
|
emsTxt += "#PR8/8/" + "\r\n";
|
|
emsTxt += "#RX0" + "\r\n";
|
|
emsTxt += "#N13" + "\r\n";
|
|
emsTxt += "#ER" + "\r\n";
|
|
emsTxt += "#T01 #J20 #YL3/0/00.2/96" + "\r\n";
|
|
emsTxt += "#T01 #J33 #YL3/0/00.2/96" + "\r\n";
|
|
emsTxt += "#T01 #J49 #YL3/0/00.2/96" + "\r\n";
|
|
emsTxt += "#T01 #J66 #YL3/0/00.2/96" + "\r\n";
|
|
emsTxt += "#T01 #J89 #YL3/0/00.2/96" + "\r\n";
|
|
emsTxt += "#T01 #J93 #YL3/0/00.2/96" + "\r\n";
|
|
emsTxt += "#T01 #J108 #YL3/0/00.2/96" + "\r\n";
|
|
emsTxt += "#T01 #J116 #YL3/0/00.2/96" + "\r\n";
|
|
emsTxt += "#T01 #J131 #YL3/0/00.2/96" + "\r\n";
|
|
emsTxt += "#T29 #J146 #YL3/0/00.2/68" + "\r\n";
|
|
emsTxt += "#T35 #J80 #YN901/2U/38///已验视" + "\r\n";
|
|
emsTxt += "#T54 #J3 #YL3/1/00.2/17" + "\r\n";
|
|
emsTxt += "#T28 #J20 #YL3/1/00.2/13" + "\r\n";
|
|
emsTxt += "#T54 #J49 #YL3/1/00.2/17" + "\r\n";
|
|
emsTxt += "#T29 #J131 #YL3/1/00.2/18" + "\r\n";
|
|
emsTxt += "#T88 #J18 #YN901/2U/70///标准快递" + "\r\n";
|
|
emsTxt += "#T51 #J19 #YB13/2P2.0MK/12/4///" + postInfo.postNo + "\r\n";
|
|
emsTxt += "#T96 #J23 #YN901/2U/32///寄件:" + "\r\n";
|
|
emsTxt += "#T88 #J23 #YN901/2U/32///" + postInfo.sendName + "\r\n";
|
|
emsTxt += "#T88 #J27 #YN901/2U/32///" + postInfo.sendNo + "\r\n";
|
|
emsTxt += "#T88 #J31 #YN901/2U/32///" + postInfo.sendAddress + "\r\n";
|
|
#region city
|
|
if (postInfo.recvAddress.Contains("武汉"))
|
|
{
|
|
postInfo.recvCity = "武汉";
|
|
}
|
|
if (postInfo.recvAddress.Contains("黄石"))
|
|
{
|
|
postInfo.recvCity = "黄石";
|
|
}
|
|
if (postInfo.recvAddress.Contains("襄樊"))
|
|
{
|
|
postInfo.recvCity = "襄樊";
|
|
}
|
|
if (postInfo.recvAddress.Contains("襄阳"))
|
|
{
|
|
postInfo.recvCity = "襄阳";
|
|
}
|
|
if (postInfo.recvAddress.Contains("十堰"))
|
|
{
|
|
postInfo.recvCity = "十堰";
|
|
}
|
|
if (postInfo.recvAddress.Contains("荆州"))
|
|
{
|
|
postInfo.recvCity = "荆州";
|
|
}
|
|
if (postInfo.recvAddress.Contains("宜昌"))
|
|
{
|
|
postInfo.recvCity = "宜昌";
|
|
}
|
|
if (postInfo.recvAddress.Contains("荆门"))
|
|
{
|
|
postInfo.recvCity = "荆门";
|
|
}
|
|
if (postInfo.recvAddress.Contains("十堰"))
|
|
{
|
|
postInfo.recvCity = "十堰";
|
|
}
|
|
if (postInfo.recvAddress.Contains("鄂州"))
|
|
{
|
|
postInfo.recvCity = "鄂州";
|
|
}
|
|
if (postInfo.recvAddress.Contains("孝感"))
|
|
{
|
|
postInfo.recvCity = "孝感";
|
|
}
|
|
if (postInfo.recvAddress.Contains("黄冈"))
|
|
{
|
|
postInfo.recvCity = "黄冈";
|
|
}
|
|
if (postInfo.recvAddress.Contains("咸宁"))
|
|
{
|
|
postInfo.recvCity = "咸宁";
|
|
}
|
|
if (postInfo.recvAddress.Contains("随州"))
|
|
{
|
|
postInfo.recvCity = "随州";
|
|
}
|
|
if (postInfo.recvAddress.Contains("恩施"))
|
|
{
|
|
postInfo.recvCity = "恩施";
|
|
}
|
|
if (postInfo.recvAddress.Contains("仙桃"))
|
|
{
|
|
postInfo.recvCity = "仙桃";
|
|
}
|
|
if (postInfo.recvAddress.Contains("潜江"))
|
|
{
|
|
postInfo.recvCity = "潜江";
|
|
}
|
|
if (postInfo.recvAddress.Contains("天门"))
|
|
{
|
|
postInfo.recvCity = "天门";
|
|
}
|
|
if (postInfo.recvAddress.Contains("神农架"))
|
|
{
|
|
postInfo.recvCity = "神农架";
|
|
}
|
|
else
|
|
{
|
|
if (postInfo.recvAddress.Contains("湖北省"))
|
|
{
|
|
postInfo.recvCity = postInfo.recvAddress.Substring(3, 2);
|
|
}
|
|
else
|
|
{
|
|
postInfo.recvCity = postInfo.recvAddress.Substring(0, 2);
|
|
}
|
|
|
|
}
|
|
#endregion city
|
|
emsTxt += "#T25 #J30 #YN901/2U/125///" + postInfo.recvCity + "\r\n";
|
|
emsTxt += "#T96 #J37 #YN901/2U/45///收件:" + "\r\n";
|
|
if (postInfo.recvName !=postInfo.applicantName)
|
|
{
|
|
postInfo.recvName = postInfo.recvName + "转" + postInfo.applicantName;
|
|
}
|
|
emsTxt += "#T87 #J37 #YN901/2U/45///" + postInfo.recvName + "\r\n";
|
|
emsTxt += "#T50 #J37 #YN901/2U/45///" + postInfo.recvNo + "\r\n";
|
|
string recvAdd1 = null, recvAdd2 = null;
|
|
if (postInfo.recvAddress.Length > 22)
|
|
{
|
|
recvAdd1 = postInfo.recvAddress.Substring(0, 22);
|
|
recvAdd2 = postInfo.recvAddress.Substring(22, postInfo.recvAddress.Length - 22);
|
|
}
|
|
else
|
|
{
|
|
recvAdd1 = postInfo.recvAddress;
|
|
}
|
|
emsTxt += "#T87 #J42 #YN901/2U/45///" + recvAdd1 + "\r\n";
|
|
emsTxt += "#T87 #J47 #YN901/2U/45///" + recvAdd2 + "\r\n";
|
|
emsTxt += "#T93 #J54 #YN901/2U/38///" + GlobalVariable.upRemark1 + "\r\n";
|
|
emsTxt += "#T96 #J58 #YN901/2U/38///" + GlobalVariable.upRemark2 + "\r\n";
|
|
emsTxt += "#T96 #J62 #YN901/2U/38///" + GlobalVariable.upRemark3 + "\r\n";
|
|
emsTxt += "#T50 #J56 #YN901/2U/38///收件人/代收人:" + "\r\n";
|
|
emsTxt += "#T50 #J62 #YN901/2U/38///签收: 年 月 日 时" + "\r\n";
|
|
emsTxt += "#T56 #J62 #YN901/2U/29///" + "\r\n";
|
|
emsTxt += "#T56 #J65 #YN901/2U/29///" + "\r\n";
|
|
emsTxt += "#T96 #J70 #YN901/2U/38///身份证号:" + "\r\n";
|
|
string strBefore, strBirthday, strAfter;
|
|
if (postInfo.idNoOne != null)
|
|
{
|
|
strBefore = postInfo.idNoOne.Substring(0, 10);
|
|
strBirthday = postInfo.idNoOne.Substring(10, 4);
|
|
strBirthday = strBirthday.Replace(strBirthday, "****");
|
|
strAfter = postInfo.idNoOne.Substring(14, 4);
|
|
postInfo.idNoOne = strBefore + strBirthday + strAfter;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
emsTxt += "#T81 #J70 #YN901/2U/38///" + postInfo.idNoOne + "\r\n";
|
|
emsTxt += "#T35 #J70 #YN901/2U/38///件数:1" + "\r\n";
|
|
emsTxt += "#T18 #J70 #YN901/2U/38///重量:0.1" + "\r\n";
|
|
emsTxt += "#T96 #J75 #YN901/2U/38///配货信息:" + "\r\n";
|
|
emsTxt += "#T81 #J75 #YN901/2U/38///居民身份证" + "\r\n";
|
|
emsTxt += "#T35 #J75 #YN901/2U/38///" + DateTime.Now.ToString("yyyy/MM/dd hh:mm") + "\r\n";
|
|
emsTxt += "#T96 #J86 #YN901/2U/60///揽投部:" + "\r\n";
|
|
emsTxt += "#T74 #J86 #YN901/2U/60///**揽投部" + "\r\n";
|
|
emsTxt += "#T94 #J107 #YB13/2P2.0MK/10/4///" + postInfo.postNo + "\r\n";
|
|
emsTxt += "#T96 #J111 #YN901/2U/32///寄件:" + "\r\n";
|
|
emsTxt += "#T88 #J111 #YN901/2U/32///" + postInfo.sendName + "\r\n";
|
|
emsTxt += "#T58 #J111 #YN901/2U/32///" + postInfo.sendNo + "\r\n";
|
|
emsTxt += "#T88 #J115 #YN901/2U/32///" + postInfo.sendAddress + "\r\n";
|
|
emsTxt += "#T96 #J120 #YN901/2U/45///收件:" + "\r\n";
|
|
emsTxt += "#T87 #J120 #YN901/2U/45///" + postInfo.recvName + "\r\n";
|
|
emsTxt += "#T50 #J120 #YN901/2U/45///" + postInfo.recvNo + "\r\n";
|
|
emsTxt += "#T87 #J125 #YN901/2U/45///" + recvAdd1 + "\r\n";
|
|
emsTxt += "#T87 #J130 #YN901/2U/45///" + recvAdd2 + "\r\n";
|
|
emsTxt += "#T96 #J137 #YN901/2U/47///" + GlobalVariable.downRemark1 + "\r\n";
|
|
emsTxt += "#T86 #J142 #YN901/2U/47///" + GlobalVariable.downRemark2 + "\r\n";
|
|
emsTxt += "#T94 #J149 #YN901/2U/35///网址:www.ems.cn" + "\r\n";
|
|
emsTxt += "#T65 #J149 #YN901/2U/35///客服电话:" + GlobalVariable.serviceTel + "\r\n";
|
|
emsTxt += "#T25 #J130 " + "\r\n";
|
|
emsTxt += "#YG/1///EMSP.BMP " + "\r\n";
|
|
emsTxt += "#Q1/" + "\r\n";
|
|
emsTxt += "\r\n";
|
|
ret = true;
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
public static bool ReplaceEmsTxt(string path, string newTxt)
|
|
{
|
|
try
|
|
{
|
|
string txt = string.Empty;
|
|
if (!File.Exists(path))
|
|
{
|
|
File.Create(path);
|
|
}
|
|
if (!ReadPrintTxt(path, ref txt))
|
|
return false;
|
|
txt = txt.Replace(txt, newTxt);
|
|
File.WriteAllText(path, txt, Encoding.UTF8);
|
|
return true;
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool ReadPrintTxt(string path, ref string txt)
|
|
{
|
|
if (!File.Exists(path))
|
|
{
|
|
txt = "0";
|
|
return false;
|
|
}
|
|
try
|
|
{
|
|
txt = File.ReadAllText(path, Encoding.UTF8);
|
|
if (txt != null)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
catch
|
|
{
|
|
txt = "0";
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static bool ReadOldPrintParam(string path, ref string[] printParam)
|
|
{
|
|
string strContent = string.Empty;
|
|
printParam = new string[] { };
|
|
if (!ReadPrintTxt(path, ref strContent))
|
|
{
|
|
return false;
|
|
}
|
|
try
|
|
{
|
|
strContent = strContent.Replace("\r\n", "|");
|
|
strContent = strContent.Replace("///", "@");
|
|
string[] eachLine = strContent.Split('|');
|
|
|
|
string traceNo = eachLine[23].Split('@')[1].ToString().TrimEnd();
|
|
string receName = eachLine[30].Split('@')[1].ToString().TrimEnd();
|
|
string recvNo = eachLine[31].Split('@')[1].ToString().TrimEnd();
|
|
string recvAdd = eachLine[32].Split('@')[1].ToString().TrimEnd();
|
|
|
|
string sendName = eachLine[25].Split('@')[1].ToString().TrimEnd();
|
|
string sendNo = eachLine[26].Split('@')[1].ToString().TrimEnd();
|
|
string sendAdd = eachLine[27].Split('@')[1].ToString().TrimEnd();
|
|
|
|
string sendTime = eachLine[47].Split('@')[1].ToString().TrimEnd();
|
|
|
|
string idNo = eachLine[42].Split('@')[1].ToString().TrimEnd();
|
|
|
|
string city = eachLine[28].Split('@')[1].ToString().TrimEnd();
|
|
|
|
string recvAdd2 = eachLine[33].Split('@')[1].ToString().TrimEnd();
|
|
|
|
string upRemark1 = eachLine[34].Split('@')[1].ToString().TrimEnd();
|
|
string upRemark2 = eachLine[35].Split('@')[1].ToString().TrimEnd();
|
|
string upRemark3 = eachLine[36].Split('@')[1].ToString().TrimEnd();
|
|
|
|
string downRemark1 = eachLine[60].Split('@')[1].ToString().TrimEnd();
|
|
string downRemark2 = eachLine[61].Split('@')[1].ToString().TrimEnd();
|
|
|
|
string emsDepartment = eachLine[49].Split('@')[1].ToString().TrimEnd();
|
|
|
|
printParam = new string[17] { traceNo, receName, recvNo, recvAdd, sendName, sendNo, sendAdd, sendTime, idNo, city, recvAdd2, upRemark1, upRemark2, upRemark3, downRemark1, downRemark2, emsDepartment };
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
public static bool ReplacePrintTxt(string path, string newTxt, string oldTxt)
|
|
{
|
|
string txt = string.Empty;
|
|
if (!ReadPrintTxt(path, ref txt))
|
|
return false;
|
|
if (!txt.Contains(oldTxt))
|
|
return false;
|
|
//txt = Regex.Replace(txt, oldTxt, newTxt);
|
|
txt = txt.Replace(oldTxt, newTxt);
|
|
File.WriteAllText(path, txt, Encoding.UTF8);
|
|
return true;
|
|
}
|
|
|
|
public static void HandleErrMsg(string warnMsg)
|
|
{
|
|
PlatformConnection.Instance.StopWork();
|
|
TriColorLight.ShowRed();
|
|
DialogResult result = MsgBoxHelper.ShowError(warnMsg);
|
|
switch (result)
|
|
{
|
|
case DialogResult.OK:
|
|
//GlobalVariable.bRun = false;
|
|
GlobalVariable.list_PostInfo.Clear();
|
|
//GlobalVariable.thLeftBeltJogMove.DisableComObjectEagerCleanup();
|
|
//GlobalVariable.thHandlePrintInfo.DisableComObjectEagerCleanup();
|
|
TriColorLight.ShowGreen();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public static void HandlePrintInfo()
|
|
{
|
|
int listCount;
|
|
string[] oldPrintParam = new string[] { };
|
|
PostInfo postInfo = new PostInfo();
|
|
while (GlobalVariable.bRun)
|
|
{
|
|
lock (GlobalVariable.lockList)
|
|
{
|
|
//sys.sys_EnterCriticalSection(Varialble.hsection);
|
|
listCount = GlobalVariable.list_PostInfo.Count;
|
|
//sys.sys_LeaveCriticalSection(Varialble.hsection);
|
|
}
|
|
if (0 == GlobalVariable.list_PostInfo.Count)
|
|
{
|
|
Thread.Sleep(10);
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
lock (GlobalVariable.lockList)
|
|
{
|
|
postInfo.postNo = GlobalVariable.list_PostInfo[0].postNo;
|
|
postInfo.recvName = GlobalVariable.list_PostInfo[0].recvName;
|
|
postInfo.recvNo = GlobalVariable.list_PostInfo[0].recvNo;
|
|
postInfo.recvAddress = GlobalVariable.list_PostInfo[0].recvAddress;
|
|
postInfo.sendName = GlobalVariable.list_PostInfo[0].sendName;
|
|
postInfo.sendNo = GlobalVariable.list_PostInfo[0].sendNo;
|
|
postInfo.sendAddress = GlobalVariable.list_PostInfo[0].sendAddress;
|
|
|
|
postInfo.idNoOne = GlobalVariable.list_PostInfo[0].idNoOne;
|
|
|
|
postInfo.applicantName = GlobalVariable.list_PostInfo[0].applicantName;
|
|
|
|
//string strBefore = postInfo.idNoOne.Substring(0, 6);
|
|
//string strBirthday = postInfo.idNoOne.Substring(6, 8);
|
|
//strBirthday = strBirthday.Replace(strBirthday, "********");
|
|
//string strAfter = postInfo.idNoOne.Substring(14, 4);
|
|
//postInfo.idNoOne = strBefore + strBirthday + strAfter;
|
|
GlobalVariable.list_PostInfo.RemoveAt(0);
|
|
}
|
|
}
|
|
|
|
string emsTxt = null;
|
|
if (!CreateEmsTxt(postInfo,ref emsTxt))
|
|
{
|
|
HandleErrMsg("生成打印信息错误,请重启软件再试");
|
|
}
|
|
if (!ReplaceEmsTxt(GlobalVariable.printTxtPath,emsTxt))
|
|
{
|
|
HandleErrMsg("替换打印信息错误,请重启软件再试");
|
|
}
|
|
|
|
if (!ALX92X.SendPrintFile(GlobalVariable.printTxtPath, 1000, 300))
|
|
HandleErrMsg("发送标签信息失败,请检查网络连接再重新启动");
|
|
//}
|
|
|
|
if (GlobalVariable.bRunEmpty)
|
|
{
|
|
do
|
|
{
|
|
Thread.Sleep(10);
|
|
} while (0 == control.read_by_name("数据就绪"));
|
|
|
|
if (!ALX92X.SendPrintFile(GlobalVariable.clearTxtPath, 1000, 300))
|
|
HandleErrMsg("发送清除标签信息指令失败,请检查网络连接再重新启动");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|