/// <summary> /// 删除防疫信息 /// </summary> /// <param name="taskNumber">任务编号</param> /// <param name="employee">人名</param> /// <returns></returns> public bool DelPrevention(string taskNumber, string employee) { var preventionService = new PreventionService(); var taskService = new TaskService(); task task = taskService.FindByTaskNumber(taskNumber); if (task != null) { foreach ( prevention prevention in preventionService.FindByTaskId(task.Id).Where(m => m.employee.Name.Equals(employee))) { preventionService = new PreventionService(); preventionService.Delete(preventionService.Find(prevention.Id)); } return true; } return false; }
/// <summary> /// 查看防疫信息 /// </summary> /// <param name="taskNumber">任务编号</param> /// <returns></returns> public PreventionInfo CheckPreventionInfo(string taskNumber, string employeeName) { var preventionService = new PreventionService(); var checkPreventionInfo = new PreventionInfo(); checkPreventionInfo.PreventionInfoDetail = new List<Detail>(); var taskService = new TaskService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) return null; task_prevention firstOrDefault = task.task_prevention.FirstOrDefault(); if (firstOrDefault != null) { checkPreventionInfo.TaskNumber = taskNumber; checkPreventionInfo.EmployeeName = employeeName; checkPreventionInfo.DiseaseName = firstOrDefault.prevention_type.Name; checkPreventionInfo.Medicine = firstOrDefault.prevention_type.medicine.Name; checkPreventionInfo.Quality = firstOrDefault.prevention_type.Quality; checkPreventionInfo.Unit = firstOrDefault.prevention_type.unit1.Name; } foreach ( prevention preventionItem in preventionService.FindByTaskId(task.Id).Where(m => m.employee.Name.Equals(employeeName))) { checkPreventionInfo.PreventionInfoDetail.Add(new Detail { PigHouse = preventionItem.pigsty.pig_house.pig_house_type. Name + preventionItem.pigsty.pig_house.Number, Pigsty = preventionItem.pigsty.Number + "", DetailTime = preventionItem.Time }); } return checkPreventionInfo; }
/// <summary> /// 修改防疫信息 /// </summary> /// <param name="updateInfo">防疫页面信息</param> /// <returns></returns> public bool UpdatePreventionInfo(PreventionInfo updateInfo) { var preventionService = new PreventionService(); var taskService = new TaskService(); task task = taskService.FindByTaskNumber(updateInfo.TaskNumber); int count = 0; if (task != null) { foreach (prevention prevention in preventionService.FindByTaskId(task.Id)) { if (count < updateInfo.PreventionInfoDetail.Count) { prevention.PigstyId = long.Parse(updateInfo.PreventionInfoDetail[count].Pigsty); prevention.EmployeeId = long.Parse(updateInfo.EmployeeName); prevention.Time = updateInfo.PreventionInfoDetail[count].DetailTime; prevention.Memo = updateInfo.Meno; preventionService.Update(prevention); } else { preventionService = new PreventionService(); preventionService.Delete(preventionService.Find(prevention.Id)); } count++; } for (; count < updateInfo.PreventionInfoDetail.Count; count++) { preventionService.Insert(new prevention { PigstyId = long.Parse(updateInfo.PreventionInfoDetail[count].Pigsty), EmployeeId = long.Parse(updateInfo.EmployeeName), Time = updateInfo.PreventionInfoDetail[count].DetailTime, Memo = updateInfo.Meno }); } return true; } return false; }
/// <summary> /// 防疫信息列表 /// </summary> /// <returns></returns> public IEnumerable<Info> GetPreventionInfoList() { var preventionInfoList = new List<Info>(); var preventionService = new PreventionService(); IOrderedEnumerable<prevention> preventionAll = preventionService.FindAll().OrderByDescending(m => m.TaskId); long taskid = 0, employeeId = 0; foreach (prevention prevention in preventionAll) { if (taskid == prevention.TaskId && employeeId == prevention.EmployeeId) continue; preventionInfoList.Add(new Info { TaskNumber = prevention.task.TaskNumber, EmployeeName = prevention.employee.Name, Time = prevention.Time }); taskid = prevention.TaskId; employeeId = prevention.EmployeeId; } return preventionInfoList; }
/// <summary> /// 新建防疫信息 /// </summary> /// <param name="newInfo"></param> /// <returns></returns> public bool CreateTransferPigstyInfo(PreventionInfo newInfo) { if (newInfo == null) return false; var preventionService = new PreventionService(); var taskStatusTypeService = new TaskStatusTypeService(); var taskService = new TaskService(); foreach (Detail newInfoItem in newInfo.PreventionInfoDetail) { preventionService.Insert(new prevention { TaskId = long.Parse(newInfo.TaskNumber), EmployeeId = long.Parse(newInfo.EmployeeName), PigstyId = long.Parse(newInfoItem.Pigsty), Time = newInfoItem.DetailTime, Memo = newInfo.Meno }); } task_status_type taskStatusType = taskStatusTypeService.FindByName("已完成"); task task = taskService.Find(long.Parse(newInfo.TaskNumber)); if (taskStatusType != null && task != null) { task.TaskStatusId = taskStatusType.Id; taskService.Update(task); } return true; }
/// <summary> /// 查看生猪个体防疫记录 /// </summary> /// <param name="pigNumber"></param> /// <param name="pageIndex"> </param> /// <param name="pageSize"> </param> /// <returns></returns> public PigInfo CheckPreventionRecord(string pigNumber, int pageIndex, int pageSize) { var pigService = new PigService(); pig pig = pigService.FindByNumber(pigNumber); var transferPigsty = new TransferService(); var taskPreventionService = new TaskPreventionService(); var preventionService = new PreventionService(); var preventionInfos = new List<PreventionInfo>(); var salePigService = new SalePigService(); List<transfer> transferPigstyList = transferPigsty.FindByPigId(pig.Id).OrderBy(m => m.Time).ToList(); transfer transfer = transferPigstyList.LastOrDefault(); sale_pig salePig = salePigService.FindByPigId(pig.Id).FirstOrDefault(); DateTime? temp = null; string pigHouse = "", pigsty = ""; if (transfer != null) { pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number; pigsty = transfer.pigsty.Number + ""; } if (salePig != null) { temp = salePig.Time; } var pigInfo = new PigInfo { Number = pigNumber, Birthday = pig.Birthday, PigType = pig.pig_type.Name, PigHouse = pigHouse, Pigsty = pigsty }; if (transferPigstyList.Count == 1) { foreach (prevention preventionItem in preventionService.FindByPistyId(transferPigstyList[0].PigstyId).Where( m => m.Time > transferPigstyList[0].Time)) { if (temp != null) if (temp > preventionItem.Time) continue; task_prevention firstOrDefault = taskPreventionService.FindByTaskId(preventionItem.TaskId).FirstOrDefault(); if (firstOrDefault != null) preventionInfos.Add(new PreventionInfo { DiseaseName = firstOrDefault.prevention_type.Name, Medicine = firstOrDefault.prevention_type.medicine.Name, Time = preventionItem.Time }); } } for (int i = 0; i < transferPigstyList.Count; i++) { DateTime startTime = transferPigstyList[i].Time; DateTime endTime = DateTime.Now; if (i + 1 < transferPigstyList.Count) endTime = transferPigstyList[i + 1].Time; foreach (prevention preventionItem in preventionService.FindByPistyId(transferPigstyList[i].PigstyId).Where( m => m.Time > startTime && m.Time < endTime)) { if (temp != null) if (temp > preventionItem.Time) continue; task_prevention firstOrDefault = taskPreventionService.FindByTaskId(preventionItem.TaskId).FirstOrDefault(); if (firstOrDefault != null) preventionInfos.Add(new PreventionInfo { DiseaseName = firstOrDefault.prevention_type.Name, Medicine = firstOrDefault.prevention_type.medicine.Name, Time = preventionItem.Time }); } } pigInfo.PreventionRecord = new PagedList<PreventionInfo>(preventionInfos.OrderByDescending(m => m.Time).ToList(), pageIndex, pageSize) { Capacity = preventionInfos.Count, PageSize = pageSize, CurrentPageIndex = pageIndex, TotalItemCount = preventionInfos.Count }; return pigInfo; }