public class ReportOperation
{
private Page objPage;
public ReportOperation(Page Page1)
{
this.objPage = Page1;
}
public string ms_ReportServer
{
get{return System.Configuration.ConfigurationSettings.AppSettings["ReportServer"];}
}
public void OpenReport(string s_aReportId, string s_aParameter)
{
string s_JS = "<script language='javascript'>" +
"var o_Win=window.open('" + GetReportURL(s_aReportId, s_aParameter) + "'" +
",'','location=no,status=no,toolbar=no,width=700,height=600,top=50,left=50');</script>";
objPage.RegisterStartupScript("0001", s_JS); //開啟報表
}
public string GetReportURL(string s_aReportId, string s_aParameter)
{
if (s_aReportId == "") return string.Empty;
// &rc:標示報表監視器參數
// Parameters=false 隱藏報表參數列
// Toolbar=true 顯示工具列
// Command=Render 呈現報表
// ClearSession=true
// Stylesheet=hr_htmlviewer 指定要应用于 HTML 查看器的样式表
string s_ReportUrl = this.ms_ReportServer + "?/" + s_aReportId
+ "&rc:Parameters=false&rc:Toolbar=true&rc:Command=Render&rc:ClearSession=true"
+ "&rc:Stylesheet=hr_htmlviewer" + EncodeParams(s_aParameter); //開啟新視窗的路徑
return s_ReportUrl;
}
private string EncodeParams(string s_aParams)
{
if (s_aParams == "") return "";
if (s_aParams.Length > 0 && s_aParams.IndexOf("=") == -1)
throw new Exception("報表參數格式錯誤.正確格式:參數名=參數值&參數名=參數值");
s_aParams = s_aParams.Replace("'", ""); //去掉特殊字符.否則開啟報表時會出錯.20050326 Modify
if (s_aParams.Length > 0 && s_aParams.IndexOf("&") == 0)
s_aParams = s_aParams.Substring(1);
string s_Params = string.Empty;
string[] arr_Param = s_aParams.Split(new char[] { '&', '=' });
for (int i_Len = 0; i_Len < arr_Param.Length; i_Len++)
{
if ((i_Len + 1) % 2 == 0)
{
s_Params += "=" + this.objPage.Server.UrlEncode(this.objPage.Server.UrlDecode(arr_Param[i_Len])); //先對字符進行解碼,再編碼.以防止參數已經編碼的情況
}
else
s_Params += "&" + arr_Param[i_Len];
}
return s_Params;
}
}