Report.cs 99 KB

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