Ejemplo n.º 1
0
        /// <summary>
        /// Tries to produce a numeric key.
        /// </summary>
        /// <param name="id">The raw ID to use (without any check digit).</param>
        /// <returns>The numeric key value (0 if a numeric key cannot be generated).</returns>
        internal uint GetNumericKey(uint id)
        {
            // If a check digit is required, and the raw ID exceeds 200
            // million, it means that the numeric key wouldn't fit in
            // a 32-bit value.
            if (HasCheckDigit && id > 200000000)
            {
                return(0);
            }

            // If the key format is not completely numeric, we can't do it.
            if (!IsNumericKey())
            {
                return(0);
            }

            // If a check digit is not required, the supplied raw ID is
            // the numeric key we want to store.
            if (!HasCheckDigit)
            {
                return(id);
            }

            // Work out the check digit and append it to the raw ID.
            uint checkdig = NativeId.GetCheckDigit(id);

            return(id * 10 + checkdig);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Formats an ID number the way this ID group likes to see it.
        /// </summary>
        /// <param name="id">The raw ID to format (may not actually lie within the
        /// limits of this packet).</param>
        /// <returns>The formatted result.</returns>
        internal string FormatId(uint id)
        {
            // Apply the format assuming no check digit.
            string key = String.Format(KeyFormat, id);

            // If there really is a check digit, work it out and append it.
            if (HasCheckDigit)
            {
                uint cd = NativeId.GetCheckDigit(id);
                key += cd.ToString();
            }

            return(key);
        }