using FineUIPro; using System; using System.Collections; using System.Linq; using Model; namespace BLL { /// /// 项目潜在自然灾害风险清单 /// public class DisasterRiskListService { public static Model.SUBQHSEDB db = Funs.DB; #region 获取在项目潜在自然灾害风险清单列表信息 /// /// 记录数 /// public static int count { get; set; } /// /// 定义变量 /// private static IQueryable getDataLists = from x in db.Manager_DisasterRiskList select x; /// /// 数据列表 /// /// /// /// public static IEnumerable getListData(string unitId, string projectId, string month, Grid Grid1) { IQueryable getDataList = getDataLists; if (!string.IsNullOrEmpty(unitId) && unitId != Const._Null) { getDataList = from x in getDataList join y in db.Base_Project on x.ProjectId equals y.ProjectId where y.UnitId == unitId select x; } if (!string.IsNullOrEmpty(projectId)) { getDataList = getDataList.Where(x => x.ProjectId == projectId); } if (!string.IsNullOrEmpty(month)) { DateTime? monthTime = Funs.GetNewDateTime(month); if (monthTime.HasValue) { getDataList = getDataList.Where(x => x.Months == monthTime.Value); } } count = getDataList.Count(); if (count == 0) { return null; } getDataList = SortConditionHelper.SortingAndPaging(getDataList, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize); return from x in getDataList join y in db.Base_Project on x.ProjectId equals y.ProjectId orderby x.Months, y.UnitId, x.ProjectId select new { x.DisasterRiskListId, x.Months, y.UnitId, db.Base_Unit.First(u => u.UnitId == y.UnitId).UnitName, x.ProjectId, db.Base_Project.First(u => u.ProjectId == x.ProjectId).ProjectName, x.Address, x.DisasterRiskId, db.Base_DisasterRisk.First(u => u.DisasterRiskId == x.DisasterRiskId).DisasterRiskName, x.ContactInfo, x.EmergencyPlan, x.EmergencyDrill, x.RiskStatus, x.FillManId, db.Sys_User.First(u => u.UserId == x.FillManId).UserName, x.FillingTime, x.FillManContact, }; } #endregion /// /// 根据主键获取项目潜在自然灾害风险清单 /// /// /// public static Model.Manager_DisasterRiskList GetDisasterRiskListById(string DisasterRiskListId) { return Funs.DB.Manager_DisasterRiskList.FirstOrDefault(e => e.DisasterRiskListId == DisasterRiskListId); } /// /// 根据月份获取项目潜在自然灾害风险清单 /// /// /// public static Manager_DisasterRiskList GetDisasterRiskListByMonths(DateTime months, string projectId) { return Funs.DB.Manager_DisasterRiskList.FirstOrDefault(e => e.ProjectId == projectId && e.Months.Value.Year == months.Year && e.Months.Value.Month == months.Month); } /// /// 添加项目潜在自然灾害风险清单 /// /// public static string AddDisasterRiskList(Manager_DisasterRiskList newList) { string newDisasterRiskListId = SQLHelper.GetNewID(); Model.Manager_DisasterRiskList newReport = new Manager_DisasterRiskList { DisasterRiskListId = newDisasterRiskListId, Months = newList.Months, ProjectId = newList.ProjectId, Address = newList.Address, DisasterRiskId = newList.DisasterRiskId, ContactInfo = newList.ContactInfo, EmergencyPlan = newList.EmergencyPlan, EmergencyDrill = newList.EmergencyDrill, RiskStatus = newList.RiskStatus, FillManId = newList.FillManId, FillingTime = newList.FillingTime, FillManContact = newList.FillManContact, }; Funs.DB.Manager_DisasterRiskList.InsertOnSubmit(newReport); Funs.DB.SubmitChanges(); return newDisasterRiskListId; } /// /// 修改项目潜在自然灾害风险清单 /// /// public static void UpdateDisasterRiskList (Model.Manager_DisasterRiskList list) { var getList = Funs.DB.Manager_DisasterRiskList.FirstOrDefault(e => e.DisasterRiskListId == list.DisasterRiskListId); if (getList != null) { getList.Months = list.Months; getList.ProjectId = list.ProjectId; getList.Address = list.Address; getList.DisasterRiskId = list.DisasterRiskId; getList.ContactInfo = list.ContactInfo; getList.EmergencyPlan = list.EmergencyPlan; getList.EmergencyDrill = list.EmergencyDrill; getList.RiskStatus = list.RiskStatus; getList.FillManId = list.FillManId; getList.FillingTime = list.FillingTime; getList.FillManContact = list.FillManContact; Funs.DB.SubmitChanges(); } } #region 根据主键删除项目潜在自然灾害风险清单 /// /// 根据主键删除项目潜在自然灾害风险清单 /// /// public static void DeleteDisasterRiskListById(string DisasterRiskListId) { var DisasterRiskList = Funs.DB.Manager_DisasterRiskList.FirstOrDefault(e => e.DisasterRiskListId == DisasterRiskListId); if (DisasterRiskList != null) { Funs.DB.Manager_DisasterRiskList.DeleteOnSubmit(DisasterRiskList); Funs.DB.SubmitChanges(); } } #endregion } }