Ejemplo n.º 1
0
        /// <summary>
        ///     新建淘汰信息
        /// </summary>
        /// <param name="newInfo"></param>
        /// <returns></returns>
        public bool CreateEliminateInfo(EliminateInfo newInfo)
        {
            var salesService = new SaleService();
            var taskStatusTypeService = new TaskStatusTypeService();
            var taskService = new TaskService();
            var pigService = new PigService();
            var pigInfo = new PigInfo();
            var newSale = new sale
            {
                TaskId = long.Parse(newInfo.TaskNumber),
                EmployeeId = long.Parse(newInfo.EmployeeName),
                SaleType = "淘汰",
                Memo = newInfo.Meno
            };

            foreach (Detail salesPigInfo in newInfo.EliminateInfoPigDetail)
            {
                newSale.sale_pig.Add(new sale_pig
                {
                    Time = salesPigInfo.DetailTime,
                    PigId = long.Parse(salesPigInfo.Pig)
                });
                pigInfo.SetState(long.Parse(salesPigInfo.Pig), true);
            }
            salesService.Insert(newSale);
            task_status_type taskStatusType = taskStatusTypeService.FindByName("已完成");
            task task = taskService.Find(long.Parse(newInfo.TaskNumber));
            if (taskStatusType != null && task != null)
            {
                task.TaskStatusId = taskStatusType.Id;
                taskService.Update(task);
            }
            return true;
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     根据生猪编号删除生猪的相关信息
 /// </summary>
 /// <param name="pigNumber"></param>
 /// <returns></returns>
 public bool DelPig(string pigNumber)
 {
     var pigService = new PigService();
     pig pig = pigService.FindByNumber(pigNumber);
     var transferService = new TransferService();
     if (pig.cure_pig.Count > 0 || pig.task_pig.Count > 0 || pig.sale_pig.Count > 0 || pig.pig_weight.Count > 0 ||
         pigService.FindByFemaleParentId(pig.Id).Count > 0 ||
         pigService.FindByMostLikelyMaleParentId(pig.Id).Count > 0 ||
         pigService.FindBySecondLikelyMaleParentId(pig.Id).Count > 0 ||
         pigService.FindByThirdLikelyMaleParentId(pig.Id).Count > 0)
     {
         return false;
     }
     foreach (transfer transfer in transferService.FindByPigId(pig.Id))
     {
         transferService = new TransferService();
         transferService.Delete(transferService.Find(transfer.Id));
     }
     pigService = new PigService();
     pigService.Delete(pigService.Find(pig.Id));
     return true;
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     全部生猪列表
 /// </summary>
 /// <returns></returns>
 //public PagedList<PigInfo> GetPigList(int pageIndex, int pageSize)
 //{
 //    //return GetALLPigList(pageIndex, pageSize);
 //    var pigService = new PigService();
 //    var pigList = new List<PigInfo>();
 //    var salePigService = new SalePigService();
 //    var transferService = new TransferService();
 //    PagedList<pig> pigInfos = pigService.FindByPigPage(pageIndex, pageSize);
 //    foreach (pig pig in pigInfos)
 //    {
 //        //transfer transfer = transferService.FindByPigId(pig.Id).OrderByDescending(m => m.Time).FirstOrDefault();
 //        transfer transfer = transferService.FindByPigId(pig.Id).OrderByDescending(m => m.Id).FirstOrDefault();
 //        string pigHouse = "";
 //        string pigsty = "";
 //        string pigState="";
 //        if (transfer != null)
 //        {
 //            pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number+"舍";
 //            pigsty = transfer.pigsty.Number + "";
 //        }
 //        if (pig.State == false) pigState = "正常";
 //        else if (salePigService.FindByPigId(pig.Id) != null) pigState = "出售";
 //        else
 //            pigState = "异常";
 //        pigList.Add(new PigInfo
 //                        {
 //                            Number=pig.Number,
 //                            Rfid=pig.RFID,
 //                            EarNumber = pig.EarNumber == null ? "" : pig.EarNumber.ToString(),
 //                            Birthday = pig.Birthday,
 //                            PigType = pig.pig_type.Name,
 //                            Memo = pig.Memo,
 //                            PigHouse = pigHouse,
 //                            Pigsty = pigsty,
 //                            state=pigState
 //                        });
 //    }
 //    return new PagedList<PigInfo>(pigList, pageIndex, pageSize, pigInfos.TotalItemCount);
 //}
 public PagedList<PigInfo> GetPigList(int pageIndex, int pageSize)
 {
     var pigService = new PigService();
     var pigList = new List<PigInfo>();
     var salePigService = new SalePigService();
     var transferService = new TransferService();
     PagedList<pig> pigInfos = pigService.FindByPigPage(pageIndex, pageSize);
     PagedList<transfer> transferList = transferService.FindByAllPage(pageIndex, pageSize);
     foreach (transfer tranfer in transferList)
     {
         pig pig = pigService.Find(tranfer.PigId);
         string pigState = "";
         var salepig = salePigService.FindByPigId(pig.Id).FirstOrDefault();
         if (pig.State == false) pigState = "正常";
         else if (salepig != null)
         {
             if (salepig.sale.SaleType=="销售")
             pigState = "出售";
             else if (salepig.sale.SaleType == "淘汰") pigState = "淘汰";
             else if (salepig.sale.SaleType == "死亡") pigState = "死亡";
             else pigState = "异常";
         }
         else
             pigState = "异常";
         pigList.Add(new PigInfo
                         {
                             Number = pig.Number,
                             Rfid = pig.RFID,
                             EarNumber = pig.EarNumber == null ? "" : pig.EarNumber.ToString(),
                             Birthday = pig.Birthday,
                             PigType = pig.pig_type.Name,
                             Memo = pig.Memo,
                             PigHouse =
                                 tranfer.pigsty.pig_house.pig_house_type.Name + tranfer.pigsty.pig_house.Number +
                                 "舍",
                             Pigsty = tranfer.pigsty.Number + "",
                             state = pigState
                         });
     }
     return new PagedList<PigInfo>(pigList, pageIndex, pageSize, pigInfos.TotalItemCount);
 }
Ejemplo n.º 4
0
        /// <summary>
        ///     添加生猪
        /// </summary>
        /// <param name="newPigInfo"></param>
        /// <returns></returns>
        public bool CreatePigInfo(PigInfo newPigInfo)
        {
            var pigService = new PigService();
            var transferService = new TransferService();
            var taskStatusTypeService = new TaskStatusTypeService();
            var taskService = new TaskService();
            if (newPigInfo == null) return false;
            long? earNumber = null,
                  femaleParentId = null,
                  mostLikelyMaleParentId = null,
                  secondLikelyMaleParentId = null,
                  thirdLikelyMaleParentId = null;
            if (newPigInfo.EarNumber != null)
                earNumber = long.Parse(newPigInfo.EarNumber);

            if (newPigInfo.FemaleParentNum != null)
                femaleParentId = long.Parse(newPigInfo.FemaleParentNum);
            if (newPigInfo.MostLikelyMaleParentNum != null)
                mostLikelyMaleParentId = long.Parse(newPigInfo.MostLikelyMaleParentNum);
            if (newPigInfo.SecondLikelyMaleParentNum != null)
                secondLikelyMaleParentId = long.Parse(newPigInfo.SecondLikelyMaleParentNum);
            if (newPigInfo.ThirdLikelyMaleParentNum != null)
                thirdLikelyMaleParentId = long.Parse(newPigInfo.ThirdLikelyMaleParentNum);
            if (newPigInfo.TaskNumber == null) return false;
            pigService.Insert(new pig
                                  {
                                      Number = newPigInfo.Number,
                                      EarNumber = earNumber,
                                      Birthday = newPigInfo.Birthday,
                                      RFID = newPigInfo.Rfid,
                                      PigTypeId = long.Parse(newPigInfo.PigType),
                                      FemaleParentId = femaleParentId,
                                      MostLikelyMaleParentId = mostLikelyMaleParentId,
                                      SecondLikelyMaleParentId = secondLikelyMaleParentId,
                                      ThirdLikelyMaleParentId = thirdLikelyMaleParentId,
                                      Memo = newPigInfo.Memo,
                                      State = true
                                  });
            if (newPigInfo.TaskNumber != null)
            {
                transferService.Insert(new transfer
                                           {
                                               TaskId = long.Parse(newPigInfo.TaskNumber),
                                               PigId = pigService.FindByNumber(newPigInfo.Number).Id,
                                               PigstyId = long.Parse(newPigInfo.Pigsty),
                                               Time = newPigInfo.TransferPigstyTime
                                           });
            }

            pigService = new PigService();

            task_status_type taskStatusType = taskStatusTypeService.FindByName("已完成");
            task task = taskService.Find(long.Parse(newPigInfo.TaskNumber));
            if (taskStatusType != null && task != null)
            {
                task.TaskStatusId = taskStatusType.Id;
                taskService.Update(task);
            }
            return true;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
 /// <summary>
 ///     公猪下拉列表
 /// </summary>
 /// <returns></returns>
 public IEnumerable<SelectListItem> GetMalePigList()
 {
     var pigService = new PigService();
     var pigTypeService = new PigTypeService();
     pig_type pigType = pigTypeService.FindByName("公猪");
     if (pigType == null) return new List<SelectListItem>();
     IEnumerable<SelectListItem> pigSelect = pigService.FindByPigTypeId(pigType.Id)
                                                       .Select(pigtypeItem => new SelectListItem
                                                                                  {
                                                                                      Text =
                                                                                          pigtypeItem.
                                                                                          Number,
                                                                                      Value =
                                                                                          pigtypeItem.
                                                                                              Id +
                                                                                          string.Empty,
                                                                                  }).OrderBy(m => m.Text);
     return pigSelect;
 }
Ejemplo n.º 8
0
 /// <summary>
 ///     修改生猪状态
 /// </summary>
 /// <param name="PigId">生猪id号</param>
 /// <param name="state">正常与否</param>
 public void SetState(long PigId, bool state)
 {
     var pigService = new PigService();
     pig pig = pigService.Find(PigId);
     pig.State = state;
     pigService.Update(pig);
 }
 public int ValidatePigNum(string pigNumber)
 {
     var pigService = new PigService();
     if (pigService.FindByNumber(pigNumber) == null)
         return 1;
     return -1;
 }
Ejemplo n.º 10
0
        public bool UpdateTransferTask(TransferTask 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.TransferFrom
                 from pig in taskDetail.Pig.Split(',')
                 select pigService.FindByNumber(pig).Id).ToList();

            int oldLen = task.task_pig.Count;
            int newLen = pigList.Count;
            int leastLength = oldLen < newLen ? oldLen : newLen;

            for (int i = 0; i < leastLength; i++)
            {
                task.task_pig.ElementAt(i).PigId = pigList[i];
            }

            var transferTaskPigService = new TaskPigService();

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

            for (int i = leastLength; i < newLen; i++)
            {
                task.task_pig.Add(new task_pig
                                      {
                                          PigId = pigList[i]
                                      });
            }

            var pigstyService = new PigstyService();

            List<long> pigstyList = (from taskDetail in updateTask.TransferTo
                                     from pigsty in taskDetail.Pigsty.Split(',')
                                     select
                                         pigstyService.FindByNumber(int.Parse(pigsty)).First(
                                             m => m.PigHouseId == long.Parse(taskDetail.PigHouse)).Id).ToList();

            oldLen = task.task_pigsty.Count;
            newLen = pigstyList.Count;
            leastLength = oldLen < newLen ? oldLen : newLen;

            for (int i = 0; i < leastLength; i++)
            {
                task.task_pigsty.ElementAt(i).PigstyId = pigstyList[i];
            }

            var taskPigstyService = new TaskPigstyService();

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

            for (int i = leastLength; i < newLen; i++)
            {
                task.task_pigsty.Add(new task_pigsty
                                         {
                                             PigstyId = pigstyList[i]
                                         });
            }

            taskService.Update(task);

            return true;
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     新建转栏任务
        /// </summary>
        /// <param name="newTask">转栏任务</param>
        /// <param name="taskTypeId">任务类型id</param>
        /// <param name="createEmployee">发布任务的员工工号</param>
        /// <returns>返回新建任务是否成功</returns>
        public bool NewTransferTask(TransferTask 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.TransferFrom.SelectMany(taskDetail => taskDetail.Pig.Split(',')))
            {
                task.task_pig.Add(new task_pig
                                      {
                                          PigId = pigService.FindByNumber(pigNumber).Id
                                      });
            }

            var pigstyService = new PigstyService();

            foreach (TaskDetail taskDetail in TransferTo)
            {
                string pigHouse = taskDetail.PigHouse;

                foreach (string pigstyNumber in taskDetail.Pigsty.Split(','))
                {
                    task.task_pigsty.Add(new task_pigsty
                                             {
                                                 PigstyId =
                                                     pigstyService.GetPigsty(int.Parse(pigstyNumber),
                                                                             long.Parse(pigHouse)).Id
                                             });
                }
            }

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

            return true;
        }
Ejemplo n.º 12
0
 public int ValidateRfid(string pigRfid)
 {
     var pigService = new PigService();
     if (pigService.FindByRfid(pigRfid) == null)
         return 1;
     return -1;
 }
Ejemplo n.º 13
0
        public bool PigDataDel(string pigNumber)
        {
            if (Session["CheckFeed"] == null || !(bool) Session["DelPigData"] || !(bool) Session["CheckPigData"])
            {
                return false;
            }

            var pigService = new PigService();
            return pigService.DelPig(pigNumber);
        }
Ejemplo n.º 14
0
 /// <summary>
 ///     查找对应条件的生猪
 /// </summary>
 /// <param name="checkInput">搜索内容</param>
 /// <param name="choseid">条件号</param>
 /// <returns></returns>
 public PagedList<PigInfo> GetPigList(string checkInput, string choseid, int pageIndex, int pageSize)
 {
     var pigService = new PigService();
     var transferService = new TransferService();
     long earnum;
     switch (choseid)
     {
         case "1":
             if (checkInput != "") //RFID
             {
                 return GetpigPageList(pigService.FindByPigPageByRfid(checkInput.Trim(), pageIndex, pageSize),
                                       pageIndex, pageSize);
             }
             else
                 return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize);
         case "2":
             if (checkInput != "") //耳号
             {
                 if (long.TryParse(checkInput.Trim(), out earnum))
                     return GetpigPageList(pigService.FindByPigPageByEarNum(earnum, pageIndex, pageSize),
                                           pageIndex, pageSize);
                 else
                     return new PagedList<PigInfo>(new List<PigInfo>(), pageIndex, pageSize, 0);
             }
             else
                 return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize);
         case "3":
             if (checkInput != "") //猪类型
                 return
                     GetpigPageList(pigService.FindByPigPageByType(long.Parse(checkInput), pageIndex, pageSize),
                                    pageIndex, pageSize);
             else
                 return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize);
         case "4":
             if (checkInput != "") //猪舍猪栏
             {
                 string[] checkStrs = checkInput.Split('+');
                 if (checkStrs.Length > 0)
                 {
                     if (checkStrs.Length > 1 && checkStrs[1] != "")
                         return
                             GetpigPageList(
                                 transferService.FindByPigstyPage(long.Parse(checkStrs[1]), pageIndex, pageSize),
                                 pageIndex, pageSize);
                     else
                         return
                             GetpigPageList(
                                 transferService.FindByPigHousePage(long.Parse(checkStrs[0]), pageIndex, pageSize),
                                 pageIndex, pageSize);
                 }
                 else return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize);
             }
             else
                 return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize);
         case "5":
             if (checkInput != "") //生猪状态
                 return
                     GetpigPageList(
                        pigService.FindByPigPageByType(checkInput, pageIndex, pageSize),
                         pageIndex, pageSize);
             else
                 return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize);
         default:
             return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize);
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 ///     查看生猪个体治疗记录
 /// </summary>
 /// <param name="pigNumber"></param>
 /// <param name="pageIndex"> </param>
 /// <param name="pageSize"> </param>
 /// <returns></returns>
 public PigInfo CheckCureRecord(string pigNumber, int pageIndex, int pageSize)
 {
     var pigService = new PigService();
     pig pig = pigService.FindByNumber(pigNumber);
     var curePigService = new CurePigService();
     var transferPigsty = new TransferService();
     transfer transfer = transferPigsty.FindByPigId(pig.Id).OrderByDescending(m => m.Time).FirstOrDefault();
     var cureInfos = new List<CureDetail>();
     string pigHouse = "", pigsty = "";
     if (transfer != null)
     {
         pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number;
         pigsty = transfer.pigsty.Number + "";
     }
     var pigInfo = new PigInfo
                       {
                           Number = pigNumber,
                           Birthday = pig.Birthday,
                           PigType = pig.pig_type.Name,
                           PigHouse = pigHouse,
                           Pigsty = pigsty
                       };
     foreach (cure_pig curePig in curePigService.FindByPigId(pig.Id))
     {
         foreach (cure_method cureMethod in curePig.cure_task_course.cure_method)
         {
             cureInfos.Add(new CureDetail
                               {
                                   CureType = cureMethod.cure_type.Name,
                                   CureMedicineDetail = cureMethod.cure_medicine.Select(
                                       cureMedicine =>
                                       new CureMedicineDetail {Medicine = cureMedicine.medicine.Name}).
                                                                   ToList(),
                                   CureTime = (DateTime) curePig.CureTime
                               });
         }
     }
     pigInfo.CureRecord = new PagedList<CureDetail>(cureInfos.OrderByDescending(m => m.CureTime).ToList(),
                                                    pageIndex, pageSize)
                              {
                                  Capacity = cureInfos.Count,
                                  CurrentPageIndex = pageIndex,
                                  PageSize = pageSize,
                                  TotalItemCount = cureInfos.Count
                              };
     return pigInfo;
 }
Ejemplo n.º 16
0
 public PagedList<PigInfo> GetpigPageList(PagedList<pig> pigInfos, int pageIndex, int pageSize)
 {
     var pigService = new PigService();
     var pigList = new List<PigInfo>();
     var salePigService = new SalePigService();
     var transferService = new TransferService();
     foreach (pig pig in pigInfos)
     {
         //transfer transfer = transferService.FindByPigId(pig.Id).OrderByDescending(m => m.Time).FirstOrDefault();
         transfer transfer = transferService.FindByPigId(pig.Id).OrderByDescending(m => m.Id).FirstOrDefault();
         string pigHouse = "";
         string pigsty = "";
         string pigState = "";
         if (transfer != null)
         {
             pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number + "舍";
             pigsty = transfer.pigsty.Number + "";
         }
         var salepig = salePigService.FindByPigId(pig.Id).FirstOrDefault();
         if (pig.State == false) pigState = "正常";
         else if (salepig != null)
         {
             if (salepig.sale.SaleType == "销售")
                 pigState = "出售";
             else if (salepig.sale.SaleType == "淘汰") pigState = "淘汰";
             else if (salepig.sale.SaleType == "死亡") pigState = "死亡";
             else pigState = "异常";
         }
         else
             pigState = "异常";
         pigList.Add(new PigInfo
                         {
                             Number = pig.Number,
                             Rfid = pig.RFID,
                             EarNumber = pig.EarNumber == null ? "" : pig.EarNumber.ToString(),
                             Birthday = pig.Birthday,
                             PigType = pig.pig_type.Name,
                             Memo = pig.Memo,
                             PigHouse = pigHouse,
                             Pigsty = pigsty,
                             state = pigState
                         });
     }
     return new PagedList<PigInfo>(pigList, pageIndex, pageSize, pigInfos.TotalItemCount);
 }
Ejemplo n.º 17
0
 /// <summary>
 ///     查看生猪个体喂食记录
 /// </summary>
 /// <param name="pigNumber"></param>
 /// <param name="pageIndex"> </param>
 /// <param name="pageSize"> </param>
 /// <returns></returns>
 public PigInfo CheckFeedRecord(string pigNumber, int pageIndex, int pageSize)
 {
     var pigService = new PigService();
     var salePigService = new SalePigService();
     pig pig = pigService.FindByNumber(pigNumber);
     var transferPigsty = new TransferService();
     var feedService = new FeedService();
     List<transfer> transferPigstyList = transferPigsty.FindByPigId(pig.Id).OrderBy(m => m.Time).ToList();
     transfer transfer = transferPigstyList.LastOrDefault();
     var feedInfos = new List<FodderTakeDetail>();
     string pigHouse = "", pigsty = "";
     DateTime? temp = null;
     sale_pig salePig = salePigService.FindByPigId(pig.Id).FirstOrDefault();
     if (transfer != null)
     {
         pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number;
         pigsty = transfer.pigsty.Number + "";
     }
     var pigInfo = new PigInfo
                       {
                           Number = pigNumber,
                           Birthday = pig.Birthday,
                           PigType = pig.pig_type.Name,
                           PigHouse = pigHouse,
                           Pigsty = pigsty
                       };
     if (salePig != null)
     {
         temp = salePig.Time;
     }
     if (transferPigstyList.Count == 1)
     {
         foreach (feed feedItem in
             feedService.FindByPigstyId(transferPigstyList[0].PigstyId).Where(
                 m => m.Time > transferPigstyList[0].Time))
         {
             if (temp != null) if (feedItem.Time > temp) continue;
             feedInfos.Add(new FodderTakeDetail
                               {
                                   FodderType =
                                       feedItem.task.task_pigsty.FirstOrDefault(
                                           m => m.PigstyId == feedItem.PigstyId)
                                               .feed_task_quality.FirstOrDefault()
                                               .fodder_type.Name,
                                   TakeTime = feedItem.Time
                               });
         }
     }
     for (int i = 0; i < transferPigstyList.Count - 1; i++)
     {
         DateTime startTime = transferPigstyList[i].Time;
         DateTime endTime = transferPigstyList[i + 1].Time;
         foreach (feed feedItem in
             feedService.FindByPigstyId(transferPigstyList[i].PigstyId).Where(
                 m => m.Time > startTime && m.Time < endTime))
         {
             if (temp != null) if (feedItem.Time > temp) continue;
             feedInfos.Add(new FodderTakeDetail
                               {
                                   // FodderType = feedItem.task.fodder_take.Where(m => m.Time > startTime && m.Time < endTime).FirstOrDefault().fodder_type.Name,
                                   FodderType =
                                       feedItem.task.task_pigsty.FirstOrDefault(
                                           m => m.PigstyId == feedItem.PigstyId)
                                               .feed_task_quality.FirstOrDefault()
                                               .fodder_type.Name,
                                   TakeTime = feedItem.Time
                               });
         }
     }
     pigInfo.FeedRecord = new PagedList<FodderTakeDetail>(feedInfos.OrderByDescending(m => m.TakeTime).ToList(),
                                                          pageIndex, pageSize)
                              {
                                  Capacity = feedInfos.Count,
                                  CurrentPageIndex = pageIndex,
                                  PageSize = pageSize,
                                  TotalItemCount = feedInfos.Count
                              };
     return pigInfo;
 }
Ejemplo n.º 18
0
        /// <summary>
        ///     更新修改生猪信息
        /// </summary>
        /// <param name="updatePigInfo"></param>
        /// <param name="pigNumber"> </param>
        /// <returns></returns>
        public bool UpdatePigInfo(PigInfo updatePigInfo, string pigNumber)
        {
            var pigService = new PigService();
            var transferService = new TransferService();
            if (updatePigInfo == null) return false;
            long? earNumber = null,
                  femaleParentId = null,
                  mostLikelyMaleParentId = null,
                  secondLikelyMaleParentId = null,
                  thirdLikelyMaleParentId = null;
            if (updatePigInfo.EarNumber != null)
                earNumber = long.Parse(updatePigInfo.EarNumber);

            if (updatePigInfo.FemaleParentNum != null)
                femaleParentId = long.Parse(updatePigInfo.FemaleParentNum);
            if (updatePigInfo.MostLikelyMaleParentNum != null)
                mostLikelyMaleParentId = long.Parse(updatePigInfo.MostLikelyMaleParentNum);
            if (updatePigInfo.SecondLikelyMaleParentNum != null)
                secondLikelyMaleParentId = long.Parse(updatePigInfo.SecondLikelyMaleParentNum);
            if (updatePigInfo.ThirdLikelyMaleParentNum != null)
                thirdLikelyMaleParentId = long.Parse(updatePigInfo.ThirdLikelyMaleParentNum);
            pig pig = pigService.FindByNumber(pigNumber);
            if (pig == null) return false;
            transfer firstTranfer = transferService.FindByPigId(pig.Id).OrderBy(m => m.Time).FirstOrDefault();
            if (firstTranfer != null)
            {
                firstTranfer.PigstyId = long.Parse(updatePigInfo.Pigsty);
                transferService.Update(firstTranfer);
            }
            else
                return false;
            pig.Number = updatePigInfo.Number;
            pig.EarNumber = earNumber;
            pig.Birthday = updatePigInfo.Birthday;
            pig.RFID = updatePigInfo.Rfid;
            pig.PigTypeId = long.Parse(updatePigInfo.PigType);
            pig.FemaleParentId = femaleParentId;
            pig.MostLikelyMaleParentId = mostLikelyMaleParentId;
            pig.SecondLikelyMaleParentId = secondLikelyMaleParentId;
            pig.ThirdLikelyMaleParentId = thirdLikelyMaleParentId;
            pig.Memo = updatePigInfo.Memo;
            pigService.Update(pig);
            return true;
        }
Ejemplo n.º 19
0
        /// <summary>
        ///     查看生猪信息
        /// </summary>
        /// <param name="pigNumber"></param>
        /// <returns></returns>
        public PigInfo CheckPigInfo(string pigNumber)
        {
            var pigService = new PigService();
            pig pig = pigService.FindByNumber(pigNumber);
            if (pig == null) return null;
            var transferService = new TransferService();
            string pigHouse = "";
            string pigsty = "";
            string earNumber = "",
                   rfid = "",
                   femaleParent = "",
                   mostLikelyMaleParent = "",
                   secondLikelyMaleParent = "",
                   thirdLikelyMaleParent = null;
            if (pig.EarNumber != null)
                earNumber = pig.EarNumber + "";
            if (pig.RFID != null)
                rfid = pig.RFID + "";
            if (pig.FemaleParentId != null)
                femaleParent = pigService.Find(pig.FemaleParentId).Number;
            if (pig.MostLikelyMaleParentId != null)
                mostLikelyMaleParent = pigService.Find(pig.MostLikelyMaleParentId).Number;
            if (pig.SecondLikelyMaleParentId != null)
                secondLikelyMaleParent = pigService.Find(pig.SecondLikelyMaleParentId).Number;
            if (pig.ThirdLikelyMaleParentId != null)
                thirdLikelyMaleParent = pigService.Find(pig.ThirdLikelyMaleParentId).Number;
            transfer transfer = transferService.FindByPigId(pig.Id).OrderByDescending(m => m.Time).FirstOrDefault();
            if (transfer != null)
            {
                pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number;
                pigsty = transfer.pigsty.Number + "";
            }
            string pigState = "";
            var salepig = new SalePigService().FindByPigId(pig.Id).FirstOrDefault();
            if (pig.State == false) pigState = "正常";
            else if (salepig != null)
            {
                if (salepig.sale.SaleType == "销售")
                    pigState = "出售";
                else if (salepig.sale.SaleType == "淘汰") pigState = "淘汰";
                else if (salepig.sale.SaleType == "死亡") pigState = "死亡";
                else pigState = "异常";
            }
            else
                pigState = "异常";
            var pigInfo = new PigInfo
                              {
                                  Number = pigNumber,
                                  EarNumber = earNumber,
                                  Birthday = pig.Birthday,
                                  Rfid = rfid,
                                  PigType = pig.pig_type.Name,
                                  FemaleParentNum = femaleParent,
                                  MostLikelyMaleParentNum = mostLikelyMaleParent,
                                  SecondLikelyMaleParentNum = secondLikelyMaleParent,
                                  ThirdLikelyMaleParentNum = thirdLikelyMaleParent,
                                  Memo = pig.Memo,
                                  PigHouse = pigHouse,
                                  Pigsty = pigsty,
                                  TransferPigstyTime = transfer == null ? new DateTime() : transfer.Time,
                                  state = pigState
                              };

            return pigInfo;
        }
Ejemplo n.º 20
0
 /// <summary>
 ///     根据公猪的类型id得到所有的公猪编号和名字
 /// </summary>
 /// <returns>所有的公猪编号和名字</returns>
 public string GetMaleParentName()
 {
     var pigservice = new PigService();
     var pigtypeservice = new PigTypeService();
     try
     {
         long maleparentid = pigtypeservice.FindByName("公猪").Id;
         return pigservice.GetPigNumberAndNameByPigType(maleparentid);
     }
     catch (Exception)
     {
         return null;
     }
 }
Ejemplo n.º 21
0
        /// <summary>
        ///     查看生猪个体防疫记录
        /// </summary>
        /// <param name="pigNumber"></param>
        /// <param name="pageIndex"> </param>
        /// <param name="pageSize"> </param>
        /// <returns></returns>
        public PigInfo CheckPreventionRecord(string pigNumber, int pageIndex, int pageSize)
        {
            var pigService = new PigService();
            pig pig = pigService.FindByNumber(pigNumber);
            var transferPigsty = new TransferService();
            var taskPreventionService = new TaskPreventionService();
            var preventionService = new PreventionService();
            var preventionInfos = new List<PreventionInfo>();
            var salePigService = new SalePigService();
            List<transfer> transferPigstyList = transferPigsty.FindByPigId(pig.Id).OrderBy(m => m.Time).ToList();
            transfer transfer = transferPigstyList.LastOrDefault();
            sale_pig salePig = salePigService.FindByPigId(pig.Id).FirstOrDefault();
            DateTime? temp = null;
            string pigHouse = "", pigsty = "";
            if (transfer != null)
            {
                pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number;
                pigsty = transfer.pigsty.Number + "";
            }
            if (salePig != null)
            {
                temp = salePig.Time;
            }
            var pigInfo = new PigInfo
                              {
                                  Number = pigNumber,
                                  Birthday = pig.Birthday,
                                  PigType = pig.pig_type.Name,
                                  PigHouse = pigHouse,
                                  Pigsty = pigsty
                              };
                if (transferPigstyList.Count == 1)
                {
                    foreach (prevention preventionItem in
                        preventionService.FindByPistyId(transferPigstyList[0].PigstyId).Where(
                            m => m.Time > transferPigstyList[0].Time))
                    {
                        if (temp != null) if (temp > preventionItem.Time) continue;
                        task_prevention firstOrDefault =
                            taskPreventionService.FindByTaskId(preventionItem.TaskId).FirstOrDefault();
                        if (firstOrDefault != null)
                            preventionInfos.Add(new PreventionInfo
                                                    {
                                                        DiseaseName = firstOrDefault.prevention_type.Name,
                                                        Medicine = firstOrDefault.prevention_type.medicine.Name,
                                                        Time = preventionItem.Time
                                                    });
                    }
                }
                for (int i = 0; i < transferPigstyList.Count; i++)
                {
                    DateTime startTime = transferPigstyList[i].Time;
                    DateTime endTime = DateTime.Now;
                    if (i + 1 < transferPigstyList.Count)
                        endTime = transferPigstyList[i + 1].Time;
                    foreach (prevention preventionItem in
                        preventionService.FindByPistyId(transferPigstyList[i].PigstyId).Where(
                            m => m.Time > startTime && m.Time < endTime))
                    {
                        if (temp != null) if (temp > preventionItem.Time) continue;
                        task_prevention firstOrDefault =
                            taskPreventionService.FindByTaskId(preventionItem.TaskId).FirstOrDefault();
                        if (firstOrDefault != null)
                            preventionInfos.Add(new PreventionInfo
                                                    {
                                                        DiseaseName = firstOrDefault.prevention_type.Name,
                                                        Medicine = firstOrDefault.prevention_type.medicine.Name,
                                                        Time = preventionItem.Time
                                                    });
                    }
                }

            pigInfo.PreventionRecord =
                new PagedList<PreventionInfo>(preventionInfos.OrderByDescending(m => m.Time).ToList(), pageIndex,
                                              pageSize)
                    {
                        Capacity = preventionInfos.Count,
                        PageSize = pageSize,
                        CurrentPageIndex = pageIndex,
                        TotalItemCount = preventionInfos.Count
                    };
            return pigInfo;
        }
Ejemplo n.º 22
0
 /// <summary>
 ///     全部猪下拉列表
 /// </summary>
 /// <returns></returns>
 public IEnumerable<SelectListItem> GetPigList()
 {
     var pigService = new PigService();
     IEnumerable<SelectListItem> pigSelect = pigService.FindAll().Select(pigtypeItem => new SelectListItem
                                                                                            {
                                                                                                Text =
                                                                                                    pigtypeItem.
                                                                                                    Number,
                                                                                                Value =
                                                                                                    pigtypeItem.
                                                                                                        Id +
                                                                                                    string.Empty,
                                                                                            })
                                                       .OrderBy(m => m.Text);
     return pigSelect;
 }
Ejemplo n.º 23
0
        /// <summary>
        ///     查看生猪个体转栏记录
        /// </summary>
        /// <param name="pigNumber"></param>
        /// <param name="pageIndex"> </param>
        /// <param name="pageSize"> </param>
        /// <returns></returns>
        public PigInfo CheckTransferPigstyRecord(string pigNumber, int pageIndex, int pageSize)
        {
            var pigService = new PigService();
            pig pig = pigService.FindByNumber(pigNumber);
            if (pig == null) return null;
            var transferPigsty = new TransferService();
            var transferInfos = new List<TransferPigstyInfoDetail>();
            List<transfer> transferPigstyList = transferPigsty.FindByPigId(pig.Id).OrderBy(m => m.Time).ToList();
            transfer transfer = transferPigstyList.LastOrDefault();

            string pigHouse = "", pigsty = "";
            if (transfer != null)
            {
                pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number;
                pigsty = transfer.pigsty.Number + "";
            }
            var pigInfo = new PigInfo
                              {
                                  Number = pigNumber,
                                  Birthday = pig.Birthday,
                                  PigType = pig.pig_type.Name,
                                  PigHouse = pigHouse,
                                  Pigsty = pigsty
                              };
            transferInfos.Add(new TransferPigstyInfoDetail
                                  {
                                      SourcePigHouse = "",
                                      SourcePigsty = "",
                                      TargetPigHouse =
                                          transferPigstyList[0].pigsty.pig_house.pig_house_type.Name
                                          + transferPigstyList[0].pigsty.pig_house.Number,
                                      TargetPigsty = transferPigstyList[0].pigsty.Number + "",
                                      TransferPigstyTime = transferPigstyList[0].Time
                                  });
            for (int i = 0; i < transferPigstyList.Count() - 1; i++)
            {
                transferInfos.Add(new TransferPigstyInfoDetail
                                      {
                                          SourcePigHouse =
                                              transferPigstyList[i].pigsty.pig_house.pig_house_type.Name
                                              + transferPigstyList[i].pigsty.pig_house.Number,
                                          SourcePigsty = transferPigstyList[i].pigsty.Number + "",
                                          TargetPigHouse =
                                              transferPigstyList[i + 1].pigsty.pig_house.pig_house_type.
                                                                        Name
                                              + transferPigstyList[i + 1].pigsty.pig_house.Number,
                                          TargetPigsty = transferPigstyList[i + 1].pigsty.Number + "",
                                          TransferPigstyTime = transferPigstyList[i + 1].Time
                                      });
            }
            pigInfo.TransferPigstyRecord =
                new PagedList<TransferPigstyInfoDetail>(transferInfos.OrderBy(m => m.TransferPigstyTime).ToList(),
                                                        pageIndex, pageSize)
                    {
                        Capacity = transferInfos.Count,
                        CurrentPageIndex = pageIndex,
                        PageSize = pageSize,
                        TotalItemCount = transferInfos.Count
                    };
            return pigInfo;
        }
Ejemplo n.º 24
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;
            }
        }
Ejemplo n.º 25
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;
        }