123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- using FastReport;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Windows;
- namespace DataSources
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- private int[] _array;
- private List<Category> 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<Category>();
- 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();
- }
- }
- }
- }
|