原創(chuàng)|其它|編輯:郝浩|2011-05-10 13:53:14.000|閱讀 1959 次
概述:我不知道在silvelright中對(duì)于report報(bào)表有什么好的解決方案,除了devexpress,telerik這些第3方的公司開(kāi)發(fā)的 silverlight 報(bào)表控件之外。我在google瘋狂檢索,沒(méi)有找到像樣的開(kāi)源的解決方案。在一番比較群橫還是選擇devexpress的報(bào)表控件。下面的內(nèi)容就是利用devexpress report來(lái)完成一個(gè)報(bào)表:
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
我不知道在silvelright中對(duì)于report報(bào)表有什么好的解決方案,除了devexpress,telerik這些第3方的公司開(kāi)發(fā)的 silverlight 報(bào)表控件之外。我在google瘋狂檢索,沒(méi)有找到像樣的開(kāi)源的解決方案。在一番比較群橫還是選擇devexpress的報(bào)表控件。
下面的內(nèi)容就是利用devexpress report來(lái)完成一個(gè)報(bào)表:
具體來(lái)將有2種方式
1)報(bào)表和silverlight app在2個(gè)不同windows 窗口
2)報(bào)表嵌在silverlight page中
無(wú)論哪種方式都是看,具體的需求。
首先在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 中的頁(yè)面: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>
放置一個(gè)DocumentPreView,當(dāng)button點(diǎn)擊,將報(bào)表通過(guò)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
這樣就是一個(gè)簡(jiǎn)單的devexpress report
(慧都控件網(wǎng)版權(quán)所有,轉(zhuǎn)載請(qǐng)注明出處,否則追究法律責(zé)任)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:博客園