我用RM24做的动态生成报表源码:
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids, DB, ADODB, ComCtrls,
DBCtrls, Mask, printers, RM_dset, RM_class, RM_dbset;
type
Tmain = class(TForm)
Panel1: TPanel;
BitBtn1: TBitBtn;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
BitBtn2: TBitBtn;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Panel2: TPanel;
GroupBox1: TGroupBox;
Edit1: TEdit;
UpDown1: TUpDown;
ADOConnection1: TADOConnection;
gzjg: TADOTable;
DataSource_gzjg: TDataSource;
xjgzb: TADOQuery;
ComboBox3: TComboBox;
Label1: TLabel;
Edit3: TEdit;
Label2: TLabel;
Edit4: TEdit;
Panel3: TPanel;
BitBtn7: TBitBtn;
BitBtn8: TBitBtn;
BitBtn9: TBitBtn;
ComboBox1: TComboBox;
DBGrid2: TDBGrid;
TabSheet3: TTabSheet;
de: TADOQuery;
DBNavigator3: TDBNavigator;
BitBtn10: TBitBtn;
hjje: TADOQuery;
DBNavigator1: TDBNavigator;
DBNavigator2: TDBNavigator;
gz: TADOQuery;
BitBtn3: TBitBtn;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
DBGrid1: TDBGrid;
sor: TADOQuery;
ADOTable1: TADOTable;
DataSource2: TDataSource;
DBGrid3: TDBGrid;
Panel4: TPanel;
chd: TADOQuery;
RMReport1: TRMReport;
RMDBDataSet1: TRMDBDataSet;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn7Click(Sender: TObject);
procedure BitBtn8Click(Sender: TObject);
procedure BitBtn9Click(Sender: TObject);
procedure ComboBox3Change(Sender: TObject);
procedure BitBtn10Click(Sender: TObject);
procedure ADOQuery1AfterOpen(DataSet: TDataSet);
procedure BitBtn5Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure ADOTable1AfterPost(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;
var
main: Tmain;
month1,field_name,field_name1,table_name,field_lx,tmp_hao,gzb_sql,tmp_month:string;
mytables:tstringlist;
title_rep,gz_xm,hz_tmp,hmc_tmp:string;
v: TrmView;
b: TrmBandView;
Page: TrmPage;
gz_x,fie_len:integer;
implementation
uses Unit1;
{$R *.dfm}
procedure Tmain.BitBtn1Click(Sender: TObject);
begin
table_name:=edit1.Text+combobox1.Text;
mytables:=tstringlist.Create ;
ADOConnection1.GetTableNames(mytables);
if not (mytables.IndexOf(table_name)=-1) then
application.MessageBox('脑病!该月工资表已做!!你不嫌累吗?','系统警告',MB_ok+MB_Iconstop)
else
begin
main.gzjg.First;
tmp_hao:='';
gzb_sql:='';
while main.gzjg.eof=false do
begin
if main.gzjg.FieldByName('字段类型').asstring='文本' then field_lx:='char'+'('+ main.gzjg.fieldbyname('字段长度').asstring+')' else field_lx:='money';
gzb_sql:=gzb_sql+tmp_hao+main.gzjg.fieldbyname('项目').asstring+' '+field_lx;
tmp_hao:=',';
main.gzjg.Next;
end;
with main.xjgzb do
begin
close;
sql.Clear;
SQL.Add('Create Table '+table_name);
sql.Add('(ID IDENTITY(1,1) PRIMARY KEY,'+gzb_sql+');');
execSQL;
end;
with adoquery1 do
begin
close;
sql.clear;
if combobox3.text='全部人员' then sql.Add('select * from '+table_name)
else sql.Add('select * from '+table_name+'where 编制='+combobox3.text);
sql.add('order by 排序');
open;
end;
end;
end;
procedure Tmain.BitBtn2Click(Sender: TObject);
var
I,k:integer;
tmp_sor,tiaoj,tmp_tiaoj:string;
begin
table_name:=edit1.Text+combobox1.Text;
if strtoint(combobox1.Text)=1 then
field_name1:=inttostr(strtoint(edit1.Text)-1)+'12' else
begin
tmp_month:=inttostr(strtoint(combobox1.Text)-1);
if length(tmp_month)=1 then tmp_month:='0'+tmp_month;
field_name1:=edit1.Text+tmp_month;
end;
if adoquery1.Active=true then
begin
if adoquery1.RecordCount<1 then
begin
mytables:=tstringlist.Create ;
ADOConnection1.GetTableNames(mytables);
if (mytables.IndexOf(field_name1)=-1) then
application.MessageBox('懒货,上月工资表还没做!!!','系统警告',MB_ok+MB_Iconstop)
else
begin
with sor do
begin
close;
sql.Clear;
sql.add('select * from '+field_name1);
open;
end;
with de do
begin
close;
sql.clear;
sql.Add('select * from '+table_name);
open;
end;
tiaoj:='';
tmp_tiaoj:='';
for i := 0 to sor.FieldCount - 1 do //上月源表的表结构名
begin
tmp_sor:=sor.Fields.FieldName;
for k := 0 to de.FieldCount - 1 do
begin
if tmp_sor=de.Fields[k].FieldName then
begin
tiaoj:=tmp_tiaoj+tmp_sor;
tmp_tiaoj:=tiaoj+',';
end;
end;
end;
with xjgzb do
begin
close;
sql.Clear;
sql.add('insert into '+table_name+'('+tiaoj+')'+' select '+tiaoj+' from '+field_name1);
execSQL;
end;
with adoquery1 do
begin
close;
sql.clear;
sql.Add('select * from '+table_name);
sql.add('order by 排序');
open;
end;
for i:=0 to adoquery1.FieldCount-1 do
if adoquery1.Fields.DataType in [ftFloat,ftCurrency,ftBCD] then
TFloatField(adoquery1.Fields).Displayformat:='#,##0.00';
end;
end else application.MessageBox('蠢货,已导入上月数据!!!','系统警告',MB_ok+MB_Iconstop);
end else application.MessageBox('血笨!请先生成表结构!!!','系统警告',MB_ok+MB_Iconstop);
end;
procedure Tmain.ComboBox1Change(Sender: TObject);
var i:integer;
begin
table_name:=edit1.Text+combobox1.Text;
mytables:=tstringlist.Create ;
with adoquery1 do
begin
close;
sql.clear;
end;
main.ADOConnection1.GetTableNames(mytables);
if not (mytables.IndexOf(table_name)=-1) then
begin
with adoquery1 do
begin
close;
sql.clear;
sql.Add('select * from '+table_name);
if combobox3.text<>'全部人员' then sql.Add('where 编制='+''''+combobox3.text+'''');
sql.add('order by 排序');
open;
end;
edit3.text:=inttostr(adoquery1.RecordCount);
for i:=0 to adoquery1.FieldCount-1 do
if adoquery1.Fields.DataType in [ftFloat,ftCurrency,ftBCD] then
TFloatField(adoquery1.Fields).Displayformat:='#,##0.00';
with hjje do
begin
close;
sql.clear;
sql.add('select sum(实发金额) from '+table_name);
if combobox3.text<>'全部人员' then sql.Add('where 编制='+''''+combobox3.text+'''');
open;
end;
edit4.Text:=hjje.Fields[0].asstring;
end;
end;
procedure Tmain.FormShow(Sender: TObject);
var i:integer;
begin
combobox3.items.clear;
combobox3.items.add('全部人员');
adotable1.First;
while adotable1.eof=false do
begin
combobox3.items.add(adotable1.Fields[1].asstring);
adotable1.Next;
end;
combobox3.ItemIndex:=0;
EDIT1.Text:=formatdatetime('yyyy',now);
table_name:=edit1.Text+combobox1.Text;
mytables:=tstringlist.Create ;
main.ADOConnection1.GetTableNames(mytables);
if not (mytables.IndexOf(table_name)=-1) then
begin
with adoquery1 do
begin
close;
sql.clear;
if combobox3.text='全部人员' then sql.Add('select * from '+table_name)
else sql.Add('select * from '+table_name+' where 编制='+''''+combobox3.text+'''');
sql.add('order by 排序');
open;
end;
for i:=0 to adoquery1.FieldCount-1 do
if adoquery1.Fields.DataType in [ftFloat,ftCurrency,ftBCD] then
TFloatField(adoquery1.Fields).Displayformat:='#,##0.00';
edit3.text:=inttostr(adoquery1.RecordCount);
with hjje do
begin
close;
sql.clear;
sql.add('select sum(实发金额) from '+table_name);
if combobox3.text<>'全部人员' then sql.Add('where 编制='+''''+combobox3.text+'''');
open;
end;
edit4.Text:=hjje.Fields[0].asstring;
end;
end;
procedure Tmain.BitBtn7Click(Sender: TObject);
begin
close;
end;
procedure Tmain.BitBtn8Click(Sender: TObject);
begin
form1.showmodal;
end;
procedure Tmain.BitBtn9Click(Sender: TObject);
begin
if application.MessageBox('国华同志,删除后不能恢复!请确定要删除吗!!','张新志的警告',MB_yesno+MB_Iconstop)=idyes then
begin
table_name:=edit1.Text+combobox1.Text;
if adoquery1.Active=true then
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.add('drop table '+table_name);
execSQL;
end;
end else application.MessageBox('该月工资表不存在!!!!','系统警告',MB_ok+MB_Iconstop);
end;
end;
procedure Tmain.ComboBox3Change(Sender: TObject);
var i:integer;
begin
table_name:=edit1.Text+combobox1.Text;
with adoquery1 do
begin
close;
sql.clear;
end;
mytables:=tstringlist.Create ;
main.ADOConnection1.GetTableNames(mytables);
if not (mytables.IndexOf(table_name)=-1) then
begin
with adoquery1 do
begin
close;
sql.clear;
if combobox3.text='全部人员' then sql.Add('select * from '+table_name)
else sql.Add('select * from '+table_name+' where 编制='+''''+combobox3.text+'''');
sql.add('order by 排序');
open;
end;
for i:=0 to adoquery1.FieldCount-1 do
if adoquery1.Fields.DataType in [ftFloat,ftCurrency,ftBCD] then
TFloatField(adoquery1.Fields).Displayformat:='#,##0.00';
edit3.text:=inttostr(adoquery1.RecordCount);
with hjje do
begin
close;
sql.clear;
sql.add('select sum(实发金额) from '+table_name);
if combobox3.text<>'全部人员' then sql.Add('where 编制='+''''+combobox3.text+'''');
open;
end;
edit4.Text:=hjje.Fields[0].asstring;
end;
end;
procedure Tmain.BitBtn10Click(Sender: TObject);
var
i:integer;
tmp_add,tmp_fie,add_fie:string;
begin
table_name:=edit1.Text+combobox1.Text;
if adoquery1.eof=false then
begin
tmp_add:='';
add_fie:='';
for i := 0 to adoquery1.FieldCount - 1 do
begin
tmp_fie:=adoquery1.Fields.FieldName;
gzjg.locate('项目',tmp_fie,[loCaseInsensitive]);
if trim(gzjg.FieldByName('类别').asstring)='加' then
begin
add_fie:=tmp_add+tmp_fie;
tmp_add:=add_fie+'+' ;
end;
end;
with xjgzb do
begin
close;
sql.Clear;
sql.add('update '+table_name+' set '+'应发金额='+add_fie);
execSQL;
end;
tmp_add:='';
add_fie:='';
for i := 0 to adoquery1.FieldCount - 1 do
begin
tmp_fie:=adoquery1.Fields.FieldName;
gzjg.locate('项目',tmp_fie,[loCaseInsensitive]);
if trim(gzjg.FieldByName('类别').asstring)='扣' then
begin
add_fie:=tmp_add+tmp_fie;
tmp_add:=add_fie+'-' ;
end;
end;
with xjgzb do
begin
close;
sql.Clear;
sql.add('update '+table_name+' set '+'实发金额=应发金额-'+add_fie);
execSQL;
end;
with adoquery1 do
begin
close;
sql.clear;
if combobox3.text='全部人员' then sql.Add('select * from '+table_name)
else sql.Add('select * from '+table_name+' where 编制='+''''+combobox3.text+'''');
sql.add('order by 排序');
open;
end;
for i:=0 to adoquery1.FieldCount-1 do
if adoquery1.Fields.DataType in [ftFloat,ftCurrency,ftBCD] then
TFloatField(adoquery1.Fields).Displayformat:='#,##0.00';
with hjje do
begin
close;
sql.clear;
sql.add('select sum(实发金额) from '+table_name);
if combobox3.text<>'全部人员' then sql.Add('where 编制='+''''+combobox3.text+'''');
open;
end;
edit4.Text:=hjje.Fields[0].asstring;
end;
end;
procedure Tmain.ADOQuery1AfterOpen(DataSet: TDataSet);
var
i:integer;
begin
with DBGrid1 do
for I := 0 to Columns.Count - 1 do
begin
if (Columns.Title.Caption='科室') or (Columns.Title.Caption ='姓名') then Columns.Width := 50 else Columns.Width := 50;
// if adoquery1.Fields.datatype<>ftstring then (adoquery1.Fields as TNumericField).DisplayFormat:='#.00';
end;
end;
procedure Tmain.BitBtn5Click(Sender: TObject);
var
i:integer;
begin
title_rep:=edit1.Text+'年'+combobox1.Text+'月份'+'工资发放花名册'+'('+combobox3.text+')';
hmc_tmp:='';
for i := 0 to adoquery1.FieldCount - 1 do
begin
if (adoquery1.Fields.FieldName<>'ID') and (adoquery1.Fields.FieldName<>'排序') and (adoquery1.Fields.FieldName<>'编制') then
if hmc_tmp='' then hmc_tmp:=adoquery1.Fields.FieldName else hmc_tmp:=hmc_tmp+','+adoquery1.Fields.FieldName;
end;
with gz do
begin
close;
sql.Clear;
sql.Add('select '+hmc_tmp+' from '+edit1.Text+combobox1.Text);
if combobox3.text<>'全部人员' then sql.Add('where 编制='+''''+combobox3.text+'''');
sql.add('order by 排序');
open;
end;
rmReport1.Pages.Clear;
rmReport1.Pages.Add;
rmReport1.pages.Pages[0].ChangePaper(256,3800,2800, 0,poPortrait);
Page := rmReport1.Pages[0];
gz_x:=40;
b := TrmBandView(rmCreateObject(gtBand, ''));
b.SetBounds(20, 20, 0, 112);
b.BandType := btpageheader;
Page.Objects.Add(b);
v := rmCreateObject(gtMemo, '');
v.SetBounds(20,60, 600, 32);
v.Memo.Add(title_rep);
TrmMemoView(v).Font.Name:='黑体';
TrmMemoView(v).Font.Size:=14;
TrmMemoView(v).BandAlign:=rmbacenter;
Page.Objects.Add(v);
b := TrmBandView(rmCreateObject(gtBand, ''));
b.SetBounds(20, 160, 0, 24);
b.BandType := btMasterData;
b.Dataset := 'rmDBDataSet1';
Page.Objects.Add(b);
b := TrmBandView(rmCreateObject(gtBand, ''));
b.SetBounds(20, 220, 0, 24);
b.BandType := btMasterfooter;
Page.Objects.Add(b);
for I:=0 to gz.FieldCount-1 do
begin
gz_xm:=gz.Fields.FieldName;
gzjg.locate('项目',gz_xm,[loCaseInsensitive]);
if gzjg.FieldByName('是否打印').asstring='Y' then
begin
if (gz_xm='科室') or (gz_xm='姓名') then fie_len:=40 else
begin
with chd do
begin
close;
sql.Clear;
sql.add('select sum('+gz_xm+') from '+table_name);
if combobox3.text<>'全部人员' then sql.Add('where 编制='+''''+combobox3.text+'''');
open;
end;
fie_len:=length(formatfloat('0.00',chd.Fields[0].asfloat))*6+5;
if fie_len<40 then fie_len:=40;
end;
begin
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,100, fie_len, 32);
v.Memo.Add(gz_xm);
v.Prop['WordWrap']:=true;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
TrmMemoView(v).Alignment:=rmtamiddle+rmtacenter;
Page.Objects.Add(v);
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,160, fie_len, 24);
v.Memo.Add('[gz."'+gz_xm+'"]');
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
TrmMemoView(v).FormatStr:='@@######';
if gz.Fields.DataType in [ftFloat,ftCurrency,ftBCD] then
begin
TrmMemoView(v).Format:=1 * $01000000 + 4 * $00010000+2*$00000100;
TrmMemoView(v).Format := TrmMemoView(v).Format + Ord('.');
TrmMemoView(v).FormatStr:='0.00';
end;
if (gz_xm='科室') or (gz_xm='姓名') then TrmMemoView(v).Alignment:=rmtamiddle
else TrmMemoView(v).Alignment:=rmtamiddle+rmtaright;
Page.Objects.Add(v);
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,220, fie_len, 24);
if gz_xm='科室'
then v.Memo.Add('合计')
else if gz_xm='姓名'
then v.Memo.Add(inttostr(gz.recordcount)+'人')
else
v.Memo.Add('[sum('+gz_xm+')]');
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
if gz.Fields.DataType in [ftFloat,ftCurrency,ftBCD] then
begin
TrmMemoView(v).Format:=1 * $01000000 + 4 * $00010000+2*$00000100;
TrmMemoView(v).Format := TrmMemoView(v).Format + Ord('.');
TrmMemoView(v).FormatStr:='0.00';
end;
if (gz_xm='科室') or (gz_xm='姓名') then TrmMemoView(v).Alignment:=rmtamiddle+rmtacenter
else TrmMemoView(v).Alignment:=rmtamiddle+rmtaright;
Page.Objects.Add(v);
gz_x:=gz_x+fie_len;
end;
end;
end;
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,100, 70, 32);
v.Memo.Add('签名');
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
TrmMemoView(v).Alignment:=rmtamiddle+rmtacenter;
Page.Objects.Add(v);
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,160, 70, 24);
v.Memo.Add('');
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
Page.Objects.Add(v);
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,220, 70, 24);
v.Memo.Add('');
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
Page.Objects.Add(v);
rmReport1.ShowReport;
// rmReport1.DesignReport;
end;
procedure Tmain.BitBtn3Click(Sender: TObject);
var
i:integer;
begin
table_name:=edit1.Text+combobox1.Text;
title_rep:=edit1.Text+'年'+combobox1.Text+'月份'+'工资发放汇总表'+'('+combobox3.text+')';
hz_tmp:='';
for i := 0 to adoquery1.FieldCount - 1 do
begin
if (adoquery1.Fields.FieldName<>'ID') and (adoquery1.Fields.FieldName<>'排序') and (adoquery1.Fields.FieldName<>'编制') and (adoquery1.Fields.FieldName<>'姓名') then
if (adoquery1.Fields.FieldName='科室') then if hz_tmp='' then hz_tmp:='科室,count(科室) as 人数' else hz_tmp:=hz_tmp+','+'科室,count(科室) as 人数' else if hz_tmp='' then hz_tmp:='sum('+adoquery1.Fields.FieldName+') as '+adoquery1.Fields.FieldName else hz_tmp:=hz_tmp+','+'sum('+adoquery1.Fields.FieldName+') as '+adoquery1.Fields.FieldName;
end;
with gz do
begin
close;
sql.Clear;
sql.Add('select '+hz_tmp+' from '+edit1.Text+combobox1.Text);
if combobox3.text<>'全部人员' then sql.Add('where 编制='+''''+combobox3.text+'''');
sql.add('group by 科室');
open;
end;
rmReport1.Pages.Clear;
rmReport1.Pages.Add;
rmReport1.pages.Pages[0].ChangePaper(256,3800,2800, 0,poPortrait);
Page := rmReport1.Pages[0];
gz_x:=40;
b := TrmBandView(rmCreateObject(gtBand, ''));
b.SetBounds(20, 20, 0, 60);
b.BandType := btpageheader;
Page.Objects.Add(b);
v := rmCreateObject(gtMemo, '');
v.SetBounds(20,40, 700, 32);
v.Memo.Add(title_rep);
TrmMemoView(v).Font.Name:='黑体';
TrmMemoView(v).Font.Size:=14;
TrmMemoView(v).BandAlign:=rmbacenter;
Page.Objects.Add(v);
b := TrmBandView(rmCreateObject(gtBand, ''));
b.SetBounds(20, 100, 0, 40);
b.BandType := btMasterheader;
Page.Objects.Add(b);
b := TrmBandView(rmCreateObject(gtBand, ''));
b.SetBounds(20, 160, 0, 16);
b.BandType := btMasterData;
b.Dataset := 'rmDBDataSet1';
Page.Objects.Add(b);
b := TrmBandView(rmCreateObject(gtBand, ''));
b.SetBounds(20, 220, 0, 16);
b.BandType := btMasterfooter;
Page.Objects.Add(b);
for I:=0 to gz.FieldCount-1 do
begin
gz_xm:=gz.Fields.FieldName;
gzjg.locate('项目',gz_xm,[loCaseInsensitive]);
if gzjg.FieldByName('是否打印').asstring='Y' then
begin
if gz_xm='科室' then fie_len:=40 else
if gz_xm='人数' then fie_len:=30 else
begin
with chd do
begin
close;
sql.Clear;
sql.add('select sum('+gz_xm+') from '+table_name);
if combobox3.text<>'全部人员' then sql.Add('where 编制='+''''+combobox3.text+'''');
open;
end;
fie_len:=length(formatfloat('0.00',chd.Fields[0].asfloat))*6+5;
if fie_len<40 then fie_len:=40;
if odd(fie_len)=false then fie_len:=fie_len+1;
end;
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,100, fie_len, 40);
v.Memo.Add(gz_xm);
v.Prop['WordWrap']:=true;
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
TrmMemoView(v).Alignment:=rmtamiddle+rmtacenter;
Page.Objects.Add(v);
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,160, fie_len, 16);
v.Memo.Add('[gz."'+gz_xm+'"]');
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
if gz.Fields.DataType in [ftFloat,ftCurrency,ftBCD] then
begin
TrmMemoView(v).Format:=1 * $01000000 + 4 * $00010000+2*$00000100;
TrmMemoView(v).Format := TrmMemoView(v).Format + Ord('.');
TrmMemoView(v).FormatStr:='0.00';
end;
if gz_xm='科室' then TrmMemoView(v).Alignment:=rmtamiddle
else TrmMemoView(v).Alignment:=rmtamiddle+rmtaright;
Page.Objects.Add(v);
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,220, fie_len, 16);
if gz.Fields.DataType in [ftFloat,ftCurrency,ftBCD] then
begin
TrmMemoView(v).Format:=1 * $01000000 + 4 * $00010000+2*$00000100;
TrmMemoView(v).Format := TrmMemoView(v).Format + Ord('.');
TrmMemoView(v).FormatStr:='0.00';
end;
if gz_xm='科室' then v.Memo.Add('合计') else v.Memo.Add('[sum('+gz_xm+')]');
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
if gz_xm='科室' then TrmMemoView(v).Alignment:=rmtamiddle+rmtacenter
else TrmMemoView(v).Alignment:=rmtamiddle+rmtaright;
Page.Objects.Add(v);
gz_x:=gz_x+fie_len;
end;
end;
rmReport1.ShowReport;
end;
procedure Tmain.BitBtn6Click(Sender: TObject);
var
i:integer;
begin
title_rep:=edit1.Text+'年'+combobox1.Text+'月份'+'工资发放个人表';
hmc_tmp:='';
for i := 0 to adoquery1.FieldCount - 1 do
begin
if (adoquery1.Fields.FieldName<>'ID') and (adoquery1.Fields.FieldName<>'排序') and (adoquery1.Fields.FieldName<>'编制') then
if hmc_tmp='' then hmc_tmp:=adoquery1.Fields.FieldName else hmc_tmp:=hmc_tmp+','+adoquery1.Fields.FieldName;
end;
with gz do
begin
close;
sql.Clear;
sql.Add('select '+hmc_tmp+' from '+edit1.Text+combobox1.Text);
sql.add('order by 排序');
open;
end;
rmReport1.Pages.Clear;
rmReport1.Pages.Add;
rmReport1.pages.Pages[0].ChangePaper(256,3800,2800, 0,poPortrait);
Page := rmReport1.Pages[0];
b := TrmBandView(rmCreateObject(gtBand, ''));
b.SetBounds(20, 20, 0, 60);
b.BandType := btpageheader;
Page.Objects.Add(b);
v := rmCreateObject(gtMemo, '');
v.SetBounds(20,40, 600, 32);
v.Memo.Add(title_rep);
TrmMemoView(v).Font.Name:='黑体';
TrmMemoView(v).Font.Size:=14;
TrmMemoView(v).BandAlign:=rmbacenter;
Page.Objects.Add(v);
b := TrmBandView(rmCreateObject(gtBand, ''));
b.SetBounds(20, 140, 20, 68);
b.BandType := btMasterData;
b.Dataset := 'rmDBDataSet1';
Page.Objects.Add(b);
gz_x:=40;
for I:=0 to gz.FieldCount-1 do
begin
gz_xm:=gz.Fields.FieldName;
gzjg.locate('项目',gz_xm,[loCaseInsensitive]);
if gzjg.FieldByName('是否打印').asstring='Y' then
begin
if (gz_xm='科室') or (gz_xm='姓名') then fie_len:=40 else
begin
with chd do
begin
close;
sql.Clear;
sql.add('select sum('+gz_xm+') from '+table_name);
open;
end;
fie_len:=length(formatfloat('0.00',chd.Fields[0].asfloat))*6;
if fie_len<40 then fie_len:=40;
if odd(fie_len)=false then fie_len:=fie_len+1;
end;
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,140,fie_len, 32);
v.Memo.Add(gz_xm);
v.Prop['WordWrap']:=true;
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
TrmMemoView(v).Alignment:=rmtamiddle+rmtacenter;
Page.Objects.Add(v);
v := rmCreateObject(gtMemo, '');
v.SetBounds(gz_x,172, fie_len, 16);
v.Memo.Add('[gz."'+gz_xm+'"]');
TrmMemoView(v).Font.Name:='宋体';
TrmMemoView(v).Font.Size:=9;
v.TopFrame.Visible:=true;v.BottomFrame.Visible:=true;v.rightFrame.Visible:=true;v.LeftFrame.Visible:=true;
if gz.Fields.DataType in [ftFloat,ftCurrency,ftBCD] then
begin
TrmMemoView(v).Format:=1 * $01000000 + 4 * $00010000+2*$00000100;
TrmMemoView(v).Format := TrmMemoView(v).Format + Ord('.');
TrmMemoView(v).FormatStr:='0.00';
end;
if (gz_xm='科室') or (gz_xm='姓名') then TrmMemoView(v).Alignment:=rmtamiddle
else TrmMemoView(v).Alignment:=rmtamiddle+rmtaright;
Page.Objects.Add(v);
gz_x:=gz_x+fie_len;
end;
end;
rmReport1.ShowReport;
end;
procedure Tmain.ADOTable1AfterPost(DataSet: TDataSet);
begin
combobox3.items.clear;
combobox3.items.add('全部人员');
adotable1.First;
while adotable1.eof=false do
begin
combobox3.items.add(adotable1.Fields[1].asstring);
adotable1.Next;
end;
combobox3.ItemIndex:=0;
end;
end.