Skip to content

Instantly share code, notes, and snippets.

@jrwren
Created December 6, 2011 20:43
Show Gist options
  • Select an option

  • Save jrwren/1439912 to your computer and use it in GitHub Desktop.

Select an option

Save jrwren/1439912 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Bars;
using DevExpress.Xpf.Layout.Core;
using DevExpress.Xpf.Docking;
namespace DXWPFApplication1
{
public partial class MainWindow : DXWindow
{
public MainWindow()
{
InitializeComponent();
}
void makepdf_click(object sender, RoutedEventArgs routedEventArgs)
{
new PdfWriter().Write().Open();
}
}
public class ReportSection
{
public string Title { get; set; }
public List<ReportItem> Items { get; set; }
public bool MultiColumn { get; set; }
/// <summary>
/// Initializes a new instance of the ReportSection class.
/// </summary>
public ReportSection()
{
Items = new List<ReportItem>();
}
}
public class ReportItem
{
public string BulletItem { get; set; }
public static implicit operator ReportItem(string @string) { return new ReportItem { BulletItem = @string }; }
public static implicit operator string(ReportItem ri) { return ri.BulletItem; }
}
public class ReportSectionCollection : List<ReportSection>
{
}
public class PdfWriter
{
ReportSectionCollection reportSectionCollection;
public PdfWriter Write()
{
reportSectionCollection = new ReportSectionCollection();
mapResultsToReport();
var report = new XtraReport();
report.DataSource = reportSectionCollection;
report.ExportToPdf("report.pdf");
return this;
}
public void Open() { System.Diagnostics.Process.Start("report.pdf"); }
void mapResultsToReport()
{
Top5_one();
three();
two();
five();
four();
six();
seven();
}
private void Top5_one()
{
string tableTitle = "This is my first section and this is the title. See, nice eh?";
ReportSection newReportSection = new ReportSection { Title = tableTitle };
reportSectionCollection.Add(newReportSection);
new[] { "Thing 1", "Thing 2", "Thing 3", "Thing 4","Thing 5" }.ToList().ForEach(i =>
{
newReportSection.Items.Add(i);
});
}
private void two()
{
string tableTitle = "And here you thought There was only thing 1 and 2";
ReportSection newReportSection = new ReportSection { Title = tableTitle, MultiColumn= true };
reportSectionCollection.Add(newReportSection);
new[] { "nope", "There are lots more things", "not just ", "Thing 3", "Thing 4", "Thing 5", "but other things along","with the cat" }
.ToList().ForEach(i =>
{
newReportSection.Items.Add(i);
});
}
private void three()
{
string tableTitle = "We keep on going and going to places";
ReportSection newReportSection = new ReportSection { Title = tableTitle, MultiColumn = true };
reportSectionCollection.Add(newReportSection);
new[] { "seas", "new islands", "our moon", "planets", "other moons", "maybe other solar systems", "but not for a long time", "with the cat" }
.ToList().ForEach(i =>
{
newReportSection.Items.Add(i);
});
}
private void four()
{
string tableTitle = "Lorem Ipsum is boring. This is much more fun. I like making silly things to file this report.";
ReportSection newReportSection = new ReportSection { Title = tableTitle, MultiColumn=false };
reportSectionCollection.Add(newReportSection);
System.Text.RegularExpressions.Regex.Split(
@"
", "\n")
.ToList().ForEach(i =>
{
newReportSection.Items.Add(i);
});
}
private void five()
{
string tableTitle = "places are nice, but how is fun too";
ReportSection newReportSection = new ReportSection { Title = tableTitle };
reportSectionCollection.Add(newReportSection);
new[] { "rockets", "solar sails", "warp drive", "FTL", "wormhole", "stargate", "Card's silly 'in and out'", }
.ToList().ForEach(i =>
{
newReportSection.Items.Add(i);
});
}
private void six()
{
string tableTitle = "Civil wars over teh world";
ReportSection newReportSection = new ReportSection { Title = tableTitle };
reportSectionCollection.Add(newReportSection);
new[] { "powerful unions interfere", "its a dangerous situation for us all",
"atomic bombs are ready to be launched", "it's time we unite",
"its time we scan the universe", "its time to move on", }
.ToList().ForEach(i =>
{
newReportSection.Items.Add(i);
});
}
private void seven()
{
string tableTitle = "We have the technology for destruction";
ReportSection newReportSection = new ReportSection { Title = tableTitle };
reportSectionCollection.Add(newReportSection);
new[] { "Can we use that knowledge to survive?", "Reverse the process and make something great",
"Our calling is not to die", "We have to find a way to survive",
"We seek Colony 5",
"The time is right",
"Last chance for mankind",
"To survive", "its time to move on", }
.ToList().ForEach(i =>
{
newReportSection.Items.Add(i);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment