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

推荐订阅源

Google Online Security Blog
Google Online Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
Cisco Talos Blog
Cisco Talos Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Scott Helme
Scott Helme
Project Zero
Project Zero
E
Exploit-DB.com RSS Feed
S
Secure Thoughts
K
Kaspersky official blog
L
Lohrmann on Cybersecurity
NISL@THU
NISL@THU
WordPress大学
WordPress大学
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LINUX DO - 热门话题
小众软件
小众软件
P
Privacy & Cybersecurity Law Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
Hacker News: Ask HN
Hacker News: Ask HN
AWS News Blog
AWS News Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hacker News: Front Page
F
Full Disclosure
Latest news
Latest news
Schneier on Security
Schneier on Security
The Hacker News
The Hacker News
T
Troy Hunt's Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Jina AI
Jina AI
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
TaoSecurity Blog
TaoSecurity Blog
G
GRAHAM CLULEY
Forbes - Security
Forbes - Security
V
V2EX - 技术
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Vulnerabilities – Threatpost
C
Cyber Attacks, Cyber Crime and Cyber Security
MongoDB | Blog
MongoDB | Blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
P
Privacy International News Feed
C
Check Point Blog
N
News and Events Feed by Topic

博客园 - 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