zoukankan      html  css  js  c++  java
  • opcenter调用bartender打印标签

    在服务器上安装bartender 软件,创建一个新的标签模板

    添加一个输入框

    右键点击输入框,打开属性对话框

    命名数据源的名字为Test,关闭对话框,然后保存模板

    打开VS创建一个framework类库BTDemo,打开项目属性对话框,按下图进行更改(EA1BEC9E-833F-4227-8130-9AA0B68E611B)

    添加引用

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

      Seagull.BarTender.Print.dll在C:Program FilesSeagullBarTender 2021SDKAssemblies

    添加类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}
    PrintTemp{temp}
    Printer:{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("
    ", 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

     

    打开desinger 添加userfunction,除了classname为固定以外,其他参数和上面类库项目代码的input output参数对应

     

    然后添加一个server和CLF来调用这个function

     

    添加到事件

     

    updateDB,然后使用API调用看

     

    查看输出的PDF文件

  • 相关阅读:
    js 将图片连接转换称base64格式
    mysql性能优化-慢查询分析、优化索引和配置
    MySQL集群(三)mysql-proxy搭建负载均衡与读写分离
    MySQL集群(二)之主主复制
    MySQL集群(一)之主从复制
    JavaSE(八)之Map总结
    JDBC(二)之JDBC处理CLOB和BLOB及事务与数据库元数据获取
    JavaSE(八)之Collection总结
    JavaSE集合(八)之Map
    JavaSE(八)之集合练习一
  • 原文地址:https://www.cnblogs.com/lidezhen/p/14934687.html
Copyright © 2011-2022 走看看