public ActionResult CheckAddPigTask(string taskNumber)
        {
            if (Session["CheckFeed"] == null || !(bool)Session["CheckAddPig"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            AddPigTask checkAddPigtask = new AddPigTask().GetAddPigTask(taskNumber);
            return checkAddPigtask == null ? View("Error") : View(checkAddPigtask);
        }
        public ActionResult EditAddPigTask(string taskNumber)
        {
            if (Session["CheckFeed"] == null || !(bool)Session["EditAddPig"] || !(bool)Session["CheckAddPig"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            AddPigTask updateTask = new AddPigTask().GetAddPigTask(taskNumber);

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

            var listService = new ListService();

            ViewData["pighouse"] = listService.GetPigHouseList();
            ViewData["taskStatus"] = listService.GetTaskStatusList();
            ViewBag.Title = "修改添加生猪任务";
            return View("NewAddPigTask", updateTask);
        }
 public ActionResult EditAddPigTask(AddPigTask updateTask)
 {
     if (Session["CheckFeed"] == null || !ModelState.IsValid || !updateTask.UpdateAddPigTask(updateTask))
     {
         return View("Error");
     }
     ViewBag.Title = "修改成功";
     return View("Message");
 }
        public ActionResult NewAddPigTask(AddPigTask newTask)
        {
            if (!ModelState.IsValid)
            {
                return View("Error");
            }

            ViewBag.Title = newTask.NewAddPigTask(newTask, TaskTypeId, User.Identity.Name.Split('|')[0])
                                ? "新建任务成功"
                                : "新建任务失败,请重新创建";
            return View("Message");
        }
Esempio n. 5
0
        /// <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;
        }
Esempio n. 6
0
        public bool UpdateAddPigTask(AddPigTask 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 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;
        }
Esempio n. 7
0
        /// <summary>
        ///     新建销售任务
        /// </summary>
        /// <param name="newTask">销售任务</param>
        /// <param name="taskTypeId">任务类型id</param>
        /// <param name="createEmployee">发布任务的员工工号</param>
        /// <returns>返回新建任务是否成功</returns>
        public bool NewAddPigTask(AddPigTask newTask, long taskTypeId, string 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
                           };

            foreach (string employeeNumber in newTask.EmployeeNumber.Split(','))
            {
                task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id});
            }

            var pigstyService = new PigstyService();
            foreach (TaskDetail detail in newTask.TaskDetails)
            {
                string[] pigstyNum = detail.Pigsty.Split(new[] {','});
                long pighouseid = long.Parse(detail.PigHouse);
                foreach (string pigstydetail in pigstyNum)
                {
                    var taskPigsty = new task_pigsty();
                    int number = int.Parse(pigstydetail);
                    taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id;
                    task.task_pigsty.Add(taskPigsty);
                }
            }

            var taskService = new TaskService();
            taskService.Insert(task);

            return true;
        }