Esempio n. 1
0
        public override string RenderContent()
        {
            if (Fields.Count == 0)
            {
                throw new FoxOneException("Fields不能为空");
            }
            StringBuilder result = new StringBuilder();

            SearchFormTemplate = TemplateGenerator.GetSearchFormTemplate();
            string searchFieldTemplate = TemplateGenerator.GetFormFieldTemplate();
            string buttonTemplate      = string.Empty;

            if (!Buttons.IsNullOrEmpty())
            {
                buttonTemplate = "<div class=\"search-control\"><div class=\"form-group\">{0}</div></div>";
                StringBuilder buttonResult = new StringBuilder();
                foreach (var button in Buttons.OrderBy(o => o.Rank))
                {
                    buttonResult.AppendLine(button.Render());
                }
                buttonTemplate = buttonTemplate.FormatTo(buttonResult.ToString());
            }
            foreach (var field in Fields.OrderBy(o => o.Rank))
            {
                if (field is HiddenField)
                {
                    continue;
                }
                if (field.ContainerTemplate.IsNullOrEmpty())
                {
                    field.ContainerTemplate = searchFieldTemplate;
                }
                if (field.Name.IsNullOrEmpty())
                {
                    field.Name = field.Id;
                }
                if (!HttpContext.Current.Request.QueryString[field.Id].IsNullOrEmpty())
                {
                    //如果URL参数中含有与当前查询控件ID一致的键值,则以URL参数的值赋初始值,并且改当前查询控件为禁用状态
                    field.Value = HttpContext.Current.Request.QueryString[field.Id];
                }
                else
                {
                    field.Enable = true;
                    if (field.Value != null)
                    {
                        field.Value = Env.Parse(field.Value.ToString());
                    }
                }
                result.AppendLine(field.Render());
            }
            return(SearchFormTemplate.FormatTo(FormCssClass, result.ToString(), buttonTemplate));
        }
Esempio n. 2
0
        public override string RenderContent()
        {
            int           displayCount      = Math.Min(PageCount, DisplayIndexCount);
            string        pagerItemTemplate = TemplateGenerator.GetPagerItemTemplate();
            string        pagerSizeTemplate = TemplateGenerator.GetPagerSizeTemplate();
            StringBuilder result            = new StringBuilder();

            result.AppendFormat(pagerItemTemplate, 1, "", "首页");
            result.AppendFormat(pagerItemTemplate, "Pre", "", "上一页");

            int startIndex = 1, endIndex = displayCount;
            int centerValue = (int)Math.Ceiling((double)displayCount / 2);

            if (CurrentPageIndex > centerValue && PageCount > displayCount)
            {
                centerValue = centerValue - 1;
                if ((CurrentPageIndex + centerValue) < PageCount)
                {
                    startIndex = CurrentPageIndex - centerValue;
                }
                else
                {
                    startIndex = PageCount - centerValue * 2;
                }
                endIndex = Math.Min(PageCount, startIndex + displayCount) - 1;
            }

            for (int i = startIndex; i <= endIndex; i++)
            {
                result.AppendFormat(pagerItemTemplate, i, i == CurrentPageIndex ? "class=\"active\"" : "", i);
            }
            result.AppendFormat(pagerItemTemplate, "Next", "", "下一页");
            result.AppendFormat(pagerItemTemplate, PageCount, "", "末页");

            string pageSizeSet = string.Empty;

            PrePageSize.Split(',').ForEach((a) =>
            {
                string active = string.Empty;
                if (a.Equals(PageSize.ToString()))
                {
                    active = "class=\"active\"";
                }
                pageSizeSet += pagerSizeTemplate.FormatTo(a, active, a);
            });
            return(TemplateGenerator.GetPagerTemplate().FormatTo(result.ToString(), pageSizeSet));
        }
Esempio n. 3
0
        public override string RenderContent()
        {
            if (Fields.Count == 0)
            {
                throw new FoxOneException("Fields不能为空");
            }
            var request = HttpContext.Current.Request;

            if (FormService != null)
            {
                if (Key.IsNullOrEmpty())
                {
                    Key = request[NamingCenter.PARAM_KEY_NAME];
                }

                //当FORM指定的服务类不为空,且当前的请求中带有KEY的URL参数,
                //则尝试去获取表单数据,如果不为空,则为编辑状态
                if (!Key.IsNullOrEmpty())
                {
                    var tempData = FormService.Get(Key);
                    if (!tempData.IsNullOrEmpty())
                    {
                        if (FormMode != FormMode.View)
                        {
                            FormMode = FormMode.Edit;
                        }
                        Data = tempData;
                    }
                    if (request != null && request.QueryString[NamingCenter.PARAM_FORM_VIEW_MODE] != null && request.QueryString[NamingCenter.PARAM_FORM_VIEW_MODE].Equals(FormMode.View.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        FormMode = FormMode.View;
                    }
                }
            }
            IDictionary <string, object> formData = null;

            if (Data != null)
            {
                formData = Data as Dictionary <string, object>;
                if (formData.IsNullOrEmpty())
                {
                    formData = Data.ToDictionary();
                }
            }
            StringBuilder result = new StringBuilder();
            ///隐藏域和按钮属于特殊群体放在表单的指定位置
            StringBuilder hiddenResult = new StringBuilder();
            StringBuilder buttonResult = new StringBuilder();

            if (!Buttons.IsNullOrEmpty() && FormMode != FormMode.View)
            {
                foreach (var button in Buttons)
                {
                    buttonResult.AppendLine(button.Render());
                }
            }
            var formModeHidden = new HiddenField()
            {
                Id = NamingCenter.PARAM_FORM_VIEW_MODE, Value = request[NamingCenter.PARAM_FORM_VIEW_MODE].IsNullOrEmpty() ? FormMode.ToString() : request[NamingCenter.PARAM_FORM_VIEW_MODE], Name = NamingCenter.PARAM_FORM_VIEW_MODE
            };

            hiddenResult.Append(formModeHidden.Render());
            var formTemplate = TemplateGenerator.GetDefaultFormTemplate();
            var renderQuerystringFinished = false;

            if (AppendQueryString && !renderQuerystringFinished)
            {
                foreach (var r in request.QueryString.AllKeys)
                {
                    if (!r.Equals(NamingCenter.PARAM_FORM_VIEW_MODE, StringComparison.OrdinalIgnoreCase) && Fields.Count(o => o.Id.Equals(r, StringComparison.CurrentCultureIgnoreCase)) == 0)
                    {
                        hiddenResult.AppendLine(new HiddenField()
                        {
                            Id = r, Name = r, Value = request.QueryString[r]
                        }.Render());
                    }
                }
                renderQuerystringFinished = true;
            }
            var renderFields = new List <FormControlBase>();

            foreach (var field in Fields.OrderBy(o => o.Rank))
            {
                if ((FormMode == FormMode.Edit && !field.CanModity) || FormMode == FormMode.View)
                {
                    //如果当前Form的模式为编辑模式,而字段又不允许修改,则改为不可用。
                    field.Enable = false;
                }
                if (field.Name.IsNullOrEmpty())
                {
                    field.Name = field.Id;
                }
                if (!formData.IsNullOrEmpty())
                {
                    if (formData.Keys.Contains(field.Id))
                    {
                        field.Value = (formData[field.Id] == null) ? "" : formData[field.Id].ToString();
                    }
                }
                else
                {
                    if (!request.QueryString[field.Id].IsNullOrEmpty())
                    {
                        //如果URL参数中含有与当前控件ID一致的键值,则以URL参数的值赋初始值
                        field.Value = request.QueryString[field.Id];
                    }
                    else
                    {
                        /// 当字段的值存在的时候从环境变量将值格式化
                        if (field.Value != null)
                        {
                            field.Value = Env.Parse(field.Value.ToString());
                        }
                    }
                }
                if (field is HiddenField)
                {
                    hiddenResult.AppendLine(field.Render());
                }
                else
                {
                    if (field.ContainerTemplate.IsNullOrEmpty())
                    {
                        field.ContainerTemplate = TemplateGenerator.GetFormFieldTemplate();
                    }
                    renderFields.Add(field);
                }
            }
            string groupTemplate = TemplateGenerator.GetFormGroupTemplate();

            for (int i = 0; i < renderFields.Count; i++)
            {
                if (!renderFields[i].EditColSpan && ((i + 1) < renderFields.Count) && !renderFields[i + 1].EditColSpan)
                {
                    result.Append(groupTemplate.FormatTo(renderFields[i].Render() + renderFields[++i].Render()));
                }
                else
                {
                    result.Append(groupTemplate.FormatTo(renderFields[i].Render()));
                }
            }
            return(formTemplate.FormatTo(PostUrl, FormCssClass, hiddenResult.ToString(), result.ToString(), buttonResult.ToString()));
        }