using FastReport;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
namespace DataSources
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
private int[] _array;
private List businessObject;
private DataSet dataSet;
public MainWindow()
{
InitializeComponent();
CreateArray();
CreateBusinessObject();
CreateDataSet();
}
private void CreateArray()
{
_array = new int[10];
for (int i = 0; i < 10; i++)
{
_array[i] = i + 1;
}
}
private void CreateBusinessObject()
{
businessObject = new List();
var category = new Category("Beverages", "Soft drinks, coffees, teas, beers");
category.Products.Add(new Product("Chai", 18m));
category.Products.Add(new Product("Chang", 19m));
category.Products.Add(new Product("Ipoh coffee", 46m));
businessObject.Add(category);
category = new Category("Confections", "Desserts, candies, and sweet breads");
category.Products.Add(new Product("Chocolade", 12.75m));
category.Products.Add(new Product("Scottish Longbreads", 12.5m));
category.Products.Add(new Product("Tarte au sucre", 49.3m));
businessObject.Add(category);
category = new Category("Seafood", "Seaweed and fish");
category.Products.Add(new Product("Boston Crab Meat", 18.4m));
category.Products.Add(new Product("Red caviar", 15m));
businessObject.Add(category);
}
private void CreateDataSet()
{
// create simple dataset with one table
dataSet = new DataSet();
var table = new DataTable();
table.TableName = "Employees";
dataSet.Tables.Add(table);
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Rows.Add(1, "Andrew Fuller");
table.Rows.Add(2, "Nancy Davolio");
table.Rows.Add(3, "Margaret Peacock");
}
private void DataFromArray_New_Click(object sender, RoutedEventArgs e)
{
// create report instance
using (var report = new Report())
{
// register the array
report.RegisterData(_array, "Array");
report.GetDataSource("Array").Enabled = true;
// design the report
report.Design();
}
}
private void DataFromArray_Existing_Click(object sender, RoutedEventArgs e)
{
// create report instance
using (var report = new Report())
{
// load the existing report
report.Load("report_from_array.frx");
// register the array
report.RegisterData(_array, "Array");
// run the report
report.Show();
}
}
private void DataFromBO_New_Click(object sender, RoutedEventArgs e)
{
// create report instance
using (var report = new Report())
{
// register the business object (and up to 3 nested data sources)
report.RegisterData(businessObject, "Categories", 3);
report.GetDataSource("Categories").Enabled = true;
// design the report. Enable the data source in the "Report|Choose Report Data..." window
report.Design();
}
}
private void DataFromBO_Existing_Click(object sender, RoutedEventArgs e)
{
// create report instance
using (var report = new Report())
{
// load the existing report
report.Load("report_from_bo.frx");
// register the business object
report.RegisterData(businessObject, "Categories");
// run the report
report.Show();
}
}
private void DataFromDataSet_New_Click(object sender, RoutedEventArgs e)
{
// create report instance
using (var report = new Report())
{
// register the dataset
report.RegisterData(dataSet);
// enable the "Employees" datasource.
// You can also do this in the "Report|Choose Report Data..." menu.
report.GetDataSource("Employees").Enabled = true;
// design the report. Enable the data source in the "Report|Choose Report Data..." window
report.Design();
}
}
private void DataFromDataSet_Existing_Click(object sender, RoutedEventArgs e)
{
// create report instance
using (var report = new Report())
{
// load the existing report
report.Load("report_from_dataset.frx");
// register the dataset
report.RegisterData(dataSet);
// run the report
report.Show();
}
}
}
}