/// <summary> /// Adds a new reporting item value /// </summary> /// <param name="value">The value to add</param> public void AddValue(string value) { ReportingCell reportingItemValue = new ReportingCell(value); this.ReportingItemValues.Add(reportingItemValue); }
/// <summary> /// Adds a new reporting item value and specifies the text and background colors /// </summary> /// <param name="value">The value to add</param> /// <param name="textColor">The color of the text</param> /// <param name="backgroundColor">The color of the cell background</param> public void AddValue(string value, Color textColor, Color backgroundColor) { ReportingCell reportingItemValue = new ReportingCell(value, textColor, backgroundColor); this.ReportingItemValues.Add(reportingItemValue); }
private string GenerateReportingItemSection(ReportingItemSection section) { StringBuilder report = new StringBuilder(); string cellDefinitionHtml = "<td bgcolor=\"<!--BGCOLOR-->\"><font face=\"Calibri\" size=\"2\" color=\"<!--TEXTCOLOR-->\"><!--VALUE--></font></td>"; string headingCellDefinitionHtml = "<td bgcolor=\"<!--BGCOLOR-->\" <!--WIDTH-->><font face=\"Calibri\" size=\"2\" color=\"<!--TEXTCOLOR-->\"><b><!--VALUE--></b></font></td>"; string fontsize = section.SectionTitleFontSize == 0 ? "3" : section.SectionTitleFontSize.ToString(); string headingRowHtml = "<table border=\"0\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">" + "<tr><!--INDENTCELLS--><td bgcolor=\"" + ColorTranslator.ToHtml(section.SectionTitleBackgroundColor) + "\" colspan=\"1\">" + "<font face=\"Calibri\" size=\"" + fontsize + "\" color=\"" + ColorTranslator.ToHtml(section.SectionTitleTextColor) + "\">" + "<b>" + CleanHtml(section.SectionTitle) + "</b></font></td></tr></table>"; for (int x = 0; x < section.IndentLevel; x++) { headingRowHtml = headingRowHtml.Replace("<!--INDENTCELLS-->", "<td width=\"15\"></td><!--INDENTCELLS-->"); } headingRowHtml = headingRowHtml.Replace("<!--INDENTCELLS-->", string.Empty); report.AppendLine(headingRowHtml); report.AppendLine("<table width=\"100%\">"); if (section.ColumnHeadings.Count > 0) { report.AppendLine("<tr>"); for (int x = 0; x < section.IndentLevel; x++) { report.AppendLine("<td width=\"15\"></td>"); } foreach (ColumnHeader cell in section.ColumnHeadings) { string width = string.Empty; if (section.AutoEqualColumnWidth) { decimal percent = ((decimal)1 / section.ColumnHeadings.Count) * 100; width = string.Format("{0}", percent.ToString("F2") + "%"); } else { if (cell.ColumnWidthPx != 0) { width = string.Format("{0}", cell.ColumnWidthPx); } else if (cell.ColumnWidthPercent != 0) { width = string.Format("{0}", cell.ColumnWidthPercent.ToString("F2") + "%"); } } string cellHtml = headingCellDefinitionHtml.Replace("<!--BGCOLOR-->", ColorTranslator.ToHtml(cell.ValueBackgroundColor)); cellHtml = cellHtml.Replace("<!--TEXTCOLOR-->", ColorTranslator.ToHtml(cell.ValueTextColor)); cellHtml = cellHtml.Replace("<!--VALUE-->", CleanHtml(cell.Value)); cellHtml = cellHtml.Replace("<!--WIDTH-->", "width=\"" + width + "\""); report.AppendLine(cellHtml); } report.AppendLine("</tr>"); } else { cellDefinitionHtml = cellDefinitionHtml.Replace("<!--WIDTH-->", "\"100%\""); } foreach (ReportingItem item in section.ReportingItems) { report.AppendLine("<tr>"); for (int x = 0; x < section.IndentLevel; x++) { report.AppendLine("<td width=\"15\"></td>"); } string titleCellHtml = cellDefinitionHtml.Replace("<!--BGCOLOR-->", ColorTranslator.ToHtml(item.TitleBackgroundColor)); titleCellHtml = titleCellHtml.Replace("<!--TEXTCOLOR-->", ColorTranslator.ToHtml(item.TitleTextColor)); titleCellHtml = titleCellHtml.Replace("<!--VALUE-->", CleanHtml(item.Title)); report.AppendLine(titleCellHtml); foreach (ReportingCell value in item.ReportingItemValues) { string cellHtml = cellDefinitionHtml.Replace("<!--BGCOLOR-->", ColorTranslator.ToHtml(value.ValueBackgroundColor)); cellHtml = cellHtml.Replace("<!--TEXTCOLOR-->", ColorTranslator.ToHtml(value.ValueTextColor)); cellHtml = cellHtml.Replace("<!--VALUE-->", CleanHtml(value.Value)); report.AppendLine(cellHtml); } // Add in any blank cells required to make a full row if (item.ReportingItemValues.Count < section.ColumnHeadings.Count - 1) { int additionalCellsRequired = section.ColumnHeadings.Count - item.ReportingItemValues.Count; ReportingCell emptyCell = new ReportingCell(); for (int x = 0; x < additionalCellsRequired; x++) { string cellHtml = cellDefinitionHtml.Replace("<!--BGCOLOR-->", ColorTranslator.ToHtml(emptyCell.ValueBackgroundColor)); cellHtml = cellHtml.Replace("<!--TEXTCOLOR-->", ColorTranslator.ToHtml(emptyCell.ValueTextColor)); cellHtml = cellHtml.Replace("<!--VALUE-->", CleanHtml(emptyCell.Value)); report.AppendLine(cellHtml); } } report.AppendLine("</tr>"); } report.AppendLine("</table>"); report.AppendLine("<br>"); return(report.ToString()); }