用BarTender Vs FastReport 打印二維碼 比較


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;
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM