📄 publicunit.~pas
字号:
MyReportPageFootLabel: TQRLabel;
MyData: TQRSysData;
MyQRShape: TQRShape;
DataLabel: TQRLabel;
i, GWidth, Heigh: integer;
fn: string;
MaxWidth: integer;
begin
Screen.Cursor := crHourGlass;
Result := False;
AReport := nil;
AReport := TQuickRep.Create(Application);
with AReport.Page do
begin
TopMargin := MyPageDesign.ReportPageTopMargin;
BottomMargin := MyPageDesign.ReportPageBottomMargin;
LeftMargin := MyPageDesign.ReportPageLeftMargin;
RightMargin := MyPageDesign.ReportPageRightMargin;
if MyPageDesign.ReportOrientation = Vertical then
Orientation := poPortrait
else
Orientation := poLandscape;
end;
GWidth := 0;
Heigh := 0;
if MyPageDesign.ReportOrientation = Horizand then
MaxWidth := 950
else
MaxWidth := 600;
with AReport do
begin
DataSet := CPrintPreviewADOQuery;
//页首设计
Bands.HasPageHeader := True;
Bands.PageHeaderBand.Height := 60;
if MyPageDesign.ReportPrintDate then
begin
DataLabel := TQRLabel(Bands.PageHeaderBand.AddPrintable(TQRLabel));
DataLabel.Caption := '打印日期';
if MyPageDesign.ReportOrientation = Vertical then
DataLabel.Left := 580;
if MyPageDesign.ReportOrientation = Horizand then
DataLabel.Left := 900;
DataLabel.Font.Name := '宋体';
DataLabel.Font.Size := 10;
DataLabel.Top := 2;
MyData := TQRSysData(Bands.PageHeaderBand.AddPrintable(TQRSysData));
MyData.Data := qrsDate;
MyData.Alignment := taCenter;
MyData.Left := DataLabel.Left + 70;
MyData.Top := 0;
end;
//页眉设计
MyReportPageHeadLabel :=
TQRLabel(Bands.PageHeaderBand.AddPrintable(TQRLabel));
with MyReportPageHeadLabel do
begin
Caption := MyPageDesign.ReportPageHead;
AutoSize := True;
Left := 20;
Font := MyPageDesign.ReportPageHeadFont;
Top := 0;
end;
//报表名称设计
MyReportNameLabel := TQRLabel(Bands.PageHeaderBand.AddPrintable(TQRLabel));
with MyReportNameLabel do
begin
Caption := MyPageDesign.ReportName;
Font := MyPageDesign.ReportNameFont;
AlignToBand := True;
Alignment := taCenter;
Top := 20;
end;
if ((MyReportPageHeadLabel.Caption <> EmptyStr) or
(MyPageDesign.ReportPrintDate = True)) then
begin
MyQRShape := TQRShape(Bands.PageHeaderBand.AddPrintable(TQRShape));
with MyQRShape do
begin
Left := 0;
Width := Bands.PageHeaderBand.Width;
Height := 1;
Pen.Width := 1;
Top := MyReportPageHeadLabel.Top + MyReportPageHeadLabel.Height + 2;
end;
end;
//表头说明设计
if MyPageDesign.ReportTitleDeclare <> '' then
begin
Bands.HasTitle := True;
MyReportTitleDeclareLabel :=
TQRLabel(Bands.TitleBand.AddPrintable(TQRLabel));
with MyReportTitleDeclareLabel do
begin
Caption := MyPageDesign.ReportTitleDeclare;
Font := MyPageDesign.ReportTitleDeclareFont;
AlignToBand := True;
Alignment := taRightJustify;
Top := 0;
end;
if MyPageDesign.AddHGrid then
Bands.TitleBand.Frame.DrawBottom := true;
end;
//关于报表表体及其字体的设计
Bands.HasColumnHeader := True;
Bands.ColumnHeaderBand.Height := MyPageDesign.ReportBodyHeadRowHeight;
Bands.HasDetail := true;
Bands.DetailBand.Height := MyPageDesign.ReportBodyRowHeight;
{ with Frame ,MyPageDesign do
begin
DrawTop :=TopFrameLine ;
DrawBottom :=BottomFrameLine ;
DrawLeft :=LeftFrameLine ;
DrawRight :=RightFrameLine ;
end;
} if MyPageDesign.AddHGrid then
begin
with Bands.ColumnHeaderBand.Frame do
begin
DrawBottom := true;
DrawTop := True;
DrawLeft := True;
DrawRight := True;
end;
with Bands.DetailBand.Frame do
begin
// DrawBottom:=true;
// DrawTop:=true;
DrawLeft := true;
DrawRight := true;
end;
end;
{spring 2001-9-17}
if MyPageDesign.AddNo then
begin
DataLabel := TQRLabel(Bands.ColumnHeaderBand.AddPrintable(TQRLabel));
with DataLabel do
begin
Caption := 'No.';
Left := GWidth + 2;
Width := 22;
Font := MyPageDesign.ReportHeadFont;
Top := 16;
Alignment := taCenter;
end;
MyData := TQRSysData(Bands.DetailBand.AddPrintable(TQRSysData));
with MyData do
begin
Data := qrsDetailNo;
Left := GWidth + 2;
Width := 22;
Font := MyPageDesign.ReportBodyFont;
Top := (MyPageDesign.ReportBodyRowHeight +
MyPageDesign.ReportBodyFont.Height) div 2;
end;
GWidth := GWidth + 24;
if MyPageDesign.AddSGrid then
begin
GWidth := GWidth + 5;
MyQRShape := TQRShape(Bands.ColumnHeaderBand.AddPrintable(TQRShape));
MyQRShape.Left := GWidth;
MyQRShape.Pen.Width := 1;
MyQRShape.Width := 1;
MyQRShape.Top := 0;
MyQRShape.Height := MyPageDesign.ReportBodyHeadRowHeight;
MyQRShape := TQRShape(Bands.DetailBand.AddPrintable(TQRShape));
MyQRShape.Left := GWidth;
MyQRShape.Pen.Width := 1;
MyQRShape.Width := 1;
MyQRShape.Top := -2; //DetailBand中线宽的2倍取反.
MyQRShape.Height := MyPageDesign.ReportBodyRowHeight;
end;
end;
{spring 2001-9-17}
for i := 0 to DataSet.FieldCount - 1 do
begin
MyColumnHeaderLabel :=
TQRLabel(Bands.ColumnHeaderBand.AddPrintable(TQRLabel));
with MyColumnHeaderLabel do
begin
fn := aReport.DataSet.Fields[i].FieldName;
if FieldNameE.IndexOf(fn) <> -1 then
Caption := FieldNameC[FieldNameE.IndexOf(fn)]
else
Caption := fn;
Left := GWidth + 5;
AutoSize := False;
{spring 2001-9-13}
Width := StrtoInt(MyPageDesign.ReportBodyColsWidth[i]);
{-spring 2001-9-13}
{ if MyPageDesign.ReportBodyColsWidth.Count=DataSet.FieldCount
then Width:=StrtoInt(MyPageDesign.ReportBodyColsWidth[i])*6
else Width:=DataSet.Fields[i].DisplayWidth*6;}
Font := MyPageDesign.ReportHeadFont;
Top := 16;
Alignment := taCenter;
end;
MyDetailQRDBText := TQRDBText(Bands.DetailBand.AddPrintable(TQRDBText));
with MyDetailQRDBText do
begin
DataSet := aReport.DataSet;
DataField := DataSet.Fields[i].FieldName;
Left := GWidth + 5;
AutoSize := False;
if DataSet.Fields[i].DataType in [ftFloat, ftCurrency, ftBCD] then
MyDetailQRDBText.Mask := '#,##0.00';
{spring 2001-9-13}
Width := StrtoInt(MyPageDesign.ReportBodyColsWidth[i]);
Alignment := MyPageDesign.ReportBodyAlignment[i];
// AutoStretch :=True ;
{-spring 2001-9-13}
{ if MyPageDesign.ReportBodyColsWidth.Count=DataSet.FieldCount
then Width:=StrtoInt(MyPageDesign.ReportBodyColsWidth[i])*6
else Width:=DataSet.Fields[i].DisplayWidth*6;}
Font := MyPageDesign.ReportBodyFont;
Top := (MyPageDesign.ReportBodyRowHeight +
MyPageDesign.ReportBodyFont.Height) div 2;
if CPrintPreviewADOQuery.FieldCount =
Length(MyPageDesign.ReportBodyAlignment) then
Alignment := MyPageDesign.ReportBodyAlignment[i];
end;
GWidth := GWidth + StrtoInt(MyPageDesign.ReportBodyColsWidth[i]);
{ if MyPageDesign.ReportBodyColsWidth.Count=DataSet.FieldCount
then GWidth:=GWidth+StrtoInt(MyPageDesign.ReportBodyColsWidth[i])*6
else GWidth:=GWidth+DataSet.Fields[i].DisplayWidth*6;
}
{spring 2001-9-13}
if GWidth > MaxWidth then
break;
{-spring 2001-9-13}
//关于报表中的竖线
if (MyPageDesign.AddSGrid and (i < DataSet.FieldCount - 1)) and (GWidth <=
MaxWidth) then
begin
GWidth := GWidth + 5;
MyQRShape := TQRShape(Bands.ColumnHeaderBand.AddPrintable(TQRShape));
MyQRShape.Left := GWidth;
MyQRShape.Pen.Width := 1;
MyQRShape.Width := 1;
MyQRShape.Top := 0;
MyQRShape.Height := MyPageDesign.ReportBodyHeadRowHeight;
MyQRShape := TQRShape(Bands.DetailBand.AddPrintable(TQRShape));
MyQRShape.Left := GWidth;
MyQRShape.Pen.Width := 1;
MyQRShape.Width := 1;
MyQRShape.Top := -2; //DetailBand中线宽的2倍取反.
MyQRShape.Height := MyPageDesign.ReportBodyRowHeight;
end;
end;
//表尾设计
Bands.HasSummary := True;
if MyPageDesign.AddHGrid then
begin
// Bands.SummaryBand.Frame.DrawBottom:=true;
Bands.SummaryBand.Frame.DrawTop := true;
// Bands.SummaryBand.Frame.DrawLeft:=True;
// Bands.SummaryBand.Frame.DrawRight:=True;
end;
if MyPageDesign.ReportEndDeclare <> '' then
begin
MyReportEndDeclareLabel :=
TQRLabel(Bands.SummaryBand.AddPrintable(TQRLabel));
with MyReportEndDeclareLabel do
begin
Caption := MyPageDesign.ReportEndDeclare;
Font := MyPageDesign.ReportEndDeclareFont;
AlignToBand := True;
Alignment := taRightJustify;
Heigh := Heigh + 20;
Top := Heigh;
end;
end;
if MyPageDesign.ReportOthers <> '' then
begin
MyReportOthersLabel := TQRLabel(Bands.SummaryBand.AddPrintable(TQRLabel));
with MyReportOthersLabel do
begin
Caption := MyPageDesign.ReportOthers;
Font := MyPageDesign.ReportEndDeclareFont;
AlignToBand := True;
Alignment := taLeftJustify;
Heigh := Heigh + 20;
Top := Heigh;
end;
end;
if MyPageDesign.ReportBuilder <> '' then
begin
MyReportBuilderLabel :=
TQRLabel(Bands.SummaryBand.AddPrintable(TQRLabel));
with MyReportBuilderLabel do
begin
Caption := '报表制作人:' + MyPageDesign.ReportBuilder;
Font := MyPageDesign.ReportEndDeclareFont;
AlignToBand := True;
Alignment := taRightJustify;
Heigh := Heigh + 20;
Top := Heigh;
end;
end;
//页尾设计
Bands.HasPageFooter := true;
//spring
//Bands.PageFooterBand.Frame.rawTop:=True ;
MyQRShape := TQRShape.Create(nil);
MyQRShape.Left := 0;
MyQRShape.Pen.Width := 1;
MyQRShape.Width := 600;
MyQRShape.Height := 1;
MyQRShape.Top := AReport.Height - 140 - MyPageDesign.ReportBodyRowHeight -
MyPageDesign.ReportPageTopMargin - MyPageDesign.ReportBodyRowHeight *
MyPageDesign.PageLinesNumber;
//spring
Bands.PageFooterBand.Height := MyPageDesign.ReportPageFootHeight;
if MyPageDesign.ReportPageNumber then
begin
MyPage := TQRSysData(Bands.PageFooterBand.AddPrintable(TQRSysData));
MyPage.Data := qrsPageNumber;
MyPage.Alignment := taCenter;
if MyPageDesign.ReportOrientation = Vertical then
MyPage.Left := 650;
if MyPageDesign.ReportOrientation = Horizand then
MyPage.Left := 960;
MyPage.Top := MyPageDesign.ReportPageFootHeight - 50;
end;
//页脚设计
MyReportPageFootLabel :=
TQRLabel(Bands.PageFooterBand.AddPrintable(TQRLabel));
with MyReportPageFootLabel do
begin
Caption := MyPageDesign.ReportPageFoot;
Left := 20;
Font := MyPageDesign.ReportPageFootFont;
Top := MyPageDesign.ReportPageFootHeight - 50;
end;
end;
if MyPageDesign.AddHGrid then
begin
MyQRShape := TQRShape(AReport.Bands.DetailBand.AddPrintable(TQRShape));
MyQRShape.Left := 0;
MyQRShape.Pen.Width := 1;
MyQRShape.Width := AReport.Bands.DetailBand.Width - 2;
{if MyPageDesign.ReportOrientation =Vertical then
MyQRShape.Width:=718-2;
if MyPageDesign.ReportOrientation =Horizand then
MyQRShape.Width :=1047-2;}
MyQRShape.Height := 1;
// MyQRShape.Top:=MyPageDesign.ReportBodyRowHeight -1;
MyQRShape.Top := MyPageDesign.ReportBodyRowHeight - 2; //常数是线宽的2倍
end;
CReport := AReport;
Result := True;
Screen.Cursor := crDefault;
end;
procedure SetPageDesignColsWidth(MyPageDesign: TPageDesign; DBGrid: TDBGrid);
var
PrintPreviewADOQuery: TADOQuery;
ss: string;
i: integer;
begin
if ((MyPageDesign.CTableName = '') and (MyPageDesign.CSQLFileName = '') and
(MyPageDesign.CSqlString.Count = 0)) then
Exit;
ss := 'Provider=SQLOLEDB.1;Persist Security Info=False;Password=' +
PublicUnit.DBPass + ';User ID=' + PublicUnit.DBUser + ';Initial Catalog=';
ss := ss + PublicUnit.DbName + ';Data Source=' + PublicUnit.ServerName + '';
PrintPreviewADOQuery := TADOQuery.Create(Application);
with PrintPreviewADOQuery do
begin
Close;
ConnectionString := ss;
Sql.Clear;
if MyPageDesign.CTableName <> '' then
begin
Sql.Add('Select *');
Sql.Add('From "' + MyPageDesign.CTableName + '"')
end
else if MyPageDesign.CSqlFileName <> '' then
begin
Sql.LoadFromFile(MyPageDesign.CSQLFileName);
end
else
begin
Sql.Assign(MyPageDesign.CSqlString);
end;
if not ExecuteSQLStatement(PrintPreviewADOQuery) then
begin
Screen.Cursor := crDefault;
ShowMessage('无法打开指定的数据库查询文件,请与系统管理员联系');
Free;
Exit;
end;
end;
(DbGrid.DataSource as TDataSource).DataSet := PrintPreviewADOQuery;
MyPageDesign.ReportBodyColsWidth.Clear;
SetLength(MyPageDesign.ReportBodyAlignment, PrintPreviewADOQuery.FieldCount);
for i := 0 to PrintPreviewADOQuery.FieldCount - 1 do
begin
MyPageDesign.ReportBodyColsWidth.Add(IntToStr(DBGrid.Columns[i].Width));
MyPageDesign.ReportBodyAlignment[i] := DBGrid.Columns[i].Alignment;
if DBGrid.Columns[i].Width > (DBGrid.Width div 5) * 2 then
DBGrid.Columns[i].Width := (DBGrid.Width div 5) * 2;
end;
(DbGrid.DataSource as TDataSource).DataSet := nil;
PrintPreviewADOQuery.Close;
PrintPreviewADOQuery.Free;
end;
procedure CreateDirInCurrentApp(DirName: string);
var
MyDir: string;
begin
MyDir := ExtractFilePath(Application.ExeName) + DirName + '\';
if not DirectoryExists(MyDir) then
CreateDir(MyDir);
end;
function WholePathOfDir(DirName: string): string;
begin
Result := ExtractFilePath(Application.ExeName) + DirName + '\';
end;
function WholePathOfReportFile(FileName: string): string;
var
s: string;
begin
s := ExtractFilePath(Application.ExeName);
Result := Copy(s, 1, Pos('\bin\', LowerCase(s))) + 'Data\' + FileName;
end;
procedure CreateReportTemplate(MyPageDesign: TPageDesign; TemplateName: string);
var
i: integer;
TempIni: TIniFile;
begin
TempIni := TIniFile.Create(WholePathOfReportFile(TemplateName));
with TempIni, MyPageDesign do
begin
WriteString('RDescription', 'ReportName', ReportName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -