Index: VerpakkingsDefinitie/UI/ProductDetailScherm.pas =================================================================== diff -u -r593 -r594 --- VerpakkingsDefinitie/UI/ProductDetailScherm.pas (.../ProductDetailScherm.pas) (revision 593) +++ VerpakkingsDefinitie/UI/ProductDetailScherm.pas (.../ProductDetailScherm.pas) (revision 594) @@ -4,14 +4,14 @@ uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, - Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.Generics.Collections, Vcl.ExtCtrls, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.Generics.Collections, Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.CheckLst, Subscherm, Navigator, - ApplicationContext, - ObserverPattern, Vcl.ComCtrls, Vcl.CheckLst, + ApplicationContext, ProductsAgent, + ObserverPattern, CheckCombo; resourceString - GEEN_DATA_CAPTION = 'Geen data om te tonen'; + GEEN_DATA_CAPTION = 'Geen product geselecteerd'; NERGENS_DEEL_VAN_CAPTION = '--Nergens deel van--'; type @@ -24,59 +24,25 @@ GroupBox1: TGroupBox; ButtonNieuw: TButton; ButtonVerwijder: TButton; - Label2: TLabel; - Label4: TLabel; - Label5: TLabel; - Label6: TLabel; - Label7: TLabel; - Label8: TLabel; - Label9: TLabel; - Label10: TLabel; - Label11: TLabel; - Label12: TLabel; - Label13: TLabel; - EditMeta: TEdit; - ComboBoxDeelVan: TComboBox; - EditBreedte: TEdit; - EditDiepte: TEdit; - EditHoogte: TEdit; - EditMaxCombAantal: TEdit; - EditAantal: TEdit; - ComboBoxPlaatsing: TComboBox; - ComboBoxPositie: TComboBox; - ComboBoxRichting: TComboBox; - ButtonMeta: TButton; - PanelVerpakkingControls: TPanel; - Label3: TLabel; - EditVolumeVan: TEdit; - Label14: TLabel; - ComboBoxOptiType: TComboBox; LabelProductNummer: TLabel; Label17: TLabel; - ScrollBoxParameters: TScrollBox; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure ListViewVerpakkingenSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); private FProductDetailsSubject: TSubject; FProductDetailsSubjectObserver: TSubjectObserver; + FProductsAgent: TProductsAgent; LabelGeenData: TLabel; - CheckComboBoxPositie: TCheckedComboBox; - CheckComboBoxRichting: TCheckedComboBox; procedure UpdateGui(Sender: TObject); - 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); + ProductDetailsSubject: TSubject; ProductsAgent: TProductsAgent); end; implementation @@ -85,27 +51,17 @@ {$R *.dfm} Constructor TFormProductDetail.Create(AOwner: TComponent; Navigator: INavigator; ApplicationContext: TApplicationContext; - ProductDetailsSubject: TSubject); + ProductDetailsSubject: TSubject; ProductsAgent: TProductsAgent); begin inherited Create(AOwner, Navigator, ApplicationContext); self.FProductDetailsSubject := ProductDetailsSubject; self.FProductDetailsSubjectObserver := TSubjectObserver.Create(self); self.FProductDetailsSubjectObserver.OnChange := UpdateGui; + self.FProductsAgent := ProductsAgent; end; procedure TFormProductDetail.FormCreate(Sender: TObject); begin - // Vervang sommige comboboxen door TCheckedComboBox - CheckComboBoxPositie := TCheckedComboBox.Create(self); - with CheckComboBoxPositie do - CheckComboBoxPositie.Delimiter := ';'; - TUtil.VervangControl(ComboBoxPositie, CheckComboBoxPositie); - - CheckComboBoxRichting := TCheckedComboBox.Create(self); - with CheckComboBoxRichting do - CheckComboBoxRichting.Delimiter := ';'; - TUtil.VervangControl(ComboBoxRichting, CheckComboBoxRichting); - // Registreer bij observer FProductDetailsSubject.RegisterObserver(FProductDetailsSubjectObserver); end; @@ -118,17 +74,44 @@ procedure TFormProductDetail.ListViewVerpakkingenSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); begin if Selected then - if (ListViewVerpakkingen.Selected.Data <> nil) then - ToonProductVerpakking(TProductVerpakking(ListViewVerpakkingen.Selected.Data)); + begin + ApplicationContext.ProductVerpakkingContext.GeselecteerdeVerpakking := TProductVerpakking(ListViewVerpakkingen.Selected.Data); + ApplicationContext.ProductVerpakkingContext.NotifyChanged(); { TODO : Vervangen door notify changed in setter } + end; end; procedure TFormProductDetail.UpdateGui(Sender: TObject); var GeselecteerdProduct: TProductInformatie; + ErrorMessage: string; ProductVerpakking: TProductVerpakking; VorigeIndexInList: Integer; begin GeselecteerdProduct := ApplicationContext.ProductsContext.GeselecteerdProduct; + + if GeselecteerdProduct <> nil then + begin + // Product informatie ophalen + FProductsAgent.ZoekProductVerpakkingenMetProductNr(GeselecteerdProduct.ProductNr, self.ApplicationContext.UserContext, + self.ApplicationContext.ProductVerpakkingContext); + + if self.ApplicationContext.ProductVerpakkingContext.IsOK then + // Gelukt + Navigator.NavigeerNaar(NAVTOONPRODUCTVERPAKKING) + else + begin + // Opzoeking gefaald + ErrorMessage := self.ApplicationContext.ProductVerpakkingContext.ErrorMessage; + if self.ApplicationContext.ProductVerpakkingContext.InternalErrorMessage <> '' then + begin + ErrorMessage := ErrorMessage + sLineBreak + self.ApplicationContext.ProductVerpakkingContext.InternalErrorMessage; + end; + + MessageDlg(ErrorMessage, TMsgDlgType.mtInformation, [mbOK], 0, mbCancel); + exit; + end; + end; + if (GeselecteerdProduct = nil) or (ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen.Count = 0) then begin UpdateGuiDataAanwezigheid(False); @@ -137,6 +120,8 @@ else UpdateGuiDataAanwezigheid(True); + UpdateControlsEnableStatus(); + // Update met data uit ApplicationContext LabelOmschrijving1.Caption := GeselecteerdProduct.Omschrijving1; LabelOmschrijving2.Caption := GeselecteerdProduct.Omschrijving2; @@ -172,162 +157,21 @@ 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 + ProductVerpakking := ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen[0] else ProductVerpakking := nil; // Geen verpakking aanwezig - if ProductVerpakking <> nil then - ToonProductVerpakking(ProductVerpakking); - - UpdateControlsEnableStatus() + ApplicationContext.ProductVerpakkingContext.GeselecteerdeVerpakking := ProductVerpakking; end; -procedure TFormProductDetail.ToonProductVerpakking(ProductVerpakking: TProductVerpakking); -var - Item: string; - Parameter: TProductVerpakkingParameter; - NieuweParameterControl: TCustomPanelVerpakkingParameter; -begin - // Linkerhelft - - EditMeta.Text := ProductVerpakking.MetaCaptionDisplay; - EditVolumeVan.Text := ProductVerpakking.VolumeVanCaption; - - // DeelVan - ComboBoxDeelVan.Items.Clear(); - // ComboBox vullen en item selecteren. - for Item in ApplicationContext.ProductVerpakkingContext.GetDeelVanOpties(ProductVerpakking) do - begin - 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.ProductVerpakkingContext.ProductVerpakkingen.IndexOf - (ProductVerpakking.DeelVan) - else - // Default waarde: 'niks' optie selecteren - ComboBoxDeelVan.ItemIndex := ComboBoxDeelVan.Items.Count - 1; - - // Breedte, Diepte, Hoogte. - // Default waarde altijd als placeholder instellen - EditBreedte.TextHint := ProductVerpakking.DefaultBreedte; // Default - if ProductVerpakking.Breedte <> '' then - EditBreedte.Text := ProductVerpakking.Breedte; - - EditDiepte.TextHint := ProductVerpakking.DefaultDiepte; // Default - if ProductVerpakking.Diepte <> '' then - EditDiepte.Text := ProductVerpakking.Diepte; - - EditHoogte.TextHint := ProductVerpakking.DefaultHoogte; // Default - if ProductVerpakking.Hoogte <> '' then - EditHoogte.Text := ProductVerpakking.Hoogte; - - // Max.Comb.Aantal, Aantal - EditMaxCombAantal.Text := ProductVerpakking.MaxCombinAantal; - EditAantal.Text := ProductVerpakking.Aantal; - - // Parameters - TUtil.FreeControlChildren(ScrollBoxParameters); - for Parameter in ProductVerpakking.Parameters do - begin - NieuweParameterControl := TCustomPanelVerpakkingParameter.Create(ScrollBoxParameters); - with NieuweParameterControl do - begin - Parent := ScrollBoxParameters; - ProductVerpakkingParameter := Parameter; - end; - end; - - // Rechterhelft - - // Plaatsing - LaadEnSelecteerWaardenComboBox(ApplicationContext.UiInstellingenContext.Plaatsing, ComboBoxPlaatsing, - ProductVerpakking.Plaatsing, ProductVerpakking.DefaultPlaatsing, ApplicationContext.UiInstellingenContext.Plaatsing); - - // Positie - LaadEnSelecteerWaardenCheckComboBox(ApplicationContext.UiInstellingenContext.Posities, CheckComboBoxPositie, - ProductVerpakking.Posities, ProductVerpakking.DefaultPosities, ApplicationContext.UiInstellingenContext.Posities); - - // Richting - LaadEnSelecteerWaardenCheckComboBox(ApplicationContext.UiInstellingenContext.Richtingen, CheckComboBoxRichting, - ProductVerpakking.Richtingen, ProductVerpakking.DefaultRichtingen, ApplicationContext.UiInstellingenContext.Richtingen); - - // OptiType - LaadEnSelecteerWaardenComboBox(ApplicationContext.UiInstellingenContext.OptiTypes, ComboBoxOptiType, ProductVerpakking.OptiType, - ProductVerpakking.DefaultOptiType, ApplicationContext.UiInstellingenContext.OptiTypes); -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 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 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(); var VerpakkingAanwezigEnGeselecteerd: Boolean; - I: Integer; begin // Details controls enable status aanpassen naargelang er een verpakking geselecteerd is. - VerpakkingAanwezigEnGeselecteerd := (ListViewVerpakkingen.Items.Count = 0) or (ListViewVerpakkingen.ItemIndex < 0); - for I := 0 to PanelVerpakkingControls.ControlCount - 1 do - if Assigned(PanelVerpakkingControls.Controls[I]) then - PanelVerpakkingControls.Controls[I].Enabled := VerpakkingAanwezigEnGeselecteerd; - + VerpakkingAanwezigEnGeselecteerd := (ListViewVerpakkingen.Items.Count > 0) and (ListViewVerpakkingen.ItemIndex >= 0); ButtonVerwijder.Enabled := VerpakkingAanwezigEnGeselecteerd; - - // Linkerdeel - EditMeta.Enabled := False; - EditVolumeVan.Enabled := False; - ComboBoxDeelVan.Enabled := (ComboBoxDeelVan.Items.Count > 0) and VerpakkingAanwezigEnGeselecteerd; end; procedure TFormProductDetail.UpdateGuiDataAanwezigheid(Aanwezig: Boolean); @@ -346,7 +190,6 @@ self.Controls[I].Visible := True; LabelGeenData.Visible := False; - PanelVerpakkingControls.Refresh(); // Anders verdwijnt label enkel op resize FreeAndNil(LabelGeenData); end else