using Microsoft.SqlServer.Dts.Runtime; using Model; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SgManager.AI; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web.UI.WebControls; using static BLL.SYLicensePublicService; using static BLL.SYPersonService; namespace BLL { public static class APIShiYeService { public static ListItem[] drpPatrolResultItem() { return new ListItem[] { new ListItem("全部", "null"), new ListItem("原状态", "0"), new ListItem("二次评估", "1"), new ListItem("下整改单", "2"), new ListItem("消除", "-1"), }; } #region 隐患 public static List getRectifyList(string projectId, int pageIndex, string IsRectify, out int count) { SUBQHSEDB db = Funs.DB; List getLists = (from x in db.SY_Check_RectifyNotices join y in db.WBS_UnitWork on x.WorkAreaId equals y.UnitWorkId into zlj from y in zlj.DefaultIfEmpty() join z in db.Base_Unit on x.UnitId equals z.UnitId into zljz from z in zljz.DefaultIfEmpty() join W in db.Sys_User on x.DutyPersonId equals W.UserId into zljW from W in zljW.DefaultIfEmpty() join Installation in db.Project_Installation on x.HiddenHazardType equals Installation.InstallationId into zljInstallation from Installation in zljInstallation.DefaultIfEmpty() where x.ProjectId == projectId select new SYRectifyNoticesClass { RectifyNoticesId = x.RectifyNoticesId, ProjectId = x.ProjectId, RectifyNoticesCode = x.RectifyNoticesCode, UnitId = x.UnitId, UnitName = z.UnitName, WorkAreaId = x.WorkAreaId, WorkAreaName = y.UnitWorkName, HiddenHazardType = x.HiddenHazardType, HiddenHazardTypeName = Installation.InstallationName, IsRectify = x.IsRectify.ToString(), IsRectifyName = x.IsRectify.ToString(), CheckedDate = x.CheckedDate.ToString(), CompleteDate = x.CompleteDate.ToString(), AttachUrl = x.AttachUrl, ReCheckOpinion = x.ReCheckOpinion, CompleteStatus = x.CompleteStatus, DutyPerson = W.UserName, DutyPersonId = x.DutyPersonId, WrongContent = x.WrongContent, CheckManNames = x.CheckManNames, }).ToList(); if (!string.IsNullOrEmpty(IsRectify)) { getLists = getLists.Where(p => p.IsRectify == IsRectify).ToList(); } count = getLists.Count(); if (pageIndex > 0) { return getLists.Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList(); } return getLists.ToList(); } /// /// 获取下拉框 /// /// public static SY_YFInitDropDownList GetYFInitDropDownList(string projectId) { SY_YFInitDropDownList DropDown = new SY_YFInitDropDownList(); using (SUBQHSEDB db = new SUBQHSEDB(Funs.ConnString)) { if (!string.IsNullOrWhiteSpace(projectId)) { DropDown.GetWorkAreaList = (from x in db.WBS_UnitWork where x.ProjectId == projectId select new SY_InitDropDown { KeyId = x.UnitWorkId, KeyName = x.UnitWorkName, }).ToList(); DropDown.GetDutyPersonList = (from x in db.Sys_User where x.IsPost == true && x.ProjectId == projectId orderby x.UserId select new SY_InitDropDown { KeyId = x.UserId, KeyName = x.UserName, }).ToList(); DropDown.GetHazardTypeList = (from x in Funs.DB.Project_Installation where x.ProjectId == projectId select new SY_InitDropDown { KeyId = x.InstallationId, KeyName = x.InstallationName, }).ToList(); } else { DropDown.GetDutyPersonList = (from x in db.Sys_User orderby x.UserId select new SY_InitDropDown { KeyId = x.UserId, KeyName = x.UserName, }).ToList(); DropDown.GetHazardTypeList = (from x in Funs.DB.Project_Installation select new SY_InitDropDown { KeyId = x.InstallationId, KeyName = x.InstallationName, }).ToList(); DropDown.GetWorkAreaList = (from x in db.WBS_UnitWork select new SY_InitDropDown { KeyId = x.UnitWorkId, KeyName = x.UnitWorkName, }).ToList(); } } return DropDown; } public class SY_YFInitDropDownList { public List GetDutyPersonList { get; set; } public List GetWorkAreaList { get; set; } public List GetHazardTypeList { get; set; } } /// /// 根据巡检记录ID获取巡检记录信息 /// /// /// public static SYRectifyNoticesClass GetRectifyNoticesById(string RectifyNoticesId) { SUBQHSEDB db = Funs.DB; SYRectifyNoticesClass getLists = (from x in db.SY_Check_RectifyNotices join y in db.WBS_UnitWork on x.WorkAreaId equals y.UnitWorkId into zlj from y in zlj.DefaultIfEmpty() join z in db.Base_Unit on x.UnitId equals z.UnitId into zljz from z in zljz.DefaultIfEmpty() join W in db.Sys_User on x.DutyPersonId equals W.UserId into zljW from W in zljW.DefaultIfEmpty() join Installation in db.Project_Installation on x.HiddenHazardType equals Installation.InstallationId into zljInstallation from Installation in zljInstallation.DefaultIfEmpty() where x.RectifyNoticesId == RectifyNoticesId select new SYRectifyNoticesClass { RectifyNoticesId = x.RectifyNoticesId, ProjectId = x.ProjectId, RectifyNoticesCode = x.RectifyNoticesCode, UnitId = x.UnitId, UnitName = z.UnitName, WorkAreaId = x.WorkAreaId, WorkAreaName = y.UnitWorkName, HiddenHazardType = x.HiddenHazardType, HiddenHazardTypeName = Installation.InstallationName, IsRectify = x.IsRectify.ToString(), IsRectifyName = x.IsRectify.ToString(), CheckedDate = x.CheckedDate.ToString(), CompleteDate = x.CompleteDate.ToString(), AttachUrl = x.AttachUrl, ReCheckOpinion = x.ReCheckOpinion, CompleteStatus = x.CompleteStatus, DutyPerson = W.UserName, DutyPersonId = x.DutyPersonId, WrongContent = x.WrongContent, CheckManNames = x.CheckManNames, }).FirstOrDefault(); return getLists; } /// /// 添加安全巡检记录 /// /// public static void AddRectifyNotices(Model.SY_Check_RectifyNotices RectifyNotices) { Model.SY_Check_RectifyNotices newRectifyNotices = new Model.SY_Check_RectifyNotices { RectifyNoticesId = SQLHelper.GetNewID(), ProjectId = RectifyNotices.ProjectId, RectifyNoticesCode = RectifyNotices.RectifyNoticesCode, UnitId = RectifyNotices.UnitId, WorkAreaId = RectifyNotices.WorkAreaId, HiddenHazardType = RectifyNotices.HiddenHazardType, IsRectify = RectifyNotices.IsRectify, CheckedDate = RectifyNotices.CheckedDate, CompleteDate = RectifyNotices.CompleteDate, AttachUrl = RectifyNotices.AttachUrl, ReCheckOpinion = RectifyNotices.ReCheckOpinion, CompleteStatus = RectifyNotices.CompleteStatus, DutyPersonId = RectifyNotices.DutyPersonId, WrongContent = RectifyNotices.WrongContent, CheckManNames = RectifyNotices.CheckManNames, }; Funs.DB.SY_Check_RectifyNotices.InsertOnSubmit(newRectifyNotices); Funs.DB.SubmitChanges(); } /// /// 修改安全巡检记录 /// /// public static void UpdateRectifyNotices(Model.SY_Check_RectifyNotices RectifyNotices) { Model.SY_Check_RectifyNotices newRectifyNotices = Funs.DB.SY_Check_RectifyNotices.FirstOrDefault(e => e.RectifyNoticesId == RectifyNotices.RectifyNoticesId); if (newRectifyNotices != null) { newRectifyNotices.ProjectId = RectifyNotices.ProjectId; newRectifyNotices.RectifyNoticesCode = RectifyNotices.RectifyNoticesCode; newRectifyNotices.UnitId = RectifyNotices.UnitId; newRectifyNotices.WorkAreaId = RectifyNotices.WorkAreaId; newRectifyNotices.HiddenHazardType = RectifyNotices.HiddenHazardType; newRectifyNotices.IsRectify = RectifyNotices.IsRectify; newRectifyNotices.CheckedDate = RectifyNotices.CheckedDate; newRectifyNotices.CompleteDate = RectifyNotices.CompleteDate; newRectifyNotices.AttachUrl = RectifyNotices.AttachUrl; newRectifyNotices.ReCheckOpinion = RectifyNotices.ReCheckOpinion; newRectifyNotices.CompleteStatus = RectifyNotices.CompleteStatus; newRectifyNotices.DutyPersonId = RectifyNotices.DutyPersonId; newRectifyNotices.WrongContent = RectifyNotices.WrongContent; newRectifyNotices.CheckManNames = RectifyNotices.CheckManNames; Funs.DB.SubmitChanges(); } } /// /// 根据巡检记录ID删除对应巡检记录记录信息 /// /// public static void DeleteRectifyNotices(string RectifyNoticesId) { var q = (from x in Funs.DB.SY_Check_RectifyNotices where x.RectifyNoticesId == RectifyNoticesId select x).FirstOrDefault(); if (q != null) { ///删除附件 BLL.CommonService.DeleteAttachFileById(RectifyNoticesId); Funs.DB.SY_Check_RectifyNotices.DeleteOnSubmit(q); Funs.DB.SubmitChanges(); } } public class SYRectifyNoticesClass { public string RectifyNoticesId { get; set; } public string ProjectId { get; set; } /// /// 编号 /// public string RectifyNoticesCode { get; set; } /// /// 隐患名称 /// public string CheckManNames { get; set; } public string UnitId { get; set; } public string UnitName { get; set; } public string HiddenHazardType { get; set; } public string HiddenHazardTypeName { get; set; } /// /// 原因分析 /// public string WrongContent { get; set; } /// /// 隐患位置 /// public string WorkAreaId { get; set; } public string WorkAreaName { get; set; } public string States { get; set; } public string AttachUrl { get; set; } /// /// 整改后照片 /// public string ReCheckOpinion { get; set; } /// /// 整改措施 /// public string CompleteStatus { get; set; } public string DutyPersonId { get; set; } public string DutyPerson { get; set; } /// /// 检查时间 /// public string CheckedDate { get { return this.checkedDate; } set { this.checkedDate = Convert.ToDateTime(value).ToString("yyyy-MM-dd"); } } private string checkedDate; /// /// 整改期限 /// public string CompleteDate { get { return this.completeDate; } set { this.completeDate = Convert.ToDateTime(value).ToString("yyyy-MM-dd"); } } private string completeDate; public string IsRectifyName { get { return this.isRectifyName; } set { this.isRectifyName = value == "True" ? "是" : "否"; } } private string isRectifyName; /// /// 是否重大 /// public string IsRectify { get; set; } } #endregion #region 风险 public static List getRoutingList(string projectId, int pageIndex, string PatrolResult, out int count) { SUBQHSEDB db = Funs.DB; IQueryable getLists = (from x in db.SY_Hazard_RoutingInspection join y in db.Base_RiskLevel on x.OldRiskLevel equals y.RiskLevelId into zlj from y in zlj.DefaultIfEmpty() join z in db.Base_RiskLevel on x.PatrolPlanId equals z.RiskLevelId into zljz from z in zljz.DefaultIfEmpty() join W in db.Sys_User on x.PatrolManId equals W.UserId into zljW from W in zljW.DefaultIfEmpty() join Installation in db.Project_Installation on x.RiskManId equals Installation.InstallationId into zljInstallation from Installation in zljInstallation.DefaultIfEmpty() where x.HazardSelectedItemId == projectId select new SY_Hazard_RoutingInspectionClass { RoutingInspectionId = x.RoutingInspectionId, ProjectId = x.HazardSelectedItemId, PatrolManId = x.PatrolManId, PatrolManName = W.UserName, PatrolTime = x.PatrolTime.ToString(), PatrolResult = x.PatrolResult.ToString(), PatrolResultName = x.PatrolResult.ToString(), OldRiskLevel = x.OldRiskLevel, OldRiskLevelName = y.RiskLevelName, PatrolPlanId = x.PatrolPlanId, PatrolPlanName = z.RiskLevelName, ControlMeasures = x.ControlMeasures, DealReason = x.DealReason, RiskManId = x.RiskManId, RiskManName = Installation.InstallationName, }); if (!string.IsNullOrEmpty(PatrolResult)) { getLists = getLists.Where(p => p.PatrolResult == PatrolResult); } count = getLists.Count(); if (pageIndex > 0) { return getLists.Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList(); } return getLists.ToList(); } /// /// 获取风险等级下拉框 /// /// public static SY_FXInitDropDownList GetFXInitDropDownList(string projectId) { SY_FXInitDropDownList DropDown = new SY_FXInitDropDownList(); using (SUBQHSEDB db = new SUBQHSEDB(Funs.ConnString)) { DropDown.GetRiskLevel = (from x in db.Base_RiskLevel select new SY_InitDropDown { KeyId = x.RiskLevelId, KeyName = x.RiskLevelName, }).ToList(); if (!string.IsNullOrWhiteSpace(projectId)) { DropDown.GetPatrolManList = (from x in db.Sys_User where x.IsPost == true && x.ProjectId == projectId orderby x.UserId select new SY_InitDropDown { KeyId = x.UserId, KeyName = x.UserName, }).ToList(); DropDown.GetPatrolDevList = (from x in Funs.DB.Project_Installation where x.ProjectId == projectId select new SY_InitDropDown { KeyId = x.InstallationId, KeyName = x.InstallationName, }).ToList(); } else { DropDown.GetPatrolManList = (from x in db.Sys_User where x.IsPost == true && x.ProjectId == projectId orderby x.UserId select new SY_InitDropDown { KeyId = x.UserId, KeyName = x.UserName, }).ToList(); DropDown.GetPatrolDevList = (from x in Funs.DB.Project_Installation select new SY_InitDropDown { KeyId = x.InstallationId, KeyName = x.InstallationName, }).ToList(); } } return DropDown; } public class SY_FXInitDropDownList { public List GetRiskLevel { get; set; } public List GetPatrolManList { get; set; } public List GetPatrolDevList { get; set; } } /// /// 根据巡检记录ID获取巡检记录信息 /// /// /// public static SY_Hazard_RoutingInspectionClass GetRoutingInspectionByRoutingInspectionId(string RoutingInspectionId) { SUBQHSEDB db = Funs.DB; SY_Hazard_RoutingInspectionClass getLists = (from x in db.SY_Hazard_RoutingInspection join y in db.Base_RiskLevel on x.OldRiskLevel equals y.RiskLevelId into zlj from y in zlj.DefaultIfEmpty() join z in db.Base_RiskLevel on x.PatrolPlanId equals z.RiskLevelId into zljz from z in zljz.DefaultIfEmpty() join W in db.Sys_User on x.PatrolManId equals W.UserId into zljW from W in zljW.DefaultIfEmpty() join Installation in db.Project_Installation on x.RiskManId equals Installation.InstallationId into zljInstallation from Installation in zljInstallation.DefaultIfEmpty() where x.RoutingInspectionId == RoutingInspectionId select new SY_Hazard_RoutingInspectionClass { RoutingInspectionId = x.RoutingInspectionId, ProjectId = x.HazardSelectedItemId, PatrolManId = x.PatrolManId, PatrolManName = W.UserName, PatrolTime = x.PatrolTime.ToString(), PatrolResult = x.PatrolResult.ToString(), PatrolResultName = x.PatrolResult.ToString(), OldRiskLevel = x.OldRiskLevel, OldRiskLevelName = y.RiskLevelName, PatrolPlanId = x.PatrolPlanId, PatrolPlanName = z.RiskLevelName, ControlMeasures = x.ControlMeasures, DealReason = x.DealReason, RiskManId = x.RiskManId, RiskManName = Installation.InstallationName, }).FirstOrDefault(); return getLists; } /// /// 添加安全巡检记录 /// /// public static void AddRoutingInspection(Model.SY_Hazard_RoutingInspection RoutingInspection) { Model.SY_Hazard_RoutingInspection newRoutingInspection = new Model.SY_Hazard_RoutingInspection { RoutingInspectionId = SQLHelper.GetNewID(), HazardSelectedItemId = RoutingInspection.HazardSelectedItemId, PatrolManId = RoutingInspection.PatrolManId, PatrolTime = RoutingInspection.PatrolTime, PatrolResult = RoutingInspection.PatrolResult, OldRiskLevel = RoutingInspection.OldRiskLevel, PohotoUrl = RoutingInspection.PohotoUrl, ControlMeasures = RoutingInspection.ControlMeasures, DealReason = RoutingInspection.DealReason, RiskManId = RoutingInspection.RiskManId, PatrolPlanId = RoutingInspection.PatrolPlanId }; Funs.DB.SY_Hazard_RoutingInspection.InsertOnSubmit(newRoutingInspection); Funs.DB.SubmitChanges(); } /// /// 修改安全巡检记录 /// /// public static void UpdateRoutingInspection(Model.SY_Hazard_RoutingInspection RoutingInspection) { Model.SY_Hazard_RoutingInspection newRoutingInspection = Funs.DB.SY_Hazard_RoutingInspection.FirstOrDefault(e => e.RoutingInspectionId == RoutingInspection.RoutingInspectionId); if (newRoutingInspection != null) { newRoutingInspection.PatrolManId = RoutingInspection.PatrolManId; newRoutingInspection.PatrolTime = RoutingInspection.PatrolTime; newRoutingInspection.PatrolResult = RoutingInspection.PatrolResult; newRoutingInspection.OldRiskLevel = RoutingInspection.OldRiskLevel; newRoutingInspection.PohotoUrl = RoutingInspection.PohotoUrl; newRoutingInspection.ControlMeasures = RoutingInspection.ControlMeasures; newRoutingInspection.DealReason = RoutingInspection.DealReason; newRoutingInspection.PatrolPlanId = RoutingInspection.PatrolPlanId; newRoutingInspection.HazardSelectedItemId = RoutingInspection.HazardSelectedItemId; newRoutingInspection.RiskManId = RoutingInspection.RiskManId; Funs.DB.SubmitChanges(); } } /// /// 根据巡检记录ID删除对应巡检记录记录信息 /// /// public static void DeleteRoutingInspection(string RoutingInspectionId) { var q = (from x in Funs.DB.SY_Hazard_RoutingInspection where x.RoutingInspectionId == RoutingInspectionId select x).FirstOrDefault(); if (q != null) { ///删除附件 BLL.CommonService.DeleteAttachFileById(RoutingInspectionId); Funs.DB.SY_Hazard_RoutingInspection.DeleteOnSubmit(q); Funs.DB.SubmitChanges(); } } public class SY_Hazard_RoutingInspectionClass { public string RoutingInspectionId { get; set; } public string ProjectId { get; set; } public string PatrolManId { get; set; } public string PatrolManName { get; set; } public string PatrolResult { get; set; } public string OldRiskLevel { get; set; } public string OldRiskLevelName { get; set; } public string PatrolPlanId { get; set; } public string PatrolPlanName { get; set; } public string PohotoUrl { get; set; } public string ControlMeasures { get; set; } public string DealReason { get; set; } public string RiskManId { get; set; } public string RiskManName { get; set; } public string PatrolTime { get { return this.patrolTime; } set { this.patrolTime = Convert.ToDateTime(value).ToString("yyyy-MM-dd"); } } private string patrolTime; public string PatrolResultName { get { return this.patrolResult; } set { this.patrolResult = (drpPatrolResultItem().Where(p => p.Value == value).FirstOrDefault() != null) ? (drpPatrolResultItem().Where(p => p.Value == value).FirstOrDefault().Text) : ""; } } private string patrolResult; } #endregion #region 作业票 #endregion } }