├── .gitattributes ├── .gitignore ├── 9781484250129.jpg ├── Chapter 2 ├── BasicFeatures.dpr ├── BasicFeatures.dproj ├── BasicFeatures.otares ├── ConnectionModule.dfm ├── ConnectionModule.pas ├── Entities.pas └── EntitiesLazy.pas ├── Chapter 3 ├── CallCentre - Skeleton │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ └── Forms │ │ ├── AgentForm.fmx │ │ ├── AgentForm.pas │ │ ├── EntityForm.fmx │ │ ├── EntityForm.pas │ │ ├── MainForm.fmx │ │ └── MainForm.pas ├── CallCentre - With Database Session │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Entities.pas │ └── Forms │ │ ├── AgentForm.fmx │ │ ├── AgentForm.pas │ │ ├── ConnectionModule.dfm │ │ ├── ConnectionModule.pas │ │ ├── EntityForm.fmx │ │ ├── EntityForm.pas │ │ ├── MainForm.fmx │ │ └── MainForm.pas └── CallCentre - Without Database Session │ ├── Builds │ └── Win32 │ │ └── Debug │ │ └── database.db │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Entities.pas │ └── Forms │ ├── AgentForm.fmx │ ├── AgentForm.pas │ ├── ConnectionModule.dfm │ ├── ConnectionModule.pas │ ├── EntityForm.fmx │ ├── EntityForm.pas │ ├── MainForm.fmx │ └── MainForm.pas ├── Chapter 4 ├── CallCentre - Import │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Database.Import.pas │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Database.Utilities.pas │ ├── Entities.pas │ └── Forms │ │ ├── AgentForm.fmx │ │ ├── AgentForm.pas │ │ ├── ConnectionModule.dfm │ │ ├── ConnectionModule.pas │ │ ├── EntityForm.fmx │ │ ├── EntityForm.pas │ │ ├── ImportFrame.fmx │ │ ├── ImportFrame.pas │ │ ├── MainForm.fmx │ │ └── MainForm.pas ├── CallCentre - With Utilities │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Database.Utilities.pas │ ├── Entities.pas │ └── Forms │ │ ├── AgentForm.fmx │ │ ├── AgentForm.pas │ │ ├── ConnectionModule.dfm │ │ ├── ConnectionModule.pas │ │ ├── EntityForm.fmx │ │ ├── EntityForm.pas │ │ ├── MainForm.fmx │ │ └── MainForm.pas └── CallCentre - Without Utilities │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Entities.pas │ └── Forms │ ├── AgentForm.fmx │ ├── AgentForm.pas │ ├── ConnectionModule.dfm │ ├── ConnectionModule.pas │ ├── EntityForm.fmx │ ├── EntityForm.pas │ ├── MainForm.fmx │ └── MainForm.pas ├── Chapter 5 ├── CallCentre - Listings │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Database.Import.pas │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Database.Utilities.pas │ ├── Entities.pas │ └── Forms │ │ ├── AgentForm.fmx │ │ ├── AgentForm.pas │ │ ├── ConnectionModule.dfm │ │ ├── ConnectionModule.pas │ │ ├── EntityForm.fmx │ │ ├── EntityForm.pas │ │ ├── ImportFrame.fmx │ │ ├── ImportFrame.pas │ │ ├── MainForm.fmx │ │ └── MainForm.pas ├── CallCentre - Queries │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Database.Import.pas │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Database.Utilities.pas │ ├── Entities.pas │ └── Forms │ │ ├── AgentForm.fmx │ │ ├── AgentForm.pas │ │ ├── ConnectionModule.dfm │ │ ├── ConnectionModule.pas │ │ ├── EntityForm.fmx │ │ ├── EntityForm.pas │ │ ├── ImportFrame.fmx │ │ ├── ImportFrame.pas │ │ ├── MainForm.fmx │ │ └── MainForm.pas └── CallCentre - Views │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Database.Import.pas │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Database.Utilities.pas │ ├── Entities.pas │ └── Forms │ ├── AgentForm.fmx │ ├── AgentForm.pas │ ├── ConnectionModule.dfm │ ├── ConnectionModule.pas │ ├── EntityForm.fmx │ ├── EntityForm.pas │ ├── ImportFrame.fmx │ ├── ImportFrame.pas │ ├── MainForm.fmx │ └── MainForm.pas ├── Chapter 6 ├── CallCentre - Events │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Database.Events.Alternative.pas │ ├── Database.Events.Types.pas │ ├── Database.Events.pas │ ├── Database.Import.pas │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Database.Utilities.pas │ ├── Entities.pas │ └── Forms │ │ ├── AgentForm.fmx │ │ ├── AgentForm.pas │ │ ├── ConnectionModule.dfm │ │ ├── ConnectionModule.pas │ │ ├── EntityForm.fmx │ │ ├── EntityForm.pas │ │ ├── ImportFrame.fmx │ │ ├── ImportFrame.pas │ │ ├── MainForm.fmx │ │ └── MainForm.pas ├── CallCentre - Inheritance │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Database.Import.pas │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Database.Utilities.pas │ ├── Entities.pas │ └── Forms │ │ ├── AgentForm.fmx │ │ ├── AgentForm.pas │ │ ├── ConnectionModule.dfm │ │ ├── ConnectionModule.pas │ │ ├── EntityForm.fmx │ │ ├── EntityForm.pas │ │ ├── ImportFrame.fmx │ │ ├── ImportFrame.pas │ │ ├── MainForm.fmx │ │ └── MainForm.pas └── CallCentre - TAureliusDataset │ ├── AndroidManifest.template.xml │ ├── CallCentre.deployproj │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── Database.Events.Types.pas │ ├── Database.Events.pas │ ├── Database.Import.pas │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Database.Utilities.pas │ ├── Entities.pas │ └── Forms │ ├── AgentForm.fmx │ ├── AgentForm.pas │ ├── ConnectionModule.dfm │ ├── ConnectionModule.pas │ ├── EntityForm.fmx │ ├── EntityForm.pas │ ├── ImportFrame.fmx │ ├── ImportFrame.pas │ ├── MainForm.fmx │ └── MainForm.pas ├── Chapter 7 ├── CallCentre - Local │ ├── AndroidManifest.template.xml │ ├── CallCentre.deployproj │ ├── CallCentre.dpr │ ├── CallCentre.dproj │ ├── CallCentre.eof │ ├── Database.Events.Types.pas │ ├── Database.Events.pas │ ├── Database.Import.pas │ ├── Database.Session.Types.pas │ ├── Database.Session.pas │ ├── Database.Utilities.pas │ ├── Entities.pas │ └── Forms │ │ ├── AgentForm.fmx │ │ ├── AgentForm.pas │ │ ├── ConnectionModule.dfm │ │ ├── ConnectionModule.pas │ │ ├── EntityForm.fmx │ │ ├── EntityForm.pas │ │ ├── FileSelectForm.fmx │ │ ├── FileSelectForm.pas │ │ ├── ImportFrame.fmx │ │ ├── ImportFrame.pas │ │ ├── MainForm.XLgXhdpiTb.fmx │ │ ├── MainForm.fmx │ │ ├── MainForm.pas │ │ ├── MainFormFix.XLgXhdpiTb.fmx │ │ ├── MainFormFix.fmx │ │ └── MainFormFix.pas ├── Client │ ├── AndroidManifest.template.xml │ ├── AureliusClient.deployproj │ ├── AureliusClient.dpr │ ├── AureliusClient.dproj │ ├── Entities.pas │ ├── MainForm.fmx │ └── MainForm.pas ├── User │ ├── Entities.pas │ ├── User.dpr │ └── User.dproj └── XData │ ├── Client.dpr │ ├── Client.dproj │ ├── Container.dfm │ ├── Container.pas │ ├── Database.Utilities.pas │ ├── Entities.pas │ ├── Main.dfm │ ├── Main.pas │ ├── MainClient.fmx │ ├── MainClient.pas │ ├── MainServer.dfm │ ├── MainServer.pas │ ├── Server.dpr │ ├── Server.dproj │ ├── XData.groupproj │ └── database.db ├── Chapter 8 ├── CallCentre.dgp ├── DataModelerScript.pas └── Entities.Dictionary.pas ├── Contributing.md ├── GitCommitWritingStyle.txt ├── LICENSE.txt ├── Misc ├── AbandonRatePerDepartment.sql ├── CallCentreData.csv ├── OverallStatisticsViewScript.sql ├── avatar-female.png └── avatar-male.png ├── README.md └── errata.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Uncomment these types if you want even more clean repository. But be careful. 2 | # It can make harm to an existing project source. Read explanations below. 3 | # 4 | # Resource files are binaries containing manifest, project icon and version info. 5 | # They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files. 6 | #*.res 7 | # 8 | # Type library file (binary). In old Delphi versions it should be stored. 9 | # Since Delphi 2009 it is produced from .ridl file and can safely be ignored. 10 | #*.tlb 11 | # 12 | # Diagram Portfolio file. Used by the diagram editor up to Delphi 7. 13 | # Uncomment this if you are not using diagrams or use newer Delphi version. 14 | #*.ddp 15 | # 16 | # Visual LiveBindings file. Added in Delphi XE2. 17 | # Uncomment this if you are not using LiveBindings Designer. 18 | #*.vlb 19 | # 20 | # Deployment Manager configuration file for your project. Added in Delphi XE2. 21 | # Uncomment this if it is not mobile development and you do not use remote debug feature. 22 | #*.deployproj 23 | # 24 | # C++ object files produced when C/C++ Output file generation is configured. 25 | # Uncomment this if you are not using external objects (zlib library for example). 26 | #*.obj 27 | # 28 | 29 | # Delphi compiler-generated binaries (safe to delete) 30 | *.exe 31 | *.dll 32 | *.bpl 33 | *.bpi 34 | *.dcp 35 | *.so 36 | *.apk 37 | *.drc 38 | *.map 39 | *.dres 40 | *.rsm 41 | *.tds 42 | *.dcu 43 | *.lib 44 | *.a 45 | *.o 46 | *.ocx 47 | 48 | # Delphi autogenerated files (duplicated info) 49 | *.cfg 50 | *.hpp 51 | *Resource.rc 52 | 53 | # Delphi local files (user-specific info) 54 | *.local 55 | *.identcache 56 | *.projdata 57 | *.tvsconfig 58 | *.dsk 59 | 60 | # Delphi history and backups 61 | __history/ 62 | __recovery/ 63 | *.~* 64 | 65 | # Castalia statistics file (since XE7 Castalia is distributed with Delphi) 66 | *.stat 67 | Full/ 68 | Chapter 7/CallCentre - Local - Without DBChart/ 69 | Chapter 3/CallCentre - With Database Session/Builds/ 70 | Chapter 4/CallCentre - Import/Builds/ 71 | Chapter 4/CallCentre - With Utilities/Builds/ 72 | Chapter 4/CallCentre - Without Utilities/Builds/ 73 | Chapter 5/CallCentre - Listings/Builds/ 74 | Chapter 5/CallCentre - Queries/Builds/ 75 | Chapter 5/CallCentre - Views/Builds/ 76 | Chapter 6/CallCentre - Inheritance/Builds/ 77 | Chapter 6/CallCentre - TAureliusDataset/Builds/ 78 | *.cbk 79 | Chapter 7/CallCentre - Local/Builds/ 80 | Chapter 7/Client/Android/ 81 | Chapter 7/Client/Win32/ 82 | Chapter 7/Client/Win64/ 83 | *.res 84 | -------------------------------------------------------------------------------- /9781484250129.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/introducing-delphi-orm/f1e146ef70bbe5f3e28615ccc03e2001682162fb/9781484250129.jpg -------------------------------------------------------------------------------- /Chapter 2/BasicFeatures.otares: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/introducing-delphi-orm/f1e146ef70bbe5f3e28615ccc03e2001682162fb/Chapter 2/BasicFeatures.otares -------------------------------------------------------------------------------- /Chapter 2/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=:memory:') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 2/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'System.Classes.TPersistent'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 2/Entities.pas: -------------------------------------------------------------------------------- 1 | unit Entities; 2 | 3 | interface 4 | 5 | uses 6 | SysUtils, 7 | Generics.Collections, 8 | Aurelius.Mapping.Attributes, 9 | Aurelius.Types.Blob, 10 | Aurelius.Types.DynamicProperties, 11 | Aurelius.Types.Nullable, 12 | Aurelius.Types.Proxy; 13 | 14 | type 15 | TPost = class; 16 | TUser = class; 17 | 18 | [Entity] 19 | [Table('Post')] 20 | [Id('FID', TIdGenerator.Guid)] 21 | TPost = class 22 | private 23 | [Column('ID', [TColumnProp.Required])] 24 | FID: TGuid; 25 | 26 | [Column('DateTime', [TColumnProp.Required])] 27 | FDateTime: TDateTime; 28 | 29 | [Column('Content', [], 50)] 30 | FContent: Nullable; 31 | 32 | [Column('Image', [TColumnProp.Lazy])] 33 | FImage: TBlob; 34 | 35 | [Association([], CascadeTypeAll - [TCascadeType.Remove])] 36 | [JoinColumn('User', [], 'ID')] 37 | FUser: TUser; 38 | public 39 | property ID: TGuid read FID write FID; 40 | property DateTime: TDateTime read FDateTime write FDateTime; 41 | property Content: Nullable read FContent write FContent; 42 | property Image: TBlob read FImage write FImage; 43 | property User: TUser read FUser write FUser; 44 | end; 45 | 46 | [Entity] 47 | [Table('User')] 48 | [Id('FID', TIdGenerator.Guid)] 49 | TUser = class 50 | private 51 | [Column('ID', [TColumnProp.Required])] 52 | FID: TGuid; 53 | 54 | [Column('Name', [TColumnProp.Required], 50)] 55 | FName: string; 56 | 57 | [ManyValuedAssociation([], 58 | [TCascadeType.SaveUpdate, TCascadeType.Merge, TCascadeType.Remove], 'FUser')] 59 | FPosts: TList; 60 | public 61 | constructor Create; 62 | destructor Destroy; override; 63 | property ID: TGuid read FID write FID; 64 | property Name: string read FName write FName; 65 | property Posts: TList read FPosts; 66 | end; 67 | 68 | 69 | implementation 70 | 71 | { TUser } 72 | 73 | constructor TUser.Create; 74 | begin 75 | inherited; 76 | FPosts := TList.Create; 77 | end; 78 | 79 | destructor TUser.Destroy; 80 | begin 81 | FPosts.Free; 82 | inherited; 83 | end; 84 | 85 | initialization 86 | RegisterEntity(TPost); 87 | RegisterEntity(TUser); 88 | 89 | finalization 90 | 91 | end. 92 | -------------------------------------------------------------------------------- /Chapter 2/EntitiesLazy.pas: -------------------------------------------------------------------------------- 1 | unit EntitiesLazy; 2 | 3 | interface 4 | 5 | uses 6 | SysUtils, 7 | Generics.Collections, 8 | Aurelius.Mapping.Attributes, 9 | Aurelius.Types.Blob, 10 | Aurelius.Types.DynamicProperties, 11 | Aurelius.Types.Nullable, 12 | Aurelius.Types.Proxy; 13 | 14 | type 15 | TPost = class; 16 | TUser = class; 17 | 18 | [Entity] 19 | [Table('Post')] 20 | [Id('FID', TIdGenerator.Guid)] 21 | TPost = class 22 | private 23 | [Column('ID', [TColumnProp.Required])] 24 | FID: TGuid; 25 | 26 | [Column('DateTime', [TColumnProp.Required])] 27 | FDateTime: TDateTime; 28 | 29 | [Column('Content', [], 50)] 30 | FContent: Nullable; 31 | 32 | [Column('Image', [TColumnProp.Lazy])] 33 | FImage: TBlob; 34 | 35 | [Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])] 36 | [JoinColumn('User', [], 'ID')] 37 | FUser: Proxy; 38 | function GetUser: TUser; 39 | procedure SetUser(const Value: TUser); 40 | public 41 | property ID: TGuid read FID write FID; 42 | property DateTime: TDateTime read FDateTime write FDateTime; 43 | property Content: Nullable read FContent write FContent; 44 | property Image: TBlob read FImage write FImage; 45 | property User: TUser read GetUser write SetUser; 46 | end; 47 | 48 | [Entity] 49 | [Table('User')] 50 | [Id('FID', TIdGenerator.Guid)] 51 | TUser = class 52 | private 53 | [Column('ID', [TColumnProp.Required])] 54 | FID: TGuid; 55 | 56 | [Column('Name', [TColumnProp.Required], 50)] 57 | FName: string; 58 | 59 | [ManyValuedAssociation([TAssociationProp.Lazy], [TCascadeType.SaveUpdate, TCascadeType.Merge], 'FUser')] 60 | FPosts: Proxy>; 61 | function GetPosts: TList; 62 | public 63 | constructor Create; 64 | destructor Destroy; override; 65 | property ID: TGuid read FID write FID; 66 | property Name: string read FName write FName; 67 | property Posts: TList read GetPosts; 68 | end; 69 | 70 | 71 | implementation 72 | 73 | { TPost } 74 | 75 | function TPost.GetUser: TUser; 76 | begin 77 | result := FUser.Value; 78 | end; 79 | 80 | procedure TPost.SetUser(const Value: TUser); 81 | begin 82 | FUser.Value := Value; 83 | end; 84 | 85 | { TUser } 86 | 87 | constructor TUser.Create; 88 | begin 89 | inherited; 90 | FPosts.SetInitialValue(TList.Create); 91 | end; 92 | 93 | destructor TUser.Destroy; 94 | begin 95 | FPosts.DestroyValue; 96 | inherited; 97 | end; 98 | 99 | function TUser.GetPosts: TList; 100 | begin 101 | result := FPosts.Value; 102 | end; 103 | 104 | initialization 105 | RegisterEntity(TPost); 106 | RegisterEntity(TUser); 107 | 108 | finalization 109 | 110 | end. 111 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Skeleton/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TFormMain, FormMain); 14 | Application.Run; 15 | end. 16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Skeleton/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Skeleton/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Skeleton/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - With Database Session/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 8 | Entities in 'Entities.pas', 9 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 10 | Database.Session in 'Database.Session.pas', 11 | Database.Session.Types in 'Database.Session.Types.pas'; 12 | 13 | {$R *.res} 14 | 15 | begin 16 | Application.Initialize; 17 | Application.CreateForm(TFormMain, FormMain); 18 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 19 | Application.Run; 20 | end. 21 | 22 | 23 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - With Database Session/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; 14 | end; 15 | 16 | implementation 17 | 18 | end. 19 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - With Database Session/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManager: TObjectManager; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; 23 | {$ENDREGION} 24 | end; 25 | 26 | implementation 27 | 28 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 29 | begin 30 | Assert(aConnection <> nil); 31 | 32 | inherited Create; 33 | fConnection:=aConnection; 34 | end; 35 | 36 | function TDatabaseSession.databaseManager: TDatabaseManager; 37 | begin 38 | if not Assigned(fDatabaseManager) then 39 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 40 | Result:=fDatabaseManager; 41 | end; 42 | 43 | destructor TDatabaseSession.Destroy; 44 | begin 45 | fDatabaseManager.Free; 46 | fObjectManager.Free; 47 | inherited; 48 | end; 49 | 50 | function TDatabaseSession.objectManager: TObjectManager; 51 | begin 52 | if not Assigned(fObjectManager) then 53 | fObjectManager:=TObjectManager.Create(fConnection); 54 | Result:=fObjectManager; 55 | end; 56 | 57 | end. 58 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - With Database Session/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - With Database Session/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - With Database Session/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - With Database Session/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - With Database Session/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Without Database Session/Builds/Win32/Debug/database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/introducing-delphi-orm/f1e146ef70bbe5f3e28615ccc03e2001682162fb/Chapter 3/CallCentre - Without Database Session/Builds/Win32/Debug/database.db -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Without Database Session/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 8 | Entities in 'Entities.pas', 9 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}; 10 | 11 | {$R *.res} 12 | 13 | begin 14 | Application.Initialize; 15 | Application.CreateForm(TFormMain, FormMain); 16 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 17 | Application.Run; 18 | end. 19 | 20 | 21 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Without Database Session/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Without Database Session/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Without Database Session/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Without Database Session/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 3/CallCentre - Without Database Session/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 8 | Entities in 'Entities.pas', 9 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 10 | Database.Session in 'Database.Session.pas', 11 | Database.Session.Types in 'Database.Session.Types.pas', 12 | Database.Utilities in 'Database.Utilities.pas', 13 | ImportFrame in 'Forms\ImportFrame.pas' {FrameImport: TFrame}, 14 | Database.Import in 'Database.Import.pas'; 15 | 16 | {$R *.res} 17 | 18 | begin 19 | Application.Initialize; 20 | Application.CreateForm(TFormMain, FormMain); 21 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 22 | Application.Run; 23 | end. 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; 14 | end; 15 | 16 | implementation 17 | 18 | end. 19 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManager: TObjectManager; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; 23 | {$ENDREGION} 24 | end; 25 | 26 | implementation 27 | 28 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 29 | begin 30 | Assert(aConnection <> nil); 31 | 32 | inherited Create; 33 | fConnection:=aConnection; 34 | end; 35 | 36 | function TDatabaseSession.databaseManager: TDatabaseManager; 37 | begin 38 | if not Assigned(fDatabaseManager) then 39 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 40 | Result:=fDatabaseManager; 41 | end; 42 | 43 | destructor TDatabaseSession.Destroy; 44 | begin 45 | fDatabaseManager.Free; 46 | fObjectManager.Free; 47 | inherited; 48 | end; 49 | 50 | function TDatabaseSession.objectManager: TObjectManager; 51 | begin 52 | if not Assigned(fObjectManager) then 53 | fObjectManager:=TObjectManager.Create(fConnection); 54 | Result:=fObjectManager; 55 | end; 56 | 57 | end. 58 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/Database.Utilities.pas: -------------------------------------------------------------------------------- 1 | unit Database.Utilities; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.ObjectManager, FMX.Graphics, Aurelius.Types.Blob; 7 | 8 | type 9 | TDatabaseUtilities = class 10 | class procedure edit(const aObjManager: TObjectManager; const aEntity: T); 11 | class procedure bitmapToBlob (const aBmp: TBitmap; const aType: string; 12 | var aBlob: TBlob); 13 | class procedure blobToBitmap (const aBlob: TBlob; var aBmp: TBitmap); 14 | end; 15 | 16 | implementation 17 | 18 | uses 19 | Aurelius.Mapping.Attributes, FMX.Surfaces, System.Classes, System.SysUtils; 20 | 21 | { TDatabaseUtilities } 22 | 23 | class procedure TDatabaseUtilities.bitmapToBlob(const aBmp: TBitmap; 24 | const aType: string; var aBlob: TBlob); 25 | var 26 | bmp: TBitmapSurface; 27 | bs: TBytesStream; 28 | begin 29 | bmp := TBitmapSurface.create; 30 | try 31 | bmp.assign(aBmp); 32 | bs := TBytesStream.create; 33 | try 34 | TBitmapCodecManager.SaveToStream(bs, bmp, aType); 35 | aBlob.AsBytes := bs.Bytes; 36 | finally 37 | bs.free; 38 | end; 39 | finally 40 | bmp.free; 41 | end; 42 | 43 | end; 44 | 45 | class procedure TDatabaseUtilities.blobToBitmap(const aBlob: TBlob; 46 | var aBmp: TBitmap); 47 | var 48 | ms: TMemoryStream; 49 | begin 50 | Assert(aBmp <> nil); 51 | ms := TMemoryStream.create; 52 | try 53 | aBlob.SaveToStream(ms); 54 | MS.Position := 0; 55 | aBmp.LoadFromStream(ms); 56 | finally 57 | ms.free; 58 | end; 59 | end; 60 | 61 | class procedure TDatabaseUtilities.edit(const aObjManager: TObjectManager; 62 | const aEntity: T); 63 | begin 64 | Assert(aObjManager <> nil); 65 | Assert(aEntity <> nil); 66 | 67 | try 68 | aObjManager.SaveOrUpdate(aEntity); 69 | aObjManager.Flush; 70 | except 71 | if not aObjManager.IsAttached(aEntity) then 72 | aEntity.Free; 73 | end; 74 | end; 75 | 76 | end. 77 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/Forms/ImportFrame.fmx: -------------------------------------------------------------------------------- 1 | object FrameImport: TFrameImport 2 | Align = Client 3 | Size.Width = 530.000000000000000000 4 | Size.Height = 164.000000000000000000 5 | Size.PlatformDefault = False 6 | object Layout21: TLayout 7 | Align = Top 8 | Margins.Left = 10.000000000000000000 9 | Margins.Right = 10.000000000000000000 10 | Position.X = 10.000000000000000000 11 | Position.Y = 67.000000000000000000 12 | Size.Width = 510.000000000000000000 13 | Size.Height = 22.000000000000000000 14 | Size.PlatformDefault = False 15 | TabOrder = 1 16 | object btImport: TButton 17 | Align = Left 18 | Size.Width = 113.000000000000000000 19 | Size.Height = 22.000000000000000000 20 | Size.PlatformDefault = False 21 | TabOrder = 0 22 | Text = 'Import Data' 23 | end 24 | end 25 | object pbImport: TProgressBar 26 | Align = Top 27 | Orientation = Horizontal 28 | Margins.Left = 10.000000000000000000 29 | Margins.Right = 10.000000000000000000 30 | Margins.Bottom = 10.000000000000000000 31 | Position.X = 10.000000000000000000 32 | Position.Y = 37.000000000000000000 33 | Size.Width = 510.000000000000000000 34 | Size.Height = 20.000000000000000000 35 | Size.PlatformDefault = False 36 | end 37 | object lbImport: TLabel 38 | Align = Top 39 | Margins.Left = 10.000000000000000000 40 | Margins.Top = 10.000000000000000000 41 | Margins.Right = 10.000000000000000000 42 | Margins.Bottom = 5.000000000000000000 43 | Position.X = 10.000000000000000000 44 | Position.Y = 10.000000000000000000 45 | Size.Width = 510.000000000000000000 46 | Size.Height = 22.000000000000000000 47 | Size.PlatformDefault = False 48 | Text = 'Idle' 49 | TabOrder = 2 50 | end 51 | object lbTime: TLabel 52 | Align = Top 53 | StyledSettings = [Family, Size, FontColor] 54 | Margins.Left = 10.000000000000000000 55 | Margins.Top = 10.000000000000000000 56 | Margins.Right = 10.000000000000000000 57 | Margins.Bottom = 10.000000000000000000 58 | Position.X = 10.000000000000000000 59 | Position.Y = 99.000000000000000000 60 | Size.Width = 510.000000000000000000 61 | Size.Height = 17.000000000000000000 62 | Size.PlatformDefault = False 63 | TextSettings.Font.StyleExt = {00040000000200000004000000} 64 | Text = 'Not started yet' 65 | TabOrder = 3 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Import/Forms/ImportFrame.pas: -------------------------------------------------------------------------------- 1 | unit ImportFrame; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Controls.Presentation, FMX.Layouts; 9 | 10 | type 11 | TFrameImport = class(TFrame) 12 | Layout21: TLayout; 13 | btImport: TButton; 14 | pbImport: TProgressBar; 15 | lbImport: TLabel; 16 | lbTime: TLabel; 17 | private 18 | { Private declarations } 19 | public 20 | { Public declarations } 21 | end; 22 | 23 | implementation 24 | 25 | {$R *.fmx} 26 | 27 | end. 28 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - With Utilities/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 7 | Entities in 'Entities.pas', 8 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 9 | Database.Session in 'Database.Session.pas', 10 | Database.Session.Types in 'Database.Session.Types.pas', 11 | Database.Utilities in 'Database.Utilities.pas', 12 | MainForm in 'Forms\MainForm.pas' {FormMain}; 13 | 14 | {$R *.res} 15 | 16 | begin 17 | Application.Initialize; 18 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 19 | Application.CreateForm(TFormMain, FormMain); 20 | Application.Run; 21 | end. 22 | 23 | 24 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - With Utilities/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; 14 | end; 15 | 16 | implementation 17 | 18 | end. 19 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - With Utilities/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManager: TObjectManager; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; 23 | {$ENDREGION} 24 | end; 25 | 26 | implementation 27 | 28 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 29 | begin 30 | Assert(aConnection <> nil); 31 | 32 | inherited Create; 33 | fConnection:=aConnection; 34 | end; 35 | 36 | function TDatabaseSession.databaseManager: TDatabaseManager; 37 | begin 38 | if not Assigned(fDatabaseManager) then 39 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 40 | Result:=fDatabaseManager; 41 | end; 42 | 43 | destructor TDatabaseSession.Destroy; 44 | begin 45 | fDatabaseManager.Free; 46 | fObjectManager.Free; 47 | inherited; 48 | end; 49 | 50 | function TDatabaseSession.objectManager: TObjectManager; 51 | begin 52 | if not Assigned(fObjectManager) then 53 | fObjectManager:=TObjectManager.Create(fConnection); 54 | Result:=fObjectManager; 55 | end; 56 | 57 | end. 58 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - With Utilities/Database.Utilities.pas: -------------------------------------------------------------------------------- 1 | unit Database.Utilities; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.ObjectManager, FMX.Graphics, Aurelius.Types.Blob; 7 | 8 | type 9 | TDatabaseUtilities = class 10 | class procedure edit(const aObjManager: TObjectManager; const aEntity: T); 11 | class procedure bitmapToBlob (const aBmp: TBitmap; const aType: string; 12 | var aBlob: TBlob); 13 | class procedure blobToBitmap (const aBlob: TBlob; var aBmp: TBitmap); 14 | end; 15 | 16 | implementation 17 | 18 | uses 19 | Aurelius.Mapping.Attributes, FMX.Surfaces, System.Classes, System.SysUtils; 20 | 21 | { TDatabaseUtilities } 22 | 23 | class procedure TDatabaseUtilities.bitmapToBlob(const aBmp: TBitmap; 24 | const aType: string; var aBlob: TBlob); 25 | var 26 | bmp: TBitmapSurface; 27 | bs: TBytesStream; 28 | begin 29 | bmp := TBitmapSurface.create; 30 | try 31 | bmp.assign(aBmp); 32 | bs := TBytesStream.create; 33 | try 34 | TBitmapCodecManager.SaveToStream(bs, bmp, aType); 35 | aBlob.AsBytes := bs.Bytes; 36 | finally 37 | bs.free; 38 | end; 39 | finally 40 | bmp.free; 41 | end; 42 | 43 | end; 44 | 45 | class procedure TDatabaseUtilities.blobToBitmap(const aBlob: TBlob; 46 | var aBmp: TBitmap); 47 | var 48 | ms: TMemoryStream; 49 | begin 50 | Assert(aBmp <> nil); 51 | ms := TMemoryStream.create; 52 | try 53 | aBlob.SaveToStream(ms); 54 | MS.Position := 0; 55 | aBmp.LoadFromStream(ms); 56 | finally 57 | ms.free; 58 | end; 59 | end; 60 | 61 | class procedure TDatabaseUtilities.edit(const aObjManager: TObjectManager; 62 | const aEntity: T); 63 | begin 64 | Assert(aObjManager <> nil); 65 | Assert(aEntity <> nil); 66 | 67 | try 68 | aObjManager.SaveOrUpdate(aEntity); 69 | aObjManager.Flush(aEntity); 70 | except 71 | if not aObjManager.IsAttached(aEntity) then 72 | aEntity.Free; 73 | end; 74 | end; 75 | 76 | end. 77 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - With Utilities/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - With Utilities/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - With Utilities/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - With Utilities/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - With Utilities/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Without Utilities/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 8 | Entities in 'Entities.pas', 9 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 10 | Database.Session in 'Database.Session.pas', 11 | Database.Session.Types in 'Database.Session.Types.pas'; 12 | 13 | {$R *.res} 14 | 15 | begin 16 | Application.Initialize; 17 | Application.CreateForm(TFormMain, FormMain); 18 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 19 | Application.Run; 20 | end. 21 | 22 | 23 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Without Utilities/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; 14 | end; 15 | 16 | implementation 17 | 18 | end. 19 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Without Utilities/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManager: TObjectManager; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; 23 | {$ENDREGION} 24 | end; 25 | 26 | implementation 27 | 28 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 29 | begin 30 | Assert(aConnection <> nil); 31 | 32 | inherited Create; 33 | fConnection:=aConnection; 34 | end; 35 | 36 | function TDatabaseSession.databaseManager: TDatabaseManager; 37 | begin 38 | if not Assigned(fDatabaseManager) then 39 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 40 | Result:=fDatabaseManager; 41 | end; 42 | 43 | destructor TDatabaseSession.Destroy; 44 | begin 45 | fDatabaseManager.Free; 46 | fObjectManager.Free; 47 | inherited; 48 | end; 49 | 50 | function TDatabaseSession.objectManager: TObjectManager; 51 | begin 52 | if not Assigned(fObjectManager) then 53 | fObjectManager:=TObjectManager.Create(fConnection); 54 | Result:=fObjectManager; 55 | end; 56 | 57 | end. 58 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Without Utilities/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Without Utilities/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Without Utilities/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Without Utilities/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 4/CallCentre - Without Utilities/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 8 | Entities in 'Entities.pas', 9 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 10 | Database.Session in 'Database.Session.pas', 11 | Database.Session.Types in 'Database.Session.Types.pas', 12 | Database.Utilities in 'Database.Utilities.pas', 13 | ImportFrame in 'Forms\ImportFrame.pas' {FrameImport: TFrame}, 14 | Database.Import in 'Database.Import.pas'; 15 | 16 | {$R *.res} 17 | 18 | begin 19 | Application.Initialize; 20 | Application.CreateForm(TFormMain, FormMain); 21 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 22 | Application.Run; 23 | end. 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; 14 | end; 15 | 16 | implementation 17 | 18 | end. 19 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManager: TObjectManager; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; 23 | {$ENDREGION} 24 | end; 25 | 26 | implementation 27 | 28 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 29 | begin 30 | Assert(aConnection <> nil); 31 | 32 | inherited Create; 33 | fConnection:=aConnection; 34 | end; 35 | 36 | function TDatabaseSession.databaseManager: TDatabaseManager; 37 | begin 38 | if not Assigned(fDatabaseManager) then 39 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 40 | Result:=fDatabaseManager; 41 | end; 42 | 43 | destructor TDatabaseSession.Destroy; 44 | begin 45 | fDatabaseManager.Free; 46 | fObjectManager.Free; 47 | inherited; 48 | end; 49 | 50 | function TDatabaseSession.objectManager: TObjectManager; 51 | begin 52 | if not Assigned(fObjectManager) then 53 | fObjectManager:=TObjectManager.Create(fConnection); 54 | Result:=fObjectManager; 55 | end; 56 | 57 | end. 58 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/Database.Utilities.pas: -------------------------------------------------------------------------------- 1 | unit Database.Utilities; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.ObjectManager, FMX.Graphics, Aurelius.Types.Blob; 7 | 8 | type 9 | TDatabaseUtilities = class 10 | class procedure edit(const aObjManager: TObjectManager; const aEntity: T); 11 | class procedure bitmapToBlob (const aBmp: TBitmap; const aType: string; 12 | var aBlob: TBlob); 13 | class procedure blobToBitmap (const aBlob: TBlob; var aBmp: TBitmap); 14 | end; 15 | 16 | implementation 17 | 18 | uses 19 | Aurelius.Mapping.Attributes, FMX.Surfaces, System.Classes, System.SysUtils; 20 | 21 | { TDatabaseUtilities } 22 | 23 | class procedure TDatabaseUtilities.bitmapToBlob(const aBmp: TBitmap; 24 | const aType: string; var aBlob: TBlob); 25 | var 26 | bmp: TBitmapSurface; 27 | bs: TBytesStream; 28 | begin 29 | bmp := TBitmapSurface.create; 30 | try 31 | bmp.assign(aBmp); 32 | bs := TBytesStream.create; 33 | try 34 | TBitmapCodecManager.SaveToStream(bs, bmp, aType); 35 | aBlob.AsBytes := bs.Bytes; 36 | finally 37 | bs.free; 38 | end; 39 | finally 40 | bmp.free; 41 | end; 42 | 43 | end; 44 | 45 | class procedure TDatabaseUtilities.blobToBitmap(const aBlob: TBlob; 46 | var aBmp: TBitmap); 47 | var 48 | ms: TMemoryStream; 49 | begin 50 | Assert(aBmp <> nil); 51 | ms := TMemoryStream.create; 52 | try 53 | aBlob.SaveToStream(ms); 54 | MS.Position := 0; 55 | aBmp.LoadFromStream(ms); 56 | finally 57 | ms.free; 58 | end; 59 | end; 60 | 61 | class procedure TDatabaseUtilities.edit(const aObjManager: TObjectManager; 62 | const aEntity: T); 63 | begin 64 | Assert(aObjManager <> nil); 65 | Assert(aEntity <> nil); 66 | 67 | try 68 | aObjManager.SaveOrUpdate(aEntity); 69 | aObjManager.Flush(aEntity); 70 | except 71 | if not aObjManager.IsAttached(aEntity) then 72 | aEntity.Free; 73 | end; 74 | end; 75 | 76 | end. 77 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/Forms/ImportFrame.fmx: -------------------------------------------------------------------------------- 1 | object FrameImport: TFrameImport 2 | Align = Client 3 | Size.Width = 530.000000000000000000 4 | Size.Height = 164.000000000000000000 5 | Size.PlatformDefault = False 6 | object Layout21: TLayout 7 | Align = Top 8 | Margins.Left = 10.000000000000000000 9 | Margins.Right = 10.000000000000000000 10 | Position.X = 10.000000000000000000 11 | Position.Y = 67.000000000000000000 12 | Size.Width = 510.000000000000000000 13 | Size.Height = 22.000000000000000000 14 | Size.PlatformDefault = False 15 | TabOrder = 1 16 | object btImport: TButton 17 | Align = Left 18 | Size.Width = 113.000000000000000000 19 | Size.Height = 22.000000000000000000 20 | Size.PlatformDefault = False 21 | TabOrder = 0 22 | Text = 'Import Data' 23 | end 24 | end 25 | object pbImport: TProgressBar 26 | Align = Top 27 | Orientation = Horizontal 28 | Margins.Left = 10.000000000000000000 29 | Margins.Right = 10.000000000000000000 30 | Margins.Bottom = 10.000000000000000000 31 | Position.X = 10.000000000000000000 32 | Position.Y = 37.000000000000000000 33 | Size.Width = 510.000000000000000000 34 | Size.Height = 20.000000000000000000 35 | Size.PlatformDefault = False 36 | end 37 | object lbImport: TLabel 38 | Align = Top 39 | Margins.Left = 10.000000000000000000 40 | Margins.Top = 10.000000000000000000 41 | Margins.Right = 10.000000000000000000 42 | Margins.Bottom = 5.000000000000000000 43 | Position.X = 10.000000000000000000 44 | Position.Y = 10.000000000000000000 45 | Size.Width = 510.000000000000000000 46 | Size.Height = 22.000000000000000000 47 | Size.PlatformDefault = False 48 | Text = 'Idle' 49 | TabOrder = 2 50 | end 51 | object lbTime: TLabel 52 | Align = Top 53 | StyledSettings = [Family, Size, FontColor] 54 | Margins.Left = 10.000000000000000000 55 | Margins.Top = 10.000000000000000000 56 | Margins.Right = 10.000000000000000000 57 | Margins.Bottom = 10.000000000000000000 58 | Position.X = 10.000000000000000000 59 | Position.Y = 99.000000000000000000 60 | Size.Width = 510.000000000000000000 61 | Size.Height = 17.000000000000000000 62 | Size.PlatformDefault = False 63 | TextSettings.Font.StyleExt = {00040000000200000004000000} 64 | Text = 'Not started yet' 65 | TabOrder = 3 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Listings/Forms/ImportFrame.pas: -------------------------------------------------------------------------------- 1 | unit ImportFrame; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Controls.Presentation, FMX.Layouts; 9 | 10 | type 11 | TFrameImport = class(TFrame) 12 | Layout21: TLayout; 13 | btImport: TButton; 14 | pbImport: TProgressBar; 15 | lbImport: TLabel; 16 | lbTime: TLabel; 17 | private 18 | { Private declarations } 19 | public 20 | { Public declarations } 21 | end; 22 | 23 | implementation 24 | 25 | {$R *.fmx} 26 | 27 | end. 28 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 8 | Entities in 'Entities.pas', 9 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 10 | Database.Session in 'Database.Session.pas', 11 | Database.Session.Types in 'Database.Session.Types.pas', 12 | Database.Utilities in 'Database.Utilities.pas', 13 | ImportFrame in 'Forms\ImportFrame.pas' {FrameImport: TFrame}, 14 | Database.Import in 'Database.Import.pas'; 15 | 16 | {$R *.res} 17 | 18 | begin 19 | Application.Initialize; 20 | Application.CreateForm(TFormMain, FormMain); 21 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 22 | Application.Run; 23 | end. 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; 14 | end; 15 | 16 | implementation 17 | 18 | end. 19 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManager: TObjectManager; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; 23 | {$ENDREGION} 24 | end; 25 | 26 | implementation 27 | 28 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 29 | begin 30 | Assert(aConnection <> nil); 31 | 32 | inherited Create; 33 | fConnection:=aConnection; 34 | end; 35 | 36 | function TDatabaseSession.databaseManager: TDatabaseManager; 37 | begin 38 | if not Assigned(fDatabaseManager) then 39 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 40 | Result:=fDatabaseManager; 41 | end; 42 | 43 | destructor TDatabaseSession.Destroy; 44 | begin 45 | fDatabaseManager.Free; 46 | fObjectManager.Free; 47 | inherited; 48 | end; 49 | 50 | function TDatabaseSession.objectManager: TObjectManager; 51 | begin 52 | if not Assigned(fObjectManager) then 53 | fObjectManager:=TObjectManager.Create(fConnection); 54 | Result:=fObjectManager; 55 | end; 56 | 57 | end. 58 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/Database.Utilities.pas: -------------------------------------------------------------------------------- 1 | unit Database.Utilities; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.ObjectManager, FMX.Graphics, Aurelius.Types.Blob, 7 | Aurelius.Criteria.Base, Aurelius.Criteria.Linq, Aurelius.Criteria.Projections; 8 | 9 | type 10 | TDatabaseUtilities = class 11 | private 12 | public 13 | class procedure edit(const aObjManager: TObjectManager; const aEntity: T); 14 | class procedure bitmapToBlob (const aBmp: TBitmap; const aType: string; 15 | var aBlob: TBlob); 16 | class procedure blobToBitmap (const aBlob: TBlob; var aBmp: TBitmap); 17 | 18 | end; 19 | 20 | implementation 21 | 22 | uses 23 | Aurelius.Mapping.Attributes, FMX.Surfaces, System.Classes, System.SysUtils, 24 | System.DateUtils; 25 | 26 | { TDatabaseUtilities } 27 | 28 | class procedure TDatabaseUtilities.bitmapToBlob(const aBmp: TBitmap; 29 | const aType: string; var aBlob: TBlob); 30 | var 31 | bmp: TBitmapSurface; 32 | bs: TBytesStream; 33 | begin 34 | bmp := TBitmapSurface.create; 35 | try 36 | bmp.assign(aBmp); 37 | bs := TBytesStream.create; 38 | try 39 | TBitmapCodecManager.SaveToStream(bs, bmp, aType); 40 | aBlob.AsBytes := bs.Bytes; 41 | finally 42 | bs.free; 43 | end; 44 | finally 45 | bmp.free; 46 | end; 47 | 48 | end; 49 | 50 | class procedure TDatabaseUtilities.blobToBitmap(const aBlob: TBlob; 51 | var aBmp: TBitmap); 52 | var 53 | ms: TMemoryStream; 54 | begin 55 | Assert(aBmp <> nil); 56 | ms := TMemoryStream.create; 57 | try 58 | aBlob.SaveToStream(ms); 59 | MS.Position := 0; 60 | aBmp.LoadFromStream(ms); 61 | finally 62 | ms.free; 63 | end; 64 | end; 65 | 66 | class procedure TDatabaseUtilities.edit(const aObjManager: TObjectManager; 67 | const aEntity: T); 68 | begin 69 | Assert(aObjManager <> nil); 70 | Assert(aEntity <> nil); 71 | 72 | try 73 | aObjManager.SaveOrUpdate(aEntity); 74 | aObjManager.Flush(aEntity); 75 | except 76 | if not aObjManager.IsAttached(aEntity) then 77 | aEntity.Free; 78 | end; 79 | end; 80 | 81 | end. 82 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/Forms/ImportFrame.fmx: -------------------------------------------------------------------------------- 1 | object FrameImport: TFrameImport 2 | Align = Client 3 | Size.Width = 530.000000000000000000 4 | Size.Height = 164.000000000000000000 5 | Size.PlatformDefault = False 6 | object Layout21: TLayout 7 | Align = Top 8 | Margins.Left = 10.000000000000000000 9 | Margins.Right = 10.000000000000000000 10 | Position.X = 10.000000000000000000 11 | Position.Y = 67.000000000000000000 12 | Size.Width = 510.000000000000000000 13 | Size.Height = 22.000000000000000000 14 | Size.PlatformDefault = False 15 | TabOrder = 1 16 | object btImport: TButton 17 | Align = Left 18 | Size.Width = 113.000000000000000000 19 | Size.Height = 22.000000000000000000 20 | Size.PlatformDefault = False 21 | TabOrder = 0 22 | Text = 'Import Data' 23 | end 24 | end 25 | object pbImport: TProgressBar 26 | Align = Top 27 | Orientation = Horizontal 28 | Margins.Left = 10.000000000000000000 29 | Margins.Right = 10.000000000000000000 30 | Margins.Bottom = 10.000000000000000000 31 | Position.X = 10.000000000000000000 32 | Position.Y = 37.000000000000000000 33 | Size.Width = 510.000000000000000000 34 | Size.Height = 20.000000000000000000 35 | Size.PlatformDefault = False 36 | end 37 | object lbImport: TLabel 38 | Align = Top 39 | Margins.Left = 10.000000000000000000 40 | Margins.Top = 10.000000000000000000 41 | Margins.Right = 10.000000000000000000 42 | Margins.Bottom = 5.000000000000000000 43 | Position.X = 10.000000000000000000 44 | Position.Y = 10.000000000000000000 45 | Size.Width = 510.000000000000000000 46 | Size.Height = 22.000000000000000000 47 | Size.PlatformDefault = False 48 | Text = 'Idle' 49 | TabOrder = 2 50 | end 51 | object lbTime: TLabel 52 | Align = Top 53 | StyledSettings = [Family, Size, FontColor] 54 | Margins.Left = 10.000000000000000000 55 | Margins.Top = 10.000000000000000000 56 | Margins.Right = 10.000000000000000000 57 | Margins.Bottom = 10.000000000000000000 58 | Position.X = 10.000000000000000000 59 | Position.Y = 99.000000000000000000 60 | Size.Width = 510.000000000000000000 61 | Size.Height = 17.000000000000000000 62 | Size.PlatformDefault = False 63 | TextSettings.Font.StyleExt = {00040000000200000004000000} 64 | Text = 'Not started yet' 65 | TabOrder = 3 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Queries/Forms/ImportFrame.pas: -------------------------------------------------------------------------------- 1 | unit ImportFrame; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Controls.Presentation, FMX.Layouts; 9 | 10 | type 11 | TFrameImport = class(TFrame) 12 | Layout21: TLayout; 13 | btImport: TButton; 14 | pbImport: TProgressBar; 15 | lbImport: TLabel; 16 | lbTime: TLabel; 17 | private 18 | { Private declarations } 19 | public 20 | { Public declarations } 21 | end; 22 | 23 | implementation 24 | 25 | {$R *.fmx} 26 | 27 | end. 28 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 8 | Entities in 'Entities.pas', 9 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 10 | Database.Session in 'Database.Session.pas', 11 | Database.Session.Types in 'Database.Session.Types.pas', 12 | Database.Utilities in 'Database.Utilities.pas', 13 | ImportFrame in 'Forms\ImportFrame.pas' {FrameImport: TFrame}, 14 | Database.Import in 'Database.Import.pas'; 15 | 16 | {$R *.res} 17 | 18 | begin 19 | Application.Initialize; 20 | Application.CreateForm(TFormMain, FormMain); 21 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 22 | Application.Run; 23 | end. 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; overload; 14 | function objectManager (const aModel: string): TObjectManager; overload; 15 | end; 16 | 17 | implementation 18 | 19 | end. 20 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager, System.Generics.Collections; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManagerDictionary: TObjectDictionary; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; overload; 23 | function objectManager (const aModel: string): TObjectManager; overload; 24 | {$ENDREGION} 25 | end; 26 | 27 | implementation 28 | 29 | uses 30 | System.SysUtils, Aurelius.Mapping.Explorer; 31 | 32 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 33 | begin 34 | Assert(aConnection <> nil); 35 | 36 | inherited Create; 37 | fConnection:=aConnection; 38 | fObjectManagerDictionary:=TObjectDictionary.Create([doOwnsValues]); 39 | end; 40 | 41 | function TDatabaseSession.databaseManager: TDatabaseManager; 42 | begin 43 | if not Assigned(fDatabaseManager) then 44 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 45 | Result:=fDatabaseManager; 46 | end; 47 | 48 | destructor TDatabaseSession.Destroy; 49 | begin 50 | fDatabaseManager.Free; 51 | fObjectManagerDictionary.Free; 52 | inherited; 53 | end; 54 | 55 | function TDatabaseSession.objectManager(const aModel: string): TObjectManager; 56 | var 57 | cModel: string; 58 | begin 59 | cModel:=Trim(UpperCase(aModel)); 60 | if cModel='' then 61 | Result:=objectManager 62 | else 63 | begin 64 | if not fObjectManagerDictionary.ContainsKey(cModel) then 65 | if cModel = 'DEFAULT' then 66 | fObjectManagerDictionary.Add('DEFAULT', TObjectManager.Create(fConnection)) 67 | else 68 | fObjectManagerDictionary.Add(cModel, 69 | TObjectManager.Create(fConnection, TMappingExplorer.Get(cModel))); 70 | Result:=fObjectManagerDictionary.Items[cModel]; 71 | end; 72 | end; 73 | 74 | function TDatabaseSession.objectManager: TObjectManager; 75 | begin 76 | result:=objectManager('default'); 77 | end; 78 | 79 | end. 80 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/Database.Utilities.pas: -------------------------------------------------------------------------------- 1 | unit Database.Utilities; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.ObjectManager, FMX.Graphics, Aurelius.Types.Blob, 7 | Aurelius.Criteria.Base, Aurelius.Criteria.Linq, Aurelius.Criteria.Projections; 8 | 9 | type 10 | TDatabaseUtilities = class 11 | private 12 | public 13 | class procedure edit(const aObjManager: TObjectManager; const aEntity: T); 14 | class procedure bitmapToBlob (const aBmp: TBitmap; const aType: string; 15 | var aBlob: TBlob); 16 | class procedure blobToBitmap (const aBlob: TBlob; var aBmp: TBitmap); 17 | 18 | end; 19 | 20 | implementation 21 | 22 | uses 23 | Aurelius.Mapping.Attributes, FMX.Surfaces, System.Classes, System.SysUtils, 24 | System.DateUtils; 25 | 26 | { TDatabaseUtilities } 27 | 28 | class procedure TDatabaseUtilities.bitmapToBlob(const aBmp: TBitmap; 29 | const aType: string; var aBlob: TBlob); 30 | var 31 | bmp: TBitmapSurface; 32 | bs: TBytesStream; 33 | begin 34 | bmp := TBitmapSurface.create; 35 | try 36 | bmp.assign(aBmp); 37 | bs := TBytesStream.create; 38 | try 39 | TBitmapCodecManager.SaveToStream(bs, bmp, aType); 40 | aBlob.AsBytes := bs.Bytes; 41 | finally 42 | bs.free; 43 | end; 44 | finally 45 | bmp.free; 46 | end; 47 | 48 | end; 49 | 50 | class procedure TDatabaseUtilities.blobToBitmap(const aBlob: TBlob; 51 | var aBmp: TBitmap); 52 | var 53 | ms: TMemoryStream; 54 | begin 55 | Assert(aBmp <> nil); 56 | ms := TMemoryStream.create; 57 | try 58 | aBlob.SaveToStream(ms); 59 | MS.Position := 0; 60 | aBmp.LoadFromStream(ms); 61 | finally 62 | ms.free; 63 | end; 64 | end; 65 | 66 | class procedure TDatabaseUtilities.edit(const aObjManager: TObjectManager; 67 | const aEntity: T); 68 | begin 69 | Assert(aObjManager <> nil); 70 | Assert(aEntity <> nil); 71 | 72 | try 73 | aObjManager.SaveOrUpdate(aEntity); 74 | aObjManager.Flush(aEntity); 75 | except 76 | if not aObjManager.IsAttached(aEntity) then 77 | aEntity.Free; 78 | end; 79 | end; 80 | 81 | end. 82 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/Forms/ImportFrame.fmx: -------------------------------------------------------------------------------- 1 | object FrameImport: TFrameImport 2 | Align = Client 3 | Size.Width = 530.000000000000000000 4 | Size.Height = 164.000000000000000000 5 | Size.PlatformDefault = False 6 | object Layout21: TLayout 7 | Align = Top 8 | Margins.Left = 10.000000000000000000 9 | Margins.Right = 10.000000000000000000 10 | Position.X = 10.000000000000000000 11 | Position.Y = 67.000000000000000000 12 | Size.Width = 510.000000000000000000 13 | Size.Height = 22.000000000000000000 14 | Size.PlatformDefault = False 15 | TabOrder = 1 16 | object btImport: TButton 17 | Align = Left 18 | Size.Width = 113.000000000000000000 19 | Size.Height = 22.000000000000000000 20 | Size.PlatformDefault = False 21 | TabOrder = 0 22 | Text = 'Import Data' 23 | end 24 | end 25 | object pbImport: TProgressBar 26 | Align = Top 27 | Orientation = Horizontal 28 | Margins.Left = 10.000000000000000000 29 | Margins.Right = 10.000000000000000000 30 | Margins.Bottom = 10.000000000000000000 31 | Position.X = 10.000000000000000000 32 | Position.Y = 37.000000000000000000 33 | Size.Width = 510.000000000000000000 34 | Size.Height = 20.000000000000000000 35 | Size.PlatformDefault = False 36 | end 37 | object lbImport: TLabel 38 | Align = Top 39 | Margins.Left = 10.000000000000000000 40 | Margins.Top = 10.000000000000000000 41 | Margins.Right = 10.000000000000000000 42 | Margins.Bottom = 5.000000000000000000 43 | Position.X = 10.000000000000000000 44 | Position.Y = 10.000000000000000000 45 | Size.Width = 510.000000000000000000 46 | Size.Height = 22.000000000000000000 47 | Size.PlatformDefault = False 48 | Text = 'Idle' 49 | TabOrder = 2 50 | end 51 | object lbTime: TLabel 52 | Align = Top 53 | StyledSettings = [Family, Size, FontColor] 54 | Margins.Left = 10.000000000000000000 55 | Margins.Top = 10.000000000000000000 56 | Margins.Right = 10.000000000000000000 57 | Margins.Bottom = 10.000000000000000000 58 | Position.X = 10.000000000000000000 59 | Position.Y = 99.000000000000000000 60 | Size.Width = 510.000000000000000000 61 | Size.Height = 17.000000000000000000 62 | Size.PlatformDefault = False 63 | TextSettings.Font.StyleExt = {00040000000200000004000000} 64 | Text = 'Not started yet' 65 | TabOrder = 3 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /Chapter 5/CallCentre - Views/Forms/ImportFrame.pas: -------------------------------------------------------------------------------- 1 | unit ImportFrame; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Controls.Presentation, FMX.Layouts; 9 | 10 | type 11 | TFrameImport = class(TFrame) 12 | Layout21: TLayout; 13 | btImport: TButton; 14 | pbImport: TProgressBar; 15 | lbImport: TLabel; 16 | lbTime: TLabel; 17 | private 18 | { Private declarations } 19 | public 20 | { Public declarations } 21 | end; 22 | 23 | implementation 24 | 25 | {$R *.fmx} 26 | 27 | end. 28 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 8 | Entities in 'Entities.pas', 9 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 10 | Database.Session in 'Database.Session.pas', 11 | Database.Session.Types in 'Database.Session.Types.pas', 12 | Database.Utilities in 'Database.Utilities.pas', 13 | ImportFrame in 'Forms\ImportFrame.pas' {FrameImport: TFrame}, 14 | Database.Import in 'Database.Import.pas', 15 | Database.Events.Types in 'Database.Events.Types.pas', 16 | Database.Events in 'Database.Events.pas'; 17 | 18 | {$R *.res} 19 | 20 | begin 21 | Application.Initialize; 22 | Application.CreateForm(TFormMain, FormMain); 23 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 24 | Application.Run; 25 | end. 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Database.Events.Alternative.pas: -------------------------------------------------------------------------------- 1 | unit Database.Events.Alternative; 2 | 3 | interface 4 | 5 | uses 6 | Database.Events.Types, Aurelius.Events.Manager; 7 | 8 | type 9 | TDatabaseEvents = class (TInterfacedObject, IDatabaseEvents) 10 | private 11 | fInsertedProc: TInsertedProc; 12 | fUpdatedProc: TUpdatedProc; 13 | public 14 | constructor Create; 15 | destructor Destroy; override; 16 | {$REGION 'Interface'} 17 | procedure subscribeEvents; 18 | procedure unsubscribeEvents; 19 | {$ENDREGION} 20 | 21 | end; 22 | 23 | implementation 24 | 25 | uses 26 | Aurelius.Mapping.Explorer, Entities, Database.Session.Types, 27 | Aurelius.Drivers.Interfaces, ConnectionModule, 28 | Database.Session, System.SysUtils, Aurelius.Engine.ObjectManager; 29 | 30 | constructor TDatabaseEvents.Create; 31 | var 32 | statement: IDBStatement; 33 | objManager: TObjectManager; 34 | sqlScript: string; 35 | begin 36 | inherited; 37 | fInsertedProc:= procedure (Args: TInsertedArgs) 38 | begin 39 | if Args.Entity is TAgent then 40 | begin 41 | statement:=(Args.Manager as TObjectManager).Connection.CreateStatement; 42 | sqlScript:='update Base set CreateTS = '+ 43 | Double(Now).ToString+' where ID = '+ 44 | QuotedStr(TAgent(Args.Entity).ID.ToString); 45 | statement.SetSQLCommand(sqlScript); 46 | statement.Execute; 47 | end; 48 | end; 49 | fUpdatedProc:= procedure (Args: TUpdatedArgs) 50 | begin 51 | if Args.Entity is TAgent then 52 | begin 53 | statement:=(Args.Manager as TObjectManager).Connection.CreateStatement; 54 | sqlScript:='update Base set ModifyTS = '+ 55 | Double(Now).ToString+' where ID = '+ 56 | QuotedStr(TAgent(Args.Entity).ID.ToString); 57 | statement.SetSQLCommand(sqlScript); 58 | statement.Execute; 59 | end; 60 | end; 61 | end; 62 | 63 | destructor TDatabaseEvents.Destroy; 64 | begin 65 | unsubscribeEvents; 66 | fInsertedProc:=nil; 67 | fUpdatedProc:=nil; 68 | inherited; 69 | end; 70 | 71 | procedure TDatabaseEvents.subscribeEvents; 72 | begin 73 | TMappingExplorer.Default.Events.OnInserted.Subscribe(fInsertedProc); 74 | TMappingExplorer.Default.Events.OnUpdated.Subscribe(fUpdatedProc); 75 | end; 76 | 77 | procedure TDatabaseEvents.unsubscribeEvents; 78 | begin 79 | TMappingExplorer.Default.Events.OnInserted.Unsubscribe(fInsertedProc); 80 | TMappingExplorer.Default.Events.OnUpdated.Unsubscribe(fUpdatedProc); 81 | end; 82 | 83 | end. 84 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Database.Events.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Events.Types; 2 | 3 | interface 4 | 5 | type 6 | IDatabaseEvents = interface 7 | ['{369927E5-976A-4263-9E66-31355C3E7C2C}'] 8 | procedure subscribeEvents; 9 | procedure unsubscribeEvents; 10 | end; 11 | 12 | implementation 13 | 14 | end. 15 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Database.Events.pas: -------------------------------------------------------------------------------- 1 | unit Database.Events; 2 | 3 | interface 4 | 5 | uses 6 | Database.Events.Types, 7 | Aurelius.Events.Manager; 8 | 9 | type 10 | TDatabaseEvents = class (TInterfacedObject, IDatabaseEvents) 11 | private 12 | fInsertingProc: TInsertingProc; 13 | fUpdatingProc: TUpdatingProc; 14 | public 15 | constructor Create; 16 | destructor Destroy; override; 17 | {$REGION 'Interface'} 18 | procedure subscribeEvents; 19 | procedure unsubscribeEvents; 20 | {$ENDREGION} 21 | 22 | end; 23 | 24 | implementation 25 | 26 | uses 27 | Entities, 28 | System.SysUtils, 29 | Aurelius.Mapping.Explorer; 30 | 31 | constructor TDatabaseEvents.Create; 32 | begin 33 | inherited; 34 | fInsertingProc:= procedure (Args: TInsertingArgs) 35 | begin 36 | if Args.Entity is TAgent then 37 | begin 38 | (Args.Entity as TAgent).CreateTS:=Now; 39 | end; 40 | end; 41 | fUpdatingProc:= procedure (Args: TUpdatingArgs) 42 | begin 43 | if Args.Entity is TAgent then 44 | begin 45 | (Args.Entity as TAgent).ModifyTS:=Now; 46 | Args.RecalculateState:=True; 47 | end; 48 | end; 49 | end; 50 | 51 | destructor TDatabaseEvents.Destroy; 52 | begin 53 | unsubscribeEvents; 54 | fInsertingProc:=nil; 55 | fUpdatingProc:=nil; 56 | inherited; 57 | end; 58 | 59 | procedure TDatabaseEvents.subscribeEvents; 60 | begin 61 | TMappingExplorer.Default.Events.OnInserting.Subscribe(fInsertingProc); 62 | TMappingExplorer.Default.Events.OnUpdating.Subscribe(fUpdatingProc); 63 | end; 64 | 65 | procedure TDatabaseEvents.unsubscribeEvents; 66 | begin 67 | TMappingExplorer.Default.Events.OnInserting.Unsubscribe(fInsertingProc); 68 | TMappingExplorer.Default.Events.OnUpdating.Unsubscribe(fUpdatingProc); 69 | end; 70 | 71 | end. 72 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; overload; 14 | function objectManager (const aModel: string): TObjectManager; overload; 15 | end; 16 | 17 | implementation 18 | 19 | end. 20 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager, System.Generics.Collections; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManagerDictionary: TObjectDictionary; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; overload; 23 | function objectManager (const aModel: string): TObjectManager; overload; 24 | {$ENDREGION} 25 | end; 26 | 27 | implementation 28 | 29 | uses 30 | System.SysUtils, Aurelius.Mapping.Explorer; 31 | 32 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 33 | begin 34 | Assert(aConnection <> nil); 35 | 36 | inherited Create; 37 | fConnection:=aConnection; 38 | fObjectManagerDictionary:=TObjectDictionary.Create([doOwnsValues]); 39 | end; 40 | 41 | function TDatabaseSession.databaseManager: TDatabaseManager; 42 | begin 43 | if not Assigned(fDatabaseManager) then 44 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 45 | Result:=fDatabaseManager; 46 | end; 47 | 48 | destructor TDatabaseSession.Destroy; 49 | begin 50 | fDatabaseManager.Free; 51 | fObjectManagerDictionary.Free; 52 | inherited; 53 | end; 54 | 55 | function TDatabaseSession.objectManager(const aModel: string): TObjectManager; 56 | var 57 | cModel: string; 58 | begin 59 | cModel:=Trim(UpperCase(aModel)); 60 | if cModel='' then 61 | Result:=objectManager 62 | else 63 | begin 64 | if not fObjectManagerDictionary.ContainsKey(cModel) then 65 | if cModel = 'DEFAULT' then 66 | fObjectManagerDictionary.Add('DEFAULT', TObjectManager.Create(fConnection)) 67 | else 68 | fObjectManagerDictionary.Add(cModel, 69 | TObjectManager.Create(fConnection, TMappingExplorer.Get(cModel))); 70 | Result:=fObjectManagerDictionary.Items[cModel]; 71 | end; 72 | end; 73 | 74 | function TDatabaseSession.objectManager: TObjectManager; 75 | begin 76 | result:=objectManager('default'); 77 | end; 78 | 79 | end. 80 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Database.Utilities.pas: -------------------------------------------------------------------------------- 1 | unit Database.Utilities; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.ObjectManager, FMX.Graphics, Aurelius.Types.Blob, 7 | Aurelius.Criteria.Base, Aurelius.Criteria.Linq, Aurelius.Criteria.Projections; 8 | 9 | type 10 | TDatabaseUtilities = class 11 | private 12 | public 13 | class procedure edit(const aObjManager: TObjectManager; const aEntity: T); 14 | class procedure bitmapToBlob (const aBmp: TBitmap; const aType: string; 15 | var aBlob: TBlob); 16 | class procedure blobToBitmap (const aBlob: TBlob; var aBmp: TBitmap); 17 | 18 | end; 19 | 20 | implementation 21 | 22 | uses 23 | Aurelius.Mapping.Attributes, FMX.Surfaces, System.Classes, System.SysUtils, 24 | System.DateUtils; 25 | 26 | { TDatabaseUtilities } 27 | 28 | class procedure TDatabaseUtilities.bitmapToBlob(const aBmp: TBitmap; 29 | const aType: string; var aBlob: TBlob); 30 | var 31 | bmp: TBitmapSurface; 32 | bs: TBytesStream; 33 | begin 34 | bmp := TBitmapSurface.create; 35 | try 36 | bmp.assign(aBmp); 37 | bs := TBytesStream.create; 38 | try 39 | TBitmapCodecManager.SaveToStream(bs, bmp, aType); 40 | aBlob.AsBytes := bs.Bytes; 41 | finally 42 | bs.free; 43 | end; 44 | finally 45 | bmp.free; 46 | end; 47 | 48 | end; 49 | 50 | class procedure TDatabaseUtilities.blobToBitmap(const aBlob: TBlob; 51 | var aBmp: TBitmap); 52 | var 53 | ms: TMemoryStream; 54 | begin 55 | Assert(aBmp <> nil); 56 | ms := TMemoryStream.create; 57 | try 58 | aBlob.SaveToStream(ms); 59 | MS.Position := 0; 60 | aBmp.LoadFromStream(ms); 61 | finally 62 | ms.free; 63 | end; 64 | end; 65 | 66 | class procedure TDatabaseUtilities.edit(const aObjManager: TObjectManager; 67 | const aEntity: T); 68 | begin 69 | Assert(aObjManager <> nil); 70 | Assert(aEntity <> nil); 71 | 72 | try 73 | aObjManager.SaveOrUpdate(aEntity); 74 | aObjManager.Flush(aEntity); 75 | except 76 | if not aObjManager.IsAttached(aEntity) then 77 | aEntity.Free; 78 | end; 79 | end; 80 | 81 | end. 82 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Forms/ImportFrame.fmx: -------------------------------------------------------------------------------- 1 | object FrameImport: TFrameImport 2 | Align = Client 3 | Size.Width = 530.000000000000000000 4 | Size.Height = 164.000000000000000000 5 | Size.PlatformDefault = False 6 | object Layout21: TLayout 7 | Align = Top 8 | Margins.Left = 10.000000000000000000 9 | Margins.Right = 10.000000000000000000 10 | Position.X = 10.000000000000000000 11 | Position.Y = 67.000000000000000000 12 | Size.Width = 510.000000000000000000 13 | Size.Height = 22.000000000000000000 14 | Size.PlatformDefault = False 15 | TabOrder = 1 16 | object btImport: TButton 17 | Align = Left 18 | Size.Width = 113.000000000000000000 19 | Size.Height = 22.000000000000000000 20 | Size.PlatformDefault = False 21 | TabOrder = 0 22 | Text = 'Import Data' 23 | end 24 | end 25 | object pbImport: TProgressBar 26 | Align = Top 27 | Orientation = Horizontal 28 | Margins.Left = 10.000000000000000000 29 | Margins.Right = 10.000000000000000000 30 | Margins.Bottom = 10.000000000000000000 31 | Position.X = 10.000000000000000000 32 | Position.Y = 37.000000000000000000 33 | Size.Width = 510.000000000000000000 34 | Size.Height = 20.000000000000000000 35 | Size.PlatformDefault = False 36 | end 37 | object lbImport: TLabel 38 | Align = Top 39 | Margins.Left = 10.000000000000000000 40 | Margins.Top = 10.000000000000000000 41 | Margins.Right = 10.000000000000000000 42 | Margins.Bottom = 5.000000000000000000 43 | Position.X = 10.000000000000000000 44 | Position.Y = 10.000000000000000000 45 | Size.Width = 510.000000000000000000 46 | Size.Height = 22.000000000000000000 47 | Size.PlatformDefault = False 48 | Text = 'Idle' 49 | TabOrder = 2 50 | end 51 | object lbTime: TLabel 52 | Align = Top 53 | StyledSettings = [Family, Size, FontColor] 54 | Margins.Left = 10.000000000000000000 55 | Margins.Top = 10.000000000000000000 56 | Margins.Right = 10.000000000000000000 57 | Margins.Bottom = 10.000000000000000000 58 | Position.X = 10.000000000000000000 59 | Position.Y = 99.000000000000000000 60 | Size.Width = 510.000000000000000000 61 | Size.Height = 17.000000000000000000 62 | Size.PlatformDefault = False 63 | TextSettings.Font.StyleExt = {00040000000200000004000000} 64 | Text = 'Not started yet' 65 | TabOrder = 3 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Events/Forms/ImportFrame.pas: -------------------------------------------------------------------------------- 1 | unit ImportFrame; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Controls.Presentation, FMX.Layouts; 9 | 10 | type 11 | TFrameImport = class(TFrame) 12 | Layout21: TLayout; 13 | btImport: TButton; 14 | pbImport: TProgressBar; 15 | lbImport: TLabel; 16 | lbTime: TLabel; 17 | private 18 | { Private declarations } 19 | public 20 | { Public declarations } 21 | end; 22 | 23 | implementation 24 | 25 | {$R *.fmx} 26 | 27 | end. 28 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 8 | Entities in 'Entities.pas', 9 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 10 | Database.Session in 'Database.Session.pas', 11 | Database.Session.Types in 'Database.Session.Types.pas', 12 | Database.Utilities in 'Database.Utilities.pas', 13 | ImportFrame in 'Forms\ImportFrame.pas' {FrameImport: TFrame}, 14 | Database.Import in 'Database.Import.pas'; 15 | 16 | {$R *.res} 17 | 18 | begin 19 | Application.Initialize; 20 | Application.CreateForm(TFormMain, FormMain); 21 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 22 | Application.Run; 23 | end. 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; overload; 14 | function objectManager (const aModel: string): TObjectManager; overload; 15 | end; 16 | 17 | implementation 18 | 19 | end. 20 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager, System.Generics.Collections; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManagerDictionary: TObjectDictionary; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; overload; 23 | function objectManager (const aModel: string): TObjectManager; overload; 24 | {$ENDREGION} 25 | end; 26 | 27 | implementation 28 | 29 | uses 30 | System.SysUtils, Aurelius.Mapping.Explorer; 31 | 32 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 33 | begin 34 | Assert(aConnection <> nil); 35 | 36 | inherited Create; 37 | fConnection:=aConnection; 38 | fObjectManagerDictionary:=TObjectDictionary.Create([doOwnsValues]); 39 | end; 40 | 41 | function TDatabaseSession.databaseManager: TDatabaseManager; 42 | begin 43 | if not Assigned(fDatabaseManager) then 44 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 45 | Result:=fDatabaseManager; 46 | end; 47 | 48 | destructor TDatabaseSession.Destroy; 49 | begin 50 | fDatabaseManager.Free; 51 | fObjectManagerDictionary.Free; 52 | inherited; 53 | end; 54 | 55 | function TDatabaseSession.objectManager(const aModel: string): TObjectManager; 56 | var 57 | cModel: string; 58 | begin 59 | cModel:=Trim(UpperCase(aModel)); 60 | if cModel='' then 61 | Result:=objectManager 62 | else 63 | begin 64 | if not fObjectManagerDictionary.ContainsKey(cModel) then 65 | if cModel = 'DEFAULT' then 66 | fObjectManagerDictionary.Add('DEFAULT', TObjectManager.Create(fConnection)) 67 | else 68 | fObjectManagerDictionary.Add(cModel, 69 | TObjectManager.Create(fConnection, TMappingExplorer.Get(cModel))); 70 | Result:=fObjectManagerDictionary.Items[cModel]; 71 | end; 72 | end; 73 | 74 | function TDatabaseSession.objectManager: TObjectManager; 75 | begin 76 | result:=objectManager('default'); 77 | end; 78 | 79 | end. 80 | 81 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/Database.Utilities.pas: -------------------------------------------------------------------------------- 1 | unit Database.Utilities; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.ObjectManager, FMX.Graphics, Aurelius.Types.Blob, 7 | Aurelius.Criteria.Base, Aurelius.Criteria.Linq, Aurelius.Criteria.Projections; 8 | 9 | type 10 | TDatabaseUtilities = class 11 | private 12 | public 13 | class procedure edit(const aObjManager: TObjectManager; const aEntity: T); 14 | class procedure bitmapToBlob (const aBmp: TBitmap; const aType: string; 15 | var aBlob: TBlob); 16 | class procedure blobToBitmap (const aBlob: TBlob; var aBmp: TBitmap); 17 | 18 | end; 19 | 20 | implementation 21 | 22 | uses 23 | Aurelius.Mapping.Attributes, FMX.Surfaces, System.Classes, System.SysUtils, 24 | System.DateUtils; 25 | 26 | { TDatabaseUtilities } 27 | 28 | class procedure TDatabaseUtilities.bitmapToBlob(const aBmp: TBitmap; 29 | const aType: string; var aBlob: TBlob); 30 | var 31 | bmp: TBitmapSurface; 32 | bs: TBytesStream; 33 | begin 34 | bmp := TBitmapSurface.create; 35 | try 36 | bmp.assign(aBmp); 37 | bs := TBytesStream.create; 38 | try 39 | TBitmapCodecManager.SaveToStream(bs, bmp, aType); 40 | aBlob.AsBytes := bs.Bytes; 41 | finally 42 | bs.free; 43 | end; 44 | finally 45 | bmp.free; 46 | end; 47 | 48 | end; 49 | 50 | class procedure TDatabaseUtilities.blobToBitmap(const aBlob: TBlob; 51 | var aBmp: TBitmap); 52 | var 53 | ms: TMemoryStream; 54 | begin 55 | Assert(aBmp <> nil); 56 | ms := TMemoryStream.create; 57 | try 58 | aBlob.SaveToStream(ms); 59 | MS.Position := 0; 60 | aBmp.LoadFromStream(ms); 61 | finally 62 | ms.free; 63 | end; 64 | end; 65 | 66 | class procedure TDatabaseUtilities.edit(const aObjManager: TObjectManager; 67 | const aEntity: T); 68 | begin 69 | Assert(aObjManager <> nil); 70 | Assert(aEntity <> nil); 71 | 72 | try 73 | aObjManager.SaveOrUpdate(aEntity); 74 | aObjManager.Flush(aEntity); 75 | except 76 | if not aObjManager.IsAttached(aEntity) then 77 | aEntity.Free; 78 | end; 79 | end; 80 | 81 | end. 82 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/Forms/ImportFrame.fmx: -------------------------------------------------------------------------------- 1 | object FrameImport: TFrameImport 2 | Align = Client 3 | Size.Width = 530.000000000000000000 4 | Size.Height = 164.000000000000000000 5 | Size.PlatformDefault = False 6 | object Layout21: TLayout 7 | Align = Top 8 | Margins.Left = 10.000000000000000000 9 | Margins.Right = 10.000000000000000000 10 | Position.X = 10.000000000000000000 11 | Position.Y = 67.000000000000000000 12 | Size.Width = 510.000000000000000000 13 | Size.Height = 22.000000000000000000 14 | Size.PlatformDefault = False 15 | TabOrder = 1 16 | object btImport: TButton 17 | Align = Left 18 | Size.Width = 113.000000000000000000 19 | Size.Height = 22.000000000000000000 20 | Size.PlatformDefault = False 21 | TabOrder = 0 22 | Text = 'Import Data' 23 | end 24 | end 25 | object pbImport: TProgressBar 26 | Align = Top 27 | Orientation = Horizontal 28 | Margins.Left = 10.000000000000000000 29 | Margins.Right = 10.000000000000000000 30 | Margins.Bottom = 10.000000000000000000 31 | Position.X = 10.000000000000000000 32 | Position.Y = 37.000000000000000000 33 | Size.Width = 510.000000000000000000 34 | Size.Height = 20.000000000000000000 35 | Size.PlatformDefault = False 36 | end 37 | object lbImport: TLabel 38 | Align = Top 39 | Margins.Left = 10.000000000000000000 40 | Margins.Top = 10.000000000000000000 41 | Margins.Right = 10.000000000000000000 42 | Margins.Bottom = 5.000000000000000000 43 | Position.X = 10.000000000000000000 44 | Position.Y = 10.000000000000000000 45 | Size.Width = 510.000000000000000000 46 | Size.Height = 22.000000000000000000 47 | Size.PlatformDefault = False 48 | Text = 'Idle' 49 | TabOrder = 2 50 | end 51 | object lbTime: TLabel 52 | Align = Top 53 | StyledSettings = [Family, Size, FontColor] 54 | Margins.Left = 10.000000000000000000 55 | Margins.Top = 10.000000000000000000 56 | Margins.Right = 10.000000000000000000 57 | Margins.Bottom = 10.000000000000000000 58 | Position.X = 10.000000000000000000 59 | Position.Y = 99.000000000000000000 60 | Size.Width = 510.000000000000000000 61 | Size.Height = 17.000000000000000000 62 | Size.PlatformDefault = False 63 | TextSettings.Font.StyleExt = {00040000000200000004000000} 64 | Text = 'Not started yet' 65 | TabOrder = 3 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - Inheritance/Forms/ImportFrame.pas: -------------------------------------------------------------------------------- 1 | unit ImportFrame; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Controls.Presentation, FMX.Layouts; 9 | 10 | type 11 | TFrameImport = class(TFrame) 12 | Layout21: TLayout; 13 | btImport: TButton; 14 | pbImport: TProgressBar; 15 | lbImport: TLabel; 16 | lbTime: TLabel; 17 | private 18 | { Private declarations } 19 | public 20 | { Public declarations } 21 | end; 22 | 23 | implementation 24 | 25 | {$R *.fmx} 26 | 27 | end. 28 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/AndroidManifest.template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | <%uses-permission%> 11 | 12 | 21 | 22 | <%provider%> 23 | <%application-meta-data%> 24 | <%services%> 25 | 27 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | <%activity%> 40 | <%receivers%> 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'Forms\MainForm.pas' {FormMain}, 7 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 8 | Entities in 'Entities.pas', 9 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 10 | Database.Session in 'Database.Session.pas', 11 | Database.Session.Types in 'Database.Session.Types.pas', 12 | Database.Utilities in 'Database.Utilities.pas', 13 | ImportFrame in 'Forms\ImportFrame.pas' {FrameImport: TFrame}, 14 | Database.Import in 'Database.Import.pas', 15 | Database.Events in 'Database.Events.pas', 16 | Database.Events.Types in 'Database.Events.Types.pas'; 17 | 18 | {$R *.res} 19 | 20 | begin 21 | Application.Initialize; 22 | Application.CreateForm(TFormMain, FormMain); 23 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 24 | Application.Run; 25 | end. 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Database.Events.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Events.Types; 2 | 3 | interface 4 | 5 | type 6 | IDatabaseEvents = interface 7 | ['{369927E5-976A-4263-9E66-31355C3E7C2C}'] 8 | procedure subscribeEvents; 9 | procedure unsubscribeEvents; 10 | end; 11 | 12 | implementation 13 | 14 | end. 15 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Database.Events.pas: -------------------------------------------------------------------------------- 1 | unit Database.Events; 2 | 3 | interface 4 | 5 | uses 6 | Database.Events.Types, 7 | Aurelius.Events.Manager; 8 | 9 | type 10 | TDatabaseEvents = class (TInterfacedObject, IDatabaseEvents) 11 | private 12 | fInsertingProc: TInsertingProc; 13 | fUpdatingProc: TUpdatingProc; 14 | public 15 | constructor Create; 16 | destructor Destroy; override; 17 | {$REGION 'Interface'} 18 | procedure subscribeEvents; 19 | procedure unsubscribeEvents; 20 | {$ENDREGION} 21 | 22 | end; 23 | 24 | implementation 25 | 26 | uses 27 | Entities, 28 | System.SysUtils, 29 | Aurelius.Mapping.Explorer; 30 | 31 | constructor TDatabaseEvents.Create; 32 | begin 33 | inherited; 34 | fInsertingProc:= procedure (Args: TInsertingArgs) 35 | begin 36 | if Args.Entity is TAgent then 37 | begin 38 | (Args.Entity as TAgent).CreateTS:=Now; 39 | end; 40 | end; 41 | fUpdatingProc:= procedure (Args: TUpdatingArgs) 42 | begin 43 | if Args.Entity is TAgent then 44 | begin 45 | (Args.Entity as TAgent).ModifyTS:=Now; 46 | Args.RecalculateState:=True; 47 | end; 48 | end; 49 | end; 50 | 51 | destructor TDatabaseEvents.Destroy; 52 | begin 53 | unsubscribeEvents; 54 | fInsertingProc:=nil; 55 | fUpdatingProc:=nil; 56 | inherited; 57 | end; 58 | 59 | procedure TDatabaseEvents.subscribeEvents; 60 | begin 61 | TMappingExplorer.Default.Events.OnInserting.Subscribe(fInsertingProc); 62 | TMappingExplorer.Default.Events.OnUpdating.Subscribe(fUpdatingProc); 63 | end; 64 | 65 | procedure TDatabaseEvents.unsubscribeEvents; 66 | begin 67 | TMappingExplorer.Default.Events.OnInserting.Unsubscribe(fInsertingProc); 68 | TMappingExplorer.Default.Events.OnUpdating.Unsubscribe(fUpdatingProc); 69 | end; 70 | 71 | end. 72 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; overload; 14 | function objectManager (const aModel: string): TObjectManager; overload; 15 | end; 16 | 17 | implementation 18 | 19 | end. 20 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager, System.Generics.Collections; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManagerDictionary: TObjectDictionary; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; overload; 23 | function objectManager (const aModel: string): TObjectManager; overload; 24 | {$ENDREGION} 25 | end; 26 | 27 | implementation 28 | 29 | uses 30 | System.SysUtils, Aurelius.Mapping.Explorer; 31 | 32 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 33 | begin 34 | Assert(aConnection <> nil); 35 | 36 | inherited Create; 37 | fConnection:=aConnection; 38 | fObjectManagerDictionary:=TObjectDictionary.Create([doOwnsValues]); 39 | end; 40 | 41 | function TDatabaseSession.databaseManager: TDatabaseManager; 42 | begin 43 | if not Assigned(fDatabaseManager) then 44 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 45 | Result:=fDatabaseManager; 46 | end; 47 | 48 | destructor TDatabaseSession.Destroy; 49 | begin 50 | fDatabaseManager.Free; 51 | fObjectManagerDictionary.Free; 52 | inherited; 53 | end; 54 | 55 | function TDatabaseSession.objectManager(const aModel: string): TObjectManager; 56 | var 57 | cModel: string; 58 | begin 59 | cModel:=Trim(UpperCase(aModel)); 60 | if cModel='' then 61 | Result:=objectManager 62 | else 63 | begin 64 | if not fObjectManagerDictionary.ContainsKey(cModel) then 65 | if cModel = 'DEFAULT' then 66 | fObjectManagerDictionary.Add('DEFAULT', TObjectManager.Create(fConnection)) 67 | else 68 | fObjectManagerDictionary.Add(cModel, 69 | TObjectManager.Create(fConnection, TMappingExplorer.Get(cModel))); 70 | Result:=fObjectManagerDictionary.Items[cModel]; 71 | end; 72 | end; 73 | 74 | function TDatabaseSession.objectManager: TObjectManager; 75 | begin 76 | result:=objectManager('default'); 77 | end; 78 | 79 | end. 80 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Database.Utilities.pas: -------------------------------------------------------------------------------- 1 | unit Database.Utilities; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.ObjectManager, FMX.Graphics, Aurelius.Types.Blob, 7 | Aurelius.Criteria.Base, Aurelius.Criteria.Linq, Aurelius.Criteria.Projections; 8 | 9 | type 10 | TDatabaseUtilities = class 11 | private 12 | public 13 | class procedure edit(const aObjManager: TObjectManager; const aEntity: T); 14 | class procedure bitmapToBlob (const aBmp: TBitmap; const aType: string; 15 | var aBlob: TBlob); 16 | class procedure blobToBitmap (const aBlob: TBlob; var aBmp: TBitmap); 17 | 18 | end; 19 | 20 | implementation 21 | 22 | uses 23 | Aurelius.Mapping.Attributes, FMX.Surfaces, System.Classes, System.SysUtils, 24 | System.DateUtils; 25 | 26 | { TDatabaseUtilities } 27 | 28 | class procedure TDatabaseUtilities.bitmapToBlob(const aBmp: TBitmap; 29 | const aType: string; var aBlob: TBlob); 30 | var 31 | bmp: TBitmapSurface; 32 | bs: TBytesStream; 33 | begin 34 | bmp := TBitmapSurface.create; 35 | try 36 | bmp.assign(aBmp); 37 | bs := TBytesStream.create; 38 | try 39 | TBitmapCodecManager.SaveToStream(bs, bmp, aType); 40 | aBlob.AsBytes := bs.Bytes; 41 | finally 42 | bs.free; 43 | end; 44 | finally 45 | bmp.free; 46 | end; 47 | 48 | end; 49 | 50 | class procedure TDatabaseUtilities.blobToBitmap(const aBlob: TBlob; 51 | var aBmp: TBitmap); 52 | var 53 | ms: TMemoryStream; 54 | begin 55 | Assert(aBmp <> nil); 56 | ms := TMemoryStream.create; 57 | try 58 | aBlob.SaveToStream(ms); 59 | MS.Position := 0; 60 | aBmp.LoadFromStream(ms); 61 | finally 62 | ms.free; 63 | end; 64 | end; 65 | 66 | class procedure TDatabaseUtilities.edit(const aObjManager: TObjectManager; 67 | const aEntity: T); 68 | begin 69 | Assert(aObjManager <> nil); 70 | Assert(aEntity <> nil); 71 | 72 | try 73 | aObjManager.SaveOrUpdate(aEntity); 74 | aObjManager.Flush(aEntity); 75 | except 76 | if not aObjManager.IsAttached(aEntity) then 77 | aEntity.Free; 78 | end; 79 | end; 80 | 81 | end. 82 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 37 | end; 38 | 39 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 40 | begin 41 | Result := TDBConnectionFactory.Create( 42 | function: IDBConnection 43 | begin 44 | Result := CreateConnection; 45 | end 46 | ); 47 | end; 48 | 49 | 50 | 51 | end. 52 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Forms/ImportFrame.fmx: -------------------------------------------------------------------------------- 1 | object FrameImport: TFrameImport 2 | Align = Client 3 | Size.Width = 530.000000000000000000 4 | Size.Height = 164.000000000000000000 5 | Size.PlatformDefault = False 6 | object Layout21: TLayout 7 | Align = Top 8 | Margins.Left = 10.000000000000000000 9 | Margins.Right = 10.000000000000000000 10 | Position.X = 10.000000000000000000 11 | Position.Y = 67.000000000000000000 12 | Size.Width = 510.000000000000000000 13 | Size.Height = 22.000000000000000000 14 | Size.PlatformDefault = False 15 | TabOrder = 1 16 | object btImport: TButton 17 | Align = Left 18 | Size.Width = 113.000000000000000000 19 | Size.Height = 22.000000000000000000 20 | Size.PlatformDefault = False 21 | TabOrder = 0 22 | Text = 'Import Data' 23 | end 24 | end 25 | object pbImport: TProgressBar 26 | Align = Top 27 | Orientation = Horizontal 28 | Margins.Left = 10.000000000000000000 29 | Margins.Right = 10.000000000000000000 30 | Margins.Bottom = 10.000000000000000000 31 | Position.X = 10.000000000000000000 32 | Position.Y = 37.000000000000000000 33 | Size.Width = 510.000000000000000000 34 | Size.Height = 20.000000000000000000 35 | Size.PlatformDefault = False 36 | end 37 | object lbImport: TLabel 38 | Align = Top 39 | Margins.Left = 10.000000000000000000 40 | Margins.Top = 10.000000000000000000 41 | Margins.Right = 10.000000000000000000 42 | Margins.Bottom = 5.000000000000000000 43 | Position.X = 10.000000000000000000 44 | Position.Y = 10.000000000000000000 45 | Size.Width = 510.000000000000000000 46 | Size.Height = 22.000000000000000000 47 | Size.PlatformDefault = False 48 | Text = 'Idle' 49 | TabOrder = 2 50 | end 51 | object lbTime: TLabel 52 | Align = Top 53 | StyledSettings = [Family, Size, FontColor] 54 | Margins.Left = 10.000000000000000000 55 | Margins.Top = 10.000000000000000000 56 | Margins.Right = 10.000000000000000000 57 | Margins.Bottom = 10.000000000000000000 58 | Position.X = 10.000000000000000000 59 | Position.Y = 99.000000000000000000 60 | Size.Width = 510.000000000000000000 61 | Size.Height = 17.000000000000000000 62 | Size.PlatformDefault = False 63 | TextSettings.Font.StyleExt = {00040000000200000004000000} 64 | Text = 'Not started yet' 65 | TabOrder = 3 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /Chapter 6/CallCentre - TAureliusDataset/Forms/ImportFrame.pas: -------------------------------------------------------------------------------- 1 | unit ImportFrame; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Controls.Presentation, FMX.Layouts; 9 | 10 | type 11 | TFrameImport = class(TFrame) 12 | Layout21: TLayout; 13 | btImport: TButton; 14 | pbImport: TProgressBar; 15 | lbImport: TLabel; 16 | lbTime: TLabel; 17 | private 18 | { Private declarations } 19 | public 20 | { Public declarations } 21 | end; 22 | 23 | implementation 24 | 25 | {$R *.fmx} 26 | 27 | end. 28 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/AndroidManifest.template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | <%uses-permission%> 11 | 12 | 21 | 22 | <%provider%> 23 | <%application-meta-data%> 24 | <%services%> 25 | 27 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | <%activity%> 40 | <%receivers%> 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/CallCentre.dpr: -------------------------------------------------------------------------------- 1 | program CallCentre; 2 | 3 | uses 4 | {$IFDEF EurekaLog} 5 | EMemLeaks, 6 | EResLeaks, 7 | EDialogWinAPIMSClassic, 8 | EDialogWinAPIEurekaLogDetailed, 9 | EDialogWinAPIStepsToReproduce, 10 | EDebugExports, 11 | EDebugJCL, 12 | EFixSafeCallException, 13 | EMapWin32, 14 | EAppFMX, 15 | ExceptionLog7, 16 | {$ENDIF EurekaLog} 17 | System.StartUpCopy, 18 | FMX.Forms, 19 | MainForm in 'Forms\MainForm.pas' {FormMain}, 20 | EntityForm in 'Forms\EntityForm.pas' {FormEntity}, 21 | Entities in 'Entities.pas', 22 | ConnectionModule in 'Forms\ConnectionModule.pas' {SQLiteConnection: TDataModule}, 23 | Database.Session in 'Database.Session.pas', 24 | Database.Session.Types in 'Database.Session.Types.pas', 25 | Database.Utilities in 'Database.Utilities.pas', 26 | ImportFrame in 'Forms\ImportFrame.pas' {FrameImport: TFrame}, 27 | Database.Import in 'Database.Import.pas', 28 | Database.Events in 'Database.Events.pas', 29 | Database.Events.Types in 'Database.Events.Types.pas', 30 | FileSelectForm in 'Forms\FileSelectForm.pas' {fmFileSelect}; 31 | 32 | {$R *.res} 33 | 34 | begin 35 | Application.Initialize; 36 | Application.CreateForm(TFormMain, FormMain); 37 | Application.CreateForm(TSQLiteConnection, SQLiteConnection); 38 | Application.Run; 39 | end. 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/CallCentre.eof: -------------------------------------------------------------------------------- 1 |  2 | 3 | [Exception Log] 4 | EurekaLog Version=8000 5 | _CustomProfile="" 6 | Activate=1 7 | atFixSafeCallException=1 8 | atFMX=1 9 | atWin32=1 10 | DeleteMapAfterCompile=0 11 | dpJCL=1 12 | Encrypt Password="" 13 | idEurekaLog=1 14 | idEurekaLogDetailed=1 15 | idMSClassic=1 16 | idStepsToReproduce=1 17 | InjectCode=1 18 | InjectInfo=1 19 | InjectOptions=1 20 | loEnableMMDebugMode=1 21 | ProjectID="{6CF4690D-0C33-49A5-AC22-F31196600102}" 22 | 23 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Database.Events.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Events.Types; 2 | 3 | interface 4 | 5 | type 6 | IDatabaseEvents = interface 7 | ['{369927E5-976A-4263-9E66-31355C3E7C2C}'] 8 | procedure subscribeEvents; 9 | procedure unsubscribeEvents; 10 | end; 11 | 12 | implementation 13 | 14 | end. 15 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Database.Events.pas: -------------------------------------------------------------------------------- 1 | unit Database.Events; 2 | 3 | interface 4 | 5 | uses 6 | Database.Events.Types, 7 | Aurelius.Events.Manager; 8 | 9 | type 10 | TDatabaseEvents = class (TInterfacedObject, IDatabaseEvents) 11 | private 12 | fInsertingProc: TInsertingProc; 13 | fUpdatingProc: TUpdatingProc; 14 | public 15 | constructor Create; 16 | destructor Destroy; override; 17 | {$REGION 'Interface'} 18 | procedure subscribeEvents; 19 | procedure unsubscribeEvents; 20 | {$ENDREGION} 21 | 22 | end; 23 | 24 | implementation 25 | 26 | uses 27 | Entities, 28 | System.SysUtils, 29 | Aurelius.Mapping.Explorer; 30 | 31 | constructor TDatabaseEvents.Create; 32 | begin 33 | inherited; 34 | fInsertingProc:= procedure (Args: TInsertingArgs) 35 | begin 36 | if Args.Entity is TAgent then 37 | begin 38 | (Args.Entity as TAgent).CreateTS:=Now; 39 | end; 40 | end; 41 | fUpdatingProc:= procedure (Args: TUpdatingArgs) 42 | begin 43 | if Args.Entity is TAgent then 44 | begin 45 | (Args.Entity as TAgent).ModifyTS:=Now; 46 | Args.RecalculateState:=True; 47 | end; 48 | end; 49 | end; 50 | 51 | destructor TDatabaseEvents.Destroy; 52 | begin 53 | unsubscribeEvents; 54 | fInsertingProc:=nil; 55 | fUpdatingProc:=nil; 56 | inherited; 57 | end; 58 | 59 | procedure TDatabaseEvents.subscribeEvents; 60 | begin 61 | TMappingExplorer.Default.Events.OnInserting.Subscribe(fInsertingProc); 62 | TMappingExplorer.Default.Events.OnUpdating.Subscribe(fUpdatingProc); 63 | end; 64 | 65 | procedure TDatabaseEvents.unsubscribeEvents; 66 | begin 67 | TMappingExplorer.Default.Events.OnInserting.Unsubscribe(fInsertingProc); 68 | TMappingExplorer.Default.Events.OnUpdating.Unsubscribe(fUpdatingProc); 69 | end; 70 | 71 | end. 72 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Database.Session.Types.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session.Types; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.DatabaseManager, 7 | Aurelius.Engine.ObjectManager; 8 | 9 | type 10 | IDatabaseSession = interface 11 | ['{7CA1B4A1-F339-47EE-AE17-9436853A618E}'] 12 | function databaseManager: TDatabaseManager; 13 | function objectManager: TObjectManager; overload; 14 | function objectManager (const aModel: string): TObjectManager; overload; 15 | end; 16 | 17 | implementation 18 | 19 | end. 20 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Database.Session.pas: -------------------------------------------------------------------------------- 1 | unit Database.Session; 2 | 3 | interface 4 | 5 | uses 6 | Database.Session.Types, 7 | Aurelius.Engine.DatabaseManager, 8 | Aurelius.Drivers.Interfaces, 9 | Aurelius.Engine.ObjectManager, System.Generics.Collections; 10 | 11 | type 12 | TDatabaseSession = class (TInterfacedObject, IDatabaseSession) 13 | private 14 | fConnection: IDBConnection; 15 | fDatabaseManager: TDatabaseManager; 16 | fObjectManagerDictionary: TObjectDictionary; 17 | public 18 | constructor Create(const aConnection: IDBConnection); 19 | destructor Destroy; override; 20 | {$REGION 'Interface'} 21 | function databaseManager: TDatabaseManager; 22 | function objectManager: TObjectManager; overload; 23 | function objectManager (const aModel: string): TObjectManager; overload; 24 | {$ENDREGION} 25 | end; 26 | 27 | implementation 28 | 29 | uses 30 | System.SysUtils, Aurelius.Mapping.Explorer; 31 | 32 | constructor TDatabaseSession.Create(const aConnection: IDBConnection); 33 | begin 34 | Assert(aConnection <> nil); 35 | 36 | inherited Create; 37 | fConnection:=aConnection; 38 | fObjectManagerDictionary:=TObjectDictionary.Create([doOwnsValues]); 39 | end; 40 | 41 | function TDatabaseSession.databaseManager: TDatabaseManager; 42 | begin 43 | if not Assigned(fDatabaseManager) then 44 | fDatabaseManager:=TDatabaseManager.Create(fConnection); 45 | Result:=fDatabaseManager; 46 | end; 47 | 48 | destructor TDatabaseSession.Destroy; 49 | begin 50 | fDatabaseManager.Free; 51 | fObjectManagerDictionary.Free; 52 | inherited; 53 | end; 54 | 55 | function TDatabaseSession.objectManager(const aModel: string): TObjectManager; 56 | var 57 | cModel: string; 58 | begin 59 | cModel:=Trim(UpperCase(aModel)); 60 | if cModel='' then 61 | Result:=objectManager 62 | else 63 | begin 64 | if not fObjectManagerDictionary.ContainsKey(cModel) then 65 | if cModel = 'DEFAULT' then 66 | fObjectManagerDictionary.Add('DEFAULT', TObjectManager.Create(fConnection)) 67 | else 68 | fObjectManagerDictionary.Add(cModel, 69 | TObjectManager.Create(fConnection, TMappingExplorer.Get(cModel))); 70 | Result:=fObjectManagerDictionary.Items[cModel]; 71 | end; 72 | end; 73 | 74 | function TDatabaseSession.objectManager: TObjectManager; 75 | begin 76 | result:=objectManager('default'); 77 | end; 78 | 79 | end. 80 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Database.Utilities.pas: -------------------------------------------------------------------------------- 1 | unit Database.Utilities; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.ObjectManager, FMX.Graphics, Aurelius.Types.Blob, 7 | Aurelius.Criteria.Base, Aurelius.Criteria.Linq, Aurelius.Criteria.Projections; 8 | 9 | type 10 | TDatabaseUtilities = class 11 | private 12 | public 13 | class procedure edit(const aObjManager: TObjectManager; const aEntity: T); 14 | class procedure bitmapToBlob (const aBmp: TBitmap; const aType: string; 15 | var aBlob: TBlob); 16 | class procedure blobToBitmap (const aBlob: TBlob; var aBmp: TBitmap); 17 | 18 | end; 19 | 20 | implementation 21 | 22 | uses 23 | Aurelius.Mapping.Attributes, FMX.Surfaces, System.Classes, System.SysUtils, 24 | System.DateUtils; 25 | 26 | { TDatabaseUtilities } 27 | 28 | class procedure TDatabaseUtilities.bitmapToBlob(const aBmp: TBitmap; 29 | const aType: string; var aBlob: TBlob); 30 | var 31 | bmp: TBitmapSurface; 32 | bs: TBytesStream; 33 | begin 34 | bmp := TBitmapSurface.create; 35 | try 36 | bmp.assign(aBmp); 37 | bs := TBytesStream.create; 38 | try 39 | TBitmapCodecManager.SaveToStream(bs, bmp, aType); 40 | aBlob.AsBytes := bs.Bytes; 41 | finally 42 | bs.free; 43 | end; 44 | finally 45 | bmp.free; 46 | end; 47 | 48 | end; 49 | 50 | class procedure TDatabaseUtilities.blobToBitmap(const aBlob: TBlob; 51 | var aBmp: TBitmap); 52 | var 53 | ms: TMemoryStream; 54 | begin 55 | Assert(aBmp <> nil); 56 | ms := TMemoryStream.create; 57 | try 58 | aBlob.SaveToStream(ms); 59 | MS.Position := 0; 60 | aBmp.LoadFromStream(ms); 61 | finally 62 | ms.free; 63 | end; 64 | end; 65 | 66 | class procedure TDatabaseUtilities.edit(const aObjManager: TObjectManager; 67 | const aEntity: T); 68 | begin 69 | Assert(aObjManager <> nil); 70 | Assert(aEntity <> nil); 71 | 72 | try 73 | aObjManager.SaveOrUpdate(aEntity); 74 | aObjManager.Flush(aEntity); 75 | except 76 | if not aObjManager.IsAttached(aEntity) then 77 | aEntity.Free; 78 | end; 79 | end; 80 | 81 | end. 82 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Forms/AgentForm.fmx: -------------------------------------------------------------------------------- 1 | object formAgent: TformAgent 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 198 6 | ClientWidth = 528 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | DesignerMasterStyle = 0 11 | object lbTitle: TLabel 12 | Align = Top 13 | StyledSettings = [Family, FontColor] 14 | Margins.Left = 10.000000000000000000 15 | Margins.Top = 10.000000000000000000 16 | Margins.Right = 10.000000000000000000 17 | Margins.Bottom = 5.000000000000000000 18 | Position.X = 10.000000000000000000 19 | Position.Y = 10.000000000000000000 20 | Size.Width = 508.000000000000000000 21 | Size.Height = 49.000000000000000000 22 | Size.PlatformDefault = False 23 | TextSettings.Font.Size = 28.000000000000000000 24 | TextSettings.Font.StyleExt = {00070000000000000004000000} 25 | Text = 'lbTitle' 26 | TabOrder = 0 27 | end 28 | object Layout1: TLayout 29 | Align = Top 30 | Margins.Left = 10.000000000000000000 31 | Margins.Right = 10.000000000000000000 32 | Margins.Bottom = 5.000000000000000000 33 | Position.X = 10.000000000000000000 34 | Position.Y = 64.000000000000000000 35 | Size.Width = 508.000000000000000000 36 | Size.Height = 105.000000000000000000 37 | Size.PlatformDefault = False 38 | TabOrder = 1 39 | object Label1: TLabel 40 | StyledSettings = [Family, FontColor] 41 | Position.X = 16.000000000000000000 42 | Position.Y = 16.000000000000000000 43 | Size.Width = 49.000000000000000000 44 | Size.Height = 33.000000000000000000 45 | Size.PlatformDefault = False 46 | TextSettings.Font.Size = 16.000000000000000000 47 | TextSettings.Font.StyleExt = {00070000000000000004000000} 48 | Text = 'ID' 49 | TabOrder = 1 50 | end 51 | object edCode: TEdit 52 | Touch.InteractiveGestures = [LongTap, DoubleTap] 53 | TabOrder = 3 54 | ReadOnly = True 55 | Position.X = 104.000000000000000000 56 | Position.Y = 16.000000000000000000 57 | Enabled = False 58 | Size.Width = 100.000000000000000000 59 | Size.Height = 33.000000000000000000 60 | Size.PlatformDefault = False 61 | end 62 | object edEntity: TEdit 63 | Touch.InteractiveGestures = [LongTap, DoubleTap] 64 | TabOrder = 2 65 | Position.X = 104.000000000000000000 66 | Position.Y = 64.000000000000000000 67 | Size.Width = 393.000000000000000000 68 | Size.Height = 33.000000000000000000 69 | Size.PlatformDefault = False 70 | end 71 | object Label2: TLabel 72 | StyledSettings = [Family, FontColor] 73 | Position.X = 16.000000000000000000 74 | Position.Y = 64.000000000000000000 75 | Size.Width = 49.000000000000000000 76 | Size.Height = 33.000000000000000000 77 | Size.PlatformDefault = False 78 | TextSettings.Font.Size = 16.000000000000000000 79 | TextSettings.Font.StyleExt = {00070000000000000004000000} 80 | Text = 'Entity' 81 | TabOrder = 0 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Forms/AgentForm.pas: -------------------------------------------------------------------------------- 1 | unit AgentForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TformAgent = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | Label1: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | Label2: TLabel; 18 | private 19 | { Private declarations } 20 | public 21 | { Public declarations } 22 | end; 23 | 24 | var 25 | formAgent: TformAgent; 26 | 27 | implementation 28 | 29 | {$R *.fmx} 30 | 31 | end. 32 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Forms/ConnectionModule.dfm: -------------------------------------------------------------------------------- 1 | object SQLiteConnection: TSQLiteConnection 2 | OldCreateOrder = True 3 | Height = 198 4 | Width = 282 5 | object AureliusConnection1: TAureliusConnection 6 | DriverName = 'SQLite' 7 | Params.Strings = ( 8 | 'Database=.\database.db') 9 | Left = 64 10 | Top = 64 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Forms/ConnectionModule.pas: -------------------------------------------------------------------------------- 1 | unit ConnectionModule; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Drivers.Interfaces, 7 | Aurelius.Drivers.SQLite, 8 | System.SysUtils, System.Classes, Aurelius.Comp.Connection; 9 | 10 | type 11 | TSQLiteConnection = class(TDataModule) 12 | AureliusConnection1: TAureliusConnection; 13 | private 14 | public 15 | class function CreateConnection: IDBConnection; 16 | class function CreateFactory: IDBConnectionFactory; 17 | 18 | end; 19 | 20 | var 21 | SQLiteConnection: TSQLiteConnection; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'FMX.Controls.TControl'} 26 | 27 | uses 28 | Aurelius.Drivers.Base, System.IOUtils; 29 | 30 | {$R *.dfm} 31 | 32 | { TMyConnectionModule } 33 | 34 | class function TSQLiteConnection.CreateConnection: IDBConnection; 35 | begin 36 | {$IFDEF ANDROID} 37 | SQLiteConnection.AureliusConnection1.Params.Values['Database']:= 38 | TPath.Combine(TPath.GetDocumentsPath, 'database.db'); 39 | {$ENDIF} 40 | Result := SQLiteConnection.AureliusConnection1.CreateConnection; 41 | end; 42 | 43 | class function TSQLiteConnection.CreateFactory: IDBConnectionFactory; 44 | begin 45 | Result := TDBConnectionFactory.Create( 46 | function: IDBConnection 47 | begin 48 | Result := CreateConnection; 49 | end 50 | ); 51 | end; 52 | 53 | 54 | 55 | end. 56 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Forms/EntityForm.pas: -------------------------------------------------------------------------------- 1 | unit EntityForm; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, 8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit; 9 | 10 | type 11 | TFormEntity = class(TForm) 12 | lbTitle: TLabel; 13 | Layout1: TLayout; 14 | lbID: TLabel; 15 | edCode: TEdit; 16 | edEntity: TEdit; 17 | lbEntity: TLabel; 18 | Layout2: TLayout; 19 | btCancel: TButton; 20 | btAction: TButton; 21 | procedure edEntityChangeTracking(Sender: TObject); 22 | private 23 | { Private declarations } 24 | public 25 | { Public declarations } 26 | end; 27 | 28 | implementation 29 | 30 | {$R *.fmx} 31 | 32 | procedure TFormEntity.edEntityChangeTracking(Sender: TObject); 33 | begin 34 | btAction.Enabled:= Trim(edEntity.Text) <> ''; 35 | end; 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Forms/ImportFrame.fmx: -------------------------------------------------------------------------------- 1 | object FrameImport: TFrameImport 2 | Align = Client 3 | Size.Width = 530.000000000000000000 4 | Size.Height = 164.000000000000000000 5 | Size.PlatformDefault = False 6 | object Layout21: TLayout 7 | Align = Top 8 | Margins.Left = 10.000000000000000000 9 | Margins.Right = 10.000000000000000000 10 | Position.X = 10.000000000000000000 11 | Position.Y = 67.000000000000000000 12 | Size.Width = 510.000000000000000000 13 | Size.Height = 22.000000000000000000 14 | Size.PlatformDefault = False 15 | TabOrder = 1 16 | object btImport: TButton 17 | Align = Left 18 | Size.Width = 113.000000000000000000 19 | Size.Height = 22.000000000000000000 20 | Size.PlatformDefault = False 21 | TabOrder = 0 22 | Text = 'Import Data' 23 | end 24 | end 25 | object pbImport: TProgressBar 26 | Align = Top 27 | Orientation = Horizontal 28 | Margins.Left = 10.000000000000000000 29 | Margins.Right = 10.000000000000000000 30 | Margins.Bottom = 10.000000000000000000 31 | Position.X = 10.000000000000000000 32 | Position.Y = 37.000000000000000000 33 | Size.Width = 510.000000000000000000 34 | Size.Height = 20.000000000000000000 35 | Size.PlatformDefault = False 36 | end 37 | object lbImport: TLabel 38 | Align = Top 39 | Margins.Left = 10.000000000000000000 40 | Margins.Top = 10.000000000000000000 41 | Margins.Right = 10.000000000000000000 42 | Margins.Bottom = 5.000000000000000000 43 | Position.X = 10.000000000000000000 44 | Position.Y = 10.000000000000000000 45 | Size.Width = 510.000000000000000000 46 | Size.Height = 22.000000000000000000 47 | Size.PlatformDefault = False 48 | Text = 'Idle' 49 | TabOrder = 2 50 | end 51 | object lbTime: TLabel 52 | Align = Top 53 | StyledSettings = [Family, Size, FontColor] 54 | Margins.Left = 10.000000000000000000 55 | Margins.Top = 10.000000000000000000 56 | Margins.Right = 10.000000000000000000 57 | Margins.Bottom = 10.000000000000000000 58 | Position.X = 10.000000000000000000 59 | Position.Y = 99.000000000000000000 60 | Size.Width = 510.000000000000000000 61 | Size.Height = 17.000000000000000000 62 | Size.PlatformDefault = False 63 | TextSettings.Font.StyleExt = {00040000000200000004000000} 64 | Text = 'Not started yet' 65 | TabOrder = 3 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /Chapter 7/CallCentre - Local/Forms/ImportFrame.pas: -------------------------------------------------------------------------------- 1 | unit ImportFrame; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, 8 | FMX.Controls.Presentation, FMX.Layouts; 9 | 10 | type 11 | TFrameImport = class(TFrame) 12 | Layout21: TLayout; 13 | btImport: TButton; 14 | pbImport: TProgressBar; 15 | lbImport: TLabel; 16 | lbTime: TLabel; 17 | private 18 | { Private declarations } 19 | public 20 | { Public declarations } 21 | end; 22 | 23 | implementation 24 | 25 | {$R *.fmx} 26 | 27 | end. 28 | -------------------------------------------------------------------------------- /Chapter 7/Client/AndroidManifest.template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | <%uses-permission%> 11 | 12 | 21 | 22 | <%provider%> 23 | <%application-meta-data%> 24 | <%services%> 25 | 27 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | <%activity%> 40 | <%receivers%> 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Chapter 7/Client/AureliusClient.dpr: -------------------------------------------------------------------------------- 1 | program AureliusClient; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainForm in 'MainForm.pas' {FormMain}, 7 | Entities in 'Entities.pas'; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.CreateForm(TFormMain, FormMain); 14 | Application.Run; 15 | end. 16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter 7/User/User.dpr: -------------------------------------------------------------------------------- 1 | program User; 2 | 3 | {$APPTYPE CONSOLE} 4 | 5 | {$R *.res} 6 | 7 | uses 8 | System.SysUtils, 9 | IdHTTP, 10 | Entities in 'Entities.pas', 11 | Bcl.Json; 12 | 13 | var 14 | idHTTP: TIdHTTP; 15 | newUser: TUsers; 16 | response: string; 17 | begin 18 | ReportMemoryLeaksOnShutdown:=True; 19 | try 20 | idHTTP:=TIdHTTP.Create(nil); 21 | response:=idHTTP.Get('http://jsonplaceholder.typicode.com/users/1'); 22 | newUser:=TJSON.Deserialize(response); 23 | 24 | newUser.address.geo.Free; 25 | newUser.address.Free; 26 | newUser.company.Free; 27 | 28 | newUser.Free; 29 | 30 | idHTTP.Free; 31 | 32 | except 33 | on E: Exception do 34 | Writeln(E.ClassName, ': ', E.Message); 35 | end; 36 | end. 37 | -------------------------------------------------------------------------------- /Chapter 7/XData/Client.dpr: -------------------------------------------------------------------------------- 1 | program Client; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | MainClient in 'MainClient.pas' {FormMain}, 7 | Entities in 'Entities.pas', 8 | Database.Utilities in 'Database.Utilities.pas'; 9 | 10 | {$R *.res} 11 | 12 | begin 13 | Application.Initialize; 14 | Application.CreateForm(TFormMain, FormMain); 15 | Application.Run; 16 | end. 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter 7/XData/Container.dfm: -------------------------------------------------------------------------------- 1 | object ServerContainer: TServerContainer 2 | OldCreateOrder = False 3 | Height = 210 4 | Width = 431 5 | object SparkleHttpSysDispatcher: TSparkleHttpSysDispatcher 6 | Active = True 7 | Left = 72 8 | Top = 16 9 | end 10 | object XDataServer: TXDataServer 11 | BaseUrl = 'http://+:2001/callcentre' 12 | Dispatcher = SparkleHttpSysDispatcher 13 | Pool = XDataConnectionPool 14 | DefaultEntitySetPermissions = [List, Get] 15 | EntitySetPermissions = <> 16 | Left = 216 17 | Top = 16 18 | end 19 | object XDataConnectionPool: TXDataConnectionPool 20 | Connection = AureliusConnection 21 | Left = 216 22 | Top = 72 23 | end 24 | object AureliusConnection: TAureliusConnection 25 | DriverName = 'SQLite' 26 | Params.Strings = ( 27 | 'Database=..\..\database.db') 28 | Left = 216 29 | Top = 128 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /Chapter 7/XData/Container.pas: -------------------------------------------------------------------------------- 1 | unit Container; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Classes, Sparkle.HttpServer.Module, 7 | Sparkle.HttpServer.Context, Sparkle.Comp.Server, 8 | Sparkle.Comp.HttpSysDispatcher, Aurelius.Drivers.Interfaces, 9 | Aurelius.Comp.Connection, XData.Comp.ConnectionPool, XData.Server.Module, 10 | XData.Comp.Server, Aurelius.Drivers.SQLite; 11 | 12 | type 13 | TServerContainer = class(TDataModule) 14 | SparkleHttpSysDispatcher: TSparkleHttpSysDispatcher; 15 | XDataServer: TXDataServer; 16 | XDataConnectionPool: TXDataConnectionPool; 17 | AureliusConnection: TAureliusConnection; 18 | end; 19 | 20 | var 21 | ServerContainer: TServerContainer; 22 | 23 | implementation 24 | 25 | {%CLASSGROUP 'Vcl.Controls.TControl'} 26 | 27 | {$R *.dfm} 28 | 29 | end. 30 | -------------------------------------------------------------------------------- /Chapter 7/XData/Database.Utilities.pas: -------------------------------------------------------------------------------- 1 | unit Database.Utilities; 2 | 3 | interface 4 | 5 | uses 6 | Aurelius.Engine.ObjectManager, FMX.Graphics, Aurelius.Types.Blob, 7 | Aurelius.Criteria.Base, Aurelius.Criteria.Linq, Aurelius.Criteria.Projections; 8 | 9 | type 10 | TDatabaseUtilities = class 11 | private 12 | public 13 | class procedure edit(const aObjManager: TObjectManager; const aEntity: T); 14 | class procedure bitmapToBlob (const aBmp: TBitmap; const aType: string; 15 | var aBlob: TBlob); 16 | class procedure blobToBitmap (const aBlob: TBlob; var aBmp: TBitmap); 17 | 18 | end; 19 | 20 | implementation 21 | 22 | uses 23 | Aurelius.Mapping.Attributes, FMX.Surfaces, System.Classes, System.SysUtils, 24 | System.DateUtils; 25 | 26 | { TDatabaseUtilities } 27 | 28 | class procedure TDatabaseUtilities.bitmapToBlob(const aBmp: TBitmap; 29 | const aType: string; var aBlob: TBlob); 30 | var 31 | bmp: TBitmapSurface; 32 | bs: TBytesStream; 33 | begin 34 | bmp := TBitmapSurface.create; 35 | try 36 | bmp.assign(aBmp); 37 | bs := TBytesStream.create; 38 | try 39 | TBitmapCodecManager.SaveToStream(bs, bmp, aType); 40 | aBlob.AsBytes := bs.Bytes; 41 | finally 42 | bs.free; 43 | end; 44 | finally 45 | bmp.free; 46 | end; 47 | 48 | end; 49 | 50 | class procedure TDatabaseUtilities.blobToBitmap(const aBlob: TBlob; 51 | var aBmp: TBitmap); 52 | var 53 | ms: TMemoryStream; 54 | begin 55 | Assert(aBmp <> nil); 56 | ms := TMemoryStream.create; 57 | try 58 | aBlob.SaveToStream(ms); 59 | MS.Position := 0; 60 | aBmp.LoadFromStream(ms); 61 | finally 62 | ms.free; 63 | end; 64 | end; 65 | 66 | class procedure TDatabaseUtilities.edit(const aObjManager: TObjectManager; 67 | const aEntity: T); 68 | begin 69 | Assert(aObjManager <> nil); 70 | Assert(aEntity <> nil); 71 | 72 | try 73 | aObjManager.SaveOrUpdate(aEntity); 74 | aObjManager.Flush; 75 | except 76 | if not aObjManager.IsAttached(aEntity) then 77 | aEntity.Free; 78 | end; 79 | end; 80 | 81 | end. 82 | -------------------------------------------------------------------------------- /Chapter 7/XData/Main.dfm: -------------------------------------------------------------------------------- 1 | object MainForm: TMainForm 2 | Left = 0 3 | Top = 0 4 | Caption = 'TMS XData Server' 5 | ClientHeight = 242 6 | ClientWidth = 472 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnCreate = FormCreate 15 | DesignSize = ( 16 | 472 17 | 242) 18 | PixelsPerInch = 96 19 | TextHeight = 13 20 | object mmInfo: TMemo 21 | Left = 8 22 | Top = 40 23 | Width = 456 24 | Height = 194 25 | Anchors = [akLeft, akTop, akRight, akBottom] 26 | ReadOnly = True 27 | TabOrder = 0 28 | end 29 | object btStart: TButton 30 | Left = 8 31 | Top = 8 32 | Width = 75 33 | Height = 25 34 | Caption = 'Start' 35 | TabOrder = 1 36 | OnClick = btStartClick 37 | end 38 | object btStop: TButton 39 | Left = 90 40 | Top = 8 41 | Width = 75 42 | Height = 25 43 | Caption = 'Stop' 44 | TabOrder = 2 45 | OnClick = btStopClick 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /Chapter 7/XData/Main.pas: -------------------------------------------------------------------------------- 1 | unit Main; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, 7 | System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, 8 | Vcl.StdCtrls, Container; 9 | 10 | type 11 | TMainForm = class(TForm) 12 | mmInfo: TMemo; 13 | btStart: TButton; 14 | btStop: TButton; 15 | procedure btStartClick(ASender: TObject); 16 | procedure btStopClick(ASender: TObject); 17 | procedure FormCreate(ASender: TObject); 18 | strict private 19 | procedure UpdateGUI; 20 | end; 21 | 22 | var 23 | MainForm: TMainForm; 24 | 25 | implementation 26 | 27 | {$R *.dfm} 28 | 29 | resourcestring 30 | SServerStopped = 'Server stopped'; 31 | SServerStartedAt = 'Server started at '; 32 | 33 | { TMainForm } 34 | 35 | procedure TMainForm.btStartClick(ASender: TObject); 36 | begin 37 | ServerContainer.SparkleHttpSysDispatcher.Start; 38 | UpdateGUI; 39 | end; 40 | 41 | procedure TMainForm.btStopClick(ASender: TObject); 42 | begin 43 | ServerContainer.SparkleHttpSysDispatcher.Stop; 44 | UpdateGUI; 45 | end; 46 | 47 | procedure TMainForm.FormCreate(ASender: TObject); 48 | begin 49 | UpdateGUI; 50 | end; 51 | 52 | procedure TMainForm.UpdateGUI; 53 | const 54 | cHttp = 'http://+'; 55 | cHttpLocalhost = 'http://localhost'; 56 | begin 57 | btStart.Enabled := not ServerContainer.SparkleHttpSysDispatcher.Active; 58 | btStop.Enabled := not btStart.Enabled; 59 | if ServerContainer.SparkleHttpSysDispatcher.Active then 60 | mmInfo.Lines.Add(SServerStartedAt + StringReplace( 61 | ServerContainer.XDataServer.BaseUrl, 62 | cHttp, cHttpLocalhost, [rfIgnoreCase])) 63 | else 64 | mmInfo.Lines.Add(SServerStopped); 65 | end; 66 | 67 | end. 68 | -------------------------------------------------------------------------------- /Chapter 7/XData/MainServer.dfm: -------------------------------------------------------------------------------- 1 | object MainForm: TMainForm 2 | Left = 0 3 | Top = 0 4 | Caption = 'TMS XData Server' 5 | ClientHeight = 242 6 | ClientWidth = 472 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -11 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | OnCreate = FormCreate 15 | DesignSize = ( 16 | 472 17 | 242) 18 | PixelsPerInch = 96 19 | TextHeight = 13 20 | object mmInfo: TMemo 21 | Left = 8 22 | Top = 40 23 | Width = 456 24 | Height = 194 25 | Anchors = [akLeft, akTop, akRight, akBottom] 26 | ReadOnly = True 27 | TabOrder = 0 28 | end 29 | object btStart: TButton 30 | Left = 8 31 | Top = 8 32 | Width = 75 33 | Height = 25 34 | Caption = 'Start' 35 | TabOrder = 1 36 | OnClick = btStartClick 37 | end 38 | object btStop: TButton 39 | Left = 90 40 | Top = 8 41 | Width = 75 42 | Height = 25 43 | Caption = 'Stop' 44 | TabOrder = 2 45 | OnClick = btStopClick 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /Chapter 7/XData/MainServer.pas: -------------------------------------------------------------------------------- 1 | unit MainServer; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, 7 | System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, 8 | Vcl.StdCtrls, Container; 9 | 10 | type 11 | TMainForm = class(TForm) 12 | mmInfo: TMemo; 13 | btStart: TButton; 14 | btStop: TButton; 15 | procedure btStartClick(ASender: TObject); 16 | procedure btStopClick(ASender: TObject); 17 | procedure FormCreate(ASender: TObject); 18 | strict private 19 | procedure UpdateGUI; 20 | end; 21 | 22 | var 23 | MainForm: TMainForm; 24 | 25 | implementation 26 | 27 | {$R *.dfm} 28 | 29 | resourcestring 30 | SServerStopped = 'Server stopped'; 31 | SServerStartedAt = 'Server started at '; 32 | 33 | { TMainForm } 34 | 35 | procedure TMainForm.btStartClick(ASender: TObject); 36 | begin 37 | ServerContainer.SparkleHttpSysDispatcher.Start; 38 | UpdateGUI; 39 | end; 40 | 41 | procedure TMainForm.btStopClick(ASender: TObject); 42 | begin 43 | ServerContainer.SparkleHttpSysDispatcher.Stop; 44 | UpdateGUI; 45 | end; 46 | 47 | procedure TMainForm.FormCreate(ASender: TObject); 48 | begin 49 | UpdateGUI; 50 | end; 51 | 52 | procedure TMainForm.UpdateGUI; 53 | const 54 | cHttp = 'http://+'; 55 | cHttpLocalhost = 'http://localhost'; 56 | begin 57 | btStart.Enabled := not ServerContainer.SparkleHttpSysDispatcher.Active; 58 | btStop.Enabled := not btStart.Enabled; 59 | if ServerContainer.SparkleHttpSysDispatcher.Active then 60 | mmInfo.Lines.Add(SServerStartedAt + StringReplace( 61 | ServerContainer.XDataServer.BaseUrl, 62 | cHttp, cHttpLocalhost, [rfIgnoreCase])) 63 | else 64 | mmInfo.Lines.Add(SServerStopped); 65 | end; 66 | 67 | end. 68 | -------------------------------------------------------------------------------- /Chapter 7/XData/Server.dpr: -------------------------------------------------------------------------------- 1 | program Server; 2 | 3 | uses 4 | Vcl.Forms, 5 | Container in 'Container.pas' {ServerContainer: TDataModule}, 6 | MainServer in 'MainServer.pas' {MainForm}, 7 | Entities in 'Entities.pas'; 8 | 9 | {$R *.res} 10 | 11 | begin 12 | Application.Initialize; 13 | Application.MainFormOnTaskbar := True; 14 | Application.CreateForm(TServerContainer, ServerContainer); 15 | Application.CreateForm(TMainForm, MainForm); 16 | Application.Run; 17 | end. 18 | -------------------------------------------------------------------------------- /Chapter 7/XData/XData.groupproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {217A3762-B4ED-4D79-A6A6-2293BC5FB164} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Default.Personality.12 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Chapter 7/XData/database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/introducing-delphi-orm/f1e146ef70bbe5f3e28615ccc03e2001682162fb/Chapter 7/XData/database.db -------------------------------------------------------------------------------- /Chapter 8/DataModelerScript.pas: -------------------------------------------------------------------------------- 1 | procedure OnClassGenerated(Args: TClassGeneratedArgs); 2 | var 3 | field: TCodeTypeMember; 4 | attr: TCodeAttributeDeclaration; 5 | i: integer; 6 | begin 7 | if Args.CodeType.Name = 'TAgent' then 8 | begin 9 | // Add the Base class 10 | Args.CodeType.BaseType:=TCodeTypeReference.Create('TBase'); 11 | 12 | // Remove the ID Field 13 | for i:=Args.CodeType.Members.Count - 1 downto 0 do 14 | begin 15 | field:=Args.CodeType.Members.Items[i]; 16 | if field.Name='FID' then 17 | begin 18 | Args.CodeType.Members.Delete(i); 19 | break; 20 | end; 21 | end; 22 | 23 | // Remove the ID property 24 | for i:=Args.CodeType.Members.Count - 1 downto 0 do 25 | begin 26 | field:=Args.CodeType.Members.Items[i]; 27 | if field.Name='ID' then 28 | begin 29 | Args.CodeType.Members.Delete(i); 30 | break; 31 | end; 32 | end; 33 | 34 | // Remove the ID Attribute 35 | for i:=Args.CodeType.CustomAttributes.Count - 1 downto 0 do 36 | begin 37 | attr:=Args.CodeType.CustomAttributes.Items[i]; 38 | if attr.Name='Id' then 39 | begin 40 | Args.CodeType.CustomAttributes.Delete(i); 41 | break; 42 | end; 43 | end; 44 | 45 | end; 46 | if Args.CodeType.Name = 'TBase' then 47 | begin 48 | Args.CodeType.AddAttribute('Inheritance').AddRawArgument('TInheritanceStrategy.JoinedTables'); 49 | end; 50 | end; -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! -------------------------------------------------------------------------------- /GitCommitWritingStyle.txt: -------------------------------------------------------------------------------- 1 | Git Commit Writing Guide 2 | Git commit messages follow the general guidelines widely available (atomic commits, imperative writing style, etc.) 3 | 4 | In addition, commits can use the following semantics: 5 | 6 | Commit Element Equivalent Commit Message Example 7 | + Add + methods to calculate ratios 8 | - Remove - redundant calls to API 9 | * Update * project files 10 | Dolphins Used to describe that the commit has 11 | some necessary changes but nothing 12 | relevant (eg. a blank line was added, 13 | the newly saved file has rearranged 14 | elements in the settings file, etc.) 15 | 16 | Use this when the modified files in the 17 | commit have just "indescribable" changes 18 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Freeware License, some rights reserved 2 | 3 | Copyright (c) 2019 John Kouraklis 4 | 5 | Permission is hereby granted, free of charge, to anyone obtaining a copy 6 | of this software and associated documentation files (the "Software"), 7 | to work with the Software within the limits of freeware distribution and fair use. 8 | This includes the rights to use, copy, and modify the Software for personal use. 9 | Users are also allowed and encouraged to submit corrections and modifications 10 | to the Software for the benefit of other users. 11 | 12 | It is not allowed to reuse, modify, or redistribute the Software for 13 | commercial use in any way, or for a user’s educational materials such as books 14 | or blog articles without prior permission from the copyright holder. 15 | 16 | The above copyright notice and this permission notice need to be included 17 | in all copies or substantial portions of the software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | 27 | 28 | -------------------------------------------------------------------------------- /Misc/AbandonRatePerDepartment.sql: -------------------------------------------------------------------------------- 1 | CREATE VIEW IF NOT EXISTS AbandonRatePerDepartment AS Select 2 | Call.ID, 3 | 4 | Week, 5 | 6 | Department.Description, 7 | 8 | (Count( case 9 | when QueueExitTime is null then 1 10 | end ) * 100.0 ) / count(*) as AbandonRate 11 | 12 | FROM 13 | Call 14 | 15 | INNER JOIN 16 | Department 17 | 18 | ON Call.DepartmentID = Department.ID 19 | 20 | GROUP BY 21 | Week, 22 | Department.ID 23 | 24 | ORDER BY 25 | Week, 26 | Department.Description; -------------------------------------------------------------------------------- /Misc/OverallStatisticsViewScript.sql: -------------------------------------------------------------------------------- 1 | CREATE VIEW IF NOT EXISTS OverallStatistics AS select 2 | 3 | Week, 4 | 5 | avg(SatisfactionScore) as SatisfactionScore, 6 | 7 | Count(*) as TotalCalls, 8 | 9 | (Avg( case 10 | when QueueExitTime is not null then QueueExitTime - QueueEntryTime 11 | end )) as AnswerSpeed, 12 | 13 | (Count( case 14 | when QueueExitTime is null then 1 15 | end ) * 100.0 ) / count(*) as AbandonRate, 16 | 17 | (Count(*) / 9.00 / 60.00) as CallsMinute, 18 | 19 | (Count ( case 20 | when (QueueExitTime is not null) and ((QueueExitTime - QueueEntryTime) < 0.00208333333333333) then 1 21 | end )) as CallsLess180, 22 | 23 | (Count( case 24 | when SatisfactionScore < 3 then 1 25 | end )) as CallsLess3, 26 | 27 | (Count( case 28 | when SatisfactionScore < 3 then 1 29 | end ) * 100.0 / count(*) ) as CallsLess3Perc 30 | 31 | FROM 32 | Call 33 | 34 | GROUP BY 35 | Week; -------------------------------------------------------------------------------- /Misc/avatar-female.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/introducing-delphi-orm/f1e146ef70bbe5f3e28615ccc03e2001682162fb/Misc/avatar-female.png -------------------------------------------------------------------------------- /Misc/avatar-male.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/introducing-delphi-orm/f1e146ef70bbe5f3e28615ccc03e2001682162fb/Misc/avatar-male.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | This repository accompanies [*Introducing Delphi ORM*](https://www.apress.com/9781484250129) by John Kouraklis (Apress, 2019). 4 | 5 | [comment]: #cover 6 | ![Cover image](9781484250129.jpg) 7 | 8 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 9 | 10 | ## Releases 11 | 12 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 13 | 14 | ## Contributions 15 | 16 | See the file Contributing.md for more information on how you can contribute to this repository. -------------------------------------------------------------------------------- /errata.md: -------------------------------------------------------------------------------- 1 | # Errata for *Book Title* 2 | 3 | On **page xx** [Summary of error]: 4 | 5 | Details of error here. Highlight key pieces in **bold**. 6 | 7 | *** 8 | 9 | On **page xx** [Summary of error]: 10 | 11 | Details of error here. Highlight key pieces in **bold**. 12 | 13 | *** --------------------------------------------------------------------------------