Changeset 3 for trunk/UMainForm.pas
- Timestamp:
- Jun 3, 2010, 3:16:40 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UMainForm.pas
r2 r3 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 StdCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, UPersistentForm ;9 StdCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, UPersistentForm, UItemView; 10 10 11 11 const … … 24 24 procedure FormCreate(Sender: TObject); 25 25 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); 26 31 procedure TreeView1Change(Sender: TObject; Node: TTreeNode); 27 32 private 28 33 procedure LoadConfiguration; 29 34 public 35 SelectedObject: Integer; 36 SelectedItem: Integer; 30 37 PersistentForm: TPersistentForm; 31 38 Database: TSQLDatabase; 32 39 procedure LoadTree; 40 procedure LoadItemList; 33 41 end; 34 42 … … 93 101 end; 94 102 103 procedure TMainForm.ListView1DblClick(Sender: TObject); 104 begin 105 ItemViewForm.Show; 106 end; 107 108 procedure TMainForm.ListView1KeyPress(Sender: TObject; var Key: char); 109 begin 110 if Key = #13 then ListView1DblClick(Sender); 111 end; 112 113 procedure TMainForm.ListView1Resize(Sender: TObject); 114 var 115 I: Integer; 116 begin 117 for I := 0 to ListView1.Columns.Count - 1 do 118 ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count; 119 end; 120 121 procedure TMainForm.ListView1SelectItem(Sender: TObject; Item: TListItem; 122 Selected: Boolean); 123 begin 124 if Assigned(ListView1.Selected) then 125 SelectedItem := Integer(ListView1.Selected.Data) 126 else SelectedItem := 0; 127 end; 128 95 129 procedure 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; 130 begin 131 LoadItemList; 136 132 end; 137 133 … … 163 159 end; 164 160 161 procedure TMainForm.LoadItemList; 162 var 163 DbRows: TDbRows; 164 Properties: TDbRows; 165 Values: TDbRows; 166 I: Integer; 167 C: Integer; 168 NewItem: TListItem; 169 NewColumn: TListColumn; 170 begin 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; 208 end; 209 165 210 end. 166 211
Note:
See TracChangeset
for help on using the changeset viewer.