📄 rm_pwwgrid.pas
字号:
{*****************************************}
{ }
{ Report Machine v2.0 }
{ wwdbgrid report }
{ }
{*****************************************}
unit RM_PwwGrid;
interface
{$I RM.inc}
{$IFDEF InfoPower}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Stdctrls,
Printers, DB, Wwdbigrd, Wwdbgrid, wwDataInspector, RM_Class, RM_dbset, RM_View,
RM_Pars, RM_wwrtf, RM_FormReport;
type
TRMwwGridReport = class(TComponent) // fake component
end;
{ TRMPrintwwSpinEdit }
TRMPrintwwSpinEdit = class(TRMPrintEdit)
public
procedure OnGenerate_Object(aFormReport: TRMFormReport; Page: TRMPage;
Control: TControl; var t: TRMView); override;
end;
{ TRMPrintwwDBCheckBox }
TRMPrintwwDBCheckBox = class(TRMPrintCheckBox)
public
procedure OnGenerate_Object(aFormReport: TRMFormReport; Page: TRMPage;
Control: TControl; var t: TRMView); override;
end;
{ TRMPrintwwRichEdit }
TRMPrintwwRichEdit = class(TRMFormReportObject)
public
procedure OnGenerate_Object(aFormReport: TRMFormReport; Page: TRMPage;
Control: TControl; var t: TRMView); override;
end;
{ TRMPrintwwDBGrid }
TRMPrintwwDBGrid = class(TRMFormReportObject)
private
FDBGrid: TwwCustomDBGrid;
procedure OnBeforePrintBandEvent(Band: TRMBand; var PrintBand: Boolean);
public
procedure OnGenerate_Object(aFormReport: TRMFormReport; Page: TRMPage;
Control: TControl; var t: TRMView); override;
end;
{$ENDIF}
implementation
{$IFDEF InfoPower}
uses Wwcommon, wwriched, wwdbedit, wwdblook, wwcheckbox, wwdbdatetimepicker,
RM_Utils;
type
THackwwDBGrid = class(TwwDBGrid)
end;
THackFormReport = class(TRMFormReport)
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMPrintwwSpinEdit}
procedure TRMPrintwwSpinEdit.OnGenerate_Object(aFormReport: TRMFormReport; Page: TRMPage;
Control: TControl; var t: TRMView);
var
ds: TDataSource;
dataset: TDataSet;
begin
inherited;
if Control is TwwDBCustomEdit then
begin
try
ds := TwwDBCustomEdit(Control).DataSource;
t.Memo.Text := Format('[%s.%s."%s"]', [ds.DataSet.Owner.Name, ds.DataSet.Name, TwwDBCustomEdit(Control).DataField]);
except
end;
end
else if Control is TwwDBCustomLookupCombo then
begin
try
ds := TwwDBCustomLookupCombo(Control).DataSource;
if ds <> nil then
t.Memo.Text := Format('[%s.%s."%s"]', [ds.DataSet.Owner.Name, ds.DataSet.Name, TwwDBCustomLookupCombo(Control).DataField])
else
begin
dataset := TwwDBCustomLookupCombo(Control).LookupTable;
t.Memo.Text := Format('[%s.%s."%s"]', [dataset.Owner.Name, dataset.Name,
RMGetOneField(TwwDBCustomLookupCombo(Control).LookupField)]);
end;
except
end;
end
else if Control is TwwDBCustomDateTimePicker then
begin
try
ds := TwwDBCustomDateTimePicker(Control).DataSource;
t.Memo.Text := Format('[%s.%s."%s"]', [ds.DataSet.Owner.Name, ds.DataSet.Name,
TwwDBCustomDateTimePicker(Control).DataField]);
except
end;
end;
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
procedure TRMPrintwwDBCheckBox.OnGenerate_Object(aFormReport: TRMFormReport; Page: TRMPage;
Control: TControl; var t: TRMView);
var
ds: TDataSource;
begin
inherited;
try
ds := TwwDBCustomCheckBox(Control).DataSource;
t.Memo.Text := Format('[%s.%s."%s"]', [ds.DataSet.Owner.Name, ds.DataSet.Name, TwwDBCustomCheckBox(Control).DataField]);
except
end;
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMPrintwwRichEdit}
procedure TRMPrintwwRichEdit.OnGenerate_Object(aFormReport: TRMFormReport; Page: TRMPage;
Control: TControl; var t: TRMView);
var
ds: TDataSource;
begin
t := RMCreateObject(gtAddin, 'TRMwwRichView');
t.CreateUniqueName;
t.x := Control.Left + THackFormReport(aFormReport).OffsX;
t.y := Control.Top + THackFormReport(aFormReport).OffsY;
t.dx := Control.Width + 2;
t.dy := Control.Height + 2;
if (Control is TwwDBRichEdit) and (TwwDBRichEdit(Control).DataSource <> nil) and
(TwwDBRichEdit(Control).DataField <> '') then
begin
try
ds := TwwDBRichEdit(Control).DataSource;
t.Memo.Text := Format('[%s.%s."%s"]', [ds.DataSet.Owner.Name, ds.DataSet.Name, TwwDBRichEdit(Control).DataField]);
except
end;
end
else
TRMwwRichView(t).RichEdit.Lines.Assign(TwwCustomRichEdit(Control).Lines);
if rmgoDrawBorder in aFormReport.ReportOptions then
t.Prop['FrameTyp'] := $F
else
t.Prop['FrameTyp'] := 0;
Page.Objects.Add(t);
if aFormReport.DrawOnPageFooter then
aFormReport.ColumnFooterViews.Add(t)
else
aFormReport.PageHeaderViews.Add(t);
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMPrintwwDBGrid}
procedure TRMPrintwwDBGrid.OnBeforePrintBandEvent(Band: TRMBand; var PrintBand: Boolean);
var
Bookmark: TBookmark;
i: integer;
begin
PrintBand := False;
Bookmark := THackwwDBGrid(FDBGrid).DataSource.DataSet.GetBookmark;
try
for i := 1 to THackwwDBGrid(FDBGrid).SelectedList.Count do
begin
PrintBand := THackwwDBGrid(FDBGrid).DataSource.DataSet.CompareBookmarks(TBookmark(THackwwDBGrid(FDBGrid).SelectedList[I - 1]), Bookmark) = 0;
if PrintBand then
Break;
end;
finally
THackwwDBGrid(FDBGrid).DataSource.DataSet.FreeBookmark(Bookmark);
end;
end;
procedure TRMPrintwwDBGrid.OnGenerate_Object(aFormReport: TRMFormReport; Page: TRMPage;
Control: TControl; var t: TRMView);
var
liView: TRMView;
i, tmpx, tmpx0, NextTop: Integer;
liDBGrid: THackwwDBGrid;
DSet: TDataSet;
str: string;
liPage: TRMPage;
liPageNo, liNum, liGridTitleHeight: Integer;
liFlagFirstColumn: Boolean;
liLastGroupName: string;
function _GetColumnWidth(aColumn: TwwColumn): Integer;
begin
if liDBGrid.UseTFields and (DSet.FindField(aColumn.FieldName) <> nil) then
Result := DSet.FindField(aColumn.FieldName).DisplayWidth * liDBGrid.Canvas.TextWidth('0') + 4
else
Result := aColumn.DisplayWidth * liDBGrid.Canvas.TextWidth('0') + 4;
end;
function _GetCustomEditControl(aParamters: string): TComponent;
begin
Result := nil;
if Pos(';', aParamters) > 0 then
begin
aParamters := Copy(aParamters, 1, Pos(';', aParamters) - 1);
Result := liDBGrid.Parent.FindComponent(aParamters);
end;
end;
procedure _MakeDataInspectorObject(liDataInspector: TwwDataInspector; aWidth: Integer);
var
i: Integer;
liDSet: TDataSet;
liView, liView1: TRMView;
liDefaultRowHeight: Integer;
begin
if liDataInspector.DefaultRowHeight <= 0 then
liDefaultRowHeight := liDataInspector.Canvas.TextHeight('0') + 4
else
liDefaultRowHeight := liDataInspector.DefaultRowHeight + 1;
for i := 0 to liDataInspector.Items.Count - 1 do
begin
// Caption
liView := TRMMemoView(RMCreateObject(gtMemo, ''));
liView.Memo.Text := liDataInspector.Items[i].Caption;
TRMMemoView(liView).PAlignment := rmtaCenterJustify;
TRMMemoView(liView).PLayout := rmtlCenter;
aFormReport.AssignFont(TRMMemoView(liView), liDataInspector.CaptionFont);
if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
liView.Prop['FrameTyp'] := $F
else
liView.Prop['FrameTyp'] := 0;
liView.CreateUniqueName;
liView.x := tmpx;
liView.y := liDefaultRowHeight * i;
liView.dx := liDataInspector.CaptionIndent + liDataInspector.CaptionWidth + 1;
liView.dy := liDefaultRowHeight;
if rmgoUseColor in aFormReport.ReportOptions then
liView.FillColor := liDataInspector.CaptionColor;
liPage.Objects.Add(liView);
aFormReport.PageDetailViews.Add(liView);
// DataField
liDSet := liDataInspector.Items[i].DataSource.DataSet;
liView1 := TRMMemoView(RMCreateObject(gtMemo, ''));
liView1.Memo.Text := Format('[%s.%s."%s"]', [liDSet.Owner.Name, liDSet.Name, liDataInspector.Items[i].DataField]);
case liDataInspector.Items[i].Alignment of
taLeftJustify: TRMMemoView(liView1).PAlignment := rmtaLeftJustify;
taRightJustify: TRMMemoView(liView1).PAlignment := rmtaRightJustify;
taCenter: TRMMemoView(liView1).PAlignment := rmtaCenterJustify;
end;
TRMMemoView(liView1).PLayout := rmtlCenter;
aFormReport.AssignFont(TRMMemoView(liView1), liDataInspector.Font);
if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
liView1.Prop['FrameTyp'] := $F
else
liView1.Prop['FrameTyp'] := 0;
liView1.CreateUniqueName;
liView1.x := tmpx + liView.dx;
liView1.y := liView.y;
liView1.dx := liDataInspector.Width - liView.dx + 1;
liView1.dy := liView.dy;
if rmgoUseColor in aFormReport.ReportOptions then
liView1.FillColor := liDataInspector.Color;
liPage.Objects.Add(liView1);
aFormReport.PageDetailViews.Add(liView1);
end;
tmpx := tmpx + aWidth;
liFlagFirstColumn := False;
end;
procedure DrawDoubleFrameBottom(aView: TRMView; aList: TList);
var
t: TRMMemoView;
begin
if rmgoDoubleFrame in aFormReport.ReportOptions then
begin
t := TRMMemoView(RMCreateObject(gtMemo, ''));
t.CreateUniqueName;
t.LeftFrame.Visible := False;
t.TopFrame.Visible := True;
t.RightFrame.Visible := False;
t.BottomFrame.Visible := False;
t.TopFrame.Width := 2;
t.Gapx := 0; t.GapY := 0;
t.SetBounds(aView.x, aFormReport.GridTop + aFormReport.GridHeight, aView.dx, 2);
t.PStretched := rmgoStretch in aFormReport.ReportOptions;
liPage.Objects.Add(t);
aList.Add(t);
end;
end;
procedure MakeOneHeader(aIndex: Integer);
var
liColumn, liColumn1: TwwColumn;
i: Integer;
begin
liColumn := liDBGrid.Columns[aIndex];
if (liColumn.GroupName <> '') and (liLastGroupName <> liColumn.GroupName) then
begin
liView := TRMMemoView(RMCreateObject(gtMemo, ''));
liView.CreateUniqueName;
str := liColumn.GroupName;
while Pos('~', str) <> 0 do
str[Pos('~', str)] := #13;
liView.Memo.Text := str;
liView.x := tmpx;
liView.y := NextTop;
liView.dx := 0;
for i := aIndex to liDBGrid.Selected.Count - 1 do
begin
liColumn1 := liDBGrid.Columns[i];
if liColumn1.GroupName <> liColumn.GroupName then
Break;
if THackFormReport(aFormReport).CalcWidth(liView.x + liView.dx + _GetColumnWidth(liColumn1) + 1) > THackFormReport(aFormReport).PageWidth then // 超宽
Break;
liView.dx := liView.dx + _GetColumnWidth(liColumn1) + 1;
end;
liView.dy := liGridTitleHeight div 2;
if rmgoUseColor in aFormReport.ReportOptions then
liView.FillColor := liDBGrid.TitleColor;
if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
liView.Prop['FrameTyp'] := $F
else
liView.Prop['FrameTyp'] := 0;
TRMMemoView(liView).PAlignment := rmtaCenterJustify;
TRMMemoView(liView).PLayout := rmtlCenter;
liPage.Objects.Add(liView);
aFormReport.PageHeaderViews.Add(liView);
end;
liView := TRMMemoView(RMCreateObject(gtMemo, ''));
liView.CreateUniqueName;
str := liColumn.DisplayLabel;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -