WebReport.cs 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931
  1. using FastReport.Data;
  2. using FastReport.Export.Html;
  3. using FastReport.Utils;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Drawing.Design;
  11. using System.IO;
  12. using System.Net;
  13. using System.Text;
  14. using System.Web;
  15. using System.Web.Caching;
  16. using System.Web.UI;
  17. using System.Web.UI.WebControls;
  18. using System.Xml.Serialization;
  19. namespace FastReport.Web
  20. {
  21. /// <summary>
  22. /// Represents the Web Report.
  23. /// </summary>
  24. [Designer("FastReport.VSDesign.WebReportComponentDesigner, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL")]
  25. [ToolboxBitmap(typeof(WebReport), "Resources.Report.bmp")]
  26. public partial class WebReport : WebControl, INamingContainer
  27. {
  28. #region Private fields
  29. private string fReportGuid;
  30. private WebToolbar fToolbar;
  31. private int currentReportIndex = -1;
  32. private List<ReportTab> tabs;
  33. private bool fPreviewMode = false;
  34. private WebReportCache cache;
  35. private WebRes reportRes = new WebRes();
  36. #endregion Private fields
  37. /// <inheritdoc/>
  38. public override Unit Width
  39. {
  40. get {
  41. return base.Width;
  42. }
  43. set {
  44. Prop.WidthString = value.ToString();
  45. base.Width = value;
  46. }
  47. }
  48. /// <inheritdoc/>
  49. public override Unit Height
  50. {
  51. get {
  52. return base.Height;
  53. }
  54. set {
  55. Prop.HeightString = value.ToString();
  56. base.Height = value;
  57. }
  58. }
  59. internal WebRes ReportRes
  60. {
  61. get { return reportRes; }
  62. }
  63. #region Public properties
  64. #region Layout
  65. /// <summary>
  66. /// Used only if layers mode is off
  67. /// </summary>
  68. [DefaultValue(false)]
  69. [Category("Layout")]
  70. [Browsable(true)]
  71. public bool AutoWidth
  72. {
  73. get { return Prop.AutoWidth; }
  74. set { Prop.AutoWidth = value; }
  75. }
  76. /// <summary>
  77. /// Used only if layers mode is off
  78. /// </summary>
  79. [DefaultValue(false)]
  80. [Category("Layout")]
  81. [Browsable(true)]
  82. public bool AutoHeight
  83. {
  84. get { return Prop.AutoHeight; }
  85. set { Prop.AutoHeight = value; }
  86. }
  87. /// <summary>
  88. /// Enable or disable inline object registration
  89. /// </summary>
  90. [DefaultValue(false)]
  91. [Category("Layout")]
  92. [Browsable(true)]
  93. public bool InlineRegistration
  94. {
  95. get { return Prop.InlineRegistration; }
  96. set { Prop.InlineRegistration = value; }
  97. }
  98. /// <summary>
  99. ///
  100. /// </summary>
  101. [DefaultValue(false)]
  102. [Category("Layout")]
  103. [Browsable(true)]
  104. public bool EnableMargins
  105. {
  106. get { return Prop.EnableMargins; }
  107. set { Prop.EnableMargins = value; }
  108. }
  109. /// <summary>
  110. /// Enable or disable using of external jQuery library
  111. /// </summary>
  112. [DefaultValue(false)]
  113. [Category("Layout")]
  114. [Browsable(true)]
  115. public bool ExternalJquery
  116. {
  117. get { return Prop.ExternalJquery; }
  118. set { Prop.ExternalJquery = value; }
  119. }
  120. /// <summary>
  121. /// Enable or disable layers mode visualisation
  122. /// </summary>
  123. [DefaultValue(true)]
  124. [Category("Layout")]
  125. [Browsable(true)]
  126. public bool Layers
  127. {
  128. get { return Prop.Layers; }
  129. set { Prop.Layers = value; }
  130. }
  131. /// <summary>
  132. /// Gets or sets Padding of Report section
  133. /// </summary>
  134. [Category("Layout")]
  135. [Browsable(true)]
  136. public System.Windows.Forms.Padding Padding
  137. {
  138. get { return Prop.Padding; }
  139. set { Prop.Padding = value; }
  140. }
  141. #endregion Layout
  142. #region Network
  143. /// <summary>
  144. /// Timeout in seconds for automatic refresh of report. Zero value disable auto-refresh.
  145. /// </summary>
  146. [Category("Network")]
  147. [DefaultValue(0)]
  148. [Browsable(true)]
  149. public int RefreshTimeout
  150. {
  151. get { return Prop.RefreshTimeout; }
  152. set { Prop.RefreshTimeout = value; }
  153. }
  154. /// <summary>
  155. /// Delay in cache in minutes
  156. /// </summary>
  157. [Category("Network")]
  158. [DefaultValue(60)]
  159. [Browsable(true)]
  160. public int CacheDelay
  161. {
  162. get { return Prop.CacheDelay; }
  163. set { Prop.CacheDelay = value; }
  164. }
  165. /// <summary>
  166. /// Priority of items in cache
  167. /// </summary>
  168. [Category("Network")]
  169. [DefaultValue(CacheItemPriority.Normal)]
  170. [Browsable(true)]
  171. public CacheItemPriority CachePriority
  172. {
  173. get { return Prop.CachePriority; }
  174. set { Prop.CachePriority = value; }
  175. }
  176. /// <summary>
  177. /// Enable or disable the multiple instances environment
  178. /// </summary>
  179. [Category("Network")]
  180. [DefaultValue(false)]
  181. [Browsable(true)]
  182. public bool CloudEnvironmet
  183. {
  184. get { return Prop.CloudEnvironmet; }
  185. set { Prop.CloudEnvironmet = value; }
  186. }
  187. internal static ScriptSecurity ScriptSecurity = null;
  188. #endregion Network
  189. #region Designer
  190. /// <summary>
  191. /// Enable the Report Designer
  192. /// </summary>
  193. [DefaultValue(false)]
  194. [Category("Designer")]
  195. [Browsable(true)]
  196. public bool DesignReport
  197. {
  198. get { return Prop.DesignReport; }
  199. set { Prop.DesignReport = value; }
  200. }
  201. /// <summary>
  202. /// Enable code editor in the Report Designer
  203. /// </summary>
  204. [DefaultValue(false)]
  205. [Category("Designer")]
  206. [Browsable(true)]
  207. public bool DesignScriptCode
  208. {
  209. get { return Prop.DesignScriptCode; }
  210. set { Prop.DesignScriptCode = value; }
  211. }
  212. /// <summary>
  213. /// Gets or sets path to the Report Designer
  214. /// </summary>
  215. [DefaultValue("~/WebReportDesigner/index.html")]
  216. [Category("Designer")]
  217. [Browsable(true)]
  218. public string DesignerPath
  219. {
  220. get { return Prop.DesignerPath; }
  221. set { Prop.DesignerPath = value; }
  222. }
  223. /// <summary>
  224. /// Gets or sets path to a folder for save designed reports
  225. /// If value is empty then designer posts saved report in variable ReportFile on call the DesignerSaveCallBack
  226. /// </summary>
  227. [DefaultValue("")]
  228. [Category("Designer")]
  229. [Browsable(true)]
  230. public string DesignerSavePath
  231. {
  232. get { return Prop.DesignerSavePath; }
  233. set { Prop.DesignerSavePath = value; }
  234. }
  235. /// <summary>
  236. /// Gets or sets path to callback page after Save from Designer
  237. /// </summary>
  238. [DefaultValue("")]
  239. [Category("Designer")]
  240. [Browsable(true)]
  241. public string DesignerSaveCallBack
  242. {
  243. get { return Prop.DesignerSaveCallBack; }
  244. set { Prop.DesignerSaveCallBack = value; }
  245. }
  246. /// <summary>
  247. /// Gets or sets the locale of Designer
  248. /// </summary>
  249. [DefaultValue("")]
  250. [Category("Designer")]
  251. [Browsable(true)]
  252. public string DesignerLocale
  253. {
  254. get { return Prop.DesignerLocale; }
  255. set { Prop.DesignerLocale = value; }
  256. }
  257. /// <summary>
  258. /// Gets or sets the text of configuration of Online Designer
  259. /// </summary>
  260. [DefaultValue("")]
  261. [Category("Designer")]
  262. [Browsable(true)]
  263. public string DesignerConfig
  264. {
  265. get { return Prop.DesignerConfig; }
  266. set { Prop.DesignerConfig = value; }
  267. }
  268. #endregion Designer
  269. #region Report
  270. /// <summary>
  271. /// Report Resource String.
  272. /// </summary>
  273. [DefaultValue("")]
  274. [Category("Report")]
  275. [Browsable(true)]
  276. public string ReportResourceString
  277. {
  278. get { return Prop.ReportResourceString; }
  279. set { Prop.ReportResourceString = value; }
  280. }
  281. /// <summary>
  282. /// Gets or sets report data source(s).
  283. /// </summary>
  284. /// <remarks>
  285. /// To pass several datasources, use ';' delimiter, for example:
  286. /// "sqlDataSource1;sqlDataSource2"
  287. /// </remarks>
  288. [DefaultValue("")]
  289. [Category("Report")]
  290. [Browsable(true)]
  291. public string ReportDataSources
  292. {
  293. get { return Prop.ReportDataSources; }
  294. set { Prop.ReportDataSources = value; }
  295. }
  296. /// <summary>
  297. /// Switches the pictures visibility in report
  298. /// </summary>
  299. [DefaultValue(true)]
  300. [Category("Report")]
  301. [Browsable(true)]
  302. public bool Pictures
  303. {
  304. get { return Prop.Pictures; }
  305. set { Prop.Pictures = value; }
  306. }
  307. /// <summary>
  308. /// Enables or disables embedding pictures in HTML (inline HTML5 images).
  309. /// </summary>
  310. [Category("Report")]
  311. [DefaultValue(false)]
  312. [Browsable(true)]
  313. public bool EmbedPictures
  314. {
  315. get { return Prop.EmbedPictures; }
  316. set { Prop.EmbedPictures = value; }
  317. }
  318. /// <summary>
  319. /// Switches the pages layout between multiple pages (false) and single page (true).
  320. /// </summary>
  321. [DefaultValue(false)]
  322. [Category("Report")]
  323. [Browsable(true)]
  324. public bool SinglePage
  325. {
  326. get { return Prop.SinglePage; }
  327. set { Prop.SinglePage = value; }
  328. }
  329. /// <summary>
  330. /// Gets or sets the name of report file.
  331. /// </summary>
  332. [DefaultValue("")]
  333. [Category("Report")]
  334. [Browsable(true)]
  335. [Editor("FastReport.VSDesign.ReportFileEditor, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL", typeof(UITypeEditor))]
  336. public string ReportFile
  337. {
  338. get { return Prop.ReportFile; }
  339. set { Prop.ReportFile = value; }
  340. }
  341. /// <summary>
  342. /// Gets or sets the default path for reports (including inherited).
  343. /// </summary>
  344. public string ReportPath
  345. {
  346. get { return Prop.ReportPath; }
  347. set { Prop.ReportPath = value; }
  348. }
  349. /// <summary>
  350. /// Gets or sets the name of localization file.
  351. /// </summary>
  352. [DefaultValue("")]
  353. [Category("Report")]
  354. [Browsable(true)]
  355. [Editor("FastReport.VSDesign.LocalizationFileEditor, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL", typeof(UITypeEditor))]
  356. public string LocalizationFile
  357. {
  358. get { return Prop.LocalizationFile; }
  359. set
  360. {
  361. Prop.LocalizationFile = value;
  362. }
  363. }
  364. /// <summary>
  365. /// Sets the zoom scale factor of previewed page between 0..1f.
  366. /// </summary>
  367. [DefaultValue(1f)]
  368. [Category("Report")]
  369. [Browsable(true)]
  370. public float Zoom
  371. {
  372. get { return Prop.Zoom; }
  373. set { Prop.Zoom = value; }
  374. }
  375. /// <summary>
  376. /// Sets the zoom mode of previewed page.
  377. /// </summary>
  378. [DefaultValue(ZoomMode.Scale)]
  379. [Category("Report")]
  380. [Browsable(true)]
  381. public ZoomMode ZoomMode
  382. {
  383. get { return Prop.ZoomMode; }
  384. set { Prop.ZoomMode = value; }
  385. }
  386. /// <summary>
  387. /// Enables or disables showing the report after call Prepare.
  388. /// </summary>
  389. [DefaultValue(false)]
  390. [Category("Report")]
  391. [Browsable(true)]
  392. public bool ShowAfterPrepare
  393. {
  394. get { return Prop.ShowAfterPrepare; }
  395. set { Prop.ShowAfterPrepare = value; }
  396. }
  397. /// <summary>
  398. /// Enables or disables showing any debug information on errors.
  399. /// </summary>
  400. [DefaultValue(false)]
  401. [Category("Report")]
  402. [Browsable(true)]
  403. public bool Debug
  404. {
  405. get { return Prop.Debug; }
  406. set { Prop.Debug = value; }
  407. }
  408. /// <summary>
  409. /// Gets or sets the log file path.
  410. /// </summary>
  411. [DefaultValue("")]
  412. [Category("Report")]
  413. [Browsable(true)]
  414. public string LogFile
  415. {
  416. get { return Prop.LogFile; }
  417. set { Prop.LogFile = value; }
  418. }
  419. /// <summary>
  420. /// Enables or disables unlimited width of report pages. This options overrides the report page property value
  421. /// when it set to true.
  422. /// </summary>
  423. [DefaultValue(false)]
  424. [Category("Report")]
  425. [Browsable(true)]
  426. public bool UnlimitedWidth
  427. {
  428. get { return Prop.UnlimitedWidth; }
  429. set { Prop.UnlimitedWidth = value; }
  430. }
  431. /// <summary>
  432. /// Enables or disables unlimited height of report pages. This options overrides the report page property value
  433. /// when it set to true.
  434. /// </summary>
  435. [DefaultValue(false)]
  436. [Category("Report")]
  437. [Browsable(true)]
  438. public bool UnlimitedHeight
  439. {
  440. get { return Prop.UnlimitedHeight; }
  441. set { Prop.UnlimitedHeight = value; }
  442. }
  443. /// <summary>
  444. /// Enables or disables showing the report dialogs.
  445. /// </summary>
  446. [DefaultValue(true)]
  447. [Category("Report")]
  448. [Browsable(true)]
  449. public bool Dialogs
  450. {
  451. get { return Prop.Dialogs; }
  452. set { Prop.Dialogs = value; }
  453. }
  454. #endregion Report
  455. #region Toolbar
  456. /// <summary>
  457. /// Sets the toolbar style - small or large.
  458. /// </summary>
  459. [DefaultValue(ToolbarStyle.Large)]
  460. [Category("Toolbar")]
  461. [Browsable(true)]
  462. public ToolbarStyle ToolbarStyle
  463. {
  464. get { return Prop.ToolbarStyle; }
  465. set { Prop.ToolbarStyle = value; }
  466. }
  467. /// <summary>
  468. /// Sets the toolbar icons style.
  469. /// </summary>
  470. [DefaultValue(ToolbarIconsStyle.Red)]
  471. [Category("Toolbar")]
  472. [Browsable(true)]
  473. public ToolbarIconsStyle ToolbarIconsStyle
  474. {
  475. get { return Prop.ToolbarIconsStyle; }
  476. set { Prop.ToolbarIconsStyle = value; }
  477. }
  478. /// <summary>
  479. /// Sets the toolbar background style.
  480. /// </summary>
  481. [DefaultValue(ToolbarBackgroundStyle.Light)]
  482. [Category("Toolbar")]
  483. [Browsable(true)]
  484. public ToolbarBackgroundStyle ToolbarBackgroundStyle
  485. {
  486. get { return Prop.ToolbarBackgroundStyle; }
  487. set { Prop.ToolbarBackgroundStyle = value; }
  488. }
  489. /// <summary>
  490. /// Switches the toolbar visibility.
  491. /// </summary>
  492. [DefaultValue(true)]
  493. [Category("Toolbar")]
  494. [Browsable(true)]
  495. public bool ShowToolbar
  496. {
  497. get { return Prop.ShowToolbar; }
  498. set { Prop.ShowToolbar = value; }
  499. }
  500. /// <summary>
  501. /// Switches the bottom toolbar visibility.
  502. /// </summary>
  503. [DefaultValue(false)]
  504. [Category("Toolbar")]
  505. [Browsable(true)]
  506. public bool ShowBottomToolbar
  507. {
  508. get { return Prop.ShowBottomToolbar; }
  509. set { Prop.ShowBottomToolbar = value; }
  510. }
  511. /// <summary>
  512. /// Sets the path to the custom buttons on site.
  513. /// </summary>
  514. /// <remarks>
  515. /// Pictures should be named:
  516. /// Checkbox.gif, Progress.gif, toolbar.png, toolbar_background.png, toolbar_big.png, toolbar_disabled.png, toolbar_disabled.png
  517. /// </remarks>
  518. [DefaultValue("")]
  519. [Category("Toolbar")]
  520. [Browsable(true)]
  521. //[UrlProperty]
  522. [Editor("FastReport.VSDesign.ReportFileEditor, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL", typeof(UITypeEditor))]
  523. public string ButtonsPath
  524. {
  525. get { return Prop.ButtonsPath; }
  526. set { Prop.ButtonsPath = value; }
  527. }
  528. /// <summary>
  529. /// Switches the visibility of Exports in toolbar.
  530. /// </summary>
  531. [DefaultValue(true)]
  532. [Category("Toolbar")]
  533. [Browsable(true)]
  534. public bool ShowExports
  535. {
  536. get { return Prop.ShowExports; }
  537. set { Prop.ShowExports = value; }
  538. }
  539. /// <summary>
  540. /// Switches the visibility of Print button in toolbar.
  541. /// </summary>
  542. [DefaultValue(true)]
  543. [Category("Toolbar")]
  544. [Browsable(true)]
  545. public bool ShowPrint
  546. {
  547. get { return Prop.ShowPrint; }
  548. set { Prop.ShowPrint = value; }
  549. }
  550. /// <summary>
  551. /// Switches the visibility of First Button in toolbar.
  552. /// </summary>
  553. [DefaultValue(true)]
  554. [Category("Toolbar")]
  555. [Browsable(true)]
  556. public bool ShowFirstButton
  557. {
  558. get { return Prop.ShowFirstButton; }
  559. set { Prop.ShowFirstButton = value; }
  560. }
  561. /// <summary>
  562. /// Switches the visibility of Previous Button in toolbar.
  563. /// </summary>
  564. [DefaultValue(true)]
  565. [Category("Toolbar")]
  566. [Browsable(true)]
  567. public bool ShowPrevButton
  568. {
  569. get { return Prop.ShowPrevButton; }
  570. set { Prop.ShowPrevButton = value; }
  571. }
  572. /// <summary>
  573. /// Switches the visibility of Next Button in toolbar.
  574. /// </summary>
  575. [DefaultValue(true)]
  576. [Category("Toolbar")]
  577. [Browsable(true)]
  578. public bool ShowNextButton
  579. {
  580. get { return Prop.ShowNextButton; }
  581. set { Prop.ShowNextButton = value; }
  582. }
  583. /// <summary>
  584. /// Switches the visibility of Last Button in toolbar.
  585. /// </summary>
  586. [DefaultValue(true)]
  587. [Category("Toolbar")]
  588. [Browsable(true)]
  589. public bool ShowLastButton
  590. {
  591. get { return Prop.ShowLastButton; }
  592. set { Prop.ShowLastButton = value; }
  593. }
  594. /// <summary>
  595. /// Switches the visibility of Zoom in toolbar.
  596. /// </summary>
  597. [DefaultValue(true)]
  598. [Category("Toolbar")]
  599. [Browsable(true)]
  600. public bool ShowZoomButton
  601. {
  602. get { return Prop.ShowZoomButton; }
  603. set { Prop.ShowZoomButton = value; }
  604. }
  605. /// <summary>
  606. /// Switches the visibility of Refresh in toolbar.
  607. /// </summary>
  608. [DefaultValue(true)]
  609. [Category("Toolbar")]
  610. [Browsable(true)]
  611. public bool ShowRefreshButton
  612. {
  613. get { return Prop.ShowRefreshButton; }
  614. set { Prop.ShowRefreshButton = value; }
  615. }
  616. /// <summary>
  617. /// Switches the visibility of Page Number in toolbar.
  618. /// </summary>
  619. [DefaultValue(true)]
  620. [Category("Toolbar")]
  621. [Browsable(true)]
  622. public bool ShowPageNumber
  623. {
  624. get { return Prop.ShowPageNumber; }
  625. set { Prop.ShowPageNumber = value; }
  626. }
  627. /// <summary>
  628. /// Switches the visibility of closing buttons for Tabs.
  629. /// </summary>
  630. [DefaultValue(false)]
  631. [Category("Toolbar")]
  632. [Browsable(true)]
  633. public bool ShowTabCloseButton
  634. {
  635. get { return Prop.ShowTabCloseButton; }
  636. set { Prop.ShowTabCloseButton = value; }
  637. }
  638. /// <summary>
  639. /// Switches the visibility of Back buttons.
  640. /// </summary>
  641. [DefaultValue(false)]
  642. [Category("Toolbar")]
  643. [Browsable(true)]
  644. public bool ShowBackButton
  645. {
  646. get { return Prop.ShowBackButton; }
  647. set { Prop.ShowBackButton = value; }
  648. }
  649. /// <summary>
  650. /// Selects the position of tabs.
  651. /// </summary>
  652. [DefaultValue(TabPosition.InsideToolbar)]
  653. [Category("Toolbar")]
  654. [Browsable(true)]
  655. public TabPosition TabPosition
  656. {
  657. get { return Prop.TabPosition; }
  658. set { Prop.TabPosition = value; }
  659. }
  660. /// <summary>
  661. /// Sets the Toolbar background color.
  662. /// </summary>
  663. [DefaultValue(0xECECEC)]
  664. [Category("Toolbar")]
  665. [Browsable(true)]
  666. public System.Drawing.Color ToolbarColor
  667. {
  668. get { return Prop.ToolbarColor; }
  669. set { Prop.ToolbarColor = value; }
  670. }
  671. /// <summary>
  672. /// Switches the outline visibility.
  673. /// </summary>
  674. [DefaultValue(false)]
  675. [Category("Toolbar")]
  676. [Browsable(true)]
  677. public bool ShowOutline
  678. {
  679. get { return Prop.ShowOutline; }
  680. set { Prop.ShowOutline = value; }
  681. }
  682. #endregion Toolbar
  683. #region Print
  684. /// <summary>
  685. /// Enable or disable print in PDF.
  686. /// </summary>
  687. [DefaultValue(true)]
  688. [Category("Print")]
  689. [Browsable(true)]
  690. public bool PrintInPdf
  691. {
  692. get { return Prop.PrintInPdf; }
  693. set { Prop.PrintInPdf = value; }
  694. }
  695. /// <summary>
  696. /// Enable or disable print in browser.
  697. /// </summary>
  698. [DefaultValue(true)]
  699. [Category("Print")]
  700. [Browsable(true)]
  701. public bool PrintInBrowser
  702. {
  703. get { return Prop.PrintInBrowser; }
  704. set { Prop.PrintInBrowser = value; }
  705. }
  706. /// <summary>
  707. /// Sets the width of print window.
  708. /// </summary>
  709. [DefaultValue("700px")]
  710. [Category("Print")]
  711. [Browsable(true)]
  712. public string PrintWindowWidth
  713. {
  714. get { return Prop.PrintWindowWidth; }
  715. set { Prop.PrintWindowWidth = value; }
  716. }
  717. /// <summary>
  718. /// Sets the height of print window.
  719. /// </summary>
  720. [DefaultValue("500px")]
  721. [Category("Print")]
  722. [Browsable(true)]
  723. public string PrintWindowHeight
  724. {
  725. get { return Prop.PrintWindowHeight; }
  726. set { Prop.PrintWindowWidth = value; }
  727. }
  728. #endregion Print
  729. #region Hidden Properties
  730. [Browsable(false)]
  731. internal bool ControlVisible
  732. {
  733. get { return Prop.ControlVisible; }
  734. set { Prop.ControlVisible = value; }
  735. }
  736. [Browsable(false)]
  737. internal List<ReportTab> ReportTabs
  738. {
  739. get
  740. {
  741. InitTabs();
  742. return tabs;
  743. }
  744. set
  745. {
  746. tabs = value;
  747. InitTabs();
  748. }
  749. }
  750. /// <summary>
  751. /// Direct access to the Properties of report object.
  752. /// </summary>
  753. [Browsable(false)]
  754. internal WebReportProperties Prop
  755. {
  756. get
  757. {
  758. return ReportTabs[currentReportIndex].Properties;
  759. }
  760. set
  761. {
  762. ReportTabs[currentReportIndex].Properties = value;
  763. }
  764. }
  765. /// <summary>
  766. /// Direct access to the Tabs.
  767. /// </summary>
  768. [Browsable(false)]
  769. public List<ReportTab> Tabs
  770. {
  771. get
  772. {
  773. return ReportTabs;
  774. }
  775. }
  776. /// <summary>
  777. /// Gets or sets the current tab index.
  778. /// </summary>
  779. [Browsable(false)]
  780. public int CurrentTabIndex
  781. {
  782. get
  783. {
  784. return currentReportIndex;
  785. }
  786. set
  787. {
  788. currentReportIndex = value;
  789. Toolbar.CurrentTabIndex = currentReportIndex;
  790. }
  791. }
  792. /// <summary>
  793. /// Gets the current tab.
  794. /// </summary>
  795. [Browsable(false)]
  796. public ReportTab CurrentTab
  797. {
  798. get
  799. {
  800. return ReportTabs[currentReportIndex];
  801. }
  802. }
  803. /// <summary>
  804. ///
  805. /// </summary>
  806. [Browsable(false)]
  807. internal WebToolbar Toolbar
  808. {
  809. get
  810. {
  811. if (fToolbar == null)
  812. {
  813. fToolbar = new WebToolbar(
  814. ReportGuid,
  815. ReportTabs,
  816. (this.Width.Type == UnitType.Pixel) && (this.Height.Type == UnitType.Pixel),
  817. reportRes);
  818. fToolbar.BackgroundColor = WebUtils.RGBAColor(this.BackColor);
  819. }
  820. return fToolbar;
  821. }
  822. set
  823. {
  824. fToolbar = value;
  825. }
  826. }
  827. /// <summary>
  828. /// Enables the preview mode for working together the Online Designer.
  829. /// </summary>
  830. [Browsable(false)]
  831. public bool PreviewMode
  832. {
  833. get { return fPreviewMode; }
  834. set { fPreviewMode = value; }
  835. }
  836. /// <summary>
  837. /// Direct access to Report object.
  838. /// </summary>
  839. [Browsable(false)]
  840. public Report Report
  841. {
  842. get
  843. {
  844. return ReportTabs[currentReportIndex].Report;
  845. }
  846. set
  847. {
  848. ReportTabs[currentReportIndex].Report = value;
  849. }
  850. }
  851. /// <summary>
  852. /// Gets total pages of current report.
  853. /// </summary>
  854. [Browsable(false)]
  855. public int TotalPages
  856. {
  857. get
  858. {
  859. if (Report.PreparedPages != null)
  860. return Report.PreparedPages.Count;
  861. else
  862. return 0;
  863. }
  864. }
  865. /// <summary>
  866. /// Gets or sets current state of report.
  867. /// </summary>
  868. [Browsable(false)]
  869. public ReportState State
  870. {
  871. get { return Prop.State; }
  872. set { Prop.State = value; }
  873. }
  874. /// <summary>
  875. /// Returns true when report done. This property may be set in true for forcing load the prepared report.
  876. /// </summary>
  877. [Browsable(false)]
  878. public bool ReportDone
  879. {
  880. get { return Prop.ReportDone; }
  881. set { Prop.ReportDone = value; }
  882. }
  883. /// <summary>
  884. /// Gets or sets number of current page.
  885. /// </summary>
  886. [Browsable(false)]
  887. public int CurrentPage
  888. {
  889. get { return Prop.CurrentPage; }
  890. set { Prop.CurrentPage = value; }
  891. }
  892. /// <summary>
  893. /// Gets or sets guid of report.
  894. /// </summary>
  895. [Browsable(false)]
  896. public string ReportGuid
  897. {
  898. get
  899. {
  900. if (String.IsNullOrEmpty(fReportGuid))
  901. {
  902. fReportGuid = TryGetGUID();
  903. }
  904. return fReportGuid;
  905. }
  906. set { fReportGuid = value; }
  907. }
  908. /// <summary>
  909. /// Gets or sets the request headers.
  910. /// </summary>
  911. [Browsable(false)]
  912. public WebHeaderCollection RequestHeaders
  913. {
  914. get { return Prop.RequestHeaders; }
  915. set { Prop.RequestHeaders = value; }
  916. }
  917. /// <summary>
  918. /// Gets or sets the response headers.
  919. /// </summary>
  920. [Browsable(false)]
  921. public WebHeaderCollection ResponseHeaders
  922. {
  923. get { return Prop.ResponseHeaders; }
  924. set { Prop.ResponseHeaders = value; }
  925. }
  926. private string TryGetGUID()
  927. {
  928. string guid = String.Empty;
  929. if (this.Context != null && !String.IsNullOrEmpty(this.ID))
  930. {
  931. if (this.Context.Session != null && this.Context.Session[this.ID] != null)
  932. guid = this.Context.Session[this.ID] as string;
  933. }
  934. if (String.IsNullOrEmpty(guid))
  935. guid = WebUtils.GetGUID();
  936. return guid;
  937. }
  938. #endregion Hidden Properties
  939. #endregion Public properties
  940. #region Events
  941. /// <summary>
  942. /// Occurs when report execution is started.
  943. /// </summary>
  944. [Browsable(true)]
  945. public event EventHandler StartReport;
  946. /// <summary>
  947. /// Occurs when designed report saving is started.
  948. /// </summary>
  949. [Browsable(true)]
  950. public event EventHandler<SaveDesignedReportEventArgs> SaveDesignedReport;
  951. /// <summary>
  952. /// Occurs when report drawing is started.
  953. /// </summary>
  954. [Browsable(true)]
  955. public event EventHandler<CustomDrawEventArgs> CustomDraw;
  956. /// <summary>
  957. /// Occurs when report auth is started.
  958. /// </summary>
  959. [Browsable(true)]
  960. public event EventHandler<CustomAuthEventArgs> CustomAuth;
  961. /// <summary>
  962. /// Runs the OnCustomDraw event.
  963. /// </summary>
  964. /// <param name="e">CustomDrawEventArgs object.</param>
  965. public void OnCustomDraw(CustomDrawEventArgs e)
  966. {
  967. if (CustomDraw != null)
  968. {
  969. CustomDraw(this, e);
  970. }
  971. }
  972. /// <summary>
  973. /// Runs the OnCustomAuth event.
  974. /// </summary>
  975. /// <param name="e">CustomAuthEventArgs object.</param>
  976. public void OnCustomAuth(CustomAuthEventArgs e)
  977. {
  978. if (CustomAuth != null)
  979. {
  980. CustomAuth(this, e);
  981. }
  982. }
  983. #endregion Events
  984. /// <summary>
  985. /// Runs the StartReport event.
  986. /// </summary>
  987. /// <param name="e">EventArgs object.</param>
  988. public void OnStartReport(EventArgs e)
  989. {
  990. if (StartReport != null)
  991. {
  992. StartReport(this, e);
  993. }
  994. }
  995. /// <summary>
  996. /// Runs the SaveDesignedReport event.
  997. /// </summary>
  998. /// <param name="e">SaveDesignedReportEventArgs object.</param>
  999. public void OnSaveDesignedReport(SaveDesignedReportEventArgs e)
  1000. {
  1001. if (SaveDesignedReport != null)
  1002. {
  1003. SaveDesignedReport(this, e);
  1004. }
  1005. }
  1006. #region Navigation
  1007. /// <summary>
  1008. /// Forces going to the next report page.
  1009. /// </summary>
  1010. public void NextPage()
  1011. {
  1012. if (CurrentPage < TotalPages - 1)
  1013. CurrentPage++;
  1014. }
  1015. /// <summary>
  1016. /// Forces going to the previous report page.
  1017. /// </summary>
  1018. public void PrevPage()
  1019. {
  1020. if (CurrentPage > 0)
  1021. CurrentPage--;
  1022. }
  1023. /// <summary>
  1024. /// Forces going to the first report page.
  1025. /// </summary>
  1026. public void FirstPage()
  1027. {
  1028. CurrentPage = 0;
  1029. }
  1030. /// <summary>
  1031. /// Forces going to the last report page.
  1032. /// </summary>
  1033. public void LastPage()
  1034. {
  1035. CurrentPage = TotalPages - 1;
  1036. }
  1037. /// <summary>
  1038. /// Forces going to the "value" report page.
  1039. /// </summary>
  1040. public void SetPage(int value)
  1041. {
  1042. if (value >= 0 && value < TotalPages)
  1043. CurrentPage = value;
  1044. }
  1045. #endregion Navigation
  1046. /// <summary>
  1047. /// Prepares the report.
  1048. /// </summary>
  1049. public void Prepare()
  1050. {
  1051. //this.Controls.Clear();
  1052. Refresh();
  1053. }
  1054. /// <summary>
  1055. /// Forces refreshing of report.
  1056. /// </summary>
  1057. public void Refresh()
  1058. {
  1059. CurrentPage = 0;
  1060. Prop.CurrentForm = 0;
  1061. State = ReportState.Empty;
  1062. ControlVisible = true;
  1063. ShowAfterPrepare = false;
  1064. }
  1065. /// <summary>
  1066. /// Adds the new report tab.
  1067. /// </summary>
  1068. /// <param name="report"></param>
  1069. /// <param name="name"></param>
  1070. /// <returns></returns>
  1071. public ReportTab AddTab(Report report, string name)
  1072. {
  1073. return AddTab(report, name, false);
  1074. }
  1075. /// <summary>
  1076. /// Adds the new report tab.
  1077. /// </summary>
  1078. /// <param name="report"></param>
  1079. /// <returns></returns>
  1080. public ReportTab AddTab(Report report)
  1081. {
  1082. return AddTab(report, String.Empty);
  1083. }
  1084. /// <summary>
  1085. /// Adds the new report tab.
  1086. /// </summary>
  1087. /// <param name="report"></param>
  1088. /// <param name="name"></param>
  1089. /// <param name="reportDone"></param>
  1090. /// <returns></returns>
  1091. public ReportTab AddTab(Report report, string name, bool reportDone)
  1092. {
  1093. return AddTab(report, name, reportDone, false);
  1094. }
  1095. /// <summary>
  1096. /// Adds the new report tab.
  1097. /// </summary>
  1098. /// <param name="report"></param>
  1099. /// <param name="name"></param>
  1100. /// <param name="reportDone"></param>
  1101. /// <param name="needParent"></param>
  1102. /// <returns></returns>
  1103. public ReportTab AddTab(Report report, string name, bool reportDone, bool needParent)
  1104. {
  1105. ReportTab tab = new ReportTab(report);
  1106. tab.Properties.Assign(tabs[0].Properties);
  1107. tab.Properties.ControlID = tabs[0].Properties.ControlID;
  1108. tab.Properties.HandlerURL = WebUtils.GetBasePath(this.Context) + WebUtils.HandlerFileName;
  1109. tab.Properties.ReportDone = reportDone;
  1110. tab.Properties.ShowRefreshButton = !reportDone;
  1111. tab.NeedParent = needParent;
  1112. if (!String.IsNullOrEmpty(name))
  1113. tab.Name = name;
  1114. ReportTabs.Add(tab);
  1115. return tab;
  1116. }
  1117. #region Protected methods
  1118. private Control FindControlRecursive(Control root, string id)
  1119. {
  1120. if (root.ID == id)
  1121. return root;
  1122. foreach (Control ctl in root.Controls)
  1123. {
  1124. Control foundCtl = FindControlRecursive(ctl, id);
  1125. if (foundCtl != null)
  1126. return foundCtl;
  1127. }
  1128. return null;
  1129. }
  1130. internal void RegisterData(Report report)
  1131. {
  1132. if (Page != null)
  1133. {
  1134. string[] dataSources = ReportDataSources.Split(';');
  1135. foreach (string dataSource in dataSources)
  1136. {
  1137. IDataSource ds = FindControlRecursive(Page, dataSource) as IDataSource;
  1138. if (ds == null)
  1139. continue;
  1140. string dataName = (ds as Control).ID;
  1141. RegisterDataAsp(report, ds, dataName);
  1142. }
  1143. }
  1144. }
  1145. /// <summary>
  1146. /// Registers the ASP.NET application data to use it in the report.
  1147. /// </summary>
  1148. /// <param name="report">The <b>Report</b> object.</param>
  1149. /// <param name="data">The application data.</param>
  1150. /// <param name="name">The name of the data.</param>
  1151. public void RegisterDataAsp(Report report, IDataSource data, string name)
  1152. {
  1153. aspDataName = name;
  1154. this.report = report;
  1155. DataSourceView view = data.GetView("");
  1156. if (view != null)
  1157. view.Select(DataSourceSelectArguments.Empty, new DataSourceViewSelectCallback(RegisterDataAsp));
  1158. }
  1159. private string aspDataName;
  1160. private Report report;
  1161. private void RegisterDataAsp(IEnumerable data)
  1162. {
  1163. if (data != null)
  1164. RegisterDataAsp(report, data, aspDataName);
  1165. }
  1166. /// <summary>
  1167. /// Registers the ASP.NET application data to use it in the report.
  1168. /// </summary>
  1169. /// <param name="report">The <b>Report</b> object.</param>
  1170. /// <param name="data">The application data.</param>
  1171. /// <param name="name">The name of the data.</param>
  1172. public void RegisterDataAsp(Report report, IEnumerable data, string name)
  1173. {
  1174. DataComponentBase existingDs = report.Dictionary.FindDataComponent(name);
  1175. if (existingDs is ViewDataSource && data is DataView)
  1176. {
  1177. // compatibility with old FR versions (earlier than 1.1.45)
  1178. report.Dictionary.RegisterDataView(data as DataView, name, true);
  1179. }
  1180. else
  1181. {
  1182. // in a new versions, always register the business object
  1183. report.Dictionary.RegisterBusinessObject(data, name, 1, true);
  1184. }
  1185. }
  1186. /// <inheritdoc/>
  1187. protected override void OnLoad(EventArgs e)
  1188. {
  1189. this.EnsureChildControls();
  1190. if (this.Context != null)
  1191. {
  1192. this.Context.Session[this.ID] = ReportGuid;
  1193. }
  1194. base.OnLoad(e);
  1195. }
  1196. /// <inheritdoc/>
  1197. protected override void OnUnload(EventArgs e)
  1198. {
  1199. cache.CleanFileStorage();
  1200. base.OnUnload(e);
  1201. }
  1202. private void InitTabs()
  1203. {
  1204. if (tabs == null)
  1205. tabs = new List<ReportTab>();
  1206. if (tabs.Count == 0)
  1207. {
  1208. ReportTab item = new ReportTab();
  1209. item.Properties.ControlID = GetControlID();
  1210. item.Properties.HandlerURL = WebUtils.GetBasePath(this.Context) + WebUtils.HandlerFileName;
  1211. tabs.Add(item);
  1212. currentReportIndex = 0;
  1213. }
  1214. }
  1215. private string GetControlID()
  1216. {
  1217. return String.Concat(ReportGuid, DateTime.Now.Ticks.ToString());
  1218. }
  1219. private void InitReport()
  1220. {
  1221. if (!DesignMode)
  1222. Config.WebMode = true;
  1223. cache = new WebReportCache(Context);
  1224. Prop.ControlID = GetControlID();
  1225. if (!fPreviewMode)
  1226. {
  1227. // load report
  1228. WebReport oldweb = (WebReport)cache.GetObject(ReportGuid, this);
  1229. if (oldweb != null)
  1230. {
  1231. Report = oldweb.Report;
  1232. WebReportProperties storedProp = oldweb.Prop;
  1233. if (storedProp != null)
  1234. Prop = storedProp;
  1235. }
  1236. }
  1237. else
  1238. {
  1239. this.Width = Unit.Percentage(100);
  1240. this.Height = Unit.Percentage(100);
  1241. this.Toolbar.EnableFit = true;
  1242. }
  1243. if (ShowAfterPrepare)
  1244. ControlVisible = false;
  1245. cache.Delay = CacheDelay;
  1246. cache.Priority = CachePriority;
  1247. if (this.ID == null)
  1248. this.ID = ReportGuid;
  1249. }
  1250. /// <inheritdoc/>
  1251. protected override void OnInit(EventArgs e)
  1252. {
  1253. if (HttpContext.Current != null)
  1254. InitReport();
  1255. base.OnInit(e);
  1256. }
  1257. internal void Localize()
  1258. {
  1259. if (!String.IsNullOrEmpty(LocalizationFile))
  1260. {
  1261. string fileName = LocalizationFile;
  1262. if (!WebUtils.IsAbsolutePhysicalPath(fileName))
  1263. fileName = this.Context.Request.MapPath(fileName, base.AppRelativeTemplateSourceDirectory, true);
  1264. reportRes.LoadLocale(fileName);
  1265. }
  1266. }
  1267. /// <inheritdoc/>
  1268. protected override void AddAttributesToRender(HtmlTextWriter writer)
  1269. {
  1270. // remove width & height styles from html element
  1271. Unit width = Width;
  1272. Unit height = Height;
  1273. if (!DesignReport)
  1274. {
  1275. Width = new Unit();
  1276. Height = new Unit();
  1277. }
  1278. Style.Add("display", "inline-block");
  1279. base.AddAttributesToRender(writer);
  1280. if (!DesignReport)
  1281. {
  1282. Width = width;
  1283. Height = height;
  1284. }
  1285. }
  1286. /// <inheritdoc/>
  1287. protected override void RenderContents(HtmlTextWriter writer)
  1288. {
  1289. if (HttpContext.Current != null && !InlineRegistration && Page != null)
  1290. {
  1291. Toolbar.RegisterGlobals(Prop.ControlID, Page.ClientScript, this.GetType(), Prop.ExternalJquery);
  1292. if (!Page.ClientScript.IsClientScriptIncludeRegistered("fr_util"))
  1293. this.InlineRegistration = true;
  1294. }
  1295. // check for design time
  1296. if (HttpContext.Current == null)
  1297. RenderDesignModeNavigatorControls(writer);
  1298. else
  1299. { // Run-time
  1300. Prop.HandlerURL = WebUtils.GetBasePath(this.Context) + WebUtils.HandlerFileName;
  1301. if (Config.FullTrust)
  1302. {
  1303. WebUtils.CheckHandlersRuntime();
  1304. }
  1305. StringBuilder container = new StringBuilder();
  1306. if (Page == null || PreviewMode) // Razor
  1307. {
  1308. InitReport();
  1309. }
  1310. if (ControlVisible)
  1311. {
  1312. if (InlineRegistration)
  1313. {
  1314. container.AppendLine(Toolbar.GetInlineRegistration(Prop.ExternalJquery));
  1315. }
  1316. //Localize();
  1317. container.AppendLine(Toolbar.GetHtmlProgress(Prop.HandlerURL, Prop.ControlID, !DesignReport, this.Width, this.Height));
  1318. writer.WriteLine(container.ToString());
  1319. base.RenderContents(writer);
  1320. if (cache.WebFarmMode)
  1321. {
  1322. StringBuilder sb = new StringBuilder();
  1323. ReportProcess(sb, this.Context);
  1324. }
  1325. // save all objects
  1326. // cache.PutObject(ReportGuid, this);
  1327. cache.PutObject(Prop.ControlID, this);
  1328. }
  1329. }
  1330. }
  1331. #endregion Protected methods
  1332. #region DotNet 4 specific
  1333. #if DOTNET_4
  1334. /// <summary>
  1335. /// Returns the HTML code of report preview control.
  1336. /// </summary>
  1337. /// <returns>HtmlString object.</returns>
  1338. public HtmlString GetHtml()
  1339. {
  1340. StringBuilder sb = new StringBuilder();
  1341. HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb, System.Globalization.CultureInfo.InvariantCulture));
  1342. this.RenderControl(writer);
  1343. return new HtmlString(Toolbar.GetCss() + sb.ToString());
  1344. }
  1345. /// <summary>
  1346. /// Returns the code "<script>...</script>" for registration the necessary js libraries.
  1347. /// </summary>
  1348. /// <returns>HtmlString object.</returns>
  1349. public HtmlString Scripts()
  1350. {
  1351. return WebReportGlobals.Scripts();
  1352. }
  1353. /// <summary>
  1354. /// Returns the code for registration the necessary CSS.
  1355. /// </summary>
  1356. /// <returns>HtmlString object.</returns>
  1357. public HtmlString Styles()
  1358. {
  1359. return WebReportGlobals.Styles();
  1360. }
  1361. #endif
  1362. #endregion DotNet 4 specific
  1363. /// <summary>
  1364. /// Sets the size of WebReport object.
  1365. /// </summary>
  1366. /// <param name="width">Width of WebReport.</param>
  1367. /// <param name="height">Height of WebReport.</param>
  1368. /// <returns>WebReport object.</returns>
  1369. public WebReport SetSize(Unit width, Unit height)
  1370. {
  1371. this.Width = width;
  1372. this.Height = height;
  1373. return this;
  1374. }
  1375. /// <summary>
  1376. /// Sets the StartReport event handler.
  1377. /// </summary>
  1378. /// <param name="start">Event handler.</param>
  1379. /// <returns>WebReport object.</returns>
  1380. public WebReport SetStartEvent(EventHandler start)
  1381. {
  1382. StartReport += start;
  1383. return this;
  1384. }
  1385. /// <summary>
  1386. /// Sets the CustomDraw event handler.
  1387. /// </summary>
  1388. /// <param name="draw">Event handler.</param>
  1389. /// <returns>WebReport object.</returns>
  1390. public WebReport SetCustomDrawEvent(EventHandler<CustomDrawEventArgs> draw)
  1391. {
  1392. CustomDraw += draw;
  1393. return this;
  1394. }
  1395. /// <summary>
  1396. /// Sets the CustomAuth event handler.
  1397. /// </summary>
  1398. /// <param name="auth">Event handler.</param>
  1399. /// <returns>WebReport object.</returns>
  1400. public WebReport SetCustomAuthEvent(EventHandler<CustomAuthEventArgs> auth)
  1401. {
  1402. CustomAuth += auth;
  1403. return this;
  1404. }
  1405. #region Register Data
  1406. /// <summary>
  1407. /// Register the DataSet in report dictionary.
  1408. /// </summary>
  1409. /// <param name="data">DataSet object.</param>
  1410. /// <param name="name">Name for the registered data.</param>
  1411. /// <returns>WebReport object.</returns>
  1412. public WebReport RegisterData(DataSet data, string name)
  1413. {
  1414. this.Report.Dictionary.RegisterData(data, name, true);
  1415. return this;
  1416. }
  1417. /// <summary>
  1418. /// Registers the DataRelation in report dictionary.
  1419. /// </summary>
  1420. /// <param name="data">DataRelation object.</param>
  1421. /// <param name="name">Name for the registered data.</param>
  1422. /// <returns>WebReport object.</returns>
  1423. public WebReport RegisterData(DataRelation data, string name)
  1424. {
  1425. this.Report.Dictionary.RegisterData(data, name, true);
  1426. return this;
  1427. }
  1428. /// <summary>
  1429. /// Register the DataSet in report dictionary.
  1430. /// </summary>
  1431. /// <param name="data">DataSet object.</param>
  1432. /// <returns>WebReport object.</returns>
  1433. public WebReport RegisterData(DataSet data)
  1434. {
  1435. this.Report.Dictionary.RegisterData(data, "Data", true);
  1436. return this;
  1437. }
  1438. /// <summary>
  1439. /// Registers the DataTable in report dictionary.
  1440. /// </summary>
  1441. /// <param name="data">DataTable object.</param>
  1442. /// <param name="name">Name for the registered data.</param>
  1443. /// <returns>WebReport object.</returns>
  1444. public WebReport RegisterData(DataTable data, string name)
  1445. {
  1446. this.Report.Dictionary.RegisterData(data, name, true);
  1447. return this;
  1448. }
  1449. /// <summary>
  1450. /// Registers the DataView in report dictionary.
  1451. /// </summary>
  1452. /// <param name="data">DataView object.</param>
  1453. /// <param name="name">Name for the registered data.</param>
  1454. /// <returns>WebReport object.</returns>
  1455. public WebReport RegisterData(DataView data, string name)
  1456. {
  1457. this.Report.Dictionary.RegisterData(data, name, true);
  1458. return this;
  1459. }
  1460. /// <summary>
  1461. /// Registers the IEnumerable in report dictionary.
  1462. /// </summary>
  1463. /// <param name="data">IEnumerable data.</param>
  1464. /// <param name="name">Name for the registered data.</param>
  1465. /// <returns>WebReport object.</returns>
  1466. public WebReport RegisterData(IEnumerable data, string name)
  1467. {
  1468. this.Report.Dictionary.RegisterData(data, name, true);
  1469. return this;
  1470. }
  1471. /// <summary>
  1472. /// Loads the report from file.
  1473. /// </summary>
  1474. /// <param name="fileName">File Name.</param>
  1475. /// <returns>WebReport object.</returns>
  1476. public WebReport LoadFromFile(string fileName)
  1477. {
  1478. this.Report.Load(fileName);
  1479. return this;
  1480. }
  1481. /// <summary>
  1482. /// Loads the report from stream.
  1483. /// </summary>
  1484. /// <param name="stream">Stream object.</param>
  1485. /// <returns>WebReport object.</returns>
  1486. public WebReport LoadFromStream(Stream stream)
  1487. {
  1488. this.Report.Load(stream);
  1489. return this;
  1490. }
  1491. /// <summary>
  1492. /// Loads the prepared report from file. Also the property <see cref="WebReport.ReportDone"/> will be enabled and
  1493. /// <see cref="WebReport.ShowRefreshButton"/> will be disabled.
  1494. /// </summary>
  1495. /// <param name="fileName">File Name.</param>
  1496. /// <returns>WebReport object.</returns>
  1497. public WebReport LoadPrepared(string fileName)
  1498. {
  1499. this.Report.LoadPrepared(fileName);
  1500. this.ReportDone = true;
  1501. this.ShowRefreshButton = false;
  1502. return this;
  1503. }
  1504. /// <summary>
  1505. /// Loads the prepared report from stream. Also the property <see cref="WebReport.ReportDone"/> will be enabled and
  1506. /// <see cref="WebReport.ShowRefreshButton"/> will be disabled.
  1507. /// </summary>
  1508. /// <param name="stream">Stream object.</param>
  1509. /// <returns>WebReport object.</returns>
  1510. public WebReport LoadPrepared(Stream stream)
  1511. {
  1512. this.Report.LoadPrepared(stream);
  1513. this.ReportDone = true;
  1514. this.ShowRefreshButton = false;
  1515. return this;
  1516. }
  1517. #endregion Register Data
  1518. private void WebReportInit(bool inlineRegistration, bool stretched)
  1519. {
  1520. this.Width = Unit.Pixel(550);
  1521. this.Height = Unit.Pixel(500);
  1522. this.ForeColor = Color.Black;
  1523. this.BackColor = Color.White;
  1524. this.InlineRegistration = inlineRegistration;
  1525. if (stretched)
  1526. {
  1527. this.Width = Unit.Percentage(100);
  1528. this.Height = Unit.Percentage(100);
  1529. }
  1530. }
  1531. /// <summary>
  1532. /// Initializes a new instance of the <see cref="WebReport"/> class.
  1533. /// </summary>
  1534. public WebReport()
  1535. {
  1536. WebReportInit(false, false);
  1537. }
  1538. /// <summary>
  1539. /// Initializes a new instance of the <see cref="WebReport"/> class.
  1540. /// </summary>
  1541. /// <param name="inlineRegistration">Enable registration of JS/CSS footprint inline.</param>
  1542. public WebReport(bool inlineRegistration)
  1543. {
  1544. WebReportInit(inlineRegistration, false);
  1545. }
  1546. /// <summary>
  1547. /// Initializes a new instance of the <see cref="WebReport"/> class.
  1548. /// </summary>
  1549. /// <param name="inlineRegistration">Enable registration of JS/CSS footprint inline.</param>
  1550. /// <param name="stretched">Creates the control with 100% width and height.</param>
  1551. public WebReport(bool inlineRegistration, bool stretched)
  1552. {
  1553. WebReportInit(inlineRegistration, stretched);
  1554. }
  1555. static WebReport()
  1556. {
  1557. ScriptSecurity = new ScriptSecurity(new ScriptChecker());
  1558. }
  1559. #region Serialization
  1560. /// <summary>
  1561. /// Gets the stream with serialized properties data.
  1562. /// </summary>
  1563. /// <returns>Stream object.</returns>
  1564. public Stream GetPropData()
  1565. {
  1566. XmlSerializer propSerializer = new XmlSerializer(typeof(WebReportProperties));
  1567. MemoryStream dataStream = new MemoryStream();
  1568. propSerializer.Serialize(dataStream, Prop);
  1569. dataStream.Position = 0;
  1570. return dataStream;
  1571. }
  1572. /// <summary>
  1573. /// Gets the stream with serialized report data.
  1574. /// </summary>
  1575. /// <returns>Stream object.</returns>
  1576. public Stream GetReportData()
  1577. {
  1578. MemoryStream dataStream = new MemoryStream();
  1579. Report.Save(dataStream);
  1580. dataStream.Position = 0;
  1581. return dataStream;
  1582. }
  1583. /// <summary>
  1584. /// Gets the stream with serialized prepared report data.
  1585. /// </summary>
  1586. /// <returns>Stream object.</returns>
  1587. public Stream GetPreparedData()
  1588. {
  1589. MemoryStream dataStream = new MemoryStream();
  1590. Report.SavePrepared(dataStream);
  1591. dataStream.Position = 0;
  1592. return dataStream;
  1593. }
  1594. #endregion Serialization
  1595. #region Deserialization
  1596. /// <summary>
  1597. /// Loads the serialized properties data from stream.
  1598. /// </summary>
  1599. /// <param name="propStream">Stream object.</param>
  1600. public void SetPropData(Stream propStream)
  1601. {
  1602. if (propStream != null && propStream.Length > 0)
  1603. {
  1604. XmlSerializer propSerializer = new XmlSerializer(typeof(WebReportProperties));
  1605. Prop = propSerializer.Deserialize(propStream) as WebReportProperties;
  1606. }
  1607. }
  1608. /// <summary>
  1609. /// Loads the serialized report data from stream.
  1610. /// </summary>
  1611. /// <param name="reportStream">Stream object.</param>
  1612. public void SetReportData(Stream reportStream)
  1613. {
  1614. if (reportStream != null && reportStream.Length > 0)
  1615. {
  1616. Report.Load(reportStream);
  1617. }
  1618. }
  1619. /// <summary>
  1620. /// Loads the serialized prepared report data from stream.
  1621. /// </summary>
  1622. /// <param name="reportStream">Stream object.</param>
  1623. public void SetPreparedData(Stream reportStream)
  1624. {
  1625. if (reportStream != null && reportStream.Length > 0)
  1626. {
  1627. Report.LoadPrepared(reportStream);
  1628. }
  1629. }
  1630. #endregion Deserialization
  1631. }
  1632. /// <summary>
  1633. /// Represents the static class WebReportGlobals with necessary methods for using in MVC environment.
  1634. /// </summary>
  1635. public static class WebReportGlobals
  1636. {
  1637. #if DOTNET_4
  1638. /// <summary>
  1639. /// Returns the code for registration the necessary scripts with jQuery.
  1640. /// </summary>
  1641. /// <returns>HtmlString object.</returns>
  1642. public static HtmlString Scripts()
  1643. {
  1644. return new HtmlString(ScriptsAsString());
  1645. }
  1646. /// <summary>
  1647. /// Returns the code for registration the necessary scripts without jQuery.
  1648. /// </summary>
  1649. /// <returns>HtmlString object.</returns>
  1650. public static HtmlString ScriptsWOjQuery()
  1651. {
  1652. return new HtmlString(ScriptsWOjQueryAsString());
  1653. }
  1654. /// <summary>
  1655. /// Returns the code for registration the necessary CSS.
  1656. /// </summary>
  1657. /// <returns>HtmlString object.</returns>
  1658. public static HtmlString Styles()
  1659. {
  1660. return new HtmlString(StylesAsString());
  1661. }
  1662. /// <summary>
  1663. /// Returns the code for registration the necessary CSS without jQuery styles.
  1664. /// </summary>
  1665. /// <returns>HtmlString object.</returns>
  1666. public static HtmlString StylesWOjQuery()
  1667. {
  1668. // reserved for future
  1669. return new HtmlString(String.Empty);
  1670. }
  1671. #endif
  1672. /// <summary>
  1673. /// Returns the string with code for registration the necessary scripts with jQuery.
  1674. /// </summary>
  1675. /// <returns>String object.</returns>
  1676. public static string ScriptsAsString()
  1677. {
  1678. StringBuilder raw = new StringBuilder();
  1679. raw.Append("<script src=\"").Append(GetResourceTemplateUrl("fr_util.js")).AppendLine("\" type=\"text/javascript\"></script>");
  1680. raw.Append("<script src=\"").Append(GetResourceJqueryUrl("jquery.min.js")).AppendLine("\" type=\"text/javascript\"></script>");
  1681. raw.Append("<script src=\"").Append(GetResourceJqueryUrl("jquery-ui.custom.min.js")).AppendLine("\" type=\"text/javascript\"></script>");
  1682. return raw.ToString();
  1683. }
  1684. /// <summary>
  1685. ///Returns the string with code for registration the necessary scripts without jQuery.
  1686. /// </summary>
  1687. /// <returns>String object.</returns>
  1688. public static string ScriptsWOjQueryAsString()
  1689. {
  1690. StringBuilder raw = new StringBuilder();
  1691. raw.Append("<script src=\"").Append(GetResourceTemplateUrl("fr_util.js")).AppendLine("\" type=\"text/javascript\"></script>");
  1692. return raw.ToString();
  1693. }
  1694. /// <summary>
  1695. /// Returns the string with code for registration the necessary CSS with jQuery.
  1696. /// </summary>
  1697. /// <returns>String object.</returns>
  1698. public static string StylesAsString()
  1699. {
  1700. StringBuilder raw = new StringBuilder();
  1701. raw.Append("<link rel=\"stylesheet\" href=\"").Append(GetResourceJqueryUrl("jquery-ui.min.css")).AppendLine("\">");
  1702. return raw.ToString();
  1703. }
  1704. /// <summary>
  1705. /// Returns the string with code for registration the necessary CSS without jQuery.
  1706. /// </summary>
  1707. /// <returns>String object.</returns>
  1708. public static string StylesWOjQueryAsString()
  1709. {
  1710. // reserved for future
  1711. return String.Empty;
  1712. }
  1713. private static string GetResourceJqueryUrl(string resName)
  1714. {
  1715. return new Page().ClientScript.GetWebResourceUrl(typeof(WebReport), string.Format("FastReport.Web.Resources.jquery.{0}", resName));
  1716. }
  1717. private static string GetResourceTemplateUrl(string resName)
  1718. {
  1719. return new Page().ClientScript.GetWebResourceUrl(typeof(WebReport), string.Format("FastReport.Web.Resources.Templates.{0}", resName));
  1720. }
  1721. }
  1722. }