首页 > 其他 > 详细

锐浪报表

时间:2014-03-08 02:33:00      阅读:718      评论:0      收藏:0      [点我收藏+]


一直以来,锐浪报表做的不错,尤其是适用于国内的状况。加上不是很满意rdlc的功能,查遍网络,很少有这方面的介绍。所以整理常用功能,以备使用。水平有限,大家根据自身情况来学习。


套打技巧

  1. 扫描原件电子版作为报表背景

  2. 在报表上面依据背景画出控件位置

  3. 根据字段可以设计数据库和报表的连接进行自动大批量打印

  1. 多表头

详见官方例子

  1. 锐浪报表使用(单数据连接)

 

数据连接有两种模式(推模式、拉模式),推模式就是由程序代码把连接字符串、SQL语句推送给报表;拉模式则是在明细网格中根据填好的连接字符串、SQL语句由报表自身自主查询(不建议,连接语句包含在报表中,不太安全)。

 

private GridppReportReport = new GridppReport();//1.定义一个新报表

public voidshowreport()

        {           

            //2.载入报表模板数据

            //Report.LoadFromFile(GridppReportDemo.Utility.GetReportTemplatePath()+ "program\\ParamQuerySQL2.grf");

           Report.LoadFromFile(Application.StartupPath+ "\\1.grf");

 

            //3.设置与数据源的连接串,因为在设计时指定的数据库路径是绝对路径。           

Report.DetailGrid.Recordset.ConnectionString = "Provider=SQLOLEDB.1;Password=xxxxxx;PersistSecurity Info=True;User ID= xxxxxx;Initial Catalog=ry_powder;DataSource=192.168.8.18;Use Procedure for Prepare=1;Auto Translate=True;PacketSize=4096;Workstation ID=UNCLE13;Use Encryption for Data=False;Tag with columncollation when possible=False";

 

//4.连接报表取数事件

Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(MyReport);

//5.设定查询显示器要显示的报表

axGRPrintViewer1.Report = Report;        

        }

private voidMyReport()//报表查询条件

        {

            string startdate = dateTimePicker1.Value.ToString("yy-MM-dd 0:00:00");

            string enddate = dateTimePicker2.Value.ToString("yy-MM-dd 23:59:59");

 

            string SQL = "SELECT* FROM production_material_lose WHERE unit= ‘" + comboBox1.Text + "‘ ANDunit_2 = ‘" + comboBox2.Text + "‘AND materialtype = ‘" + comboBox3.Text + "‘AND typedetail = ‘" + comboBox4.Text + "‘and uploaddate  >= ‘" +startdate + "‘ and uploaddate  <=‘" + enddate + "‘";

//用拉模式为报表提供数据,将按条件生成的SQL设置到报表上

Report.DetailGrid.Recordset.QuerySQL = SQL;

        }

 

  1. 子报表意义及说明

    因为主报表只能定义一个数据连接,但是有时候我们要做多个查询,分别做几个报表是可以的,但是会显得比较乱,所以我们在主报表中添加一个或多个子报表来实现。

     

    主要用途:

    1、将多个不同的报表集中在一起打印,且每个报表的页面设置可以不一样,如纸张大小与纸张方向。

    2、希望多个报表集中导出到一个文件。

    3、实现在导出Excel时,将不同的报表分别导出在不同的工作表(sheet)中。设置子报表的导出到新工作表属性为,这个子报表在导出Excel时将单独产生在一个新工作表中。

     

 

  1. 多个数据连接(子报表)

    实现方法:

    就是在载入报表时,定义子报表名称(绿色部分),隶属于主报表模块(红色部分)

    //1.获取子报表的内部报表对象

    GridppReport rptCustomerList= rptMain.ControlByName("srCustomerList").AsSubReport.Report;

    GridppReport rptTop10Customer= rptMain.ControlByName("srTop10Customer").AsSubReport.Report;

    GridppReport rptTop10Product= rptMain.ControlByName("srTop10Product").AsSubReport.Report;

     

    //2.设置与数据源的连接串。

    rptCustomerList.DetailGrid.Recordset.ConnectionString= “”;

    rptTop10Customer.DetailGrid.Recordset.ConnectionString= “”;

    rptTop10Product.DetailGrid.Recordset.ConnectionString=  “”;;

     

    //3.连接报表事件

    rptProductList.FetchRecord += new_IGridppReportEvents_FetchRecordEventHandler(MyReport);

 

  1. 主报表子报表参数关联

     

    参数前边加上一个:号,select * from Customerswhere City=:City

    4d.子报表主子关联.grf

     

    报表统计

    报表要形成类似excel的统计类型也是可以的,首先一般都有明细网格”,我们把想要设置的列设置为自由格,然后在自由格中插入综合文字框(memoBox,在综合文字框(memoBox完成统计。

     

     

    传值(控件、参数)

     

    控件传值

添加二维码,并初始化为 666666

Report.ControlByName("Barcode1").AsBarcode.Text= "666666";

StaticBox1传值

Report.ControlByName("StaticBox1").AsStaticBox.Text= "666666";

 

参数传值(不一样,注意)

Report.ParamterByName("Parameter1").AsString= "abc";

Report.ParameterByName("Parameter1").AsBoolean= true;

 

4.折线图、二维码

 

折线图(其他类似,柱图、)

1.Xy轴名字(必选)

2.图表标题(可选)

3.数据序列数(有几种数据)

4.数据组数x轴数据列数目)

5.x轴(x轴标签、x轴刻度间隔、最小值、最大值)

6. y轴(y轴标签、y轴刻度间隔、最小值、最大值)

7.图表数据(所有数据)

 

实现方法:

1.建立图表,设置

private voidmyreport()

        {

            IGRChart pChartBar = Report.ControlByName("ChartBar").AsChart; //柱形图

            FillNormalValues(pChartBar);//填充值方法,见下

            SetCustomGraphFillColor(pChartBar);//颜色方法,参见chart例子,用处不大

 

            IGRChart pChartPie = Report.ControlByName("ChartPie").AsChart; //饼图

            FillNormalValues(pChartPie);

 

            IGRChart pChartScatter = Report.ControlByName("ChartScatter").AsChart;

            FillXYValues(pChartScatter); //随机散点图

 

            IGRChart pChartScatterLine = Report.ControlByName("ChartScatterLine").AsChart; //折线图

            FillXYValues2(pChartScatterLine);

        }

 

//向柱图、叠加柱图、连线图与饼图提供数据

        protected static void FillNormalValues(IGRChartpChart)

        {

           pChart.SeriesCount = 3;//数据序列数(有几种数据)

           pChart.GroupCount = 4;//数据组数(x轴数据列数目)

            //pChart.XAxisMinimum = 0;

            //pChart.XAxisMaximum = 60;

            //pChart.XAxisSpace = 15;

 

            pChart.set_SeriesLabel(0,"张三");

            pChart.set_SeriesLabel(1,"李四");

            pChart.set_SeriesLabel(2,"王五");

          

            pChart.set_GroupLabel(0,"");

            pChart.set_GroupLabel(1,"");

            pChart.set_GroupLabel(2,"");

            pChart.set_GroupLabel(3,"");

 

            pChart.set_Value(0,0, 1000);

            pChart.set_Value(0,1, 1200);

            pChart.set_Value(0,2, 1500);

            pChart.set_Value(0,3, 800);

 

            pChart.set_Value(1,0, 1500);

            pChart.set_Value(1,1, 1800);

            pChart.set_Value(1,2, 2000);

            pChart.set_Value(1,3, 1200);

 

            pChart.set_Value(2,0, 800);

            pChart.set_Value(2,1, 1000);

            pChart.set_Value(2,2, 700);

            pChart.set_Value(2,3, 500);

        }

 

//下面方法以随机数填充折线图,折线图采用下面的思路,双for循环读取数据库或者参数生成图表

//提供散点连线图的数据,产生随机坐标点数据,保持X值是递增的,并自定义XY轴刻度位置与显示文字

        protected static void FillXYValues2(IGRChartpChart)

        {

            Random MyRandom = newRandom();

 

            pChart.EmptyXYValue();

            for (short i=0;i<pChart.SeriesCount; ++i)

            {

                double x = 0;

                int DataCount = MyRandom.Next(30);

                for (short j=0;j<DataCount; ++j)

                {

                    x+= MyRandom.NextDouble() * 10;

                    double y = MyRandom.NextDouble() * 300;

                    pChart.AddXYValue(i,x, y);

                }

            }

 

            //设置纵坐标刻度文字

            pChart.EmptyYAxisText();

            pChart.AddYAxisText(0,"0");

            pChart.AddYAxisText(50,"50");

            pChart.AddYAxisText(100,"100");

            pChart.AddYAxisText(200,"200");

            pChart.AddYAxisText(300,"300");

            pChart.AddYAxisText(400,"400");

 

            //设置横坐标刻度文字

            pChart.EmptyXAxisText();

            pChart.AddXAxisText(0,"0");

            pChart.AddXAxisText(10,"10");

            pChart.AddXAxisText(30,"30");

            pChart.AddXAxisText(40,"40");

            pChart.AddXAxisText(60,"60");

            pChart.AddXAxisText(80,"80");

            pChart.AddXAxisText(100,"100");

        }

 

 

二维码

 

通过传值对控件进行赋值。

锐浪报表,布布扣,bubuko.com

锐浪报表

原文:http://blog.csdn.net/rund11/article/details/20701563

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!