Пример #1
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;
        }
Пример #2
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;
            }
        }
Пример #3
0
 public int ValidateRfid(string pigRfid)
 {
     var pigService = new PigService();
     if (pigService.FindByRfid(pigRfid) == null)
         return 1;
     return -1;
 }