/// <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; }
public bool UpdateInspectTask(InspectTask updateTask) { var taskService = new TaskService(); task task = taskService.FindByTaskNumber(updateTask.TaskNumber); task.StartTime = updateTask.StartTime; task.EndTime = updateTask.EndTime; task.Memo = updateTask.Memo; taskService.Update(task); //修改喂食任务的喂食人员 new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber); new TaskPigHouseService().UpdateByPigHouseStr(task, updateTask.PigHouseId); var taskIntervalCycleService = new TaskIntervalCycleService(); for (int i = 0; i < updateTask.InspectTaskCycle.Count; i++) { if (i < task.task_interval_cycle.Count) { task_interval_cycle updateitem = taskIntervalCycleService.FindByTaskId(task.Id)[i]; updateitem.CycleDays = updateTask.InspectTaskCycle.ToList()[i].CycleDays; updateitem.FirstExecuteDate = updateTask.InspectTaskCycle.ToList()[i].FirstExecuteDate; taskIntervalCycleService.Update(updateitem); } else { var updateitem = new task_interval_cycle { TaskId = task.Id, CycleDays = updateTask.InspectTaskCycle.ToList()[i].CycleDays, FirstExecuteDate = updateTask.InspectTaskCycle.ToList()[i].FirstExecuteDate }; taskIntervalCycleService.Insert(updateitem); } } taskIntervalCycleService.DelTaskIntervalCycle(task, updateTask.InspectTaskCycle.Count); return true; }
public bool UpdateEliminateTask(EliminateTask updateTask) { var taskService = new TaskService(); var taskStatusTypeService = new TaskStatusTypeService(); task task = taskService.FindByTaskNumber(updateTask.TaskNumber); if (task == null) { return false; } task.StartTime = updateTask.StartTime; task.EndTime = updateTask.EndTime; task.Memo = updateTask.Memo; new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber); var pigService = new PigService(); int oldLen = task.task_pig.Count+task.task_pigsty.Count; int newLen = updateTask.EliminateTaskDetail.Count; int leastLength = oldLen < newLen ? oldLen : newLen; for (int i = 0; i < leastLength; i++) { if (updateTask.EliminateTaskDetail[i].Pig!=null) task.task_pig.ElementAt(i).PigId = pigService.FindByRfid(updateTask.EliminateTaskDetail[i].Pig).Id; else task.task_pigsty.ElementAt(i).PigstyId = long.Parse(updateTask.EliminateTaskDetail[i].Pigsty); } var taskPigService = new TaskPigService(); for (int i = leastLength; i < oldLen; i++) { if (task.task_pig.Count>0) taskPigService.Delete(taskPigService.Find(task.task_pig.ElementAt(i).Id)); else if (task.task_pigsty.Count > 0) taskPigService.Delete(taskPigService.Find(task.task_pigsty.ElementAt(i).Id)); } for (int i = leastLength; i < newLen; i++) { if (updateTask.EliminateTaskDetail[i].Pig!=null) task.task_pig.Add(new task_pig { PigId = pigService.FindByRfid(updateTask.EliminateTaskDetail[i].Pig).Id }); else task.task_pigsty.Add(new task_pigsty { PigstyId = long.Parse(updateTask.EliminateTaskDetail[i].Pigsty) }); } try { task.TaskStatusId = long.Parse(updateTask.Status); taskService.Update(task); return true; } catch (Exception) { return false; } }
/// <summary> /// 修改喂食任务 /// </summary> /// <param name="updateTask"></param> /// <returns></returns> public bool UpdateFeedTask(FeedTask updateTask) { var taskService = new TaskService(); var pigstyService = new PigstyService(); var taskQualityService = new FeedTaskQualityService(); var taskIntervalCycleService = new TaskIntervalCycleService(); task task = taskService.FindByTaskNumber(updateTask.TaskNumber); task.StartTime = updateTask.StartTime; task.EndTime = updateTask.EndTime; task.TaskStatusId = long.Parse(updateTask.Status); task.Memo = updateTask.Memo; //修改喂食任务的喂食人员 new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber); var pigstyFodders = new Dictionary<long, string>(); foreach (FeedTaskDetail detail in updateTask.Feeddetails) { string fodder = detail.Fodder; foreach (string s in detail.Pigsty.Split(',')) { pigstyFodders.Add(pigstyService.GetPigsty(int.Parse(s), long.Parse(detail.PigHouse)).Id, fodder); } } int oldLen = task.task_pigsty.Count; int newLen = pigstyFodders.Count; int leastLen = oldLen < newLen ? oldLen : newLen; var fodderTypeService = new FodderTypeService(); for (int i = 0; i < leastLen; i++) { KeyValuePair<long, string> pigstyFodder = pigstyFodders.ElementAt(i); task.task_pigsty.ElementAt(i).PigstyId = pigstyFodder.Key; string[] fodders = pigstyFodder.Value.Split(','); int oldLength = task.task_pigsty.ElementAt(i).feed_task_quality.Count; int newLength = fodders.Count(); int leastLength = oldLength < newLength ? oldLength : newLength; for (int j = 0; j < leastLength; j++) { task.task_pigsty.ElementAt(i).feed_task_quality.ElementAt(j).FodderTypeId = fodderTypeService.FindByName(fodders[j]).Id; } for (int j = leastLength; j < oldLength; j++) { taskQualityService.Delete( taskQualityService.Find(task.task_pigsty.ElementAt(i).feed_task_quality.ElementAt(j).Id)); } for (int j = leastLength; j < newLength; j++) { task.task_pigsty.ElementAt(i).feed_task_quality.Add(new feed_task_quality { FodderTypeId = fodderTypeService.FindByName( fodders[j]).Id }); } } var taskPigstyService = new TaskPigstyService(); for (int i = leastLen; i < oldLen; i++) { task_pigsty taskPigsty = task.task_pigsty.ElementAt(i); foreach (feed_task_quality feedTaskQuality in taskPigsty.feed_task_quality) { taskQualityService.Delete(taskQualityService.Find(feedTaskQuality.Id)); } taskPigstyService.Delete(taskPigstyService.Find(taskPigsty.Id)); } for (int i = leastLen; i < newLen; i++) { KeyValuePair<long, string> pigstyFodder = pigstyFodders.ElementAt(i); var taskPigsty = new task_pigsty { PigstyId = pigstyFodder.Key }; foreach (string item in pigstyFodder.Value.Split(',')) { taskPigsty.feed_task_quality.Add(new feed_task_quality { FodderTypeId = fodderTypeService.FindByName(item).Id }); } task.task_pigsty.Add(taskPigsty); } taskService.Update(task); for (int i = 0; i < updateTask.FeedTaskCycle.Count; i++) { if (i < task.task_interval_cycle.Count) { task_interval_cycle updateitem = taskIntervalCycleService.FindByTaskId(task.Id)[i]; updateitem.CycleDays = updateTask.FeedTaskCycle.ToList()[i].CycleDays; updateitem.FirstExecuteDate = updateTask.FeedTaskCycle.ToList()[i].FirstExecuteDate; taskIntervalCycleService.Update(updateitem); } else { var updateitem = new task_interval_cycle { TaskId = task.Id, CycleDays = updateTask.FeedTaskCycle.ToList()[i].CycleDays, FirstExecuteDate = updateTask.FeedTaskCycle.ToList()[i].FirstExecuteDate }; taskIntervalCycleService.Insert(updateitem); } } taskIntervalCycleService.DelTaskIntervalCycle(task, updateTask.FeedTaskCycle.Count); return true; }
/// <summary> /// 新建淘汰信息 /// </summary> /// <param name="newInfo"></param> /// <returns></returns> public bool CreateEliminateInfo(EliminateInfo newInfo) { var salesService = new SaleService(); var taskStatusTypeService = new TaskStatusTypeService(); var taskService = new TaskService(); var pigService = new PigService(); var pigInfo = new PigInfo(); var newSale = new sale { TaskId = long.Parse(newInfo.TaskNumber), EmployeeId = long.Parse(newInfo.EmployeeName), SaleType = "淘汰", Memo = newInfo.Meno }; foreach (Detail salesPigInfo in newInfo.EliminateInfoPigDetail) { newSale.sale_pig.Add(new sale_pig { Time = salesPigInfo.DetailTime, PigId = long.Parse(salesPigInfo.Pig) }); pigInfo.SetState(long.Parse(salesPigInfo.Pig), true); } salesService.Insert(newSale); 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="newPigInfo"></param> /// <returns></returns> public bool CreatePigInfo(PigInfo newPigInfo) { var pigService = new PigService(); var transferService = new TransferService(); var taskStatusTypeService = new TaskStatusTypeService(); var taskService = new TaskService(); if (newPigInfo == null) return false; long? earNumber = null, femaleParentId = null, mostLikelyMaleParentId = null, secondLikelyMaleParentId = null, thirdLikelyMaleParentId = null; if (newPigInfo.EarNumber != null) earNumber = long.Parse(newPigInfo.EarNumber); if (newPigInfo.FemaleParentNum != null) femaleParentId = long.Parse(newPigInfo.FemaleParentNum); if (newPigInfo.MostLikelyMaleParentNum != null) mostLikelyMaleParentId = long.Parse(newPigInfo.MostLikelyMaleParentNum); if (newPigInfo.SecondLikelyMaleParentNum != null) secondLikelyMaleParentId = long.Parse(newPigInfo.SecondLikelyMaleParentNum); if (newPigInfo.ThirdLikelyMaleParentNum != null) thirdLikelyMaleParentId = long.Parse(newPigInfo.ThirdLikelyMaleParentNum); if (newPigInfo.TaskNumber == null) return false; pigService.Insert(new pig { Number = newPigInfo.Number, EarNumber = earNumber, Birthday = newPigInfo.Birthday, RFID = newPigInfo.Rfid, PigTypeId = long.Parse(newPigInfo.PigType), FemaleParentId = femaleParentId, MostLikelyMaleParentId = mostLikelyMaleParentId, SecondLikelyMaleParentId = secondLikelyMaleParentId, ThirdLikelyMaleParentId = thirdLikelyMaleParentId, Memo = newPigInfo.Memo, State = true }); if (newPigInfo.TaskNumber != null) { transferService.Insert(new transfer { TaskId = long.Parse(newPigInfo.TaskNumber), PigId = pigService.FindByNumber(newPigInfo.Number).Id, PigstyId = long.Parse(newPigInfo.Pigsty), Time = newPigInfo.TransferPigstyTime }); } pigService = new PigService(); task_status_type taskStatusType = taskStatusTypeService.FindByName("已完成"); task task = taskService.Find(long.Parse(newPigInfo.TaskNumber)); if (taskStatusType != null && task != null) { task.TaskStatusId = taskStatusType.Id; taskService.Update(task); } return true; }
/// <summary> /// 新建转栏信息 /// </summary> /// <param name="newTransferPigstyInfo">转栏信息页面类</param> /// <returns>是否成功</returns> public bool CreateTransferPigstyInfo(TransferPigstyInfo newTransferPigstyInfo) { if (newTransferPigstyInfo == null) return false; var transferService = new TransferService(); var taskStatusTypeService = new TaskStatusTypeService(); var taskService = new TaskService(); foreach (TransferPigstyInfoDetail transferPigstyInfoDetail in newTransferPigstyInfo.TransferPigstyInfoDetail ) { transferService.Insert(new transfer { TaskId = long.Parse(newTransferPigstyInfo.TaskNumber), PigstyId = long.Parse(transferPigstyInfoDetail.TargetPigsty), PigId = long.Parse(transferPigstyInfoDetail.Pig), Time = transferPigstyInfoDetail.TransferPigstyTime, Memo = newTransferPigstyInfo.Meno }); } task_status_type taskStatusType = taskStatusTypeService.FindByName("已完成"); task task = taskService.Find(long.Parse(newTransferPigstyInfo.TaskNumber)); if (taskStatusType != null && task != null) { task.TaskStatusId = taskStatusType.Id; taskService.Update(task); } return true; }
public bool UpdateSaleTask(SaleTask updateTask) { var taskService = new TaskService(); task task = taskService.FindByTaskNumber(updateTask.TaskNumber); if (task == null) { return false; } task.StartTime = updateTask.StartTime; task.EndTime = updateTask.EndTime; task.Memo = updateTask.Memo; var customerService = new CustomerService(); customer customer = customerService.FindByName(updateTask.Customer) ?? customerService.Insert(new customer { Name = updateTask . Customer }); task.CustomerId = customer.Id; new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber); int oldLen = task.sale_task_quality.Count; int newLen = updateTask.SaleDetailList.Count; int leastLength = oldLen < newLen ? oldLen : newLen; for (int i = 0; i < leastLength; i++) { task.sale_task_quality.ElementAt(i).PigTypeId = long.Parse(updateTask.SaleDetailList[i].PigType); task.sale_task_quality.ElementAt(i).Price = updateTask.SaleDetailList[i].Price; task.sale_task_quality.ElementAt(i).Quality = updateTask.SaleDetailList[i].Quantity; } var saleTaskQualityService = new SaleTaskQualityService(); for (int i = leastLength; i < oldLen; i++) { saleTaskQualityService.Delete(saleTaskQualityService.Find(task.sale_task_quality.ElementAt(i).Id)); } for (int i = leastLength; i < newLen; i++) { task.sale_task_quality.Add(new sale_task_quality { PigTypeId = long.Parse(updateTask.SaleDetailList[i].PigType), Price = updateTask.SaleDetailList[i].Price, Quality = updateTask.SaleDetailList[i].Quantity }); } try { task.TaskStatusId = long.Parse(updateTask.Status); taskService.Update(task); return true; } catch (Exception) { return false; } }
/// <summary> /// 新建巡查信息 /// </summary> /// <param name="newInfo">巡查页面类</param> /// <returns></returns> public bool CreateInspectInfo(InspectInfo newInfo) { if (newInfo == null) return false; var inspectionService = new InspectionService(); var taskStatusTypeService = new TaskStatusTypeService(); var taskService = new TaskService(); Dictionary<long, Dictionary<long, long>> pigstyAndexception = SortPigstyAndexception(newInfo); foreach (var inspectDetail in pigstyAndexception) { InspectDetail newInfoDetail = newInfo.InspectDetail.FirstOrDefault(m => m.PigHouse.Equals(inspectDetail.Key + "")); if (newInfoDetail == null) continue; var inspection = new inspection { TaskId = long.Parse(newInfo.TaskNumber), EmployeeId = long.Parse(newInfo.EmployeeName), PigHouseId = inspectDetail.Key, Time = newInfoDetail.DetailTime, Memo = newInfo.Meno }; foreach (var pigsty in inspectDetail.Value) { inspection.inspection_exception.Add(new inspection_exception { PigstyId = pigsty.Key, ExceptionTypeId = pigsty.Value }); } inspectionService.Insert(inspection); } 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; }
public bool UpdateTransferTask(TransferTask updateTask) { var taskService = new TaskService(); task task = taskService.FindByTaskNumber(updateTask.TaskNumber); if (task == null) { return false; } task.StartTime = updateTask.StartTime; task.EndTime = updateTask.EndTime; task.Memo = updateTask.Memo; new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber); var pigService = new PigService(); List<long> pigList = (from taskDetail in updateTask.TransferFrom from pig in taskDetail.Pig.Split(',') select pigService.FindByNumber(pig).Id).ToList(); int oldLen = task.task_pig.Count; int newLen = pigList.Count; int leastLength = oldLen < newLen ? oldLen : newLen; for (int i = 0; i < leastLength; i++) { task.task_pig.ElementAt(i).PigId = pigList[i]; } var transferTaskPigService = new TaskPigService(); for (int i = leastLength; i < oldLen; i++) { transferTaskPigService.Delete(transferTaskPigService.Find(task.task_pig.ElementAt(i).Id)); } for (int i = leastLength; i < newLen; i++) { task.task_pig.Add(new task_pig { PigId = pigList[i] }); } var pigstyService = new PigstyService(); List<long> pigstyList = (from taskDetail in updateTask.TransferTo from pigsty in taskDetail.Pigsty.Split(',') select pigstyService.FindByNumber(int.Parse(pigsty)).First( m => m.PigHouseId == long.Parse(taskDetail.PigHouse)).Id).ToList(); oldLen = task.task_pigsty.Count; newLen = pigstyList.Count; leastLength = oldLen < newLen ? oldLen : newLen; for (int i = 0; i < leastLength; i++) { task.task_pigsty.ElementAt(i).PigstyId = pigstyList[i]; } var taskPigstyService = new TaskPigstyService(); for (int i = leastLength; i < oldLen; i++) { taskPigstyService.Delete(taskPigstyService.Find(task.task_pigsty.ElementAt(i).Id)); } for (int i = leastLength; i < newLen; i++) { task.task_pigsty.Add(new task_pigsty { PigstyId = pigstyList[i] }); } taskService.Update(task); return true; }
public bool UpdateCureTask(CureTask updateTask) { var taskService = new TaskService(); task task = taskService.FindByTaskNumber(updateTask.TaskNumber); if (task == null) { return false; } task.StartTime = updateTask.StartTime; task.EndTime = updateTask.EndTime; task.Memo = updateTask.Memo; new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber); var pigService = new PigService(); List<long> pigList = (from taskDetail in updateTask.CureDetail from pig in taskDetail.Pig.Split(',') select pigService.FindByNumber(pig).Id).ToList(); int oldLen = task.task_pig.Count; int newLen = pigList.Count; int leastLen = oldLen < newLen ? oldLen : newLen; for (int i = 0; i < leastLen; i++) { task.task_pig.ElementAt(i).PigId = pigList[i]; } var taskPigService = new TaskPigService(); for (int i = leastLen; i < oldLen; i++) { taskPigService.Delete(taskPigService.Find(task.task_pig.ElementAt(i).Id)); } for (int i = leastLen; i < newLen; i++) { task.task_pig.Add(new task_pig { PigId = pigList[i] }); } oldLen = task.cure_task_course.Count; newLen = updateTask.CureCourse.Count; leastLen = oldLen < newLen ? oldLen : newLen; var cureTaskMedicineService = new CureTaskMedicineService(); var cureTaskMethodService = new CureTaskMethodService(); for (int i = 0; i < leastLen; i++) { CureCourse cureCourse = updateTask.CureCourse[i]; task.cure_task_course.ElementAt(i).Order = cureCourse.CureOrder; task.cure_task_course.ElementAt(i).Time = cureCourse.CureTime; int oldLen2 = task.cure_task_course.ElementAt(i).cure_task_method.Count; int newLen2 = cureCourse.CureMethod.Count; int leastLen2 = oldLen2 < newLen2 ? oldLen2 : newLen2; for (int j = 0; j < leastLen2; j++) { task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).CureTypeId = long.Parse(cureCourse.CureMethod[j].CureType); int oldLen3 = task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).cure_task_medicine.Count; int newLen3 = cureCourse.CureMethod[j].CureMedicine.Count; int leastLen3 = oldLen3 < newLen3 ? oldLen3 : newLen3; for (int k = 0; k < leastLen3; k++) { Medicine medicine = cureCourse.CureMethod[j].CureMedicine[k]; if (medicine.Quality <= 0) { continue; } task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).cure_task_medicine.ElementAt(k) .MedicineId = long.Parse(medicine.MedicineName); task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).cure_task_medicine.ElementAt(k) .Quality = medicine.Quality; task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).cure_task_medicine.ElementAt(k) .UnitId = long.Parse(medicine.Unit); } for (int k = leastLen; k < oldLen3; k++) { cureTaskMedicineService.Delete( cureTaskMedicineService.Find( task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).cure_task_medicine. ElementAt(k).Id)); } for (int k = leastLen; k < newLen3; k++) { Medicine medicine = cureCourse.CureMethod[j].CureMedicine[k]; if (medicine.Quality <= 0) { continue; } task.cure_task_course.ElementAt(i) .cure_task_method.ElementAt(j) .cure_task_medicine.Add(new cure_task_medicine { MedicineId = long . Parse (medicine . MedicineName), Quality = medicine . Quality, UnitId = long . Parse (medicine . Unit) }); } } for (int j = leastLen2; j < oldLen2; j++) { cure_task_method cureTaskMethod = task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j); foreach (cure_task_medicine cureTaskMedicine in cureTaskMethod.cure_task_medicine) { cureTaskMedicineService.Delete(cureTaskMedicineService.Find(cureTaskMedicine.Id)); } cureTaskMethodService.Delete(cureTaskMethodService.Find(cureTaskMethod.Id)); } for (int j = leastLen2; j < newLen2; j++) { CureMethod cureMethod = cureCourse.CureMethod[j]; var medicineList = new Collection<cure_task_medicine>(); foreach (Medicine medicine in cureMethod.CureMedicine.Where(medicine => !(medicine.Quality <= 0))) { medicineList.Add(new cure_task_medicine { MedicineId = long.Parse(medicine.MedicineName), Quality = medicine.Quality, UnitId = long.Parse(medicine.Unit) }); } task.cure_task_course.ElementAt(i).cure_task_method.Add(new cure_task_method { CureTypeId = long.Parse(cureMethod.CureType), cure_task_medicine = medicineList }); } } var cureTaskCourseService = new CureTaskCourseService(); for (int i = leastLen; i < oldLen; i++) { foreach (cure_method cureMethod in task.cure_task_course.ElementAt(i).cure_method) { foreach (cure_medicine cureMedicine in cureMethod.cure_medicine) { cureTaskMedicineService.Delete(cureTaskMedicineService.Find(cureMedicine.Id)); } cureTaskMethodService.Delete(cureTaskMethodService.Find(cureMethod.Id)); } cureTaskCourseService.Delete(cureTaskCourseService.Find(task.cure_task_course.ElementAt(i).Id)); } for (int i = leastLen; i < newLen; i++) { var methodList = new Collection<cure_task_method>(); CureCourse cureCourse = updateTask.CureCourse[i]; foreach (CureMethod cureMethod in cureCourse.CureMethod) { var medicineList = new Collection<cure_task_medicine>(); foreach (Medicine medicine in cureMethod.CureMedicine.Where(medicine => !(medicine.Quality <= 0))) { medicineList.Add(new cure_task_medicine { MedicineId = long.Parse(medicine.MedicineName), Quality = medicine.Quality, UnitId = long.Parse(medicine.Unit) }); } methodList.Add(new cure_task_method { CureTypeId = long.Parse(cureMethod.CureType), cure_task_medicine = medicineList }); } task.cure_task_course.Add(new cure_task_course { Order = cureCourse.CureOrder, Time = cureCourse.CureTime, cure_task_method = methodList }); } taskService.Update(task); return true; }
/// <summary> /// 新建治疗信息 /// </summary> /// <param name="newInfo"></param> /// <returns></returns> public bool CreateCureInfo(CureInfo newInfo) { var curePigService = new CurePigService(); var cureTaskCourseService = new CureTaskCourseService(); var cureMethodService = new CureMethodService(); var taskStatusTypeService = new TaskStatusTypeService(); var taskService = new TaskService(); cure_task_course cureTaskCourse = cureTaskCourseService.FindByTaskId(long.Parse(newInfo.TaskNumber)).FirstOrDefault( m => m.Order == newInfo.Order); if (cureTaskCourse == null) return false; foreach (Detail detail in newInfo.PigDetail) { curePigService.Insert(new cure_pig { EmployeeId = long.Parse(newInfo.EmployeeName), CureTaskCourseId = cureTaskCourse.Id, PigId = long.Parse(detail.Pig), CureTime = detail.DetailTime, Memo = newInfo.Meno }); } foreach (CureDetail cureDetail in newInfo.CureDetail) { var cureMethod = new cure_method { CureTaskCourseId = cureTaskCourse.Id , CureTypeId = long.Parse(cureDetail.CureType) }; foreach (CureMedicineDetail cureMedicineDetail in cureDetail.CureMedicineDetail) { cureMethod.cure_medicine.Add(new cure_medicine { MedicineId = long.Parse(cureMedicineDetail.Medicine), Quality = cureMedicineDetail.Quality, UnitId = long.Parse(cureMedicineDetail.Unit) }); } cureMethodService.Insert(cureMethod); } 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="newFeedInfo"></param> /// y /// <returns></returns> public bool CreateFeedInfo(FeedInfo newFeedInfo) { var employeeService = new EmployeeService(); var feedService = new FeedService(); var fodderTakeService = new FodderTakeService(); var taskService = new TaskService(); var fodderTypeService = new FodderTypeService(); var unitService = new UnitService(); var taskStatusTypeService = new TaskStatusTypeService(); long taskId = long.Parse(TaskNumber); foreach (FodderTakeDetail takedetail in newFeedInfo.TakeDetail) { employee firstOrDefault = employeeService.Find(long.Parse(newFeedInfo.EmployeeName)); if (firstOrDefault != null) { var take = new fodder_take { TaskId = taskId, EmployeeId = firstOrDefault.Id, //FodderTypeId = fodderTypeService.Find(long.Parse(takedetail.FodderType)).Id, //Quantity = takedetail.Quantity, //UnitId = unitService.Find(long.Parse(takedetail.Unit)).Id, Time = takedetail.TakeTime }; fodderTakeService.Insert(take); } } foreach (FeedInfoDetail feedPigDetail in FeedPig) { var feedinfo = new feed {TaskId = taskId}; employee firstOrDefault = employeeService.Find(long.Parse(newFeedInfo.EmployeeName)); if (firstOrDefault != null) feedinfo.EmployeeId = firstOrDefault.Id; feedinfo.PigstyId = long.Parse(feedPigDetail.Pigsty); //feedinfo.FodderTypeId = long.Parse(feedPigDetail.FodderType); //feedinfo.Quality = feedPigDetail.Quantity; //feedinfo.UnitId = long.Parse(feedPigDetail.Unit); feedinfo.Memo = newFeedInfo.Meno; feedinfo.Time = feedPigDetail.DetailTime; feedService.Insert(feedinfo); } task_status_type taskStatusType = taskStatusTypeService.FindByName("正在进行"); task task = taskService.Find(long.Parse(newFeedInfo.TaskNumber)); if (taskStatusType != null && task != null) { task.TaskStatusId = taskStatusType.Id; taskService.Update(task); } return true; }
public bool UpdatePreventionDiseaseTask(PreventionDiseaseTask updateTask) { var taskService = new TaskService(); task task = taskService.FindByTaskNumber(updateTask.TaskNumber); if (task == null) { return false; } task.StartTime = updateTask.StartTime; task.EndTime = updateTask.EndTime; task.Memo = updateTask.Memo; if (task.task_prevention.FirstOrDefault() == null) { task.task_prevention.Add(new task_prevention { PreventionTypeId = long.Parse(updateTask.DiseaseName) }); } else { task.task_prevention.First().PreventionTypeId = long.Parse(updateTask.DiseaseName); } new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber); var pigstyService = new PigstyService(); List<long> pigstyList = (from taskDetail in updateTask.Taskdetails from pigsty in taskDetail.Pigsty.Split(',') select pigstyService.FindByNumber(int.Parse(pigsty)).First( m => m.PigHouseId == long.Parse(taskDetail.PigHouse)).Id).ToList(); int oldLen = task.task_pigsty.Count; int newLen = pigstyList.Count; int leastLength = oldLen < newLen ? oldLen : newLen; for (int i = 0; i < leastLength; i++) { task.task_pigsty.ElementAt(i).PigstyId = pigstyList[i]; } var taskPigstyService = new TaskPigstyService(); for (int i = leastLength; i < oldLen; i++) { taskPigstyService.Delete(taskPigstyService.Find(task.task_pigsty.ElementAt(i).Id)); } for (int i = leastLength; i < newLen; i++) { task.task_pigsty.Add(new task_pigsty { PigstyId = pigstyList[i] }); } taskService.Update(task); return true; }