/// <summary> /// 查看喂食信息 /// </summary> /// <param name="employeename">选中喂食信息的喂食人员</param> /// <param name="taskNumber">喂食任务编号</param> /// <param name="time">喂食时间</param> /// <returns></returns> public FeedInfo CheckFeedInfo(string employeename, string taskNumber, DateTime time) { var checkFeedInfo = new FeedInfo(); var feedService = new FeedService(); var fodderTakeService = new FodderTakeService(); var employeeService = new EmployeeService(); //var taskService = new TaskService(); checkFeedInfo.TaskNumber = taskNumber; checkFeedInfo.EmployeeName = employeename; checkFeedInfo.TakeDetail = new List<FodderTakeDetail>(); checkFeedInfo.FeedPig = new List<FeedInfoDetail>(); employee firstOrDefault = employeeService.FindByName(employeename).FirstOrDefault(); if (firstOrDefault != null) foreach (fodder_take fodderTake in fodderTakeService.FindByEmployeeId(firstOrDefault.Id)) //task firstOrDefault = taskService.FindByTaskNumber(taskNumber); //if (firstOrDefault != null) //foreach (fodder_take fodderTake in fodderTakeService.FindByTaskId(firstOrDefault.Id)) { string num = fodderTake.task.TaskNumber; if (!time.Date.Equals(fodderTake.Time.Date) && num != taskNumber) continue; checkFeedInfo.TakeDetail.Add(new FodderTakeDetail { FodderType = fodderTake.fodder_type.Name, Quantity = fodderTake.Quantity, Unit = fodderTake.unit.Name, TakeTime = fodderTake.Time }); } employee orDefault = employeeService.FindByName(employeename).FirstOrDefault(); if (orDefault != null) foreach (feed feedItem in feedService.FindByEmployeeId(orDefault.Id)) { string num = feedItem.task.TaskNumber; if (!time.Date.Equals(feedItem.Time.Date) && num != taskNumber) continue; checkFeedInfo.FeedPig.Add(new FeedInfoDetail { DetailTime = feedItem.Time, PigHouse = feedItem.pigsty.pig_house.pig_house_type.Name + feedItem.pigsty.pig_house.Number, Pigsty = feedItem.pigsty.Number + string.Empty //FodderType = feedItem.fodder_type.Name, //Quantity = feedItem.Quality, //Unit = feedItem.unit.Name }); checkFeedInfo.Meno = feedItem.Memo; } return checkFeedInfo; }
/// <summary> /// 删除饲料领取信息 /// </summary> /// <param name="employeename">领取人员</param> /// <param name="taskNumber">任务编号</param> /// <param name="time">领取时间</param> /// <returns></returns> public bool DelFodderTake(string employeename, string taskNumber, DateTime time) { var fodderTakeService = new FodderTakeService(); var employeeService = new EmployeeService(); // var taskService = new TaskService(); employee firstOrDefault = employeeService.FindByName(employeename).FirstOrDefault(); //var firstOrDefault = taskService.FindByTaskNumber(taskNumber); if (firstOrDefault == null) { return false; } for (int i = 0; i < fodderTakeService.FindByEmployeeId(firstOrDefault.Id).Count; i++) { fodder_take fodderTake = fodderTakeService.FindByEmployeeId(firstOrDefault.Id)[i]; string num = fodderTake.task.TaskNumber; if (!time.Date.Equals(fodderTake.Time.Date) && num == taskNumber) continue; fodderTakeService = new FodderTakeService(); fodderTakeService.Delete(fodderTakeService.Find(fodderTake.Id)); } return true; }
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="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="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; }