Ejemplo n.º 1
0
        public static void RecalcDeadAnimalQty(FarmPanel obj, VetFarmTree item)
        {
            var sum = obj.FarmTree.Where(c => c.idfParentParty == item.idfParentParty && !c.IsMarkedToDelete).Sum(c => c.intDeadAnimalQty);
            var o   = obj.FarmTree.Single(c => c.idfParty == item.idfParentParty);

            o.intDeadAnimalQty = sum == 0 ? null : sum;
        }
Ejemplo n.º 2
0
        protected static void CustomValidations(FarmPanel obj)
        {
            var acc = FFPresenterModel.Accessor.Instance(null);

            using (var manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance))
            {
                acc.Validate(manager, obj.FFPresenterEpi, true, false, true);
            }
        }
Ejemplo n.º 3
0
        public static void RecalcTotalAnimalQty(FarmPanel obj, VetFarmTree item)
        {
            var itemsCount = obj.FarmTree.Count(c => c.idfParentParty == item.idfParentParty && !c.IsMarkedToDelete && c.intTotalAnimalQty.HasValue);
            int?sum        = 0;

            try { sum = obj.FarmTree.Where(c => c.idfParentParty == item.idfParentParty && !c.IsMarkedToDelete).Sum(c => c.intTotalAnimalQty); }
            catch (OverflowException) {}
            var o = obj.FarmTree.Single(c => c.idfParty == item.idfParentParty);

            o.intTotalAnimalQty = sum == 0 && itemsCount == 0 ? null : sum;
        }
Ejemplo n.º 4
0
 public static void CheckAddressToSessionAddress(FarmPanel farm)
 {
     if (farm.ASSession != null)
     {
         if (!farm.ASSession._blnAssessionPosting)
         {
             if ((farm.ASSession.idfsSettlement.HasValue && farm.ASSession.idfsSettlement != farm.Address.idfsSettlement) ||
                 (farm.ASSession.idfsRayon.HasValue && farm.ASSession.idfsRayon != farm.Address.idfsRayon) ||
                 (farm.ASSession.idfsRegion.HasValue && farm.ASSession.idfsRegion != farm.Address.idfsRegion) ||
                 (farm.ASSession.idfsCountry.HasValue && farm.ASSession.idfsCountry != farm.Address.idfsCountry))
             {
                 throw new ValidationModelException("msgAddressIsOutOfBoundaries", "", "", new string[] { }, null, ValidationEventType.Question, farm);
             }
         }
     }
 }
Ejemplo n.º 5
0
        public static bool SpeciesContainsValidHerd(FarmPanel panel, VetFarmTree item)
        {
            if (item.idfsPartyType != (int)PartyTypeEnum.Species)
            {
                return(true);
            }
            string par = ((int)HACode.Livestock).Equals(item._HACode) ? "strHerd" : "strFlock";

            if (item.idfParentParty == null)
            {
                throw new ValidationModelException("ErrMandatoryFieldRequired", "FarmTree", item._HACode == (int)HACode.Livestock ? "Herd" : "Flock", new object[] { par }, typeof(RequiredValidator), ValidationEventType.Error, panel);
            }
            if (panel.FarmTree.Count(x => x.idfParty == item.idfParentParty && !x.IsMarkedToDelete) == 0)
            {
                throw new ValidationModelException("ErrInvalidValue", "", "", new object[] { par }, null, ValidationEventType.Error, panel);
            }
            return(true);
        }
Ejemplo n.º 6
0
        public static void CopyFromNonRoot(FarmRootPanel target, FarmPanel source)
        {
            // fill all value-fields except idftarget
            foreach (var prop in target.GetType().GetProperties().Select(x => x.Name))
            {
                if (COPY_EXTENSIONS.Contains(prop))
                {
                    continue;
                }

                object val = source.GetValue(prop);
                target.SetValue(prop, val == null ? "" : val.ToString());
            }

            source.Address.CopyFieldsTo(target.Address);

            source._blnAllowFarmReload = false;
            source.idfRootFarm         = target.idfFarm;
        }
Ejemplo n.º 7
0
        public static bool NewFarmTreeItemIsValid(FarmPanel panel, VetFarmTree item)
        {
            if (item.idfsPartyType != (int)PartyTypeEnum.Species)
            {
                return(true);
            }

            if (panel.FarmTree.Count(
                    x => x.idfsPartyType == (int)PartyTypeEnum.Species &&
                    x.idfParentParty == item.idfParentParty &&
                    x.idfsSpeciesTypeReference == item.idfsSpeciesTypeReference &&
                    !x.IsMarkedToDelete) > 1)
            {
                string errorMessage = item._HACode == (int)HACode.Livestock ? "DuplicateSpeciesLivestock_msgId" : "DuplicateSpeciesAvian_msgId";
                throw new ValidationModelException(errorMessage, "", "", new object[] { }, null, ValidationEventType.Error, panel);
            }
            FarmPanel.RecalcAllAnimalQty(panel, item);

            return(true);
        }
Ejemplo n.º 8
0
 public static void DuplicateSpeciesRule(FarmPanel farm)
 {
     if (farm.FarmTree.Where(t => t.idfsPartyType == (int)PartyTypeEnum.Species).GroupBy(x => new { parent = x.idfParentParty, idfsSpecies = x.idfsSpeciesTypeReference }).Where(s => s.Count() > 1).Count() > 0)
     {
         byte counter = 0;
         foreach (var herd in farm.FarmTree.Where(t => t.idfsPartyType == (int)PartyTypeEnum.Species).GroupBy(x => new { parent = x.idfParentParty, idfsSpecies = x.idfsSpeciesTypeReference }).Where(s => s.Count() > 1))
         {
             foreach (var spec in herd)
             {
                 if (!spec.IsMarkedToDelete)
                 {
                     counter++;
                 }
                 if (counter > 1)
                 {
                     string errorMessage = spec._HACode == (int)HACode.Livestock ? "DuplicateSpeciesLivestock_msgId" : "DuplicateSpeciesAvian_msgId";
                     throw new ValidationModelException(errorMessage, "", "", new string[] { }, null, ValidationEventType.Error, farm);
                 }
             }
         }
     }
 }
Ejemplo n.º 9
0
 public static void RecalcAllAnimalQty(FarmPanel obj, VetFarmTree item)
 {
     RecalcTotalAnimalQty(obj, item);
     RecalcSickAnimalQty(obj, item);
     RecalcDeadAnimalQty(obj, item);
 }