/// <summary> /// 保存Check_PunishNotice /// </summary> /// <param name="newItem">处罚通知单</param> /// <returns></returns> public static void SavePunishNotice(Model.PunishNoticeItem newItem) { using (Model.SUBHSSEDB db = new Model.SUBHSSEDB(Funs.ConnString)) { Model.Check_PunishNotice newPunishNotice = new Model.Check_PunishNotice { PunishNoticeId = newItem.PunishNoticeId, PunishNoticeCode = newItem.PunishNoticeCode, ProjectId = newItem.ProjectId, PunishNoticeDate = Funs.GetNewDateTime(newItem.PunishNoticeDate), UnitId = newItem.UnitId, ContractNum = newItem.ContractNum, IncentiveReason = newItem.IncentiveReason, BasicItem = newItem.BasicItem, PunishMoney = newItem.PunishMoney, Currency = newItem.Currency, FileContents = System.Web.HttpUtility.HtmlEncode(newItem.FileContents), States = Const.State_0, PunishStates = newItem.PunishStates, }; if (!string.IsNullOrEmpty(newItem.CompileManId)) { newPunishNotice.CompileMan = newItem.CompileManId; } if (newPunishNotice.PunishStates == Const.State_1) { newPunishNotice.SignMan = newItem.SignManId; } var getUpdate = db.Check_PunishNotice.FirstOrDefault(x => x.PunishNoticeId == newItem.PunishNoticeId); if (getUpdate == null) { newPunishNotice.CompileDate = DateTime.Now; newPunishNotice.PunishNoticeId = SQLHelper.GetNewID(); newPunishNotice.PunishNoticeCode = CodeRecordsService.ReturnCodeByMenuIdProjectId(Const.ProjectPunishNoticeMenuId, newPunishNotice.ProjectId, newPunishNotice.UnitId); db.Check_PunishNotice.InsertOnSubmit(newPunishNotice); db.SubmitChanges(); CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(Const.ProjectPunishNoticeMenuId, newPunishNotice.ProjectId, newPunishNotice.UnitId, newPunishNotice.PunishNoticeId, newPunishNotice.CompileDate); //// 回写巡检记录表 if (!string.IsNullOrEmpty(newItem.HazardRegisterId)) { List <string> listIds = Funs.GetStrListByStr(newItem.HazardRegisterId, ','); foreach (var item in listIds) { var getHazardRegister = db.HSSE_Hazard_HazardRegister.FirstOrDefault(x => x.HazardRegisterId == item); if (getHazardRegister != null) { getHazardRegister.States = "3"; getHazardRegister.HandleIdea += "已下发处罚通知单:" + newPunishNotice.PunishNoticeCode; getHazardRegister.ResultId = newPunishNotice.PunishNoticeId; getHazardRegister.ResultType = "2"; db.SubmitChanges(); } } } //// 回写专项检查明细表 if (!string.IsNullOrEmpty(newItem.CheckSpecialDetailId)) { List <string> listIds = Funs.GetStrListByStr(newItem.CheckSpecialDetailId, ','); foreach (var item in listIds) { var getCheckSpecialDetail = db.Check_CheckSpecialDetail.FirstOrDefault(x => x.CheckSpecialDetailId == item); if (getCheckSpecialDetail != null) { getCheckSpecialDetail.DataType = "2"; getCheckSpecialDetail.DataId = newPunishNotice.PunishNoticeId; db.SubmitChanges(); } } } } else { newPunishNotice.PunishNoticeId = getUpdate.PunishNoticeId; getUpdate.PunishStates = newItem.PunishStates; if (newPunishNotice.PunishStates == "0" || newPunishNotice.PunishStates == "1") ////编制人 修改或提交 { getUpdate.PunishNoticeDate = newPunishNotice.PunishNoticeDate; getUpdate.UnitId = newPunishNotice.UnitId; getUpdate.ContractNum = newPunishNotice.ContractNum; getUpdate.IncentiveReason = newPunishNotice.IncentiveReason; getUpdate.BasicItem = newPunishNotice.BasicItem; getUpdate.PunishMoney = newPunishNotice.PunishMoney; getUpdate.Currency = newPunishNotice.Currency; getUpdate.FileContents = newPunishNotice.FileContents; if (newPunishNotice.PunishStates == "1" && !string.IsNullOrEmpty(newItem.SignManId)) { getUpdate.SignMan = newItem.SignManId; } else { newPunishNotice.PunishStates = getUpdate.PunishStates = "0"; } db.SubmitChanges(); } else if (newPunishNotice.PunishStates == "2") ////【签发】总包安全经理 { /// 不同意 打回 同意抄送专业工程师、施工经理、相关施工分包单位并提交【批准】总包项目经理 if (newItem.IsAgree == false) { newPunishNotice.PunishStates = getUpdate.PunishStates = "0"; } else { if (!string.IsNullOrEmpty(newItem.ProfessionalEngineerId)) { getUpdate.ProfessionalEngineerId = newItem.ProfessionalEngineerId; } if (!string.IsNullOrEmpty(newItem.ConstructionManagerId)) { getUpdate.ConstructionManagerId = newItem.ConstructionManagerId; } if (!string.IsNullOrEmpty(newItem.UnitHeadManId)) { getUpdate.UnitHeadManId = newItem.UnitHeadManId; } if (!string.IsNullOrEmpty(newItem.ApproveManId)) { getUpdate.ApproveMan = newItem.ApproveManId; getUpdate.SignDate = DateTime.Now; } else { newPunishNotice.PunishStates = getUpdate.States = "1"; } } db.SubmitChanges(); } else if (newPunishNotice.PunishStates == "3") ////【批准】总包项目经理 { /// 不同意 打回 同意下发【回执】施工分包单位 if (newItem.IsAgree == false || string.IsNullOrEmpty(newItem.DutyPersonId)) { newPunishNotice.PunishStates = getUpdate.PunishStates = "1"; } else { getUpdate.DutyPersonId = newItem.DutyPersonId; getUpdate.ApproveDate = DateTime.Now; } db.SubmitChanges(); } else if (newPunishNotice.PunishStates == "4") ////【批准】总包项目经理 { /// 不同意 打回 同意下发【回执】施工分包单位 if (string.IsNullOrEmpty(newItem.ReceiptUrl)) { newPunishNotice.PunishStates = getUpdate.PunishStates = "3"; } else { getUpdate.DutyPersonDate = DateTime.Now; getUpdate.States = Const.State_2; } db.SubmitChanges(); } } if (newItem.PunishStates == Const.State_0 || newItem.PunishStates == Const.State_1) { //// 通知单附件 APIUpLoadFileService.SaveAttachUrl(Const.ProjectPunishNoticeStatisticsMenuId, newPunishNotice.PunishNoticeId, newItem.PunishUrl, "0"); } if (newItem.PunishStates == Const.State_4) { //// 回执单附件 APIUpLoadFileService.SaveAttachUrl(Const.ProjectPunishNoticeMenuId, newPunishNotice.PunishNoticeId, newItem.ReceiptUrl, "0"); } if (getUpdate != null && getUpdate.States == Const.State_2) { CommonService.btnSaveData(newPunishNotice.ProjectId, Const.ProjectPunishNoticeMenuId, newPunishNotice.PunishNoticeId, newPunishNotice.CompileMan, true, newPunishNotice.PunishNoticeCode, "../Check/PunishNoticeView.aspx?PunishNoticeId={0}"); var getcheck = from x in db.Check_CheckSpecialDetail where x.DataId == getUpdate.PunishNoticeId select x; if (getcheck.Count() > 0) { foreach (var item in getcheck) { item.CompleteStatus = true; item.CompletedDate = DateTime.Now; db.SubmitChanges(); } } } } }
/// <summary> /// 保存明细项 /// </summary> private void SaveDetail(string type, Model.Check_CheckSpecial checkSpecial) { List <Model.Check_CheckSpecialDetail> detailLists = new List <Model.Check_CheckSpecialDetail>(); JArray teamGroupData = Grid1.GetMergedData(); foreach (JObject teamGroupRow in teamGroupData) { JObject values = teamGroupRow.Value <JObject>("values"); Model.Check_CheckSpecialDetail newDetail = new Model.Check_CheckSpecialDetail { CheckSpecialDetailId = SQLHelper.GetNewID(), CheckSpecialId = this.CheckSpecialId, CheckContent = values.Value <string>("CheckItemName"), Unqualified = values.Value <string>("Unqualified"), WorkArea = values.Value <string>("WorkArea"), }; var getUnit = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitName == values.Value <string>("UnitName")); if (getUnit != null) { newDetail.UnitId = getUnit.UnitId; } var getHandleStep = Funs.DB.Sys_Const.FirstOrDefault(x => x.GroupId == ConstValue.Group_HandleStep && x.ConstText == values.Value <string>("HandleStepStr")); if (getHandleStep != null) { newDetail.HandleStep = getHandleStep.ConstValue; } if (values.Value <string>("CompleteStatusName") == "已整改") { newDetail.CompleteStatus = true; newDetail.CompletedDate = DateTime.Now; } else { newDetail.CompleteStatus = false; } var getCheckItem = Funs.DB.Technique_CheckItemSet.FirstOrDefault(x => x.SupCheckItem == this.drpSupCheckItemSet.SelectedValue && x.CheckItemName == newDetail.CheckContent); if (getCheckItem != null) { newDetail.CheckItem = getCheckItem.CheckItemSetId; } Check_CheckSpecialDetailService.AddCheckSpecialDetail(newDetail); if (type == Const.BtnSubmit) { if (newDetail.CompleteStatus == false) { detailLists.Add(newDetail); } } } if (detailLists.Count() > 0) { ////隐患整改单 var getDetail1 = detailLists.Where(x => x.HandleStep == "1"); if (getDetail1.Count() > 0) { var getUnitList = getDetail1.Select(x => x.UnitId).Distinct(); foreach (var unitItem in getUnitList) { Model.RectifyNoticesItem rectifyNotices = new Model.RectifyNoticesItem { ProjectId = checkSpecial.ProjectId, UnitId = unitItem, CompleteManId = this.CurrUser.UserId, CheckManNames = checkSpecial.PartInPersons, CheckManIds = checkSpecial.PartInPersonIds, CheckedDate = string.Format("{0:yyyy-MM-dd HH:mm:ss}", checkSpecial.CheckTime), States = Const.State_0, }; rectifyNotices.RectifyNoticesItemItem = new List <Model.RectifyNoticesItemItem>(); var getUnitDItem = getDetail1.Where(x => x.UnitId == unitItem); foreach (var item in getUnitDItem) { Model.RectifyNoticesItemItem newRItem = new Model.RectifyNoticesItemItem(); if (!string.IsNullOrEmpty(item.WorkArea)) { newRItem.WrongContent = item.WorkArea + item.Unqualified; } else { newRItem.WrongContent = item.Unqualified; } if (string.IsNullOrEmpty(rectifyNotices.CheckSpecialDetailId)) { rectifyNotices.CheckSpecialDetailId = item.CheckSpecialDetailId; } else { rectifyNotices.CheckSpecialDetailId += "," + item.CheckSpecialDetailId; } var getAtt = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == item.CheckSpecialDetailId); if (getAtt != null && !string.IsNullOrEmpty(getAtt.AttachUrl)) { newRItem.PhotoBeforeUrl = getAtt.AttachUrl; } rectifyNotices.RectifyNoticesItemItem.Add(newRItem); } APIRectifyNoticesService.SaveRectifyNotices(rectifyNotices); } } ///处罚单 var getDetail2 = detailLists.Where(x => x.HandleStep == "2"); if (getDetail2.Count() > 0) { var getUnitList = getDetail2.Select(x => x.UnitId).Distinct(); foreach (var unitItem in getUnitList) { Model.PunishNoticeItem punishNotice = new Model.PunishNoticeItem { ProjectId = checkSpecial.ProjectId, PunishNoticeDate = string.Format("{0:yyyy-MM-dd HH:mm:ss}", checkSpecial.CheckTime), UnitId = unitItem, CompileManId = this.CurrUser.UserId, PunishStates = Const.State_0, }; var getUnitDItem = getDetail2.Where(x => x.UnitId == unitItem); foreach (var item in getUnitDItem) { Model.RectifyNoticesItemItem newRItem = new Model.RectifyNoticesItemItem(); punishNotice.IncentiveReason += item.Unqualified; if (string.IsNullOrEmpty(punishNotice.CheckSpecialDetailId)) { punishNotice.CheckSpecialDetailId = item.CheckSpecialDetailId; } else { punishNotice.CheckSpecialDetailId += "," + item.CheckSpecialDetailId; } var getAtt = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == item.CheckSpecialDetailId); if (getAtt != null && !string.IsNullOrEmpty(getAtt.AttachUrl)) { punishNotice.PunishUrl = getAtt.AttachUrl; } } APIPunishNoticeService.SavePunishNotice(punishNotice); } } ///暂停令 var getDetail3 = detailLists.Where(x => x.HandleStep == "3"); if (getDetail3.Count() > 0) { var getUnitList = getDetail3.Select(x => x.UnitId).Distinct(); foreach (var unitItem in getUnitList) { Model.PauseNoticeItem pauseNotice = new Model.PauseNoticeItem { ProjectId = checkSpecial.ProjectId, UnitId = unitItem, PauseTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", checkSpecial.CheckTime), PauseStates = Const.State_0, }; var getUnitDItem = getDetail3.Where(x => x.UnitId == unitItem); foreach (var item in getUnitDItem) { Model.RectifyNoticesItemItem newRItem = new Model.RectifyNoticesItemItem(); pauseNotice.ThirdContent += item.Unqualified; if (string.IsNullOrEmpty(pauseNotice.ProjectPlace)) { pauseNotice.ProjectPlace = item.WorkArea; } else { if (!pauseNotice.ProjectPlace.Contains(item.WorkArea)) { pauseNotice.ProjectPlace += "," + item.WorkArea; } } if (string.IsNullOrEmpty(pauseNotice.CheckSpecialDetailId)) { pauseNotice.CheckSpecialDetailId = item.CheckSpecialDetailId; } else { pauseNotice.CheckSpecialDetailId += "," + item.CheckSpecialDetailId; } var getAtt = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == item.CheckSpecialDetailId); if (getAtt != null && !string.IsNullOrEmpty(getAtt.AttachUrl)) { pauseNotice.PauseNoticeAttachUrl = getAtt.AttachUrl; } } APIPauseNoticeService.SavePauseNotice(pauseNotice); } } } }