public Section() { SubSection = null; BackColor = Color.FromArgb(240, 240, 240); ChartValueField = "Count"; GradientBackground = false; ChartTitle = " "; }
public Section(string groupBy, string titlePrefix, Color bgcolor) { GroupBy = groupBy; TitlePrefix = titlePrefix; SubSection = null; BackColor = bgcolor; ChartValueField = "Count"; GradientBackground = false; ChartTitle = " "; }
public Section(string groupBy, string titlePrefix) { GroupBy = groupBy; TitlePrefix = titlePrefix; SubSection = null; BackColor = Color.FromArgb(240, 240, 240); ChartValueField = "Count"; GradientBackground = false; ChartTitle = " "; }
/// <summary> /// Generates all section contents /// </summary> private void WriteSections() { if (sections.Count == 0) { Section dummySection = new Section(); dummySection.Level = 5; dummySection.ChartChangeOnField = this.ChartChangeOnField; dummySection.ChartLabelHeader = this.ChartLabelHeader; dummySection.ChartPercentageHeader = this.ChartPercentageHeader; dummySection.ChartShowAtBottom = this.ChartShowAtBottom; dummySection.ChartShowBorder = this.ChartShowAtBottom; dummySection.ChartTitle = this.ChartTitle; dummySection.ChartValueField = this.ChartValueField; dummySection.ChartValueHeader = this.ChartValueHeader; dummySection.IncludeChart = this.IncludeChart; htmlContent.Append("<TABLE Width='100%' class='TableStyle' cellspacing=0 cellpadding=5 border=1>" + newline); //border=0 if (this.IncludeChart && !this.ChartShowAtBottom) GenerateBarChart("", dummySection); Hashtable total = WriteSectionDetail(null, ""); if (this.IncludeTotal) { dummySection.IncludeTotal = true; WriteSectionFooter(dummySection, total); //WriteSectionFooter(dummySection, ""); } if (this.IncludeChart && this.ChartShowAtBottom) GenerateBarChart("", dummySection); htmlContent.Append("</TABLE></BODY></HTML>"); } foreach (Section section in sections) { iLevel = 0; htmlContent.Append("<TABLE Width='100%' class='TableStyle' cellspacing=0 cellpadding=5 border=1>" + newline); //border=0 RecurseSections(section, ""); htmlContent.Append("</TABLE></BODY></HTML>"); } }
/// <summary> /// Writes the section header information. /// </summary> /// <param name="section">The section details as Section object</param> /// <param name="sectionValue">section group field data</param> private void WriteSectionHeader(Section section, string sectionValue) { string bg = section.backColor; string style = " style=\"font-family: " + ReportFont + "; font-weight:bold; font-size:"; style += getFontSize(section.Level); if (section.GradientBackground) style += "; " + gradientStyle.Replace("BackColor", bg) + "\""; else style += "\" bgcolor='" + bg + "' "; htmlContent.Append("<TR><TD colspan='" + this.ReportFields.Count + "' " + style + " >"); htmlContent.Append(section.TitlePrefix + sectionValue); htmlContent.Append("</TD></TR>" + newline); }
/// <summary> /// Method to write section footer information. /// </summary> /// <param name="section">The section details</param> private void WriteSectionFooter(Section section, Hashtable totalArray) { string cellParams = ""; //Include Total row if specified. if (section.IncludeTotal) { htmlContent.Append("<TR>" + newline); foreach (Field field in this.reportFields) { cellParams = ""; if (field.Width != 0) cellParams += " WIDTH=" + field.Width + " "; cellParams += " style=\"font-family: " + ValuesFont + "; font-size:"; cellParams += getFontSize(section.Level - 1/*+1*/) + "; border-style:outline; border-width:1 \" "; if (totalArray.Contains(field.FieldName)) { htmlContent.Append(" <TD " + cellParams + " align='"+ field.Alignment.ToString() + "'><u>" + Double.Parse(totalArray[field.FieldName].ToString()).ToString(field.FormatString) + "</u></TD> " + newline); } else { htmlContent.Append(" <TD " + cellParams + "> </TD>" + newline); } } htmlContent.Append("</TR>"); } }
/// <summary> /// Method to write Chart and Section data information /// </summary> /// <param name="section">the section details</param> /// <param name="criteria">the section selection criteria</param> private Hashtable WriteSectionDetail(Section section, string criteria) { Hashtable totalArray = new Hashtable(); totalArray = PrepareData(totalArray); if (section == null) { section = new Section(); } try { //Draw DetailHeader htmlContent.Append("<TR>" + newline); string cellParams = String.Empty; foreach (Field field in this.reportFields) { cellParams = " bgcolor='" + Util.GetHTMLColorString(field.HeaderBackColor) + "' "; if (field.Width != 0) cellParams += " WIDTH=" + field.Width + " "; cellParams += " ALIGN='" + field.Alignment.ToString() + "' "; htmlContent.Append(" <TD " + cellParams + " class='ColumnHeaderStyle'><b>" + field.HeaderName + "</b></TD>" + newline); } htmlContent.Append("</TR>" + newline); //Draw Data if (criteria == null || criteria.Trim() == String.Empty) criteria = String.Empty; else criteria = criteria.Substring(3); foreach (DataRow dr in reportSource.Select(criteria)) { htmlContent.Append("<TR>" + newline); foreach (Field field in this.reportFields) { cellParams = " bgcolor='" + Util.GetHTMLColorString(field.BackColor) + "' "; if (field.Width != 0) cellParams += " WIDTH=" + field.Width + " "; //if total field, by default set to RIGHT align. //if(this.TotalFields.Contains(field.FieldName)) if (AutoAlignTotalFields && field.IsTotalField) cellParams += " align='right' "; cellParams += " ALIGN='" + field.Alignment.ToString() + "' "; htmlContent.Append(" <TD " + cellParams + " VALIGN='top' class='DetailData'>"); //Add the field value to the html table if (dr[field.FieldName] is String && field.FormatString.Length > 0) { double value; Double.TryParse((string)dr[field.FieldName], out value); htmlContent.Append(value.ToString(field.FormatString)); } else { htmlContent.Append(dr[field.FieldName].ToString()); } htmlContent.Append("</TD>" + newline); } htmlContent.Append("</TR>" + newline); try { foreach (string totalField in TotalFields) { totalArray[totalField] = float.Parse(totalArray[totalField].ToString()) + float.Parse(dr[totalField].ToString()); } } catch (Exception exp) { //TODO: show error message at total field htmlContent.Append("<p align=CENTER><b>Unable to generate report.<br>" + exp.Message + "</b></p>"); } } } catch (Exception err) { htmlContent.Append("<p align=CENTER><b>Unable to generate report.<br>" + err.Message + "</b></p>"); } return totalArray; }
/// <summary> /// A recursive funtion to write all the section headers, details and footer content. /// </summary> /// <param name="section">the section details</param> /// <param name="criteria">section data selection criteria</param> private Hashtable RecurseSections(Section section, string criteria) { iLevel++; section.Level = iLevel; ArrayList result = GetDistinctValues(this.reportSource, section.GroupBy, criteria); Hashtable ht = new Hashtable(); PrepareData(ht); foreach (object obj in result) { Hashtable sectionTotal = new Hashtable(); PrepareData(sectionTotal); //Construct critiera string to select data for the current section string tcriteria = criteria + "and " + section.GroupBy + "='" + obj.ToString().Replace("'", "''") + "' "; WriteSectionHeader(section, obj.ToString()); //If user not specified to display chart at bottom of the section if (section.IncludeChart && !section.ChartShowAtBottom && !section.isChartCreated) GenerateBarChart(tcriteria, section); if (section.SubSection != null) { sectionTotal = RecurseSections(section.SubSection, tcriteria); iLevel--; } else { sectionTotal = WriteSectionDetail(section, tcriteria); ht = AccumulateTotal(ht, sectionTotal); } //If user specified to display chart at bottom of the section WriteSectionFooter(section, sectionTotal); if (section.IncludeChart && section.ChartShowAtBottom && !section.isChartCreated) GenerateBarChart(tcriteria, section); section.isChartCreated = false; } if (section.Level < 2) htmlContent.Append("<TR><TD colspan='" + this.ReportFields.Count + "'> </TD></TR>"); return ht; }
/// <summary> /// Method to generate BarChart /// </summary> /// <param name="criteria">Section data selection criteria</param> /// <param name="changeOnField">Y-Axis data field</param> /// <param name="valueField">X-Axis data field (Send "count" as value for reporting record count)</param> /// <param name="showBorder">Enable or disable chart border</param> private void GenerateBarChart(string criteria, Section section) { string changeOnField = section.ChartChangeOnField; string valueField = section.ChartValueField; bool showBorder = section.ChartShowBorder; section.isChartCreated = true; string[] colors = { "#ff0000", "#ffff00", "#ff00ff", "#00ff00", "#00ffff", "#0000ff", "#ff0f0f", "#f0f000", "#ff00f0", "#0f00f0" }; htmlContent.Append("<TR><TD colspan='" + this.ReportFields.Count + "' align=CENTER>" + newline); htmlContent.Append("<!--- Chart Table starts here -->" + newline); if (showBorder) { htmlContent.Append("<TABLE cellpadding=4 cellspacing=1 border=0 bgcolor='#f5f5f5' width=550> "); } else { htmlContent.Append("<TABLE border=0 cellspacing=5 width=550>"); } if (criteria.ToUpper().StartsWith(" AND ")) { criteria = criteria.Substring(3); } try { ArrayList result = GetDistinctValuesForChart(this.reportSource, criteria, changeOnField, valueField); ArrayList labels = (ArrayList)result[0]; ArrayList values = (ArrayList)result[1]; float total = 0; foreach (Object obj in values) { total += float.Parse(obj.ToString()); } int ChartWidth = 300; string barTitle = "<TR><TD class='DetailHeader' colspan=3 align='CENTER' width=550><B>ChartTitle</B></TD></TR>"; htmlContent.Append(barTitle.Replace("ChartTitle", section.ChartTitle) + newline); string barTemplate = "<TR><TD Width=150 class='DetailData' align='right'>Label</TD>" + newline; barTemplate += " <TD class='DetailData' Width=" + (ChartWidth + 25) + ">" + newline; barTemplate += " <TABLE cellpadding=0 cellspacing=0 HEIGHT='20' WIDTH=" + ChartWidth + " class='TableStyle'>" + newline; barTemplate += " <TR>" + newline; barTemplate += " <TD Width=ChartWidth>" + newline; barTemplate += " <TABLE class='TableStyle' HEIGHT='20' Width=ChartTWidth border=NOTZERO>" + newline; barTemplate += " <TR>" + newline; barTemplate += " <TD Width=ChartWidth bgcolor='BackColor' Width=ChartWidth style=\"FILTER: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=BackColor,endColorStr=#ffffff); \"></TD>" + newline; barTemplate += " </TR>" + newline; barTemplate += " </TABLE>" + newline; barTemplate += " </TD>" + newline; barTemplate += " <TD class='DetailData'> Percentage</TD>" + newline; barTemplate += " </TR>" + newline; barTemplate += " </TABLE>"; barTemplate += "</TD><TD Width=70 class='DetailData'>Value</TD></TR>"; string barHTemplate = "<TR>" + newline; barHTemplate += " <TD Width=150 class='DetailData' align='right' bgColor='#e5e5e5'>Label</TD>" + newline; barHTemplate += " <TD bgColor='#e5e5e5' class='DetailData' Width=" + (ChartWidth + 25) + ">"; barHTemplate += "Percentage</TD>" + newline; barHTemplate += " <TD Width=25 class='DetailData' bgColor='#e5e5e5'>Value</TD></TR>"; barHTemplate = barHTemplate.Replace("Label", section.ChartLabelHeader); barHTemplate = barHTemplate.Replace("Percentage", section.ChartPercentageHeader); barHTemplate = barHTemplate.Replace("Value", section.ChartValueHeader); htmlContent.Append(barHTemplate + newline); string temp; float width = 0; float val = 0; float percent = 0; int cntColor = 0; for (int i = 0; i < labels.Count; i++) { temp = barTemplate; val = float.Parse(values[i].ToString()); width = float.Parse(values[i].ToString()) * ChartWidth / total; percent = float.Parse(values[i].ToString()) * 100 / total; temp = temp.Replace("Label", labels[i].ToString()); if (percent == 0.0) { temp = temp.Replace("BackColor", "#f5f5f5"); temp = temp.Replace("NOTZERO", "0"); } else { temp = temp.Replace("BackColor", colors[cntColor]); temp = temp.Replace("NOTZERO", "1"); } temp = temp.Replace("ChartTWidth", Decimal.Round((Decimal)(width + 2), 0).ToString()); temp = temp.Replace("ChartWidth", Decimal.Round((Decimal)width, 0).ToString()); temp = temp.Replace("Value", val.ToString()); temp = temp.Replace("Percentage", Decimal.Round((decimal)percent, 2).ToString() + "%"); htmlContent.Append(temp + newline); cntColor++; if (cntColor == 10) cntColor = 0; } } catch (Exception err) { htmlContent.Append("<TR><TD valign=MIDDLE align=CENTER><b>Unable to Generate Chart.<br>" + err.Message + "</b></TD></TR>"); } htmlContent.Append("</TABLE>" + newline); htmlContent.Append("<!--- Chart Table ends here -->"); htmlContent.Append("</TD></TR>"); }