Browse Source

优化标签自定义打印

callm 1 month ago
parent
commit
e46e71d0a5

+ 309 - 0
UAS_MES_ZT/FunctionCode/Make/Make_StencilPrint.Designer.cs

@@ -0,0 +1,309 @@
+namespace UAS_MES_NEW.Make
+{
+    partial class Make_StencilPrint
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Make_StencilPrint));
+            this.pr_code_label = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.label3 = new System.Windows.Forms.Label();
+            this.PrintLabel = new UAS_MES_NEW.CustomControl.ComBoxWithFocus.ComboxWithTip(this.components);
+            this.label4 = new System.Windows.Forms.Label();
+            this.label5 = new System.Windows.Forms.Label();
+            this.sncode_label = new System.Windows.Forms.Label();
+            this.label6 = new System.Windows.Forms.Label();
+            this.pr_detail = new System.Windows.Forms.Label();
+            this.pr_spec = new System.Windows.Forms.Label();
+            this.PrintNum = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.NumOnlyTextBox();
+            this.printButton = new UAS_MES_NEW.CustomControl.ButtonUtil.NormalButton();
+            this.pr_code = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.SnCollectionBox();
+            this.inputText = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.SnCollectionBox();
+            this.OperateResult = new UAS_MES_NEW.CustomControl.RichText.RichTextAutoBottom();
+            this.Printer = new UAS_MES_NEW.CustomControl.ComBoxWithFocus.PrinterCombox();
+            this.SuspendLayout();
+            // 
+            // pr_code_label
+            // 
+            this.pr_code_label.AutoSize = true;
+            this.pr_code_label.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.pr_code_label.Location = new System.Drawing.Point(74, 43);
+            this.pr_code_label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.pr_code_label.Name = "pr_code_label";
+            this.pr_code_label.Size = new System.Drawing.Size(146, 41);
+            this.pr_code_label.TabIndex = 0;
+            this.pr_code_label.Text = "产品代码";
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label2.Location = new System.Drawing.Point(78, 147);
+            this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(146, 41);
+            this.label2.TabIndex = 1;
+            this.label2.Text = "产品名称";
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label3.Location = new System.Drawing.Point(1020, 40);
+            this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(82, 41);
+            this.label3.TabIndex = 2;
+            this.label3.Text = "规格";
+            // 
+            // PrintLabel
+            // 
+            this.PrintLabel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.PrintLabel.FormattingEnabled = true;
+            this.PrintLabel.Location = new System.Drawing.Point(693, 147);
+            this.PrintLabel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.PrintLabel.Name = "PrintLabel";
+            this.PrintLabel.Size = new System.Drawing.Size(252, 32);
+            this.PrintLabel.TabIndex = 185;
+            this.PrintLabel.SelectedValueChanged += new System.EventHandler(this.PrintLabel_SelectedValueChanged);
+            this.PrintLabel.TextChanged += new System.EventHandler(this.PrintLabel_TextChanged);
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label4.Location = new System.Drawing.Point(534, 43);
+            this.label4.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(114, 41);
+            this.label4.TabIndex = 184;
+            this.label4.Text = "打印机";
+            // 
+            // label5
+            // 
+            this.label5.AutoSize = true;
+            this.label5.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label5.Location = new System.Drawing.Point(534, 147);
+            this.label5.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label5.Name = "label5";
+            this.label5.Size = new System.Drawing.Size(82, 41);
+            this.label5.TabIndex = 183;
+            this.label5.Text = "标签";
+            // 
+            // sncode_label
+            // 
+            this.sncode_label.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left)));
+            this.sncode_label.AutoSize = true;
+            this.sncode_label.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.sncode_label.Location = new System.Drawing.Point(57, 733);
+            this.sncode_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.sncode_label.Name = "sncode_label";
+            this.sncode_label.Size = new System.Drawing.Size(114, 41);
+            this.sncode_label.TabIndex = 188;
+            this.sncode_label.Text = "输入框";
+            // 
+            // label6
+            // 
+            this.label6.AutoSize = true;
+            this.label6.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label6.Location = new System.Drawing.Point(826, 733);
+            this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(82, 41);
+            this.label6.TabIndex = 189;
+            this.label6.Text = "份数";
+            // 
+            // pr_detail
+            // 
+            this.pr_detail.AutoSize = true;
+            this.pr_detail.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.pr_detail.Location = new System.Drawing.Point(240, 147);
+            this.pr_detail.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.pr_detail.Name = "pr_detail";
+            this.pr_detail.Size = new System.Drawing.Size(0, 41);
+            this.pr_detail.TabIndex = 193;
+            // 
+            // pr_spec
+            // 
+            this.pr_spec.AutoSize = true;
+            this.pr_spec.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.pr_spec.Location = new System.Drawing.Point(1110, 40);
+            this.pr_spec.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.pr_spec.MaximumSize = new System.Drawing.Size(450, 160);
+            this.pr_spec.Name = "pr_spec";
+            this.pr_spec.Size = new System.Drawing.Size(0, 41);
+            this.pr_spec.TabIndex = 194;
+            // 
+            // PrintNum
+            // 
+            this.PrintNum.AllPower = null;
+            this.PrintNum.BackColor = System.Drawing.Color.White;
+            this.PrintNum.Enabled = false;
+            this.PrintNum.ID = null;
+            this.PrintNum.Location = new System.Drawing.Point(944, 733);
+            this.PrintNum.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.PrintNum.Name = "PrintNum";
+            this.PrintNum.Negative = false;
+            this.PrintNum.Power = null;
+            this.PrintNum.Size = new System.Drawing.Size(260, 35);
+            this.PrintNum.Str = null;
+            this.PrintNum.Str1 = null;
+            this.PrintNum.Str2 = null;
+            this.PrintNum.TabIndex = 195;
+            this.PrintNum.Text = "1";
+            // 
+            // printButton
+            // 
+            this.printButton.AllPower = null;
+            this.printButton.BackColor = System.Drawing.Color.Transparent;
+            this.printButton.DownImage = ((System.Drawing.Image)(resources.GetObject("printButton.DownImage")));
+            this.printButton.Image = null;
+            this.printButton.IsShowBorder = true;
+            this.printButton.Location = new System.Drawing.Point(1240, 733);
+            this.printButton.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.printButton.MoveImage = ((System.Drawing.Image)(resources.GetObject("printButton.MoveImage")));
+            this.printButton.Name = "printButton";
+            this.printButton.NormalImage = ((System.Drawing.Image)(resources.GetObject("printButton.NormalImage")));
+            this.printButton.Power = null;
+            this.printButton.Size = new System.Drawing.Size(100, 37);
+            this.printButton.TabIndex = 192;
+            this.printButton.Text = "打印";
+            this.printButton.UseVisualStyleBackColor = false;
+            this.printButton.Visible = false;
+            this.printButton.Click += new System.EventHandler(this.printButton_Click);
+            // 
+            // pr_code
+            // 
+            this.pr_code.AllPower = null;
+            this.pr_code.BackColor = System.Drawing.Color.White;
+            this.pr_code.Font = new System.Drawing.Font("宋体", 9F);
+            this.pr_code.ID = null;
+            this.pr_code.Location = new System.Drawing.Point(240, 43);
+            this.pr_code.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.pr_code.Name = "pr_code";
+            this.pr_code.Power = null;
+            this.pr_code.Size = new System.Drawing.Size(246, 35);
+            this.pr_code.Str = null;
+            this.pr_code.Str1 = null;
+            this.pr_code.Str2 = null;
+            this.pr_code.TabIndex = 191;
+            this.pr_code.KeyDown += new System.Windows.Forms.KeyEventHandler(this.pr_code_KeyDown);
+            this.pr_code.Leave += new System.EventHandler(this.pr_code_Leave);
+            // 
+            // inputText
+            // 
+            this.inputText.AllPower = "ifall";
+            this.inputText.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left)));
+            this.inputText.BackColor = System.Drawing.Color.White;
+            this.inputText.ID = null;
+            this.inputText.Location = new System.Drawing.Point(222, 733);
+            this.inputText.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.inputText.Name = "inputText";
+            this.inputText.Power = null;
+            this.inputText.Size = new System.Drawing.Size(388, 35);
+            this.inputText.Str = null;
+            this.inputText.Str1 = null;
+            this.inputText.Str2 = null;
+            this.inputText.TabIndex = 187;
+            this.inputText.Tag = "ifread";
+            this.inputText.KeyDown += new System.Windows.Forms.KeyEventHandler(this.inputText_KeyDown);
+            // 
+            // OperateResult
+            // 
+            this.OperateResult.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.OperateResult.Location = new System.Drawing.Point(66, 216);
+            this.OperateResult.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.OperateResult.Name = "OperateResult";
+            this.OperateResult.Size = new System.Drawing.Size(1408, 471);
+            this.OperateResult.TabIndex = 186;
+            this.OperateResult.Text = "";
+            // 
+            // Printer
+            // 
+            this.Printer.Location = new System.Drawing.Point(693, 43);
+            this.Printer.Margin = new System.Windows.Forms.Padding(8, 8, 8, 8);
+            this.Printer.Name = "Printer";
+            this.Printer.Size = new System.Drawing.Size(254, 50);
+            this.Printer.TabIndex = 182;
+            // 
+            // Make_CustomLabelPrint
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(1542, 824);
+            this.Controls.Add(this.PrintNum);
+            this.Controls.Add(this.pr_spec);
+            this.Controls.Add(this.pr_detail);
+            this.Controls.Add(this.printButton);
+            this.Controls.Add(this.pr_code);
+            this.Controls.Add(this.label6);
+            this.Controls.Add(this.sncode_label);
+            this.Controls.Add(this.inputText);
+            this.Controls.Add(this.OperateResult);
+            this.Controls.Add(this.PrintLabel);
+            this.Controls.Add(this.label4);
+            this.Controls.Add(this.label5);
+            this.Controls.Add(this.Printer);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.pr_code_label);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
+            this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.Name = "Make_CustomLabelPrint";
+            this.Tag = "Make!CustomLabelPrint";
+            this.Text = "Make_CustomLabelPrint";
+            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Make_CustomLabelPrint_FormClosing);
+            this.Load += new System.EventHandler(this.Make_CustomLablePrint_Load);
+            this.SizeChanged += new System.EventHandler(this.Make_CustomLabelPrint_SizeChanged);
+            this.ResumeLayout(true);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label pr_code_label;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Label label3;
+        private UAS_MES_NEW.CustomControl.ComBoxWithFocus.ComboxWithTip PrintLabel;
+        private System.Windows.Forms.Label label4;
+        private System.Windows.Forms.Label label5;
+        private CustomControl.ComBoxWithFocus.PrinterCombox Printer;
+        private CustomControl.RichText.RichTextAutoBottom OperateResult;
+        private System.Windows.Forms.Label sncode_label;
+        private CustomControl.TextBoxWithIcon.SnCollectionBox inputText;
+        private System.Windows.Forms.Label label6;
+        private CustomControl.TextBoxWithIcon.SnCollectionBox pr_code;
+        private CustomControl.ButtonUtil.NormalButton printButton;
+        private System.Windows.Forms.Label pr_detail;
+        private System.Windows.Forms.Label pr_spec;
+        private CustomControl.TextBoxWithIcon.NumOnlyTextBox PrintNum;
+    }
+}

+ 265 - 0
UAS_MES_ZT/FunctionCode/Make/Make_StencilPrint.cs

@@ -0,0 +1,265 @@
+using DevExpress.Printing.Core.PdfExport.Metafile;
+using LabelManager2;
+using Seagull.BarTender.Print;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading;
+using System.Windows.Forms;
+using UAS_MES_NEW.DataOperate;
+using UAS_MES_NEW.Entity;
+using UAS_MES_NEW.PublicForm;
+using UAS_MES_NEW.PublicMethod;
+
+namespace UAS_MES_NEW.Make
+{
+    public partial class Make_StencilPrint : Form
+    {
+        DataHelper dh;
+
+        LogStringBuilder sql = new LogStringBuilder();
+
+        AutoSizeFormClass asc = new AutoSizeFormClass();
+
+        Thread InitPrint;
+        //存放产品信息
+        DataTable dt;
+        //存放标签信息
+        DataTable listA;
+        //存放标签参数列表信息
+        DataTable paramsInfo;
+        //记录当前的步骤数
+        int currentIndex = 0;
+
+        FileInfo info;
+        BarTender.Application engine;
+
+        //ftpOperater ftp;
+
+        BarTender.Format format;
+
+        StringBuilder sb = new StringBuilder();
+
+        bool canPrint = false;
+
+        string[] inputValues;//存放用户输入的参数值
+        public Make_StencilPrint()
+        {
+            InitializeComponent();
+        }
+
+        private void Make_CustomLablePrint_Load(object sender, EventArgs e)
+        {
+            asc.controllInitializeSize(this);
+            OperateResult.AppendText(">>请输入产品代码\n", Color.Black);
+            InitPrint = new Thread(InPrint);
+            SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
+            BaseUtil.SetFormCenter(stw);
+            stw.ShowDialog();
+            pr_code.Focus();
+            dh = SystemInf.dh;
+        }
+        private void InPrint()
+        {
+            try
+            {
+                engine = new BarTender.Application();
+            }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(ex.Message + ex.StackTrace, Color.Red);
+            }
+        }
+
+        private void pr_code_KeyDown(object sender, KeyEventArgs e)
+        {
+            //按下enter键
+            if (e.KeyCode == Keys.Enter)
+            {
+                //判断产品是否存在
+                dt = (DataTable)dh.ExecuteSql("select pr_code,pr_detail,pr_spec from product where pr_code='" + pr_code.Text + "'  and pr_statuscode ='AUDITED'", "select");
+                //查询没有值,返回提示用户“产品:XXX,不存在或者为审核”,清空产品代码输入框中的值 
+                if (dt.Rows.Count == 0)
+                {
+                    OperateResult.AppendText("<<产品:" + pr_code.Text + ",不存在或者未审核\n", Color.Red, pr_code);
+                    return;
+                }
+                //查询产品是否有自定义的标签模板
+                sql.Clear();
+                sql.Append("select la_code,la_id,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault ");
+                sql.Append("from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='自定义' and la_statuscode='AUDITED' order by la_isdefault");
+                listA = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
+                if (listA.Rows.Count == 0)
+                {
+                    OperateResult.AppendText("<<产品:" + pr_code.Text + ",没有维护自定义模板\n", Color.Red, pr_code);
+                    return;
+                }
+                string la_id = listA.Rows[0]["la_id"].ToString();
+                string la_code = listA.Rows[0]["la_code"].ToString();
+                Console.WriteLine(listA.Rows[0]["la_isdefault"].ToString());
+                {
+                    //说明没有默认的模板,那就取pl_id最大的
+                    listA = (DataTable)dh.ExecuteSql("select fp_name la_url,'" + la_id + "' la_id,'" + la_code + "'la_code from FILEPATH where fp_id in (select *  from table(select parsestring(LA_SOFTTYPE,';') from label where la_id='" + la_id + "' ) where COLUMN_VALUE is not null)", "select");
+                    //listA = (DataTable)dh.ExecuteSql("select la_code,la_id,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='自定义' and la_statuscode='AUDITED' order by la_isdefault", "select");
+                }
+                //标签显示
+                PrintLabel.DataSource = listA;
+                PrintLabel.DisplayMember = "la_url";
+                PrintLabel.ValueMember = "la_id";
+                //有值,填充界面
+                BaseUtil.SetFormValue(this.Controls, dt);
+                //paramsInfo = (DataTable)dh.ExecuteSql("select lp_detno, lp_name, lp_valuetype,lp_sql from label left join labelparameter on lp_laid=la_id where la_code='"+ listA.Rows[0]["pl_labelcode"].ToString() + "' order by lp_detno asc", "select");
+            }
+        }
+
+        private void inputText_KeyDown(object sender, KeyEventArgs e)
+        {
+            //按下enter键
+            string oErrorMessage = "";
+            if (e.KeyCode == Keys.Enter)
+            {
+                //产品编号为空
+                if (pr_code.Text.Trim() == "")
+                {
+                    OperateResult.AppendText("<<请先输入产品编号\n", Color.Red);
+                    return;
+                }
+                if (inputText.Text.Trim() == "")
+                {
+                    OperateResult.AppendText("<<输入不能为空\n", Color.Red);
+                    return;
+                }
+                OperateResult.AppendText(">>" + inputText.Text + "\n", Color.Black);
+                if (paramsInfo == null || paramsInfo.Rows.Count == 0)
+                {
+                    OperateResult.AppendText("<<无可用标签\n", Color.Red, inputText);
+                    return;
+                }
+                else
+                {
+                    if (Print.SinglePrint(Tag.ToString(), engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputText.Text, int.Parse(PrintNum.Text),"", pr_code.Text, "自定义", "-1", out oErrorMessage))
+                    {
+                        OperateResult.AppendText(oErrorMessage + "\n", Color.Red);
+                    }
+                }
+            }
+        }
+
+        private void PrintLabe