using FastReport.Data;
using FastReport.Export.Html;
using FastReport.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Design;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
namespace FastReport.Web
{
///
/// Represents the Web Report.
///
[Designer("FastReport.VSDesign.WebReportComponentDesigner, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL")]
[ToolboxBitmap(typeof(WebReport), "Resources.Report.bmp")]
public partial class WebReport : WebControl, INamingContainer
{
#region Private fields
private string fReportGuid;
private WebToolbar fToolbar;
private int currentReportIndex = -1;
private List tabs;
private bool fPreviewMode = false;
private WebReportCache cache;
private WebRes reportRes = new WebRes();
#endregion Private fields
///
public override Unit Width
{
get {
return base.Width;
}
set {
Prop.WidthString = value.ToString();
base.Width = value;
}
}
///
public override Unit Height
{
get {
return base.Height;
}
set {
Prop.HeightString = value.ToString();
base.Height = value;
}
}
internal WebRes ReportRes
{
get { return reportRes; }
}
#region Public properties
#region Layout
///
/// Used only if layers mode is off
///
[DefaultValue(false)]
[Category("Layout")]
[Browsable(true)]
public bool AutoWidth
{
get { return Prop.AutoWidth; }
set { Prop.AutoWidth = value; }
}
///
/// Used only if layers mode is off
///
[DefaultValue(false)]
[Category("Layout")]
[Browsable(true)]
public bool AutoHeight
{
get { return Prop.AutoHeight; }
set { Prop.AutoHeight = value; }
}
///
/// Enable or disable inline object registration
///
[DefaultValue(false)]
[Category("Layout")]
[Browsable(true)]
public bool InlineRegistration
{
get { return Prop.InlineRegistration; }
set { Prop.InlineRegistration = value; }
}
///
///
///
[DefaultValue(false)]
[Category("Layout")]
[Browsable(true)]
public bool EnableMargins
{
get { return Prop.EnableMargins; }
set { Prop.EnableMargins = value; }
}
///
/// Enable or disable using of external jQuery library
///
[DefaultValue(false)]
[Category("Layout")]
[Browsable(true)]
public bool ExternalJquery
{
get { return Prop.ExternalJquery; }
set { Prop.ExternalJquery = value; }
}
///
/// Enable or disable layers mode visualisation
///
[DefaultValue(true)]
[Category("Layout")]
[Browsable(true)]
public bool Layers
{
get { return Prop.Layers; }
set { Prop.Layers = value; }
}
///
/// Gets or sets Padding of Report section
///
[Category("Layout")]
[Browsable(true)]
public System.Windows.Forms.Padding Padding
{
get { return Prop.Padding; }
set { Prop.Padding = value; }
}
#endregion Layout
#region Network
///
/// Timeout in seconds for automatic refresh of report. Zero value disable auto-refresh.
///
[Category("Network")]
[DefaultValue(0)]
[Browsable(true)]
public int RefreshTimeout
{
get { return Prop.RefreshTimeout; }
set { Prop.RefreshTimeout = value; }
}
///
/// Delay in cache in minutes
///
[Category("Network")]
[DefaultValue(60)]
[Browsable(true)]
public int CacheDelay
{
get { return Prop.CacheDelay; }
set { Prop.CacheDelay = value; }
}
///
/// Priority of items in cache
///
[Category("Network")]
[DefaultValue(CacheItemPriority.Normal)]
[Browsable(true)]
public CacheItemPriority CachePriority
{
get { return Prop.CachePriority; }
set { Prop.CachePriority = value; }
}
///
/// Enable or disable the multiple instances environment
///
[Category("Network")]
[DefaultValue(false)]
[Browsable(true)]
public bool CloudEnvironmet
{
get { return Prop.CloudEnvironmet; }
set { Prop.CloudEnvironmet = value; }
}
internal static ScriptSecurity ScriptSecurity = null;
#endregion Network
#region Designer
///
/// Enable the Report Designer
///
[DefaultValue(false)]
[Category("Designer")]
[Browsable(true)]
public bool DesignReport
{
get { return Prop.DesignReport; }
set { Prop.DesignReport = value; }
}
///
/// Enable code editor in the Report Designer
///
[DefaultValue(false)]
[Category("Designer")]
[Browsable(true)]
public bool DesignScriptCode
{
get { return Prop.DesignScriptCode; }
set { Prop.DesignScriptCode = value; }
}
///
/// Gets or sets path to the Report Designer
///
[DefaultValue("~/WebReportDesigner/index.html")]
[Category("Designer")]
[Browsable(true)]
public string DesignerPath
{
get { return Prop.DesignerPath; }
set { Prop.DesignerPath = value; }
}
///
/// Gets or sets path to a folder for save designed reports
/// If value is empty then designer posts saved report in variable ReportFile on call the DesignerSaveCallBack
///
[DefaultValue("")]
[Category("Designer")]
[Browsable(true)]
public string DesignerSavePath
{
get { return Prop.DesignerSavePath; }
set { Prop.DesignerSavePath = value; }
}
///
/// Gets or sets path to callback page after Save from Designer
///
[DefaultValue("")]
[Category("Designer")]
[Browsable(true)]
public string DesignerSaveCallBack
{
get { return Prop.DesignerSaveCallBack; }
set { Prop.DesignerSaveCallBack = value; }
}
///
/// Gets or sets the locale of Designer
///
[DefaultValue("")]
[Category("Designer")]
[Browsable(true)]
public string DesignerLocale
{
get { return Prop.DesignerLocale; }
set { Prop.DesignerLocale = value; }
}
///
/// Gets or sets the text of configuration of Online Designer
///
[DefaultValue("")]
[Category("Designer")]
[Browsable(true)]
public string DesignerConfig
{
get { return Prop.DesignerConfig; }
set { Prop.DesignerConfig = value; }
}
#endregion Designer
#region Report
///
/// Report Resource String.
///
[DefaultValue("")]
[Category("Report")]
[Browsable(true)]
public string ReportResourceString
{
get { return Prop.ReportResourceString; }
set { Prop.ReportResourceString = value; }
}
///
/// Gets or sets report data source(s).
///
///
/// To pass several datasources, use ';' delimiter, for example:
/// "sqlDataSource1;sqlDataSource2"
///
[DefaultValue("")]
[Category("Report")]
[Browsable(true)]
public string ReportDataSources
{
get { return Prop.ReportDataSources; }
set { Prop.ReportDataSources = value; }
}
///
/// Switches the pictures visibility in report
///
[DefaultValue(true)]
[Category("Report")]
[Browsable(true)]
public bool Pictures
{
get { return Prop.Pictures; }
set { Prop.Pictures = value; }
}
///
/// Enables or disables embedding pictures in HTML (inline HTML5 images).
///
[Category("Report")]
[DefaultValue(false)]
[Browsable(true)]
public bool EmbedPictures
{
get { return Prop.EmbedPictures; }
set { Prop.EmbedPictures = value; }
}
///
/// Switches the pages layout between multiple pages (false) and single page (true).
///
[DefaultValue(false)]
[Category("Report")]
[Browsable(true)]
public bool SinglePage
{
get { return Prop.SinglePage; }
set { Prop.SinglePage = value; }
}
///
/// Gets or sets the name of report file.
///
[DefaultValue("")]
[Category("Report")]
[Browsable(true)]
[Editor("FastReport.VSDesign.ReportFileEditor, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL", typeof(UITypeEditor))]
public string ReportFile
{
get { return Prop.ReportFile; }
set { Prop.ReportFile = value; }
}
///
/// Gets or sets the default path for reports (including inherited).
///
public string ReportPath
{
get { return Prop.ReportPath; }
set { Prop.ReportPath = value; }
}
///
/// Gets or sets the name of localization file.
///
[DefaultValue("")]
[Category("Report")]
[Browsable(true)]
[Editor("FastReport.VSDesign.LocalizationFileEditor, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL", typeof(UITypeEditor))]
public string LocalizationFile
{
get { return Prop.LocalizationFile; }
set
{
Prop.LocalizationFile = value;
}
}
///
/// Sets the zoom scale factor of previewed page between 0..1f.
///
[DefaultValue(1f)]
[Category("Report")]
[Browsable(true)]
public float Zoom
{
get { return Prop.Zoom; }
set { Prop.Zoom = value; }
}
///
/// Sets the zoom mode of previewed page.
///
[DefaultValue(ZoomMode.Scale)]
[Category("Report")]
[Browsable(true)]
public ZoomMode ZoomMode
{
get { return Prop.ZoomMode; }
set { Prop.ZoomMode = value; }
}
///
/// Enables or disables showing the report after call Prepare.
///
[DefaultValue(false)]
[Category("Report")]
[Browsable(true)]
public bool ShowAfterPrepare
{
get { return Prop.ShowAfterPrepare; }
set { Prop.ShowAfterPrepare = value; }
}
///
/// Enables or disables showing any debug information on errors.
///
[DefaultValue(false)]
[Category("Report")]
[Browsable(true)]
public bool Debug
{
get { return Prop.Debug; }
set { Prop.Debug = value; }
}
///
/// Gets or sets the log file path.
///
[DefaultValue("")]
[Category("Report")]
[Browsable(true)]
public string LogFile
{
get { return Prop.LogFile; }
set { Prop.LogFile = value; }
}
///
/// Enables or disables unlimited width of report pages. This options overrides the report page property value
/// when it set to true.
///
[DefaultValue(false)]
[Category("Report")]
[Browsable(true)]
public bool UnlimitedWidth
{
get { return Prop.UnlimitedWidth; }
set { Prop.UnlimitedWidth = value; }
}
///
/// Enables or disables unlimited height of report pages. This options overrides the report page property value
/// when it set to true.
///
[DefaultValue(false)]
[Category("Report")]
[Browsable(true)]
public bool UnlimitedHeight
{
get { return Prop.UnlimitedHeight; }
set { Prop.UnlimitedHeight = value; }
}
///
/// Enables or disables showing the report dialogs.
///
[DefaultValue(true)]
[Category("Report")]
[Browsable(true)]
public bool Dialogs
{
get { return Prop.Dialogs; }
set { Prop.Dialogs = value; }
}
#endregion Report
#region Toolbar
///
/// Sets the toolbar style - small or large.
///
[DefaultValue(ToolbarStyle.Large)]
[Category("Toolbar")]
[Browsable(true)]
public ToolbarStyle ToolbarStyle
{
get { return Prop.ToolbarStyle; }
set { Prop.ToolbarStyle = value; }
}
///
/// Sets the toolbar icons style.
///
[DefaultValue(ToolbarIconsStyle.Red)]
[Category("Toolbar")]
[Browsable(true)]
public ToolbarIconsStyle ToolbarIconsStyle
{
get { return Prop.ToolbarIconsStyle; }
set { Prop.ToolbarIconsStyle = value; }
}
///
/// Sets the toolbar background style.
///
[DefaultValue(ToolbarBackgroundStyle.Light)]
[Category("Toolbar")]
[Browsable(true)]
public ToolbarBackgroundStyle ToolbarBackgroundStyle
{
get { return Prop.ToolbarBackgroundStyle; }
set { Prop.ToolbarBackgroundStyle = value; }
}
///
/// Switches the toolbar visibility.
///
[DefaultValue(true)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowToolbar
{
get { return Prop.ShowToolbar; }
set { Prop.ShowToolbar = value; }
}
///
/// Switches the bottom toolbar visibility.
///
[DefaultValue(false)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowBottomToolbar
{
get { return Prop.ShowBottomToolbar; }
set { Prop.ShowBottomToolbar = value; }
}
///
/// Sets the path to the custom buttons on site.
///
///
/// Pictures should be named:
/// Checkbox.gif, Progress.gif, toolbar.png, toolbar_background.png, toolbar_big.png, toolbar_disabled.png, toolbar_disabled.png
///
[DefaultValue("")]
[Category("Toolbar")]
[Browsable(true)]
//[UrlProperty]
[Editor("FastReport.VSDesign.ReportFileEditor, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL", typeof(UITypeEditor))]
public string ButtonsPath
{
get { return Prop.ButtonsPath; }
set { Prop.ButtonsPath = value; }
}
///
/// Switches the visibility of Exports in toolbar.
///
[DefaultValue(true)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowExports
{
get { return Prop.ShowExports; }
set { Prop.ShowExports = value; }
}
///
/// Switches the visibility of Print button in toolbar.
///
[DefaultValue(true)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowPrint
{
get { return Prop.ShowPrint; }
set { Prop.ShowPrint = value; }
}
///
/// Switches the visibility of First Button in toolbar.
///
[DefaultValue(true)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowFirstButton
{
get { return Prop.ShowFirstButton; }
set { Prop.ShowFirstButton = value; }
}
///
/// Switches the visibility of Previous Button in toolbar.
///
[DefaultValue(true)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowPrevButton
{
get { return Prop.ShowPrevButton; }
set { Prop.ShowPrevButton = value; }
}
///
/// Switches the visibility of Next Button in toolbar.
///
[DefaultValue(true)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowNextButton
{
get { return Prop.ShowNextButton; }
set { Prop.ShowNextButton = value; }
}
///
/// Switches the visibility of Last Button in toolbar.
///
[DefaultValue(true)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowLastButton
{
get { return Prop.ShowLastButton; }
set { Prop.ShowLastButton = value; }
}
///
/// Switches the visibility of Zoom in toolbar.
///
[DefaultValue(true)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowZoomButton
{
get { return Prop.ShowZoomButton; }
set { Prop.ShowZoomButton = value; }
}
///
/// Switches the visibility of Refresh in toolbar.
///
[DefaultValue(true)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowRefreshButton
{
get { return Prop.ShowRefreshButton; }
set { Prop.ShowRefreshButton = value; }
}
///
/// Switches the visibility of Page Number in toolbar.
///
[DefaultValue(true)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowPageNumber
{
get { return Prop.ShowPageNumber; }
set { Prop.ShowPageNumber = value; }
}
///
/// Switches the visibility of closing buttons for Tabs.
///
[DefaultValue(false)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowTabCloseButton
{
get { return Prop.ShowTabCloseButton; }
set { Prop.ShowTabCloseButton = value; }
}
///
/// Switches the visibility of Back buttons.
///
[DefaultValue(false)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowBackButton
{
get { return Prop.ShowBackButton; }
set { Prop.ShowBackButton = value; }
}
///
/// Selects the position of tabs.
///
[DefaultValue(TabPosition.InsideToolbar)]
[Category("Toolbar")]
[Browsable(true)]
public TabPosition TabPosition
{
get { return Prop.TabPosition; }
set { Prop.TabPosition = value; }
}
///
/// Sets the Toolbar background color.
///
[DefaultValue(0xECECEC)]
[Category("Toolbar")]
[Browsable(true)]
public System.Drawing.Color ToolbarColor
{
get { return Prop.ToolbarColor; }
set { Prop.ToolbarColor = value; }
}
///
/// Switches the outline visibility.
///
[DefaultValue(false)]
[Category("Toolbar")]
[Browsable(true)]
public bool ShowOutline
{
get { return Prop.ShowOutline; }
set { Prop.ShowOutline = value; }
}
#endregion Toolbar
#region Print
///
/// Enable or disable print in PDF.
///
[DefaultValue(true)]
[Category("Print")]
[Browsable(true)]
public bool PrintInPdf
{
get { return Prop.PrintInPdf; }
set { Prop.PrintInPdf = value; }
}
///
/// Enable or disable print in browser.
///
[DefaultValue(true)]
[Category("Print")]
[Browsable(true)]
public bool PrintInBrowser
{
get { return Prop.PrintInBrowser; }
set { Prop.PrintInBrowser = value; }
}
///
/// Sets the width of print window.
///
[DefaultValue("700px")]
[Category("Print")]
[Browsable(true)]
public string PrintWindowWidth
{
get { return Prop.PrintWindowWidth; }
set { Prop.PrintWindowWidth = value; }
}
///
/// Sets the height of print window.
///
[DefaultValue("500px")]
[Category("Print")]
[Browsable(true)]
public string PrintWindowHeight
{
get { return Prop.PrintWindowHeight; }
set { Prop.PrintWindowWidth = value; }
}
#endregion Print
#region Hidden Properties
[Browsable(false)]
internal bool ControlVisible
{
get { return Prop.ControlVisible; }
set { Prop.ControlVisible = value; }
}
[Browsable(false)]
internal List ReportTabs
{
get
{
InitTabs();
return tabs;
}
set
{
tabs = value;
InitTabs();
}
}
///
/// Direct access to the Properties of report object.
///
[Browsable(false)]
internal WebReportProperties Prop
{
get
{
return ReportTabs[currentReportIndex].Properties;
}
set
{
ReportTabs[currentReportIndex].Properties = value;
}
}
///
/// Direct access to the Tabs.
///
[Browsable(false)]
public List Tabs
{
get
{
return ReportTabs;
}
}
///
/// Gets or sets the current tab index.
///
[Browsable(false)]
public int CurrentTabIndex
{
get
{
return currentReportIndex;
}
set
{
currentReportIndex = value;
Toolbar.CurrentTabIndex = currentReportIndex;
}
}
///
/// Gets the current tab.
///
[Browsable(false)]
public ReportTab CurrentTab
{
get
{
return ReportTabs[currentReportIndex];
}
}
///
///
///
[Browsable(false)]
internal WebToolbar Toolbar
{
get
{
if (fToolbar == null)
{
fToolbar = new WebToolbar(
ReportGuid,
ReportTabs,
(this.Width.Type == UnitType.Pixel) && (this.Height.Type == UnitType.Pixel),
reportRes);
fToolbar.BackgroundColor = WebUtils.RGBAColor(this.BackColor);
}
return fToolbar;
}
set
{
fToolbar = value;
}
}
///
/// Enables the preview mode for working together the Online Designer.
///
[Browsable(false)]
public bool PreviewMode
{
get { return fPreviewMode; }
set { fPreviewMode = value; }
}
///
/// Direct access to Report object.
///
[Browsable(false)]
public Report Report
{
get
{
return ReportTabs[currentReportIndex].Report;
}
set
{
ReportTabs[currentReportIndex].Report = value;
}
}
///
/// Gets total pages of current report.
///
[Browsable(false)]
public int TotalPages
{
get
{
if (Report.PreparedPages != null)
return Report.PreparedPages.Count;
else
return 0;
}
}
///
/// Gets or sets current state of report.
///
[Browsable(false)]
public ReportState State
{
get { return Prop.State; }
set { Prop.State = value; }
}
///
/// Returns true when report done. This property may be set in true for forcing load the prepared report.
///
[Browsable(false)]
public bool ReportDone
{
get { return Prop.ReportDone; }
set { Prop.ReportDone = value; }
}
///
/// Gets or sets number of current page.
///
[Browsable(false)]
public int CurrentPage
{
get { return Prop.CurrentPage; }
set { Prop.CurrentPage = value; }
}
///
/// Gets or sets guid of report.
///
[Browsable(false)]
public string ReportGuid
{
get
{
if (String.IsNullOrEmpty(fReportGuid))
{
fReportGuid = TryGetGUID();
}
return fReportGuid;
}
set { fReportGuid = value; }
}
///
/// Gets or sets the request headers.
///
[Browsable(false)]
public WebHeaderCollection RequestHeaders
{
get { return Prop.RequestHeaders; }
set { Prop.RequestHeaders = value; }
}
///
/// Gets or sets the response headers.
///
[Browsable(false)]
public WebHeaderCollection ResponseHeaders
{
get { return Prop.ResponseHeaders; }
set { Prop.ResponseHeaders = value; }
}
private string TryGetGUID()
{
string guid = String.Empty;
if (this.Context != null && !String.IsNullOrEmpty(this.ID))
{
if (this.Context.Session != null && this.Context.Session[this.ID] != null)
guid = this.Context.Session[this.ID] as string;
}
if (String.IsNullOrEmpty(guid))
guid = WebUtils.GetGUID();
return guid;
}
#endregion Hidden Properties
#endregion Public properties
#region Events
///
/// Occurs when report execution is started.
///
[Browsable(true)]
public event EventHandler StartReport;
///
/// Occurs when designed report saving is started.
///
[Browsable(true)]
public event EventHandler SaveDesignedReport;
///
/// Occurs when report drawing is started.
///
[Browsable(true)]
public event EventHandler CustomDraw;
///
/// Occurs when report auth is started.
///
[Browsable(true)]
public event EventHandler CustomAuth;
///
/// Runs the OnCustomDraw event.
///
/// CustomDrawEventArgs object.
public void OnCustomDraw(CustomDrawEventArgs e)
{
if (CustomDraw != null)
{
CustomDraw(this, e);
}
}
///
/// Runs the OnCustomAuth event.
///
/// CustomAuthEventArgs object.
public void OnCustomAuth(CustomAuthEventArgs e)
{
if (CustomAuth != null)
{
CustomAuth(this, e);
}
}
#endregion Events
///
/// Runs the StartReport event.
///
/// EventArgs object.
public void OnStartReport(EventArgs e)
{
if (StartReport != null)
{
StartReport(this, e);
}
}
///
/// Runs the SaveDesignedReport event.
///
/// SaveDesignedReportEventArgs object.
public void OnSaveDesignedReport(SaveDesignedReportEventArgs e)
{
if (SaveDesignedReport != null)
{
SaveDesignedReport(this, e);
}
}
#region Navigation
///
/// Forces going to the next report page.
///
public void NextPage()
{
if (CurrentPage < TotalPages - 1)
CurrentPage++;
}
///
/// Forces going to the previous report page.
///
public void PrevPage()
{
if (CurrentPage > 0)
CurrentPage--;
}
///
/// Forces going to the first report page.
///
public void FirstPage()
{
CurrentPage = 0;
}
///
/// Forces going to the last report page.
///
public void LastPage()
{
CurrentPage = TotalPages - 1;
}
///
/// Forces going to the "value" report page.
///
public void SetPage(int value)
{
if (value >= 0 && value < TotalPages)
CurrentPage = value;
}
#endregion Navigation
///
/// Prepares the report.
///
public void Prepare()
{
//this.Controls.Clear();
Refresh();
}
///
/// Forces refreshing of report.
///
public void Refresh()
{
CurrentPage = 0;
Prop.CurrentForm = 0;
State = ReportState.Empty;
ControlVisible = true;
ShowAfterPrepare = false;
}
///
/// Adds the new report tab.
///
///
///
///
public ReportTab AddTab(Report report, string name)
{
return AddTab(report, name, false);
}
///
/// Adds the new report tab.
///
///
///
public ReportTab AddTab(Report report)
{
return AddTab(report, String.Empty);
}
///
/// Adds the new report tab.
///
///
///
///
///
public ReportTab AddTab(Report report, string name, bool reportDone)
{
return AddTab(report, name, reportDone, false);
}
///
/// Adds the new report tab.
///
///
///
///
///
///
public ReportTab AddTab(Report report, string name, bool reportDone, bool needParent)
{
ReportTab tab = new ReportTab(report);
tab.Properties.Assign(tabs[0].Properties);
tab.Properties.ControlID = tabs[0].Properties.ControlID;
tab.Properties.HandlerURL = WebUtils.GetBasePath(this.Context) + WebUtils.HandlerFileName;
tab.Properties.ReportDone = reportDone;
tab.Properties.ShowRefreshButton = !reportDone;
tab.NeedParent = needParent;
if (!String.IsNullOrEmpty(name))
tab.Name = name;
ReportTabs.Add(tab);
return tab;
}
#region Protected methods
private Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
return root;
foreach (Control ctl in root.Controls)
{
Control foundCtl = FindControlRecursive(ctl, id);
if (foundCtl != null)
return foundCtl;
}
return null;
}
internal void RegisterData(Report report)
{
if (Page != null)
{
string[] dataSources = ReportDataSources.Split(';');
foreach (string dataSource in dataSources)
{
IDataSource ds = FindControlRecursive(Page, dataSource) as IDataSource;
if (ds == null)
continue;
string dataName = (ds as Control).ID;
RegisterDataAsp(report, ds, dataName);
}
}
}
///
/// Registers the ASP.NET application data to use it in the report.
///
/// The Report object.
/// The application data.
/// The name of the data.
public void RegisterDataAsp(Report report, IDataSource data, string name)
{
aspDataName = name;
this.report = report;
DataSourceView view = data.GetView("");
if (view != null)
view.Select(DataSourceSelectArguments.Empty, new DataSourceViewSelectCallback(RegisterDataAsp));
}
private string aspDataName;
private Report report;
private void RegisterDataAsp(IEnumerable data)
{
if (data != null)
RegisterDataAsp(report, data, aspDataName);
}
///
/// Registers the ASP.NET application data to use it in the report.
///
/// The Report object.
/// The application data.
/// The name of the data.
public void RegisterDataAsp(Report report, IEnumerable data, string name)
{
DataComponentBase existingDs = report.Dictionary.FindDataComponent(name);
if (existingDs is ViewDataSource && data is DataView)
{
// compatibility with old FR versions (earlier than 1.1.45)
report.Dictionary.RegisterDataView(data as DataView, name, true);
}
else
{
// in a new versions, always register the business object
report.Dictionary.RegisterBusinessObject(data, name, 1, true);
}
}
///
protected override void OnLoad(EventArgs e)
{
this.EnsureChildControls();
if (this.Context != null)
{
this.Context.Session[this.ID] = ReportGuid;
}
base.OnLoad(e);
}
///
protected override void OnUnload(EventArgs e)
{
cache.CleanFileStorage();
base.OnUnload(e);
}
private void InitTabs()
{
if (tabs == null)
tabs = new List();
if (tabs.Count == 0)
{
ReportTab item = new ReportTab();
item.Properties.ControlID = GetControlID();
item.Properties.HandlerURL = WebUtils.GetBasePath(this.Context) + WebUtils.HandlerFileName;
tabs.Add(item);
currentReportIndex = 0;
}
}
private string GetControlID()
{
return String.Concat(ReportGuid, DateTime.Now.Ticks.ToString());
}
private void InitReport()
{
if (!DesignMode)
Config.WebMode = true;
cache = new WebReportCache(Context);
Prop.ControlID = GetControlID();
if (!fPreviewMode)
{
// load report
WebReport oldweb = (WebReport)cache.GetObject(ReportGuid, this);
if (oldweb != null)
{
Report = oldweb.Report;
WebReportProperties storedProp = oldweb.Prop;
if (storedProp != null)
Prop = storedProp;
}
}
else
{
this.Width = Unit.Percentage(100);
this.Height = Unit.Percentage(100);
this.Toolbar.EnableFit = true;
}
if (ShowAfterPrepare)
ControlVisible = false;
cache.Delay = CacheDelay;
cache.Priority = CachePriority;
if (this.ID == null)
this.ID = ReportGuid;
}
///
protected override void OnInit(EventArgs e)
{
if (HttpContext.Current != null)
InitReport();
base.OnInit(e);
}
internal void Localize()
{
if (!String.IsNullOrEmpty(LocalizationFile))
{
string fileName = LocalizationFile;
if (!WebUtils.IsAbsolutePhysicalPath(fileName))
fileName = this.Context.Request.MapPath(fileName, base.AppRelativeTemplateSourceDirectory, true);
reportRes.LoadLocale(fileName);
}
}
///
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
// remove width & height styles from html element
Unit width = Width;
Unit height = Height;
if (!DesignReport)
{
Width = new Unit();
Height = new Unit();
}
Style.Add("display", "inline-block");
base.AddAttributesToRender(writer);
if (!DesignReport)
{
Width = width;
Height = height;
}
}
///
protected override void RenderContents(HtmlTextWriter writer)
{
if (HttpContext.Current != null && !InlineRegistration && Page != null)
{
Toolbar.RegisterGlobals(Prop.ControlID, Page.ClientScript, this.GetType(), Prop.ExternalJquery);
if (!Page.ClientScript.IsClientScriptIncludeRegistered("fr_util"))
this.InlineRegistration = true;
}
// check for design time
if (HttpContext.Current == null)
RenderDesignModeNavigatorControls(writer);
else
{ // Run-time
Prop.HandlerURL = WebUtils.GetBasePath(this.Context) + WebUtils.HandlerFileName;
if (Config.FullTrust)
{
WebUtils.CheckHandlersRuntime();
}
StringBuilder container = new StringBuilder();
if (Page == null || PreviewMode) // Razor
{
InitReport();
}
if (ControlVisible)
{
if (InlineRegistration)
{
container.AppendLine(Toolbar.GetInlineRegistration(Prop.ExternalJquery));
}
//Localize();
container.AppendLine(Toolbar.GetHtmlProgress(Prop.HandlerURL, Prop.ControlID, !DesignReport, this.Width, this.Height));
writer.WriteLine(container.ToString());
base.RenderContents(writer);
if (cache.WebFarmMode)
{
StringBuilder sb = new StringBuilder();
ReportProcess(sb, this.Context);
}
// save all objects
// cache.PutObject(ReportGuid, this);
cache.PutObject(Prop.ControlID, this);
}
}
}
#endregion Protected methods
#region DotNet 4 specific
#if DOTNET_4
///
/// Returns the HTML code of report preview control.
///
/// HtmlString object.
public HtmlString GetHtml()
{
StringBuilder sb = new StringBuilder();
HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb, System.Globalization.CultureInfo.InvariantCulture));
this.RenderControl(writer);
return new HtmlString(Toolbar.GetCss() + sb.ToString());
}
///
/// Returns the code "" for registration the necessary js libraries.
///
/// HtmlString object.
public HtmlString Scripts()
{
return WebReportGlobals.Scripts();
}
///
/// Returns the code for registration the necessary CSS.
///
/// HtmlString object.
public HtmlString Styles()
{
return WebReportGlobals.Styles();
}
#endif
#endregion DotNet 4 specific
///
/// Sets the size of WebReport object.
///
/// Width of WebReport.
/// Height of WebReport.
/// WebReport object.
public WebReport SetSize(Unit width, Unit height)
{
this.Width = width;
this.Height = height;
return this;
}
///
/// Sets the StartReport event handler.
///
/// Event handler.
/// WebReport object.
public WebReport SetStartEvent(EventHandler start)
{
StartReport += start;
return this;
}
///
/// Sets the CustomDraw event handler.
///
/// Event handler.
/// WebReport object.
public WebReport SetCustomDrawEvent(EventHandler draw)
{
CustomDraw += draw;
return this;
}
///
/// Sets the CustomAuth event handler.
///
/// Event handler.
/// WebReport object.
public WebReport SetCustomAuthEvent(EventHandler auth)
{
CustomAuth += auth;
return this;
}
#region Register Data
///
/// Register the DataSet in report dictionary.
///
/// DataSet object.
/// Name for the registered data.
/// WebReport object.
public WebReport RegisterData(DataSet data, string name)
{
this.Report.Dictionary.RegisterData(data, name, true);
return this;
}
///
/// Registers the DataRelation in report dictionary.
///
/// DataRelation object.
/// Name for the registered data.
/// WebReport object.
public WebReport RegisterData(DataRelation data, string name)
{
this.Report.Dictionary.RegisterData(data, name, true);
return this;
}
///
/// Register the DataSet in report dictionary.
///
/// DataSet object.
/// WebReport object.
public WebReport RegisterData(DataSet data)
{
this.Report.Dictionary.RegisterData(data, "Data", true);
return this;
}
///
/// Registers the DataTable in report dictionary.
///
/// DataTable object.
/// Name for the registered data.
/// WebReport object.
public WebReport RegisterData(DataTable data, string name)
{
this.Report.Dictionary.RegisterData(data, name, true);
return this;
}
///
/// Registers the DataView in report dictionary.
///
/// DataView object.
/// Name for the registered data.
/// WebReport object.
public WebReport RegisterData(DataView data, string name)
{
this.Report.Dictionary.RegisterData(data, name, true);
return this;
}
///
/// Registers the IEnumerable in report dictionary.
///
/// IEnumerable data.
/// Name for the registered data.
/// WebReport object.
public WebReport RegisterData(IEnumerable data, string name)
{
this.Report.Dictionary.RegisterData(data, name, true);
return this;
}
///
/// Loads the report from file.
///
/// File Name.
/// WebReport object.
public WebReport LoadFromFile(string fileName)
{
this.Report.Load(fileName);
return this;
}
///
/// Loads the report from stream.
///
/// Stream object.
/// WebReport object.
public WebReport LoadFromStream(Stream stream)
{
this.Report.Load(stream);
return this;
}
///
/// Loads the prepared report from file. Also the property will be enabled and
/// will be disabled.
///
/// File Name.
/// WebReport object.
public WebReport LoadPrepared(string fileName)
{
this.Report.LoadPrepared(fileName);
this.ReportDone = true;
this.ShowRefreshButton = false;
return this;
}
///
/// Loads the prepared report from stream. Also the property will be enabled and
/// will be disabled.
///
/// Stream object.
/// WebReport object.
public WebReport LoadPrepared(Stream stream)
{
this.Report.LoadPrepared(stream);
this.ReportDone = true;
this.ShowRefreshButton = false;
return this;
}
#endregion Register Data
private void WebReportInit(bool inlineRegistration, bool stretched)
{
this.Width = Unit.Pixel(550);
this.Height = Unit.Pixel(500);
this.ForeColor = Color.Black;
this.BackColor = Color.White;
this.InlineRegistration = inlineRegistration;
if (stretched)
{
this.Width = Unit.Percentage(100);
this.Height = Unit.Percentage(100);
}
}
///
/// Initializes a new instance of the class.
///
public WebReport()
{
WebReportInit(false, false);
}
///
/// Initializes a new instance of the class.
///
/// Enable registration of JS/CSS footprint inline.
public WebReport(bool inlineRegistration)
{
WebReportInit(inlineRegistration, false);
}
///
/// Initializes a new instance of the class.
///
/// Enable registration of JS/CSS footprint inline.
/// Creates the control with 100% width and height.
public WebReport(bool inlineRegistration, bool stretched)
{
WebReportInit(inlineRegistration, stretched);
}
static WebReport()
{
ScriptSecurity = new ScriptSecurity(new ScriptChecker());
}
#region Serialization
///
/// Gets the stream with serialized properties data.
///
/// Stream object.
public Stream GetPropData()
{
XmlSerializer propSerializer = new XmlSerializer(typeof(WebReportProperties));
MemoryStream dataStream = new MemoryStream();
propSerializer.Serialize(dataStream, Prop);
dataStream.Position = 0;
return dataStream;
}
///
/// Gets the stream with serialized report data.
///
/// Stream object.
public Stream GetReportData()
{
MemoryStream dataStream = new MemoryStream();
Report.Save(dataStream);
dataStream.Position = 0;
return dataStream;
}
///
/// Gets the stream with serialized prepared report data.
///
/// Stream object.
public Stream GetPreparedData()
{
MemoryStream dataStream = new MemoryStream();
Report.SavePrepared(dataStream);
dataStream.Position = 0;
return dataStream;
}
#endregion Serialization
#region Deserialization
///
/// Loads the serialized properties data from stream.
///
/// Stream object.
public void SetPropData(Stream propStream)
{
if (propStream != null && propStream.Length > 0)
{
XmlSerializer propSerializer = new XmlSerializer(typeof(WebReportProperties));
Prop = propSerializer.Deserialize(propStream) as WebReportProperties;
}
}
///
/// Loads the serialized report data from stream.
///
/// Stream object.
public void SetReportData(Stream reportStream)
{
if (reportStream != null && reportStream.Length > 0)
{
Report.Load(reportStream);
}
}
///
/// Loads the serialized prepared report data from stream.
///
/// Stream object.
public void SetPreparedData(Stream reportStream)
{
if (reportStream != null && reportStream.Length > 0)
{
Report.LoadPrepared(reportStream);
}
}
#endregion Deserialization
}
///
/// Represents the static class WebReportGlobals with necessary methods for using in MVC environment.
///
public static class WebReportGlobals
{
#if DOTNET_4
///
/// Returns the code for registration the necessary scripts with jQuery.
///
/// HtmlString object.
public static HtmlString Scripts()
{
return new HtmlString(ScriptsAsString());
}
///
/// Returns the code for registration the necessary scripts without jQuery.
///
/// HtmlString object.
public static HtmlString ScriptsWOjQuery()
{
return new HtmlString(ScriptsWOjQueryAsString());
}
///
/// Returns the code for registration the necessary CSS.
///
/// HtmlString object.
public static HtmlString Styles()
{
return new HtmlString(StylesAsString());
}
///
/// Returns the code for registration the necessary CSS without jQuery styles.
///
/// HtmlString object.
public static HtmlString StylesWOjQuery()
{
// reserved for future
return new HtmlString(String.Empty);
}
#endif
///
/// Returns the string with code for registration the necessary scripts with jQuery.
///
/// String object.
public static string ScriptsAsString()
{
StringBuilder raw = new StringBuilder();
raw.Append("");
raw.Append("");
raw.Append("");
return raw.ToString();
}
///
///Returns the string with code for registration the necessary scripts without jQuery.
///
/// String object.
public static string ScriptsWOjQueryAsString()
{
StringBuilder raw = new StringBuilder();
raw.Append("");
return raw.ToString();
}
///
/// Returns the string with code for registration the necessary CSS with jQuery.
///
/// String object.
public static string StylesAsString()
{
StringBuilder raw = new StringBuilder();
raw.Append("");
return raw.ToString();
}
///
/// Returns the string with code for registration the necessary CSS without jQuery.
///
/// String object.
public static string StylesWOjQueryAsString()
{
// reserved for future
return String.Empty;
}
private static string GetResourceJqueryUrl(string resName)
{
return new Page().ClientScript.GetWebResourceUrl(typeof(WebReport), string.Format("FastReport.Web.Resources.jquery.{0}", resName));
}
private static string GetResourceTemplateUrl(string resName)
{
return new Page().ClientScript.GetWebResourceUrl(typeof(WebReport), string.Format("FastReport.Web.Resources.Templates.{0}", resName));
}
}
}