BarcodeObject.cs 25 KB

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