当前位置: 首页 > news >正文

C#调用barTender打印标签示例

使用的电脑需要先安装BarTender 

 

 

 我封装成一个类

using System;
using System.Windows.Forms;namespace FT_Tools
{public class SysContext{public static BarTender.Application btapp = new BarTender.Application();public static BarTender.Format btFormat;public void Quit(){SysContext.btapp.Quit(BarTender.BtSaveOptions.btSaveChanges);//界面退出时同步退出bartender进程}private static bool btPrint_Test(string modelPath,string txt,string barcode ){try{btFormat = btapp.Formats.Open(modelPath, false, ""); //System.Windows.Forms.Application.StartupPath + @"\1.btw"btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;//打印份数btFormat.PrintSetup.NumberSerializedLabels = 1;//序列标签数btFormat.SetNamedSubStringValue("打印文本", txt.Trim());btFormat.SetNamedSubStringValue("打印条码", barcode.Trim());btFormat.PrintOut(true, false);//第二个false设置打印时是否跳出打印属性btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签return true;}catch (Exception ex){MessageBox.Show(ex.Message);return false;}}}}

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace BarTenderDemo
{public partial class Form1 : Form{private BarTender.Application btAPP;private BarTender.Format btFormat;//SELECT MaterielId,ProductBigPackId,NetWeight,GrossWeight,num //FROM Make_ProductBigPack mpb//LEFT JOIN Make_TaskInfo mti ON mpb.TaskId=mti.TaskId//WHERE ProductBigPackId=''public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){btAPP = new BarTender.Application();}private void btPrint_Click(object sender, EventArgs e){try{btFormat = btAPP.Formats.Open(System.Windows.Forms.Application.StartupPath+@"\1.btw", false, "");btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;//打印份数btFormat.PrintSetup.NumberSerializedLabels = 1;//序列标签数btFormat.SetNamedSubStringValue("打印文本", txtMemo.Text.Trim());btFormat.SetNamedSubStringValue("打印条码", txtBarcode.Text.Trim());btFormat.PrintOut(true, false);//第二个false设置打印时是否跳出打印属性btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签}catch(Exception ex){MessageBox.Show(ex.Message);}}private void Form1_FormClosed(object sender, FormClosedEventArgs e){btAPP.Quit(BarTender.BtSaveOptions.btSaveChanges);//界面退出时同步退出bartender进程}}
}

示例2:与上面一样的。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Runtime.InteropServices;
using BarTender;
using System.Text;
using Newtonsoft.Json;namespace bartenderService
{/// <summary>/// BartenderWebService 的摘要说明/// </summary>[WebService(Namespace = "http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.ComponentModel.ToolboxItem(false)]// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService]public class SysContext{public static BarTender.Application btapp = new BarTender.Application();public static BarTender.Format btfat;}public class BartenderWebService : System.Web.Services.WebService{[WebMethod]public string HelloWorld(){return "Hello World";}[WebMethod]public string GetTestLabelJson(){printContext pt=new printContext();pt.data = new List<printCell>();printCell cell=new printCell();pt.modelName = "气体检测仪.btw";pt.printDateStr = "生产日期";pt.printFBStr = "防爆证号";pt.printGasStr = "测量气体";pt.printSNStr = "产品编号";pt.printTELStr = "热线电话";pt.printVolStr = "工作电压";pt.printRangeStr = "检测范围";cell.printDate = "2019.12";cell.printFB = "CNEX17.0263";cell.printGas = "可燃气体";cell.printRange = "0-100";cell.printVol = "24V";cell.printUnit = "%LEL";cell.printSN = "226013221";pt.data.Add(cell);cell.printGas = "氨气";cell.printUnit = "PPM";pt.data.Add(cell);return JsonConvert.SerializeObject(pt);}[WebMethod]public string PrintLabel(string jsonstr){int printcount = 0,i=0;string path = System.AppDomain.CurrentDomain.BaseDirectory + "model";string file_ini = path + "\\configure.ini";//pt.modelName + pt.data[1].printRange + pt.data[1].printGas//Newtonsoft.Json.Linq.JArray.Parse(jsonstr);printContext pt = JsonConvert.DeserializeObject<printContext>(jsonstr);if (pt.modelName == null)pt.modelName = "";if (pt.modelName == "")pt.modelName = "气体检测仪.btw";try{SysContext.btfat = SysContext.btapp.Formats.Open(path + "\\" + pt.modelName, false, "");}catch{pt.modelName = "气体检测仪.btw";SysContext.btfat = SysContext.btapp.Formats.Open(path + "\\" + pt.modelName, false, "");}SysContext.btfat.PrintSetup.IdenticalCopiesOfLabel = 1;SysContext.btapp.Visible = false;printcount = pt.data.Count();for(i=0;i<printcount;i++){SysContext.btfat.SetNamedSubStringValue("BT_Gas", String.Format(pt.printGasStr+":"+pt.data[i].printGas));SysContext.btfat.SetNamedSubStringValue("BT_Range", String.Format(pt.printRangeStr+":"+pt.data[i].printRange+ pt.data[i].printUnit));SysContext.btfat.SetNamedSubStringValue("BT_Vol", String.Format(pt.printVolStr + ":" + pt.data[i].printVol));SysContext.btfat.SetNamedSubStringValue("BT_SN", String.Format(pt.printSNStr + ":" + pt.data[i].printSN));SysContext.btfat.SetNamedSubStringValue("BT_DATE", String.Format(pt.printDateStr + ":" + pt.data[i].printDate));SysContext.btfat.SetNamedSubStringValue("BT_FB", String.Format(pt.printFBStr + ":" + pt.data[i].printFB));if(pt.data[i].printTEL!=""&& pt.data[i].printTEL !=null)SysContext.btfat.SetNamedSubStringValue("BT_TEL", String.Format(pt.printTELStr + ":" + pt.data[i].printTEL));SysContext.btfat.PrintOut(false, false);} return "ok";}}
}

相关文章:

C#调用barTender打印标签示例

使用的电脑需要先安装BarTender 我封装成一个类 using System; using System.Windows.Forms;namespace FT_Tools {public class SysContext{public static BarTender.Application btapp new BarTender.Application();public static BarTender.Format btFormat;public void Q…...

Spring——Spring读取文件

文章目录 1.通过 value 读取比较简单的配置信息2.通过ConfigurationProperties读取并与 bean 绑定3.通过ConfigurationProperties读取并校验4. PropertySource 读取指定 properties 文件5.题外话:Spring加载配置文件的优先级 很多时候我们需要将一些常用的配置信息比如阿里云os…...

这是一条求助贴(postman测试的时候一直是404)

看到这个问题是404的时候总感觉不该求助大家&#xff0c;404多常见一看就是简单的路径问题&#xff0c;我的好像不是&#xff0c;我把我的问题奉上。 首先我先给出我的url http://10.3.22.195:8080/escloud/rest/escloud_contentws/permissionStatistics/jc-haojl/sz 这是我…...

信号完整性分析基础知识之有损传输线、上升时间衰减和材料特性(四):有损传输线建模

传输线中信号衰减的两个损耗过程是通过信号和返回路径导体的串联电阻以及通过有损耗介电材料的分流电阻。这两个电阻器的电阻都与频率相关。 值得注意的是&#xff0c;理想电阻器的电阻随频率恒定。我们已经证明&#xff0c;在理想的有损传输线中&#xff0c;用于描述损耗的两个…...

elk日志收集系统

目录 前言 一、概述 二、案例 &#xff08;一&#xff09;、环境配置 安装node1与node2节点的elasticsearch node1的elasticsearch-head插件 &#xff08;二&#xff09;、node1服务器安装logstash 测试1&#xff1a; 标准输入与输出 测试2&#xff1a;使用rubydebug解…...

perl 语言中 AUTOLOAD 的用法

这里的 AUTOLOAD可以理解为自动加载。具体来说就是&#xff0c;在正常情况下&#xff0c;我们不能调用一个尚未定义的函数&#xff08;子例程&#xff09;。不过&#xff0c;如果在未定义函数的包中有一个名为 AUTOLOAD的函数&#xff0c;那么对未定义函数的调用都会路由至这个…...

服务器放在香港好用吗?

​  相较于国内服务器&#xff0c;将网站托管在香港服务器上最直观的好处是备案层面上的。香港服务器上的网站无需备案&#xff0c;因此更无备案时限&#xff0c;购买之后即可使用。 带宽优势 香港服务器的带宽一般分为香港本地带宽和国际带宽、直连中国骨干网 CN2三种。香港…...

C++设计模式_01_设计模式简介(多态带来的便利;软件设计的目标:复用)

文章目录 本栏简介1. 什么是设计模式2. GOF 设计模式3. 从面向对象谈起4. 深入理解面向对象5. 软件设计固有的复杂性5.1 软件设计复杂性的根本原因5.2 如何解决复杂性 ? 6. 结构化 VS. 面向对象6.1 同一需求的分解写法6.1.1 Shape1.h6.1.2 MainForm1.cpp 6.2 同一需求的抽象的…...

Docker技术--WordPress博客系统部署初体验

如果使用的是传统的项目部署方式,你要部署WordPress博客系统,那么你需要装备一下的环境,才可以部署使用。 -1:操作系统linux -2:PHP5.6或者是更高版本环境 -3:MySQL数据环境 -4:Apache环境 但是如果使用Docker技术,那么就只需要进行如下的几行简单的指令: docker run …...

提高代码可读性和可维护性的命名建议

当进行接口自动化测试时&#xff0c;良好的命名可以提高代码的可读性和可维护性。以下是一些常用的命名建议&#xff1a; 变量和函数命名&#xff1a; 使用具有描述性的名称&#xff0c;清晰地表达变量或函数的用途和含义。使用小写字母和下划线来分隔单词&#xff0c;例如 log…...

Docker基础入门:Docker网络与微服务项目发布

Docker基础入门&#xff1a;Docker网络与微服务项目发布 一、前言二、Docker0理解2.1 ip a查看当前网络环境2.2 实战--启动一个tomact01容器&#xff08;查看网络环境&#xff09;2.3 实战--启动一个tomact02容器&#xff08;查看网络环境&#xff09;2.4 容器与容器之间的通信…...

Docker安装详细步骤

Docker安装详细步骤 1、安装环境准备 主机&#xff1a;192.168.40.5 zch01 设置主机名 # hostnamectl set-hostname zch01 && bash 配置hosts文件 [root ~]# vi /etc/hosts 添加如下内容&#xff1a; 192.168.40.5 zch01 关闭防火墙 [rootzch01 ~]# systemct…...

十六、pikachu之SSRF

文章目录 1、SSRF概述2、SSRF&#xff08;URL&#xff09;3、SSRF&#xff08;file_get_content&#xff09; 1、SSRF概述 SSRF(Server-Side Request Forgery&#xff1a;服务器端请求伪造)&#xff1a;其形成的原因大都是由于服务端提供了从其他服务器应用获取数据的功能&…...

最新PHP短网址生成系统/短链接生成系统/URL缩短器系统源码

全新PHP短网址系统URL缩短器平台&#xff0c;它使您可以轻松地缩短链接&#xff0c;根据受众群体的位置或平台来定位受众&#xff0c;并为缩短的链接提供分析见解。 系统使用了Laravel框架编写&#xff0c;前后台双语言使用&#xff0c;可以设置多域名&#xff0c;还可以开设套…...

漱玉平民大药房:多元化药店变革的前夜

作者 | 王聪彬 编辑 | 舞春秋 来源 | 至顶网 本文介绍了漱玉平民大药房在药品零售领域的数字化转型和发展历程。通过技术创新&#xff0c; 漱玉平民 建设了覆盖医药全生命周期的大健康生态圈&#xff0c;采用混合云架构和国产分布式数据库 TiDB&#xff0c;应对庞大的会员数据处…...

如何实现AI的矢量数据库

推荐&#xff1a;使用 NSDT场景编辑器 助你快速搭建3D应用场景 然而&#xff0c;人工智能模型有点像美食厨师。他们可以创造奇迹&#xff0c;但他们需要优质的成分。人工智能模型在大多数输入上都做得很好&#xff0c;但如果它们以最优化的格式接收输入&#xff0c;它们就会真正…...

Java与Modbus-TCP/IP网络通讯

1.需求样例 举例5&#xff1a;浮点数参数读取&#xff08;读取温度测量值&#xff09;查看参数列表&#xff0c;温度测量值地址为320&#xff0c;根据Modbus协议&#xff0c;读取参数地址转换为16进制为&#xff1a;00H A0H&#xff0c;读取长度为2个字&#xff1a;00H 02H。 …...

音视频 ffmpeg命令图片与视频互转

截取一张图片 ffmpeg -i test.mp4 -y -f image2 -ss 00:00:02 -vframes 1 -s 640x360 test.jpg ffmpeg -i test.mp4 -y -f image2 -ss 00:00:02 -vframes 1 -s 640x360 test.bmp -i 输入 -y 覆盖 -f 格式 image2 一种格式 -ss 起始值 -vframes 帧 如果大于1 那么 输出加%03d t…...

C++的基类和派生类构造函数

基类的成员函数可以被继承&#xff0c;可以通过派生类的对象访问&#xff0c;但这仅仅指的是普通的成员函数&#xff0c;类的构造函数不能被继承。构造函数不能被继承是有道理的&#xff0c;因为即使继承了&#xff0c;它的名字和派生类的名字也不一样&#xff0c;不能成为派生…...

C语言中对json格式数据的解析和封装

首先需要调库&#xff1a;#include <cJSON.h> Json的数据结构介绍&#xff1a; /* The cJSON structure: */ typedef struct cJSON { /*next/prev允许您遍历数组/对象链。或者&#xff0c;使用GetArraySize/GetArrayItem/GetObjectItem */ struct cJSON *next; struct c…...

谷歌浏览器插件

项目中有时候会用到插件 sync-cookie-extension1.0.0&#xff1a;开发环境同步测试 cookie 至 localhost&#xff0c;便于本地请求服务携带 cookie 参考地址&#xff1a;https://juejin.cn/post/7139354571712757767 里面有源码下载下来&#xff0c;加在到扩展即可使用FeHelp…...

idea大量爆红问题解决

问题描述 在学习和工作中&#xff0c;idea是程序员不可缺少的一个工具&#xff0c;但是突然在有些时候就会出现大量爆红的问题&#xff0c;发现无法跳转&#xff0c;无论是关机重启或者是替换root都无法解决 就是如上所展示的问题&#xff0c;但是程序依然可以启动。 问题解决…...

React 第五十五节 Router 中 useAsyncError的使用详解

前言 useAsyncError 是 React Router v6.4 引入的一个钩子&#xff0c;用于处理异步操作&#xff08;如数据加载&#xff09;中的错误。下面我将详细解释其用途并提供代码示例。 一、useAsyncError 用途 处理异步错误&#xff1a;捕获在 loader 或 action 中发生的异步错误替…...

【力扣数据库知识手册笔记】索引

索引 索引的优缺点 优点1. 通过创建唯一性索引&#xff0c;可以保证数据库表中每一行数据的唯一性。2. 可以加快数据的检索速度&#xff08;创建索引的主要原因&#xff09;。3. 可以加速表和表之间的连接&#xff0c;实现数据的参考完整性。4. 可以在查询过程中&#xff0c;…...

Cinnamon修改面板小工具图标

Cinnamon开始菜单-CSDN博客 设置模块都是做好的&#xff0c;比GNOME简单得多&#xff01; 在 applet.js 里增加 const Settings imports.ui.settings;this.settings new Settings.AppletSettings(this, HTYMenusonichy, instance_id); this.settings.bind(menu-icon, menu…...

解决本地部署 SmolVLM2 大语言模型运行 flash-attn 报错

出现的问题 安装 flash-attn 会一直卡在 build 那一步或者运行报错 解决办法 是因为你安装的 flash-attn 版本没有对应上&#xff0c;所以报错&#xff0c;到 https://github.com/Dao-AILab/flash-attention/releases 下载对应版本&#xff0c;cu、torch、cp 的版本一定要对…...

今日科技热点速览

&#x1f525; 今日科技热点速览 &#x1f3ae; 任天堂Switch 2 正式发售 任天堂新一代游戏主机 Switch 2 今日正式上线发售&#xff0c;主打更强图形性能与沉浸式体验&#xff0c;支持多模态交互&#xff0c;受到全球玩家热捧 。 &#x1f916; 人工智能持续突破 DeepSeek-R1&…...

HDFS分布式存储 zookeeper

hadoop介绍 狭义上hadoop是指apache的一款开源软件 用java语言实现开源框架&#xff0c;允许使用简单的变成模型跨计算机对大型集群进行分布式处理&#xff08;1.海量的数据存储 2.海量数据的计算&#xff09;Hadoop核心组件 hdfs&#xff08;分布式文件存储系统&#xff09;&a…...

【SSH疑难排查】轻松解决新版OpenSSH连接旧服务器的“no matching...“系列算法协商失败问题

【SSH疑难排查】轻松解决新版OpenSSH连接旧服务器的"no matching..."系列算法协商失败问题 摘要&#xff1a; 近期&#xff0c;在使用较新版本的OpenSSH客户端连接老旧SSH服务器时&#xff0c;会遇到 "no matching key exchange method found"​, "n…...

day36-多路IO复用

一、基本概念 &#xff08;服务器多客户端模型&#xff09; 定义&#xff1a;单线程或单进程同时监测若干个文件描述符是否可以执行IO操作的能力 作用&#xff1a;应用程序通常需要处理来自多条事件流中的事件&#xff0c;比如我现在用的电脑&#xff0c;需要同时处理键盘鼠标…...