From fad12ab96ea63fe46e75d33e95754d032deddcdb Mon Sep 17 00:00:00 2001
From: 杨乐 <yang.le.192@qq.com>
Date: 星期三, 19 一月 2022 17:04:32 +0800
Subject: [PATCH] 生产工序  完善 器具维修派工单 验证 设备维修派工单 编辑

---
 WarM/条码打印/Gy_BarCodeBill.cs |  382 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 279 insertions(+), 103 deletions(-)

diff --git "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill.cs" "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill.cs"
index 833372c..c6b008e 100644
--- "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill.cs"
+++ "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill.cs"
@@ -43,42 +43,43 @@
         public const Int16 HQtyCol = 22;
         public const Int16 HMinQtyCol = 23;
         public const Int16 HBQtyCol = 24;
-        public const Int16 HDeptIDCol = 25;
-        public const Int16 HDeptNumberCol = 26;
-        public const Int16 HDeptNameCol = 27;
-        public const Int16 HSourceIDCol = 28;
-        public const Int16 HSourceNumberCol = 29;
-        public const Int16 HSourceNameCol = 30;
-        public const Int16 HDateCol = 31;
-        public const Int16 HEndDateCol = 32;
-        public const Int16 HSupIDCol = 33;
-        public const Int16 HSupNumberCol = 34;
-        public const Int16 HSupNameCol = 35;
-        public const Int16 HCusIDCol = 36;
-        public const Int16 HCusNumberCol = 37;
-        public const Int16 HCusNameCol = 38;
-        public const Int16 HCusTypeCol = 39;
-        public const Int16 HSourceInterIDCol = 40;
-        public const Int16 HSourceEntryIDCol = 41;
-        public const Int16 HSourceBillNoCol = 42;
-        public const Int16 HSourceBillTypeCol = 43;
-        public const Int16 HInstructIDCol = 44;
-        public const Int16 HInstructNoCol = 45;
-        public const Int16 HSeOrderBillIDCol = 46;
-        public const Int16 HSeOrderBillNoCol = 47;
-        public const Int16 HWhIDCol = 48;
-        public const Int16 HWhNumberCol = 49;
-        public const Int16 HWhNameCol = 50;
-        public const Int16 HSPIDCol = 51;
-        public const Int16 HSPNumberCol = 52;
-        public const Int16 HSPNameCol = 53;
-        public const Int16 HinitQtyCol = 54;
-        public const Int16 HRemarkCol = 55;
-        public const Int16 HPinfanBarCodeCol = 56;
-        public const Int16 HMTONoCol = 57;
-        public const Int16 HShowDateCol = 58;
-        public const Int16 HInnerBillNoCol = 59;
-        public const Int16 HMakerCol = 60;
+        public const Int16 HPackQtyCol = 25;
+        public const Int16 HDeptIDCol = 26;
+        public const Int16 HDeptNumberCol = 27;
+        public const Int16 HDeptNameCol = 28;
+        public const Int16 HSourceIDCol = 29;
+        public const Int16 HSourceNumberCol = 30;
+        public const Int16 HSourceNameCol = 31;
+        public const Int16 HDateCol = 32;
+        public const Int16 HEndDateCol = 33;
+        public const Int16 HSupIDCol = 34;
+        public const Int16 HSupNumberCol = 35;
+        public const Int16 HSupNameCol = 36;
+        public const Int16 HCusIDCol = 37;
+        public const Int16 HCusNumberCol = 38;
+        public const Int16 HCusNameCol = 39;
+        public const Int16 HCusTypeCol = 40;
+        public const Int16 HSourceInterIDCol = 41;
+        public const Int16 HSourceEntryIDCol = 42;
+        public const Int16 HSourceBillNoCol = 43;
+        public const Int16 HSourceBillTypeCol = 44;
+        public const Int16 HInstructIDCol = 45;
+        public const Int16 HInstructNoCol = 46;
+        public const Int16 HSeOrderBillIDCol = 47;
+        public const Int16 HSeOrderBillNoCol = 48;
+        public const Int16 HWhIDCol = 49;
+        public const Int16 HWhNumberCol = 50;
+        public const Int16 HWhNameCol = 51;
+        public const Int16 HSPIDCol = 52;
+        public const Int16 HSPNumberCol = 53;
+        public const Int16 HSPNameCol = 54;
+        public const Int16 HinitQtyCol = 55;
+        public const Int16 HRemarkCol = 56;
+        public const Int16 HPinfanBarCodeCol = 57;
+        public const Int16 HMTONoCol = 58;
+        public const Int16 HShowDateCol = 59;
+        public const Int16 HInnerBillNoCol = 60;
+        public const Int16 HMakerCol = 61;
 
         public Int16 HSelectCol = 0;
         public Int16 HSno2Col = 1;
@@ -137,7 +138,8 @@
         public Int16 HMTONo2Col = 54;
         public Int16 HShowDate2Col = 55;
         public Int16 HInnerBillNo2Col = 56; 
-        public Int16 HMaker2Col = 57; 
+        public Int16 HMaker2Col = 57;
+        public Int16 HEntryID2Col = 58;
         //
         public  string ModName = "85";
         public  string ModCaption = "鏉$爜鐢熸垚";
@@ -266,6 +268,7 @@
         {
             this.Sub_SaveBill();
             Display();
+            
         }
 
         //閲嶇疆鎸夌航
@@ -688,6 +691,7 @@
             string HModelName = "";       //鏈哄瀷
             string HICMOBillNo = "";       //婧愬崟鍙�
             string HBarCodeBatchNo = "";       //鏉$爜鎵规鍙�
+            string HBarCodeDate = "";         //鏉$爜鏃ユ湡
             int k = 0;
             int n = 0;                  //鍚屼竴鎵圭敓鎴愭潯鐮佷腑鐨勭鍑犳潯
             string sTMNumber = "";      //鏉$爜鑷畾涔夊墠缂�
@@ -704,7 +708,7 @@
                     //鏃ユ湡鑾峰彇鏂瑰紡
                     sDate = dtpHDate.Value.ToShortDateString();
                     //
-                    if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�") //鍗曟嵁鏃ユ湡(鏀舵枡閫氱煡鍗�)
+                    if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�" || cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佸鍣ㄨ鍒�") //鍗曟嵁鏃ユ湡(鏀舵枡閫氱煡鍗�)
                     {
                         sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HDateCol].Value);
                     }
@@ -712,14 +716,15 @@
                     {
                         sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HEndDateCol].Value);
                     }
-                    else if (CompanyName=="澶忓疂鐢靛櫒")// 鏃ユ湡锛氱敓浜ц鍗� 鏉$爜鏃ユ湡
+                    else if (CampanyName == "澶忓疂鐢靛櫒")// 鏃ユ湡锛氱敓浜ц鍗� 鏉$爜鏃ユ湡
                     {
                         sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HDateCol].Value);
                     }
                     HYasuoji= DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HPinfanCol].Value); //鍘嬬缉鏈轰唬鐮侊紙澶忓疂鐢靛櫒锛�
-                    HModelName= DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterModelCol].Value); //鏈哄瀷锛堝瀹濈數鍣級
+                    HModelName= DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusTypeCol].Value); //鏈哄瀷锛堝瀹濈數鍣級
                     HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HSourceBillNoCol].Value); //鐢熶骇璁㈠崟鍙凤紙澶忓疂鐢靛櫒锛�
                     HBarCodeBatchNo= DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HPinfanBarCodeCol].Value); //鏉$爜鎵规鍙凤紙澶忓疂鐢靛櫒锛�
+                    HBarCodeDate= DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HSupNumberCol].Value); //鏉$爜鏃ユ湡锛堝瀹濈數鍣級
                     //
                     sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
                     sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
@@ -776,7 +781,7 @@
                     {
                         TM = HOrgNumber + HNumber + HBatchNo;
                     }//鍗氭棩鐗规畩澶勭悊
-                    else if(cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�")
+                    else if(cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�" || cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佸鍣ㄨ鍒�")
                     {
                         //鐗╂枡缂栫爜+鍗曟嵁鏃ユ湡锛圷YMMDD锛�+娴佹按4浣� 
                         sTMNumber = HMaterNumber + sYear + sPeriod + sDay;
@@ -785,7 +790,7 @@
                         LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                         LSHlen = 4;
                     }
-                    else if (cmbHBarCodeType.Text == "浠櫒鎴愬搧鏉$爜瑙勫垯")
+                    else if (cmbHBarCodeType.Text == "浠櫒鎴愬搧鏉$爜瑙勫垯") //鍙﹀澶勭悊浜�
                     {
                         //鐗╂枡缂栫爜+搴忓垪鍙�+鐢熶骇鏃ユ湡
                         //sTMNumber = HMaterNumber + sYear + sPeriod + sDay;
@@ -795,8 +800,8 @@
                     }
                     else if (cmbHBarCodeType.Text == "璇曞墏鎴愬搧鏉$爜瑙勫垯")
                     {
-                        //鐗╂枡缂栫爜+鐢熶骇鎵瑰彿+澶辨晥鏃ユ湡锛圷YMMDD锛�+娴佹按鍙�6浣�-
-                        sTMNumber = HMaterNumber + HBatchNo + sYear + sPeriod + sDay;
+                        //鐗╂枡缂栫爜+鐢熶骇鎵瑰彿+娴佹按鍙�6浣�-
+                        sTMNumber = HMaterNumber + HBatchNo ;
                         Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
                                                                                                                     //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                         LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
@@ -806,20 +811,31 @@
                     {
                         //鍒堕�犳湰閮�1浣嶏紙榛樿1锛�+鏈哄瀷浠g爜5浣嶏紙锛�+骞�2浣�+鏈�1浣嶏紙A銆丅銆丆浠f浛10鏈堜唤锛�
                         //+鏃�2浣�+鏉$爜鎵规鐮�2浣�+鍘嬬缉鏈轰唬鐮�1浣�+00+娴佹按鍙�4浣�+鏍¢獙鐮侊紙榛樿0锛�
-                        sTMNumber = "1" + HModelName + sYear + Sub_PeriodChange(sPeriod) + sDay + HBarCodeBatchNo + HYasuoji;
+                        sTMNumber = "1" + HModelName + HBarCodeDate + HBarCodeBatchNo + HYasuoji + "00" ;
                         Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
                                                                                                                     //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                         LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
-                        LSHlen = 4;
+                        LSHlen = 5;
+                        if (sTMNumber.Length != 16)
+                        {
+                            MessageBox.Show("鏉$爜闀垮害涓嶅16浣嶏紝鏄惁鏁版嵁涓嶅叏锛佸埗閫犳湰閮�1浣�:[0] + 鏈哄瀷浠g爜5浣�:[" + HModelName + "] + 骞存湀鏃�5浣�:["+ HBarCodeDate + "] + 鎵规鍙�2浣�:[" + HBarCodeBatchNo  + "]+ 鍘嬬缉鏈�1浣�:["+ HYasuoji + "]+00 ; ");
+                            return;
+                        }
                     }
                     else if (cmbHBarCodeType.Text == "澶栭攢鏈烘潯鐮�")
                     {
                         //鐗╂枡浠g爜11浣�+骞�2浣�+鏈�1浣嶏紙A銆丅銆丆浠f浛10鏈堜唤锛�+鏃�2浣�+鎵规2浣�+娴佹按鍙�4浣�
-                        sTMNumber = HMaterNumber + sYear + Sub_PeriodChange(sPeriod) + sDay + HBarCodeBatchNo ;
+                        //sTMNumber = HMaterNumber.Replace(Convert.ToChar("."),Convert.ToChar("")) + HBarCodeDate + HBarCodeBatchNo;
+                        sTMNumber = HMaterNumber.Replace( "."  ,  "" ) + HBarCodeDate + HBarCodeBatchNo;
                         Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
                                                                                                                     //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                         LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
-                        LSHlen = 4;
+                        LSHlen = 5;
+                        if (sTMNumber.Length != 18)
+                        {
+                            MessageBox.Show("鏉$爜闀垮害涓嶅18浣嶏紝鏄惁鏁版嵁涓嶅叏锛佺墿鏂欎唬鐮�11浣�:["+ HMaterNumber.Replace(".", "") + "]+骞存湀鏃�5浣�:["+ HBarCodeDate + "]+鎵规鍙�2浣�:[" + HBarCodeBatchNo  + "];");
+                            return;
+                        }
                     }
                     else if (cmbHBarCodeType.Text == "鍗婃垚鍝佹潯鐮�")
                     {
@@ -828,7 +844,7 @@
                         Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
                                                                                                                     //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                         LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
-                        LSHlen = 4;
+                        LSHlen = 5;
                     }
                     //else if (cmbHBarCodeType.Text == "鎵樼洏鏉$爜")
                     //{
@@ -875,7 +891,17 @@
                             //鏉$爜缂栧彿 = 鏉$爜鍓嶇紑 + 娴佹按鍙�
                             TM = sTMNumber + LSH2;
                         }
+                        else if(cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�" || cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佸鍣ㄨ鍒�" || cmbHBarCodeType.Text == "璇曞墏鎴愬搧鏉$爜瑙勫垯" 
+                            || cmbHBarCodeType.Text == "鍗婃垚鍝佹潯鐮�" || cmbHBarCodeType.Text == "澶栭攢鏈烘潯鐮�")
+                        {
+                            TM = sTMNumber + LSH2;
 
+                        }
+                        else if (cmbHBarCodeType.Text == "鍐呴攢鏈烘潯鐮�")
+                        {
+                            TM = sTMNumber + LSH2 + "0";
+                        }
+                        //
                         if (i + 1 > grdSub.Rows.Count)
                         {
                             grdSub.RowCount = grdSub.RowCount + 1;
@@ -887,6 +913,7 @@
                             return;
                         }
                         grdSub.Rows[i].Cells[HTMCol].Value = TM;
+                        grdSub.Rows[i].Cells[HEntryID2Col].Value = j + 1;
                         grdSub.Rows[i].Cells[HMaterID2Col].Value = grdMain.Rows[j].Cells[HMaterIDCol].Value;
                         grdSub.Rows[i].Cells[HMaterNumber2Col].Value = grdMain.Rows[j].Cells[HMaterNumberCol].Value;
                         grdSub.Rows[i].Cells[HMaterName2Col].Value = grdMain.Rows[j].Cells[HMaterNameCol].Value;
@@ -984,6 +1011,7 @@
             string HSeOrderBillNo = "";
             string HInnerBillNo = "";
             bool HGiveAwayFlag = false;
+            Int64 HEntryID = 0;
             try
             {
                 oCn.BeginTran();
@@ -1001,6 +1029,7 @@
                         }
                         //
                         HMaterID = ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value);
+                        HEntryID = ClsPub.isLong(grdSub.Rows[i].Cells[HEntryID2Col].Value);
                         HAuxPropID = ClsPub.isLong(grdSub.Rows[i].Cells[HAuxPropID2Col].Value);
                         HUnitID = ClsPub.isLong(grdSub.Rows[i].Cells[HUnitID2Col].Value);
                         HQty2 = ClsPub.isDoule(grdSub.Rows[i].Cells[HQty2Col].Value);
@@ -1032,7 +1061,7 @@
                                     ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                     ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                     ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " +
-                                    ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID " +
+                                    ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                     ",HGiveAwayFlag " +
                                     ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
                                     ") values ("
@@ -1041,7 +1070,7 @@
                                     + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HWei + "'"
                                     + ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
                                     + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + sDate + "'"
-                                    + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString()
+                                    + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString() + "," + HEntryID.ToString() + ""
                                     + ", " + DBUtility.ClsPub.BoolToString(HGiveAwayFlag)
                                     + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')");
 
@@ -1091,29 +1120,30 @@
             }
         }
 
-        //鏈堜唤杞寲
-        private string Sub_PeriodChange(string sPeriod)
-        {
-            if(sPeriod=="10")
-            {
-                return "A";
-            }
-            else if (sPeriod == "11")
-            {
-                return "B";
-            }
-            else if (sPeriod == "12")
-            {
-                return "C";
-            }
-            else
-            {
-                return sPeriod.Substring(2, 1);
-            }
-        }
+        ////鏈堜唤杞寲
+        //private string Sub_PeriodChange(string sPeriod)
+        //{
+        //    if(sPeriod=="10")
+        //    {
+        //        return "A";
+        //    }
+        //    else if (sPeriod == "11")
+        //    {
+        //        return "B";
+        //    }
+        //    else if (sPeriod == "12")
+        //    {
+        //        return "C";
+        //    }
+        //    else
+        //    {
+        //        return sPeriod.Substring(1, 1);
+        //    }
+        //}
 
 
-        //鐢熸垚鏉$爜 鍗氭棩 //鐗╂枡缂栫爜+搴忓垪鍙�+鐢熶骇鏃ユ湡
+        //鐢熸垚鏉$爜 鍗氭棩 
+        //鐗╂枡缂栫爜+搴忓垪鍙�+鐢熶骇鏃ユ湡
         private void SaveBarCode_bori() 
         {
             grdSub.Rows.Clear();
@@ -1127,7 +1157,7 @@
             int HBQty = 0;              //绠辨暟
             double HQty = 0;            //鏁伴噺
             string WeiShu = "";         //灏炬暟
-            int LSH = 0;                //娴佹按鍙�
+            //int LSH = 0;                //娴佹按鍙�
             string LSH2 = "";           //娴佹按鍙疯浆鎹㈡垚瀛楃
             string sDate = "";          //鏃ユ湡
             string sYear = "";          //骞�
@@ -1161,25 +1191,36 @@
                     sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
                     sDay = sDay.Substring(sDay.Length - 2, 2);
                     //==================================
-                    if (cmbHBarCodeType.Text == "鍞竴鏉$爜")
-                    { 
-                        //鏉$爜鍓嶇紑 = 缁勭粐浠g爜 + 鐗╂枡浠g爜 + 骞� + 鏈� + 鏃�
-                        sTMNumber = HOrgNumber + HNumber + sYear + sPeriod + sDay;
-                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
-                        //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
-                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]); 
-                    }
-                    else
-                    {
-                        MessageBox.Show("閿欒鐨勬潯鐮佺被鍨嬶紝涓嶈兘鐢熸垚鏉$爜锛�");
-                        return;
-                    }
+                    //if (cmbHBarCodeType.Text == "璇曞墏鎴愬搧鏉$爜瑙勫垯")
+                    //{ 
+                    //    //鏉$爜鍓嶇紑 = 缁勭粐浠g爜 + 鐗╂枡浠g爜 + 骞� + 鏈� + 鏃�
+                    //sTMNumber = HMaterNumber + HNumber + sYear + sPeriod + sDay;
+                    //    Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
+                    //    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
+                    //    LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]); 
+                    //}
+                    //else
+                    //{
+                    //    MessageBox.Show("閿欒鐨勬潯鐮佺被鍨嬶紝涓嶈兘鐢熸垚鏉$爜锛�");
+                    //    return;
+                    //}
 
                     HBQty = HBQty + ClsPub.isInt(grdMain.Rows[j].Cells[HBQtyCol].Value);
                     HMinQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HMinQtyCol].Value);
                     HSumQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HQtyCol].Value);
                     n = 0;
-                    for (int i = k; i < HBQty; i++)
+                    //浠庨噾铦跺簭鍒楀彿琛ㄨ幏鍙栧簭鍒楀彿
+                    DataSet DSet = oCn.RunProcReturn("exec h_p_CLD_GetBarCodeSno  "+ ClsPub.isStrNull(grdMain.Rows[j].Cells[HMainIDCol].Value) + "," + ClsPub.isStrNull(grdMain.Rows[j].Cells[HSubIDCol].Value) + "  ", "h_p_CLD_GetBarCodeSno", ref DBUtility.ClsPub.sExeReturnInfo);
+                    //鐢熸垚棣栬鏍囬
+                    if (DSet == null)
+                    {
+                        MessageBox.Show("娌℃湁杩斿洖浠讳綍缁撴灉,閲戣澏浜戝簭鍒楀彿涓嶅瓨鍦紒" + DBUtility.ClsPub.sExeReturnInfo);
+                        continue;
+                    }
+                    //
+
+                    for (int i = k; i < DSet.Tables[0].Rows.Count; i++)
+                    //for (int i = k; i < HBQty; i++)
                     {
                         if (HSumQty - HMinQty > 0)
                         {
@@ -1199,17 +1240,18 @@
                             HMinQty = HSumQty;
                         }
                         //
-                        LSH = LSH + 1;
-                        LSH2 = LSH.ToString();
-                        while (LSH2.Length < LSHlen)  //濡傛灉娴佹按鍙峰皬浜�6浣嶆暟鍓嶉潰琛�0
-                        {
-                            LSH2 = "0" + LSH2;
-                        }
-                        if (cmbHBarCodeType.Text == "鍞竴鏉$爜")
-                        {
+                        //LSH = LSH + 1;
+                        LSH2 =DBUtility.ClsPub.isStrNull(DSet.Tables[0].Rows[n]["SHNO"]);
+                        //while (LSH2.Length < LSHlen)  //濡傛灉娴佹按鍙峰皬浜�6浣嶆暟鍓嶉潰琛�0
+                        //{
+                        //    LSH2 = "0" + LSH2;
+                        //}
+                        //if (cmbHBarCodeType.Text == "鍞竴鏉$爜")
+                        //{
                             //鏉$爜缂栧彿 = 鏉$爜鍓嶇紑 + 娴佹按鍙�
-                            TM = sTMNumber + LSH2;
-                        }
+                            //T/*M*/ = HMaterNumber + LSH2 + sYear + sPeriod + sDay;
+                        TM =  LSH2 + sYear + sPeriod + sDay;
+                        //}
 
                         if (i + 1 > grdSub.Rows.Count)
                         {
@@ -1283,7 +1325,7 @@
                         grdSub.Rows[i].Cells[HGiveAwayFlag2Col] = oCell;
                         k = k + 1;
                         n = n + 1;
-                        oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
+                        //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                     }
                 }
             }
@@ -1436,7 +1478,7 @@
             //
             grdMain.RowCount = 0;
             grdSub.RowCount = 0;
-            grdMain.ColumnCount = 61;                       //鎬诲垪鏁�
+            grdMain.ColumnCount = 62;                       //鎬诲垪鏁�
             DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name);
             grdMain.Columns[HSnoCol].HeaderText = "搴忓彿";
             grdMain.Columns[HMainIDCol].HeaderText = "婧愬崟涓籌D";
@@ -1462,6 +1504,7 @@
             grdMain.Columns[HGiveAwayFlagCol].HeaderText = "鏄惁璧犲搧";
             grdMain.Columns[HQtyCol].HeaderText = "鏁伴噺";
             grdMain.Columns[HMinQtyCol].HeaderText = "鏈�灏忓寘瑁呮暟";
+            grdMain.Columns[HPackQtyCol].HeaderText = "澶栫鏁�";
             grdMain.Columns[HBQtyCol].HeaderText = "绠辨暟";
             grdMain.Columns[HSupIDCol].HeaderText = "渚涘簲鍟咺D";
             grdMain.Columns[HSupNumberCol].HeaderText = "渚涘簲鍟嗕唬鐮�";
@@ -1548,6 +1591,7 @@
                                 "," + HSeOrderBillNoCol.ToString() +
                                 "," + HBatchNoCol.ToString() +
                                 "," + HCusNumberCol.ToString() +
+                                "," + HPackQtyCol.ToString() +
                                 "," + HRemarkCol.ToString();
             //璁剧疆鍚堣鍒�
             string sTotalCol = HQtyCol.ToString();
@@ -1567,7 +1611,7 @@
             DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol,oSumGrid);
             //----------------------------
 
-            grdSub.ColumnCount = 58;                       //鎬诲垪鏁�
+            grdSub.ColumnCount = 59;                       //鎬诲垪鏁�
             DBUtility.Xt_BaseBillFun.initGridFst(grdSub, this.Name);
             grdSub.Columns[HSelectCol].HeaderText = "閫夋嫨";
             grdSub.Columns[HTMCol].HeaderText = "鏉$爜缂栧彿";
@@ -1625,6 +1669,7 @@
             grdSub.Columns[HShowDate2Col].HeaderText = "鏃ユ湡";
             grdSub.Columns[HInnerBillNo2Col].HeaderText = "鍐呴儴閲囪喘璁㈠崟鍙�";
             grdSub.Columns[HMaker2Col].HeaderText = "鍒跺崟浜�";
+            grdSub.Columns[HEntryID2Col].HeaderText = "琛屽彿";
             //鏍煎紡鍖� 
             grdSub.Columns[HMaterID2Col].Visible = false;
             grdSub.Columns[HModel2Col].Visible = false;
@@ -2289,6 +2334,7 @@
             grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
             grdMain.Rows[i].Cells[HSubIDCol].Value = oTable.Rows[0]["hsubid"].ToString();
             grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["鍗曟嵁鍙�"].ToString();
+            grdMain.Rows[i].Cells[HSourceBillNoCol].Value = oTable.Rows[0]["鍗曟嵁鍙�"].ToString();
             grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
             grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["鏃ユ湡"].ToString(); //鍗氭棩 鏀舵枡鍗曟嵁鏃ユ湡
             grdMain.Rows[i].Cells[HShowDateCol].Value = dtpHDate.Value.ToShortDateString();
@@ -2313,15 +2359,19 @@
             grdMain.Rows[i].Cells[HCusNumberCol].Value = oTable.Rows[0]["瀹㈡埛浠g爜"].ToString();
             grdMain.Rows[i].Cells[HCusNameCol].Value = oTable.Rows[0]["瀹㈡埛"].ToString();
             grdMain.Rows[i].Cells[HCusTypeCol].Value = oTable.Rows[0]["瀹㈡埛鍨嬪彿"].ToString();
+            grdMain.Rows[i].Cells[HPinfanBarCodeCol].Value = oTable.Rows[0]["HPinfanBarCode"].ToString();
+            grdMain.Rows[i].Cells[HPinfanCol].Value = oTable.Rows[0]["HPinfan"].ToString();
             //grdMain.Rows[i].Cells[HSourceIDCol].Value = oTable.Rows[0]["HSourceID"].ToString();
             //grdMain.Rows[i].Cells[HSourceNumberCol].Value = oTable.Rows[0]["鐢熶骇绾夸唬鐮�"].ToString();
             grdMain.Rows[i].Cells[HSourceNameCol].Value = oTable.Rows[0]["鐢熶骇绾�"].ToString();
             grdMain.Rows[i].Cells[HEndDateCol].Value = oTable.Rows[0]["璁″垝瀹屽伐鏃ユ湡"].ToString();//鍗氭棩 鐢熶骇璁㈠崟 澶辨晥鏃ユ湡
-            if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佸鍣ㄨ鍒�" && CampanyName == "鍗氭棩绉戞妧")
+            if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佸鍣ㄨ鍒�" )
             {
                 grdMain.Rows[i].Cells[HMinQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["鏈敓鎴愭潯鐮佹暟閲�"]);
             }
-            else if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�" && CampanyName == "鍗氭棩绉戞妧")
+            else if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�"  
+                || cmbHBarCodeType.Text == "浠櫒鎴愬搧鏉$爜瑙勫垯" 
+                || cmbHBarCodeType.Text == "璇曞墏鎴愬搧鏉$爜瑙勫垯")
             {
                 grdMain.Rows[i].Cells[HMinQtyCol].Value = "1";
             }
@@ -2335,6 +2385,7 @@
                                 "," + HMinQtyCol.ToString() +
                                 "," + HAuxPropNumberCol.ToString() +
                                 "," + HBatchNoCol.ToString() +
+                                "," + HPackQtyCol.ToString() +
                                 "," + HRemarkCol.ToString();
             grdMain.Columns[HBillNoCol].ReadOnly = true;
             //璁剧疆鍚堣鍒�
@@ -2378,9 +2429,13 @@
             grdMain.Rows[i].Cells[HUnitNameCol].Value = oTable.Rows[0]["璁¢噺鍗曚綅"].ToString();
             grdMain.Rows[i].Cells[HRemarkCol].Value = oTable.Rows[0]["澶囨敞"].ToString();
             grdMain.Rows[i].Cells[HMTONoCol].Value = oTable.Rows[0]["璁″垝璺熻釜鍙�"].ToString();
-            if (cmbHBarCodeType.Text == "鎵规鏉$爜" && CampanyName == "鍗氭棩绉戞妧")
+            if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佸鍣ㄨ鍒�")
             {
                 grdMain.Rows[i].Cells[HMinQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["鏈敓鎴愭潯鐮佹暟閲�"]);
+            }
+            else if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�")
+            {
+                grdMain.Rows[i].Cells[HMinQtyCol].Value = "1";
             }
             else
             {
@@ -3163,5 +3218,126 @@
                 Thread.Sleep(1000);
             }
         }
+
+        //鐢熸垚澶栫鐮�
+        private void wxm_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                Int64 iInterID = 0;
+                Int64 dPackQty = 0; //澶栫鏁伴噺
+                Int64 dPackLeftQty = 0; //澶栫鍓╀綑鏁伴噺
+                Int64 dLabelQty = 0; //灏忕鏁伴噺
+                Int64 dQty = 0; //鎬绘暟閲�
+                Int64 dEntryID = 0; //琛屽彿
+                string sPackBarCode = ""; //澶栫鐮�
+                string sBarCode = ""; //鍞竴鐮�
+                Int64 LSH = 0;
+                DataSet Ds;
+                string sYear = DateTime.Today.Year.ToString().Substring(2, 2);
+                string sPeriod = "0" + DateTime.Today.Month.ToString();
+                sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
+                string sDay = "0" + DateTime.Today.Day.ToString();
+                sDay = sDay.Substring(sDay.Length - 2, 2);
+                //
+                string sPackStr = "ZXM" + sYear + sPeriod + sDay; //澶栫鐮� 鍓嶇紑
+
+                //蹇呴』鏉$爜鐢熸垚鎸夐挳鏄伆搴︽墠鍙互鐢熸垚绠辨潯鐮�
+                if (bc.Enabled != false)
+                {
+                    MessageBox.Show("璇峰厛鐢熸垚鏉″舰鐮侊紝鍐嶇敓鎴愮鏉$爜");
+                    return;
+                }
+                //-------------------鏍规嵁HINTERID鐢熸垚绠辨潯鐮�
+                //鐢熸垚鍓嶅垽鏂紝寰幆鐗╂枡缃戞牸锛屽垽鏂� 鏄惁璁剧疆浜嗗悎鐞嗙殑 澶栫鏁伴噺銆� 澶栫鏁伴噺 蹇呴』鏄� 鏈�灏忓寘瑁呮暟鐨� 鍊嶆暟 骞跺繀椤诲ぇ浜�0鍜屽ぇ浜庣瓑浜庢渶灏忓寘瑁呮暟閲忋��
+                for (int i = 0; i < grdMain.Rows.Count; i++)
+                {
+                    if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value) != 0)
+                    {
+                        if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value) <= 0)
+                        {
+                            MessageBox.Show("璇峰綍鍏ュ悎鐞嗙殑澶栫鏁伴噺锛岀" + Convert.ToString(i + 1) + "琛�");
+                            return;
+                        }
+                        if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value)
+                            % DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMinQtyCol].Value) != 0
+                            || DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value)
+                            < DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMinQtyCol].Value))
+                        {
+                            MessageBox.Show("澶栫鏁伴噺蹇呴』鏄渶灏忓寘瑁呮暟鐨勫�嶆暟锛屼笖澶т簬绛変簬鏈�灏忓寘瑁呮暟锛岀" + Convert.ToString(i + 1) + "琛�");
+                            return;
+                        }
+                    }
+                }
+                //oCn.BeginTran();
+                //浠�0琛岃繘琛屽惊鐜� 鐗╂枡缃戞牸锛岃幏鍙栧绠辨暟閲�
+                for (int i = 0; i < grdMain.Rows.Count; i++)
+                {
+                    if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value) != 0)
+                    {
+                        //鑾峰彇鎬绘暟閲忋�佸绠辨暟閲� 
+                        dPackQty = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value);
+                        dQty = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HQtyCol].Value);
+                        dEntryID = i + 1;
+                        dPackLeftQty = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value);
+                        //鐢熸垚涓�涓绠辩爜
+                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sPackStr + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿                                                                                          //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
+                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]) + 1;
+                        sPackBarCode = sPackStr + LSH.ToString();
+                        oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sPackStr + "'");
+                        //瀛愬惊鐜� 鏉$爜缃戞牸
+                        for (int j = 0; j < grdSub.Rows.Count; j++)
+                        {
+                            if (dEntryID == DBUtility.ClsPub.isLong(grdSub.Rows[j].Cells[HEntryID2Col].Value))
+                            {
+                                if (dQty <= 0)
+                                {
+                                    continue;
+                                }
+                                if (dPackLeftQty > 0) //褰撳墿浣欏绠辨暟閲忓皬浜庣瓑浜�0鏃讹紝閲嶆柊鐢熸垚澶栫鐮�
+                                {
+                                }
+                                else
+                                {
+                                    //鐢熸垚涓�涓绠辩爜
+                                    Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sPackStr + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿                                                                                          //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
+                                    LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]) + 1;
+                                    sPackBarCode = sPackStr + LSH.ToString();
+                                    oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sPackStr + "'");
+                                    dPackLeftQty = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HPackQtyCol].Value);
+                                }
+                                sBarCode = DBUtility.ClsPub.isStrNull(grdSub.Rows[j].Cells[HTMCol].Value); // 鏉$爜
+                                dLabelQty = DBUtility.ClsPub.isLong(grdSub.Rows[j].Cells[HQty2Col].Value); // 灏忕鏁伴噺
+                                oCn.RunProc("update Gy_BarCodebill set HInnerBillNo= '" + sPackBarCode + "' Where HbarCode='" + sBarCode + "'");
+                                dPackLeftQty = dPackLeftQty - dLabelQty;
+                                dQty = dQty - dLabelQty;
+                                if (dPackLeftQty <= 0)//褰撶鍓╀綑鏁伴噺灏忎簬绛変簬0鏃� 鎵ц 缁勬墭鍗�
+                                {
+                                    //鑾峰彇缁勬墭鍗曞唴鐮�
+                                    iInterID = DBUtility.ClsPub.CreateBillID("3783", ref DBUtility.ClsPub.sExeReturnInfo); ;//寰楀埌鏂板崟鍙�; 
+                                                                                                                            //鏍规嵁澶栫鐮� 鍐欏叆 缁勬墭鍗曚富琛紝缁勬墭鍗曞瓙琛紝SUM锛屽绠辩爜妗f锛孲UM妗f
+                                    oCn.RunProc("exec  h_p_WMS_PackUnionBill_AddNew  '" + sPackBarCode + "'," + iInterID.ToString() + ",'" + DBUtility.ClsPub.CurUserName + "'," + HInterID.ToString()); //鏍规嵁绠辨潯鐮侊紝鍐欏叆 涓昏〃锛屽瓙琛� 锛岀鏉$爜妗f 
+                                    oCn.RunProc("exec  h_p_WMS_PackUnionBill_SumSubBill  " + iInterID.ToString() + ",'" + sPackBarCode + "','3783','" + DBUtility.ClsPub.CurUserName + "'," + HInterID.ToString()); //鏍规嵁绠辨潯鐮侊紝鍐欏叆 SUM琛紝SUM鏉$爜妗f
+                                }
+                            }
+                            else
+                            {
+                                continue;
+                            }
+                        }
+                    }
+                }
+                wxm.Enabled = false;
+                //oCn.Commit();
+                MessageBox.Show("鐢熸垚绠辩爜瀹屾瘯锛�");
+                //鍒锋柊鏁版嵁
+                Display();
+            }
+            catch(Exception e1)
+            {
+                //oCn.RollBack();
+                MessageBox.Show("鐢熸垚绠辩爜澶辫触锛�" + e1.Message );
+            }
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1