BarTender 要用企业版,才能动态指定数据

 

BarTender.Application btApp= new BarTender.Application(); //初始化需要5秒
var btw = GlobalVariable.btApp.Formats.Open(Application.StartupPath + "\\aaa.btw");
                btw.SetNamedSubStringValue("PackCnt", lblOKCnt.Text);
                btw.SetNamedSubStringValue("ProdLine", tslProdLine.Text);
                btw.SetNamedSubStringValue("Material", tslMaterial.Text);
                btw.SetNamedSubStringValue("Customer", lblCustomer.Text);
                string strQRCode=tslProdLine.Text + "|" + tslBanCi.Text + "|" 
                    + GlobalVariable.UserName.ToUpper() + "|" + tslMaterial.Text + "|" 
                    + DateTime.Now.ToString("yyyyMMdd") + "|" + (CurrentLayer+1).ToString("00");
                btw.SetNamedSubStringValue("strQRCode", strQRCode);

                BarTender.Messages barTenderMsg;
                btw.Print("aaa",true,2000,out barTenderMsg);

  Bartender第一次启动太慢

用FastReport 也要用破解版才行, github开源的是一个设计器,没有打印功能的.

        private bool FastReportPrint()
        {
            try
            {
                //创建Report对象
                var report = new Report();
                //获得模板的路径
                string reportLabel = Application.StartupPath + @"\" + "ndk.frx";
                //判断文件是否存在
                if (!File.Exists(reportLabel))
                {
                    MessageBox.Show("标签模板不存在!请先获取标签模板!");
                }
                //清空
                report.Clear();
                //加载报表模板
                report.Load(reportLabel);
                //获取模板中,对应的TextObject节点-替换模板内容


                string strQRCode = tslProdLine.Text + "|" + tslBanCi.Text + "|"
                    + GlobalVariable.UserName.ToUpper() + "|" + tslMaterial.Text + "|"
                    + DateTime.Now.ToString("yyyyMMdd") + "|" + (CurrentLayer + 1).ToString("00");

                //实际数据模型
                var model = new
                {
                    PackCnt = lblOKCnt.Text,
                    PackUser = GlobalVariable.UserName,
                    PackTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    ProdLine = tslProdLine.Text,
                    Material = tslMaterial.Text,
                    Customer = lblCustomer.Text,
                    strQRCode = strQRCode
                };
                var list = model.GetType().GetProperties();
                //批量设置打印模板参数值
                foreach (PropertyInfo pro in list)
                {
                    var value = pro.GetValue(model, null);
                    //获取参数
                    FastReport.Data.Parameter param = report.Parameters.FindByName(pro.Name);
                    if (param != null)
                    {
                        param.Value = value; //将属性的值赋值给名字相同的报表参数                     
                    }
                }
                var qr = report.FindObject("Barcode1") as BarcodeObject;
                qr.Text = strQRCode;

                //关闭生成进度条
                EnvironmentSettings eSet = new EnvironmentSettings();
                eSet.ReportSettings.ShowProgress = false;
                //关闭对话框
                report.PrintSettings.ShowDialog = false;
                //运行报表
                report.Prepare();
                string strPrintName = GlobalVariable.PrinterName;
                report.PrintSettings.Printer = strPrintName;//"Microsoft XPS Document Writer";//设置打印机
                // 运行报表打印
                report.Print();
                // 释放使用的资源
                report.Dispose();

                ////获取打印机的名称,这里是通过封装的方法去获取打印机名,这里可以直接指定“打印机名称”;
                //string strPrintName = GlobalVariable.PrinterName;
                //if (string.IsNullOrWhiteSpace(strPrintName))
                //{
                //    MessageBox.Show("未设置打印机!");
                //    return false;
                //}

    
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }

 

posted on 2020-09-21 13:52  Gu  阅读(848)  评论(2编辑  收藏  举报