/// <summary> /// 审核表单 /// </summary> /// <param name="keyValue"></param> /// <param name="aentity"></param> /// <param name="DetailData"></param> public string AuditForm(string keyValue, AptitudeinvestigateauditEntity aentity, string DetailData) { string message = ""; ManyPowerCheckEntity mpcEntity = new ManyPowerCheckEntity(); Operator curUser = ERCHTMS.Code.OperatorProvider.Provider.Current(); SuppliesacceptEntity entity = GetEntity(keyValue); var res = DbFactory.Base().BeginTrans(); try { aentity.APTITUDEID = keyValue; aentity.ID = Guid.NewGuid().ToString(); aentity.FlowId = entity.FlowId; res.Insert <AptitudeinvestigateauditEntity>(aentity); if (aentity.AUDITRESULT == "0") { var createdept = departmentservice.GetEntityByCode(entity.CreateUserDeptCode); mpcEntity = manypowercheckservice.CheckAuditForNext(curUser, "应急物资领用审批", "", createdept.DepartmentId, "", keyValue); if (null != mpcEntity) { entity.FlowId = mpcEntity.ID; } else { List <SuppliesAcceptDetailEntity> detail = JsonConvert.DeserializeObject <List <SuppliesAcceptDetailEntity> >(DetailData); Boolean yz = true; SuppliesService sService = new SuppliesService(); foreach (var item in detail) { var supplies = sService.GetEntity(item.SuppliesId); if (item.AcceptNum <= supplies.NUM) { res.Update <SuppliesAcceptDetailEntity>(item); supplies.NUM = supplies.NUM - item.AcceptNum; res.Update <SuppliesEntity>(supplies); var entityInorOut = new InoroutrecordEntity { USERID = supplies.USERID, USERNAME = supplies.USERNAME, DEPARTID = supplies.DEPARTID, DEPARTNAME = supplies.DEPARTNAME, INOROUTTIME = DateTime.Now, SUPPLIESCODE = supplies.SUPPLIESCODE, SUPPLIESTYPE = supplies.SUPPLIESTYPE, SUPPLIESTYPENAME = supplies.SUPPLIESTYPENAME, SUPPLIESNAME = supplies.SUPPLIESNAME, SUPPLIESUNTIL = supplies.SUPPLIESUNTIL, SUPPLIESUNTILNAME = supplies.SUPPLIESUNTILNAME, NUM = item.AcceptNum, STORAGEPLACE = supplies.STORAGEPLACE, MOBILE = supplies.MOBILE, SUPPLIESID = supplies.ID, STATUS = 1 }; entityInorOut.Create(); res.Insert <InoroutrecordEntity>(entityInorOut); } else { message += supplies.SUPPLIESNAME + "库存不足,无法申领,实际库存为" + supplies.NUM + ";"; yz = false; } } if (yz == false) { res.Rollback(); return(message); } entity.FlowId = "-100"; entity.Status = 3; } } else { entity.FlowId = "-100"; entity.Status = 2; } //entity.IsLastAudit = null; entity.DetailData = null; res.Update(entity); res.Commit(); return(message); } catch (Exception ex) { res.Rollback(); throw ex; } }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public string SaveForm(string keyValue, SuppliesacceptEntity entity) { string message = ""; ManyPowerCheckEntity mpcEntity = new ManyPowerCheckEntity(); Operator curUser = ERCHTMS.Code.OperatorProvider.Provider.Current(); entity.Status = entity.IsSubmit; var res = DbFactory.Base().BeginTrans(); if (!string.IsNullOrEmpty(keyValue)) { var result = GetEntity(keyValue); if (result == null) { entity.Create(); } else { entity.Modify(keyValue); } } else { entity.Create(); } res.Delete <SuppliesAcceptDetailEntity>(t => t.RecId == entity.Id); var num = 0; if (!entity.DetailData.IsEmpty()) { foreach (var spec in entity.DetailData) { spec.CreateDate = DateTime.Now.AddSeconds(-num); spec.Create(); spec.RecId = entity.Id; res.Insert(spec); num++; } } try { if (entity.IsSubmit == 1) { mpcEntity = manypowercheckservice.CheckAuditForNext(curUser, "应急物资领用审批", "", curUser.DeptId, "", keyValue); if (null != mpcEntity) { entity.FlowId = mpcEntity.ID; } else { //审核通过时更新库存,添加库存变更记录 Boolean yz = true; //判断是否库存数量满足申领条件 SuppliesService sService = new SuppliesService(); foreach (var item in entity.DetailData) { var supplies = sService.GetEntity(item.SuppliesId); if (item.AcceptNum <= supplies.NUM) { supplies.NUM = supplies.NUM - item.AcceptNum; res.Update <SuppliesEntity>(supplies); var entityInorOut = new InoroutrecordEntity { USERID = supplies.USERID, USERNAME = supplies.USERNAME, DEPARTID = supplies.DEPARTID, DEPARTNAME = supplies.DEPARTNAME, INOROUTTIME = DateTime.Now, SUPPLIESCODE = supplies.SUPPLIESCODE, SUPPLIESTYPE = supplies.SUPPLIESTYPE, SUPPLIESTYPENAME = supplies.SUPPLIESTYPENAME, SUPPLIESNAME = supplies.SUPPLIESNAME, SUPPLIESUNTIL = supplies.SUPPLIESUNTIL, SUPPLIESUNTILNAME = supplies.SUPPLIESUNTILNAME, NUM = item.AcceptNum, STORAGEPLACE = supplies.STORAGEPLACE, MOBILE = supplies.MOBILE, SUPPLIESID = supplies.ID, STATUS = 1 }; entityInorOut.Create(); res.Insert <InoroutrecordEntity>(entityInorOut); } else { message += supplies.SUPPLIESNAME + "库存不足,无法申领,实际库存为" + supplies.NUM + ";"; yz = false; } } if (yz == false) { res.Rollback(); return(message); } entity.FlowId = ""; entity.Status = 3; } } entity.DetailData = null; if (!string.IsNullOrEmpty(keyValue)) { var result = GetEntity(keyValue); if (result == null) { res.Insert(entity); } else { res.Update(entity); } } else { res.Insert(entity); } res.Commit(); return(message); } catch (System.Exception ex) { res.Rollback(); throw ex; } }