protected void Page_Load(object sender, EventArgs e) { //check if it is request for saved graph - by graph guid sGraphGuid = QueryHelper.GetGuid("graphguid", Guid.Empty); if (sGraphGuid != Guid.Empty) { SavedGraphInfo sGraphInfo = SavedGraphInfoProvider.GetSavedGraphInfo(sGraphGuid); if (sGraphInfo != null) { SavedReportInfo savedReport = SavedReportInfoProvider.GetSavedReportInfo(sGraphInfo.SavedGraphSavedReportID); ReportInfo report = ReportInfoProvider.GetReportInfo(savedReport.SavedReportReportID); //check graph security settings if (report.ReportAccess != ReportAccessEnum.All) { if (!AuthenticationHelper.IsAuthenticated()) { Response.StatusCode = (int)HttpStatusCode.Unauthorized; return; } else { // Check 'Read' permission if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "Read")) { RedirectToAccessDenied("cms.reporting", "Read"); } } } //send response with image data SendGraph(sGraphInfo); return; } } // Bad parameters, guid ... -> not found RequestHelper.Respond404(); }
/// <summary> /// Reload data. /// </summary> public override void ReloadData(bool forceLoad) { // If percent Width is Set and reloadonPrerender == false - it means first run .. ad postback scripts and exit if ((GraphImageWidth != 0) && (ComputedWidth == 0)) { string argument = Request.Params[Page.postEventArgumentID]; string target = Request.Params[Page.postEventSourceID]; // Check for empty (invisible) div to prevent neverending loop // If refresh postback and still no computedwidth - display graph with default width if (!((target == btnRefresh.UniqueID) && (argument == "refresh"))) { mRegisterWidthScript = true; ucChart.Visible = false; RequestStockHelper.Add("CMSGraphAutoWidth", true); return; } } RequestStockHelper.Add("CMSGraphAutoWidth", false); mRegisterWidthScript = false; // ReportGraphName is set from AbstractReportControl parameter ReportGraphName = Parameter; // Preview if (GraphInfo != null) { GetReportGraph(GraphInfo); } else { ReportGraphInfo rgi = ReportGraphInfo; // If saved report guid is empty ==> create "live" graph, else load saved graph if (SavedReportGuid == Guid.Empty) { // Get graph info object if (rgi != null) { GetReportGraph(rgi); } else { lblError.Visible = true; lblError.Text = "[ReportGraph.ascx] Report graph '" + ReportGraphName + "' not found."; EventLogProvider.LogException("Report graph", "E", new Exception("Report graph '" + ReportGraphName + "' not found.")); } } else { if (rgi != null) { int correctWidth = 0; if (ComputedWidth != 0) { correctWidth = GetGraphWidth(); } rgi.GraphTitle = ResHelper.LocalizeString(rgi.GraphTitle); rgi.GraphXAxisTitle = ResHelper.LocalizeString(rgi.GraphXAxisTitle); rgi.GraphYAxisTitle = ResHelper.LocalizeString(rgi.GraphYAxisTitle); QueryIsStoredProcedure = rgi.GraphQueryIsStoredProcedure; QueryText = ResolveMacros(rgi.GraphQuery); // Load data, generate image ReportGraph rg = new ReportGraph() { Colors = Colors }; // Save image SavedGraphInfo sgi = new SavedGraphInfo(); string noRecordText = ResolveMacros(ValidationHelper.GetString(rgi.GraphSettings["QueryNoRecordText"], String.Empty)); try { rg.CorrectWidth = correctWidth; DataSet ds = LoadData(); if (!DataHelper.DataSourceIsEmpty(ds) || !String.IsNullOrEmpty(noRecordText)) { sgi.SavedGraphBinary = rg.CreateChart(rgi, LoadData(), ContextResolver, true); } } catch (Exception ex) { EventLogProvider.LogException("Report graph", "E", ex); byte[] invalidGraph = rg.CreateChart(rgi, null, ContextResolver, true); sgi.SavedGraphBinary = invalidGraph; } if (sgi.SavedGraphBinary != null) { sgi.SavedGraphGUID = SavedReportGuid; sgi.SavedGraphMimeType = "image/png"; sgi.SavedGraphSavedReportID = SavedReportID; SavedGraphInfoProvider.SetSavedGraphInfo(sgi); // Create graph image imgGraph.Visible = true; ucChart.Visible = false; imgGraph.ImageUrl = ResolveUrl("~/CMSModules/Reporting/CMSPages/GetReportGraph.aspx") + "?graphguid=" + SavedReportGuid.ToString(); } else { Visible = false; } } } } }