C#调⽤BarTender模板打印
/// <summary>
/// 调⽤BarTender打印,模板的变量为:barcode0,,barcode7 (内循环打印集合列表) /// </summary>
/// <param name="pPrinter">打印机名称,必填</param>
/// <param name="pTagsTemplateId">标签模板ID,必填</param>
/// <param name="pPrintParameterList">打印参数列表,必填</param>
/// <param name="checkBillId">单据ID</param>
/// <param name="cellNum">每⾏打印的列数</param>
public static bool BarcodePrint(string pPrinter, string pTagsTemplateId,
List<PrintParameterObj> pPrintParameterList, string checkBillId, int cellNum)
{
BarTender.ApplicationClass btApp = null;
BarTender.Format btFormat = null;
bool isPrintOut = false;
try
{
if (string.IsNullOrEmpty(pPrinter))
{
MessageBox.Show(@"请检查打印驱动程序设置!");
return isPrintOut;
}
if (string.IsNullOrEmpty(pTagsTemplateId))
{
MessageBox.Show(@"请选择打印的模板!");
return isPrintOut;
}
var clsTagsTemplateObj = TemplateBusiness.GetObjectById(pTagsTemplateId);
if (clsTagsTemplateObj == null)
{
MessageBox.Show(@"不到所需的模板!");
return isPrintOut;
}
modCommon.GetTemplateFile(clsTagsTemplateObj);
var errMsg = "";
modCommon.DownloadAndCreatTemplate(clsTagsTemplateObj.FileName, out errMsg);
if (!string.IsNullOrEmpty(errMsg))
{
MessageBox.Show(errMsg, GenericContext.strTip);
return isPrintOut;
}
var templateFullPath = modCommon.TagsTemplateDir + @"\" + clsTagsTemplateObj.FileName;
btApp = new BarTender.ApplicationClass();
btFormat = btApp.Formats.Open(templateFullPath, false, "");
btFormat.Printer = pPrinter;
if (pPrintParameterList != null && pPrintParameterList.Count > 0)
{
int iNum = 0;
string strWhere = string.Empty;
for (int i = 0; i < pPrintParameterList.Count; i++)
{
try
{
btFormat.SetNamedSubStringValue(("barcode" + iNum), pPrintParameterList[i].ParameterValue);
}
catch
{
MessageBox.Show("打印模板错误", GenericContext.strTip);
return false;
}
//组合更新数据的条件
if (!string.IsNullOrEmpty(pPrintParameterList[i].ParameterValue)) strWhere += ("'" + pPrintParameterList[i].ParameterValue + "',");
if (iNum == cellNum - 1)
{
iNum = 0;
btFormat.PrintOut(false, false);
//更新明细数据状态
if (!string.IsNullOrEmpty(strWhere))
{
strWhere = strWhere.Substring(0, strWhere.Length - 1); CheckDetailBusiness.CheckDetailUpdate(strWhere, checkBillId);
}
strWhere = string.Empty;
}
else
iNum++;
}
}
isPrintOut = true;
}
catch
{
MessageBox.Show("调⽤模板打印时发⽣错误", GenericContext.strTip); return false;
generic打印机}
finally
{
if (btFormat != null)
btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
if (btApp != null)
btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
}
return isPrintOut;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论