/// <summary>
        /// Return Grid Irrigation Unit for Home Titles
        /// </summary>
        /// <returns></returns>
        public List <GridPivotHome> GetGridPivotHomeTitles()
        {
            #region Local Variables
            List <GridPivotHome>       lGridIrrigationUnitList = new List <GridPivotHome>();
            GridPivotHome              lGridIrrigationUnit;
            List <GridPivotDetailHome> lGridIrrigationUnitDetailRow;
            GridPivotDetailHome        lGridIrrigationUnitRow;
            DateTime lDateOfReference;

            #endregion

            try
            {
                lDateOfReference = ManageSession.GetNavigationDate();

                //Grid of irrigation data
                lGridIrrigationUnitDetailRow = new List <GridPivotDetailHome>();

                for (int i = -InitialTables.MIN_DAY_SHOW_IN_GRID_BEFORE_TODAY; i <= InitialTables.MAX_DAY_SHOW_IN_GRID_AFTER_TODAY; i++)
                {
                    //Day i
                    lGridIrrigationUnitRow = AddGridIrrigationUnitDays(lDateOfReference, lDateOfReference.AddDays(i), false);
                    lGridIrrigationUnitDetailRow.Add(lGridIrrigationUnitRow);
                }

                var homeViewModel = ManageSession.GetHomeViewModel();

                //Add all the days for the IrrigationUnit
                lGridIrrigationUnit = new GridPivotHome("Nombre",
                                                        "Cultivo",
                                                        "Siembra",
                                                        "Fen.",
                                                        "Balance H.",
                                                        "KC",
                                                        homeViewModel.IsUserAdministrator,
                                                        new List <double>(),
                                                        lGridIrrigationUnitDetailRow,
                                                        0);

                lGridIrrigationUnitList.Add(lGridIrrigationUnit);
            }
            catch (Exception ex)
            {
                Utils.LogError(ex, "Exception in HomeController.GetGridPivotHomeTitles ");
                throw ex;
            }

            return(lGridIrrigationUnitList);
        }
Exemple #2
0
        /// <summary>
        /// Return Grid Irrigation Unit for Home
        /// </summary>
        /// <returns></returns>
        public List <GridPivotHome> GetGridPivotHome()
        {
            #region Local Variables
            String lSomeData = "";
            List <GridPivotHome>       lGridIrrigationUnitList = new List <GridPivotHome>();
            GridPivotHome              lGridIrrigationUnit;
            List <GridPivotDetailHome> lGridIrrigationUnitDetailRow;
            GridPivotDetailHome        lGridIrrigationUnitRow;
            DateTime      lDateOfReference;
            FarmViewModel lFarmViewModel;
            User          lLoggedUser;
            List <Farm>   lFarmList;
            // Farm lCurrentFarm;
            List <IrrigationUnit>        lIrrigationUnitList;
            List <CropIrrigationWeather> lCropIrrigationWeatherList;
            String      lFirstPivotName = "";
            List <Rain> lRainList;
            List <Models.Water.Irrigation> lIrrigationList;
            List <DailyRecord>             lDailyRecordList;
            String        lSowingDate;
            String        lPhenologicalStageToday;
            Double        lHydricBalancePercentage;
            DailyRecord   lDailyRecord;
            String        lCropCoefficient;
            List <Double> lETcList;
            Double        lETcItem;
            HomeViewModel lHomeViewModel;
            #endregion

            #region Configuration Variables
            UserConfiguration                  lUserConfiguration;
            FarmConfiguration                  lFarmConfiguration;
            IrrigationUnitConfiguration        lIrrigationUnitConfiguration;
            CropIrrigationWeatherConfiguration lCropIrrigationWeatherConfiguration;
            IrrigationAdvisorContext           lIrrigationAdvisorContext;
            #endregion

            try
            {
                #region Configuration - Instance
                lUserConfiguration                  = new UserConfiguration();
                lFarmConfiguration                  = new FarmConfiguration();
                lIrrigationUnitConfiguration        = new IrrigationUnitConfiguration();
                lCropIrrigationWeatherConfiguration = new CropIrrigationWeatherConfiguration();
                lIrrigationAdvisorContext           = IrrigationAdvisorContext.Instance();
                #endregion

                lDateOfReference = ManageSession.GetNavigationDate();
                lSomeData        = lSomeData + "Date: " + lDateOfReference.Date + "-";

                //Obtain logged user
                lLoggedUser = lUserConfiguration.GetUserByName(ManageSession.GetUserName());
                lSomeData   = lSomeData + "User: "******"-";

                //Get list of Farms from User
                lFarmList = lFarmConfiguration.GetFarmWithActiveCropIrrigationWeathersListBy(lLoggedUser);

                //Create IrrigationQuantity Units List
                lIrrigationUnitList = new List <IrrigationUnit>();
                foreach (Farm lCurrentFarm in lFarmList)
                {
                    lSomeData      = lSomeData + "Farm: " + lCurrentFarm.Name + "-";
                    lFarmViewModel = new FarmViewModel(lCurrentFarm);

                    lIrrigationUnitList = lIrrigationUnitConfiguration.GetIrrigationUnitListBy(lCurrentFarm);

                    lCropIrrigationWeatherList = new List <CropIrrigationWeather>();
                    lDailyRecordList           = new List <DailyRecord>();

                    foreach (var lIrrigationUnit in lIrrigationUnitList)
                    {
                        lCropIrrigationWeatherList = lIrrigationUnitConfiguration.GetCropIrrigationWeatherListIncludeCropMainWeatherStationRainListIrrigationListBy(lIrrigationUnit, lDateOfReference);

                        lFirstPivotName = "";
                        lETcList        = new List <Double>();
                        foreach (CropIrrigationWeather lCropIrrigationWeather in lCropIrrigationWeatherList)
                        {
                            lSomeData = lSomeData + "CropIrrigationWeather: " + lCropIrrigationWeather.CropIrrigationWeatherName + "-";

                            lDailyRecordList = lCropIrrigationWeatherConfiguration.GetDailyRecordListIncludeDailyRecordListBy(lIrrigationUnit, lDateOfReference, lCropIrrigationWeather.Crop);

                            lRainList       = lCropIrrigationWeather.RainList;
                            lIrrigationList = lCropIrrigationWeather.IrrigationList;
                            lSowingDate     = lCropIrrigationWeather.SowingDate.Day.ToString()
                                              + "/" + lCropIrrigationWeather.SowingDate.Month.ToString();
                            //Grid of irrigation data
                            lGridIrrigationUnitDetailRow = new List <GridPivotDetailHome>();

                            lCropCoefficient         = String.Empty;
                            lPhenologicalStageToday  = String.Empty;
                            lHydricBalancePercentage = 0;

                            for (int i = -InitialTables.MIN_DAY_SHOW_IN_GRID_BEFORE_TODAY; i <= InitialTables.MAX_DAY_SHOW_IN_GRID_AFTER_TODAY; i++)
                            {
                                //Day i
                                lGridIrrigationUnitRow = AddGridIrrigationUnit(lDateOfReference, lDateOfReference.AddDays(i), lIrrigationList, lRainList, lDailyRecordList);
                                lGridIrrigationUnitDetailRow.Add(lGridIrrigationUnitRow);
                                if (i == 0) //TODAY
                                {
                                    //Obtain All data for today from DailyRecord
                                    lPhenologicalStageToday = lGridIrrigationUnitRow.Phenology;
                                    lDailyRecord            = lGridIrrigationUnitRow.DailyRecord;
                                    if (lDailyRecord != null)
                                    {
                                        lCropCoefficient         = lDailyRecord.CropCoefficient.ToString();
                                        lPhenologicalStageToday  = lDailyRecord.PhenologicalStage.Stage.ShortName;
                                        lHydricBalancePercentage = lDailyRecord.PercentageOfHydricBalance;
                                    }
                                }
                                if (lGridIrrigationUnitRow.DailyRecord == null)
                                {
                                    if (lCropIrrigationWeather.MainWeatherStationId > 0)
                                    {
                                        lETcItem = lIrrigationAdvisorContext.WeatherDatas
                                                   .Where(wd => wd.Date == lGridIrrigationUnitRow.DateOfData.Date &&
                                                          wd.WeatherStationId == lCropIrrigationWeather.MainWeatherStationId)
                                                   .Select(wd => wd.Evapotranspiration).FirstOrDefault();
                                    }
                                    else
                                    {
                                        lETcItem = lIrrigationAdvisorContext.WeatherDatas
                                                   .Where(wd => wd.Date == lGridIrrigationUnitRow.DateOfData.Date &&
                                                          wd.WeatherStationId == lCropIrrigationWeather.AlternativeWeatherStationId)
                                                   .Select(wd => wd.Evapotranspiration).FirstOrDefault();
                                    }
                                }
                                else
                                {
                                    lETcItem = Math.Round(lGridIrrigationUnitRow.DailyRecord.EvapotranspirationCrop.Output / lGridIrrigationUnitRow.DailyRecord.CropCoefficient, 2);
                                }
                                lETcList.Add(Math.Round(lETcItem, 2));
                            }
                            if (String.IsNullOrEmpty(lFirstPivotName))
                            {
                                lFirstPivotName = lCropIrrigationWeather.IrrigationUnit.ShortName;
                            }
                            else if (lFirstPivotName == lCropIrrigationWeather.IrrigationUnit.ShortName)
                            {
                                lFirstPivotName = "";
                            }

                            lHomeViewModel = ManageSession.GetHomeViewModel();

                            //Add all the days for the IrrigationUnit
                            lGridIrrigationUnit = new GridPivotHome(lCurrentFarm.Name + " | " + lFirstPivotName,
                                                                    lCropIrrigationWeather.Crop.ShortName,
                                                                    lSowingDate,
                                                                    lPhenologicalStageToday,
                                                                    lHydricBalancePercentage.ToString() + " %",
                                                                    lCropCoefficient,
                                                                    lHomeViewModel.IsUserAdministrator,
                                                                    lETcList,
                                                                    lGridIrrigationUnitDetailRow,
                                                                    lCropIrrigationWeather.CropIrrigationWeatherId);

                            lGridIrrigationUnitList.Add(lGridIrrigationUnit);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.LogError(ex, "Exception in HomeController.GetGridPivotHome \n {0} ", lSomeData);
                throw ex;
            }

            return(lGridIrrigationUnitList);
        }
Exemple #3
0
        /// <summary>
        /// Return Grid Irrigation Unit for Home Titles
        /// </summary>
        /// <returns></returns>
        public List <GridPivotHome> GetGridPivotHomeTitles()
        {
            #region Local Variables
            List <GridPivotHome>       lGridIrrigationUnitList = new List <GridPivotHome>();
            GridPivotHome              lGridIrrigationUnit;
            List <GridPivotDetailHome> lGridIrrigationUnitDetailRow;
            GridPivotDetailHome        lGridIrrigationUnitRow;
            DateTime    lDateOfReference;
            User        lLoggedUser;
            List <Farm> lFarmList;

            #endregion

            #region Configuration Variables
            UserConfiguration uc;
            FarmConfiguration fc;
            #endregion

            try
            {
                #region Configuration - Instance
                uc = new UserConfiguration();
                fc = new FarmConfiguration();
                #endregion

                lDateOfReference = ManageSession.GetNavigationDate();

                //Obtain logged user
                lLoggedUser = uc.GetUserByName(ManageSession.GetUserName());

                //Get list of Farms from User
                lFarmList = fc.GetFarmListIncludedIrrigationUnitListCityBy(lLoggedUser);

                //Grid of irrigation data
                lGridIrrigationUnitDetailRow = new List <GridPivotDetailHome>();

                for (int i = -InitialTables.MIN_DAY_SHOW_IN_GRID_BEFORE_TODAY; i <= InitialTables.MAX_DAY_SHOW_IN_GRID_AFTER_TODAY; i++)
                {
                    //Day i
                    lGridIrrigationUnitRow = AddGridIrrigationUnitDays(lDateOfReference, lDateOfReference.AddDays(i));
                    lGridIrrigationUnitDetailRow.Add(lGridIrrigationUnitRow);
                }

                var homeViewModel = ManageSession.GetHomeViewModel();
                //Add all the days for the IrrigationUnit
                lGridIrrigationUnit = new GridPivotHome("Nombre",
                                                        "Cultivo",
                                                        "Siembra",
                                                        "Fen.",
                                                        "Balance H.",
                                                        "KC",
                                                        homeViewModel.IsUserAdministrator,
                                                        new List <double>(),
                                                        lGridIrrigationUnitDetailRow,
                                                        0);

                lGridIrrigationUnitList.Add(lGridIrrigationUnit);
            }
            catch (Exception ex)
            {
                Utils.LogError(ex, "Exception in HomeController.GetGridPivotHomeTitles ");
                throw ex;
            }

            return(lGridIrrigationUnitList);
        }