Changeset 13 for trunk/USystem.pas
- Timestamp:
- Jun 10, 2011, 8:23:37 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/USystem.pas
r12 r13 16 16 PropertyTypeTable = 'Type'; 17 17 PropertyGroupTable = 'PropertyGroup'; 18 TypeEnumeration = 'TypeEnumeration'; 19 TypeFile = 'TypeFile'; 20 TypeGPS = 'TypeGPS'; 21 TypeRelationOne = 'TypeRelationOne'; 22 TypeRelationMany = 'TypeRelationMany'; 23 CustomType = 'TypeCustom'; 24 Enumeration = 'Enumeration'; 25 EnumerationState = 'EnumerationState'; 26 TypeNumber = 'TypeNumber'; 27 TypeString = 'TypeString'; 18 28 19 29 type 20 TDbValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, vtBoolean,21 vt IPv4, vtMAC, vtIPv6, vtFile, vtGPS, vtEnumeration, vtHyperlink, vtPassword,22 vt Reference, vtDate, vtTime, vtColor, vtCurrency);30 TDbValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, 31 vtBoolean, vtIPv4, vtIPv6, vtMAC, vtFile, vtGPS, vtCurrency, vtEnumeration, 32 vtTime, vtDate, vtColor, vtHyperlink, vtRelationOne, vtRelationMany, vtPassword); 23 33 24 34 TChronisType = class; … … 90 100 function AddObject(Name, TableName, Schema: string; GroupId: Integer): Integer; 91 101 function AddProperty(ObjectId: Integer; Name, ColumnName: string; DataType: Integer): Integer; 102 function AddPropertyNumber(ObjectId: Integer; Name, 103 ColumnName: string; Default: Integer = 0; Min: Integer = 0; 104 Max: Integer = High(Integer)): Integer; 105 function AddPropertyString(ObjectId: Integer; Name, ColumnName: string; 106 Default: string = ''; MaxLength: Integer = 255): Integer; 92 107 function AddObjectGroup(Name: string): Integer; 108 function AddEnumeration(Name: string): Integer; 109 function AddEnumerationState(Enum: Integer; Name: string): Integer; 93 110 procedure LoadTypes; 94 111 constructor Create; 95 112 destructor Destroy; override; 113 private 96 114 end; 97 115 … … 99 117 100 118 implementation 119 120 resourcestring 121 SUnsupportedType = 'Unsupported property type "%s"'; 101 122 102 123 { TChronisTypeList } … … 159 180 NewColumn.TypeDef := Base.Types.FindByTypeIndex(Integer(vtInteger)); 160 181 for I := 0 to Properties.Count - 1 do 161 if Properties[I].Values['Type'] <> IntToStr( 20) then begin182 if Properties[I].Values['Type'] <> IntToStr(Integer(vtRelationMany)) then begin 162 183 NewColumn := TReportColumn.Create; 163 184 Columns.Add(NewColumn); … … 165 186 NewColumn.ColumnName := Properties[I].Values['ColumnName'];; 166 187 NewColumn.TypeDef := Base.Types.FindById(StrToInt(Properties[I].Values['Type'])); 188 if not Assigned(NewColumn.TypeDef) then 189 raise Exception.Create(Format(SUnsupportedType, [Properties[I].Values['Type']])); 167 190 end; 168 191 … … 181 204 NewItem.Id := StrToInt(Values[I].Values[Obj.PrimaryKey]); 182 205 for C := 0 to Properties.Count - 1 do 183 if Properties[C].Values['Type'] <> IntToStr( 20) then begin206 if Properties[C].Values['Type'] <> IntToStr(Integer(vtRelationMany)) then begin 184 207 NewItem.Items.Add(Values[I].Values[Properties[C].Values['ColumnName']]); 185 208 end; … … 244 267 Data.Add('Object', IntToStr(ObjectId)); 245 268 Data.Add('ColumnName', ColumnName); 246 Data.Add('Type', IntToStr(DataType)); 269 Data.Add('CustomType', IntToStr(DataType)); 270 Data.Add('Editable', '1'); 247 271 Database.Insert(PropertyTable, Data); 248 272 Result := Database.LastInsertId; … … 253 277 end; 254 278 279 function TChronisBase.AddPropertyNumber(ObjectId: Integer; Name, 280 ColumnName: string; Default: Integer = 0; Min: Integer = 0; 281 Max: Integer = High(Integer)): Integer; 282 var 283 DbRows: TDbRows; 284 Data: TDictionaryStringString; 285 CustomTypeId: Integer; 286 begin 287 try 288 DbRows := TDbRows.Create; 289 Data := TDictionaryStringString.Create; 290 291 Data.Clear; 292 Data.Add('Type', IntToStr(Integer(vtInteger))); 293 Database.Insert(CustomType, Data); 294 CustomTypeId := Database.LastInsertId; 295 296 Data.Clear; 297 Data.Add('CustomType', IntToStr(CustomTypeId)); 298 Data.Add('Min', IntToStr(Min)); 299 Data.Add('Max', IntToStr(Max)); 300 Data.Add('Default', IntToStr(Default)); 301 Database.Insert(TypeNumber, Data); 302 CustomTypeId := Database.LastInsertId; 303 304 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId); 305 finally 306 Data.Free; 307 DbRows.Free; 308 end; 309 end; 310 311 function TChronisBase.AddPropertyString(ObjectId: Integer; Name, 312 ColumnName: string; Default: string = ''; MaxLength: Integer = 255): Integer; 313 var 314 DbRows: TDbRows; 315 Data: TDictionaryStringString; 316 CustomTypeId: Integer; 317 begin 318 try 319 DbRows := TDbRows.Create; 320 Data := TDictionaryStringString.Create; 321 322 Data.Clear; 323 Data.Add('Type', IntToStr(Integer(vtString))); 324 Database.Insert(CustomType, Data); 325 CustomTypeId := Database.LastInsertId; 326 327 Data.Clear; 328 Data.Add('CustomType', IntToStr(CustomTypeId)); 329 Data.Add('MaxLength', IntToStr(MaxLength)); 330 Data.Add('Default', Default); 331 Database.Insert(TypeString, Data); 332 CustomTypeId := Database.LastInsertId; 333 334 Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId); 335 finally 336 Data.Free; 337 DbRows.Free; 338 end; 339 end; 340 255 341 function TChronisBase.AddObjectGroup(Name: string): Integer; 256 342 var … … 263 349 Data.Add('Name', Name); 264 350 Database.Insert(ObjectGroupTable, Data); 351 Result := Database.LastInsertId; 352 finally 353 Data.Free; 354 DbRows.Free; 355 end; 356 end; 357 358 function TChronisBase.AddEnumeration(Name: string): Integer; 359 var 360 DbRows: TDbRows; 361 Data: TDictionaryStringString; 362 begin 363 try 364 DbRows := TDbRows.Create; 365 Data := TDictionaryStringString.Create; 366 Data.Add('Name', Name); 367 Database.Insert(Enumeration, Data); 368 Result := Database.LastInsertId; 369 finally 370 Data.Free; 371 DbRows.Free; 372 end; 373 end; 374 375 function TChronisBase.AddEnumerationState(Enum: Integer; Name: string 376 ): Integer; 377 var 378 DbRows: TDbRows; 379 Data: TDictionaryStringString; 380 begin 381 try 382 DbRows := TDbRows.Create; 383 Data := TDictionaryStringString.Create; 384 Data.Add('Enumeration', IntToStr(Enum)); 385 Data.Add('Name', Name); 386 Database.Insert(EnumerationState, Data); 265 387 Result := Database.LastInsertId; 266 388 finally
Note:
See TracChangeset
for help on using the changeset viewer.