Changeset 11 for trunk/Forms/UMainForm.pas
- Timestamp:
- Jun 9, 2011, 12:34:21 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UMainForm.pas
r10 r11 8 8 Registry, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 9 StdCtrls, ActnList, Menus, ExtCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, 10 UPersistentForm, UTreeState, SpecializedList, URegistry, USystem; 11 12 const 13 ConfigFileName = 'Config.xml'; 10 UPersistentForm, UTreeState, SpecializedList, SpecializedDictionary, 11 URegistry, USystem; 14 12 15 13 type … … 18 16 TMainForm = class(TForm) 19 17 AConnect: TAction; 18 AInitSystemValues: TAction; 20 19 ASettings: TAction; 21 20 AToggleFullscreen: TAction; … … 48 47 MenuItem16: TMenuItem; 49 48 MenuItem17: TMenuItem; 49 MenuItem18: TMenuItem; 50 MenuItem19: TMenuItem; 50 51 MenuItem2: TMenuItem; 51 52 MenuItem3: TMenuItem; … … 65 66 procedure AConnectExecute(Sender: TObject); 66 67 procedure AExitExecute(Sender: TObject); 68 procedure AInitSystemValuesExecute(Sender: TObject); 67 69 procedure AItemAddExecute(Sender: TObject); 68 70 procedure AItemEditExecute(Sender: TObject); … … 94 96 procedure SaveToRegistry; 95 97 procedure InitStructure; 98 procedure InitSystemValues; 96 99 public 97 100 SelectedObjectId: Integer; … … 157 160 158 161 procedure TMainForm.InitStructure; 159 begin 160 162 var 163 DbRows: TDbRows; 164 DbRows2: TDbRows; 165 StructureVersion: string; 166 Data: TDictionaryStringString; 167 ObjectId: Integer; 168 begin 169 with System do 170 try 171 DbRows := TDbRows.Create; 172 Data := TDictionaryStringString.Create; 173 174 Database.Query(DbRows, 'SHOW TABLES LIKE "' + InformationTable + '"'); 175 if DbRows.Count = 0 then begin 176 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + InformationTable + '` ( ' + 177 '`Version` varchar(255) NOT NULL,' + 178 '`LastUpdateTime` datetime NOT NULL' + 179 ') ENGINE=InnoDB DEFAULT CHARSET=utf8;'); 180 Database.Query(DbRows, 'INSERT INTO `' + InformationTable + '` (`Version`, `LastUpdateTime`) VALUES ' + 181 '("0.1", "0000-00-00 00:00:00");'); 182 end; 183 Database.Select(DbRows, InformationTable); 184 StructureVersion := DbRows[0].Values['Version']; 185 186 Database.Query(DbRows, 'SHOW TABLES LIKE "' + ObjectTable + '"'); 187 if DbRows.Count = 0 then begin 188 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ObjectTable + '` ( ' + 189 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 190 '`Name` varchar(255) NOT NULL,' + 191 '`Schema` varchar(255) NOT NULL,' + 192 '`Table` varchar(255) NOT NULL,' + 193 '`PrimaryKey` varchar(255) NOT NULL DEFAULT "Id", ' + 194 '`Sequence` int(11) NOT NULL,' + 195 '`Group` int(11) NOT NULL,' + 196 'PRIMARY KEY (`Id`),' + 197 'KEY `Group` (`Group`)' + 198 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 199 200 end; 201 202 Database.Query(DbRows, 'SHOW TABLES LIKE "' + ObjectGroupTable + '"'); 203 if DbRows.Count = 0 then begin 204 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ObjectGroupTable + '` ( ' + 205 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 206 '`Name` varchar(255) NOT NULL,' + 207 '`Parent` int(11) NOT NULL,' + 208 '`Sequence` int(11) NOT NULL,' + 209 'PRIMARY KEY (`Id`)' + 210 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 211 end; 212 213 Database.Query(DbRows, 'SHOW TABLES LIKE "' + PropertyTable + '"'); 214 if DbRows.Count = 0 then begin 215 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyTable + '` ( ' + 216 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 217 '`Name` varchar(255) NOT NULL,' + 218 '`Object` int(11) NOT NULL,' + 219 '`PropertyGroup` int(11) NOT NULL,' + 220 '`Type` int(11) NOT NULL,' + 221 '`ColumnName` varchar(255) NOT NULL,' + 222 'KEY `Object` (`Object`),' + 223 'KEY `PropertyGroup` (`PropertyGroup`),' + 224 'KEY `Type` (`Type`),' + 225 'PRIMARY KEY (`Id`)' + 226 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 227 end; 228 Database.Query(DbRows, 'SHOW TABLES LIKE "' + PropertyTypeTable + '"'); 229 if DbRows.Count = 0 then begin 230 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyTypeTable + '` ( ' + 231 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 232 '`Name` varchar(255) NOT NULL,' + 233 '`DbType` varchar(255) NOT NULL,' + 234 '`TypeIndex` int(11) NOT NULL,' + 235 '`Parent` int(11) NOT NULL,' + 236 '`ParameterTable` varchar(255) NOT NULL,' + 237 'PRIMARY KEY (`Id`)' + 238 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 239 end; 240 Database.Query(DbRows, 'SHOW TABLES LIKE "' + PropertyGroupTable + '"'); 241 if DbRows.Count = 0 then begin 242 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyGroupTable + '` ( ' + 243 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 244 '`Name` varchar(255) NOT NULL,' + 245 '`Object` int(11) NOT NULL,' + 246 'KEY `Object` (`Object`),' + 247 'PRIMARY KEY (`Id`)' + 248 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 249 end; 250 251 finally 252 Data.Free; 253 DbRows.Free; 254 end; 255 end; 256 257 procedure TMainForm.InitSystemValues; 258 var 259 ObjectId: Integer; 260 TypeNumber: Integer; 261 TypeString: Integer; 262 GroupId: Integer; 263 begin 264 with System do begin 265 TypeNumber := AddType('Number', 'INT', vtInteger); 266 TypeString := AddType('String', 'VAR(255)', vtString); 267 AddType('Text', 'TEXT', vtText); 268 AddType('Date and time', 'DATETIME', vtDateTime); 269 AddType('Floating number', 'FLOAT', vtFloat); 270 AddType('Image', 'BLOB', vtImage); 271 AddType('Boolean', 'BOOL', vtBoolean); 272 AddType('IPv4', 'BINARY(4)', vtIPv4); 273 AddType('IPv6', 'BINARY(16)', vtIPv6); 274 AddType('MAC address', 'BINARY(6)', vtMAC); 275 AddType('File', '', vtFile); 276 AddType('GPS', '', vtGPS); 277 AddType('Currency', 'FLOAT', vtCurrency); 278 AddType('Enumeration', '', vtEnumeration); 279 AddType('Time', 'TIME', vtTime); 280 AddType('Date', 'DATE', vtDate); 281 AddType('Color', 'INT', vtColor); 282 283 GroupId := AddObjectGroup('System'); 284 285 ObjectId := AddObject('Object groups', 'ObjectGroup', System.Database.Database, GroupId); 286 AddProperty(ObjectId, 'Name', 'Name', TypeString); 287 ObjectId := AddObject('Objects', 'Object', System.Database.Database, GroupId); 288 AddProperty(ObjectId, 'Name', 'Name', TypeString); 289 AddProperty(ObjectId, 'Group', 'Group', TypeNumber); 290 AddProperty(ObjectId, 'Schema', 'Schema', TypeString); 291 AddProperty(ObjectId, 'Table', 'Table', TypeString); 292 AddProperty(ObjectId, 'Primary key', 'PrimaryKey', TypeString); 293 AddProperty(ObjectId, 'Sequence', 'Sequence', TypeNumber); 294 ObjectId := AddObject('Property types', 'Type', System.Database.Database, GroupId); 295 AddProperty(ObjectId, 'Name', 'Name', TypeString); 296 AddProperty(ObjectId, 'Type', 'DbType', TypeString); 297 AddProperty(ObjectId, 'Type index', 'TypeIndex', TypeNumber); 298 AddProperty(ObjectId, 'Parent', 'Parent', TypeNumber); 299 ObjectId := AddObject('Property groups', 'PropertyGroup', System.Database.Database, GroupId); 300 ObjectId := AddObject('Properties', 'Property', System.Database.Database, GroupId); 301 AddProperty(ObjectId, 'Name', 'Name', TypeString); 302 AddProperty(ObjectId, 'Object', 'Object', TypeNumber); 303 AddProperty(ObjectId, 'PropertyGroup', 'PropertyGroup', TypeNumber); 304 AddProperty(ObjectId, 'Type', 'Type', TypeNumber); 305 AddProperty(ObjectId, 'ColumnName', 'ColumnName', TypeString); 306 end; 161 307 end; 162 308 … … 271 417 end; 272 418 419 procedure TMainForm.AInitSystemValuesExecute(Sender: TObject); 420 begin 421 InitSystemValues; 422 LoadTree; 423 end; 424 273 425 procedure TMainForm.AConnectExecute(Sender: TObject); 274 426 begin … … 360 512 try 361 513 DbRows := TDbRows.Create; 362 System.Database.Query(DbRows, 'SELECT * FROM ` ObjectGroup`');514 System.Database.Query(DbRows, 'SELECT * FROM `' + ObjectGroupTable + '`'); 363 515 for I := 0 to DbRows.Count - 1 do begin 364 516 NewNode := AddChild(TopItem, DbRows[I].Values['Name']); … … 368 520 try 369 521 ObjectDbRows := TDbRows.Create; 370 System.Database.Query(ObjectDbRows, 'SELECT * FROM ` Object` WHERE `Group`=' + DbRows[I].Values['Id']);522 System.Database.Query(ObjectDbRows, 'SELECT * FROM `' + ObjectTable + '` WHERE `Group`=' + DbRows[I].Values['Id']); 371 523 for O := 0 to ObjectDbRows.Count - 1 do begin 372 524 NewObjectNode := AddChild(NewNode, ObjectDbRows[O].Values['Name']);
Note:
See TracChangeset
for help on using the changeset viewer.