Wpf и программное формирование отчета
В общем вопрос в следующем: у меня есть программа которая через Sql выводит таблицу в DataGrid вот код программы:
using System;
using System.Data.SqlClient;
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.Navigation;
using System.Windows.Shapes;
using System.Data;
using FastReport;
using FastReport.Data;
using System.ComponentModel;
namespace WpfDemo
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private DataSet _set = new DataSet();
private Report report = new Report();
public MainWindow()
{
InitializeComponent();
}
SqlConnection connection;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
connection = new SqlConnection("Data source=Moroz-ПК\\Moroz;Initial catalog=LttBase;Integrated security=true");
connection.StateChange += new StateChangeEventHandler(TextBoxMessage);
SqlCommand comand = new SqlCommand("select * from Abc", connection);
DataSet _set = new DataSet();
connection.Open();
SqlDataAdapter reader = new SqlDataAdapter(comand);
reader.Fill(_set);
connection.Close();
//textBox1.Text = connection.State.ToString();
dataGrid1.ItemsSource = _set.Tables[0].DefaultView;
/* DataTable table = new DataTable();
table.TableName = "Abc";
_set.Tables.Add(table);*/
// table.Load(_set);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
SqlCommand _addCommnd = new SqlCommand("insert into abc ( firstname, lastname, age, sex, number) values ( @firstname, @lastname, @age, @sex, @number)", connection);
SqlParameter par1 = new SqlParameter();
par1.ParameterName = "@firstname";
par1.Value = ((DataRowView)dataGrid1.Items[dataGrid1.SelectedIndex]).Row.ItemArray[0];
SqlParameter par2 = new SqlParameter();
par2.ParameterName = "@lastname";
par2.Value = ((DataRowView)dataGrid1.Items[dataGrid1.SelectedIndex]).Row.ItemArray[1];
SqlParameter par3 = new SqlParameter();
par3.ParameterName = "@age";
par3.Value = ((DataRowView)dataGrid1.Items[dataGrid1.SelectedIndex]).Row.ItemArray[2];
SqlParameter par4 = new SqlParameter();
par4.ParameterName = "@sex";
par4.Value = ((DataRowView)dataGrid1.Items[dataGrid1.SelectedIndex]).Row.ItemArray[3];
SqlParameter par5 = new SqlParameter();
par5.ParameterName = "@number";
par5.Value = ((DataRowView)dataGrid1.Items[dataGrid1.SelectedIndex]).Row.ItemArray[4];
_addCommnd.Parameters.Add(par1);
_addCommnd.Parameters.Add(par2);
_addCommnd.Parameters.Add(par3);
_addCommnd.Parameters.Add(par4);
_addCommnd.Parameters.Add(par5);
connection.Open();
_addCommnd.ExecuteNonQuery();
connection.Close();
// textBox1.Text = connection.State.ToString();
}
public void TextBoxMessage(object ob, StateChangeEventArgs arg)
{
//textBox1.Text = connection.State.ToString();
MessageBox.Show(connection.State.ToString());
}
private void button2_Click(object sender, RoutedEventArgs e)
{
report.RegisterData(_set, "Abc");
//report.GetDataSource("Abc").Enabled = true;
report.Show();
report.Dispose();
}
}
}
как программно передать в фаст таблицу которую я вывожу в DataGrid? чтоб моя табличка вывелась в виде отчета в фасте?
using System;
using System.Data.SqlClient;
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.Navigation;
using System.Windows.Shapes;
using System.Data;
using FastReport;
using FastReport.Data;
using System.ComponentModel;
namespace WpfDemo
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private DataSet _set = new DataSet();
private Report report = new Report();
public MainWindow()
{
InitializeComponent();
}
SqlConnection connection;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
connection = new SqlConnection("Data source=Moroz-ПК\\Moroz;Initial catalog=LttBase;Integrated security=true");
connection.StateChange += new StateChangeEventHandler(TextBoxMessage);
SqlCommand comand = new SqlCommand("select * from Abc", connection);
DataSet _set = new DataSet();
connection.Open();
SqlDataAdapter reader = new SqlDataAdapter(comand);
reader.Fill(_set);
connection.Close();
//textBox1.Text = connection.State.ToString();
dataGrid1.ItemsSource = _set.Tables[0].DefaultView;
/* DataTable table = new DataTable();
table.TableName = "Abc";
_set.Tables.Add(table);*/
// table.Load(_set);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
SqlCommand _addCommnd = new SqlCommand("insert into abc ( firstname, lastname, age, sex, number) values ( @firstname, @lastname, @age, @sex, @number)", connection);
SqlParameter par1 = new SqlParameter();
par1.ParameterName = "@firstname";
par1.Value = ((DataRowView)dataGrid1.Items[dataGrid1.SelectedIndex]).Row.ItemArray[0];
SqlParameter par2 = new SqlParameter();
par2.ParameterName = "@lastname";
par2.Value = ((DataRowView)dataGrid1.Items[dataGrid1.SelectedIndex]).Row.ItemArray[1];
SqlParameter par3 = new SqlParameter();
par3.ParameterName = "@age";
par3.Value = ((DataRowView)dataGrid1.Items[dataGrid1.SelectedIndex]).Row.ItemArray[2];
SqlParameter par4 = new SqlParameter();
par4.ParameterName = "@sex";
par4.Value = ((DataRowView)dataGrid1.Items[dataGrid1.SelectedIndex]).Row.ItemArray[3];
SqlParameter par5 = new SqlParameter();
par5.ParameterName = "@number";
par5.Value = ((DataRowView)dataGrid1.Items[dataGrid1.SelectedIndex]).Row.ItemArray[4];
_addCommnd.Parameters.Add(par1);
_addCommnd.Parameters.Add(par2);
_addCommnd.Parameters.Add(par3);
_addCommnd.Parameters.Add(par4);
_addCommnd.Parameters.Add(par5);
connection.Open();
_addCommnd.ExecuteNonQuery();
connection.Close();
// textBox1.Text = connection.State.ToString();
}
public void TextBoxMessage(object ob, StateChangeEventArgs arg)
{
//textBox1.Text = connection.State.ToString();
MessageBox.Show(connection.State.ToString());
}
private void button2_Click(object sender, RoutedEventArgs e)
{
report.RegisterData(_set, "Abc");
//report.GetDataSource("Abc").Enabled = true;
report.Show();
report.Dispose();
}
}
}
как программно передать в фаст таблицу которую я вывожу в DataGrid? чтоб моя табличка вывелась в виде отчета в фасте?
Комментарии