private ActionResult ComplainsOnlyNumbers(ItemField field)
        {
            ActionResult res = ActionResult.SuccessNoAction;

            if (field == null)
            {
                return(res);
            }

            string value = this.item[field.Name] as string;

            if (!string.IsNullOrEmpty(value))
            {
                Regex regex = new Regex(@"^[0-9]+$");
                if (regex.IsMatch(value))
                {
                    res.SetSuccess();
                }
                else
                {
                    res.SetFail(string.Format(
                                    CultureInfo.InvariantCulture,
                                    @"El valor de {0} debe contener sólo números.",
                                    field.Label));
                }
            }

            return(res);
        }
        private ActionResult ComplainsMaximumValue(ItemField field)
        {
            ActionResult res = ActionResult.SuccessNoAction;

            if (this.item.ContainsKey(field.Name))
            {
                switch (field.DataType)
                {
                case FieldDataType.NullableInteger:
                    int valueInteger = Convert.ToInt32(this.item[field.Name], CultureInfo.InvariantCulture);
                    res.Success = valueInteger <= Convert.ToInt32(this.rule.Value[0], CultureInfo.InvariantCulture);
                    break;

                case FieldDataType.Integer:
                    res.Success = Convert.ToInt32(this.item[field.Name], CultureInfo.InvariantCulture) <= Convert.ToInt32(this.rule.Value[0], CultureInfo.InvariantCulture);
                    break;

                case FieldDataType.NullableDecimal:
                    decimal valueDecimal = Convert.ToDecimal(this.item[field.Name], CultureInfo.InvariantCulture);
                    res.Success = valueDecimal <= Convert.ToDecimal(this.rule.Value[0], CultureInfo.InvariantCulture);
                    break;

                case FieldDataType.Decimal:
                    res.Success = Convert.ToDecimal(this.item[field.Name], CultureInfo.InvariantCulture) <= Convert.ToDecimal(this.rule.Value[0], CultureInfo.InvariantCulture);
                    break;

                case FieldDataType.NullableLong:
                    long valueLong = Convert.ToInt64(this.item[field.Name], CultureInfo.InvariantCulture);
                    res.Success = valueLong <= Convert.ToInt64(this.rule.Value[0], CultureInfo.InvariantCulture);
                    break;

                case FieldDataType.Long:
                    res.Success = Convert.ToInt64(this.item[field.Name], CultureInfo.InvariantCulture) <= Convert.ToInt64(this.rule.Value[0], CultureInfo.InvariantCulture);
                    break;

                case FieldDataType.NullableFloat:
                    float valueFloat = Convert.ToSingle(this.item[field.Name], CultureInfo.InvariantCulture);
                    res.Success = valueFloat <= Convert.ToSingle(this.rule.Value[0], CultureInfo.InvariantCulture);
                    break;

                case FieldDataType.Float:
                    res.Success = Convert.ToSingle(this.item[field.Name], CultureInfo.InvariantCulture) <= Convert.ToSingle(this.rule.Value[0], CultureInfo.InvariantCulture);
                    break;

                default:
                    res.Success      = false;
                    res.MessageError = string.Format(CultureInfo.InvariantCulture, "El tipo de dato de {0} no es correcto", field.Label);
                    break;
                }

                if (!res.Success && string.IsNullOrEmpty(res.MessageError))
                {
                    res.SetFail(string.Format(CultureInfo.InvariantCulture, @"El valor de {0} es mayor que {1}.", field.Label, this.rule.Value[0]));
                }
            }

            return(res);
        }
        private ActionResult MaxLength(ItemField field)
        {
            ActionResult res = ActionResult.SuccessNoAction;

            if (field == null)
            {
                res.SetSuccess();
                return(res);
            }

            if (this.item[field.Name] == null)
            {
                res.SetSuccess();
                return(res);
            }

            string value = this.item[field.Name] as string;

            value = value.Trim();

            if (string.IsNullOrEmpty(value))
            {
                res.SetSuccess();
            }
            else
            {
                if (value.Length > (long)this.rule.Value[0])
                {
                    res.SetFail(string.Format(
                                    CultureInfo.InvariantCulture,
                                    @"El valor de {0} debe ser como máximo de {1} caracter{2}.",
                                    field.Label,
                                    this.rule.Value[0],
                                    Convert.ToInt64(this.rule.Value[0]) == 1 ? string.Empty : "es"));
                }
                else
                {
                    res.SetSuccess();
                }
            }

            return(res);
        }
        private ActionResult ComplainsRange(ItemField field)
        {
            ActionResult res = ActionResult.SuccessNoAction;

            if (this.item.ContainsKey(field.Name))
            {
                switch (field.DataType)
                {
                case FieldDataType.NullableInteger:
                    int valueInteger = Convert.ToInt32(this.item[field.Name], CultureInfo.InvariantCulture);
                    res.Success = !(valueInteger <Convert.ToInt32(this.rule.Value[0], CultureInfo.InvariantCulture) || valueInteger> Convert.ToInt32(this.rule.Value[1], CultureInfo.InvariantCulture));
                    break;

                case FieldDataType.Integer:
                    res.Success = !(Convert.ToInt32(this.item[field.Name], CultureInfo.InvariantCulture) < Convert.ToInt32(this.rule.Value[0], CultureInfo.InvariantCulture) || Convert.ToInt32(this.item[field.Name], CultureInfo.InvariantCulture) > Convert.ToInt32(this.rule.Value[1], CultureInfo.InvariantCulture));
                    break;

                case FieldDataType.NullableDecimal:
                    decimal valueDecimal = Convert.ToDecimal(this.item[field.Name], CultureInfo.InvariantCulture);
                    res.Success = !(valueDecimal <Convert.ToDecimal(this.rule.Value[0], CultureInfo.InvariantCulture) || valueDecimal> Convert.ToDecimal(this.rule.Value[1], CultureInfo.InvariantCulture));
                    break;

                case FieldDataType.Decimal:
                    if (field.Required && string.IsNullOrEmpty(this.item[field.Name].ToString()))
                    {
                        res.Success = false;
                    }
                    else
                    {
                        if (!field.Required && string.IsNullOrEmpty(this.item[field.Name].ToString()))
                        {
                            res.Success = true;
                        }
                        else
                        {
                            res.Success = !(Convert.ToDecimal(this.item[field.Name], CultureInfo.InvariantCulture) < Convert.ToDecimal(this.rule.Value[0], CultureInfo.InvariantCulture) || Convert.ToDecimal(this.item[field.Name], CultureInfo.InvariantCulture) > Convert.ToDecimal(this.rule.Value[1], CultureInfo.InvariantCulture));
                        }
                    }

                    break;

                case FieldDataType.NullableLong:
                    if (this.item[field.Name].GetType().Name.ToUpperInvariant() == "STRING")
                    {
                        if (string.IsNullOrEmpty(this.item[field.Name] as string))
                        {
                            res.Success = true;
                        }
                        else
                        {
                            long valueLong = Convert.ToInt64(this.item[field.Name], CultureInfo.InvariantCulture);
                            res.Success = !(valueLong <Convert.ToInt64(this.rule.Value[0], CultureInfo.InvariantCulture) || valueLong> Convert.ToInt64(this.rule.Value[1], CultureInfo.InvariantCulture));
                        }
                    }
                    else
                    {
                        long valueLong = Convert.ToInt64(this.item[field.Name], CultureInfo.InvariantCulture);
                        res.Success = !(valueLong <Convert.ToInt64(this.rule.Value[0], CultureInfo.InvariantCulture) || valueLong> Convert.ToInt64(this.rule.Value[1], CultureInfo.InvariantCulture));
                    }

                    break;

                case FieldDataType.Long:
                    res.Success = !(Convert.ToInt64(this.item[field.Name], CultureInfo.InvariantCulture) < Convert.ToInt64(this.rule.Value[0], CultureInfo.InvariantCulture) || Convert.ToInt64(this.item[field.Name], CultureInfo.InvariantCulture) > Convert.ToInt64(this.rule.Value[1], CultureInfo.InvariantCulture));
                    break;

                case FieldDataType.NullableFloat:
                    float valueFloat = Convert.ToSingle(this.item[field.Name], CultureInfo.InvariantCulture);
                    res.Success = !(valueFloat <Convert.ToSingle(this.rule.Value[0], CultureInfo.InvariantCulture) || valueFloat> Convert.ToSingle(this.rule.Value[1], CultureInfo.InvariantCulture));
                    break;

                case FieldDataType.Float:
                    res.Success = !(Convert.ToSingle(this.item[field.Name], CultureInfo.InvariantCulture) < Convert.ToSingle(this.rule.Value[0], CultureInfo.InvariantCulture) || Convert.ToSingle(this.item[field.Name], CultureInfo.InvariantCulture) > Convert.ToSingle(this.rule.Value[1], CultureInfo.InvariantCulture));
                    break;

                default:
                    res.Success      = false;
                    res.MessageError = string.Format(CultureInfo.InvariantCulture, "El tipo de dato de {0} no es correcto", field.Label);
                    break;
                }

                if (!res.Success && string.IsNullOrEmpty(res.MessageError))
                {
                    res.SetFail(string.Format(
                                    CultureInfo.InvariantCulture,
                                    @"El valor de {0} debe estar entre {1} y {2}.",
                                    field.Label,
                                    this.rule.Value[0],
                                    this.rule.Value[1]));
                }
            }

            return(res);
        }