Example #1
0
        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;
        }
Example #2
0
        /// <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;
        }