home *** CD-ROM | disk | FTP | other *** search
- unit MastApp;
-
- interface
- uses
- SysUtils,
- Mapping,
- DataMod,
- DB,
- DBTables;
-
- type
- TCustomerOrders = class;
-
- TCustomer = class(TORObject)
- protected
- FCustNo :Longint;
- FCompany :string;
- FAddr1 :string;
- FAddr2 :string;
- FCity :string;
- FState :string;
- FZip :string;
- FCountry :string;
- FFAX :string;
- FContact :string;
- FTaxRate :Double;
- FLastInvoiceDate :TDateTime;
-
- FOrders :TCustomerOrders;
-
- class function KeyName :string; override;
- function GetKey :Variant; override;
- procedure SetKey (Value :Variant); override;
-
- public { don't publish our key field }
- destructor Destroy; override;
-
- function GetOrders :TCustomerOrders;
-
- property CustNo :Longint read FCustNo;
- property Orders :TCustomerOrders read GetOrders;
- published
- property Company :string read FCompany write FCompany;
- property Addr1 :string read FAddr1 write FAddr1;
- property Addr2 :string read FAddr2 write FAddr2;
- property City :string read FCity write FCity;
- property State :string read FState write FState;
- property Zip :string read FZip write FZip;
- property Country :string read FCountry write FCountry;
- property FAX :string read FFAX write FFAX;
- property Contact :string read FContact write FContact;
- property TaxRate :Double read FTaxRate write FTaxRate;
- property LastInvoiceDate :TDateTime
- read FLastInvoiceDate write FLastInvoiceDate;
- end;
-
- TCustomerFile = class(TORFile)
- protected
- function GetCustomer(i :Integer) :TCustomer;
- public
- property Objects[i:Integer]:TCustomer read GetCustomer; default;
- end;
-
- TOrder = class(TORObject)
- private
- FOrderNo :Longint;
- FCustomer :TCustomer;
- FSaleDate :TDateTime;
- FShipDate :TDateTime;
- FEmpNo :Longint;
- FShipToContact :string;
- FShipToAddr1 :string;
- FShipToAddr2 :string;
- FShipToCity :string;
- FShipToState :string;
- FShipToZip :string;
- FShipToCountry :string;
- FShipToPhone :string;
- FShipVIA :string;
- FPO :string;
- FTerms :string;
- FPaymentMethod :string;
- FItemsTotal :Double;
- FTaxRate :Double;
- FFreight :Double;
- FAmountPaid :Double;
-
- protected
- class function KeyName :string; override;
- function GetKey :Variant; override;
- procedure SetKey (Value :Variant); override;
-
- public
- property OrderNo :Longint read FOrderNo;
- property Customer :TCustomer read FCustomer write FCustomer;
- published
- property CustNo :TCustomer read FCustomer write FCustomer;
- property SaleDate :TDateTime read FSaleDate write FSaleDate;
- property ShipDate :TDateTime read FShipDate write FShipDate;
- property EmpNo :Longint read FEmpNo write FEmpNo;
- property ShipToContact :string read FShipToContact write FShipToContact;
- property ShipToAddr1 :string read FShipToAddr1 write FShipToAddr1;
- property ShipToAddr2 :string read FShipToAddr2 write FShipToAddr2;
- property ShipToCity :string read FShipToCity write FShipToCity;
- property ShipToState :string read FShipToState write FShipToState;
- property ShipToZip :string read FShipToZip write FShipToZip;
- property ShipToCountry :string read FShipToCountry write FShipToCountry;
- property ShipToPhone :string read FShipToPhone write FShipToPhone;
- property ShipVIA :string read FShipVIA write FShipVIA;
- property PO :string read FPO write FPO;
- property Terms :string read FTerms write FTerms;
- property PaymentMethod :string read FPaymentMethod write FPaymentMethod;
- property ItemsTotal :Double read FItemsTotal write FItemsTotal;
- property TaxRate :Double read FTaxRate write FTaxRate;
- property Freight :Double read FFreight write FFreight;
- property AmountPaid :Double read FAmountPaid write FAmountPaid;
- end;
-
- TOrderFile = class(TORFile)
- protected
- function GetOrder(i :Integer) :TOrder;
- public
- property Objects[i:Integer]:TOrder read GetOrder; default;
- end;
-
-
- TMastMapping = class(TORMapping)
- private
- FCustomers :TCustomerFile;
- FOrders :TOrderFile;
- public
- constructor Create;
-
- property Customers :TCustomerFile read FCustomers;
- property Orders :TOrderFile read FOrders;
- end;
-
- TCustomerOrders = class(TORCachedQuery)
- protected
- FFilter :TQuery;
- constructor Create(Map :TMastMapping; Customer :TCustomer);
- destructor Destroy; override;
-
- function GetOrder(i :Integer) :TOrder;
- public
- property Objects[i:Integer]:TOrder read GetOrder; default;
- end;
-
-
- var
- MastMap :TMastMapping;
-
- implementation
-
- { TCustomer }
-
- class function TCustomer.KeyName :string;
- begin
- Result := 'CustNo'
- end;
-
- function TCustomer.GetKey :Variant;
- begin
- Result := CustNo
- end;
-
- procedure TCustomer.Setkey(Value :Variant);
- begin
- FCustNo := Value
- end;
-
- destructor TCustomer.Destroy;
- begin
- FOrders.Free;
- inherited Destroy;
- end;
-
- function TCustomer.GetOrders :TCustomerOrders;
- begin
- if (FOrders = nil) and (ORFile <> nil) then
- FOrders := TCustomerOrders.Create(ORFile.Mapping as TMastMapping, Self);
- Result := FOrders
- end;
-
-
- { TCustomerFile }
-
- function TCustomerFile.GetCustomer(i :Integer) :TCustomer;
- begin
- Result := GetObject(i) as TCustomer
- end;
-
- { TOrder }
-
- class function TOrder.KeyName :string;
- begin
- Result := 'OrderNo'
- end;
-
- function TOrder.GetKey :Variant;
- begin
- Result := OrderNo
- end;
-
- procedure TOrder.Setkey(Value :Variant);
- begin
- FOrderNo := Value
- end;
-
-
- { TOrderFile }
-
- function TOrderFile.GetOrder(i :Integer) :TOrder;
- begin
- Result := GetObject(i) as TOrder
- end;
-
- { TCustomerOrders }
-
- constructor TCustomerOrders.Create(Map :TMastMapping; Customer :TCustomer);
- begin
- FFilter := TQuery.Create(nil);
- with FFilter do begin
- Databasename := MastData.Database.DatabaseName;
- SQL.Clear;
- SQL.Add( 'SELECT * FROM '+ MastData.Orders.TableName
- + ' WHERE CustNo = ' + IntToStr(Customer.CustNo)
- );
- end;
- inherited Create(Map, TOrder, FFilter, Map.Orders);
- end;
-
- destructor TCustomerOrders.Destroy;
- begin
- FFilter.Free;
- inherited Destroy;
- end;
-
- function TCustomerOrders.GetOrder(i :Integer) :TOrder;
- begin
- Result := GetObject(i) as TOrder
- end;
-
- { TMastMapping }
-
- constructor TMastMapping.Create;
- begin
- inherited Create(MastData.Database);
- FCustomers := TCustomerFile.Create(Self, TCustomer, MastData.Cust);
- FOrders := TOrderFile.Create(Self, TOrder, MastData.Orders);
- end;
-
- procedure StartUp;
- begin
- MastData := TMastData.Create(nil);
- MastMap := TMastMapping.Create;
- end;
-
- procedure ShutDown;
- begin
- try
- MastMap.Free
- finally
- MastData.Free
- end
- end;
-
- initialization
- StartUp
- finalization
- ShutDown
- end.
-