using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; using System.Web.UI.WebControls; namespace BLL { public static class HSSE_Hazard_HazardRegisterService { public static Model.CNPCDB db = Funs.DB; /// /// 根据危险观察登记主键获取危险观察登记信息 /// /// 危险观察登记主键 /// 危险观察登记信息 public static Model.HSSE_Hazard_HazardRegister GetHazardRegisterByHazardRegisterId(string hazardRegisterId) { return Funs.DB.HSSE_Hazard_HazardRegister.FirstOrDefault(x => x.HazardRegisterId == hazardRegisterId); } public static Model.HSSE_Hazard_HazardRegister GetHazardRegisterByCheckItemDetailId(string CheckItemDetailId) { return Funs.DB.HSSE_Hazard_HazardRegister.FirstOrDefault(x => x.HazardRegisterId == CheckItemDetailId || x.CheckItemDetailId == CheckItemDetailId); } /// /// 获取项目风险列表 /// /// /// public static List GetHazardRegisterListByProjectId(string projectId) { return (from x in Funs.DB.HSSE_Hazard_HazardRegister where x.ProjectId == projectId select x).ToList(); } /// /// 增加危险观察登记信息 /// /// 危险观察登记实体 public static void AddHazardRegister(Model.HSSE_Hazard_HazardRegister model) { Model.CNPCDB db = Funs.DB; Model.HSSE_Hazard_HazardRegister newModel = new Model.HSSE_Hazard_HazardRegister(); newModel.HazardRegisterId = model.HazardRegisterId; newModel.HazardCode = model.HazardCode; newModel.RegisterDate = DateTime.Now; newModel.RegisterDef = model.RegisterDef; newModel.RegisterTypesId = model.RegisterTypesId; newModel.CheckCycle = model.CheckCycle; newModel.Rectification = model.Rectification; newModel.Place = model.Place; newModel.ResponsibleUnit = model.ResponsibleUnit; newModel.Observer = model.Observer; newModel.RectifiedDate = model.RectifiedDate; newModel.AttachUrl = model.AttachUrl; newModel.ProjectId = model.ProjectId; newModel.States = model.States; newModel.IsEffective = model.IsEffective; newModel.ResponsibleMan = model.ResponsibleMan; newModel.CheckSpecialId = model.CheckSpecialId; newModel.CheckManId = model.CheckManId; newModel.CheckTime = model.CheckTime; newModel.RectificationPeriod = model.RectificationPeriod; newModel.ImageUrl = model.ImageUrl; newModel.RectificationImageUrl = model.RectificationImageUrl; newModel.RectificationTime = model.RectificationTime; newModel.ConfirmMan = model.ConfirmMan; newModel.ConfirmDate = model.ConfirmDate; newModel.HandleIdea = model.HandleIdea; newModel.CutPayment = model.CutPayment; newModel.ProblemTypes = model.ProblemTypes; newModel.DIC_ID = model.DIC_ID; newModel.Risk_Level = model.Risk_Level; newModel.Requirements = model.Requirements; newModel.ControlId = model.ControlId; newModel.CheckItemDetailId = model.CheckItemDetailId; newModel.CompanyTrainingItemId = model.CompanyTrainingItemId; db.HSSE_Hazard_HazardRegister.InsertOnSubmit(newModel); db.SubmitChanges(); } /// /// 修改危险观察登记信息 /// /// 危险观察登记实体 public static void UpdateHazardRegister(Model.HSSE_Hazard_HazardRegister model) { Model.CNPCDB db = Funs.DB; Model.HSSE_Hazard_HazardRegister newModel = db.HSSE_Hazard_HazardRegister.FirstOrDefault(e => e.HazardRegisterId == model.HazardRegisterId); if (newModel != null) { newModel.HazardCode = model.HazardCode; newModel.RegisterDef = model.RegisterDef; newModel.Rectification = model.Rectification; newModel.Place = model.Place; newModel.ResponsibleUnit = model.ResponsibleUnit; newModel.Observer = model.Observer; newModel.RectifiedDate = model.RectifiedDate; newModel.AttachUrl = model.AttachUrl; newModel.ProjectId = model.ProjectId; newModel.States = model.States; newModel.IsEffective = model.IsEffective; newModel.ResponsibleMan = model.ResponsibleMan; newModel.CheckManId = model.CheckManId; //newModel.CheckTime = model.CheckTime; newModel.RectificationPeriod = model.RectificationPeriod; newModel.ImageUrl = model.ImageUrl; newModel.RectificationImageUrl = model.RectificationImageUrl; newModel.RectificationTime = model.RectificationTime; newModel.ConfirmMan = model.ConfirmMan; newModel.ConfirmDate = model.ConfirmDate; newModel.HandleIdea = model.HandleIdea; newModel.CutPayment = model.CutPayment; newModel.ProblemTypes = model.ProblemTypes; newModel.DIC_ID = model.DIC_ID; newModel.CheckItemDetailId = model.CheckItemDetailId; newModel.RegisterTypesId = model.RegisterTypesId; newModel.Risk_Level = model.Risk_Level; newModel.Requirements = model.Requirements; newModel.CompanyTrainingItemId = model.CompanyTrainingItemId; //把附件表的路径复制过来 Model.AttachFile file = BLL.AttachFileService.GetAttachFile(model.HazardRegisterId, Const.HSSE_HiddenRectificationListMenuId); if (file != null) { newModel.ImageUrl = file.AttachUrl; } Model.AttachFile fileR = BLL.AttachFileService.GetAttachFile(model.HazardRegisterId + "-R", Const.HSSE_HiddenRectificationListMenuId); if (fileR != null) { newModel.RectificationImageUrl = fileR.AttachUrl; } db.SubmitChanges(); } } /// /// 根据危险观察登记主键删除一个危险观察登记信息 /// /// 危险观察登记主键 public static void DeleteHazardRegisterByHazardRegisterId(string hazardRegisterId) { Model.CNPCDB db = Funs.DB; Model.HSSE_Hazard_HazardRegister model = db.HSSE_Hazard_HazardRegister.FirstOrDefault(e => e.HazardRegisterId == hazardRegisterId); if (model != null) { try { BLL.UploadFileService.DeleteFile(Funs.RootPath, model.ImageUrl);//删除整改前图片 BLL.UploadFileService.DeleteFile(Funs.RootPath, model.RectificationImageUrl);//删除整改后图片 } catch (Exception) { } db.HSSE_Hazard_HazardRegister.DeleteOnSubmit(model); db.SubmitChanges(); } } /// /// 对单位分组查询危险观察登记信息并 /// /// 危险观察登记信息 public static ListItem[] GetResponsibleUnitList(string projectId) { var q = (from x in Funs.DB.HSSE_Hazard_HazardRegister where x.ProjectId == projectId group x by x.ResponsibleUnit into x select new { ResponsibleUnit = x.Key }).ToList(); ListItem[] list = new ListItem[q.Count()]; for (int i = 0; i < q.Count(); i++) { list[i] = new ListItem(BLL.UnitService.GetUnitByUnitId(q[i].ResponsibleUnit).UnitName ?? "", q[i].ResponsibleUnit.ToString()); } return list; } /// /// 获取危险观察登记状态集合 /// /// 危险观察登记状态集合 public static List GetStatesList() { List handleSteps = new List(); Model.HandleStep handleStep1 = new Model.HandleStep(); handleStep1.Id = "1"; handleStep1.Name = "待整改"; handleSteps.Add(handleStep1); Model.HandleStep handleStep2 = new Model.HandleStep(); handleStep2.Id = "2"; handleStep2.Name = "已整改"; handleSteps.Add(handleStep2); Model.HandleStep handleStep3 = new Model.HandleStep(); handleStep3.Id = "3"; handleStep3.Name = "已闭环"; handleSteps.Add(handleStep3); Model.HandleStep handleStep4 = new Model.HandleStep(); handleStep4.Id = "4"; handleStep4.Name = "已作废"; handleSteps.Add(handleStep4); return handleSteps; } /// /// 根据时间段获取巡检信息集合 /// /// /// /// /// public static int GetCountByCheckTime(DateTime startTime, DateTime endTime, string projectId) { return (from x in Funs.DB.HSSE_Hazard_HazardRegister where x.CheckTime >= startTime && x.CheckTime < endTime && x.ProjectId == projectId select x).Count(); } } }