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.

87 lines
2.8 KiB
C#

using BarTenderPrint.codeType;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace BarTenderPrint
{
public class QRCodePrintEquip:PrintEquip
{
public override bool AddPara()
{
var para = base.ParaClass as barcodLable;
if (para != null)
{
try
{
ICodeType equip = DynamicClass(para.codeType);
if (equip == null)
{
Console.WriteLine("未找到动态生成类");
return false;
}
string barcode = equip.GetBarcode(para);//返回字符串用,隔开
Console.WriteLine($"条码:{barcode}");
string[] barcodeList = barcode.Split(',');
if (barcodeList.Length < 1)
{
Console.WriteLine("字符串返回为空");
return false ;
}
if (para.codeType == "126")
{
base.EngineFormat.SubStrings["code0"].Value = barcodeList[0];
return true;
}
base.EngineFormat.SubStrings["code0"].Value = barcodeList[0];
if (barcodeList.Length > 1)
{
for (int i = 1; i < barcodeList.Length; i++)
{
string code = "code" + i.ToString();
base.EngineFormat.SubStrings[code].Value = barcodeList[i];
}
}
if (para.codeType == "102")
{
base.EngineFormat.SubStrings["code5"].Value = para.ZJWeight;
}
return true;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return false;
}
}
else
{
return false;
}
}
private ICodeType DynamicClass(string codeType)
{
try
{
//根据类型,动态生成业务类
Assembly assembly = Assembly.GetExecutingAssembly(); // 获取当前程序集
string AssemName = "BarTenderPrint.codeType.codeType" + codeType;
Console.WriteLine("动态生成类:" + AssemName);
//var obj = assembly.CreateInstance(AssemName, true);
return (ICodeType)assembly.CreateInstance(AssemName); ;
}
catch (Exception ex)
{
return null;
}
}
}
}