unit ApplicationContext; // Dit is een klasse bedoeld om data te delen over de applicatie heen. // Dit kan bijvoorbeeld usernaam, login token, computernaam, ... // Informatie die elk component/klasse kan gebruiken. // Voor schaalbaarheid en isolatie worden interfaces gebruikt die deze klasse implementeert. interface uses ObserverPattern, System.Generics.Collections, OptiServerService, SysUtils; // SUB CONTEXTS: klassen die overeenkomen met bepaalde sub-context (bv. alles gerelateerd met authenticatie). // - User type TUserContext = class(TSubject) private FSessionKey: string; FGebruikersNaam: string; FIsOK: Boolean; FErrorMessage: string; FInternalErrorMessage: string; public procedure NotifyChanged(); property SessionKey: string read FSessionKey write FSessionKey; property GebruikersNaam: string read FGebruikersNaam write FGebruikersNaam; property IsOK: Boolean read FIsOK write FIsOK; property ErrorMessage: string read FErrorMessage write FErrorMessage; property InternalErrorMessage: string read FInternalErrorMessage write FInternalErrorMessage; end; // - Product Selection TProductInformatie = class private FProductNr: Integer; FTekst: string; FKol1: string; FKol2: string; FKol3: string; FKol4: string; function GetOmschrijving1(): string; function GetOmschrijving2(): string; public property ProductNr: Integer read FProductNr write FProductNr; property Tekst: string read FTekst write FTekst; property Kol1: string read FKol1 write FKol1; property Kol2: string read FKol2 write FKol2; property Kol3: string read FKol3 write FKol3; property Kol4: string read FKol4 write FKol4; property Omschrijving1: string read GetOmschrijving1; property Omschrijving2: string read GetOmschrijving2; end; TProductsContext = class(TSubject) private FProducten: TList; FIsOK: Boolean; FErrorMessage: string; FInternalErrorMessage: string; public constructor Create(); procedure Reset(); procedure NotifyChanged(); property Producten: TList read FProducten write FProducten; property IsOK: Boolean read FIsOK write FIsOK; property ErrorMessage: string read FErrorMessage write FErrorMessage; property InternalErrorMessage: string read FInternalErrorMessage write FInternalErrorMessage; end; // - Product Detail // TProductDetailInformatie = class() // end; TProductDetailContext = class(TSubject) private FGeselecteerdProduct: TProductInformatie; FProductDetailInformatie: OptiServerService.pxBoxData; FIsOK: Boolean; FErrorMessage: string; FInternalErrorMessage: string; public procedure NotifyChanged(); procedure Reset(); property GeselecteerdProduct: TProductInformatie read FGeselecteerdProduct write FGeselecteerdProduct; property ProductDetailInformatie: OptiServerService.pxBoxData read FProductDetailInformatie write FProductDetailInformatie; property IsOK: Boolean read FIsOK write FIsOK; property ErrorMessage: string read FErrorMessage write FErrorMessage; property InternalErrorMessage: string read FInternalErrorMessage write FInternalErrorMessage; end; // APPLICATION CONTEXT // Application context bevat alle sub-contexts TApplicationContext = class private FUserContext: TUserContext; FProductsContext: TProductsContext; FProductDetailContext: TProductDetailContext; public constructor Create(); property UserContext: TUserContext read FUserContext write FUserContext; property ProductsContext: TProductsContext read FProductsContext write FProductsContext; property ProductDetailContext: TProductDetailContext read FProductDetailContext write FProductDetailContext; end; implementation // USER procedure TUserContext.NotifyChanged(); begin self.Change(); end; // PRODUCT constructor TProductsContext.Create(); begin inherited Create(); FProducten := TList.Create(); end; // Enkel updaten wanneer nog niet op nil stond. procedure TProductsContext.Reset(); begin if FProducten.Count > 0 then begin FProducten.Clear(); NotifyChanged(); end; end; function TProductInformatie.GetOmschrijving1(): string; var S: string; begin if FKol4 = '' then begin Result := ''; end else begin try Result := copy(FKol4, 0, Pos(',', FKol4) - 1); except Result := ''; end; end; end; function TProductInformatie.GetOmschrijving2(): string; begin if FKol4 = '' then begin Result := ''; end else begin try Result := copy(FKol4, Pos(',', FKol4) + 2); Result := copy(Result, 0, Pos(',', Result) - 1); // Tweede deel na de komma except Result := ''; end; end; end; procedure TProductsContext.NotifyChanged(); begin self.Change(); end; // PRODUCT DETAIL procedure TProductDetailContext.NotifyChanged(); begin self.Change(); end; // Enkel updaten wanneer nog niet op nil stond. procedure TProductDetailContext.Reset(); begin if (GeselecteerdProduct <> nil) or (ProductDetailInformatie <> nil) then begin GeselecteerdProduct := nil; ProductDetailInformatie := nil; NotifyChanged(); end; end; // APPLICATION CONTEXT constructor TApplicationContext.Create(); begin FUserContext := TUserContext.Create(); FProductsContext := TProductsContext.Create(); FProductDetailContext := TProductDetailContext.Create(); end; end.