1
wtt
16 小时以前 d82756d630f5f9bcc588fee772b68bc2a7725cb0
WebAPI/Controllers/SCGL/Sc_MESStopWorkBillController.cs
@@ -13,14 +13,17 @@
    //生产停工单Controller
    public class Sc_MESStopWorkBillController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更)
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
        //获取系统参数
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        Pub_Class.ClsXt_SystemParameterMain oSystemParameterMain = new Pub_Class.ClsXt_SystemParameterMain();
        public DAL.ClsSc_MESStopWorkBill BillNew = new DAL.ClsSc_MESStopWorkBill();   //对应单据类
        public DAL.ClsSc_MESStopWorkBill BillOld = new DAL.ClsSc_MESStopWorkBill();   //对应单据类
        #region 停工单
@@ -185,10 +188,11 @@
        /// <returns></returns>
        [Route("Sc_MESStopWorkBill/DeltetMESStopWorkBill")]
        [HttpGet]
        public object DeltetMESStopWorkBill(string HInterID)
        public object DeltetMESStopWorkBill(string HInterID,string UserName)
        {
            DBUtility.ClsPub.CurUserName = UserName;
            //编辑权限
            if (!DBUtility.ClsPub.Security_Log("MES_MESStopWorkBill_Delete", 1, true, DBUtility.ClsPub.CurUserName))
            if (!DBUtility.ClsPub.Security_Log_second("MES_MESStopWorkBill_Delete", 1, false, DBUtility.ClsPub.CurUserName))
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
@@ -276,7 +280,7 @@
            try
            {
                //审核权限
                if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true, CurUserName))
                if (!DBUtility.ClsPub.Security_Log_second(ModRightNameCheck, 1, false, CurUserName))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
@@ -358,8 +362,8 @@
                    }
                    else
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
@@ -378,8 +382,8 @@
                    }
                    else
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "反审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
@@ -412,8 +416,16 @@
        [HttpPost]
        public object SaveGetMESStopFrom([FromBody] JObject msg)
        {
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string UserName = sArray[1].ToString();
            string refSav = sArray[2].ToString();
            DBUtility.ClsPub.CurUserName = UserName;
            //保存权限
            if (!DBUtility.ClsPub.Security_Log("MES_MESStopWorkBill_Edit", 1, true, DBUtility.ClsPub.CurUserName))
            if (!DBUtility.ClsPub.Security_Log_second("MES_MESStopWorkBill_Edit", 1, false, DBUtility.ClsPub.CurUserName))
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
@@ -434,14 +446,8 @@
                return objJsonResult;
            }
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string UserName = "";
            ListModels oListModels = new ListModels();
            try
            {
@@ -452,9 +458,58 @@
                lsmain = oListModels.getObjectByJson_Gy_MESStopWorkBillMain(msg2);
                foreach (Models.ClsSc_MESStopWorkBillMain oItem in lsmain)
                {
                    if (refSav == "Add")
                    {
                        //单据号是否重复
                        if (BillNew.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, BillOld.omodel.HInterID))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据号重复!不允许保存!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                    }
                    if (refSav == "Update")
                    {
                        if (BillOld.ShowBill(oItem.HInterID, ref s) == false)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "此单据有误!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                        //判断是否可编辑
                        if (BillOld.omodel.HChecker != "" && BillOld.omodel.HChecker != null)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "此单据已经被审核,不允许修改!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                        if (BillOld.omodel.HBillStatus > 1)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "此单据处于不可编辑状态,不允许修改!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                        if (!DBUtility.Xt_BaseBillFun.Fun_AllowEditBill(BillOld, ref s))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = s + ",不允许修改";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                    }
                    //oItem.HMaker = "";
                    DBUtility.ClsPub.CurUserName = oItem.HMaker;
                    UserName = oItem.HMaker;  //制单人
                    oItem.HMaker = UserName;  //制单人
                    oItem.HBillType = "3789";
                    oItem.HBillSubType = "3789";
                    oItem.HReportType = "3";//(1条码扫描,2机器汇报,3手工录入)
@@ -486,7 +541,7 @@
                        string sReturn = "";
                        if (oSystemParameter.ShowBill(ref sReturn) == true)
                        {
                            if (oSystemParameterMain.Sc_MESStopWorkBill_AutoCheck == "Y") //系统参数  自动审核
                            if (oSystemParameter.omodel.Sc_MESStopWorkBill_AutoCheck == "Y") //系统参数  自动审核
                            {
                                objJsonResult.Verify = "Y";
                            }
@@ -504,7 +559,7 @@
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
@@ -530,5 +585,170 @@
            }
        }
        #endregion
        #region 报工平台快捷停工
        [Route("Sc_MESStopWorkBill/FastStopWorkBill")]
        [HttpGet]
        public object FastStopWorkBill(string HBillType, int HSourceInterID, int HSourceEntryID, string HSourceBillNo, string HSourceBillType, string user)
        {
            //保存权限
            if (!DBUtility.ClsPub.Security_Log_second("MES_MESStopWorkBill_Edit", 1, false, user))
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "无保存权限!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            //判断会计期是否合理
            string s = "";
            int sYear = 0;
            int sPeriod = 0;
            if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(DateTime.Now, ref sYear, ref sPeriod, ref s) == false)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = s;
                objJsonResult.data = null;
                return objJsonResult;
            }
            ListModels oListModels = new ListModels();
            try
            {
                ds = oCN.RunProcReturn("exec h_p_JIT_GetInfoByICMOStatusInterID @HSourceInterID=" + HSourceInterID + ",@HSourceEntryID=" + HSourceEntryID + ",@HSourceBillNo='" + HSourceBillNo + "',@HSourceBillType='" + HBillType + "'", "h_p_JIT_GetInfoByICMOStatusInterID");
                Models.ClsSc_MESStopWorkBillMain ClsSc_MESStopWorkBillMain = new Models.ClsSc_MESStopWorkBillMain();
                ClsSc_MESStopWorkBillMain.HProcID = int.Parse(ds.Tables[0].Rows[0]["HProcID"].ToString());
                ClsSc_MESStopWorkBillMain.HMaterID = int.Parse(ds.Tables[0].Rows[0]["HMaterID"].ToString());
                ClsSc_MESStopWorkBillMain.HSourceID = int.Parse(ds.Tables[0].Rows[0]["HSourceID"].ToString());
                ClsSc_MESStopWorkBillMain.HMainSourceBillNo = ds.Tables[0].Rows[0]["HSourceBillNo"].ToString();
                ClsSc_MESStopWorkBillMain.HMainSourceInterID = int.Parse(ds.Tables[0].Rows[0]["HSourceInterID"].ToString());
                ClsSc_MESStopWorkBillMain.HMainSourceEntryID = long.Parse(ds.Tables[0].Rows[0]["HSourceEntryID"].ToString());
                ClsSc_MESStopWorkBillMain.HMainSourceBillType = HSourceBillType == null ? "" : HSourceBillType;
                ClsSc_MESStopWorkBillMain.HDeptID = int.Parse(ds.Tables[0].Rows[0]["HDeptID"].ToString());
                ClsSc_MESStopWorkBillMain.HICMOInterID = int.Parse(ds.Tables[0].Rows[0]["HICMOInterID"].ToString());
                ClsSc_MESStopWorkBillMain.HICMOEntryID = int.Parse(ds.Tables[0].Rows[0]["HICMOEntryID"].ToString());
                ClsSc_MESStopWorkBillMain.HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();
                ds = oCN.RunProcReturn("select * from h_v_Cj_GetDefValByUser where 用户名称='" + user + "'", "h_v_xt_UserAssociationSelect");
                //if (ds.Tables[0].Rows[0]["HGroupID"].ToString() == "0")
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "保存失败!用户没有绑定班组!";
                //    objJsonResult.data = 1;
                //    return objJsonResult;
                //}
                if (ds.Tables[0].Rows[0]["HEmpID"].ToString() == "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!用户没有绑定职员!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                ClsSc_MESStopWorkBillMain.HGroupID = int.Parse(ds.Tables[0].Rows[0]["HGroupID"].ToString());
                ClsSc_MESStopWorkBillMain.HEmpID = int.Parse(ds.Tables[0].Rows[0]["HEmpID"].ToString());
                DLL.ClsSc_MESStopWorkBill oBill = new DLL.ClsSc_MESStopWorkBill();
                List<Models.ClsSc_MESStopWorkBillMain> lsmain = new List<Models.ClsSc_MESStopWorkBillMain>();
                lsmain.Add(ClsSc_MESStopWorkBillMain);
                ClsXt_SystemParameter oClsXt_SystemParameter = new ClsXt_SystemParameter();
                DBUtility.ClsPub.CurUserName = user;
                foreach (Models.ClsSc_MESStopWorkBillMain oItem in lsmain)
                {
                    oItem.HBillNo = DBUtility.ClsPub.CreateBillCode("3789", ref DBUtility.ClsPub.sExeReturnInfo, true);
                    oItem.HBillType = "3789";
                    oItem.HBillSubType = "3789";
                    oItem.HReportType = "3";//(1条码扫描,2机器汇报,3手工录入)
                    oItem.HBillStatus = 1;   //单据状态(1未审,2审核通过,3关闭,4作废,5审核退回,6审核中,7已阅,8已回复,9结案,10验证,11下达,12开工,13申请审批,15申请检验,16 判定合格,17判定不合格)
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
                    oItem.HMaker = user;
                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
                    oItem.HBarCodeMakeDate = Convert.ToDateTime(DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"))); //扫描日期(年-月-日-时-分-秒)
                    oItem.HStopBeginWorkTime = Convert.ToDateTime(DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd")));
                    oItem.HStopEndWorkTime = Convert.ToDateTime(DBUtility.ClsPub.isStrNull(DateTime.Now.AddDays(30).ToString("yyyy-MM-dd")));
                    oItem.HRemark = "快捷停工";
                    oBill.omodel = oItem;
                }
                oCN.BeginTran();
                //保存
                //保存完毕后处理
                bool bResult = false;
                if (oBill.omodel.HInterID == 0)
                {
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                ds = oCN.RunProcReturn("select * from Sc_MESStopWorkBillMain where HBillNo='" + oBill.omodel.HBillNo + "'", "Sc_MESStopWorkBillMain");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无单据!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                string sAutoCheck = oClsXt_SystemParameter.GetSingleSystemParameter("Sc_MESStopWorkBill_AutoCheck", ref DBUtility.ClsPub.sExeReturnInfo);
                if (sAutoCheck == "Y")
                {
                    if (!oBill.CheckBill(long.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString()), ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                }
                oCN.Commit();
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message;
                objJsonResult.data = 1;
                return objJsonResult;
            }
        }
        #endregion
    }
}