| 1 | unit USystem;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, SpecializedList, SpecializedDictionary, USqlDatabase,
|
|---|
| 9 | Strings, UDataTypes, Dialogs, ComCtrls, StdCtrls, Controls, UPDClient,
|
|---|
| 10 | UChronisModule;
|
|---|
| 11 |
|
|---|
| 12 | const
|
|---|
| 13 | SystemModuleObject = 'SystemModule';
|
|---|
| 14 | SystemMenuTable = 'SystemMenu';
|
|---|
| 15 | SystemActionTable = 'SystemAction';
|
|---|
| 16 | SystemObjectTable = 'Object';
|
|---|
| 17 | InformationTable = 'Information';
|
|---|
| 18 | PropertyTable = 'Property';
|
|---|
| 19 | PropertyTypeTable = 'Type';
|
|---|
| 20 | PropertyGroupTable = 'PropertyGroup';
|
|---|
| 21 | ModuleTable = 'Module';
|
|---|
| 22 | TypeEnumeration = 'TypeEnumeration';
|
|---|
| 23 | TypeFile = 'TypeFile';
|
|---|
| 24 | TypeGPS = 'TypeGPS';
|
|---|
| 25 | TypeRelationOne = 'TypeRelationOne';
|
|---|
| 26 | TypeRelationMany = 'TypeRelationMany';
|
|---|
| 27 | CustomTypeTableName = 'TypeCustom';
|
|---|
| 28 | Enumeration = 'Enumeration';
|
|---|
| 29 | EnumerationState = 'EnumerationState';
|
|---|
| 30 | TypeNumber = 'TypeNumber';
|
|---|
| 31 | TypeString = 'TypeString';
|
|---|
| 32 | TypeFloat = 'TypeFloat';
|
|---|
| 33 | TypeDateTime = 'TypeDateTime';
|
|---|
| 34 |
|
|---|
| 35 | type
|
|---|
| 36 | TDbValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage,
|
|---|
| 37 | vtBoolean, vtIPv4, vtIPv6, vtMAC, vtFile, vtGPS, vtCurrency, vtEnumeration,
|
|---|
| 38 | vtTime, vtDate, vtColor, vtHyperlink, vtRelationOne, vtRelationMany, vtPassword);
|
|---|
| 39 |
|
|---|
| 40 | TChronisObject = class;
|
|---|
| 41 | TChronisBase = class;
|
|---|
| 42 |
|
|---|
| 43 | TReportLine = class
|
|---|
| 44 | Id: Integer;
|
|---|
| 45 | Items: TListString;
|
|---|
| 46 | constructor Create;
|
|---|
| 47 | destructor Destroy; override;
|
|---|
| 48 | end;
|
|---|
| 49 |
|
|---|
| 50 | { TReportColumn }
|
|---|
| 51 |
|
|---|
| 52 | TReportColumn = class
|
|---|
| 53 | Caption: string;
|
|---|
| 54 | //TypeDef: TChronisType;
|
|---|
| 55 | CustomType: TDataType;
|
|---|
| 56 | ColumnName: string;
|
|---|
| 57 | VirtualItem: Boolean;
|
|---|
| 58 | Control: TWinControl;
|
|---|
| 59 | destructor Destroy; override;
|
|---|
| 60 | end;
|
|---|
| 61 |
|
|---|
| 62 | { TReport }
|
|---|
| 63 |
|
|---|
| 64 | TReport = class(TListObject)
|
|---|
| 65 | Base: TChronisBase;
|
|---|
| 66 | Columns: TListObject; // TListObject<TReportColumn>
|
|---|
| 67 | constructor Create; override;
|
|---|
| 68 | destructor Destroy; override;
|
|---|
| 69 | procedure FillListColumns(AColumns: TListColumns);
|
|---|
| 70 | procedure Load(Obj: TChronisObject; Filter: string = '');
|
|---|
| 71 | end;
|
|---|
| 72 |
|
|---|
| 73 | TPropertyList = class
|
|---|
| 74 |
|
|---|
| 75 | end;
|
|---|
| 76 |
|
|---|
| 77 | { TObjectProxy }
|
|---|
| 78 |
|
|---|
| 79 | TChronisObject = class
|
|---|
| 80 | Id: Integer;
|
|---|
| 81 | Name: string;
|
|---|
| 82 | Schema: string;
|
|---|
| 83 | Table: string;
|
|---|
| 84 | PrimaryKey: string;
|
|---|
| 85 | GroupId: Integer;
|
|---|
| 86 | Base: TChronisBase;
|
|---|
| 87 | procedure Load(ObjectId: Integer);
|
|---|
| 88 | procedure Assign(Source: TChronisObject);
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | { TChronisModuleList }
|
|---|
| 92 |
|
|---|
| 93 | TChronisModuleList = class(TListObject) // TListObject<TChronisModule>
|
|---|
| 94 | Base: TChronisBase;
|
|---|
| 95 | procedure RegisterModule(ModuleClass: TChronisModuleClass);
|
|---|
| 96 | procedure UpdateList;
|
|---|
| 97 | function IsInstalled: Boolean;
|
|---|
| 98 | procedure Install;
|
|---|
| 99 | procedure Uninstall;
|
|---|
| 100 | end;
|
|---|
| 101 |
|
|---|
| 102 | { TChronisBase }
|
|---|
| 103 |
|
|---|
| 104 | TChronisBase = class
|
|---|
| 105 | private
|
|---|
| 106 | FActive: Boolean;
|
|---|
| 107 | procedure SetActive(AValue: Boolean);
|
|---|
| 108 | public
|
|---|
| 109 | Types: TPDTypeList;
|
|---|
| 110 | Client: TPDClient;
|
|---|
| 111 | Modules: TChronisModuleList;
|
|---|
| 112 | ModuleSystem: TChronisModule;
|
|---|
| 113 | function AddType(Name, DataType: string; TypeIndex: TDbValueType): Integer;
|
|---|
| 114 | function AddMenu(Name: string; ParentId: Integer = 0; ActionId: Integer = 0): Integer;
|
|---|
| 115 | function AddAction(Name: string; TargetType: string; TargetId: Integer): Integer;
|
|---|
| 116 | function AddObject(Name, TableName, Schema: string): Integer;
|
|---|
| 117 | function AddProperty(ObjectId: Integer; Name, ColumnName: string;
|
|---|
| 118 | CustomType: Integer; Editable: Boolean): Integer;
|
|---|
| 119 | function AddPropertyNumber(ObjectId: Integer; Name,
|
|---|
| 120 | ColumnName: string; Editable: Boolean; Default: Integer = 0; Min: Integer = Low(Integer);
|
|---|
| 121 | Max: Integer = High(Integer)): Integer;
|
|---|
| 122 | function AddPropertyFloat(ObjectId: Integer; Name,
|
|---|
| 123 | ColumnName: string; Editable: Boolean; Default: Double = 0; Min: Double = 0;
|
|---|
| 124 | Max: Double = 0): Integer;
|
|---|
| 125 | function AddPropertyDateTime(ObjectId: Integer; Name,
|
|---|
| 126 | ColumnName: string; Editable: Boolean; Default: TDateTime = 0; Min: TDateTime = 0;
|
|---|
| 127 | Max: TDateTime = 0): Integer;
|
|---|
| 128 | function AddPropertyString(ObjectId: Integer; Name, ColumnName: string;
|
|---|
| 129 | Editable: Boolean; Default: string = ''; MaxLength: Integer = 255): Integer;
|
|---|
| 130 | function AddPropertyBoolean(ObjectId: Integer; Name, ColumnName: string;
|
|---|
| 131 | Editable: Boolean; Default: Boolean = False): Integer;
|
|---|
| 132 | function AddPropertyText(ObjectId: Integer; Name, ColumnName: string;
|
|---|
| 133 | Editable: Boolean; Default: string = ''): Integer;
|
|---|
| 134 | function AddPropertyRelationOne(ObjectId: Integer; Name, ColumnName: string;
|
|---|
| 135 | Editable: Boolean; ReferedObject: Integer): Integer;
|
|---|
| 136 | function AddPropertyRelationMany(ObjectId: Integer; Name, ColumnName: string;
|
|---|
| 137 | Editable: Boolean; ReferedObjectProperty: Integer): Integer;
|
|---|
| 138 | function AddEnumeration(Name: string): Integer;
|
|---|
| 139 | function AddEnumerationState(Enum: Integer; Name: string): Integer;
|
|---|
| 140 | procedure LoadTypes;
|
|---|
| 141 | constructor Create;
|
|---|
| 142 | destructor Destroy; override;
|
|---|
| 143 | property Active: Boolean read FActive write SetActive;
|
|---|
| 144 | private
|
|---|
| 145 | end;
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 | implementation
|
|---|
| 150 |
|
|---|
| 151 | uses
|
|---|
| 152 | UCore;
|
|---|
| 153 |
|
|---|
| 154 | resourcestring
|
|---|
| 155 | SUnsupportedType = 'Unsupported property type "%s"';
|
|---|
| 156 |
|
|---|
| 157 | { TReportColumn }
|
|---|
| 158 |
|
|---|
| 159 | destructor TReportColumn.Destroy;
|
|---|
| 160 | begin
|
|---|
| 161 | CustomType.Free;
|
|---|
| 162 | inherited Destroy;
|
|---|
| 163 | end;
|
|---|
| 164 |
|
|---|
| 165 | { TReportLine }
|
|---|
| 166 |
|
|---|
| 167 | constructor TReportLine.Create;
|
|---|
| 168 | begin
|
|---|
| 169 | Items := TListString.Create;
|
|---|
| 170 | end;
|
|---|
| 171 |
|
|---|
| 172 | destructor TReportLine.Destroy;
|
|---|
| 173 | begin
|
|---|
| 174 | Items.Free;
|
|---|
| 175 | inherited Destroy;
|
|---|
| 176 | end;
|
|---|
| 177 |
|
|---|
| 178 | procedure TReport.Load(Obj: TChronisObject; Filter: string = '');
|
|---|
| 179 | var
|
|---|
| 180 | Properties: TListProxy;
|
|---|
| 181 | Values: TListProxy;
|
|---|
| 182 | I: Integer;
|
|---|
| 183 | C: Integer;
|
|---|
| 184 | NewItem: TReportLine;
|
|---|
| 185 | NewColumn: TReportColumn;
|
|---|
| 186 | ColumnsQuery: string;
|
|---|
| 187 | DataType: TDataType;
|
|---|
| 188 | ProxyObj: TObjectProxy;
|
|---|
| 189 | begin
|
|---|
| 190 | Clear;
|
|---|
| 191 |
|
|---|
| 192 | // Load column names
|
|---|
| 193 | try
|
|---|
| 194 | Properties := TListProxy.Create;
|
|---|
| 195 | Properties.Client := Base.Client;
|
|---|
| 196 | Properties.ObjectName := PropertyTable;
|
|---|
| 197 | Properties.Path := Base.Client.Schema;
|
|---|
| 198 | Properties.Condition := 'Object="' + IntToStr(Obj.Id) + '"';
|
|---|
| 199 | Properties.Load;
|
|---|
| 200 | Columns.Clear;
|
|---|
| 201 |
|
|---|
| 202 | for I := 0 to Properties.Objects.Count - 1 do begin
|
|---|
| 203 | ProxyObj := TObjectProxy(Properties.Objects[I]);
|
|---|
| 204 | DataType := GetDataType(StrToInt(ProxyObj.Properties.Values['CustomType']));
|
|---|
| 205 | NewColumn := TReportColumn.Create;
|
|---|
| 206 | Columns.Add(NewColumn);
|
|---|
| 207 | NewColumn.Caption := ProxyObj.Properties.Values['Name'];
|
|---|
| 208 | NewColumn.ColumnName := ProxyObj.Properties.Values['ColumnName'];
|
|---|
| 209 | NewColumn.CustomType := DataType;
|
|---|
| 210 | if (DataType is TDataTypeRelationMany) then NewColumn.VirtualItem := True;
|
|---|
| 211 | end;
|
|---|
| 212 |
|
|---|
| 213 | // Load items
|
|---|
| 214 | Values := TListProxy.Create;
|
|---|
| 215 | Values.Client := Base.Client;
|
|---|
| 216 | for I := 0 to Columns.Count - 1 do
|
|---|
| 217 | if not TReportColumn(Columns[I]).VirtualItem then
|
|---|
| 218 | Values.ColumnsFilter.Add(TReportColumn(Columns[I]).ColumnName);
|
|---|
| 219 | Values.ColumnsFilter.Add(Obj.PrimaryKey);
|
|---|
| 220 | Values.ColummsFilterUse := True;
|
|---|
| 221 | Values.ObjectName := Obj.Table;
|
|---|
| 222 | Values.Path := Obj.Schema;
|
|---|
| 223 | Values.Condition := Filter;
|
|---|
| 224 | Values.Load;
|
|---|
| 225 |
|
|---|
| 226 | //Base.Database.Query(Values, 'SELECT ' + ColumnsQuery + ', `' + Obj.PrimaryKey + '` AS `SYS_PRIMARY_KEY` FROM `' + Obj.Schema + '`.`' +
|
|---|
| 227 | // Obj.Table + '`' + Filter);
|
|---|
| 228 | for I := 0 to Values.Objects.Count - 1 do begin
|
|---|
| 229 | ProxyObj := TObjectProxy(Values.Objects[I]);
|
|---|
| 230 | NewItem := TReportLine.Create;
|
|---|
| 231 | //NewItem.Items.Add(Values[I].Values[Obj.PrimaryKey]);
|
|---|
| 232 | NewItem.Id := StrToInt(ProxyObj.Properties.Values[Obj.PrimaryKey]);
|
|---|
| 233 | for C := 0 to Columns.Count - 1 do
|
|---|
| 234 | if not TReportColumn(Columns[C]).VirtualItem then begin
|
|---|
| 235 | NewItem.Items.Add(ProxyObj.Properties.Values[TReportColumn(Columns[C]).ColumnName]);
|
|---|
| 236 | end else NewItem.Items.Add('');
|
|---|
| 237 | Add(NewItem);
|
|---|
| 238 | end;
|
|---|
| 239 | finally
|
|---|
| 240 | Properties.Free;
|
|---|
| 241 | Values.Free;
|
|---|
| 242 | end;
|
|---|
| 243 | end;
|
|---|
| 244 |
|
|---|
| 245 | procedure TChronisBase.SetActive(AValue: Boolean);
|
|---|
| 246 | begin
|
|---|
| 247 | if FActive = AValue then Exit;
|
|---|
| 248 | FActive := AValue;
|
|---|
| 249 | if AValue then begin
|
|---|
| 250 | Client.Connect;
|
|---|
| 251 | if Client.Connected then begin
|
|---|
| 252 | if not Modules.IsInstalled then begin
|
|---|
| 253 | Modules.Install;
|
|---|
| 254 | Modules.UpdateList;
|
|---|
| 255 | end;
|
|---|
| 256 | Modules.UpdateList;
|
|---|
| 257 | if not ModuleSystem.IsInstalled then ModuleSystem.Install;
|
|---|
| 258 | LoadTypes;
|
|---|
| 259 | end else FActive := False;
|
|---|
| 260 | end else begin
|
|---|
| 261 | Client.Disconnect;
|
|---|
| 262 | FreeAndNil(Client);
|
|---|
| 263 | Types.Clear;
|
|---|
| 264 | end;
|
|---|
| 265 | end;
|
|---|
| 266 |
|
|---|
| 267 | procedure TChronisModuleList.RegisterModule(ModuleClass: TChronisModuleClass);
|
|---|
| 268 | begin
|
|---|
| 269 | AddNew(ModuleClass.Create);
|
|---|
| 270 | TChronisModule(Last).System := TChronisBase(Base);
|
|---|
| 271 | end;
|
|---|
| 272 |
|
|---|
| 273 | function TChronisBase.AddType(Name, DataType: string; TypeIndex: TDbValueType): Integer;
|
|---|
| 274 | begin
|
|---|
| 275 | with TObjectProxy.Create do
|
|---|
| 276 | try
|
|---|
| 277 | Client := Self.Client;
|
|---|
| 278 | ObjectName := PropertyTypeTable;
|
|---|
| 279 | Id := Integer(TypeIndex);
|
|---|
| 280 | with Properties do begin
|
|---|
| 281 | Add('Name', Name);
|
|---|
| 282 | Add('DbType', DataType);
|
|---|
| 283 | end;
|
|---|
| 284 | Save;
|
|---|
| 285 | Result := Id;
|
|---|
| 286 | finally
|
|---|
| 287 | Free;
|
|---|
| 288 | end;
|
|---|
| 289 | end;
|
|---|
| 290 |
|
|---|
| 291 | function TChronisBase.AddMenu(Name: string; ParentId: Integer = 0; ActionId: Integer = 0): Integer;
|
|---|
| 292 | begin
|
|---|
| 293 | with TObjectProxy.Create do
|
|---|
| 294 | try
|
|---|
| 295 | Client := Self.Client;
|
|---|
| 296 | ObjectName := SystemMenuTable;
|
|---|
| 297 | with Properties do begin
|
|---|
| 298 | Add('Name', Name);
|
|---|
| 299 | Add('Parent', IntToStr(ParentId));
|
|---|
| 300 | Add('Action', IntToStr(ActionId));
|
|---|
| 301 | end;
|
|---|
| 302 | Save;
|
|---|
| 303 | Result := Id;
|
|---|
| 304 | finally
|
|---|
| 305 | Free;
|
|---|
| 306 | end;
|
|---|
| 307 | end;
|
|---|
| 308 |
|
|---|
| 309 | function TChronisBase.AddAction(Name: string; TargetType: string;
|
|---|
| 310 | TargetId: Integer): Integer;
|
|---|
| 311 | begin
|
|---|
| 312 |
|
|---|
| 313 | end;
|
|---|
| 314 |
|
|---|
| 315 | function TChronisBase.AddObject(Name, TableName, Schema: string): Integer;
|
|---|
| 316 | var
|
|---|
| 317 | Proxy: TObjectProxy;
|
|---|
| 318 | begin
|
|---|
| 319 | try
|
|---|
| 320 | Proxy := TObjectProxy.Create;
|
|---|
| 321 | Proxy.Client := Client;
|
|---|
| 322 | Proxy.ObjectName := SystemObjectTable;
|
|---|
| 323 | with Proxy.Properties do begin
|
|---|
| 324 | Add('Name', Name);
|
|---|
| 325 | Add('Schema', Schema);
|
|---|
| 326 | Add('Table', TableName);
|
|---|
| 327 | Add('PrimaryKey', 'Id');
|
|---|
| 328 | end;
|
|---|
| 329 | Proxy.Save;
|
|---|
| 330 | Result := Proxy.Id;
|
|---|
| 331 | finally
|
|---|
| 332 | Proxy.Free;
|
|---|
| 333 | end;
|
|---|
| 334 | end;
|
|---|
| 335 |
|
|---|
| 336 | function TChronisBase.AddProperty(ObjectId: Integer; Name, ColumnName: string;
|
|---|
| 337 | CustomType: Integer; Editable: Boolean): Integer;
|
|---|
| 338 | var
|
|---|
| 339 | Proxy: TObjectProxy;
|
|---|
| 340 | begin
|
|---|
| 341 | try
|
|---|
| 342 | Proxy := TObjectProxy.Create;
|
|---|
| 343 | Proxy.Client := Client;
|
|---|
| 344 | Proxy.ObjectName := PropertyTable;
|
|---|
| 345 | Proxy.Properties.Add('Name', Name);
|
|---|
| 346 | Proxy.Properties.Add('Object', IntToStr(ObjectId));
|
|---|
| 347 | Proxy.Properties.Add('ColumnName', ColumnName);
|
|---|
| 348 | Proxy.Properties.Add('CustomType', IntToStr(CustomType));
|
|---|
| 349 | Proxy.Properties.Add('Editable', IntToStr(Integer(Editable)));
|
|---|
| 350 | Proxy.Save;
|
|---|
| 351 | Result := Proxy.Id;
|
|---|
| 352 | finally
|
|---|
| 353 | Proxy.Free;
|
|---|
| 354 | end;
|
|---|
| 355 | end;
|
|---|
| 356 |
|
|---|
| 357 | function TChronisBase.AddPropertyNumber(ObjectId: Integer; Name,
|
|---|
| 358 | ColumnName: string; Editable: Boolean; Default: Integer = 0; Min: Integer = Low(Integer);
|
|---|
| 359 | Max: Integer = High(Integer)): Integer;
|
|---|
| 360 | var
|
|---|
| 361 | Proxy: TObjectProxy;
|
|---|
| 362 | CustomTypeId: Integer;
|
|---|
| 363 | begin
|
|---|
| 364 | try
|
|---|
| 365 | Proxy := TObjectProxy.Create;
|
|---|
| 366 | Proxy.Client := Client;
|
|---|
| 367 | Proxy.ObjectName := CustomTypeTableName;
|
|---|
| 368 | Proxy.Properties.Add('Type', IntToStr(Integer(vtInteger)));
|
|---|
| 369 | Proxy.Save;
|
|---|
| 370 | CustomTypeId := Proxy.Id;
|
|---|
| 371 |
|
|---|
| 372 | Proxy.Id := 0;
|
|---|
| 373 | Proxy.ObjectName := TypeNumber;
|
|---|
| 374 | Proxy.Properties.Clear;
|
|---|
| 375 | Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId));
|
|---|
| 376 | Proxy.Properties.Add('Min', IntToStr(Min));
|
|---|
| 377 | Proxy.Properties.Add('Max', IntToStr(Max));
|
|---|
| 378 | Proxy.Properties.Add('Default', IntToStr(Default));
|
|---|
| 379 | Proxy.Save;
|
|---|
| 380 | //CustomTypeId := Database.LastInsertId;
|
|---|
| 381 |
|
|---|
| 382 | Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable);
|
|---|
| 383 | Result := Proxy.Id;
|
|---|
| 384 | finally
|
|---|
| 385 | Proxy.Free;
|
|---|
| 386 | end;
|
|---|
| 387 | end;
|
|---|
| 388 |
|
|---|
| 389 | function TChronisBase.AddPropertyFloat(ObjectId: Integer; Name,
|
|---|
| 390 | ColumnName: string; Editable: Boolean; Default: Double; Min: Double; Max: Double): Integer;
|
|---|
| 391 | var
|
|---|
| 392 | Proxy: TObjectProxy;
|
|---|
| 393 | CustomTypeId: Integer;
|
|---|
| 394 | begin
|
|---|
| 395 | try
|
|---|
| 396 | Proxy := TObjectProxy.Create;
|
|---|
| 397 | Proxy.Client := Client;
|
|---|
| 398 | Proxy.ObjectName := CustomTypeTableName;
|
|---|
| 399 | Proxy.Properties.Add('Type', IntToStr(Integer(vtFloat)));
|
|---|
| 400 | Proxy.Save;
|
|---|
| 401 | CustomTypeId := Proxy.Id;
|
|---|
| 402 |
|
|---|
| 403 | Proxy.Id := 0;
|
|---|
| 404 | Proxy.ObjectName := TypeFloat;
|
|---|
| 405 | Proxy.Properties.Clear;
|
|---|
| 406 | Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId));
|
|---|
| 407 | Proxy.Properties.Add('Min', MySQLFloatToStr(Min));
|
|---|
| 408 | Proxy.Properties.Add('Max', MySQLFloatToStr(Max));
|
|---|
| 409 | Proxy.Properties.Add('Default', MySQLFloatToStr(Default));
|
|---|
| 410 | Proxy.Save;
|
|---|
| 411 | //CustomTypeId := Database.LastInsertId;
|
|---|
| 412 |
|
|---|
| 413 | Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable);
|
|---|
| 414 | finally
|
|---|
| 415 | Proxy.Free;
|
|---|
| 416 | end;
|
|---|
| 417 | end;
|
|---|
| 418 |
|
|---|
| 419 | function TChronisBase.AddPropertyDateTime(ObjectId: Integer; Name,
|
|---|
| 420 | ColumnName: string; Editable: Boolean; Default: TDateTime; Min: TDateTime; Max: TDateTime
|
|---|
| 421 | ): Integer;
|
|---|
| 422 | var
|
|---|
| 423 | Proxy: TObjectProxy;
|
|---|
| 424 | CustomTypeId: Integer;
|
|---|
| 425 | begin
|
|---|
| 426 | try
|
|---|
| 427 | Proxy := TObjectProxy.Create;
|
|---|
| 428 | Proxy.Client := Client;
|
|---|
| 429 | Proxy.ObjectName := CustomTypeTableName;
|
|---|
| 430 | Proxy.Properties.Add('Type', IntToStr(Integer(vtDateTime)));
|
|---|
| 431 | Proxy.Save;
|
|---|
| 432 | CustomTypeId := Proxy.Id;
|
|---|
| 433 |
|
|---|
| 434 | Proxy.Id := 0;
|
|---|
| 435 | Proxy.ObjectName := TypeDateTime;
|
|---|
| 436 | Proxy.Properties.Clear;
|
|---|
| 437 | Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId));
|
|---|
| 438 | Proxy.Properties.Add('Min', DateTimeToSQL(Min));
|
|---|
| 439 | Proxy.Properties.Add('Max', DateTimeToSQL(Max));
|
|---|
| 440 | Proxy.Properties.Add('Default', DateTimeToSQL(Default));
|
|---|
| 441 | Proxy.Save;
|
|---|
| 442 | //CustomTypeId := Database.LastInsertId;
|
|---|
| 443 |
|
|---|
| 444 | Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable);
|
|---|
| 445 | finally
|
|---|
| 446 | Proxy.Free;
|
|---|
| 447 | end;
|
|---|
| 448 | end;
|
|---|
| 449 |
|
|---|
| 450 | function TChronisBase.AddPropertyString(ObjectId: Integer; Name,
|
|---|
| 451 | ColumnName: string; Editable: Boolean; Default: string = ''; MaxLength: Integer = 255): Integer;
|
|---|
| 452 | var
|
|---|
| 453 | Proxy: TObjectProxy;
|
|---|
| 454 | CustomTypeId: Integer;
|
|---|
| 455 | begin
|
|---|
| 456 | try
|
|---|
| 457 | Proxy := TObjectProxy.Create;
|
|---|
| 458 | Proxy.Client := Client;
|
|---|
| 459 | Proxy.ObjectName := CustomTypeTableName;
|
|---|
| 460 | Proxy.Properties.Add('Type', IntToStr(Integer(vtString)));
|
|---|
| 461 | Proxy.Save;
|
|---|
| 462 | CustomTypeId := Proxy.Id;
|
|---|
| 463 |
|
|---|
| 464 | Proxy.Id := 0;
|
|---|
| 465 | Proxy.ObjectName := TypeString;
|
|---|
| 466 | Proxy.Properties.Clear;
|
|---|
| 467 | Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId));
|
|---|
| 468 | Proxy.Properties.Add('MaxLength', IntToStr(MaxLength));
|
|---|
| 469 | Proxy.Properties.Add('Default', Default);
|
|---|
| 470 | Proxy.Save;
|
|---|
| 471 | //CustomTypeId := Database.LastInsertId;
|
|---|
| 472 |
|
|---|
| 473 | Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable);
|
|---|
| 474 | finally
|
|---|
| 475 | Proxy.Free;
|
|---|
| 476 | end;
|
|---|
| 477 | end;
|
|---|
| 478 |
|
|---|
| 479 | function TChronisBase.AddPropertyBoolean(ObjectId: Integer; Name,
|
|---|
| 480 | ColumnName: string; Editable: Boolean; Default: Boolean): Integer;
|
|---|
| 481 | begin
|
|---|
| 482 |
|
|---|
| 483 | end;
|
|---|
| 484 |
|
|---|
| 485 | function TChronisBase.AddPropertyText(ObjectId: Integer; Name,
|
|---|
| 486 | ColumnName: string; Editable: Boolean; Default: string): Integer;
|
|---|
| 487 | var
|
|---|
| 488 | Proxy: TObjectProxy;
|
|---|
| 489 | CustomTypeId: Integer;
|
|---|
| 490 | begin
|
|---|
| 491 | try
|
|---|
| 492 | Proxy := TObjectProxy.Create;
|
|---|
| 493 | Proxy.Client := Client;
|
|---|
| 494 | Proxy.ObjectName := CustomTypeTableName;
|
|---|
| 495 | Proxy.Properties.Add('Type', IntToStr(Integer(vtText)));
|
|---|
| 496 | Proxy.Save;
|
|---|
| 497 | CustomTypeId := Proxy.Id;
|
|---|
| 498 |
|
|---|
| 499 | Proxy.Id := 0;
|
|---|
| 500 | Proxy.ObjectName := TypeString;
|
|---|
| 501 | Proxy.Properties.Clear;
|
|---|
| 502 | Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId));
|
|---|
| 503 | Proxy.Properties.Add('Default', Default);
|
|---|
| 504 | Proxy.Save;
|
|---|
| 505 | //CustomTypeId := Database.LastInsertId;
|
|---|
| 506 |
|
|---|
| 507 | Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable);
|
|---|
| 508 | finally
|
|---|
| 509 | Proxy.Free;
|
|---|
| 510 | end;
|
|---|
| 511 | end;
|
|---|
| 512 |
|
|---|
| 513 | function TChronisBase.AddPropertyRelationOne(ObjectId: Integer; Name,
|
|---|
| 514 | ColumnName: string; Editable: Boolean; ReferedObject: Integer): Integer;
|
|---|
| 515 | var
|
|---|
| 516 | Proxy: TObjectProxy;
|
|---|
| 517 | CustomTypeId: Integer;
|
|---|
| 518 | begin
|
|---|
| 519 | try
|
|---|
| 520 | Proxy := TObjectProxy.Create;
|
|---|
| 521 | Proxy.Client := Client;
|
|---|
| 522 | Proxy.ObjectName := CustomTypeTableName;
|
|---|
| 523 | Proxy.Properties.Add('Type', IntToStr(Integer(vtRelationOne)));
|
|---|
| 524 | Proxy.Save;
|
|---|
| 525 | CustomTypeId := Proxy.Id;
|
|---|
| 526 |
|
|---|
| 527 | Proxy.Id := 0;
|
|---|
| 528 | Proxy.ObjectName := TypeRelationOne;
|
|---|
| 529 | Proxy.Properties.Clear;
|
|---|
| 530 | Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId));
|
|---|
| 531 | Proxy.Properties.Add('Object', IntToStr(ReferedObject));
|
|---|
| 532 | Proxy.Save;
|
|---|
| 533 | //CustomTypeId := Database.LastInsertId;
|
|---|
| 534 |
|
|---|
| 535 | Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable);
|
|---|
| 536 | finally
|
|---|
| 537 | Proxy.Free;
|
|---|
| 538 | end;
|
|---|
| 539 | end;
|
|---|
| 540 |
|
|---|
| 541 | function TChronisBase.AddPropertyRelationMany(ObjectId: Integer; Name,
|
|---|
| 542 | ColumnName: string; Editable: Boolean; ReferedObjectProperty: Integer): Integer;
|
|---|
| 543 | var
|
|---|
| 544 | Proxy: TObjectProxy;
|
|---|
| 545 | CustomTypeId: Integer;
|
|---|
| 546 | begin
|
|---|
| 547 | try
|
|---|
| 548 | Proxy := TObjectProxy.Create;
|
|---|
| 549 | Proxy.Client := Client;
|
|---|
| 550 | Proxy.ObjectName := CustomTypeTableName;
|
|---|
| 551 | Proxy.Properties.Clear;
|
|---|
| 552 | Proxy.Properties.Add('Type', IntToStr(Integer(vtRelationMany)));
|
|---|
| 553 | Proxy.Save;
|
|---|
| 554 | CustomTypeId := Proxy.Id;
|
|---|
| 555 |
|
|---|
| 556 | Proxy.Id := 0;
|
|---|
| 557 | Proxy.ObjectName := TypeRelationMany;
|
|---|
| 558 | Proxy.Properties.Clear;
|
|---|
| 559 | Proxy.Properties.Add('CustomType', IntToStr(CustomTypeId));
|
|---|
| 560 | Proxy.Properties.Add('ObjectProperty', IntToStr(ReferedObjectProperty));
|
|---|
| 561 | Proxy.Save;
|
|---|
| 562 | //CustomTypeId := Database.LastInsertId;
|
|---|
| 563 |
|
|---|
| 564 | Result := AddProperty(ObjectId, Name, ColumnName, CustomTypeId, Editable);
|
|---|
| 565 | finally
|
|---|
| 566 | Proxy.Free;
|
|---|
| 567 | end;
|
|---|
| 568 | end;
|
|---|
| 569 |
|
|---|
| 570 | function TChronisBase.AddEnumeration(Name: string): Integer;
|
|---|
| 571 | var
|
|---|
| 572 | Proxy: TObjectProxy;
|
|---|
| 573 | begin
|
|---|
| 574 | try
|
|---|
| 575 | Proxy := TObjectProxy.Create;
|
|---|
| 576 | Proxy.Client := Client;
|
|---|
| 577 | Proxy.ObjectName := Enumeration;
|
|---|
| 578 | Proxy.Properties.Add('Name', Name);
|
|---|
| 579 | Proxy.Save;
|
|---|
| 580 | Result := Proxy.Id;
|
|---|
| 581 | finally
|
|---|
| 582 | Proxy.Free;
|
|---|
| 583 | end;
|
|---|
| 584 | end;
|
|---|
| 585 |
|
|---|
| 586 | function TChronisBase.AddEnumerationState(Enum: Integer; Name: string
|
|---|
| 587 | ): Integer;
|
|---|
| 588 | var
|
|---|
| 589 | Proxy: TObjectProxy;
|
|---|
| 590 | begin
|
|---|
| 591 | try
|
|---|
| 592 | Proxy := TObjectProxy.Create;
|
|---|
| 593 | Proxy.Client := Client;
|
|---|
| 594 | Proxy.ObjectName := EnumerationState;
|
|---|
| 595 | Proxy.Properties.Add('Enumeration', IntToStr(Enum));
|
|---|
| 596 | Proxy.Properties.Add('Name', Name);
|
|---|
| 597 | Proxy.Properties.Add('Sequence', '0');
|
|---|
| 598 | Proxy.Save;
|
|---|
| 599 | Result := Proxy.Id;
|
|---|
| 600 | finally
|
|---|
| 601 | Proxy.Free;
|
|---|
| 602 | end;
|
|---|
| 603 | end;
|
|---|
| 604 |
|
|---|
| 605 | procedure TChronisBase.LoadTypes;
|
|---|
| 606 | var
|
|---|
| 607 | Proxy: TListProxy;
|
|---|
| 608 | I: Integer;
|
|---|
| 609 | begin
|
|---|
| 610 | try
|
|---|
| 611 | Proxy := TListProxy.Create;
|
|---|
| 612 | Proxy.Client := Client;
|
|---|
| 613 | Proxy.ObjectName := PropertyTypeTable;
|
|---|
| 614 | Proxy.Load;
|
|---|
| 615 | Types.Clear;
|
|---|
| 616 | for I := 0 to Proxy.Objects.Count - 1 do begin
|
|---|
| 617 | with TPDType(Types.AddNew(TPDType.Create)) do
|
|---|
| 618 | with TObjectProxy(Proxy.Objects[I]) do begin
|
|---|
| 619 | Id := StrToInt(Properties.Values['Id']);
|
|---|
| 620 | DbType := Properties.Values['DbType'];
|
|---|
| 621 | //Parent := StrToInt(Properties.Values['Parent']);
|
|---|
| 622 | end;
|
|---|
| 623 | end;
|
|---|
| 624 | finally
|
|---|
| 625 | Proxy.Free;
|
|---|
| 626 | end;
|
|---|
| 627 | end;
|
|---|
| 628 |
|
|---|
| 629 | constructor TChronisBase.Create;
|
|---|
| 630 | begin
|
|---|
| 631 | Types := TPDTypeList.Create;
|
|---|
| 632 | Modules := TChronisModuleList.Create;
|
|---|
| 633 | Modules.Base := Self;
|
|---|
| 634 | end;
|
|---|
| 635 |
|
|---|
| 636 | destructor TChronisBase.Destroy;
|
|---|
| 637 | begin
|
|---|
| 638 | FreeAndNil(Types);
|
|---|
| 639 | FreeAndNil(Modules);
|
|---|
| 640 | inherited Destroy;
|
|---|
| 641 | end;
|
|---|
| 642 |
|
|---|
| 643 | { TReport }
|
|---|
| 644 |
|
|---|
| 645 | constructor TReport.Create;
|
|---|
| 646 | begin
|
|---|
| 647 | inherited;
|
|---|
| 648 | Columns := TListObject.Create;
|
|---|
| 649 | end;
|
|---|
| 650 |
|
|---|
| 651 | destructor TReport.Destroy;
|
|---|
| 652 | begin
|
|---|
| 653 | Columns.Free;
|
|---|
| 654 | inherited Destroy;
|
|---|
| 655 | end;
|
|---|
| 656 |
|
|---|
| 657 | procedure TReport.FillListColumns(AColumns: TListColumns);
|
|---|
| 658 | var
|
|---|
| 659 | I: Integer;
|
|---|
| 660 | NewColumn: TListColumn;
|
|---|
| 661 | begin
|
|---|
| 662 | while (AColumns.Count < Columns.Count) do
|
|---|
| 663 | AColumns.Add;
|
|---|
| 664 | while (AColumns.Count > Columns.Count) do
|
|---|
| 665 | AColumns.Delete(AColumns.Count - 1);
|
|---|
| 666 | for I := 0 to Columns.Count - 1 do
|
|---|
| 667 | if not TReportColumn(Columns[I]).VirtualItem then begin
|
|---|
| 668 | AColumns[I].Caption := TReportColumn(Columns[I]).Caption;
|
|---|
| 669 | end;
|
|---|
| 670 | end;
|
|---|
| 671 |
|
|---|
| 672 | { TChronisObject }
|
|---|
| 673 |
|
|---|
| 674 | procedure TChronisObject.Load(ObjectId: Integer);
|
|---|
| 675 | var
|
|---|
| 676 | List: TListProxy;
|
|---|
| 677 | begin
|
|---|
| 678 | try
|
|---|
| 679 | List := TListProxy.Create;
|
|---|
| 680 | List.Client := Core.System.Client;
|
|---|
| 681 | List.ObjectName := SystemObjectTable;
|
|---|
| 682 | List.Path := Core.System.Client.Schema;
|
|---|
| 683 | List.Condition := 'Id=' + IntToStr(ObjectId);
|
|---|
| 684 | List.Load;
|
|---|
| 685 | if List.Objects.Count = 1 then begin
|
|---|
| 686 | Id := ObjectId;
|
|---|
| 687 | with TObjectProxy(List.Objects[0]) do begin
|
|---|
| 688 | Name := Properties.Values['Name'];
|
|---|
| 689 | Schema := Properties.Values['Schema'];
|
|---|
| 690 | GroupId := StrToInt(Properties.Values['Group']);
|
|---|
| 691 | Table := Properties.Values['Table'];
|
|---|
| 692 | PrimaryKey := Properties.Values['PrimaryKey'];
|
|---|
| 693 | end;
|
|---|
| 694 | end;
|
|---|
| 695 | finally
|
|---|
| 696 | List.Free;
|
|---|
| 697 | end;
|
|---|
| 698 | end;
|
|---|
| 699 |
|
|---|
| 700 | procedure TChronisObject.Assign(Source: TChronisObject);
|
|---|
| 701 | begin
|
|---|
| 702 | Id := Source.Id;
|
|---|
| 703 | Table := Source.Table;
|
|---|
| 704 | Schema := Source.Schema;
|
|---|
| 705 | Name := Source.Name;
|
|---|
| 706 | Base := Source.Base;
|
|---|
| 707 | GroupId := Source.GroupId;
|
|---|
| 708 | PrimaryKey := Source.PrimaryKey;
|
|---|
| 709 | end;
|
|---|
| 710 |
|
|---|
| 711 | { TChronisModuleList }
|
|---|
| 712 |
|
|---|
| 713 | procedure TChronisModuleList.UpdateList;
|
|---|
| 714 | var
|
|---|
| 715 | I: Integer;
|
|---|
| 716 | NewObject: TObjectProxy;
|
|---|
| 717 | List: TListProxy;
|
|---|
| 718 | begin
|
|---|
| 719 | List := TListProxy.Create;
|
|---|
| 720 | List.Client := Base.Client;
|
|---|
| 721 | List.Path := Base.Client.Schema;
|
|---|
| 722 | List.ObjectName := SystemModuleObject;
|
|---|
| 723 | for I := 0 to Count - 1 do
|
|---|
| 724 | with TChronisModule(Items[I]) do begin
|
|---|
| 725 | List.Condition := 'SysName="' + SysName + '"';
|
|---|
| 726 | List.Load;
|
|---|
| 727 | NewObject := TObjectProxy.Create;
|
|---|
| 728 | NewObject.Client := Base.Client;
|
|---|
| 729 | if List.Objects.Count > 0 then
|
|---|
| 730 | NewObject.Id := StrToInt(TObjectProxy(List.Objects[0]).Properties.Values['Id'])
|
|---|
| 731 | else NewObject.Id := 0;
|
|---|
| 732 | NewObject.Path := Base.Client.Schema;
|
|---|
| 733 | NewObject.ObjectName := SystemModuleObject;
|
|---|
| 734 | with NewObject.Properties do begin
|
|---|
| 735 | Add('SysName', SysName);
|
|---|
| 736 | Add('Name', Name);
|
|---|
| 737 | Add('Version', Version);
|
|---|
| 738 | Add('License', License);
|
|---|
| 739 | Add('Creator', Creator);
|
|---|
| 740 | Add('Website', Website);
|
|---|
| 741 | Add('Description', Description.Text);
|
|---|
| 742 | end;
|
|---|
| 743 | NewObject.Save;
|
|---|
| 744 | NewObject.Free;
|
|---|
| 745 | end;
|
|---|
| 746 | List.Free;
|
|---|
| 747 | end;
|
|---|
| 748 |
|
|---|
| 749 | function TChronisModuleList.IsInstalled: Boolean;
|
|---|
| 750 | var
|
|---|
| 751 | NewType: TPDType;
|
|---|
| 752 | begin
|
|---|
| 753 | with TPDType.Create do
|
|---|
| 754 | try
|
|---|
| 755 | Client := Base.Client;
|
|---|
| 756 | Name := SystemModuleObject;
|
|---|
| 757 | Result := IsDefined;
|
|---|
| 758 | finally
|
|---|
| 759 | Free;
|
|---|
| 760 | end;
|
|---|
| 761 | end;
|
|---|
| 762 |
|
|---|
| 763 | procedure TChronisModuleList.Install;
|
|---|
| 764 | var
|
|---|
| 765 | NewType: TPDType;
|
|---|
| 766 | begin
|
|---|
| 767 | with TPDType.Create do
|
|---|
| 768 | try
|
|---|
| 769 | Client := Base.Client;
|
|---|
| 770 | Name := SystemModuleObject;
|
|---|
| 771 | with Properties do begin
|
|---|
| 772 | AddSimple('SysName', 'String');
|
|---|
| 773 | AddSimple('Name', 'String');
|
|---|
| 774 | AddSimple('Version', 'String');
|
|---|
| 775 | AddSimple('License', 'String');
|
|---|
| 776 | AddSimple('Creator', 'String');
|
|---|
| 777 | AddSimple('Website', 'String');
|
|---|
| 778 | AddSimple('Installed', 'Boolean');
|
|---|
| 779 | AddSimple('Description', 'Text');
|
|---|
| 780 | end;
|
|---|
| 781 | Define;
|
|---|
| 782 | finally
|
|---|
| 783 | Free;
|
|---|
| 784 | end;
|
|---|
| 785 | end;
|
|---|
| 786 |
|
|---|
| 787 | procedure TChronisModuleList.Uninstall;
|
|---|
| 788 | var
|
|---|
| 789 | NewType: TPDType;
|
|---|
| 790 | begin
|
|---|
| 791 | with TPDType.Create do
|
|---|
| 792 | try
|
|---|
| 793 | Client := Base.Client;
|
|---|
| 794 | Name := SystemModuleObject;
|
|---|
| 795 | Undefine;
|
|---|
| 796 | finally
|
|---|
| 797 | Free;
|
|---|
| 798 | end;
|
|---|
| 799 | end;
|
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 | end.
|
|---|
| 803 |
|
|---|