From dbbcd506929afda0a85ae23bcb5f88c1dccef387 Mon Sep 17 00:00:00 2001
From: pzy <2829717936@qq.com>
Date: 星期一, 26 八月 2024 15:19:55 +0800
Subject: [PATCH] 11

---
 DBUtility/业务单据/ClsXt_BaseBill.cs |  905 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 880 insertions(+), 25 deletions(-)

diff --git "a/DBUtility/\344\270\232\345\212\241\345\215\225\346\215\256/ClsXt_BaseBill.cs" "b/DBUtility/\344\270\232\345\212\241\345\215\225\346\215\256/ClsXt_BaseBill.cs"
index 53b2ee58..c132dcc 100644
--- "a/DBUtility/\344\270\232\345\212\241\345\215\225\346\215\256/ClsXt_BaseBill.cs"
+++ "b/DBUtility/\344\270\232\345\212\241\345\215\225\346\215\256/ClsXt_BaseBill.cs"
@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 using System.Data;
+using System.Windows.Forms;
 
 namespace DBUtility
 {
@@ -23,6 +24,8 @@
         public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
         public SQLHelper.ClsCNK3 oK3Cn = new SQLHelper.ClsCNK3();
         public SQLHelper.ClsCNK3 oCnK3 = new SQLHelper.ClsCNK3();
+        string ComputerName = SystemInformation.ComputerName;   //璁惧鍚嶇О
+        string IPAddress="";    //璁惧IP
 
         public ClsXt_BaseBill()
         {
@@ -48,14 +51,64 @@
         public bool AbandonCancelltion(Int64 lngBillKey, ref string sReturn)
         {
             try
-            { 
-                oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='',HDeleteDate=null Where HInterID=" + lngBillKey.ToString());
+            {
+                DataSet ds = oCn.RunProcReturn("select * from " + MvarItemKey + " where HInterID=" + lngBillKey.ToString(), MvarItemKey);
+                if (ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='',HDeleteDate=null,HBillStatus=3 Where HInterID=" + lngBillKey.ToString());
+                }
+                else if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='',HDeleteDate=null,HBillStatus=2 Where HInterID=" + lngBillKey.ToString());
+                }
+                else
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='',HDeleteDate=null,HBillStatus=1 Where HInterID=" + lngBillKey.ToString());
+                }
                 sReturn = "";
                 return true;
             }
             catch (Exception e)
             {
                 sReturn = e.Message;
+                throw (e);
+            }
+        }
+        //鍙嶄綔搴熷崟鎹�(鍖呭惈鍐欏叆鏃ュ織)    2024-01-31
+        public bool AbandonCancelltion(Int64 lngBillKey, string HBillNo, string sUser, ref string sReturn)
+        {
+            try
+            {
+                oCn.BeginTran();
+                DataSet ds = oCn.RunProcReturn("select * from " + MvarItemKey + " where HInterID=" + lngBillKey.ToString(), MvarItemKey);
+                if (ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='',HDeleteDate=null,HBillStatus=3 Where HInterID=" + lngBillKey.ToString());
+                }
+                else if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='',HDeleteDate=null,HBillStatus=2 Where HInterID=" + lngBillKey.ToString());
+                }
+                else
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='',HDeleteDate=null,HBillStatus=1 Where HInterID=" + lngBillKey.ToString());
+                }
+
+                //鍐欏叆鏃ュ織
+                string WorkList = "鍙嶄綔搴熷崟鎹紝鍗曟嵁鍙凤細" + HBillNo;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','鍙嶄綔搴�')"
+                    );
+
+                sReturn = "鍙嶄綔搴熷崟鎹垚鍔燂紒";
+                oCn.Commit();
+                return true;
+            }
+            catch (Exception e)
+            {
+                sReturn = e.Message;
+                oCn.RollBack();
                 throw (e);
             }
         }
@@ -63,8 +116,21 @@
         public bool CancelClose(Int64 lngBillKey, ref string sReturn)
         {
             try
-            { 
-                oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='',HCloseDate=null Where HInterID=" + lngBillKey.ToString());
+            {
+                DataSet ds = oCn.RunProcReturn("select * from " + MvarItemKey + " where HInterID=" + lngBillKey.ToString(), MvarItemKey);
+                if (ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='',HCloseDate=null,HBillStatus=4,HCloseType = 0 Where HInterID=" + lngBillKey.ToString());
+                }
+                else if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='',HCloseDate=null,HBillStatus=2,HCloseType = 0 Where HInterID=" + lngBillKey.ToString());
+                }
+                else
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='',HCloseDate=null,HBillStatus=1,HCloseType = 0 Where HInterID=" + lngBillKey.ToString());
+                }
+
                 sReturn = "";
                 return true;
             }
@@ -74,8 +140,329 @@
                 throw (e);
             }
         }
+        //鍙嶅叧闂崟鎹�(鍖呭惈鍐欏叆鏃ュ織)    2024-01-31
+        public bool CancelClose(Int64 lngBillKey, string HBillNo, string sUser, ref string sReturn)
+        {
+            try
+            {
+                oCn.BeginTran();
+                DataSet ds = oCn.RunProcReturn("select * from " + MvarItemKey + " where HInterID=" + lngBillKey.ToString(), MvarItemKey);
+                if (ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='',HCloseDate=null,HBillStatus=4,HCloseType = 0 Where HInterID=" + lngBillKey.ToString());
+                }
+                else if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='',HCloseDate=null,HBillStatus=2,HCloseType = 0 Where HInterID=" + lngBillKey.ToString());
+                }
+                else
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='',HCloseDate=null,HBillStatus=1,HCloseType = 0 Where HInterID=" + lngBillKey.ToString());
+                }
+
+                //鍐欏叆鏃ュ織
+                string WorkList = "鍙嶅叧闂崟鎹紝鍗曟嵁鍙凤細" + HBillNo;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','鍙嶅叧闂�')"
+                    );
+
+                sReturn = "鍙嶅叧闂崟鎹垚鍔燂紒";
+                oCn.Commit();
+                return true;
+            }
+            catch (Exception e)
+            {
+                sReturn = e.Message;
+                oCn.RollBack();
+                throw (e);
+            }
+        }
+        //琛屽弽鍏抽棴鍗曟嵁(鍖呭惈鍐欏叆鏃ュ織)    2024-01-31
+        public bool CancelRow(Int64 lngBillKey,Int64 HEntryID, string HBillNo, string sUser, ref string sReturn)
+        {
+            try
+            {
+                //oCn.BeginTran();
+                string sql = "select * from " + MvarItemKeySub + " where HInterID=" + lngBillKey.ToString() + " and HEntryID = " + HEntryID;
+                DataSet ds = oCn.RunProcReturn(sql, MvarItemKeySub);
+                if(ds==null || ds.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "琛岃褰曚笉瀛樺湪锛�";
+                    return false;
+                }
+                else
+                {
+                    sql = " Update " + MvarItemKeySub + " set HCloseMan='',HEntryCloseDate='',HCloseType=0 Where HInterID=" + lngBillKey.ToString() + " and HEntryID = " + HEntryID;
+                    oCn.RunProc(sql);
+                }
+
+                //鍐欏叆鏃ュ織
+                string WorkList = "琛屽弽鍏抽棴锛屽崟鎹彿锛�" + HBillNo + "锛涘瓙琛ㄥ唴鐮侊細" + HEntryID;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','琛屽弽鍏抽棴')"
+                    );
+
+                sReturn = "琛屽弽鍏抽棴鎴愬姛锛�";
+                //oCn.Commit();
+                return true;
+            }
+            catch (Exception e)
+            {
+                sReturn = e.Message;
+                oCn.RollBack();
+                throw (e);
+            }
+        }
         //鍙嶅鏍�
         public bool AbandonCheck(Int64 lngBillKey, ref string sReturn)
+        {
+            string sql = "";
+            if (isUse(lngBillKey, ref sReturn))
+            {
+                return false;
+            }
+            try
+            {
+                DataSet ds = oCn.RunProcReturn("select * from " + MvarItemKey + " where HInterID=" + lngBillKey.ToString(), MvarItemKey);
+                if (ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=4 Where HInterID=" + lngBillKey.ToString());
+                }
+                else if (ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=3 Where HInterID=" + lngBillKey.ToString());
+                }
+                else
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=1 Where HInterID=" + lngBillKey.ToString());
+                }
+
+                //鍙嶅鏍稿悗 鏇存柊鍙婃椂搴撳瓨琛� 鍑忓皯搴撳瓨
+                sql = "select * from  " + MvarItemKey + " where HInterID=" + lngBillKey.ToString();
+                ds = oCn.RunProcReturn(sql, MvarItemKey);
+                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
+                {
+                    string HBillType = ds.Tables[0].Rows[0]["HBillType"].ToString();
+                    if (HBillType == "1201" || HBillType == "1202" || HBillType == "1203" || HBillType == "1247" || HBillType == "1244" || HBillType == "1251" || HBillType == "1210" || HBillType == "1204")
+                    {
+                        //鍙嶅鏍告洿鏂� 鍙婃椂搴撳瓨琛� 澧炲姞搴撳瓨 1201 1202 1203 1247 1244 1251 1210
+                        //鍙嶅鏍告洿鏂� 鍙婃椂搴撳瓨琛� 鍑忓皯搴撳瓨 1204 1202 1203 1247 1244 1251 1210
+                        ds = oCn.RunProcReturn("exec h_KF_UPDateICinventory  '" + lngBillKey.ToString() + "','" + HBillType + "','2'", "h_KF_UPDateICinventory");
+                    }
+                    //=========================瀹℃牳鍙嶅鏍稿悗璐熷簱瀛樻帶鍒�  
+                    DataSet ds2 = oCn.RunProcReturn("Exec h_p_KF_ICinventoryStockCtrl '" + lngBillKey.ToString() + "', '" + HBillType + "'", "h_p_KF_ICinventoryStockCtrl");
+                    if (ds2 == null)
+                    {
+                        sReturn = "搴撳瓨鏇存柊鍚庢帶鍒跺垽鏂け璐ワ紒";
+                        oCn.RollBack();
+                        return false;
+                    }
+                    if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
+                    {
+                        sReturn = "搴撳瓨鏇存柊澶辫触锛�" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]);
+                        oCn.RollBack();
+                        return false;
+                    }
+                    //============================
+                }
+
+                sReturn = "";
+                return true;
+            }
+            catch (Exception e)
+            {
+                sReturn = e.Message;
+                throw (e);
+            }
+        }
+        //鍙嶅鏍�(鍖呭惈鍙嶅鏍稿悗鎺у埗銆佸啓鍏ユ棩蹇�)    2024-01-31
+        public bool AbandonCheck(Int64 lngBillKey, string HBillNo, string procName, string sUser, ref string sReturn)
+        {
+            string sql = "";
+            DataSet ds;
+
+            if (isUse(lngBillKey, ref sReturn))
+            {
+                return false;
+            }
+            try
+            {
+                //寮�鍚簨鍔�
+                oCn.BeginTran();
+
+                ds = oCn.RunProcReturn("select * from " + MvarItemKey + " where HInterID=" + lngBillKey.ToString(), MvarItemKey);
+                if (ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=4 Where HInterID=" + lngBillKey.ToString());
+                }
+                else if (ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=3 Where HInterID=" + lngBillKey.ToString());
+                }
+                else
+                {
+                    oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=1 Where HInterID=" + lngBillKey.ToString());
+                }
+
+                //鍙嶅鏍稿悗鎺у埗
+                sql = "exec " + procName + " " + lngBillKey + ",'" + HBillNo + "','" + sUser + "'";
+                ds = oCn.RunProcReturn(sql, procName);
+                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "鍙嶅鏍歌繃绋嬩腑鍑洪敊锛岃涓庣綉缁滅鐞嗕汉鍛樿仈绯�";
+                    oCn.RollBack();
+                    return false;
+                }
+                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                {
+                    sReturn = ds.Tables[0].Rows[0]["HRemark"].ToString();
+                    oCn.RollBack();
+                    return false;
+                }
+                //鍙嶅鏍稿悗 鏇存柊鍙婃椂搴撳瓨琛� 鍑忓皯搴撳瓨
+                sql = "select * from  " + MvarItemKey + " where HInterID=" + lngBillKey.ToString();
+                ds = oCn.RunProcReturn(sql, MvarItemKey);
+                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
+                {
+                    string HBillType = ds.Tables[0].Rows[0]["HBillType"].ToString();
+                    if (HBillType == "1201" || HBillType == "1202" || HBillType == "1203" || HBillType == "1247" || HBillType == "1244" || HBillType == "1251" || HBillType == "1210" || HBillType == "1205" || HBillType == "1250" || HBillType == "1206" || HBillType == "1245" || HBillType == "1239")
+                    {
+                        //鍙嶅鏍告洿鏂� 鍙婃椂搴撳瓨琛� 澧炲姞搴撳瓨 1201 1202 1203 1247 1244 1251 1210
+                        //鍙嶅鏍告洿鏂� 鍙婃椂搴撳瓨琛� 鍑忓皯搴撳瓨 1205 1250 1206 1245 1239 
+                        ds = oCn.RunProcReturn("exec h_KF_UPDateICinventory  '" + lngBillKey.ToString() + "','" + HBillType + "','2'", "h_KF_UPDateICinventory");
+                    }else if (HBillType == "1207")
+                    {
+                        //鏇存柊鍙婃椂搴撳瓨琛�   澧炲姞璋冨叆搴撳瓨,鍑忓皯璋冨嚭搴撳瓨
+                        ds = oCn.RunProcReturn("exec h_KF_UPDateICinventory_Move  '" + lngBillKey.ToString() + "','" + HBillType + "','2'", "h_KF_UPDateICinventory_Move");
+                    }
+                    //=========================瀹℃牳鍙嶅鏍稿悗璐熷簱瀛樻帶鍒�  
+                    DataSet ds2 = oCn.RunProcReturn("Exec h_p_KF_ICinventoryStockCtrl '" + lngBillKey.ToString() + "', '" + HBillType + "'", "h_p_KF_ICinventoryStockCtrl");
+                    if (ds2 == null)
+                    {
+                        sReturn = "搴撳瓨鏇存柊澶辫触鍚庢帶鍒跺垽鏂け璐ワ紒";
+                        oCn.RollBack();
+                        return false;
+                    }
+                    if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
+                    {
+                        sReturn = "搴撳瓨鏇存柊澶辫触锛�" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]);
+                        oCn.RollBack();
+                        return false;
+                    }
+                    //============================
+                }
+                //鍐欏叆鏃ュ織
+                string WorkList = "鍙嶅鏍稿崟鎹紝鍗曟嵁鍙凤細" + HBillNo;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','鍙嶅鏍�')"
+                    );
+
+                sReturn = "鍙嶅鏍稿崟鎹垚鍔燂紒";
+                oCn.Commit();
+                return true;
+            }
+            catch (Exception e)
+            {
+                oCn.RollBack();
+                sReturn = e.Message;
+                throw (e);
+            }
+        }
+
+        //鍙戣捣澶氱骇瀹℃壒
+        public bool startCheckFlow(Int64 lngBillKey,ref string sReturn)
+        {
+            try
+            {
+                string HBillNo = "";                //鍗曟嵁鍙�
+                string HCheckFlowID = "";           //瀹℃壒娴両D
+                string HCheckItemNowID = "";        //褰撳墠瀹℃牳椤圭洰ID
+                string HCheckItemNextID = "";       //寰呭鏍搁」鐩甀D
+
+                //鍒ゆ柇鏄惁宸茬粡鍙戣捣瀹℃壒
+                string sql0 = "select * from Xt_BillCheckFlowStatus where HBillInterID = " + lngBillKey + " and HBillTypeID = '" + this.BillType + "'";
+                DataSet ds0 = oCn.RunProcReturn(sql0, "Xt_BillCheckFlowStatus");
+                if (ds0 != null && ds0.Tables[0].Rows.Count > 0)
+                {
+                    sReturn = "鍗曟嵁宸插彂璧峰鎵癸紝涓嶅彲閲嶅瀹℃壒锛�";
+                    return false;
+                }
+
+                //鑾峰彇鍗曟嵁鏁版嵁
+                string sql = "select * from " + this.MvarItemKey + " where HInterID = " + lngBillKey;
+                DataSet ds = oCn.RunProcReturn(sql, this.MvarItemKey);
+                if (ds == null || ds.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "鍗曟嵁涓嶅瓨鍦紒";
+                    return false;
+                }
+                HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
+                string HCheckFlowID_select = ds.Tables[0].Rows[0]["HCheckFlowID"].ToString();
+                //鑾峰彇鍗曟嵁绫诲瀷瀵瑰簲鐨勯粯璁ゅ鎵规祦
+                string sql1 = "select b.HInterID,b.HCheckItemID from Xt_CheckFlowMain as a " +
+                                "inner join Xt_CheckFlowSub as b on a.HInterID = b.HInterID " +
+                                "where a.HBillTypeID = '" + this.BillType + "' " +
+                                "and a.HInterID = " + HCheckFlowID_select + " " +
+                                "order by b.HFlowNo asc";
+                DataSet ds1 = oCn.RunProcReturn(sql1, "Xt_CheckFlowMain");
+                if (ds1 == null || ds1.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "榛樿瀹℃壒娴佷笉瀛樺湪锛�";
+                    return false;
+                }
+
+                HCheckFlowID = ds1.Tables[0].Rows[0]["HInterID"].ToString();
+                HCheckItemNowID = ds1.Tables[0].Rows[0]["HCheckItemID"].ToString();
+                if (ds1.Tables[0].Rows.Count >= 2)
+                {
+                    HCheckItemNextID = ds1.Tables[0].Rows[1]["HCheckItemID"].ToString();
+                }
+                else
+                {
+                    HCheckItemNextID = "0";
+                }
+
+                oCn.BeginTran();
+                //澧炲姞 鍗曟嵁瀹℃壒鐘舵�佽〃 鏁版嵁
+                for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
+                {
+                    string sql2 = "insert into Xt_BillCheckFlowStatus" +
+                        "(HBillTypeID,HBillInterID,HBillNo,HCheckFlowID,HCheckItemID,HChecker,HCheckDate,HCheckNote) " +
+                        "values(" +
+                        "'" + this.BillType + "'," +
+                        "" + lngBillKey + "," +
+                        "'" + HBillNo + "'," +
+                        "" + ds1.Tables[0].Rows[i]["HInterID"].ToString() + "," +
+                        "" + ds1.Tables[0].Rows[i]["HCheckItemID"].ToString() + "," +
+                        "" + "''" + "," +
+                        "" + "''" + "," +
+                        "" + "''" + "" +
+                        ")";
+
+                    oCn.RunProc(sql2);
+                }
+
+                //鏇存柊涓昏〃 瀹℃壒娴� 鏁版嵁
+                string sql3 = "update " + this.MvarItemKey + " set HCheckFlowID = " + HCheckFlowID + ",HCheckItemNowID=" + HCheckItemNowID + ",HCheckItemNextID=" + HCheckItemNextID + ",HBillStatus=" + 6 + " where HInterID = " + lngBillKey;
+                oCn.RunProc(sql3);
+
+
+                oCn.Commit();
+
+                return true;
+            }
+            catch (Exception e)
+            {
+                sReturn += e.Message;
+                return false;
+            }
+        }
+
+        //椹冲洖
+        public bool RejectCheckFlowProgress(Int64 lngBillKey, string HBillNo,string sUser, ref string sReturn)
         {
 
             if (isUse(lngBillKey, ref sReturn))
@@ -83,9 +470,128 @@
                 return false;
             }
             try
-            { 
-                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null Where HInterID=" + lngBillKey.ToString());
-                sReturn = "";
+            {
+                //寮�鍚簨鍔�
+                oCn.BeginTran();
+
+                //鍒ゆ柇鏄惁瀛樺湪瀹℃牳杩囩殑椤圭洰
+                //string sql0 = "select * from Xt_BillCheckFlowStatus where HBillInterID = " + lngBillKey + " and HBillTypeID = '" + this.BillType + "' and ISNULL(HChecker,'') <> ''";
+                //DataSet ds0 = oCn.RunProcReturn(sql0, "Xt_BillCheckFlowStatus");
+                //if (ds0 != null && ds0.Tables[0].Rows.Count == 0)
+                //{
+                //    sReturn = "鍗曟嵁涓嶅瓨鍦ㄥ凡缁忓鏍哥殑椤圭洰锛�";
+                //    return false;
+                //}
+
+                //鑾峰彇闇�瑕侀┏鍥炵殑瀹℃牳椤圭洰
+                string sql0 = "select c.* from Xt_CheckFlowMain as a " +
+                              "inner join Xt_CheckFlowSub as b on a.HInterID = b.HInterID " +
+                              "inner join Xt_BillCheckFlowStatus as c on a.HBillTypeID = c.HBillTypeID and b.HCheckItemID = c.HCheckItemID " +
+                              "where c.HBillTypeID = '" + this.BillType + "' and c.HBillInterID = " + lngBillKey + " " +
+                              "order by b.HFlowNo asc";
+                DataSet ds0 = oCn.RunProcReturn(sql0, "Xt_BillCheckFlowStatus");
+                if (ds0 == null || ds0.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "椹冲洖澶辫触!鍘熷洜:鏈彂璧峰鎵癸紒锛�";
+                    return false;
+                }
+                //鑾峰彇褰撳墠瀹℃牳椤圭洰
+                string HCheckFlowID = ds0.Tables[0].Rows[0]["HCheckFlowID"].ToString();             //瀹℃壒娴佸唴鐮�
+                sql0 = "select * from " + MvarItemKey + " where HInterID = " + lngBillKey;
+                ds0 = oCn.RunProcReturn(sql0, MvarItemKey);
+                string HCheckItemNowID = ds0.Tables[0].Rows[0]["HCheckItemNowID"].ToString();       //褰撳墠瀹℃壒椤圭洰鍐呯爜
+                //鏌ユ壘鏄惁鏈夋潈闄�
+                string sql01 = "select * from Xt_CheckUserRight where HUserID = '" + sUser + "' and HCheckFlowInterID = " + HCheckFlowID + " and HCheckItemID = " + HCheckItemNowID + "";
+                DataSet ds01 = oCn.RunProcReturn(sql01, "Xt_CheckUserRight");
+                if (ds01.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "鏃犳潈闄愶紒";
+                    return false;
+                }
+                //鏇存柊 椹冲洖鍒犻櫎瀹℃牳娴佺姸鎬佽〃
+                string sql02 = "Delete Xt_BillCheckFlowStatus where HBillTypeID = '" + this.BillType + "' and HBillInterID=" + lngBillKey + " and HCheckFlowID=" + HCheckFlowID;
+                oCn.RunProc(sql02);
+                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=5,HCheckItemNowID = 0,HCheckItemNextID = 0 Where HInterID=" + lngBillKey.ToString());
+
+                //鍐欏叆鏃ュ織
+                string WorkList = "椹冲洖鍗曟嵁锛屽崟鎹彿锛�" + HBillNo;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','椹冲洖')"
+                    );
+
+                sReturn = "鍙嶅鏍稿崟鎹垚鍔燂紒";
+                oCn.Commit();
+                return true;
+            }
+            catch (Exception e)
+            {
+                oCn.RollBack();
+                sReturn = e.Message;
+                throw (e);
+            }
+        }
+
+        //瀹℃壒娴�-鍙嶅鏍�(鍖呭惈鍙嶅鏍稿悗鎺у埗銆佸啓鍏ユ棩蹇�)    2024-01-31
+        public bool AbandonCheck(SQLHelper.ClsCN oCN,Int64 lngBillKey, string HBillNo, string procName, string sUser, ref string sReturn)
+        {
+            string sql = "";
+            DataSet ds;
+
+            if (isUse(lngBillKey, ref sReturn))
+            {
+                return false;
+            }
+            try
+            {
+                ds = oCN.RunProcReturn("select * from " + MvarItemKey + " where HInterID=" + lngBillKey.ToString(), MvarItemKey);
+                if (ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "")
+                {
+                    oCN.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=4 Where HInterID=" + lngBillKey.ToString());
+                }
+                else if (ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
+                {
+                    oCN.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=3 Where HInterID=" + lngBillKey.ToString());
+                }
+                else
+                {
+                    oCN.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=1 Where HInterID=" + lngBillKey.ToString());
+                }
+
+                //鍙嶅鏍稿悗鎺у埗
+                sql = "exec " + procName + " " + lngBillKey + ",'" + HBillNo + "','" + sUser + "'";
+                ds = oCN.RunProcReturn(sql, procName);
+                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "鍙嶅鏍歌繃绋嬩腑鍑洪敊锛岃涓庣綉缁滅鐞嗕汉鍛樿仈绯�";
+                    return false;
+                }
+                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                {
+                    sReturn = ds.Tables[0].Rows[0]["HRemark"].ToString();
+                    return false;
+                }
+                //鍙嶅鏍稿悗 鏇存柊鍙婃椂搴撳瓨琛� 鍑忓皯搴撳瓨
+                sql = "select * from  " + MvarItemKey + " where HInterID=" + lngBillKey.ToString();
+                ds = oCN.RunProcReturn(sql, MvarItemKey);
+                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
+                {
+                    string HBillType = ds.Tables[0].Rows[0]["HBillType"].ToString();
+                    if (HBillType == "1201" || HBillType == "1202" || HBillType == "1203" || HBillType == "1247" || HBillType == "1244" || HBillType == "1251" || HBillType == "1210" || HBillType == "1205" || HBillType == "1250" || HBillType == "1206" || HBillType == "1245" || HBillType == "1239")
+                    {
+                        //鍙嶅鏍告洿鏂� 鍙婃椂搴撳瓨琛� 澧炲姞搴撳瓨 1201 1202 1203 1247 1244 1251 1210
+                        //鍙嶅鏍告洿鏂� 鍙婃椂搴撳瓨琛� 鍑忓皯搴撳瓨 1205 1250 1206 1245 1239 
+                        ds = oCN.RunProcReturn("exec h_KF_UPDateICinventory  '" + lngBillKey.ToString() + "','" + HBillType + "','2'", "h_KF_UPDateICinventory");
+                    }
+                }
+                //鍐欏叆鏃ュ織
+                string WorkList = "鍙嶅鏍稿崟鎹紝鍗曟嵁鍙凤細" + HBillNo;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCN.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','鍙嶅鏍�')"
+                    );
+
+                sReturn = "鍙嶅鏍稿崟鎹垚鍔燂紒";
                 return true;
             }
             catch (Exception e)
@@ -94,15 +600,45 @@
                 throw (e);
             }
         }
+
         //瀹℃牳
         public bool CheckBill(Int64 lngBillKey, ref string sReturn)
         {
-           
+            string sql = "";
+            DataSet ds;
             try
             {
                 string  HChecker = ClsPub.CurUserName ;
                 string  HCheckDate =ClsPub.GetServerDate(-1);
-                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='" + HChecker + "',HCheckDate='" + HCheckDate + "' Where HInterID=" + lngBillKey.ToString());
+                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='" + HChecker + "',HCheckDate='" + HCheckDate + "',HBillStatus=2 Where HInterID=" + lngBillKey.ToString());
+                //瀹℃牳鍚� 鏇存柊鍙婃椂搴撳瓨琛� 澧炲姞搴撳瓨
+                sql = "select * from  " + MvarItemKey + " where HInterID=" + lngBillKey.ToString();
+                ds = oCn.RunProcReturn(sql, MvarItemKey);
+                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
+                {
+                    string HBillType = ds.Tables[0].Rows[0]["HBillType"].ToString();
+                    if (HBillType == "1201" || HBillType == "1202" || HBillType == "1203" || HBillType == "1247" || HBillType == "1244" || HBillType == "1251" || HBillType == "1210" || HBillType == "1204")
+                    {
+                        //瀹℃牳鏇存柊 鍙婃椂搴撳瓨琛� 澧炲姞搴撳瓨 1201 1202 1203 1247 1244 1251 1210
+                        //瀹℃牳鏇存柊 鍙婃椂搴撳瓨琛� 鍑忓皯搴撳瓨 1204 
+                        ds = oCn.RunProcReturn("exec h_KF_UPDateICinventory  '" + lngBillKey.ToString() + "','" + HBillType + "','1'", "h_KF_UPDateICinventory");
+                    }
+                    //=========================瀹℃牳鍙嶅鏍稿悗璐熷簱瀛樻帶鍒�  
+                    DataSet ds2 = oCn.RunProcReturn("Exec h_p_KF_ICinventoryStockCtrl '" + lngBillKey.ToString() + "', '" + HBillType + "'", "h_p_KF_ICinventoryStockCtrl");
+                    if (ds2 == null)
+                    {
+                        sReturn = "搴撳瓨鏇存柊鍚庢帶鍒跺垽鏂け璐ワ紒";
+                        oCn.RollBack();
+                        return false;
+                    }
+                    if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
+                    {
+                        sReturn = "搴撳瓨鏇存柊澶辫触锛�" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]);
+                        oCn.RollBack();
+                        return false;
+                    }
+                    //============================
+                }
                 sReturn = "";
                 return true;
             }
@@ -130,6 +666,145 @@
                 throw (e);
             }
         }
+        //瀹℃牳(鍖呭惈瀹℃牳鍚庢帶鍒躲�佸啓鍏ユ棩蹇�)    2024-01-31
+        public bool CheckBill(Int64 lngBillKey, string HBillNo,string procName , string sUser, ref string sReturn)
+        {
+            string sql = "";
+            DataSet ds;
+            try
+            {
+                string HChecker = sUser;
+                string HCheckDate = ClsPub.GetServerDate(-1);
+                
+                //寮�鍚簨鍔�
+                oCn.BeginTran();
+
+                //鏇存柊鍗曟嵁鐘舵��
+                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='" + HChecker + "',HCheckDate='" + HCheckDate + "',HBillStatus=2 Where HInterID=" + lngBillKey.ToString());
+
+                //瀹℃牳鍚庢帶鍒�
+                sql = "exec " + procName + " " + lngBillKey + ",'" + HBillNo + "','" + sUser + "'";
+                ds = oCn.RunProcReturn(sql, procName);
+                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "瀹℃牳杩囩▼涓嚭閿欙紝璇蜂笌缃戠粶绠$悊浜哄憳鑱旂郴";
+                    oCn.RollBack();
+                    return false;
+                }
+                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                {
+                    sReturn = ds.Tables[0].Rows[0]["HRemark"].ToString();
+                    oCn.RollBack();
+                    return false;
+                }
+                //瀹℃牳鍚� 鏇存柊鍙婃椂搴撳瓨琛� 澧炲姞搴撳瓨
+                sql = "select * from  " + MvarItemKey + " where HInterID=" + lngBillKey.ToString();
+                ds = oCn.RunProcReturn(sql, MvarItemKey);
+                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
+                {
+                    string HBillType = ds.Tables[0].Rows[0]["HBillType"].ToString();
+                    if (HBillType == "1201" || HBillType == "1202" || HBillType == "1203" || HBillType == "1247" || HBillType == "1244" || HBillType == "1251" || HBillType == "1210" || HBillType == "1250" || HBillType == "1206" || HBillType == "1245" || HBillType == "1239")
+                    {
+                        //瀹℃牳鏇存柊 鍙婃椂搴撳瓨琛� 澧炲姞搴撳瓨 1201 1202 1203 1247 1244 1251 1210
+                        //瀹℃牳鏇存柊 鍙婃椂搴撳瓨琛� 鍑忓皯搴撳瓨 1204 1250 1206 1245 1239 
+                        ds = oCn.RunProcReturn("exec h_KF_UPDateICinventory  '" + lngBillKey.ToString() + "','" + HBillType + "','1'", "h_KF_UPDateICinventory");
+                    }//鐩存帴璋冩嫧鍗曞鏍告洿鏂�
+                    else if (HBillType == "1207")
+                    {
+                        //鏇存柊鍙婃椂搴撳瓨琛�   鍑忓皯璋冨叆搴撳瓨,澧炲姞璋冨嚭搴撳瓨
+                        ds = oCn.RunProcReturn("exec h_KF_UPDateICinventory_Move  '" + lngBillKey.ToString() + "','" + HBillType + "','1'", "h_KF_UPDateICinventory_Move");
+                    }
+                    //=========================瀹℃牳鍙嶅鏍稿悗璐熷簱瀛樻帶鍒�  
+                    DataSet ds2 = oCn.RunProcReturn("Exec h_p_KF_ICinventoryStockCtrl '" + lngBillKey.ToString() + "', '" + HBillType +"'", "h_p_KF_ICinventoryStockCtrl");
+                    if (ds2 == null)
+                    {
+                        sReturn = "搴撳瓨鏇存柊鍚庢帶鍒跺垽鏂け璐ワ紒";
+                        oCn.RollBack();
+                        return false;
+                    }
+                    if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
+                    {
+                        sReturn = "搴撳瓨鏇存柊澶辫触锛�" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]);
+                        oCn.RollBack();
+                        return false;
+                    }
+                    //============================
+                }
+                //鍐欏叆鏃ュ織
+                string WorkList = "瀹℃牳鍗曟嵁锛屽崟鎹彿锛�" + HBillNo;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','"+SystemName+"','" + IPAddress + "','瀹℃牳')"
+                    );
+
+                sReturn = "瀹℃牳鍗曟嵁鎴愬姛锛�";
+                oCn.Commit();
+                return true;
+            }
+            catch (Exception e)
+            {
+                oCn.RollBack();
+                sReturn = e.Message;
+                throw (e);
+            }
+        }
+
+        //瀹℃壒娴�-瀹℃牳(鍖呭惈瀹℃牳鍚庢帶鍒躲�佸啓鍏ユ棩蹇�)    2024-01-31
+        public bool CheckBill(SQLHelper.ClsCN oCN,Int64 lngBillKey, string HBillNo, string procName, string sUser, ref string sReturn)
+        {
+            string sql = "";
+            DataSet ds;
+            try
+            {
+                string HChecker = sUser;
+                string HCheckDate = ClsPub.GetServerDate(-1);
+
+                //鏇存柊鍗曟嵁鐘舵��
+                oCN.RunProc(" Update " + MvarItemKey + " set HChecker='" + HChecker + "',HCheckDate='" + HCheckDate + "',HBillStatus=2 Where HInterID=" + lngBillKey.ToString());
+
+                //瀹℃牳鍚庢帶鍒�
+                sql = "exec " + procName + " " + lngBillKey + ",'" + HBillNo + "','" + sUser + "'";
+                ds = oCN.RunProcReturn(sql, procName);
+                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "瀹℃牳杩囩▼涓嚭閿欙紝璇蜂笌缃戠粶绠$悊浜哄憳鑱旂郴";
+                    return false;
+                }
+                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                {
+                    sReturn = ds.Tables[0].Rows[0]["HRemark"].ToString();
+                    return false;
+                }
+                //瀹℃牳鍚� 鏇存柊鍙婃椂搴撳瓨琛� 澧炲姞搴撳瓨
+                sql = "select * from  " + MvarItemKey + " where HInterID=" + lngBillKey.ToString();
+                ds = oCN.RunProcReturn(sql, MvarItemKey);
+                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
+                {
+                    string HBillType = ds.Tables[0].Rows[0]["HBillType"].ToString();
+                    if (HBillType == "1201" || HBillType == "1202" || HBillType == "1203" || HBillType == "1247" || HBillType == "1244" || HBillType == "1251" || HBillType == "1210" || HBillType == "1250" || HBillType == "1206" || HBillType == "1245" || HBillType == "1239")
+                    {
+                        //瀹℃牳鏇存柊 鍙婃椂搴撳瓨琛� 澧炲姞搴撳瓨 1201 1202 1203 1247 1244 1251 1210
+                        //瀹℃牳鏇存柊 鍙婃椂搴撳瓨琛� 鍑忓皯搴撳瓨 1204 1250 1206 1245 1239 
+                        ds = oCN.RunProcReturn("exec h_KF_UPDateICinventory  '" + lngBillKey.ToString() + "','" + HBillType + "','1'", "h_KF_UPDateICinventory");
+                    }
+                }
+                //鍐欏叆鏃ュ織
+                string WorkList = "瀹℃牳鍗曟嵁锛屽崟鎹彿锛�" + HBillNo;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCN.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','瀹℃牳')"
+                    );
+
+                sReturn = "瀹℃牳鍗曟嵁鎴愬姛锛�";
+                return true;
+            }
+            catch (Exception e)
+            {
+                sReturn = e.Message;
+                throw (e);
+            }
+        }
+
         //鍏抽棴
         public bool CloseBill(Int64 lngBillKey, ref string sReturn)
         {
@@ -138,7 +813,7 @@
             {
                 string HCloseMan = ClsPub.CurUserName;
                 string HCloseDate = ClsPub.GetServerDate(-1); 
-                oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='" + HCloseMan + "',HCloseDate='" + HCloseDate + "' Where HInterID=" + lngBillKey.ToString());
+                oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='" + HCloseMan + "',HCloseDate='" + HCloseDate + "',HBillStatus=3,HCloseType = 1 Where HInterID=" + lngBillKey.ToString());
                 sReturn = "";
                 return true;
             }
@@ -148,21 +823,138 @@
                 throw (e);
             }
         }
-        //鍏抽棴
-        public bool CloseBill(Int64 lngBillKey, string sUser, ref string sReturn)
+        //鍏抽棴鍗曟嵁(鍖呭惈鍐欏叆鏃ュ織)    2024-01-31
+        public bool CloseBill(Int64 lngBillKey, string HBillNo, string sUser, ref string sReturn)
         {
-
             try
             {
+                oCn.BeginTran();
                 string HCloseMan = sUser;
                 string HCloseDate = ClsPub.GetServerDate(-1);
-                oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='" + HCloseMan + "',HCloseDate='" + HCloseDate + "' Where HInterID=" + lngBillKey.ToString());
-                sReturn = "";
+                oCn.RunProc(" Update " + MvarItemKey + " set HCloseMan='" + HCloseMan + "',HCloseDate='" + HCloseDate + "',HBillStatus=3,HCloseType = 1 Where HInterID=" + lngBillKey.ToString());
+                
+                //鍐欏叆鏃ュ織
+                string WorkList = "鍏抽棴鍗曟嵁锛屽崟鎹彿锛�" + HBillNo;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','鍏抽棴')"
+                    );
+
+                sReturn = "鍏抽棴鍗曟嵁鎴愬姛锛�";
+                oCn.Commit();
                 return true;
             }
             catch (Exception e)
             {
                 sReturn = e.Message;
+                oCn.RollBack();
+                throw (e);
+            }
+        }
+
+        //琛屽叧闂崟鎹紙琛屽叧闂悗鎺у埗锛�(鍖呭惈鍐欏叆鏃ュ織)    2024-01-31
+        public bool CloseRow(Int64 lngBillKey, Int64 HEntryID, string HBillNo, string sUser, string procName, ref string sReturn)
+        {
+            DataSet ds;
+            try
+            {
+                oCn.BeginTran();
+                string HCloseMan = sUser;
+                string HEntryCloseDate = ClsPub.GetServerDate(-1);
+                //鍙樻洿琛屽叧闂姸鎬�
+                string sql = " Update " + MvarItemKeySub + " set HCloseMan='" + HCloseMan + "',HEntryCloseDate='" + HEntryCloseDate + "',HCloseType=1 Where HInterID=" + lngBillKey.ToString() + " and HEntryID = " + HEntryID;
+                oCn.RunProc(sql);
+
+                //妫�鏌ュ崟鎹瓙琛ㄦ墍鏈夎鏄惁閮藉叧闂紝鑻ラ兘鍏抽棴鍒欒嚜鍔ㄥ叧闂崟鎹�
+                //sql = "select * from " + MvarItemKeySub + " where HInterID=" + lngBillKey + " and HCloseMan=''";
+                //ds = oCn.RunProcReturn(sql, MvarItemKeySub);
+                //if(ds!=null && ds.Tables[0].Rows.Count == 0)
+                //{
+                //    sql = " Update " + MvarItemKey + " set HCloseMan='" + HCloseMan + "',HCloseDate=getdate(),HBillStatus=3,HCloseType = 0 Where HInterID=" + lngBillKey.ToString();
+                //    oCn.RunProc(sql);
+                //}
+
+                //鍐欏叆鏃ュ織
+                string WorkList = "琛屽叧闂紝鍗曟嵁鍙凤細" + HBillNo + "锛涘瓙琛ㄥ唴鐮侊細" + HEntryID;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','琛屽叧闂�')"
+                    );
+
+
+
+                //琛屽叧闂悗鎺у埗=========================================      
+                string sql_afterClose = "exec " + procName + " " + lngBillKey + "," + HEntryID + ",'" + HBillNo + "','" + sUser + "'";
+                DataSet ds_afterClose = oCn.RunProcReturn(sql_afterClose, procName);
+                if (ds_afterClose == null || ds_afterClose.Tables[0].Rows.Count <= 0)
+                {
+                    sReturn = "琛屽叧闂け璐ワ紝鍘熷洜锛氳鍏抽棴鍚庢帶鍒堕敊璇紝璇疯仈绯荤綉缁滅鐞嗕汉鍛橈紒";
+
+                    oCn.RollBack();
+
+                    return false;
+                }
+                else
+                {
+                    if (ds_afterClose.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                    {
+                        sReturn = "鍏抽棴澶辫触锛屽師鍥狅細" + ds_afterClose.Tables[0].Rows[0]["HRemark"].ToString();
+                        oCn.RollBack();
+
+                        return false;
+                    }
+                }
+                //=========================================
+
+
+                sReturn = "琛屽叧闂垚鍔燂紒";
+                oCn.Commit();
+                return true;
+            }
+            catch (Exception e)
+            {
+                sReturn = e.Message;
+                oCn.RollBack();
+                throw (e);
+            }
+        }
+        //琛屽叧闂崟鎹�(鍖呭惈鍐欏叆鏃ュ織)    2024-01-31
+        public bool CloseRow(Int64 lngBillKey,Int64 HEntryID, string HBillNo, string sUser, ref string sReturn)
+        {
+            DataSet ds;
+            try
+            {
+                oCn.BeginTran();
+                string HCloseMan = sUser;
+                string HEntryCloseDate = ClsPub.GetServerDate(-1);
+                //鍙樻洿琛屽叧闂姸鎬�
+                string sql = " Update " + MvarItemKeySub + " set HCloseMan='" + HCloseMan + "',HEntryCloseDate='" + HEntryCloseDate + "',HCloseType=1 Where HInterID=" + lngBillKey.ToString() + " and HEntryID = " + HEntryID;
+                oCn.RunProc(sql);
+
+                //妫�鏌ュ崟鎹瓙琛ㄦ墍鏈夎鏄惁閮藉叧闂紝鑻ラ兘鍏抽棴鍒欒嚜鍔ㄥ叧闂崟鎹�
+                //sql = "select * from " + MvarItemKeySub + " where HInterID=" + lngBillKey + " and HCloseMan=''";
+                //ds = oCn.RunProcReturn(sql, MvarItemKeySub);
+                //if(ds!=null && ds.Tables[0].Rows.Count == 0)
+                //{
+                //    sql = " Update " + MvarItemKey + " set HCloseMan='" + HCloseMan + "',HCloseDate=getdate(),HBillStatus=3,HCloseType = 0 Where HInterID=" + lngBillKey.ToString();
+                //    oCn.RunProc(sql);
+                //}
+
+                //鍐欏叆鏃ュ織
+                string WorkList = "琛屽叧闂紝鍗曟嵁鍙凤細" + HBillNo + "锛涘瓙琛ㄥ唴鐮侊細" + HEntryID;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','琛屽叧闂�')"
+                    );
+
+                sReturn = "琛屽叧闂垚鍔燂紒";
+                oCn.Commit();
+                return true;
+            }
+            catch (Exception e)
+            {
+                sReturn = e.Message;
+                oCn.RollBack();
                 throw (e);
             }
         }
@@ -173,7 +965,7 @@
             {
                 string HDeleteMan = ClsPub.CurUserName;
                 string HDeleteDate = ClsPub.GetServerDate(-1);
-                oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='" + HDeleteMan + "',HDeleteDate='" + HDeleteDate + "' Where HInterID=" + lngBillKey.ToString());
+                oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='" + HDeleteMan + "',HDeleteDate='" + HDeleteDate + "',HBillStatus=4 Where HInterID=" + lngBillKey.ToString());
                 sReturn = "";
                 return true;
             }
@@ -184,29 +976,40 @@
             }
         }
 
-        //浣滃簾
-        public bool Cancelltion(Int64 lngBillKey,string sUser, ref string sReturn)
+        //浣滃簾鍗曟嵁(鍖呭惈鍐欏叆鏃ュ織)    2024-01-31
+        public bool Cancelltion(Int64 lngBillKey, string HBillNo, string sUser, ref string sReturn)
         {
             try
             {
+                oCn.BeginTran();
                 string HDeleteMan = sUser;
                 string HDeleteDate = ClsPub.GetServerDate(-1);
-                oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='" + HDeleteMan + "',HDeleteDate='" + HDeleteDate + "' Where HInterID=" + lngBillKey.ToString());
-                sReturn = "";
+                oCn.RunProc(" Update " + MvarItemKey + " set HDeleteMan='" + HDeleteMan + "',HDeleteDate='" + HDeleteDate + "',HBillStatus=4 Where HInterID=" + lngBillKey.ToString());
+                
+                //鍐欏叆鏃ュ織
+                string WorkList = "浣滃簾鍗曟嵁锛屽崟鎹彿锛�" + HBillNo;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','浣滃簾')"
+                    );
+
+                sReturn = "浣滃簾鍗曟嵁鎴愬姛锛�";
+                oCn.Commit();
                 return true;
             }
             catch (Exception e)
             {
                 sReturn = e.Message;
+                oCn.RollBack();
                 throw (e);
             }
         }
-        //鍒犻櫎瀛愯〃
+        //淇濆吇璁″垝鍒犻櫎瀛愯〃1
         public void DeleteBillSub(Int64 lngBillKey)
         {
             oCn.RunProc("Delete From " + MvarItemKeySub + "  where HInterID=" + lngBillKey.ToString());
         }
-        //鍒犻櫎瀛愯〃
+        //淇濆吇璁″垝鍒犻櫎瀛愯〃2
         public void DeleteBillSub2(Int64 lngBillKey)
         {
             if (MvarItemKeySub2 != "")
@@ -250,6 +1053,57 @@
                 DeleteBillSub4(lngBillKey);
                 //鍒犻櫎涓昏〃
                 DeleteBillMain(lngBillKey);
+                sReturn = "鍒犻櫎鍗曟嵁鎴愬姛锛�";
+                oCn.Commit();
+                return true;
+            }
+            catch (Exception e)
+            {
+                sReturn = e.Message;
+                oCn.RollBack();
+                throw (e);
+            }
+        }
+        //鍒犻櫎鍗曟嵁(鍖呭惈鍒犻櫎鍚庢帶鍒躲�佸啓鍏ユ棩蹇�)    2024-01-31
+        public bool DeleteBill(Int64 lngBillKey, string HBillNo, string procName, string sUser, ref string sReturn)
+        {
+            string sql = "";
+            DataSet ds;
+            try
+            {
+                oCn.BeginTran();
+                //鍒犻櫎鍏宠仈
+                DeleteRelation(ref sReturn, lngBillKey);
+                //鍒犻櫎鏄庣粏琛�
+                DeleteBillSub(lngBillKey);
+                DeleteBillSub2(lngBillKey);
+                DeleteBillSub3(lngBillKey);
+                DeleteBillSub4(lngBillKey);
+                //鍒犻櫎涓昏〃
+                DeleteBillMain(lngBillKey);
+
+                //鍒犻櫎鍚庢帶鍒�
+                sql = "exec " + procName + " " + lngBillKey + ",'" + HBillNo + "','" + sUser + "'";
+                ds = oCn.RunProcReturn(sql, procName);
+                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
+                {
+                    sReturn = "鍒犻櫎杩囩▼涓嚭閿欙紝璇蜂笌缃戠粶绠$悊浜哄憳鑱旂郴";
+                    oCn.RollBack();
+                    return false;
+                }
+                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
+                {
+                    sReturn = ds.Tables[0].Rows[0]["HRemark"].ToString();
+                    oCn.RollBack();
+                    return false;
+                }
+                //鍐欏叆鏃ュ織
+                string WorkList = "鍒犻櫎鍗曟嵁锛屽崟鎹彿锛�" + HBillNo;
+                string SystemName = "LMES-" + MvarReportTitle + "妯″潡";
+                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
+                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','鍒犻櫎')"
+                    );
+
                 sReturn = "鍒犻櫎鍗曟嵁鎴愬姛锛�";
                 oCn.Commit();
                 return true;
@@ -463,9 +1317,10 @@
         //鍗曟嵁鍙锋槸鍚﹂噸澶�
         public virtual bool IsExistBillNo(ref string sReturn, string sBillNo, ClsPub.Enum_BillStatus oBillStatus, Int64 lngBillKey)
         {
+            string sSql = "";
             try
             {
-                string sSql = "";
+           
                 if (oBillStatus == ClsPub.Enum_BillStatus.BillStatus_AddNew)
                 {
                     sSql = "Select HInterID from " + MvarItemKey + "  where hbilltype='" + BillType + "'and HBillNO ='" + sBillNo + "'";
@@ -486,8 +1341,8 @@
             }
             catch (Exception e)
             {
-                sReturn = e.Message;
-                throw (e);
+                sReturn = e.Message+"sql:"+ sSql;
+                return false;
             }
         }
         #endregion

--
Gitblit v1.9.1