博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MVC引用asp.net报表(测试小例子)
阅读量:5064 次
发布时间:2019-06-12

本文共 5630 字,大约阅读时间需要 18 分钟。

1  public class Default1Controller : Controller 2     { 3         // 4         // GET: /Default1/ 5  6         public ActionResult Index() 7         { 8             return View(); 9         }10 11         public JsonResult ReportFileName()12         {13             DirectoryInfo d = new DirectoryInfo(Server.MapPath("~/") + "Report/");14             FileSystemInfo[] fsinfos = d.GetFileSystemInfos();15             List
fileName = fsinfos.Where(p => p.Name.IndexOf(".rdlc", StringComparison.Ordinal) == -1).Select(fsinfo => fsinfo.Name.Replace(".rdl", "")).ToList();16 return Json(new { Result = fileName });17 }18 19 public JsonResult ExistsFile(string keyId)20 {21 string path = Server.MapPath("~/") + "Report/" + keyId + ".rdl";22 return this.Json(new { ResultBool = System.IO.File.Exists(path) });23 }24 }
MVC后端
1 @{ 2     ViewBag.Title = "Index"; 3 } 4  5 站点: 6  7  8  9 10 
11 12 13
MVC前端
1  public partial class WebForm1 : System.Web.UI.Page  2     {  3         protected void Page_Load(object sender, EventArgs e)  4         {  5             if (!IsPostBack)  6             {  7                 BindReport(Request["KeyId"]);  8             }  9         } 10  11  12  13  14         private void BindReport(string keyId) 15         { 16             string sql = string.Empty; 17             string site = Request["site"]; 18             switch (keyId) 19             { 20                 case "无标题": 21                     sql = " select * from sysuser"; 22                     if (site.Length > 0) 23                     { 24                         sql += " where defsite like '" + site.Trim() + "%'"; 25                     } 26                     break; 27                 case "有标题": 28                     sql = " select * from facility"; 29                     if (site.Length > 0) 30                     { 31                         sql += " where siteid like '" + site.Trim() + "%'"; 32                     } 33                     break; 34                 case "报表模板": 35                     sql = "SELECT USERID AS SEQ,PERSONID AS KSSJ,DEFSITE AS JSSJ FROM SYSUSER"; 36                     if (site.Length > 0) 37                     { 38                         sql += " where siteid like '" + site.Trim() + "%'"; 39                     } 40                     break; 41                 default: 42                     break; 43             } 44  45             DataTable dt = new DataTable(); 46             ReportViewer1.ProcessingMode = ProcessingMode.Local; 47             ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/") + @"Report/" + keyId + ".rdl"; //可以通过SQL语句传参形式 48             ReportViewer1.LocalReport.EnableExternalImages = true; 49             dt = QueryTable(sql); 50             ReportDataSource rds = new ReportDataSource("DataSet1", dt); //DataSetl报表数据集名称 51             ReportViewer1.LocalReport.DataSources.Clear(); 52             ReportViewer1.LocalReport.DataSources.Add(rds); 53             ReportViewer1.LocalReport.Refresh(); 54             //ClientScript.RegisterClientScriptBlock(ClientScript.GetType(), "MyScript", ""); 55             //Response.Write(""); 56             //string js = 57             //    ""; 69             //Response.Write(js); 70         } 71  72  73  74         ///  75         /// 执行查询语句,返回DataTable 76         ///  77         /// 查询语句 78         /// 
DataTable
79 public static DataTable QueryTable(string sqlString) 80 { 81 82 using (var connection = new OracleConnection("DATA SOURCE=192.168.1.61:5050/Xinsida;USER ID=BKCYUN;PASSWORD=bkc123456;")) 83 { 84 var dt = new DataTable(); 85 try 86 { 87 connection.Open(); 88 var command = new OracleDataAdapter(sqlString, connection); 89 command.Fill(dt); 90 return dt; 91 } 92 catch (Exception e) 93 { 94 throw e; 95 } 96 finally 97 { 98 if (connection.State == ConnectionState.Open) 99 {100 connection.Close();101 }102 }103 }104 }105 protected override void Render(HtmlTextWriter writer)106 {107 using (StringWriter sw = new StringWriter())108 {109 HtmlTextWriter tmpWriter = new HtmlTextWriter(sw);110 base.Render(tmpWriter);111 string val = sw.ToString();112 val = val.Replace(@"!= 'javascript:\'\''", @"!= 'javascript:\'\'' && false");113 writer.Write(val);114 }115 }116 }
WebForm后端
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ReportBuilderTest1.WebForm1" %> 2  3 <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> 4  5  6  7  8  9     
10 11 17 <%-- --%>28 29 30
31
32
33
39
40
34
35
36
37
38
41
42 43
WebForm前端

还有一个文件夹Report下面有.rdl报表。这里就不写了。

转载于:https://www.cnblogs.com/Zhengxue/p/8777944.html

你可能感兴趣的文章
mysqladmin
查看>>
解决 No Entity Framework provider found for the ADO.NET provider
查看>>
设置虚拟机虚拟机中fedora上网配置-bridge连接方式(图解)
查看>>
[置顶] Android仿人人客户端(v5.7.1)——人人授权访问界面
查看>>
Eclipse 调试的时候Tomcat报错启动不了
查看>>
ES6内置方法find 和 filter的区别在哪
查看>>
Android入门之文件系统操作(二)文件操作相关指令
查看>>
Android实现 ScrollView + ListView无滚动条滚动
查看>>
java学习笔记之String类
查看>>
UVA 11082 Matrix Decompressing 矩阵解压(最大流,经典)
查看>>
jdk从1.8降到jdk1.7失败
查看>>
硬件笔记之Thinkpad T470P更换2K屏幕
查看>>
【知识库】-数据库_MySQL 的七种 join
查看>>
iOS开发——缩放图片
查看>>
HTTP之URL的快捷方式
查看>>
满世界都是图论
查看>>
配置链路聚合中极小错误——失之毫厘谬以千里
查看>>
代码整洁
查看>>
蓝桥杯-分小组-java
查看>>
Android Toast
查看>>