protected WebLocationSearch() { objLocPresenter = new locSearchPresenter(this); objNearByPre = new nearbyPointPresenter(this); objSvcInfo = ServiceInfo.ServiceConfig; objDataPointInfo = DataPointInfo.getDataPointObject; objLocInfo = LocationInfo.getLocationInfoObj; }
void DeserializeAgriInfoCookieString(string cookiestr) { string[] values = cookiestr.Split('#'); if (values[8] == root)// Add Pub name for the data format issue when change the pub 20140615 { //Add for Date Issue - 20140612 - Start if (valid) { string format = newinfo.ShortDatePattern.ToString(); DateTime Y; if (!string.IsNullOrEmpty(values[0]) && DateTime.TryParse(values[0], out Y)) { //DateTime.TryParseExact(values[0], "MM/DD/YYYY", null, DateTimeStyles.None, out startDateFromCookie); values[0] = Convert.ToDateTime(values[0]).ToString(format).ToString(); } if (!string.IsNullOrEmpty(values[5]) && DateTime.TryParse(values[5], out Y)) { // DateTime.TryParseExact(values[0], "MM/DD/YYYY", null, DateTimeStyles.None, out endDateFromCookie); values[5] = Convert.ToDateTime(values[5]).ToString(format).ToString(); } } //Add for Date Issue - 20140612 - End int i = 0; { try { DateTime date = StartDate; DateTime plntDate = DateTime.Today; bool valid2 = valid;//valid for StatDate and EndDate should be same //IM01838379:Cookie Issue - start txtstartDate.Value = ShortMonthDayPattern(valid ? null : oldinfo, newinfo, values[0]); //if (!string.IsNullOrEmpty(values[5])) if (!string.IsNullOrEmpty(values[5])) { txtEndDate.Value = ShortMonthDayPattern(valid2 ? null : oldinfo, newinfo, values[5]); } else { txtEndDate.Value = ""; } //txtstartDate.Value = ShortMonthDayPattern(valid ? null : oldinfo, newinfo, values[0]); //txtEndDate.Value = ShortMonthDayPattern(valid ? null : oldinfo, newinfo, values[5]); //txtstartDate.Value = ShortMonthDayPattern(oldinfo, newinfo, values[0]); //txtEndDate.Value = ShortMonthDayPattern(oldinfo, newinfo, values[5]); //IM01838379:Cookie Issue - end //start of changes - 2013/03/12 //txtstartDate.Value = DateTime.TryParse(ShortMonthDayPattern(null, newinfo, values[0]), out date) ? date.ToShortDateString() : StartDate.ToShortDateString(); //txtstartDate.Value = ShortMonthDayPattern(null, newinfo, values[0]); //end of changes - 2013/03/12 /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - Start */ //txtEndDate.Value = ShortMonthDayPattern(null, newinfo, values[5]); /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - End */ hdnSeries.Value = values[1]; ddlAggregate.SelectedIndex = Int32.TryParse(values[2], out i) ? (i >= 0) ? i : 0 : 0; ddlDuration.SelectedIndex = Int32.TryParse(values[3], out i) ? (i >= 0) ? i : 0 : 0; if (HttpContext.Current != null) { objLocInfo = LocationInfo.getLocationInfoObj; } else { objLocInfo = new LocationInfo(); } string[] lat = values[7].Split('&'); if (lat[0] == objLocInfo.latitude.ToString() && lat[1] == objLocInfo.longitude.ToString()) txtAltitude.Value = values[6]; //if (txtPlantingDate != null && values[4] != string.Empty) // /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - Start */ // //txtPlantingDate.Value = DateTime.TryParse(ShortMonthDayPattern(null, newinfo, values[4]), out plntDate) ? plntDate.ToShortDateString() : ""; // txtPlantingDate.Value = DateTime.TryParse(ShortMonthDayPattern(null, newinfo, Server.UrlDecode(values[4])), out plntDate) ? plntDate.ToShortDateString() : ""; ///* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - Start */ } catch (Exception ex) { HttpContext.Current.Session["ErrorMessage"] = TranslatedText(Constants.GENERIC_ERRORONPAGE) + ":" + ex.Message.ToString(); throw ex; } } } }
protected void Page_Load(object sender, EventArgs e) { try { if (Session == null || Session["serviceInfo"] == null) { objSvcInfo = new ServiceInfo(); } else { objSvcInfo = (ServiceInfo)Session["serviceInfo"]; } objAgriPresenter = new AgriInfoPresenter(this, Name); if (HttpContext.Current != null) { objLocInfo = LocationInfo.getLocationInfoObj; } else { objLocInfo = new LocationInfo(); } if (Session["CurrentCulture"] != null) { NewCulture = new CultureInfo(Session["CurrentCulture"].ToString()); } else { /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - Start */ if (string.IsNullOrWhiteSpace(objSvcInfo.Culture)) NewCulture = new CultureInfo("en-GB"); else NewCulture = new CultureInfo(objSvcInfo.Culture); // NewCulture = new CultureInfo("en-GB"); /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - End */ } if (Session["PreviousCulture"] != null) { OldCulture = new CultureInfo(Session["PreviousCulture"].ToString()); } else { OldCulture = new CultureInfo("en-GB"); } //Set the datetime formats //Add for when change Pub, the data formate will not correct - 20140615 - Start url = HttpContext.Current.Request.Url.ToString().ToLower(); url = url.Remove(url.LastIndexOf(".aspx")); root = url.Remove(url.LastIndexOf('/')).Substring(url.IndexOf("pub/") + 4); HttpCookie agriInfoCookiePub = Request.Cookies["AgriInfo_HistoryData_ECMWF"]; if (agriInfoCookiePub != null && Server.UrlDecode(agriInfoCookiePub.Value).ToString() != "") { string[] cookValues = Server.UrlDecode(agriInfoCookiePub.Value).Split('#'); if (cookValues[8] != root) { if (string.IsNullOrWhiteSpace(objSvcInfo.Culture)) { NewCulture = new CultureInfo("en-GB"); } else { NewCulture = new CultureInfo(objSvcInfo.Culture); } OldCulture = new CultureInfo("en-GB"); Session["PreviousCulture"] = null; Session["CurrentCulture"] = null; } } //Add for when change Pub, the data formate will not correct - 20140615 - END oldinfo = OldCulture.DateTimeFormat; newinfo = NewCulture.DateTimeFormat; if (!ExcelFlag) { //if (!IsPostBack) //{ // PopulateAltitude(); //} readDate(); setControlText(); PopulateDropDowns(); loadSeries(); HttpCookie agriInfoCookie = Request.Cookies["AgriInfo_" + objSvcInfo.Module]; if (agriInfoCookie != null && agriInfoCookie.Value.ToString() != "") { DeserializeAgriInfoCookieString(Server.UrlDecode(agriInfoCookie.Value)); } } /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/ if (objSvcInfo.Moss == "true" && objSvcInfo.Module.ToLower() == "watermodel") { if (Session["IAgriInfo"] != null) { objAgriInfo = (Dictionary<string, string>)Session["IAgriInfo"]; } hdnSeries.Value = "gdd_cb_WaterModel"; hdnSeries_ValueChanged("gdd_cb_WaterModel"); hApply_Click(sender, e); } /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/ } catch (Exception ex) { AgriCastException currEx = new AgriCastException(objSvcPre.GetServiceDetails(), ex); AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error); HttpContext.Current.Session["ErrorMessage"] = TranslatedText(Constants.GENERIC_ERRORONPAGE) + ":" + ex.Message.ToString(); } }
string SerializeAgriInfoCookieString() { string cookieValue; try { string date = ShortMonthDayPattern(oldinfo, newinfo, txtstartDate.Value); string plntDate = string.Empty; if (txtPlantingDate != null && txtPlantingDate.Value != string.Empty) plntDate = ShortMonthDayPattern(oldinfo, newinfo, txtPlantingDate.Value); /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - Start */ string endDate = string.Empty; if (txtEndDate != null && txtEndDate.Value != string.Empty) endDate = ShortMonthDayPattern(oldinfo, newinfo, txtEndDate.Value); /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - End */ if (HttpContext.Current != null) { objLocInfo = LocationInfo.getLocationInfoObj; } else { objLocInfo = new LocationInfo(); } cookieValue = Server.UrlEncode((valid ? DateTime.ParseExact(date, NewCulture.DateTimeFormat.ShortDatePattern, CultureInfo.InvariantCulture).ToShortDateString() : date).ToString() + "#" + hdnSeries.Value + "#" + ddlAggregate.SelectedIndex + "#" + ddlDuration.SelectedIndex + "#" + (txtPlantingDate != null && txtPlantingDate.Value != string.Empty ? (valid ? DateTime.ParseExact(plntDate, NewCulture.DateTimeFormat.ShortDatePattern, CultureInfo.InvariantCulture).ToShortDateString() : plntDate).ToString() : "") + "#"//); /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - Start */ + (txtEndDate != null && txtEndDate.Value != string.Empty ? (valid ? DateTime.ParseExact(endDate, NewCulture.DateTimeFormat.ShortDatePattern, CultureInfo.InvariantCulture).ToShortDateString() : txtEndDate.Value).ToString() : "") + "#"//); /* IM01289657 - New Agricast - Agriinfo - date formatting - Jerrey - End */ + txtAltitude.Value + "#" + objLocInfo.latitude + "&" + objLocInfo.longitude + "#" + root + "#");// Add Pub name for the data format issue when change the pub 20140615 } catch (Exception ex) { HttpContext.Current.Session["ErrorMessage"] = TranslatedText(Constants.GENERIC_ERRORONPAGE) + ":" + ex.Message.ToString(); throw ex; } return cookieValue; }
void PopulateAltitude() { if (HttpContext.Current != null) { objLocInfo = LocationInfo.getLocationInfoObj; } else { objLocInfo = new LocationInfo(); } //Fill the altitude textbox with value from datapoint object if (objLocInfo != null) { txtAltitude.Value = GetElevation(objLocInfo.latitude, objLocInfo.longitude); } }
/// <summary> /// Constructor /// </summary> public ChartService() { loc = LocationInfo.getLocationInfoObj; dpi = (DataPointInfo)loc.DataPointInfo; }
protected void Page_Load(object sender, EventArgs e) { try { objPreTool = new ToolBarPresenter(this); objSvcInfo = (ServiceInfo)Session["serviceInfo"]; objLocInfo = (LocationInfo)Session["objLocationInfo"]; objSvcPre = new ServicePresenter(); if (!IsPostBack) { //Set the UserName objUserInfo = (UserInfo)Session["objuserinfo"]; if (objUserInfo != null) { /*IM01246266 - New Agricast - can't save a favourite - Begin */ //userName.InnerText = objUserInfo.UserName; if (!string.IsNullOrEmpty(objUserInfo.UserName)) { if (objUserInfo.UserName.IndexOf('^') > -1) { userName.InnerText = objUserInfo.UserName.Substring(objUserInfo.UserName.IndexOf('^') + 1); } } /*IM01246266 - New Agricast - can't save a favourite - End */ } objSvcPre = new ServicePresenter(this); string strLink = ConfigurationManager.AppSettings["link"]; userName.HRef = strLink; //objSvcPre.createServiceSession("Demo"); objPreTool.loadPageSettings(); if (!showFavorites) { imgFav.Visible = false; } else { //getFavorites(); /*IM01246233 :- New Agricast - missing translation tags - Begin */ //add the clientclick event for validation only when Email is enabled Fav_AddToFavorites.Attributes.Add("OnClick", "Javascript:return ValidateFavName(" + "'" + objCommonUtil.getTransText(Constants.FAV_NAME_EMPTY_CHECK) + "'" + ");"); /*IM01246233 :- New Agricast - missing translation tags - End */ } if (!showPrint) imgPrint.Visible = false; if (!showEmail) imgEmail.Visible = false; /*IM01246233 :- New Agricast - missing translation tags - Begin */ else { //add the clientclick event for validation only when Email is enabled EMailPage.Attributes.Add("OnClick", "Javascript:return ValidateEMail(" + "'" + objCommonUtil.getTransText(Constants.EMAIL_ID_EMPTY_CHECK) + "'" + ");"); } /*IM01246233 :- New Agricast - missing translation tags - End */ if (!showExportExcel) btnExcel.Visible = false; if (!showFeedback) imgFB.Visible = false; LoadCulture(); objPreTool.getCultureCode(); changeLabelText(strCulCode); } //Load units if not postback or in case culture has changed. if ((!IsPostBack) || ddlCulture.SelectedValue != objSvcInfo.Culture) LoadUnits(); LoadCustomSettings(); getFavorites(); if (!IsPostBack) { LoadCaptcha(); //set the first value in Dropdown as default unit and add it o session DefaultUnitSettings = dtUnits.Rows[0][0].ToString(); if (objSvcInfo.Unit.Trim() != "") {int count=0; for(int i=0; i< dtUnits.Rows.Count; i++) { if(objSvcInfo.Unit.Trim().ToLower().ToString() == dtUnits.Rows[i][0].ToString().ToLower().Trim()) { ddlUnits.SelectedIndex = ddlUnits.Items.IndexOf(ddlUnits.Items.FindByValue(objSvcInfo.Unit.Trim())); count++; break; } } if (count==0) objSvcInfo.Unit = DefaultUnitSettings; } else objSvcInfo.Unit = DefaultUnitSettings; } setEmailValues(); } catch (Exception ex) { AgriCastException currEx = new AgriCastException(objServicePre.GetServiceDetails(), ex); AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error); HttpContext.Current.Session["ErrorMessage"] = objPreTool.getTranslatedText(Constants.TOOLBAR_LOADFAILURE, strCulCode) + ex.Message.ToString(); return; } }
public LocationInfo DeserializeCookieString(string cookiestr) { string[] values = cookiestr.Split('#'); //int i = 0; HttpSessionState Session = HttpContext.Current.Session; if (HttpContext.Current != null) Session = HttpContext.Current.Session; objDataPointInfo = DataPointInfo.getDataPointObject; objLocInfo = LocationInfo.getLocationInfoObj; if (Session == null || Session["serviceInfo"] == null) { objSvcInfo = new ServiceInfo(); } else { objSvcInfo = (ServiceInfo)Session["serviceInfo"]; } try { int pid=0; double coord=0d; searchLocation = (values[0]); placeID = Int32.TryParse(values[1],out pid)?pid:0; placeName = HttpUtility.UrlDecode(values[2]); longitude = double.TryParse(values[3], out coord) ? coord : 0d; latitude = double.TryParse(values[4],out coord)?coord:0d; CountryCode = (values[5]); if (Enum.IsDefined(typeof(LocationSearchSource), values[6])) Provider = (LocationSearchSource)Enum.Parse(typeof(LocationSearchSource), values[6], true); else Provider = LocationSearchSource.defaultService; AdminName = values[7] ; objDataPointInfo.stationName = HttpUtility.UrlDecode(values[8]); objDataPointInfo.stationLatitude = double.TryParse(values[9],out coord)?coord:0d; objDataPointInfo.stationLongitude = double.TryParse(values[10], out coord) ? coord : 0d; objSvcInfo.Country = (values[11]); objSvcInfo.Culture = (values[12]); objSvcInfo.Module = (values[13]); //objSvcInfo.ServiceName = (values[14]); objSvcInfo.Unit = (values[14]); //objDataPointInfo.CheckStationValidity(); } catch { return null; } return this; }
//Method to populate the country dropdown. protected void getCountry() { try { objLocPresenter.getCountry(); if (objLocInfo.CountryCode != null && objLocInfo.CountryCode != "") { string strCountryCode = ""; if (dtCon.Select("code = '" + objLocInfo.CountryCode + "'").Length != 0) strCountryCode = dtCon.Select("code = '" + objLocInfo.CountryCode + "'")[0]["code"].ToString(); if (strCountryCode != null && strCountryCode != "") { IsCountryPresent = true; ddlCountry.SelectedValue = strCountryCode; } else { IsCountryPresent = false; Session["CountryNotPresent"] = true; objLocInfo = new LocationInfo(); Session["objLocationInfo"] = objLocInfo; } } } catch (Exception ex) { AgriCastException currEx = new AgriCastException(objSvcPre.GetServiceDetails(), ex); AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error); HttpContext.Current.Session["ErrorMessage"] = objComUtil.getTransText(Constants.LS_FETCH_COUNTRIES_FAILURE) + ex.Message.ToString(); return; } }
protected void Page_PreRender(object sender, EventArgs args) { try { objLocInfo = (LocationInfo)HttpContext.Current.Session["objLocationInfo"]; if (objLocInfo.DataPointInfo != null && objLocInfo.DataPointInfo.stationLatitude != 0 && objLocInfo.DataPointInfo.stationLongitude != 0 && objLocInfo.DataPointInfo.stationName != "") { loadIcons(); } } catch (Exception ex) { AgriCastException currEx = new AgriCastException(objSvcPre.GetServiceDetails(), ex); AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error); HttpContext.Current.Session["ErrorMessage"] = objCommonUtil.getTransText(Constants.WINDICONS_LOAD_FAILURE) + ":" + ex.Message.ToString(); } }
public void setDefaultLoc() { try { IDictionary dict = null; if (HttpContext.Current.Session != null && HttpContext.Current.Session["AuditData"] != null) { dict = (IDictionary)HttpContext.Current.Session["AuditData"]; } objServiceInfo = (ServiceInfo)HttpContext.Current.Session["serviceInfo"]; svc = readConfig(); string defaultLoc = svc.locationSearch.defaultLocation; objLocInfo = LocationInfo.getLocationInfoObj; if (defaultLoc != "" && defaultLoc.Split(',').Count() > 1) { if (objLocInfo.placeName == null || objLocInfo.placeName == "") { objLocInfo.placeName = defaultLoc.Split(',')[0]; } if (objLocInfo.latitude == 0.0) { objLocInfo.latitude = Convert.ToDouble(defaultLoc.Split(',')[1]); } if (objLocInfo.longitude == 0.0) { objLocInfo.longitude = Convert.ToDouble(defaultLoc.Split(',')[2]); } if (dict != null) { dict["locSearchType"] = "defaultLocation"; HttpContext.Current.Session["AuditData"] = dict; } } else if ((bool)(svc.locationSearch.useIPLocation)) { HttpRequest req = HttpContext.Current.Request; //string url = "http://api.hostip.info/get_xml.php?position=true& ip=" + (req.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? req.ServerVariables["REMOTE_ADDR"]); string url = "http://freegeoip.net/xml/" + ( req.ServerVariables["HTTP_X_FORWARDED_FOR"] == null ? req.ServerVariables["REMOTE_ADDR"] : req.ServerVariables["HTTP_X_FORWARDED_FOR"]); string proxyName = ConfigurationManager.AppSettings["proxyName"]; WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; string username = ConfigurationManager.AppSettings["UserName"] ?? ""; string domain = ConfigurationManager.AppSettings["Domain"] ?? ""; string password = ConfigurationManager.AppSettings["Password"] ?? ""; if (username != "" && password != "") webClient.Credentials = new System.Net.NetworkCredential(username, password, domain); webClient.Headers.Add(HttpRequestHeader.UserAgent, "test"); WebProxy proxy = new WebProxy(proxyName, true); if (username != "" && password != "") proxy.Credentials = new System.Net.NetworkCredential(username, password, domain); webClient.Proxy = proxy; try { string xml = webClient.DownloadString(url); XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(xml); DataSet dsTest = new DataSet(); dsTest.ReadXml(new XmlNodeReader(xdoc)); if (dsTest != null && dsTest.Tables.Count > 0) { //if (dsTest.Tables.Contains("Hostip") && dsTest.Tables["Hostip"].Rows.Count > 0) //{ // if (dsTest.Tables["Hostip"].Rows[0]["countryAbbrev"].ToString() != "XX") // { // objLocInfo.placeName = dsTest.Tables["Hostip"].Rows[0]["name"].ToString().IndexOf(',') > 0 ? dsTest.Tables["Hostip"].Rows[0]["name"].ToString().Split(',')[0] : dsTest.Tables["Hostip"].Rows[0]["name"].ToString(); // objLocInfo.CountryCode = dsTest.Tables["Hostip"].Rows[0]["countryAbbrev"].ToString(); // } //} //if (dsTest.Tables.Contains("point") && dsTest.Tables["point"].Rows.Count > 0) //{ // string lnglat = dsTest.Tables["point"].Rows[0]["coordinates"].ToString(); // if (lnglat != "") // { // objLocInfo.latitude = Double.Parse(lnglat.Split(',')[1].ToString()); // objLocInfo.longitude = Double.Parse(lnglat.Split(',')[0].ToString()); // } //} if (dsTest.Tables[0].Rows.Count > 0) { objLocInfo.placeName = dsTest.Tables[0].Rows[0]["City"].ToString(); objLocInfo.CountryCode = dsTest.Tables[0].Rows[0]["CountryCode"].ToString(); objLocInfo.latitude = Double.Parse(dsTest.Tables[0].Rows[0]["Latitude"].ToString()); objLocInfo.longitude = Double.Parse(dsTest.Tables[0].Rows[0]["Longitude"].ToString()); } } if (dict != null && objLocInfo.CountryCode != "") { dict["locSearchType"] = "UserIP"; HttpContext.Current.Session["AuditData"] = dict; } } catch (Exception ex) { AgriCastException currEx = new AgriCastException(GetServiceDetails(), ex); AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error); } } } catch (Exception ex) { AgriCastException currEx = new AgriCastException(GetServiceDetails(), ex); AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error); HttpContext.Current.Session["ErrorMessage"] = util.getTransText(Constants.TOOLBAR_DEFAULTLOCATION) + " : " + ex.Message.ToString(); } }
public void ReadQueryStringValues() { if (HttpContext.Current.Session == null || HttpContext.Current.Session["serviceInfo"] == null) { objServiceInfo = new ServiceInfo(); } else { objServiceInfo = (ServiceInfo)HttpContext.Current.Session["serviceInfo"]; } objLocInfo = LocationInfo.getLocationInfoObj; objDataPointInfo = DataPointInfo.getDataPointObject; if (HttpContext.Current.Request.QueryString["module"] != null) { //if (objSvcInfo.Module != HttpContext.Current.Request.QueryString["module"]) //{ // if (HttpContext.Current.Session["Rating"] != null) // { // SaveRatings(); // } //} objServiceInfo.Module = HttpContext.Current.Request.QueryString["module"]; } if (HttpContext.Current.Request.QueryString["Culture"] != null) { objServiceInfo.Culture = HttpContext.Current.Request.QueryString["Culture"]; } if (HttpContext.Current.Request.QueryString["Country"] != null) { objServiceInfo.Country = HttpContext.Current.Request.QueryString["Country"]; objLocInfo.CountryCode = HttpContext.Current.Request.QueryString["Country"]; } if (HttpContext.Current.Request.QueryString["Unit"] != null) { objServiceInfo.ServiceName = HttpContext.Current.Request.QueryString["Unit"]; } if (HttpContext.Current.Request.QueryString["Placename"] != null) { objLocInfo.searchLocation = HttpContext.Current.Request.QueryString["Placename"]; //Clearing off datapoint object in case search crtieria is given in query string objDataPointInfo = null; objLocInfo.DataPointInfo = null; //HttpContext.Current.Session["objDataPointInfo"] = null; } if (HttpContext.Current.Request.QueryString["Latitude"] != null && HttpContext.Current.Request.QueryString["Longitude"] != null) { objLocInfo.latitude = Convert.ToDouble(HttpContext.Current.Request.QueryString["Latitude"]); objLocInfo.longitude = Convert.ToDouble(HttpContext.Current.Request.QueryString["Longitude"]); if (HttpContext.Current.Request.QueryString["Placename"] == null) objLocInfo.placeName = "Lat: " + objLocInfo.latitude + " Long: " + objLocInfo.longitude; //Clearing off datapoint object in case search crtieria is given in query string objDataPointInfo = null; objLocInfo.DataPointInfo = null; // HttpContext.Current.Session["objDataPointInfo"] = null; } }
public void ExportToExcel(DataSet source) { if (HttpContext.Current.Session == null || HttpContext.Current.Session["serviceInfo"] == null) { objServiceInfo = new ServiceInfo(); } else { objServiceInfo = (ServiceInfo)HttpContext.Current.Session["serviceInfo"]; } objLocInfo = LocationInfo.getLocationInfoObj; try { if (source != null) { String fileName = HttpContext.Current.Request.PhysicalApplicationPath + "/Temp/report.xls"; System.IO.StreamWriter excelDoc; string Loc = getTranslatedText(LOC_DETAILS, getCultureCode()); excelDoc = new System.IO.StreamWriter(fileName); const string startExcelXML = "<xml version>\r\n<Workbook " + "xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n" + " xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n " + "xmlns:x=\"urn:schemas- microsoft-com:office:" + "excel\"\r\n xmlns:ss=\"urn:schemas-microsoft-com:" + "office:spreadsheet\">\r\n <Styles>\r\n " + "<Style ss:ID=\"Default\" ss:Name=\"Normal\">\r\n " + "<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>" + "\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>" + "\r\n <Protection/>\r\n </Style>\r\n " + "<Style ss:ID=\"BoldColumn\">\r\n <Font " + "x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n </Style>\r\n " + "<Style ss:ID=\"StringLiteral\">\r\n <NumberFormat" + " ss:Format=\"@\"/>\r\n </Style>\r\n <Style " + "ss:ID=\"Decimal\">\r\n <NumberFormat " + "ss:Format=\"0.0\"/>\r\n </Style>\r\n " + "<Style ss:ID=\"Integer\">\r\n <NumberFormat " + "ss:Format=\"0\"/>\r\n </Style>\r\n <Style " + "ss:ID=\"DateLiteral\">\r\n <NumberFormat " + "ss:Format=\"General Date\"/>\r\n </Style>\r\n " + "</Styles>\r\n "; const string endExcelXML = "</Workbook>"; int rowCount = 0; int sheetCount = 1; excelDoc.Write(startExcelXML); for (int i = 0; i < source.Tables.Count; i++) { /* IM01246267 - New agricast - export to excel not working - Begin*/ //Excel Sheet Name Cannot Exceed 31 characters. truncate the sheet name if it exceeds. string strSheetName = source.Tables[i].TableName; if (!string.IsNullOrEmpty(strSheetName)) { if (strSheetName.Length > 31) { strSheetName = strSheetName.Substring(0, 30) + i; } } //excelDoc.Write("<Worksheet ss:Name=\"" + source.Tables[i].TableName + "\">"); excelDoc.Write("<Worksheet ss:Name=\"" + strSheetName + "\">"); /* IM01246267 - New agricast - export to excel not working - Begin*/ excelDoc.Write("<Table>"); excelDoc.Write("<Column ss:AutoFitWidth=\"1\" ss:Width=\"108.75\" ss:Span=\"1\"/>"); //Adding the ist row in each table as the location details excelDoc.Write("<Row><Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">"); excelDoc.Write(Loc + " : " + objLocInfo.placeName + " , " + objLocInfo.latitude + " , " + objLocInfo.longitude); excelDoc.Write("</Data></Cell>"); excelDoc.Write("</Row>"); excelDoc.Write("<Row><Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">"); excelDoc.Write(""); excelDoc.Write("</Data></Cell>"); excelDoc.Write("</Row>"); excelDoc.Write("<Row>"); for (int x = 0; x < source.Tables[i].Columns.Count; x++) { excelDoc.Write("<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">"); excelDoc.Write(source.Tables[i].Columns[x].ColumnName); excelDoc.Write("</Data></Cell>"); } excelDoc.Write("</Row>"); foreach (DataRow x in source.Tables[i].Rows) { rowCount++; //if the number of rows is > 64000 create a new page to continue output if (rowCount == 64000) { rowCount = 0; sheetCount++; excelDoc.Write("</Table>"); excelDoc.Write(" </Worksheet>"); excelDoc.Write("<Worksheet ss:Name=\"Sheet" + sheetCount + "\">"); excelDoc.Write("<Table>"); } excelDoc.Write("<Row>"); //ID=" + rowCount + " for (int y = 0; y < source.Tables[i].Columns.Count; y++) { System.Type rowType; rowType = x[y].GetType(); switch (rowType.ToString()) { case "System.String": if (y == 0 && objServiceInfo.ServiceName == "geotroll1") { var datetime = DateTime.Parse(x[y].ToString()); string XMLstring = datetime.ToString("dd/MM/yyyy"); excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" + "<Data ss:Type=\"String\">"); excelDoc.Write(XMLstring); excelDoc.Write("</Data></Cell>"); } else { string XMLstring = x[y].ToString(); XMLstring = XMLstring.Trim(); XMLstring = XMLstring.Replace("&", "&"); XMLstring = XMLstring.Replace(">", ">"); XMLstring = XMLstring.Replace("<", "<"); excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" + "<Data ss:Type=\"String\">"); excelDoc.Write(XMLstring); excelDoc.Write("</Data></Cell>"); } //string XMLstring = x[y].ToString(); // XMLstring = XMLstring.Trim(); // XMLstring = XMLstring.Replace("&", "&"); // XMLstring = XMLstring.Replace(">", ">"); // XMLstring = XMLstring.Replace("<", "<"); // excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" + // "<Data ss:Type=\"String\">"); // excelDoc.Write(XMLstring); // excelDoc.Write("</Data></Cell>"); break; //case "System.DateTime": // //Excel has a specific Date Format of YYYY-MM-DD followed by // //the letter 'T' then hh:mm:sss.lll Example 2005-01-31T24:01:21.000 // //The Following Code puts the date stored in XMLDate // //to the format above // DateTime XMLDate = (DateTime)x[y]; // string XMLDatetoString = ""; //Excel Converted Date // XMLDatetoString = XMLDate.Year.ToString() + // "-" + // (XMLDate.Month < 10 ? "0" + // XMLDate.Month.ToString() : XMLDate.Month.ToString()) + // "-" + // (XMLDate.Day < 10 ? "0" + // XMLDate.Day.ToString() : XMLDate.Day.ToString()) + // "T" + // (XMLDate.Hour < 10 ? "0" + // XMLDate.Hour.ToString() : XMLDate.Hour.ToString()) + // ":" + // (XMLDate.Minute < 10 ? "0" + // XMLDate.Minute.ToString() : XMLDate.Minute.ToString()) + // ":" + // (XMLDate.Second < 10 ? "0" + // XMLDate.Second.ToString() : XMLDate.Second.ToString()) + // ".000"; // excelDoc.Write("<Cell ss:StyleID=\"DateLiteral\">" + // "<Data ss:Type=\"DateTime\">"); // excelDoc.Write(XMLDatetoString); // excelDoc.Write("</Data></Cell>"); // break; case "System.DateTime": excelDoc.Write(string.Format("<Cell ss:StyleID=\"DateLiteral\"><Data ss:Type=\"DateTime\">{0:s}</Data></Cell>", x[y])); // {0:s}={0:yyyy'-'MM'-'dd'T'HH':'mm':'ss} SortableDateTimePattern, culture independent break; case "System.Boolean": excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" + "<Data ss:Type=\"String\">"); excelDoc.Write(x[y].ToString()); excelDoc.Write("</Data></Cell>"); break; case "System.Int16": case "System.Int32": case "System.Int64": case "System.Byte": excelDoc.Write("<Cell ss:StyleID=\"Integer\">" + "<Data ss:Type=\"Number\">"); excelDoc.Write(x[y].ToString()); excelDoc.Write("</Data></Cell>"); break; case "System.Decimal": case "System.Double": excelDoc.Write("<Cell ss:StyleID=\"Decimal\">" + "<Data ss:Type=\"Number\">"); excelDoc.Write(x[y].ToString()); excelDoc.Write("</Data></Cell>"); break; case "System.DBNull": excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" + "<Data ss:Type=\"String\">"); excelDoc.Write(""); excelDoc.Write("</Data></Cell>"); break; default: throw (new Exception(rowType.ToString() + " not handled.")); } } excelDoc.Write("</Row>"); } excelDoc.Write("</Table>"); excelDoc.Write(" </Worksheet>"); } excelDoc.Write(endExcelXML); excelDoc.Close(); FileStream sourceFile = new FileStream(HttpRuntime.AppDomainAppPath + @"Temp\report.xls", FileMode.Open); string name = objServiceInfo.Module.ToString(); float FileSize; FileSize = sourceFile.Length; byte[] getContent = new byte[(int)FileSize]; sourceFile.Read(getContent, 0, (int)sourceFile.Length); sourceFile.Close(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.Buffer = true; //HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.ContentType = "application/vnd.xls"; HttpContext.Current.Response.AddHeader("Content-Length", getContent.Length.ToString()); HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + name + ".xls"); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Unicode; HttpContext.Current.Response.BinaryWrite(getContent); } else { HttpContext.Current.Session["ErrorMessage"] = "No data to be exported."; } HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } catch (Exception ex) { AgriCastException currEx = new AgriCastException(GetServiceDetails(), ex); AgriCastLogger.Publish(currEx, AgriCastLogger.LogType.Error); HttpContext.Current.Session["ErrorMessage"] = "The following error occured while exporting data to excel: " + ex.Message.ToString(); } }
public void setIconWebServiceValues(double dLat, double dLong, int alt, int maxAltDiff, int maxDistDiff, DateTime dSunrise, DateTime dSunset, string strSvcName, string strModule, string strCulCode) { dLatitude = dLat; dLongitude = dLong; dTSunrise = dSunrise; dTSunset = dSunset; altitude = alt; maxAlt = maxAltDiff; maxDist = maxDistDiff; strServiceName = strSvcName; strModuleName = strModule; strCultureCode = strCulCode; objLocInfo = (LocationInfo)HttpContext.Current.Session["objLocationInfo"]; objLocInfo.DataPointInfo = null; objLocInfo.ServiceInfo = null; HttpContext.Current.Session["objLocationInfo"] = objLocInfo; HttpContext.Current.Session["objDataPointInfo"] = objLocInfo.DataPointInfo; /* SD01241630 - New Agricast webservices - can't get two views(iconsdailyandTabledata) - BEGIN -*/ objSvcHandler.setSvcHandlerWebSvcValues(strServiceName, strModuleName); /* SD01241630 - New Agricast webservices - can't get two views(iconsdailyandTabledata) - END -*/ }
public bool AddToFavorites(string strFavName) { //Update the Dt Favorites Datatable in session ObjUserInfo = (UserInfo)HttpContext.Current.Session["objUserInfo"]; //Location Info object - moved code here - trans message change objLocationinfo = (LocationInfo)HttpContext.Current.Session["objLocationInfo"]; if (ObjUserInfo != null) { //Check if the Newly Added Key allreeady Exists in datatable //check whether the the Dictionary key exists in Datatable var res = from p in ObjUserInfo.DtFavorites.AsEnumerable() where p[Constants.FAV_FAVORITENAME].Equals(strFavName) select p[Constants.FAV_FAVORITENAME]; //when no matach found if (res.ToList().Count == 1) { isFavoriteAdded = false; HttpContext.Current.Session["ErrorMessage"] = getTranslatedText(Constants.FAVORITE_UPDATE_DUPLICATE, objLocationinfo.ServiceInfo.Culture) + strFavName + getTranslatedText(Constants.GENERIC_ALREADYEXISTS, objLocationinfo.ServiceInfo.Culture); } else { //Fetch all the Values from Session isFavoriteAdded = true; //Check if the Object is null if (ObjUserInfo != null) { dtTemp = ObjUserInfo.DtFavorites; dr = dtTemp.NewRow(); //Take the User Entered Favorite name dr[Constants.FAV_Key] = strFavName.Trim(); dr[Constants.FAV_FAVORITENAME] = strFavName.Trim(); //Fetch Id from LocationInfo Object if (objLocationinfo != null) { //Fetch the Datapoint Info from Location Info itself objDataPointInfo = objLocationinfo.DataPointInfo; //Fetch the Service Info from Location Info itself objServiceInfo = objLocationinfo.ServiceInfo; dr[Constants.FAV_ALTITUDE] = objDataPointInfo.altitude;//Altitude dr[Constants.FAV_LATITUDE] = objLocationinfo.latitude;//Place - Latitude dr[Constants.FAV_LONGITUDE] = objLocationinfo.longitude;//Place - Longitiude dr[Constants.FAV_PLACENAME] = objLocationinfo.placeName;//PlaceName dr[Constants.FAV_PLACEID] = objLocationinfo.placeID;//Place ID dr[Constants.FAV_SERVICENAME] = objServiceInfo.ServiceName;//ServieName dr[Constants.FAV_MODULENAME] = objServiceInfo.Module;//ModuleName } //add the New Row to DtFavorites dtTemp.Rows.Add(dr); ObjUserInfo.DtFavorites = dtTemp; //Add the Userinfo Back to Sessions HttpContext.Current.Session["ObjUserInfo"] = ObjUserInfo; } } } return isFavoriteAdded; }
void populateObject() { /*Changes by jerrey - web service issue - added new condition*/ //&& objLocInfo != null && objDatapoint != null) if (HttpContext.Current != null) { objLocInfo = (LocationInfo)HttpContext.Current.Session["objLocationInfo"]; //Web Service Issue if (objLocInfo.DataPointInfo != null && objLocInfo.ServiceInfo != null) { objDatapoint = objLocInfo.DataPointInfo; objSvcInfo = objLocInfo.ServiceInfo; } else { objDatapoint = new DataPointInfo(); objLocInfo = new LocationInfo(); objSvcInfo = new ServiceInfo(); objDatapoint.SunRise = dTSunrise; objDatapoint.SunSet = dTSunset; objDatapoint.stationLatitude = dLatitude; objDatapoint.stationLongitude = dLongitude; objDatapoint.altitude = altitude; objDatapoint.NearbyPointSettings.MaxAllowedDistance = maxDist; objDatapoint.NearbyPointSettings.MaxAllowedAltitude = maxAlt; objSvcInfo.Culture = strCultureCode; objSvcHandler.setSvcHandlerWebSvcValues(strServiceName, strModuleName); //Web service issue fix objLocInfo.DataPointInfo = objDatapoint; HttpContext.Current.Session["objDataPointInfo"] = objDatapoint; objLocInfo.ServiceInfo = objSvcInfo; HttpContext.Current.Session["objLocationInfo"] = objLocInfo; } } }
//This method will be called from the web service to populate the values required to populate the DataPoint object public void setTableWebServiceValues(double dStnLat, double dStnLong, int iAtl, int iMaxDist, int iMaxAltDiff) { dStnLatitude = dStnLat; dStnLongitude = dStnLong; iAltitude = iAtl; iMaxAllowedDist = iMaxDist; iMaxAltitudeDiff = iMaxAltDiff; objLocInfo = (LocationInfo)HttpContext.Current.Session["objLocationInfo"]; objLocInfo.DataPointInfo = null; HttpContext.Current.Session["objLocationInfo"] = objLocInfo; }
public string SerializeCookieString() { HttpSessionState Session = HttpContext.Current.Session; if (HttpContext.Current != null) Session = HttpContext.Current.Session; objDataPointInfo = DataPointInfo.getDataPointObject; objLocInfo = LocationInfo.getLocationInfoObj; if (Session == null || Session["serviceInfo"] == null) { objSvcInfo = new ServiceInfo(); } else { objSvcInfo = (ServiceInfo)Session["serviceInfo"]; } return objLocInfo.searchLocation + "#" + objLocInfo.placeID + "#" + HttpUtility.UrlEncode(objLocInfo.placeName) + "#" + objLocInfo.longitude.ToString(NumberFormatInfo.InvariantInfo) + "#" + objLocInfo.latitude.ToString(NumberFormatInfo.InvariantInfo) + "#" + objLocInfo.CountryCode + "#" + objLocInfo.Provider + "#" + objLocInfo.AdminName + "#" + HttpUtility.UrlEncode(objDataPointInfo.stationName) + "#" + objDataPointInfo.stationLatitude + "#" + objDataPointInfo.stationLongitude + "#" + objSvcInfo.Country + "#" + objSvcInfo.Culture + "#" + objSvcInfo.Module + "#" //+ objSvcInfo.ServiceName + "#" + objSvcInfo.Unit + "#"; }
/*Method to populate the objects. If session is availabel then objects will be populated using seesion objects else objects will be populated using values passed from the webservice * */ protected void populateObject() { /*Changes by jerrey - web service issue - added new condition*/ if (HttpContext.Current != null) // { objLocInfo = LocationInfo.getLocationInfoObj; //Web service issue if (objLocInfo.DataPointInfo != null) { objDataPoint = objLocInfo.DataPointInfo; } else { objDataPoint = new DataPointInfo(); objLocInfo = new LocationInfo(); objDataPoint.stationLatitude = dStnLatitude; objDataPoint.stationLongitude = dStnLongitude; objDataPoint.altitude = iAltitude; objDataPoint.NearbyPointSettings.MaxAllowedDistance = iMaxAllowedDist; objDataPoint.altitude = iMaxAltitudeDiff; } } }
/*Method to populate the objects. If session is availabel then objects will be populated using seesion objects else objects will be populated using values passed from the webservice * */ protected void populateObject() { if (HttpContext.Current != null) { objLocInfo = LocationInfo.getLocationInfoObj; objDataPoint = objLocInfo.DataPointInfo; } else { objDataPoint = new DataPointInfo(); objLocInfo = new LocationInfo(); objDataPoint.stationLatitude = dStnLatitude; objDataPoint.stationLongitude = dStnLongitude; objDataPoint.altitude = iAltitude; objDataPoint.NearbyPointSettings.MaxAllowedDistance = iMaxAllowedDist; objDataPoint.altitude = iMaxAltitudeDiff; } }
public void getChartData(LocationInfo objLocation, string strSeries, string strCultureCode, int intAggregation, string strDate) { throw new System.NotImplementedException(); }