Index: VerpakkingsDefinitie/ApplicationContext.pas =================================================================== diff -u -r600 -r602 --- VerpakkingsDefinitie/ApplicationContext.pas (.../ApplicationContext.pas) (revision 600) +++ VerpakkingsDefinitie/ApplicationContext.pas (.../ApplicationContext.pas) (revision 602) @@ -135,9 +135,9 @@ FObjType: string; FObjRef: string; FCutOrder: Integer; - FDeelVan: TProductVerpakking; FDeelVanCaption: string; - FDeelVanID: string; { TODO : Setter die ID en caption instelt + notify } + FDeelVanID: string; + FDeelVan: TProductVerpakking; FVolumeVanCaption: string; FVolumeVanID: string; FMetaCaption: string; @@ -160,6 +160,7 @@ FMaxCombinAantal: string; FParameters: TList; + function GetDeelVanDisplay(): string; function GetMetaCaptionDisplay(): string; function GetBreedteDisplay: string; function GetDiepteDisplay: string; @@ -176,6 +177,7 @@ property DeelVanID: string read FDeelVanID write FDeelVanID; property DeelVanCaption: string read FDeelVanCaption write FDeelVanCaption; property DeelVan: TProductVerpakking read FDeelVan write FDeelVan; + property DeelVanDisplay: string read GetDeelVanDisplay; property VolumeVanCaption: string read FVolumeVanCaption write FVolumeVanCaption; property VolumeVanID: string read FVolumeVanID write FVolumeVanID; @@ -238,7 +240,7 @@ procedure SetProductVerpakkingen(Collection: TEnumerable); procedure AddProductVerpakking(ProductVerpakking: TProductVerpakking); procedure VerwijderProductVerpakking(ProductVerpakking: TProductVerpakking); - function GetDeelVanOpties(ProductVerpakking: TProductVerpakking): TList; + function GetDeelVanOpties(ProductVerpakking: TProductVerpakking): TReadOnlyList; property GeselecteerdeVerpakking: TProductVerpakking read FGeselecteerdeVerpakking write SetGeselecteerdeVerpakking; property IsOK: Boolean read FIsOK write FIsOK; @@ -438,19 +440,17 @@ self.NotifyChanged(); end; -function TProductVerpakkingenContext.GetDeelVanOpties(ProductVerpakking: TProductVerpakking): TList; +function TProductVerpakkingenContext.GetDeelVanOpties(ProductVerpakking: TProductVerpakking): TReadOnlyList; var ProductVerpakkingTeZoeken: TProductVerpakking; - Namen: TList; + ProductVerpakkingen: TList; begin - Namen := TList.Create(); + ProductVerpakkingen := TList.Create(); for ProductVerpakkingTeZoeken in FProductVerpakkingen do - begin if not ProductVerpakkingTeZoeken.Equals(ProductVerpakking) then - Namen.Add(intToStr(ProductVerpakkingTeZoeken.CutOrder) + ': ' + ProductVerpakkingTeZoeken.MetaCaptionDisplay) - end; + ProductVerpakkingen.Add(ProductVerpakkingTeZoeken); - Result := Namen; + Result := TReadOnlyList.Create(ProductVerpakkingen); end; // Product verpakking @@ -478,6 +478,11 @@ Result := False; end; +function TProductVerpakking.GetDeelVanDisplay(): string; +begin + Result := intToStr(CutOrder) + ': ' + GetMetaCaptionDisplay(); +end; + function TProductVerpakking.GetMetaCaptionDisplay(): string; begin if FMetaCaption <> '' then Index: VerpakkingsDefinitie/UI/VerpakkingDetailScherm.dfm =================================================================== diff -u -r598 -r602 --- VerpakkingsDefinitie/UI/VerpakkingDetailScherm.dfm (.../VerpakkingDetailScherm.dfm) (revision 598) +++ VerpakkingsDefinitie/UI/VerpakkingDetailScherm.dfm (.../VerpakkingDetailScherm.dfm) (revision 602) @@ -2,7 +2,7 @@ Left = 0 Top = 0 Caption = 'FormVerpakkingDetail' - ClientHeight = 418 + ClientHeight = 396 ClientWidth = 672 Color = clBtnFace Font.Charset = DEFAULT_CHARSET @@ -15,21 +15,21 @@ OnDestroy = FormDestroy DesignSize = ( 672 - 418) + 396) PixelsPerInch = 96 TextHeight = 13 object PanelVerpakkingControls: TPanel Left = 0 Top = 0 Width = 671 - Height = 417 + Height = 396 Anchors = [akLeft, akTop, akRight, akBottom] BevelOuter = bvNone TabOrder = 0 - ExplicitWidth = 657 + ExplicitHeight = 409 DesignSize = ( 671 - 417) + 396) object LabelParameters: TLabel Left = 336 Top = 15 @@ -228,5 +228,20 @@ Anchors = [akLeft, akTop, akRight] TabOrder = 13 end + object ButtonOpslaan: TButton + Left = 495 + Top = 362 + Width = 162 + Height = 25 + Caption = 'Opslaan' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [fsBold] + ParentFont = False + TabOrder = 14 + OnClick = ButtonOpslaanClick + end end end Index: VerpakkingsDefinitie/WS/ProductsAgent.pas =================================================================== diff -u -r601 -r602 --- VerpakkingsDefinitie/WS/ProductsAgent.pas (.../ProductsAgent.pas) (revision 601) +++ VerpakkingsDefinitie/WS/ProductsAgent.pas (.../ProductsAgent.pas) (revision 602) @@ -40,6 +40,8 @@ procedure RegistreerMislukteVerpakkingQuery(ProductVerpakkingenContext: TProductVerpakkingenContext; pxStatusObj: OptiServerService.pxStatus); overload; function BepaalNieuwCutOrderProductVerpakking(ProductVerpakkingen: TEnumerable): Integer; + procedure OpslaanProductVerpakking(ProductVerpakking: TProductVerpakking; UserContext: TUserContext; + ProductVerpakkingenContext: TProductVerpakkingenContext; nieuw: Boolean); function GetVerpakkingIDsViaProduct(ProductNr: Integer; UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext): TList; function GeefVerpakkingMetID(VerpakkingID: string; UserContext: TUserContext; @@ -60,7 +62,7 @@ UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); procedure DupliceerVerpakking(ProductVerpakkingen: TEnumerable; ProductVerpakking: TProductVerpakking; UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); - procedure OpslaanProductVerpakking(ProductVerpakking: TProductVerpakking; UserContext: TUserContext; + procedure OpslaanGewijzigdeProductVerpakking(ProductVerpakking: TProductVerpakking; UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); procedure VerwijderVerpakking(ProductVerpakking: TProductVerpakking; UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); @@ -491,6 +493,7 @@ // Opvragen productverpakkingen TempProductVerpakkingen := GeefVerpakkingenMetIDs(VerpakkingIDs, UserContext, ProductVerpakkingenContext); if ProductVerpakkingenContext.IsOK = false then + // Mislukt, breek af exit; // Registreer DeelVan, zoekt de verpakking op met het overeenkomstige DeelVanID = ID @@ -617,7 +620,7 @@ // Nadien slaan we deze verpakking meteen op de server. if ProductVerpakking = nil then exit; - + { TODO : Bug: dupliceren van diplicaat geeft probleem met default data (data uit database lijkt alsof leeg ID werd gebruikt, geeft leeg object terug dan) } NieuweVerpakking := GeefVerpakkingMetID(ProductVerpakking.ID, UserContext, ProductVerpakkingenContext); if ProductVerpakkingenContext.IsOK = false then @@ -631,48 +634,51 @@ NieuweVerpakking.CutOrder := BepaalNieuwCutOrderProductVerpakking(ProductVerpakkingen); // Opslaan - OpslaanProductVerpakking(NieuweVerpakking, UserContext, ProductVerpakkingenContext); + OpslaanProductVerpakking(NieuweVerpakking, UserContext, ProductVerpakkingenContext, True); if ProductVerpakkingenContext.IsOK then - ProductVerpakkingenContext.AddProductVerpakking(NieuweVerpakking); + ProductVerpakkingenContext.AddProductVerpakking(NieuweVerpakking); // Notify gebeurt hier end; -procedure TProductsAgent.OpslaanProductVerpakking(ProductVerpakking: TProductVerpakking; UserContext: TUserContext; +procedure TProductsAgent.OpslaanGewijzigdeProductVerpakking(ProductVerpakking: TProductVerpakking; UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); +begin + OpslaanProductVerpakking(ProductVerpakking, UserContext, ProductVerpakkingenContext, false); + ProductVerpakkingenContext.NotifyChanged(); +end; + +procedure TProductsAgent.OpslaanProductVerpakking(ProductVerpakking: TProductVerpakking; UserContext: TUserContext; + ProductVerpakkingenContext: TProductVerpakkingenContext; nieuw: Boolean); var RequestData: OptiServerService.SaveBoxData; VerpakkingData: OptiServerService.pxBoxData; SaveBoxDataResponseObj: SaveBoxDataResponse; begin - RequestData := nil; - try - // Request - RequestData := OptiServerService.SaveBoxData.Create(); - RequestData.SessionKey := UserContext.SessionKey; + // Request + // Kan hier geen try--finally met free rond zetten, want dan geeft free de tweede keer dat deze functie wordt opgeroepen een error. + RequestData := OptiServerService.SaveBoxData.Create(); + RequestData.SessionKey := UserContext.SessionKey; - VerpakkingData := OptiServerService.pxBoxData.Create(); - MapProductVerpakkingNaarPxBoxData(ProductVerpakking, VerpakkingData); - RequestData.pxBoxData := VerpakkingData; + VerpakkingData := OptiServerService.pxBoxData.Create(); + MapProductVerpakkingNaarPxBoxData(ProductVerpakking, VerpakkingData); + RequestData.pxBoxData := VerpakkingData; - // Verpakking opslaan + // Verpakking opslaan - SaveBoxDataResponseObj := FOptiBoxServerSoap.SaveBoxData(RequestData); + SaveBoxDataResponseObj := FOptiBoxServerSoap.SaveBoxData(RequestData); - // Response - if SaveBoxDataResponseObj.SaveBoxDataResult.IsOK then - begin - // Gelukt - RegistreerGelukteVerpakkingQuery(ProductVerpakkingenContext); + // Response + if SaveBoxDataResponseObj.SaveBoxDataResult = nil then + begin + // Gelukt + RegistreerGelukteVerpakkingQuery(ProductVerpakkingenContext); + if nieuw then // ID juist zetten ProductVerpakking.ID := SaveBoxDataResponseObj.SaveBoxDataResult.Data; - ProductVerpakkingenContext.NotifyChanged(); - end - else - begin - // Mislukt - RegistreerMislukteVerpakkingQuery(ProductVerpakkingenContext, SaveBoxDataResponseObj.SaveBoxDataResult); - end; - finally - FreeAndNil(RequestData); + end + else + begin + // Mislukt + RegistreerMislukteVerpakkingQuery(ProductVerpakkingenContext, SaveBoxDataResponseObj.SaveBoxDataResult); end; end; @@ -751,7 +757,6 @@ with ProductVerpakking do begin RawDefaultData := pxBoxDataObj.DefaultData; - VolumeVanCaption := pxBoxDataObj.VolumeVanCaption; ID := pxBoxDataObj.ID; ObjType := pxBoxDataObj.ObjType; @@ -839,8 +844,16 @@ // Speciale properties DeelVanCaption := ProductVerpakking.DeelVanCaption; - DeelVanID := ProductVerpakking.DeelVanID; - VolumeVanCaption := ProductVerpakking.VolumeVanCaption; + // Deel van informatie halen uit object. Leeg betekent niks geslecteerd. + if ProductVerpakking.DeelVan <> nil then + // Caption wordt door server juist gezet + DeelVanID := ProductVerpakking.DeelVan.ID + else + begin + DeelVanID := ''; + DeelVanCaption := ''; + end; + VolumeVanID := ProductVerpakking.VolumeVanID; MetaCaption := ProductVerpakking.MetaCaption; MetaID := ProductVerpakking.MetaID; @@ -896,8 +909,6 @@ ProductVerpakkingenContext.IsOK := pxStatusObj.IsOK; ProductVerpakkingenContext.ErrorMessage := pxStatusObj.Message_; ProductVerpakkingenContext.InternalErrorMessage := pxStatusObj.InternalMessage; - - ProductVerpakkingenContext.NotifyChanged(); end; end. Index: VerpakkingsDefinitie/UI/NavProductScherm.pas =================================================================== diff -u -r598 -r602 --- VerpakkingsDefinitie/UI/NavProductScherm.pas (.../NavProductScherm.pas) (revision 598) +++ VerpakkingsDefinitie/UI/NavProductScherm.pas (.../NavProductScherm.pas) (revision 602) @@ -78,7 +78,7 @@ TUtil.PlaatsControlOpGrid(GridPanelRight, TFormProductDetail.Create(GridPanelRight, self, ApplicationContext, ApplicationContext.ProductsContext, ApplicationContext.ProductVerpakkingContext, FProductsAgent), 0, 0); TUtil.PlaatsControlOpGrid(GridPanelRight, TFormVerpakkingDetail.Create(GridPanelRight, self, ApplicationContext, - ApplicationContext.ProductVerpakkingContext), 1, 0); + FProductsAgent, ApplicationContext.ProductVerpakkingContext), 1, 0); end; end; NAVTOONPRODUCTVERPAKKING: Index: VerpakkingsDefinitie/UI/VerpakkingDetailScherm.pas =================================================================== diff -u -r598 -r602 --- VerpakkingsDefinitie/UI/VerpakkingDetailScherm.pas (.../VerpakkingDetailScherm.pas) (revision 598) +++ VerpakkingsDefinitie/UI/VerpakkingDetailScherm.pas (.../VerpakkingDetailScherm.pas) (revision 602) @@ -7,6 +7,7 @@ Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.CheckLst, System.Generics.Collections, Subscherm, Navigator, + ProductsAgent, ApplicationContext, ObserverPattern, CheckCombo; @@ -45,9 +46,13 @@ EditVolumeVan: TEdit; ComboBoxOptiType: TComboBox; ScrollBoxParameters: TScrollBox; + ButtonOpslaan: TButton; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); + procedure ButtonOpslaanClick(Sender: TObject); private + FProductsAgent: TProductsAgent; + FProductVerpakkingSubject: TSubject; FProductVerpakkingSubjectObserver: TSubjectObserver; @@ -59,14 +64,15 @@ procedure LaadCheckedComboBoxen(); procedure UpdateGui(Sender: TObject); procedure ToonProductVerpakking(ProductVerpakking: TProductVerpakking); + procedure RegistreerWijzigingenVerpakking(ProductVerpakking: TProductVerpakking); procedure UpdateControlsEnableStatus(); 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; - ProductVerpakkingSubject: TSubject); + ProductsAgent: TProductsAgent; ProductVerpakkingSubject: TSubject); end; implementation @@ -76,9 +82,10 @@ uses Util, System.StrUtils, CustomPanelVerpakkingParameter; Constructor TFormVerpakkingDetail.Create(AOwner: TComponent; Navigator: INavigator; ApplicationContext: TApplicationContext; - ProductVerpakkingSubject: TSubject); + ProductsAgent: TProductsAgent; ProductVerpakkingSubject: TSubject); begin inherited Create(AOwner, Navigator, ApplicationContext); + FProductsAgent := ProductsAgent; // Observer self.FProductVerpakkingSubject := ProductVerpakkingSubject; self.FProductVerpakkingSubjectObserver := TSubjectObserver.Create(self); @@ -113,6 +120,30 @@ TUtil.VervangControl(ComboBoxRichting, CheckComboBoxRichting); end; +procedure TFormVerpakkingDetail.ButtonOpslaanClick(Sender: TObject); +var + ErrorMessage: string; +begin + // Wijzigingen van GUI overbrengen naar instantie + RegistreerWijzigingenVerpakking(ApplicationContext.ProductVerpakkingContext.GeselecteerdeVerpakking); + + // Wijzigingen opslaan + FProductsAgent.OpslaanGewijzigdeProductVerpakking(ApplicationContext.ProductVerpakkingContext.GeselecteerdeVerpakking, + ApplicationContext.UserContext, ApplicationContext.ProductVerpakkingContext); + + begin + if self.ApplicationContext.ProductVerpakkingContext.IsOK = false then + begin + // Opzoeking gefaald + ErrorMessage := self.ApplicationContext.ProductVerpakkingContext.ErrorMessage; + if self.ApplicationContext.ProductVerpakkingContext.InternalErrorMessage <> '' then + ErrorMessage := ErrorMessage + sLineBreak + self.ApplicationContext.ProductVerpakkingContext.InternalErrorMessage; + + MessageDlg(ErrorMessage, TMsgDlgType.mtInformation, [mbOK], 0, mbCancel); + end; + end; +end; + procedure TFormVerpakkingDetail.UpdateGui(Sender: TObject); begin // Toon de geselecteerde verpakking @@ -182,7 +213,7 @@ procedure TFormVerpakkingDetail.ToonProductVerpakking(ProductVerpakking: TProductVerpakking); var - Item: string; + TempProductVerpakking: TProductVerpakking; Parameter: TProductVerpakkingParameter; NieuweParameterControl: TCustomPanelVerpakkingParameter; begin @@ -194,10 +225,8 @@ // DeelVan ComboBoxDeelVan.Items.Clear(); // ComboBox vullen en item selecteren. - for Item in ApplicationContext.ProductVerpakkingContext.GetDeelVanOpties(ProductVerpakking) do - begin - ComboBoxDeelVan.Items.Add(Item); - end; + for TempProductVerpakking in ApplicationContext.ProductVerpakkingContext.GetDeelVanOpties(ProductVerpakking) do + ComboBoxDeelVan.Items.Add(TempProductVerpakking.DeelVanDisplay); ComboBoxDeelVan.Items.Add(NERGENS_DEEL_VAN_CAPTION); // Item selecteren if ProductVerpakking.DeelVan <> nil then @@ -260,6 +289,32 @@ end; end; +procedure TFormVerpakkingDetail.RegistreerWijzigingenVerpakking(ProductVerpakking: TProductVerpakking); +begin + // Linkerhelft + + // DeelVan + // Kijken waar geselecteerde index ligt. Indien het een geldige selectie is, object selecteren. + if (ComboBoxDeelVan.ItemIndex > 0) and (ComboBoxDeelVan.ItemIndex < ComboBoxDeelVan.Items.Count - 1) then + ProductVerpakking.DeelVan := ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen[ComboBoxDeelVan.ItemIndex] + else + // Geen 'deel van' geselecteerd. + ProductVerpakking.DeelVan := nil; + + // Breedte, Diepte, Hoogte. + ProductVerpakking.Breedte := EditBreedte.Text; + ProductVerpakking.Diepte := EditDiepte.Text; + ProductVerpakking.Hoogte := EditHoogte.Text; + + // Max.Comb.Aantal + ProductVerpakking.MaxCombinAantal := EditMaxCombAantal.Text; + + // Aantal + ProductVerpakking.Aantal := EditAantal.Text; + + { TODO : Andere properties opslaan } +end; + procedure TFormVerpakkingDetail.UpdateControlsEnableStatus(); begin EditMeta.Enabled := false;