📄 datagrp.pas
字号:
unit Datagrp;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Buttons, SctBtn, SctCtrl, SctVar, SctRep, DB,
DBTables, ExtCtrls, Grids, DBGrids;
type
TFormSubDataGroups = class(TForm)
SctReport1: TSctReport;
ReportPage: TSctGrouppage;
ReportHeaderBand: TSctBand;
ReportHeaderBandlevel: TSctLevel;
PageHeaderBand: TSctBand;
PageHeaderBandlevel: TSctLevel;
DetailBand: TSctBand;
DetailBandlevel: TSctLevel;
PageFooterBand: TSctBand;
PageFooterBandlevel: TSctLevel;
ReportFooterBand: TSctBand;
ReportFooterBandlevel: TSctLevel;
CustomerTable: TTable;
CustomerSource: TDataSource;
svarDateTime: TSctDateTimeVar;
svarPage: TSctPageVar;
DataSourceGuide: TSctDataSourceGuide;
customertableCustNo: TSctDBVar;
customertableCompany: TSctDBVar;
customertableAddr1: TSctDBVar;
customertableAddr2: TSctDBVar;
customertableCity: TSctDBVar;
customertableState: TSctDBVar;
customertableZip: TSctDBVar;
customertableCountry: TSctDBVar;
customertablePhone: TSctDBVar;
customertableFAX: TSctDBVar;
customertableTaxRate: TSctDBVar;
customertableContact: TSctDBVar;
customertableLastInvoiceDate: TSctDBVar;
varlabel: TSctvarlabel;
TextLabel: TSctTextLabel;
varlabel1: TSctvarlabel;
TextLabel1: TSctTextLabel;
SctReportButton1: TSctReportButton;
OrdersPaySource: TDataSource;
DataSourceGuide1: TSctDataSourceGuide;
orderstableOrderNo: TSctDBVar;
orderstableCustNo: TSctDBVar;
orderstableSaleDate: TSctDBVar;
orderstableShipDate: TSctDBVar;
orderstableEmpNo: TSctDBVar;
orderstableShipToContact: TSctDBVar;
orderstableShipToAddr1: TSctDBVar;
orderstableShipToAddr2: TSctDBVar;
orderstableShipToCity: TSctDBVar;
orderstableShipToState: TSctDBVar;
orderstableShipToZip: TSctDBVar;
orderstableShipToCountry: TSctDBVar;
orderstableShipToPhone: TSctDBVar;
orderstableShipVIA: TSctDBVar;
orderstablePO: TSctDBVar;
orderstableTerms: TSctDBVar;
orderstablePaymentMethod: TSctDBVar;
orderstableItemsTotal: TSctDBVar;
orderstableTaxRate: TSctDBVar;
orderstableFreight: TSctDBVar;
orderstableAmountPaid: TSctDBVar;
OrdersStart: TSctSubDataBand;
OrdersStartlevel: TSctLevel;
OrdersGroup: TSctSubDataBand;
OrdersGrouplevel: TSctLevel;
OrdersGroupHead: TSctDataHeadBand;
OrdersGroupHeadlevel: TSctLevel;
OrdersGroupFoot: TSctDataFootBand;
OrdersGroupFootlevel: TSctLevel;
varlabel2: TSctvarlabel;
TextLabel2: TSctTextLabel;
varlabel3: TSctvarlabel;
TextLabel3: TSctTextLabel;
varlabel4: TSctvarlabel;
TextLabel4: TSctTextLabel;
SctLine1: TSctLine;
TotalOfAmountPaid: TSctTotalvar;
TotalvarLabel: TSctTotalvarLabel;
TextLabel5: TSctTextLabel;
SctShape1: TSctShape;
OrdersByPayQuery: TQuery;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
SctReportButton2: TSctReportButton;
OrdersByShipVia: TQuery;
OrdersViaSource: TDataSource;
DBGrid3: TDBGrid;
DataSourceGuide2: TSctDataSourceGuide;
ordersbyshipviaOrderNo: TSctDBVar;
ordersbyshipviaCustNo: TSctDBVar;
ordersbyshipviaSaleDate: TSctDBVar;
ordersbyshipviaShipDate: TSctDBVar;
ordersbyshipviaEmpNo: TSctDBVar;
ordersbyshipviaShipToContact: TSctDBVar;
ordersbyshipviaShipToAddr1: TSctDBVar;
ordersbyshipviaShipToAddr2: TSctDBVar;
ordersbyshipviaShipToCity: TSctDBVar;
ordersbyshipviaShipToState: TSctDBVar;
ordersbyshipviaShipToZip: TSctDBVar;
ordersbyshipviaShipToCountry: TSctDBVar;
ordersbyshipviaShipToPhone: TSctDBVar;
ordersbyshipviaShipVIA: TSctDBVar;
ordersbyshipviaPO: TSctDBVar;
ordersbyshipviaTerms: TSctDBVar;
ordersbyshipviaPaymentMethod: TSctDBVar;
ordersbyshipviaItemsTotal: TSctDBVar;
ordersbyshipviaTaxRate: TSctDBVar;
ordersbyshipviaFreight: TSctDBVar;
ordersbyshipviaAmountPaid: TSctDBVar;
OrdersViaStart: TSctSubDataBand;
OrdersViaStartlevel: TSctLevel;
OrdersVia: TSctSubDataBand;
OrdersVialevel: TSctLevel;
OrdersViaHead: TSctDataHeadBand;
OrdersViaHeadlevel: TSctLevel;
OrdersViaFoot: TSctDataFootBand;
OrdersViaFootlevel: TSctLevel;
TotalOfAmountPaidByVia: TSctTotalvar;
SctLine2: TSctLine;
SctTextLabel1: TSctTextLabel;
SctTextLabel2: TSctTextLabel;
SctTextLabel3: TSctTextLabel;
Sctvarlabel1: TSctvarlabel;
Sctvarlabel2: TSctvarlabel;
Sctvarlabel3: TSctvarlabel;
SctShape2: TSctShape;
SctTotalvarLabel1: TSctTotalvarLabel;
SctTextLabel4: TSctTextLabel;
OrdersStartHead: TSctDataHeadBand;
OrdersStartHeadlevel: TSctLevel;
OrdersViaStartHead: TSctDataHeadBand;
OrdersViaStartHeadlevel: TSctLevel;
SctTextLabel6: TSctTextLabel;
SctTextLabel5: TSctTextLabel;
procedure OrdersStartDataStart(Sender: TObject);
procedure OrdersStartDataSkip(Sender: TObject);
procedure OrdersGroupDataStart(Sender: TObject);
procedure OrdersGroupDataSkip(Sender: TObject);
private
{ Private declarations }
{ Saves the last field value of each record that groups need to break on }
GroupValue: String;
public
{ Public declarations }
end;
const
{ Array of fields that need to break on }
FieldBreak: array[0..1] of String[20] = ('PaymentMethod', 'ShipVia');
var
FormSubDataGroups: TFormSubDataGroups;
implementation
{$R *.DFM}
{
This report shows an example of grouping on a subdataband.
To simulate this first set up your table, queries, datasource and set
the proper relations. Then when you have done that place grids on your
form that point to your datasources and run the form. Check to make sure
all of your relations are working proeperly. Now drop a report on your
form and set it up with your master table and make sure that is working
propertly.
Now create a subdataband and set its datasource property to the datasource
you are grouping on. Then create a second subdataband to the first
subdataband. Set the datasource property to the same as the first
datasource. Then go into the DataControl center and set the updatelevel
of the DataSourceGuide of the datasource to the second subdataband.
Repeat above steps for each subdata grouping that you need to create.
Now you need to override the ondataskip and ondatastart events for all
subdatabands. Place the code below in those events. Create a private
variable (GroupValue as above) to hold the last value of the field you
will need to group on. Then modify the constant array above which
holds the field that you need to break on. Then you need to go to each
subdataband and set the tag propery so the event knows which array value
to access.
The first subdataband that you create is not used so set the visible
property of that band to false. That band is only used to get to the
first record in the table and to print all of the groups.
}
procedure TFormSubDataGroups.OrdersStartDataStart(Sender: TObject);
begin
{ This is referencing the properties of the SubDataBand so the they
can be used generically for multiple subdata bands.
This will just set the datasource to the first record and tell ace
that there are no records if the datasource is at eof.
}
with Sender as TSctSubDataBand do
begin
DataSource.DataSet.First;
DataIsFinished := DataSource.DataSet.Eof;
end;
end;
procedure TFormSubDataGroups.OrdersStartDataSkip(Sender: TObject);
begin
{ This is referencing the properties of the SubDataBand so the they
can be used generically for multiple subdata bands.
Must tell Ace the this section is finsished if the Datasource is
at eof.
}
with Sender as TSctSubDataBand do
begin
if DataSource.DataSet.Eof then DataIsFinished := True;
end;
end;
procedure TFormSubDataGroups.OrdersGroupDataStart(Sender: TObject);
begin
{ this will grab the first value for this group so that I can see
if the group breaks when I go to the next record
The Datasource should never be at eof because the section above
gets called just before this and this part would never get called
if the Datasource was at eof.
}
with Sender as TSctSubDataBand do
begin
{ The tab property is set on the subdataband so this event knows
which array value to reference }
GroupValue := DataSource.DataSet.FieldByName(FieldBreak[Tag]).AsString;
DataIsFinished := False;
end;
end;
procedure TFormSubDataGroups.OrdersGroupDataSkip(Sender: TObject);
var
NextValue: String;
begin
{ This method skips to the next record in the table and checks to
see if the group is broken or not. If it is then Ace is told that.
}
with Sender as TSctSubDataBand do
begin
DataSource.DataSet.Next;
if DataSource.DataSet.Eof then DataIsFinished := True
else
begin
{ The tab property is set on the subdataband so this event knows
which array value to reference }
NextValue := DataSource.DataSet.FieldByName(FieldBreak[Tag]).AsString;
if GroupValue <> NextValue then DataIsFinished := True;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -