yangle
2024-02-26 14d1953a72b762f1f5e93f07964fc9747a783ea5
WebAPI/Controllers/²Ö´æ¹ÜÀí/ÁìÁÏ·¢»õ/Kf_StepFoldOutBillController.cs
@@ -5,6 +5,9 @@
using System.Web;
using System.Web.Http;
using WebAPI.Models;
using Newtonsoft.Json.Linq;
using Model;
using DBUtility;
namespace WebAPI.Controllers.仓存管理.领料发货
{
@@ -14,34 +17,76 @@
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        public DAL.ClsKf_StepFoldOutBill BillOld = new DAL.ClsKf_StepFoldOutBill();
        #region åˆ†æ­¥å¼è°ƒå‡ºå• æŸ¥è¯¢
        #region åˆ†æ­¥å¼è°ƒå‡ºå• è¿”回列表
        [Route("Kf_StepFoldOutBill/GetStepFoldOutBillList")]
        [HttpGet]
        public object GetStepFoldOutBillList(string sWhere, string user, string Organization)
        //public object GetStepFoldOutBillList(string sWhere, string user, string Organization)
        //{
        //    try
        //    {
        //        //判断是否有查询权限
        //        if (!DBUtility.ClsPub.Security_Log("Kf_MoveStockStepOutBillQuery", 1, false, user))
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "无查询权限!";
        //            objJsonResult.data = null;
        //            return objJsonResult;
        //        }
        //        string sql1 = string.Format("select * from h_v_IF_StepFoldOutBillList where (调入组织='" + Organization + "')");
        //        if (sWhere == null || sWhere.Equals(""))
        //        {
        //            ds = oCn.RunProcReturn(sql1 + " order by hmainid desc", "h_v_IF_StepFoldOutBillList");
        //        }
        //        else
        //        {
        //            string sql = sql1 + sWhere + " order by hmainid desc";
        //            ds = oCn.RunProcReturn(sql, "h_v_IF_StepFoldOutBillList");
        //        }
        //        //if (ds.Tables[0].Rows.Count != 0 || ds != null)
        //        //{
        //        objJsonResult.code = "1";
        //        objJsonResult.count = 1;
        //        objJsonResult.Message = "Sucess!";
        //        objJsonResult.data = ds.Tables[0];
        //        return objJsonResult;
        //        //}
        //        //else
        //        //{
        //        //objJsonResult.code = "0";
        //        //objJsonResult.count = 0;
        //        //objJsonResult.Message = "无数据";
        //        //objJsonResult.data = null;
        //        //return objJsonResult;
        //        //}
        //    }
        //    catch (Exception ex)
        //    {
        //        objJsonResult.code = "0";
        //        objJsonResult.count = 0;
        //        objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
        //        objJsonResult.data = null;
        //        return objJsonResult;
        //    }
        //}
        public object list(string sWhere)
        {
            try
            {
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Kf_MoveStockStepOutBillQuery", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查询权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                string sql1 = string.Format("select * from h_v_Kf_MoveStockStepOutBillList where (调入组织='" + Organization + "')");
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCn.RunProcReturn(sql1 + " order by hmainid desc", "h_v_Kf_MoveStockStepOutBillList");
                    ds = oCn.RunProcReturn("select * from h_v_IF_StepFoldOutBillList order by hmainid desc", "h_v_IF_StepFoldOutBillList");
                }
                else
                {
                    string sql1 = "select * from h_v_IF_StepFoldOutBillList where 1 = 1 ";
                    string sql = sql1 + sWhere + " order by hmainid desc";
                    ds = oCn.RunProcReturn(sql, "h_v_Kf_MoveStockStepOutBillList");
                    ds = oCn.RunProcReturn(sql, "h_v_IF_StepFoldOutBillList");
                }
                //if (ds.Tables[0].Rows.Count != 0 || ds != null)
@@ -61,16 +106,659 @@
                //return objJsonResult;
                //}
            }
            catch (Exception ex)
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region åˆ†æ­¥å¼è°ƒå‡ºå• æŸ¥è¯¢
        [Route("Kf_StepFoldOutBill/cx")]
        [HttpGet]
        public object cx(long HInterID)
        {
            try
            {
                ds = oCn.RunProcReturn("select * from h_v_IF_StepFoldOutBillList where hmainid =" + HInterID, "h_v_IF_StepFoldOutBillList");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "false!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region åˆ†æ­¥å¼è°ƒå‡ºå• ä¿å­˜/编辑功能
        [Route("Kf_StepFoldOutBill/Kf_StepFoldOutBillEdit")]
        [HttpPost]
        public object StepFoldOutBillEdit([FromBody] JObject sMainSub)
        {
            try
            {
                var _value = sMainSub["sMainSub"].ToString();
                string msg1 = _value.ToString();
                oCn.BeginTran();
                //保存主表
                objJsonResult = AddBillMain(msg1);
                if (objJsonResult.code == "0")
                {
                    oCn.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCn.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "单据保存成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        public json AddBillMain(string msg1)
        {
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString(); //主表数据
            string msg3 = sArray[1].ToString(); //子表数据
            int OperationType = int.Parse(sArray[2].ToString()); // æ•°æ®ç±»åž‹ 1添加 3修改
            string user = sArray[3].ToString();
            string msg_allVal = sArray[4].ToString(); //主表+子表所有数据
            try
            {
                msg2 = "[" + msg2.ToString() + "]";
                List<ClsKf_StepFoldOutBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_StepFoldOutBillMain>>(msg2);
                long HInterID = mainList[0].HInterID;//递入type得到的单据ID
                string HBillNo = mainList[0].HBillNo;//递入type得到的单据号
                long HPRDORGID = mainList[0].HPRDORGID;//组织
                DateTime HDate = mainList[0].HDate;//日期
                string HRemark = mainList[0].HRemark;//备注
                long HSupID = mainList[0].HSupID;//供应商
                long HEmpID = mainList[0].HEmpID;//仓管员
                long HDeptID = mainList[0].HDeptID;//部门
                long HWHID = mainList[0].HWHID;//调入仓库
                long HSCWHID = mainList[0].HSCWHID;//调出仓库
                long HManagerID = mainList[0].HManagerID;//负责人
                long HSecManagerID = mainList[0].HSecManagerID;//验收员
                long HKeeperID = mainList[0].HKeeperID;//保管员
                string HMaker = user;//制单人
                string HExplanation = mainList[0].HExplanation;//摘要
                string HInnerBillNo = mainList[0].HInnerBillNo;//内部单据号
                string HBillType = mainList[0].HBillType;
                string HBillSubType = mainList[0].HBillSubType;
                long HBillStatus = mainList[0].HBillStatus;
                string HMakeDate = mainList[0].HMakeDate;
                string HChecker = mainList[0].HChecker;
                string HCheckDate = mainList[0].HCheckDate;
                string HUpDater = mainList[0].HUpDater;
                string HUpDateDate = mainList[0].HUpDateDate;
                string HDeleteMan = mainList[0].HDeleteMan;
                string HDeleteDate = mainList[0].HDeleteDate;
                string HCloseMan = mainList[0].HCloseMan;
                string HCloseDate = mainList[0].HCloseDate;
                long HCurID = mainList[0].HCurID;
                ds = oCn.RunProcReturn("select * from h_v_IF_StepFoldOutBillList where hmainid=" + HInterID + " and å•据号='" + HBillNo + "'", "h_v_IF_StepFoldOutBillList");
                if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//新增
                {
                    //主表
                    oCn.RunProc(@"Insert Into Kf_ICStockBillMain
                        (HInterID,HBillNo,HDate,HBillType,HBillSubType,HBillStatus,HYear,HPeriod
                       ,HSupID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID,HKeeperID,HDeptID
                       ,HMaker,HMakeDate,HChecker,HUpDater
                       ,HDeleteMan,HCloseMan
                       ,HRemark,HExplanation,HInnerBillNo,HCurID)
                        values(" + HInterID + ",'" + HBillNo + "','" + HDate + "','" + 1250 + "','" +
                    HBillSubType + "'," + HBillStatus + "," + DateTime.Now.Year + "," + DateTime.Now.Month + "," + HSupID +
                    "," + HWHID + "," + HSCWHID + "," + HEmpID + "," + HManagerID + "," + HSecManagerID +
                    "," + HKeeperID + "," + HDeptID + ",'" + HMaker + "','" + HMakeDate + "','" + HChecker + "','" + HUpDater + "','" + HDeleteMan + "','" + HCloseMan + "','"
                    + HRemark + "','" + HExplanation + "','" + HInnerBillNo + "'," + HCurID + "" + ")");
                }
                else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0)
                { //修改
                    String sql="update Kf_ICStockBillMain   set " +
                                "HRemark='" + HRemark + "', HUpDater='" + HMaker + "', HUpDateDate=getdate()" + " where HInterID=" + "HInterID";
                    oCn.RunProc(sql);
                    //删除子表
                    oCn.RunProc("delete from Kf_ICStockBillSub where HInterID='" + HInterID + "'");
                }
                //保存子表
                objJsonResult = AddBillSub(msg3, HInterID, OperationType);
                if (objJsonResult.code == "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = null;
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        public json AddBillSub(string msg3, long HInterID, int OperationType)
        {
            List<ClsKf_StepFoldOutBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_StepFoldOutBillSub>>(msg3);
            int i = 0;
            foreach (ClsKf_StepFoldOutBillSub oSub in DetailColl)
            {
                i++;
                if (oSub.HQty <= 0 || oSub.HQty == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "第" + i + "行,数量不能为0或者小于0";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HMaterID == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "第" + i + "行,物料不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HUnitID == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "第" + i + "行,计量单位不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DataSet Cs;
                Int64 NewHEntryID = 1;
                Cs = oCn.RunProcReturn("select MAX(HEntryID)HEntryID from Kf_ICStockBillSub", "Kf_ICStockBillSub");
                if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()) != 0)
                {
                    NewHEntryID = ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString());
                    NewHEntryID += 1;
                }
                oCn.RunProc($@"Insert into Kf_ICStockBillSub
                (HInterID,HEntryID,HRemark
               ,HMaterID,HUnitID,HSecUnitID,HPropertyID,HBatchNo
               ,HWHID,HSCWHID,HSPID,HSCSPID
               ,HQtyMust,HQty,HRelationQty,HRelationMoney,HSecUnitRate,HPrice,HMoney,HOrderPrice
               ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType
               ,HPOOrderInterID,HPOOrderEntryID,HPOOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HSeOrderBillNo)
                 values({HInterID},{NewHEntryID},'{oSub.HRemark}'
                ,{oSub.HMaterID},{oSub.HUnitID},{oSub.HSecUnitID},{oSub.HPropertyID},'{oSub.HBatchNo}',{oSub.HWHID},{oSub.HSCWHID}
                ,{oSub.HSPID},{oSub.HSCSPID},{oSub.HQtyMust},{(oSub.HQty == null ? 0 : oSub.HQty)},{oSub.HRelationQty},{oSub.HRelationMoney},{oSub.HSecUnitRate}
                ,{oSub.HPrice},{oSub.HMoney},{oSub.HOrderPrice}
                ,{oSub.HSourceInterID},{oSub.HSourceEntryID},'{oSub.HSourceBillNo}','{oSub.HSourceBillType}',{oSub.HPOOrderInterID},{oSub.HPOOrderEntryID}
                ,'{oSub.HPOOrderBillNo}',{oSub.HSeOrderInterID},{oSub.HSeOrderEntryID},'{oSub.HSeOrderBillNo}')");
            }
            objJsonResult.code = "1";
            objJsonResult.count = 1;
            objJsonResult.Message = null;
            objJsonResult.data = null;
            return objJsonResult;
        }
        #endregion
        #region åˆ†æ­¥å¼è°ƒå‡ºå• åˆ é™¤åŠŸèƒ½
        [Route("Fb_StepFoldOutBill/DeltetFb_StepFoldOutBill")]
        [HttpGet]
        public object DeltetFb_StepFoldOutBill(string HInterID)
        {
            try
            {
                oCn.BeginTran();
                oCn.RunProc("Delete From Kf_ICStockBillMain where HInterID = " + HInterID);
                oCn.RunProc("Delete From Kf_ICStockBillSub where HInterID = " + HInterID);
                oCn.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "删除成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region åˆ†æ­¥å¼è°ƒå‡ºå• å®¡æ ¸/反审核
        /// <summary>
        ///
        /// </summary>
        /// <param name="HInterID">单据ID</param>
        /// <param name="IsAudit">审核(0),反审核(1)</param>
        /// <param name="CurUserName">审核人</param>
        /// <returns></returns>
        [Route("Kf_StepFoldOutBill/AuditKf_StepFoldOutBill")]
        [HttpGet]
        public object AuditKf_StepFoldOutBill(string HInterID, int Type, string user)
        {
            string sql = "";
            //ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
            try
            {
                //判断是否有审核权限
                if (!DBUtility.ClsPub.Security_Log("Kf_MoveStockStepOutBill_Check", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限审核!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ClsPub.CurUserName = user;
                BillOld.MvarItemKey = "Kf_ICStockBillMain";
                ds = oCn.RunProcReturn("select * from Kf_ICStockBillMain where HInterID = " + int.Parse(HInterID), "Kf_ICStockBillMain");
                string HBillNo = "";
                oCn.BeginTran();//开始事务
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据不存在!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                }
                //Type 1 å®¡æ ¸  2  åå®¡æ ¸
                if (Type == 1)
                {
                    //审核前控制
                    sql = "exec h_p_Cg_POInStockBill_BeforeCheckCtrl " + int.Parse(HInterID) + ",'" + HBillNo + "','" + user + "'";
                    ds = oCn.RunProcReturn(sql, "h_p_Cg_POInStockBill_BeforeCheckCtrl");
                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:审核前判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (!BillOld.CheckBill(int.Parse(HInterID), HBillNo, "h_p_Cg_POInStockBill_AfterCheckCtrl", user, ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    //反审核前控制
                    sql = "exec h_p_Cg_POInStockBill_BeforeUnCheckCtrl " + int.Parse(HInterID) + ",'" + HBillNo + "','" + user + "'";
                    ds = oCn.RunProcReturn(sql, "h_p_Cg_POInStockBill_BeforeUnCheckCtrl");
                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反审核失败!原因:反审核前判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (BillOld.AbandonCheck(int.Parse(HInterID), HBillNo, "h_p_Cg_POInStockBill_AfterUnCheckCtrl", user, ref ClsPub.sExeReturnInfo))
                    {
                        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "执行成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region åˆ†æ­¥å¼è°ƒå‡ºå• å…³é—­/反关闭功能
        [Route("Kf_StepFoldOutBill/CloseKf_StepFoldOutBill")]
        [HttpGet]
        public object CloseKf_StepFoldOutBill(string HInterID, int Type, string user)
        {
            try
            {
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Kf_MoveStockStepOutBill_Close", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限关闭!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ClsPub.CurUserName = user;
                BillOld.MvarItemKey = "Kf_ICStockBillMain";
                oCn.BeginTran();//开始事务
                //Type 1 å…³é—­  2  åå…³é—­
                if (Type == 1)
                {
                    //判断单据是否已经关闭
                    DataSet ds;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCn.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds == null || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据不存在!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["HDeleteMan"] != null && ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据已作废!不能进行关闭!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //if (ds.Tables[0].Rows[0]["HChecker"] == null || ds.Tables[0].Rows[0]["HChecker"].ToString() == "")
                        //{
                        //    objJsonResult.code = "0";
                        //    objJsonResult.count = 0;
                        //    objJsonResult.Message = "单据未审核!不能进行关闭!";
                        //    objJsonResult.data = null;
                        //    return objJsonResult;
                        //}
                        if (ds.Tables[0].Rows[0]["HCloseMan"] != null && ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据已关闭!不能再次关闭!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //关闭单据
                        if (!BillOld.CloseBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "关闭失败!原因:" + ClsPub.sExeReturnInfo;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                }
                else
                {
                    //判断单据是否已经反关闭
                    DataSet ds;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCn.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["HDeleteMan"] != null && ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据已作废!不能进行关闭!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //if (ds.Tables[0].Rows[0]["HChecker"] == null || ds.Tables[0].Rows[0]["HChecker"].ToString() == "")
                        //{
                        //    objJsonResult.code = "0";
                        //    objJsonResult.count = 0;
                        //    objJsonResult.Message = "单据未审核!不能进行关闭!";
                        //    objJsonResult.data = null;
                        //    return objJsonResult;
                        //}
                        if (ds.Tables[0].Rows[0]["HCloseMan"] == null || ds.Tables[0].Rows[0]["HCloseMan"].ToString() == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据未关闭!不需要再反关闭!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //反关闭单据
                        if (!BillOld.CancelClose(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 1;
                            objJsonResult.Message = "反关闭失败!原因:" + ClsPub.sExeReturnInfo;
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                }
                oCn.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "执行成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region åˆ†æ­¥å¼è°ƒå‡ºå• ä½œåºŸ/反作废功能
        [Route("Kf_StepFoldOutBill/CancellKf_StepFoldOutBill")]
        [HttpGet]
        public object CancellKf_StepFoldOutBill(string HInterID, int Type, string user)
        {
            try
            {
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Kf_MoveStockStepOutBill_Delete", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限作废!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ClsPub.CurUserName = user;
                oCn.BeginTran();//开始事务
                //Type 1 ä½œåºŸ  2  åä½œåºŸ
                if (Type == 1)
                {
                    if (!BillOld.Cancelltion(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "作废失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    if (!BillOld.AbandonCancelltion(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反作废失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                oCn.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "执行成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}