Changeset 13 for trunk/Forms/UMainForm.pas
- Timestamp:
- Jun 10, 2011, 8:23:37 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UMainForm.pas
r12 r13 68 68 procedure AInitSystemValuesExecute(Sender: TObject); 69 69 procedure AItemAddExecute(Sender: TObject); 70 procedure AItemDeleteExecute(Sender: TObject); 70 71 procedure AItemEditExecute(Sender: TObject); 71 72 procedure AItemViewExecute(Sender: TObject); … … 116 117 SObjectNotFound = 'Object not found'; 117 118 SGroup = 'Groups'; 119 SItemDeletion = 'Delete items'; 120 SReallyWantToDelete = 'Really want to delete selected items?'; 118 121 119 122 … … 171 174 Data: TDictionaryStringString; 172 175 ObjectId: Integer; 176 Tables: TListString; 177 I: Integer; 173 178 begin 174 179 with System do 175 180 try 176 181 DbRows := TDbRows.Create; 182 Tables := TListString.Create; 177 183 Data := TDictionaryStringString.Create; 178 184 179 Database.Query(DbRows, 'SHOW TABLES LIKE "' + InformationTable + '"'); 180 if DbRows.Count = 0 then begin 185 Database.Query(DbRows, 'SHOW TABLES'); 186 Tables.Count := DbRows.Count; 187 for I := 0 to DbRows.Count - 1 do 188 Tables[I] := DbRows[I].Items[0].Value; 189 190 if Tables.IndexOf(InformationTable) = -1 then begin 181 191 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + InformationTable + '` ( ' + 182 192 '`Version` varchar(255) NOT NULL,' + … … 189 199 StructureVersion := DbRows[0].Values['Version']; 190 200 191 Database.Query(DbRows, 'SHOW TABLES LIKE "' + ObjectTable + '"'); 192 if DbRows.Count = 0 then begin 201 if Tables.IndexOf(ObjectTable) = -1 then begin 193 202 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ObjectTable + '` ( ' + 194 203 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + … … 197 206 '`Table` varchar(255) NOT NULL,' + 198 207 '`PrimaryKey` varchar(255) NOT NULL DEFAULT "Id", ' + 199 '`Sequence` int(11) NOT NULL ,' +208 '`Sequence` int(11) NOT NULL DEFAULT 0,' + 200 209 '`Group` int(11) NOT NULL,' + 201 ' PRIMARY KEY (`Id`),' +202 ' KEY `Group` (`Group`)' +210 'KEY `Group` (`Group`),' + 211 'PRIMARY KEY (`Id`)' + 203 212 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 204 213 205 214 end; 206 215 207 Database.Query(DbRows, 'SHOW TABLES LIKE "' + ObjectGroupTable + '"'); 208 if DbRows.Count = 0 then begin 216 if Tables.IndexOf(ObjectGroupTable) = -1 then begin 209 217 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + ObjectGroupTable + '` ( ' + 210 218 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 211 219 '`Name` varchar(255) NOT NULL,' + 212 '`Parent` int(11) NOT NULL,' + 213 '`Sequence` int(11) NOT NULL,' + 220 '`Parent` int(11) NOT NULL DEFAULT 0,' + 221 '`Sequence` int(11) NOT NULL DEFAULT 0,' + 222 'KEY `Parent` (`Parent`),' + 214 223 'PRIMARY KEY (`Id`)' + 215 224 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 216 225 end; 217 226 218 Database.Query(DbRows, 'SHOW TABLES LIKE "' + PropertyTable + '"'); 219 if DbRows.Count = 0 then begin 227 if Tables.IndexOf(PropertyTable) = -1 then begin 220 228 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyTable + '` ( ' + 221 229 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 222 230 '`Name` varchar(255) NOT NULL,' + 223 231 '`Object` int(11) NOT NULL,' + 224 '`PropertyGroup` int(11) NOT NULL,' + 225 '`Type` int(11) NOT NULL,' + 232 '`PropertyGroup` int(11) NOT NULL DEFAULT 0,' + 233 '`CustomType` int(11) NOT NULL,' + 234 '`Editable` bool NOT NULL DEFAULT 1,' + 226 235 '`ColumnName` varchar(255) NOT NULL,' + 227 236 'KEY `Object` (`Object`),' + 228 237 'KEY `PropertyGroup` (`PropertyGroup`),' + 229 'KEY ` Type` (`Type`),' +238 'KEY `CustomType` (`CustomType`),' + 230 239 'PRIMARY KEY (`Id`)' + 231 240 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 232 241 end; 233 Database.Query(DbRows, 'SHOW TABLES LIKE "' + PropertyTypeTable + '"'); 234 if DbRows.Count = 0 then begin 242 if Tables.IndexOf(PropertyTypeTable) = -1 then begin 235 243 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyTypeTable + '` ( ' + 236 244 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + … … 238 246 '`DbType` varchar(255) NOT NULL,' + 239 247 '`TypeIndex` int(11) NOT NULL,' + 240 '`Parent` int(11) NOT NULL,' +241 '`ParameterTable` varchar(255) NOT NULL,' +242 248 'PRIMARY KEY (`Id`)' + 243 249 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 244 250 end; 245 Database.Query(DbRows, 'SHOW TABLES LIKE "' + PropertyGroupTable + '"'); 246 if DbRows.Count = 0then begin251 252 if Tables.IndexOf(PropertyGroupTable) = -1 then begin 247 253 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + PropertyGroupTable + '` ( ' + 248 254 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + … … 254 260 end; 255 261 262 if Tables.IndexOf(EnumerationState) = -1 then begin 263 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 begin 274 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 begin 282 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 begin 291 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeRelationOne + '` ( ' + 292 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 293 '`Type` int(11) NOT NULL,' + 294 '`Object` int(11) NOT NULL,' + 295 'KEY `Type` (`Type`),' + 296 'PRIMARY KEY (`Id`)' + 297 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 298 end; 299 300 if Tables.IndexOf(TypeRelationMany) = -1 then begin 301 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeRelationMany + '` ( ' + 302 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 303 '`Type` int(11) NOT NULL,' + 304 '`ObjectProperty` int(11) NOT NULL,' + 305 'KEY `Type` (`Type`),' + 306 'PRIMARY KEY (`Id`)' + 307 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 308 end; 309 310 if Tables.IndexOf(TypeFile) = -1 then begin 311 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 begin 320 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(CustomType) = -1 then begin 329 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + CustomType + '` ( ' + 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 begin 338 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(TypeString) = -1 then begin 350 Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + TypeString + '` ( ' + 351 '`Id` int(11) NOT NULL AUTO_INCREMENT,' + 352 '`CustomType` int NOT NULL,' + 353 '`Default` VARCHAR(255) NOT NULL,' + 354 '`MaxLength` int NOT NULL,' + 355 'KEY `CustomType` (`CustomType`),' + 356 'PRIMARY KEY (`Id`)' + 357 ') ENGINE=InnoDB DEFAULT CHARSET=utf8'); 358 end; 256 359 finally 360 Tables.Free; 257 361 Data.Free; 258 362 DbRows.Free; … … 265 369 TypeNumber: Integer; 266 370 TypeString: Integer; 371 TypeBoolean: Integer; 267 372 GroupId: Integer; 373 EnumId: Integer; 268 374 begin 269 375 with System do begin 270 376 TypeNumber := AddType('Number', 'INT', vtInteger); 271 TypeString := AddType('String', 'VAR (255)', vtString);377 TypeString := AddType('String', 'VARCHAR(255)', vtString); 272 378 AddType('Text', 'TEXT', vtText); 273 379 AddType('Date and time', 'DATETIME', vtDateTime); 274 380 AddType('Floating number', 'FLOAT', vtFloat); 275 381 AddType('Image', 'BLOB', vtImage); 276 AddType('Boolean', 'BOOL', vtBoolean);382 TypeBoolean := AddType('Boolean', 'BOOL', vtBoolean); 277 383 AddType('IPv4', 'BINARY(4)', vtIPv4); 278 384 AddType('IPv6', 'BINARY(16)', vtIPv6); 279 385 AddType('MAC address', 'BINARY(6)', vtMAC); 280 AddType('File', ' ', vtFile);281 AddType('GPS', ' ', vtGPS);386 AddType('File', 'INT', vtFile); 387 AddType('GPS', 'INT', vtGPS); 282 388 AddType('Currency', 'FLOAT', vtCurrency); 283 AddType('Enumeration', ' ', vtEnumeration);389 AddType('Enumeration', 'INT', vtEnumeration); 284 390 AddType('Time', 'TIME', vtTime); 285 391 AddType('Date', 'DATE', vtDate); 286 392 AddType('Color', 'INT', vtColor); 393 AddType('Hyperlink', 'VARCHAR(255)', vtHyperlink); 394 AddType('RelationOne', 'INT', vtRelationOne); 395 AddType('RelationMany', 'INT', vtRelationMany); 396 AddType('Password', 'VARCHAR(255)', vtPassword); 397 398 EnumId := AddEnumeration('Boolean'); 399 AddEnumerationState(EnumId, 'False'); 400 AddEnumerationState(EnumId, 'True'); 401 402 EnumId := AddEnumeration('Priority'); 403 AddEnumerationState(EnumId, 'Low'); 404 AddEnumerationState(EnumId, 'Normal'); 405 AddEnumerationState(EnumId, 'High'); 287 406 288 407 GroupId := AddObjectGroup('System'); 289 408 290 409 ObjectId := AddObject('Object groups', 'ObjectGroup', System.Database.Database, GroupId); 291 AddProperty (ObjectId, 'Name', 'Name', TypeString);410 AddPropertyString(ObjectId, 'Name', 'Name'); 292 411 ObjectId := AddObject('Objects', 'Object', System.Database.Database, GroupId); 293 AddProperty (ObjectId, 'Name', 'Name', TypeString);294 AddProperty (ObjectId, 'Group', 'Group', TypeNumber);295 AddProperty (ObjectId, 'Schema', 'Schema', TypeString);296 AddProperty (ObjectId, 'Table', 'Table', TypeString);297 AddProperty (ObjectId, 'Primary key', 'PrimaryKey', TypeString);298 AddProperty (ObjectId, 'Sequence', 'Sequence', TypeNumber);412 AddPropertyString(ObjectId, 'Name', 'Name'); 413 AddPropertyNumber(ObjectId, 'Group', 'Group'); 414 AddPropertyString(ObjectId, 'Schema', 'Schema'); 415 AddPropertyString(ObjectId, 'Table', 'Table'); 416 AddPropertyString(ObjectId, 'Primary key', 'PrimaryKey'); 417 AddPropertyNumber(ObjectId, 'Sequence', 'Sequence'); 299 418 ObjectId := AddObject('Property types', 'Type', System.Database.Database, GroupId); 300 AddProperty (ObjectId, 'Name', 'Name', TypeString);301 AddProperty (ObjectId, 'Type', 'DbType', TypeString);302 AddProperty (ObjectId, 'Type index', 'TypeIndex', TypeNumber);303 AddProperty (ObjectId, 'Parent', 'Parent', TypeNumber);419 AddPropertyString(ObjectId, 'Name', 'Name'); 420 AddPropertyString(ObjectId, 'Type', 'DbType'); 421 AddPropertyNumber(ObjectId, 'Type index', 'TypeIndex'); 422 AddPropertyNumber(ObjectId, 'Parent', 'Parent'); 304 423 ObjectId := AddObject('Property groups', 'PropertyGroup', System.Database.Database, GroupId); 305 424 ObjectId := AddObject('Properties', 'Property', System.Database.Database, GroupId); 306 AddProperty(ObjectId, 'Name', 'Name', TypeString); 307 AddProperty(ObjectId, 'Object', 'Object', TypeNumber); 308 AddProperty(ObjectId, 'PropertyGroup', 'PropertyGroup', TypeNumber); 309 AddProperty(ObjectId, 'Type', 'Type', TypeNumber); 310 AddProperty(ObjectId, 'ColumnName', 'ColumnName', TypeString); 425 AddPropertyString(ObjectId, 'Name', 'Name'); 426 AddPropertyNumber(ObjectId, 'Object', 'Object'); 427 AddPropertyNumber(ObjectId, 'PropertyGroup', 'PropertyGroup'); 428 AddPropertyNumber(ObjectId, 'Type', 'Type'); 429 AddProperty(ObjectId, 'Editable', 'Editable', TypeBoolean); 430 AddPropertyString(ObjectId, 'ColumnName', 'ColumnName'); 311 431 end; 312 432 end; … … 412 532 end; 413 533 414 procedure TMainForm.AItemAddExecute(Sender: TObject);415 begin416 ItemAddForm.Show;417 end;418 419 534 procedure TMainForm.AExitExecute(Sender: TObject); 420 535 begin … … 426 541 InitSystemValues; 427 542 LoadTree; 543 end; 544 545 procedure TMainForm.AItemAddExecute(Sender: TObject); 546 begin 547 ItemAddForm.ShowModal; 548 end; 549 550 procedure TMainForm.AItemDeleteExecute(Sender: TObject); 551 begin 552 if MessageDlg(SItemDeletion, SReallyWantToDelete, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin 553 554 end; 428 555 end; 429 556
Note:
See TracChangeset
for help on using the changeset viewer.