Browse Source

修改品网打印方式为BarTender

callm 4 years ago
parent
commit
80988c7214

+ 5 - 0
UAS-出货标签管理(贸易版)/PublicMethod/LogicHandler.cs

@@ -321,6 +321,11 @@ namespace UAS_LabelMachine.PublicMethod
                     MessageBox.Show("出货单" + iInOutNo + "不包含型号" + pr_spec);
                     return;
                 }
+                if (datarow == null)
+                {
+                    MessageBox.Show("请检查型号" + pr_spec);
+                    return;
+                }
                 decimal outqty = decimal.Parse(Regex.Replace(qty, @"[^\d]*", ""));
                 for (int k = 0; k < 1; k++)
                 {

+ 1 - 1
UAS-出货标签管理(贸易版)/UAS_出货标签管理.cs

@@ -2726,7 +2726,7 @@ namespace UAS_LabelMachine
             string year = "0";
             string month = "0";
             string day = "0";
-            string date = "";
+            //string date = "";
             string sql = "update prodiobarcode set pib_autoset=-1,pib_ifrecheck=-1,pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (select pib_id from prodiobarcode where  pib_inoutno='" + pi_inoutno.Text + "'";
             string PrintSQL = "select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
             if (datecode != "")

+ 57 - 30
UAS_CheckWork/Form1.Designer.cs

@@ -43,6 +43,8 @@
             this.dataGridViewCheckBoxColumn1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             this.ExportEmp = new System.Windows.Forms.Button();
             this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
+            this.Master = new System.Windows.Forms.ComboBox();
+            this.label3 = new System.Windows.Forms.Label();
             ((System.ComponentModel.ISupportInitialize)(this.showDataGrid)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.allData)).BeginInit();
             this.SuspendLayout();
@@ -51,10 +53,10 @@
             // 
             this.label2.AutoSize = true;
             this.label2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label2.Location = new System.Drawing.Point(167, 17);
-            this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.label2.Location = new System.Drawing.Point(334, 34);
+            this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label2.Name = "label2";
-            this.label2.Size = new System.Drawing.Size(42, 21);
+            this.label2.Size = new System.Drawing.Size(82, 41);
             this.label2.TabIndex = 14;
             this.label2.Text = "Port";
             // 
@@ -62,36 +64,36 @@
             // 
             this.label1.AutoSize = true;
             this.label1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label1.Location = new System.Drawing.Point(24, 16);
-            this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.label1.Location = new System.Drawing.Point(48, 32);
+            this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(25, 21);
+            this.label1.Size = new System.Drawing.Size(47, 41);
             this.label1.TabIndex = 13;
             this.label1.Text = "IP";
             // 
             // txtPort
             // 
-            this.txtPort.Location = new System.Drawing.Point(215, 17);
-            this.txtPort.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
+            this.txtPort.Location = new System.Drawing.Point(430, 34);
+            this.txtPort.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
             this.txtPort.Name = "txtPort";
-            this.txtPort.Size = new System.Drawing.Size(37, 21);
+            this.txtPort.Size = new System.Drawing.Size(70, 35);
             this.txtPort.TabIndex = 12;
             // 
             // txtIP
             // 
-            this.txtIP.Location = new System.Drawing.Point(58, 17);
-            this.txtIP.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
+            this.txtIP.Location = new System.Drawing.Point(116, 34);
+            this.txtIP.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
             this.txtIP.Name = "txtIP";
-            this.txtIP.Size = new System.Drawing.Size(99, 21);
+            this.txtIP.Size = new System.Drawing.Size(194, 35);
             this.txtIP.TabIndex = 11;
             // 
             // btnConnect
             // 
             this.btnConnect.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.btnConnect.Location = new System.Drawing.Point(279, 15);
-            this.btnConnect.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
+            this.btnConnect.Location = new System.Drawing.Point(558, 30);
+            this.btnConnect.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
             this.btnConnect.Name = "btnConnect";
-            this.btnConnect.Size = new System.Drawing.Size(50, 25);
+            this.btnConnect.Size = new System.Drawing.Size(100, 50);
             this.btnConnect.TabIndex = 10;
             this.btnConnect.Text = "连接";
             this.btnConnect.UseVisualStyleBackColor = true;
@@ -101,10 +103,10 @@
             // 
             this.lblState.AutoSize = true;
             this.lblState.ForeColor = System.Drawing.Color.Crimson;
-            this.lblState.Location = new System.Drawing.Point(359, 22);
-            this.lblState.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.lblState.Location = new System.Drawing.Point(718, 44);
+            this.lblState.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.lblState.Name = "lblState";
-            this.lblState.Size = new System.Drawing.Size(71, 12);
+            this.lblState.Size = new System.Drawing.Size(142, 24);
             this.lblState.TabIndex = 15;
             this.lblState.Text = "状态:未连接";
             // 
@@ -117,11 +119,11 @@
             this.cl_cardcode,
             this.cl_time});
             this.showDataGrid.Enabled = false;
-            this.showDataGrid.Location = new System.Drawing.Point(17, 59);
-            this.showDataGrid.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
+            this.showDataGrid.Location = new System.Drawing.Point(34, 116);
+            this.showDataGrid.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
             this.showDataGrid.Name = "showDataGrid";
             this.showDataGrid.RowTemplate.Height = 30;
-            this.showDataGrid.Size = new System.Drawing.Size(795, 377);
+            this.showDataGrid.Size = new System.Drawing.Size(1734, 756);
             this.showDataGrid.TabIndex = 16;
             this.showDataGrid.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.showDataGrid_DataError);
             // 
@@ -143,10 +145,10 @@
             // getAllData
             // 
             this.getAllData.BackColor = System.Drawing.SystemColors.ControlLightLight;
-            this.getAllData.Location = new System.Drawing.Point(560, 18);
-            this.getAllData.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
+            this.getAllData.Location = new System.Drawing.Point(1544, 8);
+            this.getAllData.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
             this.getAllData.Name = "getAllData";
-            this.getAllData.Size = new System.Drawing.Size(102, 25);
+            this.getAllData.Size = new System.Drawing.Size(204, 50);
             this.getAllData.TabIndex = 17;
             this.getAllData.Text = "同步考勤数据";
             this.getAllData.UseVisualStyleBackColor = false;
@@ -160,20 +162,42 @@
             // ExportEmp
             // 
             this.ExportEmp.BackColor = System.Drawing.SystemColors.ControlLightLight;
-            this.ExportEmp.Location = new System.Drawing.Point(682, 18);
-            this.ExportEmp.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
+            this.ExportEmp.Location = new System.Drawing.Point(1544, 62);
+            this.ExportEmp.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
             this.ExportEmp.Name = "ExportEmp";
-            this.ExportEmp.Size = new System.Drawing.Size(102, 25);
+            this.ExportEmp.Size = new System.Drawing.Size(204, 50);
             this.ExportEmp.TabIndex = 18;
             this.ExportEmp.Text = "导出人员数据";
             this.ExportEmp.UseVisualStyleBackColor = false;
             this.ExportEmp.Click += new System.EventHandler(this.ExportEmp_Click);
             // 
+            // Master
+            // 
+            this.Master.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.Master.FormattingEnabled = true;
+            this.Master.Location = new System.Drawing.Point(1018, 41);
+            this.Master.Name = "Master";
+            this.Master.Size = new System.Drawing.Size(480, 32);
+            this.Master.TabIndex = 19;
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.ForeColor = System.Drawing.Color.Black;
+            this.label3.Location = new System.Drawing.Point(905, 44);
+            this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(106, 24);
+            this.label3.TabIndex = 20;
+            this.label3.Text = "选择账套";
+            // 
             // Form1
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(823, 451);
+            this.ClientSize = new System.Drawing.Size(1781, 902);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.Master);
             this.Controls.Add(this.ExportEmp);
             this.Controls.Add(this.getAllData);
             this.Controls.Add(this.showDataGrid);
@@ -183,9 +207,10 @@
             this.Controls.Add(this.txtPort);
             this.Controls.Add(this.txtIP);
             this.Controls.Add(this.btnConnect);
-            this.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
+            this.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
             this.Name = "Form1";
             this.Text = "Form1";
+            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
             this.Load += new System.EventHandler(this.Form1_Load);
             ((System.ComponentModel.ISupportInitialize)(this.showDataGrid)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.allData)).EndInit();
@@ -210,6 +235,8 @@
         private System.Windows.Forms.DataGridViewTextBoxColumn cl_time;
         private System.Windows.Forms.Button ExportEmp;
         private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
+        private System.Windows.Forms.ComboBox Master;
+        private System.Windows.Forms.Label label3;
     }
 }
 

+ 7 - 0
UAS_CheckWork/Form1.cs

@@ -34,6 +34,10 @@ namespace UAS_CheckWork
             txtIP.Text = Properties.Settings.Default.IP;
             txtPort.Text = Properties.Settings.Default.Port;
             dh = new DataHelper();
+            DataTable dt = (DataTable)dh.ExecuteSql("select ma_user,ma_function from master", "select");
+            Master.DataSource = dt;
+            Master.DisplayMember = "ma_function";
+            Master.ValueMember = "ma_user";
         }
 
         private void btnConnect_Click(object sender, EventArgs e)
@@ -77,6 +81,9 @@ namespace UAS_CheckWork
 
         private void getAllData_Click(object sender, EventArgs e)
         {
+            string master = Master.SelectedValue.ToString();
+            DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID="+master+";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=yitoadt.wicp.io)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+            dh = new DataHelper();
             if (!bIsConnected)
             {
                 MessageBox.Show("请先连接设备", "Error");

BIN
UAS_CheckWork/Tools/Interop.zkemkeeper.dll


+ 23 - 23
UAS_MES_PW/DataOperate/DataHelper.cs

@@ -44,7 +44,7 @@ namespace UAS_MES_NEW.DataOperate
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
-            
+
             return dt;
         }
 
@@ -74,7 +74,7 @@ namespace UAS_MES_NEW.DataOperate
                 ad.Fill(dt);
             }
             ad.Dispose();
-            
+
             if (dt.Rows.Count > 0)
             {
                 return dt.Rows[0][0];
@@ -114,7 +114,7 @@ namespace UAS_MES_NEW.DataOperate
                 DataTable dt = new DataTable();
                 ad.Fill(dt);
                 ad.Dispose();
-                
+
                 return dt;
             }
             return "参数错误,请检查SQL语句";
@@ -133,7 +133,7 @@ namespace UAS_MES_NEW.DataOperate
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
-            
+
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -152,7 +152,7 @@ namespace UAS_MES_NEW.DataOperate
 
             ad.Fill(dt);
             ad.Dispose();
-            
+
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -182,7 +182,7 @@ namespace UAS_MES_NEW.DataOperate
                 ad.Fill(dt);
             }
             ad.Dispose();
-            
+
             return dt;
         }
 
@@ -235,7 +235,7 @@ namespace UAS_MES_NEW.DataOperate
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
-            
+
             dt.Columns.RemoveAt(0);
             foreach (DataColumn dc in dt.Columns)
             {
@@ -272,7 +272,7 @@ namespace UAS_MES_NEW.DataOperate
                 ad.Fill(dt);
             }
             ad.Dispose();
-            
+
             return dt;
         }
 
@@ -303,7 +303,7 @@ namespace UAS_MES_NEW.DataOperate
                 ad.Fill(dt);
             }
             ad.Dispose();
-            
+
             return dt;
         }
 
@@ -425,7 +425,7 @@ namespace UAS_MES_NEW.DataOperate
             ad.UpdateCommand = command;
             ad.Update(DataTable);
             ad.Dispose();
-            
+
         }
 
         /// <summary>
@@ -495,7 +495,7 @@ namespace UAS_MES_NEW.DataOperate
                 ad.Fill(dt);
             }
             ad.Dispose();
-            
+
             Console.WriteLine(dt.Rows[0][0].ToString());
             Console.WriteLine(int.Parse(dt.Rows[0][0].ToString()) > 0);
             return int.Parse(dt.Rows[0][0].ToString()) > 0;
@@ -595,7 +595,7 @@ namespace UAS_MES_NEW.DataOperate
                     }
                     break;
             }
-            
+
             return result;
         }
 
@@ -608,7 +608,7 @@ namespace UAS_MES_NEW.DataOperate
             SQL = SQL.Replace("?", ":Param");
             command = new OracleCommand(SQL, connection);
             command.ExecuteNonQuery();
-            
+
         }
 
         public int GetDistinctRowCount(string TableName, string Field)
@@ -632,7 +632,7 @@ namespace UAS_MES_NEW.DataOperate
                 ad.Fill(dt);
             }
             ad.Dispose();
-            
+
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -672,7 +672,7 @@ namespace UAS_MES_NEW.DataOperate
                 command.Connection.Open();
                 command.ExecuteNonQuery();
             }
-            
+
         }
 
         /// <summary>
@@ -830,7 +830,7 @@ namespace UAS_MES_NEW.DataOperate
                 command.Connection.Open();
                 command.ExecuteNonQuery();
             }
-            
+
         }
 
         public void BatchInsertDataTable(string sql, string[] param, params object[][] param1)
@@ -854,7 +854,7 @@ namespace UAS_MES_NEW.DataOperate
                 command.Connection.Open();
                 command.ExecuteNonQuery();
             }
-            
+
         }
 
         /// <summary>
@@ -935,7 +935,7 @@ namespace UAS_MES_NEW.DataOperate
                 command.Connection.Open();
                 command.ExecuteNonQuery();
             }
-            
+
             return sql;
         }
 
@@ -965,7 +965,7 @@ namespace UAS_MES_NEW.DataOperate
             }
             for (int i = 0; i < command.Parameters.Count; i++)
                 param[i] = command.Parameters[i].Value.ToString();
-            
+
         }
 
 
@@ -993,7 +993,7 @@ namespace UAS_MES_NEW.DataOperate
             }
             for (int i = 0; i < command.Parameters.Count; i++)
                 param[i] = command.Parameters[i].Value.ToString();
-            
+
         }
 
         /// <summary>
@@ -1034,7 +1034,7 @@ namespace UAS_MES_NEW.DataOperate
                 tx.Rollback();
                 throw new Exception(E.Message);
             }
-            
+
         }
 
         /// <summary>
@@ -1104,12 +1104,12 @@ namespace UAS_MES_NEW.DataOperate
             if (dt.Rows.Count > 0)
             {
                 ad.Dispose();
-                
+
                 return dt.Rows[0][0];
             }
             else
             {
-                
+
                 return "";
             }
         }

+ 5 - 3
UAS_MES_PW/FunctionCode/Make/Make_ColorBoxLabelPrint.cs

@@ -10,6 +10,7 @@ using LabelManager2;
 using System.Threading;
 using UAS_MES_NEW.PublicForm;
 using System.Web.UI.WebControls;
+using Seagull.BarTender.Print;
 
 namespace UAS_MES_NEW.Make
 {
@@ -34,6 +35,8 @@ namespace UAS_MES_NEW.Make
         Thread InitPrint;
         ApplicationClass lbl;
 
+        Engine engine;
+
         DataTable Dbfind;
 
         public Make_ColorBoxLabelPrint()
@@ -88,8 +91,7 @@ namespace UAS_MES_NEW.Make
         {
             try
             {
-                lbl = new ApplicationClass();
-                BaseUtil.WriteLbl();
+                engine = new Engine(true);
             }
             catch (Exception)
             {
@@ -229,7 +231,7 @@ namespace UAS_MES_NEW.Make
 
                                     for (int i = 0; i < _dt.Rows.Count; i++)
                                     {
-                                        if (Print.CodeSoft(Tag.ToString(), ref lbl, _dt.Rows[i]["la_url"].ToString(), _dt.Rows[i]["la_id"].ToString(), Printer.Text, sncode.Text, int.Parse(PrintNum.Text), oMakeCode, pr_code.Text, "彩盒标", "0", out ErrorMessage))
+                                        if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, sncode.Text, int.Parse(PrintNum.Text), oMakeCode, pr_code.Text, "彩盒标", "0", out ErrorMessage))
                                         {
                                             //提示用户打印成功
                                             OperateResult.AppendText(">>序列号:" + sncode.Text + "打印结束\n", Color.Green);

+ 32 - 34
UAS_MES_PW/FunctionCode/Make/Make_CustomLabelPrint.cs

@@ -1,4 +1,5 @@
 using LabelManager2;
+using Seagull.BarTender.Print;
 using System;
 using System.Collections;
 using System.Collections.Generic;
@@ -26,8 +27,6 @@ namespace UAS_MES_NEW.Make
 
         AutoSizeFormClass asc = new AutoSizeFormClass();
 
-        ApplicationClass lbl;
-
         Thread InitPrint;
         //存放产品信息
         DataTable dt;
@@ -38,12 +37,13 @@ namespace UAS_MES_NEW.Make
         //记录当前的步骤数
         int currentIndex = 0;
 
-        Document doc;
-
         FileInfo info;
+        Engine engine;
 
         //ftpOperater ftp;
 
+        LabelFormatDocument format;
+
         StringBuilder sb = new StringBuilder();
 
         bool canPrint = false;
@@ -69,12 +69,11 @@ namespace UAS_MES_NEW.Make
         {
             try
             {
-                lbl = new ApplicationClass();
-                BaseUtil.WriteLbl();
+                engine = new Engine(true);
             }
             catch (Exception ex)
             {
-                OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
+                OperateResult.AppendText(ex.Message+ex.StackTrace, Color.Red);
             }
         }
 
@@ -155,25 +154,23 @@ namespace UAS_MES_NEW.Make
                         string filechangetime = PrintFile.LastWriteTime.ToString();
                         if (filechangetime != filelastwritetime)
                         {
-                            lbl.Quit();
-                            lbl = new ApplicationClass();
-                            BaseUtil.WriteLbl();
+                            engine = new Engine(true);
                             filechangetime = PrintFile.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
                             string update = "la_lastwritetime = to_date((regexp_substr('" + filechangetime + "','\\d+.+\\d+')),'yyyy-mm-dd hh24:mi:ss')";
                             dh.UpdateByCondition("label", update, "la_id = '" + listA.Rows[PrintLabel.SelectedIndex]["la_id"].ToString() + "'");
                         }
-                        doc = lbl.Documents.Open(listA.Rows[PrintLabel.SelectedIndex]["la_url"].ToString(), true);
+                        format = engine.Documents.Open(listA.Rows[PrintLabel.SelectedIndex]["la_url"].ToString());
                     }
-                    //将值赋到doc对应的变量
-                    for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
+                    //将值赋到format对应的变量
+                    for (int i = 0; i < format.SubStrings.Count; i++)
                     {
                         //找到对应的变量名
-                        if (doc.Variables.FormVariables.Item(i + 1).Name == paramsInfo.Rows[currentIndex - 1]["lp_name"].ToString())
+                        if (format.SubStrings[i].Name == paramsInfo.Rows[currentIndex - 1]["lp_name"].ToString())
                         {
                             //如果当时采集行的 lp_valuetype=’INPUT’,并且lp_sql 为空,则直接将采集的值赋给标签打印
                             if (paramsInfo.Rows[currentIndex - 1]["lp_valuetype"].ToString() == "INPUT" && paramsInfo.Rows[currentIndex - 1]["lp_sql"].ToString() == "")
                             {
-                                doc.Variables.FormVariables.Item(i + 1).Value = inputText.Text;
+                                format.SubStrings[i].Value = inputText.Text;
                             }
                             else
                             {
@@ -185,10 +182,10 @@ namespace UAS_MES_NEW.Make
                                     string x = mch.Value.Trim();
                                     sql = sql.Replace(x, "'" + inputText.Text + "'");
                                 }
-                                doc.Variables.FormVariables.Item(i + 1).Value = dh.GetLabelParam(sql).ToString();
-                                sb.AppendLine("打印参数【" + doc.Variables.FormVariables.Item(i + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + doc.Variables.FormVariables.Item(i + 1).Value);
+                                format.SubStrings[i].Value = dh.GetLabelParam(sql).ToString();
+                                sb.AppendLine("打印参数【" + format.SubStrings[i].Name + "】赋值," + "取值SQL:" + sql + ",取到值" + format.SubStrings[i].Value);
                             }
-                            inputValues[currentIndex - 1] = doc.Variables.FormVariables.Item(i + 1).Value;
+                            inputValues[currentIndex - 1] = format.SubStrings[i].Value;
                         }
                     }
                     if (currentIndex == paramsInfo.Rows.Count)
@@ -198,11 +195,12 @@ namespace UAS_MES_NEW.Make
                         //打印
                         LogManager.DoLog(sb.ToString());
                         //保存本次赋值进行打印
-                        doc.Printer.SwitchTo(Printer.Text);
-                        doc.PrintDocument(int.Parse(PrintNum.Text));
-                        for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
+                        format.PrintSetup.PrinterName = Printer.Text;
+                        format.PrintSetup.IdenticalCopiesOfLabel = int.Parse(PrintNum.Text);
+                        format.Print();
+                        for (int i = 0; i < format.SubStrings.Count; i++)
                         {
-                            doc.Variables.FormVariables.Item(i + 1).Value = null;
+                            format.SubStrings[i].Value = null;
                         }
                         //讲文件最后写入时间改成数据库中拿到的时间
                         //记录打印日志
@@ -254,7 +252,7 @@ namespace UAS_MES_NEW.Make
 
         private void Make_CustomLabelPrint_FormClosing(object sender, FormClosingEventArgs e)
         {
-            BaseUtil.ClosePrint(lbl);
+
         }
 
         private void pr_code_Leave(object sender, EventArgs e)
@@ -276,36 +274,36 @@ namespace UAS_MES_NEW.Make
                 string filechangetime = PrintFile.LastWriteTime.ToString();
                 if (filechangetime != filelastwritetime)
                 {
-                    lbl.Quit();
-                    lbl = new ApplicationClass();
+                    engine = new Engine(true);
                     BaseUtil.WriteLbl();
                     filechangetime = PrintFile.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
                     string update = "la_lastwritetime = to_date((regexp_substr('" + filechangetime + "','\\d+.+\\d+')),'yyyy-mm-dd hh24:mi:ss')";
                     dh.UpdateByCondition("label", update, "la_id = '" + listA.Rows[PrintLabel.SelectedIndex]["la_id"].ToString() + "'");
                 }
-                doc = lbl.Documents.Open(listA.Rows[PrintLabel.SelectedIndex]["la_url"].ToString(), true);
+                format = engine.Documents.Open(listA.Rows[PrintLabel.SelectedIndex]["la_url"].ToString());
                 sb = new StringBuilder();
-                //将值赋到doc对应的变量
-                for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
+                //将值赋到format对应的变量
+                for (int i = 0; i < format.SubStrings.Count; i++)
                 {
                     for (int j = 0; j < paramsInfo.Rows.Count; j++)
                     {
                         //找到对应的变量名
-                        if (doc.Variables.FormVariables.Item(i + 1).Name == paramsInfo.Rows[j]["lp_name"].ToString())
+                        if (format.SubStrings[i].Name == paramsInfo.Rows[j]["lp_name"].ToString())
                         {
                             //直接赋值
-                            doc.Variables.FormVariables.Item(i + 1).Value = inputValues[j];
+                            format.SubStrings[i].Value = inputValues[j];
                         }
                     }
                 }
                 //打印
                 LogManager.DoLog(sb.ToString());
                 //保存本次赋值进行打印
-                doc.Printer.SwitchTo(Printer.Text);
-                doc.PrintDocument(int.Parse(PrintNum.Text));
-                for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
+                format.PrintSetup.PrinterName = Printer.Text;
+                format.PrintSetup.IdenticalCopiesOfLabel = int.Parse(PrintNum.Text);
+                format.Print();
+                for (int i = 0; i < format.SubStrings.Count; i++)
                 {
-                    doc.Variables.FormVariables.Item(i + 1).Value = null;
+                    format.SubStrings[i].Value = null;
                 }
                 //讲文件最后写入时间改成数据库中拿到的时间
                 //记录打印日志

+ 8 - 10
UAS_MES_PW/FunctionCode/Make/Make_RePrintLabel.cs

@@ -1,4 +1,5 @@
 using LabelManager2;
+using Seagull.BarTender.Print;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -23,7 +24,7 @@ namespace UAS_MES_NEW.Make
 
         AutoSizeFormClass asc = new AutoSizeFormClass();
 
-        ApplicationClass lbl;
+        Engine engine;
 
         Thread InitPrint;//实例化打印进程
 
@@ -35,8 +36,6 @@ namespace UAS_MES_NEW.Make
 
         DataTable mapB;
 
-        String TSN = "";//记录第一次输入的SN
-
         string ms_id = "";
 
         DataTable formValue;//界面赋值
@@ -65,12 +64,12 @@ namespace UAS_MES_NEW.Make
         {
             try
             {
-                lbl = new ApplicationClass();
+                engine = new Engine(true);
                 BaseUtil.WriteLbl();
             }
-            catch (Exception ex)
+            catch (Exception)
             {
-                OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
+                OperateResult.AppendText("未正确安装Bartender软件\n", Color.Red);
             }
         }
 
@@ -83,7 +82,7 @@ namespace UAS_MES_NEW.Make
         private void Make_RePrintLabel_FormClosing(object sender, FormClosingEventArgs e)
         {
             //窗口关闭的时候
-            BaseUtil.ClosePrint(lbl);
+            BaseUtil.ClosePrint(engine);
         }
 
         private void radioButton_CheckedChange(object sender, EventArgs e)
@@ -215,7 +214,7 @@ namespace UAS_MES_NEW.Make
                 }
                 //判定通过进行打印 
                 //doc = lbl.Documents.Open(PrintLabel.Text);
-                if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, giftBox.Checked ? "彩盒标" : "机身标", "-1", out errorMessage))
+                if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, giftBox.Checked ? "彩盒标" : "机身标", "-1", out errorMessage))
                 {
                     //按照打印张数打印
                     OperateResult.AppendText("<<打印成功\n", Color.Green);
@@ -246,7 +245,7 @@ namespace UAS_MES_NEW.Make
                     return;
                 }
                 //doc = lbl.Documents.Open(PrintLabel.Text);
-                if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, "卡通箱标", "-1", out errorMessage))
+                if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, "卡通箱标", "-1", out errorMessage))
                 {
                     //判断通过,打印
                     OperateResult.AppendText("<<打印成功\n", Color.Green);
@@ -318,7 +317,6 @@ namespace UAS_MES_NEW.Make
             ms_makecode.Text = "";
             pr_code.Text = "";
             pr_detail.Text = "";
-            TSN = "";
             if (listA != null)
             {
                 listA.Clear();

+ 5 - 2
UAS_MES_PW/FunctionCode/Packing/Packing_PackageCollection.cs

@@ -10,6 +10,7 @@ using System.Threading;
 using UAS_MES_NEW.PublicForm;
 using System.Collections.Generic;
 using System.Diagnostics;
+using Seagull.BarTender.Print;
 
 namespace UAS_MES_NEW.Packing
 {
@@ -21,6 +22,8 @@ namespace UAS_MES_NEW.Packing
         AutoSizeFormClass asc = new AutoSizeFormClass();
         ApplicationClass lbl;
         Thread thread;
+        Engine engine;
+
         DataTable Dbfind;
         string ErrorMessage = "";
         string oMakeCode = "";
@@ -45,7 +48,7 @@ namespace UAS_MES_NEW.Packing
         {
             try
             {
-                lbl = new ApplicationClass();
+                engine = new Engine(true);
             }
             catch (Exception ex)
             {
@@ -156,7 +159,7 @@ namespace UAS_MES_NEW.Packing
                     dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
                     for (int i = 0; i < _dt.Rows.Count; i++)
                     {
-                        if (Print.CodeSoft(Tag.ToString(), ref lbl, _dt.Rows[i]["la_url"].ToString(), _dt.Rows[i]["la_id"].ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), oMakeCode == "" ? pa_makecode.Text : oMakeCode, pr_code.Text, "卡通箱标", "0", out ErrorMessage))
+                        if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), oMakeCode == "" ? pa_makecode.Text : oMakeCode, pr_code.Text, "卡通箱标", "0", out ErrorMessage))
                         {
                             OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
                         }

+ 5 - 6
UAS_MES_PW/FunctionCode/Packing/Packing_PalletWightCollection.cs

@@ -12,6 +12,7 @@ using UAS_MES_NEW.Entity;
 using UAS_MES_NEW.PublicForm;
 using UAS_MES_NEW.PublicMethod;
 using UAS_MES_NEW.Packing;
+using Seagull.BarTender.Print;
 
 namespace UAS_MES_NEW.Packing
 {
@@ -46,9 +47,7 @@ namespace UAS_MES_NEW.Packing
 
         string PR_CHECKCARTONW = "0";
 
-        ApplicationClass lbl;
-
-        Document doc;
+        Engine engine;
 
         Thread InitPrint;
 
@@ -69,7 +68,7 @@ namespace UAS_MES_NEW.Packing
         {
             try
             {
-                lbl = new ApplicationClass();
+                engine = new Engine(true);
                 BaseUtil.WriteLbl();
             }
             catch
@@ -490,7 +489,7 @@ namespace UAS_MES_NEW.Packing
                         pa_outboxcode.SelectAll();
                     }
                     //doc = lbl.Documents.Open(PrintLabel.Text);
-                    if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), pa_makecode.Text, pa_prodcode.Text, "栈板标", "0", out ErrorMessage))
+                    if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), pa_makecode.Text, pa_prodcode.Text, "栈板标", "0", out ErrorMessage))
                     {
                         OperateResult.AppendText(">>打印栈板" + pa_outboxcode.Text + "\n", Color.Black);
                     }
@@ -549,7 +548,7 @@ namespace UAS_MES_NEW.Packing
 
         private void Make_PalletCollection_FormClosing(object sender, FormClosingEventArgs e)
         {
-            BaseUtil.ClosePrint(lbl);
+            //BaseUtil.ClosePrint(lbl);
             StopWeight.PerformClick();
             InitPrint.Abort();
             if (serialPort1.IsOpen)

+ 12 - 2
UAS_MES_PW/PublicMethod/BaseUtil.cs

@@ -1,4 +1,5 @@
 using LabelManager2;
+using Seagull.BarTender.Print;
 using System;
 using System.Collections;
 using System.Collections.Generic;
@@ -1204,13 +1205,22 @@ namespace UAS_MES_NEW.PublicMethod
             close.Start();
         }
 
+        public static void ClosePrint(Engine lbl)
+        {
+            eng = lbl;
+            Thread close = new Thread(ClosePrintProcess);
+            close.Start();
+        }
+
+        static Engine eng;
+
         static ApplicationClass lblpro;
 
         private static void ClosePrintProcess()
         {
             try
             {
-                lblpro.Quit();
+                eng.Stop();
             }
             catch (Exception)
             {
@@ -1516,7 +1526,7 @@ namespace UAS_MES_NEW.PublicMethod
             IMEI1 = "";
             BARCODE = "";
             string txt = "";
-        
+
             while (true)
             {
                 try

+ 109 - 4
UAS_MES_PW/PublicMethod/Print.cs

@@ -6,6 +6,7 @@ using System.IO;
 using UAS_MES_NEW.Entity;
 using System.Text.RegularExpressions;
 using System.Windows.Forms;
+using Seagull.BarTender.Print;
 
 namespace UAS_MES_NEW.PublicMethod
 {
@@ -16,7 +17,8 @@ namespace UAS_MES_NEW.PublicMethod
         static Document doc;
         ////CodeSoft的打印机
         //string CodeSpft_Printer;
-        static FileInfo info;
+
+        static LabelFormatDocument format;
 
         public Print() { }
 
@@ -87,7 +89,7 @@ namespace UAS_MES_NEW.PublicMethod
                         }
                     }
                 }
-                catch (System.Exception ex)
+                catch (System.Exception)
                 {
                     MessageBox.Show("SQL维护不正确");
                 }
@@ -131,7 +133,7 @@ namespace UAS_MES_NEW.PublicMethod
             FileInfo PrintFile = new FileInfo(LabelName);
             //打开模板路径
             //查询模板对应的取值SQL和参数名称
-            dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_id='" + LaID + "' order by to_number(lp_detno)" , "select");
+            dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_id='" + LaID + "' order by to_number(lp_detno)", "select");
             StringBuilder sb = new StringBuilder();
             if (!PrintFile.Exists)
             {
@@ -190,7 +192,7 @@ namespace UAS_MES_NEW.PublicMethod
                         }
                     }
                 }
-                catch (System.Exception ex)
+                catch (System.Exception)
                 {
                     MessageBox.Show("SQL维护不正确");
                 }
@@ -207,5 +209,108 @@ namespace UAS_MES_NEW.PublicMethod
             LogicHandler.doLabelPrintLog(SnCode, LabelType + LabelName, MakeCode, ProdCode, User.UserSourceCode, User.CurrentStepCode, IfRePrint, User.UserCode);
             return true;
         }
+
+        public static bool BarTender(string iCaller, ref Engine lbl, string LabelName, string LaID, string PrinterName, string SnCode, int PrintNum, string MakeCode, string ProdCode, string LabelType, string IfRePrint, out string ErrorMessage)
+        {
+            ErrorMessage = "";
+            DataTable dt = new DataTable();
+            if (IfRePrint != "-1")
+            {
+                if (LabelType == "卡通箱标" || LabelType == "大箱标" || LabelType == "栈板标")
+                {
+                    dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_type='" + LabelType + "' and lpl_stepcode='" + User.CurrentStepCode + "'", "select");
+                }
+                else
+                {
+                    dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_makecode='" + MakeCode + "' and lpl_type='" + LabelType + "' and lpl_stepcode='" + User.CurrentStepCode + "'", "select");
+                }
+                ////如果已经打印过了,则不允许再打印
+                if (dt.Rows.Count > 0)
+                {
+                    ErrorMessage = SnCode + LabelType + "已打印";
+                    return false;
+                }
+            }
+            string filelastwritetime = dh.getFieldDataByCondition("label", "la_lastwritetime", "la_id = '" + LaID + "'").ToString();
+            FileInfo PrintFile = new FileInfo(LabelName);
+            //打开模板路径
+            //查询模板对应的取值SQL和参数名称
+            dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_id='" + LaID + "'", "select");
+            StringBuilder sb = new StringBuilder();
+            if (!PrintFile.Exists)
+            {
+                MessageBox.Show("打印文件不存在");
+                return false;
+            }
+            string filechangetime = PrintFile.LastWriteTime.ToString();
+            if (filechangetime != filelastwritetime)
+            {
+                lbl.Stop();
+                lbl = new Engine(true);
+                BaseUtil.WriteLbl();
+                filechangetime = PrintFile.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
+                string update = "la_lastwritetime = to_date((regexp_substr('" + filechangetime + "','\\d+.+\\d+')),'yyyy-mm-dd hh24:mi:ss')";
+                dh.UpdateByCondition("label", update, "la_id = '" + LaID + "'");
+            }
+            format = lbl.Documents.Open(LabelName);
+            if (format == null)
+            {
+                MessageBox.Show("标签文件打开失败");
+                return false;
+            }
+            //执行全部的SQL
+            for (int i = 0; i < dt.Rows.Count; i++)
+            {
+                string sql = dt.Rows[i]["lp_sql"].ToString();
+                try
+                {
+                    Regex ConnoteA = new Regex("{\\w+}");
+                    foreach (Match mch in ConnoteA.Matches(sql))
+                    {
+                        string x = mch.Value.Trim();
+                        sql = sql.Replace(x, "'" + SnCode + "'");
+                    }
+                    DataTable Param = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                    if (Param.Rows.Count == 0)
+                        continue;
+                    //查询的结果的参数个数大于1需要给标签的多个参数赋值
+                    if (Param.Rows.Count > 0)
+                    {
+                        int LoopTime = Param.Rows.Count > 100 ? 100 : Param.Rows.Count;
+                        for (int j = 0; j < LoopTime; j++)
+                        {
+                            for (int k = 0; k < format.SubStrings.Count; k++)
+                            {
+                                if (j == 0 & format.SubStrings[k].Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper())
+                                {
+                                    format.SubStrings[k].Value = Param.Rows[0][0].ToString();
+                                }
+                                //使用SN开头的参数赋值SN1,SN2,SN3等参数
+                                if (format.SubStrings[k].Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1))
+                                {
+                                    format.SubStrings[k].Value = Param.Rows[j][0].ToString();
+                                }
+                            }
+                        }
+                    }
+                }
+                catch (System.Exception)
+                {
+                    MessageBox.Show("SQL维护不正确");
+                }
+            }
+            LogManager.DoLog(sb.ToString());
+            //保存本次赋值进行打印
+            format.PrintSetup.PrinterName = PrinterName;
+            format.PrintSetup.IdenticalCopiesOfLabel = PrintNum;
+            format.Print();
+            LogicHandler.DoCommandLog(iCaller, User.UserCode, "", User.UserLineCode, User.UserSourceCode, "打印", "成功打印", SnCode, "");
+            for (int k = 0; k < format.SubStrings.Count; k++)
+            {
+                format.SubStrings[k].Value = null;
+            }
+            LogicHandler.doLabelPrintLog(SnCode, LabelType, MakeCode, ProdCode, User.UserSourceCode, User.CurrentStepCode, IfRePrint, User.UserCode);
+            return true;
+        }
     }
 }

BIN
UAS_MES_PW/Tool/Seagull.BarTender.Print.dll


+ 4 - 0
UAS_MES_PW/UAS_MES_PW.csproj

@@ -138,6 +138,10 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>Tool\Oracle.ManagedDataAccess.dll</HintPath>
     </Reference>
+    <Reference Include="Seagull.BarTender.Print, Version=10.1.4.1, Culture=neutral, PublicKeyToken=109ff779a1b4cbc7, processorArchitecture=x86">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>Tool\Seagull.BarTender.Print.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Configuration" />
     <Reference Include="System.Core" />