Browse Source

解决条码重复的问题

章政 7 years ago
parent
commit
1e99a5dcec
1 changed files with 44 additions and 12 deletions
  1. 44 12
      UAS-出货标签管理(泽天)/UAS_出货标签管理.cs

+ 44 - 12
UAS-出货标签管理(泽天)/UAS_出货标签管理.cs

@@ -342,7 +342,7 @@ namespace UAS_LabelMachine
                 Input.SelectAll();
                 return;
             }
-            GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
+            GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, CodeCount);
             List<string> CustBarCode = new List<string>();
             if (!(Radix > 0))
             {
@@ -379,7 +379,6 @@ namespace UAS_LabelMachine
                 MessageBox.Show("未成功插入数据,请核对出货单当前明细", "提示");
             }
             //更新流水号
-            dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum) + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
             LoadGridData(new object(), new EventArgs());
             if (LabelInf.Rows.Count > 0)
             {
@@ -598,7 +597,7 @@ namespace UAS_LabelMachine
                     OutBoxNum_Click(new object(), new EventArgs());
                     LoadPrcodeData();
                     //获取条码规则
-                    GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
+                    GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, 1);
                     SingleID.Clear();
                     Input.Focus();
                     ////从后往前找未采集的行
@@ -1518,7 +1517,7 @@ namespace UAS_LabelMachine
         /// <param name="MaxNum"></param>
         /// <param name="SerialNumLength"></param>
         /// <param name="Radix"></param>
-        private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix)
+        private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix, int Count)
         {
             //获取编码规则
             Prefix = "";
@@ -1576,12 +1575,13 @@ namespace UAS_LabelMachine
                         //设置当前流水
                         if (maxnum == "")
                         {
-                            dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "','" + Prefix + "','1')", "insert");
+                            dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "','" + Prefix + "','" + Count + "')", "insert");
                             MaxNum = 1;
                         }
                         else
                         {
                             MaxNum = int.Parse(maxnum);
+                            dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
                         }
                         SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
                         Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
@@ -1752,7 +1752,27 @@ namespace UAS_LabelMachine
         {
             if (LabelInf.Rows.Count > 0)
             {
-                GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
+                int GetNumCount = 1;
+                for (int i = 0; i < LabelInf.Rows.Count; i++)
+                {
+                    if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
+                    {
+                        if (i + 1 < LabelInf.Rows.Count)
+                        {
+                            string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
+                            string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
+                            string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
+                            string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
+                            string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
+                            string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
+                            if (FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode)
+                            {
+                                GetNumCount = GetNumCount + 1;
+                            }
+                        }
+                    }
+                }
+                GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
                 List<string> OutBoxCode = new List<string>();
                 List<string> PIBID = new List<string>();
                 for (int i = 0; i < LabelInf.Rows.Count; i++)
@@ -1782,8 +1802,6 @@ namespace UAS_LabelMachine
                     }
                 }
                 dh.BatchInsert("update prodiobarcode set pib_custoutboxcode=:pib_custoutboxcode where pib_id=:pib_id and pib_custoutboxcode is null", new string[] { "pib_custoutboxcode", "pib_outboxcode2" }, OutBoxCode.ToArray(), PIBID.ToArray());
-                MaxNum = MaxNum + 1;
-                dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + MaxNum + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
                 LoadGridData(sender, e);
             }
         }
@@ -1791,7 +1809,23 @@ namespace UAS_LabelMachine
         private void PackMidBox_Click(object sender, EventArgs e)
         {
             DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_outboxcode2", "select");
-            GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
+            DataTable dt1 = null;
+            int GetNumCount = 0;
+            for (int i = 0; i < dt.Rows.Count; i++)
+            {
+                dt1 = (DataTable)dh.ExecuteSql("select pib_id,pib_prodcode,pd_custprodcode from prodiobarcode left join prodiodetail on pib_pdid=pd_id where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + dt.Rows[i]["pib_outboxcode2"].ToString() + "' and pib_outboxcode1 is null order by  to_number(pib_id)", "select");
+                //如果不是10的整数倍则为尾盒
+                int tencount = 0;
+                for (int j = 0; j < dt1.Rows.Count; j++)
+                {
+                    if (tencount % MidboxCapacity.Value == 0 || (dt1.Rows[j]["pib_prodcode"].ToString() != dt1.Rows[j - 1]["pib_prodcode"].ToString()) || (dt1.Rows[j]["pd_custprodcode"].ToString() != dt1.Rows[j - 1]["pd_custprodcode"].ToString()))
+                    {
+                        GetNumCount = GetNumCount + 1;
+                    }
+                    tencount = tencount + 1;
+                }
+            }
+            GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
             if (Radix > 0)
             {
                 //生成中盒条码
@@ -1802,7 +1836,7 @@ namespace UAS_LabelMachine
                     List<string> MidBoxCode = new List<string>();
                     List<string> PIBID = new List<string>();
                     List<string> PIBOUTBOXCODE1 = new List<string>();
-                    DataTable dt1 = (DataTable)dh.ExecuteSql("select pib_id,pib_prodcode,pd_custprodcode from prodiobarcode left join prodiodetail on pib_pdid=pd_id where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + dt.Rows[i]["pib_outboxcode2"].ToString() + "' and pib_outboxcode1 is null order by  to_number(pib_id)", "select");
+                    dt1 = (DataTable)dh.ExecuteSql("select pib_id,pib_prodcode,pd_custprodcode from prodiobarcode left join prodiodetail on pib_pdid=pd_id where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + dt.Rows[i]["pib_outboxcode2"].ToString() + "' and pib_outboxcode1 is null order by  to_number(pib_id)", "select");
                     //如果不是10的整数倍则为尾盒
                     int tencount = 0;
                     for (int j = 0; j < dt1.Rows.Count; j++)
@@ -1825,8 +1859,6 @@ namespace UAS_LabelMachine
                     }
                     dh.BatchInsert("update prodiobarcode set pib_custmidboxcode=:pib_custmidboxcode,pib_outboxcode1=:pib_outboxcode1 where pib_id=:pib_id and pib_custmidboxcode is null", new string[] { "pib_custmidboxcode", "pib_outboxcode1", "pib_id" }, MidBoxCode.ToArray(), PIBOUTBOXCODE1.ToArray(), PIBID.ToArray());
                 }
-                MaxNum = MaxNum + 1;
-                dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + MaxNum + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
             }
             LoadGridData(sender, e);
         }