Ejemplo n.º 1
0
        /// <summary>
        /// Update the IrrigationUnit from Farm IrrigationUnit List,
        /// If do not exists return null
        /// </summary>
        /// <param name="pName"></param>
        /// <param name="pShortName"></param>
        /// <param name="pIrrigationType"></param>
        /// <param name="pIrrigationEfficiency"></param>
        /// <param name="pIrrigationList"></param>
        /// <param name="pSurface"></param>
        /// <param name="pBombId"></param>
        /// <param name="pPositionId"></param>
        /// <param name="pPredeterminatedIrrigationQuantity"></param>
        /// <returns></returns>
        public IrrigationUnit UpdateIrrigationUnit(String pName, String pShortName, Utils.IrrigationUnitType pIrrigationType,
                                                   double pIrrigationEfficiency, List <Pair <DateTime, double> > pIrrigationList,
                                                   double pSurface, long pBombId, long pPositionId, Double pPredeterminatedIrrigationQuantity)
        {
            IrrigationUnit lReturn         = null;
            IrrigationUnit lIrrigationUnit = new IrrigationUnit(this.GetNewIrrigationUnitListId(), pName, pShortName,
                                                                pIrrigationType, pIrrigationEfficiency,
                                                                pIrrigationList, pSurface, pBombId, pPositionId,
                                                                pPredeterminatedIrrigationQuantity);

            lReturn = ExistIrrigationUnit(lIrrigationUnit);
            if (lReturn != null)
            {
                lReturn.Name                 = pName;
                lReturn.ShortName            = pShortName;
                lReturn.IrrigationType       = pIrrigationType;
                lReturn.IrrigationEfficiency = pIrrigationEfficiency;
                lReturn.IrrigationList       = pIrrigationList;
                lReturn.Surface              = pSurface;
                lReturn.BombId               = pBombId;
                lReturn.PositionId           = pPositionId;
                lReturn.PredeterminatedIrrigationQuantity = pPredeterminatedIrrigationQuantity;
            }
            return(lReturn);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get a DailyRecord in CropIrrigationWeather list
        /// Where CropIrrigationWeather is the IrrigationUnit instance
        ///     And DailyRecord Date equals Date of Reference
        /// </summary>
        /// <param name="pIrrigationUnit"></param>
        /// <param name="pDateOfReference"></param>
        /// <returns></returns>
        public DailyRecord GetDailyRecordBy(IrrigationUnit pIrrigationUnit,
                                            DateTime pDateOfReference, Crop pCrop)
        {
            DailyRecord                  lReturn = null;
            CropIrrigationWeather        lCropIrrigationWeather    = null;
            List <CropIrrigationWeather> lCropIrrigationWeaterList = new List <CropIrrigationWeather>();

            if (pIrrigationUnit != null && pDateOfReference != null)
            {
                lCropIrrigationWeather = db.CropIrrigationWeathers
                                         .Include(ciw => ciw.Crop)
                                         .Include(ciw => ciw.IrrigationList)
                                         .Include(ciw => ciw.MainWeatherStation)
                                         .Include(ciw => ciw.AlternativeWeatherStation)
                                         .Include(ciw => ciw.PhenologicalStageAdjustmentList)
                                         .Include(ciw => ciw.Soil)
                                         .Include(ciw => ciw.DailyRecordList)
                                         .Where(ciw => ciw.IrrigationUnitId == pIrrigationUnit.IrrigationUnitId &&
                                                ciw.CropId == pCrop.CropId &&
                                                ciw.SowingDate <= pDateOfReference &&
                                                ciw.HarvestDate >= pDateOfReference).FirstOrDefault();

                lReturn = lCropIrrigationWeather.DailyRecordList
                          .Where(ciw => ciw.DailyRecordDateTime.Date == pDateOfReference.Date).FirstOrDefault();
            }

            return(lReturn);
        }
Ejemplo n.º 3
0
 public IrrigationUnitViewModel(IrrigationUnit pIrrigationUnit)
 {
     this.IrrigationUnitId     = pIrrigationUnit.IrrigationUnitId;
     this.Name                 = pIrrigationUnit.Name;
     this.IrrigationType       = pIrrigationUnit.IrrigationType;
     this.IrrigationEfficiency = pIrrigationUnit.IrrigationEfficiency;
     this.IrrigationList       = pIrrigationUnit.IrrigationList;
     this.Surface              = pIrrigationUnit.Surface;
     this.BombId               = pIrrigationUnit.BombId;
     this.Bomb                 = new BombViewModel(pIrrigationUnit.Bomb);
     this.PositionId           = pIrrigationUnit.PositionId;
     this.PredeterminatedIrrigationQuantity = pIrrigationUnit.PredeterminatedIrrigationQuantity;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Return if the IrrigationUnit exists in Farm IrrigationUnit List,
        /// else null
        /// </summary>
        /// <param name="pIrrigationUnit"></param>
        /// <returns></returns>
        public IrrigationUnit ExistIrrigationUnit(IrrigationUnit pIrrigationUnit)
        {
            IrrigationUnit lReturn = null;

            foreach (IrrigationUnit item in this.IrrigationUnitList)
            {
                if (item.Equals(pIrrigationUnit))
                {
                    lReturn = item;
                    break;
                }
            }
            return(lReturn);
        }
Ejemplo n.º 5
0
        public ActionResult DeleteConfirmed(long id)
        {
            //Sprinkler lSprinkler = db.Sprinklers.Find(id);
            //lSprinkler.Show = false;
            //db.Entry(lSprinkler).State = EntityState.Modified;
            //db.SaveChanges();

            IrrigationUnitConfiguration fc = new IrrigationUnitConfiguration();
            IrrigationUnit irrigationUnit  = db.IrrigationUnits.Find(id);

            fc.Disable(irrigationUnit);
            db.SaveChanges();

            return(Redirect("/IrrigationUnit"));
            //var lList = db.IrrigationUnits.Include(f => f.Farm);
            //return View("~/Views/Irrigation/IrrigationUnit/Index.cshtml", lList.ToList());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add a IrrigationUnit to Farm IrrigationUnit List,
        /// If exists return null
        /// </summary>
        /// <param name="pName"></param>
        /// <param name="pShortName"></param>
        /// <param name="pIrrigationType"></param>
        /// <param name="pIrrigationEfficiency"></param>
        /// <param name="pIrrigationList"></param>
        /// <param name="pSurface"></param>
        /// <param name="pBombId"></param>
        /// <param name="pPositionId"></param>
        /// <param name="pPredeterminatedIrrigationQuantity"></param>
        /// <returns></returns>
        public IrrigationUnit AddIrrigationUnit(String pName, String pShortName, Utils.IrrigationUnitType pIrrigationType,
                                                double pIrrigationEfficiency, List <Pair <DateTime, double> > pIrrigationList,
                                                double pSurface, long pBombId, long pPositionId, Double pPredeterminatedIrrigationQuantity)
        {
            IrrigationUnit lReturn           = null;
            long           lIdIrrigationUnit = this.GetNewIrrigationUnitListId();
            IrrigationUnit lIrrigationUnit   = new IrrigationUnit(lIdIrrigationUnit, pName,
                                                                  pShortName, pIrrigationType, pIrrigationEfficiency,
                                                                  pIrrigationList, pSurface, pBombId, pPositionId,
                                                                  pPredeterminatedIrrigationQuantity);

            if (ExistIrrigationUnit(lIrrigationUnit) == null)
            {
                this.IrrigationUnitList.Add(lIrrigationUnit);
                lReturn = lIrrigationUnit;
            }
            return(lReturn);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get a DailyRecord in CropIrrigationWeather list
        /// Where CropIrrigationWeather is the IrrigationUnit instance
        ///     And DailyRecord Date equals Date of Reference plus DAYS_FOR_PREDICTION
        /// Include: DailyRecordList;
        /// </summary>
        /// <param name="pIrrigationUnit"></param>
        /// <param name="pDateOfReference"></param>
        /// <param name="pCrop"></param>
        /// <returns></returns>
        public List <DailyRecord> GetDailyRecordListIncludeDailyRecordListBy(IrrigationUnit pIrrigationUnit,
                                                                             DateTime pDateOfReference, Crop pCrop)
        {
            List <DailyRecord>           lReturn                   = null;
            List <DailyRecord>           lNewDailyRecordList       = new List <DailyRecord>();
            CropIrrigationWeather        lCropIrrigationWeather    = null;
            List <CropIrrigationWeather> lCropIrrigationWeaterList = new List <CropIrrigationWeather>();

            if (pIrrigationUnit != null && pDateOfReference != null)
            {
                lCropIrrigationWeather = db.CropIrrigationWeathers
                                         .Include(ciw => ciw.DailyRecordList)
                                         .Include(ciw => ciw.DailyRecordList.Select(dr => dr.MainWeatherData))
                                         .Include(ciw => ciw.DailyRecordList.Select(dr => dr.AlternativeWeatherData))
                                         .Include(ciw => ciw.DailyRecordList.Select(dr => dr.PhenologicalStage))
                                         .Include(ciw => ciw.DailyRecordList.Select(dr => dr.Rain))
                                         .Include(ciw => ciw.DailyRecordList.Select(dr => dr.Irrigation))
                                         .Include(ciw => ciw.DailyRecordList.Select(dr => dr.EvapotranspirationCrop))
                                         .Where(ciw => ciw.IrrigationUnitId == pIrrigationUnit.IrrigationUnitId &&
                                                ciw.CropId == pCrop.CropId &&
                                                ciw.SowingDate <= pDateOfReference &&
                                                ciw.HarvestDate >= pDateOfReference).FirstOrDefault();
                //TODO: Get from 10 days before DateOfReference
                foreach (var record in lCropIrrigationWeather.DailyRecordList)
                {
                    if (record.DailyRecordDateTime <= pDateOfReference.AddDays(InitialTables.DAYS_FOR_PREDICTION))
                    {
                        //Only the days between (Date of Reference - DAYS_FOR_PREDICTION) and (Date of Reference + DAYS_FOR_PREDICTION)
                        if (record.DailyRecordDateTime >= pDateOfReference.AddDays(-InitialTables.DAYS_FOR_PREDICTION))
                        {
                            lNewDailyRecordList.Add(record);
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                lReturn = lNewDailyRecordList.ToList();
            }

            return(lReturn);
        }
Ejemplo n.º 8
0
 public IrrigationUnitViewModel(IrrigationUnit pIrrigationUnit)
 {
     this.IrrigationUnitId     = pIrrigationUnit.IrrigationUnitId;
     this.Name                 = pIrrigationUnit.Name;
     this.IrrigationType       = pIrrigationUnit.IrrigationType;
     this.IrrigationEfficiency = pIrrigationUnit.IrrigationEfficiency;
     this.IrrigationList       = pIrrigationUnit.IrrigationList;
     this.Surface              = pIrrigationUnit.Surface;
     this.BombId               = pIrrigationUnit.BombId;
     this.Bomb                 = new BombViewModel(pIrrigationUnit.Bomb);
     this.PositionId           = pIrrigationUnit.PositionId;
     this.Position             = pIrrigationUnit.Position;
     this.PredeterminatedIrrigationQuantity = pIrrigationUnit.PredeterminatedIrrigationQuantity;
     this.FarmId    = pIrrigationUnit.FarmId;
     this.Farm      = pIrrigationUnit.Farm;
     this.ShortName = pIrrigationUnit.ShortName;
     this.Latitude  = pIrrigationUnit.Position.Latitude;
     this.Longitude = pIrrigationUnit.Position.Longitude;
     this.Show      = pIrrigationUnit.Show;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Get a MAX date of reference in CropIrrigationWeather list
        /// Where CropIrrigationWeather is the IrrigationUnit instance
        ///     And DailyRecord Date equals Date of Reference plus DAYS_FOR_PREDICTION
        /// Include:
        /// </summary>
        /// <param name="pIrrigationUnit"></param>
        /// <param name="pDateOfReference"></param>
        /// <returns></returns>
        public DateTime GetMaxDateOfReferenceBy(IrrigationUnit pIrrigationUnit,
                                                DateTime pDateOfReference)
        {
            DateTime                     lReturn                   = Utils.MIN_DATETIME;
            DateTime                     lMAXDate                  = Utils.MAX_DATETIME;
            List <DailyRecord>           lNewDailyRecordList       = new List <DailyRecord>();
            CropIrrigationWeather        lCropIrrigationWeather    = null;
            List <CropIrrigationWeather> lCropIrrigationWeaterList = new List <CropIrrigationWeather>();
            DateTime                     lSowingDate;
            DateTime                     lHarvestDate;
            DateTime                     lDateLastDailyRecord;


            if (pIrrigationUnit != null && pDateOfReference != null)
            {
                lCropIrrigationWeaterList = db.CropIrrigationWeathers
                                            .Include(ciw => ciw.DailyRecordList)
                                            .Where(ciw => ciw.IrrigationUnitId == pIrrigationUnit.IrrigationUnitId &&
                                                   ciw.SowingDate <= pDateOfReference &&
                                                   ciw.HarvestDate >= pDateOfReference).ToList();
                foreach (CropIrrigationWeather item in lCropIrrigationWeaterList)
                {
                    lSowingDate  = item.SowingDate;
                    lHarvestDate = item.HarvestDate;

                    //TODO: Could be more than one CropIrrigationWeather, when the IrrigationUnit is used for more than one Crop
                    if ((lSowingDate <= pDateOfReference) &&
                        (lHarvestDate >= pDateOfReference))
                    {
                        lCropIrrigationWeather = item;
                        lDateLastDailyRecord   = lCropIrrigationWeather.DailyRecordList
                                                 .OrderByDescending(dr => dr.DailyRecordDateTime).FirstOrDefault().DailyRecordDateTime;
                        lMAXDate = Utils.MinDateTimeBetween(lDateLastDailyRecord, lMAXDate);
                    }
                }

                lReturn = lMAXDate;
            }

            return(lReturn);
        }
Ejemplo n.º 10
0
        private List <System.Web.Mvc.SelectListItem> LoadFarm(long?farmId = null, IrrigationUnit irrigationUnit = null)
        {
            FarmConfiguration rc = new FarmConfiguration();
            List <Farm>       farmConfiguration         = rc.GetAllFarms();
            List <System.Web.Mvc.SelectListItem> result = new List <SelectListItem>();

            foreach (var item in farmConfiguration)
            {
                bool isSelected = false;

                SelectListItem sl = new SelectListItem()
                {
                    Value    = item.FarmId.ToString(),
                    Text     = item.Name,
                    Selected = isSelected
                };

                result.Add(sl);
            }

            return(result);
        }
 public PartialViewResult InputWaterPerDayPartial(IrrigationUnit pIrrigationUnit)
 {
     return(PartialView("~/Views/Reports/CropIrrigationWeathersActive/_InputWaterPerDayPartial.cshtml", GetGridDailyRecordIrrigationResume(pIrrigationUnit)));
 }
        /// <summary>
        /// Return Grid Datail from dailyrecord days
        /// </summary>
        /// <returns></returns>
        public List <GridReportPivotState> GetGridDailyRecordIrrigationResume(IrrigationUnit pIrrigationUnit)
        {
            #region Local Variables
            string lEffectiveRain;
            string lEffectiveInputWater;
            double lEffectiveRainDouble;
            double lEffectiveInputWaterDouble;

            List <GridReportPivotState> lGridIrrigationUnitList = new List <GridReportPivotState>();
            List <GridReportPivotState> lGridDailyRecordIrrigationResumeList = new List <GridReportPivotState>();
            GridReportPivotState        lGridDailyRecordIrrigationResume     = null;
            DateTime lDateOfReference;

            List <DailyRecord>           lDailyRecordList;
            DailyRecordConfiguration     lDailyRecordConfiguration;
            List <CropIrrigationWeather> lCropIrrigationWeatherList;
            IrrigationUnitConfiguration  lIrrigationUnitConfiguration;
            #endregion

            try
            {
                lDateOfReference             = Utils.GetDateOfReference().Value;
                lIrrigationUnitConfiguration = new IrrigationUnitConfiguration();
                lDailyRecordConfiguration    = new DailyRecordConfiguration();

                lCropIrrigationWeatherList = lIrrigationUnitConfiguration.GetCropIrrigationWeatherListIncludeCropMainWeatherStationRainListIrrigationListBy(pIrrigationUnit, lDateOfReference);
                foreach (CropIrrigationWeather lCropIrrigationWeather in lCropIrrigationWeatherList)
                {
                    lDailyRecordList = lDailyRecordConfiguration.GetDailyRecordsListDataUntilDateBy(lCropIrrigationWeather.CropIrrigationWeatherId, lDateOfReference);

                    foreach (var lDailyRecordUnit in lDailyRecordList)
                    {
                        lEffectiveRain             = "";
                        lEffectiveInputWater       = "";
                        lEffectiveRainDouble       = 0;
                        lEffectiveInputWaterDouble = 0;

                        if (lDailyRecordUnit.Rain != null)
                        {
                            lEffectiveRainDouble = lDailyRecordUnit.Rain.ExtraInput + lDailyRecordUnit.Rain.Input;
                        }

                        if (lDailyRecordUnit.Irrigation != null)
                        {
                            lEffectiveInputWaterDouble = lDailyRecordUnit.Irrigation.ExtraInput + lDailyRecordUnit.Irrigation.Input;
                        }
                        if (lEffectiveRainDouble + lEffectiveInputWaterDouble > 0) // not input
                        {
                            if (lEffectiveRainDouble != 0)
                            {
                                lEffectiveRain = lEffectiveRainDouble.ToString();
                            }

                            if (lEffectiveInputWaterDouble != 0)
                            {
                                lEffectiveInputWater = lEffectiveInputWaterDouble.ToString();
                            }

                            lGridDailyRecordIrrigationResume = new GridReportPivotState(lDailyRecordUnit.DaysAfterSowing.ToString(), lDailyRecordUnit.DailyRecordDateTime.ToShortDateString(), lEffectiveRain, lEffectiveInputWater);
                            lGridDailyRecordIrrigationResumeList.Add(lGridDailyRecordIrrigationResume);
                        }
                    }
                }
            }


            catch (Exception ex)
            {
                Utils.LogError(ex, "Exception in ReportPivotState.GetGridDailyRecordIrrigationResume \n {0} ");
                return(null);
            }

            return(lGridDailyRecordIrrigationResumeList);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Get a DailyRecord in CropIrrigationWeather list
        /// Where CropIrrigationWeather is the IrrigationUnit instance
        ///     And DailyRecord Date equals Date of Reference plus DAYS_FOR_PREDICTION
        /// Include:
        /// </summary>
        /// <param name="pIrrigationUnit"></param>
        /// <param name="pDateOfReference"></param>
        /// <returns></returns>
        public List <DailyRecord> GetDailyRecordListBy(IrrigationUnit pIrrigationUnit,
                                                       DateTime pDateOfReference)
        {
            List <DailyRecord>           lReturn                   = null;
            List <DailyRecord>           lNewDailyRecordList       = new List <DailyRecord>();
            CropIrrigationWeather        lCropIrrigationWeather    = null;
            List <CropIrrigationWeather> lCropIrrigationWeaterList = new List <CropIrrigationWeather>();

            if (pIrrigationUnit != null && pDateOfReference != null)
            {
                lCropIrrigationWeaterList = db.CropIrrigationWeathers
                                            .Include(ciw => ciw.Crop)
                                            .Include(ciw => ciw.Crop.Region)
                                            .Include(ciw => ciw.Crop.Region.EffectiveRainList)
                                            .Include(ciw => ciw.Crop.Region.TemperatureDataList)
                                            .Include(ciw => ciw.Crop.PhenologicalStageList)
                                            .Include(ciw => ciw.Crop.PhenologicalStageList.Select(ps => ps.Stage))
                                            .Include(ciw => ciw.Crop.StageList)
                                            .Include(ciw => ciw.Crop.CropCoefficient)
                                            .Include(ciw => ciw.Crop.CropCoefficient.KCList)
                                            .Include(ciw => ciw.Soil)
                                            .Include(ciw => ciw.Soil.HorizonList)
                                            .Include(ciw => ciw.CropInformationByDate)
                                            .Include(ciw => ciw.MainWeatherStation)
                                            .Include(ciw => ciw.MainWeatherStation.WeatherDataList)
                                            .Include(ciw => ciw.AlternativeWeatherStation)
                                            .Include(ciw => ciw.AlternativeWeatherStation.WeatherDataList)
                                            .Include(ciw => ciw.RainList)
                                            .Include(ciw => ciw.IrrigationList)
                                            .Include(ciw => ciw.EvapotranspirationCropList)
                                            .Include(ciw => ciw.DailyRecordList)
                                            .Include(ciw => ciw.DailyRecordList.Select(dr => dr.MainWeatherData))
                                            .Include(ciw => ciw.DailyRecordList.Select(dr => dr.AlternativeWeatherData))
                                            .Include(ciw => ciw.DailyRecordList.Select(dr => dr.PhenologicalStage))
                                            .Include(ciw => ciw.DailyRecordList.Select(dr => dr.Rain))
                                            .Include(ciw => ciw.DailyRecordList.Select(dr => dr.Irrigation))
                                            .Include(ciw => ciw.DailyRecordList.Select(dr => dr.EvapotranspirationCrop))
                                            .Where(ciw => ciw.IrrigationUnitId == pIrrigationUnit.IrrigationUnitId &&
                                                   ciw.SowingDate <= pDateOfReference &&
                                                   ciw.HarvestDate >= pDateOfReference).ToList();
                foreach (CropIrrigationWeather item in lCropIrrigationWeaterList)
                {
                    lCropIrrigationWeather = item;
                    foreach (var record in lCropIrrigationWeather.DailyRecordList)
                    {
                        if (record.DailyRecordDateTime <= pDateOfReference.AddDays(InitialTables.DAYS_FOR_PREDICTION))
                        {
                            lNewDailyRecordList.Add(record);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                lReturn = lNewDailyRecordList.ToList();
            }

            return(lReturn);
        }
Ejemplo n.º 14
0
        private List <System.Web.Mvc.SelectListItem> LoadIrrigationType(Utils.IrrigationUnitType?irrigationType = null, IrrigationUnit irrigationUnit = null)
        {
            Array irrigationUnitTypes = System.Enum.GetValues(typeof(Utils.IrrigationUnitType));

            List <System.Web.Mvc.SelectListItem> result = new List <SelectListItem>();

            foreach (var item in irrigationUnitTypes)
            {
                bool isSelected = false;
                if (irrigationUnit != null && irrigationType != null)
                {
                    isSelected = (irrigationUnit.IrrigationType == irrigationType);
                }

                SelectListItem sl = new SelectListItem()
                {
                    Value    = item.ToString(),
                    Text     = item.ToString(),
                    Selected = isSelected
                };

                result.Add(sl);
            }

            return(result);
        }