public static void Main()
    {
        HexNumber hex;          // ссылка с типом класса

        hex = new HexNumber(0); // объект класса
        uint number;

        while (true)
        { // цикл для ввода разных значений числа
            do
            {
                Console.Write("Введите целое неотрицательное число:  ");
            }while (!uint.TryParse(Console.ReadLine(), out number));

            hex.Number = number;     // Изменяем объект через свойство
            Console.WriteLine("Свойство Number: " + hex.Number);
            Console.Write("Шестнадцатеричные цифры числа: ");

            foreach (char h in hex.HexView)
            {
                Console.Write("{0} ", h);
            }

            Console.WriteLine("\nШестнадцатеричная запись: " + hex.Record);
            Console.WriteLine("Для выхода нажмите клавишу ESC");

            if (Console.ReadKey(true).Key == ConsoleKey.Escape)
            {
                break;
            }
        }    // while
    }
    public static void Main()
    {
        HexNumber hex;

        hex = new HexNumber(0);
        uint number;

        while (true)
        {
            do
            {
                Console.Write("Введите целое неотрицательное число:  ");
            }while (!uint.TryParse(Console.ReadLine(), out number));

            hex.Number = number;
            Console.WriteLine("Свойство Number: " + hex.Number);
            Console.Write("Шестнадцатеричные цифры числа: ");

            foreach (char h in hex.HexView)
            {
                Console.Write("{0} ", h);
            }

            Console.WriteLine("\nШестнадцатеричная запись: " + hex.Record);
            Console.WriteLine("Для выхода нажмите клавишу ESC");

            if (Console.ReadKey(true).Key == ConsoleKey.Escape)
            {
                break;
            }
        }
    }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // Default values

            string pathTags = @"..\..\DOCUMENTS\tags.txt";
            string pathData = @"..\..\DOCUMENTS\data.csv";

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "--data-file" && (i + 1) < args.Length)
                {
                    pathData = args[i + 1];
                }
                if (args[i] == "--tags-file" && (i + 1) < args.Length)
                {
                    pathTags = args[i + 1];
                }
            }


            string productName = "MilkaOreo";

            string fullProductName = productName;

            var tagLines  = File.ReadLines(pathTags);
            var dataLines = File.ReadLines(pathData);

            if (!(File.Exists(pathData)) || !(File.Exists(pathTags)))
            {
                System.Environment.Exit(1);
            }

            string companyPrefix = "";
            string itemReference = "";
            string serialReference = "";
            int    companyPrefixLength, itemReferenceLength, counterFailed = 0;

            string str, partition, binary;

            HexNumber           hex         = new HexNumber();
            Parser              parser      = new Parser();
            LinkedList <string> productList = new LinkedList <string>();

            productName = parser.normalizeString(productName);

            foreach (var line in dataLines)
            {
                str = parser.normalizeString(line);
                string[] words = str.Split(';');

                if (productName == words[3])
                {
                    companyPrefix = words[0];
                    itemReference = words[2];
                    break;
                }
            }

            foreach (var line in tagLines)
            {
                if (hex.isHex(line) && line.Length == 24)
                {
                    // Half of 96 bits length, because it is bigger then int64

                    int halfOfBinaryLength = 48;
                    binary = parser.parseToBigBinary(line.Substring(0, 12), line.Substring(12, 12), halfOfBinaryLength, halfOfBinaryLength);

                    if (line.Substring(0, 2) != "30")
                    {
                        // It is hexadecimal and it's length is 24 hexadecimal chars, but it does not begin with "30" so it is not SGTIN-96 code

                        // failedProduct.AddLast(binary);
                        counterFailed++;
                    }
                    else
                    {
                        string companyPrefixBinary = "";
                        string itemReferenceBinary = "";
                        int    startFirst          = 14;
                        int    startSecond         = 0;

                        partition = binary.Substring(11, 3);

                        // Get company prefix length based on partition if it does not have code in [0,6] , it is not SGTIN-96
                        companyPrefixLength = parser.getCompanyPrefixLength(partition);

                        if (companyPrefixLength != 0)
                        {
                            itemReferenceLength = 44 - companyPrefixLength;

                            startSecond = startFirst + companyPrefixLength;

                            companyPrefixBinary = parser.parseToBinary(companyPrefix, companyPrefixLength);
                            itemReferenceBinary = parser.parseToBinary(itemReference, itemReferenceLength);

                            if (binary.Substring(startFirst, companyPrefixLength) == companyPrefixBinary && binary.Substring(startSecond, itemReferenceLength) == itemReferenceBinary)
                            {
                                productList.AddLast(binary);
                            }
                        }
                        else
                        {
                            // It is hexadecimal, length 24 hexadecimal chars, begins with "30" but partition code is not in [0,6]

                            //failedProduct.AddLast(line);
                            counterFailed++;
                        }
                    }
                }
                else
                {
                    // failedProduct.AddLast(line);
                    counterFailed++;
                }
            }
            Console.WriteLine("Number of invalid SGTIN-96 EPCs : {0}", counterFailed);
            Console.WriteLine("Number of product {0} : {1}", fullProductName, productList.Count());
            Console.WriteLine("\n---- Serial numbers of all {0} products ----\n", fullProductName);

            foreach (var item in productList)
            {
                serialReference = item.Substring(58, 38);
                Console.WriteLine(serialReference);
            }
            Console.ReadKey();
        }
Esempio n. 4
0
        public NumberHelper()
        {
            InitializeComponent();

            BinaryNumber.GotFocus  += UpdateFocus;
            HexNumber.GotFocus     += UpdateFocus;
            DecimalNumber.GotFocus += UpdateFocus;
            LostFocus += UpdateFocus;

            BinaryNumber.KeyPress += (sender, args) =>
            {
                if (!char.IsControl(args.KeyChar) && !BinaryChars.Contains(args.KeyChar))
                {
                    args.Handled = true;
                }
            };
            BinaryNumber.KeyDown += (sender, args) =>
            {
                if (args.KeyCode == Keys.Up)
                {
                    args.Handled = true;
                    HexNumber.Focus();
                    HexNumber.SelectAll();
                }
            };
            HexNumber.KeyPress += (sender, args) =>
            {
                if (!char.IsControl(args.KeyChar) && !HexChars.Contains(char.ToUpperInvariant(args.KeyChar)))
                {
                    args.Handled = true;
                }
                args.KeyChar = char.ToUpperInvariant(args.KeyChar);
            };
            HexNumber.KeyDown += (sender, args) =>
            {
                if (args.KeyCode == Keys.Up)
                {
                    args.Handled = true;
                    DecimalNumber.Focus();
                    DecimalNumber.SelectAll();
                }
                else if (args.KeyCode == Keys.Down)
                {
                    args.Handled = true;
                    BinaryNumber.Focus();
                    BinaryNumber.SelectAll();
                }
            };
            DecimalNumber.KeyPress += (sender, args) =>
            {
                if (!char.IsControl(args.KeyChar) && !DecimalChars.Contains(args.KeyChar))
                {
                    args.Handled = true;
                }
            };
            DecimalNumber.KeyDown += (sender, args) =>
            {
                if (args.KeyCode == Keys.Down)
                {
                    args.Handled = true;
                    HexNumber.Focus();
                    HexNumber.SelectAll();
                }
            };

            DecimalNumber.TextChanged += (sender, args) =>
            {
                if (Regex.IsMatch(DecimalNumber.Text, @"[^\-0-9]"))
                {
                    DecimalNumber.Text = Regex.Replace(DecimalNumber.Text, @"[^\-0-9]", "");
                }
                if (!Regex.IsMatch(DecimalNumber.Text, @"[0-9]"))
                {
                    return;
                }
                var number = string.IsNullOrEmpty(DecimalNumber.Text) ? 0 : Convert.ToInt64(DecimalNumber.Text);

                SetHex(number);
                SetBinary(number);
            };
            HexNumber.TextChanged += (sender, args) =>
            {
                if (Regex.IsMatch(HexNumber.Text, @"[^0-9A-F]"))
                {
                    HexNumber.Text = Regex.Replace(HexNumber.Text, @"[^0-9A-F]", "");
                }
                var number = string.IsNullOrEmpty(HexNumber.Text) ? 0 : Convert.ToInt64(HexNumber.Text, 16);

                SetDecimal(number);
                SetBinary(number);
            };
            BinaryNumber.TextChanged += (sender, args) =>
            {
                if (Regex.IsMatch(BinaryNumber.Text, @"[^01]"))
                {
                    BinaryNumber.Text = Regex.Replace(BinaryNumber.Text, @"[^01]", "");
                }
                var number = string.IsNullOrEmpty(BinaryNumber.Text) ? 0 : Convert.ToInt64(BinaryNumber.Text, 2);

                SetHex(number);
                SetDecimal(number);
            };
        }