コード例 #1
0
        /// <summary>
        ///     更新任务的人员
        /// </summary>
        /// <param name="task">任务类</param>
        /// <param name="numbers">员工名字的字符串数组</param>
        public void UpdateByNumber(task task, string[] numbers)
        {
            int oldLen = task.task_employee.Count;
            int newLen = numbers.Length;
            int leastLength = oldLen < newLen ? oldLen : newLen;

            var employeeService = new EmployeeService();
            var taskEmployeeService = new TaskEmployeeService();

            for (int i = 0; i < leastLength; i++)
            {
                task_employee updateitem = taskEmployeeService.FindByTaskId(task.Id)[i];
                updateitem.EmployeeId = employeeService.FindByNumber(numbers[i]).Id;
                taskEmployeeService.Update(updateitem);
            }

            for (int i = leastLength; i < oldLen; i++)
            {
                taskEmployeeService.Delete(taskEmployeeService.Find(task.task_employee.ElementAt(i).Id));
            }

            for (int i = leastLength; i < newLen; i++)
            {
                taskEmployeeService.Insert(new task_employee
                                               {
                                                   TaskId = task.Id,
                                                   EmployeeId = employeeService.FindByNumber(numbers[i]).Id
                                               });
            }
        }
コード例 #2
0
        /// <summary>
        ///     删除指定任务编号的任务
        /// </summary>
        /// <param name="taskNumber">任务编号</param>
        /// <returns>返回删除是否成功</returns>
        public bool DeleteTask(string taskNumber)
        {
            task task = FindByTaskNumber(taskNumber);

            if (task == null || new FeedService().FindByTaskId(task.Id).Count > 0 ||
                new FodderTakeService().FindByTaskId(task.Id).Count > 0 ||
                new TransferService().FindByTaskId(task.Id).Count > 0 ||
                new PreventionService().FindByTaskId(task.Id).Count > 0 ||
                new InspectionService().FindByTaskId(task.Id).Count > 0 ||
                new SaleService().FindByTaskId(task.Id).Count > 0)
            {
                return false;
            }

            var cureMethodService = new CureMethodService();
            cure_task_course cureCourse = task.cure_task_course.FirstOrDefault();
            if (cureCourse != null && cureMethodService.FindByCureTaskCourseId(cureCourse.Id).Count > 0)
            {
                return false;
            }

            var saleTaskQualityService = new SaleTaskQualityService();
            foreach (sale_task_quality delItem in task.sale_task_quality)
            {
                saleTaskQualityService.Delete(saleTaskQualityService.Find(delItem.Id));
            }

            var transferTaskPigService = new TaskPigService();
            foreach (task_pig transferTaskPig in task.task_pig)
            {
                transferTaskPigService.Delete(transferTaskPigService.Find(transferTaskPig.Id));
            }

            var taskIntervalCycleService = new TaskIntervalCycleService();
            foreach (task_interval_cycle item in task.task_interval_cycle)
            {
                taskIntervalCycleService.Delete(taskIntervalCycleService.Find(item.Id));
            }

            var taskPigstyService = new TaskPigstyService();
            var feedTaskQualityService = new FeedTaskQualityService();
            foreach (task_pigsty item in task.task_pigsty)
            {
                foreach (feed_task_quality delItem in item.feed_task_quality)
                {
                    feedTaskQualityService.Delete(feedTaskQualityService.Find(delItem.Id));
                }
                taskPigstyService.Delete(taskPigstyService.Find(item.Id));
            }

            var taskEmployeeService = new TaskEmployeeService();
            foreach (task_employee item in task.task_employee)
            {
                taskEmployeeService.Delete(taskEmployeeService.Find(item.Id));
            }

            var cureTaskCourseService = new CureTaskCourseService();
            var cureTaskMethodService = new CureTaskMethodService();
            var cureTaskMedicineService = new CureTaskMedicineService();
            foreach (cure_task_course cureTaskCourse in task.cure_task_course)
            {
                foreach (cure_task_method cureTaskMethod in cureTaskCourse.cure_task_method)
                {
                    foreach (cure_task_medicine cureTaskMedicine in cureTaskMethod.cure_task_medicine)
                    {
                        cureTaskMedicineService.Delete(cureTaskMedicineService.Find(cureTaskMedicine.Id));
                    }
                    cureTaskMethodService.Delete(cureTaskMethodService.Find(cureTaskMethod.Id));
                }
                cureTaskCourseService.Delete(cureTaskCourseService.Find(cureTaskCourse.Id));
            }

            var taskPreventionService = new TaskPreventionService();
            foreach (task_prevention taskPrevention in task.task_prevention)
            {
                taskPreventionService.Delete(taskPreventionService.Find(taskPrevention.Id));
            }

            var taskPigHouseService = new TaskPigHouseService();
            foreach (task_pighouse taskPighouse in task.task_pighouse)
            {
                taskPigHouseService.Delete(taskPigHouseService.Find(taskPighouse.Id));
            }

            var taskRepository = new TaskRepository();
            taskRepository.Delete(taskRepository.Find(task.Id));

            return true;
        }