public ActionResult FodderTake(FodderTakeModel model)
 {
     model = new FodderDetail().GetFodderDetail(model);
     var listService = new ListService();
     ViewData["FeedTaskEmployee"] = listService.GetFeedTaskEmployee();
     ViewData["FodderType"] = listService.GetFodderTypeList();
     ViewData["Unit"] = listService.GetUnitList();
     return View(model);
 }
 public ActionResult FodderTakeConfirm(FodderTakeModel model)
 {
     var fodderTakeService = new FodderTakeService();
     var taskService = new TaskService();
     FodderTakeModel newModel = new FodderDetail().GetFodderDetail(model);
     foreach (FodderDetail actualDetail in model.ActualDetail)
     {
         var newFodderTake = new fodder_take
                                 {
                                     EmployeeId = model.ActualEmployeeId,
                                     TaskId = taskService.FindByTaskNumber(newModel.TaskNumber).Id,
                                     FodderTypeId = actualDetail.FodderTypeId,
                                     Quantity = actualDetail.Quality,
                                     UnitId = actualDetail.UnitId,
                                     Time = Convert.ToDateTime(DateTime.Now),
                                     Memo = model.Memo
                                 };
         fodderTakeService.Insert(newFodderTake);
     }
     return View();
 }
        public ActionResult FodderTake()
        {
            if (Session["CheckFeed"] == null || !(bool) Session["CheckFodderTake"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            var listService = new ListService();
            ViewData["FeedTaskEmployee"] = listService.GetFeedTaskEmployee();
            ViewData["FodderType"] = listService.GetFodderTypeList();
            ViewData["Unit"] = listService.GetUnitList();
            //初始化
            var fodderTakeModel = new FodderTakeModel();
            var taskDetail = new List<FodderDetail>();
            var actualDetail = new List<FodderDetail>();
            var fodderDetail = new FodderDetail();
            taskDetail.Add(fodderDetail);
            actualDetail.Add(fodderDetail);
            fodderTakeModel.ActualDetail = actualDetail;
            fodderTakeModel.TaskDetail = taskDetail;
            return View(fodderTakeModel);
        }
Example #4
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;
        }