Report.cs 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680
  1. using FastReport.Code;
  2. using FastReport.CrossView;
  3. using FastReport.Data;
  4. using FastReport.Dialog;
  5. using FastReport.Engine;
  6. using FastReport.Export;
  7. using FastReport.Utils;
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Drawing.Text;
  15. using System.IO;
  16. using System.Security;
  17. using System.Text;
  18. namespace FastReport
  19. {
  20. /// <summary>
  21. /// Specifies the language of the report's script.
  22. /// </summary>
  23. public enum Language
  24. {
  25. /// <summary>
  26. /// The C# language.
  27. /// </summary>
  28. CSharp,
  29. /// <summary>
  30. /// The VisualBasic.Net language.
  31. /// </summary>
  32. Vb
  33. }
  34. /// <summary>
  35. /// Specifies the quality of text rendering.
  36. /// </summary>
  37. public enum TextQuality
  38. {
  39. /// <summary>
  40. /// The default text quality, depends on system settings.
  41. /// </summary>
  42. Default,
  43. /// <summary>
  44. /// The regular quality.
  45. /// </summary>
  46. Regular,
  47. /// <summary>
  48. /// The "ClearType" quality.
  49. /// </summary>
  50. ClearType,
  51. /// <summary>
  52. /// The AntiAlias quality. This mode may be used to produce the WYSIWYG text.
  53. /// </summary>
  54. AntiAlias,
  55. /// <summary>
  56. /// The "SingleBitPerPixel" quality.
  57. /// </summary>
  58. SingleBPP,
  59. /// <summary>
  60. /// The "SingleBitPerPixelGridFit" quality.
  61. /// </summary>
  62. SingleBPPGridFit
  63. }
  64. /// <summary>
  65. /// Specifies the report operation.
  66. /// </summary>
  67. public enum ReportOperation
  68. {
  69. /// <summary>
  70. /// Specifies no operation.
  71. /// </summary>
  72. None,
  73. /// <summary>
  74. /// The report is running.
  75. /// </summary>
  76. Running,
  77. /// <summary>
  78. /// The report is printing.
  79. /// </summary>
  80. Printing,
  81. /// <summary>
  82. /// The report is exporting.
  83. /// </summary>
  84. Exporting
  85. }
  86. /// <summary>
  87. /// Specifies the page range to print/export.
  88. /// </summary>
  89. public enum PageRange
  90. {
  91. /// <summary>
  92. /// Print all pages.
  93. /// </summary>
  94. All,
  95. /// <summary>
  96. /// Print current page.
  97. /// </summary>
  98. Current,
  99. /// <summary>
  100. /// Print pages specified in the <b>PageNumbers</b> property of the <b>PrintSettings</b>.
  101. /// </summary>
  102. PageNumbers
  103. }
  104. /// <summary>
  105. /// Represents a report object.
  106. /// </summary>
  107. /// <remarks>
  108. /// <para>The instance of this class contains a report. Here are some common
  109. /// actions that can be performed with this object:</para>
  110. /// <list type="bullet">
  111. /// <item>
  112. /// <description>To load a report, use the <see cref="Load(string)"/>
  113. /// method or call static <see cref="FromFile"/> method. </description>
  114. /// </item>
  115. /// <item>
  116. /// <description>To save a report, call the <see cref="Save(string)"/> method.</description>
  117. /// </item>
  118. /// <item>
  119. /// <description>To register application dataset for use it in a report, call one of the
  120. /// <b>RegisterData</b> methods.</description>
  121. /// </item>
  122. /// <item>
  123. /// <description>To pass some parameter to a report, use the
  124. /// <see cref="SetParameterValue"/> method.</description>
  125. /// </item>
  126. /// <item>
  127. /// <description>To design a report, call the <see cref="Design()"/> method.</description>
  128. /// </item>
  129. /// <item>
  130. /// <description>To run a report and preview it, call the <see cref="Show()"/> method.
  131. /// Another way is to call the <see cref="Prepare()"/> method, then call the
  132. /// <see cref="ShowPrepared()"/> method.</description>
  133. /// </item>
  134. /// <item>
  135. /// <description>To run a report and print it, call the <see cref="Print"/> method.
  136. /// Another way is to call the <see cref="Prepare()"/> method, then call the
  137. /// <see cref="PrintPrepared()"/> method.</description>
  138. /// </item>
  139. /// <item>
  140. /// <description>To load/save prepared report, use one of the <b>LoadPrepared</b> and
  141. /// <b>SavePrepared</b> methods.</description>
  142. /// </item>
  143. /// <item>
  144. /// <description>To set up some global properties, use the <see cref="Config"/> static class
  145. /// or <see cref="EnvironmentSettings"/> component that you can use in the Visual Studio IDE.
  146. /// </description>
  147. /// </item>
  148. /// </list>
  149. /// <para/>The report consists of one or several report pages (pages of the
  150. /// <see cref="ReportPage"/> type) and/or dialog forms (pages of the <see cref="DialogPage"/> type).
  151. /// They are stored in the <see cref="Pages"/> collection. In turn, each page may contain report
  152. /// objects. See the example below how to create a simple report in code.
  153. /// </remarks>
  154. /// <example>This example shows how to create a report instance, load it from a file,
  155. /// register the application data, run and preview.
  156. /// <code>
  157. /// Report report = new Report();
  158. /// report.Load("reportfile.frx");
  159. /// report.RegisterData(application_dataset);
  160. /// report.Show();
  161. /// </code>
  162. /// <para/>This example shows how to create simple report in code.
  163. /// <code>
  164. /// Report report = new Report();
  165. /// // create the report page
  166. /// ReportPage page = new ReportPage();
  167. /// page.Name = "ReportPage1";
  168. /// // set paper width and height. Note: these properties are measured in millimeters.
  169. /// page.PaperWidth = 210;
  170. /// page.PaperHeight = 297;
  171. /// // add a page to the report
  172. /// report.Pages.Add(page);
  173. /// // create report title
  174. /// page.ReportTitle = new ReportTitleBand();
  175. /// page.ReportTitle.Name = "ReportTitle1";
  176. /// page.ReportTitle.Height = Units.Millimeters * 10;
  177. /// // create Text object and put it to the title
  178. /// TextObject text = new TextObject();
  179. /// text.Name = "Text1";
  180. /// text.Bounds = new RectangleF(0, 0, Units.Millimeters * 100, Units.Millimeters * 5);
  181. /// page.ReportTitle.Objects.Add(text);
  182. /// // create data band
  183. /// DataBand data = new DataBand();
  184. /// data.Name = "Data1";
  185. /// data.Height = Units.Millimeters * 10;
  186. /// // add data band to a page
  187. /// page.Bands.Add(data);
  188. /// </code>
  189. /// </example>
  190. public partial class Report : Base, IParent, ISupportInitialize
  191. {
  192. #region Fields
  193. private PageCollection pages;
  194. private Dictionary dictionary;
  195. private ReportInfo reportInfo;
  196. private string baseReport;
  197. private Report baseReportObject;
  198. private string baseReportAbsolutePath;
  199. private string fileName;
  200. private string scriptText;
  201. private Language scriptLanguage;
  202. private bool compressed;
  203. private bool useFileCache;
  204. private TextQuality textQuality;
  205. private bool smoothGraphics;
  206. private string password;
  207. private bool convertNulls;
  208. private bool doublePass;
  209. private bool autoFillDataSet;
  210. private int initialPageNumber;
  211. private int maxPages;
  212. private string startReportEvent;
  213. private string finishReportEvent;
  214. private StyleCollection styles;
  215. private CodeHelperBase codeHelper;
  216. private GraphicCache graphicCache;
  217. private string[] referencedAssemblies;
  218. private Hashtable cachedDataItems;
  219. private AssemblyCollection assemblies;
  220. private FastReport.Preview.PreparedPages preparedPages;
  221. private ReportEngine engine;
  222. private bool aborted;
  223. private Bitmap measureBitmap;
  224. private IGraphics measureGraphics;
  225. private bool storeInResources;
  226. private PermissionSet scriptRestrictions;
  227. private ReportOperation operation;
  228. private int tickCount;
  229. private bool needCompile;
  230. private bool needRefresh;
  231. private bool initializing;
  232. private object initializeData;
  233. private string initializeDataName;
  234. private object tag;
  235. private bool isLoadPrepared = false;
  236. #endregion Fields
  237. #region Properties
  238. /// <summary>
  239. /// Occurs when calc execution is started.
  240. /// </summary>
  241. public event CustomCalcEventHandler CustomCalc;
  242. /// <summary>
  243. /// Occurs when report is inherited and trying to load a base report.
  244. /// </summary>
  245. /// <remarks>
  246. /// Typical use of this event is to load the base report from a database instead of a file.
  247. /// </remarks>
  248. public event CustomLoadEventHandler LoadBaseReport;
  249. /// <summary>
  250. /// Occurs when report execution is started.
  251. /// </summary>
  252. public event EventHandler StartReport;
  253. /// <summary>
  254. /// Occurs when report execution is finished.
  255. /// </summary>
  256. public event EventHandler FinishReport;
  257. /// <summary>
  258. /// Occurs before export to set custom export parameters.
  259. /// </summary>
  260. public event EventHandler<ExportParametersEventArgs> ExportParameters;
  261. /// <summary>
  262. /// Gets the pages contained in this report.
  263. /// </summary>
  264. /// <remarks>
  265. /// This property contains pages of all types (report and dialog). Use the <b>is/as</b> operators
  266. /// if you want to work with pages of <b>ReportPage</b> type.
  267. /// </remarks>
  268. /// <example>The following code demonstrates how to access the first report page:
  269. /// <code>
  270. /// ReportPage page1 = report1.Pages[0] as ReportPage;
  271. /// </code>
  272. /// </example>
  273. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  274. public PageCollection Pages
  275. {
  276. get { return pages; }
  277. }
  278. /// <summary>
  279. /// Gets the report's data.
  280. /// </summary>
  281. /// <remarks>
  282. /// The dictionary contains all data items such as connections, data sources, parameters,
  283. /// system variables.
  284. /// </remarks>
  285. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  286. public Dictionary Dictionary
  287. {
  288. get { return dictionary; }
  289. set
  290. {
  291. SetProp(dictionary, value);
  292. dictionary = value;
  293. }
  294. }
  295. /// <summary>
  296. /// Gets the collection of report parameters.
  297. /// </summary>
  298. /// <remarks>
  299. /// <para>Parameters are displayed in the "Data" window under the "Parameters" node.</para>
  300. /// <para>Typical use of parameters is to pass some static data from the application to the report.
  301. /// You can print such data, use it in the data row filter, script etc. </para>
  302. /// <para>Another way to use parameters is to define some reusable piece of code, for example,
  303. /// to define an expression that will return the concatenation of first and second employee name.
  304. /// In this case, you set the parameter's <b>Expression</b> property to something like this:
  305. /// [Employees.FirstName] + " " + [Employees.LastName]. Now this parameter may be used in the report
  306. /// to print full employee name. Each time you access such parameter, it will calculate the expression
  307. /// and return its value. </para>
  308. /// <para>You can create nested parameters. To do this, add the new <b>Parameter</b> to the
  309. /// <b>Parameters</b> collection of the root parameter. To access the nested parameter, you may use the
  310. /// <see cref="GetParameter"/> method.</para>
  311. /// <para>To get or set the parameter's value, use the <see cref="GetParameterValue"/> and
  312. /// <see cref="SetParameterValue"/> methods. To set the parameter's expression, use the
  313. /// <see cref="GetParameter"/> method that returns a <b>Parameter</b> object and set its
  314. /// <b>Expression</b> property.</para>
  315. /// </remarks>
  316. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  317. public ParameterCollection Parameters
  318. {
  319. get { return dictionary.Parameters; }
  320. }
  321. /// <summary>
  322. /// Gets or sets the report information such as report name, author, description etc.
  323. /// </summary>
  324. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  325. [SRCategory("Design")]
  326. public ReportInfo ReportInfo
  327. {
  328. get { return reportInfo; }
  329. set { reportInfo = value; }
  330. }
  331. /// <summary>
  332. /// Gets or sets the base report file name.
  333. /// </summary>
  334. /// <remarks>
  335. /// This property contains the name of a report file this report is inherited from.
  336. /// <b>Note:</b> setting this property to non-empty value will clear the report and
  337. /// load the base file into it.
  338. /// </remarks>
  339. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  340. public string BaseReport
  341. {
  342. get { return baseReport; }
  343. set { SetBaseReport(value); }
  344. }
  345. /// <summary>
  346. /// Gets a value indicating whether Report is prepared
  347. /// </summary>
  348. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  349. public bool IsPrepared
  350. {
  351. get { return PreparedPages != null && PreparedPages.Count != 0; }
  352. }
  353. /// <summary>
  354. /// Gets or sets the absolute path to the parent report.
  355. /// </summary>
  356. /// <remarks>
  357. /// This property contains the absolute path to the parent report.
  358. /// </remarks>
  359. [Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  360. public string BaseReportAbsolutePath
  361. {
  362. get { return baseReportAbsolutePath; }
  363. set { baseReportAbsolutePath = value; }
  364. }
  365. /// <summary>
  366. /// Gets or sets the name of a file the report was loaded from.
  367. /// </summary>
  368. /// <remarks>
  369. /// This property is used to support the FastReport.Net infrastructure;
  370. /// typically you don't need to use it.
  371. /// </remarks>
  372. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  373. public string FileName
  374. {
  375. get { return fileName; }
  376. set { fileName = value; }
  377. }
  378. /// <summary>
  379. /// Gets or sets the report script.
  380. /// </summary>
  381. /// <remarks>
  382. /// <para>The script contains the <b>ReportScript</b> class that contains all report objects'
  383. /// event handlers and own items such as private fields, properties, methods etc. The script
  384. /// contains only items written by you. Unlike other report generators, the script does not
  385. /// contain report objects declarations, initialization code. It is added automatically when
  386. /// you run the report.</para>
  387. /// <para>By default this property contains an empty script text. You may see it in the designer
  388. /// when you switch to the Code window.</para>
  389. /// <para>If you set this property programmatically, you have to declare the <b>FastReport</b>
  390. /// namespace and the <b>ReportScript</b> class in it. Do not declare report items (such as bands,
  391. /// objects, etc) in the <b>ReportScript</b> class: the report engine does this automatically when
  392. /// you run the report.</para>
  393. /// <para><b>Security note:</b> since the report script is compiled into .NET assembly, it allows
  394. /// you to do ANYTHING. For example, you may create a script that will read/write files from/to a disk.
  395. /// To restrict such operations, use the <see cref="ScriptRestrictions"/> property.</para>
  396. /// </remarks>
  397. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  398. public string ScriptText
  399. {
  400. get { return scriptText; }
  401. set { scriptText = value; }
  402. }
  403. /// <summary>
  404. /// Gets or sets the script language of this report.
  405. /// </summary>
  406. /// <remarks>
  407. /// Note: changing this property will reset the report script to default empty script.
  408. /// </remarks>
  409. [DefaultValue(Language.CSharp)]
  410. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  411. [SRCategory("Script")]
  412. public Language ScriptLanguage
  413. {
  414. get { return scriptLanguage; }
  415. set
  416. {
  417. bool needClear = scriptLanguage != value;
  418. scriptLanguage = value;
  419. if (scriptLanguage == Language.CSharp)
  420. codeHelper = new CsCodeHelper(this);
  421. else
  422. codeHelper = new VbCodeHelper(this);
  423. if (needClear)
  424. scriptText = codeHelper.EmptyScript();
  425. }
  426. }
  427. /// <summary>
  428. /// Gets or sets a value indicating whether the null DB value must be converted to zero, false or
  429. /// empty string depending on the data column type.
  430. /// </summary>
  431. /// <remarks>
  432. /// This property is <b>true</b> by default. If you set it to <b>false</b>, you should check
  433. /// the DB value before you do something with it (for example, typecast it to any type, use it
  434. /// in a expression etc.)
  435. /// </remarks>
  436. [DefaultValue(true)]
  437. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  438. [SRCategory("Engine")]
  439. public bool ConvertNulls
  440. {
  441. get { return convertNulls; }
  442. set { convertNulls = value; }
  443. }
  444. /// <summary>
  445. /// Gets or sets a value that specifies whether the report engine should perform the second pass.
  446. /// </summary>
  447. /// <remarks>
  448. /// <para>Typically the second pass is necessary to print the number of total pages. It also
  449. /// may be used to perform some calculations on the first pass and print its results on the
  450. /// second pass.</para>
  451. /// <para>Use the <b>Engine.FirstPass</b>, <b>Engine.FinalPass</b> properties to determine which
  452. /// pass the engine is performing now.</para>
  453. /// </remarks>
  454. [DefaultValue(false)]
  455. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  456. [SRCategory("Engine")]
  457. public bool DoublePass
  458. {
  459. get { return doublePass; }
  460. set { doublePass = value; }
  461. }
  462. /// <summary>
  463. /// Gets or sets a value that specifies whether to compress the report file.
  464. /// </summary>
  465. /// <remarks>
  466. /// The report file is compressed using the Gzip algorithm. So you can open the
  467. /// compressed report in any zip-compatible archiver.
  468. /// </remarks>
  469. [DefaultValue(false)]
  470. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  471. [SRCategory("Misc")]
  472. public bool Compressed
  473. {
  474. get { return compressed; }
  475. set { compressed = value; }
  476. }
  477. /// <summary>
  478. /// Returns a bool value depending on the .frx or .fpx report was loaded
  479. /// </summary>
  480. public bool IsLoadPrepared
  481. {
  482. get => isLoadPrepared;
  483. }
  484. /// <summary>
  485. /// Gets or sets a value that specifies whether to use the file cache rather than memory
  486. /// to store the prepared report pages.
  487. /// </summary>
  488. [DefaultValue(false)]
  489. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  490. [SRCategory("Engine")]
  491. public bool UseFileCache
  492. {
  493. get { return useFileCache; }
  494. set { useFileCache = value; }
  495. }
  496. /// <summary>
  497. /// Gets or sets a value that specifies the quality of text rendering.
  498. /// </summary>
  499. /// <remarks>
  500. /// <b>Note:</b> the default property value is <b>TextQuality.Default</b>. That means the report
  501. /// may look different depending on OS settings. This property does not affect the printout.
  502. /// </remarks>
  503. [DefaultValue(TextQuality.Default)]
  504. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  505. [SRCategory("Misc")]
  506. public TextQuality TextQuality
  507. {
  508. get { return textQuality; }
  509. set { textQuality = value; }
  510. }
  511. /// <summary>
  512. /// Gets or sets a value that specifies if the graphic objects such as bitmaps
  513. /// and shapes should be displayed smoothly.
  514. /// </summary>
  515. [DefaultValue(false)]
  516. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  517. [SRCategory("Misc")]
  518. public bool SmoothGraphics
  519. {
  520. get { return smoothGraphics; }
  521. set { smoothGraphics = value; }
  522. }
  523. /// <summary>
  524. /// Gets or sets the report password.
  525. /// </summary>
  526. /// <remarks>
  527. /// <para>When you try to load the password-protected report, you will be asked
  528. /// for a password. You also may specify the password in this property before loading
  529. /// the report. In this case the report will load silently.</para>
  530. /// <para>Password-protected report file is crypted using Rijndael algorithm.
  531. /// Do not forget your password! It will be hard or even impossible to open
  532. /// the protected file in this case.</para>
  533. /// </remarks>
  534. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  535. public string Password
  536. {
  537. get { return password; }
  538. set { password = value; }
  539. }
  540. /// <summary>
  541. /// Gets or sets a value indicating whether it is necessary to automatically fill
  542. /// DataSet registered with <b>RegisterData</b> call.
  543. /// </summary>
  544. /// <remarks>
  545. /// If this property is <b>true</b> (by default), FastReport will automatically fill
  546. /// the DataSet with data when you trying to run a report. Set it to <b>false</b> if
  547. /// you want to fill the DataSet by yourself.
  548. /// </remarks>
  549. [DefaultValue(true)]
  550. [SRCategory("Misc")]
  551. public bool AutoFillDataSet
  552. {
  553. get { return autoFillDataSet; }
  554. set { autoFillDataSet = value; }
  555. }
  556. /// <summary>
  557. /// Gets or sets the maximum number of generated pages in a prepared report.
  558. /// </summary>
  559. /// <remarks>
  560. /// Use this property to limit the number of pages in a prepared report.
  561. /// </remarks>
  562. [DefaultValue(0)]
  563. [SRCategory("Misc")]
  564. public int MaxPages
  565. {
  566. get { return maxPages; }
  567. set { maxPages = value; }
  568. }
  569. /// <summary>
  570. /// Gets or sets the collection of styles used in this report.
  571. /// </summary>
  572. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  573. [SRCategory("Misc")]
  574. public StyleCollection Styles
  575. {
  576. get { return styles; }
  577. set { styles = value; }
  578. }
  579. /// <summary>
  580. /// Gets or sets an array of assembly names that will be used to compile the report script.
  581. /// </summary>
  582. /// <remarks>
  583. /// By default this property contains the following assemblies: "System.dll", "System.Drawing.dll",
  584. /// "System.Windows.Forms.dll", "System.Data.dll", "System.Xml.dll". If your script uses some types
  585. /// from another assemblies, you have to add them to this property.
  586. /// </remarks>
  587. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  588. [SRCategory("Script")]
  589. public string[] ReferencedAssemblies
  590. {
  591. get { return referencedAssemblies; }
  592. set {
  593. if (value != null)
  594. {
  595. // fix for old reports with "System.Windows.Forms.DataVisualization" in referenced assemblies
  596. for (int i = 0; i < value.Length; i++)
  597. {
  598. value[i] = value[i].Replace("System.Windows.Forms.DataVisualization", "FastReport.DataVisualization");
  599. }
  600. }
  601. referencedAssemblies = value;
  602. }
  603. }
  604. /// <summary>
  605. /// Gets or sets a script event name that will be fired when the report starts.
  606. /// </summary>
  607. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  608. [SRCategory("Build")]
  609. public string StartReportEvent
  610. {
  611. get { return startReportEvent; }
  612. set { startReportEvent = value; }
  613. }
  614. /// <summary>
  615. /// Gets or sets a script event name that will be fired when the report is finished.
  616. /// </summary>
  617. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  618. [SRCategory("Build")]
  619. public string FinishReportEvent
  620. {
  621. get { return finishReportEvent; }
  622. set { finishReportEvent = value; }
  623. }
  624. /// <summary>
  625. /// Gets a value indicating that report execution was aborted.
  626. /// </summary>
  627. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  628. public bool Aborted
  629. {
  630. get
  631. {
  632. Config.DoEvent();
  633. return aborted;
  634. }
  635. }
  636. /// <summary>
  637. /// Gets or sets a value that determines whether to store the report in the application resources.
  638. /// Use this property in the MS Visual Studio IDE only.
  639. /// </summary>
  640. /// <remarks>
  641. /// By default this property is <b>true</b>. When set to <b>false</b>, you should store your report
  642. /// in a file.
  643. /// </remarks>
  644. [DefaultValue(true)]
  645. [SRCategory("Design")]
  646. public bool StoreInResources
  647. {
  648. get { return storeInResources; }
  649. set { storeInResources = value; }
  650. }
  651. /// <summary>
  652. /// Gets or sets the resource string that contains the report.
  653. /// </summary>
  654. /// <remarks>
  655. /// This property is used by the MS Visual Studio to store the report. Do not use it directly.
  656. /// </remarks>
  657. [Browsable(false)]
  658. [Localizable(true)]
  659. public string ReportResourceString
  660. {
  661. get
  662. {
  663. if (!StoreInResources)
  664. return "";
  665. return SaveToString();
  666. }
  667. set
  668. {
  669. if (String.IsNullOrEmpty(value))
  670. {
  671. Clear();
  672. return;
  673. }
  674. LoadFromString(value);
  675. }
  676. }
  677. /// <summary>
  678. /// Gets a value indicating that this report contains dialog forms.
  679. /// </summary>
  680. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  681. public bool HasDialogs
  682. {
  683. get
  684. {
  685. foreach (PageBase page in Pages)
  686. {
  687. if (page is DialogPage)
  688. return true;
  689. }
  690. return false;
  691. }
  692. }
  693. /// <summary>
  694. /// Gets or sets a set of permissions that will be restricted for the script code.
  695. /// </summary>
  696. /// <remarks>
  697. /// Since the report script is compiled into .NET assembly, it allows you to do ANYTHING.
  698. /// For example, you may create a script that will read/write files from/to a disk. This property
  699. /// is used to restrict such operations.
  700. /// <example>This example shows how to restrict the file IO operations in a script:
  701. /// <code>
  702. /// using System.Security;
  703. /// using System.Security.Permissions;
  704. /// ...
  705. /// PermissionSet ps = new PermissionSet(PermissionState.None);
  706. /// ps.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
  707. /// report1.ScriptRestrictions = ps;
  708. /// report1.Prepare();
  709. /// </code>
  710. /// </example>
  711. /// </remarks>
  712. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  713. public PermissionSet ScriptRestrictions
  714. {
  715. get { return scriptRestrictions; }
  716. set { scriptRestrictions = value; }
  717. }
  718. /// <summary>
  719. /// Gets a reference to the graphics cache for this report.
  720. /// </summary>
  721. /// <remarks>
  722. /// This property is used to support the FastReport.Net infrastructure. Do not use it directly.
  723. /// </remarks>
  724. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  725. public GraphicCache GraphicCache
  726. {
  727. get { return graphicCache; }
  728. }
  729. /// <summary>
  730. /// Gets a pages of the prepared report.
  731. /// </summary>
  732. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  733. public Preview.PreparedPages PreparedPages
  734. {
  735. get { return preparedPages; }
  736. }
  737. /// <summary>
  738. /// Gets a reference to the report engine.
  739. /// </summary>
  740. /// <remarks>
  741. /// This property can be used when report is running. In other cases it returns <b>null</b>.
  742. /// </remarks>
  743. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  744. public ReportEngine Engine
  745. {
  746. get { return engine; }
  747. }
  748. /// <summary>
  749. /// Gets or sets the initial page number for PageN/PageNofM system variables.
  750. /// </summary>
  751. [DefaultValue(1)]
  752. [SRCategory("Engine")]
  753. public int InitialPageNumber
  754. {
  755. get { return initialPageNumber; }
  756. set { initialPageNumber = value; }
  757. }
  758. /// <summary>
  759. /// This property is not relevant to this class.
  760. /// </summary>
  761. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  762. public new string Name
  763. {
  764. get { return base.Name; }
  765. }
  766. /// <summary>
  767. /// This property is not relevant to this class.
  768. /// </summary>
  769. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  770. public new Restrictions Restrictions
  771. {
  772. get { return base.Restrictions; }
  773. set { base.Restrictions = value; }
  774. }
  775. /// <summary>
  776. /// Gets the report operation that is currently performed.
  777. /// </summary>
  778. [Browsable(false)]
  779. public ReportOperation Operation
  780. {
  781. get { return operation; }
  782. }
  783. /// <summary>
  784. /// Gets or sets the Tag object of the report.
  785. /// </summary>
  786. [Browsable(false)]
  787. public object Tag
  788. {
  789. get { return tag; }
  790. set { tag = value; }
  791. }
  792. private string[] DefaultAssemblies
  793. {
  794. get
  795. {
  796. return new string[] {
  797. "System.dll",
  798. "System.Drawing.dll",
  799. "System.Data.dll",
  800. "System.Xml.dll",
  801. "FastReport.Compat.dll",
  802. #if !CROSSPLATFORM
  803. "System.Windows.Forms.dll",
  804. #endif
  805. #if CROSSPLATFORM || COREWIN
  806. "System.Drawing.Primitives",
  807. #endif
  808. #if MSCHART
  809. "FastReport.DataVisualization.dll"
  810. #endif
  811. };
  812. }
  813. }
  814. internal CodeHelperBase CodeHelper
  815. {
  816. get { return codeHelper; }
  817. }
  818. public IGraphics MeasureGraphics
  819. {
  820. get
  821. {
  822. if (measureGraphics == null)
  823. {
  824. #if CROSSPLATFORM || MONO
  825. measureBitmap = new Bitmap(1, 1);
  826. measureGraphics = new GdiGraphics(measureBitmap);
  827. #else
  828. measureGraphics = GdiGraphics.FromGraphics(Graphics.FromHwnd(IntPtr.Zero));
  829. #endif
  830. }
  831. return measureGraphics;
  832. }
  833. }
  834. public string GetReportName
  835. {
  836. get
  837. {
  838. string result = ReportInfo.Name;
  839. if (String.IsNullOrEmpty(result))
  840. result = Path.GetFileNameWithoutExtension(FileName);
  841. return result;
  842. }
  843. }
  844. /// <summary>
  845. /// Gets or sets the flag for refresh.
  846. /// </summary>
  847. public bool NeedRefresh
  848. {
  849. get { return needRefresh; }
  850. set { needRefresh = value; }
  851. }
  852. internal ObjectCollection AllNamedObjects
  853. {
  854. get
  855. {
  856. ObjectCollection allObjects = AllObjects;
  857. // data objects are not included into AllObjects list. Include named items separately.
  858. foreach (Base c in Dictionary.AllObjects)
  859. {
  860. if (c is DataConnectionBase || c is DataSourceBase || c is Relation || c is CubeSourceBase)
  861. allObjects.Add(c);
  862. }
  863. return allObjects;
  864. }
  865. }
  866. #endregion Properties
  867. #region Private Methods
  868. private bool ShouldSerializeReferencedAssemblies()
  869. {
  870. return Converter.ToString(ReferencedAssemblies) != Converter.ToString(DefaultAssemblies);
  871. }
  872. // convert absolute path to the base report to relative path (based on the main report path).
  873. private string GetRelativePathToBaseReport()
  874. {
  875. string path = "";
  876. if (!String.IsNullOrEmpty(FileName))
  877. {
  878. try
  879. {
  880. path = Path.GetDirectoryName(FileName);
  881. }
  882. catch
  883. {
  884. }
  885. }
  886. if (!String.IsNullOrEmpty(path))
  887. {
  888. try
  889. {
  890. return FileUtils.GetRelativePath(BaseReport, path);
  891. }
  892. catch
  893. {
  894. }
  895. }
  896. return BaseReport;
  897. }
  898. private void SetBaseReport(string value)
  899. {
  900. baseReport = value;
  901. if (baseReportObject != null)
  902. {
  903. baseReportObject.Dispose();
  904. baseReportObject = null;
  905. }
  906. // detach the base report
  907. if (String.IsNullOrEmpty(value))
  908. {
  909. foreach (Base c in AllObjects)
  910. {
  911. c.SetAncestor(false);
  912. }
  913. SetAncestor(false);
  914. return;
  915. }
  916. string saveFileName = fileName;
  917. if (LoadBaseReport != null)
  918. {
  919. LoadBaseReport(this, new CustomLoadEventArgs(value, this));
  920. }
  921. else
  922. {
  923. // convert the relative path to absolute path (based on the main report path).
  924. if (!Path.IsPathRooted(value))
  925. {
  926. var fullPath = Path.GetFullPath(Path.GetDirectoryName(FileName));
  927. // since directory path separator for Win OS is '\' and for Unix OS is '/'
  928. // we have to modify the incoming path string with actual for current OS path separator
  929. value = Path.Combine(fullPath, GetFixedSeparatedPath(value));
  930. }
  931. if (!File.Exists(value) && File.Exists(BaseReportAbsolutePath))
  932. {
  933. value = BaseReportAbsolutePath;
  934. }
  935. Load(value);
  936. }
  937. fileName = saveFileName;
  938. baseReport = "";
  939. Password = "";
  940. baseReportObject = Activator.CreateInstance(GetType()) as Report;
  941. baseReportObject.AssignAll(this, true);
  942. // set Ancestor & CanChangeParent flags
  943. foreach (Base c in AllObjects)
  944. {
  945. c.SetAncestor(true);
  946. }
  947. SetAncestor(true);
  948. baseReport = value;
  949. }
  950. private static string GetFixedSeparatedPath( string baseReport)
  951. {
  952. return baseReport.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar);
  953. }
  954. private void GetDiff(object sender, DiffEventArgs e)
  955. {
  956. if (baseReportObject != null)
  957. {
  958. if (e.Object is Report)
  959. e.DiffObject = baseReportObject;
  960. else if (e.Object is Base)
  961. e.DiffObject = baseReportObject.FindObject((e.Object as Base).Name);
  962. }
  963. }
  964. private void StartPerformanceCounter()
  965. {
  966. tickCount = Environment.TickCount;
  967. }
  968. private void StopPerformanceCounter()
  969. {
  970. tickCount = Environment.TickCount - tickCount;
  971. }
  972. private void ClearReportProperties()
  973. {
  974. ReportInfo.Clear();
  975. Dictionary.Clear();
  976. if (IsDesigning)
  977. {
  978. ScriptLanguage = Config.ReportSettings.DefaultLanguage;
  979. }
  980. else
  981. {
  982. ScriptLanguage = Language.CSharp;
  983. }
  984. ScriptText = codeHelper.EmptyScript();
  985. BaseReport = "";
  986. BaseReportAbsolutePath = "";
  987. DoublePass = false;
  988. ConvertNulls = true;
  989. Compressed = false;
  990. TextQuality = TextQuality.Default;
  991. SmoothGraphics = false;
  992. Password = "";
  993. InitialPageNumber = 1;
  994. MaxPages = 0;
  995. ClearDesign();
  996. Styles.Clear();
  997. Styles.Name = "";
  998. ReferencedAssemblies = DefaultAssemblies;
  999. StartReportEvent = "";
  1000. FinishReportEvent = "";
  1001. needCompile = true;
  1002. }
  1003. #endregion Private Methods
  1004. #region Protected Methods
  1005. /// <inheritdoc/>
  1006. protected override void Dispose(bool disposing)
  1007. {
  1008. if (disposing)
  1009. {
  1010. if (graphicCache != null)
  1011. graphicCache.Dispose();
  1012. graphicCache = null;
  1013. if (measureGraphics != null)
  1014. measureGraphics.Dispose();
  1015. measureGraphics = null;
  1016. if (measureBitmap != null)
  1017. measureBitmap.Dispose();
  1018. measureBitmap = null;
  1019. DisposeDesign();
  1020. if (PreparedPages != null)
  1021. PreparedPages.Dispose();
  1022. }
  1023. base.Dispose(disposing);
  1024. }
  1025. /// <inheritdoc/>
  1026. protected override void DeserializeSubItems(FRReader reader)
  1027. {
  1028. if (String.Compare(reader.ItemName, "ScriptText", true) == 0)
  1029. ScriptText = reader.ReadPropertyValue();
  1030. else if (String.Compare(reader.ItemName, "Dictionary", true) == 0)
  1031. reader.Read(Dictionary);
  1032. else if (String.Compare(reader.ItemName, "Styles", true) == 0)
  1033. reader.Read(Styles);
  1034. else
  1035. base.DeserializeSubItems(reader);
  1036. }
  1037. #endregion Protected Methods
  1038. #region IParent
  1039. /// <inheritdoc/>
  1040. public bool CanContain(Base child)
  1041. {
  1042. return child is PageBase || child is Dictionary;
  1043. }
  1044. /// <inheritdoc/>
  1045. public void GetChildObjects(ObjectCollection list)
  1046. {
  1047. foreach (PageBase page in pages)
  1048. {
  1049. list.Add(page);
  1050. }
  1051. }
  1052. /// <inheritdoc/>
  1053. public void AddChild(Base obj)
  1054. {
  1055. if (obj is PageBase)
  1056. pages.Add(obj as PageBase);
  1057. else if (obj is Dictionary)
  1058. Dictionary = obj as Dictionary;
  1059. }
  1060. /// <inheritdoc/>
  1061. public void RemoveChild(Base obj)
  1062. {
  1063. if (obj is PageBase)
  1064. pages.Remove(obj as PageBase);
  1065. else if (obj is Dictionary && (obj as Dictionary) == dictionary)
  1066. Dictionary = null;
  1067. }
  1068. /// <inheritdoc/>
  1069. public virtual int GetChildOrder(Base child)
  1070. {
  1071. if (child is PageBase)
  1072. return pages.IndexOf(child as PageBase);
  1073. return 0;
  1074. }
  1075. /// <inheritdoc/>
  1076. public virtual void SetChildOrder(Base child, int order)
  1077. {
  1078. if (child is PageBase)
  1079. {
  1080. if (order > pages.Count)
  1081. order = pages.Count;
  1082. int oldOrder = child.ZOrder;
  1083. if (oldOrder != -1 && order != -1 && oldOrder != order)
  1084. {
  1085. if (oldOrder <= order)
  1086. order--;
  1087. pages.Remove(child as PageBase);
  1088. pages.Insert(order, child as PageBase);
  1089. }
  1090. }
  1091. }
  1092. /// <inheritdoc/>
  1093. public virtual void UpdateLayout(float dx, float dy)
  1094. {
  1095. // do nothing
  1096. }
  1097. #endregion IParent
  1098. #region ISupportInitialize Members
  1099. /// <inheritdoc/>
  1100. public void BeginInit()
  1101. {
  1102. initializing = true;
  1103. }
  1104. /// <inheritdoc/>
  1105. public void EndInit()
  1106. {
  1107. initializing = false;
  1108. Dictionary.RegisterData(initializeData, initializeDataName, false);
  1109. }
  1110. #endregion ISupportInitialize Members
  1111. #region Script related
  1112. private void FillDataSourceCache()
  1113. {
  1114. cachedDataItems.Clear();
  1115. ObjectCollection dictionaryObjects = Dictionary.AllObjects;
  1116. foreach (Parameter c in Dictionary.SystemVariables)
  1117. {
  1118. dictionaryObjects.Add(c);
  1119. }
  1120. foreach (Base c in dictionaryObjects)
  1121. {
  1122. if (c is DataSourceBase)
  1123. {
  1124. DataSourceBase data = c as DataSourceBase;
  1125. CachedDataItem cachedItem = new CachedDataItem();
  1126. cachedItem.dataSource = data;
  1127. cachedDataItems[data.FullName] = cachedItem;
  1128. for (int i = 0; i < data.Columns.Count; i++)
  1129. {
  1130. cachedItem = new CachedDataItem();
  1131. cachedItem.dataSource = data;
  1132. cachedItem.column = data.Columns[i];
  1133. cachedDataItems[data.FullName + "." + data.Columns[i].Alias] = cachedItem;
  1134. }
  1135. }
  1136. else if (c is Parameter)
  1137. {
  1138. cachedDataItems[(c as Parameter).FullName] = c;
  1139. }
  1140. else if (c is Total)
  1141. {
  1142. cachedDataItems[(c as Total).Name] = c;
  1143. }
  1144. }
  1145. }
  1146. internal void Compile()
  1147. {
  1148. FillDataSourceCache();
  1149. if (needCompile)
  1150. {
  1151. AssemblyDescriptor descriptor = new AssemblyDescriptor(this, ScriptText);
  1152. assemblies.Clear();
  1153. assemblies.Add(descriptor);
  1154. descriptor.AddObjects();
  1155. descriptor.AddExpressions();
  1156. descriptor.AddFunctions();
  1157. descriptor.Compile();
  1158. }
  1159. else
  1160. {
  1161. InternalInit();
  1162. }
  1163. }
  1164. /// <summary>
  1165. /// Initializes the report's fields.
  1166. /// </summary>
  1167. /// <remarks>
  1168. /// This method is for internal use only.
  1169. /// </remarks>
  1170. protected void InternalInit()
  1171. {
  1172. needCompile = false;
  1173. AssemblyDescriptor descriptor = new AssemblyDescriptor(this, CodeHelper.EmptyScript());
  1174. assemblies.Clear();
  1175. assemblies.Add(descriptor);
  1176. descriptor.InitInstance(this);
  1177. }
  1178. /// <summary>
  1179. /// Generates the file (.cs or .vb) that contains the report source code.
  1180. /// </summary>
  1181. /// <param name="fileName">Name of the file.</param>
  1182. /// <remarks>
  1183. /// Use this method to generate the report source code. This code can be attached to your project.
  1184. /// In this case, you will need to call the following code to run a report:
  1185. /// <code>
  1186. /// SimpleListReport report = new SimpleListReport();
  1187. /// report.RegisterData(your_dataset);
  1188. /// report.Show();
  1189. /// </code>
  1190. /// </remarks>
  1191. public void GenerateReportAssembly(string fileName)
  1192. {
  1193. // create the class name
  1194. string className = "";
  1195. const string punctuation = " ~`!@#$%^&*()-=+[]{},.<>/?;:'\"\\|";
  1196. foreach (char c in Path.GetFileNameWithoutExtension(fileName))
  1197. {
  1198. if (!punctuation.Contains(c.ToString()))
  1199. className += c;
  1200. }
  1201. AssemblyDescriptor descriptor = new AssemblyDescriptor(this, ScriptText);
  1202. descriptor.AddObjects();
  1203. descriptor.AddExpressions();
  1204. descriptor.AddFunctions();
  1205. string reportClassText = descriptor.GenerateReportClass(className);
  1206. File.WriteAllText(fileName, reportClassText, Encoding.UTF8);
  1207. }
  1208. /// <summary>
  1209. /// Calculates an expression and returns the result.
  1210. /// </summary>
  1211. /// <param name="expression">The expression to calculate.</param>
  1212. /// <returns>If report is running, returns the result of calculation.
  1213. /// Otherwise returns <b>null</b>.</returns>
  1214. /// <remarks>
  1215. /// <para>The expression may be any valid expression such as "1 + 2". The expression
  1216. /// is calculated in the report script's <b>ReportScript</b> class instance context,
  1217. /// so you may refer to any objects available in this context: private fields,
  1218. /// methods, report objects.</para>
  1219. /// </remarks>
  1220. public object Calc(string expression)
  1221. {
  1222. return Calc(expression, 0);
  1223. }
  1224. /// <summary>
  1225. /// Calculates an expression and returns the result.
  1226. /// </summary>
  1227. /// <param name="expression">The expression to calculate.</param>
  1228. /// <param name="value">The value of currently printing object.</param>
  1229. /// <returns>If report is running, returns the result of calculation.
  1230. /// Otherwise returns <b>null</b>.</returns>
  1231. /// <remarks>
  1232. /// Do not call this method directly. Use the <b>Calc(string expression)</b> method instead.
  1233. /// </remarks>
  1234. public object Calc(string expression, Variant value)
  1235. {
  1236. if (!IsRunning)
  1237. return null;
  1238. if (String.IsNullOrEmpty(expression) || String.IsNullOrEmpty(expression.Trim()))
  1239. return null;
  1240. string expr = expression;
  1241. if (expr.StartsWith("[") && expr.EndsWith("]"))
  1242. expr = expression.Substring(1, expression.Length - 2);
  1243. // check cached items first
  1244. object cachedObject = cachedDataItems[expr];
  1245. if (cachedObject is CachedDataItem)
  1246. {
  1247. CachedDataItem cachedItem = cachedObject as CachedDataItem;
  1248. DataSourceBase data = cachedItem.dataSource;
  1249. Column column = cachedItem.column;
  1250. object val = ConvertToColumnDataType(column.Value, column.DataType, ConvertNulls);
  1251. if (CustomCalc != null)
  1252. {
  1253. CustomCalcEventArgs e = new CustomCalcEventArgs(expr, val, this);
  1254. CustomCalc(this, e);
  1255. val = e.CalculatedObject;
  1256. }
  1257. return val;
  1258. }
  1259. else if (cachedObject is Parameter)
  1260. {
  1261. return (cachedObject as Parameter).Value;
  1262. }
  1263. else if (cachedObject is Total)
  1264. {
  1265. object val = (cachedObject as Total).Value;
  1266. if (ConvertNulls && (val == null || val is DBNull))
  1267. val = 0;
  1268. (cachedObject as Total).ExecuteTotal(val);
  1269. return val;
  1270. }
  1271. // calculate the expression
  1272. return CalcExpression(expression, value);
  1273. }
  1274. private object ConvertToColumnDataType(object val, Type dataType, bool convertNulls)
  1275. {
  1276. if (val == null || val is DBNull)
  1277. {
  1278. if (convertNulls)
  1279. val = Converter.ConvertNull(dataType);
  1280. }
  1281. else
  1282. {
  1283. if (val is IConvertible)
  1284. {
  1285. Type t = Nullable.GetUnderlyingType(dataType);
  1286. try
  1287. {
  1288. val = Convert.ChangeType(val, t != null ? t : dataType);
  1289. }
  1290. catch (InvalidCastException)
  1291. {
  1292. // do nothing
  1293. }
  1294. catch (FormatException)
  1295. {
  1296. // do nothing
  1297. }
  1298. }
  1299. }
  1300. return val;
  1301. }
  1302. /// <summary>
  1303. /// Returns an expression value.
  1304. /// </summary>
  1305. /// <param name="expression">The expression.</param>
  1306. /// <param name="value">The value of currently printing object.</param>
  1307. /// <returns>Returns the result of calculation.</returns>
  1308. /// <remarks>
  1309. /// This method is for internal use only, do not call it directly.
  1310. /// </remarks>
  1311. protected virtual object CalcExpression(string expression, Variant value)
  1312. {
  1313. if (expression.ToLower() == "true" || expression.ToLower() == "false")
  1314. {
  1315. expression = expression.ToLower();
  1316. }
  1317. // try to calculate the expression
  1318. foreach (AssemblyDescriptor d in assemblies)
  1319. {
  1320. if (d.ContainsExpression(expression))
  1321. return d.CalcExpression(expression, value);
  1322. }
  1323. // expression not found. Probably it was added after the start of the report.
  1324. // Compile new assembly containing this expression.
  1325. AssemblyDescriptor descriptor = new AssemblyDescriptor(this, CodeHelper.EmptyScript());
  1326. assemblies.Add(descriptor);
  1327. descriptor.AddObjects();
  1328. descriptor.AddSingleExpression(expression);
  1329. descriptor.AddFunctions();
  1330. descriptor.Compile();
  1331. return descriptor.CalcExpression(expression, value);
  1332. }
  1333. /// <summary>
  1334. /// Invokes the script method with given name.
  1335. /// </summary>
  1336. /// <param name="name">The name of the script method.</param>
  1337. /// <param name="parms">The method parameters.</param>
  1338. public object InvokeMethod(string name, object[] parms)
  1339. {
  1340. if (assemblies.Count > 0)
  1341. return assemblies[0].InvokeMethod(name, parms);
  1342. return null;
  1343. }
  1344. private Column GetColumn(string complexName)
  1345. {
  1346. if (String.IsNullOrEmpty(complexName))
  1347. return null;
  1348. CachedDataItem cachedItem = cachedDataItems[complexName] as CachedDataItem;
  1349. if (cachedItem != null)
  1350. return cachedItem.column;
  1351. string[] names = complexName.Split('.');
  1352. cachedItem = cachedDataItems[names[0]] as CachedDataItem;
  1353. DataSourceBase data = cachedItem != null ? cachedItem.dataSource : GetDataSource(names[0]);
  1354. return DataHelper.GetColumn(Dictionary, data, names, true);
  1355. }
  1356. private object GetColumnValue(string complexName, bool convertNull)
  1357. {
  1358. Column column = GetColumn(complexName);
  1359. if (column == null)
  1360. return null;
  1361. return ConvertToColumnDataType(column.Value, column.DataType, convertNull);
  1362. }
  1363. private Variant GetTotalValue(string name, bool convertNull)
  1364. {
  1365. object value = Dictionary.Totals.GetValue(name);
  1366. if (convertNull && (value == null || value is DBNull))
  1367. value = 0;
  1368. return new Variant(value);
  1369. }
  1370. /// <summary>
  1371. /// Gets the data column's value. Automatically converts null value to 0, false or ""
  1372. /// depending on the column type.
  1373. /// </summary>
  1374. /// <param name="complexName">The name of the data column including the datasource name.</param>
  1375. /// <returns>If report is running, returns the column value. Otherwise returns <b>null</b>.</returns>
  1376. /// <remarks>
  1377. /// The return value of this method does not depend on the <see cref="ConvertNulls"/> property.
  1378. /// </remarks>
  1379. /// <example>
  1380. /// <code>
  1381. /// string employeeName = (string)report.GetColumnValue("Employees.FirstName");
  1382. /// </code>
  1383. /// </example>
  1384. public object GetColumnValue(string complexName)
  1385. {
  1386. return GetColumnValue(complexName, true);
  1387. }
  1388. /// <summary>
  1389. /// Gets the data column's value. This method does not convert null values.
  1390. /// </summary>
  1391. /// <param name="complexName">The name of the data column including the datasource name.</param>
  1392. /// <returns>If report is running, returns the column value.
  1393. /// Otherwise returns <b>null</b>.</returns>
  1394. public object GetColumnValueNullable(string complexName)
  1395. {
  1396. return GetColumnValue(complexName, false);
  1397. }
  1398. /// <summary>
  1399. /// Gets the report parameter with given name.
  1400. /// </summary>
  1401. /// <param name="complexName">The name of the parameter.</param>
  1402. /// <returns>The <see cref="Parameter"/> object if found, otherwise <b>null</b>.</returns>
  1403. /// <remarks>
  1404. /// To find nested parameter, use the "." separator: "MainParameter.NestedParameter"
  1405. /// </remarks>
  1406. public Parameter GetParameter(string complexName)
  1407. {
  1408. if (IsRunning)
  1409. return cachedDataItems[complexName] as Parameter;
  1410. return DataHelper.GetParameter(Dictionary, complexName);
  1411. }
  1412. /// <summary>
  1413. /// Gets a value of the parameter with given name.
  1414. /// </summary>
  1415. /// <param name="complexName">The name of the parameter.</param>
  1416. /// <returns>The parameter's value if found, otherwise <b>null</b>.</returns>
  1417. /// <remarks>
  1418. /// To find nested parameter, use the "." separator: "MainParameter.NestedParameter"
  1419. /// </remarks>
  1420. public object GetParameterValue(string complexName)
  1421. {
  1422. Parameter par = GetParameter(complexName);
  1423. if (par != null)
  1424. {
  1425. // avoid InvalidCastException when casting object that is int to double
  1426. if (par.DataType.Name == "Double" && par.Value.GetType() == typeof(int))
  1427. {
  1428. return (double)(int)par.Value;
  1429. }
  1430. return par.Value;
  1431. }
  1432. return null;
  1433. }
  1434. /// <summary>
  1435. /// Sets the parameter's value.
  1436. /// </summary>
  1437. /// <param name="complexName">The name of the parameter.</param>
  1438. /// <param name="value">Value to set.</param>
  1439. /// <remarks>
  1440. /// Use this method to pass a value to the parameter that you've created in the "Data" window.
  1441. /// Such parameter may be used everythere in a report; for example, you can print its value
  1442. /// or use it in expressions.
  1443. /// <para/>You should call this method <b>after</b> the report was loaded and <b>before</b> you run it.
  1444. /// <para/>To access a nested parameter, use the "." separator: "MainParameter.NestedParameter"
  1445. /// <note type="caution">
  1446. /// This method will create the parameter if it does not exist.
  1447. /// </note>
  1448. /// </remarks>
  1449. /// <example>This example shows how to pass a value to the parameter with "MyParam" name:
  1450. /// <code>
  1451. /// // load the report
  1452. /// report1.Load("report.frx");
  1453. /// // setup the parameter
  1454. /// report1.SetParameterValue("MyParam", 10);
  1455. /// // show the report
  1456. /// report1.Show();
  1457. /// </code>
  1458. /// </example>
  1459. public void SetParameterValue(string complexName, object value)
  1460. {
  1461. Parameter par = GetParameter(complexName);
  1462. if (par == null)
  1463. par = DataHelper.CreateParameter(Dictionary, complexName);
  1464. if (par != null)
  1465. {
  1466. par.Value = value;
  1467. par.Expression = "";
  1468. }
  1469. }
  1470. /// <summary>
  1471. /// Gets a value of the system variable with specified name.
  1472. /// </summary>
  1473. /// <param name="complexName">Name of a variable.</param>
  1474. /// <returns>The variable's value if found, otherwise <b>null</b>.</returns>
  1475. public object GetVariableValue(string complexName)
  1476. {
  1477. return GetParameterValue(complexName);
  1478. }
  1479. /// <summary>
  1480. /// Gets a value of the total with specified name.
  1481. /// </summary>
  1482. /// <param name="name">Name of total.</param>
  1483. /// <returns>The total's value if found, otherwise <b>0</b>.</returns>
  1484. /// <remarks>This method converts null values to 0 if the <see cref="ConvertNulls"/> property is set to true.
  1485. /// Use the <see cref="GetTotalValueNullable"/> method if you don't want the null conversion.
  1486. /// </remarks>
  1487. public Variant GetTotalValue(string name)
  1488. {
  1489. return GetTotalValue(name, ConvertNulls);
  1490. }
  1491. /// <summary>
  1492. /// Gets a value of the total with specified name.
  1493. /// </summary>
  1494. /// <param name="name">Name of total.</param>
  1495. /// <returns>The total's value if found, otherwise <b>null</b>.</returns>
  1496. public Variant GetTotalValueNullable(string name)
  1497. {
  1498. return GetTotalValue(name, false);
  1499. }
  1500. /// <summary>
  1501. /// Gets the datasource with specified name.
  1502. /// </summary>
  1503. /// <param name="alias">Alias name of a datasource.</param>
  1504. /// <returns>The datasource object if found, otherwise <b>null</b>.</returns>
  1505. public DataSourceBase GetDataSource(string alias)
  1506. {
  1507. return Dictionary.FindByAlias(alias) as DataSourceBase;
  1508. }
  1509. #endregion Script related
  1510. #region Public Methods
  1511. /// <inheritdoc/>
  1512. public override void Assign(Base source)
  1513. {
  1514. BaseAssign(source);
  1515. }
  1516. /// <summary>
  1517. /// Aborts the report execution.
  1518. /// </summary>
  1519. public void Abort()
  1520. {
  1521. SetAborted(true);
  1522. }
  1523. /// <inheritdoc/>
  1524. public override Base FindObject(string name)
  1525. {
  1526. foreach (Base c in AllNamedObjects)
  1527. {
  1528. if (String.Compare(name, c.Name, true) == 0)
  1529. return c;
  1530. }
  1531. return null;
  1532. }
  1533. /// <inheritdoc/>
  1534. public override void Clear()
  1535. {
  1536. base.Clear();
  1537. ClearReportProperties();
  1538. }
  1539. /// <summary>
  1540. /// Updates the report component's styles.
  1541. /// </summary>
  1542. /// <remarks>
  1543. /// Call this method if you change the <see cref="Styles"/> collection.
  1544. /// </remarks>
  1545. public void ApplyStyles()
  1546. {
  1547. foreach (Base c in AllObjects)
  1548. {
  1549. if (c is ReportComponentBase)
  1550. (c as ReportComponentBase).Style = (c as ReportComponentBase).Style;
  1551. }
  1552. }
  1553. /// <summary>
  1554. /// Sets prepared pages.
  1555. /// </summary>
  1556. /// <param name="pages"></param>
  1557. public void SetPreparedPages(Preview.PreparedPages pages)
  1558. {
  1559. preparedPages = pages;
  1560. if (pages != null)
  1561. pages.SetReport(this);
  1562. }
  1563. internal void SetAborted(bool value)
  1564. {
  1565. aborted = value;
  1566. }
  1567. internal void SetOperation(ReportOperation operation)
  1568. {
  1569. this.operation = operation;
  1570. }
  1571. /// <summary>
  1572. /// This method fires the <b>StartReport</b> event and the script code connected
  1573. /// to the <b>StartReportEvent</b>.
  1574. /// </summary>
  1575. public void OnStartReport(EventArgs e)
  1576. {
  1577. SetRunning(true);
  1578. if (StartReport != null)
  1579. StartReport(this, e);
  1580. InvokeMethod(StartReportEvent, new object[] { this, e });
  1581. }
  1582. /// <summary>
  1583. /// This method fires the <b>FinishReport</b> event and the script code connected
  1584. /// to the <b>FinishReportEvent</b>.
  1585. /// </summary>
  1586. public void OnFinishReport(EventArgs e)
  1587. {
  1588. SetRunning(false);
  1589. if (FinishReport != null)
  1590. FinishReport(this, e);
  1591. InvokeMethod(FinishReportEvent, new object[] { this, e });
  1592. }
  1593. /// <summary>
  1594. /// Runs the Export event.
  1595. /// </summary>
  1596. /// <param name="e">ExportReportEventArgs object.</param>
  1597. public void OnExportParameters(ExportParametersEventArgs e)
  1598. {
  1599. if (ExportParameters != null)
  1600. {
  1601. ExportParameters(this, e);
  1602. }
  1603. }
  1604. /// <summary>
  1605. /// Add the name of the assembly (in addition to the default) that will be used to compile the report script
  1606. /// </summary>
  1607. /// <param name="assembly_name">Assembly name</param>
  1608. /// <remarks>
  1609. /// For example: <code>report.AddReferencedAssembly("Newtonsoft.Json.dll")</code>
  1610. /// </remarks>
  1611. public void AddReferencedAssembly(string assembly_name)
  1612. {
  1613. string[] assemblies = ReferencedAssemblies;
  1614. Array.Resize(ref assemblies, assemblies.Length + 1);
  1615. assemblies[assemblies.Length - 1] = assembly_name;
  1616. ReferencedAssemblies = assemblies;
  1617. }
  1618. /// <summary>
  1619. /// Add the names of the assembly (in addition to the default) that will be used to compile the report script
  1620. /// </summary>
  1621. /// <param name="assembly_names">Assembly's names</param>
  1622. public void AddReferencedAssembly(IList<string> assembly_names)
  1623. {
  1624. string[] assemblies = ReferencedAssemblies;
  1625. int oldLength = assemblies.Length;
  1626. Array.Resize(ref assemblies, oldLength + assembly_names.Count);
  1627. for (int i = 0; i < assembly_names.Count; i++)
  1628. {
  1629. assemblies[oldLength + i] = assembly_names[i];
  1630. }
  1631. ReferencedAssemblies = assemblies;
  1632. }
  1633. /// <inheritdoc/>
  1634. public override void Serialize(FRWriter writer)
  1635. {
  1636. Report c = writer.DiffObject as Report;
  1637. writer.ItemName = IsAncestor ? "inherited" : ClassName;
  1638. if (BaseReport != c.BaseReport)
  1639. {
  1640. // when save to the report file, convert absolute path to the base report to relative path
  1641. // (based on the main report path). Do not convert when saving to the clipboard.
  1642. string value = writer.SerializeTo != SerializeTo.Undo ? GetRelativePathToBaseReport() : BaseReport;
  1643. writer.WriteStr("BaseReport", value);
  1644. // Fix bug with moving child report to another folder without parent report.
  1645. if (writer.SerializeTo == SerializeTo.Report)
  1646. writer.WriteStr("BaseReportAbsolutePath", BaseReport);
  1647. }
  1648. // always serialize ScriptLanguage because its default value depends on Config.ReportSettings.DefaultLanguage
  1649. writer.WriteValue("ScriptLanguage", ScriptLanguage);
  1650. if (ScriptText != c.ScriptText)
  1651. writer.WritePropertyValue("ScriptText", ScriptText);
  1652. if (!writer.AreEqual(ReferencedAssemblies, c.ReferencedAssemblies))
  1653. writer.WriteValue("ReferencedAssemblies", ReferencedAssemblies);
  1654. if (ConvertNulls != c.ConvertNulls)
  1655. writer.WriteBool("ConvertNulls", ConvertNulls);
  1656. if (DoublePass != c.DoublePass)
  1657. writer.WriteBool("DoublePass", DoublePass);
  1658. if (Compressed != c.Compressed)
  1659. writer.WriteBool("Compressed", Compressed);
  1660. if (UseFileCache != c.UseFileCache)
  1661. writer.WriteBool("UseFileCache", UseFileCache);
  1662. if (TextQuality != c.TextQuality)
  1663. writer.WriteValue("TextQuality", TextQuality);
  1664. if (SmoothGraphics != c.SmoothGraphics)
  1665. writer.WriteBool("SmoothGraphics", SmoothGraphics);
  1666. if (Password != c.Password)
  1667. writer.WriteStr("Password", Password);
  1668. if (InitialPageNumber != c.InitialPageNumber)
  1669. writer.WriteInt("InitialPageNumber", InitialPageNumber);
  1670. if (MaxPages != c.MaxPages)
  1671. writer.WriteInt("MaxPages", MaxPages);
  1672. if (StartReportEvent != c.StartReportEvent)
  1673. writer.WriteStr("StartReportEvent", StartReportEvent);
  1674. if (FinishReportEvent != c.FinishReportEvent)
  1675. writer.WriteStr("FinishReportEvent", FinishReportEvent);
  1676. ReportInfo.Serialize(writer, c.ReportInfo);
  1677. SerializeDesign(writer, c);
  1678. if (Styles.Count > 0)
  1679. writer.Write(Styles);
  1680. writer.Write(Dictionary);
  1681. if (writer.SaveChildren)
  1682. {
  1683. foreach (Base child in ChildObjects)
  1684. {
  1685. writer.Write(child);
  1686. }
  1687. }
  1688. }
  1689. /// <inheritdoc/>
  1690. public override void Deserialize(FRReader reader)
  1691. {
  1692. if (reader.HasProperty("BaseReportAbsolutePath"))
  1693. {
  1694. BaseReportAbsolutePath = reader.ReadStr("BaseReportAbsolutePath");
  1695. }
  1696. base.Deserialize(reader);
  1697. // call OnAfterLoad method of each report object
  1698. foreach (Base c in AllObjects)
  1699. {
  1700. c.OnAfterLoad();
  1701. }
  1702. }
  1703. /// <summary>
  1704. /// Saves the report to a stream.
  1705. /// </summary>
  1706. /// <param name="stream">The stream to save to.</param>
  1707. public void Save(Stream stream)
  1708. {
  1709. using (FRWriter writer = new FRWriter())
  1710. {
  1711. if (IsAncestor)
  1712. writer.GetDiff += new DiffEventHandler(GetDiff);
  1713. writer.Write(this);
  1714. List<Stream> disposeList = new List<Stream>();
  1715. if (Compressed)
  1716. {
  1717. stream = Compressor.Compress(stream);
  1718. disposeList.Add(stream);
  1719. }
  1720. if (!String.IsNullOrEmpty(Password))
  1721. {
  1722. stream = Crypter.Encrypt(stream, Password);
  1723. disposeList.Insert(0, stream);
  1724. }
  1725. writer.Save(stream);
  1726. foreach (Stream s in disposeList)
  1727. {
  1728. s.Dispose();
  1729. }
  1730. }
  1731. }
  1732. /// <summary>
  1733. /// Saves the report to a file.
  1734. /// </summary>
  1735. /// <param name="fileName">The name of the file to save to.</param>
  1736. public void Save(string fileName)
  1737. {
  1738. FileName = fileName;
  1739. using (FileStream f = new FileStream(fileName, FileMode.Create))
  1740. {
  1741. Save(f);
  1742. }
  1743. }
  1744. /// <summary>
  1745. /// Saves the report to a stream with randomized values in data sources.
  1746. /// </summary>
  1747. /// <param name="stream">The stream to save to.</param>
  1748. public void SaveWithRandomData(Stream stream)
  1749. {
  1750. FRRandom random = new FRRandom();
  1751. random.RandomizeDataSources(Dictionary.DataSources);
  1752. Save(stream);
  1753. }
  1754. /// <summary>
  1755. /// Saves the report to a file with randomized values in data sources.
  1756. /// </summary>
  1757. /// <param name="fileName">The name of the file to save to.</param>
  1758. public void SaveWithRandomData(string fileName)
  1759. {
  1760. FRRandom random = new FRRandom();
  1761. random.RandomizeDataSources(Dictionary.DataSources);
  1762. Save(fileName);
  1763. }
  1764. /// <summary>
  1765. /// Loads report from a stream.
  1766. /// </summary>
  1767. /// <param name="stream">The stream to load from.</param>
  1768. /// <remarks>
  1769. /// When you try to load the password-protected report, you will be asked
  1770. /// for a password. You also may specify the password in the <see cref="Password"/>
  1771. /// property before loading the report. In this case the report will load silently.
  1772. /// </remarks>
  1773. public void Load(Stream stream)
  1774. {
  1775. string password = Password;
  1776. Clear();
  1777. using (FRReader reader = new FRReader(this))
  1778. {
  1779. List<Stream> disposeList = new List<Stream>();
  1780. if (Compressor.IsStreamCompressed(stream))
  1781. {
  1782. stream = Compressor.Decompress(stream, true);
  1783. disposeList.Add(stream);
  1784. }
  1785. bool crypted = Crypter.IsStreamEncrypted(stream);
  1786. if (crypted)
  1787. {
  1788. if (String.IsNullOrEmpty(password))
  1789. {
  1790. password = ShowPaswordForm(password);
  1791. }
  1792. stream = Crypter.Decrypt(stream, password);
  1793. disposeList.Add(stream);
  1794. }
  1795. try
  1796. {
  1797. reader.Load(stream);
  1798. }
  1799. catch (Exception e)
  1800. {
  1801. if (crypted)
  1802. throw new DecryptException();
  1803. throw e;
  1804. }
  1805. finally
  1806. {
  1807. foreach (Stream s in disposeList)
  1808. {
  1809. try
  1810. {
  1811. s.Dispose();
  1812. }
  1813. catch
  1814. {
  1815. }
  1816. }
  1817. }
  1818. reader.Read(this);
  1819. foreach (Base c in AllObjects)
  1820. {
  1821. if (c is BandBase)
  1822. Validator.ValidateIntersectionAllObjects(c as BandBase);
  1823. }
  1824. }
  1825. }
  1826. /// <summary>
  1827. /// Loads the report from a file.
  1828. /// </summary>
  1829. /// <param name="fileName">The name of the file to load from.</param>
  1830. /// <remarks>
  1831. /// When you try to load the password-protected report, you will be asked
  1832. /// for a password. You also may specify the password in the <see cref="Password"/>
  1833. /// property before loading the report. In this case the report will load silently.
  1834. /// </remarks>
  1835. public void Load(string fileName)
  1836. {
  1837. this.fileName = "";
  1838. using (FileStream f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
  1839. {
  1840. this.fileName = fileName;
  1841. Load(f);
  1842. }
  1843. }
  1844. /// <summary>
  1845. /// Loads the report from a string.
  1846. /// </summary>
  1847. /// <param name="s">The string that contains a stream in UTF8 or Base64 encoding.</param>
  1848. public void LoadFromString(string s)
  1849. {
  1850. if (String.IsNullOrEmpty(s))
  1851. return;
  1852. byte[] buffer;
  1853. int startIndex = s.IndexOf("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
  1854. if (startIndex != -1)
  1855. {
  1856. buffer = Encoding.UTF8.GetBytes(s.Substring(startIndex));
  1857. }
  1858. else
  1859. {
  1860. buffer = Convert.FromBase64String(s);
  1861. }
  1862. using (MemoryStream stream = new MemoryStream(buffer))
  1863. {
  1864. Load(stream);
  1865. }
  1866. }
  1867. /// <summary>
  1868. /// Saves the report to a string.
  1869. /// </summary>
  1870. /// <returns>The string that contains a stream.</returns>
  1871. public string SaveToString()
  1872. {
  1873. using (MemoryStream stream = new MemoryStream())
  1874. {
  1875. Save(stream);
  1876. if (Compressed || !String.IsNullOrEmpty(Password))
  1877. {
  1878. return Convert.ToBase64String(stream.ToArray());
  1879. }
  1880. else
  1881. {
  1882. return Encoding.UTF8.GetString(stream.ToArray());
  1883. }
  1884. }
  1885. }
  1886. /// <summary>
  1887. /// Saves the report to a string using the Base64 encoding.
  1888. /// </summary>
  1889. /// <returns>The string that contains a stream.</returns>
  1890. public string SaveToStringBase64()
  1891. {
  1892. using (MemoryStream stream = new MemoryStream())
  1893. {
  1894. Save(stream);
  1895. return Convert.ToBase64String(stream.ToArray());
  1896. }
  1897. }
  1898. /// <summary>
  1899. /// Creates the report instance and loads the report from a stream.
  1900. /// </summary>
  1901. /// <param name="stream">The stream to load from.</param>
  1902. /// <returns>The new report instance.</returns>
  1903. public static Report FromStream(Stream stream)
  1904. {
  1905. Report result = new Report();
  1906. result.Load(stream);
  1907. return result;
  1908. }
  1909. /// <summary>
  1910. /// Creates the report instance and loads the report from a file.
  1911. /// </summary>
  1912. /// <param name="fileName">The name of the file to load from.</param>
  1913. /// <returns>The new report instance.</returns>
  1914. public static Report FromFile(string fileName)
  1915. {
  1916. Report result = new Report();
  1917. result.Load(fileName);
  1918. return result;
  1919. }
  1920. /// <summary>
  1921. /// Creates the report instance and loads the report from a string.
  1922. /// </summary>
  1923. /// <param name="utf8String">The string that contains a stream in UTF8 encoding.</param>
  1924. /// <returns>The new report instance.</returns>
  1925. public static Report FromString(string utf8String)
  1926. {
  1927. Report result = new Report();
  1928. result.LoadFromString(utf8String);
  1929. return result;
  1930. }
  1931. /// <summary>
  1932. /// Registers the application dataset with all its tables and relations to use it in the report.
  1933. /// </summary>
  1934. /// <param name="data">The application data.</param>
  1935. /// <remarks>
  1936. /// If you register more than one dataset, use the <see cref="RegisterData(DataSet, string)"/> method.
  1937. /// </remarks>
  1938. /// <example>
  1939. /// <code>
  1940. /// report1.Load("report.frx");
  1941. /// report1.RegisterData(dataSet1);
  1942. /// </code>
  1943. /// </example>
  1944. public void RegisterData(DataSet data)
  1945. {
  1946. Dictionary.RegisterDataSet(data, "Data", false);
  1947. }
  1948. /// <summary>
  1949. /// Registers the application dataset with all its tables and relations to use it in the report and enables all its tables.
  1950. /// </summary>
  1951. /// <param name="data">The application data.</param>
  1952. /// <param name="enableAllTables">The boolean value indicating whether all tables should be enabled.</param>
  1953. /// <remarks>
  1954. /// If you register more than one dataset, use the <see cref="RegisterData(DataSet, string)"/> method.
  1955. /// </remarks>
  1956. /// <example>
  1957. /// <code>
  1958. /// report1.Load("report.frx");
  1959. /// report1.RegisterData(dataSet1, true);
  1960. /// </code>
  1961. /// </example>
  1962. public void RegisterData(DataSet data, bool enableAllTables)
  1963. {
  1964. Dictionary.RegisterDataSet(data, "Data", false);
  1965. foreach (DataTable table in data.Tables)
  1966. {
  1967. DataSourceBase ds = Report.GetDataSource(table.TableName);
  1968. if (ds != null)
  1969. ds.Enabled = true;
  1970. }
  1971. }
  1972. /// <summary>
  1973. /// Registers the application dataset with specified name.
  1974. /// </summary>
  1975. /// <param name="data">The application data.</param>
  1976. /// <param name="name">The name of the data.</param>
  1977. /// <remarks>
  1978. /// Use this method if you register more than one dataset. You may specify any value
  1979. /// for the <b>name</b> parameter: it is not displayed anywhere in the designer and used only
  1980. /// to load/save a report. The name must be persistent and unique for each registered dataset.
  1981. /// </remarks>
  1982. /// <example>
  1983. /// <code>
  1984. /// report1.Load("report.frx");
  1985. /// report1.RegisterData(dataSet1, "NorthWind");
  1986. /// </code>
  1987. /// </example>
  1988. public void RegisterData(DataSet data, string name)
  1989. {
  1990. if (initializing)
  1991. {
  1992. initializeData = data;
  1993. initializeDataName = name;
  1994. }
  1995. else
  1996. Dictionary.RegisterDataSet(data, name, false);
  1997. }
  1998. /// <summary>
  1999. /// Registers the application dataset with specified name and enables all its tables.
  2000. /// </summary>
  2001. /// <param name="data">The application data.</param>
  2002. /// <param name="name">The name of the data.</param>
  2003. /// <param name="enableAllTables">The boolean value indicating whether all tables should be enabled.</param>
  2004. /// <remarks>
  2005. /// Use this method if you register more than one dataset. You may specify any value
  2006. /// for the <b>name</b> parameter: it is not displayed anywhere in the designer and used only
  2007. /// to load/save a report. The name must be persistent and unique for each registered dataset.
  2008. /// </remarks>
  2009. /// <example>
  2010. /// <code>
  2011. /// report1.Load("report.frx");
  2012. /// report1.RegisterData(dataSet1, "NorthWind", true);
  2013. /// </code>
  2014. /// </example>
  2015. public void RegisterData(DataSet data, string name, bool enableAllTables)
  2016. {
  2017. if (initializing)
  2018. {
  2019. initializeData = data;
  2020. initializeDataName = name;
  2021. }
  2022. else
  2023. {
  2024. Dictionary.RegisterDataSet(data, name, false);
  2025. foreach (DataTable table in data.Tables)
  2026. {
  2027. DataSourceBase ds = Report.GetDataSource(table.TableName);
  2028. if (ds != null)
  2029. ds.Enabled = true;
  2030. }
  2031. }
  2032. }
  2033. /// <summary>
  2034. /// Registers the application data table to use it in the report.
  2035. /// </summary>
  2036. /// <param name="data">The application data.</param>
  2037. /// <param name="name">The name of the data.</param>
  2038. /// <example>
  2039. /// <code>
  2040. /// report1.Load("report.frx");
  2041. /// report1.RegisterData(dataSet1.Tables["Orders"], "Orders");
  2042. /// </code>
  2043. /// </example>
  2044. public void RegisterData(DataTable data, string name)
  2045. {
  2046. Dictionary.RegisterDataTable(data, name, false);
  2047. }
  2048. /// <summary>
  2049. /// Registers the application data view to use it in the report.
  2050. /// </summary>
  2051. /// <param name="data">The application data.</param>
  2052. /// <param name="name">The name of the data.</param>
  2053. /// <example>
  2054. /// <code>
  2055. /// report1.Load("report.frx");
  2056. /// report1.RegisterData(myDataView, "OrdersView");
  2057. /// </code>
  2058. /// </example>
  2059. public void RegisterData(DataView data, string name)
  2060. {
  2061. Dictionary.RegisterDataView(data, name, false);
  2062. }
  2063. /// <summary>
  2064. /// Registers the application data relation to use it in the report.
  2065. /// </summary>
  2066. /// <param name="data">The application data.</param>
  2067. /// <param name="name">The name of the data.</param>
  2068. /// <remarks>
  2069. /// You may specify any value for the <b>name</b> parameter: it is not displayed anywhere
  2070. /// in the designer and used only to load/save a report. The name must be persistent
  2071. /// and unique for each registered relation.
  2072. /// </remarks>
  2073. /// <example>
  2074. /// <code>
  2075. /// report1.Load("report.frx");
  2076. /// report1.RegisterData(myDataRelation, "myRelation");
  2077. /// </code>
  2078. /// </example>
  2079. public void RegisterData(DataRelation data, string name)
  2080. {
  2081. Dictionary.RegisterDataRelation(data, name, false);
  2082. }
  2083. /// <summary>
  2084. /// <b>Obsolete</b>. Registers the application business object to use it in the report.
  2085. /// </summary>
  2086. /// <param name="data">Application data.</param>
  2087. /// <param name="name">Name of the data.</param>
  2088. /// <param name="flags">Not used.</param>
  2089. /// <param name="maxNestingLevel">Maximum nesting level of business objects.</param>
  2090. /// <remarks>
  2091. /// This method is obsolete. Use the <see cref="RegisterData(IEnumerable, string)"/> method instead.
  2092. /// </remarks>
  2093. public void RegisterData(IEnumerable data, string name, BOConverterFlags flags, int maxNestingLevel)
  2094. {
  2095. RegisterData(data, name, maxNestingLevel);
  2096. }
  2097. /// <summary>
  2098. /// Registers the application business object to use it in the report.
  2099. /// </summary>
  2100. /// <param name="data">Application data.</param>
  2101. /// <param name="name">Name of the data.</param>
  2102. /// <example>
  2103. /// <code>
  2104. /// report1.Load("report.frx");
  2105. /// report1.RegisterData(myBusinessObject, "Customers");
  2106. /// </code>
  2107. /// </example>
  2108. public void RegisterData(IEnumerable data, string name)
  2109. {
  2110. if (initializing)
  2111. {
  2112. initializeData = data;
  2113. initializeDataName = name;
  2114. }
  2115. else
  2116. Dictionary.RegisterBusinessObject(data, name, 1, false);
  2117. }
  2118. /// <summary>
  2119. /// Registers the application business object to use it in the report.
  2120. /// </summary>
  2121. /// <param name="data">Application data.</param>
  2122. /// <param name="name">Name of the data.</param>
  2123. /// <param name="maxNestingLevel">Maximum nesting level of business objects.</param>
  2124. /// <remarks>
  2125. /// This method creates initial datasource with specified nesting level. It is useful if
  2126. /// you create a report in code. In most cases, you don't need to specify the nesting level
  2127. /// because it may be selected in the designer's "Choose Report Data" dialog.
  2128. /// </remarks>
  2129. public void RegisterData(IEnumerable data, string name, int maxNestingLevel)
  2130. {
  2131. Dictionary.RegisterBusinessObject(data, name, maxNestingLevel, false);
  2132. }
  2133. /// <summary>
  2134. /// Registers the application cube link to use it in the report.
  2135. /// </summary>
  2136. /// <param name="data">The application data.</param>
  2137. /// <param name="name">The name of the data.</param>
  2138. /// <example>
  2139. /// <code>
  2140. /// report1.Load("report.frx");
  2141. /// report1.RegisterData(myCubeLink, "Orders");
  2142. /// </code>
  2143. /// </example>
  2144. public void RegisterData(IBaseCubeLink data, string name)
  2145. {
  2146. Dictionary.RegisterCubeLink(data, name, false);
  2147. }
  2148. /// <summary>
  2149. /// Prepares the report.
  2150. /// </summary>
  2151. /// <returns><b>true</b> if report was prepared succesfully.</returns>
  2152. public bool Prepare()
  2153. {
  2154. return Prepare(false);
  2155. }
  2156. /// <summary>
  2157. /// Prepares the report.
  2158. /// </summary>
  2159. /// <param name="append">Specifies whether the new report should be added to a
  2160. /// report that was prepared before.</param>
  2161. /// <returns><b>true</b> if report was prepared succesfully.</returns>
  2162. /// <remarks>
  2163. /// Use this method to merge prepared reports.
  2164. /// </remarks>
  2165. /// <example>This example shows how to merge two reports and preview the result:
  2166. /// <code>
  2167. /// Report report = new Report();
  2168. /// report.Load("report1.frx");
  2169. /// report.Prepare();
  2170. /// report.Load("report2.frx");
  2171. /// report.Prepare(true);
  2172. /// report.ShowPrepared();
  2173. /// </code>
  2174. /// </example>
  2175. public bool Prepare(bool append)
  2176. {
  2177. SetRunning(true);
  2178. try
  2179. {
  2180. if (PreparedPages == null || !append)
  2181. {
  2182. ClearPreparedPages();
  2183. SetPreparedPages(new Preview.PreparedPages(this));
  2184. }
  2185. engine = new ReportEngine(this);
  2186. if (!Config.WebMode)
  2187. StartPerformanceCounter();
  2188. try
  2189. {
  2190. Compile();
  2191. return Engine.Run(true, append, true);
  2192. }
  2193. finally
  2194. {
  2195. if (!Config.WebMode)
  2196. StopPerformanceCounter();
  2197. }
  2198. }
  2199. finally
  2200. {
  2201. SetRunning(false);
  2202. }
  2203. }
  2204. /// <summary>
  2205. /// Prepares the report with pages limit.
  2206. /// </summary>
  2207. /// <param name="pagesLimit">Pages limit. The number of pages equal or less will be prepared.</param>
  2208. /// <returns><b>true</b> if report was prepared succesfully.</returns>
  2209. public bool Prepare(int pagesLimit)
  2210. {
  2211. SetRunning(true);
  2212. try
  2213. {
  2214. ClearPreparedPages();
  2215. SetPreparedPages(new Preview.PreparedPages(this));
  2216. engine = new ReportEngine(this);
  2217. if (!Config.WebMode)
  2218. StartPerformanceCounter();
  2219. try
  2220. {
  2221. Compile();
  2222. return Engine.Run(true, false, true, pagesLimit);
  2223. }
  2224. finally
  2225. {
  2226. if (!Config.WebMode)
  2227. StopPerformanceCounter();
  2228. }
  2229. }
  2230. finally
  2231. {
  2232. SetRunning(false);
  2233. }
  2234. }
  2235. /// <summary>
  2236. /// For internal use only.
  2237. /// </summary>
  2238. [EditorBrowsable(EditorBrowsableState.Never)]
  2239. public void PreparePhase1()
  2240. {
  2241. bool webDialog = false;
  2242. SetRunning(true);
  2243. if (preparedPages != null)
  2244. {
  2245. // if prepared pages are set before => it's call method again => it's web dialog
  2246. webDialog = true;
  2247. preparedPages.Clear();
  2248. }
  2249. SetPreparedPages(new Preview.PreparedPages(this));
  2250. engine = new ReportEngine(this);
  2251. Compile();
  2252. Engine.RunPhase1(true, webDialog);
  2253. }
  2254. /// <summary>
  2255. /// For internal use only.
  2256. /// </summary>
  2257. [EditorBrowsable(EditorBrowsableState.Never)]
  2258. public void PreparePhase2(int? pagesLimit = null)
  2259. {
  2260. Engine.RunPhase2(pagesLimit);
  2261. SetRunning(false);
  2262. }
  2263. /// <summary>
  2264. /// Refresh the current report.
  2265. /// </summary>
  2266. /// <remarks>
  2267. /// Call this method in the Click or MouseUp event handler of a report object to refresh
  2268. /// the currently previewed report. Report will be generated again, but without dialog forms.
  2269. /// </remarks>
  2270. public void Refresh()
  2271. {
  2272. needRefresh = true;
  2273. }
  2274. /// <summary>
  2275. /// Refresh prepared report after intercative actions.
  2276. /// </summary>
  2277. public void InteractiveRefresh()
  2278. {
  2279. PreparedPages.ClearPageCache();
  2280. InternalRefresh();
  2281. }
  2282. internal void InternalRefresh()
  2283. {
  2284. SetRunning(true);
  2285. try
  2286. {
  2287. Engine.Run(false, false, false);
  2288. }
  2289. finally
  2290. {
  2291. SetRunning(false);
  2292. }
  2293. }
  2294. internal TextRenderingHint GetTextQuality()
  2295. {
  2296. switch (this.TextQuality)
  2297. {
  2298. case TextQuality.Regular:
  2299. return TextRenderingHint.AntiAliasGridFit;
  2300. case TextQuality.ClearType:
  2301. return TextRenderingHint.ClearTypeGridFit;
  2302. case TextQuality.AntiAlias:
  2303. return TextRenderingHint.AntiAlias;
  2304. case TextQuality.SingleBPP:
  2305. return TextRenderingHint.SingleBitPerPixel;
  2306. case TextQuality.SingleBPPGridFit:
  2307. return TextRenderingHint.SingleBitPerPixelGridFit;
  2308. }
  2309. return TextRenderingHint.SystemDefault;
  2310. }
  2311. /// <summary>
  2312. /// Prepare page
  2313. /// </summary>
  2314. /// <param name="page"></param>
  2315. public void PreparePage(ReportPage page)
  2316. {
  2317. SetRunning(true);
  2318. try
  2319. {
  2320. Engine.Run(false, false, false, page);
  2321. }
  2322. finally
  2323. {
  2324. SetRunning(false);
  2325. }
  2326. }
  2327. /// <summary>
  2328. /// Exports a report. Report should be prepared using the <see cref="Prepare()"/> method.
  2329. /// </summary>
  2330. /// <param name="export">The export filter.</param>
  2331. /// <param name="stream">Stream to save export result to.</param>
  2332. public void Export(ExportBase export, Stream stream)
  2333. {
  2334. export.Export(this, stream);
  2335. }
  2336. /// <summary>
  2337. /// Exports a report. Report should be prepared using the <see cref="Prepare()"/> method.
  2338. /// </summary>
  2339. /// <param name="export">The export filter.</param>
  2340. /// <param name="fileName">File name to save export result to.</param>
  2341. public void Export(ExportBase export, string fileName)
  2342. {
  2343. export.Export(this, fileName);
  2344. }
  2345. /// <summary>
  2346. /// Saves the prepared report. Report should be prepared using the <see cref="Prepare()"/> method.
  2347. /// </summary>
  2348. /// <param name="fileName">File name to save to.</param>
  2349. public void SavePrepared(string fileName)
  2350. {
  2351. if (PreparedPages != null)
  2352. PreparedPages.Save(fileName);
  2353. }
  2354. /// <summary>
  2355. /// Saves the prepared report. Report should be prepared using the <see cref="Prepare()"/> method.
  2356. /// </summary>
  2357. /// <param name="stream">Stream to save to.</param>
  2358. public void SavePrepared(Stream stream)
  2359. {
  2360. if (PreparedPages != null)
  2361. PreparedPages.Save(stream);
  2362. }
  2363. /// <summary>
  2364. /// Loads the prepared report from a .fpx file.
  2365. /// </summary>
  2366. /// <param name="fileName">File name to load form.</param>
  2367. public void LoadPrepared(string fileName)
  2368. {
  2369. isLoadPrepared = true;
  2370. if (PreparedPages == null)
  2371. SetPreparedPages(new FastReport.Preview.PreparedPages(this));
  2372. PreparedPages.Load(fileName);
  2373. }
  2374. /// <summary>
  2375. /// Loads the prepared report from a .fpx file.
  2376. /// </summary>
  2377. /// <param name="stream">Stream to load from.</param>
  2378. public void LoadPrepared(Stream stream)
  2379. {
  2380. isLoadPrepared = true;
  2381. if (PreparedPages == null)
  2382. SetPreparedPages(new FastReport.Preview.PreparedPages(this));
  2383. PreparedPages.Load(stream);
  2384. }
  2385. #endregion Public Methods
  2386. /// <summary>
  2387. /// Initializes a new instance of the <see cref="Report"/> class with default settings.
  2388. /// </summary>
  2389. public Report()
  2390. {
  2391. pages = new PageCollection(this);
  2392. reportInfo = new ReportInfo();
  2393. InitDesign();
  2394. styles = new StyleCollection();
  2395. Dictionary = new Dictionary();
  2396. graphicCache = new GraphicCache();
  2397. assemblies = new AssemblyCollection();
  2398. cachedDataItems = new Hashtable(StringComparer.InvariantCultureIgnoreCase); // needed for case insensitivity
  2399. storeInResources = true;
  2400. fileName = "";
  2401. autoFillDataSet = true;
  2402. tag = null;
  2403. ClearReportProperties();
  2404. SetFlags(Flags.CanMove | Flags.CanResize | Flags.CanDelete | Flags.CanEdit | Flags.CanChangeOrder |
  2405. Flags.CanChangeParent | Flags.CanCopy, false);
  2406. //FInlineImageCache = new InlineImageCache();
  2407. }
  2408. static Report()
  2409. {
  2410. Config.Init();
  2411. }
  2412. /// <summary>
  2413. /// Ensure that static constructor is called.
  2414. /// </summary>
  2415. public static void EnsureInit()
  2416. {
  2417. // do nothing, just ensure that static constructor is called.
  2418. }
  2419. /// <summary>
  2420. /// Create name for all unnamed elements with prefix and start with number
  2421. /// </summary>
  2422. /// <param name="prefix">Prefix for name</param>
  2423. /// <param name="number">Number from which to start</param>
  2424. public void PostNameProcess(string prefix, int number)
  2425. {
  2426. int i = number;
  2427. foreach (Base obj in AllObjects)
  2428. {
  2429. if (String.IsNullOrEmpty(obj.Name))
  2430. {
  2431. obj.SetName(prefix + i.ToString());
  2432. i++;
  2433. }
  2434. }
  2435. }
  2436. private class CachedDataItem
  2437. {
  2438. public DataSourceBase dataSource;
  2439. public Column column;
  2440. }
  2441. }
  2442. }