RDLImport.BaseExt.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using FastReport.MSChart;
  7. using FastReport.Table;
  8. namespace FastReport.Import.RDL
  9. {
  10. /// <summary>
  11. /// Represents the RDL import plugin.
  12. /// </summary>
  13. public partial class RDLImport : ImportBase
  14. {
  15. #region Private Methods
  16. private void LoadBorderColorExt(XmlNode borderColorNode)
  17. {
  18. XmlNodeList nodeList = borderColorNode.ChildNodes;
  19. foreach (XmlNode node in nodeList)
  20. {
  21. if (node.Name == "Default")
  22. {
  23. if (component is MSChartObject)
  24. {
  25. (component as MSChartObject).Chart.BorderlineColor = UnitsConverter.ConvertColor(node.InnerText);
  26. }
  27. else if (component is ReportComponentBase)
  28. {
  29. (component as ReportComponentBase).Border.Color = UnitsConverter.ConvertColor(node.InnerText);
  30. }
  31. }
  32. else if (node.Name == "Top")
  33. {
  34. if (component is ReportComponentBase)
  35. {
  36. (component as ReportComponentBase).Border.TopLine.Color = UnitsConverter.ConvertColor(node.InnerText);
  37. }
  38. }
  39. else if (node.Name == "Left")
  40. {
  41. if (component is ReportComponentBase)
  42. {
  43. (component as ReportComponentBase).Border.LeftLine.Color = UnitsConverter.ConvertColor(node.InnerText);
  44. }
  45. }
  46. else if (node.Name == "Right")
  47. {
  48. if (component is ReportComponentBase)
  49. {
  50. (component as ReportComponentBase).Border.RightLine.Color = UnitsConverter.ConvertColor(node.InnerText);
  51. }
  52. }
  53. else if (node.Name == "Bottom")
  54. {
  55. if (component is ReportComponentBase)
  56. {
  57. (component as ReportComponentBase).Border.BottomLine.Color = UnitsConverter.ConvertColor(node.InnerText);
  58. }
  59. }
  60. }
  61. }
  62. private void LoadBorderStyleExt(XmlNode borderStyleNode)
  63. {
  64. XmlNodeList nodeList = borderStyleNode.ChildNodes;
  65. foreach (XmlNode node in nodeList)
  66. {
  67. if (node.Name == "Default")
  68. {
  69. if (component is MSChartObject)
  70. {
  71. (component as MSChartObject).Chart.BorderlineDashStyle = UnitsConverter.ConvertBorderStyleToChartDashStyle(node.InnerText);
  72. }
  73. else if (component is ReportComponentBase)
  74. {
  75. (component as ReportComponentBase).Border.Lines = BorderLines.All;
  76. (component as ReportComponentBase).Border.Style = UnitsConverter.ConvertBorderStyle(node.InnerText);
  77. }
  78. }
  79. else if (node.Name == "Top")
  80. {
  81. if (component is ReportComponentBase)
  82. {
  83. (component as ReportComponentBase).Border.Lines |= BorderLines.Top;
  84. (component as ReportComponentBase).Border.TopLine.Style = UnitsConverter.ConvertBorderStyle(node.InnerText);
  85. }
  86. }
  87. else if (node.Name == "Left")
  88. {
  89. if (component is ReportComponentBase)
  90. {
  91. (component as ReportComponentBase).Border.Lines |= BorderLines.Left;
  92. (component as ReportComponentBase).Border.LeftLine.Style = UnitsConverter.ConvertBorderStyle(node.InnerText);
  93. }
  94. }
  95. else if (node.Name == "Right")
  96. {
  97. if (component is ReportComponentBase)
  98. {
  99. (component as ReportComponentBase).Border.Lines |= BorderLines.Right;
  100. (component as ReportComponentBase).Border.RightLine.Style = UnitsConverter.ConvertBorderStyle(node.InnerText);
  101. }
  102. }
  103. else if (node.Name == "Bottom")
  104. {
  105. if (component is ReportComponentBase)
  106. {
  107. (component as ReportComponentBase).Border.Lines |= BorderLines.Bottom;
  108. (component as ReportComponentBase).Border.BottomLine.Style = UnitsConverter.ConvertBorderStyle(node.InnerText);
  109. }
  110. }
  111. }
  112. }
  113. private void LoadBorderWidthExt(XmlNode borderWidthNode)
  114. {
  115. XmlNodeList nodeList = borderWidthNode.ChildNodes;
  116. foreach (XmlNode node in nodeList)
  117. {
  118. if (node.Name == "Default")
  119. {
  120. if (component is MSChartObject)
  121. {
  122. (component as MSChartObject).Chart.BorderlineWidth = (int)UnitsConverter.SizeToPixels(node.InnerText);
  123. }
  124. else if (component is ReportComponentBase)
  125. {
  126. (component as ReportComponentBase).Border.Width = UnitsConverter.SizeToPixels(node.InnerText);
  127. }
  128. }
  129. else if (node.Name == "Top")
  130. {
  131. if (component is ReportComponentBase)
  132. {
  133. (component as ReportComponentBase).Border.TopLine.Width = UnitsConverter.SizeToPixels(node.InnerText);
  134. }
  135. }
  136. else if (node.Name == "Left")
  137. {
  138. if (component is ReportComponentBase)
  139. {
  140. (component as ReportComponentBase).Border.LeftLine.Width = UnitsConverter.SizeToPixels(node.InnerText);
  141. }
  142. }
  143. else if (node.Name == "Right")
  144. {
  145. if (component is ReportComponentBase)
  146. {
  147. (component as ReportComponentBase).Border.RightLine.Width = UnitsConverter.SizeToPixels(node.InnerText);
  148. }
  149. }
  150. else if (node.Name == "Bottom")
  151. {
  152. if (component is ReportComponentBase)
  153. {
  154. (component as ReportComponentBase).Border.BottomLine.Width = UnitsConverter.SizeToPixels(node.InnerText);
  155. }
  156. }
  157. }
  158. }
  159. private void LoadStyleExt(XmlNode styleNode)
  160. {
  161. FontStyle fontStyle = FontStyle.Regular;
  162. string fontFamily = "Arial";
  163. float fontSize = 10.0f;
  164. int paddingTop = 0;
  165. int paddingLeft = 2;
  166. int paddingRight = 2;
  167. int paddingBottom = 0;
  168. XmlNodeList nodeList = styleNode.ChildNodes;
  169. foreach (XmlNode node in nodeList)
  170. {
  171. if (node.Name == "BorderColor")
  172. {
  173. LoadBorderColorExt(node);
  174. }
  175. else if (node.Name == "BorderStyle")
  176. {
  177. LoadBorderStyleExt(node);
  178. }
  179. else if (node.Name == "BorderWidth")
  180. {
  181. LoadBorderWidthExt(node);
  182. }
  183. else if (node.Name == "BackgroundColor")
  184. {
  185. if (component is ShapeObject)
  186. {
  187. (component as ShapeObject).FillColor = UnitsConverter.ConvertColor(node.InnerText);
  188. }
  189. else if (component is MSChartObject)
  190. {
  191. (component as MSChartObject).Chart.BackColor = UnitsConverter.ConvertColor(node.InnerText);
  192. }
  193. else if (component is TableObject)
  194. {
  195. (component as TableObject).FillColor = UnitsConverter.ConvertColor(node.InnerText);
  196. }
  197. //else if (component is SubreportObject)
  198. //{
  199. // (component as SubreportObject).FillColor = UnitsConverter.ConvertColor(node.InnerText);
  200. //}
  201. }
  202. else if (node.Name == "BackgroundGradientType")
  203. {
  204. if (component is MSChartObject)
  205. {
  206. (component as MSChartObject).Chart.BackGradientStyle = UnitsConverter.ConvertGradientType(node.InnerText);
  207. }
  208. }
  209. else if (node.Name == "BackgroundGradientEndColor")
  210. {
  211. if (component is MSChartObject)
  212. {
  213. (component as MSChartObject).Chart.BackSecondaryColor = UnitsConverter.ConvertColor(node.InnerText);
  214. }
  215. }
  216. else if (node.Name == "FontStyle")
  217. {
  218. fontStyle = UnitsConverter.ConvertFontStyle(node.InnerText);
  219. }
  220. else if (node.Name == "FontFamily")
  221. {
  222. fontFamily = node.InnerText;
  223. }
  224. else if (node.Name == "FontSize")
  225. {
  226. fontSize = Convert.ToSingle(UnitsConverter.ConvertFontSize(node.InnerText));
  227. }
  228. else if (node.Name == "TextAlign")
  229. {
  230. if (component is TextObject)
  231. {
  232. (component as TextObject).HorzAlign = UnitsConverter.ConvertTextAlign(node.InnerText);
  233. }
  234. }
  235. else if (node.Name == "VerticalAlign")
  236. {
  237. if (component is TextObject)
  238. {
  239. (component as TextObject).VertAlign = UnitsConverter.ConvertVerticalAlign(node.InnerText);
  240. }
  241. }
  242. else if (node.Name == "WritingMode")
  243. {
  244. if (component is TextObject)
  245. {
  246. (component as TextObject).Angle = UnitsConverter.ConvertWritingMode(node.InnerText);
  247. }
  248. }
  249. else if (node.Name == "Color")
  250. {
  251. if (component is TextObject)
  252. {
  253. (component as TextObject).TextColor = UnitsConverter.ConvertColor(node.InnerText);
  254. }
  255. }
  256. else if (node.Name == "PaddingLeft")
  257. {
  258. paddingLeft = UnitsConverter.SizeToInt(node.InnerText, SizeUnits.Point);
  259. }
  260. else if (node.Name == "PaddingRight")
  261. {
  262. paddingRight = UnitsConverter.SizeToInt(node.InnerText, SizeUnits.Point);
  263. }
  264. else if (node.Name == "PaddingTop")
  265. {
  266. paddingTop = UnitsConverter.SizeToInt(node.InnerText, SizeUnits.Point);
  267. }
  268. else if (node.Name == "PaddingBottom")
  269. {
  270. paddingBottom = UnitsConverter.SizeToInt(node.InnerText, SizeUnits.Point);
  271. }
  272. }
  273. if (component is TextObject)
  274. {
  275. (component as TextObject).Font = new Font(fontFamily, fontSize, fontStyle);
  276. (component as TextObject).Padding = new Padding(paddingLeft, paddingTop, paddingRight, paddingBottom);
  277. }
  278. else if (component is PictureObject)
  279. {
  280. (component as PictureObject).Padding = new Padding(paddingLeft, paddingTop, paddingRight, paddingBottom);
  281. }
  282. #if !FRCORE
  283. else if (component is MSChartObject)
  284. {
  285. (component as MSChartObject).Chart.Padding = new Padding(paddingLeft, paddingTop, paddingRight, paddingBottom);
  286. }
  287. #endif
  288. }
  289. private void LoadThreeDProperties(XmlNode threeDPropertiesNode)
  290. {
  291. XmlNodeList nodeList = threeDPropertiesNode.ChildNodes;
  292. foreach (XmlNode node in nodeList)
  293. {
  294. if (node.Name == "Enabled")
  295. {
  296. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.Enable3D = UnitsConverter.BooleanToBool(node.InnerText);
  297. }
  298. else if (node.Name == "Rotation")
  299. {
  300. int rotation = Convert.ToInt32(node.InnerText);
  301. if (rotation >= -180 && rotation <= 180)
  302. {
  303. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.Rotation = rotation;
  304. }
  305. else
  306. {
  307. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.Rotation = 30;
  308. }
  309. }
  310. else if (node.Name == "Inclination")
  311. {
  312. int inclination = Convert.ToInt32(node.InnerText);
  313. if (inclination >= -90 && inclination <= 90)
  314. {
  315. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.Inclination = inclination;
  316. }
  317. else
  318. {
  319. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.Inclination = 30;
  320. }
  321. }
  322. else if (node.Name == "Perspective")
  323. {
  324. int perspective = Convert.ToInt32(node.InnerText);
  325. if (perspective >= 0 && perspective <= 60)
  326. {
  327. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.Perspective = perspective;
  328. }
  329. else
  330. {
  331. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.Perspective = 0;
  332. }
  333. }
  334. else if (node.Name == "DepthRatio")
  335. {
  336. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.PointDepth = Convert.ToInt32(node.InnerText);
  337. }
  338. else if (node.Name == "Shading")
  339. {
  340. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.LightStyle = UnitsConverter.ConvertShading(node.InnerText);
  341. }
  342. else if (node.Name == "GapDepth")
  343. {
  344. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.PointGapDepth = Convert.ToInt32(node.InnerText);
  345. }
  346. else if (node.Name == "WallThickness")
  347. {
  348. int width = Convert.ToInt32(node.InnerText);
  349. if (width < 0)
  350. {
  351. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.WallWidth = 0;
  352. }
  353. else if (width > 30)
  354. {
  355. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.WallWidth = 30;
  356. }
  357. else
  358. {
  359. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.WallWidth = width;
  360. }
  361. }
  362. else if (node.Name == "Clustered")
  363. {
  364. (component as MSChartObject).Chart.ChartAreas[0].Area3DStyle.IsClustered = UnitsConverter.BooleanToBool(node.InnerText);
  365. }
  366. }
  367. }
  368. #endregion // Private Methods
  369. }
  370. }