fastreports.net 怎样报表动态更改数据源?

akt45678 2009-02-22 12:16:52
第一次用FastReprots,没有经验,报表在本地可以正常打印,但移动到别的电脑,报表的数据源须重新设置才可以正常打印,请各位有没有什么办法在程序中动态更改报表的数据源,谢谢?
...全文
223 6 打赏 收藏 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wu345654 2009-04-09
  • 打赏
  • 举报
回复
 public  class F_Reports_Class
{

public TfrxReportClass frx;
public TfrxADOQuery ado_query;
public TfrxADOQuery ado_query2;
public TfrxADODatabaseClass ado_database;

DBConnection dbconn;
int job_ko_ids;
string str1s;
string str2s;
string strpaths;


public F_Reports_Class(int job_ko_id,string strs1,string strs2,string strpath)
{
frx = new TfrxReportClass();
frx.ClearReport();

this.job_ko_ids = job_ko_id;
this.str1s = strs1;
this.str2s = strs2;
this.strpaths = strpath;

create();

}

public void create()
{

try
{

ado_database = new TfrxADODatabaseClass();
ado_database.ConnectionString = ConfigurationManager.AppSettings["db2Connection"].ToString(); //在app.config文件中建立連接字符串節點
ado_database.LoginPrompt = false;
ado_database.Connected = true;

ado_query = new TfrxADOQueryClass();
ado_query.Query = null;
ado_query.Name = "ADOQuery1";
ado_query.Query = "select a.pn_number,e.job_ko_desc,a.lot_number,a.ticket_barcode,a.ticket_number,a.size_name,a.ticket_quantity,c.job_order_number,d.work_process_desc from ticket as a,job_order as c,work_process as d,job_ko as e where a.job_ko_id=" + job_ko_ids + " " + str1s + " " + str2s + " and a.job_order_id=c.job_order_id and c.work_process_id=d.work_process_id and a.job_ko_id=e.job_ko_id order by a.ticket_id";
ado_query.DataBase = ado_database;

ado_query2 = new TfrxADOQueryClass();
ado_query2.Query = null;
ado_query2.Name = "ADOQuery2";
ado_query2.Query = "select case d.idx when 1 then 'A' when 2 then 'B' when 3 then 'C' when 4 then 'D' when 5 then 'E' when 6 then 'F' when 7 then 'G' when 8 then 'H' end as idx,name_chinese,b.code,c.lot_number from sp_color a,sp_color_yarn b,job_lot_number c,job_color d,job_ko_color e where e.job_ko_id="+job_ko_ids+" and e.job_lot_number_id=c.job_lot_number_id and e.job_color_id=d.job_color_id and d.sp_color_yarn_id=b.sp_color_yarn_id and b.sp_color_id=a.sp_color_id order by idx";
ado_query2.DataBase = ado_database;

frx.LoadReportFromFile(strpaths); //從傳入的路徑載入報表
frx.SelectDataset(true, ado_query); //為報表載入數據
frx.SelectDataset(true,ado_query2);

}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

}

public void no1()//預覽報表
{
frx.ShowReport();
frx.ClearReport();
}

public void no2() //設計報表 {
frx.DesignReport();
frx.ClearReport();

}

}
wu345654 2009-04-09
  • 打赏
  • 举报
回复
有如下代碼,可參考
 public  class F_Reports_Class
{

public TfrxReportClass frx;
public TfrxADOQuery ado_query;
public TfrxADOQuery ado_query2;
public TfrxADODatabaseClass ado_database;

DBConnection dbconn;
int job_ko_ids;
string str1s;
string str2s;
string strpaths;


public F_Reports_Class(int job_ko_id,string strs1,string strs2,string strpath)
{
frx = new TfrxReportClass();
frx.ClearReport();

this.job_ko_ids = job_ko_id;
this.str1s = strs1;
this.str2s = strs2;
this.strpaths = strpath;

create();

}

public void create()
{

try
{

ado_database = new TfrxADODatabaseClass();
ado_database.ConnectionString = ConfigurationManager.AppSettings["db2Connection"].ToString();
ado_database.LoginPrompt = false;
ado_database.Connected = true;

ado_query = new TfrxADOQueryClass();
ado_query.Query = null;
ado_query.Name = "ADOQuery1";
ado_query.Query = "select a.pn_number,e.job_ko_desc,a.lot_number,a.ticket_barcode,a.ticket_number,a.size_name,a.ticket_quantity,c.job_order_number,d.work_process_desc from ticket as a,job_order as c,work_process as d,job_ko as e where a.job_ko_id=" + job_ko_ids + " " + str1s + " " + str2s + " and a.job_order_id=c.job_order_id and c.work_process_id=d.work_process_id and a.job_ko_id=e.job_ko_id order by a.ticket_id";
ado_query.DataBase = ado_database;

ado_query2 = new TfrxADOQueryClass();
ado_query2.Query = null;
ado_query2.Name = "ADOQuery2";
ado_query2.Query = "select case d.idx when 1 then 'A' when 2 then 'B' when 3 then 'C' when 4 then 'D' when 5 then 'E' when 6 then 'F' when 7 then 'G' when 8 then 'H' end as idx,name_chinese,b.code,c.lot_number from sp_color a,sp_color_yarn b,job_lot_number c,job_color d,job_ko_color e where e.job_ko_id="+job_ko_ids+" and e.job_lot_number_id=c.job_lot_number_id and e.job_color_id=d.job_color_id and d.sp_color_yarn_id=b.sp_color_yarn_id and b.sp_color_id=a.sp_color_id order by idx";
ado_query2.DataBase = ado_database;

frx.LoadReportFromFile(strpaths);
frx.SelectDataset(true, ado_query);
frx.SelectDataset(true,ado_query2);

}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

}

public void no1()
{
frx.ShowReport();

dbconn = new DBConnection();
dbconn.sets_1();
dbconn.sets(job_ko_ids, str1s, str2s);
frx.ClearReport();
}

public void no2()
{
frx.DesignReport();
}

}
liu_ying_shan 2009-03-06
  • 打赏
  • 举报
回复
设置成udl试试
anzhiqiang_touzi 2009-02-28
  • 打赏
  • 举报
回复
说得不够详细
我前几天更完成这个模块:C/S+B/s:仅C/S可以自定义
有兴趣可以探讨一下
akt45678 2009-02-22
  • 打赏
  • 举报
回复
再顶下

4,818

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧