Changeset 9 for trunk/Forms/UMainForm.pas
- Timestamp:
- Dec 26, 2010, 8:12:59 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 2 2 Config.xml 3 3 chronis 4 heaptrclog.trc
-
- Property svn:ignore
-
trunk/Forms/UMainForm.pas
r8 r9 6 6 7 7 uses 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,8 Registry, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 9 StdCtrls, ActnList, Menus, ExtCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, 10 UPersistentForm, UTreeState, SpecializedList ;10 UPersistentForm, UTreeState, SpecializedList, URegistry, USystem; 11 11 12 12 const … … 14 14 15 15 type 16 TDbValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, vtBoolean,17 vtIPv4, vtMAC, vtIPv6, vtFile, vtGPS, vtEnumeration, vtHyperlink, vtPassword,18 vtReference, vtDate, vtTime, vtColor);19 20 { TReportLine }21 22 TReportLine = class23 Id: Integer;24 Items: TListString;25 constructor Create;26 destructor Destroy; override;27 end;28 29 16 { TMainForm } 30 17 … … 96 83 OriginalWindowState: TWindowState; 97 84 ScreenBounds: TRect; 85 RegistryKey: string; 86 RegistryRootKey: HKEY; 98 87 procedure LoadConfiguration; 88 procedure LoadFromRegistry; 89 procedure SaveToRegistry; 99 90 public 100 SelectedObject: Integer; 91 SelectedObjectId: Integer; 92 SelectedObject: TChronisObject; 101 93 SelectedItem: Integer; 102 94 PersistentForm: TPersistentForm; 103 Database: TSQLDatabase;104 95 TreeState: TTreeState; 105 Report: TListObject; 96 System: TChronisBase; 97 Report: TReport; 106 98 procedure LoadTree; 107 99 procedure LoadItemList; … … 121 113 uses 122 114 UItemView, UItemEdit, UItemAdd; 123 124 { TReportLine }125 126 constructor TReportLine.Create;127 begin128 Items := TListString.Create;129 end;130 131 destructor TReportLine.Destroy;132 begin133 Items.Free;134 inherited Destroy;135 end;136 115 137 116 {$R *.lfm} … … 157 136 with ChildNodes[I3] do begin 158 137 if NodeName = 'hostname' then 159 Database.HostName := TextContent;138 System.Database.HostName := TextContent; 160 139 if NodeName = 'schema' then 161 Database.Database := TextContent;140 System.Database.Database := TextContent; 162 141 if NodeName = 'username' then 163 Database.UserName := TextContent;142 System.Database.UserName := TextContent; 164 143 if NodeName = 'password' then 165 Database.Password := TextContent;144 System.Database.Password := TextContent; 166 145 end; 167 146 end; … … 172 151 end; 173 152 153 procedure TMainForm.LoadFromRegistry; 154 begin 155 with TRegistryEx.Create do 156 try 157 RootKey := RegistryRootKey; 158 OpenKey(RegistryKey, True); 159 Panel1.Width := ReadIntegerWithDefault('GroupTreeWidth', 200); 160 finally 161 Free; 162 end; 163 end; 164 165 procedure TMainForm.SaveToRegistry; 166 begin 167 with TRegistryEx.Create do 168 try 169 RootKey := RegistryRootKey; 170 OpenKey(RegistryKey, True); 171 WriteInteger('GroupTreeWidth', Panel1.Width); 172 finally 173 Free; 174 end; 175 end; 176 174 177 procedure TMainForm.FormCreate(Sender: TObject); 175 178 begin 176 Database := TSqlDatabase.Create; 179 System := TChronisBase.Create; 180 System.Database := TSqlDatabase.Create; 177 181 LoadConfiguration; 178 Database.Connect;182 System.Database.Connect; 179 183 TreeState := TTreeState.Create; 184 Report := TReport.Create; 185 Report.Base := System; 186 SelectedObject := TChronisObject.Create; 187 SelectedObject.Base := System; 188 RegistryRootKey := HKEY_CURRENT_USER; 189 RegistryKey := '\Software\Chronosoft\Chronis'; 180 190 PersistentForm := TPersistentForm.Create; 181 Report := TListObject.Create;191 PersistentForm.RegistryKey := RegistryKey; 182 192 end; 183 193 … … 186 196 Report.Free; 187 197 TreeState.Free; 188 Database.Free;189 198 PersistentForm.Free; 199 System.Free; 190 200 end; 191 201 … … 193 203 begin 194 204 PersistentForm.Save(Self); 205 SaveToRegistry; 195 206 end; 196 207 … … 208 219 begin 209 220 if Assigned(TreeView1.Selected) then begin 210 SelectedObject := 9;221 SelectedObjectId := 9; 211 222 SelectedItem := Integer(TreeView1.Selected.Data); 212 223 ItemEditForm.Show; … … 222 233 begin 223 234 if Assigned(TreeView1.Selected) then begin 224 SelectedObject := 8;235 SelectedObjectId := 8; 225 236 SelectedItem := Integer(TreeView1.Selected.Data); 226 237 ItemEditForm.Show; … … 274 285 PersistentForm.Load(Self); 275 286 LoadTree; 287 LoadFromRegistry; 276 288 end; 277 289 … … 351 363 try 352 364 DbRows := TDbRows.Create; 353 Database.Query(DbRows, 'SELECT * FROM `ObjectGroup`');365 System.Database.Query(DbRows, 'SELECT * FROM `ObjectGroup`'); 354 366 for I := 0 to DbRows.Count - 1 do begin 355 367 NewNode := AddChild(TopItem, DbRows[I].Values['Name']); … … 359 371 try 360 372 ObjectDbRows := TDbRows.Create; 361 Database.Query(ObjectDbRows, 'SELECT * FROM `Object` WHERE `Group`=' + DbRows[I].Values['Id']);373 System.Database.Query(ObjectDbRows, 'SELECT * FROM `Object` WHERE `Group`=' + DbRows[I].Values['Id']); 362 374 for O := 0 to ObjectDbRows.Count - 1 do begin 363 375 NewObjectNode := AddChild(NewNode, ObjectDbRows[O].Values['Name']); … … 380 392 procedure TMainForm.LoadItemList; 381 393 var 382 DbRows: TDbRows; 383 Properties: TDbRows; 384 Values: TDbRows; 394 NewColumn: TListColumn; 385 395 I: Integer; 386 C: Integer; 387 NewItem: TReportLine; 388 NewColumn: TListColumn; 389 begin 390 SelectedObject := 0; 396 begin 397 SelectedObjectId := 0; 391 398 if Assigned(TreeView1.Selected) then 392 399 with ListView1 do begin 393 400 Visible := True; 394 Report.Clear; 395 try 396 DbRows := TDbRows.Create; 397 Database.Query(DbRows, 'SELECT * FROM `Object` WHERE `Id`=' + IntToStr(Integer(TreeView1.Selected.Data))); 398 if DbRows.Count = 1 then begin 399 SelectedObject := StrToInt(DbRows[0].Values['Id']); 400 401 // Load column names 402 try 403 Properties := TDbRows.Create; 404 Database.Query(Properties, 'SELECT * FROM `Property` WHERE `Object`=' + 405 DbRows[0].Values['Id']); 406 Columns.Clear; 407 NewColumn := Columns.Add; 408 NewColumn.Caption := 'Id'; 409 for I := 0 to Properties.Count - 1 do begin 410 NewColumn := Columns.Add; 411 NewColumn.Caption := Properties[I].Values['Name']; 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; 431 finally 432 Properties.Free; 433 Values.Free; 434 end; 401 SelectedObject.Load(Integer(TreeView1.Selected.Data)); 402 Report.Load(SelectedObject); 403 404 Columns.Clear; 405 for I := 0 to Report.Columns.Count - 1 do begin 406 NewColumn := Columns.Add; 407 NewColumn.Caption := TReportColumn(Report.Columns[I]).Caption; 435 408 end; 436 finally437 DbRows.Free;438 439 end;409 Items.Count := Report.Count; 410 Refresh; 411 end; 412 ListView1Resize(Self); 440 413 end; 441 414
Note:
See TracChangeset
for help on using the changeset viewer.