项目中使用SqlServer Reporting Service作为报表开发的工具,现将操作记录在此,无论报表还是单证其展示方式一般分为两种:
1、 在页面中某个区域直接显示
2、 点击某个按钮触发后弹出新窗口显示
为此基类ApplicationBasePage.cs页面提供了如下两个方法
1.在页面中某个区域直接显示
1、 在页面中某个区域直接显示
2、 点击某个按钮触发后弹出新窗口显示
为此基类ApplicationBasePage.cs页面提供了如下两个方法
1
/// <summary>
2
/// 得到报表窗口的URL
3
/// </summary>
4
/// <param name="reportCode">报表代码,如rp_pr_qa_001</param>
5
/// <param name="paraName">参数名称数组,与参数值数组对应</param>
6
/// <param name="paraValue">参数值数组,与参数名称数组对于</param>
7
/// <param name="viewFormat">显示格式代码,0:显示参数、工具栏,1:不显示参数、显示工具栏,2:不显示参数、工具栏</param>
8
protected
string
GetReportUrl(
string
reportCode,
string
[] paraName,
string
[] paraValue,
int
viewFormat)
9
{
10
//报表的基础地址
11
//string reportingServerUrlBase = "http://10.3.130.72/ReportServer?/BpmsReports/";//ReportServer
12
string reportingServerUrlBase = ConfigurationManager.AppSettings["ReportServer"].ToString();
13
//参数拼接
14
string paras = "";
15
int paraCount = paraName.Length;
16
if (paraValue.Length < paraCount)
17
paraCount = paraValue.Length;
18
for (int i = 0; i < paraCount; i++)
19
{
20
paras += "&" + paraName[i] + "=" + Server.UrlEncode(paraValue[i]);
21
}
22
//显示格式
23
string format = "";
24
switch (viewFormat)
25
{
26
case 0:
27
format = "&rc:toolbar=true&rc:parameters=true&rc:Zoom=Page%20Width";
28
break;
29
case 1:
30
format = "&rc:toolbar=true&rc:parameters=false&rc:Zoom=Page%20Width";
31
break;
32
case 2:
33
format = "&rc:toolbar=false&rc:parameters=false&rc:Zoom=Page%20Width";
34
break;
35
default:
36
format = "&rc:toolbar=true&rc:parameters=true&rc:Zoom=Page%20Width";
37
break;
38
}
39
//组织最终报表URL
40
string reportUrl = reportingServerUrlBase + reportCode + paras + format;
41
42
return reportUrl;
43
}
44
/// <summary>
45
/// 打开报表窗口
46
/// </summary>
47
/// <param name="reportCode">报表代码,如rp_pr_qa_001</param>
48
/// <param name="paraName">参数名称数组,与参数值数组对应</param>
49
/// <param name="paraValue">参数值数组,与参数名称数组对于</param>
50
/// <param name="viewFormat">显示格式代码,暂时只有两种,0:显示title,1:不显示title</param>
51
protected
void
PopUpReport(
string
reportCode,
string
[] paraName,
string
[] paraValue,
int
viewFormat)
52
{
53
//获得报表地址
54
string reportUrl = GetReportUrl(reportCode, paraName, paraValue, viewFormat);
55
56
//弹出报表窗口
57
StringBuilder builder = new StringBuilder();
58
builder.Append("<script language='javascript'>");
59
builder.Append("{open('" + reportUrl + "','aa','width='+screen.width+' height='+screen.height+' top=0 left=0 toolbar=no menubar=no resizable=yes status=yes');}");
60
builder.Append("</script>");
61
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "open", builder.ToString());
62
}
调用事例

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

1.在页面中某个区域直接显示
1
合同号
<
asp:TextBox
ID
="TextBox1"
runat
="server"
></
asp:TextBox
>
2
<
asp:Button
ID
="btnViewReportInPage"
runat
="server"
Text
="页内显示报表"
OnClick
="btnViewReportInPage_Click"
/>
3
<
asp:Button
ID
="btnViewReportOutPage"
runat
="server"
Text
="弹出页显示报表"
OnClick
="btnViewReportOutPage_Click"
/>
4
<
br
/>
5
<
iframe
id
="RptFrame"
runat
="server"
width
="100%"
height
="500"
></
iframe
>

2

3

4

5

1
protected
void
btnViewReportInPage_Click(
object
sender, EventArgs e)
2
{
3
string reportCode = "rp_pr_qa_136";
4
string[] paraName = new string[] {"ContractNoSys"};
5
string[] paraValue = new string[1];
6
paraValue[0] = TextBox1.Text;
7
ReportURL = GetReportUrl(reportCode, paraName, paraValue, 1);
8
RptFrame.Attributes.Add("src", ReportURL);
9
}
2.点击某个按钮触发后弹出新窗口显示

2

3

4

5

6

7

8

9

1
protected
void
btnViewReportOutPage_Click(
object
sender, EventArgs e)
2
{
3
string reportCode = "rp_pr_qa_136";
4
string[] paraName = new string[] { "ContractNoSys" };
5
string[] paraValue = new string[1];
6
paraValue[0] = TextBox1.Text;
7
PopUpReport(reportCode, paraName, paraValue, 1);
8
}

2

3

4

5

6

7

8
