Ejemplo n.º 1
0
        public string Generate(Report report)
        {
            if (string.IsNullOrWhiteSpace(report.Title))
            {
                return string.Empty;
            }

            return "<div class='report title'>" + report.Title + "</div>";
        }
Ejemplo n.º 2
0
        public string Generate(Report report)
        {
            if (string.IsNullOrWhiteSpace(report.Title))
            {
                return string.Empty;
            }

            return "<div class='bottom section'>" + report.BottomSection + "</div>";
        }
Ejemplo n.º 3
0
        public ReportParser(string path, string tenant, List<Parameter> parameters)
        {
            this.Path = path;

            this.Report = new Report
            {
                Tenant = tenant,
                Parameters = parameters
            };
        }
Ejemplo n.º 4
0
        private DataTable GetDataSource(Report report, DataSource dataSource)
        {
            var parameters = new ParameterInfo
            {
                Parameters = report.Parameters,
                DataSourceParameters = dataSource.Parameters
            };

            return DataSourceHelper.GetDataTable(report.Tenant, dataSource.Query, parameters);
        }
Ejemplo n.º 5
0
        public string Generate(Report report)
        {
            if (!report.HasHeader)
            {
                return string.Empty;
            }

            string pathToHeader = PathMapper.MapPath("~/Reports/Assets/Header.html");
            return File.ReadAllText(pathToHeader, Encoding.UTF8);
        }
Ejemplo n.º 6
0
        private string GetGridViews(Report report)
        {
            var html = new StringBuilder();

            foreach (var grid in report.Body.GridViews)
            {
                html.Append(this.GetGridView(report, grid));
            }

            return html.ToString();
        }
Ejemplo n.º 7
0
        private object GetDefaultValue(Report report, XmlNode node, string type)
        {
            string value = this.ReadAttributeValue(node, "DefaultValue");

            if (string.IsNullOrWhiteSpace(value))
            {
                return null;
            }

            value = ExpressionHelper.ParseExpression(report.Tenant, value, report.DataSources, ParameterHelper.GetPraParameterInfo(report));
            return DataSourceParameterHelper.CastValue(value, type);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        private List<DataSourceParameter> GetParameters(Report report, XmlNode node)
        {
            var parameters = new List<DataSourceParameter>();

            var candidates = node.ChildNodes.Cast<XmlNode>().Where(x => x.Name.Equals("Parameters"));

            foreach (var item in candidates)
            {
                foreach (var current in item.ChildNodes.Cast<XmlNode>().Where(x => x.Name.Equals("Parameter")))
                {
                    if (current.Attributes != null)
                    {
                        string name = this.GetAttributeValue(current, "Name").ToString();
                        string type = this.GetAttributeValue(current, "Type").ToString();
                        var defaultValue = this.GetDefaultValue(report, current, type);
                        bool hasMetaValue = this.HasMetaValue(current);

                        string populateFrom = this.GetAttributeValue(current, "PopulateFrom")?.ToString();
                        string keyField = this.GetAttributeValue(current, "KeyField")?.ToString();
                        string valueField = this.GetAttributeValue(current, "ValueField")?.ToString();
                        string fieldLabel = this.GetAttributeValue(current, "FieldLabel")?.ToString();
                        var optional = this.GetAttributeValue(current, "Optional")?.ToString().ToUpperInvariant().StartsWith("T");

                        fieldLabel = ExpressionHelper.ParseExpression(report.Tenant, fieldLabel, report.DataSources, ParameterHelper.GetPraParameterInfo(report));

                        parameters.Add(new DataSourceParameter
                        {
                            Name = name,
                            Type = type,
                            DefaultValue = defaultValue,
                            HasMetaValue = hasMetaValue,
                            PopulateFrom = populateFrom,
                            KeyField = keyField,
                            ValueField = valueField,
                            FieldLabel = fieldLabel,
                            Optional = optional ?? false
                        });
                    }
                }
            }

            return parameters;
        }
Ejemplo n.º 10
0
        public string Generate(Report report)
        {
            var html = new StringBuilder();
            html.Append("<div class='body'>");

            if (!string.IsNullOrWhiteSpace(report.Body.Content))
            {
                html.Append("<div class='body content'>");
                html.Append(report.Body.Content);
                html.Append("</div>");
            }


            html.Append("<div class='gridviews'>");
            html.Append(this.GetGridViews(report));
            html.Append("</div>");

            html.Append("</div>"); //<div class='body'>

            return html.ToString();
        }
Ejemplo n.º 11
0
        public static ParameterInfo GetPraParameterInfo(Report report)
        {
            var dsp = new List<DataSourceParameter>();

            if (report.DataSources != null)
            {
                foreach (var dataSource in report.DataSources)
                {
                    foreach (var parameter in dataSource.Parameters)
                    {
                        if (!dsp.Any(x => x.Name.ToLower().Equals(parameter.Name)))
                        {
                            dsp.Add(parameter);
                        }
                    }
                }
            }

            return new ParameterInfo
            {
                Parameters = report.Parameters,
                DataSourceParameters = dsp
            };
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
0
        public List<DataSource> Get(Report report)
        {
            var nodes = XmlHelper.GetNodes(this.Path, "//DataSource");
            int index = 0;
            foreach (XmlNode node in nodes)
            {
                this.DataSources.Add(new DataSource
                {
                    Index = index,
                    Query = this.GetQuery(node),
                    Parameters = this.GetParameters(report, node),
                    RunningTotalFieldIndices = this.GetRunningTotalFieldIndices(node),
                    RunningTotalTextColumnIndex = this.GetRunningTotalTextColumnIndex(node)
                });

                index++;
            }

            return this.DataSources;
        }