home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / Runimage / Delphi50 / Demos / Midas / Aggregate / aggform.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1999-08-11  |  3.6 KB  |  108 lines

  1. unit aggform;
  2. {
  3.   This project demonstrates the use of maintained aggregates on clientdatasets.
  4.   The Customer and Orders tables from DBDEMOS are used to create a master-detail
  5.   relationanship. The data is transfered through the provider. On the "client"
  6.   side, two aggregate fields are set up on the orders clientdataset. 
  7.   One is a "global" aggregate ( the grouping level of the
  8.   aggregate field is zero ). The other is a grouped aggregate defined on an
  9.   an index that is created on the 'ShipVIA' field. When the datasets are first
  10.   opened, only the global aggregate is displayed.  As you navigate through the
  11.   customer dataset, the new value for that customer is displayed. If you
  12.   add, delete or modify any records in the detail set the new value for the
  13.   aggregate is automatically updated. If you press the 'GroupByShipVIA' button
  14.   the 'ShipVIA' index is activated on the details. This also activates any
  15.   non-global aggregates ( Agg.GroupingLeve > 0 ) that use this index, and 
  16.   now the sub-total for each shipping method is displayed. As you navigate 
  17.   among the detail set, if you move to a different shipping method, the 
  18.   aggregate value will change. Any updates to the detail dataset will 
  19.   force updates to the aggregate values.
  20. }
  21.  
  22. interface
  23.  
  24. uses
  25.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  26.   StdCtrls, Mask, DBCtrls, Grids, DBGrids, DBClient, Provider, Db,
  27.   DBTables, ExtCtrls;
  28.  
  29. type
  30.   TForm1 = class(TForm)
  31.     CustDataSource: TDataSource;
  32.     CustQuery: TQuery;
  33.     OrderQuery: TQuery;
  34.     Provider1: TDataSetProvider;
  35.     CustOrders: TClientDataSet;
  36.     DBGrid1: TDBGrid;
  37.     DBEdit1: TDBEdit;
  38.     CustOrdersDataSource: TDataSource;
  39.     DBNavigator1: TDBNavigator;
  40.     CustOrdersCustNo: TFloatField;
  41.     CustOrdersCompany: TStringField;
  42.     CustOrdersAddr1: TStringField;
  43.     CustOrdersAddr2: TStringField;
  44.     CustOrdersCity: TStringField;
  45.     CustOrdersState: TStringField;
  46.     CustOrdersZip: TStringField;
  47.     CustOrdersCountry: TStringField;
  48.     CustOrdersPhone: TStringField;
  49.     CustOrdersFAX: TStringField;
  50.     CustOrdersTaxRate: TFloatField;
  51.     CustOrdersContact: TStringField;
  52.     CustOrdersLastInvoiceDate: TDateTimeField;
  53.     CustOrdersOrderQuery: TDataSetField;
  54.     OrderDSDataSource: TDataSource;
  55.     OrderDS: TClientDataSet;
  56.     OrderDSTotalPerCustomer: TAggregateField;
  57.     Button1: TButton;
  58.     CustQueryCustNo: TFloatField;
  59.     CustQueryCompany: TStringField;
  60.     CustQueryAddr1: TStringField;
  61.     CustQueryAddr2: TStringField;
  62.     CustQueryCity: TStringField;
  63.     CustQueryState: TStringField;
  64.     CustQueryZip: TStringField;
  65.     CustQueryCountry: TStringField;
  66.     CustQueryPhone: TStringField;
  67.     CustQueryFAX: TStringField;
  68.     CustQueryTaxRate: TFloatField;
  69.     CustQueryContact: TStringField;
  70.     CustQueryLastInvoiceDate: TDateTimeField;
  71.     DBEdit2: TDBEdit;
  72.     Label1: TLabel;
  73.     DBNavigator2: TDBNavigator;
  74.     OrderDSOrderTotalPerShipMethod: TAggregateField;
  75.     DBEdit3: TDBEdit;
  76.     Button2: TButton;
  77.     DBTextShipMethod: TDBEdit;
  78.     Label2: TLabel;
  79.     procedure Button1Click(Sender: TObject);
  80.     procedure Button2Click(Sender: TObject);
  81.   private
  82.     { Private declarations }
  83.   public
  84.     { Public declarations }
  85.   end;
  86.  
  87. var
  88.   Form1: TForm1;
  89.  
  90. implementation
  91.  
  92. {$R *.DFM}
  93.  
  94. procedure TForm1.Button1Click(Sender: TObject);
  95. begin
  96.    CustOrders.Active := True;
  97.    OrderDS.Active := True;
  98. end;
  99.  
  100. procedure TForm1.Button2Click(Sender: TObject);
  101. begin
  102.    OrderDS.IndexName := 'ShipVIA';
  103.    DBTextShipMethod.DataField := 'ShipVIA';
  104.    CustOrders.First;
  105. end;
  106.  
  107. end.
  108.