
我不知道在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 + "//" + 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%22
binding="basichttpBinding" bindingConfiguration="BasichttpBinding_IReportService"
contract="ReportService.IReportService" name="BasichttpBinding_IReportService" />
contract是 ReportService.IReportService
这样就是一个简单的devexpress report
环境:visual studio 2010,silverlight4 DevExpress v10.1
总结以上是内存溢出为你收集整理的Silverlight4:Devexpress Report全部内容,希望文章能够帮你解决Silverlight4:Devexpress Report所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)