Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
<Project>{355CAFF3-F806-4194-BE54-2F7640463CED}</Project>
<Name>DoddleReport.AbcPdf</Name>
</ProjectReference>
<ProjectReference Include="..\DoddleReport.iTextSharp\DoddleReport.iTextSharp.csproj">
<Project>{347d0716-0297-4866-9fd5-5e019b51c408}</Project>
<Name>DoddleReport.iTextSharp</Name>
</ProjectReference>
<ProjectReference Include="..\DoddleReport.OpenXml\DoddleReport.OpenXml.csproj">
<Project>{0646C575-0EA6-4331-809C-10DC000929F3}</Project>
<Name>DoddleReport.OpenXml</Name>
Expand All @@ -94,6 +98,11 @@
<Name>DoddleReport</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Resources\Logomakr.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
29 changes: 16 additions & 13 deletions src/DoddleReport.Sample.WinForms/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

179 changes: 179 additions & 0 deletions src/DoddleReport.Sample.WinForms/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using DoddleReport.Sample.Web.Models;
using System.IO;
using System.Diagnostics;
using System.Drawing;
using DoddleReport.Sample.WinForms.Properties;
using DoddleReport.Writers;

namespace DoddleReport.Sample.WinForms
{
Expand All @@ -20,6 +23,27 @@ private void Form1_Load(object sender, System.EventArgs e)
}

private void button1_Click(object sender, System.EventArgs e)
{
if (cmbReportType.Text == "Excel (Open XML)")
{
RenderExcel();
}
else if (cmbReportType.Text == "PDF with title image (ITextSharp)")
{
RenderPdfWithImage();
}
else if (cmbReportType.Text == "HTML with custom title style & image")
{
RenderHtmlWithImage();
}
else if (cmbReportType.Text == "Excel using HTML")
{
RenderExcelFromHtml();
}

}

private static void RenderExcel()
{
var query = DoddleProductRepository.GetAll();
var totalProducts = query.Count;
Expand Down Expand Up @@ -53,5 +77,160 @@ private void button1_Click(object sender, System.EventArgs e)

Process.Start("Report.xlsx");
}

private static void RenderPdfWithImage()
{
var query = DoddleProductRepository.GetAll();
var totalProducts = query.Count;
var totalOrders = query.Sum(p => p.OrderCount);

// Create the report and turn our query into a ReportSource
var report = new Report(query.ToReportSource(), new DoddleReport.iTextSharp.PdfReportWriter());

// Customize the Text Fields
report.TextFields.Title = "Products Report";
report.TextFields.SubTitle = "This is a sample report showing how Doddle Report works";
report.TextFields.Footer = "Copyright 2011 &copy; The Doddle Project";
report.TextFields.Header = string.Format(@"
Report Generated: {0}
Total Products: {1}
Total Orders: {2}
Total Sales: {3:c}", DateTime.Now, totalProducts, totalOrders, totalProducts * totalOrders);

// Render hints allow you to pass additional hints to the reports as they are being rendered
report.RenderHints.BooleanCheckboxes = true;

report.RenderHints["TitleStyle"] = new ReportTitleStyle
{
Bold = true,
FontSize = 18,
HorizontalAlignment = HorizontalAlignment.Left,
ImageWidthPercentage = 20, //Image will take up 20% with page width
Image = new ReportImage
{
ImageData = File.ReadAllBytes(@"./Resources/Logomakr.png"),
Width = 75,
Height = 75
}
};




// Customize the data fields
report.DataFields["Id"].Hidden = true;
report.DataFields["Price"].DataFormatString = "{0:c}";
report.DataFields["LastPurchase"].DataFormatString = "{0:d}";

using (var stream = File.Create("Report.pdf"))
{
report.WriteReport(stream);
}

Process.Start("Report.pdf");
}


private static void RenderHtmlWithImage()
{
var query = DoddleProductRepository.GetAll();
var totalProducts = query.Count;
var totalOrders = query.Sum(p => p.OrderCount);

// Create the report and turn our query into a ReportSource
var report = new Report(query.ToReportSource(), new HtmlReportWriter());

// Customize the Text Fields
report.TextFields.Title = "Products Report";
report.TextFields.SubTitle = "This is a sample report showing how Doddle Report works";
report.TextFields.Footer = "Copyright 2011 &copy; The Doddle Project";
report.TextFields.Header = string.Format(@"
Report Generated: {0}
Total Products: {1}
Total Orders: {2}
Total Sales: {3:c}", DateTime.Now, totalProducts, totalOrders, totalProducts * totalOrders);

// Render hints allow you to pass additional hints to the reports as they are being rendered
report.RenderHints.BooleanCheckboxes = true;

report.RenderHints["TitleStyle"] = new ReportTitleStyle
{
Bold = true,
Underline = true,
FontSize = 18,
HorizontalAlignment = HorizontalAlignment.Left,
ForeColor = Color.SteelBlue,
Image = new ReportImage
{
ImageData = File.ReadAllBytes(@"./Resources/Logomakr.png"),
Width = 150,
Height = 100
}
};

report.RenderHints["SubTitleStyle"] = new ReportStyle
{
Bold = true,
FontSize = 12,
HorizontalAlignment = HorizontalAlignment.Left,
ForeColor = Color.SteelBlue
};

report.RenderHints["HeaderStyle"] = new ReportStyle
{
Italic = true,
FontSize = 10,
HorizontalAlignment = HorizontalAlignment.Left,
ForeColor = Color.Salmon
};

// Customize the data fields
report.DataFields["Id"].Hidden = true;
report.DataFields["Price"].DataFormatString = "{0:c}";
report.DataFields["LastPurchase"].DataFormatString = "{0:d}";

using (var stream = File.Create("Report.html"))
{
report.WriteReport(stream);
}

Process.Start("Report.html");
}

private static void RenderExcelFromHtml()
{
var query = DoddleProductRepository.GetAll();
var totalProducts = query.Count;
var totalOrders = query.Sum(p => p.OrderCount);

// Create the report and turn our query into a ReportSource
var report = new Report(query.ToReportSource(), new ExcelReportWriter());

// Customize the Text Fields
report.TextFields.Title = "Products Report";
report.TextFields.SubTitle = "This is a sample report showing how Doddle Report works";
report.TextFields.Footer = "Copyright 2011 &copy; The Doddle Project";
report.TextFields.Header = string.Format(@"
Report Generated: {0}
Total Products: {1}
Total Orders: {2}
Total Sales: {3:c}", DateTime.Now, totalProducts, totalOrders, totalProducts * totalOrders);

// Render hints allow you to pass additional hints to the reports as they are being rendered
report.RenderHints.BooleanCheckboxes = true;

// Customize the data fields
report.DataFields["Id"].Hidden = true;
report.DataFields["Price"].DataFormatString = "{0:c}";
report.DataFields["LastPurchase"].DataFormatString = "{0:d}";

using (var stream = File.Create("Report.xls"))
{
report.WriteReport(stream);
}

Process.Start("Report.xls");
}

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions src/DoddleReport.Sample.WinForms/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
Expand All @@ -60,6 +60,7 @@
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
Expand All @@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
Expand All @@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
Expand All @@ -109,9 +112,9 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading