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.

169 lines
5.0 KiB
C#

using Seagull.BarTender.Print;
using SlnMesnac.LabelPrint.Bartender.equip;
using SlnMesnac.LabelPrint.BarTender.equip;
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
{
public class PrintManager
{
private LogHelper logHelper = LogHelper.Instance;
#region 单例实现
private static readonly Lazy<PrintManager> lazy = new Lazy<PrintManager>(() => new PrintManager());
public static PrintManager Instance
{
get
{
return lazy.Value;
}
}
#endregion
public PrintManager() { }
/// <summary>
/// 标签打印
/// </summary>
/// <param name="labelInfo"></param>
public bool Print(BaseLabelInfo labelInfo)
{
bool result = false;
try
{
if (labelInfo.productType == "Gas")
{
result = this.PrintGasLabel(labelInfo);
}else if (labelInfo.productType == "TF")
{
result = this.PrintTFLabel(labelInfo);
}else if(labelInfo.productType == "Drum")
{
result = this.PrintDrumLabel(labelInfo);
}else if(labelInfo.productType == "Unit")
{
result = this.PrintUnitLabel(labelInfo);
}else if(labelInfo.productType == "Pallet")
{
result = this.PrintPalletLabel(labelInfo);
}
else
{
logHelper.Info("产品类型未匹配到对应的模板");
}
#region 测试代码
/*Engine btEngine = new Engine();
// 启动Bartender引擎
btEngine.Start();
// 打开打印模板
LabelFormatDocument btFormat = btEngine.Documents.Open(@"C:\Path\To\Your\Template.btw");
// 设置模板中的变量值
btFormat.SubStrings["VariableName"].Value = "Value";
// 打印模板
btFormat.Print();
// 关闭模板
btFormat.Close(SaveOptions.DoNotSaveChanges);
// 关闭Bartender引擎
btEngine.Stop();*/
#endregion
result = true;
}
catch (Exception ex)
{
logHelper.Error("标签打印异常", ex);
}
return result;
}
/// <summary>
/// 气体打印
/// </summary>
/// <param name="labelInfo"></param>
private bool PrintGasLabel(BaseLabelInfo labelInfo)
{
bool result = false;
PrintEquip equip = new GasLabelPrintEquip();
equip.tempPath = "C:\\temp\\bartender打印模板\\Gas.btw";
equip.ParaClass = labelInfo;
equip.Open();
result = equip.print();
equip.Colse();
return result;
}
/// <summary>
/// 不锈钢标签打印
/// </summary>
/// <param name="labelInfo"></param>
private bool PrintTFLabel(BaseLabelInfo labelInfo)
{
bool result = false;
PrintEquip equip = new TFLabelPrintEquip();
equip.tempPath = "C:\\temp\\bartender打印模板\\TF.btw";
equip.ParaClass = labelInfo;
equip.Open();
result = equip.print();
equip.Colse();
return result;
}
/// <summary>
///
/// </summary>
/// <param name="labelInfo"></param>
private bool PrintDrumLabel(BaseLabelInfo labelInfo)
{
bool result = false;
PrintEquip equip = new DrumLabelPrintEquip();
equip.tempPath = "C:\\temp\\bartender打印模板\\Drum.btw";
equip.ParaClass = labelInfo;
equip.Open();
result = equip.print();
equip.Colse();
return result;
}
private bool PrintUnitLabel(BaseLabelInfo labelInfo)
{
bool result = false;
PrintEquip equip = new UnitLabelPrintEquip();
equip.tempPath = "C:\\temp\\bartender打印模板\\Unit.btw";
equip.ParaClass = labelInfo;
equip.Open();
result = equip.print();
equip.Colse();
return result;
}
private bool PrintPalletLabel(BaseLabelInfo labelInfo)
{
bool result = false;
PrintEquip equip = new PalletLabelPrintEquip();
equip.tempPath = "C:\\temp\\bartender打印模板\\Pallet.btw";
equip.ParaClass = labelInfo;
equip.Open();
result = equip.print();
equip.Colse();
return result;
}
}
}