DevExpressImport.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Drawing;
  5. using FastReport.Barcode;
  6. using FastReport.Table;
  7. using FastReport.Utils;
  8. using System.Linq;
  9. namespace FastReport.Import.DevExpress
  10. {
  11. /// <summary>
  12. /// Represents the DevExpess import plugin.
  13. /// </summary>
  14. public partial class DevExpressImport : ImportBase
  15. {
  16. #region Constants
  17. private const string TOP_MARGIN_BAND_MASK = "DevExpress.XtraReports.UI.TopMarginBand";
  18. private const string BOTTOM_MARGIN_BAND_MASK = "DevExpress.XtraReports.UI.BottomMarginBand";
  19. private const string DETAIL_REPORT_BAND_MASK = "DevExpress.XtraReports.UI.DetailReportBand";
  20. private const string REPORT_HEADER_BAND_MASK = "DevExpress.XtraReports.UI.ReportHeaderBand";
  21. private const string REPORT_FOOTER_BAND_MASK = "DevExpress.XtraReports.UI.ReportFooterBand";
  22. private const string DETAIL_BAND_MASK = "DevExpress.XtraReports.UI.DetailBand";
  23. private const string GROUP_HEADER_BAND_MASK = "DevExpress.XtraReports.UI.GroupHeaderBand";
  24. private const string GROUP_FOOTER_BAND_MASK = "DevExpress.XtraReports.UI.GroupFooterBand";
  25. private const string BAND_CHILD_DEFINITION = "new DevExpress.XtraReports.UI.XRControl[]";
  26. private const string BAND_CHILDBAND_DEFINITION = "new DevExpress.XtraReports.UI.Band[]";
  27. private const string DEV_EXPRESS_LABEL = "DevExpress.XtraReports.UI.XRLabel";
  28. private const string DEV_EXPRESS_LINE = "DevExpress.XtraReports.UI.XRLine";
  29. private const string DEV_EXPRESS_TABLE = "DevExpress.XtraReports.UI.XRTable";
  30. private const string DEV_EXPRESS_TABLE_ROW = "DevExpress.XtraReports.UI.XRTableRow";
  31. private const string DEV_EXPRESS_TABLE_CELL = "DevExpress.XtraReports.UI.XRTableCell";
  32. private const string DEV_EXPRESS_PICTURE = "DevExpress.XtraReports.UI.XRPictureBox";
  33. private const string DEV_EXPRESS_PAGE_INFO = "DevExpress.XtraReports.UI.XRPageInfo";
  34. private const string DEV_EXPRESS_SHAPE = "DevExpress.XtraReports.UI.XRShape";
  35. private const string DEV_EXPRESS_ZIP_CODE = "DevExpress.XtraReports.UI.XRZipCode";
  36. private const string DEV_EXPRESS_BAR_CODE = "DevExpress.XtraReports.UI.XRBarCode";
  37. private const string DEV_EXPRESS_RICH_TEXT = "DevExpress.XtraReports.UI.XRRichText";
  38. private const string DEV_EXPRESS_STYLE = "DevExpress.XtraReports.UI.XRControlStyle ";
  39. #endregion // Constants
  40. #region Fields
  41. private ReportPage page;
  42. private string devText;
  43. private List<string> outsideBands = new List<string>();
  44. #endregion // Fields
  45. private class TableInfo
  46. {
  47. public List<float> Column;
  48. public List<float> Row;
  49. public TableInfo()
  50. {
  51. Column = new List<float>();
  52. Row = new List<float>();
  53. }
  54. }
  55. #region Constructors
  56. /// <summary>
  57. /// Initializes a new instance of the <see cref="DevExpressImport"/> class.
  58. /// </summary>
  59. public DevExpressImport() : base()
  60. {
  61. devText = "";
  62. }
  63. #endregion // Constructors
  64. #region Private Methods
  65. private void LoadReportCode()
  66. {
  67. if (devText.IndexOf("namespace") >= 0)
  68. {
  69. devText = devText.Remove(0, devText.IndexOf("namespace")).Replace(@"http://", " ");
  70. }
  71. LoadReport();
  72. page = null;
  73. }
  74. private string FindObjectName(string mask)
  75. {
  76. string name = "";
  77. int start = devText.IndexOf(mask);
  78. if (start > -1)
  79. {
  80. start += mask.Length;
  81. int length = devText.IndexOf(";", start) - start;
  82. name = devText.Substring(start, length).Trim();
  83. }
  84. return name;
  85. }
  86. private void LoadOutsideBandsNames()
  87. {
  88. string bandsRagneStart = "this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[]";
  89. int start = devText.IndexOf(bandsRagneStart);
  90. if (start > -1)
  91. {
  92. start += bandsRagneStart.Length;
  93. int lenght = devText.IndexOf(";", start) - start;
  94. string bandsEnumeration = devText.Substring(start, lenght).Replace("{", "").Replace("}", "").Replace(")", "").Replace("\n", "").Replace("\r", "").Trim();
  95. string[] outBands = bandsEnumeration.Split(',');
  96. outsideBands.Clear();
  97. foreach (string bandString in outBands)
  98. {
  99. // Trim() is not working :(
  100. string band = String.Concat(bandString.Where(c => !Char.IsWhiteSpace(c)));
  101. if (band.StartsWith("this."))
  102. outsideBands.Add(band.Substring(5));
  103. else
  104. outsideBands.Add(band);
  105. }
  106. }
  107. }
  108. private string FindReportOutsideBandName(string mask)
  109. {
  110. string name = "";
  111. int start = devText.IndexOf(mask);
  112. while (start != -1)
  113. {
  114. if (start == -1)
  115. return string.Empty;
  116. start += mask.Length;
  117. int length = devText.IndexOf(";", start) - start;
  118. name = devText.Substring(start, length).Trim();
  119. if (outsideBands.Contains(name))
  120. return name;
  121. start = devText.IndexOf(mask, start + mask.Length);
  122. }
  123. return string.Empty;
  124. }
  125. private string GetObjectDescription(string name)
  126. {
  127. string description = "";
  128. int start = 0;
  129. while (start > -1)
  130. {
  131. start = devText.IndexOf(@"// " + name, start);
  132. if (devText.Substring(start, name.Length + 2 + 3).EndsWith("\r\n"))
  133. break;
  134. start += 1;
  135. }
  136. if (start > -1)
  137. {
  138. start = devText.IndexOf(@"//", start + 2);
  139. int length = devText.IndexOf(@"//", start + 2) - start + 2;
  140. description = devText.Substring(start, length);
  141. }
  142. return description;
  143. }
  144. private string GetPropertyValue(string name, string description)
  145. {
  146. string value = "";
  147. int start = description.IndexOf("." + name + " ");
  148. if (start > -1)
  149. {
  150. start += name.Length + 3;
  151. int length = description.IndexOf(";", start) - start;
  152. value = description.Substring(start, length).Trim();
  153. }
  154. return value;
  155. }
  156. private bool ExistValue(string name, string description)
  157. {
  158. int start = description.IndexOf("." + name + " ");
  159. return start > 0;
  160. }
  161. private int GetLevelPropValue(string description)
  162. {
  163. string level = "level = ";
  164. if (description == null)
  165. return -1;
  166. int start = description.ToLower().IndexOf(level);
  167. if (start > -1)
  168. {
  169. string value = description.Substring(start + level.Length, 1);
  170. try
  171. {
  172. return int.Parse(value);
  173. }
  174. catch
  175. {
  176. return -1;
  177. }
  178. //bool parsed = int.TryParse(value, out int resultValue);
  179. //if (parsed)
  180. // return resultValue;
  181. }
  182. return -1;
  183. }
  184. private void LoadBand(BandBase band, string description)
  185. {
  186. if (ExistValue("HeightF", description))
  187. band.Height = UnitsConverter.SizeFToPixels(GetPropertyValue("HeightF", description));
  188. else
  189. band.Height = UnitsConverter.SizeFToPixels("100F");
  190. band.FillColor = UnitsConverter.ConvertBackColor(GetPropertyValue("BackColor", description));
  191. }
  192. private List<string> GetObjectNames(string description)
  193. {
  194. List<string> names = new List<string>();
  195. int start = description.IndexOf(BAND_CHILD_DEFINITION);
  196. if (start > -1)
  197. {
  198. start += BAND_CHILD_DEFINITION.Length;
  199. int end = description.IndexOf("});", start);
  200. string namesStr = description.Substring(start, end - start + 1).Replace("}", ",");
  201. int pos = 0;
  202. while (pos < end)
  203. {
  204. pos = namesStr.IndexOf("this.", pos);
  205. if (pos < 0)
  206. {
  207. break;
  208. }
  209. names.Add(namesStr.Substring(pos + 5, namesStr.IndexOf(",", pos) - pos - 5));
  210. pos += 5;
  211. }
  212. }
  213. return names;
  214. }
  215. private List<string> GetBandsNames(string description)
  216. {
  217. List<string> names = new List<string>();
  218. int start = description.IndexOf(BAND_CHILDBAND_DEFINITION);
  219. if (start > -1)
  220. {
  221. start += BAND_CHILDBAND_DEFINITION.Length;
  222. int end = description.IndexOf("});", start);
  223. string namesStr = description.Substring(start, end - start + 1).Replace("}", ",");
  224. int pos = 0;
  225. while (pos < end)
  226. {
  227. pos = namesStr.IndexOf("this.", pos);
  228. if (pos < 0)
  229. {
  230. break;
  231. }
  232. names.Add(namesStr.Substring(pos + 5, namesStr.IndexOf(",", pos) - pos - 5));
  233. pos += 5;
  234. }
  235. }
  236. return names;
  237. }
  238. private bool IsTypeOfBand(string name, string bandType)
  239. {
  240. int index = devText.IndexOf(name + " = new " + bandType);
  241. if (index > -1)
  242. return true;
  243. return false;
  244. }
  245. private string GetBandType(string name)
  246. {
  247. string type = string.Empty;
  248. int start = devText.IndexOf(name + " = new ");
  249. if (start > -1)
  250. {
  251. int end = devText.IndexOf(";", start);
  252. start += name.Length + 7;
  253. type = devText.Substring(start, end - start - 2);
  254. }
  255. return type;
  256. }
  257. private string GetObjectType(string name)
  258. {
  259. string str = "this." + name + " = new ";
  260. int start = devText.IndexOf(str) + str.Length;
  261. int end = devText.IndexOf("();", start);
  262. return devText.Substring(start, end - start);
  263. }
  264. private void LoadComponent(string description, ComponentBase comp)
  265. {
  266. comp.Name = GetPropertyValue("Name", description).Replace("\"", "");
  267. string location = GetPropertyValue("LocationFloat", description);
  268. if (!String.IsNullOrEmpty(location))
  269. {
  270. int start = location.IndexOf("(");
  271. int comma = location.IndexOf(",", start);
  272. int end = location.IndexOf(")");
  273. comp.Left = UnitsConverter.SizeFToPixels(location.Substring(start + 1, comma - start));
  274. comp.Top = UnitsConverter.SizeFToPixels(location.Substring(comma + 2, end - comma - 1));
  275. }
  276. }
  277. private void LoadBorder(string description, Border border)
  278. {
  279. string borders = GetPropertyValue("Borders", description);
  280. if (!String.IsNullOrEmpty(borders))
  281. {
  282. if (borders.IndexOf("Left") > -1)
  283. {
  284. border.Lines |= BorderLines.Left;
  285. }
  286. if (borders.IndexOf("Top") > -1)
  287. {
  288. border.Lines |= BorderLines.Top;
  289. }
  290. if (borders.IndexOf("Right") > -1)
  291. {
  292. border.Lines |= BorderLines.Right;
  293. }
  294. if (borders.IndexOf("Bottom") > -1)
  295. {
  296. border.Lines |= BorderLines.Bottom;
  297. }
  298. }
  299. string color = GetPropertyValue("BorderColor", description);
  300. if (!String.IsNullOrEmpty(color))
  301. {
  302. border.Color = UnitsConverter.ConvertColor(color);
  303. }
  304. string style = GetPropertyValue("BorderDashStyle", description);
  305. if (!String.IsNullOrEmpty(style))
  306. {
  307. border.Style = UnitsConverter.ConvertBorderDashStyle(style);
  308. }
  309. string width = GetPropertyValue("BorderWidth", description);
  310. if (!String.IsNullOrEmpty(width))
  311. {
  312. border.Width = UnitsConverter.SizeFToPixels(width);
  313. }
  314. }
  315. private void LoadSize(string description, ComponentBase comp)
  316. {
  317. string size = GetPropertyValue("SizeF", description);
  318. if (!String.IsNullOrEmpty(size))
  319. {
  320. int start = size.IndexOf("(");
  321. int comma = size.IndexOf(",", start);
  322. int end = size.IndexOf(")");
  323. comp.Width = UnitsConverter.SizeFToPixels(size.Substring(start + 1, comma - start));
  324. comp.Height = UnitsConverter.SizeFToPixels(size.Substring(comma + 2, end - comma - 1));
  325. }
  326. }
  327. private Font LoadFont(string description)
  328. {
  329. string font = GetPropertyValue("Font", description);
  330. if (!String.IsNullOrEmpty(font))
  331. {
  332. int start = font.IndexOf("(");
  333. int comma = font.IndexOf(",", start);
  334. int secondComma = font.IndexOf(",", comma + 1);
  335. string fontFamily = font.Substring(start + 2, comma - start - 3);
  336. float fontSize = 10.0f;
  337. if (secondComma > -1)
  338. {
  339. string str = font.Substring(comma + 2, secondComma - comma - 2);
  340. fontSize = UnitsConverter.SizeFToPixelsFont(font.Substring(comma + 2, secondComma - comma - 2));
  341. FontStyle fontStyle = FontStyle.Regular;
  342. if (font.Contains("Bold"))
  343. {
  344. fontStyle |= FontStyle.Bold;
  345. }
  346. if (font.Contains("Italic"))
  347. {
  348. fontStyle |= FontStyle.Italic;
  349. }
  350. if (font.Contains("Underline"))
  351. {
  352. fontStyle |= FontStyle.Underline;
  353. }
  354. if (font.Contains("Strikeout"))
  355. {
  356. fontStyle |= FontStyle.Strikeout;
  357. }
  358. return new Font(fontFamily, fontSize, fontStyle);
  359. }
  360. else
  361. {
  362. string str = font.Substring(comma + 2, font.IndexOf(")") - comma - 2);
  363. fontSize = UnitsConverter.SizeFToPixelsFont(font.Substring(comma + 2, font.IndexOf(")") - comma - 2));
  364. }
  365. }
  366. return new Font("Arial", 10.0f, FontStyle.Regular);
  367. }
  368. private void LoadLabel(string name, Base parent)
  369. {
  370. string description = GetObjectDescription(name);
  371. TextObject text = ComponentsFactory.CreateTextObject(name, parent);
  372. LoadComponent(description, text);
  373. LoadSize(description, text);
  374. LoadBorder(description, text.Border);
  375. text.Name = name;
  376. text.FillColor = UnitsConverter.ConvertBackColor(GetPropertyValue("BackColor", description));
  377. text.TextColor = UnitsConverter.ConvertColor(GetPropertyValue("ForeColor", description));
  378. text.Text = GetPropertyValue("Text", description).Replace("\"", "");
  379. text.HorzAlign = UnitsConverter.ConvertTextAlignmentToHorzAlign(GetPropertyValue("TextAlignment", description));
  380. text.VertAlign = UnitsConverter.ConvertTextAlignmentToVertAlign(GetPropertyValue("TextAlignment", description));
  381. text.Font = LoadFont(description);
  382. ApplyStyleByName(text, GetPropertyValue("StyleName", description).Replace("\"", ""));
  383. }
  384. private void LoadTableCell(string name, TableCell cell)
  385. {
  386. string description = GetObjectDescription(name);
  387. cell.Name = name;
  388. cell.FillColor = UnitsConverter.ConvertBackColor(GetPropertyValue("BackColor", description));
  389. cell.TextColor = UnitsConverter.ConvertColor(GetPropertyValue("ForeColor", description));
  390. cell.Text = GetPropertyValue("Text", description).Replace("\"", "");
  391. cell.HorzAlign = UnitsConverter.ConvertTextAlignmentToHorzAlign(GetPropertyValue("TextAlignment", description));
  392. cell.VertAlign = UnitsConverter.ConvertTextAlignmentToVertAlign(GetPropertyValue("TextAlignment", description));
  393. cell.Font = LoadFont(description);
  394. ApplyStyleByName(cell, GetPropertyValue("StyleName", description).Replace("\"", ""));
  395. }
  396. private void LoadLine(string name, Base parent)
  397. {
  398. string description = GetObjectDescription(name);
  399. LineObject line = ComponentsFactory.CreateLineObject(name, parent);
  400. LoadComponent(description, line);
  401. LoadSize(description, line);
  402. line.Border.Color = UnitsConverter.ConvertColor(GetPropertyValue("ForeColor", description));
  403. line.Border.Style = UnitsConverter.ConvertLineStyle(GetPropertyValue("LineStyle", description));
  404. string width = GetPropertyValue("LineWidth", description);
  405. if (!String.IsNullOrEmpty(width))
  406. {
  407. line.Border.Width = Convert.ToSingle(width);
  408. }
  409. line.Style = GetPropertyValue("StyleName", description).Replace("\"", "");
  410. }
  411. private void LoadPicture(string name, Base parent)
  412. {
  413. string description = GetObjectDescription(name);
  414. PictureObject picture = ComponentsFactory.CreatePictureObject(name, parent);
  415. LoadComponent(description, picture);
  416. LoadSize(description, picture);
  417. picture.SizeMode = UnitsConverter.ConvertImageSizeMode(GetPropertyValue("Sizing", description));
  418. picture.Style = GetPropertyValue("StyleName", description).Replace("\"", "");
  419. }
  420. private void LoadShape(string name, Base parent)
  421. {
  422. string description = GetObjectDescription(name);
  423. ShapeObject shape = ComponentsFactory.CreateShapeObject(name, parent);
  424. LoadComponent(description, shape);
  425. LoadSize(description, shape);
  426. shape.Border.Color = UnitsConverter.ConvertColor(GetPropertyValue("ForeColor", description));
  427. shape.FillColor = UnitsConverter.ConvertBackColor(GetPropertyValue("FillColor", description));
  428. shape.Shape = UnitsConverter.ConvertShape(GetPropertyValue("Shape", description));
  429. string width = GetPropertyValue("LineWidth", description);
  430. if (!String.IsNullOrEmpty(width))
  431. {
  432. shape.Border.Width = Convert.ToSingle(width);
  433. }
  434. shape.Style = GetPropertyValue("StyleName", description).Replace("\"", "");
  435. }
  436. private void LoadZipCode(string name, Base parent)
  437. {
  438. string description = GetObjectDescription(name);
  439. ZipCodeObject zipCode = ComponentsFactory.CreateZipCodeObject(name, parent);
  440. LoadComponent(description, zipCode);
  441. LoadSize(description, zipCode);
  442. zipCode.FillColor = UnitsConverter.ConvertBackColor(GetPropertyValue("BackColor", description));
  443. zipCode.Border.Color = UnitsConverter.ConvertColor(GetPropertyValue("ForeColor", description));
  444. zipCode.Text = GetPropertyValue("Text", description).Replace("\"", "");
  445. zipCode.Style = GetPropertyValue("StyleName", description).Replace("\"", "");
  446. }
  447. private void LoadBarCode(string name, Base parent)
  448. {
  449. string description = GetObjectDescription(name);
  450. BarcodeObject barcode = ComponentsFactory.CreateBarcodeObject(name, parent);
  451. LoadComponent(description, barcode);
  452. LoadSize(description, barcode);
  453. LoadBorder(description, barcode.Border);
  454. barcode.FillColor = UnitsConverter.ConvertBackColor(GetPropertyValue("BackColor", description));
  455. UnitsConverter.ConvertBarcodeSymbology(GetPropertyValue("Symbology", description), barcode);
  456. barcode.Style = GetPropertyValue("StyleName", description).Replace("\"", "");
  457. }
  458. partial void LoadRichText(string name, Base parent);
  459. private List<string> GetChildNames(string childType, string description)
  460. {
  461. List<string> names = new List<string>();
  462. int start = description.IndexOf(childType + "[]");
  463. if (start > -1)
  464. {
  465. start += childType.Length + 2;
  466. int end = description.IndexOf("});", start);
  467. string namesStr = description.Substring(start, end - start + 1).Replace("}", ",");
  468. int pos = 0;
  469. while (pos < end)
  470. {
  471. pos = namesStr.IndexOf("this.", pos);
  472. if (pos < 0)
  473. {
  474. break;
  475. }
  476. names.Add(namesStr.Substring(pos + 5, namesStr.IndexOf(",", pos) - pos - 5));
  477. pos += 5;
  478. }
  479. }
  480. return names;
  481. }
  482. private void LoadTable(string name, Base parent)
  483. {
  484. string description = GetObjectDescription(name);
  485. TableObject table = ComponentsFactory.CreateTableObject(name, parent);
  486. LoadComponent(description, table);
  487. LoadSize(description, table);
  488. LoadBorder(description, table.Border);
  489. table.Style = GetPropertyValue("StyleName", description).Replace("\"", "");
  490. List<string> rowNames = GetChildNames(DEV_EXPRESS_TABLE_ROW, description);
  491. TableInfo tableInfo = new TableInfo();
  492. // Create table columns.
  493. int columnsCount = 0;
  494. foreach (string rowName in rowNames)
  495. {
  496. string rowDescription = GetObjectDescription(rowName);
  497. List<string> cellNames = GetChildNames(DEV_EXPRESS_TABLE_CELL, rowDescription);
  498. if (columnsCount < cellNames.Count)
  499. {
  500. columnsCount = cellNames.Count;
  501. tableInfo.Column.Clear();
  502. foreach (string cellName in cellNames)
  503. {
  504. tableInfo.Column.Add(GetWeight(cellName));
  505. }
  506. }
  507. }
  508. for (int i = 0; i < rowNames.Count; i++)
  509. {
  510. tableInfo.Row.Add(GetWeight(rowNames[i]));
  511. }
  512. for (int i = 0; i < columnsCount; i++)
  513. {
  514. TableColumn column = new TableColumn();
  515. column.Width = GetRowColumnSize(tableInfo.Column, i, table.Width);
  516. table.Columns.Add(column);
  517. column.CreateUniqueName();
  518. }
  519. // Create table rows.
  520. for (int i = 0; i < rowNames.Count; i++)
  521. {
  522. TableRow row = new TableRow();
  523. row.Name = rowNames[i];
  524. string rowDescription = GetObjectDescription(row.Name);
  525. row.Height = GetRowColumnSize(tableInfo.Row, i, table.Height);
  526. List<string> cellNames = GetChildNames(DEV_EXPRESS_TABLE_CELL, rowDescription);
  527. // Create table cell.
  528. foreach (string cellName in cellNames)
  529. {
  530. TableCell cell = new TableCell();
  531. cell.Name = cellName;
  532. LoadTableCell(cellName, cell);
  533. row.AddChild(cell);
  534. }
  535. table.Rows.Add(row);
  536. }
  537. }
  538. private float GetWeight(string componentName)
  539. {
  540. string weight = GetPropertyValue("Weight", GetObjectDescription(componentName));
  541. weight = weight.Substring(0, weight.Length - 1);
  542. return float.Parse(weight.Replace(".", ","));
  543. }
  544. private float GetRowColumnSize(List<float> allSizes, int index, float totalSize)
  545. {
  546. float size = totalSize / allSizes.Sum() * allSizes[index];
  547. if (allSizes.Count == 1)
  548. return totalSize;
  549. return size;
  550. }
  551. private void LoadObjects(string description, Base parent)
  552. {
  553. List<string> names = GetObjectNames(description);
  554. foreach (string name in names)
  555. {
  556. string type = GetObjectType(name);
  557. if (!String.IsNullOrEmpty(type))
  558. {
  559. switch (type)
  560. {
  561. case DEV_EXPRESS_LABEL:
  562. LoadLabel(name, parent);
  563. break;
  564. case DEV_EXPRESS_PAGE_INFO:
  565. LoadLabel(name, parent);
  566. break;
  567. case DEV_EXPRESS_LINE:
  568. LoadLine(name, parent);
  569. break;
  570. case DEV_EXPRESS_PICTURE:
  571. LoadPicture(name, parent);
  572. break;
  573. case DEV_EXPRESS_SHAPE:
  574. LoadShape(name, parent);
  575. break;
  576. case DEV_EXPRESS_ZIP_CODE:
  577. LoadZipCode(name, parent);
  578. break;
  579. case DEV_EXPRESS_BAR_CODE:
  580. LoadBarCode(name, parent);
  581. break;
  582. case DEV_EXPRESS_RICH_TEXT:
  583. LoadRichText(name, parent);
  584. break;
  585. case DEV_EXPRESS_TABLE:
  586. LoadTable(name, parent);
  587. break;
  588. default:
  589. break;
  590. }
  591. }
  592. }
  593. }
  594. private void LoadPageSize()
  595. {
  596. string height = GetPropertyValue("PageHeight", devText);
  597. string width = GetPropertyValue("PageWidth", devText);
  598. if (!String.IsNullOrEmpty(height))
  599. page.PaperHeight = UnitsConverter.SizeFToPixels(height) / Units.Millimeters;
  600. if (!String.IsNullOrEmpty(width))
  601. page.PaperWidth = UnitsConverter.SizeFToPixels(width) / Units.Millimeters;
  602. }
  603. private void CheckDpiZoom()
  604. {
  605. string dpi = GetPropertyValue("Dpi", devText);
  606. if (!String.IsNullOrEmpty(dpi))
  607. {
  608. UnitsConverter.Ratio = float.Parse(dpi.Substring(0, dpi.Length - 1)) / 96;
  609. }
  610. }
  611. private List<string> GetStyleNames()
  612. {
  613. List<string> names = new List<string>();
  614. int start = devText.IndexOf(DEV_EXPRESS_STYLE);
  615. while (start > -1)
  616. {
  617. start += DEV_EXPRESS_STYLE.Length;
  618. int end = devText.IndexOf(";", start);
  619. names.Add(devText.Substring(start, end - start));
  620. start = end;
  621. start = devText.IndexOf(DEV_EXPRESS_STYLE, start);
  622. }
  623. return names;
  624. }
  625. private void LoadStyles()
  626. {
  627. List<string> names = GetStyleNames();
  628. foreach (string name in names)
  629. {
  630. Style style = ComponentsFactory.CreateStyle(name, Report);
  631. string description = GetObjectDescription(name);
  632. LoadBorder(description, style.Border);
  633. style.TextFill = new SolidFill(UnitsConverter.ConvertColor(GetPropertyValue("ForeColor", description)));
  634. style.Fill = new SolidFill(UnitsConverter.ConvertBackColor(GetPropertyValue("BackColor", description)));
  635. style.Font = LoadFont(description);
  636. }
  637. }
  638. private void ApplyStyleByName(ReportComponentBase component, string styleName)
  639. {
  640. foreach (Style subStyle in Report.Styles)
  641. {
  642. if (subStyle.Name == styleName)
  643. {
  644. Font f = new Font("Arial", 10, FontStyle.Regular);
  645. if (component is TextObject)
  646. {
  647. f = (component as TextObject).Font;
  648. }
  649. component.Style = styleName;
  650. component.ApplyStyle(subStyle);
  651. string descr = GetObjectDescription(component.Name);
  652. string useFont = GetPropertyValue("UseFont", descr);
  653. if (useFont != string.Empty)
  654. if (!UnitsConverter.ConvertBool(useFont))
  655. {
  656. (component as TextObject).Font = f;
  657. }
  658. return;
  659. }
  660. }
  661. }
  662. private void LoadTopMarginBand() // Page Header
  663. {
  664. string name = FindObjectName(TOP_MARGIN_BAND_MASK);
  665. if (!String.IsNullOrEmpty(name))
  666. {
  667. PageHeaderBand header = ComponentsFactory.CreatePageHeaderBand(page);
  668. string description = GetObjectDescription(name);
  669. LoadBand(header, description);
  670. LoadObjects(description, header);
  671. }
  672. }
  673. private void LoadBottomMarginBand() // Page Footer
  674. {
  675. string name = FindObjectName(BOTTOM_MARGIN_BAND_MASK);
  676. if (!String.IsNullOrEmpty(name))
  677. {
  678. PageFooterBand footer = ComponentsFactory.CreatePageFooterBand(page);
  679. string description = GetObjectDescription(name);
  680. LoadBand(footer, description);
  681. LoadObjects(description, footer);
  682. }
  683. }
  684. private void LoadReportHeaderBand() // Report Title
  685. {
  686. string name = FindReportOutsideBandName(REPORT_HEADER_BAND_MASK);
  687. if (!String.IsNullOrEmpty(name))
  688. {
  689. ReportTitleBand title = ComponentsFactory.CreateReportTitleBand(page);
  690. string description = GetObjectDescription(name);
  691. LoadBand(title, description);
  692. LoadObjects(description, title);
  693. }
  694. }
  695. private void LoadReportFooterBand() // Report Summary
  696. {
  697. string name = FindObjectName(REPORT_FOOTER_BAND_MASK);
  698. if (!String.IsNullOrEmpty(name))
  699. {
  700. ReportSummaryBand summary = ComponentsFactory.CreateReportSummaryBand(page);
  701. string description = GetObjectDescription(name);
  702. LoadBand(summary, description);
  703. LoadObjects(description, summary);
  704. }
  705. }
  706. #region DetailReportBand
  707. private void LoadDetailReportBand() // One More Data Band
  708. {
  709. //string name = FindObjectName(DETAIL_REPORT_BAND_MASK);
  710. List<string> detailReports = NamesOfDetailReportBand();
  711. for (int i = 0; i < detailReports.Count; i++)
  712. {
  713. string name = detailReports.Where(x => GetLevelPropValue(GetObjectDescription(x)) == i).FirstOrDefault();
  714. if (!String.IsNullOrEmpty(name))
  715. {
  716. DataBand data = ComponentsFactory.CreateDataBand(page);
  717. string description = GetObjectDescription(name);
  718. List<string> bandsInDetailReport = GetBandsNames(description);
  719. LoadDetailBandInDetailReport(bandsInDetailReport, data);
  720. LoadReportHeaderFooter(bandsInDetailReport, data);
  721. LoadDetailReportGroupBands(bandsInDetailReport, data);
  722. }
  723. }
  724. }
  725. private List<string> NamesOfDetailReportBand()
  726. {
  727. List<string> names = new List<string>();
  728. int start = 0;
  729. while (start != -1)
  730. {
  731. start = devText.IndexOf(DETAIL_REPORT_BAND_MASK, start);
  732. if (start == -1)
  733. return names;
  734. start += DETAIL_REPORT_BAND_MASK.Length + 1;
  735. int end = devText.IndexOf(";", start);
  736. string stringName = devText.Substring(start, end - start).Replace("}", ",");
  737. if (!stringName.EndsWith(")"))
  738. names.Add(devText.Substring(start, end - start).Replace("}", ","));
  739. }
  740. return names;
  741. }
  742. private void LoadDetailBandInDetailReport(List<string> bands, BandBase data)
  743. {
  744. string detailName = bands.Where(x => IsTypeOfBand(x, DETAIL_BAND_MASK)).FirstOrDefault();
  745. if (String.IsNullOrEmpty(detailName))
  746. return;
  747. string detailDescription = GetObjectDescription(detailName);
  748. LoadBand(data, detailDescription);
  749. LoadObjects(detailDescription, data);
  750. bands.Remove(detailName);
  751. }
  752. private void LoadReportHeaderFooter(List<string> bands, DataBand data)
  753. {
  754. GroupHeaderBand header = LoadReportHeaderInDetailReport(bands, data);
  755. LoadReportFooterInDetailReport(bands, header);
  756. }
  757. private GroupHeaderBand LoadReportHeaderInDetailReport(List<string> bands, DataBand data)
  758. {
  759. string detailName = bands.Where(x => IsTypeOfBand(x, REPORT_HEADER_BAND_MASK)).FirstOrDefault();
  760. if (detailName == null)
  761. return null;
  762. // Load one more report header as GroupHeader, 'cause FR don't support more than one ReportTitle band
  763. GroupHeaderBand groupHeader = new GroupHeaderBand();
  764. groupHeader.Data = data;
  765. page.Bands.Add(groupHeader);
  766. string detailDescription = GetObjectDescription(detailName);
  767. LoadBand(groupHeader, detailDescription);
  768. LoadObjects(detailDescription, groupHeader);
  769. bands.Remove(detailName);
  770. return groupHeader;
  771. }
  772. private void LoadReportFooterInDetailReport(List<string> bands, GroupHeaderBand header)
  773. {
  774. if (header == null)
  775. return;
  776. string detailName = bands.Where(x => IsTypeOfBand(x, REPORT_FOOTER_BAND_MASK)).FirstOrDefault();
  777. if (String.IsNullOrEmpty(detailName))
  778. return;
  779. // Load one more report header as GroupHeader, 'cause FR don't support more than one ReportTitle band
  780. GroupFooterBand groupFooter = new GroupFooterBand();
  781. header.GroupFooter = groupFooter;
  782. string detailDescription = GetObjectDescription(detailName);
  783. LoadBand(groupFooter, detailDescription);
  784. LoadObjects(detailDescription, groupFooter);
  785. bands.Remove(detailName);
  786. }
  787. private void LoadDetailReportGroupBands(List<string> subBands, DataBand data)
  788. {
  789. int curLevel = 0;
  790. for (int i = 0; i < subBands.Count; i++)
  791. {
  792. // Search header
  793. string headerName = "";
  794. if (i == 0)
  795. // First header level may or may not contain a property "level", but the second level must contain a property with a value of 1
  796. headerName = subBands.Where(x => (GetLevelPropValue(GetObjectDescription(x)) == curLevel || GetLevelPropValue(GetObjectDescription(x)) == -1) && GetBandType(x).Equals(GROUP_HEADER_BAND_MASK)).FirstOrDefault();
  797. else
  798. headerName = subBands.Where(x => GetLevelPropValue(GetObjectDescription(x)) == curLevel && GetBandType(x).Equals(GROUP_HEADER_BAND_MASK)).FirstOrDefault();
  799. // Try to create header
  800. GroupHeaderBand groupHeader = LoadDetailReportGroupHeaderBand(data, headerName);
  801. if (groupHeader == null)
  802. {
  803. curLevel++;
  804. continue;
  805. }
  806. int headerLevel = GetLevelPropValue(GetObjectDescription(headerName));
  807. // The same situation with levels
  808. if (headerLevel == -1 && i != 0)
  809. headerLevel = -2;
  810. string footerName = subBands.Where(x => GetLevelPropValue(GetObjectDescription(x)) == headerLevel && GetBandType(x).Equals(GROUP_FOOTER_BAND_MASK)).FirstOrDefault();
  811. LoadDetailReportGroupFooterBand(groupHeader, footerName);
  812. curLevel++;
  813. }
  814. }
  815. private GroupHeaderBand LoadDetailReportGroupHeaderBand(DataBand data, string bandName)
  816. {
  817. if (bandName == null)
  818. return null;
  819. GroupHeaderBand groupHeader = new GroupHeaderBand();
  820. if (data.Parent is GroupHeaderBand)
  821. {
  822. GroupHeaderBand parent = data.Parent as GroupHeaderBand;
  823. groupHeader.Data = data;
  824. parent.NestedGroup = groupHeader;
  825. }
  826. else
  827. {
  828. groupHeader.Data = data;
  829. page.Bands.Add(groupHeader);
  830. }
  831. string detailDescription = GetObjectDescription(bandName);
  832. LoadBand(groupHeader, detailDescription);
  833. LoadObjects(detailDescription, groupHeader);
  834. return groupHeader;
  835. }
  836. private void LoadDetailReportGroupFooterBand(GroupHeaderBand groupHeader, string bandName)
  837. {
  838. if (groupHeader == null || String.IsNullOrEmpty(bandName))
  839. return;
  840. GroupFooterBand groupFooter = new GroupFooterBand();
  841. groupHeader.GroupFooter = groupFooter;
  842. string detailDescription = GetObjectDescription(bandName);
  843. LoadBand(groupFooter, detailDescription);
  844. LoadObjects(detailDescription, groupFooter);
  845. }
  846. #endregion
  847. private void LoadDetailBand() // Data
  848. {
  849. string name = FindObjectName(DETAIL_BAND_MASK);
  850. if (!String.IsNullOrEmpty(name))
  851. {
  852. DataBand data = ComponentsFactory.CreateDataBand(page);
  853. string description = GetObjectDescription(name);
  854. LoadBand(data, description);
  855. LoadObjects(description, data);
  856. LoadGroupHeaderFooterBand(data);
  857. }
  858. }
  859. private void LoadGroupHeaderFooterBand(DataBand data)
  860. {
  861. GroupHeaderBand groupHeader = LoadGroupHeaderBand(data);
  862. LoadGroupFooterBand(groupHeader);
  863. }
  864. private GroupHeaderBand LoadGroupHeaderBand(DataBand data)
  865. {
  866. string name = FindReportOutsideBandName(GROUP_HEADER_BAND_MASK);
  867. if (!String.IsNullOrEmpty(name))
  868. {
  869. GroupHeaderBand groupHeader = new GroupHeaderBand();
  870. groupHeader.Data = data;
  871. page.Bands.Add(groupHeader);
  872. string description = GetObjectDescription(name);
  873. LoadBand(groupHeader, description);
  874. LoadObjects(description, groupHeader);
  875. return groupHeader;
  876. }
  877. return null;
  878. }
  879. private void LoadGroupFooterBand(GroupHeaderBand header)
  880. {
  881. if (header == null)
  882. return;
  883. string name = FindReportOutsideBandName(GROUP_FOOTER_BAND_MASK);
  884. if (!String.IsNullOrEmpty(name))
  885. {
  886. GroupFooterBand groupFooter = new GroupFooterBand();
  887. header.GroupFooter = groupFooter;
  888. string Description = GetObjectDescription(name);
  889. LoadBand(groupFooter, Description);
  890. LoadObjects(Description, groupFooter);
  891. }
  892. }
  893. private void LoadReport()
  894. {
  895. CheckDpiZoom();
  896. LoadPageSize();
  897. LoadStyles();
  898. LoadOutsideBandsNames();
  899. LoadTopMarginBand();
  900. LoadBottomMarginBand();
  901. LoadReportHeaderBand();
  902. LoadReportFooterBand();
  903. LoadDetailBand();
  904. LoadDetailReportBand();
  905. UnitsConverter.Ratio = 1;
  906. }
  907. #endregion // Private Methods
  908. #region Public Methods
  909. /// <inheritdoc />
  910. public override void LoadReport(Report report, string filename)
  911. {
  912. using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
  913. {
  914. LoadReport(report, fs);
  915. }
  916. }
  917. /// <inheritdoc />
  918. public override void LoadReport(Report report, Stream content)
  919. {
  920. Report = report;
  921. Report.Clear();
  922. using (var sr = new StreamReader(content))
  923. {
  924. devText = sr.ReadToEnd();
  925. }
  926. try
  927. {
  928. devDoc = new System.Xml.XmlDocument();
  929. devDoc.LoadXml(devText);
  930. }
  931. catch { }
  932. page = ComponentsFactory.CreateReportPage(Report);
  933. if (devDoc.LastChild != null)
  934. {
  935. LoadReportXml();
  936. }
  937. else
  938. {
  939. LoadReportCode();
  940. }
  941. }
  942. #endregion // Public Methods
  943. }
  944. }