zoukankan      html  css  js  c++  java
  • 利用VS2015自带的报表制作报表

    我用的是VSEnterprise2015

    注意:如果要用VS自带的报表,就需要在安装Microsoft SQL Server Data Tools

    下面讲讲具体步骤:

    1.添加winform界面

    2.添加生成报表界面这里要注意,工具箱的数据里面要有ReportViewer控件,如果没有则要工具箱-》数据-》选择项-》.NET Framework组件-》勾选ReportViewer(命名空间对应的是Microsoft.Reporting.WinForms【winform程序,如果是asp.net则勾选命名空间是Microsoft.Reporting.WebForms】)

    生成报表界面对应代码

                try
                {
                    this.reportViewer1.LocalReport.ReportPath = "Report_JSHZB.rdlc";//Report_JSHZB.rdlc对应添加的报表文件
                    DataTable dt = new DataTable();
                    dt.Columns.Add("BMMC");
                    dt.Columns.Add("JYBS", typeof(int));//对应报表文件中的数据集字段
                    dt.Columns.Add("JYJE", typeof(decimal));
                    dt.Columns.Add("HCBS", typeof(int));
                    dt.Columns.Add("HCJE", typeof(decimal));
                    dt.Columns.Add("JSJE", typeof(decimal));
                    dt.Rows.Add("第一食堂", 13305, 27246.68, 0, 0.0, 27246.68);
                    dt.Rows.Add("第二食堂", 12277, 27965.63, 1, 15.0, 27950.63);
                    dt.Rows.Add("超市", 26, 1062.90, 0, 0.0, 1065.90);
                    dt.Rows.Add("医务室", 78, 857.00, 0, 0.0, 857.00);
                    dt.Rows.Add("电子阅览室", 157, 871.00, 0, 0.0, 871.00);
                    dt.Rows.Add("图书馆", 120, 1176.50, 0, 0.0, 1176.50);
                    dt.Rows.Add("学生公寓沐浴", 693, 5371.19, 0, 0.0, 5371.19);
                    ReportDataSource rds1 = new ReportDataSource("DataSet_JSHZB", dt);//DataSet_JSHZB对应报表文件中的数据集
                    this.reportViewer1.LocalReport.DataSources.Add(rds1);
                    ReportParameter Rar_CNDate = new ReportParameter();
                    Rar_CNDate.Name = "Rar_CNDate";//报表参数,对应报表文件中的参数
                    Rar_CNDate.Values.Add(CNDate.ToString("yyyy-MM-dd"));
                    ReportParameter Rar_Time = new ReportParameter();
                    Rar_Time.Name = "Rar_Time";
                    Rar_Time.Values.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    ReportParameter Rar_UserName = new ReportParameter();
                    Rar_UserName.Name = "Rar_UserName";
                    Rar_UserName.Values.Add("系统管理员");
                    this.reportViewer1.LocalReport.SetParameters(Rar_CNDate);
                    this.reportViewer1.LocalReport.SetParameters(Rar_Time);
                    this.reportViewer1.LocalReport.SetParameters(Rar_UserName);
                    this.reportViewer1.RefreshReport();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.reportViewer1.RefreshReport();

    3.添加报表文件

    4.最终生成的报表

  • 相关阅读:
    刨根问底 | Elasticsearch 5.X集群多节点角色配置深入详解【转】
    ElasticSearch 内存那点事【转】
    Zookeeper之Zookeeper的Client的分析【转】
    Zookeeper之Zookeeper底层客户端架构实现原理(转载)
    elasticsearch 性能调优
    ElasticSearch性能优化策略【转】
    elasticsearch中 refresh 和flush区别【转】
    我理解的朴素贝叶斯模型【转】
    (转)Intellij IDEA 快捷键整理
    使用Mongo dump 将数据导入到hive
  • 原文地址:https://www.cnblogs.com/luoxiaozhao/p/5602718.html
Copyright © 2011-2022 走看看