欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#調用barTender打印標簽示例的實現(xiàn)

 更新時間:2023年08月28日 14:46:55   作者:小黃人軟件  
Bartender是最優(yōu)秀的條碼打印軟件,在企業(yè)里使用非常普遍,本文主要介紹了C#調用barTender打印標簽示例的實現(xiàn),具有一定的參考價值,感興趣的可以了解一下

使用的電腦需要先安裝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;//打印份數(shù)
                btFormat.PrintSetup.NumberSerializedLabels = 1;//序列標簽數(shù)
                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;//打印份數(shù)
                btFormat.PrintSetup.NumberSerializedLabels = 1;//序列標簽數(shù)
                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打印標簽示例的實現(xiàn)的文章就介紹到這了,更多相關C#調用barTender打印標簽內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • UGUI輪播圖組件實現(xiàn)方法詳解

    UGUI輪播圖組件實現(xiàn)方法詳解

    這篇文章主要為大家詳細介紹了UGUI輪播圖組件的實現(xiàn)方法,支持自動輪播、手勢切換等功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-03-03
  • 詳解C#中的定時器Timer類及其垃圾回收機制

    詳解C#中的定時器Timer類及其垃圾回收機制

    這篇文章主要介紹了C#中的定時器Timer類及其垃圾回收機制,講解了Timer相關的單線程異步工作,需要的朋友可以參考下
    2016-04-04
  • 深入學習C#網絡編程之HTTP應用編程(上)

    深入學習C#網絡編程之HTTP應用編程(上)

    這篇文章主要介紹了如何學習C#網絡編程之HTTP應用編程的相關知識,文中講解的非常細致,代碼幫助大家更好的理解和學習,感興趣的朋友可以了解下
    2020-06-06
  • C#求n個數(shù)中最大值和最小值的方法

    C#求n個數(shù)中最大值和最小值的方法

    這篇文章主要介紹了C#求n個數(shù)中最大值和最小值的方法,涉及C#中max及min方法的使用技巧,需要的朋友可以參考下
    2015-05-05
  • 基于C#制作一個休息提醒鬧鐘的詳細步驟

    基于C#制作一個休息提醒鬧鐘的詳細步驟

    小鬧鐘大家都應該很熟悉,它包括時間、事件,當達到某某時間時,事件發(fā)生了,并且還有一個提示信息,下面這篇文章主要給大家介紹了關于如何基于C#制作一個休息提醒鬧鐘的詳細步驟,需要的朋友可以參考下
    2023-02-02
  • C#中ArrayList?類的使用詳解

    C#中ArrayList?類的使用詳解

    這篇文章主要介紹了C#中ArrayList?類的使用詳解,動態(tài)數(shù)組ArrayList類在System.Collecions的命名空間下,所以使用時要加入System.Collecions命名空間,而且ArrayList提供添加,插入或移除某一范圍元素的方法
    2022-09-09
  • C#以太網Sockets客戶端設計實現(xiàn)

    C#以太網Sockets客戶端設計實現(xiàn)

    本文主要介紹了C#以太網Sockets客戶端設計實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-02-02
  • C#生成漂亮驗證碼完整代碼類

    C#生成漂亮驗證碼完整代碼類

    本文主要介紹了C#生成漂亮驗證碼的完整代碼類。具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03
  • C# WinForm實現(xiàn)畫筆簽名功能

    C# WinForm實現(xiàn)畫筆簽名功能

    這篇文章主要為大家詳細介紹了如何通過 C# WinForm 通過畫布畫筆實現(xiàn)手寫簽名,并在開發(fā)過程中解決遇到的一些格式轉換的問題簽名功能,希望對大家有所幫助
    2024-11-11
  • C# 實現(xiàn)的圖片蓋章功能,支持拖拽、旋轉、放縮、保存

    C# 實現(xiàn)的圖片蓋章功能,支持拖拽、旋轉、放縮、保存

    這篇文章主要介紹了C# 實現(xiàn)的圖片蓋章功能,支持拖拽、旋轉、放縮、保存,需要的朋友可以參考下
    2014-04-04

最新評論