public JsonResult DeletePeriod(string dataID) { S_P_ContractInfo_Fb_SettlePeriod period = entities.Set <S_P_ContractInfo_Fb_SettlePeriod>().Find(dataID); if (period == null) { //throw new Formula.Exceptions.BusinessValidationException("ID为【" + id + "】的计量期不存在"); } else if (period.Finished) { throw new Formula.Exceptions.BusinessValidationException("第" + period.PeriodNum + "计量期已结束,不能删除。"); } else if (entities.Set <S_P_ContractInfo_Fb_BOQCheck>().Any(a => a.SettlePeriodID == dataID)) { throw new Formula.Exceptions.BusinessValidationException("第" + period.PeriodNum + "计量期已有计量记录,因此计量期不能删除"); } else { //后续的期号重排 var periods = entities.Set <S_P_ContractInfo_Fb_SettlePeriod>().Where(a => a.PeriodNum > period.PeriodNum && a.ContractInfoID == period.ContractInfoID); foreach (var p in periods) { p.PeriodNum -= 1; } entities.Set <S_P_ContractInfo_Fb_SettlePeriod>().Delete(a => a.ID == dataID); } entities.SaveChanges(); return(Json("")); }
public JsonResult AddPeriod(string ContractInfoID) { if (!entities.Set <S_P_ContractInfo>().Any(a => a.ID == ContractInfoID)) { throw new Formula.Exceptions.BusinessValidationException("未找到ID为【" + ContractInfoID + "】的合同信息"); } S_P_ContractInfo_Fb_SettlePeriod tmp = entities.Set <S_P_ContractInfo_Fb_SettlePeriod>().Where(a => a.ContractInfoID == ContractInfoID).OrderByDescending(a => a.PeriodNum).FirstOrDefault(); int currentNum = 1; if (tmp != null) { currentNum = tmp.PeriodNum + 1; } entities.Set <S_P_ContractInfo_Fb_SettlePeriod>().Add(new S_P_ContractInfo_Fb_SettlePeriod() { ID = FormulaHelper.CreateGuid(), ContractInfoID = ContractInfoID, PeriodName = "第" + currentNum + "期", BeginDate = tmp != null ? tmp.EndDate : DateTime.Now, EndDate = DateTime.Now, PeriodNum = currentNum, CreateDate = DateTime.Now, CreateUser = CurrentUserInfo.UserName, CreateUserID = CurrentUserInfo.UserID, OrgID = CurrentUserInfo.UserOrgID }); entities.SaveChanges(); return(Json("")); }
protected override void OnFlowEnd(S_P_ContractInfo_Fb_BOQCheck entity, Workflow.Logic.Domain.S_WF_InsTaskExec taskExec, Workflow.Logic.Domain.S_WF_InsDefRouting routing) { base.OnFlowEnd(entity, taskExec, routing); //将之前的所有计量期全部设置为完成 S_P_ContractInfo_Fb_SettlePeriod period = EPCEntites.Set <S_P_ContractInfo_Fb_SettlePeriod>().Find(entity.SettlePeriodID); EPCEntites.Set <S_P_ContractInfo_Fb_SettlePeriod>().Where(a => a.PeriodNum < period.PeriodNum && a.ContractInfoID == period.ContractInfoID).ToList().Update(a => a.Finished = true); }
public JsonResult SaveList(string listData) { var list = JsonHelper.ToList(listData); foreach (var item in list) { string dataStateFromUICtrl = item.GetValue("_state").ToLower(); if (dataStateFromUICtrl == "modified") { var data = this.GetEntityByID <S_P_ContractInfo_Fb_SettlePeriod>(item.GetValue("ID")); if (data != null) { if (data.Finished) { throw new Formula.Exceptions.BusinessValidationException("第" + data.PeriodNum + "计量期已结束,不能编辑。"); } string id = item.GetValue("ID"); this.UpdateEntity <S_P_ContractInfo_Fb_SettlePeriod>(data, item); } } else if (dataStateFromUICtrl == "added") { S_P_ContractInfo_Fb_SettlePeriod period = new S_P_ContractInfo_Fb_SettlePeriod(); period.ID = FormulaHelper.CreateGuid(); period.ContractInfoID = item.GetValue("ContractInfoID"); period.PeriodNum = Convert.ToInt32(item.GetValue("PeriodNum")); period.PeriodName = item.GetValue("PeriodName"); period.BeginDate = Convert.ToDateTime(item.GetValue("BeginDate")); period.EndDate = Convert.ToDateTime(item.GetValue("EndDate")); period.Remark = item.GetValue("Remark"); period.CreateDate = DateTime.Now; period.CreateUser = CurrentUserInfo.UserName; period.CreateUserID = CurrentUserInfo.UserID; period.OrgID = CurrentUserInfo.UserOrgID; entities.Set <S_P_ContractInfo_Fb_SettlePeriod>().Add(period); } } entities.SaveChanges(); return(Json("")); }