Changeset 8 for trunk/Forms/UMainForm.pas
- Timestamp:
- Dec 25, 2010, 10:28:06 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UMainForm.pas
r7 r8 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 9 StdCtrls, ActnList, Menus, ExtCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, 10 UPersistentForm, UTreeState ;10 UPersistentForm, UTreeState, SpecializedList; 11 11 12 12 const … … 14 14 15 15 type 16 T ValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, vtBoolean,16 TDbValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, vtBoolean, 17 17 vtIPv4, vtMAC, vtIPv6, vtFile, vtGPS, vtEnumeration, vtHyperlink, vtPassword, 18 18 vtReference, vtDate, vtTime, vtColor); 19 20 { TReportLine } 21 22 TReportLine = class 23 Id: Integer; 24 Items: TListString; 25 constructor Create; 26 destructor Destroy; override; 27 end; 19 28 20 29 { TMainForm } … … 76 85 procedure FormDestroy(Sender: TObject); 77 86 procedure FormShow(Sender: TObject); 87 procedure ListView1Data(Sender: TObject; Item: TListItem); 78 88 procedure ListView1DblClick(Sender: TObject); 79 89 procedure ListView1KeyPress(Sender: TObject; var Key: char); … … 93 103 Database: TSQLDatabase; 94 104 TreeState: TTreeState; 105 Report: TListObject; 95 106 procedure LoadTree; 96 107 procedure LoadItemList; … … 103 114 SItemNotFound = 'Item not found'; 104 115 SObjectNotFound = 'Object not found'; 116 SGroup = 'Groups'; 105 117 106 118 … … 109 121 uses 110 122 UItemView, UItemEdit, UItemAdd; 123 124 { TReportLine } 125 126 constructor TReportLine.Create; 127 begin 128 Items := TListString.Create; 129 end; 130 131 destructor TReportLine.Destroy; 132 begin 133 Items.Free; 134 inherited Destroy; 135 end; 111 136 112 137 {$R *.lfm} … … 154 179 TreeState := TTreeState.Create; 155 180 PersistentForm := TPersistentForm.Create; 181 Report := TListObject.Create; 156 182 end; 157 183 158 184 procedure TMainForm.FormDestroy(Sender: TObject); 159 185 begin 186 Report.Free; 160 187 TreeState.Free; 161 188 Database.Free; … … 249 276 end; 250 277 278 procedure TMainForm.ListView1Data(Sender: TObject; Item: TListItem); 279 var 280 I: Integer; 281 begin 282 if Item.Index < Report.Count then 283 with TReportLine(Report[Item.Index]) do begin 284 Item.Caption := Items[0]; 285 for I := 1 to Items.Count - 1 do 286 Item.SubItems.Add(Items[I]); 287 end; 288 end; 289 251 290 procedure TMainForm.ListView1DblClick(Sender: TObject); 252 291 begin … … 271 310 begin 272 311 if Assigned(ListView1.Selected) then 273 SelectedItem := Integer(ListView1.Selected.Data)312 SelectedItem := TReportLine(Report[ListView1.Selected.Index]).Id 274 313 else SelectedItem := 0; 275 314 … … 307 346 TreeState.SaveTree(TreeView1); 308 347 Clear; 309 AddChild(nil, 'Skupiny');348 AddChild(nil, SGroup); 310 349 TopItem.ImageIndex := 0; 311 350 TopItem.SelectedIndex := 0; … … 346 385 I: Integer; 347 386 C: Integer; 348 NewItem: T ListItem;387 NewItem: TReportLine; 349 388 NewColumn: TListColumn; 350 389 begin 351 390 SelectedObject := 0; 352 if Assigned(TreeView1.Selected) then353 with ListView1 , Itemsdo begin391 if Assigned(TreeView1.Selected) then 392 with ListView1 do begin 354 393 Visible := True; 355 Clear;394 Report.Clear; 356 395 try 357 396 DbRows := TDbRows.Create; … … 372 411 NewColumn.Caption := Properties[I].Values['Name']; 373 412 end; 413 414 ListView1Resize(Self); 415 416 // Load items 417 Values := TDbRows.Create; 418 Database.Query(Values, 'SELECT * FROM `' + DbRows[0].Values['Schema'] + '`.`' + 419 DbRows[0].Values['Table'] + '`'); 420 for I := 0 to Values.Count - 1 do begin 421 NewItem := TReportLine.Create; 422 NewItem.Items.Add(Values[I].Values[DbRows[0].Values['PrimaryKey']]); 423 NewItem.Id := StrToInt(Values[I].Values[DbRows[0].Values['PrimaryKey']]); 424 for C := 0 to Properties.Count - 1 do begin 425 NewItem.Items.Add(Values[I].Values[Properties[C].Values['ColumnName']]); 426 end; 427 Report.Add(NewItem); 428 end; 429 Items.Count := Values.Count; 430 Refresh; 374 431 finally 375 432 Properties.Free; 376 end;377 378 ListView1Resize(Self);379 380 // Load items381 try382 Values := TDbRows.Create;383 Database.Query(Values, 'SELECT * FROM `' + DbRows[0].Values['Schema'] + '`.`' +384 DbRows[0].Values['Table'] + '`');385 for I := 0 to Values.Count - 1 do begin386 NewItem := Items.Add;387 NewItem.Caption := Values[I].Values[DbRows[0].Values['PrimaryKey']];388 NewItem.Data := Pointer(StrToInt(Values[I].Values[DbRows[0].Values['PrimaryKey']]));389 for C := 0 to Properties.Count - 1 do begin390 NewItem.SubItems.Add(Values[I].Values[Properties[C].Values['ColumnName']]);391 end;392 end;393 finally394 433 Values.Free; 395 434 end;
Note:
See TracChangeset
for help on using the changeset viewer.