Example #1
0
        /// <summary>
        /// Gera codigo de barras randomico.
        /// </summary>
        /// <returns></returns>
        public static string GetRandomBarcode(this TypeBarCode t)
        {
            switch (t)
            {
            case TypeBarCode.EAN_8:
            case TypeBarCode.EAN_13:
            case TypeBarCode.UPC_A:
                int    length   = t.GetLength();
                char[] chars    = t.GetValidChars();
                int    minValue = 0;
                int    maxValue = chars.Length - 1;
                char[] result   = new char[length];
                Random r        = new Random();

                for (int i = 0; i < length; i++)
                {
                    int index = r.Next(minValue, maxValue);
                    result[i] = chars[index];
                }

                return(new string(result));

            default:
                throw new InvalidOperationException($"Tipo de codigo de barras {t} não pode gerar codigo de barras randomico!");
            }
        }
Example #2
0
        /// <summary>
        /// Obtem lista de caracteres validos para o codigo de barras.
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static char[] GetValidChars(this TypeBarCode t)
        {
            switch (t)
            {
            case TypeBarCode.EAN_8:
            case TypeBarCode.EAN_13:
            case TypeBarCode.UPC_A:
            case TypeBarCode.CODE_11:
                return(new List <char>()
                       .AddRange('0', '9')
                       .ToArray());

            case TypeBarCode.CODE_39:
            case TypeBarCode.CODE_93:
                return(new List <char>()
                       .AddRange('0', '9')
                       .AddRange('A', 'Z')
                       .AddRange('-', '.', '%', '/', '$', ' ', '+')
                       .ToArray());

            case TypeBarCode.CODABAR:
                return(new List <char>()
                       .AddRange('0', '9')
                       .AddRange('$', '-', ':', '/', '.', '+')
                       .ToArray());

            case TypeBarCode.CODE_128:
                return(new List <char>()
                       .AddRange(char.MinValue, char.MaxValue)
                       .ToArray());

            default:
                throw new InvalidOperationException($"Não foi possivel obter tipo de caracteres para o codigo de barras {t}");
            }
        }
Example #3
0
        public static byte GetByteToFujitsu(this TypeBarCode t)
        {
            switch (t)
            {
            case TypeBarCode.UPC_A:
                return(65);

            case TypeBarCode.EAN_13:
                return(67);

            case TypeBarCode.EAN_8:
                return(68);

            case TypeBarCode.CODE_39:
                return(69);

            case TypeBarCode.INTERLEAVED_2_OF_5:
                return(70);

            case TypeBarCode.CODABAR:
                return(71);

            case TypeBarCode.CODE_128:
                return(73);

            default:
                throw new ArgumentException("Tipo nao suportado!");
            }
        }
Example #4
0
        public static int GetCodeToPRT(this TypeBarCode t)
        {
            switch (t)
            {
            case TypeBarCode.UPC_A:
                return(0);

            case TypeBarCode.EAN_8:
                return(2);

            case TypeBarCode.EAN_13:
                return(3);

            case TypeBarCode.CODE_39:
                return(4);

            case TypeBarCode.INTERLEAVED_2_OF_5:
                return(5);

            case TypeBarCode.CODABAR:
                return(6);

            case TypeBarCode.CODE_93:
                return(7);

            case TypeBarCode.CODE_128:
                return(8);

            default:
                throw new ArgumentException("Tipo nao suportado!");
            }
        }
Example #5
0
        /// <summary>
        /// Quantidade de digitos para gerar o codigo de barras.
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static int GetLength(this TypeBarCode t)
        {
            switch (t)
            {
            case TypeBarCode.EAN_8:
                return(7);

            case TypeBarCode.EAN_13:
                return(12);

            case TypeBarCode.UPC_A:
                return(11);

            case TypeBarCode.CODE_11:
                return(16);

            case TypeBarCode.CODE_128:
                return(22);

            default:
                throw new InvalidOperationException($"Codigo de barras {t} não possui tamanho fixo.");
            }
        }