Пример #1
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;
 }
Пример #2
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;
        }
Пример #3
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;
        }
Пример #4
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;
        }
Пример #5
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;
        }
Пример #6
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;
        }
Пример #7
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;
 }
Пример #8
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;
 }
 public int ValidatePigNum(string pigNumber)
 {
     var pigService = new PigService();
     if (pigService.FindByNumber(pigNumber) == null)
         return 1;
     return -1;
 }
Пример #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;
        }
Пример #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;
        }
Пример #12
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;
        }
Пример #13
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;
        }