/// <summary> /// 更新修改巡查信息 /// </summary> /// <param name="updateInfo">巡查页面类</param> /// <returns></returns> public bool UpdateInspectInfo(InspectInfo updateInfo, DateTime time, string employeeName) { var inspectionService = new InspectionService(); var inspectionExceptionService = new InspectionExceptionService(); var taskService = new TaskService(); int count = 0; task task = taskService.FindByTaskNumber(updateInfo.TaskNumber); if (task == null) return false; var pigHouse = new HashSet<long>(); foreach (InspectDetail detail in updateInfo.InspectDetail) pigHouse.Add(long.Parse(detail.PigHouse)); foreach ( inspection inspection in inspectionService.FindByTaskId(task.Id).Where(m => m.employee.Name.Equals(employeeName))) { if (!time.Date.Equals(inspection.Time.Date)) continue; if (count < pigHouse.Count) { inspection.PigHouseId = pigHouse.ElementAtOrDefault(count); inspection.Time = updateInfo.InspectDetail[count].DetailTime; inspection.Memo = updateInfo.Meno; inspectionService.Update(inspection); } else { inspectionExceptionService.ClearInspectionException(inspection); inspectionService = new InspectionService(); inspectionService.Delete(inspectionService.Find(inspection)); } count++; } for (; count < pigHouse.Count; count++) { inspectionService.Insert(new inspection { TaskId = task.Id, EmployeeId = long.Parse(updateInfo.EmployeeName), PigHouseId = long.Parse(updateInfo.InspectDetail[count].PigHouse), Time = updateInfo.InspectDetail[count].DetailTime, Memo = updateInfo.Meno }); } Dictionary<long, Dictionary<long, long>> pigstyAndexception = SortPigstyAndexception(updateInfo); foreach (var exception in pigstyAndexception) { count = 0; inspection inspection = inspectionService.FindByTaskId(task.Id).FirstOrDefault(m => m.employee.Name.Equals(employeeName) && m.Time.Date.Equals(time.Date) && m.PigHouseId == exception.Key); if (inspection == null) continue; foreach (var l in exception.Value) { if (count < inspection.inspection_exception.Count) { inspection_exception inspectionException = inspectionExceptionService.FindByInspectionId(inspection.Id).ElementAtOrDefault(count); if (inspectionException == null) continue; inspectionException.PigstyId = l.Key; inspectionException.ExceptionTypeId = l.Value; inspectionExceptionService.Update(inspectionException); count++; } else { var inspectionException = new inspection_exception { InspectionId = inspection.Id, PigstyId = l.Key, ExceptionTypeId = l.Value }; inspectionExceptionService.Insert(inspectionException); } } for (; count < inspection.inspection_exception.Count; count++) { inspection_exception inspectionException = inspectionExceptionService.FindByInspectionId(inspection.Id).FirstOrDefault(); if (inspectionException == null) continue; inspectionExceptionService = new InspectionExceptionService(); inspectionExceptionService.Delete(inspectionExceptionService.Find(inspectionException.Id)); } } return true; }
/// <summary> /// 删除巡查信息 /// </summary> /// <param name="taskNumber">任务编号</param> /// <param name="employeeName">人员名字</param> /// <param name="time">巡查时间</param> /// <returns></returns> public bool DelInspectInfo(string taskNumber, string employeeName, DateTime time) { var inspectionService = new InspectionService(); var inspectionExceptionService = new InspectionExceptionService(); task task = new TaskService().FindByTaskNumber(taskNumber); if (task != null) { foreach ( inspection inspectionItem in inspectionService.FindByTaskId(task.Id).Where(m => m.employee.Name.Equals(employeeName))) { if (!time.Date.Equals(inspectionItem.Time.Date)) continue; List<inspection_exception> exceptionList = inspectionExceptionService.FindByInspectionId(inspectionItem.Id); if (exceptionList.Count > 0) foreach (inspection_exception exceptionItem in exceptionList) { inspectionExceptionService = new InspectionExceptionService(); inspectionExceptionService.Delete(inspectionExceptionService.Find(exceptionItem.Id)); } inspectionService = new InspectionService(); inspectionService.Delete(inspectionService.Find(inspectionItem.Id)); } return true; } return false; }