예제 #1
0
        private string GetErrorMessage(Control control)
        {
            // Get the properties for this control.

            ProvidedProperties properties  = (ProvidedProperties)m_providedProperties[control];
            string             displayName = properties.DisplayName.Length == 0 ? control.Name : properties.DisplayName;

            string value = control.Text;

            // Check against required.

            if (value.Length == 0)
            {
                if (properties.Required)
                {
                    return(displayName + " is required.");
                }
                else
                {
                    return(string.Empty);
                }
            }

            // Validate that the text can be converted to the type.

            try
            {
                TypeConvert.ToType(value, properties.PrimitiveType);
            }
            catch (Exception)
            {
                return("The text cannot be converted to the '" + properties.PrimitiveType.ToString() + "' type.");
            }

            // Validate the regular expression.

            if (properties.RegularExpression.Length > 0)
            {
                if (!Regex.IsMatch(value, properties.RegularExpression))
                {
                    return("The text is not of the correct format.");
                }
            }

            // All tests passed.

            return(string.Empty);
        }
예제 #2
0
        private ProvidedProperties GetProperties(Control control)
        {
            if (m_providedProperties.Contains(control))
            {
                return((ProvidedProperties)m_providedProperties[control]);
            }
            else
            {
                ProvidedProperties properties = new ProvidedProperties();
                m_providedProperties.Add(control, properties);

                control.Validating += new CancelEventHandler(ValidatingHandler);
                control.KeyUp      += new KeyEventHandler(CheckOnKeystrokeHandler);

                return(properties);
            }
        }