示例#1
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;
        }