public string GetErrorText(KeypadParseResult result)
        {
            var cause = result.NumberErrorCause;

            if (cause == NumberErrorCause.Invalid)
            {
                return("숫자가 아님");
            }
            else if (cause == NumberErrorCause.DpsOver)
            {
                return("소숫점 제한 초과함");
            }
            else if (cause == NumberErrorCause.MinOver)
            {
                return("하한 값 넘음");
            }
            else if (cause == NumberErrorCause.MaxOver)
            {
                return("상한 값 넘음");
            }
            else if (result.CustomError != null)
            {
                return(result.CustomError.ErrorMessage);
            }
            else if (cause == NumberErrorCause.None)
            {
                return(string.Empty);
            }

            return("알 수 없는 에러");
        }
        public string GetErrorText(KeypadParseResult result)
        {
            var cause = result.IPAddressCause;

            if (cause == IPAddressErrorCause.DecimalCountInvalid)
            {
                return("값 인식 불가");
            }
            else if (cause == IPAddressErrorCause.AnyDecimalInvalid)
            {
                return("값 인식 불가");
            }
            else if (cause == IPAddressErrorCause.ParseError)
            {
                return("값 인식 불가");
            }
            else if (result.CustomError != null)
            {
                return(result.CustomError.ErrorMessage);
            }
            else if (cause == IPAddressErrorCause.None)
            {
                return(string.Empty);
            }

            return("알 수 없는 에러");
        }
        public KeypadTextBox()
        {
            this.Settings   = new KeypadSettings();
            this.LastKeypad = null;

            this.LastParseResult = new KeypadParseResult();
        }
        private KeypadParseResult Parse()
        {
            var text   = string.Join(".", this.TextBoxs.Select(t => t.Text));
            var result = this.Settings.Validate(text);

            this.Result            = result;
            this.FirstErrorTextBox = this.GetFirstErrorTextBox();
            return(result);
        }
Exemplo n.º 5
0
        public KeypadParseResult Validate(string text)
        {
            var result = new KeypadParseResult();
            var type   = this.Type;

            if (type == KeypadType.Number)
            {
                var cause = NumberRange.TryParse(text, this.ToNumberRange(), out var value);
                result.NumberErrorCause = cause;
                result.Number           = value;
                result.Validated        = cause == NumberErrorCause.None;
            }
            else if (type == KeypadType.IPAddress)
            {
                IPAddress value  = null;
                var       cause  = IPAddressErrorCause.None;
                var       splits = text.Split('.');

                if (splits.Length == 4)
                {
                    var anyDecimalValidated = splits.All(t => { return(byte.TryParse(t, out var b)); });

                    if (anyDecimalValidated == true)
                    {
                        if (IPAddress.TryParse(text, out value) == false)
                        {
                            cause = IPAddressErrorCause.ParseError;
                        }
                    }
                    else
                    {
                        cause = IPAddressErrorCause.AnyDecimalInvalid;
                    }
                }
                else
                {
                    cause = IPAddressErrorCause.DecimalCountInvalid;
                }

                result.Validated      = cause == IPAddressErrorCause.None;
                result.IPAddressCause = cause;
                result.IPAddress      = value;
            }
            else if (type == KeypadType.String)
            {
                result.Validated = true;
                result.String    = text;
            }

            var e = new KeypadValidateEventArgs(this, result, text);

            this.OnValidate(e);
            return(result);
        }
Exemplo n.º 6
0
        public KeypadParseResult(KeypadParseResult other)
        {
            this.Type        = other.Type;
            this.Validated   = other.Validated;
            this.CustomError = other.CustomError;

            this.NumberErrorCause = other.NumberErrorCause;
            this.Number           = other.Number;
            this.IPAddressCause   = other.IPAddressCause;
            this.IPAddress        = other.IPAddress;
            this.String           = other.String;
        }
        public KeypadParseResult Validate()
        {
            var result = this.Settings.Validate(this.Text);

            this.LastParseResult = result;

            var color = result.Validated == true ? Color.Black : Color.Red;

            this.ForeColor = color;

            return(result);
        }
 private void UpdateResult()
 {
     this.Result = this.Settings.Validate(this.TextBox.Text);
 }
Exemplo n.º 9
0
 public KeypadValidateEventArgs(KeypadSettings settings, KeypadParseResult processing, string text)
 {
     this.Settings   = settings;
     this.Processing = processing;
     this.Text       = text;
 }