UnitsConverter.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. using System;
  2. using System.Globalization;
  3. using System.Drawing;
  4. using FastReport.Utils;
  5. using FastReport.Barcode;
  6. using System.Drawing.Drawing2D;
  7. using FastReport.Format;
  8. using System.Xml;
  9. #if MSCHART
  10. using FastReport.DataVisualization.Charting;
  11. #endif
  12. using FastReport.Matrix;
  13. namespace FastReport.Import.StimulSoft
  14. {
  15. /// <summary>
  16. /// The StimulSoft units converter.
  17. /// </summary>
  18. public static class UnitsConverter
  19. {
  20. #region Public Methods
  21. /// <summary>
  22. /// Converts value to Boolean.
  23. /// </summary>
  24. /// <param name="str">Boolen value as string.</param>
  25. public static bool ConvertBool(string str)
  26. {
  27. return str.ToLower() == "true";
  28. }
  29. /// <summary>
  30. /// Converts value to PageUnits.
  31. /// </summary>
  32. /// <param name="unitType"></param>
  33. /// <returns></returns>
  34. public static float GetPixelsInUnit(PageUnits unitType)
  35. {
  36. switch (unitType)
  37. {
  38. case PageUnits.Centimeters:
  39. return Units.Centimeters;
  40. case PageUnits.Inches:
  41. return Units.Inches;
  42. case PageUnits.HundrethsOfInch:
  43. return Units.HundrethsOfInch;
  44. default:
  45. return Units.Millimeters;
  46. }
  47. }
  48. /// <summary>
  49. /// Converts value to PageUnits.
  50. /// </summary>
  51. /// <param name="unitType"></param>
  52. /// <returns></returns>
  53. public static PageUnits ConverPageUnits(string unitType)
  54. {
  55. switch (unitType)
  56. {
  57. case "Centimeters":
  58. return PageUnits.Centimeters;
  59. case "Inches":
  60. return PageUnits.Inches;
  61. case "HundredthsOfInch":
  62. return PageUnits.HundrethsOfInch;
  63. default:
  64. return PageUnits.Millimeters;
  65. }
  66. }
  67. /// <summary>
  68. /// Converts the PaperSize to width and height values of paper size in millimeters
  69. /// </summary>
  70. /// <param name="paperSize">The PaperSize value.</param>
  71. /// <param name="page">The ReportPage instance.</param>
  72. public static void ConvertPaperSize(string paperSize, ReportPage page)
  73. {
  74. if (page == null)
  75. return;
  76. float width = 210;
  77. float height = 297;
  78. switch (paperSize)
  79. {
  80. case "A4":
  81. width = 210;
  82. height = 297;
  83. break;
  84. case "A3":
  85. width = 297;
  86. height = 420;
  87. break;
  88. case "A5":
  89. width = 148;
  90. height = 210;
  91. break;
  92. case "B4":
  93. width = 257;
  94. height = 364;
  95. break;
  96. case "B5":
  97. width = 182;
  98. height = 257;
  99. break;
  100. case "Legal":
  101. width = 216;
  102. height = 356;
  103. break;
  104. case "Letter":
  105. width = 216;
  106. height = 279;
  107. break;
  108. case "Tabloid":
  109. width = 432;
  110. height = 279;
  111. break;
  112. case "Statement":
  113. width = 140;
  114. height = 216;
  115. break;
  116. case "Executive":
  117. width = 184;
  118. height = 267;
  119. break;
  120. default:
  121. width = 210;
  122. height = 297;
  123. break;
  124. }
  125. page.PaperWidth = width;
  126. page.PaperHeight = height;
  127. }
  128. /// <summary>
  129. /// Parse int value.
  130. /// </summary>
  131. /// <param name="strInt"></param>
  132. /// <returns></returns>
  133. public static int ConvertInt(string strInt)
  134. {
  135. int result = 0;
  136. int.TryParse(strInt, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out result);
  137. return result;
  138. }
  139. /// <summary>
  140. /// Parse float value
  141. /// </summary>
  142. /// <param name="strFloat"></param>
  143. /// <returns></returns>
  144. public static float ConvertFloat(string strFloat)
  145. {
  146. float result = 0;
  147. float.TryParse(strFloat, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out result);
  148. return result;
  149. }
  150. /// <summary>
  151. /// Converts StimulSoft Color.
  152. /// </summary>
  153. /// <param name="str">The DevExpress Color value as string.</param>
  154. /// <returns>The Color value.</returns>
  155. public static Color ConvertColor(string str)
  156. {
  157. if (!String.IsNullOrEmpty(str))
  158. {
  159. if (str.Contains("["))
  160. {
  161. string[] rgb = str.Replace("[", "").Replace("]","").Split(':');
  162. if(rgb.Length > 3)
  163. return Color.FromArgb(ConvertInt(rgb[0]), ConvertInt(rgb[1]), ConvertInt(rgb[2]), ConvertInt(rgb[3]));
  164. return Color.FromArgb(ConvertInt(rgb[0]), ConvertInt(rgb[1]), ConvertInt(rgb[2]));
  165. }
  166. else if (str.Contains(","))
  167. {
  168. string[] rgb = str.Replace(" ", "").Split(',');
  169. if (rgb.Length > 3)
  170. return Color.FromArgb(ConvertInt(rgb[0]), ConvertInt(rgb[1]), ConvertInt(rgb[2]), ConvertInt(rgb[3]));
  171. return Color.FromArgb(ConvertInt(rgb[0]), ConvertInt(rgb[1]), ConvertInt(rgb[2]));
  172. }
  173. else
  174. return Color.FromName(str);
  175. }
  176. return Color.Black;
  177. }
  178. /// <summary>
  179. /// Converts StimulSoft Border.
  180. /// </summary>
  181. /// <param name="border"></param>
  182. /// <returns></returns>
  183. public static Border ConvertBorder(string border)
  184. {
  185. Border result = new Border();
  186. string[] parametrs = border.Split(';');
  187. int indexParam = 0;
  188. if (border.StartsWith("Adv"))
  189. {
  190. parametrs = border.Remove(0, 3).Split(';');
  191. result.SimpleBorder = false;
  192. for (int i = 0; i < 4; i++)
  193. {
  194. BorderLine line = new BorderLine();
  195. line.Color = ConvertColor(parametrs[indexParam]);
  196. indexParam++;
  197. line.Width = ConvertInt(parametrs[indexParam]);
  198. indexParam++;
  199. if (parametrs[indexParam] == "None")
  200. {
  201. indexParam++;
  202. continue;
  203. }
  204. else
  205. {
  206. line.Style = ConvertBorderDashStyle(parametrs[indexParam]);
  207. indexParam++;
  208. }
  209. switch (i)
  210. {
  211. case 0:
  212. result.TopLine = line;
  213. result.Lines |= BorderLines.Top;
  214. break;
  215. case 1:
  216. result.BottomLine = line;
  217. result.Lines |= BorderLines.Bottom;
  218. break;
  219. case 2:
  220. result.LeftLine = line;
  221. result.Lines |= BorderLines.Left;
  222. break;
  223. case 3:
  224. result.RightLine = line;
  225. result.Lines |= BorderLines.Right;
  226. break;
  227. }
  228. }
  229. }
  230. else
  231. {
  232. result.Lines = ConvertBorderSides(parametrs[indexParam]);
  233. indexParam++;
  234. result.Color = ConvertColor(parametrs[indexParam]);
  235. indexParam++;
  236. result.Width = ConvertInt(parametrs[indexParam]);
  237. indexParam++;
  238. result.Style = ConvertBorderDashStyle(parametrs[indexParam]);
  239. indexParam++;
  240. }
  241. result.Shadow = ConvertBool(parametrs[indexParam]);
  242. indexParam++;
  243. result.ShadowWidth = ConvertInt(parametrs[indexParam]);
  244. indexParam++;
  245. result.ShadowColor = ConvertColor(parametrs[indexParam]);
  246. return result;
  247. }
  248. /// <summary>
  249. /// Converts the StimulSoft BorderDashStyle to LineStyle.
  250. /// </summary>
  251. /// <param name="borderDashStyle">The DevExpress BorderDashStyle value.</param>
  252. /// <returns>The LineStyle value.</returns>
  253. public static LineStyle ConvertBorderDashStyle(string borderDashStyle)
  254. {
  255. if (borderDashStyle.Equals("Dot"))
  256. {
  257. return LineStyle.Dot;
  258. }
  259. else if (borderDashStyle.Equals("Dash"))
  260. {
  261. return LineStyle.Dash;
  262. }
  263. else if (borderDashStyle.Equals("DashDot"))
  264. {
  265. return LineStyle.DashDot;
  266. }
  267. else if (borderDashStyle.Equals("DashDotDot"))
  268. {
  269. return LineStyle.DashDotDot;
  270. }
  271. else if (borderDashStyle.Equals("Double"))
  272. {
  273. return LineStyle.Double;
  274. }
  275. return LineStyle.Solid;
  276. }
  277. #if MSCHART
  278. /// <summary>
  279. /// Converts the StimulSoft BorderDashStyle to LineStyle.
  280. /// </summary>
  281. /// <param name="chartDashStyle">The DevExpress BorderDashStyle value.</param>
  282. /// <returns>The LineStyle value.</returns>
  283. public static ChartDashStyle ConvertBorderChartDashStyle(string chartDashStyle)
  284. {
  285. if (chartDashStyle.Equals("Dot"))
  286. {
  287. return ChartDashStyle.Dot;
  288. }
  289. else if (chartDashStyle.Equals("Dash"))
  290. {
  291. return ChartDashStyle.Dash;
  292. }
  293. else if (chartDashStyle.Equals("DashDot"))
  294. {
  295. return ChartDashStyle.DashDot;
  296. }
  297. else if (chartDashStyle.Equals("DashDotDot"))
  298. {
  299. return ChartDashStyle.DashDotDot;
  300. }
  301. else if (chartDashStyle.Equals("Double"))
  302. {
  303. return ChartDashStyle.NotSet;
  304. }
  305. return ChartDashStyle.Solid;
  306. }
  307. #endif
  308. /// <summary>
  309. /// Converts the StimulSoft LineStyle to LineStyle.
  310. /// </summary>
  311. /// <param name="lineStyle">The StimulSoft LineStyle value.</param>
  312. /// <returns>The LineStyle value.</returns>
  313. public static LineStyle ConvertLineStyle(string lineStyle)
  314. {
  315. if (lineStyle == "System.Drawing.Drawing2D.DashStyle.Dot")
  316. {
  317. return LineStyle.Dot;
  318. }
  319. else if (lineStyle == "System.Drawing.Drawing2D.DashStyle.Dash")
  320. {
  321. return LineStyle.Dash;
  322. }
  323. else if (lineStyle == "System.Drawing.Drawing2D.DashStyle.DashDot")
  324. {
  325. return LineStyle.DashDot;
  326. }
  327. else if (lineStyle == "System.Drawing.Drawing2D.DashStyle.DashDotDot")
  328. {
  329. return LineStyle.DashDotDot;
  330. }
  331. else if (lineStyle == "System.Drawing.Drawing2D.DashStyle.Double")
  332. {
  333. return LineStyle.Double;
  334. }
  335. return LineStyle.Solid;
  336. }
  337. /// <summary>
  338. /// Converts the StimulSoft TextAlignment to HorzAlignment.
  339. /// </summary>
  340. /// <param name="textAlignment">The StimulSoft TextAlignment value.</param>
  341. /// <returns>The HorzAlign value.</returns>
  342. public static HorzAlign ConvertTextAlignmentToHorzAlign(string textAlignment)
  343. {
  344. if (textAlignment.Contains("Center"))
  345. {
  346. return HorzAlign.Center;
  347. }
  348. if (textAlignment.Contains("Width"))
  349. {
  350. return HorzAlign.Justify;
  351. }
  352. if (textAlignment.Contains("Right"))
  353. {
  354. return HorzAlign.Right;
  355. }
  356. return HorzAlign.Left;
  357. }
  358. /// <summary>
  359. /// Converts the StimulSoft Brush to FillBase object.
  360. /// </summary>
  361. /// <param name="brush"></param>
  362. /// <returns></returns>
  363. public static FillBase ConvertBrush(string brush)
  364. {
  365. string[] parametrs = brush.Split(',');
  366. if (brush.Contains("HatchBrush"))
  367. {
  368. HatchFill fill = new HatchFill();
  369. fill.ForeColor = ConvertColor(parametrs[2]);
  370. fill.BackColor = ConvertColor(parametrs[3]);
  371. foreach (HatchStyle style in Enum.GetValues(typeof(HatchStyle)))
  372. {
  373. if (style.ToString() == parametrs[1])
  374. {
  375. fill.Style = style;
  376. break;
  377. }
  378. }
  379. return fill;
  380. }
  381. if (brush.Contains("GradientBrush"))
  382. {
  383. return new LinearGradientFill(ConvertColor(parametrs[2]), ConvertColor(parametrs[1]), ConvertInt(parametrs[3]));
  384. }
  385. if (brush.Contains("GlareBrush"))
  386. {
  387. return new LinearGradientFill(ConvertColor(parametrs[1]), ConvertColor(parametrs[2]), ConvertInt(parametrs[3]), ConvertFloat(parametrs[4]), 100);
  388. }
  389. if (brush.Contains("GlassBrush"))
  390. {
  391. return new GlassFill(ConvertColor(parametrs[1]), ConvertFloat(parametrs[3]), ConvertBool(parametrs[2]));
  392. }
  393. return new SolidFill(ConvertColor(brush));
  394. }
  395. /// <summary>
  396. /// Converts the StimulSoft Format to FormatBase object.
  397. /// </summary>
  398. /// <param name="node"></param>
  399. /// <returns></returns>
  400. public static FormatBase ConvertFormat(XmlNode node)
  401. {
  402. switch (node.Attributes["type"].Value)
  403. {
  404. case "NumberFormat":
  405. NumberFormat numberFormat = new NumberFormat();
  406. if (node["GroupSeparator"] != null)
  407. numberFormat.GroupSeparator = node["GroupSeparator"].InnerText;
  408. if (node["NegativePattern"] != null)
  409. numberFormat.NegativePattern = ConvertInt(node["NegativePattern"].InnerText);
  410. if (node["DecimalDigits"] != null)
  411. numberFormat.DecimalDigits = ConvertInt(node["DecimalDigits"].InnerText);
  412. if (node["DecimalSeparator"] != null)
  413. numberFormat.DecimalSeparator = node["DecimalSeparator"].InnerText;
  414. return numberFormat;
  415. case "CurrencyFormat":
  416. CurrencyFormat currencyFormat = new CurrencyFormat();
  417. if (node["GroupSeparator"] != null)
  418. currencyFormat.GroupSeparator = node["GroupSeparator"].InnerText;
  419. if (node["NegativePattern"] != null)
  420. currencyFormat.NegativePattern = ConvertInt(node["NegativePattern"].InnerText);
  421. if (node["DecimalDigits"] != null)
  422. currencyFormat.DecimalDigits = ConvertInt(node["DecimalDigits"].InnerText);
  423. if (node["DecimalSeparator"] != null)
  424. currencyFormat.DecimalSeparator = node["DecimalSeparator"].InnerText;
  425. if (node["PositivePattern"] != null)
  426. currencyFormat.PositivePattern = ConvertInt(node["PositivePattern"].InnerText);
  427. if (node["Symbol"] != null)
  428. currencyFormat.CurrencySymbol = node["Symbol"].InnerText;
  429. return currencyFormat;
  430. case "PercentageFormat":
  431. PercentFormat percentFormat = new PercentFormat();
  432. if (node["GroupSeparator"] != null)
  433. percentFormat.GroupSeparator = node["GroupSeparator"].InnerText;
  434. if (node["NegativePattern"] != null)
  435. percentFormat.NegativePattern = ConvertInt(node["NegativePattern"].InnerText);
  436. if (node["DecimalDigits"] != null)
  437. percentFormat.DecimalDigits = ConvertInt(node["DecimalDigits"].InnerText);
  438. if (node["DecimalSeparator"] != null)
  439. percentFormat.DecimalSeparator = node["DecimalSeparator"].InnerText;
  440. if (node["PositivePattern"] != null)
  441. percentFormat.PositivePattern = ConvertInt(node["PositivePattern"].InnerText);
  442. return percentFormat;
  443. case "DateFormat":
  444. DateFormat dataFormats = new DateFormat();
  445. if (node["StringFormat"] != null)
  446. dataFormats.Format = node["StringFormat"].InnerText;
  447. return dataFormats;
  448. case "TimeFormat":
  449. TimeFormat timeFormats = new TimeFormat();
  450. if (node["StringFormat"] != null)
  451. timeFormats.Format = node["StringFormat"].InnerText;
  452. return timeFormats;
  453. case "BooleanFormat":
  454. BooleanFormat booleanFormat = new BooleanFormat();
  455. if (node["FalseDisplay"] != null)
  456. booleanFormat.FalseText = node["FalseDisplay"].InnerText;
  457. if (node["TrueDisplay"] != null)
  458. booleanFormat.TrueText = node["TrueDisplay"].InnerText;
  459. return booleanFormat;
  460. case "CustomFormat":
  461. CustomFormat customFormat = new CustomFormat();
  462. customFormat.Format = node["StringFormat"].InnerText;
  463. return customFormat;
  464. }
  465. return new GeneralFormat();
  466. }
  467. /// <summary>
  468. /// Converts the StimulSoft RTF string to raw RTF.
  469. /// </summary>
  470. /// <param name="rtfStimulsoft"></param>
  471. /// <returns></returns>
  472. public static string ConvertRTF(string rtfStimulsoft)
  473. {
  474. string result = rtfStimulsoft.Replace("__LP__", "{").Replace("__RP__", "}");
  475. for(int i = 0; i < result.Length; i++)
  476. {
  477. if(result[i] == '_')
  478. try
  479. {
  480. result = result.Replace(result.Substring(i, 7), ((char)Int16.Parse(result.Substring(i + 2, 4), NumberStyles.AllowHexSpecifier)).ToString());
  481. }
  482. catch { }
  483. }
  484. return result;
  485. }
  486. /// <summary>
  487. /// Converts the StimulSoft CapStyle to CapStyle.
  488. /// </summary>
  489. /// <param name="style"></param>
  490. /// <returns></returns>
  491. public static CapStyle ConvertCapStyle(string style)
  492. {
  493. switch (style)
  494. {
  495. case "Diamond":
  496. return CapStyle.Diamond;
  497. case "Open":
  498. return CapStyle.Arrow;
  499. case "Square":
  500. return CapStyle.Square;
  501. case "Oval":
  502. return CapStyle.Circle;
  503. default:
  504. return CapStyle.Arrow;
  505. }
  506. }
  507. /// <summary>
  508. /// Converts the StimulSoft TextAlignment to VertAlignment.
  509. /// </summary>
  510. /// <param name="textAlignment">The StimulSoft TextAlignment value.</param>
  511. /// <returns>The VertAlign value.</returns>
  512. public static VertAlign ConvertTextAlignmentToVertAlign(string textAlignment)
  513. {
  514. if (textAlignment.Contains("Center"))
  515. {
  516. return VertAlign.Center;
  517. }
  518. if (textAlignment.Contains("Bottom"))
  519. {
  520. return VertAlign.Bottom;
  521. }
  522. return VertAlign.Top;
  523. }
  524. /// <summary>
  525. /// Converts the StimulSoft CheckedSymbol to CheckedSymbol.
  526. /// </summary>
  527. /// <param name="checksymbol"></param>
  528. /// <returns></returns>
  529. public static CheckedSymbol ConvertCheckSymbol(string checksymbol)
  530. {
  531. switch (checksymbol)
  532. {
  533. case "Cross":
  534. return CheckedSymbol.Cross;
  535. case "DotRectangle":
  536. return CheckedSymbol.Fill;
  537. default:
  538. return CheckedSymbol.Check;
  539. }
  540. }
  541. /// <summary>
  542. /// Converts the StimulSoft Barcode.Symbology to Barcode.Barcode.
  543. /// </summary>
  544. /// <param name="symbology">The StimulSoft Barcode.Symbology value as string.</param>
  545. /// <param name="barcode">The BarcodeObject instance.</param>
  546. public static void ConvertBarcodeSymbology(string symbology, BarcodeObject barcode)
  547. {
  548. switch (symbology)
  549. {
  550. case "Stimulsoft.Report.BarCodes.StiEAN128bBarCodeType":
  551. case "Stimulsoft.Report.BarCodes.StiEAN128cBarCodeType":
  552. case "Stimulsoft.Report.BarCodes.StiEAN128AutoBarCodeType":
  553. case "Stimulsoft.Report.BarCodes.StiEAN128aBarCodeType":
  554. case "Stimulsoft.Report.BarCodes.StiGS1_128BarCodeType":
  555. barcode.Barcode = new BarcodeEAN128();
  556. break;
  557. case "Stimulsoft.Report.BarCodes.StiDataMatrixBarCodeType":
  558. barcode.Barcode = new BarcodeDatamatrix();
  559. break;
  560. case "Stimulsoft.Report.BarCodes.StiQRCodeBarCodeType":
  561. barcode.Barcode = new BarcodeQR();
  562. break;
  563. case "Stimulsoft.Report.BarCodes.StiMaxicodeBarCodeType":
  564. barcode.Barcode = new BarcodeMaxiCode();
  565. break;
  566. case "Stimulsoft.Report.BarCodes.StiPdf417BarCodeType":
  567. barcode.Barcode = new BarcodePDF417();
  568. break;
  569. case "Stimulsoft.Report.BarCodes.StiAztecBarCodeType":
  570. barcode.Barcode = new BarcodeAztec();
  571. break;
  572. case "Stimulsoft.Report.BarCodes.StiEAN8BarCodeType":
  573. barcode.Barcode = new BarcodeEAN8();
  574. break;
  575. case "Stimulsoft.Report.BarCodes.StiUpcABarCodeType":
  576. barcode.Barcode = new BarcodeUPC_A();
  577. break;
  578. case "Stimulsoft.Report.BarCodes.StiITF14BarCodeType":
  579. barcode.Barcode = new BarcodeITF14();
  580. break;
  581. case "Stimulsoft.Report.BarCodes.StiAustraliaPost4StateBarCodeType":
  582. break;
  583. case "Stimulsoft.Report.BarCodes.StiIntelligentMail4StateBarCodeType":
  584. barcode.Barcode = new BarcodeIntelligentMail();
  585. break;
  586. case "Stimulsoft.Report.BarCodes.StiCode128aBarCodeType":
  587. case "Stimulsoft.Report.BarCodes.StiCode128bBarCodeType":
  588. case "Stimulsoft.Report.BarCodes.StiCode128cBarCodeType":
  589. case "Stimulsoft.Report.BarCodes.StiCode128AutoBarCodeType":
  590. barcode.Barcode = new Barcode128();
  591. break;
  592. case "Stimulsoft.Report.BarCodes.StiCode39BarCodeType":
  593. barcode.Barcode = new Barcode39();
  594. break;
  595. case "Stimulsoft.Report.BarCodes.StiCode39ExtBarCodeType":
  596. barcode.Barcode = new Barcode39Extended();
  597. break;
  598. case "Stimulsoft.Report.BarCodes.StiCode93BarCodeType":
  599. barcode.Barcode = new Barcode93();
  600. break;
  601. case "Stimulsoft.Report.BarCodes.StiCode93ExtBarCodeType":
  602. barcode.Barcode = new Barcode93Extended();
  603. break;
  604. case "Stimulsoft.Report.BarCodes.StiCodabarBarCodeType":
  605. barcode.Barcode = new BarcodeCodabar();
  606. break;
  607. case "Stimulsoft.Report.BarCodes.StiMsiBarCodeType":
  608. barcode.Barcode = new BarcodeMSI();
  609. break;
  610. case "Stimulsoft.Report.BarCodes.StiPlesseyBarCodeType":
  611. barcode.Barcode = new BarcodePlessey();
  612. break;
  613. case "Stimulsoft.Report.BarCodes.StiInterleaved2of5BarCodeType":
  614. barcode.Barcode = new Barcode2of5Interleaved();
  615. break;
  616. case "Stimulsoft.Report.BarCodes.StiPharmacodeBarCodeType":
  617. barcode.Barcode = new BarcodePharmacode();
  618. break;
  619. case "Stimulsoft.Report.BarCodes.StiStandard2of5BarCodeType":
  620. case "Stimulsoft.Report.BarCodes.StiDutchKIXBarCodeType":
  621. case "Stimulsoft.Report.BarCodes.StiRoyalMail4StateBarCodeType":
  622. case "Stimulsoft.Report.BarCodes.StiFIMBarCodeType":
  623. case "Stimulsoft.Report.BarCodes.StiCode11BarCodeType":
  624. case "Stimulsoft.Report.BarCodes.StiUpcEBarCodeType":
  625. case "Stimulsoft.Report.BarCodes.StiUpcSup2BarCodeType":
  626. case "Stimulsoft.Report.BarCodes.StiJan13BarCodeType":
  627. case "Stimulsoft.Report.BarCodes.StiJan8BarCodeType":
  628. case "Stimulsoft.Report.BarCodes.StiSSCC18BarCodeType":
  629. case "Stimulsoft.Report.BarCodes.StiIsbn10BarCodeType":
  630. case "Stimulsoft.Report.BarCodes.StiIsbn13BarCodeType":
  631. default:
  632. barcode.Barcode = new Barcode39();
  633. break;
  634. }
  635. }
  636. /// <summary>
  637. /// Converts the StimulSoft border sides to FastReport border sides
  638. /// </summary>
  639. /// <param name="sides"></param>
  640. public static BorderLines ConvertBorderSides(string sides)
  641. {
  642. BorderLines borderLines = BorderLines.None;
  643. if (!String.IsNullOrEmpty(sides))
  644. {
  645. if (sides.IndexOf("Left") > -1)
  646. {
  647. borderLines |= BorderLines.Left;
  648. }
  649. if (sides.IndexOf("Top") > -1)
  650. {
  651. borderLines |= BorderLines.Top;
  652. }
  653. if (sides.IndexOf("Right") > -1)
  654. {
  655. borderLines |= BorderLines.Right;
  656. }
  657. if (sides.IndexOf("Bottom") > -1)
  658. {
  659. borderLines |= BorderLines.Bottom;
  660. }
  661. if (sides.IndexOf("All") > -1)
  662. {
  663. borderLines = BorderLines.All;
  664. }
  665. }
  666. return borderLines;
  667. }
  668. /// <summary>
  669. /// Converts the StimulSoft AggregateFunction sides to FastReport MatrixAggregateFunction
  670. /// </summary>
  671. /// <param name="node"></param>
  672. /// <returns></returns>
  673. public static MatrixAggregateFunction GetMatrixAggregateFunction(XmlNode node)
  674. {
  675. if (node["Summary"] != null)
  676. {
  677. switch (node["Summary"].InnerText)
  678. {
  679. case "Image":
  680. return MatrixAggregateFunction.None;
  681. case "Average":
  682. return MatrixAggregateFunction.Avg;
  683. case "Min":
  684. return MatrixAggregateFunction.Min;
  685. case "Max":
  686. return MatrixAggregateFunction.Max;
  687. case "Count":
  688. return MatrixAggregateFunction.Count;
  689. case "CountDistinct":
  690. return MatrixAggregateFunction.CountDistinct;
  691. case "None":
  692. return MatrixAggregateFunction.None;
  693. }
  694. }
  695. return MatrixAggregateFunction.Sum;
  696. }
  697. /// <summary>
  698. /// Convert fill to color
  699. /// </summary>
  700. /// <param name="fill"></param>
  701. /// <returns></returns>
  702. public static Color ConvertBrushToColor(FillBase fill)
  703. {
  704. if (fill is HatchFill)
  705. return (fill as HatchFill).ForeColor;
  706. if (fill is LinearGradientFill)
  707. return (fill as LinearGradientFill).StartColor;
  708. if (fill is GlassFill)
  709. return (fill as GlassFill).Color;
  710. if (fill is SolidFill)
  711. return (fill as SolidFill).Color;
  712. return Color.Transparent;
  713. }
  714. #if MSCHART
  715. /// <summary>
  716. /// Converts the StimulSoft SeriesChartType to SeriesChartType.
  717. /// </summary>
  718. /// <param name="value"></param>
  719. /// <returns></returns>
  720. public static SeriesChartType ConvertChartType(string value)
  721. {
  722. switch (value)
  723. {
  724. case "Stimulsoft.Report.Chart.StiPieSeries":
  725. return SeriesChartType.Pie;
  726. case "Stimulsoft.Report.Chart.StiStackedColumnSeries":
  727. return SeriesChartType.StackedColumn;
  728. case "Stimulsoft.Report.Chart.StiStackedLineSeries":
  729. return SeriesChartType.StackedColumn;
  730. case "Stimulsoft.Report.Chart.StiClusteredBarSeries":
  731. return SeriesChartType.Bar;
  732. case "Stimulsoft.Report.Chart.StiLineSeries":
  733. return SeriesChartType.Line;
  734. case "Stimulsoft.Report.Chart.StiGanttSeries":
  735. case "Stimulsoft.Report.Chart.StiClusteredColumnSeries":
  736. return SeriesChartType.Column;
  737. case "Stimulsoft.Report.Chart.StiRadarAreaSeries":
  738. case "Stimulsoft.Report.Chart.StiSteppedAreaSeries":
  739. return SeriesChartType.Area;
  740. case "Stimulsoft.Report.Chart.StiDoughnutSeries":
  741. return SeriesChartType.Doughnut;
  742. case "Stimulsoft.Report.Chart.StiStackedSplineAreaSeries":
  743. return SeriesChartType.SplineArea;
  744. case "Stimulsoft.Report.Chart.StiFullStackedColumnSeries":
  745. return SeriesChartType.StackedColumn100;
  746. case "Stimulsoft.Report.Chart.StiFullStackedAreaSeries":
  747. return SeriesChartType.StackedArea100;
  748. case "Stimulsoft.Report.Chart.StiStackedBarSeries":
  749. return SeriesChartType.StackedBar;
  750. default:
  751. return SeriesChartType.Column;
  752. }
  753. }
  754. #endif
  755. /// <summary>
  756. /// Parse string to struct f Point.
  757. /// </summary>
  758. /// <param name="value"></param>
  759. /// <returns></returns>
  760. public static Point ConvertPoint(string value)
  761. {
  762. string[] points = value.Split(',');
  763. return new Point(ConvertInt(points[0]), ConvertInt(points[1]));
  764. }
  765. /// <summary>
  766. /// Parse string to struct of Size.
  767. /// </summary>
  768. /// <param name="value"></param>
  769. /// <returns></returns>
  770. public static Size ConvertSize(string value)
  771. {
  772. string[] points = value.Split(',');
  773. return new Size(ConvertInt(points[0]), ConvertInt(points[1]));
  774. }
  775. /// <summary>
  776. /// Converts the StimulSoft SeriesChartType to SeriesChartType.
  777. /// </summary>
  778. /// <param name="value"></param>
  779. /// <returns></returns>
  780. public static ContentAlignment ConvertContentAlignment(string value)
  781. {
  782. switch (value)
  783. {
  784. case "TopLeft":
  785. return ContentAlignment.TopLeft;
  786. case "TopCenter":
  787. return ContentAlignment.TopCenter;
  788. case "TopRight":
  789. return ContentAlignment.TopRight;
  790. case "MiddleLeft":
  791. return ContentAlignment.MiddleLeft;
  792. case "MiddleCenter":
  793. return ContentAlignment.MiddleCenter;
  794. case "MiddleRight":
  795. return ContentAlignment.MiddleRight;
  796. case "BottomLeft":
  797. return ContentAlignment.BottomLeft;
  798. case "BottomCenter":
  799. return ContentAlignment.BottomCenter;
  800. case "BottomRight":
  801. return ContentAlignment.BottomRight;
  802. }
  803. return ContentAlignment.TopLeft;
  804. }
  805. #endregion // Public Methods
  806. }
  807. }