using System;
using System.Data;
using System.Drawing;
//using System.Windows.Forms;
using ReportPrinting;
namespace ReportDocumentTesting
{
/// <summary>
/// A sample of grades
/// </summary>
public class ReportTest13 : IReportMaker
{
public void MakeDocument(ReportDocument reportDocument)
{
TextStyle.ResetStyles();
ReportBuilder builder = new ReportBuilder (reportDocument);
builder.StartLinearLayout (Direction.Vertical);
TextStyle.TableRow.MarginTop = 0.05f;
TextStyle.TableRow.MarginBottom = 0.03f;
TextStyle.TableHeader.MarginBottom = 0.03f;
builder.AddPageHeader ("Science 101", String.Empty, DateTime.Now.ToLongDateString());
builder.AddFormatExpression (typeof (float), DecimalFormatString);
DataTable roster = GetRoster();
DataView dv;
if (roster == null)
{
dv = null;
System.Windows.Forms.MessageBox.Show ("oops... there was a problem loading the grades xml file.");
}
else
{
dv = roster.DefaultView;
}
builder.DefaultTablePen = null; // turn of all lines that aren't explicitly enabled later
builder.AddTable (dv, true);
builder.Table.InnerPenHeaderBottom = reportDocument.NormalPen;
builder.Table.InnerPenRow = new Pen (Color.Gray, reportDocument.ThinPen.Width);
builder.Table.OuterPenBottom = new Pen (Color.Gray, reportDocument.ThinPen.Width);
builder.Table.HorizontalAlignment = ReportPrinting.HorizontalAlignment.Center;
builder.AddColumn ("Name", "Name", 2.5f, false, false);
float width = 0.7f;
foreach (DataColumn col in roster.Columns)
{
if (col.ColumnName.StartsWith (catPrefix))
{
string catName = GetCatName (col.ColumnName);
builder.AddColumn (col, catName, width, false, false, HorizontalAlignment.Right);
}
}
builder.AddColumn ("Average", "Avg", width, false, false, HorizontalAlignment.Right);
builder.FinishLinearLayout ();
}
DataTable GetRoster()
{
DataSet ds = new DataSet();
MainForm.GradesXml.Position = 0;
ds.ReadXml (MainForm.GradesXml);
if (ds.Tables.Count >= 1)
{
return ds.Tables[0];
}
return null;
}
const string catPrefix = "Cat_";
string GetCatName (string colName)
{
string name = String.Empty;
if (colName.StartsWith(catPrefix))
{
name = colName.Replace (catPrefix, String.Empty);
}
return name;
}
static int decimalPlacesDisplayed = 1;
/// <summary>
/// Gets or sets the number of decimal places displayed
/// </summary>
public static int DecimalDisplayed
{
get { return decimalPlacesDisplayed; }
set { decimalPlacesDisplayed = value; }
}
/// <summary>
/// Gets a format string for floating point numbers
/// </summary>
public static string DecimalFormatString
{
get { return "F" + DecimalDisplayed; }
}
}
}