Ejemplo n.º 1
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.º 2
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);
 }