Index: VerpakkingsDefinitie/WS/ProductsAgent.pas =================================================================== diff -u -r590 -r591 --- VerpakkingsDefinitie/WS/ProductsAgent.pas (.../ProductsAgent.pas) (revision 590) +++ VerpakkingsDefinitie/WS/ProductsAgent.pas (.../ProductsAgent.pas) (revision 591) @@ -26,19 +26,19 @@ function GeefBruikbareLijnenUitXMLDataSet(DataSetXml: string): TStringList; procedure RegistreerZoekResultaten(ProductsContext: TProductsContext; DataSet: string); overload; procedure RegistreerMislukteOpzoeking(ProductsContext: TProductsContext; pxStatusObj: SelectService.pxStatus); overload; - procedure RegistreerZoekResultaten(ProductDetailContext: TProductDetailContext; + procedure RegistreerZoekResultaten(ProductDetailContext: TProductVerpakkingContext; pxBoxDataObj: OptiServerService.pxBoxData); overload; - procedure RegistreerMislukteOpzoeking(ProductDetailContext: TProductDetailContext; + procedure RegistreerMislukteOpzoeking(ProductDetailContext: TProductVerpakkingContext; pxStatusObj: OptiServerService.pxStatus); overload; - function GetBoxDataIDsViaProduct(ProductNr: Integer; UserContext: TUserContext; ProductDetailContext: TProductDetailContext) + function GetBoxDataIDsViaProduct(ProductNr: Integer; UserContext: TUserContext; ProductDetailContext: TProductVerpakkingContext) : TList; public Constructor Create(); procedure LaadUIInstellingen(UserContext: TUserContext; UiInstellingenContext: TUiInstellingenContext); procedure ZoekOp(UserContext: TUserContext; ProductsContext: TProductsContext; Zoekmethode: TZoekMethode; Zoek: string; KLNr: string; LevNr: string; StockType: string; Taal: string); procedure ZoekProductDataMetProductNr(ProductNr: Integer; UserContext: TUserContext; - ProductDetailContext: TProductDetailContext); + ProductDetailContext: TProductVerpakkingContext); end; implementation @@ -336,7 +336,7 @@ end; function TProductsAgent.GetBoxDataIDsViaProduct(ProductNr: Integer; UserContext: TUserContext; - ProductDetailContext: TProductDetailContext): TList; + ProductDetailContext: TProductVerpakkingContext): TList; var ZoekData: OptiServerService.GetBoxDataIDsViaProduct; GetBoxDataIDsViaProductResponseObj: OptiServerService.GetBoxDataIDsViaProductResponse; @@ -410,7 +410,7 @@ end; procedure TProductsAgent.ZoekProductDataMetProductNr(ProductNr: Integer; UserContext: TUserContext; - ProductDetailContext: TProductDetailContext); + ProductDetailContext: TProductVerpakkingContext); var ZoekData: OptiServerService.GetBoxDataViaId; BoxDataIDs: TList; @@ -468,7 +468,7 @@ end; end; -procedure TProductsAgent.RegistreerZoekResultaten(ProductDetailContext: TProductDetailContext; +procedure TProductsAgent.RegistreerZoekResultaten(ProductDetailContext: TProductVerpakkingContext; pxBoxDataObj: OptiServerService.pxBoxData); var Verpakking: TProductVerpakking; @@ -533,7 +533,7 @@ ProductDetailContext.ProductVerpakkingen.Add(Verpakking); end; -procedure TProductsAgent.RegistreerMislukteOpzoeking(ProductDetailContext: TProductDetailContext; +procedure TProductsAgent.RegistreerMislukteOpzoeking(ProductDetailContext: TProductVerpakkingContext; pxStatusObj: OptiServerService.pxStatus); begin ProductDetailContext.ProductVerpakkingen.Clear(); Index: VerpakkingsDefinitie/Main.pas =================================================================== diff -u -r589 -r591 --- VerpakkingsDefinitie/Main.pas (.../Main.pas) (revision 589) +++ VerpakkingsDefinitie/Main.pas (.../Main.pas) (revision 591) @@ -69,7 +69,6 @@ var NieuwScherm: TControl; NavGridPanelStandard: TNavGridPanelStandard; - i: Integer; begin Application.ProcessMessages; // Interrupts the execution of an application so that it can process the message queue. @@ -95,7 +94,7 @@ NavGridPanelStandard.Init(TFormGebruiker.Create(NavGridPanelStandard, Self, FAppContext, FAppContext.UserContext, FUserAgent), TFormZoekProducten.Create(NavGridPanelStandard, Self, FAppContext, FProductsAgent), TFormGevondenProducten.Create(NavGridPanelStandard, Self, FAppContext, FAppContext.ProductsContext, FProductsAgent), - TFormProductDetail.Create(NavGridPanelStandard, Self, FAppContext, FAppContext.ProductDetailContext)); + TFormProductDetail.Create(NavGridPanelStandard, Self, FAppContext, FAppContext.ProductVerpakkingContext)); end; NAVLOGIN: Index: VerpakkingsDefinitie/ApplicationContext.pas =================================================================== diff -u -r590 -r591 --- VerpakkingsDefinitie/ApplicationContext.pas (.../ApplicationContext.pas) (revision 590) +++ VerpakkingsDefinitie/ApplicationContext.pas (.../ApplicationContext.pas) (revision 591) @@ -89,6 +89,7 @@ TProductsContext = class(TSubject) private FProducten: TList; + FGeselecteerdProduct: TProductInformatie; FIsOK: Boolean; FErrorMessage: string; @@ -98,6 +99,11 @@ procedure Reset(); procedure NotifyChanged(); property Producten: TList read FProducten; + { TODO : +Immutable list type retourneren en functie om item(s) toe te voegen (met Notify) +https://stackoverflow.com/questions/22693154/make-delphi-tlist-immutable } + property GeselecteerdProduct: TProductInformatie read FGeselecteerdProduct write FGeselecteerdProduct; + { TODO : GeselecteerdProduct setter hierop plaatsen en NotifyChanged() callen } property IsOK: Boolean read FIsOK write FIsOK; property ErrorMessage: string read FErrorMessage write FErrorMessage; @@ -181,6 +187,7 @@ property DefaultRichtingen: TList read FDefaultRichtingen; property Parameters: TList read FParameters; + { TODO : Immutable list } property DeelVanID: string read FDeelVanID write FDeelVanID; property DeelVanCaption: string read FDeelVanCaption write FDeelVanCaption; @@ -193,10 +200,10 @@ constructor Create(); end; - TProductDetailContext = class(TSubject) + TProductVerpakkingContext = class(TSubject) private - FGeselecteerdProduct: TProductInformatie; FProductVerpakkingen: TList; + FGeselecteerdeVerpakking: TProductVerpakking; FIsOK: Boolean; FErrorMessage: string; @@ -205,10 +212,13 @@ constructor Create(); procedure NotifyChanged(); procedure Reset(); - property GeselecteerdProduct: TProductInformatie read FGeselecteerdProduct write FGeselecteerdProduct; property ProductVerpakkingen: TList read FProductVerpakkingen; + { TODO : +Immutable list type retourneren en functie om item(s) toe te voegen (met Notify) +https://stackoverflow.com/questions/22693154/make-delphi-tlist-immutable } function GetDeelVanOpties(ProductVerpakking: TProductVerpakking): TList; - + property GeselecteerdeVerpakking: TProductVerpakking read FGeselecteerdeVerpakking write FGeselecteerdeVerpakking; + { TODO : GeselecteerdeVerpakking setter hierop plaatsen en NotifyChanged() callen } property IsOK: Boolean read FIsOK write FIsOK; property ErrorMessage: string read FErrorMessage write FErrorMessage; property InternalErrorMessage: string read FInternalErrorMessage write FInternalErrorMessage; @@ -221,13 +231,13 @@ FUserContext: TUserContext; FUiInstellingenContext: TUiInstellingenContext; FProductsContext: TProductsContext; - FProductDetailContext: TProductDetailContext; + FProductDetailContext: TProductVerpakkingContext; public constructor Create(); property UserContext: TUserContext read FUserContext write FUserContext; property UiInstellingenContext: TUiInstellingenContext read FUiInstellingenContext write FUiInstellingenContext; property ProductsContext: TProductsContext read FProductsContext write FProductsContext; - property ProductDetailContext: TProductDetailContext read FProductDetailContext write FProductDetailContext; + property ProductVerpakkingContext: TProductVerpakkingContext read FProductDetailContext write FProductDetailContext; end; implementation @@ -272,9 +282,10 @@ // Enkel updaten wanneer nog niet op nil stond. procedure TProductsContext.Reset(); begin - if FProducten.Count > 0 then + if (GeselecteerdProduct <> nil) or (FProducten.Count > 0) then begin FProducten.Clear(); + GeselecteerdProduct := nil; NotifyChanged(); end; end; @@ -315,29 +326,28 @@ end; // PRODUCT DETAIL -constructor TProductDetailContext.Create; +constructor TProductVerpakkingContext.Create; begin inherited Create(); FProductVerpakkingen := TList.Create(); end; -procedure TProductDetailContext.NotifyChanged(); +procedure TProductVerpakkingContext.NotifyChanged(); begin self.Change(); end; -// Enkel updaten wanneer nog niet op nil stond. -procedure TProductDetailContext.Reset(); +procedure TProductVerpakkingContext.Reset(); begin - if (GeselecteerdProduct <> nil) or (ProductVerpakkingen.Count > 0) then + if (FGeselecteerdeVerpakking <> nil) or (FProductVerpakkingen.Count > 0) then begin - GeselecteerdProduct := nil; - ProductVerpakkingen.Clear(); + FProductVerpakkingen.Clear(); + FGeselecteerdeVerpakking := nil; NotifyChanged(); end; end; -function TProductDetailContext.GetDeelVanOpties(ProductVerpakking: TProductVerpakking): TList; +function TProductVerpakkingContext.GetDeelVanOpties(ProductVerpakking: TProductVerpakking): TList; var ProductVerpakkingTeZoeken: TProductVerpakking; Namen: TList; @@ -391,7 +401,7 @@ FUserContext := TUserContext.Create(); FUiInstellingenContext := TUiInstellingenContext.Create(); FProductsContext := TProductsContext.Create(); - FProductDetailContext := TProductDetailContext.Create(); + FProductDetailContext := TProductVerpakkingContext.Create(); end; end. Index: VerpakkingsDefinitie/UI/GevondenProductenScherm.pas =================================================================== diff -u -r589 -r591 --- VerpakkingsDefinitie/UI/GevondenProductenScherm.pas (.../GevondenProductenScherm.pas) (revision 589) +++ VerpakkingsDefinitie/UI/GevondenProductenScherm.pas (.../GevondenProductenScherm.pas) (revision 591) @@ -59,22 +59,22 @@ begin if (Selected = false) or (Item = nil) or (Item.Data = nil) then exit; - ApplicationContext.ProductDetailContext.GeselecteerdProduct := Item.Data; + ApplicationContext.ProductsContext.GeselecteerdProduct := Item.Data; // ApplicationContext.ProductDetailContext.NotifyChanged(); FProductsAgent.ZoekProductDataMetProductNr(TProductInformatie(Item.Data).ProductNr, self.ApplicationContext.UserContext, - self.ApplicationContext.ProductDetailContext); + self.ApplicationContext.ProductVerpakkingContext); - if self.ApplicationContext.ProductDetailContext.IsOK = false then + if self.ApplicationContext.ProductVerpakkingContext.IsOK = false then begin // Opzoeking gefaald - ErrorMessage := self.ApplicationContext.ProductDetailContext.ErrorMessage; - if self.ApplicationContext.ProductDetailContext.InternalErrorMessage <> '' then + ErrorMessage := self.ApplicationContext.ProductVerpakkingContext.ErrorMessage; + if self.ApplicationContext.ProductVerpakkingContext.InternalErrorMessage <> '' then begin - ErrorMessage := ErrorMessage + sLineBreak + self.ApplicationContext.ProductDetailContext.InternalErrorMessage; + ErrorMessage := ErrorMessage + sLineBreak + self.ApplicationContext.ProductVerpakkingContext.InternalErrorMessage; end; MessageDlg(ErrorMessage, TMsgDlgType.mtInformation, [mbOK], 0, mbCancel); - self.ApplicationContext.ProductDetailContext.Reset(); + self.ApplicationContext.ProductVerpakkingContext.Reset(); end; end; @@ -101,7 +101,7 @@ ListViewProducten.Items.EndUpdate; // Bij opnieuw inladen is de selectie verloren gegaan. - self.ApplicationContext.ProductDetailContext.Reset(); + self.ApplicationContext.ProductVerpakkingContext.Reset(); end; end. Index: VerpakkingsDefinitie/UI/ProductDetailScherm.pas =================================================================== diff -u -r590 -r591 --- VerpakkingsDefinitie/UI/ProductDetailScherm.pas (.../ProductDetailScherm.pas) (revision 590) +++ VerpakkingsDefinitie/UI/ProductDetailScherm.pas (.../ProductDetailScherm.pas) (revision 591) @@ -122,11 +122,13 @@ procedure TFormProductDetail.UpdateGui(Sender: TObject); var + GeselecteerdProduct: TProductInformatie; ProductVerpakking: TProductVerpakking; VorigeIndexInList: Integer; begin - if (ApplicationContext.ProductDetailContext.GeselecteerdProduct = nil) or - (ApplicationContext.ProductDetailContext.ProductVerpakkingen.Count = 0) then + GeselecteerdProduct := ApplicationContext.ProductsContext.GeselecteerdProduct; + if (GeselecteerdProduct = nil) or + (ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen.Count = 0) then begin UpdateGuiDataAanwezigheid(False); exit; @@ -135,17 +137,17 @@ UpdateGuiDataAanwezigheid(True); // Update met data uit ApplicationContext - LabelOmschrijving1.Caption := ApplicationContext.ProductDetailContext.GeselecteerdProduct.Omschrijving1; - LabelOmschrijving2.Caption := ApplicationContext.ProductDetailContext.GeselecteerdProduct.Omschrijving2; - LabelProductNaam.Caption := ApplicationContext.ProductDetailContext.GeselecteerdProduct.Kol1; - LabelProductNummer.Caption := intToStr(ApplicationContext.ProductDetailContext.GeselecteerdProduct.ProductNr); + LabelOmschrijving1.Caption := GeselecteerdProduct.Omschrijving1; + LabelOmschrijving2.Caption := GeselecteerdProduct.Omschrijving2; + LabelProductNaam.Caption := GeselecteerdProduct.Kol1; + LabelProductNummer.Caption := intToStr(GeselecteerdProduct.ProductNr); VorigeIndexInList := ListViewVerpakkingen.ItemIndex; // List view (grid) ListViewVerpakkingen.Items.BeginUpdate; ListViewVerpakkingen.Clear(); - for ProductVerpakking in ApplicationContext.ProductDetailContext.ProductVerpakkingen do + for ProductVerpakking in ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen do begin With ListViewVerpakkingen.Items.Add Do begin @@ -166,10 +168,10 @@ ListViewVerpakkingen.Items.EndUpdate; // Kijk of dezelfde verpakking als voor de update opnieuw geselecteerd kan worden - if (VorigeIndexInList >= 0) and (VorigeIndexInList < ApplicationContext.ProductDetailContext.ProductVerpakkingen.Count) then - ProductVerpakking := ApplicationContext.ProductDetailContext.ProductVerpakkingen[VorigeIndexInList] - else if ApplicationContext.ProductDetailContext.ProductVerpakkingen.Count > 0 then - ProductVerpakking := ApplicationContext.ProductDetailContext.ProductVerpakkingen[0] + if (VorigeIndexInList >= 0) and (VorigeIndexInList < ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen.Count) then + ProductVerpakking := ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen[VorigeIndexInList] + else if ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen.Count > 0 then + ProductVerpakking := ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen[0] // Default eerste verpakking selecteren else ProductVerpakking := nil; // Geen verpakking aanwezig @@ -182,7 +184,6 @@ procedure TFormProductDetail.ToonProductVerpakking(ProductVerpakking: TProductVerpakking); var - TempStr: string; Item: string; Parameter: TProductVerpakkingParameter; NieuweParameterControl: TCustomPanelVerpakkingParameter; @@ -195,15 +196,16 @@ // DeelVan ComboBoxDeelVan.Items.Clear(); // ComboBox vullen en item selecteren. - for TempStr in ApplicationContext.ProductDetailContext.GetDeelVanOpties(ProductVerpakking) do + for Item in ApplicationContext.ProductVerpakkingContext.GetDeelVanOpties(ProductVerpakking) do begin - ComboBoxDeelVan.Items.Add(TempStr); + ComboBoxDeelVan.Items.Add(Item); end; ComboBoxDeelVan.Items.Add(NERGENS_DEEL_VAN_CAPTION); // Item selecteren if ProductVerpakking.DeelVan <> nil then // Index zoeken in lijst van producten - ComboBoxDeelVan.ItemIndex := ApplicationContext.ProductDetailContext.ProductVerpakkingen.IndexOf(ProductVerpakking.DeelVan) + ComboBoxDeelVan.ItemIndex := ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen.IndexOf + (ProductVerpakking.DeelVan) else // Default waarde: 'niks' optie selecteren ComboBoxDeelVan.ItemIndex := ComboBoxDeelVan.Items.Count - 1;