rm_ptopgrid.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,027 行 · 第 1/3 页
PAS
1,027 行
aFormReport.ColumnHeaderViews.Add(liView);
tmpx := tmpx + liView.spWidth;
if rmgoDoubleFrame in aFormReport.ReportOptions then
begin
if liFlagFirstColumn then
liView.LeftFrame.spWidth := 2;
liView.TopFrame.spWidth := 2;
end;
liFlagFirstColumn := False;
end;
procedure MakeOneDetail(aIndex: Integer);
var
liCol: TtsDBCol;
begin
liCol := liGrid.Col[aIndex];
if liCol.ControlType = ctPicture then
begin
liView := TRMPictureView(RMCreateObject(gtPicture, ''));
liView.ParentPage := liPage;
liView.Memo.Text := Format('[%s.%s."%s"]', [DSet.Owner.Name, DSet.Name, liCol.DatasetField.FieldName]);
TRMPictureView(liView).PictureRatio := TRUE;
TRMPictureView(liView).PictureStretched := (liCol.StretchPicture = dopOn) or ((liCol.StretchPicture = dopDefault) and liGrid.StretchPicture);
TRMPictureView(liView).PictureCenter := liGrid.CenterPicture;
end
else
begin
liView := TRMMemoView(RMCreateObject(gtMemo, ''));
liView.ParentPage := liPage;
TRMMemoView(liView).Stretched := rmgoStretch in aFormReport.ReportOptions;
if liCol.Font <> nil then
aFormReport.AssignFont(TRMMemoView(liView), liCol.Font)
else
aFormReport.AssignFont(TRMMemoView(liView), liGrid.Font);
liView.Memo.Text := Format('[%s.%s."%s"]', [DSet.Owner.Name, DSet.Name, liCol.FieldName]);
TRMMemoView(liView).WordWrap := (liCol.WordWrap = wwOn) or ((liCol.WordWrap = wwDefault) and (liGrid.WordWrap = wwOn));
case liCol.HorzAlignment of
htaLeft: TRMMemoView(liView).HAlign := rmhLeft;
htaRight: TRMMemoView(liView).HAlign := rmhRight;
else
TRMMemoView(liView).HAlign := rmhCenter;
end;
case liCol.VertAlignment of
vtaCenter: TRMMemoView(liView).VAlign := rmvCenter;
vtaBottom: TRMMemoView(liView).VAlign := rmvBottom;
else
TRMMemoView(liView).VAlign := rmvTop;
end;
THackFormReport(aFormReport).SetMemoViewFormat(TRMMemoView(liView), liCol.DatasetField);
end;
if rmgoGridLines in aFormReport.ReportOptions then
begin
liView.LeftFrame.Visible := True;
liView.TopFrame.Visible := True;
liView.RightFrame.Visible := True;
liView.BottomFrame.Visible := True;
end
else
begin
liView.LeftFrame.Visible := False;
liView.TopFrame.Visible := False;
liView.RightFrame.Visible := False;
liView.BottomFrame.Visible := False;
end;
liView.spLeft := tmpx;
liView.spTop := 0;
liView.spWidth := liCol.Width + 1;
liView.spHeight := liGrid.DefaultRowHeight + 4;
if rmgoUseColor in aFormReport.ReportOptions then
liView.FillColor := liGrid.Color;
if liCol.DatasetField = nil then
begin
liNeedBeforePrint := True;
FList.Add(liView.Name);
liView.Memo.Text := IntToStr(aIndex);
end;
aFormReport.PageDetailViews.Add(liView);
tmpx := tmpx + liView.spWidth;
if Assigned(aFormReport.OnAfterCreateGridObjectEvent) then
aFormReport.OnAfterCreateGridObjectEvent(aControl, DSet.Fields[aIndex].FieldName, liView);
if rmgoDoubleFrame in aFormReport.ReportOptions then
begin
if liFlagFirstColumn then
liView.LeftFrame.spWidth := 2;
end;
DrawDoubleFrameBottom(liView, aFormReport.ColumnFooterViews);
liFlagFirstColumn := False;
end;
procedure DrawFixedColHeader;
var
i: Integer;
liCol: TtsDBCol;
begin
for i := 1 to aFormReport.GridFixedCols do
begin
liCol := liGrid.Col[i];
if not liCol.Visible then Continue;
if i < liGrid.Cols then
MakeOneHeader(i);
end;
end;
procedure DrawFixedColDetail;
var
i: Integer;
liCol: TtsDBCol;
begin
for i := 1 to aFormReport.GridFixedCols do
begin
liCol := liGrid.Col[i];
if not liCol.Visible then Continue;
if i < liGrid.Cols then
MakeOneDetail(i);
end;
end;
begin
if aFormReport.DrawOnPageFooter then exit;
liGrid := THackDBGrid(aControl);
if (liGrid.Datasource = nil) or (liGrid.Datasource.Dataset = nil) then Exit;
if not liGrid.Datasource.Dataset.Active then Exit;
FDBGrid := liGrid;
FList.Clear;
liNeedBeforePrint := False;
if (rmgoSelectedRecordsOnly in aFormReport.ReportOptions) and
(liGrid.SelectedRows.Count > 0) then
begin
// AutoFree := False;
// aFormReport.Report.OnBeforePrintBand := OnBeforePrintBandEvent;
end;
aFormReport.DrawOnPageFooter := TRUE;
aFormReport.GridTop := THackFormReport(aFormReport).OffsY + aControl.Top;
aFormReport.GridHeight := aControl.Height;
liGridTitleHeight := 0;
NextTop := aControl.Top + THackFormReport(aFormReport).OffsY;
aFormReport.MainDataSet := THackFormReport(aFormReport).AddRMDataSet(THackDBGrid(FDBGrid).DataSource.DataSet);
DSet := liGrid.Datasource.Dataset;
tmpx := 0;
for i := 1 to liGrid.Cols do
begin
liCol := liGrid.Col[i];
if liCol.Visible then
tmpx := tmpx + liCol.Width + 1;
end;
if liGrid.HeadingOn and (rmgoGridNumber in aFormReport.ReportOptions) then
tmpx := tmpx + RMCanvasHeight('a', liGrid.Font) * aFormReport.GridNumOptions.Number;
if (aFormReport.PrintControl = aControl) or (tmpx > StrToInt(THackFormReport(aFormReport).FormWidth[0])) then
THackFormReport(aFormReport).FormWidth[0] := IntToStr(tmpx + (THackFormReport(aFormReport).OffsX + aControl.Left) * 2);
if liGrid.HeadingOn then //表头
begin
liFlagFirstColumn := True;
liGridTitleHeight := liGrid.RowHeights[0] + 4;
tmpx := aControl.Left + THackFormReport(aFormReport).OffsX;
if rmgoGridNumber in aFormReport.ReportOptions then
begin
liView := RMCreateObject(gtMemo, '');
liView.ParentPage := aPage;
liView.spLeft := tmpx;
liView.spTop := NextTop;
liView.spWidth := RMCanvasHeight('a', liGrid.Font) * aFormReport.GridNumOptions.Number;
liView.spHeight := liGridTitleHeight;
liView.Memo.Add(aFormReport.GridNumOptions.Text);
TRMMemoView(liView).VAlign := rmvCenter;
TRMMemoView(liView).HAlign := rmhCenter;
if rmgoGridLines in aFormReport.ReportOptions then
begin
liView.LeftFrame.Visible := True;
liView.TopFrame.Visible := True;
liView.RightFrame.Visible := True;
liView.BottomFrame.Visible := True;
end
else
begin
liView.LeftFrame.Visible := False;
liView.TopFrame.Visible := False;
liView.RightFrame.Visible := False;
liView.BottomFrame.Visible := False;
end;
aFormReport.ColumnHeaderViews.Add(liView);
tmpx := tmpx + liView.spWidth;
if rmgoDoubleFrame in aFormReport.ReportOptions then
begin
if liFlagFirstColumn then
liView.LeftFrame.spWidth := 2;
liView.TopFrame.spWidth := 2;
end;
liFlagFirstColumn := False;
end;
liPage := aPage; liNum := 0;
tmpx0 := tmpx;
for i := 1 to liGrid.Cols do
begin
liCol := liGrid.Col[i];
if not liCol.Visible then Continue;
if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
begin
if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(tmpx + (liCol.Width + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
begin
liNum := 0;
liFlagFirstColumn := True;
if rmgoDoubleFrame in aFormReport.ReportOptions then
liView.RightFrame.spWidth := 2;
THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(tmpx);
THackFormReport(aFormReport).AddPage;
THackFormReport(aFormReport).FormWidth.Add('0');
liPage := TRMReportPage(aFormReport.Report.Pages[aFormReport.Report.Pages.Count - 1]);
tmpx := tmpx0;
liFlagFirstColumn := True;
DrawFixedColHeader;
end;
end;
MakeOneHeader(i);
Inc(liNum);
end;
liFlagFirstColumn := True;
if rmgoDoubleFrame in aFormReport.ReportOptions then
liView.RightFrame.spWidth := 2;
end;
if aFormReport.Report.Pages.Count > 1 then
THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(tmpx);
liPage := aPage; //表体
tmpx := aControl.Left + THackFormReport(aFormReport).OffsX;
liFlagFirstColumn := True;
if rmgoGridNumber in aFormReport.ReportOptions then
begin
liView := RMCreateObject(gtMemo, '');
liView.ParentPage := aPage;
liView.spLeft := tmpx;
liView.spTop := 0;
liView.spWidth := RMCanvasHeight('a', liGrid.Font) * aFormReport.GridNumOptions.Number;
liView.spHeight := liGrid.DefaultRowHeight + 4;
liView.Memo.Add('[Line#]');
TRMMemoView(liView).VAlign := rmvCenter;
TRMMemoView(liView).HAlign := rmhCenter;
if (rmgoGridLines in aFormReport.ReportOptions) then
begin
liView.LeftFrame.Visible := True;
liView.TopFrame.Visible := True;
liView.RightFrame.Visible := True;
liView.BottomFrame.Visible := True;
end
else
begin
liView.LeftFrame.Visible := False;
liView.TopFrame.Visible := False;
liView.RightFrame.Visible := False;
liView.BottomFrame.Visible := False;
end;
aFormReport.PageDetailViews.Add(liView);
tmpx := tmpx + liView.spWidth;
if rmgoDoubleFrame in aFormReport.ReportOptions then
begin
if liFlagFirstColumn then
liView.LeftFrame.spWidth := 2;
end;
DrawDoubleFrameBottom(liView, aFormReport.ColumnFooterViews);
liFlagFirstColumn := False;
end;
tmpx0 := tmpx;
liNum := 0; liPageNo := 0;
for i := 1 to liGrid.Cols do
begin
liCol := liGrid.Col[i];
if not liCol.Visible then Continue;
if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
begin
if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(tmpx + (liCol.Width + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
begin
liNum := 0;
liFlagFirstColumn := True;
if rmgoDoubleFrame in aFormReport.ReportOptions then
liView.RightFrame.spWidth := 2;
liFlagFirstColumn := True;
THackFormReport(aFormReport).FormWidth[liPageNo] := IntToStr(tmpx);
Inc(liPageNo);
if liPageNo >= aFormReport.Report.Pages.Count then
begin
THackFormReport(aFormReport).AddPage;
THackFormReport(aFormReport).FormWidth.Add('0');
end;
liPage := TRMReportPage(aFormReport.Report.Pages[liPageNo]);
tmpx := tmpx0;
liFlagFirstColumn := True;
DrawFixedColDetail;
end;
end;
MakeOneDetail(i);
Inc(liNum);
end;
if liNum > 0 then
begin
liFlagFirstColumn := True;
if rmgoDoubleFrame in aFormReport.ReportOptions then
liView.RightFrame.spWidth := 2;
end;
if aFormReport.Report.Pages.Count > 1 then
THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(tmpx);
if liNeedBeforePrint then
begin
AutoFree := False;
aFormReport.Report.OnBeforePrint := _OnBeforePrint;
end;
end;
initialization
RMRegisterFormReportControl(TtsCustomDBGrid, TRMPrintTopDBGrid);
RMRegisterFormReportControl(TtsCustomGrid, TRMPrintTopGrid);
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?