Exemplo n.º 1
0
        public override MvcHtmlString Html(HtmlHelper htmlHelper, string name, object value)
        {
            var htmlAttributes = GetHtmlAttributes();
            var result         = "";

            if (!Readonly)
            {
                if (htmlHelper.ViewData["hasDataBoxJs"] == null)
                {
                    var configMapper = PFDataHelper.GetConfigMapper();
                    var pathConfig   = configMapper.GetPathConfig();
                    result = string.Format("<script language='javascript' type='text/javascript' src='/{0}'></script>", pathConfig.DataBoxJsPath);
                    htmlHelper.ViewData["hasDataBoxJs"] = true;
                }
            }
            return(new MvcHtmlString(result + htmlHelper.TextBox(name, PFDataHelper.ObjectToDateString(value, _format), htmlAttributes).ToString()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 注意:Model为DataTable时没必要写自动生成列的方法,因为在PFGrid.ColumnsFor方法里循环Table生成也是很简单的
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <returns></returns>
        public MvcHtmlString Html(HtmlHelper htmlHelper)
        {
            var sb = new StringBuilder();
            ////特性
            var htmlAttributes = GetHtmlAttributes();
            var sAttributes    = "";

            foreach (var a in htmlAttributes)
            {
                sAttributes += string.Format(" {0}='{1}' ", a.Key, a.Value);
            }

            var configMapper = PFDataHelper.GetConfigMapper();
            var pathConfig   = configMapper.GetPathConfig();


            if (htmlHelper.ViewData["hasPFGridCss"] == null)
            {
                sb.AppendFormat("<link href=\"/{0}/PFGrid.css\" rel=\"stylesheet\" />", pathConfig.CssPath);
                htmlHelper.ViewData["hasPFGridCss"] = true;
            }
            #region 标题
            //            if (!string.IsNullOrWhiteSpace(_title))
            //            {
            ////                sb.AppendFormat(@"
            ////                            <tr>
            ////                                <td style='' class='txt_86433c_12 pf-grid-head-td' align='left'>
            ////                                    <strong>◎ {0}</strong>
            ////                                </td>
            ////                            </tr>
            ////", _title);

            //            }
            #endregion 标题

            #region 主体table

            sb.AppendFormat(@"<table {0}>", sAttributes);

            bool hasData = _model != null && _model.Count > 0;
            #region 表头
            if (hasData)
            {
                if (_header != null)
                {
                    sb.Append(_header.Html(this));
                }
                else
                {
                    sb.AppendFormat("<thead><tr class='{0}'>", _headClass);
                    _columns.ForEach(c =>
                    {
                        var style = c.GetStyle(false);
                        if (!string.IsNullOrWhiteSpace(c.Width))
                        {
                            style += ";min-width:" + c.Width;
                        }
                        if (!string.IsNullOrWhiteSpace(style))
                        {
                            style = string.Format("style='{0} '", style);
                        }
                        sb.AppendFormat("<th {1} field-name='{2}' >{0}</th>", c.Text, style, c.DataIndex);
                        //var style = "";
                        //if (!c.Visible) { style += "display:none;"; }
                        //if (c.Width != null) { style += "width:" + c.Width + ";"; }
                        //if (!string.IsNullOrWhiteSpace(style)) { style = string.Format("style='{0}'", style); }
                        //sb.AppendFormat("<th {1}  >{0}</th>", c.Text, style);
                    });
                    sb.Append("</tr></thead>");
                }
            }
            #endregion 表头
            sb.Append(@"<tbody>");
            if (hasData)
            {
                #region 行内容
                int  i      = 0;
                bool isTree = false;
                foreach (var row in _model)
                {
                    if (row is TreeListItem)
                    {
                        isTree = true;
                        if (_columns.Any())
                        {
                            var style = "text-align:left;padding-left:5px;padding-right:5px;white-space:nowrap;";
                            if (_header != null)
                            {
                                _columns.First(c => c.Text == _header.FirstLeaf(a => a.Visible).Text).SetStyle(style);
                            }
                            else
                            {
                                _columns.First(a => a.Visible).SetStyle(style);
                            }
                        }
                        break;
                    }
                }
                if (isTree)
                {
                    var matrix = new TreeMatrix(_model);
                    foreach (var row in _model)
                    {
                        var tRow = row as TreeListItem;
                        sb.Append(TreeRowToHtml(tRow, i, 1, matrix));
                        i++;
                        tRow.EachChild((a, b) =>
                        {
                            //sb.Append(TreeRowToHtml(tRow, i, b, matrix));
                            sb.Append(TreeRowToHtml(a, i, b, matrix));
                            i++;
                        });
                    }
                }
                else
                {
                    foreach (var row in _model)
                    {
                        sb.Append(RowToHtml(row));
                    }
                }

                #endregion 行内容
            }
            else
            {
                sb.AppendFormat("<tr><td>{0}</td></tr>", "无相关数据");
                //sb.AppendFormat("<table style='width: 100%;'><tr class='{0}'><td style='text-align:center;color:red'>无相关数据</td></tr></table>", _itemClass);
            }
            sb.Append(@"</tbody>");
            sb.Append(@"</table>");

            #endregion 主体table


            return(MvcHtmlString.Create(sb.ToString()));
        }