예제 #1
0
        public void CreateValidationMetadata(ValidationMetadataProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var viewConfig = ViewConfigureAttribute.GetAttribute(context.Key.ContainerType);

            if (viewConfig != null && context.Key.Name.IsNotNullAndWhiteSpace())
            {
                var descriptor = viewConfig.GetViewPortDescriptor(context.Key.Name);
                if (descriptor != null)
                {
                    descriptor.Validator.Each(v =>
                    {
                        v.DisplayName = descriptor.DisplayName;
                        if (v is RangeValidator)
                        {
                            RangeValidator valid = (RangeValidator)v;
                            RangeAttribute range = new RangeAttribute(valid.Min, valid.Max);
                            range.ErrorMessage   = valid.ErrorMessage;

                            context.ValidationMetadata.ValidatorMetadata.Add(range);
                        }
                        else if (v is RegularValidator)
                        {
                            RegularValidator valid             = (RegularValidator)v;
                            RegularExpressionAttribute regular = new RegularExpressionAttribute(valid.Expression);
                            regular.ErrorMessage = valid.ErrorMessage;
                            context.ValidationMetadata.ValidatorMetadata.Add(regular);
                        }
                        else if (v is RemoteValidator)
                        {
                            RemoteValidator valid  = (RemoteValidator)v;
                            RemoteAttribute remote = new RemoteAttribute(valid.Action, valid.Controller, valid.Area);
                            remote.ErrorMessage    = valid.ErrorMessage;
                            context.ValidationMetadata.ValidatorMetadata.Add(remote);
                        }
                        else if (v is RequiredValidator)
                        {
                            RequiredValidator valid  = (RequiredValidator)v;
                            RequiredAttribute remote = new RequiredAttribute();
                            remote.ErrorMessage      = valid.ErrorMessage;
                            context.ValidationMetadata.ValidatorMetadata.Add(remote);
                        }
                        else if (v is StringLengthValidator)
                        {
                            StringLengthValidator valid        = (StringLengthValidator)v;
                            StringLengthAttribute stringLength = new StringLengthAttribute(valid.Max);
                            stringLength.ErrorMessage          = valid.ErrorMessage;
                            context.ValidationMetadata.ValidatorMetadata.Add(stringLength);
                        }
                    });
                }
            }
        }
예제 #2
0
        public void CreateDisplayMetadata(DisplayMetadataProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var viewConfig = ViewConfigureAttribute.GetAttribute(context.Key.ContainerType);


            var displayMetadata = context.DisplayMetadata;

            if (viewConfig != null && context.Key.Name.IsNotNullAndWhiteSpace())
            {
                var descriptor = viewConfig.GetViewPortDescriptor(context.Key.Name);
                if (descriptor != null)
                {
                    displayMetadata.AdditionalValues.Add("ViewPortDescriptor", descriptor);
                    if (displayMetadata.DisplayName == null)
                    {
                        displayMetadata.DisplayName = () =>
                        {
                            var attr = ViewConfigureAttribute.GetAttribute(context.Key.ContainerType);
                            attr.InitDisplayName();
                            var descriptop = attr.GetViewPortDescriptor(context.Key.Name);
                            return(descriptop.DisplayName);
                        };
                    }

                    displayMetadata.Order          = descriptor.OrderIndex;
                    displayMetadata.TemplateHint   = descriptor.TemplateName;
                    displayMetadata.ShowForDisplay = descriptor.IsShowForDisplay;
                    displayMetadata.ShowForEdit    = descriptor.IsShowForEdit;
                    if (descriptor.IsHidden)
                    {
                        displayMetadata.TemplateHint   = "HiddenInput";
                        displayMetadata.ShowForDisplay = false;
                        displayMetadata.ShowForEdit    = false;
                    }
                    if (descriptor.IsIgnore)
                    {
                        displayMetadata.ShowForDisplay = false;
                        displayMetadata.ShowForEdit    = false;
                        displayMetadata.TemplateHint   = "Ignore";
                    }
                }
            }
        }
예제 #3
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (Source.IsNullOrWhiteSpace())
            {
                Source = Url.Action(DefaultSourceAction);
            }
            if (GridClass.IsNullOrWhiteSpace())
            {
                GridClass = DefaultClass;
            }
            if (ModelType == null)
            {
                ModelType = ViewContext.ViewData.ModelMetadata.ModelType;
            }
            var           viewConfig         = ViewConfigureAttribute.GetAttribute(ModelType);
            StringBuilder tableHeaderBuilder = new StringBuilder();
            StringBuilder tableSearchBuilder = new StringBuilder();

            if (viewConfig != null)
            {
                var primaryKey = viewConfig.MetaData.Properties.Select(m => m.Value).FirstOrDefault(m => m.CustomAttributes.Any(attr => attr.AttributeType == typeof(KeyAttribute)));
                viewConfig.InitDisplayName();
                if ((EditAble ?? true) && primaryKey != null)
                {
                    string name = primaryKey.Name.FirstCharToLowerCase();
                    if (name.Length == 2)
                    {
                        name = name.ToLower();
                    }

                    if (Edit.IsNullOrWhiteSpace())
                    {
                        Edit = Url.Action(DefaultEditAction) + "/{" + name + "}";
                    }
                    tableHeaderBuilder.AppendFormat(TableHeadStructure,
                                                    string.Empty,
                                                    WebUtility.HtmlEncode(EditLinkTemplate.FormatWith(Edit)),
                                                    string.Empty,
                                                    "操作",
                                                    string.Empty,
                                                    Query.Operators.None,
                                                    string.Empty,
                                                    string.Empty);
                    tableSearchBuilder.Append(TableSearchStructure);
                }

                var columns = viewConfig.GetViewPortDescriptors(true)
                              .Where(m => m.IsShowInGrid)
                              .Each(m =>
                {
                    var dropDown = m as DropDownListDescriptor;
                    StringBuilder optionBuilder = new StringBuilder();
                    if (dropDown != null)
                    {
                        foreach (var item in dropDown.OptionItems)
                        {
                            optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", item.Value, item.Key);
                        }
                    }
                    else if (m.DataType == typeof(bool) || m.DataType == typeof(bool?))
                    {
                        optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", "是", "true");
                        optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", "否", "false");
                    }
                    tableHeaderBuilder.AppendFormat(TableHeadStructure,
                                                    m.Name.FirstCharToLowerCase(),
                                                    WebUtility.HtmlEncode(m.GridColumnTemplate),
                                                    OrderAsc == m.Name ? "asc" : OrderDesc == m.Name ? "desc" : "",
                                                    m.DisplayName,
                                                    optionBuilder.Length == 0 ? string.Empty : WebUtility.HtmlEncode($"[{optionBuilder.ToString().Trim(',')}]"),
                                                    m.SearchOperator,
                                                    m.DataType.Name,
                                                    (m as TextBoxDescriptor)?.JavaScriptDateFormat);
                    tableSearchBuilder.Append(TableSearchStructure);
                });
            }
            output.TagName = "div";
            output.Attributes.Add("class", "container-fluid");
            output.Content.SetHtmlContent(TableStructure.FormatWith(GridClass, Source, tableHeaderBuilder, tableSearchBuilder));
        }
예제 #4
0
 public static void RemoveCache(string lanKey)
 {
     LanguageCache.Remove(lanKey);
     ViewConfigureAttribute.ClearCache();
 }