Ejemplo n.º 1
0
        private static EditableList <VetFarmTree> RootTreeToFarm(DbManagerProxy manager, IObject Parent, EditableList <RootFarmTree> roots, long?idfCase = null)
        {
            var farmTree     = new EditableList <VetFarmTree>();
            var treeAccessor = VetFarmTree.Accessor.Instance(null);

            foreach (var farmroot in roots.Where(x => x.idfParentParty == null))
            {
                VetFarmTree farmItem = treeAccessor.CreateNewT(manager, Parent, farmroot._HACode);
                farmTree.Add(farmItem);
                foreach (var herdroot in roots.Where(x => x.idfParentParty == farmroot.idfParty))
                {
                    VetFarmTree herdItem = treeAccessor.CreateHerd(manager, Parent, farmItem);
                    herdItem.strName = herdroot.strName;
                    farmTree.Add(herdItem);
                    foreach (var speciesroot in roots.Where(x => x.idfParentParty == herdroot.idfParty))
                    {
                        VetFarmTree species = treeAccessor.CreateSpecies(manager, Parent, herdItem);
                        species.idfsSpeciesTypeReference = speciesroot.idfsSpeciesTypeReference;
                        species.SpeciesType = speciesroot.SpeciesType;
                        species.strHerdName = herdItem.strName;
                        farmTree.Add(species);
                    }
                }
            }
            if (idfCase.HasValue)
            {
                farmTree.ForEach(x => x.idfCase = idfCase.Value);
            }
            return(farmTree);
        }
Ejemplo n.º 2
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.º 3
0
 public void CopyMainProperties(VetFarmTree spec)
 {
     //this._HACode = spec._HACode;
     this.idfSpecies  = spec.idfParty;
     this.idfCase     = spec.idfCase ?? this.idfCase;
     this.idfHerd     = spec.idfParentParty.Value;
     this.strSpecies  = spec.strSpeciesName;
     this.strHerdCode = spec.strHerdName;
 }
Ejemplo n.º 4
0
        protected static void CustomValidations(VetFarmTree obj)
        {
            var acc = FFPresenterModel.Accessor.Instance(null);

            using (var manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance))
            {
                acc.Validate(manager, obj.FFPresenterCs, true, false, true);
            }
        }
Ejemplo n.º 5
0
        public static void UpdateTemplate(VetFarmTree obj)
        {
            var templateSpecies = FFPresenterModel.LoadActualTemplate(EidssSiteContext.Instance.CountryID,
                                                                      obj.idfsDiagnosisForCs,
                                                                      (obj._HACode == (int)HACode.Livestock)
                                                                               ? FFTypeEnum.LivestockSpeciesCS
                                                                               : FFTypeEnum.AvianSpeciesCS);

            obj.FFPresenterCs.SetProperties(templateSpecies, obj.idfFarm);
            obj.idfsFormTemplate = templateSpecies.idfsFormTemplate;
        }
Ejemplo n.º 6
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.º 7
0
        protected static void TotalQuantityRule(VetFarmTree data)
        {
            //sum of dead and sick animals must not exceed total quantity
            if (data.intTotalAnimalQty.HasValue || data.intSickAnimalQty.HasValue || data.intDeadAnimalQty.HasValue)
            {
                int total = data.intTotalAnimalQty ?? 0;
                int sick  = data.intSickAnimalQty ?? 0;
                int dead  = data.intDeadAnimalQty ?? 0;

                if (sick + dead > total)
                {
                    throw new ValidationModelException("VetFarmTree_TotalQuantityRule_Obeyed", "", "", new string[] {},
                                                       null, ValidationEventType.Error, data);
                }
            }
        }
Ejemplo n.º 8
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.º 9
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.º 10
0
 public static void RecalcAllAnimalQty(FarmPanel obj, VetFarmTree item)
 {
     RecalcTotalAnimalQty(obj, item);
     RecalcSickAnimalQty(obj, item);
     RecalcDeadAnimalQty(obj, item);
 }