Index: VerpakkingsDefinitie/UI/GebruikerScherm.dfm =================================================================== diff -u --- VerpakkingsDefinitie/UI/GebruikerScherm.dfm (revision 0) +++ VerpakkingsDefinitie/UI/GebruikerScherm.dfm (revision 555) @@ -0,0 +1,57 @@ +object FormGebruiker: TFormGebruiker + Left = 0 + Top = 0 + BorderStyle = bsNone + Caption = 'FormGebruiker' + ClientHeight = 40 + ClientWidth = 584 + Color = 1513421 + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + OldCreateOrder = False + OnCreate = FormCreate + OnDestroy = FormDestroy + DesignSize = ( + 584 + 40) + PixelsPerInch = 96 + TextHeight = 13 + object LabelGebruikersnaam: TLabel + Left = 8 + Top = 8 + Width = 134 + Height = 19 + Caption = 'Gebruikersnaam' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWhite + Font.Height = -16 + Font.Name = 'Tahoma' + Font.Style = [fsBold] + ParentFont = False + end + object PanelLogIn: TPanel + Left = 484 + Top = 4 + Width = 92 + Height = 28 + Anchors = [akTop, akRight] + BevelEdges = [] + BevelOuter = bvSpace + BiDiMode = bdLeftToRight + Caption = 'LOG UIT' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWhite + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [fsBold] + ParentBiDiMode = False + ParentFont = False + TabOrder = 0 + OnClick = PanelLogInClick + OnMouseDown = PanelLogInMouseDown + OnMouseUp = PanelLogInMouseUp + end +end Index: VerpakkingsDefinitie/VerpakkingsDefinitie.dproj =================================================================== diff -u -r553 -r555 --- VerpakkingsDefinitie/VerpakkingsDefinitie.dproj (.../VerpakkingsDefinitie.dproj) (revision 553) +++ VerpakkingsDefinitie/VerpakkingsDefinitie.dproj (.../VerpakkingsDefinitie.dproj) (revision 555) @@ -70,6 +70,9 @@ true + true + true + true true 1033 false @@ -98,6 +101,11 @@
FormZoekProducten
+ +
FormGebruiker
+ dfm +
+ Cfg_2 Base Index: VerpakkingsDefinitie/Main.pas =================================================================== diff -u -r554 -r555 --- VerpakkingsDefinitie/Main.pas (.../Main.pas) (revision 554) +++ VerpakkingsDefinitie/Main.pas (.../Main.pas) (revision 555) @@ -1,7 +1,7 @@ unit Main; interface - + { TODO -cnavigatie : NavigeerNaar in interface zetten ter abstractie voor subschermen } uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, @@ -35,7 +35,7 @@ implementation uses - Subscherm, LogInScherm, ZoekProductenScherm; + Subscherm, LogInScherm, ZoekProductenScherm, GebruikerScherm; {$R *.dfm} @@ -67,7 +67,6 @@ Application.ProcessMessages; // Interrupts the execution of an application so that it can process the message queue. // Volgende subscherm laden in panel - { TODO -cNavigatie : Huidige schermen verwijderen (indien nodig) met Controls property } // PanelMain behouden we altijd, the children can be free. for i := 0 to PanelMain.ControlCount - 1 do @@ -84,7 +83,7 @@ // Schermen op GridPanel plaatsen // PlaatsControlOpGrid(GridPanel; Control; RowI; ColI; (opt) RowSpan; (opt)ColSpan); // Gebruikersgegevens scherm bovenaan. - NieuweGridControl := TFormLogin.Create(GridPanel, Self, FAppContext, FAgent); + NieuweGridControl := TFormGebruiker.Create(GridPanel, Self, FAppContext, FAppContext.UserServerServiceContext, FAgent); PlaatsControlOpGrid(GridPanel, NieuweGridControl, 0, 0, 1, 2); // Zoekscherm daaronder links NieuweGridControl := TFormZoekProducten.Create(GridPanel, Self, FAppContext); Index: VerpakkingsDefinitie/UI/GebruikerScherm.pas =================================================================== diff -u --- VerpakkingsDefinitie/UI/GebruikerScherm.pas (revision 0) +++ VerpakkingsDefinitie/UI/GebruikerScherm.pas (revision 555) @@ -0,0 +1,81 @@ +unit GebruikerScherm; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, + ObserverPattern, + Agent, Main, ApplicationContext, Subscherm; + +type + TFormGebruiker = class(TFormSubscherm) + LabelGebruikersnaam: TLabel; + PanelLogIn: TPanel; + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); + procedure PanelLogInMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); + procedure PanelLogInMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); + procedure PanelLogInClick(Sender: TObject); + private + FGebruikerSubject: TSubject; + FGebruikerSubjectObserver: TSubjectObserver; + FUserAgent: TAgent; + procedure UpdateGui(Sender: TObject); + public + Constructor Create(AOwner: TComponent; Navigator: TFormMain; ApplicationContext: TApplicationContext; + GebruikerSubject: TSubject; UserAgent: TAgent); + end; + +implementation + +{$R *.dfm} + +constructor TFormGebruiker.Create(AOwner: TComponent; Navigator: TFormMain; ApplicationContext: TApplicationContext; + GebruikerSubject: TSubject; UserAgent: TAgent); +begin + inherited Create(AOwner, Navigator, ApplicationContext); + self.FGebruikerSubject := GebruikerSubject; + self.FGebruikerSubjectObserver := TSubjectObserver.Create(self); + self.FGebruikerSubjectObserver.OnChange := UpdateGui; + self.FUserAgent := UserAgent; +end; + +procedure TFormGebruiker.FormCreate(Sender: TObject); +begin + FGebruikerSubject.RegisterObserver(FGebruikerSubjectObserver); +end; + +procedure TFormGebruiker.FormDestroy(Sender: TObject); +begin + FGebruikerSubject.UnregisterObserver(FGebruikerSubjectObserver); +end; + +procedure TFormGebruiker.UpdateGui(Sender: TObject); +begin + // Update with data from ApplicationContext + LabelGebruikersnaam.Caption := self.ApplicationContext.UserServerServiceContext.GebruikersNaam; +end; + +// Indrukken van button simuleren op panel: http://www.festra.com/wwwboard/messages/1006.html +procedure TFormGebruiker.PanelLogInClick(Sender: TObject); +begin + try + FUserAgent.GebruikerAfmelden(self.ApplicationContext.UserServerServiceContext); + finally + // Als logout mislukt, gewoon naar inlog scherm gaan. De gebruiker kan dan opnieuw inloggen. + self.Navigator.NavigeerNaar(Main.NAVLOGIN); + end; +end; + +procedure TFormGebruiker.PanelLogInMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); +begin + (Sender as TPanel).BevelOuter := bvLowered; +end; + +procedure TFormGebruiker.PanelLogInMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); +begin + (Sender as TPanel).BevelOuter := bvRaised; +end; + +end. Index: VerpakkingsDefinitie/UI/Subscherm.pas =================================================================== diff -u -r552 -r555 --- VerpakkingsDefinitie/UI/Subscherm.pas (.../Subscherm.pas) (revision 552) +++ VerpakkingsDefinitie/UI/Subscherm.pas (.../Subscherm.pas) (revision 555) @@ -17,7 +17,7 @@ FApplicationContext: TApplicationContext; protected property Navigator: TFormMain Read FNavigator write FNavigator; - property ApplicationContextObj: TApplicationContext Read FApplicationContext write FApplicationContext; + property ApplicationContext: TApplicationContext Read FApplicationContext write FApplicationContext; public Constructor Create(AOwner: TComponent; Navigator: TFormMain; ApplicationContext: TApplicationContext); overload; end; @@ -29,7 +29,7 @@ inherited Create(AOwner); Self.Navigator := Navigator; - Self.ApplicationContextObj := ApplicationContext; + Self.ApplicationContext := ApplicationContext; BorderStyle := bsNone; // Subschermen hebben geen border end; Index: VerpakkingsDefinitie/ApplicationContext.pas =================================================================== diff -u -r551 -r555 --- VerpakkingsDefinitie/ApplicationContext.pas (.../ApplicationContext.pas) (revision 551) +++ VerpakkingsDefinitie/ApplicationContext.pas (.../ApplicationContext.pas) (revision 555) @@ -7,11 +7,14 @@ interface +uses + ObserverPattern; + // SUB CONTEXTS: klassen die overeenkomen met bepaalde sub-context (bv. alles gerelateerd met authenticatie). // - UserServerService type - TUserServerServiceContext = class + TUserServerServiceContext = class(TSubject) private FSessionKey: string; FGebruikersNaam: string; @@ -20,6 +23,7 @@ FErrorMessage: string; FInternalErrorMessage: string; public + procedure Changed(); property SessionKey: string read FSessionKey write FSessionKey; property GebruikersNaam: string read FGebruikersNaam write FGebruikersNaam; property IsOK: Boolean read FIsOK write FIsOK; @@ -31,14 +35,19 @@ // Application context bevat alle sub-contexts TApplicationContext = class private - FUserServerServiceContext: TUserServerServiceContext; + FUserServerServiceContext: TUserServerServiceContext; public constructor Create(); property UserServerServiceContext: TUserServerServiceContext read FUserServerServiceContext write FUserServerServiceContext; end; implementation +procedure TUserServerServiceContext.Changed(); +begin + self.Change(); +end; + constructor TApplicationContext.Create(); begin FUserServerServiceContext := TUserServerServiceContext.Create(); Index: VerpakkingsDefinitie/VerpakkingsDefinitie.dpr =================================================================== diff -u -r553 -r555 --- VerpakkingsDefinitie/VerpakkingsDefinitie.dpr (.../VerpakkingsDefinitie.dpr) (revision 553) +++ VerpakkingsDefinitie/VerpakkingsDefinitie.dpr (.../VerpakkingsDefinitie.dpr) (revision 555) @@ -9,7 +9,9 @@ Subscherm in 'UI\Subscherm.pas', UserServerService in 'WS\UserServerService.pas', ZoekProductenScherm in 'UI\ZoekProductenScherm.pas' {FormZoekProducten}, - Util in 'UI\Util.pas'; + Util in 'UI\Util.pas', + GebruikerScherm in 'UI\GebruikerScherm.pas' {FormGebruiker}, + ObserverPattern in 'UI\ObserverPattern.pas'; {$R *.res} Index: VerpakkingsDefinitie/UI/ObserverPattern.pas =================================================================== diff -u --- VerpakkingsDefinitie/UI/ObserverPattern.pas (revision 0) +++ VerpakkingsDefinitie/UI/ObserverPattern.pas (revision 555) @@ -0,0 +1,83 @@ +// Based on: https://sourcemaking.com/design_patterns/observer/delphi +unit ObserverPattern; + +interface + +uses + System.Classes; + +type + TSubjectObserver = class(TComponent) + private + FEnabled: Boolean; + FOnChange: TNotifyEvent; + protected + procedure Change; + public + constructor Create(AOwner: TComponent); + published + property Enabled: Boolean read FEnabled write FEnabled; + property OnChange: TNotifyEvent read FOnChange write FOnChange; + end; + + TSubject = class(TObject) + private + FObservers: TList; + protected + procedure Change; // Call this method to dispatch change + public + constructor Create(); + procedure RegisterObserver(Observer: TSubjectObserver); + procedure UnregisterObserver(Observer: TSubjectObserver); + end; + +implementation + +constructor TSubjectObserver.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + self.FEnabled := True; +end; + +procedure TSubjectObserver.Change; +begin + if Assigned(FOnChange) then + FOnChange(self); +end; + +constructor TSubject.Create(); +begin + inherited Create(); + FObservers := TList.Create(); +end; + +procedure TSubject.Change; +var + Obs: TSubjectObserver; + I: Integer; +begin + for I := 0 to FObservers.Count - 1 do + begin + Obs := FObservers[I]; + if Obs.Enabled then + Obs.Change; + end; +end; + +procedure TSubject.RegisterObserver(Observer: TSubjectObserver); +begin + if FObservers.IndexOf(Observer) = -1 then + begin + FObservers.Add(Observer); + // Update nieuwe observer + if Observer.Enabled then + Observer.Change; + end; +end; + +procedure TSubject.UnregisterObserver(Observer: TSubjectObserver); +begin + FObservers.Remove(Observer); +end; + +end. Index: VerpakkingsDefinitie/UI/LogInScherm.pas =================================================================== diff -u -r552 -r555 --- VerpakkingsDefinitie/UI/LogInScherm.pas (.../LogInScherm.pas) (revision 552) +++ VerpakkingsDefinitie/UI/LogInScherm.pas (.../LogInScherm.pas) (revision 555) @@ -28,7 +28,6 @@ procedure Login(); public Constructor Create(AOwner: TComponent; Navigator: TFormMain; ApplicationContext: TApplicationContext; Agent: TAgent); - overload; end; implementation @@ -96,19 +95,19 @@ var ErrorMessage: string; begin - FAgent.GebruikerAanmelden(EditGebruikersnaam.Text, EditWachtwoord.Text, ApplicationContextObj.UserServerServiceContext); + FAgent.GebruikerAanmelden(EditGebruikersnaam.Text, EditWachtwoord.Text, ApplicationContext.UserServerServiceContext); - if ApplicationContextObj.UserServerServiceContext.IsOK then + if ApplicationContext.UserServerServiceContext.IsOK then begin (self.Navigator as TFormMain).NavigeerNaar(Main.NAVZOEKPRODUCTEN); end else begin // Login gefaald - ErrorMessage := ApplicationContextObj.UserServerServiceContext.ErrorMessage; - if ApplicationContextObj.UserServerServiceContext.InternalErrorMessage <> '' then + ErrorMessage := ApplicationContext.UserServerServiceContext.ErrorMessage; + if ApplicationContext.UserServerServiceContext.InternalErrorMessage <> '' then begin - ErrorMessage := ErrorMessage + sLineBreak + ApplicationContextObj.UserServerServiceContext.InternalErrorMessage; + ErrorMessage := ErrorMessage + sLineBreak + ApplicationContext.UserServerServiceContext.InternalErrorMessage; end; if MessageDlg(ErrorMessage, TMsgDlgType.mtInformation, [mbRetry, mbCancel], 0, mbCancel) = mrRetry then Index: VerpakkingsDefinitie/UI/LogInScherm.dfm =================================================================== diff -u -r554 -r555 --- VerpakkingsDefinitie/UI/LogInScherm.dfm (.../LogInScherm.dfm) (revision 554) +++ VerpakkingsDefinitie/UI/LogInScherm.dfm (.../LogInScherm.dfm) (revision 555) @@ -72,7 +72,6 @@ Anchors = [akTop] TabOrder = 0 OnChange = EditGebruikersnaamChange - ExplicitLeft = 19 end object EditWachtwoord: TEdit Left = 23 @@ -81,7 +80,6 @@ Height = 21 Anchors = [akTop] TabOrder = 1 - ExplicitLeft = 19 end object PanelLogIn: TPanel Left = 57 @@ -104,6 +102,5 @@ OnClick = PanelLogInClick OnMouseDown = PanelLogInMouseDown OnMouseUp = PanelLogInMouseUp - ExplicitLeft = 53 end end Index: VerpakkingsDefinitie/UI/ZoekProductenScherm.dfm =================================================================== diff -u -r554 -r555 --- VerpakkingsDefinitie/UI/ZoekProductenScherm.dfm (.../ZoekProductenScherm.dfm) (revision 554) +++ VerpakkingsDefinitie/UI/ZoekProductenScherm.dfm (.../ZoekProductenScherm.dfm) (revision 555) @@ -32,12 +32,8 @@ Font.Style = [] ParentFont = False TabOrder = 0 - ExplicitWidth = 839 - ExplicitHeight = 625 object TabSheetKortTekst: TTabSheet Caption = 'Kort tekst' - ExplicitWidth = 831 - ExplicitHeight = 597 object Label1: TLabel Left = 3 Top = 16 Index: VerpakkingsDefinitie/Main.dfm =================================================================== diff -u -r554 -r555 --- VerpakkingsDefinitie/Main.dfm (.../Main.dfm) (revision 554) +++ VerpakkingsDefinitie/Main.dfm (.../Main.dfm) (revision 555) @@ -29,7 +29,5 @@ ParentShowHint = False ShowHint = True TabOrder = 0 - ExplicitWidth = 497 - ExplicitHeight = 441 end end Index: VerpakkingsDefinitie/WS/Agent.pas =================================================================== diff -u -r552 -r555 --- VerpakkingsDefinitie/WS/Agent.pas (.../Agent.pas) (revision 552) +++ VerpakkingsDefinitie/WS/Agent.pas (.../Agent.pas) (revision 555) @@ -3,7 +3,7 @@ interface uses SysUtils, - ApplicationContext, UserServerService; + ObserverPattern, ApplicationContext, UserServerService; // Resource strings are stored as resources and linked into the executable or // library so that they can be modified without recompiling the program. @@ -78,6 +78,8 @@ UserServerServiceContext.SessionKey := pxLogInObj.SessionKey; UserServerServiceContext.GebruikersNaam := pxLogInObj.GebruikersNaam; + + UserServerServiceContext.Changed(); end; procedure TAgent.RegistreerMislukteLogin(UserServerServiceContext: TUserServerServiceContext; pxStatusObj: pxStatus); @@ -89,6 +91,8 @@ UserServerServiceContext.IsOK := pxStatusObj.IsOK; UserServerServiceContext.ErrorMessage := pxStatusObj.Message_; UserServerServiceContext.InternalErrorMessage := pxStatusObj.InternalMessage; + + UserServerServiceContext.Changed(); end; procedure TAgent.GebruikerAfmelden(UserServerServiceContext: TUserServerServiceContext); @@ -133,13 +137,17 @@ UserServerServiceContext.InternalErrorMessage := ''; UserServerServiceContext.SessionKey := ''; UserServerServiceContext.GebruikersNaam := ''; + + UserServerServiceContext.Changed(); end; procedure TAgent.RegistreerMislukteLogout(UserServerServiceContext: TUserServerServiceContext; pxStatusObj: pxStatus); begin UserServerServiceContext.IsOK := pxStatusObj.IsOK; UserServerServiceContext.ErrorMessage := pxStatusObj.Message_; UserServerServiceContext.InternalErrorMessage := pxStatusObj.InternalMessage; + + UserServerServiceContext.Changed(); end; end.