/// <summary> /// 查看转栏信息 /// </summary> /// <param name="taskNumber">任务编号</param> /// <returns></returns> public TransferPigstyInfo CheckTransferPigstyInfo(string taskNumber) { var checkTransferPigstyInfo = new TransferPigstyInfo {TransferPigstyInfoDetail = new List<TransferPigstyInfoDetail>()}; var taskEmployee = new TaskEmployeeService(); var taskService = new TaskService(); var transferService = new TransferService(); task transferPigstyTask = taskService.FindByTaskNumber(taskNumber); if (transferPigstyTask != null) { checkTransferPigstyInfo.TaskNumber = taskNumber; checkTransferPigstyInfo.EmployeeName = taskEmployee.GetEmployeeNames(transferPigstyTask.Id); transfer firstOrDefault = transferService.FindByTaskId(transferPigstyTask.Id).FirstOrDefault(); if (firstOrDefault != null) checkTransferPigstyInfo.Meno = firstOrDefault.Memo; foreach ( transfer transfer in transferService.FindByTaskId(transferPigstyTask.Id).OrderByDescending(m => m.Time)) { transfer lastPigsty = transferService.GetLastTransfer(transfer.PigId, transferPigstyTask.Id); if (lastPigsty != null && lastPigsty.pigsty.Id != transfer.pigsty.Id) checkTransferPigstyInfo.TransferPigstyInfoDetail.Add(new TransferPigstyInfoDetail { SourcePigHouse = lastPigsty.pigsty.pig_house. pig_house_type.Name + lastPigsty.pigsty.pig_house. Number, SourcePigsty = lastPigsty.pigsty.Number + "", Pig = transfer.pig.Number, TargetPigHouse = transfer.pigsty.pig_house. pig_house_type.Name + transfer.pigsty.pig_house. Number, TargetPigsty = transfer.pigsty.Number + "", TransferPigstyTime = transfer.Time }); else checkTransferPigstyInfo.TransferPigstyInfoDetail.Add(new TransferPigstyInfoDetail { SourcePigHouse = "", SourcePigsty = "", Pig = transfer.pig.Number, TargetPigHouse = transfer.pigsty.pig_house. pig_house_type.Name + transfer.pigsty.pig_house. Number, TargetPigsty = transfer.pigsty.Number + "", TransferPigstyTime = transfer.Time }); } } return checkTransferPigstyInfo; }
/// <summary> /// 查看治疗信息 /// </summary> /// <param name="employeename">治疗人员</param> /// <param name="taskNumber">任务编号</param> /// <param name="order">疗程号</param> /// <returns></returns> public CureInfo CheckCureInfo(string employeename, string taskNumber, int order) { var curePigService = new CurePigService(); var cureTaskCourseService = new CureTaskCourseService(); var cureMethodService = new CureMethodService(); var transferService = new TransferService(); var taskService = new TaskService(); var cureMedicineService = new CureMedicineService(); cure_task_course cureTaskCourse = cureTaskCourseService.FindByTaskId(taskService.FindByTaskNumber(taskNumber).Id).FirstOrDefault( m => m.Order == order); var checkCureInfo = new CureInfo { TaskNumber = taskNumber, Order = order, EmployeeName = employeename, CureDetail = new List<CureDetail>(), PigDetail = new List<Detail>() }; if (cureTaskCourse == null) return checkCureInfo; foreach ( cure_pig curePig in curePigService.FindByCureTaskCourseId(cureTaskCourse.Id).Where( m => m.employee.Name.Equals(employeename))) { transfer firstOrDefault = transferService.FindByPigId(curePig.PigId).OrderByDescending(m => m.Time).FirstOrDefault(); if (firstOrDefault != null) checkCureInfo.PigDetail.Add(new Detail { PigHouse = firstOrDefault.pigsty.pig_house.pig_house_type.Name + firstOrDefault.pigsty.pig_house.Number, Pigsty = firstOrDefault.pigsty.Number + "", Pig = firstOrDefault.pig.Number, DetailTime = (DateTime) curePig.CureTime }); } foreach (cure_method cureMethod in cureMethodService.FindByCureTaskCourseId(cureTaskCourse.Id)) { var medicineList = new List<CureMedicineDetail>(); foreach (cure_medicine cureMedicine in cureMedicineService.FindByCureMethoId(cureMethod.Id)) { medicineList.Add(new CureMedicineDetail { Medicine = cureMedicine.medicine.Name, Quality = cureMedicine.Quality, Unit = cureMedicine.unit.Name }); } checkCureInfo.CureDetail.Add(new CureDetail { CureType = cureMethod.cure_type.Name, CureMedicineDetail = medicineList }); } return checkCureInfo; }
/// <summary> /// 根据任务编号删除转栏信息 /// </summary> /// <param name="taskNumber">任务编号</param> /// <returns></returns> public bool DelTransfer(string taskNumber) { var taskService = new TaskService(); long taskId = taskService.FindByTaskNumber(taskNumber).Id; var transferService = new TransferService(); foreach (transfer transfer in transferService.FindByTaskId(taskId)) { transferService = new TransferService(); transferService.Delete(transferService.Find(transfer.Id)); } return true; }
/// <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; }
public InspectTask GetInspectTask(string taskNumber) { var taskService = new TaskService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) { return null; } var taskEmployeeService = new TaskEmployeeService(); var taskPigHouseService = new TaskPigHouseService(); var checkTask = new InspectTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), PigHouse = taskPigHouseService.GetPigHouseTypeAndNumsByTaskId(task.Id), PigHouseId = taskPigHouseService.GetPigHouseIds(task.Id), Status = task.task_status_type.Name, Memo = task.Memo }; List<TaskCycle> taskCycle = task.task_interval_cycle.Select(taskCycleitem => new TaskCycle { FirstExecuteDate = taskCycleitem . FirstExecuteDate, CycleDays = taskCycleitem . CycleDays }).ToList(); if (taskCycle.Count != 0) { checkTask.InspectTaskCycle = taskCycle; } return checkTask; }
/// <summary> /// 查看销售任务 /// </summary> /// <param name="taskNumber">任务编号</param> /// <returns></returns> public SaleTask GetSaleTask(string taskNumber) { var taskService = new TaskService(); var taskEmployeeService = new TaskEmployeeService(); var pigTypeService = new PigTypeService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) { return null; } var customerService = new CustomerService(); var checkTask = new SaleTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), Customer = customerService.Find(task.CustomerId).Name, Status = task.task_status_type.Name, Memo = task.Memo }; List<SaleDetail> saleDetailList = task.sale_task_quality.Select(item => new SaleDetail { PigType = pigTypeService.Find( item.PigTypeId).Name, Price = item.Price, Quantity = item.Quality }).ToList(); if (saleDetailList.Count != 0) { checkTask.SaleDetailList = saleDetailList; } return checkTask; }
public ActionResult FodderTakeConfirm(FodderTakeModel model) { var fodderTakeService = new FodderTakeService(); var taskService = new TaskService(); FodderTakeModel newModel = new FodderDetail().GetFodderDetail(model); foreach (FodderDetail actualDetail in model.ActualDetail) { var newFodderTake = new fodder_take { EmployeeId = model.ActualEmployeeId, TaskId = taskService.FindByTaskNumber(newModel.TaskNumber).Id, FodderTypeId = actualDetail.FodderTypeId, Quantity = actualDetail.Quality, UnitId = actualDetail.UnitId, Time = Convert.ToDateTime(DateTime.Now), Memo = model.Memo }; fodderTakeService.Insert(newFodderTake); } return View(); }
/// <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; }
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 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; }
/// <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="taskNumber">任务编号</param> /// <returns></returns> public FeedTask GetFeedTask(string taskNumber) { var taskService = new TaskService(); var taskEmployeeService = new TaskEmployeeService(); var pigHouseService = new PigHouseService(); task task = taskService.FindByTaskNumber(taskNumber); var feedTaskQualityService = new FeedTaskQualityService(); if (task == null) { return null; } var feedTask = new FeedTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), Status = task.task_status_type.Name, Memo = task.Memo }; List<FeedTaskDetail> taskDetailList = (from item in feedTaskQualityService.GetPigstyByHouse(task.Id) let keys = item.Key.Split('|') let pigHouse = pigHouseService.Find(long.Parse(keys[0])) let pigsty = item.Value.Remove(item.Value.Length - 1) select new FeedTaskDetail { PigHouse = pigHouse.pig_house_type.Name + pigHouse.Number, Pigsty = pigsty, Fodder = keys[1] }).ToList(); //var taskDetailList = new List<FeedTaskDetail>(); //foreach (var item in feedTaskQualityService.GetPigstyByHouse(task.Id)) //{ // string[] keys = item.Key.Split('|'); // pig_house pigHouse = pigHouseService.Find(long.Parse(keys[0])); // string pigsty = item.Value.Remove(item.Value.Length - 1); // taskDetailList.Add(new FeedTaskDetail // { // PigHouse = pigHouse.pig_house_type.Name + pigHouse.Number, // Pigsty = pigsty, // Fodder = keys[1] // }); //} List<TaskCycle> taskCycleList = task.task_interval_cycle.Select(taskCycleitem => new TaskCycle { FirstExecuteDate = taskCycleitem . FirstExecuteDate, CycleDays = taskCycleitem . CycleDays }).ToList(); if (taskDetailList.Count > 0) { feedTask.Feeddetails = taskDetailList; } if (taskCycleList.Count > 0) { feedTask.FeedTaskCycle = taskCycleList; } return feedTask; }
public object GetCureTask(string taskNumber) { var taskService = new TaskService(); var taskEmployeeService = new TaskEmployeeService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) { return null; } var checkTask = new CureTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), Status = task.task_status_type.Name, Memo = task.Memo }; var transferService = new TransferService(); var pigstyDic = new Dictionary<long, StringBuilder>(); foreach (task_pig item in task.task_pig) { transfer transfer = transferService.GetLastTransfer(item.PigId, task.Id); if (transfer == null) { continue; } long pigsty = transfer.PigstyId; if (!pigstyDic.ContainsKey(pigsty)) { pigstyDic.Add(pigsty, new StringBuilder().Append(transfer.pig.Number)); } else { pigstyDic[pigsty].Append("," + transfer.pig.Number); } } var pigHouseService = new PigHouseService(); var pigstyService = new PigstyService(); if (pigstyDic.Count != 0) { checkTask.CureDetail = (from builder in pigstyDic let pigHouse = pigHouseService.FindbyPigstyId(builder.Key) select new TaskDetail { PigHouse = pigHouse.pig_house_type.Name + pigHouse.Number, Pigsty = pigstyService.Find(builder.Key).Number + "", Pig = builder.Value.ToString() }).ToList(); } List<CureCourse> courseList = (from cureCourse in task.cure_task_course let methodList = (from cureMethod in cureCourse.cure_task_method let medicineList = cureMethod.cure_task_medicine.Select( cureTaskMedicine => new Medicine { MedicineName = cureTaskMedicine. medicine.Name, Quality = cureTaskMedicine. Quality, Unit = cureTaskMedicine. unit.Name }).ToList() select new CureMethod { CureMedicine = medicineList, CureType = cureMethod.cure_type.Name }).ToList() select new CureCourse { CureOrder = cureCourse.Order, CureTime = cureCourse.Time, CureMethod = methodList }).ToList(); if (courseList[0].CureMethod.Count != 0 && courseList[0].CureMethod[0].CureMedicine.Count != 0) { checkTask.CureCourse = courseList; } return checkTask; }
public PreventionDiseaseTask GetPreventionDiseaseTask(string taskNumber) { var taskService = new TaskService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) { return null; } var taskEmployeeService = new TaskEmployeeService(); List<task_pigsty> taskPigsties = task.task_pigsty.ToList(); var checkTask = new PreventionDiseaseTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), Status = task.task_status_type.Name, Memo = task.Memo }; task_prevention taskPrevention = task.task_prevention.FirstOrDefault(); if (taskPrevention != null) { checkTask.DiseaseName = taskPrevention.prevention_type.Name; checkTask.Medicine.MedicineName = new MedicineService().Find(taskPrevention.prevention_type.MedicineId).Name; checkTask.Medicine.Quality = taskPrevention.prevention_type.Quality; checkTask.Medicine.Unit = new UnitService().Find(taskPrevention.prevention_type.UnitId).Name; } var pigHouseService = new PigHouseService(); var taskPigstyService = new TaskPigstyService(); var taskPigService = new TaskPigService(); List<TaskDetail> details = taskPigstyService.GetPigHouseIds(taskPigsties).Select(pigHouseid => new TaskDetail { PigHouse = pigHouseService . Find (pigHouseid) . pig_house_type . Name + pigHouseService . Find (pigHouseid) . Number, Pigsty = taskPigstyService . GetPigstyNums (task .Id, pigHouseid), Pig = taskPigService.GetMumPigBypigStys( taskPigstyService.GetPigstyNums(task.Id, pigHouseid) , pigHouseid) }).ToList(); foreach (var munPigHouseId in taskPigService.GetPigHouseByMum(task.Id)) { details.Add(new TaskDetail() { PigHouse = pigHouseService.Find(munPigHouseId).pig_house_type.Name+pigHouseService.Find(munPigHouseId).Number, Pigsty = taskPigService.GetPigstyNumsByMum(task.Id, munPigHouseId), Pig = "母猪" }); } if (details.Count != 0) { checkTask.Taskdetails = details; } return checkTask; }
/// <summary> /// 修改喂食信息 /// </summary> /// <param name="feedInfo">已修改的喂食信息页面类</param> /// <param name="time">原时间</param> /// <param name="employeeName">原喂食人员名字</param> /// <returns></returns> public bool UpdateFeedInfo(FeedInfo feedInfo, DateTime time, string employeeName) { var feedService = new FeedService(); var fodderTakeService = new FodderTakeService(); var employeeService = new EmployeeService(); var taskService = new TaskService(); int i = 0, j = 0; employee firstOrDefault = employeeService.FindByName(employeeName).FirstOrDefault(); //var firstOrDefault = taskService.FindByTaskNumber(feedInfo.TaskNumber); if (firstOrDefault != null) { foreach (fodder_take fodderTake in fodderTakeService.FindByEmployeeId(firstOrDefault.Id)) { string num = fodderTake.task.TaskNumber; if (!time.Date.Equals(fodderTake.Time.Date) && num != feedInfo.TaskNumber) continue; if (i < feedInfo.TakeDetail.Count) { fodderTake.EmployeeId = long.Parse(feedInfo.EmployeeName); fodderTake.FodderTypeId = long.Parse(feedInfo.TakeDetail[i].FodderType); fodderTake.Quantity = feedInfo.TakeDetail[i].Quantity; fodderTake.UnitId = long.Parse(feedInfo.TakeDetail[i].Unit); fodderTake.Time = feedInfo.TakeDetail[i].TakeTime; fodderTakeService.Update(fodderTake); i++; } else { fodderTakeService = new FodderTakeService(); fodderTakeService.Delete(fodderTakeService.Find(fodderTake.Id)); } } for (; i < feedInfo.TakeDetail.Count; i++) { string num = feedInfo.TaskNumber ?? null; long id = taskService.FindByTaskNumber(num).Id; fodderTakeService.Insert(new fodder_take { TaskId = id, EmployeeId = long.Parse(feedInfo.EmployeeName), FodderTypeId = long.Parse(feedInfo.TakeDetail[i].FodderType), Quantity = feedInfo.TakeDetail[i].Quantity, UnitId = long.Parse(feedInfo.TakeDetail[i].Unit), Time = feedInfo.TakeDetail[i].TakeTime }); } employee orDefault = employeeService.Find(long.Parse(feedInfo.EmployeeName)); if (orDefault != null) foreach (feed feedItem in feedService.FindByEmployeeId(orDefault.Id)) { string num = feedItem.task.TaskNumber; if (!time.Date.Equals(feedItem.Time.Date) && num != feedInfo.TaskNumber) continue; if (j < feedInfo.FeedPig.Count) { feedItem.EmployeeId = long.Parse(feedInfo.EmployeeName); //feedItem.FodderTypeId = long.Parse(feedInfo.FeedPig[j].FodderType); //feedItem.Quality = feedInfo.FeedPig[j].Quantity; //feedItem.UnitId = long.Parse(feedInfo.FeedPig[j].Unit); feedItem.PigstyId = long.Parse(feedInfo.FeedPig[j].Pigsty); feedItem.Time = feedInfo.FeedPig[j].DetailTime; feedItem.Memo = feedInfo.Meno; feedService.Update(feedItem); j++; } else { feedService = new FeedService(); feedService.Delete(feedService.Find(feedItem.Id)); } } for (; j < feedInfo.FeedPig.Count; j++) { string num = feedInfo.TaskNumber ?? null; long id = taskService.FindByTaskNumber(num).Id; feedService.Insert(new feed { TaskId = id, EmployeeId = long.Parse(feedInfo.EmployeeName), PigstyId = long.Parse(feedInfo.FeedPig[j].Pigsty), //FodderTypeId = long.Parse(feedInfo.FeedPig[j].FodderType), //Quality = feedInfo.FeedPig[j].Quantity, //UnitId = long.Parse(feedInfo.FeedPig[j].Unit), Time = feedInfo.FeedPig[j].DetailTime, Memo = feedInfo.Meno }); } } else { return false; } return true; }
/// <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> /// <param name="employeename">治疗人员</param> /// <param name="taskNumber">任务编号</param> /// <param name="order">疗程号</param> /// <returns></returns> public bool DelCureInfo(string employeename, string taskNumber, int order) { var curePigService = new CurePigService(); var cureTaskCourseService = new CureTaskCourseService(); var cureMethodService = new CureMethodService(); var taskService = new TaskService(); var cureMedicineService = new CureMedicineService(); cure_task_course cureTaskCourse = cureTaskCourseService.FindByTaskId(taskService.FindByTaskNumber(taskNumber).Id).FirstOrDefault( m => m.Order == order); if (cureTaskCourse == null) return false; foreach ( cure_pig curePig in curePigService.FindByCureTaskCourseId(cureTaskCourse.Id).Where( m => m.employee.Name.Equals(employeename))) { foreach (cure_method cureMethod in cureMethodService.FindByCureTaskCourseId(curePig.Id)) { cureMedicineService.ClearCureMedicine(cureMethod); cureMethodService = new CureMethodService(); cureMethodService.Delete(cureMethodService.Find(cureMethod.Id)); } curePigService = new CurePigService(); curePigService.Delete(curePigService.Find(curePig.Id)); } 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; } }
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; }
/// <summary> /// 查看喂食任务 /// </summary> /// <param name="taskNumber">任务编号</param> /// <returns></returns> public AddPigTask GetAddPigTask(string taskNumber) { var taskService = new TaskService(); var taskEmployeeService = new TaskEmployeeService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) { return null; } var checkTask = new AddPigTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), Status = task.task_status_type.Name, Memo = task.Memo }; var pigHouseService = new PigHouseService(); var taskPigstyService = new TaskPigstyService(); List<task_pigsty> taskPigsties = task.task_pigsty.ToList(); List<TaskDetail> taskDetailList = taskPigstyService.GetPigHouseIds(taskPigsties).Select(pigHouseid => new TaskDetail { PigHouse = pigHouseService . Find (pigHouseid) . pig_house_type . Name + pigHouseService . Find (pigHouseid) . Number, Pigsty = taskPigstyService . GetPigstyNums (task .Id, pigHouseid), PigNum = taskPigstyService . GetPigstyCapacitySum (task .Id, pigHouseid) }).ToList(); if (taskDetailList.Count != 0) { checkTask.TaskDetails = taskDetailList; } return checkTask; }
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; }
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="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> /// <returns></returns> public EliminateTask GetEliminateTask(string taskNumber) { var taskService = new TaskService(); var taskEmployeeService = new TaskEmployeeService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) { return null; } var customerService = new CustomerService(); var checkTask = new EliminateTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), Status = task.task_status_type.Name, Memo = task.Memo }; var transferService = new TransferService(); var pigstyDic = new Dictionary<long, StringBuilder>(); foreach (task_pig item in task.task_pig) { transfer transfer = transferService.GetLastTransfer(item.PigId, task.Id); if (transfer == null) { continue; } long pigsty = transfer.PigstyId; if (!pigstyDic.ContainsKey(pigsty)) { pigstyDic.Add(pigsty, new StringBuilder().Append(transfer.pig.Number)); } else { pigstyDic[pigsty].Append("," + transfer.pig.Number); } } foreach (task_pigsty item in task.task_pigsty) { long pigsty = item.PigstyId; pigstyDic.Add(pigsty, new StringBuilder().Append("")); } var pigHouseService = new PigHouseService(); var pigstyService = new PigstyService(); if (pigstyDic.Count != 0) { checkTask.EliminateTaskDetail = (from builder in pigstyDic let pigHouse = pigHouseService.FindbyPigstyId(builder.Key) select new TaskDetail { PigHouse = pigHouse.pig_house_type.Name + pigHouse.Number, Pigsty = pigstyService.Find(builder.Key).Number + "", Pig = builder.Value.ToString() }).ToList(); } return checkTask; }
/// <summary> /// 修改转栏信息 /// </summary> /// <param name="updateTransferPigstyInfo">转栏信息页面类</param> /// <returns></returns> public bool UpdateTransferPigstyInfo(TransferPigstyInfo updateTransferPigstyInfo) { var taskService = new TaskService(); var transferService = new TransferService(); task transferPigstyTask = taskService.FindByTaskNumber(updateTransferPigstyInfo.TaskNumber); int count = 0; if (transferPigstyTask != null) { List<transfer> transferList = transferService.FindByTaskId(transferPigstyTask.Id).OrderByDescending(m => m.Time).ToList(); for (; count < transferList.Count; count++) { //transfer lastPigsty = transferService.GetLastTransfer(transferList[count].PigId, // transferPigstyTask.Id); if (count < updateTransferPigstyInfo.TransferPigstyInfoDetail.Count) { if (transferList[count] != null) { transfer lastTransfer = transferService.Find(transferList[count].Id); if (updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig == "null") updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig = lastTransfer.PigId + ""; if (updateTransferPigstyInfo.TransferPigstyInfoDetail[count].SourcePigsty != null) lastTransfer.PigstyId = long.Parse(updateTransferPigstyInfo.TransferPigstyInfoDetail[count].SourcePigsty); if (updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig != null) lastTransfer.PigId = long.Parse(updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig); transferService.Update(lastTransfer); } transferList[count].PigstyId = long.Parse(updateTransferPigstyInfo.TransferPigstyInfoDetail[count].TargetPigsty); if (updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig != null) transferList[count].PigId = long.Parse(updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig); transferList[count].Memo = updateTransferPigstyInfo.Meno; transferService.Update(transferList[count]); } else { transferService = new TransferService(); transferService.Delete(transferService.Find(transferList[count].Id)); } } for (; count < updateTransferPigstyInfo.TransferPigstyInfoDetail.Count; count++) { transferService.Insert(new transfer { TaskId = transferPigstyTask.Id, PigstyId = long.Parse( updateTransferPigstyInfo.TransferPigstyInfoDetail[count]. TargetPigsty), PigId = long.Parse( updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig), Time = updateTransferPigstyInfo.TransferPigstyInfoDetail[count]. TransferPigstyTime, Memo = updateTransferPigstyInfo.Meno }); } return true; } return false; }
public TransferTask GetTransferTask(string taskNumber) { var taskService = new TaskService(); var taskEmployeeService = new TaskEmployeeService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) { return null; } var checkTask = new TransferTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), Status = task.task_status_type.Name, Memo = task.Memo }; var transferService = new TransferService(); var pigstyDic = new Dictionary<long, StringBuilder>(); foreach (task_pig item in task.task_pig) { transfer transfer = transferService.GetLastTransfer(item.PigId, task.Id); if (transfer == null) { continue; } long pigsty = transfer.PigstyId; if (!pigstyDic.ContainsKey(pigsty)) { pigstyDic.Add(pigsty, new StringBuilder().Append(transfer.pig.Number)); } else { pigstyDic[pigsty].Append("," + transfer.pig.Number); } } var pigHouseService = new PigHouseService(); var pigstyService = new PigstyService(); if (pigstyDic.Count != 0) { List<TaskDetail> transferFromList = (from builder in pigstyDic let pigHouse = pigHouseService.FindbyPigstyId(builder.Key) select new TaskDetail { PigHouse = pigHouse.pig_house_type.Name + pigHouse.Number, Pigsty = pigstyService.Find(builder.Key).Number + "", Pig = builder.Value.ToString() }).ToList(); checkTask.TransferFrom = transferFromList; } var transferToList = new List<TaskDetail>(); var pigHouseDic = new Dictionary<string, StringBuilder>(); foreach (task_pigsty taskPigsty in task.task_pigsty) { pig_house pigHouse = pigHouseService.FindbyPigstyId(taskPigsty.PigstyId); if (pigHouse == null) { continue; } string pigHouseStr = pigHouse.pig_house_type.Name + pigHouse.Number; if (!pigHouseDic.ContainsKey(pigHouseStr)) { pigHouseDic.Add(pigHouseStr, new StringBuilder().Append(taskPigsty.pigsty.Number)); } else { pigHouseDic[pigHouseStr].Append("," + taskPigsty.pigsty.Number); } } if (pigHouseDic.Count != 0) { transferToList.AddRange(pigHouseDic.Select(builder => new TaskDetail { PigHouse = builder.Key, Pigsty = builder.Value.ToString() })); checkTask.TransferTo = transferToList; } return checkTask; }
/// <summary> /// 修改治疗信息 /// </summary> /// <param name="newInfo">治疗信息页面类</param> /// <param name="employeename">原人员名字</param> /// <returns></returns> public bool UpdateCureInfo(CureInfo newInfo, string employeename) { var curePigService = new CurePigService(); var cureTaskCourseService = new CureTaskCourseService(); var cureMethodService = new CureMethodService(); var taskService = new TaskService(); int count = 0, j = 0; var cureMedicineService = new CureMedicineService(); cure_task_course cureTaskCourse = cureTaskCourseService.FindByTaskId(taskService.FindByTaskNumber(newInfo.TaskNumber).Id).FirstOrDefault( m => m.Order == newInfo.Order); if (cureTaskCourse == null) return false; //治疗生猪信息更新 foreach (cure_pig curePig in curePigService.FindByCureTaskCourseId(cureTaskCourse.Id)) { if (!curePig.employee.Name.Equals(employeename)) continue; if (count < newInfo.PigDetail.Count) { curePig.EmployeeId = long.Parse(newInfo.EmployeeName); curePig.PigId = long.Parse(newInfo.PigDetail[count].Pig); curePig.CureTime = newInfo.PigDetail[count].DetailTime; curePig.Memo = newInfo.Meno; curePigService.Update(curePig); } else { curePigService = new CurePigService(); curePigService.Delete(curePigService.Find(curePig.Id)); } count++; } for (; count < newInfo.PigDetail.Count; count++) { curePigService.Insert(new cure_pig { CureTaskCourseId = cureTaskCourse.Id, EmployeeId = long.Parse(newInfo.EmployeeName), PigId = long.Parse(newInfo.PigDetail[count].Pig), CureTime = newInfo.PigDetail[count].DetailTime, Memo = newInfo.Meno }); } count = 0; //治疗方式信息更新 foreach (cure_method cureMethod in cureMethodService.FindByCureTaskCourseId(cureTaskCourse.Id)) { j = 0; if (count < newInfo.CureDetail.Count) { cureMethod.CureTypeId = long.Parse(newInfo.CureDetail[count].CureType); cureMethodService.Update(cureMethod); //治疗药物信息更新 foreach (cure_medicine cureMedicine in cureMedicineService.FindByCureMethoId(cureMethod.Id)) { if (j < cureMethod.cure_medicine.Count) { cureMedicine.MedicineId = long.Parse(newInfo.CureDetail[count].CureMedicineDetail[j].Medicine); cureMedicine.Quality = newInfo.CureDetail[count].CureMedicineDetail[j].Quality; cureMedicine.UnitId = long.Parse(newInfo.CureDetail[count].CureMedicineDetail[j].Unit); cureMedicineService.Update(cureMedicine); } else { cureMedicineService = new CureMedicineService(); cureMedicineService.Delete(cureMedicineService.Find(cureMedicine.Id)); } j++; } for (; j < cureMethod.cure_medicine.Count; j++) { cureMedicineService.Insert(new cure_medicine { CureMethodId = cureMethod.Id, MedicineId = long.Parse( newInfo.CureDetail[count].CureMedicineDetail[j]. Medicine), Quality = newInfo.CureDetail[count].CureMedicineDetail[j].Quality, UnitId = long.Parse( newInfo.CureDetail[count].CureMedicineDetail[j].Unit) }); } } else { cureMethodService = new CureMethodService(); cureMedicineService.ClearCureMedicine(cureMethod); cureMethodService.Delete(cureMethodService.Find(cureMethod.Id)); } count++; } for (; count < newInfo.CureDetail.Count; count++) { var cure = new cure_method { CureTaskCourseId = cureTaskCourse.Id, CureTypeId = long.Parse(newInfo.CureDetail[count].CureType) }; foreach (CureMedicineDetail cureMedicineItem in newInfo.CureDetail[count].CureMedicineDetail) { cure.cure_medicine.Add(new cure_medicine { MedicineId = long.Parse(cureMedicineItem.Medicine), Quality = cureMedicineItem.Quality, UnitId = long.Parse(cureMedicineItem.Unit) }); } cureMethodService.Insert(cure); } return true; }