Esempio n. 1
0
 public ActionResult EditFeedTask(FeedTask updateTask)
 {
     if (!ModelState.IsValid || !updateTask.UpdateFeedTask(updateTask))
     {
         return View("Error");
     }
     ViewBag.Title = "修改成功";
     return View("Message");
 }
Esempio n. 2
0
        public ActionResult CheckFeedTask(string taskNumber)
        {
            if (Session["CheckFeed"] == null || !(bool) Session["CheckFeed"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            FeedTask checkFeedtask = new FeedTask().GetFeedTask(taskNumber);
            return checkFeedtask == null ? View("Error") : View(checkFeedtask);
        }
Esempio n. 3
0
        public ActionResult EditFeedTask(string taskNumber)
        {
            if (Session["CheckFeed"] == null || !(bool) Session["EditFeed"] || !(bool) Session["CheckFeed"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            FeedTask updateTask = new FeedTask().GetFeedTask(taskNumber);

            if (updateTask == null)
            {
                return View("Error");
            }

            var listService = new ListService();

            ViewData["pighouse"] = listService.GetPigHouseList();
            ViewData["taskStatus"] = listService.GetTaskStatusList();
            ViewBag.Title = "修改喂食任务";
            return View("NewFeedTask", updateTask);
        }
Esempio n. 4
0
        /// <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;
        }
Esempio n. 5
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;
        }
Esempio n. 6
0
        /// <summary>
        ///     新建喂食任务
        /// </summary>
        /// <param name="newTask"></param>
        /// <param name="taskTypeId"></param>
        /// <param name="createEmployee">发布任务的员工工号</param>
        /// <returns></returns>
        public bool NewFeedTask(FeedTask newTask, long taskTypeId, string createEmployee)
        {
            if (createEmployee == null) throw new ArgumentNullException("createEmployee");
            var employeeService = new EmployeeService();

            var task = new task
                           {
                               TaskNumber = newTask.TaskNumber,
                               StartTime = newTask.StartTime,
                               EndTime = newTask.EndTime,
                               CreateTime = DateTime.Now,
                               CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id,
                               TaskStatusId = 1,
                               TaskTypeId = taskTypeId,
                               Memo = newTask.Memo
                           };

            //根据工号找到对应的id
            foreach (string employeeNumber in newTask.EmployeeNumber.Split(','))
            {
                task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id});
            }

            var pigstyService = new PigstyService();
            var fodderService = new FodderTypeService();
            foreach (FeedTaskDetail detail in newTask.Feeddetails)
            {
                string[] pigstyNum = detail.Pigsty.Split(',');
                long pighouseid = long.Parse(detail.PigHouse);
                string[] fodders = detail.Fodder.Split(',');
                List<long> fodderIds = fodders.Select(fodder => fodderService.FindByName(fodder).Id).ToList();

                foreach (string pigstydetail in pigstyNum)
                {
                    var taskPigsty = new task_pigsty();
                    int number = int.Parse(pigstydetail);
                    taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id;

                    foreach (long fodder in fodderIds)
                    {
                        taskPigsty.feed_task_quality.Add(new feed_task_quality {FodderTypeId = fodder});
                    }
                    task.task_pigsty.Add(taskPigsty);
                }
            }

            foreach (
                task_interval_cycle taskIntervalCycle in
                    newTask.FeedTaskCycle.Select(taskcycle => new task_interval_cycle
                                                                  {
                                                                      FirstExecuteDate = taskcycle.FirstExecuteDate,
                                                                      CycleDays = taskcycle.CycleDays
                                                                  }))
            {
                task.task_interval_cycle.Add(taskIntervalCycle);
            }
            var taskService = new TaskService();
            taskService.Insert(task);

            return true;
        }
Esempio n. 7
0
        public ActionResult NewFeedTask(FeedTask newTask)
        {
            if (!ModelState.IsValid)
            {
                return View("Error");
            }

            ViewBag.Title = newTask.NewFeedTask(newTask, TaskTypeId, User.Identity.Name.Split('|')[0])
                                ? "新建任务成功"
                                : "新建任务失败,请重新创建";
            return View("Message");
        }