我前二天写了一个工资管理程序,就是可以随时动态打印,在报表生成过程中可自动分析
哪些是应该打的,哪些是不应该的要,并可以根据本列中最长的字符长度自动设置该栏
宽度。可现在改成report machine的了。
请看部分源码:
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 - 1do
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 gzdo
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-1do
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 chddo
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;