原創(chuàng)|使用教程|編輯:龔雪|2013-12-09 10:27:54.000|閱讀 810 次
概述:SharpShooter Reports.WPF是原生的基于XMAL的報表控件,無論是設(shè)計簡單的標(biāo)準(zhǔn)格式報表還是復(fù)雜的針對特殊行業(yè)的報表它都能勝任。本文主要介紹了SharpShooter Reports.WPF的一個報表創(chuàng)建的實例。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
安裝
首先下載SharpShooter Report.WPF,然后運行SharpShooterReports.msi。
在“Additional Options”選擇框中勾選如下兩項:
授權(quán)
如果你已經(jīng)有許可證,從開始菜單啟動許可證管理器安裝許可證。
添加許可證請按“Add from file”按鈕,然后選擇你下載的*. elic。按“Close”按鈕關(guān)閉許可證管理器。
如果沒有許可證,則會彈出“Trial”窗口,進入試用模式。
試用模式下工作時在視圖設(shè)計器中會顯示水印。
激活
如果你沒有使用過SharpShooter products,你需要在第一次運行產(chǎn)品時激活改軟件。請在如下的輸入框中輸入你的姓名和電子郵件來激活該產(chǎn)品。
填寫完ActivationForm后,該產(chǎn)品就激活了。
Step 1. 應(yīng)用程序創(chuàng)建
打開Visual Studio。創(chuàng)建一個新的WPF應(yīng)用程序項目(使用.NET Framework 4)。
如果你使用客戶端配置文件作為默認(rèn)框架,你需要在項目屬性中修改它為完整版本的框架。
Step 2. 為報表添加模板
為項目添加一個新東西——SharpShooter Reports Template。
Step 3. 添加引用
為項目的下列組件添加引用:
Step 4. 添加XAML代碼
添加如下代碼到MainWindow.xaml中:
<Window x:Class="WPFSample.MainWindow" xmlns="//schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="//schemas.microsoft.com/winfx/2006/xaml" xmlns:reports="clr-namespace:PerpetuumSoft.Reporting.WPF;assembly=PerpetuumSoft.Reporting.WPF" Title="ReportViewer" Height="auto" Width="auto"> <!-----以上的添加部分為 xmlns:reports="clr-namespace:PerpetuumSoft.Reporting.WPF;assembly=PerpetuumSoft.Reporting.WPF" Title="ReportViewer" Height="auto" Width="auto" ------> <Grid> <!-----以下是添加部分------> <reports:ReportViewer x:Name="reportViewer"> <reports:ReportViewer.Source> <reports:ReportSource x:Name="reportSource" Source="c:\Projects\WPFSample\WPFSample\ReportTemplate1.rst"> </reports:ReportSource> </reports:ReportViewer.Source> </reports:ReportViewer> <!-----end------> </Grid> </Window>
Step 5. 創(chuàng)建和填充數(shù)據(jù)源
使用Business Objects的列表作為數(shù)據(jù)源。為項目添加一個新的Employee類。這個類的結(jié)構(gòu)如下:
internal class Employee { public string FirstName { get; set; } public string LastName { get; set; } public string Title { get; set; } public string Phone { get; set; } public DateTime BirthDate { get; set; } public string Address { get; set; } }
填寫產(chǎn)品的集合和添加數(shù)據(jù)源集合到reportSource(例如,在加載窗體事件處理程序中)。
List<Employee> employeeList = new List<Employee>(); employeeList.Add(new Employee() { FirstName = "Maria", LastName = "Anders" Title = "Sales Representative", Phone = "(71)555-5598", BirthDate = new DateTime(1960, 5, 29), Address = "Obere str. 57" }); employeeList.Add(new Employee() { FirstName = "Ana", LastName = "Trujillo", Title = "Owner", Phone = "(5)555-4729", BirthDate = new DateTime(1971, 7, 1), Address = "Avda. de la Constitution 222" }); employeeList.Add(new Employee() { FirstName = "Antonio", LastName = "Moreno", Title = "Owner", Phone = "(5)555-3932", BirthDate = new DateTime(1969, 3, 12), Address = "Mataderos 2312" }); reportSource.DataSources.Add("EmployeeList", employeeList): reportViewer.RenderDocument();
Step 6. 編輯報表模板
你需要編輯報表,并且有可能是在運行時或設(shè)計時編輯報表。編輯報表模板更方便是在運行時。
為應(yīng)用程序添加運行時修改模板的功能。把設(shè)計模板按鈕放在表單上。為該按鈕的單擊事件添加如下的處理程序:
private void designTemplate_Click(object sender, RoutedEventArgs e) { reportSource.DesignTemplate(); reportViewer.RenderDocument(); }
如果你想在設(shè)計時編輯報表的模板,請在Solution Explorer中雙擊相應(yīng)的項目。
Step 7. 設(shè)計報表
運行該應(yīng)用程序,然后按Design Template按鈕。在設(shè)計器中您可以選擇程序語言:C#、Visual Basic或自定義語言。在文檔的ScriptLanguage屬性中選擇你需要的。本例中使用的是C#。
在這個例子中,報表是使用Table Wizard的簡化報表創(chuàng)建過程創(chuàng)建的。單擊Insert tab上的表格按鈕。在打開的Table Wizard中選擇數(shù)據(jù)源。
在選擇字段區(qū)域選擇FirstName、LastName、Phone 和 Address。單擊Next>。使用默認(rèn)字段的設(shè)置,單擊Next>。指定根據(jù)LastName和FirstName排序。單擊Finish(完成)。
然后,你可以根據(jù)你的需要編輯表格。例如,你可以更改文本的對齊方式,高亮顯示標(biāo)題等:
Step 8. 查看報表
保存該模板并關(guān)閉設(shè)計器。你創(chuàng)建的報表就顯示在ReportViewer中了。
如果你不想你的最終用戶編輯模板,你可以移除設(shè)計模板按鈕,更改ReportSource.Source到資源路徑(被添加的模板在默認(rèn)情況下是有資源類型的):
<reports:ReportViewer x:Name="reportViewer" Grid.Row="1"> <reports:ReportViewer.Source> <reports:ReportSource x:Name="reportSource" Source="/WPFSample;component/ReportTemplate1.rst"/> </reports:ReportViewer.Source> </reports:ReportViewer>
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)