Przeglądaj źródła

Merge branch 'master' of ssh://10.10.100.21/source/mes-client

Hcsy 7 lat temu
rodzic
commit
0df9bd6315

+ 16 - 15
UAS-出货标签管理(泽天)/UAS_出货标签管理.Designer.cs

@@ -568,19 +568,20 @@
             // PackOutBox
             // 
             this.PackOutBox.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.PackOutBox.Location = new System.Drawing.Point(485, 48);
+            this.PackOutBox.Location = new System.Drawing.Point(485, 81);
             this.PackOutBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.PackOutBox.Name = "PackOutBox";
             this.PackOutBox.Size = new System.Drawing.Size(64, 26);
             this.PackOutBox.TabIndex = 96;
             this.PackOutBox.Text = "封箱";
             this.PackOutBox.UseVisualStyleBackColor = true;
+            this.PackOutBox.Visible = false;
             this.PackOutBox.Click += new System.EventHandler(this.Pack_Click);
             // 
             // PrintStatus
             // 
             this.PrintStatus.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.PrintStatus.Location = new System.Drawing.Point(296, 80);
+            this.PrintStatus.Location = new System.Drawing.Point(485, 50);
             this.PrintStatus.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.PrintStatus.Name = "PrintStatus";
             this.PrintStatus.Size = new System.Drawing.Size(64, 26);
@@ -644,7 +645,7 @@
             // 
             this.CustomerLabel.Enabled = false;
             this.CustomerLabel.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.CustomerLabel.Location = new System.Drawing.Point(485, 80);
+            this.CustomerLabel.Location = new System.Drawing.Point(296, 81);
             this.CustomerLabel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.CustomerLabel.Name = "CustomerLabel";
             this.CustomerLabel.Size = new System.Drawing.Size(84, 26);
@@ -849,7 +850,7 @@
             // 
             this.label18.AutoSize = true;
             this.label18.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label18.Location = new System.Drawing.Point(61, 136);
+            this.label18.Location = new System.Drawing.Point(59, 134);
             this.label18.Name = "label18";
             this.label18.Size = new System.Drawing.Size(13, 17);
             this.label18.TabIndex = 90;
@@ -883,7 +884,7 @@
             // 
             this.label16.AutoSize = true;
             this.label16.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label16.Location = new System.Drawing.Point(60, 73);
+            this.label16.Location = new System.Drawing.Point(58, 71);
             this.label16.Name = "label16";
             this.label16.Size = new System.Drawing.Size(13, 17);
             this.label16.TabIndex = 87;
@@ -917,7 +918,7 @@
             // 
             this.label12.AutoSize = true;
             this.label12.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label12.Location = new System.Drawing.Point(4, 108);
+            this.label12.Location = new System.Drawing.Point(2, 106);
             this.label12.Name = "label12";
             this.label12.Size = new System.Drawing.Size(56, 17);
             this.label12.TabIndex = 77;
@@ -927,7 +928,7 @@
             // 
             this.label7.AutoSize = true;
             this.label7.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label7.Location = new System.Drawing.Point(4, 30);
+            this.label7.Location = new System.Drawing.Point(2, 28);
             this.label7.Name = "label7";
             this.label7.Size = new System.Drawing.Size(56, 17);
             this.label7.TabIndex = 76;
@@ -1190,7 +1191,7 @@
             // 
             this.SingleLabelPrint.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
             this.SingleLabelPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.SingleLabelPrint.Location = new System.Drawing.Point(-15, 174);
+            this.SingleLabelPrint.Location = new System.Drawing.Point(56, 177);
             this.SingleLabelPrint.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.SingleLabelPrint.Name = "SingleLabelPrint";
             this.SingleLabelPrint.Size = new System.Drawing.Size(68, 26);
@@ -1205,7 +1206,7 @@
             this.SingleLabelAutoPrint.Checked = true;
             this.SingleLabelAutoPrint.CheckState = System.Windows.Forms.CheckState.Checked;
             this.SingleLabelAutoPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.SingleLabelAutoPrint.Location = new System.Drawing.Point(7, 95);
+            this.SingleLabelAutoPrint.Location = new System.Drawing.Point(5, 93);
             this.SingleLabelAutoPrint.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.SingleLabelAutoPrint.Name = "SingleLabelAutoPrint";
             this.SingleLabelAutoPrint.Size = new System.Drawing.Size(75, 21);
@@ -1263,7 +1264,7 @@
             // 
             this.label2.AutoSize = true;
             this.label2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label2.Location = new System.Drawing.Point(6, 121);
+            this.label2.Location = new System.Drawing.Point(4, 119);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(32, 17);
             this.label2.TabIndex = 92;
@@ -1286,7 +1287,7 @@
             // 
             this.label5.AutoSize = true;
             this.label5.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label5.Location = new System.Drawing.Point(5, 155);
+            this.label5.Location = new System.Drawing.Point(3, 153);
             this.label5.Name = "label5";
             this.label5.Size = new System.Drawing.Size(32, 17);
             this.label5.TabIndex = 50;
@@ -1319,7 +1320,7 @@
             this.MidLabelAutoPrint.Checked = true;
             this.MidLabelAutoPrint.CheckState = System.Windows.Forms.CheckState.Checked;
             this.MidLabelAutoPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.MidLabelAutoPrint.Location = new System.Drawing.Point(7, 93);
+            this.MidLabelAutoPrint.Location = new System.Drawing.Point(5, 91);
             this.MidLabelAutoPrint.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.MidLabelAutoPrint.Name = "MidLabelAutoPrint";
             this.MidLabelAutoPrint.Size = new System.Drawing.Size(75, 21);
@@ -1362,7 +1363,7 @@
             // LogingOut
             // 
             this.LogingOut.AutoSize = true;
-            this.LogingOut.Location = new System.Drawing.Point(105, 6);
+            this.LogingOut.Location = new System.Drawing.Point(103, 4);
             this.LogingOut.Name = "LogingOut";
             this.LogingOut.Size = new System.Drawing.Size(42, 21);
             this.LogingOut.TabIndex = 77;
@@ -1388,7 +1389,7 @@
             // 
             this.label10.AutoSize = true;
             this.label10.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label10.Location = new System.Drawing.Point(5, 149);
+            this.label10.Location = new System.Drawing.Point(3, 147);
             this.label10.Name = "label10";
             this.label10.Size = new System.Drawing.Size(32, 17);
             this.label10.TabIndex = 90;
@@ -1398,7 +1399,7 @@
             // 
             this.label6.AutoSize = true;
             this.label6.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label6.Location = new System.Drawing.Point(4, 112);
+            this.label6.Location = new System.Drawing.Point(2, 110);
             this.label6.Name = "label6";
             this.label6.Size = new System.Drawing.Size(32, 17);
             this.label6.TabIndex = 87;

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

@@ -10,7 +10,6 @@ using UAS_LabelMachine.PublicMethod;
 using UAS_LabelMachine.Entity;
 using UAS_LabelMachine.PublicForm;
 using System.Threading;
-using System.Globalization;
 using FastReport;
 using System.Linq;
 
@@ -352,7 +351,7 @@ namespace UAS_LabelMachine
             sql.Append("from prodinout left join prodiodetail on pi_id=pd_piid left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode where pi_id='" + PI_ID + "' and pd_prodcode='" + CurrentPrCode + "' and pd_pdno='" + CurrentPDNO + "'");
             dh.BatchInsert(sql.ToString(), new string[] { "PIB_ID", "PIB_CUSTBARCODE" }, PIBID, CustBarCode.ToArray());
             //更新流水号
-            dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum) + "'", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'");
+            dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum) + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
             LoadGridData(new object(), new EventArgs());
             //加载完数据之后进行容量的判断
             int BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
@@ -373,26 +372,6 @@ namespace UAS_LabelMachine
             //采集达到了数量进行换行
             if (CollectQty == double.Parse(CurrentPrCount))
             {
-                //for (int i = 0; i < GridPrcode.Rows.Count; i++)
-                //{
-                //    string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
-                //    string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
-                //    //采集之前的行,如后续行有物料编号相同的并且编号较大的跳到这样
-                //    if (GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString() == CurrentPrCode && double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
-                //    {
-                //        if (int.Parse(GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString()) > int.Parse(CurrentPDNO))
-                //        {
-                //            GridPrcode.Rows[i].Selected = true;
-                //            if (i - 1 > 0)
-                //                GridPrcode.FirstDisplayedScrollingRowIndex = i - 1;
-                //            else
-                //                GridPrcode.FirstDisplayedScrollingRowIndex = i;
-                //            Input.Clear();
-                //            OutBoxNum_Click(new object(), new EventArgs());
-                //            return;
-                //        }
-                //    }
-                //}
                 DataGridViewSelectedRowCollection selectrow = GridPrcode.SelectedRows;
                 if (selectrow.Count > 0)
                 {
@@ -403,7 +382,6 @@ namespace UAS_LabelMachine
                         if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
                         {
                             GridPrcode.Rows[selectrow[0].Index + 1].Selected = true;
-                            GridPrcode.FirstDisplayedScrollingRowIndex = selectrow[0].Index + 1;
                         }
                     }
                 }
@@ -569,8 +547,8 @@ namespace UAS_LabelMachine
                         if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
                         {
                             GridPrcode.Rows[i].Selected = true;
-                            if (i - 1 > 0)
-                                GridPrcode.FirstDisplayedScrollingRowIndex = i - 1;
+                            if (i - 2 >= 0)
+                                GridPrcode.FirstDisplayedScrollingRowIndex = i - 2;
                             else
                                 GridPrcode.FirstDisplayedScrollingRowIndex = i;
                         }
@@ -667,7 +645,7 @@ namespace UAS_LabelMachine
                     }
                     else
                     {
-                        MessageBox.Show("未勾选打印明细!", "提示");
+                        MessageBox.Show("未勾选打印明细", "提示", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                     }
                     LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标", "打印成功");
                     dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
@@ -791,15 +769,34 @@ namespace UAS_LabelMachine
                     MidOutBoxCodeIndex.Clear();
                     SelectProdcode = LabelInf.Rows[SelectRowIndex].Cells["pib_prodcode"].Value.ToString();
                     SelectMidBoxCode = LabelInf.Rows[SelectRowIndex].Cells["pib_outboxcode1"].Value.ToString();
-                }
-                for (int i = 0; i < LabelInf.Rows.Count; i++)
-                {
-                    if (LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == SelectMidBoxCode)
+                    for (int i = SelectRowIndex; i >= 0; i--)
                     {
-                        if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
+                        if (LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode)
                         {
-                            MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
-                            MidOutBoxCodeIndex.Add(i);
+                            if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
+                            {
+                                MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
+                                MidOutBoxCodeIndex.Add(i);
+                            }
+                        }
+                        else
+                        {
+                            break;
+                        }
+                    }
+                    for (int i = SelectRowIndex; i < LabelInf.Rows.Count - 1; i++)
+                    {
+                        if (LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode)
+                        {
+                            if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
+                            {
+                                MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
+                                MidOutBoxCodeIndex.Add(i);
+                            }
+                        }
+                        else
+                        {
+                            break;
                         }
                     }
                 }
@@ -1026,6 +1023,7 @@ namespace UAS_LabelMachine
         {
             if (OutBoxCombox.Text != "")
             {
+                Pack_Click(sender, e);
                 thread = new Thread(OutBoxPrint);
                 stw = new SetLoadingWindow(thread, "正在打印外箱");
                 BaseUtil.SetFormCenter(stw);
@@ -1065,7 +1063,6 @@ namespace UAS_LabelMachine
             {
                 BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
             }
-            //有数据的话默认取第一条的品牌去取采集策略
             if (LabelInf.Rows.Count > 0)
                 LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1;
             double CollectNum = 0;
@@ -1336,7 +1333,6 @@ namespace UAS_LabelMachine
                 CurrentPrCount = GridPrcode.Rows[0].Cells["pd_outqty"].Value.ToString();
                 CurrentBrand = GridPrcode.Rows[0].Cells["pd_brand"].Value.ToString();
                 GridPrcode.Rows[0].Selected = true;
-                GridPrcode.FirstDisplayedScrollingRowIndex = 0;
             }
         }
 
@@ -1421,11 +1417,11 @@ namespace UAS_LabelMachine
                         break;
                     //流水需要通过MaxNumber去取
                     case "流水":
-                        string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'").ToString();
+                        string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'").ToString();
                         //设置当前流水
                         if (maxnum == "")
                         {
-                            dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + 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 + "','1')", "insert");
                             MaxNum = 1;
                         }
                         else
@@ -1455,8 +1451,10 @@ namespace UAS_LabelMachine
             CurrentPrCount = GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString();
             CurrentBrand = GridPrcode.Rows[e.RowIndex].Cells["pd_brand"].Value.ToString();
             GridPrcode.Rows[e.RowIndex].Selected = true;
-            GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
-            //dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno='" + CurrentPDNO + "' and pib_prodcode='" + CurrentPrCode + "'", "delete");
+            if (e.RowIndex - 2 >= 0)
+                GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
+            else
+                GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
             LoadGridData(sender, new EventArgs());
         }
 
@@ -1472,8 +1470,8 @@ namespace UAS_LabelMachine
                 CurrentPrCount = GridPrcode.Rows[dsc[0].Index].Cells["pd_outqty"].Value.ToString();
                 CurrentBrand = GridPrcode.Rows[dsc[0].Index].Cells["pd_brand"].Value.ToString();
                 GridPrcode.Rows[dsc[0].Index].Selected = true;
-                if (dsc[0].Index - 1 > 0)
-                    GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index - 1;
+                if (dsc[0].Index - 2 >= 0)
+                    GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2;
                 else
                     GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index;
             }
@@ -1486,8 +1484,8 @@ namespace UAS_LabelMachine
             if (e.RowIndex >= 0)
             {
                 GridPrcode.Rows[e.RowIndex].Selected = true;
-                if (e.RowIndex - 1 > 0)
-                    GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 1;
+                if (e.RowIndex - 2 > 0)
+                    GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
                 else
                     GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
             }
@@ -1605,35 +1603,34 @@ namespace UAS_LabelMachine
         {
             if (LabelInf.Rows.Count > 0)
             {
-                DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_outboxcode2)", "select");
-                string pibcustoutboxcode = dh.getFieldDataByCondition("prodiobarcode", "pib_custoutboxcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode2"].Value.ToString() + "' and pib_custoutboxcode is not null").ToString();
                 GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
-                if (Radix > 0)
+                List<string> OutBoxCode = new List<string>();
+                List<string> PIBID = new List<string>();
+                for (int i = 0; i < LabelInf.Rows.Count; i++)
                 {
-                    //生成外箱条码
-                    for (int i = 0; i < dt.Rows.Count; i++)
+                    if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
                     {
-                        List<string> OutBoxCode = new List<string>();
-                        List<string> PIBOUTBOXCODE2 = new List<string>();
+                        PIBID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
                         string serialcode = BaseUtil.DToAny(MaxNum, Radix);
                         for (int k = serialcode.ToString().Length; k < NumLength; k++)
                         {
                             serialcode = "0" + serialcode;
                         }
-                        if (pibcustoutboxcode == "")
-                        {
-                            OutBoxCode.Add(Prefix + serialcode + Suffix);
-                            MaxNum = MaxNum + 1;
-                        }
-                        else
+                        if (i + 1 < LabelInf.Rows.Count)
                         {
-                            OutBoxCode.Add(pibcustoutboxcode);
+                            string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
+                            string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
+                            if (FPrcode != BPrcode)
+                            {
+                                MaxNum = MaxNum + 1;
+                            }
                         }
-                        PIBOUTBOXCODE2.Add(dt.Rows[i]["pib_outboxcode2"].ToString());
-                        dh.BatchInsert("update prodiobarcode set pib_custoutboxcode=:pib_custoutboxcode where pib_outboxcode2=:pib_outboxcode2 and pib_custoutboxcode is null", new string[] { "pib_custoutboxcode", "pib_outboxcode2" }, OutBoxCode.ToArray(), PIBOUTBOXCODE2.ToArray());
+                        OutBoxCode.Add(Prefix + serialcode + Suffix);
                     }
-                    dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + MaxNum + "'", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'");
                 }
+                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);
             }
         }
@@ -1676,7 +1673,7 @@ 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 + "' and rmn_prefix='" + Prefix + "'");
+                dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + MaxNum + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
             }
             LoadGridData(sender, e);
         }