原創(chuàng)|使用教程|編輯:郝浩|2013-07-31 12:01:10.000|閱讀 278 次
概述:ActiveReports允許開(kāi)發(fā)者在過(guò)濾器中使用參數(shù),也允許開(kāi)發(fā)者在運(yùn)行時(shí)添加顯示數(shù)據(jù)到報(bào)表的。固可實(shí)現(xiàn)在報(bào)表運(yùn)行過(guò)程中,最終用戶通過(guò)參數(shù)來(lái)改變報(bào)表輸出內(nèi)容的需求。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
報(bào)表開(kāi)發(fā)工具ActiveReports允許開(kāi)發(fā)者在過(guò)濾器中使用參數(shù),也允許開(kāi)發(fā)者在運(yùn)行時(shí)添加顯示數(shù)據(jù)到報(bào)表的。所以ActiveReports可以實(shí)現(xiàn)在報(bào)表運(yùn)行過(guò)程中,最終用戶通過(guò)參數(shù)來(lái)改變報(bào)表輸出內(nèi)容的需求。
最常見(jiàn)的需求場(chǎng)景是,經(jīng)理使用報(bào)表查看器查看銷售報(bào)表時(shí),需要分地區(qū)查看銷售業(yè)績(jī),這時(shí)候就需要在查看器上添加一個(gè)下拉菜單作為過(guò)濾器來(lái)實(shí)現(xiàn)這一需求了。如下圖所示:
首先,需要在ActiveReports的Viewer窗體中添加一個(gè)Combobox,并將參數(shù)值填入其中。需要使用SQL查詢中的UNIQUE語(yǔ)句將數(shù)據(jù)集的值填入,示例代碼如下:
private void Form1_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\STDUser\My Documents\ComponentOne Samples\ActiveReports Developer 7\Data\NWIND.mdb;Persist Security Info=False"); System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand("select distinct country from customers", con); con.Open(); System.Data.OleDb.OleDbDataAdapter _da = new System.Data.OleDb.OleDbDataAdapter(command); _da.Fill(ds); comboBox1.ValueMember = "Country"; comboBox1.DataSource = ds.Tables[0]; con.Close(); }
在為下拉框添加了參數(shù)值后,需要將下拉框選擇的參數(shù)傳到報(bào)表中,使用組合框的SelectedIndexChanged事件:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { SectionReport1 rpt = new SectionReport1(); GrapeCity.ActiveReports.Data.OleDBDataSource _oDS = new GrapeCity.ActiveReports.Data.OleDBDataSource(); _oDS.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\STDUser\My Documents\ComponentOne Samples\ActiveReports Developer 7\Data\NWIND.mdb;Persist Security Info=False"; _oDS.SQL = "Select * from customers where country='" + this.comboBox1.SelectedValue + "'"; rpt.DataSource = _oDS; rpt.Run(); viewer1.LoadDocument(rpt); }
接下來(lái)就只需要執(zhí)行ActiveReports的報(bào)表查看器就行了。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)