Exemplo n.º 1
0
        /* Barcode Commands */
        public byte[] PrintBarcode(BarcodeType type, string barcode, BarcodeCode code = BarcodeCode.CODE_B)
        {
            DataValidator.ValidateBarcode(type, code, barcode);

            // For CODE128, prepend the first 2 characters as 0x7B and the CODE type, and escape 0x7B characters.
            if (type == BarcodeType.CODE128)
            {
                if (code == BarcodeCode.CODE_C)
                {
                    var b  = Encoding.ASCII.GetBytes(barcode);
                    var ob = new byte[b.Length / 2];
                    for (int i = 0, obc = 0; i < b.Length; i += 2)
                    {
                        ob[obc++] = (byte)((b[i] - '0') * 10 + (b[i + 1] - '0'));
                    }

                    barcode = Encoding.ASCII.GetString(ob);
                }

                barcode = barcode.Replace("{", "{{");
                barcode = $"{(char) 0x7B}{(char) code}" + barcode;
            }

            var command = new List <byte> {
                Cmd.GS, Barcodes.PrintBarcode, (byte)type, (byte)barcode.Length
            };

            command.AddRange(barcode.ToCharArray().Select(x => (byte)x));
            return(command.ToArray());
        }
Exemplo n.º 2
0
        public static void ValidateBarcode(BarcodeType type, BarcodeCode code, string data)
        {
            if (singletonBarcode is null)
            {
                singletonBarcode = new BarcodeDataValidator();
            }

            singletonBarcode.Validate(type, data, code);
        }
Exemplo n.º 3
0
        /* Barcode Commands */
        public byte[] PrintBarcode(BarcodeType type, string barcode, BarcodeCode code = BarcodeCode.CODE_B)
        {
            DataValidator.ValidateBarcode(type, barcode);

            // For CODE128, prepend the first 2 characters as 0x7B and the CODE type, and escape 0x7B characters.
            if (type == BarcodeType.CODE128)
            {
                barcode = barcode.Replace("{", "{{");
                barcode = $"{(char)0x7B}{(char)code}" + barcode;
            }

            var command = new List <byte> {
                Cmd.GS, Barcodes.PrintBarcode, (byte)type, (byte)barcode.Length
            };

            command.AddRange(barcode.ToCharArray().Select(x => (byte)x));
            return(command.ToArray());
        }
Exemplo n.º 4
0
        /* Barcode Commands */
        public byte[] PrintBarcode(BarcodeType type, string barcode, BarcodeCode code = BarcodeCode.CODE_B)
        {
            DataValidator.ValidateBarcode(type, barcode);

            // For CODE128, prepend the first 2 characters as 0x7B and the CODE type, and escape 0x7B characters.
            if (type == BarcodeType.CODE128)
            {
                #region Issue #48
                if (code == BarcodeCode.CODE_C)
                {
                    if (barcode.Length % 2 != 0)
                    {
                        throw new ArgumentException($"{nameof(barcode)} length must be divisible by 2");
                    }

                    byte[] b = Encoding.ASCII.GetBytes(barcode);
                    for (int i = 0; i < b.Length; i++)
                    {
                        if (b[i] < '0' || b[i] > '9')
                        {
                            throw new ArgumentException($"{nameof(barcode)} must contain numerals only");
                        }
                    }

                    byte[] ob = new byte[b.Length / 2];
                    for (int i = 0,
                         obc = 0; i < b.Length; i += 2)
                    {
                        ob[obc++] = (byte)(((b[i] - '0') * 10) + (b[i + 1] - '0'));
                    }

                    barcode = Encoding.ASCII.GetString(ob);
                }
                #endregion
                barcode = barcode.Replace("{", "{{");
                barcode = $"{(char)0x7B}{(char)code}" + barcode;
            }

            var command = new List <byte> {
                Cmd.GS, Barcodes.PrintBarcode, (byte)type, (byte)barcode.Length
            };
            command.AddRange(barcode.ToCharArray().Select(x => (byte)x));
            return(command.ToArray());
        }
Exemplo n.º 5
0
 public DirectPrinter PrintBarcode(BarcodeType type, string barcode, BarcodeCode code = BarcodeCode.CODE_B)
 {
     UpdateBuffer(this.Emitter.PrintBarcode(type, barcode, code));
     return(this);
 }
Exemplo n.º 6
0
        private void recognize_Click(object sender, EventArgs e)
        {
            numberblack       = 0;
            richTextBox1.Text = "";
            if (button == true)
            {
                Color[,] All = new Color[image.Width - 1, image.Height - 1];
                for (int i = 0; i < (image.Width - 1); i++)
                {
                    for (int j = 0; j < (image.Height - 1); j++)
                    {
                        All[i, j] = image.GetPixel(i, j);
                    }
                }
                numberblack = barcode.numberblack(image, All);
                switch (numberblack)
                {
                case 30:
                {
                    richTextBox1.Text += "Код: EAN-13" + "\n";
                    string[] result = barcodeEAN.barcodeEAN13(image, All);
                    if (result.Length != 0)
                    {
                        for (int i = 0; i < 13; i++)
                        {
                            richTextBox1.Text += result[i];
                        }
                        richTextBox1.Text += "\nТовар:" + barcode.searchProduct(String.Concat <string>(result));
                    }
                    else
                    {
                        richTextBox1.Text = "Штрих-код не розпізнано!";
                    }
                }
                break;

                case 22:
                {
                    richTextBox1.Text += "Код:EAN-8" + "\n";
                    string[] result = barcodeEAN.barcodeEAN8(image, All);
                    if (result.Length != 0)
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            richTextBox1.Text += result[i];
                        }
                        richTextBox1.Text += "\nТовар:" + barcode.searchProduct(String.Concat <string>(result));
                    }
                    else
                    {
                        richTextBox1.Text = "Штрих-код не розпізнано!";
                    }
                }
                break;

                default:
                {
                    richTextBox1.Text += "Код:Code39" + "\n";
                    ArrayList barcode = new ArrayList();
                    string    code    = "";
                    BarcodeCode.barcodeCode(ref barcode, image);
                    if (barcode.Count != 0)
                    {
                        for (int i = 0; i < barcode.Count; i++)
                        {
                            richTextBox1.Text += barcode[i];
                            code += barcode[i];
                        }
                        richTextBox1.Text += "\nТовар:" + this.barcode.searchProduct(code);
                    }
                    else
                    {
                        richTextBox1.Text = "Штрих-код не розпізнано!";
                    }
                }
                break;
                }
            }
            else
            {
                MessageBox.Show("Завантажте зображення!", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 7
0
 /* Barcode Commands */
 public virtual byte[] PrintBarcode(BarcodeType type, string barcode, BarcodeCode code = BarcodeCode.CODE_B)
 {
     DataValidator.ValidateBarcode(type, code, barcode);
     return(BarcodeBytes(type, barcode, code));
 }
Exemplo n.º 8
0
        public void barcodeCodeTest()
        { // arrange
            Bitmap        image_1   = new Bitmap("D:\\ИАД Курсач\\image\\Code\\1.gif");
            Bitmap        image_2   = new Bitmap("D:\\ИАД Курсач\\image\\Code\\2.gif");
            Bitmap        image_3   = new Bitmap("D:\\ИАД Курсач\\image\\Code\\3.gif");
            Bitmap        image_4   = new Bitmap("D:\\ИАД Курсач\\image\\Code\\4.gif");
            Bitmap        image_5   = new Bitmap("D:\\ИАД Курсач\\image\\Code\\5.gif");
            Bitmap        image_6   = new Bitmap("D:\\ИАД Курсач\\image\\Code\\6.gif");
            Bitmap        image_7   = new Bitmap("D:\\ИАД Курсач\\image\\Code\\7.gif");
            Bitmap        image_8   = new Bitmap("D:\\ИАД Курсач\\image\\Code\\8.gif");
            Bitmap        image_9   = new Bitmap("D:\\ИАД Курсач\\image\\Code\\9.gif");
            Bitmap        image_10  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\10.gif");
            Bitmap        image_11  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\11.gif");
            Bitmap        image_12  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\12.gif");
            Bitmap        image_13  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\13.gif");
            Bitmap        image_14  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\14.gif");
            Bitmap        image_15  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\15.gif");
            Bitmap        image_16  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\16.gif");
            Bitmap        image_17  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\17.gif");
            Bitmap        image_18  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\18.gif");
            Bitmap        image_19  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\19.gif");
            Bitmap        image_20  = new Bitmap("D:\\ИАД Курсач\\image\\Code\\20.gif");
            List <Bitmap> imageList = new List <Bitmap>();

            imageList.Add(image_1);
            imageList.Add(image_2);
            imageList.Add(image_3);
            imageList.Add(image_4);
            imageList.Add(image_5);
            imageList.Add(image_6);
            imageList.Add(image_7);
            imageList.Add(image_8);
            imageList.Add(image_9);
            imageList.Add(image_10);
            imageList.Add(image_11);
            imageList.Add(image_12);
            imageList.Add(image_13);
            imageList.Add(image_14);
            imageList.Add(image_15);
            imageList.Add(image_16);
            imageList.Add(image_17);
            imageList.Add(image_18);
            imageList.Add(image_19);
            imageList.Add(image_20);
            int count = 0;

            string[]  barcodeOtvet = { "AB2-1234", "222-1234",     "2691734",     "ABC-abc-1234", "789-abc-1234",
                                       "7821234",   "896-abc-1234", "896-abc1234", "89612bc1234",  "1112bc1234",
                                       "1259",      "178hdk",       "78sdf55",     "ABC-789J",     "789-789J",
                                       "TGB7789J",  "789-144-44",   "890-144-44",  "UUU-11",       "7890-011" };
            ArrayList barcode = new ArrayList();
            string    code    = "";

            for (int t = 0; t < 20; t++)
            {
                barcode.Clear();
                code = "";
                string otvet = "";
                // act
                BarcodeCode.barcodeCode(ref barcode, imageList[t]);
                //richTextBox1.Text += barcode.Count.ToString();
                for (int i = 0; i < barcode.Count; i++)
                {
                    code += barcode[i];
                }
                // assert
                //Assert.AreEqual(result, code);

                if (code == barcodeOtvet[t])
                {
                    otvet = "    Функція повернула вірне значення"; count++;
                }
                else
                {
                    otvet = "   Функція повертає невірне значення";
                }
                Debug.WriteLine("Правильна відповідь має бути: " + barcodeOtvet[t] + "   Функція повернула значення: " + code + otvet);
            }
            Debug.Write("Кількість правильно розпізнаних штрих-кодів: " + count);
        }