Пример #1
0
        private bool TryDecode(string full_bin_list)
        {
            BinaryBox1.Clear();
            BinaryBox2.Clear();
            PatterBox.Clear();
            number_type[] n_type_array = new number_type[12];
            for (int i = 0; i < 12; i++)
            {
                if (!encoding_table.TryGetValue(full_bin_list.Substring(i * 7, 7), out n_type_array[i]))
                {
                    label1.Text = "Error. There is no such bit patter in encoding table";
                    return(false);
                }
                if (i < 6)
                {
                    BinaryBox1.Text += full_bin_list.Substring(i * 7, 7) + " ";
                }
                else
                {
                    BinaryBox2.Text += full_bin_list.Substring(i * 7, 7) + " ";
                }
            }

            string encoded_type_str = "";

            for (int i = 0; i < 6; i++)
            {
                encoded_type_str += n_type_array[i].type.ToString();
            }
            for (int i = 0; i < 12; i++)
            {
                PatterBox.Text += n_type_array[i].type.ToString();
            }

            int first_number = -1;

            for (int i = 0; i < 10; i++)
            {
                if (first_number_code[i] == encoded_type_str)
                {
                    first_number = i;
                    break;
                }
            }
            if (first_number == -1)
            {
                label1.Text = "Error. First number wasn't recognized";
                return(false);
            }

            string fullEAN = first_number.ToString();

            for (int i = 0; i < 12; i++)
            {
                fullEAN += n_type_array[i].number.ToString();
            }

            DigitBox.Text = fullEAN;

            if (get_control_sum(fullEAN) != int.Parse(fullEAN[12].ToString()))
            {
                label1.Text = "Error. Checksum is wrong";
                return(false);
            }
            return(true);
        }
Пример #2
0
        private void Encode(string ean)
        {
            Bitmap Img2 = new Bitmap(530, 200);

            using (Graphics g = Graphics.FromImage(Img2))
            {
                int barwidth = 5;
                int shift    = 7;
                g.Clear(Color.White);
                DrawLine(1 + shift, barwidth, Img2);
                DrawLine(3 + shift, barwidth, Img2);
                DrawLine(47 + shift, barwidth, Img2);
                DrawLine(49 + shift, barwidth, Img2);
                DrawLine(95 + shift, barwidth, Img2);
                DrawLine(93 + shift, barwidth, Img2);
                PatterBox.Text = first_number_code[int.Parse(ean[0].ToString())] + "CCCCCC";
                ean           += get_control_sum(ean).ToString();
                DigitBox.Text  = ean;
                string bin_code = "";
                for (int i = 1; i < 7; i++)
                {
                    bin_code += str_mutate(A_codes[int.Parse(ean[i].ToString())], first_number_code[int.Parse(ean[0].ToString())][i - 1]);
                }
                for (int i = 7; i < 13; i++)
                {
                    bin_code += str_mutate(A_codes[int.Parse(ean[i].ToString())], 'C');
                }
                BinaryBox1.Clear();
                BinaryBox2.Clear();
                for (int i = 0; i < 6; i++)
                {
                    BinaryBox1.Text += bin_code.Substring(i * 7, 7) + " ";
                }
                for (int i = 6; i < 12; i++)
                {
                    BinaryBox2.Text += bin_code.Substring(i * 7, 7) + " ";
                }
                for (int i = 0; i < 42; i++)
                {
                    if (bin_code[i] == '1')
                    {
                        DrawLine(4 + i + shift, barwidth, Img2);
                    }
                }
                for (int i = 42; i < 84; i++)
                {
                    if (bin_code[i] == '1')
                    {
                        DrawLine(9 + i + shift, barwidth, Img2);
                    }
                }

                g.FillRectangle(Brushes.White, (4 + shift) * barwidth, Img2.Height - 40, 42 * barwidth, 40);
                g.FillRectangle(Brushes.White, (51 + shift) * barwidth, Img2.Height - 40, 42 * barwidth, 40);
                g.DrawString(ean.Substring(1, 6), new Font("Courier New", 38, FontStyle.Bold), Brushes.Black, (5 + shift) * barwidth, Img2.Height - 47);
                g.DrawString(ean.Substring(7, 6), new Font("Courier New", 38, FontStyle.Bold), Brushes.Black, (52 + shift) * barwidth, Img2.Height - 47);
                g.DrawString(ean[0].ToString(), new Font("Courier New", 38, FontStyle.Bold), Brushes.Black, (-7 + shift) * barwidth, Img2.Height - 47);
            }
            Img          = Img2;
            PicBox.Image = Img2;
        }