/// <summary> /// Add a new PhenologicalStage, if exists, return null /// </summary> /// <param name="pSpecie"></param> /// <param name="pStage"></param> /// <param name="pMinDegree"></param> /// <param name="pMaxDegree"></param> /// <param name="pCoefficient"></param> /// <param name="pRootDepth"></param> /// <param name="pHydricBalanceDepth"></param> /// <returns></returns> public PhenologicalStage AddPhenologicalStage(Specie pSpecie, Stage pStage, Double pMinDegree, Double pMaxDegree, Double pCoefficient, Double pRootDepth, Double pHydricBalanceDepth) { //Refactroing 2017/09/14 Changes in Phenological Table Modificable ///TODO ver si es mejor ingresar datos externos o calcular "lDegreesDaysInterval" bool lPhenologicalStageIsUsed = true; Double lDegreesDaysInterval = pMaxDegree - pMinDegree; PhenologicalStage lReturn = null; long lPhenologicalStageId = this.GetNewPhenologicalStageListId(); PhenologicalStage lPhenologicalStage = new PhenologicalStage(lPhenologicalStageId, pSpecie, pStage, pMinDegree, pMaxDegree, pCoefficient, pRootDepth, pHydricBalanceDepth, lPhenologicalStageIsUsed, lDegreesDaysInterval); lReturn = ExistPhenologicalStage(lPhenologicalStage); if (lReturn == null) { this.StageList.Add(pStage); this.PhenologicalStageList.Add(lPhenologicalStage); lReturn = lPhenologicalStage; } return(lReturn); }
/// <summary> /// Update PhenologicalStage /// </summary> /// <param name="pPhenologicalStage"></param> /// <returns></returns> public PhenologicalStage UpdatePhenologicalStage(PhenologicalStage pPhenologicalStage) { PhenologicalStage lReturn = null; Stage lStage = null; lReturn = ExistPhenologicalStage(pPhenologicalStage); if (lReturn != null) { lStage = this.FindStage(pPhenologicalStage.Stage.Name); if (lStage != null) { lStage.Name = pPhenologicalStage.Stage.Name; lStage.ShortName = pPhenologicalStage.Stage.ShortName; lStage.Description = pPhenologicalStage.Stage.Description; lStage.Order = pPhenologicalStage.Stage.Order; } else { //TODO throw exception "There is a Phenological Stage without Stage in StageList!! Error of data." } lReturn.UpdateStage(pPhenologicalStage.Stage.Name, pPhenologicalStage.Stage.ShortName, pPhenologicalStage.Stage.Description, pPhenologicalStage.Stage.Order); lReturn.MinDegree = pPhenologicalStage.MinDegree; lReturn.MaxDegree = pPhenologicalStage.MaxDegree; lReturn.Coefficient = pPhenologicalStage.Coefficient; lReturn.RootDepth = pPhenologicalStage.RootDepth; lReturn.HydricBalanceDepth = pPhenologicalStage.HydricBalanceDepth; } return(lReturn); }
/// <summary> /// Get the initial Phenological Stage /// </summary> /// <returns></returns> public PhenologicalStage GetInitialPhenologicalStage() { PhenologicalStage lReturn = null; if (this.PhenologicalStageList.Count() > 0) { lReturn = this.PhenologicalStageList[0]; } return(lReturn); }
/// <summary> /// Find A Stage Order by StageId /// </summary> /// <param name="pStageId"></param> /// <returns></returns> public int FindStageOrder(long pStageId) { int lReturn = 0; PhenologicalStage lPhenologicalStage = this.FindPhenologicalStage(pStageId); if (lPhenologicalStage != null) { lReturn = lPhenologicalStage.Stage.Order; } return(lReturn); }
// Different region for each class override /// <summary> /// Overrides equals /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { bool lReturn = false; if (obj == null || obj.GetType() != this.GetType()) { return(false); } PhenologicalStage lPhenologicalStage = obj as PhenologicalStage; lReturn = this.Stage.Equals(lPhenologicalStage.Stage); return(lReturn); }
/// <summary> /// Update all the information about an existing PhenologicalStage, /// if not exist, return null /// </summary> /// <param name="pSpecie"></param> /// <param name="pStage"></param> /// <param name="pMinDegree"></param> /// <param name="pMaxDegree"></param> /// <param name="pCoefficient"></param> /// <param name="pRootDepth"></param> /// <param name="pHydricBalanceDepth"></param> /// <returns></returns> public PhenologicalStage UpdatePhenologicalStage(Specie pSpecie, Stage pStage, Double pMinDegree, Double pMaxDegree, Double pCoefficient, Double pRootDepth, Double pHydricBalanceDepth) { //Refactroing 2017/09/14 Changes in Phenological Table Modificable ///TODO ver si es mejor ingresar datos externos o calcular "lDegreesDaysInterval" bool lPhenologicalStageIsUsed = true; Double lDegreesDaysInterval = pMaxDegree - pMinDegree; PhenologicalStage lReturn = null; Stage lStage = null; try { PhenologicalStage lPhenologicalStage = new PhenologicalStage(0, pSpecie, pStage, pMinDegree, pMaxDegree, pCoefficient, pRootDepth, pHydricBalanceDepth, lPhenologicalStageIsUsed, lDegreesDaysInterval); lReturn = ExistPhenologicalStage(lPhenologicalStage); if (lReturn != null) { lStage = this.FindStage(pStage.Name); if (lStage != null) { lStage.Name = pStage.Name; lStage.ShortName = pStage.ShortName; lStage.Description = pStage.Description; } else { //TODO throw exception "There is a Phenological Stage without Stage in StageList!! Error of data." logger.Error("Phenological Stage", "UpdatePhenologicalStage" + "\n" + "There is a Phenological Stage without Stage in StageList!! Error of data."); } lReturn.SpecieId = pSpecie.SpecieId; lReturn.UpdateStage(pStage.Name, pStage.ShortName, pStage.Description, pStage.Order); lReturn.MinDegree = pMinDegree; lReturn.MaxDegree = pMaxDegree; lReturn.Coefficient = pCoefficient; lReturn.RootDepth = pRootDepth; lReturn.HydricBalanceDepth = pHydricBalanceDepth; } } catch (Exception ex) { logger.Error(ex, "Exception in CropIrrigationWeather.UpdatePhenologicalStage " + "\n" + ex.Message + "\n" + ex.StackTrace); throw ex; } return(lReturn); }
/// <summary> /// Return Phenological Stage by Growing Degree Days /// is between Min & Max Degrees /// </summary> /// <param name="pGrowingDegreeDays"></param> /// <returns></returns> private PhenologicalStage setPhenologicalStage(Double pGrowingDegreeDays) { PhenologicalStage lReturn = null; foreach (PhenologicalStage lPhenologicalStage in this.PhenologicalStageList) { if (pGrowingDegreeDays >= lPhenologicalStage.MinDegree && pGrowingDegreeDays <= lPhenologicalStage.MaxDegree) { lReturn = lPhenologicalStage; break; } } return(lReturn); }
/// <summary> /// Find A PhenologicalStage by StageId /// </summary> /// <param name="pStageId"></param> /// <returns></returns> public PhenologicalStage FindPhenologicalStage(long pStageId) { PhenologicalStage lReturn = null; foreach (PhenologicalStage item in this.PhenologicalStageList) { if (item.Stage.StageId == pStageId) { lReturn = item; break; } } return(lReturn); }
/// <summary> /// If PhenologicalStage exist in List, return the PhenologicalStage, /// else return null /// </summary> /// <param name="pInitialPhenologicalStage"></param> /// <returns></returns> public PhenologicalStage ExistPhenologicalStage(PhenologicalStage pPhenologicalStage) { PhenologicalStage lReturn = null; if (pPhenologicalStage != null) { foreach (PhenologicalStage item in this.PhenologicalStageList) { if (item.Equals(pPhenologicalStage)) { lReturn = item; break; } } } return(lReturn); }