Index: VerpakkingsDefinitie/Main.pas =================================================================== diff -u -r587 -r589 --- VerpakkingsDefinitie/Main.pas (.../Main.pas) (revision 587) +++ VerpakkingsDefinitie/Main.pas (.../Main.pas) (revision 589) @@ -59,8 +59,6 @@ FAppContext := TApplicationContext.Create(); FUserAgent := TUserAgent.Create(); FProductsAgent := TProductsAgent.Create(); - { TODO -cMain: Wat doet dit in de originele applicatie?: fUiContext.ImagesScherm := TImagesScherm.Create(self); } - { TODO -cMain: Kijken of "VerwerkParamStrings;" nodig is } PanelMain.Parent := Self; PanelMain.Align := TAlign.alClient; Index: VerpakkingsDefinitie/UI/ProductDetailScherm.pas =================================================================== diff -u -r587 -r589 --- VerpakkingsDefinitie/UI/ProductDetailScherm.pas (.../ProductDetailScherm.pas) (revision 587) +++ VerpakkingsDefinitie/UI/ProductDetailScherm.pas (.../ProductDetailScherm.pas) (revision 589) @@ -4,10 +4,11 @@ uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, - Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, - Subscherm, Main, ApplicationContext, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.Generics.Collections, Vcl.ExtCtrls, + Subscherm, Main, + ApplicationContext, ObserverPattern, Vcl.ComCtrls, Vcl.CheckLst, - CheckCombo, Vcl.ExtCtrls; + CheckCombo; resourceString GEEN_DATA_CAPTION = 'Geen data om te tonen'; @@ -72,15 +73,18 @@ procedure ToonProductVerpakking(ProductVerpakking: TProductVerpakking); procedure UpdateControlsEnableStatus(); procedure UpdateGuiDataAanwezigheid(Aanwezig: Boolean); + procedure LaadEnSelecteerWaardenComboBox(Waarden: TDictionary; ComboBox: TComboBox; + GeselecteerdeWaarde: string; DefaultGeselecteerdeWaarde: string; Vertaling: TDictionary); + procedure LaadEnSelecteerWaardenCheckComboBox(Waarden: TDictionary; CheckedComboBox: TCheckedComboBox; + GeselecteerdeWaarden: TList; DefaultGeselecteerdeWaarden: TList; Vertaling: TDictionary); public Constructor Create(AOwner: TComponent; Navigator: INavigator; ApplicationContext: TApplicationContext; ProductDetailsSubject: TSubject); end; implementation -uses - OptiServerService, Util, System.StrUtils, CustomPanelVerpakkingParameter; +uses OptiServerService, Util, System.StrUtils, CustomPanelVerpakkingParameter; {$R *.dfm} Constructor TFormProductDetail.Create(AOwner: TComponent; Navigator: INavigator; ApplicationContext: TApplicationContext; @@ -238,65 +242,67 @@ // Rechterhelft // Plaatsing - ComboBoxPlaatsing.Items.Clear(); - // Combobox vullen en item selecteren. Indien item niet aanwezig is, eerste item selecteren. - for Item in ApplicationContext.UiInstellingenContext.Plaatsing.keys do - ComboBoxPlaatsing.Items.AddObject(ApplicationContext.UiInstellingenContext.Plaatsing[Item], TObject(Item)); - if (ProductVerpakking.Plaatsing <> '') and - (ApplicationContext.UiInstellingenContext.Plaatsing.TryGetValue(ProductVerpakking.Plaatsing, Item) = True) then - ComboBoxPlaatsing.ItemIndex := ComboBoxPlaatsing.Items.IndexOf(Item) - else if (ProductVerpakking.DefaultPlaatsing <> '') and - (ApplicationContext.UiInstellingenContext.Plaatsing.TryGetValue(ProductVerpakking.DefaultPlaatsing, Item) = True) then - ComboBoxPlaatsing.ItemIndex := ComboBoxPlaatsing.Items.IndexOf(Item) // Default - else if ComboBoxPlaatsing.Items.Count > 0 then - ComboBoxPlaatsing.ItemIndex := 0; // Geen waarde, geen default, eerste item selecteren. + LaadEnSelecteerWaardenComboBox(ApplicationContext.UiInstellingenContext.Plaatsing, ComboBoxPlaatsing, + ProductVerpakking.Plaatsing, ProductVerpakking.DefaultPlaatsing, ApplicationContext.UiInstellingenContext.Plaatsing); // Positie - CheckComboBoxPositie.Items.Clear(); - // CheckComboBox vullen en items selecteren. Als waarde niet aanwezig is, uit default halen. - { TODO : Bug fixen als item niet bestaat in dictionary } - for Item in ApplicationContext.UiInstellingenContext.Posities.keys do - CheckComboBoxPositie.Items.AddObject(ApplicationContext.UiInstellingenContext.Posities[Item], TObject(Item)); - if ProductVerpakking.Posities.Count > 0 then - begin - for Item in ProductVerpakking.Posities do - begin - TempStr := ApplicationContext.UiInstellingenContext.Posities[Item]; - if CheckComboBoxPositie.Items.IndexOf(TempStr) >= 0 then - CheckComboBoxPositie.Checked[CheckComboBoxPositie.Items.IndexOf(TempStr)] := True; - end; - end - else - // Default waarden - for Item in ProductVerpakking.DefaultPosities do - begin - TempStr := ApplicationContext.UiInstellingenContext.Posities[Item]; - if CheckComboBoxPositie.Items.IndexOf(TempStr) >= 0 then - CheckComboBoxPositie.Checked[CheckComboBoxPositie.Items.IndexOf(TempStr)] := True; - end; + LaadEnSelecteerWaardenCheckComboBox(ApplicationContext.UiInstellingenContext.Posities, CheckComboBoxPositie, + ProductVerpakking.Posities, ProductVerpakking.DefaultPosities, ApplicationContext.UiInstellingenContext.Posities); // Richting - CheckComboBoxRichting.Items.Clear(); - // CheckComboBox vullen en items selecteren. Als waarde niet aanwezig is, uit default halen. - for Item in ApplicationContext.UiInstellingenContext.Richtingen.keys do - CheckComboBoxRichting.Items.AddObject(ApplicationContext.UiInstellingenContext.Richtingen[Item], TObject(Item)); - if ProductVerpakking.Richtingen.Count > 0 then + LaadEnSelecteerWaardenCheckComboBox(ApplicationContext.UiInstellingenContext.Richtingen, CheckComboBoxRichting, + ProductVerpakking.Richtingen, ProductVerpakking.DefaultRichtingen, ApplicationContext.UiInstellingenContext.Richtingen); +end; + +procedure TFormProductDetail.LaadEnSelecteerWaardenComboBox(Waarden: TDictionary; ComboBox: TComboBox; + GeselecteerdeWaarde: string; DefaultGeselecteerdeWaarde: string; Vertaling: TDictionary); +var + Item: string; +begin + ComboBox.Items.Clear(); + // Vullen + for Item in Waarden.keys do + ComboBox.Items.AddObject(Vertaling[Item], TObject(Item)); + // Items selecteren. Als waarde niet aanwezig is, uit default halen. Als dat niet gaat eerste item selecteren. + if (GeselecteerdeWaarde <> '') and (Vertaling.TryGetValue(GeselecteerdeWaarde, Item) = True) then + ComboBox.ItemIndex := ComboBox.Items.IndexOf(Item) + else if (DefaultGeselecteerdeWaarde <> '') and (Vertaling.TryGetValue(DefaultGeselecteerdeWaarde, Item) = True) then + ComboBox.ItemIndex := ComboBox.Items.IndexOf(Item) // Default + else if ComboBox.Items.Count > 0 then + ComboBox.ItemIndex := 0; // Geen waarde, geen default, eerste item selecteren. +end; + +procedure TFormProductDetail.LaadEnSelecteerWaardenCheckComboBox(Waarden: TDictionary; + CheckedComboBox: TCheckedComboBox; GeselecteerdeWaarden: TList; DefaultGeselecteerdeWaarden: TList; + Vertaling: TDictionary); +var + Item: string; + TempStr: string; +begin + CheckedComboBox.Items.Clear(); + + // CheckComboBox vullen. + for Item in Waarden.keys do + CheckedComboBox.Items.AddObject(Waarden[Item], TObject(Item)); + + // Items selecteren. Als waarde niet aanwezig is, uit default halen. + if GeselecteerdeWaarden.Count > 0 then begin - for Item in ProductVerpakking.Richtingen do - begin - TempStr := ApplicationContext.UiInstellingenContext.Richtingen[Item]; - if CheckComboBoxRichting.Items.IndexOf(TempStr) >= 0 then - CheckComboBoxRichting.Checked[CheckComboBoxRichting.Items.IndexOf(TempStr)] := True; - end; + for Item in GeselecteerdeWaarden do + if Vertaling.TryGetValue(Item, TempStr) = True then + begin + if CheckedComboBox.Items.IndexOf(TempStr) >= 0 then + CheckedComboBox.Checked[CheckedComboBox.Items.IndexOf(TempStr)] := True; + end; end else // Default waarden - for Item in ProductVerpakking.DefaultRichtingen do - begin - TempStr := ApplicationContext.UiInstellingenContext.Richtingen[Item]; - if CheckComboBoxRichting.Items.IndexOf(TempStr) >= 0 then - CheckComboBoxRichting.Checked[CheckComboBoxRichting.Items.IndexOf(TempStr)] := True; - end; + for Item in DefaultGeselecteerdeWaarden do + if Vertaling.TryGetValue(Item, TempStr) = True then + begin + if CheckedComboBox.Items.IndexOf(TempStr) >= 0 then + CheckedComboBox.Checked[CheckedComboBox.Items.IndexOf(TempStr)] := True; + end; end; procedure TFormProductDetail.UpdateControlsEnableStatus(); Index: VerpakkingsDefinitie/UI/GevondenProductenScherm.pas =================================================================== diff -u -r585 -r589 --- VerpakkingsDefinitie/UI/GevondenProductenScherm.pas (.../GevondenProductenScherm.pas) (revision 585) +++ VerpakkingsDefinitie/UI/GevondenProductenScherm.pas (.../GevondenProductenScherm.pas) (revision 589) @@ -57,10 +57,8 @@ var ErrorMessage: string; begin - if Item = nil then + if (Selected = false) or (Item = nil) or (Item.Data = nil) then exit; - if Item.Data = nil then - exit; ApplicationContext.ProductDetailContext.GeselecteerdProduct := Item.Data; // ApplicationContext.ProductDetailContext.NotifyChanged(); FProductsAgent.ZoekProductDataMetProductNr(TProductInformatie(Item.Data).ProductNr, self.ApplicationContext.UserContext,