实例介绍
【实例简介】调用bartender软件进行打印操作,支持bartender9.4 10.0版本
【实例截图】中节能代工唛头打印
【核心代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Oracle.ManagedDataAccess;
using Oracle.ManagedDataAccess.Client;
namespace WindowsFormsApp1
{
public partial class bartender : Form
{
// private BarTender.Application btapp;
BarTender.Application btApp=new BarTender.Application();
BarTender.Format btFormat;
// OpenFileDialog fileDlg = new OpenFileDialog();
public bartender()
{
InitializeComponent();
}
private void Form1_Load(object sender, KeyPressEventArgs e)
{
// btApp = new BarTender.Application();
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog fileDlg = new OpenFileDialog();
// 设置打开控件后,默认程序所在盘
fileDlg.InitialDirectory = Application.StartupPath;
// 设置控件打开的文件类型
//fileDlg.Filter = "hex files(*.hex)| *.hex";
// 设置控件打开文件类型的显示顺序
fileDlg.FilterIndex = 1;
// 设置对话框是否记忆之前打开的目录
fileDlg.RestoreDirectory = true;
if (fileDlg.ShowDialog() == DialogResult.OK)
{
file.Text = fileDlg.FileName;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length == 0)
{
MessageBox.Show("未输入箱号");
}
else
{
string cartionid = textBox1.Text;
OracleConnection conn = null;
try
{
//获取与数据库的连接对象
conn = new OracleConnection();
//绑定连接字符串
conn.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.0.24.13)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=module)));Persist Security Info=True;User ID=mycim;Password=mycim;";
//开启连接
conn.Open();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "select max(nvl(case when ROWNUM = 1 then lp.lot_id end, 0)) tm1,"
" max(nvl(case when ROWNUM = 2 then lp.lot_id end, 0)) tm2,"
" max(nvl(case when ROWNUM = 3 then lp.lot_id end, 0)) tm3 ,"
" max(nvl(case when rownum = 4 then lp.lot_id end, 0)) tm4,"
" max(nvl(case when rownum = 5 then lp.lot_id end, 0)) tm5,"
" max(nvl(case when rownum = 6 then lp.lot_id end, 0)) tm6,"
" max(nvl(case when rownum = 7 then lp.lot_id end, 0)) tm7,"
" max(nvl(case when rownum = 8 then lp.lot_id end, 0)) tm8,"
" max(nvl(case when rownum = 9 then lp.lot_id end, 0)) tm9,"
" max(nvl(case when rownum = 10 then lp.lot_id end, 0)) tm10,"
" max(nvl(case when rownum = 11 then lp.lot_id end, 0)) tm11,"
" max(nvl(case when rownum = 12 then lp.lot_id end, 0)) tm12,"
" max(nvl(case when rownum = 13 then lp.lot_id end, 0)) tm13,"
" max(nvl(case when rownum = 14 then lp.lot_id end, 0)) tm14,"
" max(nvl(case when rownum = 15 then lp.lot_id end, 0)) tm15,"
" max(nvl(case when rownum = 16 then lp.lot_id end, 0)) tm16,"
" max(nvl(case when rownum = 17 then lp.lot_id end, 0)) tm17,"
" max(nvl(case when rownum = 18 then lp.lot_id end, 0)) tm18,"
" max(nvl(case when rownum = 19 then lp.lot_id end, 0)) tm19,"
" max(nvl(case when rownum = 20 then lp.lot_id end, 0)) tm20,"
" max(nvl(case when rownum = 21 then lp.lot_id end, 0)) tm21,"
" max(nvl(case when rownum = 22 then lp.lot_id end, 0)) tm22,"
" max(nvl(case when rownum = 23 then lp.lot_id end, 0)) tm23,"
" max(nvl(case when rownum = 24 then lp.lot_id end, 0)) tm24,"
" max(nvl(case when rownum = 25 then lp.lot_id end, 0)) tm25,"
" max(nvl(case when rownum = 26 then lp.lot_id end, 0)) tm26,"
" t.palletsmall,t.palletbig"
" from lot_package lp, pallet p,test009 t where lp.pallet_rrn = p.pallet_rrn and p.carton_id=t.cartonid and p.carton_id = " "'" cartionid "'"
"group by t.palletsmall,t.palletbig";
cmd.CommandType = CommandType.Text;
//执行并设置返回值
IDataReader reader = null;
reader = cmd.ExecuteReader();
while (reader.Read())
{
string tm1 = reader["tm1"].ToString();
string tm2 = reader["tm2"].ToString();
string tm3 = reader["tm3"].ToString();
string tm4 = reader["tm4"].ToString();
string tm5 = reader["tm5"].ToString();
string tm6 = reader["tm6"].ToString();
string tm7 = reader["tm7"].ToString();
string tm8 = reader["tm8"].ToString();
string tm9 = reader["tm9"].ToString();
string tm10 = reader["tm10"].ToString();
string tm11 = reader["tm11"].ToString();
string tm12 = reader["tm12"].ToString();
string tm13 = reader["tm13"].ToString();
string tm14 = reader["tm14"].ToString();
string tm15 = reader["tm15"].ToString();
string tm16 = reader["tm16"].ToString();
string tm17 = reader["tm17"].ToString();
string tm18 = reader["tm18"].ToString();
string tm19 = reader["tm19"].ToString();
string tm20 = reader["tm20"].ToString();
string tm21 = reader["tm21"].ToString();
string tm22 = reader["tm22"].ToString();
string tm23 = reader["tm23"].ToString();
string tm24 = reader["tm24"].ToString();
string tm25 = reader["tm25"].ToString();
string tm26 = reader["tm26"].ToString();
string palletsmall = reader["palletsmall"].ToString();
string palletbig = reader["palletbig"].ToString();
string moudle = Moudle.Text;
string qty = Qty.Text;
string weight = Weight.Text;
string grade = Grade.Text;
string File = file.Text;
// moudle = string(370);
switch (moudle.Trim())
{
case "350": number.Text = "50014778"; break;
case "355": number.Text = "50014783"; break;
case "360": number.Text = "50007313"; break;
case "365": number.Text = "50014792"; break;
case "370": number.Text = "50014797"; break;
case "375": number.Text = "50014802"; break;
}
btFormat = btApp.Formats.Open(File, false, "");
btFormat.PrintSetup.IdenticalCopiesOfLabel = 1; //设置同序列打印的份数
btFormat.PrintSetup.NumberSerializedLabels = 1; //设置需要打印的序列数
btFormat.SetNamedSubStringValue("tm1", tm1); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm2", tm2); // 向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm3", tm3); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm4", tm4); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm5", tm5); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm6", tm6); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm7", tm7); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm8", tm8); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm9", tm9); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm10", tm10); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm11", tm11); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm12", tm12); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm13", tm13); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm14", tm14); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm15", tm15); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm16", tm16); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm17", tm17); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm18", tm18); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm19", tm19); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm20", tm20); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm21", tm21); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm22", tm22); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm23", tm23); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm24", tm24); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm25", tm25); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("tm26", tm26); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("palletsmall", palletsmall); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("palletbig", palletbig); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("moudle", moudle); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("qty", qty); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("weight", weight); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("grade", grade); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("number", number.Text);
btFormat.PrintOut(false, false); //第二个false设置打印时是否跳出打印属性
btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签
textBox1.Text = "";
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
conn.Close();
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void bartender_Load(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void reset_Click(object sender, EventArgs e)
{
textBox1.Text = "";
Moudle.Text = "";
Qty.Text = "";
Grade.Text = "";
Weight.Text = "";
}
}
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论