unit ProductMetaScherm; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ObserverPattern, Navigator, ApplicationContext, Subscherm, ProductsAgent, Vcl.ComCtrls, Vcl.StdCtrls; type TFormVerpakkingMeta = class(TForm) ComboBoxGroep: TComboBox; GroupBox1: TGroupBox; GroupBox2: TGroupBox; ListViewMetas: TListView; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure ComboBoxGroepChange(Sender: TObject); procedure ListViewMetasSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); private FNavigator: INavigator; FApplicationContext: TApplicationContext; FProductsAgent: TProductsAgent; procedure ToonGroepen(); procedure ToonMetaDatas(); procedure VerwerkProductAgentCall(); public Constructor Create(AOwner: TComponent; Navigator: INavigator; ApplicationContext: TApplicationContext; ProductsAgent: TProductsAgent); reintroduce; end; implementation {$R *.dfm} procedure TFormVerpakkingMeta.Button1Click(Sender: TObject); begin self.Close(); end; constructor TFormVerpakkingMeta.Create(AOwner: TComponent; Navigator: INavigator; ApplicationContext: TApplicationContext; ProductsAgent: TProductsAgent); begin inherited Create(AOwner); self.FNavigator := Navigator; self.FApplicationContext := ApplicationContext; self.FProductsAgent := ProductsAgent; end; procedure TFormVerpakkingMeta.FormCreate(Sender: TObject); begin ToonGroepen(); end; procedure TFormVerpakkingMeta.ToonGroepen(); var TempProductGroep: string; begin if FApplicationContext.ProductVerpakkingMetaContext.ProductGroepen.Count = 0 then begin // Inladen uit Agent FProductsAgent.LaadProductGroepen(FApplicationContext.UserContext, FApplicationContext.ProductVerpakkingMetaContext); VerwerkProductAgentCall(); end; // Tonen, in ComboBox laden. if FApplicationContext.ProductVerpakkingMetaContext.ProductGroepen.Count > 0 then begin ComboBoxGroep.Items.BeginUpdate; for TempProductGroep in FApplicationContext.ProductVerpakkingMetaContext.ProductGroepen do ComboBoxGroep.Items.Add(TempProductGroep); ComboBoxGroep.Items.EndUpdate; end; end; procedure TFormVerpakkingMeta.ComboBoxGroepChange(Sender: TObject); begin if ComboBoxGroep.ItemIndex < 0 then exit; // Productgroep geselecteerd, meta data's inladen. FProductsAgent.LaadProductVerpakkingMetas(ComboBoxGroep.Items[ComboBoxGroep.ItemIndex], FApplicationContext.UserContext, FApplicationContext.ProductVerpakkingMetaContext); VerwerkProductAgentCall(); ToonMetaDatas(); end; procedure TFormVerpakkingMeta.ToonMetaDatas(); var Meta: TProductVerpakkingMeta; begin ListViewMetas.Items.BeginUpdate; ListViewMetas.Items.clear(); for Meta in FApplicationContext.ProductVerpakkingMetaContext.Metas do begin with ListViewMetas.Items.Add do begin Caption := Meta.Name; Data := Meta; end; end; ListViewMetas.Items.EndUpdate; end; procedure TFormVerpakkingMeta.ListViewMetasSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); begin if Selected and (Item.Index > 0) then begin // Registreer binnen agent FProductsAgent.KiesProductVerpakkingMeta(Item.Data, FApplicationContext.ProductVerpakkingContext.GeselecteerdeVerpakking, FApplicationContext.UserContext, FApplicationContext.ProductVerpakkingContext, FApplicationContext.ProductVerpakkingMetaContext); VerwerkProductAgentCall(); if FApplicationContext.ProductVerpakkingMetaContext.IsOK then // Meta selecteren gelukt, scherm afsluiten. self.Close(); end; end; procedure TFormVerpakkingMeta.VerwerkProductAgentCall(); var ErrorMessage: string; begin if FApplicationContext.ProductVerpakkingMetaContext.IsOK = false then begin // Opzoeking gefaald ErrorMessage := FApplicationContext.ProductVerpakkingMetaContext.ErrorMessage; if FApplicationContext.ProductVerpakkingMetaContext.InternalErrorMessage <> '' then ErrorMessage := ErrorMessage + sLineBreak + FApplicationContext.ProductVerpakkingMetaContext.InternalErrorMessage; MessageDlg(ErrorMessage, TMsgDlgType.mtInformation, [mbOK], 0, mbCancel); end; end; end.