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.

85 lines
3.4 KiB
C#

using SlnMesnac.LabelPrint.Bartender.equip;
using SlnMesnac.LabelPrint.Common;
using SlnMesnac.LabelPrint.Log4net;
using SlnMesnac.LabelPrint.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.LabelPrint.BarTender.equip
{
public class UnitLabelPrintEquip : PrintEquip
{
private readonly LogHelper logHelper = LogHelper.Instance;
private readonly JsonChange jsonChange = JsonChange.Instance;
public override bool AddPara()
{
var para = base.ParaClass as BaseLabelInfo;
if (para != null)
{
try
{
logHelper.Info($"打印标签信息:{jsonChange.ModeToJson(para)}");
//base.EngineFormat.SubStrings["rfid"].Value =
// para.column_A.ToString() + para.column_B.ToString() + para.column_C.ToString()
// + para.column_D.ToString() + para.column_E.ToString() + para.column_F.ToString()
// + para.column_G.ToString() + para.column_H.ToString() + para.column_I.ToString()
// + para.column_J.ToString();
//stirng 转为16进制
string msg = "25SUN544858988" + para.column_E.ToString() + "+" + para.column_B.ToString();
byte[] buffer = Encoding.UTF8.GetBytes(msg);
string hexString = BitConverter.ToString(buffer).Replace("-", string.Empty);
//Console.WriteLine(hexString);
base.EngineFormat.SubStrings["rfid"].Value = hexString;
base.EngineFormat.SubStrings["qrcode"].Value = "25SUN544858988" + para.column_E.ToString() + "+" + para.column_B.ToString();
base.EngineFormat.SubStrings["exp.date"].Value = ReformatDate(para.column_D.ToString());
base.EngineFormat.SubStrings["lot"].Value = para.column_C.ToString();
base.EngineFormat.SubStrings["serial"].Value = para.column_B.ToString();
base.EngineFormat.SubStrings["p/n"].Value = para.column_E.ToString();
base.EngineFormat.SubStrings["barcode"].Value = para.column_B.ToString();
//"UN1H1/Y2.0/170/23 USA/+AA1964" +
return true;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return false;
}
}
else
{
return false;
}
}
// 私有方法:重新组合日期字符串
private static string ReformatDate(string inputDate)
{
try
{
// 使用 DateTime.ParseExact 解析输入日期字符串
DateTime date = DateTime.ParseExact(inputDate, "dd.MM.yyyy", null);
// 使用 ToString 将日期格式化为目标格式
string formattedDate = date.ToString("yyyyMMdd");
return formattedDate;
}
catch (FormatException ex)
{
// 如果解析失败,可以在这里处理异常
Console.WriteLine("日期格式不正确:" + ex.Message);
return string.Empty;
}
}
}
}