Exemplo n.º 1
0
        public string CheckField(UniversalEditorField field, object value)
        {
            var errText = "Поле \"" + field.HeaderText + "\" обязательно для заполнения";

            if (field.FieldType == UniversalEditorFieldType.DBImageUpload)
            {
                var rq = HttpContext.Current.Request[field.FieldName + "_Path"];

                if (rq.IsNullOrEmpty() && value == null)
                {
                    return(errText);
                }
                return("");
            }
            var obj = value.ToTypedObject(field.DataType);

            if (obj == null || (obj is DateTime && (DateTime)obj == DateTime.MinValue))
            {
                return(errText);
            }
            if (obj is string && ((string)obj).IsNullOrEmpty())
            {
                return(errText);
            }
            return("");
        }
Exemplo n.º 2
0
        public string CheckField(UniversalEditorField field, object value)
        {
            string errText = "Поле \"" + field.HeaderText + "\" должно быть ";

            if (MinVal != decimal.MinValue)
            {
                errText += "больше " + MinVal.ToUniString();
            }
            if (MinVal != decimal.MinValue && MaxVal != decimal.MaxValue)
            {
                errText += " и ";
            }
            if (MaxVal != decimal.MaxValue)
            {
                errText += "меньше " + MaxVal.ToUniString();
            }
            var obj = value.ToTypedObject(field.DataType);

            if (obj == null)
            {
                if (field.DataType == typeof(decimal))
                {
                    obj = (value ?? "").ToString().Replace(",", ".").ToTypedObject(field.DataType) ??
                          (value ?? "").ToString().Replace(".", ",").ToTypedObject(field.DataType);
                }
            }
            if (obj == null)
            {
                return(errText);
            }
            if (obj is decimal)
            {
                if ((decimal)obj <= MinVal || (decimal)obj >= MaxVal)
                {
                    return(errText);
                }
            }
            if (obj is int)
            {
                if ((int)obj <= MinVal || (int)obj >= MaxVal)
                {
                    return(errText);
                }
            }
            return("");
        }