BarcodeMSI.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace FastReport.Barcode
  5. {
  6. /// <summary>
  7. /// Generates the MSI barcode.
  8. /// </summary>
  9. public class BarcodeMSI : LinearBarcodeBase
  10. {
  11. private static string[] tabelle_MSI = {
  12. "51515151", //0
  13. "51515160", //1
  14. "51516051", //2
  15. "51516060", //3
  16. "51605151", //4
  17. "51605160", //5
  18. "51606051", //6
  19. "51606060", //7
  20. "60515151", //8
  21. "60515160" //9
  22. };
  23. private int quersumme(int x)
  24. {
  25. int sum = 0;
  26. while (x > 0)
  27. {
  28. sum += x % 10;
  29. x /= 10;
  30. }
  31. return sum;
  32. }
  33. internal override string GetPattern()
  34. {
  35. string result = "60"; // Startcode
  36. int check_even = 0;
  37. int check_odd = 0;
  38. for (int i = 0; i < text.Length; i++)
  39. {
  40. if ((i % 2) != 0)
  41. check_odd = check_odd * 10 + CharToInt(text[i]);
  42. else
  43. check_even += CharToInt(text[i]);
  44. result += tabelle_MSI[CharToInt(text[i])];
  45. }
  46. int checksum = quersumme(check_odd * 2) + check_even;
  47. checksum %= 10;
  48. if (checksum > 0)
  49. checksum = 10 - checksum;
  50. if (CalcCheckSum)
  51. result += tabelle_MSI[checksum];
  52. result += "515"; //Stopcode
  53. return result;
  54. }
  55. }
  56. }