Changeset 3 for trunk/UMainForm.pas


Ignore:
Timestamp:
Jun 3, 2010, 3:16:40 PM (14 years ago)
Author:
george
Message:
  • Přidáno: Formulář pro zobrazení a editaci položky.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UMainForm.pas

    r2 r3  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    9   StdCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, UPersistentForm;
     9  StdCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, UPersistentForm, UItemView;
    1010
    1111const
     
    2424    procedure FormCreate(Sender: TObject);
    2525    procedure FormShow(Sender: TObject);
     26    procedure ListView1DblClick(Sender: TObject);
     27    procedure ListView1KeyPress(Sender: TObject; var Key: char);
     28    procedure ListView1Resize(Sender: TObject);
     29    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
     30      Selected: Boolean);
    2631    procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
    2732  private
    2833    procedure LoadConfiguration;
    2934  public
     35    SelectedObject: Integer;
     36    SelectedItem: Integer;
    3037    PersistentForm: TPersistentForm;
    3138    Database: TSQLDatabase;
    3239    procedure LoadTree;
     40    procedure LoadItemList;
    3341  end;
    3442
     
    93101end;
    94102
     103procedure TMainForm.ListView1DblClick(Sender: TObject);
     104begin
     105  ItemViewForm.Show;
     106end;
     107
     108procedure TMainForm.ListView1KeyPress(Sender: TObject; var Key: char);
     109begin
     110  if Key = #13 then ListView1DblClick(Sender);
     111end;
     112
     113procedure TMainForm.ListView1Resize(Sender: TObject);
     114var
     115  I: Integer;
     116begin
     117  for I := 0 to ListView1.Columns.Count - 1 do
     118    ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count;
     119end;
     120
     121procedure TMainForm.ListView1SelectItem(Sender: TObject; Item: TListItem;
     122  Selected: Boolean);
     123begin
     124  if Assigned(ListView1.Selected) then
     125    SelectedItem := Integer(ListView1.Selected.Data)
     126    else SelectedItem := 0;
     127end;
     128
    95129procedure TMainForm.TreeView1Change(Sender: TObject; Node: TTreeNode);
    96 var
    97   DbRows: TDbRows;
    98   Properties: TDbRows;
    99   Values: TDbRows;
    100   I: Integer;
    101   C: Integer;
    102   NewItem: TListItem;
    103   NewColumn: TListColumn;
    104 begin
    105   if Assigned(TreeView1.Selected) then
    106   with ListView1, Items do begin
    107     Clear;
    108     DbRows := Database.Query('SELECT * FROM `Object` WHERE `Id`=' + IntToStr(TreeView1.Selected.ImageIndex));
    109     if DbRows.Count = 1 then begin
    110       // Load column names
    111       Properties := Database.Query('SELECT * FROM `Property` WHERE `Object`=' +
    112         DbRows[0].Values['Id']);
    113       Columns.Clear;
    114       NewColumn := Columns.Add;
    115       NewColumn.Caption := 'Id';
    116       for I := 0 to Properties.Count - 1 do begin
    117         NewColumn := Columns.Add;
    118         NewColumn.Caption := DbRows[I].Values['Name'];
    119       end;
    120 
    121       // Load items
    122       Values := Database.Query('SELECT * FROM `' + DbRows[0].Values['Schema'] + '`.`' +
    123         DbRows[0].Values['Table'] + '`');
    124       for I := 0 to Values.Count - 1 do begin
    125         NewItem := Items.Add;
    126         NewItem.Caption := Values[I].Values['Id'];
    127         for C := 0 to Properties.Count - 1 do begin
    128           NewItem.SubItems.Add(Values[I].Values[Properties[C].Values['ColumnName']]);
    129         end;
    130       end;
    131       Values.Destroy;
    132       Properties.Destroy;
    133     end;
    134     DbRows.Destroy;
    135   end;
     130begin
     131  LoadItemList;
    136132end;
    137133
     
    163159end;
    164160
     161procedure TMainForm.LoadItemList;
     162var
     163  DbRows: TDbRows;
     164  Properties: TDbRows;
     165  Values: TDbRows;
     166  I: Integer;
     167  C: Integer;
     168  NewItem: TListItem;
     169  NewColumn: TListColumn;
     170begin
     171  SelectedObject := 0;
     172  if Assigned(TreeView1.Selected) then
     173  with ListView1, Items do begin
     174    Clear;
     175    DbRows := Database.Query('SELECT * FROM `Object` WHERE `Id`=' + IntToStr(TreeView1.Selected.ImageIndex));
     176    if DbRows.Count = 1 then begin
     177      SelectedObject := StrToInt(DbRows[0].Values['Id']);
     178
     179      // Load column names
     180      Properties := Database.Query('SELECT * FROM `Property` WHERE `Object`=' +
     181        DbRows[0].Values['Id']);
     182      Columns.Clear;
     183      NewColumn := Columns.Add;
     184      NewColumn.Caption := 'Id';
     185      for I := 0 to Properties.Count - 1 do begin
     186        NewColumn := Columns.Add;
     187        NewColumn.Caption := Properties[I].Values['Name'];
     188      end;
     189
     190      ListView1Resize(Self);
     191
     192      // Load items
     193      Values := Database.Query('SELECT * FROM `' + DbRows[0].Values['Schema'] + '`.`' +
     194        DbRows[0].Values['Table'] + '`');
     195      for I := 0 to Values.Count - 1 do begin
     196        NewItem := Items.Add;
     197        NewItem.Caption := Values[I].Values[DbRows[0].Values['PrimaryKey']];
     198        NewItem.Data := Pointer(StrToInt(Values[I].Values[DbRows[0].Values['PrimaryKey']]));
     199        for C := 0 to Properties.Count - 1 do begin
     200          NewItem.SubItems.Add(Values[I].Values[Properties[C].Values['ColumnName']]);
     201        end;
     202      end;
     203      Values.Destroy;
     204      Properties.Destroy;
     205    end;
     206    DbRows.Destroy;
     207  end;
     208end;
     209
    165210end.
    166211
Note: See TracChangeset for help on using the changeset viewer.