//向任务添加工作人员 public static void AddServerToMission(uint mission_id, Worker server) { using (var entity = new CommunityEpidemicManagementSystemContext()) { try { entity.ResidentMissions.Find(mission_id).Server = server; entity.SaveChanges(); } catch (Exception ex) { string errorInfo = ex.Message; if (ex is DbEntityValidationException) { foreach (var validationResult in ((DbEntityValidationException)ex).EntityValidationErrors) { foreach (var error in validationResult.ValidationErrors) { errorInfo = $"{errorInfo}" + "\n" + $"{error.ErrorMessage}"; } } } throw new ApplicationException("更新时出错!\n" + $"{errorInfo}"); } } }
//删除居民的出入记录 public static void RemoveRecord(string id) { using (var entity = new CommunityEpidemicManagementSystemContext()) { try { entity.ResidentAccessManagements.Remove(Get(id)); entity.SaveChanges(); } catch (Exception ex) { string errorInfo = ex.Message; if (ex is DbEntityValidationException) { foreach (var validationResult in ((DbEntityValidationException)ex).EntityValidationErrors) { foreach (var error in validationResult.ValidationErrors) { errorInfo = $"{errorInfo}" + "\n" + $"{error.ErrorMessage}"; } } } throw new ApplicationException("删除时出错!\n" + $"{errorInfo}"); } } }
} //居民 public ResidentAccessManagement() { using (var entity = new CommunityEpidemicManagementSystemContext()) { ResidentAccessManagementId = (Int16.Parse(entity.ResidentAccessManagements.Last().ResidentAccessManagementId) + 1).ToString(); } }
//获取全部 public static List <ResidentAccessManagement> GetAll() { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.ResidentAccessManagements.ToList()); } }
//由ID获取 public static ResidentAccessManagement Get(string id) { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.ResidentAccessManagements.Find(id)); } }
} //用户名 public Worker() { using (var entity = new CommunityEpidemicManagementSystemContext()) { WorkerId = (Int16.Parse(entity.Workers.Last().WorkerId) + 1).ToString(); } }
public TravelRecord() { using (var entity = new CommunityEpidemicManagementSystemContext()) { TravelRecordId = (Int16.Parse(entity.TravelRecords.Last().TravelRecordId) + 1).ToString(); } }
//由ID获取 public static Emergency Get(string id) { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.Emergencies.Find(id)); } }
//添加紧急事件 public static void Add(Emergency emerg) { try { using (var entity = new CommunityEpidemicManagementSystemContext()) { entity.Emergencies.Add(emerg); entity.SaveChanges(); } } catch (Exception ex) { string errorInfo = ex.Message; if (ex is DbEntityValidationException) { foreach (var validationResult in ((DbEntityValidationException)ex).EntityValidationErrors) { foreach (var error in validationResult.ValidationErrors) { errorInfo = $"{errorInfo}" + "\n" + $"{error.ErrorMessage}"; } } } throw new ApplicationException("添加时出错!\n" + $"{errorInfo}"); } }
//删除 public static void Remove(string task_id) { using (var entity = new CommunityEpidemicManagementSystemContext()) { try { AdministratorTask task = Get(task_id); entity.AdministratorTasks.Remove(task); entity.SaveChanges(); } catch (Exception ex) { string errorInfo = ex.Message; if (ex is DbEntityValidationException) { foreach (var validationResult in ((DbEntityValidationException)ex).EntityValidationErrors) { foreach (var error in validationResult.ValidationErrors) { errorInfo = $"{errorInfo}" + "\n" + $"{error.ErrorMessage}"; } } } throw new ApplicationException("删除时出错!\n" + $"{errorInfo}"); } } }
//获取全部 public static List <Emergency> GetAll() { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.Emergencies.ToList()); } }
//新增 public static void Add(AdministratorTask task) { using (var entity = new CommunityEpidemicManagementSystemContext()) { if (Get(task.AdministratorTaskId) != null) { throw new ApplicationException("已经存在!"); } try { entity.AdministratorTasks.Add(task); entity.SaveChanges(); } catch (Exception ex) { string errorInfo = ex.Message; if (ex is DbEntityValidationException) { foreach (var validationResult in ((DbEntityValidationException)ex).EntityValidationErrors) { foreach (var error in validationResult.ValidationErrors) { errorInfo = $"{errorInfo}" + "\n" + $"{error.ErrorMessage}"; } } } throw new ApplicationException("添加时出错!\n" + $"{errorInfo}"); } } }
//由ID获取 public static AdministratorTask Get(string task_id) { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.AdministratorTasks.Find(task_id)); } }
//获取全部 public static List <AdministratorTask> GetAll() { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.AdministratorTasks.ToList()); } }
//由ID获取 public static HealthInformation Get(string id) { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.HealthInformations.Find(id)); } }
//获取全部 public static List <HealthInformation> GetAll() { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.HealthInformations.ToList <HealthInformation>()); } }
//更新 public static void Update(Worker worker) { using (var entity = new CommunityEpidemicManagementSystemContext()) { try { entity.Workers.Remove(Get(worker.WorkerId)); entity.Workers.Add(worker); entity.SaveChanges(); } catch (Exception ex) { string errorInfo = ex.Message; if (ex is DbEntityValidationException) { foreach (var validationResult in ((DbEntityValidationException)ex).EntityValidationErrors) { foreach (var error in validationResult.ValidationErrors) { errorInfo = $"{errorInfo}" + "\n" + $"{error.ErrorMessage}"; } } } throw new ApplicationException("更新时出错!\n" + $"{errorInfo}"); } } }
//由ID获取 public static Worker Get(string id) { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.Workers.Find(id)); } }
public HealthInformation() { using (var entity = new CommunityEpidemicManagementSystemContext()) { HealthInformationId = (Int16.Parse(entity.HealthInformations.Last().HealthInformationId) + 1).ToString(); } }
//获取全部 public static List <Worker> GetAll() { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.Workers.ToList <Worker>()); } }
//获取全部出行经历 public static List <TravelRecord> GetAll() { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.TravelRecords.ToList <TravelRecord>()); } }
//由ID获取出行经历 public static TravelRecord Get(string id) { using (var entity = new CommunityEpidemicManagementSystemContext()) { return(entity.TravelRecords.Find(id)); } }
//按委托查找 public static List <Worker> QueryByFunc(Func <Worker, bool> func) { using (var entity = new CommunityEpidemicManagementSystemContext()) { var query = entity.Workers.Where(u => func(u)); return(query.ToList()); } }
//按用户名查询 public static List <Worker> QueryByUser(string userid) { using (var entity = new CommunityEpidemicManagementSystemContext()) { var query = entity.Workers.Where(u => u.User.UserId == userid); return(query.ToList()); } }
//按姓名查询 public static List <Worker> QueryByName(string name) { using (var entity = new CommunityEpidemicManagementSystemContext()) { var query = entity.Workers.Where(u => u.Name == name); return(query.ToList()); } }
} //用户名和id public Emergency() { using (var entity = new CommunityEpidemicManagementSystemContext()) { EmergencyId = (Int16.Parse(entity.Emergencies.Last().EmergencyId) + 1).ToString(); } EmergState = EmergencyStatus.已完成; }
} //管理员 public AdministratorTask() { using (var entity = new CommunityEpidemicManagementSystemContext()) { AdministratorTaskId = (Int16.Parse(entity.AdministratorTasks.Last().AdministratorTaskId) + 1).ToString(); } CreatedTime = DateTime.Now; }
//查询一户的出行经历 public static List <TravelRecord> QueryByUserID(String ID) { using (var entity = new CommunityEpidemicManagementSystemContext()) { var query = entity.TravelRecords.Where(t => t.User.UserId == ID); return(query.ToList()); } }
//查询某一天出发的的出行情况 public static List <TravelRecord> QueryTravelRecordByDateCome(DateTime date) { using (var entity = new CommunityEpidemicManagementSystemContext()) { var query = entity.TravelRecords.Where(t => t.DateCome == date); return(query.ToList()); } }
//查询某个日期所有居民的打卡记录 public static List <HealthInformation> QueryByDate(DateTime date) { using (var entity = new CommunityEpidemicManagementSystemContext()) { var query = entity.HealthInformations.Where(u => u.Date.Date == date.Date); return(query.ToList()); } }