Ejemplo n.º 1
0
        public override TSqlQuery Compile(ClauseCompilationContext context)
        {
            string concatenatedFields = TSqlSyntax.AllFieldsSymbol;

            if (SelectItems != null & SelectItems.Any())
            {
                concatenatedFields = string.Join(
                    TSqlSyntax.FieldsDelimeter,
                    SelectItems.Select(f => f.Compile())
                    );
            }

            StringBuilder sb = new StringBuilder();

            sb.Append($"{TSqlSyntax.Select}");

            if (Distinct)
            {
                sb.Append(" ");
                sb.Append($"{TSqlSyntax.Distinct}");
            }
            if (topCount.HasValue)
            {
                sb.Append(" ");
                sb.Append($"{TSqlSyntax.Top} {topCount}");
            }
            sb.Append(" ");
            sb.Append($"{concatenatedFields} {TSqlSyntax.From} {SqlBuilderHelper.PrepareTableName(TableName)}");

            if (TableHints.HasValue)
            {
                string hints = SqlBuilderHelper.GetTableHintString(TableHints.Value);
                sb.Append(" ");
                sb.Append($"{TSqlSyntax.With}({hints})");
            }

            return(new TSqlQuery(sb.ToString()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Process
        /// </summary>
        /// <param name="context">Context</param>
        /// <param name="output">Output</param>
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            //clear the output
            output.SuppressOutput();

            //disabled attribute
            bool.TryParse(IsDisabled, out bool disabled);
            if (disabled)
            {
                var d = new TagHelperAttribute("disabled", "disabled");
                output.Attributes.Add(d);
            }

            //required asterisk
            bool.TryParse(IsRequired, out bool required);
            if (required)
            {
                output.PreElement.SetHtmlContent("<div class='input-group input-group-required'>");
                output.PostElement.SetHtmlContent("<div class=\"input-group-btn\"><span class=\"required\">*</span></div></div>");
            }

            //contextualize IHtmlHelper
            var viewContextAware = _htmlHelper as IViewContextAware;

            viewContextAware?.Contextualize(ViewContext);

            //add form-control class
            bool.TryParse(RenderFormControlClass, out bool renderFormControlClass);
            object htmlAttributes = null;

            if (string.IsNullOrEmpty(RenderFormControlClass) && For.Metadata.ModelType.Name.Equals("String") || renderFormControlClass)
            {
                htmlAttributes = new { @class = "form-control k-input" }
            }
            ;

            var viewEngine  = GetPrivateFieldValue(_htmlHelper, "_viewEngine") as IViewEngine;
            var bufferScope = GetPrivateFieldValue(_htmlHelper, "_bufferScope") as IViewBufferScope;

            if (SelectItems != null)
            {
                if (SelectItems.Any())
                {
                    if (_htmlHelper.ViewData.ContainsKey("SelectList"))
                    {
                        _htmlHelper.ViewData["SelectList"] = SelectItems;
                    }
                    else
                    {
                        _htmlHelper.ViewData.Add("SelectList", SelectItems);
                    }
                }
                else
                {
                    if (_htmlHelper.ViewData.ContainsKey("SelectList"))
                    {
                        _htmlHelper.ViewData["SelectList"] = new List <SelectListItem>();
                    }
                    else
                    {
                        _htmlHelper.ViewData.Add("SelectList", new List <SelectListItem>());
                    }
                }
            }

            var templateBuilder = new TemplateBuilder(
                viewEngine,
                bufferScope,
                _htmlHelper.ViewContext,
                _htmlHelper.ViewData,
                For.ModelExplorer,
                For.Name,
                Template,
                readOnly: false,
                additionalViewData: new { htmlAttributes, postfix = this.Postfix });

            var htmlOutput = templateBuilder.Build();

            output.Content.SetHtmlContent(htmlOutput.RenderHtmlContent());
        }