C#调用bartender打印标签配置和测试说明

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

C#调用bartender打印标签第一部分:配置说明//useLegacyV2RuntimeActivationPolicy=true;在app.config中添加一个配置节:startup//增加引用,BarTender10.1和Seagull.Bartender.Print两个引用.dll文件//一个两个方法(用数据库和具名数据源作为区分)//方法1:配置如下//标签test1.btw设置为具名数据源(数据源类型为镶入的数据)同时配对每一个输出标签格//方法2:配置如下//标签test.btw设置为数据库(以excel为数据库)同时配对每一个输出标签格第二部分:界面和代码usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSeagull.BarTender.Print;usingSystem;usingSystem.Diagnostics;usingSystem.Drawing.Printing;namespaceWindowsFormsApplication1{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}//useLegacyV2RuntimeActivationPolicy=true;在app.config中添加一个配置节:startup//增加引用,BarTender10.1,Seagull.Bartender.Print两个引用privatevoidbutton1_Click(objectsender,EventArgse)//输入内容后选择打印机{BarTender.ApplicationbtApp=newBarTender.Application();BarTender.FormatbtFormat;btFormat=btApp.Formats.Open(@d:\test1.btw,false,);btFormat.PrintSetup.IdenticalCopiesOfLabel=1;btFormat.PrintSetup.NumberSerializedLabels=1;btFormat.SetNamedSubStringValue(StyleNo,this.StyleNotext.Text);btFormat.SetNamedSubStringValue(HelpCode,this.HelpCodetext.Text);btFormat.SetNamedSubStringValue(ProductCategoryName,this.ProductCategoryNametext.Text);btFormat.SetNamedSubStringValue(MetalPurityName,this.MetalPurityNametext.Text);btFormat.SetNamedSubStringValue(MaterialTypeName,this.MaterialTypeNametext.Text);btFormat.SetNamedSubStringValue(RingSize,this.RingSizetext.Text);btFormat.SetNamedSubStringValue(Weight,this.Weighttext.Text);btFormat.SetNamedSubStringValue(StoneQuantity,this.StoneQuantitytext.Text);btFormat.SetNamedSubStringValue(StoneWeight,this.StoneWeighttext.Text);btFormat.PrintOut(false,true);}privatevoidbutton3_Click(objectsender,System.EventArgse)//导出execl后调用模板选择打印机{BarTender.ApplicationbtApp=newBarTender.Application();BarTender.FormatbtFormat;btFormat=btApp.Formats.Open(@d:\test.btw,false,);//btFormat.PrintSetup.IdenticalCopiesOfLabel=1;//btFormat.PrintSetup.NumberSerializedLabels=1;//btFormat.SetNamedSubStringValue(StyleNo,RG170403001);//btFormat.SetNamedSubStringValue(HelpCode,101765);//btFormat.SetNamedSubStringValue(ProductCategoryName,戒指);//btFormat.SetNamedSubStringValue(MetalPurityName,S925);//btFormat.SetNamedSubStringValue(MaterialTypeName,锆石);//btFormat.SetNamedSubStringValue(RingSize,14ch);//btFormat.SetNamedSubStringValue(Weight,1.56);//btFormat.SetNamedSubStringValue(StoneQuantity,33);//btFormat.SetNamedSubStringValue(StoneWeight,0.123);btFormat.PrintOut(false,true);}privatevoidbutton4_Click(objectsender,System.EventArgse)//输入内容后指定打印机{EnginebtEngine=newEngine();btEngine.Start();LabelFormatDocumentbtFormat=btEngine.Documents.Open(d:\\test1.btw);//指定打印机名btFormat.PrintSetup.PrinterName=ArgoxCP-3140LPPLB;//改变标签打印数份连载btFormat.PrintSetup.NumberOfSerializedLabels=1;//打印份数btFormat.PrintSetup.IdenticalCopiesOfLabel=1;btFormat.SubStrings[StyleNo].Value=this.StyleNotext.Text;btFormat.SubStrings[HelpCode].Value=this.HelpCodetext.Text;btFormat.SubStrings[ProductCategoryName].Value=this.ProductCategoryNametext.Text;btFormat.SubStrings[MetalPurityName].Value=this.MetalPurityNametext.Text;btFormat.SubStrings[MaterialTypeName].Value=this.MaterialTypeNametext.Text;btFormat.SubStrings[RingSize].Value=this.Weighttext.Text;btFormat.SubStrings[Weight].Value=this.StoneQuantitytext.Text;btFormat.SubStrings[StoneWeight].Value=this.StoneWeighttext.Text;Messagesmessages;intwaitout=10000;//10秒超时ResultnResult1=btFormat.Print(标签打印软件,waitout,outmessages);btFormat.PrintSetup.Cache.FlushInterval=CacheFlushInterval.PerSession;//不保存对打开模板的修改//btFormat.Close(SaveOptions.DoNotSaveChanges);//结束打印引擎btEngine.Stop();}privatevoidbutton5_Click(objectsender,System.EventArgse)//导出execl后调用模板指定打印机{BarTender.ApplicationbtApp=newBarTender.Application();BarTender.FormatbtFormat;btFormat=btApp.Formats.Open(@d:\test.btw,false,);//btFormat.PrintSetup.IdenticalCopiesOfLabel=1;//btFormat.PrintSetup.NumberSerializedLabels=1;//btFormat.SetNamedSubStringValue(StyleNo,RG170403001);//btFormat.SetNamedSubStringValue(HelpCode,101765);//btFormat.SetNamedSubStringValue(ProductCategoryName,戒指);//btFormat.SetNamedSubStringValue(MetalPurityName,S925);//btFormat.SetNamedSubStringValue(MaterialTypeName,锆石);//btFormat.SetNamedSubStringValue(RingSize,14ch);//btFormat.SetNamedSubStringValue(Weight,1.56);//btFormat.SetNamedSubStringValue(StoneQuantity,33);//btFormat.SetNamedSubStringValue(StoneWeight,0.123);btFormat.PrintOut(false,false);}privatevoidbutton2_Click(objectsender,System.EventArgse)//同一模板选择打印机//特别说明这里要测试的是同一个模板,先设置数据库再设置具名数据源的情况下报错//报错代码为btFormat.SetNamedSubStringValue(StyleNo,this.StyleNotext.Text);找不到具名数据源//测试之后发现,不能同时支持数据库和具名数据源两个配置{this.StyleNotext.Text=654321;this.HelpCodetext.Text=123456;this.ProductCategoryNametext.Text=戒指;this.MetalPurityNametext.Text=18红黄白;this.MaterialTypeNametext.Text=爆炸石;this.RingSizetext.Text=12VI;this.Weighttext.Text=1.45;this.StoneQuantitytext.Text=22;this.StoneWeighttext.Text=0.034;BarTender.ApplicationbtApp=newBa

1 / 7
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功