Ignore:
Timestamp:
Jan 22, 2009, 9:20:15 AM (16 years ago)
Author:
george
Message:
  • Přidáno: Jednotka pro správu finančních dokladů.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/web/UDatabase.pas

    r139 r142  
    99
    1010type
     11  TDatabase = class;
    1112
    1213  { TDbObject }
     
    1415  TDbObject = class
    1516    Id: Integer;
     17    Loaded: Boolean;
     18    Database: TDatabase;
    1619    procedure Store; virtual;
     20    procedure Load; virtual;
    1721    procedure Delete;
     22    constructor Create;
     23    destructor Destroy; override;
    1824  end;
     25
     26  TDbObjectClass = class of TDbObject;
    1927
    2028  { TDbList }
    2129
    2230  TDbList = class
     31    Id: Integer;
     32    Database: TDatabase;
     33    ItemClassType: TDbObjectClass;
    2334    Items: TList;
    2435    constructor Create;
    2536    destructor Destroy; override;
     37    function Add: TDbObject;
     38    procedure Store;
     39    procedure Load;
    2640  end;
    2741
     
    3549  { TDatabase }
    3650
    37   TDatabase = class
    38     SqlDatabase: TSqlDatabase;
    39     procedure Open;
    40     procedure Close;
     51  TDatabase = class(TSqlDatabase)
     52    BaseObject: TDbObject;
     53    constructor Create;
     54    destructor Destroy; override;
     55    procedure Init;
    4156  end;
    4257
     
    4863end;
    4964
     65procedure TDbObject.Load;
     66begin
     67
     68end;
     69
    5070procedure TDbObject.Delete;
    5171begin
    5272
     73end;
     74
     75constructor TDbObject.Create;
     76begin
     77end;
     78
     79destructor TDbObject.Destroy;
     80begin
     81  inherited Destroy;
    5382end;
    5483
     
    7099end;
    71100
     101function TDbList.Add: TDbObject;
     102var
     103  Data: TAssocArray;
     104begin
     105  Result := ItemClassType.Create;
     106  Data := TAssocArray.Create;
     107  Data.AddKeyValue('id', '');
     108  Database.Insert(ClassName, Data);
     109  Result.Id := Database.LastInsertId;;
     110  Items.Add(Result);
     111end;
     112
     113procedure TDbList.Store;
     114var
     115  I: Integer;
     116  Data: TAssocArray;
     117begin
     118  Data := TAssocArray.Create;
     119  Database.Insert(ClassName, Data);
     120  for I := 0 to Items.Count - 1 do begin
     121    Database.Insert(ClassName, Data);
     122  end;
     123end;
     124
     125procedure TDbList.Load;
     126begin
     127
     128end;
     129
    72130{ TDbResultSet }
    73131
     
    83141{ TDatabase }
    84142
    85 procedure TDatabase.Open;
     143constructor TDatabase.Create;
    86144begin
    87 
     145  BaseObject := TDbObject.Create;;
    88146end;
    89147
    90 procedure TDatabase.Close;
     148destructor TDatabase.Destroy;
    91149begin
     150  BaseObject.Free;
     151end;
    92152
     153procedure TDatabase.Init;
     154begin
     155  BaseObject.Id := 1;
     156  BaseObject.Database := Self;
     157  BaseObject.Load;
    93158end;
    94159
Note: See TracChangeset for help on using the changeset viewer.