Пример #1
0
        public ActionResult EditCureTask(string taskNumber)
        {
            if (Session["CheckFeed"] == null || !(bool)Session["EditCure"] || !(bool)Session["CheckCure"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            object cureTask = new CureTask().GetCureTask(taskNumber);
            if (cureTask == null)
            {
                return View("Error");
            }

            var listService = new ListService();

            ViewData["Pigsty"] = listService.GetFirstPigstyList();
            ViewData["Employee"] = listService.GetEmployeeList();
            ViewData["PigHouse"] = listService.GetPigHouseList();
            ViewData["Medicine"] = listService.GetMedicineList();
            ViewData["CureType"] = listService.GetCureTypeList();
            ViewData["Unit"] = listService.GetUnitList();
            ViewData["Status"] = listService.GetTaskStatusList();
            ViewBag.Title = "修改治疗信息";
            return View("NewCureTask", cureTask);
        }
Пример #2
0
        public ActionResult CheckCureTask(string taskNumber)
        {
            if (Session["CheckFeed"] == null || !(bool)Session["CheckCure"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            object checkTask = new CureTask().GetCureTask(taskNumber);
            if (checkTask == null)
            {
                return View("Error");
            }
            ViewBag.Title = "查看治疗任务";
            return View(checkTask);
        }
Пример #3
0
 public ActionResult EditCureTask(CureTask cureTask)
 {
     if (!ModelState.IsValid || !cureTask.UpdateCureTask(cureTask))
     {
         return View("Error");
     }
     ViewBag.Title = "修改治疗任务成功!";
     return View("Message");
 }
Пример #4
0
 public ActionResult NewCureTask(CureTask newtask)
 {
     if (Session["CheckFeed"] == null || !ModelState.IsValid ||
         !newtask.NewCureTask(newtask, TaskTypeId, User.Identity.Name.Split('|')[0]))
     {
         return View("Error");
     }
     ViewBag.Title = "新建治疗任务成功!";
     return View("Message");
 }
Пример #5
0
        public bool UpdateCureTask(CureTask updateTask)
        {
            var taskService = new TaskService();

            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();

            List<long> pigList =
                (from taskDetail in updateTask.CureDetail
                 from pig in taskDetail.Pig.Split(',')
                 select pigService.FindByNumber(pig).Id).ToList();

            int oldLen = task.task_pig.Count;
            int newLen = pigList.Count;
            int leastLen = oldLen < newLen ? oldLen : newLen;
            for (int i = 0; i < leastLen; i++)
            {
                task.task_pig.ElementAt(i).PigId = pigList[i];
            }
            var taskPigService = new TaskPigService();
            for (int i = leastLen; i < oldLen; i++)
            {
                taskPigService.Delete(taskPigService.Find(task.task_pig.ElementAt(i).Id));
            }
            for (int i = leastLen; i < newLen; i++)
            {
                task.task_pig.Add(new task_pig
                                      {
                                          PigId = pigList[i]
                                      });
            }

            oldLen = task.cure_task_course.Count;
            newLen = updateTask.CureCourse.Count;
            leastLen = oldLen < newLen ? oldLen : newLen;

            var cureTaskMedicineService = new CureTaskMedicineService();
            var cureTaskMethodService = new CureTaskMethodService();
            for (int i = 0; i < leastLen; i++)
            {
                CureCourse cureCourse = updateTask.CureCourse[i];
                task.cure_task_course.ElementAt(i).Order = cureCourse.CureOrder;
                task.cure_task_course.ElementAt(i).Time = cureCourse.CureTime;

                int oldLen2 = task.cure_task_course.ElementAt(i).cure_task_method.Count;
                int newLen2 = cureCourse.CureMethod.Count;
                int leastLen2 = oldLen2 < newLen2 ? oldLen2 : newLen2;
                for (int j = 0; j < leastLen2; j++)
                {
                    task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).CureTypeId =
                        long.Parse(cureCourse.CureMethod[j].CureType);
                    int oldLen3 =
                        task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).cure_task_medicine.Count;
                    int newLen3 = cureCourse.CureMethod[j].CureMedicine.Count;
                    int leastLen3 = oldLen3 < newLen3 ? oldLen3 : newLen3;
                    for (int k = 0; k < leastLen3; k++)
                    {
                        Medicine medicine = cureCourse.CureMethod[j].CureMedicine[k];
                        if (medicine.Quality <= 0)
                        {
                            continue;
                        }
                        task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).cure_task_medicine.ElementAt(k)
                            .MedicineId
                            = long.Parse(medicine.MedicineName);
                        task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).cure_task_medicine.ElementAt(k)
                            .Quality = medicine.Quality;
                        task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).cure_task_medicine.ElementAt(k)
                            .UnitId = long.Parse(medicine.Unit);
                    }

                    for (int k = leastLen; k < oldLen3; k++)
                    {
                        cureTaskMedicineService.Delete(
                            cureTaskMedicineService.Find(
                                task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j).cure_task_medicine.
                                     ElementAt(k).Id));
                    }
                    for (int k = leastLen; k < newLen3; k++)
                    {
                        Medicine medicine = cureCourse.CureMethod[j].CureMedicine[k];
                        if (medicine.Quality <= 0)
                        {
                            continue;
                        }
                        task.cure_task_course.ElementAt(i)
                            .cure_task_method.ElementAt(j)
                            .cure_task_medicine.Add(new cure_task_medicine
                                                        {
                                                            MedicineId
                                                                =
                                                                long
                                                                .
                                                                Parse
                                                                (medicine
                                                                     .
                                                                     MedicineName),
                                                            Quality
                                                                =
                                                                medicine
                                                                .
                                                                Quality,
                                                            UnitId
                                                                =
                                                                long
                                                                .
                                                                Parse
                                                                (medicine
                                                                     .
                                                                     Unit)
                                                        });
                    }
                }

                for (int j = leastLen2; j < oldLen2; j++)
                {
                    cure_task_method cureTaskMethod = task.cure_task_course.ElementAt(i).cure_task_method.ElementAt(j);
                    foreach (cure_task_medicine cureTaskMedicine in cureTaskMethod.cure_task_medicine)
                    {
                        cureTaskMedicineService.Delete(cureTaskMedicineService.Find(cureTaskMedicine.Id));
                    }
                    cureTaskMethodService.Delete(cureTaskMethodService.Find(cureTaskMethod.Id));
                }
                for (int j = leastLen2; j < newLen2; j++)
                {
                    CureMethod cureMethod = cureCourse.CureMethod[j];
                    var medicineList = new Collection<cure_task_medicine>();

                    foreach (Medicine medicine in cureMethod.CureMedicine.Where(medicine => !(medicine.Quality <= 0)))
                    {
                        medicineList.Add(new cure_task_medicine
                                             {
                                                 MedicineId = long.Parse(medicine.MedicineName),
                                                 Quality = medicine.Quality,
                                                 UnitId = long.Parse(medicine.Unit)
                                             });
                    }
                    task.cure_task_course.ElementAt(i).cure_task_method.Add(new cure_task_method
                                                                                {
                                                                                    CureTypeId =
                                                                                        long.Parse(cureMethod.CureType),
                                                                                    cure_task_medicine = medicineList
                                                                                });
                }
            }

            var cureTaskCourseService = new CureTaskCourseService();
            for (int i = leastLen; i < oldLen; i++)
            {
                foreach (cure_method cureMethod in task.cure_task_course.ElementAt(i).cure_method)
                {
                    foreach (cure_medicine cureMedicine in cureMethod.cure_medicine)
                    {
                        cureTaskMedicineService.Delete(cureTaskMedicineService.Find(cureMedicine.Id));
                    }
                    cureTaskMethodService.Delete(cureTaskMethodService.Find(cureMethod.Id));
                }
                cureTaskCourseService.Delete(cureTaskCourseService.Find(task.cure_task_course.ElementAt(i).Id));
            }

            for (int i = leastLen; i < newLen; i++)
            {
                var methodList = new Collection<cure_task_method>();
                CureCourse cureCourse = updateTask.CureCourse[i];

                foreach (CureMethod cureMethod in cureCourse.CureMethod)
                {
                    var medicineList = new Collection<cure_task_medicine>();

                    foreach (Medicine medicine in cureMethod.CureMedicine.Where(medicine => !(medicine.Quality <= 0)))
                    {
                        medicineList.Add(new cure_task_medicine
                                             {
                                                 MedicineId = long.Parse(medicine.MedicineName),
                                                 Quality = medicine.Quality,
                                                 UnitId = long.Parse(medicine.Unit)
                                             });
                    }

                    methodList.Add(new cure_task_method
                                       {
                                           CureTypeId = long.Parse(cureMethod.CureType),
                                           cure_task_medicine = medicineList
                                       });
                }
                task.cure_task_course.Add(new cure_task_course
                                              {
                                                  Order = cureCourse.CureOrder,
                                                  Time = cureCourse.CureTime,
                                                  cure_task_method = methodList
                                              });
            }

            taskService.Update(task);

            return true;
        }
Пример #6
0
        public bool NewCureTask(CureTask 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 (string pigNumber in newTask.CureDetail.SelectMany(taskDetail => taskDetail.Pig.Split(',')))
            {
                task.task_pig.Add(new task_pig
                                      {
                                          PigId = pigService.FindByNumber(pigNumber).Id
                                      });
            }

            foreach (CureCourse cureCourse in newTask.CureCourse)
            {
                var cureMethodList = new Collection<cure_task_method>();
                foreach (CureMethod cureMethod in cureCourse.CureMethod)
                {
                    var medicineList = new Collection<cure_task_medicine>();
                    foreach (Medicine medicine in cureMethod.CureMedicine.Where(medicine => !(medicine.Quality <= 0)))
                    {
                        medicineList.Add(new cure_task_medicine
                                             {
                                                 MedicineId = long.Parse(medicine.MedicineName),
                                                 Quality = medicine.Quality,
                                                 UnitId = long.Parse(medicine.Unit)
                                             });
                    }
                    cureMethodList.Add(new cure_task_method
                                           {
                                               CureTypeId = long.Parse(cureMethod.CureType),
                                               cure_task_medicine = medicineList
                                           });
                }
                task.cure_task_course.Add(new cure_task_course
                                              {
                                                  Order = cureCourse.CureOrder + 1,
                                                  Time = cureCourse.CureTime,
                                                  cure_task_method = cureMethodList
                                              });
            }

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

            return true;
        }
Пример #7
0
        public object GetCureTask(string taskNumber)
        {
            var taskService = new TaskService();
            var taskEmployeeService = new TaskEmployeeService();

            task task = taskService.FindByTaskNumber(taskNumber);

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

            var checkTask = new CureTask
                                {
                                    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);
                }
            }

            var pigHouseService = new PigHouseService();
            var pigstyService = new PigstyService();
            if (pigstyDic.Count != 0)
            {
                checkTask.CureDetail = (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();
            }

            List<CureCourse> courseList = (from cureCourse in task.cure_task_course
                                           let methodList = (from cureMethod in cureCourse.cure_task_method
                                                             let medicineList =
                                                                 cureMethod.cure_task_medicine.Select(
                                                                     cureTaskMedicine => new Medicine
                                                                                             {
                                                                                                 MedicineName =
                                                                                                     cureTaskMedicine.
                                                                                                     medicine.Name,
                                                                                                 Quality =
                                                                                                     cureTaskMedicine.
                                                                                                     Quality,
                                                                                                 Unit =
                                                                                                     cureTaskMedicine.
                                                                                                     unit.Name
                                                                                             }).ToList()
                                                             select new CureMethod
                                                                        {
                                                                            CureMedicine = medicineList,
                                                                            CureType = cureMethod.cure_type.Name
                                                                        }).ToList()
                                           select new CureCourse
                                                      {
                                                          CureOrder = cureCourse.Order,
                                                          CureTime = cureCourse.Time,
                                                          CureMethod = methodList
                                                      }).ToList();

            if (courseList[0].CureMethod.Count != 0 && courseList[0].CureMethod[0].CureMedicine.Count != 0)
            {
                checkTask.CureCourse = courseList;
            }

            return checkTask;
        }