public ActionResult Index() { try { DailyRecordConfiguration drc = new DailyRecordConfiguration(); List <DailyRecord> lDailyRecordList = new List <DailyRecord>(); ciwId = GetCropIrrigationWeatherIdFromURL(); lDailyRecordList = drc.GetDailyRecordsListDataUntilDateBy(ciwId, Utils.GetDateOfReference().Value); //fc.GetFarmBy (lDailyRecordList.) foreach (DailyRecord item in lDailyRecordList) { vm.CropIrrigationWeatherId = ciwId; vm.Title = item.CropIrrigationWeather.ToString(); } return(View("~/Views/Reports/ReportIrrigationUnit/ReportIrrigationUnit.cshtml", vm)); } catch (Exception ex) { Utils.LogError(ex, "Exception in ReportIrrigationUnit.Index \n {0} "); return(null); } }
/// <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); }
public ActionResult Index() { try { #region userdata User lLoggedUser; UserConfiguration uc; LoginViewModel lLoginViewModel; uc = new UserConfiguration(); LoginViewModel localLgM = ManageSession.GetLoginViewModel(); if (localLgM == null) { return(RedirectToAction("Index")); } else { lLoginViewModel = ManageSession.GetLoginViewModel(); } lLoggedUser = uc.GetUserByName(lLoginViewModel.UserName); vm.IsUserAdministrator = (lLoggedUser.RoleId == (int)Utils.UserRoles.Administrator); #endregion DailyRecordConfiguration drc = new DailyRecordConfiguration(); CropIrrigationWeatherConfiguration ciwc = new CropIrrigationWeatherConfiguration(); List <DailyRecord> lDailyRecordList = new List <DailyRecord>(); double lHydricBalancePercentage = 0; double lSumTotalEffectiveRain = 0; double lSumTotalEffectiveInputWater = 0; double lSumTotalEvapotranspirationCrop = 0; string lCropIrrigationWeatherTitle = ""; ciwId = GetCropIrrigationWeatherIdFromURL(); lDailyRecordList = drc.GetDailyRecordsListDataUntilDateBy(ciwId, Utils.GetDateOfReference().Value); #region get ciw //List<CropIrrigationWeather> lCropIrrigationWeatherList = new List<CropIrrigationWeather>(); //List<long> lListciw = new List<long>(); //lListciw.Add(ciwId); //lCropIrrigationWeatherList = ciwc.GetCropIrrigationWeatherByIds(lListciw, Utils.GetDateOfReference().Value); //foreach (CropIrrigationWeather lCropIrrigationWeather in lCropIrrigationWeatherList) //{ // lHydricBalancePercentage = lCropIrrigationWeather.GetPercentageOfHydricBalance(); //} #endregion foreach (DailyRecord item in lDailyRecordList) { if (item.Rain != null) { lSumTotalEffectiveRain = lSumTotalEffectiveRain + item.Rain.Input + item.Rain.ExtraInput; } ; if (item.Irrigation != null) { lSumTotalEffectiveInputWater = lSumTotalEffectiveInputWater + item.Irrigation.Input + item.Irrigation.ExtraInput; } lSumTotalEvapotranspirationCrop = item.TotalEvapotranspirationCrop; lHydricBalancePercentage = item.PercentageOfHydricBalance; lCropIrrigationWeatherTitle = item.CropIrrigationWeather.ToString(); } vm.TotalEffectiveRain = lSumTotalEffectiveRain; vm.TotalEffectiveInputWater = lSumTotalEffectiveInputWater; vm.TotalEvapotranspirationCrop = lSumTotalEvapotranspirationCrop; vm.Title = lCropIrrigationWeatherTitle; vm.CropIrrigationWeatherId = ciwId; vm.HydricBalancePercentage = lHydricBalancePercentage; return(View("~/Views/Reports/ReportPivotState/ReportPivotState.cshtml", vm)); } catch (Exception ex) { Utils.LogError(ex, "Exception in ReportPivotState.Index \n {0} "); return(null); } }
/// <summary> /// Return Grid Datail from dailyrecord days /// </summary> /// <returns></returns> public List <GridReportPivotState> GetGridDailyRecordIrrigationResume() { #region Local Variables List <GridReportPivotState> lGridIrrigationUnitList = new List <GridReportPivotState>(); List <GridReportPivotState> lGridDailyRecordIrrigationResumeList = new List <GridReportPivotState>(); GridReportPivotState lGridDailyRecordIrrigationResume = null; string lEffectiveRain; string lEffectiveInputWater; double lEffectiveRainDouble; double lEffectiveInputWaterDouble; List <DailyRecord> lDailyRecordList; DailyRecordConfiguration drc; #endregion try { drc = new DailyRecordConfiguration(); lDailyRecordList = drc.GetDailyRecordsListDataUntilDateBy(ciwId, Utils.GetDateOfReference().Value); 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); }
public ActionResult GetChart() { DailyRecordConfiguration drc = new DailyRecordConfiguration(); List <DailyRecord> lDailyRecordList = new List <DailyRecord>(); double lRain; double lIrrigation; lDailyRecordList = drc.GetDailyRecordsListDataUntilDateBy(ciwId, Utils.GetDateOfReference().Value); try { ArrayList yArrayRain = new ArrayList(); ArrayList yArrayIrrigation = new ArrayList(); ArrayList yArrayETC = new ArrayList(); ArrayList xDaysAfterSowing = new ArrayList(); foreach (DailyRecord item in lDailyRecordList) { if (item.DaysAfterSowing > 0) { lRain = 0; lIrrigation = 0; if (item.Rain != null) { lRain = item.Rain.Input + item.Rain.ExtraInput; } if (item.Irrigation != null) { lIrrigation = item.Irrigation.ExtraInput + item.Irrigation.Input; } yArrayIrrigation.Add(lIrrigation); yArrayRain.Add(lRain); yArrayETC.Add(Math.Round(item.TotalEvapotranspirationCrop, 1)); xDaysAfterSowing.Add(item.DaysAfterSowing); } } System.Web.UI.DataVisualization.Charting.Chart chart = new System.Web.UI.DataVisualization.Charting.Chart(); chart.Width = 1000; chart.Height = 450; chart.BackColor = Color.FromArgb(210, 240, 204); chart.BorderlineDashStyle = ChartDashStyle.Solid; chart.BackSecondaryColor = Color.White; chart.BackGradientStyle = GradientStyle.TopBottom; chart.BorderlineWidth = 1; chart.Palette = ChartColorPalette.BrightPastel; chart.BorderlineColor = Color.FromArgb(26, 59, 105); chart.RenderType = RenderType.BinaryStreaming; chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss; chart.AntiAliasing = AntiAliasingStyles.All; chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal; chart.ChartAreas.Add(CreateChartArea()); chart.Series.Add(CreateSeries(yArrayETC, xDaysAfterSowing, "ETc acumulada", SeriesChartType.Line, Color.FromArgb(246, 134, 36), AxisType.Primary)); chart.Series.Add(CreateSeries(yArrayRain, xDaysAfterSowing, "Lluvia", SeriesChartType.Column, Color.FromArgb(74, 164, 209), AxisType.Secondary)); chart.Series.Add(CreateSeries(yArrayIrrigation, xDaysAfterSowing, "Riego", SeriesChartType.Column, Color.FromArgb(97, 209, 74), AxisType.Secondary)); System.Web.UI.DataVisualization.Charting.Title title = chart.Titles.Add("Evolución de la ETc acumulada y distribucion de las lluvias y riegos, expresadas en mm de lámina bruta"); title.Font = new Font("Verdana,Arial,Helvetica,sans-serif", 10, FontStyle.Regular); chart.Legends.Clear(); chart.Legends.Add("Default"); chart.Legends[0].Docking = Docking.Bottom; chart.Legends[0].TableStyle = LegendTableStyle.Wide; chart.Legends[0].Alignment = StringAlignment.Center; MemoryStream ms = new MemoryStream(); chart.SaveImage(ms); return(File(ms.GetBuffer(), @"image/png")); } catch (Exception ex) { Utils.LogError(ex, "Exception in ReportPivotState.GetChart \n {0} "); return(null); } }
/// <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); }
/// <summary> /// Return Grid Datail from dailyrecord days /// </summary> /// <returns></returns> public List <GridReportIrrigationUnit> GetGridDailyRecordIrrigationResume() { #region Local Variables List <GridReportIrrigationUnit> lGridIrrigationUnitList = new List <GridReportIrrigationUnit>(); List <GridReportIrrigationUnit> lGridDailyRecordIrrigationResumeList = new List <GridReportIrrigationUnit>(); GridReportIrrigationUnit lGridReportIrrigationUnit = null; string lEffectiveRain; string lEffectiveInputWater; double lEffectiveRainDouble; double lEffectiveInputWaterDouble; double lTemperature; double lStationTemperatureInDR; List <DailyRecord> lDailyRecordList; bool lIsUserAdministrator; #endregion try { #region Configuration Variables DailyRecordConfiguration drc; UserConfiguration uc; FarmConfiguration fc; #endregion #region userdata User lLoggedUser; LoginViewModel lLoginViewModel; uc = new UserConfiguration(); LoginViewModel localLgM = ManageSession.GetLoginViewModel(); lLoginViewModel = ManageSession.GetLoginViewModel(); lLoggedUser = uc.GetUserByName(lLoginViewModel.UserName); lIsUserAdministrator = (lLoggedUser.RoleId == (int)Utils.UserRoles.Administrator); #endregion #region Configuration - Instance uc = new UserConfiguration(); drc = new DailyRecordConfiguration(); fc = new FarmConfiguration(); #endregion lCurrentFarm = fc.GetFarmBy(ciwId); lDailyRecordList = drc.GetDailyRecordsListWithTemperatureDataUntilDateBy(ciwId, Utils.GetDateOfReference().Value); foreach (var lDailyRecordItem in lDailyRecordList) { lEffectiveRain = ""; lEffectiveInputWater = ""; lEffectiveRainDouble = 0; lEffectiveInputWaterDouble = 0; if (lDailyRecordItem.Rain != null) { lEffectiveRainDouble = lDailyRecordItem.Rain.ExtraInput + lDailyRecordItem.Rain.Input; } if (lDailyRecordItem.Irrigation != null) { lEffectiveInputWaterDouble = lDailyRecordItem.Irrigation.ExtraInput + lDailyRecordItem.Irrigation.Input; } if (lEffectiveRainDouble + lEffectiveInputWaterDouble > 0) // not input { if (lEffectiveRainDouble != 0) { lEffectiveRain = lEffectiveRainDouble.ToString(); } if (lEffectiveInputWaterDouble != 0) { lEffectiveInputWater = lEffectiveInputWaterDouble.ToString(); } #region temperature to show if (lDailyRecordItem.MainWeatherDataId > 0) // Get temperature from MainWeatherDataId { lStationTemperatureInDR = lDailyRecordItem.MainWeatherDataId; } else { lStationTemperatureInDR = lDailyRecordItem.AlternativeWeatherDataId; } lTemperature = db.WeatherDatas .Where(wd => wd.WeatherDataId == lStationTemperatureInDR) .Select(wd => wd.Temperature).FirstOrDefault(); #endregion lGridReportIrrigationUnit = new GridReportIrrigationUnit(lDailyRecordItem.DaysAfterSowing.ToString(), lDailyRecordItem.DailyRecordDateTime.ToShortDateString(), lEffectiveRain, lEffectiveInputWater, lTemperature.ToString(), lDailyRecordItem.TotalEvapotranspirationCrop.ToString(), lDailyRecordItem.PercentageOfHydricBalance.ToString(), lDailyRecordItem.PhenologicalStage.Stage.ShortName, lDailyRecordItem.CropCoefficient.ToString(), lCurrentFarm.IrrigationUnitReportShowEvapotranspiration, lCurrentFarm.IrrigationUnitReportShowTemperature, lCurrentFarm.IrrigationUnitReportShowAvailableWater, lIsUserAdministrator); lGridDailyRecordIrrigationResumeList.Add(lGridReportIrrigationUnit); } } } catch (Exception ex) { Utils.LogError(ex, "Exception in ReportIrrigationUnit.GetGridDailyRecordIrrigationResume \n {0} "); return(null); } return(lGridDailyRecordIrrigationResumeList); }