Z
zongytao
Unregistered / Unconfirmed
GUEST, unregistred user!
这个报表在程序运行后打印预览时为什么不能显示"应交水电费的数值"即qrdbtext3.Caption?为空,这个问题如何解决?
程序代码如下:
unit org_reports;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt, QRCtrls, DB, ADODB;
type
TForm29 = class(TForm)
QuickRep1: TQuickRep;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
QRBand1: TQRBand;
QRLabel1: TQRLabel;
QRBand2: TQRBand;
QRLabel3: TQRLabel;
QRLabel4: TQRLabel;
QRLabel2: TQRLabel;
QRExpr2: TQRExpr;
ADOQuery2: TADOQuery;
DataSource2: TDataSource;
QRDBText1: TQRDBText;
QRLabel5: TQRLabel;
QRDBText2: TQRDBText;
QRDBText3: TQRDBText;
procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form29: TForm29;
jiaofei_shiqi:string;
feiyong_shijiao:real;
org_name:string;
dep_name:string;
dep_namex:string;
implementation
uses org_report_prn;
{$R *.dfm}
procedure TForm29.QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
begin
qrdbtext1.Caption:=org_report_prns.DBLookupListBox1.SelectedItem;
org_name:=qrdbtext1.Caption;
jiaofei_shiqi:=org_report_prns.Edit1.Text;
qrlabel5.Caption:=jiaofei_shiqi;
with adoquery1 do
begin
close;
sql.clear;
sql.Add('select * from department where organize_name='''+org_name+'''');//从department表中选取组织名为org_report_prns窗体上DBLookupListBox1的被选中的组织名所包含的部门名称
open;
end;
dep_namex:=adoquery1.Fields.Fields[1].AsString;
qrdbtext2.Caption:=dep_namex;
with adoquery2 do
begin
close;
sql.clear;
sql.Add('select sum(feiyong_shijiao) from pay_feiyong where jiaofei_shiqi='''+jiaofei_shiqi+''' and organize_name='''+org_name+''' and department_name='''+dep_namex+'''');//从pay_feiyong 表中根据从department表中选取出的部门名(多个)以及交费月份和组织名选取X单位Y部门X月的应交水电费合计.(pay_feiyong 表中的记录为X公司Y部门W员工X月的应交水电费
open;
end;
feiyong_shijiao:=adoquery2.Fields.Fields[0].AsFloat;
qrdbtext3.Caption:=formatfloat('0.00',feiyong_shijiao);
end;
end.
程序代码如下:
unit org_reports;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt, QRCtrls, DB, ADODB;
type
TForm29 = class(TForm)
QuickRep1: TQuickRep;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
QRBand1: TQRBand;
QRLabel1: TQRLabel;
QRBand2: TQRBand;
QRLabel3: TQRLabel;
QRLabel4: TQRLabel;
QRLabel2: TQRLabel;
QRExpr2: TQRExpr;
ADOQuery2: TADOQuery;
DataSource2: TDataSource;
QRDBText1: TQRDBText;
QRLabel5: TQRLabel;
QRDBText2: TQRDBText;
QRDBText3: TQRDBText;
procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form29: TForm29;
jiaofei_shiqi:string;
feiyong_shijiao:real;
org_name:string;
dep_name:string;
dep_namex:string;
implementation
uses org_report_prn;
{$R *.dfm}
procedure TForm29.QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
begin
qrdbtext1.Caption:=org_report_prns.DBLookupListBox1.SelectedItem;
org_name:=qrdbtext1.Caption;
jiaofei_shiqi:=org_report_prns.Edit1.Text;
qrlabel5.Caption:=jiaofei_shiqi;
with adoquery1 do
begin
close;
sql.clear;
sql.Add('select * from department where organize_name='''+org_name+'''');//从department表中选取组织名为org_report_prns窗体上DBLookupListBox1的被选中的组织名所包含的部门名称
open;
end;
dep_namex:=adoquery1.Fields.Fields[1].AsString;
qrdbtext2.Caption:=dep_namex;
with adoquery2 do
begin
close;
sql.clear;
sql.Add('select sum(feiyong_shijiao) from pay_feiyong where jiaofei_shiqi='''+jiaofei_shiqi+''' and organize_name='''+org_name+''' and department_name='''+dep_namex+'''');//从pay_feiyong 表中根据从department表中选取出的部门名(多个)以及交费月份和组织名选取X单位Y部门X月的应交水电费合计.(pay_feiyong 表中的记录为X公司Y部门W员工X月的应交水电费
open;
end;
feiyong_shijiao:=adoquery2.Fields.Fields[0].AsFloat;
qrdbtext3.Caption:=formatfloat('0.00',feiyong_shijiao);
end;
end.