Jelajahi Sumber

标签模板配置化

yhluo 2 hari lalu
induk
melakukan
dcfb7cd74f

+ 23 - 23
UAS_MES_XMW/FunctionCode/Make/Make_ServerListen.Designer.cs

@@ -33,12 +33,12 @@
             this.IpPort = new System.Windows.Forms.TextBox();
             this.IpPortLab = new System.Windows.Forms.Label();
             this.SettingBox = new System.Windows.Forms.Panel();
+            this.Template = new System.Windows.Forms.ComboBox();
+            this.ModelLab = new System.Windows.Forms.Label();
             this.TestPrint = new System.Windows.Forms.Button();
             this.confirmPrint = new System.Windows.Forms.Button();
             this.PrintList = new System.Windows.Forms.ComboBox();
             this.PrintListLab = new System.Windows.Forms.Label();
-            this.ModelLab = new System.Windows.Forms.Label();
-            this.Model = new System.Windows.Forms.ComboBox();
             this.OperatResult = new UAS_MES_NEW.CustomControl.RichText.RichTextAutoBottom();
             this.SNDetails = new UAS_MES_NEW.CustomControl.GroupBoxWithBorder.GroupBoxWithBorder();
             this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
@@ -96,7 +96,7 @@
             // 
             // SettingBox
             // 
-            this.SettingBox.Controls.Add(this.Model);
+            this.SettingBox.Controls.Add(this.Template);
             this.SettingBox.Controls.Add(this.ModelLab);
             this.SettingBox.Controls.Add(this.TestPrint);
             this.SettingBox.Controls.Add(this.confirmPrint);
@@ -112,6 +112,25 @@
             this.SettingBox.Size = new System.Drawing.Size(1280, 194);
             this.SettingBox.TabIndex = 98;
             // 
+            // Template
+            // 
+            this.Template.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.Template.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Template.FormattingEnabled = true;
+            this.Template.Location = new System.Drawing.Point(108, 82);
+            this.Template.Name = "Template";
+            this.Template.Size = new System.Drawing.Size(309, 32);
+            this.Template.TabIndex = 99;
+            // 
+            // ModelLab
+            // 
+            this.ModelLab.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.ModelLab.Location = new System.Drawing.Point(22, 84);
+            this.ModelLab.Name = "ModelLab";
+            this.ModelLab.Size = new System.Drawing.Size(117, 28);
+            this.ModelLab.TabIndex = 98;
+            this.ModelLab.Text = "打印模板:";
+            // 
             // TestPrint
             // 
             this.TestPrint.Cursor = System.Windows.Forms.Cursors.Hand;
@@ -153,25 +172,6 @@
             this.PrintListLab.TabIndex = 94;
             this.PrintListLab.Text = "打印机列表:";
             // 
-            // ModelLab
-            // 
-            this.ModelLab.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ModelLab.Location = new System.Drawing.Point(22, 84);
-            this.ModelLab.Name = "ModelLab";
-            this.ModelLab.Size = new System.Drawing.Size(117, 28);
-            this.ModelLab.TabIndex = 98;
-            this.ModelLab.Text = "打印模板:";
-            // 
-            // Model
-            // 
-            this.Model.Cursor = System.Windows.Forms.Cursors.Hand;
-            this.Model.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Model.FormattingEnabled = true;
-            this.Model.Location = new System.Drawing.Point(108, 82);
-            this.Model.Name = "Model";
-            this.Model.Size = new System.Drawing.Size(309, 32);
-            this.Model.TabIndex = 99;
-            // 
             // OperatResult
             // 
             this.OperatResult.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -355,6 +355,6 @@
         private System.Windows.Forms.Button confirmPrint;
         private System.Windows.Forms.Button TestPrint;
         private System.Windows.Forms.Label ModelLab;
-        private System.Windows.Forms.ComboBox Model;
+        private System.Windows.Forms.ComboBox Template;
     }
 }

+ 48 - 19
UAS_MES_XMW/FunctionCode/Make/Make_ServerListen.cs

@@ -34,6 +34,7 @@ namespace UAS_MES_NEW.Make
         private int currCount = 0;
 
         private LabelPrinter _printer;
+        private List<string> pahtArr = new List<string>() { };
 
         private void Make_ServerListen_Load(object sender, EventArgs e)
         {
@@ -49,29 +50,44 @@ namespace UAS_MES_NEW.Make
                 PrintList.Items.Add(printerName);
             }
 
-            StringBuilder strB = new StringBuilder();
-            dt = (DataTable)dh.ExecuteSql($@"SELECT la_softtype FROM label WHERE la_templatetype = '机身标' AND la_statuscode = 'AUDITED'", "select");
-            if (dt.Rows.Count > 0)
+            try
             {
-                foreach (DataRow dr in dt.Rows)
-                {
-                    strB.Append(dr["la_softtype"].ToString());
-                }
-                string[] arr = strB.ToString().Split(';');
-
-                foreach(string s in arr)
+                dt = (DataTable)dh.ExecuteSql($@"SELECT la_softtype FROM label WHERE la_templatetype = '机身标' AND la_statuscode = 'AUDITED'", "select");
+                if (dt.Rows.Count > 0)
                 {
-                    dt = (DataTable)dh.ExecuteSql($"select FP_PATH, FP_DATE, FP_NAME from FILEPATH where fp_id='{s}'", "select");
-                    if (dt.Rows.Count > 0)
+                    foreach (DataRow dr in dt.Rows)
                     {
-                        string fp_path = dt.Rows[0]["FP_PATH"].ToString().Replace("/app/uas/webapps/", "");
-                        string fp_name = dt.Rows[0]["fp_name"].ToString();
-                        WebClient webCli = new WebClient();
-                        webCli.DownloadFile("http://192.168.1.86:8099/mes/" + fp_path, Application.StartupPath + fp_name);
-                        Model.Items.Add(fp_name);
+                        string[] arr = dr["la_softtype"].ToString().Trim().Split(';');
+
+                        foreach (string s in arr)
+                        {
+                            if (string.IsNullOrEmpty(s)) continue;
+
+                            dt = (DataTable)dh.ExecuteSql($"select FP_PATH, FP_DATE, FP_NAME from FILEPATH where fp_id = '{s}'", "select");
+                            if (dt.Rows.Count > 0)
+                            {
+                                string fp_path = dt.Rows[0]["FP_PATH"].ToString().Replace("/app/uas/webapps/", "");
+                                string fp_name = dt.Rows[0]["fp_name"].ToString();
+                                Template.Items.Add(fp_name);
+
+                                string outPath = Path.Combine(Application.StartupPath, fp_name);
+                                using (WebClient client = new WebClient())
+                                {
+                                    //client.DownloadFile($"http://192.168.1.86:8099/mes/{fp_path}", outPath);
+                                    //webCli.DownloadFile("http://erp.ubtob.net:11791/" + fp_path, outPath);
+
+                                    pahtArr.Add(outPath);
+                                }
+                            }
+                        }
                     }
                 }
             }
+            catch (Exception ex)
+            {
+                ShowMsg(0, $"获取系统机身标模板失败,请检查上传模板,{ex.Message}");
+            }
+            
 
             try
             {
@@ -149,6 +165,14 @@ namespace UAS_MES_NEW.Make
                 return;
             }*/
 
+            if (Template.SelectedIndex == -1)
+            {
+                Template.Focus();
+                Template.SelectAll();
+                ShowMsg(0, "请选择打印模板");
+                return;
+            }
+
             if (PrintList.SelectedIndex == -1)
             {
                 PrintList.Focus();
@@ -161,8 +185,12 @@ namespace UAS_MES_NEW.Make
             {
                 confirmPrint.Text = "取消打印机";
                 PrintList.Enabled = false;
+                Template.Enabled = false;
+
+                string str1 = Application.StartupPath + "\\机身标 (1).btw";
 
-                _printer = new LabelPrinter(Application.StartupPath + "\\机身标 (1).btw");
+                string str = pahtArr[Template.SelectedIndex];
+                _printer = new LabelPrinter(str);
                 _printer.SetPrinter(PrintList.Text);
                 _printer.PrintError += (s, args) =>
                 {
@@ -183,6 +211,7 @@ namespace UAS_MES_NEW.Make
             {
                 confirmPrint.Text = "确认打印机";
                 PrintList.Enabled = true;
+                Template.Enabled = true;
 
                 if (_printer != null)
                 {
@@ -747,7 +776,7 @@ namespace UAS_MES_NEW.Make
                 get { return _templateFolder; }
                 set
                 {
-                    if (!File.Exists(value)) throw new DirectoryNotFoundException($"模板文件不存在: {value}");
+                    if (!File.Exists(value)) throw new DirectoryNotFoundException($"模板文件不存在: {value}");
                     _templateFolder = value;
                 }
             }