home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / WIN / Programa / OORDB.ZIP / OORDB.EXE / MASTAPP.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-12  |  7.2 KB  |  273 lines

  1. unit MastApp;
  2.  
  3. interface
  4. uses
  5.   SysUtils,
  6.   Mapping,
  7.   DataMod,
  8.   DB,
  9.   DBTables;
  10.  
  11. type
  12.   TCustomerOrders = class;
  13.  
  14.   TCustomer = class(TORObject)
  15.   protected
  16.     FCustNo  :Longint;
  17.     FCompany :string;
  18.     FAddr1   :string;
  19.     FAddr2   :string;
  20.     FCity    :string;
  21.     FState   :string;
  22.     FZip     :string;
  23.     FCountry :string;
  24.     FFAX     :string;
  25.     FContact :string;
  26.     FTaxRate :Double;
  27.     FLastInvoiceDate :TDateTime;
  28.  
  29.     FOrders  :TCustomerOrders;
  30.  
  31.     class function KeyName   :string;   override;
  32.     function  GetKey :Variant;          override;
  33.     procedure SetKey (Value :Variant);  override;
  34.  
  35.   public { don't publish our key field }
  36.     destructor  Destroy;                 override;
  37.  
  38.     function GetOrders :TCustomerOrders;
  39.  
  40.     property CustNo   :Longint read FCustNo;
  41.     property Orders   :TCustomerOrders read GetOrders;
  42.   published
  43.     property Company  :string read FCompany write FCompany;
  44.     property Addr1    :string read FAddr1   write FAddr1;
  45.     property Addr2    :string read FAddr2   write FAddr2;
  46.     property City     :string read FCity    write FCity;
  47.     property State    :string read FState   write FState;
  48.     property Zip      :string read FZip     write FZip;
  49.     property Country  :string read FCountry write FCountry;
  50.     property FAX      :string read FFAX     write FFAX;
  51.     property Contact  :string read FContact write FContact;
  52.     property TaxRate  :Double read FTaxRate write FTaxRate;
  53.     property LastInvoiceDate :TDateTime
  54.       read FLastInvoiceDate write FLastInvoiceDate;
  55.   end;
  56.  
  57.   TCustomerFile = class(TORFile)
  58.   protected
  59.     function GetCustomer(i :Integer) :TCustomer;
  60.   public
  61.     property Objects[i:Integer]:TCustomer read GetCustomer; default;
  62.   end;
  63.  
  64.   TOrder = class(TORObject)
  65.   private
  66.     FOrderNo        :Longint;
  67.     FCustomer       :TCustomer;
  68.     FSaleDate       :TDateTime;
  69.     FShipDate       :TDateTime;
  70.     FEmpNo          :Longint;
  71.     FShipToContact  :string;
  72.     FShipToAddr1    :string;
  73.     FShipToAddr2    :string;
  74.     FShipToCity     :string;
  75.     FShipToState    :string;
  76.     FShipToZip      :string;
  77.     FShipToCountry  :string;
  78.     FShipToPhone    :string;
  79.     FShipVIA        :string;
  80.     FPO             :string;
  81.     FTerms          :string;
  82.     FPaymentMethod  :string;
  83.     FItemsTotal     :Double;
  84.     FTaxRate        :Double;
  85.     FFreight        :Double;
  86.     FAmountPaid     :Double;
  87.  
  88.  protected
  89.     class function KeyName   :string;   override;
  90.     function  GetKey :Variant;          override;
  91.     procedure SetKey (Value :Variant);  override;
  92.  
  93.   public
  94.     property OrderNo        :Longint   read FOrderNo;
  95.     property Customer       :TCustomer read FCustomer      write FCustomer;
  96.   published
  97.     property CustNo         :TCustomer read FCustomer      write FCustomer;
  98.     property SaleDate       :TDateTime read FSaleDate      write FSaleDate;
  99.     property ShipDate       :TDateTime read FShipDate      write FShipDate;
  100.     property EmpNo          :Longint   read FEmpNo         write FEmpNo;
  101.     property ShipToContact  :string    read FShipToContact write FShipToContact;
  102.     property ShipToAddr1    :string    read FShipToAddr1   write FShipToAddr1;
  103.     property ShipToAddr2    :string    read FShipToAddr2   write FShipToAddr2;
  104.     property ShipToCity     :string    read FShipToCity    write FShipToCity;
  105.     property ShipToState    :string    read FShipToState   write FShipToState;
  106.     property ShipToZip      :string    read FShipToZip     write FShipToZip;
  107.     property ShipToCountry  :string    read FShipToCountry write FShipToCountry;
  108.     property ShipToPhone    :string    read FShipToPhone   write FShipToPhone;
  109.     property ShipVIA        :string    read FShipVIA       write FShipVIA;
  110.     property PO             :string    read FPO            write FPO;
  111.     property Terms          :string    read FTerms         write FTerms;
  112.     property PaymentMethod  :string    read FPaymentMethod write FPaymentMethod;
  113.     property ItemsTotal     :Double    read FItemsTotal    write FItemsTotal;
  114.     property TaxRate        :Double    read FTaxRate       write FTaxRate;
  115.     property Freight        :Double    read FFreight       write FFreight;
  116.     property AmountPaid     :Double    read FAmountPaid    write FAmountPaid;
  117.   end;
  118.  
  119.   TOrderFile = class(TORFile)
  120.   protected
  121.     function GetOrder(i :Integer) :TOrder;
  122.   public
  123.     property Objects[i:Integer]:TOrder read GetOrder; default;
  124.   end;
  125.  
  126.  
  127.   TMastMapping = class(TORMapping)
  128.   private
  129.      FCustomers :TCustomerFile;
  130.      FOrders    :TOrderFile;
  131.   public
  132.      constructor Create;
  133.  
  134.      property Customers :TCustomerFile read FCustomers;
  135.      property Orders    :TOrderFile    read FOrders;
  136.   end;
  137.  
  138.   TCustomerOrders = class(TORCachedQuery)
  139.   protected
  140.     FFilter :TQuery;
  141.     constructor Create(Map :TMastMapping; Customer :TCustomer);
  142.     destructor  Destroy; override;
  143.  
  144.     function  GetOrder(i :Integer) :TOrder;
  145.   public
  146.     property Objects[i:Integer]:TOrder read GetOrder; default;
  147.   end;
  148.  
  149.  
  150. var
  151.   MastMap    :TMastMapping;
  152.  
  153. implementation
  154.  
  155. { TCustomer }
  156.  
  157. class function TCustomer.KeyName   :string;
  158. begin
  159.   Result := 'CustNo'
  160. end;
  161.  
  162. function TCustomer.GetKey :Variant;
  163. begin
  164.   Result := CustNo
  165. end;
  166.  
  167. procedure TCustomer.Setkey(Value :Variant);
  168. begin
  169.   FCustNo := Value
  170. end;
  171.  
  172. destructor TCustomer.Destroy;
  173. begin
  174.   FOrders.Free;
  175.   inherited Destroy;
  176. end;
  177.  
  178. function TCustomer.GetOrders :TCustomerOrders;
  179. begin
  180.   if (FOrders = nil) and (ORFile <> nil) then
  181.     FOrders := TCustomerOrders.Create(ORFile.Mapping as TMastMapping, Self);
  182.   Result := FOrders
  183. end;
  184.  
  185.  
  186. { TCustomerFile }
  187.  
  188. function TCustomerFile.GetCustomer(i :Integer) :TCustomer;
  189. begin
  190.   Result := GetObject(i) as TCustomer
  191. end;
  192.  
  193. { TOrder }
  194.  
  195. class function TOrder.KeyName   :string;
  196. begin
  197.   Result := 'OrderNo'
  198. end;
  199.  
  200. function TOrder.GetKey :Variant;
  201. begin
  202.   Result := OrderNo
  203. end;
  204.  
  205. procedure TOrder.Setkey(Value :Variant);
  206. begin
  207.   FOrderNo := Value
  208. end;
  209.  
  210.  
  211. { TOrderFile }
  212.  
  213. function TOrderFile.GetOrder(i :Integer) :TOrder;
  214. begin
  215.   Result := GetObject(i) as TOrder
  216. end;
  217.  
  218. { TCustomerOrders }
  219.  
  220. constructor TCustomerOrders.Create(Map :TMastMapping; Customer :TCustomer);
  221. begin
  222.    FFilter := TQuery.Create(nil);
  223.    with FFilter do begin
  224.      Databasename  := MastData.Database.DatabaseName;
  225.      SQL.Clear;
  226.      SQL.Add( 'SELECT * FROM '+ MastData.Orders.TableName
  227.                     + ' WHERE CustNo = ' + IntToStr(Customer.CustNo)
  228.              );
  229.    end;
  230.    inherited Create(Map, TOrder, FFilter, Map.Orders);
  231. end;
  232.  
  233. destructor  TCustomerOrders.Destroy;
  234. begin
  235.   FFilter.Free;
  236.   inherited Destroy;
  237. end;
  238.  
  239. function TCustomerOrders.GetOrder(i :Integer) :TOrder;
  240. begin
  241.   Result := GetObject(i) as TOrder
  242. end;
  243.  
  244. { TMastMapping }
  245.  
  246. constructor TMastMapping.Create;
  247. begin
  248.   inherited Create(MastData.Database);
  249.   FCustomers := TCustomerFile.Create(Self, TCustomer, MastData.Cust);
  250.   FOrders    := TOrderFile.Create(Self, TOrder, MastData.Orders);
  251. end;
  252.  
  253. procedure StartUp;
  254. begin
  255.     MastData  := TMastData.Create(nil);
  256.     MastMap   := TMastMapping.Create;
  257. end;
  258.  
  259. procedure ShutDown;
  260. begin
  261.   try
  262.      MastMap.Free
  263.   finally
  264.      MastData.Free
  265.   end
  266. end;
  267.  
  268. initialization
  269.   StartUp
  270. finalization
  271.   ShutDown
  272. end.
  273.