Browse Source

SN号生成打印

callm 1 year ago
parent
commit
c97b230bcf

+ 0 - 27
UAS_MES_YD/FunctionCode/Query/Query_SN.Designer.cs

@@ -30,9 +30,7 @@
         {
         {
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Query_SN));
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Query_SN));
             this.ma_salecode_label = new System.Windows.Forms.Label();
             this.ma_salecode_label = new System.Windows.Forms.Label();
-            this.ma_printcount = new System.Windows.Forms.Label();
             this.ma_qty = new System.Windows.Forms.Label();
             this.ma_qty = new System.Windows.Forms.Label();
-            this.lade = new System.Windows.Forms.Label();
             this.label7 = new System.Windows.Forms.Label();
             this.label7 = new System.Windows.Forms.Label();
             this.label5 = new System.Windows.Forms.Label();
             this.label5 = new System.Windows.Forms.Label();
             this.pr_detail = new System.Windows.Forms.Label();
             this.pr_detail = new System.Windows.Forms.Label();
@@ -65,16 +63,6 @@
             this.ma_salecode_label.TabIndex = 20;
             this.ma_salecode_label.TabIndex = 20;
             this.ma_salecode_label.Text = "打印机列表";
             this.ma_salecode_label.Text = "打印机列表";
             // 
             // 
-            // ma_printcount
-            // 
-            this.ma_printcount.AutoSize = true;
-            this.ma_printcount.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ma_printcount.Location = new System.Drawing.Point(650, 270);
-            this.ma_printcount.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
-            this.ma_printcount.Name = "ma_printcount";
-            this.ma_printcount.Size = new System.Drawing.Size(0, 41);
-            this.ma_printcount.TabIndex = 237;
-            // 
             // ma_qty
             // ma_qty
             // 
             // 
             this.ma_qty.AutoSize = true;
             this.ma_qty.AutoSize = true;
@@ -85,17 +73,6 @@
             this.ma_qty.Size = new System.Drawing.Size(0, 41);
             this.ma_qty.Size = new System.Drawing.Size(0, 41);
             this.ma_qty.TabIndex = 236;
             this.ma_qty.TabIndex = 236;
             // 
             // 
-            // lade
-            // 
-            this.lade.AutoSize = true;
-            this.lade.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.lade.Location = new System.Drawing.Point(492, 270);
-            this.lade.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
-            this.lade.Name = "lade";
-            this.lade.Size = new System.Drawing.Size(146, 41);
-            this.lade.TabIndex = 235;
-            this.lade.Text = "已打印数";
-            // 
             // label7
             // label7
             // 
             // 
             this.label7.AutoSize = true;
             this.label7.AutoSize = true;
@@ -332,9 +309,7 @@
             this.Controls.Add(this.label4);
             this.Controls.Add(this.label4);
             this.Controls.Add(this.pr_code);
             this.Controls.Add(this.pr_code);
             this.Controls.Add(this.label8);
             this.Controls.Add(this.label8);
-            this.Controls.Add(this.ma_printcount);
             this.Controls.Add(this.ma_qty);
             this.Controls.Add(this.ma_qty);
-            this.Controls.Add(this.lade);
             this.Controls.Add(this.label7);
             this.Controls.Add(this.label7);
             this.Controls.Add(this.ma_code);
             this.Controls.Add(this.ma_code);
             this.Controls.Add(this.label5);
             this.Controls.Add(this.label5);
@@ -360,9 +335,7 @@
         private CustomControl.ComBoxWithFocus.PrinterCombox PrinterList;
         private CustomControl.ComBoxWithFocus.PrinterCombox PrinterList;
         private CustomControl.ButtonUtil.NormalButton Setting;
         private CustomControl.ButtonUtil.NormalButton Setting;
         private CustomControl.ButtonUtil.NormalButton Export;
         private CustomControl.ButtonUtil.NormalButton Export;
-        private System.Windows.Forms.Label ma_printcount;
         private System.Windows.Forms.Label ma_qty;
         private System.Windows.Forms.Label ma_qty;
-        private System.Windows.Forms.Label lade;
         private System.Windows.Forms.Label label7;
         private System.Windows.Forms.Label label7;
         private CustomControl.TextBoxWithIcon.SearchTextBox ma_code;
         private CustomControl.TextBoxWithIcon.SearchTextBox ma_code;
         private System.Windows.Forms.Label label5;
         private System.Windows.Forms.Label label5;

+ 123 - 9
UAS_MES_YD/FunctionCode/Query/Query_SN.cs

@@ -1,19 +1,13 @@
 using Seagull.BarTender.Print;
 using Seagull.BarTender.Print;
 using System;
 using System;
-using System.Collections.Generic;
-using System.ComponentModel;
 using System.Data;
 using System.Data;
 using System.Drawing;
 using System.Drawing;
 using System.Drawing.Printing;
 using System.Drawing.Printing;
-using System.Linq;
-using System.Text;
 using System.Text.RegularExpressions;
 using System.Text.RegularExpressions;
 using System.Windows.Forms;
 using System.Windows.Forms;
 using UAS_MES_NEW.DataOperate;
 using UAS_MES_NEW.DataOperate;
 using UAS_MES_NEW.Entity;
 using UAS_MES_NEW.Entity;
 using UAS_MES_NEW.PublicMethod;
 using UAS_MES_NEW.PublicMethod;
-using UAS_MES_NEW.Query;
-using static System.Runtime.CompilerServices.RuntimeHelpers;
 
 
 namespace UAS_MES_NEW.Query
 namespace UAS_MES_NEW.Query
 {
 {
@@ -30,6 +24,10 @@ namespace UAS_MES_NEW.Query
 
 
         DataHelper dh = SystemInf.dh;
         DataHelper dh = SystemInf.dh;
 
 
+        //前缀条件
+
+        //生成条码的流水号
+
         DataTable Dbfind;
         DataTable Dbfind;
         public Query_SN()
         public Query_SN()
         {
         {
@@ -217,7 +215,7 @@ namespace UAS_MES_NEW.Query
             ma_code.SelectField = "ma_code # 工单编号,pr_code # 产品编号,pr_spec # 型号";
             ma_code.SelectField = "ma_code # 工单编号,pr_code # 产品编号,pr_spec # 型号";
             ma_code.FormName = Name;
             ma_code.FormName = Name;
             ma_code.SetValueField = new string[] { "ma_code" };
             ma_code.SetValueField = new string[] { "ma_code" };
-            ma_code.Condition = "ma_statuscode='STARTED'";
+            //ma_code.Condition = "ma_statuscode='STARTED'";
             ma_code.DbChange += pr_code_DbChange;
             ma_code.DbChange += pr_code_DbChange;
         }
         }
 
 
@@ -225,19 +223,135 @@ namespace UAS_MES_NEW.Query
         {
         {
             Dbfind = ma_code.ReturnData;
             Dbfind = ma_code.ReturnData;
             BaseUtil.SetFormValue(this.Controls, Dbfind);
             BaseUtil.SetFormValue(this.Controls, Dbfind);
-            DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,mil_makecode from makeimeilist where mil_printstatus=-1 group by mil_makecode) on mil_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
+            DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail from make left join product on ma_prodcode=pr_code  where ma_code='" + ma_code.Text + "'", "select");
             if (dt.Rows.Count > 0)
             if (dt.Rows.Count > 0)
             {
             {
                 pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
                 pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
                 ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
                 ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
-                ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
                 pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
                 pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
             }
             }
         }
         }
 
 
         private void GenSN_Click(object sender, EventArgs e)
         private void GenSN_Click(object sender, EventArgs e)
         {
         {
+            string Prefix = "";
 
 
+            string Suffix = "";
+            //获取编码规则
+            if (!dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
+            {
+                MessageBox.Show("工单号不存在");
+                return;
+            }
+            if (dh.getRowCount("makesnlist", "msl_makecode='" + ma_code.Text + "'") > 0)
+            {
+                MessageBox.Show("工单号" + ma_code.Text + "已存在导入清单");
+                return;
+            }
+            DataTable dt = (DataTable)dh.ExecuteSql("select pr_exbarcode,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + ma_code.Text + "'", "select");
+            string pr_exbarcode = "";
+            string ma_qty = "";
+            if (dt.Rows.Count > 0)
+            {
+                pr_exbarcode = dt.Rows[0]["pr_exbarcode"].ToString();
+                ma_qty = dt.Rows[0]["ma_qty"].ToString();
+            }
+            DataTable Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_type,nrd_radix,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_code='" + pr_exbarcode + "' order by nrd_detno", "select");
+            //如果没有则取公共规则
+            if (Nr.Rows.Count == 0)
+                Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_isdefault <> 0 order by nrd_detno", "select");
+            //用于过滤参数的正则表达式
+            Regex match = new Regex("{\\w+}");
+            //用于存放每一项的明细的数据
+            string[] NrData = new string[Nr.Rows.Count];
+            //流水号的索引
+            int SerialNumIndex = 0;
+            //流水长度
+            int SerialNumLength = 0;
+            //存放键值对
+            int Radix = 10;
+            string PrefixFixed = "";
+            for (int m = 0; m < Nr.Rows.Count; m++)
+            {
+                switch (Nr.Rows[m]["nrd_type"].ToString())
+                {
+                    //常量直接进行拼接
+                    case "常量":
+                        NrData[m] = Nr.Rows[m]["nrd_sql"].ToString();
+                        Prefix += NrData[m];
+                        Suffix += NrData[m];
+                        break;
+                    case "SQL":
+                        string SQL = Nr.Rows[m]["nrd_sql"].ToString();
+                        DataTable Temp;
+                        //如果不包含参数替换
+                        if (SQL.IndexOf("{") == 0)
+                        {
+                            Temp = (DataTable)dh.ExecuteSql(SQL, "select");
+                        }
+                        else
+                        {
+                            //替换参数后重新执行SQL
+                            foreach (Match mch in match.Matches(SQL))
+                            {
+                                SQL = SQL.Replace(mch.Value.Trim(), "'" + ma_code.Text + "'");
+                            }
+                            Temp = (DataTable)dh.ExecuteSql(SQL, "select");
+                        }
+                        if (Temp.Rows.Count > 0)
+                        {
+                            NrData[m] = Temp.Rows[0][0].ToString();
+                            Prefix += NrData[m];
+                            Suffix += NrData[m];
+                        }
+                        else
+                        {
+                            NrData[m] = "";
+                            Prefix += NrData[m];
+                            Suffix += NrData[m];
+                        }
+                        break;
+                    //流水需要通过MaxNumber去取
+                    case "流水":
+                        NrData[m] = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + pr_exbarcode + "'").ToString();
+                        Suffix = "";
+                        PrefixFixed = Prefix;
+                        //设置当前流水
+                        custserialnum = int.Parse(NrData[m] == "" ? "0" : NrData[m]);
+                        SerialNumIndex = m;
+                        SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
+                        Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
+                        break;
+                    default:
+                        break;
+                }
+            }
+            //获取最大的流水号
+            string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + pr_exbarcode + "' and rmn_prefix='" + Prefix + "'").ToString();
+            //如果流水号为空则插入一条新记录,从1开始取
+            if (maxnum == "")
+            {
+                dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + pr_exbarcode + "','" + Prefix + "','1')", "insert");
+                custserialnum = 1;
+            }
+            //如果流水号不为空则取当前流水
+            else
+            {
+                custserialnum = int.Parse(maxnum);
+            }
+            //遍历整个Grid,勾选的项目全部进行条码生成
+            ArrayList<string> custbarcode = new ArrayList<string>();
+            for (int i = 0; i < int.Parse(ma_qty); i++)
+            {
+                custbarcode.Add(BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix));
+            }
+            //插入条码
+            string sql = "insert into makesnlist(MSL_ID, MSL_INDATE, MSL_MAKECODE, MSL_SNCODE, MSL_TYPE)" +
+                "values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "',:custbarcode,'before')";
+            dh.BatchInsert(sql, new string[] { "custbarcode" }, custbarcode.ToArray(), custbarcode.ToArray());
+            //更新最大流水号
+            dh.UpdateByCondition("RuleMaxNum", "rmn_maxnumber='" + custserialnum + "'", "rmn_nrcode='" + pr_exbarcode + "' and rmn_prefix='" + Prefix + "'");
+            MessageBox.Show("工单" + ma_code.Text + "生成SN清单成功");
         }
         }
     }
     }
 }
 }