unit ProductDetailScherm; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Subscherm, Main, ApplicationContext, ObserverPattern, Vcl.ComCtrls, Vcl.CheckLst, CheckCombo; resourceString RICHTING_DEFAULT_VALUES = 'X;Y;Z;F'; GEEN_DATA_CAPTION = 'Geen data om te tonen'; type TFormProductDetail = class(TFormSubscherm) LabelOmschrijving1: TLabel; LabelOmschrijving2: TLabel; Label1: TLabel; LabelProductNaam: TLabel; ListViewDozen: TListView; GroupBox1: TGroupBox; ButtonNieuw: TButton; ButtonVerwijder: TButton; ButtonMaakDozen: TButton; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Label9: TLabel; Label10: TLabel; Label11: TLabel; Label12: TLabel; Label13: TLabel; Label14: TLabel; Label15: TLabel; EditMeta: TEdit; EditVolumeVan: TEdit; ComboBoxDeelVan: TComboBox; EditBreedte: TEdit; EditDiepte: TEdit; EditHoogte: TEdit; EditMaxCombAantal: TEdit; EditAantal: TEdit; ComboBoxPlaatsing: TComboBox; ComboBoxPositie: TComboBox; ComboBoxRichting: TComboBox; ComboBoxOptiType: TComboBox; ComboBoxBoxSelect: TComboBox; ButtonMeta: TButton; ButtonDeelVan: TButton; MemoParameters: TMemo; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private FProductDetailsSubject: TSubject; FProductDetailsSubjectObserver: TSubjectObserver; LabelGeenData: TLabel; CheckComboBoxPositie: TCheckedComboBox; CheckComboBoxRichting: TCheckedComboBox; procedure UpdateGui(Sender: TObject); procedure UpdateGuiDataAanwezigheid(Aanwezig: boolean); public Constructor Create(AOwner: TComponent; Navigator: INavigator; ApplicationContext: TApplicationContext; ProductDetailsSubject: TSubject); end; implementation uses OptiServerService, Util, System.StrUtils; {$R *.dfm} Constructor TFormProductDetail.Create(AOwner: TComponent; Navigator: INavigator; ApplicationContext: TApplicationContext; ProductDetailsSubject: TSubject); begin inherited Create(AOwner, Navigator, ApplicationContext); self.FProductDetailsSubject := ProductDetailsSubject; self.FProductDetailsSubjectObserver := TSubjectObserver.Create(self); self.FProductDetailsSubjectObserver.OnChange := UpdateGui; end; procedure TFormProductDetail.FormCreate(Sender: TObject); begin FProductDetailsSubject.RegisterObserver(FProductDetailsSubjectObserver); // 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); end; procedure TFormProductDetail.FormDestroy(Sender: TObject); begin FProductDetailsSubject.UnregisterObserver(FProductDetailsSubjectObserver); end; procedure TFormProductDetail.UpdateGui(Sender: TObject); var ProductDetailInformatie: OptiServerService.pxBoxData; PPSPrioriteitEl: OptiServerService.pxemPPSPrioriteit; TempStr: string; begin if (ApplicationContext.ProductDetailContext.GeselecteerdProduct = nil) or (ApplicationContext.ProductDetailContext.ProductDetailInformatie = nil) then begin UpdateGuiDataAanwezigheid(False); exit; end else UpdateGuiDataAanwezigheid(True); // Update with data from ApplicationContext LabelOmschrijving1.Caption := ApplicationContext.ProductDetailContext.GeselecteerdProduct.Omschrijving1; LabelOmschrijving2.Caption := ApplicationContext.ProductDetailContext.GeselecteerdProduct.Omschrijving2; LabelProductNaam.Caption := ApplicationContext.ProductDetailContext.GeselecteerdProduct.Kol1; ProductDetailInformatie := ApplicationContext.ProductDetailContext.ProductDetailInformatie; // List view (grid) ListViewDozen.Clear(); With ListViewDozen.Items.Add Do begin // Caption := IntToStr(Product.ProductNr); // Deze casting geeft geen access violation Caption := IntToStr(ProductDetailInformatie.CutOrder); SubItems.Add(ProductDetailInformatie.MetaCaption); SubItems.Add(ProductDetailInformatie.Breedte + ' x ' + ProductDetailInformatie.Diepte + ' x ' + ProductDetailInformatie.Hoogte); SubItems.Add(ProductDetailInformatie.Aantal); SubItems.Add(ProductDetailInformatie.MaxCombinAantal); SubItems.Add(ProductDetailInformatie.DeelVanCaption); // Linkerhelft EditMeta.Text := ProductDetailInformatie.MetaCaption; EditVolumeVan.Text := ProductDetailInformatie.VolumeVanCaption; ComboBoxDeelVan.Items.Add(ProductDetailInformatie.DeelVanCaption); if ProductDetailInformatie.Breedte <> '' then EditBreedte.Text := ProductDetailInformatie.Breedte else EditBreedte.Text := ProductDetailInformatie.DefaultData.Breedte; // Default if ProductDetailInformatie.Diepte <> '' then EditDiepte.Text := ProductDetailInformatie.Diepte else EditDiepte.Text := ProductDetailInformatie.DefaultData.Diepte; // Default if ProductDetailInformatie.Hoogte <> '' then EditHoogte.Text := ProductDetailInformatie.Hoogte else EditHoogte.Text := ProductDetailInformatie.DefaultData.Hoogte; EditMaxCombAantal.Text := ProductDetailInformatie.MaxCombinAantal; EditAantal.Text := ProductDetailInformatie.Aantal; // Rechterhelft // Plaatsing ComboBoxPlaatsing.Items.Clear(); // Combobox vullen en item selecteren. Indien item niet aanwezig is, eerste item selecteren. for PPSPrioriteitEl in ProductDetailInformatie.PPSPrioriteit do begin ComboBoxPlaatsing.Items.Add(PPSPrioriteitEl.Key); end; if ComboBoxPlaatsing.Items.IndexOf(ProductDetailInformatie.OptiType) >= 0 then ComboBoxPlaatsing.ItemIndex := ComboBoxPlaatsing.Items.IndexOf(ProductDetailInformatie.OptiType) else if ComboBoxPlaatsing.Items.Count > 0 then ComboBoxPlaatsing.ItemIndex := 0; // Positie CheckComboBoxPositie.Items.Clear(); // CheckComboBoxPositie vullen en item selecteren. for TempStr in SplitString(ProductDetailInformatie.DefaultData.Positie, ';') do begin CheckComboBoxPositie.Items.Add(TempStr); end; if CheckComboBoxPositie.Items.IndexOf(ProductDetailInformatie.Positie) >= 0 then CheckComboBoxPositie.Checked[CheckComboBoxPositie.Items.IndexOf(ProductDetailInformatie.Positie)] := True; // Richting CheckComboBoxRichting.Items.Clear(); // CheckComboBoxPositie vullen en item selecteren. Als waarde niet aanwezig is, uit default halen. for TempStr in SplitString(RICHTING_DEFAULT_VALUES, ';') do begin CheckComboBoxRichting.Items.Add(TempStr); end; if CheckComboBoxRichting.Items.IndexOf(ProductDetailInformatie.Rotatie) >= 0 then CheckComboBoxRichting.Checked[CheckComboBoxRichting.Items.IndexOf(ProductDetailInformatie.Rotatie)] := True else if CheckComboBoxRichting.Items.IndexOf(ProductDetailInformatie.DefaultData.Rotatie) >= 0 then CheckComboBoxRichting.Checked[CheckComboBoxRichting.Items.IndexOf(ProductDetailInformatie.DefaultData.Rotatie)] := True end; end; procedure TFormProductDetail.UpdateGuiDataAanwezigheid(Aanwezig: boolean); var I: Integer; begin if Aanwezig then begin // Skip update als alles al zichtbaar staat. if Assigned(LabelGeenData) = False then exit; // Wel resultaten, toon alles. for I := 0 to self.ControlCount - 1 do if Assigned(self.Controls[I]) then self.Controls[I].Visible := True; FreeAndNil(LabelGeenData); end else begin // Skip update als melding al getoond wordt en alles onzichtbaar staat. if Assigned(LabelGeenData) then exit; // Geen resultaten, verberg kinderen, toon melding (label) en stop. for I := 0 to self.ControlCount - 1 do if Assigned(self.Controls[I]) then self.Controls[I].Visible := False; // Label tonen LabelGeenData := TLabel.Create(self); with LabelGeenData do begin Parent := self; Caption := GEEN_DATA_CAPTION; Font.Size := 15; // Centreren: https://stackoverflow.com/questions/18545937/make-a-component-appear-in-the-middle-of-form-no-matter-what-screen-resolution Left := (self.Width - Width) div 2; Top := (self.Height - Height) div 2; Anchors := []; // Relatief tegenover parent end; end end; end.