Пример #1
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);
        }
Пример #2
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;
        }