示例#1
0
        /// <summary>
        /// Parses/sets the NHS Number.
        /// </summary>
        /// <param name="nhsNumber">String to assign to the NHS Number.</param>
        private void SetNhsNumber(string nhsNumber)
        {
            // Parse the text passed in to see if meets the formatting criteria
            // If it is store the value and format it for display
            string parsedValue;

            NhsNumber.NhsNumberParseResult result = NhsNumber.TryParseNhsNumber(nhsNumber, out parsedValue);
            if (result == NhsNumber.NhsNumberParseResult.Success)
            {
                this.nhsNumber = parsedValue.Substring(0, 3) + " " + parsedValue.Substring(3, 3) + " " + parsedValue.Substring(6, 4);
            }
            else
            {
                if (result == NhsNumber.NhsNumberParseResult.FailedAlphaCharacterContent)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageAlphaChars, nhsNumber));
                }
                else if (result == NhsNumber.NhsNumberParseResult.FailedChecksum)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageChecksum, nhsNumber));
                }
                else if (result == NhsNumber.NhsNumberParseResult.FailedDigitCount)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageDigitCount, nhsNumber));
                }
                else if (result == NhsNumber.NhsNumberParseResult.FailedAllSameDigits)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageDigitsAllSame, nhsNumber));
                }
                else
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageUnknownError, nhsNumber));
                }
            }
        }
示例#2
0
        /// <summary>
        /// Converts the specified string representation of an NHS identifier to its correctly-formatted equivalent.
        /// </summary>
        /// <remarks>
        /// Throws an exception if the string cannot be parsed.
        /// </remarks>
        /// <param name="value">A string containing an NHS identifier to be parsed. </param>
        /// <returns>An NHS identifier constructed from the value parameter. </returns>
        public static NhsNumber ParseNhsNumber(string value)
        {
            string parsedValue;

            NhsNumber.NhsNumberParseResult result = NhsNumber.TryParseNhsNumber(value, out parsedValue);
            if (result == NhsNumber.NhsNumberParseResult.Success)
            {
                return(new NhsNumber(parsedValue));
            }
            else
            {
                if (result == NhsNumber.NhsNumberParseResult.FailedAlphaCharacterContent)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageAlphaChars, value));
                }
                else if (result == NhsNumber.NhsNumberParseResult.FailedChecksum)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageChecksum, value));
                }
                else if (result == NhsNumber.NhsNumberParseResult.FailedDigitCount)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageDigitCount, value));
                }
                else if (result == NhsNumber.NhsNumberParseResult.FailedAllSameDigits)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageDigitsAllSame, value));
                }
                else
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageUnknownError, value));
                }
            }
        }
示例#3
0
        public void ValueTest()
        {
            IdentifierLabel target = new IdentifierLabel();

            NhsNumber val = new NhsNumber("4372623623");

            target.Value = val;

            Assert.AreEqual<NhsNumber>(val, target.Value, "NhsCui.Toolkit.WinForms.IdentifierLabel.Value was not set correctly.");
        }