Exemplo n.º 1
0
        /// <summary>
        /// 初始化数据类型
        /// </summary>
        private static void InitDataType(TextBoxConfig config, DataTypeAttribute attribute)
        {
            if (attribute == null)
            {
                return;
            }
            switch (attribute.DataType)
            {
            case DataType.Date:
            case DataType.DateTime:
            case DataType.Time:
                config.IsDatePicker = true;
                break;

            case DataType.MultilineText:
                config.IsTextArea = true;
                break;

            case DataType.EmailAddress:
                config.Email();
                break;

            case DataType.Password:
                config.Password();
                break;
            }
        }
        /// <summary>
        /// 获取渲染器
        /// </summary>
        /// <param name="context">上下文</param>
        protected override IRender GetRender(Context context)
        {
            var config = new TextBoxConfig(context)
            {
                IsTextArea = true
            };

            return(new TextBoxRender(config));
        }
Exemplo n.º 3
0
 /// <summary>
 /// 初始化验证
 /// </summary>
 /// <param name="config">配置</param>
 /// <param name="member">成员</param>
 public static void InitValidation(TextBoxConfig config, MemberInfo member)
 {
     InitEmail(config, member);
     InitRegex(config, member);
     InitLength(config, member);
     InitRange(config, member);
     InitPhone(config, member);
     InitIdCard(config, member);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 获取渲染器
        /// </summary>
        /// <param name="context">上下文</param>
        protected override IRender GetRender(Context context)
        {
            var config = new TextBoxConfig(context)
            {
                IsDatePicker = true
            };

            Helper.SetColspan(config, context);
            return(new TextBoxRender(config));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取渲染器
        /// </summary>
        /// <param name="context">上下文</param>
        protected override IRender GetRender(Context context)
        {
            var config = new TextBoxConfig(context);

            if (config.GetValue <TextBoxType?>(UiConst.Type) == TextBoxType.Multiple)
            {
                config.IsTextArea = true;
            }
            return(new TextBoxRender(config));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 初始化正则表达式验证
        /// </summary>
        private static void InitRegex(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <RegularExpressionAttribute>();

            if (attribute == null)
            {
                return;
            }
            InitRegex(config, attribute.Pattern, attribute.ErrorMessage);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 初始化字符串最大长度验证
        /// </summary>
        private static void InitMaxLength(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <MaxLengthAttribute>();

            if (attribute == null)
            {
                return;
            }
            config.SetAttribute(UiConst.MaxLength, attribute.Length);
        }
Exemplo n.º 8
0
 /// <summary>
 /// 初始化文本框表达式解析器
 /// </summary>
 /// <param name="expression">属性表达式</param>
 /// <param name="config">配置</param>
 private TextBoxExpressionResolver(ModelExpression expression, TextBoxConfig config)
 {
     if (expression == null || config == null)
     {
         return;
     }
     _expression = expression;
     _config     = config;
     _memberInfo = expression.GetMemberInfo();
 }
Exemplo n.º 9
0
 /// <summary>
 /// A gui button class that should be used as a base for all buttons
 /// </summary>
 /// <param name="textBoxConfig">The text that should be shown with the button</param>
 /// <param name="size">The size of the button</param>
 /// <param name="parentOffset">The offset of the components parent</param>
 /// <param name="parent">The parent of this object</param>
 /// <param name="graphicToLoad">The graphic for this button</param>
 protected GuiButton(Point size, Vector2 parentOffset, GuiComponent parent, TextBoxConfig textBoxConfig = null, Enum graphicToLoad = null) : base(parentOffset, size, parent)
 {
     if (graphicToLoad != null)
     {
         _guiImageComponent = new GuiImageComponent(this, graphicToLoad, size, parentOffset);
     }
     if (textBoxConfig != null)
     {
         _buttonTextComponent = new GuiTextComponent(textBoxConfig, textBoxConfig.FontType);
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// 初始化文本框表达式解析器
 /// </summary>
 /// <param name="expression">属性表达式</param>
 /// <param name="config">配置</param>
 /// <param name="isTableEdit">是否表格编辑</param>
 private TextBoxExpressionResolver(ModelExpression expression, TextBoxConfig config, bool isTableEdit)
 {
     if (expression == null || config == null)
     {
         return;
     }
     _expression  = expression;
     _config      = config;
     _memberInfo  = expression.GetMemberInfo();
     _isTableEdit = isTableEdit;
 }
Exemplo n.º 11
0
        /// <summary>
        /// 初始化数值范围验证
        /// </summary>
        private static void InitRange(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <RangeAttribute>();

            if (attribute == null)
            {
                return;
            }
            config.SetAttribute(UiConst.Min, attribute.Minimum);
            config.SetAttribute(UiConst.Max, attribute.Maximum);
            config.SetAttribute(UiConst.MinMessage, attribute.ErrorMessage);
            config.SetAttribute(UiConst.MaxMessage, attribute.ErrorMessage);
        }
Exemplo n.º 12
0
 /// <summary>
 /// 初始化数据类型
 /// </summary>
 /// <param name="config">配置</param>
 /// <param name="member">成员</param>
 public static void InitDataType(TextBoxConfig config, MemberInfo member)
 {
     if (Reflection.IsDate(member))
     {
         config.IsDatePicker = true;
         return;
     }
     if (Reflection.IsNumber(member))
     {
         config.Number();
         return;
     }
     InitDataType(config, member.GetCustomAttribute <DataTypeAttribute>());
 }
Exemplo n.º 13
0
        /// <summary>
        /// 初始化电子邮件验证
        /// </summary>
        private static void InitEmail(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <EmailAddressAttribute>();

            if (attribute == null)
            {
                return;
            }
            config.Email();
            if (attribute.ErrorMessage.Contains("field is not a valid e-mail address"))
            {
                return;
            }
            config.SetAttribute(UiConst.EmailMessage, attribute.ErrorMessage);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 初始化手机号验证
        /// </summary>
        private static void InitPhone(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <PhoneAttribute>();

            if (attribute == null)
            {
                return;
            }
            var message = attribute.ErrorMessage;

            if (message.IsEmpty() || message.Contains("is not a valid phone number"))
            {
                message = LibraryResource.InvalidMobilePhone;
            }
            InitRegex(config, ValidatePattern.MobilePhonePattern, message);
        }
Exemplo n.º 15
0
        protected TextBoxConfig PopulateTextConfig(TextComponent textComponentJson, GuiComponent parent)
        {
            var textConfig = new TextBoxConfig();

            textConfig.Alignment = textComponentJson.Alignment switch
            {
                "Center" => GuiTextComponent.Alignment.Center,
                "Left" => GuiTextComponent.Alignment.Left,
                _ => textConfig.Alignment
            };
            textConfig.DisplayText  = textComponentJson.DisplayText;
            textConfig.FontType     = textComponentJson.FontType;
            textConfig.Parent       = parent;
            textConfig.ParentOffset = new Vector2(textComponentJson.ParentOffset.X, textComponentJson.ParentOffset.Y);
            return(textConfig);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 初始化身份证验证
        /// </summary>
        private static void InitIdCard(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <IdCardAttribute>();

            if (attribute == null)
            {
                return;
            }
            var message = attribute.ErrorMessage;

            if (message.IsEmpty())
            {
                message = LibraryResource.InvalidIdCard;
            }
            InitRegex(config, ValidatePattern.IdCardPattern, message);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 获取渲染器
        /// </summary>
        /// <param name="context">上下文</param>
        protected override IRender GetRender(Context context)
        {
            var config = new TextBoxConfig(context);
            var type   = config.GetValue <TextBoxType?>(UiConst.Type);

            switch (type)
            {
            case TextBoxType.Multiple:
                config.IsTextArea = true;
                break;

            case TextBoxType.Number:
                config.IsNumber = true;
                break;
            }
            return(new TextBoxRender(config));
        }
Exemplo n.º 18
0
        /// <summary>
        /// 初始化字符串长度验证
        /// </summary>
        private static void InitStringLength(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <StringLengthAttribute>();

            if (attribute == null)
            {
                return;
            }
            if (attribute.MinimumLength > 0)
            {
                config.SetAttribute(UiConst.MinLength, attribute.MinimumLength);
            }
            if (attribute.MaximumLength > 0)
            {
                config.SetAttribute(UiConst.MaxLength, attribute.MaximumLength);
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// 初始化正则表达式验证
 /// </summary>
 private static void InitRegex(TextBoxConfig config, string pattern, string errorMessage)
 {
     config.SetAttribute(UiConst.Regex, pattern);
     config.SetAttribute(UiConst.RegexMessage, errorMessage);
 }
Exemplo n.º 20
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="expression">属性表达式</param>
 /// <param name="config">配置</param>
 /// <param name="isTableEdit">是否表格编辑</param>
 public static void Init(ModelExpression expression, TextBoxConfig config, bool isTableEdit = false)
 {
     new TextBoxExpressionResolver(expression, config, isTableEdit).Init();
 }
Exemplo n.º 21
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="expression">属性表达式</param>
 /// <param name="config">配置</param>
 public static void Init(ModelExpression expression, TextBoxConfig config)
 {
     new TextBoxExpressionResolver(expression, config).Init();
 }
 public TitleScreenMainMenuButton(TextBoxConfig textBoxConfig, Point size, Vector2 parentOffset, GuiComponent parent, int graphicToLoad) : base(size, parentOffset, parent, textBoxConfig)
 {
 }
Exemplo n.º 23
0
 /// <summary>
 /// 初始化字符串长度验证
 /// </summary>
 private static void InitLength(TextBoxConfig config, MemberInfo member)
 {
     InitStringLength(config, member);
     InitMinLength(config, member);
     InitMaxLength(config, member);
 }
Exemplo n.º 24
0
 /// <summary>
 /// 初始化验证
 /// </summary>
 /// <param name="config">配置</param>
 /// <param name="member">成员</param>
 public static void InitValidation(TextBoxConfig config, MemberInfo member)
 {
     InitLength(config, member);
     InitEmail(config, member);
 }
Exemplo n.º 25
0
 /// <summary>
 /// 初始化文本框
 /// </summary>
 /// <param name="gridConfig">栅格配置</param>
 public TextBox(IConfig gridConfig = null)
 {
     _config = new TextBoxConfig();
     _config.AddColspan(gridConfig);
 }
Exemplo n.º 26
0
 /// <summary>
 /// 初始化文本框渲染器
 /// </summary>
 /// <param name="config">文本框配置</param>
 public TextBoxRender(TextBoxConfig config) : base(config)
 {
     _config = config;
 }
Exemplo n.º 27
0
 /// <summary>
 /// 初始化文本框
 /// </summary>
 public TextBox()
 {
     _config = new TextBoxConfig();
 }