示例#1
0
        private string GetGridView(Report report, GridView grid)
        {
            var index = grid.DataSourceIndex;

            if (index == null)
            {
                return null;
            }

            var dataSource = report.DataSources.FirstOrDefault(x => x.Index == index.Value);

            if (dataSource == null)
            {
                return string.Empty;
            }

            return this.DataTableToHtml(dataSource, grid, report);
        }
示例#2
0
        private string DataTableToHtml(DataSource dataSource, GridView grid, Report report)
        {
            var html = new StringBuilder();

            html.Append("<table ");

            if (!string.IsNullOrWhiteSpace(grid.CssStyle))
            {
                html.Append("style='" + grid.CssStyle + "' ");
            }

            if (!string.IsNullOrWhiteSpace(grid.CssClass))
            {
                html.Append("class='" + grid.CssClass + "'");
            }

            html.Append(">");

            html.Append("<thead>");
            html.Append("<tr>");

            for (int i = 0; i < dataSource.Data.Columns.Count; i++)
            {
                string columnName = dataSource.Data.Columns[i].ColumnName;
                columnName = ResourceManager.GetString(report.Tenant, "ScrudResource", columnName);

                html.Append("<th>" + columnName + "</th>");
            }

            html.Append("</tr>");
            html.Append("</thead>");

            if (dataSource.RunningTotalTextColumnIndex != null && dataSource.RunningTotalTextColumnIndex > 0)
            {
                int index = dataSource.RunningTotalTextColumnIndex.Value;
                var candidates = dataSource.RunningTotalFieldIndices;

                html.Append("<tfoot>");
                html.Append("<tr>");

                html.Append("<th class='right aligned' colspan='");
                html.Append(index + 1);
                html.Append("'>Total</th>");

                for (int i = index + 1; i < dataSource.Data.Columns.Count; i++)
                {
                    html.Append("<th class='right aligned'>");

                    if (candidates.Contains(i))
                    {
                        decimal sum = ExpressionHelper.GetSum(dataSource.Data, i);
                        html.Append(FormattingHelper.GetFormattedValue(sum));
                    }

                    html.Append("</th>");
                }

                html.Append("</tr>");
                html.Append("</tfoot>");
            }

            html.Append("<tbody>");

            for (int i = 0; i < dataSource.Data.Rows.Count; i++)
            {
                html.Append("<tr>");

                for (int j = 0; j < dataSource.Data.Columns.Count; j++)
                {
                    var value = dataSource.Data.Rows[i][j];
                    html.Append(this.GetFormattedCell(value));
                }

                html.Append("</tr>");
            }

            html.Append("</tbody>");
            html.Append("</table>");

            return html.ToString();
        }