public WeatherDataResponse GetWeatherData(WeatherDataRequest weatherDatarequest, bool IsAgrinfo = false, int stationId = 0) { try { string str = ""; switch (weatherDatarequest.temporalAggregation.ToString().ToLower()) { case "eighthourly": str = "8hourly"; break; case "twelvehourly": str = "12hourly"; break; default: str = weatherDatarequest.temporalAggregation.ToString(); break; } Database dbGrows = new SqlDatabase(ConfigurationManager.ConnectionStrings["P_Grows"].ToString()); DbCommand dbCommand = dbGrows.GetStoredProcCommand("Agriweb_Get_WeatherData"); dbCommand.CommandTimeout = 120; dbGrows.AddInParameter(dbCommand, "latitude", DbType.Decimal, weatherDatarequest.FeatureRequest.Latitude); dbGrows.AddInParameter(dbCommand, "longitude", DbType.Decimal, weatherDatarequest.FeatureRequest.Longitude); dbGrows.AddInParameter(dbCommand, "altitude", DbType.Int32, weatherDatarequest.FeatureRequest.Altitude); if (weatherDatarequest.FeatureRequest.MaxDistanceDiff == 0d) dbGrows.AddInParameter(dbCommand, "maxDistanceDiff", DbType.Int32, DBNull.Value); else dbGrows.AddInParameter(dbCommand, "maxDistanceDiff", DbType.Int32, weatherDatarequest.FeatureRequest.MaxDistanceDiff); if (weatherDatarequest.FeatureRequest.MaxAltitudeDiff == 0d) dbGrows.AddInParameter(dbCommand, "maxAltitudeDiff", DbType.String, DBNull.Value); else dbGrows.AddInParameter(dbCommand, "maxAltitudeDiff", DbType.String, weatherDatarequest.FeatureRequest.MaxAltitudeDiff); dbGrows.AddInParameter(dbCommand, "dataSource", DbType.String, weatherDatarequest.DataSource); dbGrows.AddInParameter(dbCommand, "gapFillSource", DbType.Boolean, weatherDatarequest.GapFillSource); dbGrows.AddInParameter(dbCommand, "temporalAggregation", DbType.String, str); dbGrows.AddInParameter(dbCommand, "startDate", DbType.DateTime, weatherDatarequest.StartDate); dbGrows.AddInParameter(dbCommand, "endDate", DbType.DateTime, weatherDatarequest.EndDate); for (int i = 0; i < weatherDatarequest.Series.Count; i++) { dbGrows.AddInParameter(dbCommand, "series" + (i + 1), DbType.String, weatherDatarequest.Series[i].SeriesName); } if (IsAgrinfo && stationId != 0) dbGrows.AddInParameter(dbCommand, "dataPointID", DbType.Int32, stationId); DataSet dsData = new DataSet(); dsData = dbGrows.ExecuteDataSet(dbCommand); /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/ FeatureResponse featureResponse = null; WeatherDataResponse weatherDataResponse = null; if (IsAgrinfo && stationId != 0) { featureResponse = new FeatureResponse(stationId, weatherDatarequest.FeatureRequest.Latitude, weatherDatarequest.FeatureRequest.Longitude, 0, 0, 0); weatherDataResponse = new WeatherDataResponse(featureResponse, weatherDatarequest.Series, dsData.Tables[0]); } else { featureResponse = new FeatureResponse((int)dsData.Tables[0].Rows[0]["dataPointID"], Convert.ToDouble(dsData.Tables[0].Rows[0]["latitude"]), Convert.ToDouble(dsData.Tables[0].Rows[0]["longitude"]), Convert.ToDouble(dsData.Tables[0].Rows[0]["altitude"]), Convert.ToDouble(dsData.Tables[0].Rows[0]["distance"]), Convert.ToDouble(dsData.Tables[0].Rows[0]["bearingDegrees"])); weatherDataResponse = new WeatherDataResponse(featureResponse, weatherDatarequest.Series, dsData.Tables[1]); } /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/ return weatherDataResponse; } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// Public constructor /// </summary> /// <param name="FeatureResponse">Feature Response</param> /// <param name="Series">Series</param> internal WeatherDataResponse(FeatureResponse featureResponse, List<Serie> series, DataTable weatherData) { this.FeatureResponse = featureResponse; this.Series = series; this.WeatherData = weatherData; }
void setParamsHistory(DataSet config, FeatureResponse featureResponse = null) { objGparams.Height = Int32.Parse(config.Tables[CHART].Rows[0]["height"].ToString()); objGparams.Width = Int32.Parse(config.Tables[CHART].Rows[0]["width"].ToString()); objGparams.WaterMark = cUtil.getApplPath(@"Images\") + config.Tables[CHART].Rows[0]["watermark"].ToString(); int cols = 1; foreach (DataRow dr in config.Tables[ChartSerie].Select("", "panel")) { int rowCount = 0; series = new Series(); string extras = dr["addlInfo"].ToString() != "" ? " (" + dr["addlInfo"].ToString().TrimStart(',') + ")" : ""; if (dr.Table.Columns.Contains("trnsTag")) series.SerieName = cUtil.getTransText(dr["trnsTag"].ToString()) + extras; else series.SerieName = dr["name"].ToString() + extras; series.MarkerType = dr["markerType"].ToString(); series.Position = dr["axisPosition"].ToString(); series.Stacked = Convert.ToBoolean(dr["stacked"]); series.Gallery = dr["gallery"].ToString(); series.Color = dr["color"].ToString(); series.pane = dr.Table.Columns.Contains("panel") ? Int32.Parse(dr["panel"].ToString()) : 1; series.axisLabel = (dr.Table.Columns.Contains("labeltext") && dr["labeltext"].ToString() != "") ? cUtil.getTransText(dr["labeltext"].ToString()) : ""; /* IM01288870 - New Agricast - Missing data - Jerrey - Begin */ //noofvalues = ((TimeSpan)(endDate - startDate)).Days / (valuestep == 24 ? 1 : valuestep); //noofvalues = (valuestep == 30 && noofvalues > 0) ? noofvalues : noofvalues + 1; noofvalues = ((TimeSpan)(endDate.AddDays(1) - startDate)).Days / (valuestep == 24 ? 1 : valuestep); /* IM01288870 - New Agricast - Missing data - Jerrey - End */ double?[] vals = new double?[noofvalues]; DataRow[] dt = null; DateTime from = startDate; DateTime to = endDate; if (dr["year"].ToString() != "") { from = new DateTime(Int32.Parse(dr["year"].ToString()), from.Month, (from.Month == 2 && from.Day > 28) ? 28 : from.Day); int range = (endDate.Year - startDate.Year); to = new DateTime(Int32.Parse(dr["year"].ToString()) + range, to.Month, (to.Month == 2 && to.Day > 28) ? 28 : to.Day); if (range != 0) series.SerieName = series.SerieName + " " + dr["year"].ToString() + "-" + (Int32.Parse(dr["year"].ToString()) + range).ToString(); else series.SerieName = series.SerieName + " " + dr["year"].ToString(); if (to > DateTime.Parse(config.Tables["ChartData"].Select("date=max(date)")[0]["date"].ToString())) { to = DateTime.Parse(config.Tables["ChartData"].Select("date=max(date)")[0]["date"].ToString()); } } dt = config.Tables["ChartData"].Select("date>='" + from + "' and date<='" + to + "'", "date asc"); if (dt != null && dt.Count() != 0) { if (series.MarkerType.ToString().ToLower() == "marker") { ArrayList mks = new ArrayList(); ResultMarker marker = null; dswidth = "1"; int barwidth = int.Parse(dswidth); string color = dr.Table.Columns.Contains("textColor") ? dr["textColor"].ToString() : Color.Black.Name; for (int x = 0; x < dt.Length; x++) { if (dt[x][cols].ToString() != "") { marker = new ResultMarker(DateTime.Parse(dt[x][0].ToString()).ToOADate(), 0, color, dt[x][cols].ToString()); marker.width = barwidth; //marker.label = dt[x][cols].ToString(); mks.Add(marker); } } objGparams.markers = (ResultMarker[])mks.ToArray(marker.GetType()); } else if (series.MarkerType.ToString().ToLower() == "shader") { ResultShade rsh = null; ArrayList shades = new ArrayList(); PaletteMap objPm = new PaletteMap(); objPm = getPalleteColor(dr["pallete"].ToString()); DateTime cdate = startDate; double shadestart = cdate.ToOADate(); double shadestop = cdate.ToOADate(); double preval = 0d; double curval = 0d; for (int i = 0; i <= dt.Length; i++) { string color = Color.Red.Name; if (i == 0) { if (!string.IsNullOrEmpty(dt[i][cols].ToString())) curval = double.Parse(dt[i][cols].ToString()); shadestart = DateTime.Parse(dt[i][0].ToString()).ToOADate(); preval = curval; } if (i < dt.Length && !string.IsNullOrEmpty(dt[i][cols].ToString())) curval = double.Parse(dt[i][cols].ToString()); else curval = 0d; if (preval != curval) { shadestop = DateTime.Parse(dt[i - 1][0].ToString()).ToOADate(); if (dr.Table.Columns.Contains("pallete")) { color = !string.IsNullOrEmpty(preval.ToString()) ? objPm.getColor(preval, "") : Color.Red.Name; } rsh = new ResultShade(shadestart, shadestop, color); shades.Add(rsh); shadestart = 0d; shadestop = 0d; shadestart = DateTime.Parse(dt[i - 1][0].ToString()).ToOADate(); preval = curval; } } if (shades.Count > 0) objGparams.shades = (ResultShade[])shades.ToArray(rsh.GetType()); } else { int i = 0; from = DateTime.Parse(dt[0]["date"].ToString()); /* IM01288870 - New Agricast - Missing data - Jerrey - Begin */ //while (from <= to) while (from <= to.AddDays(1).AddDays(-(valuestep == 24 ? 1 : valuestep))) /* IM01288870 - New Agricast - Missing data - Jerrey - End */ { double j; if (dt.Length > rowCount && dt[rowCount][cols].ToString() != "" && vals.Length > i) { vals[i] = double.TryParse(dt[rowCount][cols].ToString(), out j) ? j : 0; series.hasvalues = true; } else { missingData = true; series.hasGaps = true; } rowCount++; //} from = from.AddDays(valuestep == 24 ? 1 : valuestep); i++; } } } if (series.Position.ToLower() == "primary") { series.MinorY = double.Parse(config.Tables[PrimaryAxis].Rows[0]["minValue"].ToString()); series.MajorY = double.Parse(config.Tables[PrimaryAxis].Rows[0]["maxvalue"].ToString()); series.Scale = config.Tables[PrimaryAxis].Rows[0]["ScaleType"].ToString(); } else { series.MinorY = double.Parse(config.Tables[SecondaryAxis].Rows[0]["minValue"].ToString()); series.MajorY = double.Parse(config.Tables[SecondaryAxis].Rows[0]["maxvalue"].ToString()); series.Scale = config.Tables[SecondaryAxis].Rows[0]["ScaleType"].ToString(); } series.values = vals; objGparams.addSeries(series); cols++; } objGparams.LeftScaleType = config.Tables[PrimaryAxis].Rows[0]["scaleType"].ToString(); objGparams.LeftAxisLabel = cUtil.getTransText(config.Tables[PrimaryAxis].Rows[0]["trnsTag"].ToString()); objGparams.Ymax = double.Parse(config.Tables[PrimaryAxis].Rows[0]["maxValue"].ToString()); objGparams.Ymin = double.Parse(config.Tables[PrimaryAxis].Rows[0]["minValue"].ToString()); objGparams.RightAxisLabel = cUtil.getTransText(config.Tables[SecondaryAxis].Rows[0]["trnsTag"].ToString()); objGparams.RightScaleType = config.Tables[SecondaryAxis].Rows[0]["scaletype"].ToString(); objGparams.Y2max = double.Parse(config.Tables[SecondaryAxis].Rows[0]["maxValue"].ToString()); objGparams.Y2min = double.Parse(config.Tables[SecondaryAxis].Rows[0]["minValue"].ToString()); objGparams.BottomLabels = getLabelsHistory(startDate, selectedEndDate, valuestep); string distText = cUtil.getTransText("ResDistanceFrom"); string stationInfo = dpi.stationName.ToString(); string lattranslate = objSvcPre.getTranslatedText("Lat", culture); string longtranslate = objSvcPre.getTranslatedText("Long", culture); stationInfo = stationInfo.Replace("Lat", lattranslate); stationInfo = stationInfo.Replace("Long", longtranslate); if (featureResponse != null && dpi.stationLatitude != featureResponse.Latitude && dpi.stationLongitude != featureResponse.Longitude) { distText = distText.Replace("{Dist}", featureResponse.Distance.ToString()); distText = distText.Replace("{Dir}", cUtil.getTextDirection(Convert.ToInt32(featureResponse.BearingDegrees))); distText = distText.Replace("{Elevation}", featureResponse.Altitude.ToString()); stationInfo = lattranslate + ":" + featureResponse.Latitude + ";" + longtranslate + ":" + featureResponse.Longitude; } else { distText = distText.Replace("{Dist}", dpi.distance.ToString()); distText = distText.Replace("{Dir}", dpi.directionLetter); distText = distText.Replace("{Elevation}", dpi.altitude.ToString()); } distText = distText.Replace("{CityName}", HttpUtility.HtmlDecode((LocationInfo.getLocationInfoObj).placeName)); distText = distText.Replace("<strong>", "").Replace("</strong>", ""); /*IM01166162 - AgriInfo UI Issues - BEGIN*/ //objGparams.Title = cUtil.getTransText("weather") + " " + cUtil.getTransText("for") + " " + dpi.stationName.ToString() +" "+ distText + "\n" + // cUtil.getTransText("from")+ " " + startDate.ToString("dd-MMM-yyyy", new CultureInfo(culture)) + " " + // cUtil.getTransText("to") + " " + selectedEndDate.ToString("dd-MMM-yyyy", new CultureInfo(culture)) + " " + cUtil.getTransText("aggregation")+" :"+ cUtil.getTransText(agriInfo["aggregation"]); /*IM01848085 - New Agricast - Agriinfo - "location" name not translatable - BEGIN*/ //objGparams.Title = cUtil.getTransText("weather") + " " + cUtil.getTransText("for") + " " + dpi.stationName.ToString() + "#" + distText + "#" /* IM01848087 - New Agricast - AgriInfo chart title - changing the structure of the lines - Start */ if (culture == "hu-HU") { //objGparams.Title = cUtil.getTransText("weather") + " " + cUtil.getTransText("for") + " " + stationInfo + "#" + distText + "#" // /*IM01848085 - New Agricast - Agriinfo - "location" name not translatable - END*/ // /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - Start */ // + FormatDateTime(startDate, culture) + " " + cUtil.getTransText("from") //startDate.ToString("dd-MMM-yyyy", new CultureInfo(culture)) // + " " + FormatDateTime(selectedEndDate, culture) + " " + cUtil.getTransText("to") //selectedEndDate.ToString("dd-MMM-yyyy", new CultureInfo(culture)) // /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - End */ // + " " + cUtil.getTransText("Aggregation") + ": " + cUtil.getTransText(agriInfo["aggregation"]); objGparams.Title = cUtil.getTransText("weather") + " " + cUtil.getTransText("for") + " " + stationInfo + "#" + distText; } else { //objGparams.Title = cUtil.getTransText("weather") + " " + cUtil.getTransText("for") + " " + stationInfo + "#" + distText + "#" // /*IM01848085 - New Agricast - Agriinfo - "location" name not translatable - END*/ // /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - Start */ // + cUtil.getTransText("from") + " " + FormatDateTime(startDate, culture) //startDate.ToString("dd-MMM-yyyy", new CultureInfo(culture)) // + " " + cUtil.getTransText("to") + " " + FormatDateTime(selectedEndDate, culture) //selectedEndDate.ToString("dd-MMM-yyyy", new CultureInfo(culture)) // /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - End */ // + " " + cUtil.getTransText("Aggregation") + ": " + cUtil.getTransText(agriInfo["aggregation"]); objGparams.Title = cUtil.getTransText("weather") + " " + cUtil.getTransText("for") + " " + stationInfo + "#" + distText; } /* IM01848087 - New Agricast - AgriInfo chart title - changing the structure of the lines - End */ /*IM01166162 - AgriInfo UI Issues - END*/ if (missingData) objGparams.warning = cUtil.getTransText("wm_warning") + ":" + cUtil.getTransText("This chart has been plotted with missing data."); // objGparams.FooterText += cUtil.getTransText("chartcopyright"); }