📄 dayreport.pas
字号:
unit dayreport;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, Buttons, FR_Class, FR_DSet, FR_DBSet, DB,
ADODB;
type
TFrmdayreport = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
mydate: TDateTimePicker;
SpeedButton1: TSpeedButton;
frReport1: TfrReport;
frDBDataSet1: TfrDBDataSet;
ADOQuery1: TADOQuery;
procedure SpeedButton1Click(Sender: TObject);
procedure createreport(dataset:Tdataset;sumdate:Tdatetime);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Frmdayreport: TFrmdayreport;
implementation
uses dbmodule;
{$R *.dfm}
procedure TFrmdayreport.createreport(dataset:Tdataset;sumdate:Tdatetime);
var
v: TfrView;
b: TfrBandView;
Page: TfrPage;
fieldcount:integer;
datamemo:string;
begin
//frReport1.Clear;
//frReport1.Pages.Free;
//if frReport1.Pages.Count>0 then
// showmessage('报表生成前没有清除。')
// else
// showmessage('报表生成前已清除');
if frReport1.Pages=Nil then
begin
frReport1.Pages.Create(frReport1);
end;
frReport1.Pages.Add; // create page
Page := frReport1.Pages[0];
page.pgMargins.Top:=36;
b := TfrBandView(frCreateObject(gtBand, '')); // create ReportHeader band
b.SetBounds(0,36,757,76);
b.BandType := btpageheader;
Page.Objects.Add(b);
v := TfrMemoView.Create; // create memo
v.SetBounds(216,48, 304, 32);
v.BandAlign := baWidth;
v.Prop['Alignment'] := frtaCenter; // another way to access properties
v.Prop['Font.Style'] := 2;
v.Prop['Font.Name']:='宋体';
v.Prop['Font.Size']:=16;
v.Memo.Add('上岛咖啡营业明细日报表');
Page.Objects.Add(v);
v := TfrMemoView.Create; // create memo
v.SetBounds(452,88,260,20);
//v.BandAlign := baWidth;
//v.Prop['Alignment'] := frtaRight; // another way to access properties
v.Prop['Font.Style'] := 2;
v.Prop['Font.Name']:='宋体';
v.Prop['Font.Size']:=10;
v.Memo.Add('统计日期:'+datetostr(sumdate));
Page.Objects.Add(v);
b := TfrBandView(frCreateObject(gtBand, '')); // create MasterHeader band
b.SetBounds(0,112,757,36);
b.BandType := btMasterheader;
Page.Objects.Add(b);
for Fieldcount:=0 to DataSet.FieldCount-1 do //create masterheadermemo
begin
v := TfrMemoView.Create;
v.SetBounds(64+(Fieldcount*96),128, 96, 20);
v.Prop['Alignment'] :=frtaMiddle+frtaCenter;
v.Prop['Font.Style'] := 2;
v.Prop['Font.Name']:='宋体';
v.Prop['Font.Size']:=10;
v.Prop['FrameTyp']:=15;
v.Memo.Add(DataSet.Fields[Fieldcount].FieldName);
Page.Objects.Add(v);
end;
b := TfrBandView(frCreateObject(gtBand, '')); // create MasterData band
b.SetBounds(0,158,757, 20);
b.BandType := btMasterData;
b.Dataset := 'frDBDataSet1'; // band's dataset
Page.Objects.Add(b);
for Fieldcount:=0 to DataSet.FieldCount-1 do //create MasterDataMemo
begin
v := TfrMemoView.Create;
v.SetBounds(64+(Fieldcount*96),158,96, 20);
v.Prop['Alignment'] :=frtaMiddle+frtaCenter;
v.Prop['Font.Style'] := 1;
v.Prop['Font.Name']:='宋体';
v.Prop['Font.Size']:=10;
v.Prop['FrameTyp']:=15;
if DataSet.Fields[Fieldcount].DataType in [ftFloat, ftCurrency, ftBCD] then
begin
datamemo:='['+dataset.Name+'.'+DataSet.Fields[Fieldcount].FieldName+' #9.2]';
end
else
datamemo:='['+dataset.Name+'.'+DataSet.Fields[Fieldcount].FieldName+']';
v.Memo.Add(datamemo);
Page.Objects.Add(v);
end;
b := TfrBandView(frCreateObject(gtBand, '')); // create Reportfooter band
b.SetBounds(0,256,757,34);
b.BandType := btpagefooter;
Page.Objects.Add(b);
v := TfrMemoView.Create; // create memo
v.SetBounds(330,256,96,20);
v.BandAlign := baWidth;
v.Prop['Alignment'] := frtaCenter; // another way to access properties
v.Prop['Font.Style'] := 2;
v.Prop['Font.Name']:='宋体';
v.Prop['Font.Size']:=10;
v.Memo.Add('[page#]');
Page.Objects.Add(v);
frReport1.PrepareReport;
//frReport1.ShowReport;
frReport1.ShowPreparedReport;
//frReport1.EMFPages.Free;
//frReport1.Pages.Free;
frReport1.Pages.Clear;
//frReport1.Preview.Free;
// if frReport1.Pages.Count>0 then
// showmessage('报表没有清除。')
// else
// showmessage('报表已清除');
end;
procedure TFrmdayreport.SpeedButton1Click(Sender: TObject);
begin
if adoquery1.Active then
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('TRANSFORM sum(Q_customertemp.caipincount*Q_customertemp.caipinprice) AS heji');
adoquery1.SQL.Add(' SELECT Q_customertemp.chuanbiaohao as 传票号码,Q_customertemp.fangtaiid as 房台编号');
adoquery1.SQL.Add(' FROM ((Q_caipin INNER JOIN Q_childclass ON Q_caipin.chclassid=Q_childclass.chclassid) INNER JOIN Q_customertemp ON Q_caipin.Caipinid=Q_customertemp.Caipinid) INNER JOIN Q_masterclass ON Q_childclass.Mclassid=Q_masterclass.mclassid');
adoquery1.SQL.Add(' WHERE Q_customertemp.opratedate between #'+datetostr(mydate.Date)+' 00:00:00# and #'+datetostr(mydate.Date)+' 23:59:59#');
adoquery1.SQL.Add(' GROUP BY Q_customertemp.chuanbiaohao,Q_customertemp.fangtaiid');
adoquery1.SQL.Add(' PIVOT Q_masterclass.Mclass_name');
adoquery1.Open;
if not adoquery1.Eof then
createreport(adoquery1,mydate.Date)
else
application.MessageBox('没有要查询的数据。','提示',mb_ok);
adoquery1.Close;
end;
procedure TFrmdayreport.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if adoquery1.Active then
adoquery1.Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -