开发自己的SQL2005报表查看SharePoint WebPart(三)

我们在(一)里完成了web part的实现
在(二)里完成了通过调用SQL2005 reporting services的web service,查询并显示报表
现在,我们要给Web part增加属性来设置报表服务器的地址和报表路径
首先,为了能够在SharePoint中设置属性,需要增加对Microsoft.SharePoint的引用,原来我们的BARreportWebPart是从System.Web.UI.WebControls.WebParts.WebPart继承的,现在要改为从Microsoft.SharePoint.WebPartPages.WebPart继承。否则你在Sharepoint web part属性设置里面看不到你的自定义属性
然后,增加两个字符类型的属性:ReportServerURL,ReportPath。具体的attribute设置请参考
如何给Web part增加自定义属性Creating a Web Part with Custom Properties(http://msdn2.microsoft.com/en-us/library/ms948927.aspx)
这是最后的代码
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint.WebPartPages;

namespace BARreportWebPart
{
    [DefaultProperty("Text"),
     ToolboxData("<{0}:BARreportWebPart runat=server></{0}:BARreportWebPart>"),
     XmlRoot(Namespace = "BARreportWebPart")]

    public class BARreportWebPart : Microsoft.SharePoint.WebPartPages.WebPart//System.Web.UI.WebControls.WebParts.WebPart
    {
        string _reportServerURL="";// = "http://ctc-bar:81/ReportServer/ReportService.asmx";
        string _reportPath = "";// = "/BARreports/EBCdetailList";

        public BARreportWebPart()
        {

        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (string.Empty == ReportServerURL.Trim() || null == ReportServerURL
                 || string.Empty == ReportPath.Trim() || null == ReportPath)
            {
                writer.Write("please set the ReportServerURL, ReportPath");
                return;
            }
            string reportServerURL = ReportServerURL;
            string reportPath = ReportPath;

            ReportAdapter rsAdapter = new ReportAdapter(reportServerURL, reportPath);
            ReportingServer.ReportParameter[] parameters = rsAdapter.GetParameters();
            ReportingServer.ParameterValue[] parameterValues = null;
            if (parameters.Length > 0)
            {
                parameterValues = new ReportingServer.ParameterValue[parameters.Length];
                for (int i = 0; i < parameters.Length; i++)
                {
                    parameterValues[i] = new ReportingServer.ParameterValue();
                    parameterValues[i].Name = parameters[i].Name;
                    parameterValues[i].Label = parameters[i].Prompt;
                }
                parameterValues[0].Value = "2007-1-1";
                parameterValues[1].Value = "2007-3-1";
            }
            System.Text.Encoding enc = System.Text.Encoding.UTF8;
            byte[] result = rsAdapter.RenderReport(parameterValues);
            string htmlResult = enc.GetString(result);
            //htmlResult = htmlResult.Replace(reportServerURL.Replace("/ReportService.asmx", "?"), "http://" & Request("SERVER_NAME") & Request("SCRIPT_NAME") & "?Report=");
            //writer.Write(htmlResult);
        }

        // Creates a custom property :
        // This property will be displayed as a text box in the
        // property pane.

        // Create a custom category in the property sheet.
        //[Category("Custom Properties")]
        // Assign the default value.
        [DefaultValue("http://ctc-bar:81/ReportServer/ReportService.asmx")]
        // Property is available in both Personalization
        // and Customization mode.
        [WebPartStorage(Storage.Personal)]
        // The caption that appears in the property sheet.
        [FriendlyNameAttribute("ReportServerURL")]
        // The tool tip that appears when pausing the mouse pointer over
        // the friendly name in the property pane.
        [Description("Report Server URL: (like http://ctc-bar:81/ReportServer/ReportService.asmx )")]
        // Display the property in the property pane.
        [Browsable(true)]
        [XmlElement(ElementName = "ReportServerURL")]
        // The accessor for this property.
        public string ReportServerURL
        {
            get
            {
                return _reportServerURL;
            }
            set
            {
                _reportServerURL = value;
            }
        }

        // Assign the default value.
        [DefaultValue("")]
        // Property is available in both Personalization
        // and Customization mode.
        [WebPartStorage(Storage.Personal)]
        // The caption that appears in the property sheet.
        [FriendlyNameAttribute("ReportPath")]
        // The tool tip that appears when pausing the mouse pointer over
        // the friendly name in the property pane.
        [Description("Report Path")]
        // Display the property in the property pane.
        [Browsable(true)]
        [XmlElement(ElementName = "ReportPath")]
        // The accessor for this property.
        public string ReportPath
        {
            get{
                return _reportPath;
            }
            set {
                _reportPath = value;
            }
        }

     }
}

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值