惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
G
Google Developers Blog
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
P
Proofpoint News Feed
V
Visual Studio Blog
爱范儿
爱范儿
The Cloudflare Blog
博客园 - 叶小钗
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
Microsoft Security Blog
Microsoft Security Blog
博客园 - 聂微东
H
Help Net Security
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
量子位
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - davin

Beginning Asp.Net Security 读书笔记-----XSS phonegap3.0+HTMLl5 开发 ipad app 总结 移动支付-修复FireFox在android移动设备下面的Session 丢失的问题 Window.history.forward(1) 阻止页面后退详解 Pro WPF and Silverlight MVVM:第5章 Event and Command 读书笔记 Pro WPF and Silverlight MVVM 第4章ViewModel 读书笔记 Useful rules for compatible with FF,safari and ie8 Entity Framework 4.0 FK Properties && FK Associations Entity Framework 4.0 recipes 读书笔记2 ExecuteStoreQuery() Entity Framework 4.0 Recipes 读书笔记1 EDM中的 Complex Type sqlserver2008 + team foundation server 2008 sp1 silverlight animation 读书笔记(4)三角函数 silverlight animation 读书笔记(3)坐标与向量 silverlight animation 读书笔记<2>模糊, 裁剪,拖拽 foundation silverligh3 animation 读书笔记<1>transform 在silverlight中打开调用外部程序的几种方式 Entity Framework object && Json 序列化的问题 silverlight3:(ItemControl 的)UI Virtualization SharpZipLib 数据压缩
Silverlight4:Devexpress Report
davin · 2011-04-04 · via 博客园 - davin

我不知道在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