Changeset 2 for trunk/UMainForm.pas
- Timestamp:
- May 30, 2010, 6:09:55 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 1 1 lib 2 Config.xml 3 chronis
-
- Property svn:ignore
-
trunk/UMainForm.pas
r1 r2 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 StdCtrls, USqlDatabase; 9 StdCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, UPersistentForm; 10 11 const 12 ConfigFileName = 'Config.xml'; 10 13 11 14 type … … 18 21 ListView1: TListView; 19 22 TreeView1: TTreeView; 23 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 20 24 procedure FormCreate(Sender: TObject); 25 procedure FormShow(Sender: TObject); 26 procedure TreeView1Change(Sender: TObject; Node: TTreeNode); 21 27 private 22 { private declarations }28 procedure LoadConfiguration; 23 29 public 30 PersistentForm: TPersistentForm; 24 31 Database: TSQLDatabase; 25 32 procedure LoadTree; … … 35 42 { TMainForm } 36 43 44 procedure TMainForm.LoadConfiguration; 45 var 46 Config: TXMLDocument; 47 I1: Integer; 48 I2: Integer; 49 I3: Integer; 50 begin 51 if FileExists(ConfigFileName) then begin 52 ReadXMLFile(Config, ConfigFileName); 53 for I1 := 0 to Config.ChildNodes.Count - 1 do 54 with Config.ChildNodes[I1] do begin 55 if NodeName = 'configuration' then 56 for I2 := 0 to ChildNodes.Count - 1 do 57 with ChildNodes[I2] do begin 58 if NodeName = 'database' then 59 for I3 := 0 to ChildNodes.Count - 1 do 60 with ChildNodes[I3] do begin 61 if NodeName = 'hostname' then 62 Database.HostName := TextContent; 63 if NodeName = 'schema' then 64 Database.Schema := TextContent; 65 if NodeName = 'username' then 66 Database.UserName := TextContent; 67 if NodeName = 'password' then 68 Database.Password := TextContent; 69 end; 70 end; 71 end; 72 Config.Destroy; 73 end; 74 end; 75 37 76 procedure TMainForm.FormCreate(Sender: TObject); 38 77 begin 39 78 Database := TSqlDatabase.Create; 40 with Database do begin41 Hostname := 'localhost';42 Schema := 'chronis_system';43 UserName := 'root';79 LoadConfiguration; 80 Database.Connect; 81 PersistentForm := TPersistentForm.Create; 82 end; 44 83 84 procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction); 85 begin 86 PersistentForm.Save(Self); 87 end; 88 89 procedure TMainForm.FormShow(Sender: TObject); 90 begin 91 PersistentForm.Load(Self); 92 LoadTree; 93 end; 94 95 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; 45 135 end; 46 136 end; 47 137 48 138 procedure TMainForm.LoadTree; 139 var 140 DbRows: TDbRows; 141 ObjectDbRows: TDbRows; 142 I: Integer; 143 O: Integer; 144 NewNode: TTreeNode; 145 NewObjectNode: TTreeNode; 49 146 begin 50 147 with TreeView1, Items do begin 148 Clear; 149 AddChild(nil, 'Skupiny'); 150 DbRows := Database.Query('SELECT * FROM `MenuGroup`'); 151 for I := 0 to DbRows.Count - 1 do begin 152 NewNode := AddChild(TopItem, DbRows[I].Values['Name']); 153 ObjectDbRows := Database.Query('SELECT * FROM `Object` WHERE `MenuGroup`=' + DbRows[I].Values['Id']); 154 for O := 0 to ObjectDbRows.Count - 1 do begin 155 NewObjectNode := AddChild(NewNode, ObjectDbRows[O].Values['Name']); 156 NewObjectNode.ImageIndex := StrToInt(ObjectDbRows[O].Values['Id']); 157 end; 158 ObjectDbRows.Destroy; 159 end; 160 TopItem.Expand(True); 161 DbRows.Destroy; 162 end; 51 163 end; 52 164
Note:
See TracChangeset
for help on using the changeset viewer.