/// <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; }
/// <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; }