Exemple #1
0
        public override CodedValueCollection GetCodes(string value)
        {
            var codes = new CodedValueCollection();

            value = value.Replace(" ", "").ToUpper();

            var index = ToBinary(ParsePair(value.Substring(0, 2)), 0, 8, codes);

            index = ToBinary(_Lookup[value.Substring(2, 1)], index, 5, codes);
            index = ToBinary(_Lookup[value.Substring(3, 1)], index, 4, codes);
            ToBinary(ParsePair(value.Substring(4, 2)), index, 8, codes);

            int p = codes.Sum() + 1;

            codes.Add(ALIGNMENTBAR);
            if (p % 2 == 0)
            {
                codes.Insert(0, ALIGNMENTBAR);
            }
            else
            {
                codes.Insert(0, ODDCOUNT);
            }

            return(codes);
        }
Exemple #2
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = base.ParseText(value, codes);

            codes.Insert(0, 33);
            codes.Insert(2, 34);

            return(value);
        }
Exemple #3
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            var parsed = value.Replace(" ", "");

            if (!System.Text.RegularExpressions.Regex.IsMatch(parsed, "^\\d+$"))
            {
                throw new ArgumentException("Only numeric values can have a check digit");
            }

            int total = 0;

            for (int i = 0; i < parsed.Length; i++)
            {
                if (i % 2 == 0)
                {
                    total += int.Parse(parsed.Substring(i, 1));
                }
                else
                {
                    int tmp = int.Parse(parsed.Substring(i, 1)) * 2;
                    total += (tmp % 9);
                }
            }

            total = total % 10;

            codes.Insert(codes.Count - 1, total.ToString()[0]);
            return(value + total.ToString());
        }
Exemple #4
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            var values = PatternSet.Keys;

            int rowTotal = 0, colTotal = 0, tmp;

            for (int i = 1; i < codes.Count - 1; i++)
            {
                int index = values.First(x => x == codes[i]);
                tmp = (index / 6) + 1;
                rowTotal += (tmp == 6 ? 0 : tmp);

                tmp = (index % 6) + 1;
                colTotal += (tmp == 6 ? 0 : tmp);
            }

            rowTotal = rowTotal % 6;
            rowTotal = rowTotal == 0 ? 6 : rowTotal - 1;

            colTotal = colTotal % 6;
            colTotal = colTotal == 0 ? 5 : colTotal - 1;

            codes.Insert(codes.Count - 1, values.First(x => x == (rowTotal * 6) + colTotal));

            return value;
        }
Exemple #5
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            var values = PatternSet.Keys;

            int rowTotal = 0, colTotal = 0, tmp;

            for (int i = 1; i < codes.Count - 1; i++)
            {
                int index = values.First(x => x == codes[i]);
                tmp       = (index / 6) + 1;
                rowTotal += (tmp == 6 ? 0 : tmp);

                tmp       = (index % 6) + 1;
                colTotal += (tmp == 6 ? 0 : tmp);
            }

            rowTotal = rowTotal % 6;
            rowTotal = rowTotal == 0 ? 6 : rowTotal - 1;

            colTotal = colTotal % 6;
            colTotal = colTotal == 0 ? 5 : colTotal - 1;

            codes.Insert(codes.Count - 1, values.First(x => x == (rowTotal * 6) + colTotal));

            return(value);
        }
Exemple #6
0
        protected static string DoChecksumCalculation(string value, int factor, CodedValueCollection codes)
        {
            int tmp    = 0;
            int weight = 0;

            for (int i = 0; i < value.Length; i++)
            {
                weight = ((value.Length - i) % factor);
                if (weight == 0)
                {
                    weight = factor;
                }
                tmp += ((value[i] == '-' ? 10 : int.Parse(value.Substring(i, 1))) * weight);
            }

            tmp    = tmp % 11;
            value += tmp > 9 ? "-" : tmp.ToString();
            if (codes != null)
            {
                if (codes.Last() == LIMIT)
                {
                    codes.Insert(codes.Count - 1, tmp > 9 ? '-' : tmp + '0');
                }
                else
                {
                    codes.Add(tmp > 9 ? '-' : tmp + '0');
                }
            }

            return(value);
        }
Exemple #7
0
        private int ToBinary(int value, int index, int count, CodedValueCollection codes)
        {
            for (int i = 0; i < count; i++)
            {
                codes.Insert(index, value % 2);
                value >>= 1;
            }

            return(index + count);
        }
Exemple #8
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = value.Replace(" ", "").ToUpper();
            if (!IsValidData(value))
            {
                throw new ApplicationException("The data was not valid.");
            }

            int tmp = ParsePair(value.Substring(0, 2));

            codes.Add(tmp / 0x10);
            codes.Add(tmp % 0x10);

            tmp = _Lookup[value.Substring(2, 1)];
            codes.Add(tmp / 0x10);
            codes.Add(tmp % 0x10);

            codes.Add(_Lookup[value.Substring(3, 1)]);

            tmp = ParsePair(value.Substring(4, 2));
            codes.Add(tmp / 0x10);
            codes.Add(tmp % 0x10);

            int p = 1;

            foreach (int item in codes)
            {
                p += PatternSet[item].BlackCount;
            }

            codes.Add(ALIGNMENTBAR);
            if (p % 2 == 0)
            {
                codes.Insert(0, ALIGNMENTBAR);
            }
            else
            {
                codes.Insert(0, ODDCOUNT);
            }

            return(null);
        }
Exemple #9
0
        public override CodedValueCollection GetCodes(string value)
        {
            var codes = new CodedValueCollection();

            value = value.Replace(" ", "").ToUpper();

            var index = ToBinary(ParsePair(value.Substring(0, 2)), 0, 8, codes);
            index = ToBinary(_Lookup[value.Substring(2, 1)], index, 5, codes);
            index = ToBinary(_Lookup[value.Substring(3, 1)], index, 4, codes);
            ToBinary(ParsePair(value.Substring(4, 2)), index, 8, codes);

            int p = codes.Sum() + 1;
            codes.Add(ALIGNMENTBAR);
            if (p % 2 == 0)
                codes.Insert(0, ALIGNMENTBAR);
            else
                codes.Insert(0, ODDCOUNT);

            return codes;
        }
Exemple #10
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = base.ParseText(value, codes);

            for (int i = 0; i < value.Length; i++)
            {
                codes.Add(int.Parse(value.Substring(i, 1)));
            }

            codes.Insert(0, START);
            codes.Add(STOP);

            return value;
        }
Exemple #11
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            int total = 0;
            for (int i = 1; i < codes.Count - 1; i++)
            {
                total += codes[i];
            }

            total = total % 10;

            codes.Insert(codes.Count - 1, total == 0 ? 0 : 10 - total);

            return value;
        }
Exemple #12
0
        public override CodedValueCollection GetCodes(string value)
        {
            var result = new CodedValueCollection();

            for (int i = 0; i < value.Length; i++)
            {
                result.Add(int.Parse(value.Substring(i, 1)));
            }

            result.Insert(0, START);
            result.Add(STOP);

            return result;
        }
Exemple #13
0
        public override CodedValueCollection GetCodes(string value)
        {
            var result = new CodedValueCollection();

            for (int i = 0; i < value.Length; i++)
            {
                result.Add(int.Parse(value.Substring(i, 1)));
            }

            result.Insert(0, START);
            result.Add(STOP);

            return(result);
        }
Exemple #14
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = base.ParseText(value, codes);

            foreach (var item in value.ToCharArray())
            {
                codes.Add(item);
            }

            codes.Insert(0, START);
            codes.Add(STOP);

            return(value);
        }
Exemple #15
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = base.ParseText(value, codes);

            for (int i = 0; i < value.Length; i++)
            {
                codes.Add(int.Parse(value.Substring(i, 1)));
            }

            codes.Insert(0, START);
            codes.Add(STOP);

            return(value);
        }
Exemple #16
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            int total = 0;

            for (int i = 1; i < codes.Count - 1; i++)
            {
                total += codes[i];
            }

            total = total % 10;

            codes.Insert(codes.Count - 1, total == 0 ? 0 : 10 - total);

            return(value);
        }
Exemple #17
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            int  total  = 0;
            bool isEven = true;

            for (int i = codes.Count - 2; i < 0; i--)
            {
                total += isEven ? 3 * codes[i] : codes[i];
            }

            total = total % 10;
            total = total == 0 ? 0 : 10 - total;
            codes.Insert(codes.Count - 1, total);

            return(value + total.ToString());
        }
Exemple #18
0
        public override CodedValueCollection GetCodes(string value)
        {
            var codes = new CodedValueCollection();

            value = value.Replace(" ", "").Replace("-", "");

            for (int i = 0; i < value.Length; i++)
            {
                codes.Add(int.Parse(value.Substring(i, 1)));
            }

            codes.Insert(0, STARTSTOP);
            codes.Add(STARTSTOP);

            return(codes);
        }
Exemple #19
0
        public override CodedValueCollection GetCodes(string value)
        {
            var codes = new CodedValueCollection();

            value = value.Replace(" ", "").Replace("-", "");

            for (int i = 0; i < value.Length; i++)
            {
                codes.Add(int.Parse(value.Substring(i, 1)));
            }

            codes.Insert(0, STARTSTOP);
            codes.Add(STARTSTOP);

            return codes;
        }
Exemple #20
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            int total = 0;
            bool isEven = true;

            for (int i = codes.Count - 2; i < 0; i--)
            {
                total += isEven ? 3 * codes[i] : codes[i];
            }

            total = total % 10;
            total = total == 0 ? 0 : 10 - total;
            codes.Insert(codes.Count - 1, total);

            return value + total.ToString();
        }
Exemple #21
0
        private void AddCheckDigit(int weight, CodedValueCollection codes)
        {
            int total = 0;
            int w     = 1;

            for (int i = codes.Count - 3; i > 0; i--)
            {
                total += (w * codes[i]);
                w++;
                if (w > weight)
                {
                    w = 1;
                }
            }

            total = total % 47;
            codes.Insert(codes.Count - 2, total);
        }
Exemple #22
0
        protected static string DoChecksumCalculation(string value, int factor, CodedValueCollection codes)
        {
            int tmp = 0;
            int weight = 0;
            for (int i = 0; i < value.Length; i++)
            {
                weight = ((value.Length - i) % factor);
                if (weight == 0)
                    weight = factor;
                tmp += ((value[i] == '-' ? 10 : int.Parse(value.Substring(i, 1))) * weight);
            }

            tmp = tmp % 11;
            value += tmp > 9 ? "-" : tmp.ToString();
            if (codes != null)
            {
                if (codes.Last() == LIMIT)
                    codes.Insert(codes.Count - 1, tmp > 9 ? '-' : tmp + '0');
                else
                    codes.Add(tmp > 9 ? '-' : tmp + '0');
            }

            return value;
        }
Exemple #23
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            var parsed = value.Replace(" ", "");
            if (!System.Text.RegularExpressions.Regex.IsMatch(parsed, "^\\d+$"))
                throw new ArgumentException("Only numeric values can have a check digit");

            int total = 0;

            for (int i = 0; i < parsed.Length; i++)
            {
                if (i % 2 == 0)
                    total += int.Parse(parsed.Substring(i, 1));
                else
                {
                    int tmp = int.Parse(parsed.Substring(i, 1)) * 2;
                    total += (tmp % 9);
                }
            }

            total = total % 10;

            codes.Insert(codes.Count - 1, total.ToString()[0]);
            return value + total.ToString();
        }
Exemple #24
0
        private void AddCheckDigit(int weight, CodedValueCollection codes)
        {
            int total = 0;
            int w = 1;
            for (int i = codes.Count - 3; i > 0; i--)
            {
                total += (w * codes[i]);
                w++;
                if (w > weight)
                    w = 1;
            }

            total = total % 47;
            codes.Insert(codes.Count - 2, total);
        }
Exemple #25
0
        public override CodedValueCollection GetCodes(string value)
        {
            var codes = new CodedValueCollection();

            foreach (char item in value.ToCharArray())
            {
                if (item == ' ')
                {
                    codes.Add(38);
                }
                else if (item == '$')
                {
                    codes.Add(39);
                }
                else if (item == '/')
                {
                    codes.Add(40);
                }
                else if (item == '+')
                {
                    codes.Add(41);
                }
                else if (item == '%')
                {
                    codes.Add(42);
                }

                else if (item >= '0' && item <= '9')
                {
                    codes.Add(item - 48);
                }
                else
                {
                    var tmp = AsciiEncoder.Lookup(item);

                    switch (tmp[0])
                    {
                    case '$':
                        codes.Add(SHIFT1);
                        codes.Add(tmp[1] - 55);
                        break;

                    case '%':
                        codes.Add(SHIFT2);
                        codes.Add(tmp[1] - 55);
                        break;

                    case '/':
                        codes.Add(SHIFT3);
                        codes.Add(tmp[1] - 55);
                        break;

                    case '+':
                        codes.Add(SHIFT4);
                        codes.Add(tmp[1] - 55);
                        break;

                    default:
                        codes.Add(tmp[0] - 55);
                        break;
                    }
                }
            }

            codes.Insert(0, LIMIT);
            codes.Add(LIMIT);
            codes.Add(TERMINATOR);

            return(codes);
        }
Exemple #26
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = value.Replace(" ", "").ToUpper();
            if (!IsValidData(value))
                throw new ApplicationException("The data was not valid.");

            int tmp = ParsePair(value.Substring(0, 2));
            codes.Add(tmp / 0x10);
            codes.Add(tmp % 0x10);

            tmp = _Lookup[value.Substring(2, 1)];
            codes.Add(tmp / 0x10);
            codes.Add(tmp % 0x10);

            codes.Add(_Lookup[value.Substring(3, 1)]);

            tmp = ParsePair(value.Substring(4, 2));
            codes.Add(tmp / 0x10);
            codes.Add(tmp % 0x10);

            int p = 1;
            foreach (int item in codes)
            {
                p += PatternSet[item].BlackCount;
            }

            codes.Add(ALIGNMENTBAR);
            if (p % 2 == 0)
                codes.Insert(0, ALIGNMENTBAR);
            else
                codes.Insert(0, ODDCOUNT);

            return null;
        }
Exemple #27
0
 protected override void CalculateParity(CodedValueCollection codes)
 {
     codes.Insert(0, 0);
     base.CalculateParity(codes);
 }
Exemple #28
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = base.ParseText(value, codes);

            foreach (var item in value.ToCharArray())
            {
                codes.Add(item);
            }

            codes.Insert(0, START);
            codes.Add(STOP);

            return value;
        }
Exemple #29
0
 protected override void CalculateParity(CodedValueCollection codes)
 {
     codes.Insert(0, 0);
     base.CalculateParity(codes);
 }
Exemple #30
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = base.ParseText(value, codes);

            codes.Insert(4, 34);
            codes.Insert(3, 34);
            codes.Insert(2, 34);
            codes.Insert(1, 34);
            codes.Insert(0, 33);

            return value;
        }
Exemple #31
0
        private int ToBinary(int value, int index, int count, CodedValueCollection codes)
        {
            for (int i = 0; i < count; i++)
            {
                codes.Insert(index, value % 2);
                value >>= 1;
            }

            return index + count;
        }
Exemple #32
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = base.ParseText(value, codes);

            string tmp = null;

            foreach (char item in value.ToCharArray())
            {
                if (item == ' ')
                {
                    codes.Add(38);
                }
                else if (item == '$')
                {
                    codes.Add(39);
                }
                else if (item == '/')
                {
                    codes.Add(40);
                }
                else if (item == '+')
                {
                    codes.Add(41);
                }
                else if (item == '%')
                {
                    codes.Add(42);
                }

                else if (item >= '0' && item <= '9')
                {
                    codes.Add(item - 48);
                }
                else
                {
                    tmp = AsciiEncoder.Lookup(item);

                    switch (tmp[0])
                    {
                    case '$':
                        codes.Add(SHIFT1);
                        codes.Add(tmp[1] - 55);
                        break;

                    case '%':
                        codes.Add(SHIFT2);
                        codes.Add(tmp[1] - 55);
                        break;

                    case '/':
                        codes.Add(SHIFT3);
                        codes.Add(tmp[1] - 55);
                        break;

                    case '+':
                        codes.Add(SHIFT4);
                        codes.Add(tmp[1] - 55);
                        break;

                    default:
                        codes.Add(tmp[0]);
                        break;
                    }
                }
            }

            codes.Insert(0, LIMIT);
            codes.Add(LIMIT);
            codes.Add(TERMINATOR);

            return(value);
        }
Exemple #33
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = base.ParseText(value, codes);

            string tmp = null;
            foreach (char item in value.ToCharArray())
            {
                if (item == ' ')
                    codes.Add(38);
                else if (item == '$')
                    codes.Add(39);
                else if (item == '/')
                    codes.Add(40);
                else if (item == '+')
                    codes.Add(41);
                else if (item == '%')
                    codes.Add(42);

                else if (item >= '0' && item <= '9')
                    codes.Add(item - 48);
                else
                {
                    tmp = AsciiEncoder.Lookup(item);

                    switch (tmp[0])
                    {
                        case '$':
                            codes.Add(SHIFT1);
                            codes.Add(tmp[1] - 55);
                            break;
                        case '%':
                            codes.Add(SHIFT2);
                            codes.Add(tmp[1] - 55);
                            break;
                        case '/':
                            codes.Add(SHIFT3);
                            codes.Add(tmp[1] - 55);
                            break;
                        case '+':
                            codes.Add(SHIFT4);
                            codes.Add(tmp[1] - 55);
                            break;
                        default:
                            codes.Add(tmp[0]);
                            break;
                    }
                }

            }

            codes.Insert(0, LIMIT);
            codes.Add(LIMIT);
            codes.Add(TERMINATOR);

            return value;
        }
Exemple #34
0
        public override CodedValueCollection GetCodes(string value)
        {
            var codes = new CodedValueCollection();
            foreach (char item in value.ToCharArray())
            {
                if (item == ' ')
                    codes.Add(38);
                else if (item == '$')
                    codes.Add(39);
                else if (item == '/')
                    codes.Add(40);
                else if (item == '+')
                    codes.Add(41);
                else if (item == '%')
                    codes.Add(42);

                else if (item >= '0' && item <= '9')
                    codes.Add(item - 48);
                else
                {
                    var tmp = AsciiEncoder.Lookup(item);

                    switch (tmp[0])
                    {
                        case '$':
                            codes.Add(SHIFT1);
                            codes.Add(tmp[1] - 55);
                            break;
                        case '%':
                            codes.Add(SHIFT2);
                            codes.Add(tmp[1] - 55);
                            break;
                        case '/':
                            codes.Add(SHIFT3);
                            codes.Add(tmp[1] - 55);
                            break;
                        case '+':
                            codes.Add(SHIFT4);
                            codes.Add(tmp[1] - 55);
                            break;
                        default:
                            codes.Add(tmp[0] - 55);
                            break;
                    }
                }

            }

            codes.Insert(0, LIMIT);
            codes.Add(LIMIT);
            codes.Add(TERMINATOR);

            return codes;
        }