Exemple #1
0
        /// <summary>
        /// Calculate parity for given list of codes
        /// </summary>
        /// <param name="codes">list of values</param>
        protected virtual void CalculateParity(CodedValueCollection codes)
        {
            if (Parity == null)
            {
                CreateParity();
            }

            bool[] parity = Parity[codes[0]];

            for (int i = 1; i < codes.Count; i++)
            {
                if (i < 1 + DigitGrouping[1])
                {
                    if (parity[i - 1])
                    {
                        codes[i] += 10;
                    }
                }
                else
                {
                    codes[i] += 20;
                }
            }
            codes.RemoveAt(0);
        }
Exemple #2
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            //10 narrow space queit zone + 2 narrow bars for the STOP
            width += (codes.Count * 11 * settings.NarrowWidth) + (2 * 10 * settings.NarrowWidth) + (2 * settings.NarrowWidth);

            return(base.OnCalculateWidth(width, settings, codes));
        }
Exemple #3
0
 protected override void CalculateParity(CodedValueCollection codes)
 {
     for (int i = 4; i < codes.Count; i++)
     {
         codes[i] += 20;
     }
 }
Exemple #4
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 #5
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 #6
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 #7
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 #8
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 #9
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            if (codes.Count == 13)
            {
                return(value);
            }

            int total = 0;

            for (int i = 0; i < codes.Count; i++)
            {
                if (i % 2 == 0)
                {
                    total += (codes[i] % 10);
                }
                else
                {
                    total += 3 * (codes[i] % 10);
                }
            }

            total = total % 10;
            codes.Add(total == 0 ? 20 : 30 - total);

            return(value + (total == 0 ? 0 : 10 - total).ToString());
        }
Exemple #10
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 #11
0
 protected override void CalculateParity(CodedValueCollection codes)
 {
     for (int i = 4; i < codes.Count; i++)
     {
         codes[i] += 20;
     }
 }
Exemple #12
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            AddCheckDigit(20, codes);
            AddCheckDigit(15, codes);

            return(value);
        }
Exemple #13
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            AddCheckDigit(20, codes);
            AddCheckDigit(15, codes);

            return value;
        }
Exemple #14
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            foreach (int item in codes)
            {
                width += (PatternSet[item].NarrowCount * settings.NarrowWidth) + (PatternSet[item].WideCount * settings.WideWidth);
            }

            return(base.OnCalculateWidth(width, settings, codes));
        }
Exemple #15
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            if (value.Length > 7)
            {
                value = FromUpcA(value);
            }

            return(base.ParseText(value, codes).Substring(1, 6));
        }
Exemple #16
0
 public virtual CodedValueCollection GetCodes(string value)
 {
     var result = new CodedValueCollection();
     foreach (var item in value)
     {
         result.Add(item);
     }
     return result;
 }
Exemple #17
0
        /// <summary>
        /// Parses the text into encodable characters
        /// </summary>
        /// <param name="value">the text to encode</param>
        /// <param name="codes">the code set to sue for encoding</param>
        /// <returns>the text after any clean-up</returns>
        protected virtual string ParseText(string value, CodedValueCollection codes)
        {
            if (!IsValidData(value))
            {
                throw new ApplicationException();
            }

            return(value);
        }
Exemple #18
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 #19
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            foreach (int item in codes)
            {
                width += (PatternSet[item].WideCount * settings.WideWidth) + (PatternSet[item].NarrowCount * settings.NarrowWidth);
            }

            return base.OnCalculateWidth(width, settings, codes);
        }
Exemple #20
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 #21
0
        public virtual CodedValueCollection GetCodes(string value)
        {
            var result = new CodedValueCollection();

            foreach (var item in value)
            {
                result.Add(item);
            }
            return(result);
        }
Exemple #22
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 #23
0
        /// <summary>
        /// If the barcode supports a check digit, add it to the string
        /// </summary>
        /// <param name="value">barcode value to use for calculation</param>
        /// <returns>check digit to return</returns>
        public virtual string AddCheckDigit(string value)
        {
            CodedValueCollection codes = new CodedValueCollection();

            value = ParseText(value, codes);
            AddChecksumEventArgs e = new AddChecksumEventArgs(value, codes);

            OnAddChecksum(e);

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

            if (_Value != null)
            {
                value  = _Value.ToDisplayString();
                _Value = null;
            }

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

            if (_Value != null)
            {
                value = _Value.ToDisplayString();
                _Value = null;
            }

            return value;
        }
Exemple #26
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            StringBuilder v = new StringBuilder();
            foreach (char item in value.ToCharArray())
            {
                v.Append(AsciiEncoder.Lookup(item));
            }

            base.ParseText(v.ToString(), codes);

            return value;
        }
Exemple #27
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            StringBuilder v = new StringBuilder();

            foreach (char item in value.ToCharArray())
            {
                v.Append(AsciiEncoder.Lookup(item));
            }

            base.ParseText(v.ToString(), codes);

            return(value);
        }
Exemple #28
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            codes.RemoveAt(codes.Count - 1);

            value = DoChecksumCalculation(value, 10, codes);

            if (value.Length >= 10)
                value = DoChecksumCalculation(value, 9,codes);

            codes.Add(LIMIT);

            return value;
        }
Exemple #29
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)));
            }

            CalculateParity(codes);

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

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

            CalculateParity(codes);

            return(codes);
        }
Exemple #31
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 #32
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 #33
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = value.ToLower();
            string tmp = value.Replace(" ", "");

            tmp = base.ParseText(tmp, codes);

            foreach (char item in tmp.ToCharArray())
            {
                codes.Add(item);
            }

            return(value.Substring(1, value.Length - 2));
        }
Exemple #34
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 #35
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 #36
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 #37
0
        public override CodedValueCollection GetCodes(string value)
        {
            var codes = new CodedValueCollection();

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

            codes.Add(ENDMARKER);

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

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

            codes.Add(ENDMARKER);

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

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

            }

            CalculateParity(codes);

            return codes;
        }
Exemple #40
0
        protected override void CalculateParity(CodedValueCollection codes)
        {
            int total = (codes[0] + codes[2] + codes[4]) * 3;
            total += (codes[1] + codes[3]) * 9;
            total = (total % 10);

            bool[] parity = Parity[total];

            for (int i = 0; i < codes.Count; i++)
            {
                if (parity[i])
                    codes[i] += 10;
            }
        }
Exemple #41
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 #42
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 #43
0
        protected override void CalculateParity(CodedValueCollection codes)
        {
            int m = ((codes[0] * 10) + codes[1]) % 4;

            if (m > 1)
            {
                codes[0] += 10;
            }

            if (m == 1 || m == 3)
            {
                codes[1] += 10;
            }
        }
Exemple #44
0
        public override string AddChecksum(string value, CodedValueCollection codes)
        {
            codes.RemoveAt(codes.Count - 1);

            value = DoChecksumCalculation(value, 10, codes);

            if (value.Length >= 10)
            {
                value = DoChecksumCalculation(value, 9, codes);
            }

            codes.Add(LIMIT);

            return(value);
        }
Exemple #45
0
        public object Render(CodedValueCollection codes, string displayText)
        {
            Codes = codes;
            DisplayText = displayText;

            var size = GetDimensions();
            var b = new Bitmap(size.Width, size.Height);
            Canvas = Graphics.FromImage(b);

            var start = new Point(Settings.LeftMargin, Settings.TopMargin);

            Paint(start);

            return b;
        }
Exemple #46
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = value.Trim('*');
            if (!IsValidData(value))
                throw new ApplicationException("Invalid data for this barcode.");

            value = "*" + value.ToUpper() + "*";

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

            return value;
        }
Exemple #47
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 #48
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 #49
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 #50
0
        public object Render(CodedValueCollection codes, string displayText)
        {
            Codes       = codes;
            DisplayText = displayText;

            var size = GetDimensions();
            var b    = new Bitmap(size.Width, size.Height);

            Canvas = Graphics.FromImage(b);

            var start = new Point(Settings.LeftMargin, Settings.TopMargin);

            Paint(start);

            return(b);
        }
Exemple #51
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            if (!IsValidData(value))
                throw new ApplicationException();

            codes.Add(STARTMARKER);

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

            codes.Add(ENDMARKER);

            return value;
        }
Exemple #52
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 #53
0
        public int CheckDigitCalculate(CodedValueCollection codes)
        {
            int total = 0;
            bool flip = true;
            for (int i = codes.Count-1; i > 0; i--)
            {
                if (flip)
                    total += codes[i] * 3;
                else
                    total += codes[i];

                flip = !flip;
            }

            total = total % 10;
            return total == 0 ? 0 : 10 - total;
        }
Exemple #54
0
		public override string AddChecksum(string value, CodedValueCollection codes)
		{
			if (codes.Count == 13)
				return value;

			int total = 0;
			for (int i = 0; i < codes.Count; i++)
			{
				if (i % 2 == 0)
					total += (codes[i] % 10);
				else
					total += 3 * (codes[i] % 10);
			}

			total = total % 10;
			codes.Add(total == 0 ? 20 : 30 - total);
			
			return value + (total == 0 ? 0 : 10 - total).ToString();
		}
Exemple #55
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 #56
0
        protected override string ParseText(string value, CodedValueCollection codes)
        {
            value = base.ParseText(value, codes);
            value = Regex.Replace(value, "[-\\s]", "");

            byte[] data1 = IntelligentMailHelper.Instance.ConvertToBytes(IntelligentMailHelper.Instance.ConvertRoutingCode(value.Substring(20)), value.Substring(0,20));
            int fcs = IntelligentMailHelper.Instance.CRC11(data1);

            short[] data2 = IntelligentMailHelper.Instance.ConvertToCodewords(data1);

            if (IntelligentMailHelper.Instance.CheckFcs(fcs))
                data2[0] += 659;

            IntelligentMailHelper.Instance.ConvertToCharacters(data2);

            IntelligentMailHelper.Instance.IncludeFcs(data2, fcs);

            codes.AddRange(IntelligentMailHelper.Instance.ConvertToBars(data2));

            return null;
        }
Exemple #57
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 #58
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 #59
0
		protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
		{
			width += (settings.NarrowWidth * ((codes.Count * 7) + 11)) + (DigitGrouping[0] * 7 * settings.NarrowWidth);

			return base.OnCalculateWidth(width, settings, codes);
		}
Exemple #60
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)));

			}

			CalculateParity(codes);

			return value;
		}