From 7f8ed8cdc49b33178f34c91edf862f831cd30c9c Mon Sep 17 00:00:00 2001
From: yusijie <ysj@hz-kingdee.com>
Date: 星期三, 08 二月 2023 09:18:04 +0800
Subject: [PATCH] 供应商物料;根据登录用户获取默认值

---
 WarM/条码打印/Gy_BarCodeBill.cs | 1306 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 1,168 insertions(+), 138 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 580f92b..92c9009 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"
@@ -27,8 +27,8 @@
         public const Int16 HMaterIDCol = 6;
         public const Int16 HMaterNumberCol = 7;
         public const Int16 HMaterNameCol = 8;
-        public const Int16 HPinfanCol = 9;
-        public const Int16 HMaterModelCol = 10;
+        public const Int16 HPinfanCol = 9;//
+        public const Int16 HMaterModelCol = 10;//
         public const Int16 HModelCol = 11;
         public const Int16 HAuxPropIDCol = 12;
         public const Int16 HAuxPropNumberCol = 13;
@@ -39,45 +39,48 @@
         public const Int16 HBarCodeTypeCol = 18;
         public const Int16 HBatchManagerCol = 19;
         public const Int16 HBatchNoCol = 20;
-        public const Int16 HQtyCol = 21;
-        public const Int16 HMinQtyCol = 22;
-        public const Int16 HBQtyCol = 23;
-        public const Int16 HDeptIDCol = 24;
-        public const Int16 HDeptNumberCol = 25;
-        public const Int16 HDeptNameCol = 26;
-        public const Int16 HSourceIDCol = 27;
-        public const Int16 HSourceNumberCol = 28;
-        public const Int16 HSourceNameCol = 29;
-        public const Int16 HDateCol = 30;
-        public const Int16 HEndDateCol = 31;
-        public const Int16 HSupIDCol = 32;
-        public const Int16 HSupNumberCol = 33;
-        public const Int16 HSupNameCol = 34;
-        public const Int16 HCusIDCol = 35;
-        public const Int16 HCusNumberCol = 36;
-        public const Int16 HCusNameCol = 37;
-        public const Int16 HCusTypeCol = 38;
-        public const Int16 HSourceInterIDCol = 39;
-        public const Int16 HSourceEntryIDCol = 40;
-        public const Int16 HSourceBillNoCol = 41;
-        public const Int16 HSourceBillTypeCol = 42;
-        public const Int16 HInstructIDCol = 43;
-        public const Int16 HInstructNoCol = 44;
-        public const Int16 HSeOrderBillIDCol = 45;
-        public const Int16 HSeOrderBillNoCol = 46;
-        public const Int16 HWhIDCol = 47;
-        public const Int16 HWhNumberCol = 48;
-        public const Int16 HWhNameCol = 49;
-        public const Int16 HSPIDCol = 50;
-        public const Int16 HSPNumberCol = 51;
-        public const Int16 HSPNameCol = 52;
-        public const Int16 HinitQtyCol = 53;
-        public const Int16 HRemarkCol = 54;
-        public const Int16 HPinfanBarCodeCol = 55;
-        public const Int16 HMTONoCol = 56;
-        public const Int16 HShowDateCol = 57;
-        public const Int16 HInnerBillNoCol = 58;
-        public const Int16 HMakerCol = 59;
+        public const Int16 HGiveAwayFlagCol = 21;
+        public const Int16 HQtyCol = 22;
+        public const Int16 HMinQtyCol = 23;
+        public const Int16 HBQtyCol = 24;
+        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 HSeOrderSEQCol = 49;
+        public const Int16 HWhIDCol = 50;
+        public const Int16 HWhNumberCol = 51;
+        public const Int16 HWhNameCol = 52;
+        public const Int16 HSPIDCol = 53;
+        public const Int16 HSPNumberCol = 54;
+        public const Int16 HSPNameCol = 55;
+        public const Int16 HinitQtyCol = 56;
+        public const Int16 HRemarkCol = 57;
+        public const Int16 HPinfanBarCodeCol = 58;
+        public const Int16 HMTONoCol = 59;
+        public const Int16 HShowDateCol = 60;
+        public const Int16 HInnerBillNoCol = 61;
+        public const Int16 HMakerCol = 62;
 
         public Int16 HSelectCol = 0;
         public Int16 HSno2Col = 1;
@@ -93,49 +96,52 @@
         public Int16 HAuxPropNumber2Col = 11;
         public Int16 HAuxPropName2Col = 12;
         public Int16 HBatchNo2Col = 13;
-        public Int16 HUnitID2Col = 14;
-        public Int16 HUnitNumber2Col = 15;
-        public Int16 HUnitName2Col = 16;
-        public Int16 HQty2Col = 17;
-        public Int16 HWeiCol = 18;
-        public Int16 HPrintCol = 19;
-        public Int16 HDeptID2Col = 20;
-        public Int16 HDeptNumber2Col = 21;
-        public Int16 HDeptName2Col = 22;
-        public Int16 HSourceID2Col = 23;
-        public Int16 HSourceNumber2Col = 24;
-        public Int16 HSourceName2Col = 25;
-        public Int16 HDate2Col = 26;
-        public Int16 HEndDate2Col = 27;
-        public Int16 HBarcodeNoCol = 28;
-        public Int16 HBarcodeQtysCol = 29;
-        public Int16 HSupID2Col = 30;
-        public Int16 HSupNumber2Col = 31;
-        public Int16 HSupName2Col = 32;
-        public Int16 HCusID2Col = 33;
-        public Int16 HCusNumber2Col = 34;
-        public Int16 HCusName2Col = 35;
-        public Int16 HCusType2Col = 36;
-        public Int16 HSourceInterID2Col = 37;
-        public Int16 HSourceEntryID2Col = 38;
-        public Int16 HSourceBillNo2Col = 39;
-        public Int16 HSourceBillType2Col = 40;
-        public Int16 HInstructID2Col = 41;
-        public Int16 HInstructNo2Col = 42;
-        public Int16 HSeOrderBillID2Col = 43;
-        public Int16 HSeOrderBillNo2Col = 44;
-        public Int16 HWhID2Col = 45;
-        public Int16 HWhNumber2Col = 46;
-        public Int16 HWhName2Col = 47;
-        public Int16 HSPID2Col = 48;
-        public Int16 HSPNumber2Col = 49;
-        public Int16 HSPName2Col = 50;
-        public Int16 HRemark2Col = 51;
-        public Int16 HPinfanBarCode2Col = 52;
-        public Int16 HMTONo2Col = 53;
-        public Int16 HShowDate2Col = 54;
-        public Int16 HInnerBillNo2Col = 55; 
-        public Int16 HMaker2Col = 56; 
+        public Int16 HGiveAwayFlag2Col = 14;
+        public Int16 HUnitID2Col = 15;
+        public Int16 HUnitNumber2Col = 16;
+        public Int16 HUnitName2Col = 17;
+        public Int16 HQty2Col = 18;
+        public Int16 HWeiCol = 19;
+        public Int16 HPrintCol = 20;
+        public Int16 HDeptID2Col = 21;
+        public Int16 HDeptNumber2Col = 22;
+        public Int16 HDeptName2Col = 23;
+        public Int16 HSourceID2Col = 24;
+        public Int16 HSourceNumber2Col = 25;
+        public Int16 HSourceName2Col = 26;
+        public Int16 HDate2Col = 27;
+        public Int16 HEndDate2Col = 28;
+        public Int16 HBarcodeNoCol = 29;
+        public Int16 HBarcodeQtysCol = 30;
+        public Int16 HSupID2Col = 31;
+        public Int16 HSupNumber2Col = 32;
+        public Int16 HSupName2Col = 33;
+        public Int16 HCusID2Col = 34;
+        public Int16 HCusNumber2Col = 35;
+        public Int16 HCusName2Col = 36;
+        public Int16 HCusType2Col = 37;
+        public Int16 HSourceInterID2Col = 38;
+        public Int16 HSourceEntryID2Col = 39;
+        public Int16 HSourceBillNo2Col = 40;
+        public Int16 HSourceBillType2Col = 41;
+        public Int16 HInstructID2Col = 42;
+        public Int16 HInstructNo2Col = 43;
+        public Int16 HSeOrderBillID2Col = 44;
+        public Int16 HSeOrderBillNo2Col = 45;
+        public Int16 HSeOrderSEQ2Col = 46;
+        public Int16 HWhID2Col = 47;
+        public Int16 HWhNumber2Col = 48;
+        public Int16 HWhName2Col = 49;
+        public Int16 HSPID2Col = 50;
+        public Int16 HSPNumber2Col = 51;
+        public Int16 HSPName2Col = 52;
+        public Int16 HRemark2Col = 53;
+        public Int16 HPinfanBarCode2Col = 54;
+        public Int16 HMTONo2Col = 55;
+        public Int16 HShowDate2Col = 56;
+        public Int16 HInnerBillNo2Col = 57; 
+        public Int16 HMaker2Col = 58;
+        public Int16 HEntryID2Col = 59;
         //
         public  string ModName = "85";
         public  string ModCaption = "鏉$爜鐢熸垚";
@@ -159,7 +165,10 @@
         public string ERPMode = ""; //ERP妯″紡锛圵ISE銆丆LOUD锛�
         public string CampanyName = ""; //瀹㈡埛瀹氬埗鍖栧悕绉�
         public string SourceQtyCtl = ""; //瓒呮簮鍗曟暟閲忔帶鍒�
-                                         //-------------------------------------------------------------------------
+        public long PrintQty = 0;               //鍏佽鏉$爜鎵撳嵃娆℃暟
+        public string PrintQtyCtl = "";         //鏉$爜鎵撳嵃娆℃暟鎺у埗
+        public string UpdatePrintQtyCtl = "";   //鏉$爜鎵撳嵃娆℃暟鏇存柊
+                                                //-------------------------------------------------------------------------
         #region 鍥哄畾浠g爜
 
         //娓呯┖鐣岄潰
@@ -171,16 +180,39 @@
             cmbHBarCodeType.Items.Clear();
             cmbSourceBillType.Items.Clear();
 
-            cmbHBarCodeType.Items.Add("鍞竴鏉$爜");
-            cmbHBarCodeType.Items.Add("鍝佺鏉$爜");
-            cmbHBarCodeType.Items.Add("鎵规鏉$爜");
-            //cmbHBarCodeType.Items.Add("鎵樼洏鏉$爜");
+            //鏍规嵁绯荤粺鍙傛暟鑾峰彇瀵瑰簲鐨勬潯鐮佺被鍨嬶紙澶忓疂鐢靛櫒銆佸崥鏃�   浠ュ悗浣跨敤鏉$爜瑙勫垯琛級
+            ClsXt_SystemParameter oClsXt_SystemParameter = new ClsXt_SystemParameter();
+            string sCapName = oClsXt_SystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
+            if(sCapName=="澶忓疂鐢靛櫒")
+            { 
+                cmbHBarCodeType.Items.Add("鍐呴攢鏈烘潯鐮�");
+                cmbHBarCodeType.Items.Add("澶栭攢鏈烘潯鐮�");
+                cmbHBarCodeType.Items.Add("鍗婃垚鍝佹潯鐮�"); 
+            }
+            else if (sCapName == "鍗氭棩绉戞妧")
+            {
+                cmbHBarCodeType.Items.Add("浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�");
+                cmbHBarCodeType.Items.Add("浠櫒澶栬喘浠舵潯鐮佸鍣ㄨ鍒�");
+                cmbHBarCodeType.Items.Add("浠櫒鎴愬搧鏉$爜瑙勫垯");
+                cmbHBarCodeType.Items.Add("璇曞墏鎴愬搧鏉$爜瑙勫垯");
+            }
+            else
+            {
+                //
+                cmbHBarCodeType.Items.Add("鍞竴鏉$爜");
+                cmbHBarCodeType.Items.Add("鍝佺鏉$爜");
+                cmbHBarCodeType.Items.Add("鎵规鏉$爜");
+                //cmbHBarCodeType.Items.Add("鎵樼洏鏉$爜");
+            }
+
             //
             cmbSourceBillType.Items.Add("鐢熶骇璁㈠崟");
             cmbSourceBillType.Items.Add("鐢熶骇姹囨姤鍗�");
             cmbSourceBillType.Items.Add("閲囪喘璁㈠崟");
             cmbSourceBillType.Items.Add("鏀舵枡閫氱煡鍗�");
             cmbSourceBillType.Items.Add("濮斿璁㈠崟");
+            cmbSourceBillType.Items.Add("宸ュ簭姹囨姤鍗�");
+            cmbSourceBillType.Items.Add("宸ュ簭娴佽浆鍗�");
             cmbSourceBillType.Items.Add("閫�璐ч�氱煡鍗�");
             cmbSourceBillType.Items.Add("鍏朵粬鍏ュ簱鍗�");
             cmbSourceBillType.Items.Add("鐩存帴璋冩嫧鍗�");
@@ -243,6 +275,7 @@
         {
             this.Sub_SaveBill();
             Display();
+            
         }
 
         //閲嶇疆鎸夌航
@@ -377,6 +410,9 @@
                 ERPMode = oSystemParameter.omodel.WMS_WMSStockCtl_ERPMode;
                 CampanyName = oSystemParameter.omodel.WMS_CampanyName;
                 SourceQtyCtl = oSystemParameter.omodel.BarCode_SourceQtyCtl;
+                PrintQty = oSystemParameter.omodel.BarCode_PrintQty;
+                PrintQtyCtl = oSystemParameter.omodel.BarCode_PrintQtyCtl;
+                UpdatePrintQtyCtl = oSystemParameter.omodel.BarCode_UpdatePrintQtyCtl;
             }
 
             cmbHWorksNumber.Items.Clear();
@@ -629,7 +665,14 @@
                 return false;
             }
             bc.Enabled = false;
-            SaveBarCode();
+            if (cmbHBarCodeType.Text == "浠櫒鎴愬搧鏉$爜瑙勫垯")
+            {
+                SaveBarCode_bori(); //鐗╂枡缂栫爜+搴忓垪鍙�+鐢熶骇鏃ユ湡
+            }
+            else
+            {
+                SaveBarCode();
+            }
             return true;
         }
 
@@ -640,21 +683,27 @@
             int LSHlen = 6;             //娴佹按鍙烽暱搴�
             int SumLen = 10;            //鎬婚暱搴�
             string TM = "";             //鏉$爜
-            string HNumber = "";        //鐗╂枡浠g爜
+            string HNumber = "";        //鐗╂枡鍐呯爜
+            string HMaterNumber = "";   //鐗╂枡浠g爜
             double HSumQty = 0;         //浜у搧鏁伴噺
             double HMinQty = 0;         //鏈�灏忓寘瑁呮暟
-            int HBQty = 0;              //绠辨暟
+            Int64 HBQty = 0;              //绠辨暟
             double HQty = 0;            //鏁伴噺
             string WeiShu = "";         //灏炬暟
-            int LSH = 0;                //娴佹按鍙�
+            Int64 LSH = 0;                //娴佹按鍙�
             string LSH2 = "";           //娴佹按鍙疯浆鎹㈡垚瀛楃
             string sDate = "";          //鏃ユ湡
             string sYear = "";          //骞�
             string sPeriod = "";        //鏈�
             string sDay = "";           //鏃�
             string HBatchNo = "";       //鎵规
+            string HYasuoji = "";       //鍘嬬缉鏈�
+            string HModelName = "";       //鏈哄瀷
+            string HICMOBillNo = "";       //婧愬崟鍙�
+            string HBarCodeBatchNo = "";       //鏉$爜鎵规鍙�
+            string HBarCodeDate = "";         //鏉$爜鏃ユ湡
             int k = 0;
-            int n = 0;                  //鍚屼竴鎵圭敓鎴愭潯鐮佷腑鐨勭鍑犳潯
+            Int64 n = 0;                  //鍚屼竴鎵圭敓鎴愭潯鐮佷腑鐨勭鍑犳潯
             string sTMNumber = "";      //鏉$爜鑷畾涔夊墠缂�
             DataSet Ds;
             //Ds = oCn.RunProcReturn("exec GetLSH '" + ClsPub.GetServerDate(0) + "'", "GetLSH");
@@ -664,8 +713,29 @@
                 if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0)
                 {
                     HNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterIDCol].Value);
+                    HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterNumberCol].Value);
                     HBatchNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value);
+                    //鏃ユ湡鑾峰彇鏂瑰紡
                     sDate = dtpHDate.Value.ToShortDateString();
+                    //
+                    if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�" || cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佸鍣ㄨ鍒�") //鍗曟嵁鏃ユ湡(鏀舵枡閫氱煡鍗�)
+                    {
+                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HDateCol].Value);
+                    }
+                    else if (cmbHBarCodeType.Text == "璇曞墏鎴愬搧鏉$爜瑙勫垯")// 澶辨晥鏃ユ湡锛堢敓浜ц鍗曪級
+                    {
+                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HEndDateCol].Value);
+                    }
+                    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[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();
                     sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
@@ -680,7 +750,7 @@
                             sTMNumber = 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]);
+                            LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                         }
                         else if (CampanyName == "椋為緳")
                         {
@@ -695,7 +765,7 @@
                             sTMNumber = HWorksNumber + 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]);
+                            LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                         }
                         else  //閫氱敤鏂规硶
                         {
@@ -703,7 +773,7 @@
                             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]);
+                            LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                         }
                     }
                     else if (cmbHBarCodeType.Text == "鍝佺鏉$爜")
@@ -720,6 +790,80 @@
                     else if (cmbHBarCodeType.Text == "鎵规鏉$爜")
                     {
                         TM = HOrgNumber + HNumber + HBatchNo;
+                    }//鍗氭棩鐗规畩澶勭悊
+                    else if (cmbHBarCodeType.Text == "搴忓垪鐮�")
+                    {
+                        //鏉$爜瑙勫垯锛� GX+鐗╂枡鍐呯爜+骞村勾鏈堟湀鏃ユ棩+5浣嶆祦姘村彿
+                        LSHlen = 5;
+                        //鏉$爜鍓嶇紑 = GX+鐗╂枡鍐呯爜+骞村勾鏈堟湀鏃ユ棩
+                        sTMNumber = "GX" + HNumber + sYear + sPeriod + sDay;
+                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
+                        LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
+                    }
+                    else if(cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�" || cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佸鍣ㄨ鍒�")
+                    {
+                        //鐗╂枡缂栫爜+鍗曟嵁鏃ユ湡锛圷YMMDD锛�+娴佹按4浣� 
+                        sTMNumber = HMaterNumber + 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.isLong(Ds.Tables[0].Rows[0][0]);
+                        LSHlen = 4;
+                    }
+                    else if (cmbHBarCodeType.Text == "浠櫒鎴愬搧鏉$爜瑙勫垯") //鍙﹀澶勭悊浜�
+                    {
+                        //鐗╂枡缂栫爜+搴忓垪鍙�+鐢熶骇鏃ユ湡
+                        //sTMNumber = HMaterNumber + 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.isLong(Ds.Tables[0].Rows[0][0]);
+                    }
+                    else if (cmbHBarCodeType.Text == "璇曞墏鎴愬搧鏉$爜瑙勫垯")
+                    {
+                        //鐗╂枡缂栫爜+鐢熶骇鎵瑰彿+娴佹按鍙�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.isLong(Ds.Tables[0].Rows[0][0]);
+                        LSHlen = 6;
+                    }
+                    else if (cmbHBarCodeType.Text == "鍐呴攢鏈烘潯鐮�")
+                    {
+                        //鍒堕�犳湰閮�1浣嶏紙榛樿1锛�+鏈哄瀷浠g爜5浣嶏紙锛�+骞�2浣�+鏈�1浣嶏紙A銆丅銆丆浠f浛10鏈堜唤锛�
+                        //+鏃�2浣�+鏉$爜鎵规鐮�2浣�+鍘嬬缉鏈轰唬鐮�1浣�+00+娴佹按鍙�4浣�+鏍¢獙鐮侊紙榛樿0锛�
+                        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.isLong(Ds.Tables[0].Rows[0][0]);
+                        LSHlen = 4;
+                        if (sTMNumber.Length != 16 && sTMNumber.Length != 15)
+                        {
+                            MessageBox.Show("鏉$爜闀垮害涓嶅15鎴�16浣嶏紝鏄惁鏁版嵁涓嶅叏锛佸埗閫犳湰閮�1浣�:[0] + 鏈哄瀷浠g爜5浣�:[" + HModelName + "] + 骞存湀鏃�4鎴�5浣�:["+ HBarCodeDate + "] + 鎵规鍙�2浣�:[" + HBarCodeBatchNo  + "]+ 鍘嬬缉鏈�1浣�:["+ HYasuoji + "]+00 ; ");
+                            return;
+                        }
+                    }
+                    else if (cmbHBarCodeType.Text == "澶栭攢鏈烘潯鐮�")
+                    {
+                        //鐗╂枡浠g爜11浣�+骞�2浣�+鏈�1浣嶏紙A銆丅銆丆浠f浛10鏈堜唤锛�+鏃�2浣�+鎵规2浣�+娴佹按鍙�4浣�
+                        //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.isLong(Ds.Tables[0].Rows[0][0]);
+                        LSHlen = 4;
+                        if (sTMNumber.Length != 18 && sTMNumber.Length != 17)
+                        {
+                            MessageBox.Show("鏉$爜闀垮害涓嶅17鎴�18浣嶏紝鏄惁鏁版嵁涓嶅叏锛佺墿鏂欎唬鐮�11浣�:["+ HMaterNumber.Replace(".", "") + "]+骞存湀鏃�4鎴�5浣�:["+ HBarCodeDate + "]+鎵规鍙�2浣�:[" + HBarCodeBatchNo  + "];");
+                            return;
+                        }
+                    }
+                    else if (cmbHBarCodeType.Text == "鍗婃垚鍝佹潯鐮�")
+                    {
+                        //鐢熶骇璁㈠崟鍙�+4浣嶆祦姘村彿
+                        sTMNumber = HICMOBillNo;
+                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
+                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
+                        LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
+                        LSHlen = 5;
                     }
                     //else if (cmbHBarCodeType.Text == "鎵樼洏鏉$爜")
                     //{
@@ -731,10 +875,11 @@
                         return;
                     }
 
-                    HBQty = HBQty + ClsPub.isInt(grdMain.Rows[j].Cells[HBQtyCol].Value);
+                    HBQty = HBQty + ClsPub.isLong(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;
+                    int nn = 0;
                     for (int i = k; i < HBQty; i++)
                     {
                         if (HSumQty - HMinQty > 0)
@@ -766,6 +911,378 @@
                             //鏉$爜缂栧彿 = 鏉$爜鍓嶇紑 + 娴佹按鍙�
                             TM = sTMNumber + LSH2;
                         }
+                        else if (cmbHBarCodeType.Text == "搴忓垪鐮�")
+                        {
+                            //鏉$爜缂栧彿 = 鏉$爜鍓嶇紑 + 娴佹按鍙�
+                            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;
+                        }
+                        grdSub.Rows[i].Cells[HSno2Col].Value = ClsPub.isStrNull(i + 1);
+                        if (TM.Trim() == "")
+                        {
+                            MessageBox.Show("鏉″舰鐮佷笉鑳戒负绌猴紝涓嶈兘鐢熸垚鏉$爜锛�");
+                            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;
+                        grdSub.Rows[i].Cells[HMaterModel2Col].Value = grdMain.Rows[j].Cells[HMaterModelCol].Value;
+                        grdSub.Rows[i].Cells[HPinfan2Col].Value = grdMain.Rows[j].Cells[HPinfanCol].Value;
+                        grdSub.Rows[i].Cells[HPinfanBarCode2Col].Value = grdMain.Rows[j].Cells[HPinfanBarCodeCol].Value;
+
+                        grdSub.Rows[i].Cells[HAuxPropID2Col].Value = grdMain.Rows[j].Cells[HAuxPropIDCol].Value;
+                        grdSub.Rows[i].Cells[HAuxPropNumber2Col].Value = grdMain.Rows[j].Cells[HAuxPropNumberCol].Value;
+                        grdSub.Rows[i].Cells[HAuxPropName2Col].Value = grdMain.Rows[j].Cells[HAuxPropNameCol].Value;
+
+                        grdSub.Rows[i].Cells[HUnitID2Col].Value = grdMain.Rows[j].Cells[HUnitIDCol].Value;
+                        grdSub.Rows[i].Cells[HUnitNumber2Col].Value = grdMain.Rows[j].Cells[HUnitNumberCol].Value;
+                        grdSub.Rows[i].Cells[HUnitName2Col].Value = grdMain.Rows[j].Cells[HUnitNameCol].Value;
+
+                        grdSub.Rows[i].Cells[HQty2Col].Value = HMinQty;
+                        grdSub.Rows[i].Cells[HBatchNo2Col].Value = grdMain.Rows[j].Cells[HBatchNoCol].Value;
+                        grdSub.Rows[i].Cells[HSourceInterID2Col].Value = grdMain.Rows[j].Cells[HMainIDCol].Value;
+                        grdSub.Rows[i].Cells[HSourceEntryID2Col].Value = grdMain.Rows[j].Cells[HSubIDCol].Value;
+                        grdSub.Rows[i].Cells[HSourceBillNo2Col].Value = grdMain.Rows[j].Cells[HBillNoCol].Value;
+                        grdSub.Rows[i].Cells[HSourceBillType2Col].Value = grdMain.Rows[j].Cells[HBillTypeCol].Value;
+                        grdSub.Rows[i].Cells[HPrintCol].Value = "0";
+                        grdSub.Rows[i].Cells[HWeiCol].Value = WeiShu;
+                        grdSub.Rows[i].Cells[HBarcodeNoCol].Value = n + 1;
+                        grdSub.Rows[i].Cells[HBarcodeQtysCol].Value = grdMain.Rows[j].Cells[HBQtyCol].Value;
+                        grdSub.Rows[i].Cells[HSupID2Col].Value = grdMain.Rows[j].Cells[HSupIDCol].Value;
+                        grdSub.Rows[i].Cells[HSupNumber2Col].Value = grdMain.Rows[j].Cells[HSupNumberCol].Value;
+                        grdSub.Rows[i].Cells[HSupName2Col].Value = grdMain.Rows[j].Cells[HSupNameCol].Value;
+                        grdSub.Rows[i].Cells[HDeptID2Col].Value = grdMain.Rows[j].Cells[HDeptIDCol].Value;
+                        grdSub.Rows[i].Cells[HDeptNumber2Col].Value = grdMain.Rows[j].Cells[HDeptNumberCol].Value;
+                        grdSub.Rows[i].Cells[HDeptName2Col].Value = grdMain.Rows[j].Cells[HDeptNameCol].Value;
+                        grdSub.Rows[i].Cells[HRemark2Col].Value = grdMain.Rows[j].Cells[HRemarkCol].Value;
+                        grdSub.Rows[i].Cells[HDate2Col].Value = grdMain.Rows[j].Cells[HDateCol].Value;
+                        grdSub.Rows[i].Cells[HShowDate2Col].Value = grdMain.Rows[j].Cells[HShowDateCol].Value;
+                        grdSub.Rows[i].Cells[HWhID2Col].Value = grdMain.Rows[j].Cells[HWhIDCol].Value;
+                        grdSub.Rows[i].Cells[HWhNumber2Col].Value = grdMain.Rows[j].Cells[HWhNumberCol].Value;
+                        grdSub.Rows[i].Cells[HWhName2Col].Value = grdMain.Rows[j].Cells[HWhNameCol].Value;
+                        grdSub.Rows[i].Cells[HSPID2Col].Value = grdMain.Rows[j].Cells[HSPIDCol].Value;
+                        grdSub.Rows[i].Cells[HSPNumber2Col].Value = grdMain.Rows[j].Cells[HSPNumberCol].Value;
+                        grdSub.Rows[i].Cells[HSPName2Col].Value = grdMain.Rows[j].Cells[HSPNameCol].Value;
+                        grdSub.Rows[i].Cells[HMTONo2Col].Value = grdMain.Rows[j].Cells[HMTONoCol].Value;
+                        grdSub.Rows[i].Cells[HCusID2Col].Value = grdMain.Rows[j].Cells[HCusIDCol].Value;
+                        grdSub.Rows[i].Cells[HCusNumber2Col].Value = grdMain.Rows[j].Cells[HCusNumberCol].Value;
+                        grdSub.Rows[i].Cells[HCusName2Col].Value = grdMain.Rows[j].Cells[HCusNameCol].Value;
+                        grdSub.Rows[i].Cells[HCusType2Col].Value = grdMain.Rows[j].Cells[HCusTypeCol].Value;
+                        grdSub.Rows[i].Cells[HSourceID2Col].Value = grdMain.Rows[j].Cells[HSourceIDCol].Value;
+                        grdSub.Rows[i].Cells[HSourceNumber2Col].Value = grdMain.Rows[j].Cells[HSourceNumberCol].Value;
+                        grdSub.Rows[i].Cells[HSourceName2Col].Value = grdMain.Rows[j].Cells[HSourceNameCol].Value;
+                        grdSub.Rows[i].Cells[HEndDate2Col].Value = grdMain.Rows[j].Cells[HEndDateCol].Value;
+                        grdSub.Rows[i].Cells[HSeOrderBillNo2Col].Value = grdMain.Rows[j].Cells[HSeOrderBillNoCol].Value;
+                        grdSub.Rows[i].Cells[HSeOrderSEQ2Col].Value = grdMain.Rows[j].Cells[HSeOrderSEQCol].Value;
+                        grdSub.Rows[i].Cells[HInnerBillNo2Col].Value = grdMain.Rows[j].Cells[HInnerBillNoCol].Value;
+                        grdSub.Rows[i].Cells[HMaker2Col].Value = grdMain.Rows[j].Cells[HMakerCol].Value;
+                        grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value = grdMain.Rows[j].Cells[HGiveAwayFlagCol].Value;
+                        //缃戞牸鎵撳嬀
+                        DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
+                        oCell.ThreeState = false;
+                        oCell.Value = grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value;
+                        oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
+                        grdSub.Rows[i].Cells[HGiveAwayFlag2Col] = oCell;
+                        k = k + 1;
+                        n = n + 1;
+                        //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
+                        nn = nn + 1;
+                    }
+                    //鍚庡彴鎵归噺鎵ц璇彞
+                    oCn.RunProc("exec h_p_WMS_SetMaxNo_QTY '" + sTMNumber + "'," + nn.ToString() + " ");
+                }
+            }
+            string HWei = "";      //灏炬暟
+            string HBarCode = "";
+            string HBarCodeType = "";
+            Int64 HMaterID = 0;
+            Int64 HAuxPropID = 0;
+            Int64 HUnitID = 0;
+            double HQty2 = 0;
+            string HBatchNo2 = "";
+            Int64 HSupID = 0;
+            Int64 HGroupID = 0;
+            int HPrintQty = 0;
+            Int64 HSourceInterID = 0;
+            Int64 HSourceEntryID = 0;
+            string HSourceBillNo = "";
+            string HSourceBillType = "";
+            Int64 HBarcodeNo = 0;       //鎵樺彿
+            Int64 HBarcodeQtys = 0;     //鎬绘墭鏁�
+            Int64 HDeptID = 0;
+            Int64 HWhID = 0;
+            Int64 HSPID = 0;
+            string HRemark = "";
+            string HMaterName = "";
+            string HMaterModel = "";
+            string HPinfan = "";
+            string HMTONo = "";
+            Int64 HCusID = 0;
+            string HCusType = "";
+            DateTime HEndDate;
+            string HWorkLineName = "";
+            string HSeOrderBillNo = "";
+            Int64 HSeOrderSEQ = 0;
+            string HInnerBillNo = "";
+            bool HGiveAwayFlag = false;
+            Int64 HEntryID = 0;
+            try
+            {
+                oCn.BeginTran();
+                for (int i = 0; i < grdSub.Rows.Count; i++)
+                {
+                    if (ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value) != 0)
+                    {
+                        HWei = ClsPub.isStrNull(grdSub.Rows[i].Cells[HWeiCol].Value);
+                        HBarCode = ClsPub.isStrNull(grdSub.Rows[i].Cells[HTMCol].Value);
+                        //
+                        HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
+                        if (CampanyName == "鍗氭棩绉戞妧" || CampanyName == "澶忓疂鐢靛櫒")
+                        {
+                            HBarCodeType = "鍞竴鏉$爜";
+                        }
+                        //
+                        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);
+                        HBatchNo2 = ClsPub.isStrNull(grdSub.Rows[i].Cells[HBatchNo2Col].Value);
+                        HSourceInterID = ClsPub.isLong(grdSub.Rows[i].Cells[HSourceInterID2Col].Value);
+                        HSourceEntryID = ClsPub.isLong(grdSub.Rows[i].Cells[HSourceEntryID2Col].Value);
+                        HSourceBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceBillNo2Col].Value);
+                        HSourceBillType = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceBillType2Col].Value);
+                        HBarcodeQtys = ClsPub.isLong(grdSub.Rows[i].Cells[HBarcodeQtysCol].Value);
+                        HBarcodeNo = ClsPub.isLong(grdSub.Rows[i].Cells[HBarcodeNoCol].Value);
+                        HSupID = ClsPub.isLong(grdSub.Rows[i].Cells[HSupID2Col].Value);
+                        HDeptID = ClsPub.isLong(grdSub.Rows[i].Cells[HDeptID2Col].Value);
+                        HWhID = ClsPub.isLong(grdSub.Rows[i].Cells[HWhID2Col].Value);
+                        HSPID = ClsPub.isLong(grdSub.Rows[i].Cells[HSPID2Col].Value);
+                        HRemark = ClsPub.isStrNull(grdSub.Rows[i].Cells[HRemark2Col].Value);
+                        HMaterName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterName2Col].Value);
+                        HMaterModel = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterModel2Col].Value);
+                        HPinfan = ClsPub.isStrNull(grdSub.Rows[i].Cells[HPinfan2Col].Value);
+                        HMTONo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMTONo2Col].Value);
+                        HCusID = ClsPub.isLong(grdSub.Rows[i].Cells[HCusID2Col].Value);
+                        HCusType = ClsPub.isStrNull(grdSub.Rows[i].Cells[HCusType2Col].Value);
+                        HEndDate = ClsPub.isDate(grdSub.Rows[i].Cells[HEndDate2Col].Value);
+                        HWorkLineName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceName2Col].Value);
+                        HSeOrderBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSeOrderBillNo2Col].Value);
+                        HSeOrderSEQ = ClsPub.isLong(grdSub.Rows[i].Cells[HSeOrderSEQ2Col].Value);
+                        HInnerBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HInnerBillNo2Col].Value);
+                        HGiveAwayFlag = ClsPub.isBool(grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value);
+                        oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
+                                    ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
+                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
+                                    ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
+                                    ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " +
+                                    ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
+                                    ",HGiveAwayFlag,HSeOrderSEQ,HInitSourceEntryID " +
+                                    ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
+                                    ") values ("
+                                    + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
+                                    + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString()
+                                    + ", " + 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() + "," + HEntryID.ToString() + ""
+                                    + ", " + DBUtility.ClsPub.BoolToString(HGiveAwayFlag) + "," + HSeOrderSEQ.ToString() + "," + HSourceEntryID.ToString()
+                                    + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')");
+
+
+                        //HNumber = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterID2Col].Value);
+                        //if (cmbHBarCodeType.Text == "鍞竴鏉$爜")
+                        //{
+                        //    if (CampanyName == "鍗撳姏") //绯荤粺鍙傛暟  瀹㈡埛瀹氬埗鍖栧悕绉�
+                        //    {
+                        //        //鏉$爜鍓嶇紑 = 鐗╂枡浠g爜 + 骞� + 鏈� + 鏃�
+                        //        sTMNumber = HNumber + sYear + sPeriod + sDay; 
+                        //    }
+                        //    else if (CampanyName == "椋為緳")
+                        //    {
+                        //        string HWorksNumber = "";
+                        //        HWorksNumber = cmbHWorksNumber.Text;
+                        //        if (HWorksNumber == "")
+                        //        {
+                        //            MessageBox.Show("宸ュ巶浠g爜涓嶈兘涓虹┖锛�");
+                        //            return;
+                        //        }
+                        //        //鏉$爜鍓嶇紑 = 宸ュ巶浠g爜 + 鐗╂枡鍐呯爜 + 鏃ユ湡
+                        //        sTMNumber = HWorksNumber + HNumber + sYear + sPeriod + sDay; 
+                        //    }
+                        //    else  //閫氱敤鏂规硶
+                        //    {
+                        //        //鏉$爜鍓嶇紑 = 缁勭粐浠g爜 + 鐗╂枡浠g爜 + 骞� + 鏈� + 鏃�
+                        //        sTMNumber = HOrgNumber + HNumber + sYear + sPeriod + sDay; 
+                        //    }
+                        //}
+                        //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
+                    }
+                }
+                //澧炲姞 鏉$爜瓒呰繃鏈敓鎴愬姛鑳芥帶鍒�
+
+                //
+                oCn.Commit();
+                MessageBox.Show("鏉$爜鐢熸垚瀹屾瘯锛�");
+                //grdSub.RowCount = 0;
+                tabControl1.SelectedIndex = 1;
+            }
+            catch (Exception e)
+            {
+                oCn.RollBack();
+                MessageBox.Show("鏉$爜鐢熸垚澶辫触锛�" + e.Message);
+                grdSub.RowCount = 0;
+            }
+        }
+
+        ////鏈堜唤杞寲
+        //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();
+            int LSHlen = 6;             //娴佹按鍙烽暱搴�
+            int SumLen = 10;            //鎬婚暱搴�
+            string TM = "";             //鏉$爜
+            string HNumber = "";        //鐗╂枡鍐呯爜
+            string HMaterNumber = "";   //鐗╂枡浠g爜
+            double HSumQty = 0;         //浜у搧鏁伴噺
+            double HMinQty = 0;         //鏈�灏忓寘瑁呮暟
+            Int64 HBQty = 0;              //绠辨暟
+            double HQty = 0;            //鏁伴噺
+            string WeiShu = "";         //灏炬暟
+            //int LSH = 0;                //娴佹按鍙�
+            string LSH2 = "";           //娴佹按鍙疯浆鎹㈡垚瀛楃
+            string sDate = "";          //鏃ユ湡
+            string sYear = "";          //骞�
+            string sPeriod = "";        //鏈�
+            string sDay = "";           //鏃�
+            string HBatchNo = "";       //鎵规
+            int k = 0;
+            int n = 0;                  //鍚屼竴鎵圭敓鎴愭潯鐮佷腑鐨勭鍑犳潯
+            string sTMNumber = "";      //鏉$爜鑷畾涔夊墠缂�
+            DataSet Ds;
+            //Ds = oCn.RunProcReturn("exec GetLSH '" + ClsPub.GetServerDate(0) + "'", "GetLSH");
+            //LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
+            for (int j = 0; j < grdMain.Rows.Count; j++)
+            {
+                if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0)
+                {
+                    HNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterIDCol].Value);
+                    HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterNumberCol].Value);
+                    HBatchNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value);
+                    //鏃ユ湡鑾峰彇鏂瑰紡
+                    sDate = dtpHDate.Value.ToShortDateString();
+                    //
+                    if (cmbHBarCodeType.Text == "璇曞墏鎴愬搧鏉$爜瑙勫垯")// 澶辨晥鏃ユ湡锛堢敓浜ц鍗曪級
+                    {
+                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HEndDateCol].Value);
+                    }
+                    //
+                    sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
+                    sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
+                    sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
+                    sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
+                    sDay = sDay.Substring(sDay.Length - 2, 2);
+                    //==================================
+                    //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.isLong(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;
+                    //浠庨噾铦跺簭鍒楀彿琛ㄨ幏鍙栧簭鍒楀彿
+                    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)
+                        {
+                            WeiShu = "";
+                            HSumQty = HSumQty - HMinQty;
+                        }
+                        else
+                        {
+                            if (HSumQty == HMinQty)
+                            {
+                                WeiShu = "";
+                            }
+                            else
+                            {
+                                WeiShu = "灏炬暟";
+                            }
+                            HMinQty = HSumQty;
+                        }
+                        //
+                        //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 == "鍞竴鏉$爜")
+                        //{
+                            //鏉$爜缂栧彿 = 鏉$爜鍓嶇紑 + 娴佹按鍙�
+                            //T/*M*/ = HMaterNumber + LSH2 + sYear + sPeriod + sDay;
+                        TM =  LSH2 + sYear + sPeriod + sDay;
+                        //}
 
                         if (i + 1 > grdSub.Rows.Count)
                         {
@@ -830,9 +1347,16 @@
                         grdSub.Rows[i].Cells[HSeOrderBillNo2Col].Value = grdMain.Rows[j].Cells[HSeOrderBillNoCol].Value;
                         grdSub.Rows[i].Cells[HInnerBillNo2Col].Value = grdMain.Rows[j].Cells[HInnerBillNoCol].Value;
                         grdSub.Rows[i].Cells[HMaker2Col].Value = grdMain.Rows[j].Cells[HMakerCol].Value;
+                        grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value = grdMain.Rows[j].Cells[HGiveAwayFlagCol].Value;
+                        //缃戞牸鎵撳嬀
+                        DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
+                        oCell.ThreeState = false;
+                        oCell.Value = grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value;
+                        oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
+                        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 + "'");
                     }
                 }
             }
@@ -867,6 +1391,7 @@
             string HWorkLineName = "";
             string HSeOrderBillNo = "";
             string HInnerBillNo = "";
+            bool HGiveAwayFlag = false;
             try
             {
                 oCn.BeginTran();
@@ -876,7 +1401,13 @@
                     {
                         HWei = ClsPub.isStrNull(grdSub.Rows[i].Cells[HWeiCol].Value);
                         HBarCode = ClsPub.isStrNull(grdSub.Rows[i].Cells[HTMCol].Value);
+                        //
                         HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
+                        if (CampanyName == "鍗氭棩绉戞妧" || CampanyName == "澶忓疂鐢靛櫒")
+                        {
+                            HBarCodeType = "鍞竴鏉$爜";
+                        }
+                        //
                         HMaterID = ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value);
                         HAuxPropID = ClsPub.isLong(grdSub.Rows[i].Cells[HAuxPropID2Col].Value);
                         HUnitID = ClsPub.isLong(grdSub.Rows[i].Cells[HUnitID2Col].Value);
@@ -903,12 +1434,14 @@
                         HWorkLineName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceName2Col].Value);
                         HSeOrderBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSeOrderBillNo2Col].Value);
                         HInnerBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HInnerBillNo2Col].Value);
+                        HGiveAwayFlag = ClsPub.isBool(grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value);
                         oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                     ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                     ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                     ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                     ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " +
                                     ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID " +
+                                    ",HGiveAwayFlag " +
                                     ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
                                     ") values ("
                                     + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
@@ -917,6 +1450,7 @@
                                     + ", " + 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()
+                                    + ", " + DBUtility.ClsPub.BoolToString(HGiveAwayFlag)
                                     + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')");
 
 
@@ -975,7 +1509,7 @@
             //
             grdMain.RowCount = 0;
             grdSub.RowCount = 0;
-            grdMain.ColumnCount = 60;                       //鎬诲垪鏁�
+            grdMain.ColumnCount = 63;                       //鎬诲垪鏁�
             DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name);
             grdMain.Columns[HSnoCol].HeaderText = "搴忓彿";
             grdMain.Columns[HMainIDCol].HeaderText = "婧愬崟涓籌D";
@@ -998,8 +1532,10 @@
             grdMain.Columns[HBarCodeTypeCol].HeaderText = "鏉$爜绫诲瀷";
             grdMain.Columns[HBatchManagerCol].HeaderText = "鏄惁鍚敤鎵规";
             grdMain.Columns[HBatchNoCol].HeaderText = "鎵瑰彿";
+            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 = "渚涘簲鍟嗕唬鐮�";
@@ -1015,6 +1551,7 @@
             grdMain.Columns[HSPNameCol].HeaderText = "浠撲綅";
             grdMain.Columns[HInstructNoCol].HeaderText = "鎸囦护鍗曞彿";
             grdMain.Columns[HSeOrderBillNoCol].HeaderText = "閿�鍞鍗曞彿";
+            grdMain.Columns[HSeOrderSEQCol].HeaderText = "閿�鍞鍗曡鍙�";
             grdMain.Columns[HDateCol].HeaderText = "杩涙枡鏃ユ湡";
             grdMain.Columns[HRemarkCol].HeaderText = "澶囨敞";
             grdMain.Columns[HMTONoCol].HeaderText = "璁″垝璺熻釜鍙�";
@@ -1086,15 +1623,27 @@
                                 "," + HSeOrderBillNoCol.ToString() +
                                 "," + HBatchNoCol.ToString() +
                                 "," + HCusNumberCol.ToString() +
+                                "," + HPackQtyCol.ToString() +
                                 "," + HRemarkCol.ToString();
             //璁剧疆鍚堣鍒�
             string sTotalCol = HQtyCol.ToString();
+
+            //璁剧疆鐗规畩鍒�
+            for (int i = 0; i < grdMain.Rows.Count; i++)
+            {
+                //缃戞牸鎵撳嬀
+                DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
+                oCell.ThreeState = false;
+                oCell.Value = 0;
+                oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
+                grdMain.Rows[i].Cells[HGiveAwayFlagCol] = oCell;
+            }
             //
 
             DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol,oSumGrid);
             //----------------------------
 
-            grdSub.ColumnCount = 57;                       //鎬诲垪鏁�
+            grdSub.ColumnCount = 60;                       //鎬诲垪鏁�
             DBUtility.Xt_BaseBillFun.initGridFst(grdSub, this.Name);
             grdSub.Columns[HSelectCol].HeaderText = "閫夋嫨";
             grdSub.Columns[HTMCol].HeaderText = "鏉$爜缂栧彿";
@@ -1111,6 +1660,7 @@
             grdSub.Columns[HPinfan2Col].HeaderText = "鍝佺暘";
             grdSub.Columns[HPinfanBarCode2Col].HeaderText = "HPinfanBarCode";
             grdSub.Columns[HBatchNo2Col].HeaderText = "鎵瑰彿";
+            grdSub.Columns[HGiveAwayFlag2Col].HeaderText = "鏄惁璧犲搧";
             grdSub.Columns[HUnitID2Col].HeaderText = "璁¢噺鍗曚綅ID";
             grdSub.Columns[HUnitNumber2Col].HeaderText = "璁¢噺鍗曚綅浠g爜";
             grdSub.Columns[HUnitName2Col].HeaderText = "璁¢噺鍗曚綅";
@@ -1122,6 +1672,7 @@
             grdSub.Columns[HSourceBillNo2Col].HeaderText = "婧愬崟鍗曞彿";
             grdSub.Columns[HSourceBillType2Col].HeaderText = "婧愬崟绫诲瀷";
             grdSub.Columns[HSeOrderBillNo2Col].HeaderText = "閿�鍞鍗曞彿";
+            grdSub.Columns[HSeOrderSEQ2Col].HeaderText = "閿�鍞鍗曡鍙�";
             grdSub.Columns[HBarcodeNoCol].HeaderText = "鎵樺彿";
             grdSub.Columns[HBarcodeQtysCol].HeaderText = "鎬绘墭鏁�";
             grdSub.Columns[HSupID2Col].HeaderText = "渚涘簲鍟咺D";
@@ -1151,6 +1702,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;
@@ -1194,6 +1746,17 @@
             grdSub.Columns[HSourceID2Col].Visible = false;
             grdSub.Columns[HSourceNumber2Col].Visible = false;
             grdSub.Columns[HSourceName2Col].Visible = false;
+
+            //璁剧疆鐗规畩鍒�
+            for (int i = 0; i < grdSub.Rows.Count; i++)
+            {
+                //缃戞牸鎵撳嬀
+                DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
+                oCell.ThreeState = false;
+                oCell.Value = 0;
+                oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
+                grdSub.Rows[i].Cells[HGiveAwayFlag2Col] = oCell;
+            }
 
             DBUtility.Xt_BaseBillFun.GetGrid(grdMain, this.Name);
             DBUtility.Xt_BaseBillFun.GetGrid(grdSub, this.Name + "grdSub");
@@ -1630,6 +2193,24 @@
                     FillSelectData(oIF_PackageDismantleBillList.oBillSelectColl);
                 }
             }
+            else if (cmbSourceBillType.Text.Trim() == "宸ュ簭娴佽浆鍗�")
+            {
+                string sWhere = " and HOrgID =" + HOrgID.ToString();
+                DAL.Cls_S_IF_ProcessExchangeBillList oIF_ProcessExchangeBillList = new DAL.Cls_S_IF_ProcessExchangeBillList();
+                if (oIF_ProcessExchangeBillList.Refresh(sWhere))  //閫夋嫨鍘熷崟
+                {
+                    FillSelectData(oIF_ProcessExchangeBillList.oBillSelectColl);
+                }
+            }
+            else if (cmbSourceBillType.Text.Trim() == "宸ュ簭姹囨姤鍗�")
+            {
+                string sWhere = " and HOrgID =" + HOrgID.ToString();
+                DAL.Cls_S_IF_ProcessReportBillList oIF_ProcessReportBillList = new DAL.Cls_S_IF_ProcessReportBillList();
+                if (oIF_ProcessReportBillList.Refresh(sWhere))  //閫夋嫨鍘熷崟
+                {
+                    FillSelectData(oIF_ProcessReportBillList.oBillSelectColl);
+                }
+            }
             else
             {
 
@@ -1775,6 +2356,26 @@
                     //鍐欏叆淇℃伅
                     Sub_WriteInForm1(Ds.Tables[0], i);
                 }
+                //宸ュ簭娴佽浆鍗�
+                if (oSelectRow.BillType == "3772")
+                {
+                    grdMain.Rows.Add();
+                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
+                    //寰楀埌淇℃伅
+                    Ds = oCn.RunProcReturn("select * from h_v_IF_ProcessExchangeList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_ProcessExchangeList");
+                    //鍐欏叆淇℃伅
+                    Sub_WriteInForm1(Ds.Tables[0], i);
+                }
+                //鐢熶骇姹囨姤鍗�
+                if (oSelectRow.BillType == "3714")
+                {
+                    grdMain.Rows.Add();
+                    grdMain.Rows[i].Cells[HTagCol].Value = "*";
+                    //寰楀埌淇℃伅
+                    Ds = oCn.RunProcReturn("select * from h_v_IF_ProcessReportList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_IF_ProcessReportList");
+                    //鍐欏叆淇℃伅
+                    Sub_WriteInForm1(Ds.Tables[0], i);
+                }
                 //鍗虫椂搴撳瓨
                 if (oSelectRow.BillType == "JSKC")
                 {
@@ -1804,8 +2405,9 @@
             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[HDateCol].Value = oTable.Rows[0]["鏃ユ湡"].ToString(); //鍗氭棩 鏀舵枡鍗曟嵁鏃ユ湡
             grdMain.Rows[i].Cells[HShowDateCol].Value = dtpHDate.Value.ToShortDateString();
             grdMain.Rows[i].Cells[HSupIDCol].Value = oTable.Rows[0]["hsupid"].ToString();
             grdMain.Rows[i].Cells[HSupNumberCol].Value = oTable.Rows[0]["渚涘簲鍟嗕唬鐮�"].ToString();
@@ -1828,17 +2430,33 @@
             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();
-            grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["鏈�灏忓寘瑁呮暟"].ToString();
+            grdMain.Rows[i].Cells[HEndDateCol].Value = oTable.Rows[0]["璁″垝瀹屽伐鏃ユ湡"].ToString();//鍗氭棩 鐢熶骇璁㈠崟 澶辨晥鏃ユ湡
+            if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佸鍣ㄨ鍒�" )
+            {
+                grdMain.Rows[i].Cells[HMinQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["鏈敓鎴愭潯鐮佹暟閲�"]);
+            }
+            else if (cmbHBarCodeType.Text == "浠櫒澶栬喘浠舵潯鐮佹櫘閫氳鍒�"  
+                || cmbHBarCodeType.Text == "浠櫒鎴愬搧鏉$爜瑙勫垯" 
+                || cmbHBarCodeType.Text == "璇曞墏鎴愬搧鏉$爜瑙勫垯")
+            {
+                grdMain.Rows[i].Cells[HMinQtyCol].Value = "1";
+            }
+            else
+            {
+                grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["鏈�灏忓寘瑁呮暟"].ToString();
+            }
             //--
             //璁剧疆鍙紪杈戝垪
             string sAllowCol = HQtyCol.ToString() +
                                 "," + HMinQtyCol.ToString() +
                                 "," + HAuxPropNumberCol.ToString() +
                                 "," + HBatchNoCol.ToString() +
+                                "," + HPackQtyCol.ToString() +
                                 "," + HRemarkCol.ToString();
             grdMain.Columns[HBillNoCol].ReadOnly = true;
             //璁剧疆鍚堣鍒�
@@ -1866,7 +2484,7 @@
             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[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
-            grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["鏃ユ湡"].ToString();
+            grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["鏃ユ湡"].ToString(); //鍗氭棩 鍗曟嵁鏃ユ湡
             grdMain.Rows[i].Cells[HShowDateCol].Value = dtpHDate.Value.ToShortDateString();
             grdMain.Rows[i].Cells[HDeptIDCol].Value = oTable.Rows[0]["HDeptID"].ToString();
             grdMain.Rows[i].Cells[HDeptNumberCol].Value = oTable.Rows[0]["閮ㄩ棬浠g爜"].ToString();
@@ -1882,7 +2500,18 @@
             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();
-            grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["鏈�灏忓寘瑁呮暟"].ToString(); 
+            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
+            {
+                grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["鏈�灏忓寘瑁呮暟"].ToString();
+            }
             grdMain.Rows[i].Cells[HMakerCol].Value = ClsPub.CurUserName;
             if (cmbSourceBillType.Text.Trim() == "鏀舵枡閫氱煡鍗�"|| cmbSourceBillType.Text.Trim() == "閲囪喘璁㈠崟"
                 || cmbSourceBillType.Text.Trim() == "濮斿璁㈠崟" || cmbSourceBillType.Text.Trim() == "閲囪喘鍏ュ簱鍗�")
@@ -1891,6 +2520,20 @@
                 grdMain.Rows[i].Cells[HSupIDCol].Value = oTable.Rows[0]["hsupid"].ToString();
                 grdMain.Rows[i].Cells[HSupNumberCol].Value = oTable.Rows[0]["渚涘簲鍟嗕唬鐮�"].ToString();
                 grdMain.Rows[i].Cells[HSupNameCol].Value = oTable.Rows[0]["渚涘簲鍟�"].ToString();
+                if (cmbSourceBillType.Text.Trim() == "鏀舵枡閫氱煡鍗�")
+                {
+                    if (oTable.Rows[0]["鏄惁璧犲搧"].ToString() == "鏄�")
+                    {
+                        grdMain.Rows[i].Cells[HGiveAwayFlagCol].Value = 1;
+                    }
+                    else
+                    {
+                        grdMain.Rows[i].Cells[HGiveAwayFlagCol].Value = 0;
+                    }
+                    grdMain.Rows[i].Cells[HSeOrderBillNoCol].Value = oTable.Rows[0]["閿�鍞鍗曞彿"].ToString();
+                    grdMain.Rows[i].Cells[HSeOrderSEQCol].Value = oTable.Rows[0]["閿�鍞鍗曡鍙�"].ToString();
+                }
+
             }
             if (cmbSourceBillType.Text.Trim() == "閫�璐ч�氱煡鍗�")
             {
@@ -2128,9 +2771,10 @@
         #region  //鎵撳嵃璁剧疆
 
         GridppReport Report;
+        int CurRows = 0;
+        string sBarCodeItemID = ""; //鏉$爜鑷鍒�
 
         //棰勮
-        int CurRows = 0;
         private void yl_Click(object sender, EventArgs e)
         {
             //鍒ゆ柇鏄惁宸茬粡鐢熸垚鏉$爜
@@ -2159,32 +2803,68 @@
             }
         }
 
-        //鎵撳嵃鍓嶅垽鏂潯鐮佹槸鍚﹀凡鎵撳嵃杩�
+        //鎵撳嵃
+        private void dy_Click(object sender, EventArgs e)
+        {
+            //鍒ゆ柇鏄惁宸茬粡鐢熸垚鏉$爜
+            if (DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value) == "")
+            {
+                MessageBox.Show("鏉$爜鏈敓鎴愶紝璇峰厛鐢熸垚鏉$爜鍚庡啀鎵撳嵃锛�");
+                return;
+            }
+
+            //鎵撳嵃鍓嶅垽鏂潯鐮佹槸鍚﹀凡鎵撳嵃杩�
+            if (ReportPrintBegin())
+            {
+                return;
+            }
+
+            //閫夋嫨鎵撳嵃妯℃澘
+            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
+            oFrm.sBillName = ModName;
+            oFrm.sBillModel = ModCaption;
+            oFrm.ShowDialog();
+            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
+            {
+                //寰幆閫変腑琛�
+                Sub_SetReport(oFrm.sOpenTmp);
+                Report.Print(true);
+                Thread.Sleep(1000);
+            }
+        }
+
+        ////鎵撳嵃鍓嶅垽鏂潯鐮佹槸鍚﹀凡鎵撳嵃杩�
+        //private bool ReportPrintBegin()
+        //{
+        //    string sRelQty = "";
+
+        //    if (oBar.Set_BPrintQty(DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value), ref sRelQty))
+        //    {
+        //        MessageBox.Show("鏉$爜宸茬粡鎵撳嵃杩囷紝涓嶅彲閲嶅鎵撳嵃锛�");
+        //        return true;
+        //    }
+        //    else
+        //    {
+        //        return false;
+        //    }
+        //}
+
+        //鎵撳嵃鍓嶅垽鏂潯鐮佹槸鍚﹁秴杩囧厑璁稿彲鎵撳嵃娆℃暟
         private bool ReportPrintBegin()
         {
-            string sRelQty = "";
-
-            if (oBar.Set_BPrintQty(DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value), ref sRelQty))
+            string sHRemark = "";
+            if (PrintQtyCtl == "Y")
             {
-                MessageBox.Show("鏉$爜宸茬粡鎵撳嵃杩囷紝涓嶅彲閲嶅鎵撳嵃锛�");
-                return true;
+                if (oBar.Set_CheckPrintQty_SD(HInterID, PrintQty, ref sHRemark))
+                {
+                    MessageBox.Show(sHRemark);
+                    return true;
+                }
+                return false;
             }
             else
             {
                 return false;
-            }
-        }
-
-        //鎵撳嵃缁撴潫鍚庡洖濉潯鐮佹墦鍗版鏁�
-        private void ReportPrintEnd()
-        {
-            try
-            {
-                oCn.RunProc("update Gy_BarCodeBill set HPrintQty=isnull(HPrintQty,0)+1 where HInterID=" + HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
-            }
-            catch (Exception e)
-            {
-                MessageBox.Show("鎵撳嵃澶辫触!鎵撳嵃缁撴潫 锛�" + e.Message);
             }
         }
 
@@ -2225,11 +2905,7 @@
             }
         }
 
-        private Int32 Fun_GetCol(string sCol)
-        {
-            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdList);
-        }
-
+        //濉叆鍗曟嵁琛ㄤ綋淇℃伅
         private void ReportFetchRecordByDataTable()
         {
             try
@@ -2243,17 +2919,40 @@
             }
         }
 
-        private void dy_Click(object sender, EventArgs e)
+        ////鎵撳嵃缁撴潫鍚庡洖濉潯鐮佹墦鍗版鏁�
+        //private void ReportPrintEnd()
+        //{
+        //    try
+        //    {
+        //        oCn.RunProc("update Gy_BarCodeBill set HPrintQty=isnull(HPrintQty,0)+1 where HInterID=" + HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
+        //    }
+        //    catch (Exception e)
+        //    {
+        //        MessageBox.Show("鎵撳嵃澶辫触!鎵撳嵃缁撴潫 锛�" + e.Message);
+        //    }
+        //}
+
+        //鎵撳嵃缁撴潫鍚庡洖濉潯鐮佹墦鍗版鏁�
+        private void ReportPrintEnd()
+        {
+            if (UpdatePrintQtyCtl == "Y")
+            {
+                oBar.Set_UpdatePrintQty_SD(HInterID);
+            }
+        }
+
+        //璇曟墦鍗�
+        private void sdy_Click(object sender, EventArgs e)
         {
             //鍒ゆ柇鏄惁宸茬粡鐢熸垚鏉$爜
             if (DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value) == "")
             {
-                MessageBox.Show("鏉$爜鏈敓鎴愶紝璇峰厛鐢熸垚鏉$爜鍚庡啀鎵撳嵃锛�");
+                MessageBox.Show("鏉$爜鏈敓鎴愶紝璇峰厛鐢熸垚鏉$爜鍚庡啀棰勮锛�");
                 return;
             }
 
             //鎵撳嵃鍓嶅垽鏂潯鐮佹槸鍚﹀凡鎵撳嵃杩�
-            if (ReportPrintBegin())
+            if (ReportPrintBegin_SDY())
             {
                 return;
             }
@@ -2265,12 +2964,71 @@
             oFrm.ShowDialog();
             if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
             {
-                //寰幆閫変腑琛�
-                Sub_SetReport(oFrm.sOpenTmp);
-                Report.Print(true);
+                Sub_SetReportView(oFrm.sOpenTmp);
+                Report.PrintPreview(false);
                 Thread.Sleep(1000);
             }
         }
+
+        //鎵撳嵃鍓嶅垽鏂潯鐮佹槸鍚﹁秴杩囧厑璁稿彲鎵撳嵃娆℃暟
+        private bool ReportPrintBegin_SDY()
+        {
+            string sHRemark = "";
+            sBarCodeItemID = "";
+            for (int i = 0; i < grdList.SelectedRows.Count; i++)
+            {
+                sBarCodeItemID = sBarCodeItemID + "," + DBUtility.ClsPub.isLong(grdList.Rows[grdList.SelectedRows[i].Index].Cells[Fun_GetCol("HItemID")].Value).ToString();
+            }
+            sBarCodeItemID = sBarCodeItemID.Remove(0, 1);
+
+            if (PrintQtyCtl == "Y")
+            {
+                if (oBar.Set_CheckPrintQty(sBarCodeItemID, PrintQty, ref sHRemark))
+                {
+                    MessageBox.Show(sHRemark);
+                    return true;
+                }
+                return false;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        private void Sub_SetReportView(string sOpenTmp)
+        {
+            //鍒ゆ柇琛屾暟
+            for (int i = 0; i < grdList.Rows.Count; i++)
+            {
+                grdList.Rows[i].Cells[0].Value = "";
+            }
+            for (int i = 0; i < grdList.SelectedRows.Count; i++)
+            {
+                grdList.Rows[grdList.SelectedRows[i].Index].Cells[0].Value = "*";
+            }
+            //
+            Report = new GridppReport();
+            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
+            Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
+            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
+            Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd_SDY);
+        }
+
+        //鎵撳嵃缁撴潫鍚庡洖濉潯鐮佹墦鍗版鏁�
+        private void ReportPrintEnd_SDY()
+        {
+            if (UpdatePrintQtyCtl == "Y")
+            {
+                oBar.Set_UpdatePrintQty(sBarCodeItemID);
+            }
+        }
+
+        private Int32 Fun_GetCol(string sCol)
+        {
+            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdList);
+        }
+
 
         #endregion
 
@@ -2314,7 +3072,7 @@
             }
             sWhere = " and HOrgID =" + sHOrgID.ToString();
             BLL.Cls_S_KF_ICInventoryList_IF oadd = new BLL.Cls_S_KF_ICInventoryList_IF();
-            if (oadd.Refresh(""))  //閫夋嫨鍘熷崟
+            if (oadd.Refresh(sWhere))  //閫夋嫨鍘熷崟
             //if (oadd.Refresh(" and HErpClsID in (1,2,3) "))  //閫夋嫨鍘熷崟
             {
                 FillSelectData(oadd.oBillSelectColl);
@@ -2413,6 +3171,12 @@
                 grdMain.Rows[row + r].Cells[HMTONoCol].Value = grdMain.Rows[row].Cells[HMTONoCol].Value;
                 grdMain.Rows[row + r].Cells[HInnerBillNoCol].Value = grdMain.Rows[row].Cells[HInnerBillNoCol].Value;
                 grdMain.Rows[row + r].Cells[HMakerCol].Value = grdMain.Rows[row].Cells[HMakerCol].Value;
+                //缃戞牸鎵撳嬀
+                DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
+                oCell.ThreeState = false;
+                oCell.Value = grdMain.Rows[row].Cells[HGiveAwayFlagCol].Value;
+                oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
+                grdMain.Rows[row + r].Cells[HGiveAwayFlagCol] = oCell;
 
             }
             DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
@@ -2471,8 +3235,274 @@
             }
         }
 
+        //鎵规鎸夐挳
+        private void BatchNo_Click(object sender, EventArgs e)
+        {
+            lblCaption.Focus();
+            bool b = false;
+            for (int i = 0; i < grdMain.RowCount; i++)
+            {
+                long HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value);          // 鐗╂枡鍐呯爜
+                string HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HBatchNoCol].Value);     // 鎵瑰彿
+
+                if (HMaterID != 0)
+                {
+                    DataSet oDs = oCn.RunProcReturn("exec h_p_Gy_BarCodeBill_GetBatchNo " + HMaterID.ToString() + ",'" + HBatchNo + "','" + dtpHDate.Value.ToShortDateString() + "','" + CampanyName + "'", "h_p_Gy_BarCodeBill_GetBatchNo");
+                    //
+                    if (oDs == null && oDs.Tables[0].Rows.Count == 0)
+                    {
+                        MessageBox.Show("鐢熸垚鎵规澶辫触锛�");
+                        return;
+                    }
+                    else if (DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0][0]) == "1")
+                    {
+                        grdMain.Rows[i].Cells[HBatchNoCol].Value = DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0]["HBatchNo"]);
+                        b = true;
+                    }
+                }
+            }
+            //鏄庣粏琛ㄦ槸鍚︿负闆惰
+            if (b == false)
+            {
+                MessageBox.Show("娌℃湁闇�瑕佺敓鎴愭壒娆$殑鏄庣粏琛岋紒", "鎻愮ず");
+                return;
+            }
+        }
+
+        private void txtHSourceBillNo_KeyPress(object sender, KeyPressEventArgs e)
+        {
+            if (e.KeyChar == (char)Keys.Return)//鍥炶溅甯﹀嚭婧愬崟淇℃伅
+            {
+                long sHOrgID = -1;
+                DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View();
+                if (oClsGy_ORGANIZATIONS_View.GetInfoByName(cmbHOrgID.Text))
+                {
+                    sHOrgID = oClsGy_ORGANIZATIONS_View.omodel.HItemID;
+                }
+
+                if (txtHSourceBillNo.Text.Length < 4)
+                {
+                    MessageBox.Show("璇疯緭鍏�4浣嶄互涓婃暟鎹紒");
+                    return;
+                }
+                //鏍规嵁婧愬崟绫诲瀷 鍜屾簮鍗曞彿 鑾峰彇淇℃伅
+                if (cmbSourceBillType.Text.Trim() == "鐢熶骇璁㈠崟")
+                {
+                    DAL.Cls_S_IFCLD_ICMOList oIFCLD_ICMOList = new DAL.Cls_S_IFCLD_ICMOList();
+                    if (oIFCLD_ICMOList.RefreshBySourceBillNo(" Where 鍗曟嵁鍙� like '%" + txtHSourceBillNo.Text + "' and HOrgID =" + sHOrgID.ToString()))  //閫夋嫨鍘熷崟
+                    {
+                        FillSelectData(oIFCLD_ICMOList.oBillSelectColl);
+                        txtHSourceBillNo.Text = "";
+                    }
+                    else
+                    {
+                        MessageBox.Show("鏈煡璇㈠埌浠诲姟鏁版嵁锛岃纭鎵�閫夌粍缁囥�佹簮鍗曠被鍨嬩笌婧愬崟鍗曞彿鏄惁姝g‘锛�");
+                        return;
+                    }
+                }
+                else if (cmbSourceBillType.Text.Trim() == "鐢熶骇姹囨姤鍗�")
+                {
+                    DAL.Cls_S_IF_ICMOReportBillList oIF_ICMOReportBillList = new DAL.Cls_S_IF_ICMOReportBillList();
+                    if (oIF_ICMOReportBillList.RefreshBySourceBillNo(" Where 鍗曟嵁鍙� like '%" + txtHSourceBillNo.Text + "' "))  //閫夋嫨鍘熷崟
+                    {
+                        FillSelectData(oIF_ICMOReportBillList.oBillSelectColl);
+                        txtHSourceBillNo.Text = "";
+                    }
+                    else
+                    {
+                        MessageBox.Show("鏈煡璇㈠埌浠诲姟鏁版嵁锛岃纭鎵�閫夌粍缁囥�佹簮鍗曠被鍨嬩笌婧愬崟鍗曞彿鏄惁姝g‘锛�");
+                        return;
+                    }
+                }
+                else if (cmbSourceBillType.Text.Trim() == "鏀舵枡閫氱煡鍗�")
+                {
+                    DAL.Cls_S_IF_POInStockBillList oIF_POInStockBillList = new DAL.Cls_S_IF_POInStockBillList();
+                    if (oIF_POInStockBillList.RefreshBySourceBillNo(" Where 鍗曟嵁鍙� like '%" + txtHSourceBillNo.Text + "' "))  //閫夋嫨鍘熷崟
+                    {
+                        FillSelectData(oIF_POInStockBillList.oBillSelectColl);
+                        txtHSourceBillNo.Text = "";
+                    }
+                    else
+                    {
+                        MessageBox.Show("鏈煡璇㈠埌浠诲姟鏁版嵁锛岃纭鎵�閫夌粍缁囥�佹簮鍗曠被鍨嬩笌婧愬崟鍗曞彿鏄惁姝g‘锛�");
+                        return;
+                    }
+                }
+                else if (cmbSourceBillType.Text.Trim() == "閲囪喘璁㈠崟")
+                {
+                    DAL.Cls_S_IF_POOrderBillList oIF_POOrderBillList = new DAL.Cls_S_IF_POOrderBillList();
+                    if (oIF_POOrderBillList.RefreshBySourceBillNo(" Where 鍗曟嵁鍙� like '%" + txtHSourceBillNo.Text + "' "))  //閫夋嫨鍘熷崟
+                    {
+                        FillSelectData(oIF_POOrderBillList.oBillSelectColl);
+                        txtHSourceBillNo.Text = "";
+                    }
+                    else
+                    {
+                        MessageBox.Show("鏈煡璇㈠埌浠诲姟鏁版嵁锛岃纭鎵�閫夌粍缁囥�佹簮鍗曠被鍨嬩笌婧愬崟鍗曞彿鏄惁姝g‘锛�");
+                        return;
+                    }
+                }
+                else if (cmbSourceBillType.Text.Trim() == "濮斿璁㈠崟")
+                {
+                    DAL.Cls_S_IF_EntrustOrderBillList oIF_EntrustOrderBillList = new DAL.Cls_S_IF_EntrustOrderBillList();
+                    if (oIF_EntrustOrderBillList.RefreshBySourceBillNo(" Where 鍗曟嵁鍙� like '%" + txtHSourceBillNo.Text + "' "))  //閫夋嫨鍘熷崟
+                    {
+                        FillSelectData(oIF_EntrustOrderBillList.oBillSelectColl);
+                        txtHSourceBillNo.Text = "";
+                    }
+                    else
+                    {
+                        MessageBox.Show("鏈煡璇㈠埌浠诲姟鏁版嵁锛岃纭鎵�閫夌粍缁囥�佹簮鍗曠被鍨嬩笌婧愬崟鍗曞彿鏄惁姝g‘锛�");
+                        return;
+                    }
+                }
+                else
+                {
+                    MessageBox.Show("鎵�閫夋簮鍗曠被鍨嬶紝涓嶆敮鎸佹鍔熻兘锛�");
+                    return;
+                }
+
+            }
+        }
 
 
+        //鐢熸垚澶栫鐮�
+        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 );
+            }
+        }
+
+        private void cmbSourceBillType_TextChanged(object sender, EventArgs e)
+        {
+            if (cmbSourceBillType.Text == "宸ュ簭娴佽浆鍗�")
+            {
+                cmbHBarCodeType.Items.Clear();
+                cmbHBarCodeType.Items.Add("搴忓垪鐮�");
+                this.cmbHBarCodeType.SelectedIndex = 0;
+            }
+            else
+            {
+                cmbHBarCodeType.Items.Clear();
+                cmbHBarCodeType.Items.Add("鍞竴鏉$爜");
+                cmbHBarCodeType.Items.Add("鍝佺鏉$爜");
+                cmbHBarCodeType.Items.Add("鎵规鏉$爜");
+                this.cmbHBarCodeType.SelectedIndex = 0;
+            }
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1