BarcodeObject.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Drawing.Text;
  6. using System.Drawing.Drawing2D;
  7. using FastReport.Utils;
  8. using FastReport.Code;
  9. using System.Windows.Forms;
  10. using System.Drawing.Design;
  11. using FastReport.Barcode.QRCode;
  12. namespace FastReport.Barcode
  13. {
  14. /// <summary>
  15. /// Represents a barcode object.
  16. /// Represents a barcode object.
  17. /// </summary>
  18. /// <remarks>
  19. /// The instance of this class represents a barcode. Here are some common
  20. /// actions that can be performed with this object:
  21. /// <list type="bullet">
  22. /// <item>
  23. /// <description>To select the type of barcode, use the <see cref="Barcode"/> property.
  24. /// </description>
  25. /// </item>
  26. /// <item>
  27. /// <description>To specify a static barcode data, use the <see cref="Text"/> property.
  28. /// You also may use the <see cref="DataColumn"/> or <see cref="Expression"/> properties
  29. /// to specify dynamic value for a barcode.
  30. /// </description>
  31. /// </item>
  32. /// <item>
  33. /// <description>To set a barcode orientation, use the <see cref="Angle"/> property.
  34. /// </description>
  35. /// </item>
  36. /// <item>
  37. /// <description>To specify the size of barcode, set the <see cref="AutoSize"/> property
  38. /// to <b>true</b> and use the <see cref="Zoom"/> property to zoom the barcode.
  39. /// If <see cref="AutoSize"/> property is set to <b>false</b>, you need to specify the
  40. /// size using the <see cref="ComponentBase.Width">Width</see> and
  41. /// <see cref="ComponentBase.Height">Height</see> properties.
  42. /// </description>
  43. /// </item>
  44. /// </list>
  45. /// </remarks>
  46. /// <example>This example shows how to configure the BarcodeObject to display PDF417 barcode.
  47. /// <code>
  48. /// BarcodeObject barcode;
  49. /// ...
  50. /// barcode.Barcode = new BarcodePDF417();
  51. /// (barcode.Barcode as BarcodePDF417).CompactionMode = CompactionMode.Text;
  52. /// </code>
  53. /// </example>
  54. public partial class BarcodeObject : ReportComponentBase
  55. {
  56. /// <summary>
  57. /// Specifies the horizontal alignment of a Barcode object. Works only when autosize is on.
  58. /// </summary>
  59. public enum Alignment
  60. {
  61. /// <summary>
  62. /// Specifies that the barcode is aligned to the left of the original layout.
  63. /// </summary>
  64. Left,
  65. /// <summary>
  66. /// Specifies that the barcode is aligned to the center of the original layout.
  67. /// </summary>
  68. Center,
  69. /// <summary>
  70. /// Specifies that the barcode is aligned to the right of the original layout.
  71. /// </summary>
  72. Right
  73. }
  74. #region Fields
  75. private int angle;
  76. private bool autoSize;
  77. private BarcodeBase barcode;
  78. private string dataColumn;
  79. private string expression;
  80. private string text;
  81. private bool showText;
  82. private Padding padding;
  83. private float zoom;
  84. private bool hideIfNoData;
  85. private string noDataText;
  86. private string brackets;
  87. private bool allowExpressions;
  88. private string savedText;
  89. private bool asBitmap;
  90. private Alignment horzAlign;
  91. private RectangleF origRect;
  92. private bool showMarker;
  93. #endregion
  94. #region Properties
  95. /// <summary>
  96. /// Gets or sets the barcode type.
  97. /// </summary>
  98. [Category("Appearance")]
  99. [Editor("FastReport.TypeEditors.BarcodeEditor, FastReport", typeof(UITypeEditor))]
  100. public BarcodeBase Barcode
  101. {
  102. get { return barcode; }
  103. set
  104. {
  105. if (value == null)
  106. value = new Barcode39();
  107. barcode = value;
  108. }
  109. }
  110. /// <summary>
  111. /// Gets or sets the horizontal alignment of a Barcode object.
  112. /// </summary>
  113. [DefaultValue(Alignment.Left)]
  114. [Category("Appearance")]
  115. public Alignment HorzAlign
  116. {
  117. get { return horzAlign; }
  118. set { horzAlign = value; }
  119. }
  120. /// <summary>
  121. /// Gets or sets the symbology name.
  122. /// </summary>
  123. /// <remarks>
  124. /// The following symbology names are supported:
  125. /// <list type="bullet">
  126. /// <item><description>"2/5 Interleaved"</description></item>
  127. /// <item><description>"2/5 Industrial"</description></item>
  128. /// <item><description>"2/5 Matrix"</description></item>
  129. /// <item><description>"Codabar"</description></item>
  130. /// <item><description>"Code128"</description></item>
  131. /// <item><description>"Code39"</description></item>
  132. /// <item><description>"Code39 Extended"</description></item>
  133. /// <item><description>"Code93"</description></item>
  134. /// <item><description>"Code93 Extended"</description></item>
  135. /// <item><description>"EAN8"</description></item>
  136. /// <item><description>"EAN13"</description></item>
  137. /// <item><description>"MSI"</description></item>
  138. /// <item><description>"PostNet"</description></item>
  139. /// <item><description>"UPC-A"</description></item>
  140. /// <item><description>"UPC-E0"</description></item>
  141. /// <item><description>"UPC-E1"</description></item>
  142. /// <item><description>"Supplement 2"</description></item>
  143. /// <item><description>"Supplement 5"</description></item>
  144. /// <item><description>"PDF417"</description></item>
  145. /// <item><description>"Datamatrix"</description></item>
  146. /// <item><description>"QRCode"</description></item>
  147. /// </list>
  148. /// </remarks>
  149. /// <example>
  150. /// <code>
  151. /// barcode.SymbologyName = "PDF417";
  152. /// (barcode.Barcode as BarcodePDF417).CompactionMode = CompactionMode.Text;
  153. /// </code>
  154. /// </example>
  155. [Browsable(false)]
  156. public string SymbologyName
  157. {
  158. get
  159. {
  160. return Barcode.Name;
  161. }
  162. set
  163. {
  164. if (SymbologyName != value)
  165. {
  166. Type bartype = Barcodes.GetType(value);
  167. Barcode = Activator.CreateInstance(bartype) as BarcodeBase;
  168. Text = barcode.GetDefaultValue();
  169. }
  170. }
  171. }
  172. /// <summary>
  173. /// Gets or sets the angle of barcode, in degrees.
  174. /// </summary>
  175. [DefaultValue(0)]
  176. [Category("Appearance")]
  177. public int Angle
  178. {
  179. get { return angle; }
  180. set { angle = value; }
  181. }
  182. /// <summary>
  183. /// Gets or sets a value that determines whether the barcode should handle its width automatically.
  184. /// </summary>
  185. [DefaultValue(true)]
  186. [Category("Behavior")]
  187. public bool AutoSize
  188. {
  189. get { return autoSize; }
  190. set { autoSize = value; }
  191. }
  192. /// <summary>
  193. /// Gets or sets a data column name bound to this control.
  194. /// </summary>
  195. /// <remarks>
  196. /// Value must be in the form "Datasource.Column".
  197. /// </remarks>
  198. [Category("Data")]
  199. [Editor("FastReport.TypeEditors.DataColumnEditor, FastReport", typeof(UITypeEditor))]
  200. public string DataColumn
  201. {
  202. get { return dataColumn; }
  203. set { dataColumn = value; }
  204. }
  205. /// <summary>
  206. /// Gets or sets an expression that contains the barcode data.
  207. /// </summary>
  208. [Category("Data")]
  209. [Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
  210. public string Expression
  211. {
  212. get { return expression; }
  213. set { expression = value; }
  214. }
  215. /// <summary>
  216. /// Enable or disable of using an expression in Text
  217. /// </summary>
  218. [Category("Data")]
  219. [DefaultValue(false)]
  220. public bool AllowExpressions
  221. {
  222. get { return allowExpressions; }
  223. set { allowExpressions = value; }
  224. }
  225. /// <summary>
  226. /// Gets or sets brackets for using in expressions
  227. /// </summary>
  228. [Category("Data")]
  229. public string Brackets
  230. {
  231. get { return brackets; }
  232. set { brackets = value; }
  233. }
  234. /// <summary>
  235. /// Gets or sets a value that indicates if the barcode should display a human-readable text.
  236. /// </summary>
  237. [DefaultValue(true)]
  238. [Category("Behavior")]
  239. public bool ShowText
  240. {
  241. get { return showText; }
  242. set { showText = value; }
  243. }
  244. /// <summary>
  245. /// Gets or sets the barcode data.
  246. /// </summary>
  247. [Category("Data")]
  248. [Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
  249. public string Text
  250. {
  251. get { return text; }
  252. set { text = value; }
  253. }
  254. /// <summary>
  255. /// Gets or sets padding within the BarcodeObject.
  256. /// </summary>
  257. [Category("Layout")]
  258. public Padding Padding
  259. {
  260. get { return padding; }
  261. set { padding = value; }
  262. }
  263. /// <summary>
  264. /// Gets or sets a zoom of the barcode.
  265. /// </summary>
  266. [DefaultValue(1f)]
  267. [Category("Appearance")]
  268. public float Zoom
  269. {
  270. get { return zoom; }
  271. set { zoom = value; }
  272. }
  273. /// <summary>
  274. /// Gets or sets a value that determines whether it is necessary to hide the object if the
  275. /// barcode data is empty.
  276. /// </summary>
  277. [DefaultValue(true)]
  278. [Category("Behavior")]
  279. public bool HideIfNoData
  280. {
  281. get { return hideIfNoData; }
  282. set { hideIfNoData = value; }
  283. }
  284. /// <summary>
  285. /// Gets or sets the text that will be displayed if the barcode data is empty.
  286. /// </summary>
  287. [Category("Data")]
  288. public string NoDataText
  289. {
  290. get { return noDataText; }
  291. set { noDataText = value; }
  292. }
  293. /// <summary>
  294. /// Gets or sets values for forced use of a bitmap image instead of a vector
  295. /// </summary>
  296. [Category("Appearance")]
  297. [DefaultValue(false)]
  298. public bool AsBitmap
  299. {
  300. get { return asBitmap; }
  301. set { asBitmap = value; }
  302. }
  303. /// <summary>
  304. /// Gets or sets values for hiding or showing barcode markers
  305. /// </summary>
  306. [DefaultValue(true)]
  307. [Category("Appearance")]
  308. public bool ShowMarker
  309. {
  310. get { return showMarker; }
  311. set { showMarker = value; }
  312. }
  313. #endregion
  314. #region Private Methods
  315. private void SetBarcodeProperties()
  316. {
  317. barcode.Initialize(Text, ShowText, Angle, Zoom, ShowMarker);
  318. }
  319. private void DrawBarcode(FRPaintEventArgs e)
  320. {
  321. RectangleF displayRect = new RectangleF(
  322. (AbsLeft + Padding.Left) * e.ScaleX,
  323. (AbsTop + Padding.Top) * e.ScaleY,
  324. (Width - Padding.Horizontal) * e.ScaleX,
  325. (Height - Padding.Vertical) * e.ScaleY);
  326. IGraphics g = e.Graphics;
  327. IGraphicsState state = g.Save();
  328. try
  329. {
  330. Report report = Report;
  331. if (report != null)
  332. {
  333. if (report.SmoothGraphics)
  334. {
  335. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  336. g.SmoothingMode = SmoothingMode.AntiAlias;
  337. }
  338. g.TextRenderingHint = report.GetTextQuality();
  339. }
  340. barcode.DrawBarcode(g, displayRect);
  341. }
  342. finally
  343. {
  344. g.Restore(state);
  345. }
  346. }
  347. #endregion
  348. #region Public Methods
  349. /// <summary>
  350. /// Initialize current BarcodeObject as Swiss QR.
  351. /// </summary>
  352. /// <param name="parameters">Parameters of swiss qr.</param>
  353. public void CreateSwissQR(QRSwissParameters parameters)
  354. {
  355. QRSwiss swiss = new QRSwiss(parameters);
  356. this.Barcode = new BarcodeQR();
  357. Barcode.text = swiss.Pack();
  358. this.Text = swiss.Pack();
  359. this.ShowText = false;
  360. }
  361. public void UpdateAutoSize()
  362. {
  363. SetBarcodeProperties();
  364. SizeF size = Barcode.CalcBounds();
  365. size.Width *= Zoom;
  366. size.Height *= Zoom;
  367. if (AutoSize)
  368. {
  369. if (Angle == 0 || Angle == 180)
  370. {
  371. Width = size.Width + Padding.Horizontal;
  372. if (size.Height > 0)
  373. Height = size.Height + Padding.Vertical;
  374. }
  375. else if (Angle == 90 || Angle == 270)
  376. {
  377. Height = size.Width + Padding.Vertical;
  378. if (size.Height > 0)
  379. Width = size.Height + Padding.Horizontal;
  380. }
  381. RelocateAlign();
  382. }
  383. }
  384. /// <summary>
  385. /// Relocate BarcodeObject based on alignment
  386. /// </summary>
  387. public void RelocateAlign()
  388. {
  389. if (HorzAlign == Alignment.Left || origRect == RectangleF.Empty)
  390. return;
  391. switch (HorzAlign)
  392. {
  393. case Alignment.Center:
  394. {
  395. this.Left = origRect.Left + (origRect.Width / 2) - this.Width / 2;
  396. break;
  397. }
  398. case Alignment.Right:
  399. {
  400. this.Left = origRect.Right - this.Width;
  401. break;
  402. }
  403. }
  404. origRect = RectangleF.Empty;
  405. }
  406. /// <inheritdoc/>
  407. public override void Assign(Base source)
  408. {
  409. base.Assign(source);
  410. BarcodeObject src = source as BarcodeObject;
  411. Barcode = src.Barcode.Clone();
  412. Angle = src.Angle;
  413. AutoSize = src.AutoSize;
  414. DataColumn = src.DataColumn;
  415. Expression = src.Expression;
  416. Text = src.Text;
  417. ShowText = src.ShowText;
  418. Padding = src.Padding;
  419. Zoom = src.Zoom;
  420. HideIfNoData = src.HideIfNoData;
  421. NoDataText = src.NoDataText;
  422. Brackets = src.Brackets;
  423. AllowExpressions = src.AllowExpressions;
  424. AsBitmap = src.AsBitmap;
  425. HorzAlign = src.HorzAlign;
  426. ShowMarker = src.ShowMarker;
  427. }
  428. /// <inheritdoc/>
  429. public override void Draw(FRPaintEventArgs e)
  430. {
  431. bool error = false;
  432. string errorText = "";
  433. if (String.IsNullOrEmpty(Text))
  434. {
  435. error = true;
  436. errorText = NoDataText;
  437. }
  438. else
  439. {
  440. try
  441. {
  442. UpdateAutoSize();
  443. }
  444. catch (Exception ex)
  445. {
  446. error = true;
  447. errorText = ex.Message;
  448. }
  449. }
  450. base.Draw(e);
  451. if (!error)
  452. {
  453. DrawBarcode(e);
  454. }
  455. else
  456. {
  457. if (IsDesigning && text.StartsWith(Brackets.Split(',')[0]) && Text.EndsWith(Brackets.Split(',')[1]))
  458. {
  459. try
  460. {
  461. barcode.text = barcode.GetDefaultValue();
  462. DrawBarcode(e);
  463. error = false;
  464. }
  465. catch
  466. {
  467. error = true;
  468. }
  469. }
  470. if (error)
  471. e.Graphics.DrawString(errorText, DrawUtils.DefaultReportFont, Brushes.Red,
  472. new RectangleF(AbsLeft * e.ScaleX, AbsTop * e.ScaleY, Width * e.ScaleX, Height * e.ScaleY));
  473. }
  474. DrawMarkers(e);
  475. Border.Draw(e, new RectangleF(AbsLeft, AbsTop, Width, Height));
  476. }
  477. /// <inheritdoc/>
  478. public override void Serialize(FRWriter writer)
  479. {
  480. BarcodeObject c = writer.DiffObject as BarcodeObject;
  481. base.Serialize(writer);
  482. if (Angle != c.Angle)
  483. writer.WriteInt("Angle", Angle);
  484. if (AutoSize != c.AutoSize)
  485. writer.WriteBool("AutoSize", AutoSize);
  486. if (DataColumn != c.DataColumn)
  487. writer.WriteStr("DataColumn", DataColumn);
  488. if (Expression != c.Expression)
  489. writer.WriteStr("Expression", Expression);
  490. if (Text != c.Text)
  491. writer.WriteStr("Text", Text);
  492. if (ShowText != c.ShowText)
  493. writer.WriteBool("ShowText", ShowText);
  494. if (Padding != c.Padding)
  495. writer.WriteValue("Padding", Padding);
  496. if (Zoom != c.Zoom)
  497. writer.WriteFloat("Zoom", Zoom);
  498. if (HideIfNoData != c.HideIfNoData)
  499. writer.WriteBool("HideIfNoData", HideIfNoData);
  500. if (NoDataText != c.NoDataText)
  501. writer.WriteStr("NoDataText", NoDataText);
  502. if (AllowExpressions != c.AllowExpressions)
  503. writer.WriteBool("AllowExpressions", AllowExpressions);
  504. if (Brackets != c.Brackets)
  505. writer.WriteStr("Brackets", Brackets);
  506. if (AsBitmap != c.AsBitmap)
  507. writer.WriteBool("AsBitmap", AsBitmap);
  508. if (HorzAlign != c.HorzAlign)
  509. writer.WriteValue("HorzAlign", HorzAlign);
  510. if (ShowMarker != c.ShowMarker)
  511. writer.WriteValue("ShowMarker", ShowMarker);
  512. Barcode.Serialize(writer, "Barcode.", c.Barcode);
  513. }
  514. #endregion
  515. #region Report Engine
  516. /// <inheritdoc/>
  517. public override string[] GetExpressions()
  518. {
  519. List<string> expressions = new List<string>();
  520. expressions.AddRange(base.GetExpressions());
  521. if (!String.IsNullOrEmpty(DataColumn))
  522. expressions.Add(DataColumn);
  523. if (!String.IsNullOrEmpty(Expression))
  524. expressions.Add(Expression);
  525. else
  526. {
  527. if (AllowExpressions && !String.IsNullOrEmpty(Brackets))
  528. {
  529. string[] brackets = Brackets.Split(',');
  530. // collect expressions found in the text
  531. expressions.AddRange(CodeUtils.GetExpressions(Text, brackets[0], brackets[1]));
  532. }
  533. }
  534. return expressions.ToArray();
  535. }
  536. /// <inheritdoc/>
  537. public override void SaveState()
  538. {
  539. base.SaveState();
  540. savedText = Text;
  541. }
  542. /// <inheritdoc/>
  543. public override void RestoreState()
  544. {
  545. base.RestoreState();
  546. Text = savedText;
  547. }
  548. /// <inheritdoc/>
  549. public override void GetData()
  550. {
  551. base.GetData();
  552. if (!String.IsNullOrEmpty(DataColumn))
  553. {
  554. object value = Report.GetColumnValue(DataColumn);
  555. Text = value == null ? "" : value.ToString();
  556. }
  557. else if (!String.IsNullOrEmpty(Expression))
  558. {
  559. object value = Report.Calc(Expression);
  560. Text = value == null ? "" : value.ToString();
  561. }
  562. else
  563. {
  564. // process expressions
  565. if (AllowExpressions && !String.IsNullOrEmpty(this.brackets))
  566. {
  567. string[] bracket_arr = this.brackets.Split(',');
  568. FindTextArgs args = new FindTextArgs();
  569. args.Text = new FastString(Text);
  570. args.OpenBracket = bracket_arr[0];
  571. args.CloseBracket = bracket_arr[1];
  572. int expressionIndex = 0;
  573. while (args.StartIndex < args.Text.Length)
  574. {
  575. string expression = CodeUtils.GetExpression(args, false);
  576. if (expression == null)
  577. break;
  578. string value = Report.Calc(expression).ToString();
  579. args.Text = args.Text.Remove(args.StartIndex, args.EndIndex - args.StartIndex);
  580. args.Text = args.Text.Insert(args.StartIndex, value);
  581. args.StartIndex += value.Length;
  582. expressionIndex++;
  583. }
  584. Text = args.Text.ToString();
  585. }
  586. }
  587. if (Visible)
  588. Visible = !String.IsNullOrEmpty(Text) || !HideIfNoData;
  589. if (Visible)
  590. {
  591. try
  592. {
  593. origRect = this.Bounds;
  594. UpdateAutoSize();
  595. }
  596. catch
  597. {
  598. }
  599. }
  600. if (Barcode is BarcodeQR)
  601. {
  602. //QRData.Parse(Text);
  603. //QRSwiss qRSwiss = new QRSwiss(Text);
  604. //Text = qRSwiss.Pack();
  605. QRData qr = QRData.Parse(Text);
  606. if (qr is QRSwiss)
  607. {
  608. QRSwiss _qr = qr as QRSwiss;
  609. QRSwissParameters parameters = new QRSwissParameters();
  610. parameters.Iban = _qr._Iban;
  611. parameters.Creditor = _qr.Creditor;
  612. parameters.Reference = _qr._Reference;
  613. parameters.AlternativeProcedure1 = _qr.AlternativeProcedure1;
  614. parameters.AlternativeProcedure2 = _qr.AlternativeProcedure2;
  615. parameters.AdditionalInformation = _qr._AdditionalInformation;
  616. parameters.Amount = _qr.Amount;
  617. parameters.Currency = _qr._Currency;
  618. parameters.Debitor = _qr.Debitor;
  619. QRSwiss swissQR = new QRSwiss(parameters);
  620. Text = swissQR.Pack();
  621. }
  622. }
  623. }
  624. #endregion
  625. /// <summary>
  626. /// Initializes a new instance of the <see cref="BarcodeObject"/> class with default settings.
  627. /// </summary>
  628. public BarcodeObject()
  629. {
  630. Barcode = new Barcode39();
  631. AutoSize = true;
  632. DataColumn = "";
  633. Expression = "";
  634. Text = Barcode.GetDefaultValue();
  635. ShowText = true;
  636. ShowMarker = true;
  637. Padding = new Padding();
  638. Zoom = 1;
  639. HideIfNoData = true;
  640. NoDataText = "";
  641. AllowExpressions = false;
  642. Brackets = "[,]";
  643. SetFlags(Flags.HasSmartTag, true);
  644. }
  645. }
  646. internal static class Barcodes
  647. {
  648. #if READONLY_STRUCTS
  649. internal readonly struct BarcodeItem
  650. #else
  651. internal struct BarcodeItem
  652. #endif
  653. {
  654. public readonly Type objType;
  655. public readonly string barcodeName;
  656. public readonly string category;
  657. public BarcodeItem(Type objType, string barcodeName, string category)
  658. {
  659. this.objType = objType;
  660. this.barcodeName = barcodeName;
  661. this.category = category;
  662. }
  663. }
  664. public readonly static BarcodeItem[] Items = {
  665. new BarcodeItem(typeof(Barcode2of5Interleaved), "2/5 Interleaved", "Others"),
  666. new BarcodeItem(typeof(Barcode2of5Industrial), "2/5 Industrial", "Others"),
  667. new BarcodeItem(typeof(Barcode2of5Matrix), "2/5 Matrix", "Others"),
  668. new BarcodeItem(typeof(BarcodeDeutscheIdentcode), "Deutsche Identcode", "Post"),
  669. new BarcodeItem(typeof(BarcodeDeutscheLeitcode),"Deutshe Leitcode", "Post"),
  670. new BarcodeItem(typeof(BarcodeITF14), "ITF-14", "Others"),
  671. new BarcodeItem(typeof(BarcodeCodabar), "Codabar", "Others"),
  672. new BarcodeItem(typeof(Barcode128), "Code128", "Others"),
  673. new BarcodeItem(typeof(Barcode39), "Code39", "Others"),
  674. new BarcodeItem(typeof(Barcode39Extended), "Code39 Extended", "Others"),
  675. new BarcodeItem(typeof(Barcode93), "Code93", "Others"),
  676. new BarcodeItem(typeof(Barcode93Extended), "Code93 Extended", "Others"),
  677. new BarcodeItem(typeof(BarcodeEAN8), "EAN8", "EANUPC"),
  678. new BarcodeItem(typeof(BarcodeEAN13), "EAN13", "EANUPC"),
  679. new BarcodeItem(typeof(BarcodeMSI), "MSI", "Others"),
  680. new BarcodeItem(typeof(BarcodePostNet), "PostNet", "Post"),
  681. new BarcodeItem(typeof(BarcodeJapanPost4StateCode), "Japan Post 4 State Code", "Post"),
  682. new BarcodeItem(typeof(BarcodeUPC_A), "UPC-A", "EANUPC"),
  683. new BarcodeItem(typeof(BarcodeUPC_E0), "UPC-E0", "EANUPC"),
  684. new BarcodeItem(typeof(BarcodeUPC_E1), "UPC-E1", "EANUPC"),
  685. new BarcodeItem(typeof(BarcodeSupplement2), "Supplement 2", "Others"),
  686. new BarcodeItem(typeof(BarcodeSupplement5), "Supplement 5", "Others"),
  687. new BarcodeItem(typeof(BarcodePDF417), "PDF417", "2D"),
  688. new BarcodeItem(typeof(BarcodeDatamatrix), "Datamatrix", "2D"),
  689. new BarcodeItem(typeof(BarcodeQR), "QR Code", "2D"),
  690. new BarcodeItem(typeof(BarcodeAztec), "Aztec", "2D"),
  691. new BarcodeItem(typeof(BarcodePlessey), "Plessey", "Others"),
  692. new BarcodeItem(typeof(BarcodeEAN128), "GS1-128 (UCC/EAN-128)", "GS1"),
  693. new BarcodeItem(typeof(BarcodeGS1Omnidirectional), "GS1 DataBar Omnidirectional", "GS1"),
  694. new BarcodeItem(typeof(BarcodeGS1Limited), "GS1 DataBar Limited", "GS1"),
  695. new BarcodeItem(typeof(BarcodeGS1Stacked), "GS1 DataBar Stacked", "GS1"),
  696. new BarcodeItem(typeof(BarcodeGS1StackedOmnidirectional), "GS1 DataBar Stacked Omnidirectional", "GS1"),
  697. new BarcodeItem(typeof(BarcodePharmacode), "Pharmacode", "Others"),
  698. new BarcodeItem(typeof(BarcodeIntelligentMail), "Intelligent Mail (USPS)", "Post"),
  699. new BarcodeItem(typeof(BarcodeMaxiCode), "MaxiCode", "2D")
  700. };
  701. public static string GetName(Type type)
  702. {
  703. foreach (BarcodeItem item in Items)
  704. {
  705. if (item.objType == type)
  706. return item.barcodeName;
  707. }
  708. return "";
  709. }
  710. public static Type GetType(string name)
  711. {
  712. foreach (BarcodeItem item in Items)
  713. {
  714. if (item.barcodeName == name)
  715. return item.objType;
  716. }
  717. return null;
  718. }
  719. public static string[] GetDisplayNames()
  720. {
  721. List<string> result = new List<string>();
  722. MyRes res = new MyRes("ComponentMenu,Barcode,Barcodes");
  723. for (int i = 0; i < Items.Length; i++)
  724. {
  725. result.Add(res.Get("Barcode" + i.ToString()));
  726. }
  727. return result.ToArray();
  728. }
  729. public static string[] GetSymbologyNames()
  730. {
  731. List<string> result = new List<string>();
  732. foreach (BarcodeItem item in Items)
  733. {
  734. result.Add(item.barcodeName);
  735. }
  736. return result.ToArray();
  737. }
  738. }
  739. }