Exemplo n.º 1
0
        /// <summary>
        /// Return Grid Datail from dailyrecord days
        /// </summary>
        /// <returns></returns>
        public List <GridReportPivotState> GetGridDailyRecordIrrigationResume()
        {
            #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 <IrrigationUnit>        lIrrigationUnitList;
            List <CropIrrigationWeather> lCropIrrigationWeatherList;
            List <Farm>                 lFarmList;
            FarmConfiguration           lFarmConfiguration;
            UserConfiguration           lUserConfiguration;
            IrrigationUnitConfiguration lIrrigationUnitConfiguration;
            User lLoggedUser;
            #endregion

            #region Configuration - Instance
            lUserConfiguration = new UserConfiguration();
            lFarmConfiguration = new FarmConfiguration();

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


                lLoggedUser = lUserConfiguration.GetUserByName(ManageSession.GetUserName());
                lFarmList   = lFarmConfiguration.GetFarmWithActiveCropIrrigationWeathersListBy(lLoggedUser);


                //Create IrrigationQuantity Units List
                lIrrigationUnitList = new List <IrrigationUnit>();
                foreach (Farm lCurrentFarm in lFarmList)
                {
                    lIrrigationUnitList = lIrrigationUnitConfiguration.GetIrrigationUnitListBy(lCurrentFarm);

                    foreach (var lIrrigationUnit in lIrrigationUnitList)
                    {
                        lCropIrrigationWeatherList = lIrrigationUnitConfiguration.GetCropIrrigationWeatherListIncludeCropMainWeatherStationRainListIrrigationListBy(lIrrigationUnit, 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(lCurrentFarm.Name + " | " + lCropIrrigationWeather.IrrigationUnit.ShortName, 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);
        }
Exemplo n.º 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);
        }
        /// <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);
        }