StimulSoftImport.cs 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582
  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using FastReport.Table;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Reflection;
  10. using FastReport.Barcode;
  11. using FastReport.Utils;
  12. #if MSCHART
  13. using FastReport.MSChart;
  14. using FastReport.DataVisualization.Charting;
  15. #endif
  16. using FastReport.Matrix;
  17. using FastReport.Dialog;
  18. using FastReport.Data;
  19. using FastReport.Data.JsonConnection;
  20. namespace FastReport.Import.StimulSoft
  21. {
  22. /// <summary>
  23. /// Represents the StimulSoft import plugin.
  24. /// </summary>
  25. public partial class StimulSoftImport : ImportBase
  26. {
  27. #region Fields
  28. private ReportPage page;
  29. private XmlNode reportNode;
  30. private PageUnits unitType;
  31. private float leftOffset;
  32. #endregion // Fields
  33. #region Constructors
  34. /// <summary>
  35. /// Initializes a new instance of the <see cref="StimulSoftImport"/> class.
  36. /// </summary>
  37. public StimulSoftImport() : base() { }
  38. #endregion // Constructors
  39. #region Private Methods
  40. private string RemovePrefix(string value)
  41. {
  42. if (!value.Contains("."))
  43. return value;
  44. string[] temp = value.Split('.');
  45. return temp[temp.Length - 1].Replace("Sti", "");
  46. }
  47. private string SwapBarackets(string value)
  48. {
  49. return value.Replace("{", "[").Replace("}", "]");
  50. }
  51. private void LoadImage(ReportComponentBase parent, XmlNode xmlObject, bool useAbsTop)
  52. {
  53. if (xmlObject["File"] != null && new FileInfo(xmlObject["File"].InnerText).Extension == ".svg"
  54. || xmlObject["ImageURL"] != null && xmlObject["ImageURL"].InnerText.EndsWith(".svg"))
  55. {
  56. LoadSVGImage(parent, xmlObject, useAbsTop);
  57. }
  58. else
  59. {
  60. var PictureObject = ComponentsFactory.CreatePictureObject(xmlObject["Name"].InnerText, parent);
  61. LoadReportComponentBase(PictureObject, xmlObject);
  62. if (parent is TableCell)
  63. {
  64. RectangleF rect = ParseRectangleF(xmlObject["ClientRectangle"].InnerText);
  65. rect.Offset(-rect.Left, -rect.Top);
  66. rect.Offset(-rect.Left + 1, -rect.Top + 1);
  67. rect.Width -= 2;
  68. rect.Height -= 2;
  69. PictureObject.Bounds = rect;
  70. }
  71. else if (useAbsTop)
  72. SetAbsTop(PictureObject, parent);
  73. if (xmlObject["Margins"] != null)
  74. PictureObject.Padding = ParseMargins(xmlObject["Margins"].InnerText);
  75. if (xmlObject["File"] != null)
  76. PictureObject.ImageLocation = xmlObject["File"].InnerText;
  77. else if (xmlObject["ImageURL"] != null)
  78. PictureObject.ImageLocation = xmlObject["ImageURL"].InnerText;
  79. else if (xmlObject["DataColumn"] != null)
  80. PictureObject.DataColumn = xmlObject["DataColumn"].InnerText;
  81. else if (xmlObject["ImageBytes"] != null)
  82. {
  83. MemoryStream memoryStream = new MemoryStream();
  84. StreamWriter streamWriter = new StreamWriter(memoryStream);
  85. byte[] arrayimg = Convert.FromBase64String(xmlObject["ImageBytes"].InnerText);
  86. PictureObject.Image = ImageHelper.Load(arrayimg);
  87. streamWriter.Dispose();
  88. memoryStream.Dispose();
  89. }
  90. if (xmlObject["AspectRatio"] != null)
  91. PictureObject.SizeMode = UnitsConverter.ConvertBool(xmlObject["AspectRatio"].InnerText) ? PictureBoxSizeMode.Zoom : PictureBoxSizeMode.Normal;
  92. }
  93. }
  94. partial void LoadSVGImage(ReportComponentBase parent, XmlNode xmlObject, bool useAbsTop);
  95. private void LoadCheckBox(ReportComponentBase band, XmlNode xmlObject, bool useAbsTop)
  96. {
  97. CheckBoxObject checkBox = ComponentsFactory.CreateCheckBoxObject(xmlObject["Name"].InnerText, band);
  98. LoadReportComponentBase(checkBox, xmlObject);
  99. if (band is TableCell)
  100. {
  101. checkBox.Bounds = new RectangleF(1, 1, Math.Min(checkBox.Width, checkBox.Height) - 1, Math.Min(checkBox.Width, checkBox.Height) - 1);
  102. }
  103. else if (useAbsTop)
  104. SetAbsTop(checkBox, band);
  105. if (xmlObject["Checked"] != null)
  106. {
  107. checkBox.Checked = UnitsConverter.ConvertBool(xmlObject["Checked"].InnerText.Replace("{", "").Replace("}", ""));
  108. checkBox.DataColumn = xmlObject["Checked"].InnerText.Replace("{true}", "").Replace("{false}", "");
  109. }
  110. if (xmlObject["Editable"] != null)
  111. checkBox.Editable = UnitsConverter.ConvertBool(xmlObject["Editable"].InnerText);
  112. if (xmlObject["TextBrush"] != null)
  113. checkBox.CheckColor = UnitsConverter.ConvertBrushToColor(UnitsConverter.ConvertBrush(xmlObject["TextBrush"].InnerText));
  114. if (xmlObject["CheckStyleForTrue"] != null)
  115. checkBox.CheckedSymbol = UnitsConverter.ConvertCheckSymbol(xmlObject["CheckStyleForTrue"].InnerText);
  116. }
  117. private void LoadShape(BandBase band, XmlNode xmlObject, bool useAbsTop)
  118. {
  119. switch (RemovePrefix(xmlObject["ShapeType"].Attributes["type"].Value))
  120. {
  121. case "DiagonalUpLineShapeType":
  122. {
  123. LineObject lineObject = ComponentsFactory.CreateLineObject(xmlObject["Name"].InnerText, band);
  124. LoadReportComponentBase(lineObject, xmlObject);
  125. lineObject.Diagonal = true;
  126. RectangleF rectangle = ParseRectangleF(xmlObject["ClientRectangle"].InnerText);
  127. lineObject.Bounds = new RectangleF(rectangle.X, rectangle.Y + rectangle.Height, rectangle.Width, -rectangle.Height);
  128. if (useAbsTop)
  129. SetAbsTop(lineObject, band);
  130. if (xmlObject["BorderColor"] != null)
  131. lineObject.Border.Color = UnitsConverter.ConvertColor(xmlObject["BorderColor"].InnerText);
  132. if (xmlObject["Size"] != null)
  133. lineObject.Border.Width = UnitsConverter.ConvertFloat(xmlObject["Size"].InnerText);
  134. if (xmlObject["Style"] != null)
  135. lineObject.Border.Style = UnitsConverter.ConvertLineStyle(xmlObject["Style"].InnerText);
  136. break;
  137. }
  138. case "DiagonalDownLineShapeType":
  139. {
  140. LineObject lineObject = ComponentsFactory.CreateLineObject(xmlObject["Name"].InnerText, band);
  141. LoadReportComponentBase(lineObject, xmlObject);
  142. lineObject.Diagonal = true;
  143. if (useAbsTop)
  144. SetAbsTop(lineObject, band);
  145. if (xmlObject["BorderColor"] != null)
  146. lineObject.Border.Color = UnitsConverter.ConvertColor(xmlObject["BorderColor"].InnerText);
  147. if (xmlObject["Size"] != null)
  148. lineObject.Border.Width = UnitsConverter.ConvertFloat(xmlObject["Size"].InnerText);
  149. if (xmlObject["Style"] != null)
  150. lineObject.Border.Style = UnitsConverter.ConvertLineStyle(xmlObject["Style"].InnerText);
  151. break;
  152. }
  153. case "HorizontalLineShapeType":
  154. case "VerticalLineShapeType":
  155. {
  156. LineObject lineObject = ComponentsFactory.CreateLineObject(xmlObject["Name"].InnerText, band);
  157. LoadReportComponentBase(lineObject, xmlObject);
  158. if (useAbsTop)
  159. SetAbsTop(lineObject, band);
  160. if (xmlObject["BorderColor"] != null)
  161. lineObject.Border.Color = UnitsConverter.ConvertColor(xmlObject["BorderColor"].InnerText);
  162. if (xmlObject["Size"] != null)
  163. lineObject.Border.Width = UnitsConverter.ConvertFloat(xmlObject["Size"].InnerText);
  164. if (xmlObject["Style"] != null)
  165. lineObject.Border.Style = UnitsConverter.ConvertLineStyle(xmlObject["Style"].InnerText);
  166. break;
  167. }
  168. }
  169. }
  170. private void LoadZipCode(BandBase band, XmlNode xmlObject, bool useAbsTop)
  171. {
  172. ZipCodeObject zipCode = ComponentsFactory.CreateZipCodeObject(xmlObject["Name"].InnerText, band);
  173. LoadReportComponentBase(zipCode, xmlObject);
  174. if (useAbsTop)
  175. SetAbsTop(zipCode, band);
  176. if (xmlObject["Code"] != null)
  177. {
  178. zipCode.Text = xmlObject["Code"].InnerText;
  179. zipCode.SegmentCount = xmlObject["Code"].InnerText.Length;
  180. }
  181. if (xmlObject["SpaceRatio"] != null)
  182. zipCode.Spacing = UnitsConverter.ConvertFloat(xmlObject["SpaceRatio"].InnerText);
  183. }
  184. private void LoadMatrix(BandBase band, XmlNode xmlObject, bool useAbsTop)
  185. {
  186. MatrixObject matrix = ComponentsFactory.CreateMatrixObject(xmlObject["Name"].InnerText, band);
  187. matrix.AutoSize = false;
  188. LoadReportComponentBase(matrix, xmlObject);
  189. if (useAbsTop)
  190. SetAbsTop(matrix, band);
  191. Dictionary<string, TableCell> totalTemplates = new Dictionary<string, TableCell>();
  192. foreach (XmlNode node in xmlObject["Components"])
  193. {
  194. switch (RemovePrefix(node.Attributes["type"].Value))
  195. {
  196. case "CrossColumnTotal":
  197. case "CrossRowTotal":
  198. totalTemplates.Add(node["Guid"].InnerText, LoadTableCell(node));
  199. break;
  200. }
  201. }
  202. foreach (XmlNode node in xmlObject["Components"])
  203. {
  204. switch (RemovePrefix(node.Attributes["type"].Value))
  205. {
  206. case "CrossRow":
  207. MatrixHeaderDescriptor row = new MatrixHeaderDescriptor(node["Value"].InnerText.Replace("}", "").Replace("{", ""));
  208. matrix.Data.Rows.Add(row);
  209. matrix.BuildTemplate();
  210. RectangleF rectCellOfRow = ParseRectangleF(node["ClientRectangle"].InnerText);
  211. row.TemplateColumn.Width = rectCellOfRow.Width;
  212. row.TemplateRow.Height = rectCellOfRow.Height;
  213. row.TemplateCell.AssignAll(LoadTableCell(node));
  214. row.TemplateCell.Brackets = "[,]";
  215. if (node["ShowTotal"] != null)
  216. row.Totals = UnitsConverter.ConvertBool(node["ShowTotal"].InnerText);
  217. if (node["TotalGuid"] != null)
  218. row.TemplateTotalCell = totalTemplates[node["TotalGuid"].InnerText];
  219. break;
  220. case "CrossColumn":
  221. MatrixHeaderDescriptor column = new MatrixHeaderDescriptor(node["Value"].InnerText.Replace("}", "").Replace("{", ""));
  222. matrix.Data.Columns.Add(column);
  223. matrix.BuildTemplate();
  224. RectangleF rectCellOfColumn = ParseRectangleF(node["ClientRectangle"].InnerText);
  225. column.TemplateColumn.Width = rectCellOfColumn.Width;
  226. column.TemplateRow.Height = rectCellOfColumn.Height;
  227. column.TemplateCell.AssignAll(LoadTableCell(node));
  228. column.TemplateCell.Brackets = "[,]";
  229. if (node["TotalGuid"] != null)
  230. column.TemplateTotalCell = totalTemplates[node["TotalGuid"].InnerText];
  231. if (node["ShowTotal"] != null)
  232. column.Totals = UnitsConverter.ConvertBool(node["ShowTotal"].InnerText);
  233. break;
  234. case "CrossSummary":
  235. MatrixCellDescriptor cell = new MatrixCellDescriptor(
  236. node["Value"].InnerText.Replace("}", "").Replace("{", ""),
  237. UnitsConverter.GetMatrixAggregateFunction(node)
  238. );
  239. matrix.Data.Cells.Add(cell);
  240. matrix.BuildTemplate();
  241. cell.TemplateCell.AssignAll(LoadTableCell(node));
  242. cell.TemplateCell.Brackets = "[,]";
  243. if (node["Summary"] != null && node["Summary"].InnerText == "Image")
  244. {
  245. cell.Expression = "";
  246. cell.TemplateCell.Text = "";
  247. LoadImage(cell.TemplateCell, node, false);
  248. }
  249. break;
  250. }
  251. }
  252. matrix.BuildTemplate();
  253. }
  254. private void LoadTable(BandBase band, XmlNode xmlObject, bool useAbsTop)
  255. {
  256. TableObject table = ComponentsFactory.CreateTableObject(xmlObject["Name"].InnerText, band);
  257. LoadReportComponentBase(table, xmlObject);
  258. int fixRows = 0;
  259. DataBand nonHeaderPartOfTab = null;
  260. RectangleF rectangle = table.Bounds;
  261. if (useAbsTop)
  262. {
  263. rectangle.Offset(0, -band.Bounds.Top);
  264. table.Bounds = rectangle;
  265. }
  266. if (xmlObject["HeaderRowsCount"] != null)
  267. {
  268. fixRows = UnitsConverter.ConvertInt(xmlObject["HeaderRowsCount"].InnerText);
  269. table.FixedRows = fixRows;
  270. }
  271. int columnCount = 5;//default value
  272. if (xmlObject["ColumnCount"] != null)
  273. columnCount = UnitsConverter.ConvertInt(xmlObject["ColumnCount"].InnerText);
  274. table.ColumnCount = columnCount;
  275. int index = 0;
  276. TableRow row = new TableRow();
  277. foreach (XmlNode cell in xmlObject["Components"])
  278. {
  279. if (index % columnCount == 0)
  280. {
  281. if (table.Rows.Count == fixRows)
  282. {
  283. SubreportObject subreport = ComponentsFactory.CreateSubreportObject("SubReport_" + xmlObject["Name"].InnerText, band);
  284. ReportPage page = ComponentsFactory.CreateReportPage(Report);
  285. page.SetName("SubReport_" + xmlObject["Name"].InnerText);
  286. subreport.Bounds = rectangle;
  287. page.PaperWidth = subreport.Bounds.Width / Units.Millimeters;
  288. page.PaperHeight = subreport.Bounds.Height / Units.Millimeters;
  289. page.LeftMargin = 0;
  290. page.TopMargin = 0;
  291. page.RightMargin = 0;
  292. page.BottomMargin = 0;
  293. subreport.ReportPage = page;
  294. nonHeaderPartOfTab = ComponentsFactory.CreateDataBand(page);
  295. nonHeaderPartOfTab.CanGrow = true;
  296. table = ComponentsFactory.CreateTableObject(xmlObject["Name"].InnerText, nonHeaderPartOfTab);
  297. table.ColumnCount = columnCount;
  298. index = 0;
  299. }
  300. row = new TableRow();
  301. row.SetReport(Report);
  302. row.CreateUniqueName();
  303. row.Height = ParseRectangleF(cell["ClientRectangle"].InnerText).Height;
  304. rectangle.Height -= row.Height;
  305. rectangle.Y += row.Height;
  306. table.Rows.Add(row);
  307. }
  308. if (index < columnCount)
  309. {
  310. table.Columns[index].Width = ParseRectangleF(cell["ClientRectangle"].InnerText).Width;
  311. }
  312. TableCell tableCell = LoadTableCell(cell);
  313. tableCell.SetReport(Report);
  314. row[index % columnCount] = tableCell;
  315. tableCell.CreateUniqueName();
  316. List<int> joinCellId = new List<int>();
  317. foreach (XmlNode val in cell["JoinCells"])
  318. joinCellId.Add(UnitsConverter.ConvertInt(val.InnerText));
  319. TableCell cellConteiner = tableCell;
  320. int rowSpan = 1, colSpan = 1;
  321. if (cell["JoinHeight"] != null)
  322. rowSpan = UnitsConverter.ConvertInt(cell["JoinHeight"].InnerText);
  323. else
  324. {
  325. rowSpan = GetRowSpan(joinCellId, columnCount);
  326. if (rowSpan > table.Rows.Count)
  327. rowSpan = 1;
  328. }
  329. if (cell["JoinWidth"] != null)
  330. colSpan = UnitsConverter.ConvertInt(cell["JoinWidth"].InnerText);
  331. else
  332. {
  333. colSpan = GetColSpan(joinCellId, columnCount);
  334. if (colSpan > columnCount)
  335. colSpan = 1;
  336. }
  337. if (rowSpan > 1 && colSpan > 1)
  338. {
  339. cellConteiner = table.Rows[table.Rows.Count - rowSpan][index % columnCount - colSpan + 1];
  340. cellConteiner.AssignAll(tableCell);
  341. table.Rows[table.Rows.Count - rowSpan][index % columnCount - colSpan + 1].RowSpan = rowSpan;
  342. table.Rows[table.Rows.Count - rowSpan][index % columnCount - colSpan + 1].ColSpan = colSpan;
  343. }
  344. else if (colSpan > 1)
  345. {
  346. cellConteiner = row[index % columnCount - colSpan + 1];
  347. cellConteiner.AssignAll(tableCell);
  348. row[index % columnCount - colSpan + 1].ColSpan = colSpan;
  349. }
  350. else if (rowSpan > 1)
  351. {
  352. cellConteiner = table.Rows[table.Rows.Count - rowSpan][index % columnCount];
  353. cellConteiner.AssignAll(tableCell);
  354. table.Rows[table.Rows.Count - rowSpan][index % columnCount].RowSpan = rowSpan;
  355. }
  356. switch (RemovePrefix(cell.Attributes["type"].Value))
  357. {
  358. case "TableCellRichText":
  359. LoadRichText(cellConteiner, cell, false);
  360. tableCell.Text = "";
  361. break;
  362. case "TableCellImage":
  363. LoadImage(cellConteiner, cell, false);
  364. break;
  365. case "TableCellCheckBox":
  366. LoadCheckBox(cellConteiner, cell, false);
  367. break;
  368. }
  369. index++;
  370. }
  371. if (nonHeaderPartOfTab != null)
  372. nonHeaderPartOfTab.CalcHeight();
  373. }
  374. private void LoadBarCode(BandBase band, XmlNode xmlObject, bool useAbsTop)
  375. {
  376. BarcodeObject barcodeObject = ComponentsFactory.CreateBarcodeObject(xmlObject["Name"].InnerText, band);
  377. LoadReportComponentBase(barcodeObject, xmlObject);
  378. barcodeObject.Brackets = "{,}";
  379. if (xmlObject["Code"] != null)
  380. barcodeObject.Text = xmlObject["Code"].InnerText;
  381. UnitsConverter.ConvertBarcodeSymbology(xmlObject["BarCodeType"].Attributes["type"].Value, barcodeObject);
  382. if (useAbsTop)
  383. SetAbsTop(barcodeObject, band);
  384. if (xmlObject["ShowLabelText"] != null)
  385. barcodeObject.ShowText = UnitsConverter.ConvertBool(xmlObject["ShowLabelText"].InnerText);
  386. }
  387. partial void LoadRichText(ReportComponentBase band, XmlNode xmlObject, bool useAbsTop);
  388. partial void LoadMap(ReportComponentBase band, XmlNode xmlObject, bool useAbsTop);
  389. private void LoadGauge(BandBase band, XmlNode xmlObject, bool useAbsTop)
  390. {
  391. Gauge.GaugeObject gauge;
  392. if (xmlObject["Type"] != null)
  393. {
  394. switch (RemovePrefix(xmlObject["Type"].InnerText))
  395. {
  396. case "Linear":
  397. case "HorizontalLinear":
  398. gauge = ComponentsFactory.CreateSimpleProgressGauge(xmlObject["Type"].InnerText, band);
  399. break;
  400. case "Bullet":
  401. gauge = ComponentsFactory.CreateSimpleGauge(xmlObject["Name"].InnerText, band);
  402. break;
  403. default:
  404. gauge = ComponentsFactory.CreateRadialGauge(xmlObject["Name"].InnerText, band);
  405. break;
  406. }
  407. }
  408. else
  409. {
  410. gauge = ComponentsFactory.CreateRadialGauge(xmlObject["Name"].InnerText, band);
  411. }
  412. LoadReportComponentBase(gauge, xmlObject);
  413. if (useAbsTop)
  414. SetAbsTop(gauge, band);
  415. if (xmlObject["Maximum"] != null)
  416. gauge.Maximum = UnitsConverter.ConvertFloat(xmlObject["Maximum"].InnerText);
  417. if (xmlObject["Minimum"] != null)
  418. gauge.Minimum = UnitsConverter.ConvertFloat(xmlObject["Minimum"].InnerText);
  419. gauge.Value = 0;
  420. }
  421. partial void LoadSparkLine(BandBase band, XmlNode xmlObject, bool useAbsTop);
  422. private void LoadTextObjBase(TextObject textObject, XmlNode xmlObject)
  423. {
  424. LoadReportComponentBase(textObject, xmlObject);
  425. textObject.Brackets = "{,}";
  426. if (xmlObject["Text"] != null)
  427. textObject.Text = xmlObject["Text"].InnerText;
  428. if (xmlObject["Margins"] != null)
  429. textObject.Padding = ParseMargins(xmlObject["Margins"].InnerText);
  430. if (xmlObject["Font"] != null)
  431. textObject.Font = ParseFont(xmlObject["Font"].InnerText);
  432. if (xmlObject["TextBrush"] != null)
  433. textObject.TextColor = UnitsConverter.ConvertColor(xmlObject["TextBrush"].InnerText);
  434. if (xmlObject["HorAlignment"] != null)
  435. textObject.HorzAlign = UnitsConverter.ConvertTextAlignmentToHorzAlign(xmlObject["HorAlignment"].InnerText);
  436. if (xmlObject["VertAlignment"] != null)
  437. textObject.VertAlign = UnitsConverter.ConvertTextAlignmentToVertAlign(xmlObject["VertAlignment"].InnerText);
  438. if (xmlObject["TextFormat"] != null)
  439. textObject.Format = UnitsConverter.ConvertFormat(xmlObject["TextFormat"]);
  440. if (xmlObject["TextOptions"] != null)
  441. ParseTextOptions(textObject, xmlObject["TextOptions"].InnerText);
  442. if (xmlObject["AllowHtmlTags"] != null)
  443. textObject.TextRenderType = UnitsConverter.ConvertBool(xmlObject["AllowHtmlTags"].InnerText) ? TextRenderType.HtmlTags : TextRenderType.Default;
  444. if (xmlObject["Editable"] != null)
  445. textObject.Editable = UnitsConverter.ConvertBool(xmlObject["Editable"].InnerText);
  446. foreach (XmlNode xmlHighlight in xmlObject["Conditions"])
  447. {
  448. try
  449. {
  450. string[] parametrs = xmlHighlight.InnerText.Split(',');
  451. HighlightCondition highlight = new HighlightCondition();
  452. highlight.Expression = UnitsConverter.ConvertRTF(parametrs[0]).Replace("value", "Value").Replace("{", "").Replace("}", "");
  453. highlight.TextFill = new SolidFill(UnitsConverter.ConvertColor(UnitsConverter.ConvertRTF(parametrs[1])));
  454. highlight.Fill = new SolidFill(UnitsConverter.ConvertColor(UnitsConverter.ConvertRTF(parametrs[2])));
  455. highlight.Font = ParseFont(UnitsConverter.ConvertRTF(parametrs[3]));
  456. highlight.Border.Lines = UnitsConverter.ConvertBorderSides(UnitsConverter.ConvertRTF(parametrs[8]));
  457. highlight.ApplyFont = true;
  458. highlight.ApplyFill = true;
  459. highlight.ApplyTextFill = true;
  460. highlight.ApplyBorder = true;
  461. textObject.Highlight.Add(highlight);
  462. }
  463. catch { }
  464. }
  465. }
  466. private void LoadTextObject(BandBase band, XmlNode xmlObject, bool useAbsTop)
  467. {
  468. TextObject textObject = ComponentsFactory.CreateTextObject(xmlObject["Name"].InnerText, band);
  469. LoadTextObjBase(textObject, xmlObject);
  470. if (useAbsTop)
  471. SetAbsTop(textObject, band);
  472. }
  473. private void LoadCellularTextObject(BandBase band, XmlNode xmlObject, bool useAbsTop)
  474. {
  475. CellularTextObject CellularTextObject = ComponentsFactory.CreateCellularTextObject(xmlObject["Name"].InnerText, band);
  476. LoadTextObjBase(CellularTextObject, xmlObject);
  477. if (useAbsTop)
  478. SetAbsTop(CellularTextObject, band);
  479. if (xmlObject["CellHeight"] != null)
  480. CellularTextObject.CellHeight = UnitsConverter.ConvertFloat(xmlObject["CellHeight"].InnerText);
  481. if (xmlObject["CellWidth"] != null)
  482. CellularTextObject.CellWidth = UnitsConverter.ConvertFloat(xmlObject["CellWidth"].InnerText);
  483. }
  484. private void LoadPrimitiveShape(BandBase band, XmlNode xmlObject, ShapeKind shapeKind, bool useAbsTop)
  485. {
  486. ShapeObject shapeObject = ComponentsFactory.CreateShapeObject(xmlObject["Name"].InnerText, band);
  487. shapeObject.Shape = shapeKind;
  488. LoadReportComponentBase(shapeObject, xmlObject);
  489. if (useAbsTop)
  490. SetAbsTop(shapeObject, band);
  491. if (xmlObject["Color"] != null)
  492. shapeObject.Border.Color = UnitsConverter.ConvertColor(xmlObject["Color"].InnerText);
  493. if (xmlObject["Style"] != null)
  494. shapeObject.Border.Style = UnitsConverter.ConvertLineStyle(xmlObject["Style"].InnerText);
  495. if (xmlObject["Size"] != null)
  496. shapeObject.Border.Width = UnitsConverter.ConvertInt(xmlObject["Size"].InnerText);
  497. }
  498. private void LoadPanel(BandBase band, XmlNode xmlObject, bool useAbsTop)
  499. {
  500. SubreportObject subreportObject = ComponentsFactory.CreateSubreportObject(xmlObject["Name"].InnerText, band);
  501. ReportPage page = ComponentsFactory.CreateReportPage(Report);
  502. LoadReportComponentBase(subreportObject, xmlObject);
  503. if (useAbsTop)
  504. SetAbsTop(subreportObject, band);
  505. page.PaperWidth = subreportObject.Bounds.Width / Units.Millimeters;
  506. page.PaperHeight = subreportObject.Bounds.Height / Units.Millimeters;
  507. page.LeftMargin = 0;
  508. page.TopMargin = 0;
  509. page.RightMargin = 0;
  510. page.BottomMargin = 0;
  511. LoadBands(xmlObject, page);
  512. LoadChildBands(xmlObject, page);
  513. subreportObject.ReportPage = page;
  514. }
  515. private void LoadLineObject(BandBase band, XmlNode xmlObject, bool useAbsTop)
  516. {
  517. LineObject lineObject = ComponentsFactory.CreateLineObject(xmlObject["Name"].InnerText, band);
  518. LoadReportComponentBase(lineObject, xmlObject);
  519. if (useAbsTop)
  520. SetAbsTop(lineObject, band);
  521. if (xmlObject["EndCap"] != null && xmlObject["EndCap"]["Style"] != null)
  522. lineObject.EndCap.Style = UnitsConverter.ConvertCapStyle(xmlObject["EndCap"]["Style"].InnerText);
  523. if (xmlObject["StartCap"] != null && xmlObject["StartCap"]["Style"] != null)
  524. lineObject.StartCap.Style = UnitsConverter.ConvertCapStyle(xmlObject["StartCap"]["Style"].InnerText);
  525. if (xmlObject["Color"] != null)
  526. lineObject.Border.Color = UnitsConverter.ConvertColor(xmlObject["Color"].InnerText);
  527. if (xmlObject["Size"] != null)
  528. lineObject.Border.Width = UnitsConverter.ConvertFloat(xmlObject["Size"].InnerText);
  529. }
  530. partial void LoadChart(BandBase band, XmlNode xmlObject, bool useAbsTop);
  531. private void LoadPage(XmlNode node)
  532. {
  533. page = ComponentsFactory.CreateReportPage(node["Name"].InnerText, Report);
  534. if (node["PageWidth"] != null && node["PageHeight"] != null)
  535. {
  536. page.PaperWidth = UnitsConverter.ConvertFloat(node["PageWidth"].InnerText) * UnitsConverter.GetPixelsInUnit(unitType) / Units.Millimeters;
  537. page.PaperHeight = UnitsConverter.ConvertFloat(node["PageHeight"].InnerText) * UnitsConverter.GetPixelsInUnit(unitType) / Units.Millimeters;
  538. }
  539. else if (node["PaperSize"] != null)
  540. {
  541. UnitsConverter.ConvertPaperSize(node["PaperSize"].InnerText, page);
  542. }
  543. if (node["Margins"] != null)
  544. {
  545. Padding pagePadding = ParsePageMargins(node["Margins"].InnerText);
  546. page.LeftMargin = pagePadding.Left / Units.Millimeters;
  547. page.TopMargin = pagePadding.Top / Units.Millimeters;
  548. page.RightMargin = pagePadding.Right / Units.Millimeters;
  549. page.BottomMargin = pagePadding.Bottom / Units.Millimeters;
  550. }
  551. if (node["Columns"] != null)
  552. page.Columns.Count = UnitsConverter.ConvertInt(node["Columns"].InnerText);
  553. if (node["ColumnWidth"] != null)
  554. page.Columns.Width = UnitsConverter.ConvertFloat(node["ColumnWidth"].InnerText) * UnitsConverter.GetPixelsInUnit(unitType) / Units.Millimeters;
  555. if (node["ColumnGaps"] != null)
  556. page.Columns.Width += UnitsConverter.ConvertFloat(node["ColumnGaps"].InnerText) * UnitsConverter.GetPixelsInUnit(unitType) / Units.Millimeters;
  557. page.Tag = node["Guid"].InnerText;
  558. LoadBands(node, page);
  559. LoadChildBands(node, page);
  560. }
  561. private void LoadReportObjects(XmlNode node, BandBase band)
  562. {
  563. foreach (XmlNode item in SortNodeByTop(node))
  564. {
  565. LoadObject(band, item, false);
  566. }
  567. }
  568. private void LoadBands(XmlNode node, ReportPage page)
  569. {
  570. BandBase band;
  571. foreach (XmlNode item in SortNodeByTop(node))
  572. {
  573. band = null;
  574. switch (RemovePrefix(item.Attributes["type"].Value))
  575. {
  576. case "DataBand":
  577. {
  578. band = ComponentsFactory.CreateDataBand(page);
  579. if (item["DataSourceName"] != null)
  580. (band as DataBand).DataSource = Report.GetDataSource(item["DataSourceName"].InnerText);
  581. if (item["Columns"] != null)
  582. (band as DataBand).Columns.Count = UnitsConverter.ConvertInt(item["Columns"].InnerText);
  583. if (item["ColumnWidth"] != null)
  584. (band as DataBand).Columns.Width = UnitsConverter.ConvertFloat(item["ColumnWidth"].InnerText) * UnitsConverter.GetPixelsInUnit(unitType);
  585. if (item["ColumnGaps"] != null)
  586. (band as DataBand).Columns.Width += UnitsConverter.ConvertFloat(item["ColumnGaps"].InnerText) * UnitsConverter.GetPixelsInUnit(unitType);
  587. break;
  588. }
  589. case "ReportTitleBand":
  590. {
  591. band = ConvertToChildIfDuplicatedBand(typeof(ReportTitleBand));
  592. if (band == null)
  593. band = ComponentsFactory.CreateReportTitleBand(page);
  594. break;
  595. }
  596. case "ReportSummaryBand":
  597. {
  598. band = ConvertToChildIfDuplicatedBand(typeof(ReportSummaryBand));
  599. if (band == null)
  600. band = ComponentsFactory.CreateReportSummaryBand(page);
  601. break;
  602. }
  603. case "OverlayBand":
  604. {
  605. band = ComponentsFactory.CreateOverlayBand(page);
  606. break;
  607. }
  608. case "ColumnHeaderBand":
  609. {
  610. band = ConvertToChildIfDuplicatedBand(typeof(ColumnHeaderBand));
  611. if (band == null)
  612. band = ComponentsFactory.CreateColumnHeaderBand(page);
  613. break;
  614. }
  615. case "ColumnFooterBand":
  616. {
  617. band = ConvertToChildIfDuplicatedBand(typeof(ColumnFooterBand));
  618. if (band == null)
  619. band = ComponentsFactory.CreateColumnFooterBand(page);
  620. break;
  621. }
  622. case "PageHeaderBand":
  623. {
  624. band = ConvertToChildIfDuplicatedBand(typeof(PageHeaderBand));
  625. if (band == null)
  626. band = ComponentsFactory.CreatePageHeaderBand(page);
  627. break;
  628. }
  629. case "PageFooterBand":
  630. {
  631. band = ConvertToChildIfDuplicatedBand(typeof(PageFooterBand));
  632. if (band == null)
  633. band = ComponentsFactory.CreatePageFooterBand(page);
  634. break;
  635. }
  636. case "HierarchicalBand":
  637. {
  638. band = ComponentsFactory.CreateDataBand(page);
  639. if (item["Indent"] != null)
  640. (band as DataBand).Indent = UnitsConverter.ConvertFloat(item["Indent"].InnerText);
  641. if (item["DataSourceName"] != null)
  642. {
  643. (band as DataBand).DataSource = Report.GetDataSource(item["DataSourceName"].InnerText);
  644. if (item["KeyDataColumn"] != null)
  645. (band as DataBand).IdColumn = item["DataSourceName"].InnerText + "." + item["KeyDataColumn"].InnerText;
  646. if (item["MasterKeyDataColumn"] != null)
  647. (band as DataBand).ParentIdColumn = item["DataSourceName"].InnerText + "." + item["MasterKeyDataColumn"].InnerText;
  648. }
  649. break;
  650. }
  651. default:
  652. {
  653. //report object without band
  654. if (item["ClientRectangle"] != null)
  655. {
  656. DataBand dataBand = ComponentsFactory.CreateDataBand(page);
  657. RectangleF rect = ParseRectangleF(item["ClientRectangle"].InnerText);
  658. dataBand.Bounds = rect;
  659. foreach (Base obj in page.AllObjects)
  660. {
  661. if (obj is DataBand && obj != dataBand && (obj as DataBand).Bounds.Top + (obj as DataBand).Bounds.Height >= rect.Top)
  662. {
  663. page.RemoveChild(dataBand);
  664. dataBand = (DataBand)obj;
  665. break;
  666. }
  667. }
  668. LoadObject(dataBand, item, true);
  669. if (dataBand.ChildObjects.Count == 0)
  670. page.RemoveChild(dataBand);
  671. else
  672. {
  673. dataBand.CanGrow = true;
  674. dataBand.CalcHeight();
  675. }
  676. }
  677. break;
  678. }
  679. }
  680. LoadBandBase(band, item);
  681. }
  682. }
  683. private void LoadObject(BandBase band, XmlNode xmlObject, bool useAbsTop)
  684. {
  685. switch (RemovePrefix(xmlObject.Attributes["type"].Value))
  686. {
  687. case "Text":
  688. {
  689. LoadTextObject(band, xmlObject, useAbsTop);
  690. break;
  691. }
  692. case "RichText":
  693. {
  694. LoadRichText(band, xmlObject, useAbsTop);
  695. break;
  696. }
  697. case "TextInCells":
  698. {
  699. LoadCellularTextObject(band, xmlObject, useAbsTop);
  700. break;
  701. }
  702. case "Image":
  703. {
  704. LoadImage(band, xmlObject, useAbsTop);
  705. break;
  706. }
  707. case "Chart":
  708. {
  709. LoadChart(band, xmlObject, useAbsTop);
  710. break;
  711. }
  712. case "Shape":
  713. {
  714. LoadShape(band, xmlObject, useAbsTop);
  715. break;
  716. }
  717. case "CheckBox":
  718. {
  719. LoadCheckBox(band, xmlObject, useAbsTop);
  720. break;
  721. }
  722. case "VerticalLinePrimitive":
  723. case "HorizontalLinePrimitive":
  724. {
  725. LoadLineObject(band, xmlObject, useAbsTop);
  726. break;
  727. }
  728. case "RectanglePrimitive":
  729. {
  730. LoadPrimitiveShape(band, xmlObject, ShapeKind.Rectangle, useAbsTop);
  731. break;
  732. }
  733. case "RoundedRectanglePrimitive":
  734. {
  735. LoadPrimitiveShape(band, xmlObject, ShapeKind.RoundRectangle, useAbsTop);
  736. break;
  737. }
  738. case "BarCode":
  739. {
  740. LoadBarCode(band, xmlObject, useAbsTop);
  741. break;
  742. }
  743. case "Panel":
  744. {
  745. LoadPanel(band, xmlObject, useAbsTop);
  746. break;
  747. }
  748. case "SubReport":
  749. {
  750. SubreportObject subreportObject = ComponentsFactory.CreateSubreportObject(xmlObject["Name"].InnerText, band);
  751. LoadReportComponentBase(subreportObject, xmlObject);
  752. if (useAbsTop)
  753. SetAbsTop(subreportObject, band);
  754. subreportObject.Tag = xmlObject["SubReportPageGuid"].InnerText;
  755. break;
  756. }
  757. case "Sparkline":
  758. {
  759. LoadSparkLine(band, xmlObject, useAbsTop);
  760. break;
  761. }
  762. case "Table":
  763. {
  764. LoadTable(band, xmlObject, useAbsTop);
  765. break;
  766. }
  767. case "Map":
  768. {
  769. LoadMap(band, xmlObject, useAbsTop);
  770. break;
  771. }
  772. case "Gauge":
  773. {
  774. LoadGauge(band, xmlObject, useAbsTop);
  775. break;
  776. }
  777. case "ZipCode":
  778. {
  779. LoadZipCode(band, xmlObject, useAbsTop);
  780. break;
  781. }
  782. case "CrossTab":
  783. {
  784. LoadMatrix(band, xmlObject, useAbsTop);
  785. break;
  786. }
  787. case "CrossGroupFooterBand":
  788. case "CrossHeaderBand":
  789. case "CrossFooterBand":
  790. case "CrossDataBand":
  791. case "CrossGroupHeaderBand":
  792. {
  793. RectangleF rectangle = ParseRectangleF(xmlObject["ClientRectangle"].InnerText);
  794. leftOffset = rectangle.X;
  795. LoadReportObjects(xmlObject, band);
  796. leftOffset = 0;
  797. break;
  798. }
  799. default:
  800. {
  801. break;
  802. }
  803. }
  804. }
  805. private void SetAbsTop(ReportComponentBase obj, ReportComponentBase parent)
  806. {
  807. RectangleF rect = obj.Bounds;
  808. rect.Offset(0, -parent.Bounds.Top);
  809. obj.Bounds = rect;
  810. }
  811. private TableCell LoadTableCell(XmlNode node)
  812. {
  813. TableCell result = new TableCell();
  814. result.SetReport(Report);
  815. LoadTextObjBase(result, node);
  816. if (node["HorAlignment"] == null)
  817. result.HorzAlign = HorzAlign.Center;
  818. if (node["VertAlignment"] == null)
  819. result.VertAlign = VertAlign.Center;
  820. return result;
  821. }
  822. private int GetColSpan(List<int> arr, int columnCount)
  823. {
  824. int result = 0;
  825. foreach (int i in arr)
  826. if (i % columnCount == arr[0])
  827. result++;
  828. return result;
  829. }
  830. private int GetRowSpan(List<int> arr, int columnCount)
  831. {
  832. int result = 0;
  833. foreach (int i in arr)
  834. if (i < columnCount)
  835. result++;
  836. return result;
  837. }
  838. private void LoadChildBands(XmlNode node, ReportPage page)
  839. {
  840. foreach (XmlNode item in SortNodeByTop(node))
  841. {
  842. switch (RemovePrefix(item.Attributes["type"].Value))
  843. {
  844. case "HeaderBand":
  845. {
  846. BandBase parent = GetParentDataBand(ParseRectangleF(item["ClientRectangle"].InnerText), page, true);
  847. BandBase newBand;
  848. if (parent is DataBand)
  849. newBand = ComponentsFactory.CreateDataHeaderBand((DataBand)parent);
  850. else
  851. newBand = ComponentsFactory.CreateChildBand(parent);
  852. LoadBandBase(newBand, item);
  853. break;
  854. }
  855. case "FooterBand":
  856. {
  857. BandBase parent = GetParentDataBand(ParseRectangleF(item["ClientRectangle"].InnerText), page, false);
  858. BandBase newBand;
  859. if (parent is DataBand)
  860. newBand = ComponentsFactory.CreateDataFooterBand((DataBand)parent);
  861. else
  862. newBand = ComponentsFactory.CreateChildBand(parent);
  863. LoadBandBase(newBand, item);
  864. break;
  865. }
  866. case "GroupHeaderBand":
  867. {
  868. GroupHeaderBand band = ComponentsFactory.CreateGroupHeaderBand(page);
  869. band.Data = GetParentDataBand(ParseRectangleF(item["ClientRectangle"].InnerText), page);
  870. band.Condition = item["Condition"].InnerText;
  871. LoadBandBase(band, item);
  872. break;
  873. }
  874. case "GroupFooterBand":
  875. {
  876. BandBase band = ComponentsFactory.CreateGroupFooterBand(GetParentGroupHeaderBand(ParseRectangleF(item["ClientRectangle"].InnerText), page));
  877. LoadBandBase(band, item);
  878. break;
  879. }
  880. case "ChildBand":
  881. {
  882. ChildBand childBand = ComponentsFactory.CreateChildBand(GetParentBandBase(ParseRectangleF(item["ClientRectangle"].InnerText), page));
  883. LoadBandBase(childBand, item);
  884. break;
  885. }
  886. }
  887. }
  888. }
  889. private void LoadBandBase(BandBase band, XmlNode node)
  890. {
  891. if (band == null)
  892. return;
  893. band.Bounds = ParseRectangleF(node["ClientRectangle"].InnerText);
  894. if (node["Border"] != null)
  895. band.Border = UnitsConverter.ConvertBorder(node["Border"].InnerText);
  896. if (node["Brush"] != null)
  897. band.Fill = UnitsConverter.ConvertBrush(node["Brush"].InnerText);
  898. if (node["CanBreak"] != null)
  899. band.CanBreak = UnitsConverter.ConvertBool(node["CanBreak"].InnerText);
  900. if (node["CanGrow"] != null)
  901. band.CanGrow = UnitsConverter.ConvertBool(node["CanGrow"].InnerText);
  902. else
  903. band.CanGrow = true; // theirs default value
  904. if (node["CanShrink"] != null)
  905. band.CanShrink = UnitsConverter.ConvertBool(node["CanShrink"].InnerText);
  906. LoadReportObjects(node, band);
  907. }
  908. private void LoadReportComponentBase(ReportComponentBase obj, XmlNode node)
  909. {
  910. if (node["ClientRectangle"] != null)
  911. {
  912. RectangleF rect = ParseRectangleF(node["ClientRectangle"].InnerText);
  913. rect.X += leftOffset;
  914. obj.Bounds = rect;
  915. }
  916. if (node["ComponentStyle"] != null)
  917. ApplyStyleByName(obj, node["ComponentStyle"].InnerText);
  918. if (node["Border"] != null)
  919. obj.Border = UnitsConverter.ConvertBorder(node["Border"].InnerText);
  920. if (node["Brush"] != null)
  921. obj.Fill = UnitsConverter.ConvertBrush(node["Brush"].InnerText);
  922. if (node["CanGrow"] != null)
  923. obj.CanGrow = UnitsConverter.ConvertBool(node["CanGrow"].InnerText);
  924. if (node["CanShrink"] != null)
  925. obj.CanShrink = UnitsConverter.ConvertBool(node["CanShrink"].InnerText);
  926. if (node["Interaction"] != null)
  927. {
  928. foreach (XmlNode hyperlink in node["Interaction"])
  929. if (hyperlink.Attributes["type"] != null)
  930. switch (RemovePrefix(hyperlink.Attributes["type"].Value))
  931. {
  932. case "DrillDownParameter":
  933. obj.Hyperlink.Expression = hyperlink["Expression"].InnerText;
  934. break;
  935. }
  936. }
  937. if (node["Hyperlink"] != null && !node["Hyperlink"].InnerText.StartsWith("mailto"))
  938. {
  939. if (node["Hyperlink"].InnerText.StartsWith("#"))
  940. {
  941. obj.Hyperlink.Expression = SwapBarackets(node["Hyperlink"].InnerText.Replace("#", ""));
  942. obj.Hyperlink.Kind = HyperlinkKind.Bookmark;
  943. }
  944. if (node["Hyperlink"].InnerText.StartsWith("http"))
  945. {
  946. obj.Hyperlink.Value = SwapBarackets(node["Hyperlink"].InnerText);
  947. obj.Hyperlink.Kind = HyperlinkKind.URL;
  948. }
  949. }
  950. if (obj is BreakableComponent)
  951. if (node["CanBreak"] != null)
  952. (obj as BreakableComponent).CanBreak = UnitsConverter.ConvertBool(node["CanBreak"].InnerText);
  953. }
  954. private BandBase ConvertToChildIfDuplicatedBand(Type type)
  955. {
  956. BandBase band = null;
  957. foreach (Base obj in page.AllObjects)
  958. {
  959. if (obj.GetType() == type)
  960. {
  961. band = ComponentsFactory.CreateChildBand(GetLastChild((BandBase)obj));
  962. break;
  963. }
  964. }
  965. return band;
  966. }
  967. private BandBase GetLastChild(BandBase band)
  968. {
  969. if (band.Child != null)
  970. return GetLastChild(band.Child);
  971. else
  972. return band;
  973. }
  974. private BandBase GetParentBandBase(RectangleF rect, ReportPage page)
  975. {
  976. BandBase result = null;
  977. float offset = 10000;
  978. foreach (ReportComponentBase obj in page.AllObjects)
  979. if (obj is BandBase && obj.Bottom - rect.Top > 0 && obj.Bottom - rect.Top < offset)
  980. {
  981. result = (BandBase)obj;
  982. offset = obj.Bottom - rect.Top;
  983. }
  984. return result;
  985. }
  986. private GroupHeaderBand GetParentGroupHeaderBand(RectangleF rect, ReportPage page)
  987. {
  988. GroupHeaderBand result = null;
  989. float offset = 10000;
  990. foreach (ReportComponentBase obj in page.AllObjects)
  991. if (obj is GroupHeaderBand && rect.Top - obj.Bottom > 0 && rect.Top - obj.Bottom < offset)
  992. {
  993. result = (GroupHeaderBand)obj;
  994. offset = obj.Bottom - rect.Top;
  995. }
  996. return result;
  997. }
  998. private BandBase GetParentDataBand(RectangleF rect, ReportPage page, bool isTopBand)
  999. {
  1000. BandBase result = null;
  1001. float offset = 10000;
  1002. foreach (ReportComponentBase obj in page.AllObjects)
  1003. if (isTopBand)
  1004. {
  1005. if (obj is DataBand && obj.Top - rect.Bottom >= 0 && obj.Top - rect.Bottom < offset)
  1006. {
  1007. if ((obj as DataBand).Header != null)
  1008. result = (obj as DataBand).Header;
  1009. else
  1010. result = (DataBand)obj;
  1011. offset = obj.Top - rect.Bottom;
  1012. }
  1013. }
  1014. else
  1015. {
  1016. if (obj is DataBand && rect.Top - obj.Bottom >= 0 && rect.Top - obj.Bottom < offset)
  1017. {
  1018. if ((obj as DataBand).Footer != null)
  1019. result = (obj as DataBand).Footer;
  1020. else
  1021. result = (DataBand)obj;
  1022. offset = rect.Top - obj.Bottom;
  1023. }
  1024. }
  1025. return result;
  1026. }
  1027. private DataBand GetParentDataBand(RectangleF rect, ReportPage page)
  1028. {
  1029. DataBand result = null;
  1030. float offset = 10000;
  1031. foreach (ReportComponentBase obj in page.AllObjects)
  1032. if (obj is DataBand && obj.Top - rect.Bottom >= 0 && obj.Top - rect.Bottom < offset)
  1033. {
  1034. result = (DataBand)obj;
  1035. offset = obj.Top - rect.Bottom;
  1036. }
  1037. return result;
  1038. }
  1039. private List<XmlNode> SortNodeByTop(XmlNode node)
  1040. {
  1041. List<XmlNode> xmlNodeList = new List<XmlNode>();
  1042. if (node["Components"] != null)
  1043. foreach (XmlNode childNode in node["Components"].ChildNodes)
  1044. xmlNodeList.Add(childNode);
  1045. xmlNodeList = xmlNodeList.OrderBy(x => ParseRectangleF(x["ClientRectangle"].InnerText).Top).ToList();
  1046. return xmlNodeList;
  1047. }
  1048. private Font ParseFont(string font)
  1049. {
  1050. FontStyle fontStyle = FontStyle.Regular;
  1051. string[] defFontParts = font.Split(',');
  1052. if (font.Contains("Bold"))
  1053. {
  1054. fontStyle |= FontStyle.Bold;
  1055. }
  1056. if (font.Contains("Italic"))
  1057. {
  1058. fontStyle |= FontStyle.Italic;
  1059. }
  1060. if (font.Contains("Underline"))
  1061. {
  1062. fontStyle |= FontStyle.Underline;
  1063. }
  1064. if (font.Contains("Strikeout"))
  1065. {
  1066. fontStyle |= FontStyle.Strikeout;
  1067. }
  1068. return new Font(defFontParts[0], UnitsConverter.ConvertFloat(defFontParts[1]), fontStyle);
  1069. }
  1070. private void ParseTextOptions(TextObject textObject, string data)
  1071. {
  1072. if (data == null)
  1073. {
  1074. return;
  1075. }
  1076. string[] props = data.Split(',');
  1077. if (props[2].Contains("="))
  1078. textObject.RightToLeft = UnitsConverter.ConvertBool(props[2].Split('=')[1]);
  1079. if (props[4].Contains("="))
  1080. textObject.WordWrap = UnitsConverter.ConvertBool(props[4].Split('=')[1]);
  1081. int angle = 0;
  1082. if (props[5].Contains("="))
  1083. int.TryParse(props[5].Split('=')[1], System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out angle);
  1084. textObject.Angle = -angle;
  1085. }
  1086. private Padding ParsePageMargins(string margins)
  1087. {
  1088. int[] marg = new int[4];
  1089. int index = 0;
  1090. foreach (var item in margins.Split(','))
  1091. {
  1092. marg[index] = (int)(UnitsConverter.ConvertFloat(item) * UnitsConverter.GetPixelsInUnit(unitType));
  1093. index++;
  1094. }
  1095. return new Padding(marg[0], marg[1], marg[2], marg[3]);
  1096. }
  1097. private Padding ParseMargins(string margins)
  1098. {
  1099. int[] marg = new int[4];
  1100. int index = 0;
  1101. foreach (var item in margins.Split(','))
  1102. {
  1103. marg[index] = UnitsConverter.ConvertInt(item);
  1104. index++;
  1105. }
  1106. return new Padding(marg[0], marg[1], marg[2], marg[3]);
  1107. }
  1108. private RectangleF ParseRectangleF(string rect)
  1109. {
  1110. float[] marg = new float[4];
  1111. int index = 0;
  1112. foreach (var item in rect.Split(','))
  1113. {
  1114. float.TryParse(item, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out marg[index]);
  1115. marg[index] *= UnitsConverter.GetPixelsInUnit(unitType);
  1116. index++;
  1117. }
  1118. return new RectangleF(marg[0], marg[1], marg[2], marg[3]);
  1119. }
  1120. private void LoadReferencedAssemblies(XmlNode references)
  1121. {
  1122. foreach (XmlNode reference in references.ChildNodes)
  1123. {
  1124. bool exists = false;
  1125. if (String.IsNullOrEmpty(reference.InnerText))
  1126. continue;
  1127. // Strip off any trailing ".dll" ".exe" if present.
  1128. string dllName = reference.InnerText;
  1129. if (string.Compare(reference.InnerText.Substring(reference.InnerText.Length - 4), ".dll", true) == 0 ||
  1130. string.Compare(reference.InnerText.Substring(reference.InnerText.Length - 4), ".exe", true) == 0)
  1131. dllName = reference.InnerText.Substring(0, reference.InnerText.Length - 4);
  1132. // See if the required assembly is already present in our current AppDomain
  1133. foreach (Assembly currAssembly in AppDomain.CurrentDomain.GetAssemblies())
  1134. {
  1135. if (string.Compare(currAssembly.GetName().Name, dllName, true) == 0)
  1136. {
  1137. // Found it, return the location as the full reference.
  1138. exists = true;
  1139. }
  1140. }
  1141. // See if the required assembly is present in the ReferencedAssemblies but not yet loaded
  1142. foreach (AssemblyName assemblyName in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
  1143. {
  1144. if (string.Compare(assemblyName.Name, dllName, true) == 0)
  1145. {
  1146. // Found it, try to load assembly and return the location as the full reference.
  1147. try
  1148. {
  1149. exists = true;
  1150. }
  1151. catch { }
  1152. }
  1153. }
  1154. // Search assembly local and in current folder.
  1155. if (File.Exists(Path.Combine(Config.ApplicationFolder, reference.InnerText)) ||
  1156. File.Exists(reference.InnerText))
  1157. {
  1158. exists = true;
  1159. }
  1160. if (exists)
  1161. {
  1162. Report.AddReferencedAssembly(reference.InnerText);
  1163. }
  1164. }
  1165. }
  1166. private void LoadReportInfo()
  1167. {
  1168. unitType = UnitsConverter.ConverPageUnits(reportNode["ReportUnit"].InnerText);
  1169. Report.SetName(reportNode["ReportName"].InnerText);
  1170. Report.ScriptLanguage = reportNode["ScriptLanguage"].InnerText == "CSharp" ? Language.CSharp : Language.Vb;
  1171. Report.ScriptText += "/*" + reportNode["Script"].InnerText + "*/";
  1172. Report.Alias = reportNode["ReportAlias"].InnerText;
  1173. if (reportNode["ReportDescription"] != null)
  1174. Report.ReportInfo.Description = reportNode["ReportDescription"].InnerText;
  1175. LoadReferencedAssemblies(reportNode["ReferencedAssemblies"]);
  1176. }
  1177. private void LoadStyles()
  1178. {
  1179. foreach (XmlNode style in reportNode["Styles"])
  1180. {
  1181. Style newStyle = ComponentsFactory.CreateStyle(style["Name"].InnerText, Report);
  1182. if (style["Border"] != null)
  1183. {
  1184. newStyle.Border = UnitsConverter.ConvertBorder(style["Border"].InnerText);
  1185. newStyle.ApplyBorder = true;
  1186. }
  1187. if (style["TextBrush"] != null)
  1188. {
  1189. newStyle.TextFill = UnitsConverter.ConvertBrush(style["TextBrush"].InnerText);
  1190. newStyle.ApplyTextFill = true;
  1191. }
  1192. if (style["Brush"] != null)
  1193. {
  1194. newStyle.Fill = UnitsConverter.ConvertBrush(style["Brush"].InnerText);
  1195. newStyle.ApplyFill = true;
  1196. }
  1197. if (style["Font"] != null)
  1198. {
  1199. newStyle.Font = ParseFont(style["Font"].InnerText);
  1200. newStyle.ApplyFont = true;
  1201. }
  1202. }
  1203. }
  1204. private void ApplyStyleByName(ReportComponentBase component, string styleName)
  1205. {
  1206. foreach (Style subStyle in Report.Styles)
  1207. {
  1208. if (subStyle.Name == styleName)
  1209. {
  1210. component.Style = styleName;
  1211. component.ApplyStyle(subStyle);
  1212. return;
  1213. }
  1214. }
  1215. }
  1216. private void LoadReport()
  1217. {
  1218. LoadReportInfo();
  1219. LoadDataSource();
  1220. LoadStyles();
  1221. LoadPages();
  1222. }
  1223. private void LoadDataSource()
  1224. {
  1225. foreach (XmlNode db in reportNode["Dictionary"]["Databases"])
  1226. {
  1227. switch (RemovePrefix(db.Attributes["type"].Value))
  1228. {
  1229. case "XmlDatabase":
  1230. {
  1231. XmlDataConnection connection = new XmlDataConnection();
  1232. XmlConnectionStringBuilder stringBuilder = new XmlConnectionStringBuilder();
  1233. if (db["PathSchema"].InnerText != "")
  1234. stringBuilder.XsdFile = db["PathSchema"].InnerText;
  1235. stringBuilder.XmlFile = db["PathData"].InnerText;
  1236. connection.Name = db["Name"].InnerText;
  1237. connection.Alias = db["Alias"].InnerText;
  1238. connection.ConnectionString = stringBuilder.ToString();
  1239. connection.CreateAllTables();
  1240. connection.Enabled = true;
  1241. Report.Dictionary.Connections.Add(connection);
  1242. foreach (TableDataSource table in connection.Tables)
  1243. {
  1244. table.Enabled = true;
  1245. }
  1246. break;
  1247. }
  1248. case "JsonDatabase":
  1249. {
  1250. JsonDataSourceConnection connection = new JsonDataSourceConnection();
  1251. JsonDataSourceConnectionStringBuilder stringBuilder = new JsonDataSourceConnectionStringBuilder();
  1252. if (db["PathData"].InnerText.StartsWith("http"))
  1253. stringBuilder.Json = db["PathData"].InnerText;
  1254. else
  1255. stringBuilder.Json = new StreamReader(db["PathData"].InnerText).ReadToEnd();
  1256. connection.Name = db["Name"].InnerText;
  1257. connection.Alias = db["Alias"].InnerText;
  1258. connection.ConnectionString = stringBuilder.ToString();
  1259. connection.CreateAllTables();
  1260. connection.Enabled = true;
  1261. Report.Dictionary.Connections.Add(connection);
  1262. foreach (TableDataSource table in connection.Tables)
  1263. {
  1264. table.Enabled = true;
  1265. }
  1266. break;
  1267. }
  1268. case "CsvDatabase":
  1269. {
  1270. if (!File.Exists(db["PathData"].InnerText))
  1271. break;
  1272. CsvDataConnection connection = new CsvDataConnection();
  1273. CsvConnectionStringBuilder stringBuilder = new CsvConnectionStringBuilder();
  1274. stringBuilder.CsvFile = db["PathData"].InnerText;
  1275. stringBuilder.Codepage = UnitsConverter.ConvertInt(db["CodePage"].InnerText);
  1276. stringBuilder.Separator = db["CodePage"].InnerText;
  1277. connection.Name = db["Name"].InnerText;
  1278. connection.Alias = db["Alias"].InnerText;
  1279. connection.ConnectionString = stringBuilder.ToString();
  1280. connection.CreateAllTables();
  1281. connection.Enabled = true;
  1282. Report.Dictionary.Connections.Add(connection);
  1283. foreach (TableDataSource table in connection.Tables)
  1284. {
  1285. table.Enabled = true;
  1286. }
  1287. break;
  1288. }
  1289. }
  1290. }
  1291. }
  1292. private void LoadPages()
  1293. {
  1294. foreach (XmlNode node in reportNode["Pages"].ChildNodes)
  1295. {
  1296. if (RemovePrefix(node.Attributes["type"].Value) == "Form")
  1297. LoadDialogPage(node);
  1298. else
  1299. LoadPage(node);
  1300. }
  1301. UpdateSubReportPage();
  1302. }
  1303. partial void LoadDialogPage(XmlNode node);
  1304. private void UpdateSubReportPage()
  1305. {
  1306. foreach (Base obj in Report.AllObjects)
  1307. {
  1308. if (obj is SubreportObject)
  1309. {
  1310. foreach (ReportPage page in Report.Pages)
  1311. {
  1312. if (page.Tag == (obj as SubreportObject).Tag)
  1313. (obj as SubreportObject).ReportPage = page;
  1314. }
  1315. }
  1316. }
  1317. }
  1318. #endregion // Private Methods
  1319. #region Public Methods
  1320. /// <inheritdoc/>
  1321. public override void LoadReport(Report report, string filename)
  1322. {
  1323. using (var stream = new FileStream(filename, FileMode.Open))
  1324. {
  1325. LoadReport(report, stream);
  1326. }
  1327. }
  1328. /// <inheritdoc/>
  1329. public override void LoadReport(Report report, Stream stream)
  1330. {
  1331. Report = report;
  1332. Report.Clear();
  1333. System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
  1334. doc.Load(stream);
  1335. reportNode = doc.LastChild;
  1336. page = null;
  1337. leftOffset = 0;
  1338. LoadReport();
  1339. }
  1340. #endregion // Public Methods
  1341. }
  1342. }