Quantcast
Viewing all articles
Browse latest Browse all 18858

Wpf Reports with Image List

i have created Reports in FlowDocument using Assembly "CodeReason".

and i have listed the studentName and Age in report from DataTable.

Data is came dynamically for that i use following code.

File: "Template/SimpleReport.xaml"

<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:xrd="clr-namespace:CodeReason.Reports.Document;assembly=CodeReason.Reports" PageHeight="29.7cm" PageWidth="21cm" ColumnWidth="21cm"><FlowDocument.Resources><!-- Style for header/footer rows. --><Style x:Key="headerFooterRowStyle" TargetType="{x:Type TableRowGroup}"><Setter Property="FontWeight" Value="DemiBold"/><Setter Property="FontSize" Value="16"/><Setter Property="Background" Value="LightGray"/></Style><!-- Style for data rows. --><Style x:Key="dataRowStyle" TargetType="{x:Type TableRowGroup}"><Setter Property="FontSize" Value="12"/></Style><!-- Style for data cells. --><Style TargetType="{x:Type TableCell}"><Setter Property="Padding" Value="0.1cm"/><Setter Property="BorderBrush" Value="Black"/><Setter Property="BorderThickness" Value="0.01cm"/></Style></FlowDocument.Resources><xrd:ReportProperties Foreground="Red"><xrd:ReportProperties.ReportName>Students Report</xrd:ReportProperties.ReportName><xrd:ReportProperties.ReportTitle>Students Report</xrd:ReportProperties.ReportTitle></xrd:ReportProperties><Section Padding="80,20,40,10" FontSize="12" BreakPageBefore="True"><Paragraph FontSize="24" FontWeight="Bold"> Report</Paragraph><Paragraph>Reports whose headers/colums and data/rows are created on execution time.</Paragraph><Paragraph>Report 1</Paragraph><Table CellSpacing="0" BorderBrush="Black" BorderThickness="0.02cm" ><TableRowGroup Style="{StaticResource headerFooterRowStyle}"><xrd:TableRowForDynamicHeader TableName="Header" /></TableRowGroup><TableRowGroup Style="{StaticResource dataRowStyle}"><xrd:TableRowForDynamicDataTable TableName="Data"/></TableRowGroup></Table></Section></FlowDocument>

Following code wrriten in .cs file in which Document Report viewer

  private void Window_Activated(object sender, EventArgs e)
        {
            if (!_firstActivated) return;

            _firstActivated = false;

            try
            {
                ReportDocument reportDocument = new ReportDocument();

                StreamReader reader = new StreamReader(new FileStream(@"Templates\SimpleReport.xaml", FileMode.Open, FileAccess.Read));
                reportDocument.XamlData = reader.ReadToEnd();
                reportDocument.XamlImagePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Templates\");
                reader.Close();
                ReportData data = new ReportData();
                // REPORT 1 DATA


                StudentViewModel[] studentViewmodel = MainWindowViewModel.Current.Students.ToArray();
               

                DataTable tableHeader;
                DataTable tableData;
                object[] obj;
                tableHeader = new DataTable("Header");
                tableData = new DataTable("Data");

                tableHeader.Columns.Add();
                tableHeader.Rows.Add(new object[] { "Student GRNo" });
                tableHeader.Rows.Add(new object[] { "First Name" });
                tableHeader.Rows.Add(new object[] { "Last Name" });
                tableHeader.Rows.Add(new object[] { "Photo" });
                tableData.Columns.Add();
                tableData.Columns.Add();
                tableData.Columns.Add();
                tableData.Columns.Add();
                obj = new object[4];
                for (int i = 0; i < studentViewmodel.Count(); i++)
                {
                    obj[0] = studentViewmodel[i].StudentGRNo as object;
                    obj[1] = studentViewmodel[i].FirstName as object;
                    obj[2] = studentViewmodel[i].LastName as object;
                    obj[3] = studentViewmodel[i].Photo as object;
                    tableData.Rows.Add(obj);
                }

                
                data.DataTables.Add(tableData);
                data.DataTables.Add(tableHeader);

                // REPORT 2 DATA
                tableHeader = new DataTable("Header2");
                tableData = new DataTable("Data2");

                tableHeader.Columns.Add();
                tableHeader.Rows.Add(new object[] { "Service" });
                tableHeader.Rows.Add(new object[] { "Amount" });
                tableData.Columns.Add();
                tableData.Columns.Add();
                obj = new object[2];
                for (int i = 0; i < 15; i++)
                {

                    obj[0] = String.Format("Service offered. Nº{0}", i);
                    obj[1] = i;
                    tableData.Rows.Add(obj);
                }

                data.DataTables.Add(tableData);
                data.DataTables.Add(tableHeader);

                documentViewer.DataContext = new MyDataContext { LoginUserName = "TestUserName" };
                XpsDocument xps = reportDocument.CreateXpsDocument(data);   
                documentViewer.Document = xps.GetFixedDocumentSequence();   
            }
            catch (Exception ex)
            {
                // show exception
                MessageBox.Show(ex.Message + "\r\n\r\n" + ex.GetType() + "\r\n" + ex.StackTrace, ex.GetType().ToString(), MessageBoxButton.OK, MessageBoxImage.Stop);
            }
        }

now i want to include Photo of Each students in Student List



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>