原創|其它|編輯:郝浩|2011-05-10 13:53:14.000|閱讀 1959 次
概述:我不知道在silvelright中對于report報表有什么好的解決方案,除了devexpress,telerik這些第3方的公司開發的 silverlight 報表控件之外。我在google瘋狂檢索,沒有找到像樣的開源的解決方案。在一番比較群橫還是選擇devexpress的報表控件。下面的內容就是利用devexpress report來完成一個報表:
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
我不知道在silvelright中對于report報表有什么好的解決方案,除了devexpress,telerik這些第3方的公司開發的 silverlight 報表控件之外。我在google瘋狂檢索,沒有找到像樣的開源的解決方案。在一番比較群橫還是選擇devexpress的報表控件。
下面的內容就是利用devexpress report來完成一個報表:
具體來將有2種方式
1)報表和silverlight app在2個不同windows 窗口
2)報表嵌在silverlight page中
無論哪種方式都是看,具體的需求。
首先在silverlight host web里面加入Report.svc:
/// <summary>
/// IReportService
/// </summary>
[ServiceContract]
public interface IReportService : DevExpress.XtraReports.Service.IReportService {
[OperationContract]
DocumentId GetReportsByName(string reportName);
}
/// <summary>
/// ReportService
/// </summary>
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ReportService : DevExpress.XtraReports.Service.ReportService, IReportService {
public ReportService() {
}
const string filePath = "~/Reports";
public byte[] GetReportFile(string path)
{
return File.ReadAllBytes(path);
}
private static string GetAbsulotePath(string path)
{
return "\\" + path;
}
public DocumentId GetReportsByName(string reportName)
{
//XtraReport report = new XtraReport();
string path=HttpContext.Current.Server.MapPath(filePath + "http://" + reportName+".repx");
byte[] bytes=GetReportFile(path);
XtraReport report = XtraReport.FromStream(new MemoryStream(bytes), true);
//report.DataSource = GetData();
DocumentId doc = StartBuild(report);
return doc;
}
}
Silverlight Project 中的頁面:xaml
<Grid x:Name="LayoutRoot"> <StackPanel Orientation="Vertical"> <Button Content="button" Width="50" Height="20" Click="Button_Click"></Button> <my:DocumentPreview Name="documentPreview1" /> </StackPanel> </Grid>
放置一個DocumentPreView,當button點擊,將報表通過DocumentPreView渲染,mainPage.cs
private void Button_Click(object sender, RoutedEventArgs e)
{
ReportService.ReportServiceClient client = new ReportServiceClient();
client.GetReportsByNameCompleted += new EventHandler<GetReportsByNameCompletedEventArgs>(client_GetReportsByNameCompleted);
client.GetReportsByNameAsync("XtraReport1");
}
void client_GetReportsByNameCompleted(object sender, GetReportsByNameCompletedEventArgs e)
{
ReportPreviewModel previewModel = new ReportPreviewModel(ServiceUri.AbsoluteUri);
previewModel.ProcessDocument(e.Result);
documentPreview1.Model = previewModel;
//throw new NotImplementedException();
}
const string RelativeServiceUrl = "/ReportService.svc";
static Uri serviceAbsoluteUri;
internal static Uri ServiceUri
{
get
{
if (serviceAbsoluteUri == null)
serviceAbsoluteUri = new Uri(Application.Current.Host.Source, ".." + RelativeServiceUrl);
return serviceAbsoluteUri;
}
}
剩下要注意的是ServiceReference.ClientConfig:
<endpoint address="http://localhost:53609/ReportService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IReportService"
contract="ReportService.IReportService" name="BasicHttpBinding_IReportService" />
contract是 ReportService.IReportService
這樣就是一個簡單的devexpress report
(慧都控件網版權所有,轉載請注明出處,否則追究法律責任)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:博客園