From e294473fbac1442d4d2466edd0bf0ce0385460a5 Mon Sep 17 00:00:00 2001
From: duhe <226547893@qq.com>
Date: 星期二, 30 四月 2024 11:21:45 +0800
Subject: [PATCH] 托盘条码自动组托:组托保证数据一致性。

---
 WarM/条码打印/Gy_PackBarCodeBill_automaticallyByPLC.cs |  162 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 100 insertions(+), 62 deletions(-)

diff --git "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_PackBarCodeBill_automaticallyByPLC.cs" "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_PackBarCodeBill_automaticallyByPLC.cs"
index 578ef1d..a53a36e 100644
--- "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_PackBarCodeBill_automaticallyByPLC.cs"
+++ "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_PackBarCodeBill_automaticallyByPLC.cs"
@@ -347,12 +347,18 @@
         //鏈弧鎵樼敓鎴� 鎸夐挳 鐐瑰嚮浜嬩欢
         private void button_produceByHand_Click(object sender, EventArgs e)
         {
-            if (HQty == 0)
+            try
             {
-                MessageBox.Show("璇锋壂鐮佸瓙鏉$爜!");
-                return;
+                if (HQty == 0)
+                {
+                    MessageBox.Show("璇锋壂鐮佸瓙鏉$爜!");
+                    return;
+                }
+                this.Sub_SaveBill();
+            }catch(Exception ex)
+            {
+                MessageBox.Show(ex.Message);
             }
-            this.Sub_SaveBill();
         }
 
         //鑷姩缁勬墭 
@@ -408,22 +414,28 @@
         {
             if(isStartListen == 1)
             {
-                if(HQty == DBUtility.ClsPub.isDoule(textBox_PackQty.Text))
+                try
                 {
-                    this.Sub_SaveBill();
-
-                    //璁剧疆鎵撳嵃妯℃澘锛屾墦鍗�
-                    grdSub.Rows[0].Cells[0].Value = "*";
-                    Report = new GridppReport();
-                    Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + textBox_PrintModelParams.Text + ".grf");  //here .
-                    Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
-                    Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
-                    Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
-                    if (comboBox_PrinterParams.Text != "")
+                    if (HQty == DBUtility.ClsPub.isDoule(textBox_PackQty.Text))
                     {
-                        Report.Printer.PrinterName = comboBox_PrinterParams.Text.Replace("(榛樿)", "");
+                        this.Sub_SaveBill();
+
+                        //璁剧疆鎵撳嵃妯℃澘锛屾墦鍗�
+                        grdSub.Rows[0].Cells[0].Value = "*";
+                        Report = new GridppReport();
+                        Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + textBox_PrintModelParams.Text + ".grf");  //here .
+                        Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
+                        Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
+                        Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
+                        if (comboBox_PrinterParams.Text != "")
+                        {
+                            Report.Printer.PrinterName = comboBox_PrinterParams.Text.Replace("(榛樿)", "");
+                        }
+                        Report.Print(false);
                     }
-                    Report.Print(false);
+                }catch(Exception ex)
+                {
+                    MessageBox.Show(ex.Message);
                 }
             }
         }
@@ -432,25 +444,29 @@
         //鐢熸垚鎵樼洏鏉$爜
         private bool Sub_SaveBill()
         {
-            //鑾峰彇缁勭粐淇℃伅
-            HOrgID = get_ORGANIZATIONSIDByName(cmbHOrgID.Text);
-            HOrgNumber = get_ORGANIZATIONSNOByName(cmbHOrgID.Text);
-
-            if (HOrgID == -1)
+            try
             {
-                MessageBox.Show("閫夋嫨缁勭粐鏈夐敊璇紒");
-                return false;
-            }
+                //鑾峰彇缁勭粐淇℃伅
+                HOrgID = get_ORGANIZATIONSIDByName(cmbHOrgID.Text);
+                HOrgNumber = get_ORGANIZATIONSNOByName(cmbHOrgID.Text);
 
+                if (HOrgID == -1)
+                {
+                    throw new Exception("閫夋嫨缁勭粐鏈夐敊璇紒");
+                }
 
-            if (!Sub_AllowSave())//鍗曟嵁瀹屾暣鎬у垽鏂�
+                if (!Sub_AllowSave())//鍗曟嵁瀹屾暣鎬у垽鏂�
+                {
+                    throw new Exception("鍗曟嵁瀹屾暣鎬у垽鏂け璐ワ紒");
+                }
+
+                SaveBarCode();
+                return true;
+            }catch(Exception ex)
             {
-                return false;
+                throw new Exception(ex.Message);
             }
-
-
-            SaveBarCode();
-            return true;
+            
         }
 
         //鍗曟嵁瀹屾暣鎬у垽鏂�          鏈畬鎴�
@@ -508,6 +524,15 @@
 
                 sSQLMul[1] = " exec h_p_WMS_SetMaxNo_QTY '" + sTMNumber + "'," + HQty.ToString() + " ";
 
+                //鍒ゆ柇褰撳墠鎵樼洏鏉$爜鏄惁宸茬粡閫氳繃涓存椂缁勬墭鍦ㄦ潯鐮佹。妗堜腑鐢熸垚浜嗭紝鑻ュ凡缁忕敓鎴愪簡鍒欎笉闇�瑕佸湪鎻掑叆
+                ds = oCn.RunProcReturn("select * from Gy_BarCodeBill where HBarCode = '" + textBox_HPackBarCode.Text + "' and HSTOCKORGID = " + HOrgID, "Gy_BarCodeBill");
+                if (ds != null && ds.Tables[0].Rows.Count > 0)
+                {
+                    sSQLMul[0] = "";                
+                }
+
+                oCn.BeginTran();
+
                 if (getRunProcByMul_Back(sSQLMul, ref DBUtility.ClsPub.sExeReturnInfo))
                 {
                     //MessageBox.Show("鏉$爜鐢熸垚瀹屾瘯锛�");
@@ -519,15 +544,21 @@
                     setPackBarCodeBillData();
 
                     getDisplay_GrdMain();
+
+                    oCn.Commit();
                 }
                 else
                 {
                     //MessageBox.Show("鏉$爜鐢熸垚澶辫触锛�" + DBUtility.ClsPub.sExeReturnInfo);
+                    oCn.RollBack();
                 }
+
+                //oCn.Commit();
             }
             catch (Exception e)
             {
-                //MessageBox.Show("鏉$爜鐢熸垚澶辫触锛�" + e.Message);
+                oCn.RollBack();
+                throw new Exception(e.Message);
             }
         }
 
@@ -542,27 +573,30 @@
                 {
                     for (int i = 0; i < 1; i++)
                     {
-                        oCn.RunProc(sSQL[i]);
+                        if (sSQL[i].Length > 0)
+                        {
+                            oCn.RunProc(sSQL[i]);
+                        }
                     }
 
-                    
-
+                    //涓婁紶缁勬墭淇℃伅鍒版湇鍔″櫒
                     send();
+                    oCn.Commit();
                 }
                 else
                 {
-                    sErrMsg = "娌℃湁鏁版嵁锛�";
                     oCn.Commit();
-                    return false;
+                    sErrMsg = "娌℃湁鏁版嵁锛�";
+                    throw new Exception(sErrMsg);
                 }
-                oCn.Commit();
+                //oCn.Commit();
                 return true;
             }
             catch (Exception e)
             {
-                sErrMsg = e.Message;
                 oCn.RollBack();
-                return false;
+                sErrMsg = e.Message;
+                throw new Exception(sErrMsg);
             }
         }
         #endregion
@@ -581,7 +615,13 @@
             //{
             //    return;
             //}
-            LoadData();
+            try
+            {
+                LoadData();
+            }catch(Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
         }
 
         //鍒ゆ柇鐢ㄦ埛鏉冮檺
@@ -610,7 +650,7 @@
             //鍒ゆ柇鏄惁鏁版嵁瀹屾暣 
             if (AllowLoadData() == false)
             {
-                return;
+                throw new Exception("鏁版嵁瀹屾暣鎬у垽鏂け璐ワ紒");
             }
             try
             {
@@ -628,14 +668,14 @@
                 }
                 else
                 {
-                    MessageBox.Show("鐢熸垚澶辫触锛佸師鍥�:" + err);
-                    return;
+                    string error = "鐢熸垚澶辫触锛佸師鍥�:" + err;
+                    throw new Exception(error);
                 }
             }
             catch (Exception e)
             {
-                MessageBox.Show("鍗曟嵁鍙凤細" + textBox_sBillID.Text + "锛屽崟鎹甀D锛�" + textBox_sBillID.Text + "锛涗笂浼犲け璐ワ紒" + e.Message);
-                return;
+                string error = "鍗曟嵁鍙凤細" + textBox_sBillID.Text + "锛屽崟鎹甀D锛�" + textBox_sBillID.Text + "锛涗笂浼犲け璐ワ紒" + e.Message;
+                throw new Exception(error);
             }
         }
 
@@ -659,37 +699,37 @@
         public bool set_SavePackUnionBill_Add(Int64 HInterID, string HBillType, string HBillNo, string HBarCode_Pack, string HMaker, Int64 HStockOrgID, ref string sErrMsg)
         {
             SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
+            oCn.BeginTran();
             try
             {
-                oCn.BeginTran();
                 DataSet ds = oCn.RunProcReturn("exec h_p_Sc_PackUnionBill_Insert_New " + HInterID.ToString() + ",'" + HBillNo + "','" + HBillType + "','" + HBarCode_Pack + "','" + HMaker + "'," + HStockOrgID.ToString(), "h_p_Sc_PackUnionBill_Insert_New");
                 if (ds == null || ds.Tables[0].Rows.Count == 0)
                 {
-                    sErrMsg = "鍗曟嵁鍙凤細" + HBillNo + "锛屽崟鎹甀D锛�" + HInterID + "锛涗笂浼犲け璐ワ紒";
                     oCn.RollBack();
-                    return false;
+                    sErrMsg = "鍗曟嵁鍙凤細" + HBillNo + "锛屽崟鎹甀D锛�" + HInterID + "锛涗笂浼犲け璐ワ紒";
+                    throw new Exception(sErrMsg);
                 }
                 else
                 {
                     if (DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0][0]) == 1)
                     {
-                        sErrMsg = "涓婁紶澶辫触锛屽崟鎹彿锛�" + HBillNo + "锛屽崟鎹甀D锛�" + HInterID + "锛�" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HRemark"]);
                         oCn.RollBack();
-                        return false;
+                        sErrMsg = "涓婁紶澶辫触锛屽崟鎹彿锛�" + HBillNo + "锛屽崟鎹甀D锛�" + HInterID + "锛�" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HRemark"]);
+                        throw new Exception(sErrMsg);
                     }
                     else
                     {
-                        //sErrMsg = "鐢熸垚鐢熶骇缁勬墭鍗曟垚鍔燂紒鍗曟嵁鍙蜂负锛�" + HBillNo;
                         oCn.Commit();
+                        //sErrMsg = "鐢熸垚鐢熶骇缁勬墭鍗曟垚鍔燂紒鍗曟嵁鍙蜂负锛�" + HBillNo;
                         return true;
                     }
                 }
             }
             catch (Exception e)
             {
-                sErrMsg = "鐢熸垚鐢熶骇缁勬墭鍗曞け璐ワ紒" + e.Message;
                 oCn.RollBack();
-                return false;
+                sErrMsg = "鐢熸垚鐢熶骇缁勬墭鍗曞け璐ワ紒" + e.Message;
+                throw new Exception(sErrMsg);
             }
         }
 
@@ -715,11 +755,9 @@
             }
             catch (Exception e2)
             {
-                //if (DBUtility.ClsPub.bSound)
-                //{
-                //    DBUtility.ClsPub.MessageBeep((int)DBUtility.ClsPub.BeepType.Warning);
-                //}
-                MessageBox.Show("鍙戠敓缃戠粶寮傚父锛岃绋嶅悗鍐嶈瘯锛�");
+                textBox_HBarCode.Text = "";
+                textBox_HBarCode.Focus();
+                MessageBox.Show(e2.Message);
             }
         }
         //灏嗘潯鐮佷俊鎭啓鍏ユ潯鐮佸嚭鍏ュ簱涓存椂琛�
@@ -743,13 +781,13 @@
                 }
                 else
                 {
-                    MessageBox.Show(err);
-                    return;
+                    throw new Exception(err);
                 }
             }
             catch (Exception e)
             {
-                MessageBox.Show("鎵弿瀛愭潯鐮侊紝鍐欏叆涓存椂琛ㄤ俊鎭け璐ワ紒" + e.Message + err);
+                string sError = "鎵弿瀛愭潯鐮侊紝鍐欏叆涓存椂琛ㄤ俊鎭け璐ワ紒" + e.Message + err;
+                throw new Exception(sError);
             }
         }
 

--
Gitblit v1.9.1