在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → 实现调用bartender打印条码

实现调用bartender打印条码

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:9.09M
  • 下载次数:149
  • 浏览次数:942
  • 发布时间:2020-04-07
  • 实例类别:C#语言基础
  • 发 布 人:飞段
  • 文件格式:.zip
  • 所需积分:2
 相关标签: BarTender DER en 调用 打印

实例介绍

【实例简介】调用bartender软件进行打印操作,支持bartender9.4 10.0版本

【实例截图】中节能代工唛头打印

from clipboard

【核心代码】


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
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 = "";
             
        }
 
        
    }
}


实例下载地址

实现调用bartender打印条码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警