Changeset 29 for trunk/Forms/UMainForm.pas
- Timestamp:
- Nov 23, 2011, 8:24:07 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UMainForm.pas
r27 r29 20 20 ADisconnect: TAction; 21 21 AImportStructure: TAction; 22 AInitSystemValues: TAction;23 22 ASettings: TAction; 24 23 AToggleFullscreen: TAction; … … 52 51 MenuItem17: TMenuItem; 53 52 MenuItem18: TMenuItem; 54 MenuItem19: TMenuItem;55 53 MenuItem2: TMenuItem; 56 54 MenuItem20: TMenuItem; … … 76 74 procedure AExitExecute(Sender: TObject); 77 75 procedure AImportStructureExecute(Sender: TObject); 78 procedure AInitSystemValuesExecute(Sender: TObject);79 76 procedure AItemAddExecute(Sender: TObject); 80 77 procedure AItemDeleteExecute(Sender: TObject); … … 98 95 Selected: Boolean); 99 96 procedure MenuItem17Click(Sender: TObject); 97 procedure MenuItem19Click(Sender: TObject); 100 98 procedure TreeView1Change(Sender: TObject; Node: TTreeNode); 101 99 private … … 105 103 procedure LoadFromRegistry; 106 104 procedure SaveToRegistry; 107 procedure InitStructure;108 procedure InitSystemValues;109 105 public 110 106 SelectedObjectId: Integer; … … 168 164 end; 169 165 170 procedure TMainForm.InitStructure;171 var172 DbRows: TDbRows;173 DbRows2: TDbRows;174 StructureVersion: string;175 Data: TDictionaryStringString;176 ObjectId: Integer;177 Tables: TListString;178 I: Integer;179 begin180 with Core.System do181 try182 DbRows := TDbRows.Create;183 Tables := TListString.Create;184 Data := TDictionaryStringString.Create;185 186 Database.Query(DbRows, 'SHOW TABLES');187 Tables.Count := DbRows.Count;188 for I := 0 to DbRows.Count - 1 do189 Tables[I] := DbRows[I].Items[0].Value;190 191 if Tables.IndexOf(InformationTable) = -1 then begin192 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + InformationTable + '` ( ' +193 '`Version` varchar(255) NOT NULL,' +194 '`LastUpdateTime` datetime NOT NULL' +195 ') ENGINE=InnoDB DEFAULT CHARSET=utf8;');196 Database.Query(DbRows, 'INSERT INTO `' + InformationTable + '` (`Version`, `LastUpdateTime`) VALUES ' +197 '("0.1", "0000-00-00 00:00:00");');198 end;199 Database.Select(DbRows, InformationTable);200 StructureVersion := DbRows[0].Values['Version'];201 202 if Tables.IndexOf(ObjectTable) = -1 then begin203 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ObjectTable + '` ( ' +204 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +205 '`Name` varchar(255) NOT NULL,' +206 '`Schema` varchar(255) NOT NULL,' +207 '`Table` varchar(255) NOT NULL,' +208 '`PrimaryKey` varchar(255) NOT NULL DEFAULT "Id", ' +209 '`Sequence` int(11) NOT NULL DEFAULT 0,' +210 '`Group` int(11) NOT NULL,' +211 'KEY `Group` (`Group`),' +212 'PRIMARY KEY (`Id`)' +213 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');214 215 end;216 217 if Tables.IndexOf(ObjectGroupTable) = -1 then begin218 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ObjectGroupTable + '` ( ' +219 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +220 '`Name` varchar(255) NOT NULL,' +221 '`Parent` int(11) NOT NULL DEFAULT 0,' +222 '`Sequence` int(11) NOT NULL DEFAULT 0,' +223 'KEY `Parent` (`Parent`),' +224 'PRIMARY KEY (`Id`)' +225 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');226 end;227 228 if Tables.IndexOf(PropertyTable) = -1 then begin229 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyTable + '` ( ' +230 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +231 '`Name` varchar(255) NOT NULL,' +232 '`Object` int(11) NOT NULL,' +233 '`PropertyGroup` int(11) NOT NULL DEFAULT 0,' +234 '`CustomType` int(11) NOT NULL,' +235 '`Editable` bool NOT NULL DEFAULT 1,' +236 '`ColumnName` varchar(255) NOT NULL,' +237 'KEY `Object` (`Object`),' +238 'KEY `PropertyGroup` (`PropertyGroup`),' +239 'KEY `CustomType` (`CustomType`),' +240 'PRIMARY KEY (`Id`)' +241 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');242 end;243 if Tables.IndexOf(PropertyTypeTable) = -1 then begin244 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyTypeTable + '` ( ' +245 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +246 '`Name` varchar(255) NOT NULL,' +247 '`DbType` varchar(255) NOT NULL,' +248 'PRIMARY KEY (`Id`)' +249 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');250 end;251 252 if Tables.IndexOf(PropertyGroupTable) = -1 then begin253 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyGroupTable + '` ( ' +254 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +255 '`Name` varchar(255) NOT NULL,' +256 '`Object` int(11) NOT NULL,' +257 'KEY `Object` (`Object`),' +258 'PRIMARY KEY (`Id`)' +259 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');260 end;261 262 if Tables.IndexOf(EnumerationState) = -1 then begin263 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + EnumerationState + '` ( ' +264 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +265 '`Enumeration` int(11) NOT NULL,' +266 '`Name` varchar(255) NOT NULL,' +267 '`Sequence` int(11) NOT NULL DEFAULT 0,' +268 'KEY `Enumeration` (`Enumeration`),' +269 'PRIMARY KEY (`Id`)' +270 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');271 end;272 273 if Tables.IndexOf(Enumeration) = -1 then begin274 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + Enumeration + '` ( ' +275 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +276 '`Name` varchar(255) NOT NULL,' +277 'PRIMARY KEY (`Id`)' +278 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');279 end;280 281 if Tables.IndexOf(TypeEnumeration) = -1 then begin282 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeEnumeration + '` ( ' +283 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +284 '`Enumeration` int(11) NOT NULL,' +285 'KEY `Enumeration` (`Enumeration`),' +286 'PRIMARY KEY (`Id`)' +287 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');288 end;289 290 if Tables.IndexOf(TypeRelationOne) = -1 then begin291 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeRelationOne + '` ( ' +292 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +293 '`CustomType` int(11) NOT NULL,' +294 '`Object` int(11) NOT NULL,' +295 'KEY `CustomType` (`CustomType`),' +296 'PRIMARY KEY (`Id`)' +297 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');298 end;299 300 if Tables.IndexOf(TypeRelationMany) = -1 then begin301 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeRelationMany + '` ( ' +302 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +303 '`CustomType` int(11) NOT NULL,' +304 '`ObjectProperty` int(11) NOT NULL,' +305 'KEY `CustomType` (`CustomType`),' +306 'PRIMARY KEY (`Id`)' +307 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');308 end;309 310 if Tables.IndexOf(TypeFile) = -1 then begin311 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeFile + '` ( ' +312 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +313 '`Name` varchar(255) NOT NULL,' +314 '`Size` int(11) NOT NULL,' +315 'PRIMARY KEY (`Id`)' +316 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');317 end;318 319 if Tables.IndexOf(TypeGPS) = -1 then begin320 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeGPS + '` ( ' +321 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +322 '`Latitude` double NOT NULL,' +323 '`Longitude` double NOT NULL,' +324 'PRIMARY KEY (`Id`)' +325 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');326 end;327 328 if Tables.IndexOf(CustomTypeTableName) = -1 then begin329 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + CustomTypeTableName + '` ( ' +330 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +331 '`Type` int NOT NULL,' +332 'KEY `Type` (`Type`),' +333 'PRIMARY KEY (`Id`)' +334 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');335 end;336 337 if Tables.IndexOf(TypeNumber) = -1 then begin338 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeNumber + '` ( ' +339 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +340 '`CustomType` int NOT NULL,' +341 '`Default` int NOT NULL,' +342 '`Min` int NOT NULL,' +343 '`Max` int NOT NULL,' +344 'KEY `CustomType` (`CustomType`),' +345 'PRIMARY KEY (`Id`)' +346 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');347 end;348 349 if Tables.IndexOf(TypeFloat) = -1 then begin350 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeFloat + '` ( ' +351 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +352 '`CustomType` int NOT NULL,' +353 '`Default` float NOT NULL,' +354 '`Min` float NOT NULL,' +355 '`Max` float NOT NULL,' +356 'KEY `CustomType` (`CustomType`),' +357 'PRIMARY KEY (`Id`)' +358 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');359 end;360 361 if Tables.IndexOf(TypeDateTime) = -1 then begin362 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeDateTime + '` ( ' +363 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +364 '`CustomType` int NOT NULL,' +365 '`Default` datetime NOT NULL,' +366 '`Min` datetime NOT NULL,' +367 '`Max` datetime NOT NULL,' +368 'KEY `CustomType` (`CustomType`),' +369 'PRIMARY KEY (`Id`)' +370 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');371 end;372 373 if Tables.IndexOf(TypeString) = -1 then begin374 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeString + '` ( ' +375 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +376 '`CustomType` int NOT NULL,' +377 '`Default` VARCHAR(255) NOT NULL,' +378 '`MaxLength` int NOT NULL,' +379 'KEY `CustomType` (`CustomType`),' +380 'PRIMARY KEY (`Id`)' +381 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');382 end;383 384 if Tables.IndexOf(ModuleTable) = -1 then begin385 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ModuleTable + '` ( ' +386 '`Id` int(11) NOT NULL AUTO_INCREMENT,' +387 '`Name` VARCHAR(255) NOT NULL,' +388 '`Author` VARCHAR(255) NOT NULL,' +389 '`Website` VARCHAR(255) NOT NULL,' +390 '`Version` VARCHAR(255) NOT NULL,' +391 '`License` VARCHAR(255) NOT NULL,' +392 '`Description` TEXT NOT NULL,' +393 'PRIMARY KEY (`Id`)' +394 ') ENGINE=InnoDB DEFAULT CHARSET=utf8');395 end;396 finally397 Tables.Free;398 Data.Free;399 DbRows.Free;400 end;401 end;402 403 procedure TMainForm.InitSystemValues;404 var405 ObjectId: Integer;406 ObjectGroupId: Integer;407 PropertyParentId: Integer;408 ObjectPropertyGroupId: Integer;409 PropertyTypeId: Integer;410 ObjectPropertyId: Integer;411 ObjectPropertyIdGroup: Integer;412 PropertyObjectId: Integer;413 CustomTypeId: Integer;414 CustomTypeIdType: Integer;415 ObjectIdGroupId: Integer;416 TypeNumber: Integer;417 ObjectGroupParentId: Integer;418 TypeString: Integer;419 TypeBoolean: Integer;420 GroupId: Integer;421 EnumId: Integer;422 ModuleId: Integer;423 ModuleBaseId: Integer;424 begin425 with Core.System do begin426 TypeNumber := AddType('Number', 'INT', vtInteger);427 TypeString := AddType('String', 'VARCHAR(255)', vtString);428 AddType('Text', 'TEXT', vtText);429 AddType('Date and time', 'DATETIME', vtDateTime);430 AddType('Floating number', 'FLOAT', vtFloat);431 AddType('Image', 'BLOB', vtImage);432 TypeBoolean := AddType('Boolean', 'BOOL', vtBoolean);433 AddType('IPv4', 'BINARY(4)', vtIPv4);434 AddType('IPv6', 'BINARY(16)', vtIPv6);435 AddType('MAC address', 'BINARY(6)', vtMAC);436 AddType('File', 'INT', vtFile);437 AddType('GPS', 'INT', vtGPS);438 AddType('Currency', 'FLOAT', vtCurrency);439 AddType('Enumeration', 'INT', vtEnumeration);440 AddType('Time', 'TIME', vtTime);441 AddType('Date', 'DATE', vtDate);442 AddType('Color', 'INT', vtColor);443 AddType('Hyperlink', 'VARCHAR(255)', vtHyperlink);444 AddType('RelationOne', 'INT', vtRelationOne);445 AddType('RelationMany', 'INT', vtRelationMany);446 AddType('Password', 'VARCHAR(255)', vtPassword);447 448 EnumId := AddEnumeration('Boolean');449 AddEnumerationState(EnumId, 'False');450 AddEnumerationState(EnumId, 'True');451 452 EnumId := AddEnumeration('Priority');453 AddEnumerationState(EnumId, 'Low');454 AddEnumerationState(EnumId, 'Normal');455 AddEnumerationState(EnumId, 'High');456 457 GroupId := AddObjectGroup('System');458 459 ObjectGroupId := AddObject('Object groups', 'ObjectGroup', Core.System.Database.Database, GroupId);460 AddPropertyNumber(ObjectGroupId, 'Id', 'Id', False);461 AddPropertyString(ObjectGroupId, 'Name', 'Name', True);462 ObjectGroupParentId := AddPropertyRelationOne(ObjectGroupId, 'Parent', 'Parent', True, ObjectGroupId);463 464 ObjectId := AddObject('Objects', 'Object', Core.System.Database.Database, GroupId);465 AddPropertyNumber(ObjectId, 'Id', 'Id', False);466 AddPropertyString(ObjectId, 'Name', 'Name', True);467 ObjectIdGroupId := AddPropertyRelationOne(ObjectId, 'Group', 'Group', True, ObjectGroupId);468 AddPropertyString(ObjectId, 'Schema', 'Schema', True);469 AddPropertyString(ObjectId, 'Table', 'Table', True);470 AddPropertyString(ObjectId, 'Primary key', 'PrimaryKey', True);471 AddPropertyNumber(ObjectId, 'Sequence', 'Sequence', True);472 473 PropertyTypeId := AddObject('Property types', 'Type', Core.System.Database.Database, GroupId);474 AddPropertyNumber(PropertyTypeId, 'Id', 'Id', False);475 AddPropertyString(PropertyTypeId, 'Name', 'Name', True);476 AddPropertyString(PropertyTypeId, 'Type', 'DbType', True);477 //AddPropertyNumber(ObjectId, 'Parent', 'Parent');478 479 CustomTypeId := AddObject('Custom types', 'TypeCustom', Core.System.Database.Database, GroupId);480 AddPropertyNumber(CustomTypeId, 'Id', 'Id', False);481 CustomTypeIdType := AddPropertyRelationOne(CustomTypeId, 'Type', 'Type', True, PropertyTypeId);482 483 ObjectPropertyGroupId := AddObject('Property groups', 'PropertyGroup', Core.System.Database.Database, GroupId);484 AddPropertyNumber(ObjectPropertyGroupId, 'Id', 'Id', False);485 486 ObjectPropertyId := AddObject('Properties', 'Property', Core.System.Database.Database, GroupId);487 AddPropertyNumber(ObjectPropertyId, 'Id', 'Id', False);488 AddPropertyString(ObjectPropertyId, 'Name', 'Name', True);489 PropertyParentId := AddPropertyRelationOne(ObjectPropertyId, 'Object', 'Object', True, ObjectId);490 ObjectPropertyIdGroup := AddPropertyRelationOne(ObjectPropertyId, 'Property group', 'PropertyGroup', True, ObjectPropertyGroupId);491 AddPropertyNumber(ObjectPropertyId, 'Custom type', 'CustomType', True);492 AddProperty(ObjectPropertyId, 'Editable', 'Editable', TypeBoolean, True);493 AddPropertyString(ObjectPropertyId, 'Column name', 'ColumnName', True);494 495 AddPropertyRelationMany(ObjectGroupId, 'Childs', 'Childs', True, PropertyParentId);496 AddPropertyRelationMany(ObjectGroupId, 'Objects', 'Objects', True, ObjectIdGroupId);497 AddPropertyRelationMany(ObjectId, 'Properties', 'Properties', True, PropertyParentId);498 AddPropertyRelationMany(ObjectPropertyGroupId, 'Properties', 'Properties', True, ObjectPropertyIdGroup);499 AddPropertyRelationMany(PropertyTypeId, 'Custom types', 'CustomTypes', True, CustomTypeIdType);500 ModuleId := AddObject('Modules', 'Module', Core.System.Database.Database, GroupId);501 AddPropertyNumber(ModuleId, 'Id', 'Id', False);502 AddPropertyString(ModuleId, 'Name', 'Name', True);503 AddPropertyString(ModuleId, 'Author', 'Author', True);504 AddPropertyString(ModuleId, 'Website', 'Website', False);505 AddPropertyString(ModuleId, 'Version', 'Version', True);506 AddPropertyText(ModuleId, 'Description', 'Description', False);507 AddPropertyString(ModuleId, 'License', 'License', False);508 509 ModuleBaseId := AddModule('Base', 'Chronos', '', '0.1', '', 'GNU/GPL');510 end;511 end;512 513 166 procedure TMainForm.UpdateInterface; 514 167 begin 515 168 ADisconnect.Enabled := Core.System.Database.Connected; 516 169 AConnect.Enabled := not Core.System.Database.Connected; 517 AInitSystemValues.Enabled := Core.System.Database.Connected;518 170 AImportStructure.Enabled := Core.System.Database.Connected; 519 171 end; … … 624 276 end; 625 277 626 procedure TMainForm.AInitSystemValuesExecute(Sender: TObject);627 begin628 InitSystemValues;629 LoadTree;630 end;631 632 278 procedure TMainForm.AItemAddExecute(Sender: TObject); 633 279 begin … … 656 302 try 657 303 Core.System.Database.Connect; 658 InitStructure;304 if Core.System.IsDatabaseEmpty then Core.System.ModuleSystem.Install; 659 305 Core.System.LoadTypes; 660 306 LoadTree; … … 733 379 begin 734 380 LoginForm.ShowModal; 381 end; 382 383 procedure TMainForm.MenuItem19Click(Sender: TObject); 384 begin 385 735 386 end; 736 387
Note:
See TracChangeset
for help on using the changeset viewer.