public ActionResult EditEliminateTask(EliminateTask updateTask)
 {
     if (updateTask == null || !updateTask.UpdateEliminateTask(updateTask))
     {
         return View("Error");
     }
     ViewBag.Title = "修改成功";
     return View("Message");
 }
        public ActionResult CheckEliminateTask(string taskNumber)
        {
            if (Session["CheckEliminateTask"] == null || !(bool)Session["CheckEliminateTask"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            EliminateTask checkEliminateTask = new EliminateTask().GetEliminateTask(taskNumber);
            return checkEliminateTask == null ? View("Error") : View(checkEliminateTask);
        }
        public ActionResult EditEliminateTask(string taskNumber)
        {
            if (Session["CheckEliminateTask"] == null || !(bool)Session["EditEliminateTask"] || !(bool)Session["CheckEliminateTask"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            EliminateTask updateTask = new EliminateTask().GetEliminateTask(taskNumber);

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

            var listService = new ListService();
            IEnumerable<SelectListItem> pighouse = listService.GetPigHouseList();
            ViewData["Status"] = listService.GetTaskStatusList();
            ViewData["PigHouse"] = pighouse;
            ViewData["Pigsty"] = listService.FindPigstyListByPigHouseId(pighouse.First().Value);
            ViewBag.Title = "修改淘汰任务";
            return View("NewEliminateTask", updateTask);
        }
Example #4
0
        /// <summary>
        ///     查看淘汰任务
        /// </summary>
        /// <param name="taskNumber">任务编号</param>
        /// <returns></returns>
        public EliminateTask GetEliminateTask(string taskNumber)
        {
            var taskService = new TaskService();
            var taskEmployeeService = new TaskEmployeeService();

            task task = taskService.FindByTaskNumber(taskNumber);

            if (task == null)
            {
                return null;
            }

            var customerService = new CustomerService();
            var checkTask = new EliminateTask
            {
                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 transferService = new TransferService();
            var pigstyDic = new Dictionary<long, StringBuilder>();

            foreach (task_pig item in task.task_pig)
            {
                transfer transfer = transferService.GetLastTransfer(item.PigId, task.Id);
                if (transfer == null)
                {
                    continue;
                }
                long pigsty = transfer.PigstyId;

                if (!pigstyDic.ContainsKey(pigsty))
                {
                    pigstyDic.Add(pigsty, new StringBuilder().Append(transfer.pig.Number));
                }
                else
                {
                    pigstyDic[pigsty].Append("," + transfer.pig.Number);
                }
            }

            foreach (task_pigsty item in task.task_pigsty)
            {

                long pigsty = item.PigstyId;

                    pigstyDic.Add(pigsty, new StringBuilder().Append(""));

            }
            var pigHouseService = new PigHouseService();
            var pigstyService = new PigstyService();
            if (pigstyDic.Count != 0)
            {
                checkTask.EliminateTaskDetail = (from builder in pigstyDic
                                        let pigHouse = pigHouseService.FindbyPigstyId(builder.Key)
                                        select new TaskDetail
                                        {
                                            PigHouse =
                                                pigHouse.pig_house_type.Name + pigHouse.Number,
                                            Pigsty = pigstyService.Find(builder.Key).Number + "",
                                            Pig = builder.Value.ToString()
                                        }).ToList();
            }

            return checkTask;
        }
Example #5
0
        public bool UpdateEliminateTask(EliminateTask updateTask)
        {
            var taskService = new TaskService();
            var taskStatusTypeService = new TaskStatusTypeService();
            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 pigService = new PigService();
            int oldLen = task.task_pig.Count+task.task_pigsty.Count;
            int newLen = updateTask.EliminateTaskDetail.Count;
            int leastLength = oldLen < newLen ? oldLen : newLen;

            for (int i = 0; i < leastLength; i++)
            {
                if (updateTask.EliminateTaskDetail[i].Pig!=null)
                task.task_pig.ElementAt(i).PigId = pigService.FindByRfid(updateTask.EliminateTaskDetail[i].Pig).Id;
                else
                    task.task_pigsty.ElementAt(i).PigstyId = long.Parse(updateTask.EliminateTaskDetail[i].Pigsty);
            }

            var taskPigService = new TaskPigService();

            for (int i = leastLength; i < oldLen; i++)
            {
                if (task.task_pig.Count>0)
                taskPigService.Delete(taskPigService.Find(task.task_pig.ElementAt(i).Id));
                else if (task.task_pigsty.Count > 0)
                    taskPigService.Delete(taskPigService.Find(task.task_pigsty.ElementAt(i).Id));
            }

            for (int i = leastLength; i < newLen; i++)
            {
                if (updateTask.EliminateTaskDetail[i].Pig!=null)
                task.task_pig.Add(new task_pig
                {
                    PigId = pigService.FindByRfid(updateTask.EliminateTaskDetail[i].Pig).Id
                });
                else
                    task.task_pigsty.Add(new task_pigsty
                    {
                         PigstyId = long.Parse(updateTask.EliminateTaskDetail[i].Pigsty)
                    });
            }

            try
            {

                task.TaskStatusId = long.Parse(updateTask.Status);
                taskService.Update(task);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Example #6
0
        /// <summary>
        /// 新建淘汰任务
        /// </summary>
        /// <param name="newTask"></param>
        /// <param name="taskTypeId"></param>
        /// <param name="createEmployee"></param>
        /// <returns></returns>
        public bool NewEliminateTask(EliminateTask 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 pigService = new PigService();

            foreach (var  detail in newTask.EliminateTaskDetail)
            {
                if (detail.Pig != null)
                {
                    var detailPigs = detail.Pig.Split(',');
                    foreach (var str in detailPigs)
                        task.task_pig.Add(new task_pig
                        {
                            PigId = pigService.FindByRfid(str).Id
                        });
                }
                else
                {
                    task.task_pigsty.Add(new task_pigsty
                    {
                        PigstyId = long.Parse(detail.Pigsty)
                    });
                }
            }

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

            return true;
        }
        public ActionResult NewEliminateTask(EliminateTask newTask)
        {
            if (!ModelState.IsValid || !newTask.NewEliminateTask(newTask, TaskTypeId, User.Identity.Name.Split('|')[0]))
            {
                return View("Error");
            }

            ViewBag.Title = "新建任务成功";
            return View("Message");
        }