/// <summary>
 /// 修改时删除任务方式表
 /// </summary>
 /// <param name="update">任务类</param>
 /// <param name="count">任务方式表的行数</param>
 public void DelTaskIntervalCycle(task update, int count)
 {
     for (int i = 0; i < update.task_interval_cycle.Count - count; i++)
     {
         var taskIntervalCycle = new TaskIntervalCycleService();
         taskIntervalCycle.Delete(taskIntervalCycle.Find(update.task_interval_cycle.Last().Id));
     }
 }
Exemplo n.º 2
0
        public bool UpdateInspectTask(InspectTask updateTask)
        {
            var taskService = new TaskService();
            task task = taskService.FindByTaskNumber(updateTask.TaskNumber);
            task.StartTime = updateTask.StartTime;
            task.EndTime = updateTask.EndTime;
            task.Memo = updateTask.Memo;
            taskService.Update(task);

            //修改喂食任务的喂食人员
            new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber);
            new TaskPigHouseService().UpdateByPigHouseStr(task, updateTask.PigHouseId);

            var taskIntervalCycleService = new TaskIntervalCycleService();
            for (int i = 0; i < updateTask.InspectTaskCycle.Count; i++)
            {
                if (i < task.task_interval_cycle.Count)
                {
                    task_interval_cycle updateitem = taskIntervalCycleService.FindByTaskId(task.Id)[i];
                    updateitem.CycleDays = updateTask.InspectTaskCycle.ToList()[i].CycleDays;
                    updateitem.FirstExecuteDate = updateTask.InspectTaskCycle.ToList()[i].FirstExecuteDate;
                    taskIntervalCycleService.Update(updateitem);
                }
                else
                {
                    var updateitem = new task_interval_cycle
                                         {
                                             TaskId = task.Id,
                                             CycleDays = updateTask.InspectTaskCycle.ToList()[i].CycleDays,
                                             FirstExecuteDate = updateTask.InspectTaskCycle.ToList()[i].FirstExecuteDate
                                         };
                    taskIntervalCycleService.Insert(updateitem);
                }
            }
            taskIntervalCycleService.DelTaskIntervalCycle(task, updateTask.InspectTaskCycle.Count);
            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        ///     根据id返回是否有喂饲任务
        /// </summary>
        /// <param name="employeeId">人员id</param>
        /// <returns>返回是否有喂饲任务</returns>
        public string GetFeedTaskById(long employeeId)
        {
            var tasktypeService = new TaskTypeService();
            var taskEmployeeService = new TaskEmployeeService();
            var taskIntervalCycleService = new TaskIntervalCycleService();
            int taskflag = 0;

            var taskService = new TaskService();
            List<task_employee> alltask = taskEmployeeService.FindByEmployeeId(employeeId);
            //根据任务id找到任务类型,若是当天的喂饲任务,记录taskid
            foreach (task_employee task in alltask)
            {
                long tasktypeid = taskService.Find(task.TaskId).TaskTypeId;
                string tasktype = tasktypeService.Find(tasktypeid).Name;
                if (tasktype == "喂饲")
                {
                    List<task_interval_cycle> taskInterval = taskIntervalCycleService.FindByTaskId(task.TaskId);
                    foreach (task_interval_cycle taskinterval in taskInterval)
                    {
                        for (int i = 0; i < 1000; i++)
                        {
                            //根据任务的循环时间匹配是否有当天的任务
                            if (
                                taskinterval.FirstExecuteDate.AddDays(Convert.ToDouble(taskinterval.CycleDays * i))
                                            .
                                             ToShortDateString() == DateTime.Now.ToShortDateString())
                            {
                                taskflag = 1; //标志
                                break;
                            }
                        }
                    }
                }
            }
            if (taskflag == 0)
            {
                return "今天该员工没有喂饲任务";
            }
            return "";
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        public FodderTakeModel GetFodderDetail(FodderTakeModel model)
        {
            //初始化
            var newFodderDetails = new List<FodderDetail>();
            //var newFodderDetail=new FodderDetail();
            //newFodderDetails.Add(newFodderDetail);
            model.TaskDetail = newFodderDetails;

            var pigstyService = new PigstyService();
            var tasktypeService = new TaskTypeService();
            var taskEmployeeService = new TaskEmployeeService();
            var taskpigstyservice = new TaskPigstyService();
            var feedTaskQualityService = new FeedTaskQualityService();
            var taskIntervalCycleService = new TaskIntervalCycleService();
            int taskflag = 0;
            long employeeTaskId = 0;
            var taskService = new TaskService();
            List<task_employee> alltask = taskEmployeeService.FindByEmployeeId(model.ActualEmployeeId);
            //根据任务id找到任务类型,若是当天的喂饲任务,记录taskid
            foreach (task_employee task in alltask)
            {
                long tasktypeid = taskService.Find(task.TaskId).TaskTypeId;
                string tasktype = tasktypeService.Find(tasktypeid).Name;
                if (tasktype == "喂饲")
                {
                    List<task_interval_cycle> taskInterval = taskIntervalCycleService.FindByTaskId(task.TaskId);
                    foreach (task_interval_cycle taskinterval in taskInterval)
                    {
                        for (int i = 0; i < 1000; i++)
                        {
                            //根据任务的循环时间匹配是否有当天的任务
                            if (
                                taskinterval.FirstExecuteDate.AddDays(Convert.ToDouble(taskinterval.CycleDays*i))
                                            .
                                             ToShortDateString() == DateTime.Now.ToShortDateString())
                            {
                                taskflag = 1; //标志
                                employeeTaskId = task.TaskId;
                                break;
                            }
                        }
                    }
                }
            }
            if (taskflag == 1)
            {
                List<task_pigsty> taskPisties = taskpigstyservice.FindByTaskId(employeeTaskId);

                //遍历该任务的所有的猪栏,并将其对应的饲料添加到model.TaskDetail中
                int i;
                foreach (task_pigsty taskPigsty in taskPisties)
                {
                    List<feed_task_quality> taskQuality = feedTaskQualityService.FindByFeedTaskPigstyId(taskPigsty.Id);
                    if (model.TaskDetail.Count == 0)
                    {
                        var fodderDetail = new FodderDetail
                                               {
                                                   FodderTypeName = taskQuality[0].fodder_type.Name,
                                                   //Quality = taskQuality[0].Quality * pigstyService.GetPignumbers(Convert.ToInt64(taskPigsty.PigstyId)),
                                                   //UnitName = taskQuality[0].unit.Name,
                                                   FodderTypeId = taskQuality[0].FodderTypeId,
                                                   //UnitId = taskQuality[0].UnitId
                                               };
                        model.TaskDetail.Add(fodderDetail);
                    }
                    else
                    {
                        int knt = 0; //判断该猪栏的饲料是否跟
                        for (i = 0; i < model.TaskDetail.Count; i++)
                        {
                            if (model.TaskDetail[i].FodderTypeName == taskQuality[0].fodder_type.Name)
                            {
                                //model.TaskDetail[i].Quality = taskQuality[0].Quality*
                                //                              pigstyService.GetPignumbers(
                                //                                  Convert.ToInt64(taskPigsty.PigstyId)) +
                                //                              model.TaskDetail[i].Quality;
                                knt = 1;
                            }
                        }
                        if (knt == 0)
                        {
                            var fodderDetail = new FodderDetail
                                                   {
                                                       FodderTypeName = taskQuality[0].fodder_type.Name,
                                                       //Quality = taskQuality[0].Quality * pigstyService.GetPignumbers(Convert.ToInt64(taskPigsty.PigstyId)),
                                                       //UnitName = taskQuality[0].unit.Name,
                                                       FodderTypeId = taskQuality[0].FodderTypeId,
                                                       //UnitId = taskQuality[0].UnitId
                                                   };
                            model.TaskDetail.Add(fodderDetail);
                        }
                    }
                }
                model.TaskNumber = taskService.Find(employeeTaskId).TaskNumber;
                //任务的全部人员
                List<task_employee> allemployees = taskEmployeeService.FindByTaskId(employeeTaskId);
                string reAllEmployeeName = "";
                for (i = 0; i < allemployees.Count - 1; i++)
                {
                    reAllEmployeeName = reAllEmployeeName + allemployees[i].employee.Name + ",";
                }
                reAllEmployeeName = reAllEmployeeName + allemployees[i].employee.Name;
                model.TaskEmployeeName = reAllEmployeeName;
            }
            return model;
        }