From cb3d53118483109c762409abec96dbe81bf31d14 Mon Sep 17 00:00:00 2001
From: ch <37327@LLOOCCY>
Date: 星期一, 14 三月 2022 21:18:43 +0800
Subject: [PATCH] 合并

---
 WarM/条码打印/Sc_ICMOToBarCode.cs |  542 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 418 insertions(+), 124 deletions(-)

diff --git "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Sc_ICMOToBarCode.cs" "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Sc_ICMOToBarCode.cs"
index a704a01..5f5cfa8 100644
--- "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Sc_ICMOToBarCode.cs"
+++ "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Sc_ICMOToBarCode.cs"
@@ -69,7 +69,7 @@
             //    sFastSQL = sFastSQL + " and HMaterName  like '%" + txtHMaterID.Text + "%'";
             //}
             string HMaterName = "";
-            HMaterName = txtHMaterID.Text.Trim().ToString();
+            HMaterName = txtHMaterID.Text.Trim().ToString(); //鐗╂枡浠g爜
             //鏈哄彴
             //if (txtHSourceID.Text.Trim() != "")
             //{
@@ -113,7 +113,7 @@
             }
             //
             grdMain.DataSource = DSet.Tables[0].DefaultView;
-          
+
             //鏍囧噯瑁呯
             //for (int i = 0; i < grdMain.SelectedRows.Count; i++)
             //{
@@ -129,15 +129,15 @@
             //DBUtility.Xt_BaseBillFun.DisplayGrid(grdMain, this.Name, s,FrCol);
             //鐢荤嚎
             GraphLine();
-            
-            
+
+
             // 
         }
 
         //
         private void timer1_Tick(object sender, EventArgs e)
         {
-            timer1.Enabled=false;
+            timer1.Enabled = false;
             initGrid();
             Display();
         }
@@ -204,6 +204,8 @@
             this.Text = ModCaption;
             //lblCaption.Text = ModCaption;
             initGrid();
+            cmbHBarCodeType.SelectedIndex = 0;
+            dtpHBeginDate.Value = DateTime.Today;
         }
 
         private void grdMain_DblClick(object sender, EventArgs e)
@@ -243,7 +245,7 @@
         //鍒犻櫎
         private void Sub_DeleteBill()
         {
-        //    //缂栬緫鏉冮檺
+            //    //缂栬緫鏉冮檺
             if (!DBUtility.ClsPub.Security_Log(ModRightNameEdit, 1, true, DBUtility.ClsPub.CurUserName))
             {
                 return;
@@ -331,7 +333,7 @@
             //}
         }
 
- 
+
 
         private void bclk_Click(object sender, EventArgs e)
         {
@@ -365,7 +367,7 @@
         private void Sub_CheckBill()
         {
             //瀹℃牳鏉冮檺
-            if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true,DBUtility.ClsPub.CurUserName))
+            if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true, DBUtility.ClsPub.CurUserName))
             {
                 return;
             }
@@ -376,7 +378,7 @@
             lngBillKey = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("hmainid")].Value);
             if (lngBillKey == 0)
                 return;
-            DAL.ClsGy_ICBomBill  oBill = new DAL.ClsGy_ICBomBill();
+            DAL.ClsGy_ICBomBill oBill = new DAL.ClsGy_ICBomBill();
             //鏌ョ湅鏄惁宸插鏍�,鍏抽棴,浣滃簾
             if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))
             {
@@ -407,7 +409,7 @@
         private void Sub_AbandonCheck()
         {
             //瀹℃牳鏉冮檺
-            if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true,DBUtility.ClsPub.CurUserName))
+            if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true, DBUtility.ClsPub.CurUserName))
             {
                 return;
             }
@@ -418,7 +420,7 @@
             lngBillKey = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("hmainid")].Value);
             if (lngBillKey == 0)
                 return;
-            DAL.ClsGy_ICBomBill  oBill = new DAL.ClsGy_ICBomBill();
+            DAL.ClsGy_ICBomBill oBill = new DAL.ClsGy_ICBomBill();
             //鏌ョ湅鏄惁宸插鏍�,鍏抽棴,浣滃簾
             if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))
             {
@@ -757,7 +759,7 @@
 
         private void cmdHSaveBill_Click(object sender, EventArgs e)
         {
-          
+
             Display();
         }
 
@@ -770,84 +772,31 @@
 
 
 
-        private void button4_Click(object sender, EventArgs e)
+        //=======鐢熸垚 鍞竴鐮� 鍜� 鎵樻潯鐮� 銆佺粍鎵樺崟
+        private void Sub_SaveBarCode()//鍒嗛厤鏃� 瑕佽�冭檻 璁㈠崟鍓╀綑鏁伴噺宸茬粡鏄� 璐熸暟鐨勬儏鍐�
         {
-            //1.鑾峰彇鐣岄潰涓婇潰鏁寸鏁伴噺妗嗚緭鍏ョ殑鏁伴噺 璧嬪�肩粰鍙橀噺  骞跺埛鏂扮綉鏍�
-            double HBarCodeQty = 0;
-            double HZXQty = 0;
-            HZXQty = ClsPub.isDoule(txtHZXQty.Text);
-            if (HZXQty ==0)
+            try
             {
-                MessageBox.Show("璇疯緭鍏ユ暣绠辨暟閲忥紒");
-                return;
-            }
-            Display();
-            //2.鑾峰彇缃戞牸閫変腑琛岀墿鏂橧D
-            //int a = grdMain.CurrentRow.Index;
-            //long HMaterID = 0;
-            ////HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[a].Cells[Fun_GetCol("HMaterID")].Value);
-            //    if (HMaterID == 0)
-            //    {
-            //        MessageBox.Show("娌℃湁閫変腑浠讳綍璁板綍锛�");
-            //        return;
-            //    }
-            //3.瀹氫箟鏄惁缁勬墭鐨勫彉閲�
-            int Mul = 0;
-            //4.鏍规嵁鍗曟嵁绫诲瀷鑾峰彇鏈鏉$爜涓诲唴鐮丠InterID
-            HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
-            for (int i = 0; i < grdMain.Rows.Count; i++)
-            {
-
-                //鑾峰彇缃戞牸閲岄潰姣忎竴琛岃鍗曞搴旂殑璁㈠崟鏁伴噺
-                double HDDQty = 0;
-                HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("璁㈠崟鏁伴噺")].Value);
-
-
-                //鑾峰彇褰撳墠绯荤粺鐧婚檰缁勭粐浠g爜
-                HOrgNumber = ClsPub.HOrgNumber;
-
-              
-
-
-                //鑷姩鍖归厤閫昏緫  鍒ゆ柇璁㈠崟鏁伴噺鏄惁澶т簬鏁寸鏁伴噺   濡傛灉璁㈠崟鏁伴噺澶т簬鏁寸鏁伴噺  鐩存帴鐢熸垚鍞竴鐮�
-                //濡傛灉璁㈠崟鏁伴噺灏忎簬鏁寸鏁伴噺  鍒欏惊鐜敓鎴愬敮涓�鐮�   鐢熸垚瀵瑰簲鐨勬墭鏉$爜
-                    if (HDDQty >= HZXQty)
-                    {
-                        HBarCodeQty = HZXQty;
-                        this.Sub_SaveBill_TTM();
-                        Display();
-                        Mul = Mul + 1;
-                        break;
-                    }
-                    else if(HDDQty < HZXQty)
-                    {
-                        HBarCodeQty = HDDQty;
-                        HZXQty = HZXQty - HDDQty;
-                        this.Sub_SaveBill_TTM();
-                        Mul = Mul + 1;
-                        continue;
-                    }
-
-                //濡傛灉Mul>1 鏂板缁勬墭鍗曚富琛�
-              
-            }
-
-            if (Mul > 1)
-            {
-                //HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("鐢熶骇璁㈠崟鍙�")].Value);
-                DataSet DS1;
-                HTTMNumber = HOrgNumber + HICMOBillNo;
-                DS1 = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
-                TLSH = ClsPub.isInt(DS1.Tables[0].Rows[0][0]);
-                TLSH2 = TLSH.ToString();
-                TTM = HTTMNumber + TLSH2;
-                HInterID_TTM = DBUtility.ClsPub.CreateBillID_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo);
-                HBillNo_TTM = DBUtility.ClsPub.CreateBillCode_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo, true);//寰楀埌鏂板崟鍙�
-
+                string HMaterNumber = "";
+                string HBatchNo = "";
                 string HDate = "";
                 string HYear = "";
                 string HPeriod = "";
                 string HDay = "";
+                string HTMNumber = "";
+                string HOrgNumber = "";
+                DataSet Ds;
+                int LSH = 0;                //娴佹按鍙�
+                string LSH2 = "";           //娴佹按鍙疯浆鎹㈡垚瀛楃
+                double HZXQty = 0;         //瑁呯鏁伴噺
+                double HDDQty = 0;         //璁㈠崟鏁伴噺
+                double HBQty = 0;         //绠辨暟
+                int k = 0;
+                int n = 0;                  //鍚屼竴鎵圭敓鎴愭潯鐮佷腑鐨勭鍑犳潯
+                string WeiShu = "";         //灏炬暟
+                int LSHlen = 6;             //娴佹按鍙烽暱搴�
+                string TM = "";             //鏉$爜
+
                 HDate = DateTime.Now.ToShortDateString();
                 HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2);
                 HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString();
@@ -855,52 +804,343 @@
                 HDay = "0" + ClsPub.isDate(HDate).Day.ToString();
                 HDay = HDay.Substring(HDay.Length - 2, 2);
 
-                oCn.RunProc("insert into Sc_PackUnionBillMain (HYear,HPeriod,HBillType,HInterID,HDate" +
-                                   ",HBillNo,HBillStatus,HICMOBillNo,HBarCode_Pack,HMaterID,HUnitID,HWeight" +
-                                   ",HPWeight,HProdOrgID,HDeptID,HEmpID,HSNum,HPackNum,HBarCode_Cus,HBatchNo " +
-                                   ") values ("
-                                   + HYear + "," + HPeriod + ",'3783'," + HInterID_TTM + ",'" + HDate + "'"
-                                   + ", " + HBillNo_TTM.ToString() + ",1,''," + TTM.ToString() + ",0,0,0"
-                                   + ",0,1,0,0,0,0,'','')");
+                //=============鏍规嵁鐣岄潰涓婂凡缁忓垎閰嶇殑鏁版嵁杩涜鏉$爜鐢熸垚鍜屾墦鍗般��
+                //鑾峰彇鏈鐢熸垚鐨� 涓诲唴鐮� 
+                Int64 HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
+                HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
+                Int64 HInterID_TTM = DBUtility.ClsPub.CreateBillID_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo); //缁勬墭鍗曞唴鐮�
+                string HBillNo_TTM = DBUtility.ClsPub.CreateBillCode_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo, true);//缁勬墭鍗曞崟鍙�
+
+                //0 寮�鍚簨鍔�
+                oCn.BeginTran();
+                //00 鍏堢敓鎴� 鍞竴鐨� 鎵樻潯鐮�
+
+                //鐢熸垚涓�涓绠辩爜
+                string sPackStr = "ZXM" + HYear + HPeriod + HDay; //澶栫鐮� 鍓嶇紑
+                DataSet  DsTM = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sPackStr + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿                                                                                          //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
+                Int64 TTM_LSH = ClsPub.isLong(DsTM.Tables[0].Rows[0][0]) + 1;
+                string sPackBarCode = sPackStr + LSH.ToString();
+                oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sPackStr + "'");
+                
+                //1.寰幆缃戞牸锛屾牴鎹� 鏈鏁伴噺 鍒�  鐢熸垚 鍞竴鐮�
+               
+                for (int j = 0; j < grdMain.Rows.Count; j++)
+                {
+                    if (DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("鏈鏁伴噺")].Value) > 0)
+                    {
+                        HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("鐗╂枡浠g爜")].Value);
+                        HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("鎵规")].Value);
+                        
+                        HOrgNumber = ClsPub.HOrgNumber;
+
+
+                        //HBQty = HBQty + ClsPub.isInt(txtHBQty.Text);
+                        HZXQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("鏈鏁伴噺")].Value);
+                        HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("璁㈠崟鏁伴噺")].Value);
+                        HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("鐢熶骇璁㈠崟鍙�")].Value);
+
+                        HTMNumber = HOrgNumber + HMaterNumber + HYear + HPeriod + HDay;
+                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
+                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
+                        n = 0;
+                        LSH2 = LSH.ToString();
+                        while (LSH2.Length < LSHlen)  //濡傛灉娴佹按鍙峰皬浜�6浣嶆暟鍓嶉潰琛�0
+                        {
+                            LSH2 = "0" + LSH2;
+                        }
+                        //鏉$爜缂栧彿 = 鏉$爜鍓嶇紑 + 娴佹按鍙�
+                        TM = HTMNumber + LSH2;
+                        if (TM.Trim() == "")
+                        {
+                            MessageBox.Show("鏉″舰鐮佷笉鑳戒负绌猴紝涓嶈兘鐢熸垚鏉$爜锛�");
+                            return;
+                        }
+                        string HWei = "";      //灏炬暟
+                        string HBarCode = "";
+                        string HBarCodeType = "";
+                        Int64 HMaterID1 = 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 = "";
+                        string HInnerBillNo = "";
+                        HWei = WeiShu;
+                        HBarCode = TM;
+                        HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
+                        HMaterID1 = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HMaterID")].Value);
+                        HAuxPropID = 0;
+                        HUnitID = 0;
+                        HQty2 = HZXQty;
+                        HBatchNo2 = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("鎵规")].Value);
+                        HSourceInterID = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HSourceInterID")].Value);
+                        HSourceEntryID = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HSourceEntryID")].Value);
+                        HSourceBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("鐢熶骇璁㈠崟鍙�")].Value);
+                        HSourceBillType = "3710";
+                        HBarcodeQtys = 0;
+                        HBarcodeNo = 0;
+                        HSupID = 0;
+                        HDeptID = 0;
+                        HWhID = 0;
+                        HSPID = 0;
+                        HRemark = "";
+                        HMaterName = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("鐗╂枡鍚嶇О")].Value);
+                        HMaterModel = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("瑙勬牸鍨嬪彿")].Value);
+                        HPinfan = "";
+                        HMTONo = "";
+                        HCusID = 0;
+                        HCusType = "";
+                        HEndDate = ClsPub.isDate(grdMain.Rows[j].Cells[Fun_GetCol("鏃ユ湡")].Value);
+                        HWorkLineName = "";
+                        HSeOrderBillNo = "";
+                        HInnerBillNo = sPackBarCode;
+                        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 " +
+                                            ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
+                                            ") values ("
+                                            + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID1.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 + "','" + HDate + "'"
+                                            + ", " + ClsPub.HOrgID.ToString() + "," + ClsPub.HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString()
+                                            + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')");
+
+                        oCn.RunProc("exec h_p_WMS_SetMaxNo '" + HTMNumber + "'");
+                    }
+                }
+                //2.寰幆缁撴潫鍚庯紝鏍规嵁 鏈鐢熸垚鐨� 涓诲唴鐮侊紝浠庡悗鍙版暟鎹簱鑾峰彇 鏉$爜鍒楄〃锛岀敓鎴� 缁勬墭鍗� 鍜� 鎵樻潯鐮侊紝 鐩存帴璋冪敤瀛樺偍杩囩▼ 
+                 //鏍规嵁澶栫鐮� 鍐欏叆 缁勬墭鍗曚富琛紝缁勬墭鍗曞瓙琛紝SUM锛屽绠辩爜妗f锛孲UM妗f
+                oCn.RunProc("exec  h_p_WMS_PackUnionBill_AddNew  '" + sPackBarCode + "'," + HInterID_TTM.ToString() + ",'" + DBUtility.ClsPub.CurUserName + "'," + HInterID.ToString()); //鏍规嵁绠辨潯鐮侊紝鍐欏叆 涓昏〃锛屽瓙琛� 锛岀鏉$爜妗f 
+                oCn.RunProc("exec  h_p_WMS_PackUnionBill_SumSubBill  " + HInterID_TTM.ToString() + ",'" + sPackBarCode + "','3783','" + DBUtility.ClsPub.CurUserName + "'," + HInterID.ToString()); //鏍规嵁绠辨潯鐮侊紝鍐欏叆 SUM琛紝SUM鏉$爜妗f
+
+
+
+
+
+
+                oCn.Commit();
+                MessageBox.Show("鏉$爜鐢熸垚瀹屾瘯锛�");
+               
+
+
+
+                
+
+
+
+                //0缁撴潫浜嬪姟
+
+                //
+                Display();
+
             }
-
-
-            //3.鍏堝垽鏂墿鏂欐槸鍚︿竴鑷�  濡傛灉涓�鑷村紑濮嬪惊鐜綉鏍�
-            for (int i = 0; i < grdMain.Rows.Count; i++)
+            catch(Exception e )
             {
-                //long HGrdMaterID = 0;
-                //HGrdMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("HMaterID")].Value);
-                //if (HGrdMaterID == HMaterID)
-                //{
-                //    double HDDQty = 0;
-                //    HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("璁㈠崟鏁伴噺")].Value);
-                //    //濡傛灉寰幆鐨勮琛岃褰曠殑璁㈠崟鏁伴噺宸茬粡澶т簬绛変簬鏈瑁呯鏁伴噺  鍒欑洿鎺ョ敓鎴愬敮涓�鐮�  骞朵笖鍒锋柊缃戞牸  鍒锋柊鏉$爜淇℃伅椤�
-                //    if (HDDQty >= HZXQty)
-                //    {
-                //        double HBarCodeQty = 0;
-                //        HBarCodeQty = HZXQty;
-                //        this.Sub_SaveBill();
-                //        Display();
-                //    }
-                //    //濡傛灉鏀硅璁板綍璁㈠崟鏁伴噺灏忎簬鏈瑁呯鏁伴噺 鍒欑户缁惊鐜�  璧扮敓鎴愭墭鏉$爜鏂规硶
-                //    else  
-                //    {
-                //        //鏌ュ嚭绗﹀悎鏉′欢鐨勯�変腑杩欐潯鏁伴噺璺熻绠辨暟閲忕殑宸紓鍊�
-                //        double HCYQty = 0;
-                //        HCYQty = HZXQty - DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("璁㈠崟鏁伴噺")].Value);
+                //鍥炴粴浜嬪姟
 
-                //    }
-
-                //}
-                //else
-                //{
-                   
-                //}
+                MessageBox.Show("鐢熸垚鏉$爜澶辫触锛�" + e.Message);
+                Display();
             }
+        }
+
+        private void button4_Click(object sender, EventArgs e)
+        {
+            //鏍规嵁鏈鏁伴噺 鏉� 鍒嗛厤鍒� 姣忎釜鐢熶骇璁㈠崟涓婏紙鍒嗛厤鏃� 瑕佽�冭檻 璁㈠崟鍓╀綑鏁伴噺宸茬粡鏄� 璐熸暟鐨勬儏鍐碉級
+            //1.鍒ゆ柇鏈鏁伴噺 蹇呴』澶т簬0
+            double HZXQty = 0;//鏁寸鏁伴噺
+            HZXQty = ClsPub.isDoule(txtHZXQty.Text);
+            if (HZXQty <= 0)
+            {
+                MessageBox.Show("璇疯緭鍏ユ暣绠辨暟閲忥紒");
+                return;
+            }
+            //2.鍒锋柊缃戞牸
+            Display();
+            //3.鎶婃暣绠辨暟閲� 鍒嗛厤鍒� 缃戞牸涓嬮潰鐨勬瘡涓�涓� 鐢熶骇璁㈠崟涓婂幓銆�  寰幆缃戞牸
+            for(int i =0;i<grdMain.Rows.Count;i++)
+            {
+                if(HZXQty>0)
+                {
+                    if(HZXQty>DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["鐢熶骇璁㈠崟鏁伴噺"].Value))
+                    {
+                        HZXQty = HZXQty - DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["鐢熶骇璁㈠崟鏁伴噺"].Value);
+                        grdMain.Rows[i].Cells["鏈鏁伴噺"].Value = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["鐢熶骇璁㈠崟鏁伴噺"].Value);
+                    }
+                    else
+                    {
+                        grdMain.Rows[i].Cells["鏈鏁伴噺"].Value = HZXQty;
+                        break;
+                    }
+                }
+                else
+                {
+                    break;
+                }
+            }
+            Sub_SaveBarCode();
+            //
 
 
 
-           
+
+
+            ////1.鑾峰彇鐣岄潰涓婇潰鏁寸鏁伴噺妗嗚緭鍏ョ殑鏁伴噺 璧嬪�肩粰鍙橀噺  骞跺埛鏂扮綉鏍�
+            //double HBarCodeQty = 0;
+            //double HZXQty = 0;
+            //HZXQty = ClsPub.isDoule(txtHZXQty.Text);
+            //if (HZXQty ==0)
+            //{
+            //    MessageBox.Show("璇疯緭鍏ユ暣绠辨暟閲忥紒");
+            //    return;
+            //}
+            //Display();
+            ////2.鑾峰彇缃戞牸閫変腑琛岀墿鏂橧D
+            ////int a = grdMain.CurrentRow.Index;
+            ////long HMaterID = 0;
+            //////HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[a].Cells[Fun_GetCol("HMaterID")].Value);
+            ////    if (HMaterID == 0)
+            ////    {
+            ////        MessageBox.Show("娌℃湁閫変腑浠讳綍璁板綍锛�");
+            ////        return;
+            ////    }
+            ////3.瀹氫箟鏄惁缁勬墭鐨勫彉閲�
+            //int Mul = 0;
+            ////4.鏍规嵁鍗曟嵁绫诲瀷鑾峰彇鏈鏉$爜涓诲唴鐮丠InterID
+            //HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
+
+
+            //for (int i = 0; i < grdMain.Rows.Count; i++)
+            //{
+
+            //    //鑾峰彇缃戞牸閲岄潰姣忎竴琛岃鍗曞搴旂殑璁㈠崟鏁伴噺
+            //    double HDDQty = 0;
+            //    HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("璁㈠崟鏁伴噺")].Value);
+
+
+            //    //鑾峰彇褰撳墠绯荤粺鐧婚檰缁勭粐浠g爜
+            //    HOrgNumber = ClsPub.HOrgNumber;
+
+
+
+
+            //    //鑷姩鍖归厤閫昏緫  鍒ゆ柇璁㈠崟鏁伴噺鏄惁澶т簬鏁寸鏁伴噺   濡傛灉璁㈠崟鏁伴噺澶т簬鏁寸鏁伴噺  鐩存帴鐢熸垚鍞竴鐮�
+            //    //濡傛灉璁㈠崟鏁伴噺灏忎簬鏁寸鏁伴噺  鍒欏惊鐜敓鎴愬敮涓�鐮�   鐢熸垚瀵瑰簲鐨勬墭鏉$爜
+            //        if (HDDQty >= HZXQty)
+            //        {
+            //            HBarCodeQty = HZXQty;
+            //            this.Sub_SaveBill_TTM();
+            //            Display();
+            //            Mul = Mul + 1;
+            //            break;
+            //        }
+            //        else if(HDDQty < HZXQty)
+            //        {
+            //            HBarCodeQty = HDDQty;
+            //            HZXQty = HZXQty - HDDQty;
+            //            this.Sub_SaveBill_TTM();
+            //            Mul = Mul + 1;
+            //            continue;
+            //        }
+
+            //    //濡傛灉Mul>1 鏂板缁勬墭鍗曚富琛�
+
+            //}
+
+            //if (Mul > 1)
+            //{
+            //    //HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("鐢熶骇璁㈠崟鍙�")].Value);
+            //    DataSet DS1;
+            //    HTTMNumber = HOrgNumber + HICMOBillNo;
+            //    DS1 = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTTMNumber + "'", "h_p_WMS_GetMaxNo");    //鑾峰彇鏈�澶ф祦姘村彿
+            //    TLSH = ClsPub.isInt(DS1.Tables[0].Rows[0][0]);
+            //    TLSH2 = TLSH.ToString();
+            //    TTM = HTTMNumber + TLSH2;
+            //    HInterID_TTM = DBUtility.ClsPub.CreateBillID_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo);
+            //    HBillNo_TTM = DBUtility.ClsPub.CreateBillCode_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo, true);//寰楀埌鏂板崟鍙�
+
+            //    string HDate = "";
+            //    string HYear = "";
+            //    string HPeriod = "";
+            //    string HDay = "";
+            //    HDate = DateTime.Now.ToShortDateString();
+            //    HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2);
+            //    HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString();
+            //    HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2);
+            //    HDay = "0" + ClsPub.isDate(HDate).Day.ToString();
+            //    HDay = HDay.Substring(HDay.Length - 2, 2);
+
+            //    oCn.RunProc("insert into Sc_PackUnionBillMain (HYear,HPeriod,HBillType,HInterID,HDate" +
+            //                       ",HBillNo,HBillStatus,HICMOBillNo,HBarCode_Pack,HMaterID,HUnitID,HWeight" +
+            //                       ",HPWeight,HProdOrgID,HDeptID,HEmpID,HSNum,HPackNum,HBarCode_Cus,HBatchNo " +
+            //                       ") values ("
+            //                       + HYear + "," + HPeriod + ",'3783'," + HInterID_TTM + ",'" + HDate + "'"
+            //                       + ", " + HBillNo_TTM.ToString() + ",1,''," + TTM.ToString() + ",0,0,0"
+            //                       + ",0,1,0,0,0,0,'','')");
+            //}
+
+
+            ////3.鍏堝垽鏂墿鏂欐槸鍚︿竴鑷�  濡傛灉涓�鑷村紑濮嬪惊鐜綉鏍�
+            //for (int i = 0; i < grdMain.Rows.Count; i++)
+            //{
+            //    //long HGrdMaterID = 0;
+            //    //HGrdMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("HMaterID")].Value);
+            //    //if (HGrdMaterID == HMaterID)
+            //    //{
+            //    //    double HDDQty = 0;
+            //    //    HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("璁㈠崟鏁伴噺")].Value);
+            //    //    //濡傛灉寰幆鐨勮琛岃褰曠殑璁㈠崟鏁伴噺宸茬粡澶т簬绛変簬鏈瑁呯鏁伴噺  鍒欑洿鎺ョ敓鎴愬敮涓�鐮�  骞朵笖鍒锋柊缃戞牸  鍒锋柊鏉$爜淇℃伅椤�
+            //    //    if (HDDQty >= HZXQty)
+            //    //    {
+            //    //        double HBarCodeQty = 0;
+            //    //        HBarCodeQty = HZXQty;
+            //    //        this.Sub_SaveBill();
+            //    //        Display();
+            //    //    }
+            //    //    //濡傛灉鏀硅璁板綍璁㈠崟鏁伴噺灏忎簬鏈瑁呯鏁伴噺 鍒欑户缁惊鐜�  璧扮敓鎴愭墭鏉$爜鏂规硶
+            //    //    else  
+            //    //    {
+            //    //        //鏌ュ嚭绗﹀悎鏉′欢鐨勯�変腑杩欐潯鏁伴噺璺熻绠辨暟閲忕殑宸紓鍊�
+            //    //        double HCYQty = 0;
+            //    //        HCYQty = HZXQty - DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("璁㈠崟鏁伴噺")].Value);
+
+            //    //    }
+
+            //    //}
+            //    //else
+            //    //{
+
+            //    //}
+            //}
+
+
+
+
         }
 
         private void Sub_SaveBill()
@@ -1414,6 +1654,9 @@
             {
                 this.txtHSourceID.Text = oWork.oModel.HName;
                 this.txtHSourceID.Tag = oWork.oModel.HItemID.ToString();
+                //
+                Display();
+                //
             }
             else
             {
@@ -1611,9 +1854,60 @@
             grdMain.DataSource = DSBefore.Tables[0].DefaultView;
         }
 
+        //瓒呴鎵撳嵃
         private void button7_Click(object sender, EventArgs e)
         {
-            
+            //鏍规嵁鏈鏁伴噺 鏉� 鍒嗛厤鍒� 姣忎釜鐢熶骇璁㈠崟涓婏紝骞朵笖鍏佽瓒呰繃璁㈠崟鏁伴噺 锛堝垎閰嶆椂 瑕佽�冭檻 璁㈠崟鍓╀綑鏁伴噺宸茬粡鏄� 璐熸暟鐨勬儏鍐碉級
+            //1.鍒ゆ柇鏈鏁伴噺 蹇呴』澶т簬0
+            double HZXQty = 0;//鏁寸鏁伴噺
+            HZXQty = ClsPub.isDoule(txtHZXQty.Text);
+            if (HZXQty <= 0)
+            {
+                MessageBox.Show("璇疯緭鍏ユ暣绠辨暟閲忥紒");
+                return;
+            }
+            //2.鍒锋柊缃戞牸
+            Display();
+            //3.寰幆缃戞牸锛岀疮璁″叏閮ㄥ墿浣欐暟閲忥紝鍒ゆ柇鏄惁 鍓╀綑鏁伴噺 灏忎簬 鏈鏁伴噺锛涘鏋� 澶т簬鍒欐姤閿� 閫�鍑恒��
+            double sumLeftQty = 0;
+            for (int i = 0; i < grdMain.Rows.Count; i++)
+            { 
+                if ( DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["鐢熶骇璁㈠崟鏁伴噺"].Value)>0)
+                {
+                    sumLeftQty = sumLeftQty + DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["鐢熶骇璁㈠崟鏁伴噺"].Value); 
+                }
+                else
+                { 
+                } 
+            }
+            if(sumLeftQty>= HZXQty )
+            {
+                MessageBox.Show("鍓╀綑鏁伴噺澶т簬鏈鏁伴噺锛屼笉鑳借秴棰濇墦鍗帮紝璇风敤鏅�氭墦鍗板姛鑳姐��");
+                return;
+            }
+            //4.鎶婃暣绠辨暟閲� 鍒嗛厤鍒� 缃戞牸涓嬮潰鐨勬瘡涓�涓� 鐢熶骇璁㈠崟涓婂幓銆�  寰幆缃戞牸
+            for (int i = 0; i < grdMain.Rows.Count; i++)
+            { 
+                if (HZXQty > DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["鐢熶骇璁㈠崟鏁伴噺"].Value))
+                {
+                    if (i == grdMain.Rows.Count - 1)
+                    {
+                        grdMain.Rows[i].Cells["鏈鏁伴噺"].Value = HZXQty;
+                    }
+                    else
+                    {
+                        HZXQty = HZXQty - DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["鐢熶骇璁㈠崟鏁伴噺"].Value);
+                        grdMain.Rows[i].Cells["鏈鏁伴噺"].Value = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["鐢熶骇璁㈠崟鏁伴噺"].Value);
+                    }
+                }
+                else
+                {
+                    //grdMain.Rows[i].Cells["鏈鏁伴噺"].Value = HZXQty;
+                    break;
+                } 
+            }
+            Sub_SaveBarCode();
+            //
         }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1