天天看點

opcenter調用bartender列印标簽

在伺服器上安裝bartender 軟體,建立一個新的标簽模闆

opcenter調用bartender列印标簽
opcenter調用bartender列印标簽
添加一個輸入框
opcenter調用bartender列印标簽
右鍵點選輸入框,打開屬性對話框
opcenter調用bartender列印标簽
命名資料源的名字為Test,關閉對話框,然後儲存模闆
opcenter調用bartender列印标簽
opcenter調用bartender列印标簽
打開VS建立一個framework類庫BTDemo,打開項目屬性對話框,按下圖進行更改(EA1BEC9E-833F-4227-8130-9AA0B68E611B)
opcenter調用bartender列印标簽
opcenter調用bartender列印标簽

添加引用

Camstar.AppServer.BusinessLogic.CustomProcImpl.dll,Camstar.AppServer.BusinessLogic.CustomProcParameters.dll,Newtonsoft.Json.dll在C:\Program Files (x86)\Camstar\InSite Server目錄,

  Seagull.BarTender.Print.dll在C:\Program Files\Seagull\BarTender 2021\SDK\Assemblies

opcenter調用bartender列印标簽
添加類BarTend

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Camstar.AppServer.BusinessLogic;
using Newtonsoft.Json;
using Seagull.BarTender.Print;

namespace BTDemo
{
    [ClassInterface(ClassInterfaceType.None)]
    public class BarTend : CustomProcImpl
    {
        protected override bool Execute()
        {
            try
            {
                var data = this.GetInputParam("PrintData").ToString();//列印資料
                var temp = this.GetInputParam("PrintTemp").ToString();//列印模闆路徑
                var row = (int)this.GetInputParam("PrintRow");//列印行數
                var col =(int) this.GetInputParam("PrintCol");//列印列數
                var  printer= this.GetInputParam("Printer").ToString();//列印機
                var values= JsonConvert.DeserializeObject<IEnumerable< PrintData>>(data);
                if (values.Any())
                {
                   // LogInfo ($"PrintData:{data}\nPrintTemp{temp}\nPrinter:{printer}");
                    Engine engine = new Engine(true);
                    var format = engine.Documents.Open(temp);
                    foreach (var subString in format.SubStrings)
                    {
                        var val = values.FirstOrDefault(m => m.Name == subString.Name);
                        //注冊資料
                        if (val!=null)
                        {
                            subString.Value = val.Value;
                        }
                    }
                    format.PrintSetup.PrinterName = printer;//列印機
                    format.PrintSetup.IdenticalCopiesOfLabel = row;  //設定同序列列印的份數
                    format.PrintSetup.NumberOfSerializedLabels = col;  //設定需要列印的序列數 
                    var result = format.Print("LabelPrint", 60, out var messages);
                    SetOutputParam("PrintStatus", result == Result.Success ? "1" : "0");
                    SetOutputParam("PrintMessage",string.Join("\n", from message in messages select  message.Text));

                    if (engine != null)      

                          engine.Stop(SaveOptions.DoNotSaveChanges);

}
                return true;
            }
            catch (Exception ex)
            {
                this.ErrorLabelName = "ErrorText";
                this.SetErrorParam("ErrorMessage", (object)ex.ToString());
                this.SetErrorParam("FunctionName", (object)ex.GetType().FullName);
                this.LogError(ex.ToString());
                return false;
            }
        }
        public void LogError(string error)
        {
            try
            {
                string source = "BarTend";
                string logName = "CustProc";
                if (!EventLog.SourceExists(source))
                    EventLog.CreateEventSource(new EventSourceCreationData(source, logName));
                new EventLog() { Source = source }.WriteEntry(error, EventLogEntryType.Error);
            }
            catch (Exception ex)
            {
            }
        }
        public void LogInfo(string error)
        {
            try
            {
                string source = "BarTend";
                string logName = "CustProc";
                if (!EventLog.SourceExists(source))
                    EventLog.CreateEventSource(new EventSourceCreationData(source, logName));
                new EventLog() { Source = source }.WriteEntry(error, EventLogEntryType.Information);
            }
            catch (Exception ex)
            {
            }
        }
    }

    public class PrintData
    {
        public string Name { get; set; }
        public string Value { get; set; }
        public string DataType { get; set; }
    }
}      

生成項目,把檔案複制到insite server

opcenter調用bartender列印标簽

打開desinger 添加userfunction,除了classname為固定以外,其他參數和上面類庫項目代碼的input output參數對應

opcenter調用bartender列印标簽
opcenter調用bartender列印标簽
opcenter調用bartender列印标簽

然後添加一個server和CLF來調用這個function

opcenter調用bartender列印标簽
opcenter調用bartender列印标簽

添加到事件

opcenter調用bartender列印标簽

updateDB,然後使用API調用看

opcenter調用bartender列印标簽
opcenter調用bartender列印标簽

檢視輸出的PDF檔案

opcenter調用bartender列印标簽