yangle
2023-11-07 0f72c941f402f624cc6b5d364724d08d6f60dfc3
WebAPI/Controllers/CJGL/Sc_ProcExchWorkBackBillController.cs
@@ -16,6 +16,7 @@
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill();
        DataSet ds;
        #region 工序返工申请单列表
@@ -77,7 +78,7 @@
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                string sql = string.Format(@"select top 2 * from h_v_Sc_ProcessExchangeBillQuerySub");
                ds = oCN.RunProcReturn(sql + sWhere, "h_v_Sc_ProcessExchangeBillQuerySub");
                ds = oCN.RunProcReturn(sql + sWhere + " order by cast(流水号 as int) ", "h_v_Sc_ProcessExchangeBillQuerySub");
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "获取信息成功!";
@@ -145,6 +146,14 @@
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    if (oItem.HChecker != "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!单据已审核,无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
@@ -301,102 +310,348 @@
        }
        #endregion
        #region 工序返工申请单 审核
        [Route("Sc_ProcExchWorkBackBill/set_CheckBill")]
        //#region 工序返工申请单 审核
        //[Route("Sc_ProcExchWorkBackBill/set_CheckBill")]
        //[HttpGet]
        //public object set_CheckBill(int HInterID, string CurUserName)
        //{
        //    try
        //    {
        //        //审核权限
        //        if (!DBUtility.ClsPub.Security_Log("Sc_ProcExchWorkBackBill_Check", 1, false, CurUserName))
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "审核失败!无权限!";
        //            objJsonResult.data = null;
        //            return objJsonResult;
        //        }
        //        if (HInterID == 0)
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = "单据ID为0,不能审核!";
        //            objJsonResult.data = null;
        //            return objJsonResult;
        //        }
        //        DataSet Ds = oCN.RunProcReturn("Select * from Sc_ProcExchWorkBackBillMain Where HInterID=" + HInterID, "Sc_ProcExchWorkBackBillMain");
        //        if (Ds.Tables[0].Rows.Count > 0)
        //        {
        //            //查看是否已审核,关闭,作废
        //            if (Ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
        //            {
        //                objJsonResult.code = "0";
        //                objJsonResult.count = 0;
        //                objJsonResult.Message = "单据已审核!不能再次审核";
        //                objJsonResult.data = null;
        //                return objJsonResult;
        //            }
        //            //审核
        //            if (Cj_StationInBillCheckBill(HInterID,int.Parse( Ds.Tables[0].Rows[0]["HProcExchInterID"].ToString()), CurUserName, ref DBUtility.ClsPub.sExeReturnInfo))
        //            {
        //                objJsonResult.code = "1";
        //                objJsonResult.count = 1;
        //                objJsonResult.Message = "审核成功!";
        //                objJsonResult.data = null;
        //                return objJsonResult;
        //            }
        //            else
        //            {
        //                objJsonResult.code = "0";
        //                objJsonResult.count = 0;
        //                objJsonResult.Message = "审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
        //                objJsonResult.data = null;
        //                return objJsonResult;
        //            }
        //        }
        //        else
        //        {
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            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;
        //    }
        //}
        ////审核
        //public bool Cj_StationInBillCheckBill(Int64 HInterID,int HProcExchInterID, string CurUserName, ref string sReturn)
        //{
        //    try
        //    {
        //        oCN.BeginTran();
        //        oCN.RunProc(" Update Sc_ProcExchWorkBackBillMain set HChecker='" + CurUserName + "',HBillStatus=2,HCheckDate=getdate() Where HInterID=" + HInterID.ToString());
        //        //回填工序流转卡
        //        oCN.RunProc("exec h_p_ProcExchWorkBackBill_Check_In " + HInterID.ToString());
        //        oCN.RunProc("exec h_p_Sc_ProcessExchangeBill_SetRemark " + HProcExchInterID.ToString()); //设置 备注 为 工艺流
        //        oCN.RunProc("exec h_p_Sc_ProcessExchangeBill_SetUpdate " + HProcExchInterID.ToString()); //设置 末道 首道 转 等信息   器具清单  工艺参数清单;
        //        DataSet ds = new DataSet();
        //        //设置条码号  回填 领料批次
        //        ds = oCN.RunProcReturn("exec h_p_Mes_ProcessExchangeBackBarCode " + HProcExchInterID.ToString(), "h_p_Mes_ProcessExchangeBackBarCode");
        //        if (DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HBack"]) != 0)
        //        {
        //            sReturn = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]).ToString();
        //            oCN.RollBack();
        //            return false;
        //        }
        //        //控制关联数量
        //        ds = null;
        //        ds = oCN.RunProcReturn("exec h_p_Sc_ProcessExchangeBill_Checkqty " + HProcExchInterID.ToString(), "h_p_Sc_ProcessExchangeBill_Checkqty");
        //        if (DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HBack"]) != 0)
        //        {
        //            sReturn = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]).ToString();
        //            oCN.RollBack();
        //            return false;
        //        }
        //        oCN.Commit();
        //        return true;
        //    }
        //    catch (Exception e)
        //    {
        //        sReturn = e.Message;
        //        oCN.RollBack();
        //        return false; ;
        //    }
        //}
        //#endregion
        #region 工艺路线审核/反审核功能
        [Route("Sc_ProcExchWorkBackBill/CheckSc_ProcExchWorkBackBill")]
        [HttpGet]
        public object set_CheckBill(int HInterID, string CurUserName)
        public object CheckSc_ProcExchWorkBackBill(string HInterID, int Type, string user)
        {
            try
            {
                //审核权限
                if (!DBUtility.ClsPub.Security_Log("Sc_ProcExchWorkBackBill_Check", 1, false, CurUserName))
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Sc_ProcExchWorkBackBill_Check", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "审核失败!无权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (HInterID == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据ID为0,不能审核!";
                    objJsonResult.Message = "无权限审核!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DataSet Ds = oCN.RunProcReturn("Select * from Sc_ProcExchWorkBackBillMain Where HInterID=" + HInterID, "Sc_ProcExchWorkBackBillMain");
                if (Ds.Tables[0].Rows.Count > 0)
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    //查看是否已审核,关闭,作废
                    if (Ds.Tables[0].Rows[0]["HChecker"].ToString() != "")
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ClsPub.CurUserName = user;
                BillOld.MvarItemKey = "Sc_ProcExchWorkBackBillMain";
                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.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        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 (!BillOld.CheckBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已审核!不能再次审核";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //审核
                    if (Cj_StationInBillCheckBill(HInterID, CurUserName, ref DBUtility.ClsPub.sExeReturnInfo))
                }
                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)
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        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 (BillOld.AbandonCheck(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        //SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                        //DataSet DSet = oCn.RunProcReturn("exec h_p_Sc_ICMOBill_AbandonCheckCtrl " + int.Parse(HInterID), "h_p_Sc_ICMOBill_AbandonCheckCtrl");
                        ////if (DBUtility.ClsPub.isInt(DSet.Tables[0].Rows[0]["Hback"]) != 0)
                        ////{
                        ////    objJsonResult.code = "0";
                        ////    objJsonResult.count = 1;
                        ////    objJsonResult.Message = "该任务单已下推流转卡,不允许反审核" + DBUtility.ClsPub.isStrNull(DSet.Tables[0].Rows[0]["HBackRemark"]);
                        ////    objJsonResult.data = null;
                        ////    return objJsonResult;
                        ////}
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据未找到!";
                    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.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        //审核
        public bool Cj_StationInBillCheckBill(Int64 HInterID, string CurUserName, ref string sReturn)
        #region 工艺路线单关闭/反关闭功能
        [Route("Sc_ProcExchWorkBackBill/CloseSc_ProcExchWorkBackBill")]
        [HttpGet]
        public object CloseSc_ProcExchWorkBackBill(string HInterID, int Type, string user)
        {
            try
            {
                oCN.BeginTran();
                oCN.RunProc(" Update Sc_ProcExchWorkBackBillMain set HChecker='" + CurUserName + "',HBillStatus=2,HCheckDate='getdate()' Where HInterID=" + HInterID.ToString());
                oCN.RunProc("exec h_p_ProcExchWorkBackBill_Check_In " + HInterID.ToString());
                oCN.Commit();
                return true;
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Sc_ProcExchWorkBackBill_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 = "Sc_ProcExchWorkBackBillMain";
                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.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        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]["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)
            {
                sReturn = e.Message;
                oCN.RollBack();
                return false; ;
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}