Index: VerpakkingsDefinitie/WS/ProductsAgent.pas =================================================================== diff -u -r600 -r601 --- VerpakkingsDefinitie/WS/ProductsAgent.pas (.../ProductsAgent.pas) (revision 600) +++ VerpakkingsDefinitie/WS/ProductsAgent.pas (.../ProductsAgent.pas) (revision 601) @@ -39,6 +39,7 @@ procedure RegistreerGelukteVerpakkingQuery(ProductVerpakkingenContext: TProductVerpakkingenContext); procedure RegistreerMislukteVerpakkingQuery(ProductVerpakkingenContext: TProductVerpakkingenContext; pxStatusObj: OptiServerService.pxStatus); overload; + function BepaalNieuwCutOrderProductVerpakking(ProductVerpakkingen: TEnumerable): Integer; function GetVerpakkingIDsViaProduct(ProductNr: Integer; UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext): TList; function GeefVerpakkingMetID(VerpakkingID: string; UserContext: TUserContext; @@ -55,10 +56,10 @@ // Verpakkingen procedure ZoekProductVerpakkingenMetProductNr(ProductNr: Integer; UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); - procedure NieuweVerpakking(CutOrder: Integer; Product: TProductInformatie; UserContext: TUserContext; - ProductVerpakkingenContext: TProductVerpakkingenContext); - procedure DupliceerVerpakking(ProductVerpakking: TProductVerpakking; NieuweCutOrder: Integer; UserContext: TUserContext; - ProductVerpakkingenContext: TProductVerpakkingenContext); + procedure NieuweVerpakking(ProductVerpakkingen: TEnumerable; Product: TProductInformatie; + UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); + procedure DupliceerVerpakking(ProductVerpakkingen: TEnumerable; ProductVerpakking: TProductVerpakking; + UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); procedure OpslaanProductVerpakking(ProductVerpakking: TProductVerpakking; UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); procedure VerwijderVerpakking(ProductVerpakking: TProductVerpakking; UserContext: TUserContext; @@ -582,39 +583,39 @@ Result := TempProductVerpakkingen; end; -procedure TProductsAgent.NieuweVerpakking(CutOrder: Integer; Product: TProductInformatie; UserContext: TUserContext; - ProductVerpakkingenContext: TProductVerpakkingenContext); +procedure TProductsAgent.NieuweVerpakking(ProductVerpakkingen: TEnumerable; Product: TProductInformatie; + UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); var NieuweProductVerpakking: TProductVerpakking; begin // Een nieuwe verpakking kan worden opgevraagd met een lege request naar GetBoxDataViaID // Hier gaan we gewoon voor de constructor call van de klasse, maar zijn transparant naar de callende klasse // De nieuwe instantie bevat nog te weinig informatie om te worden opgeslagen - if (Product = nil) or (CutOrder < 0) then + if Product = nil then exit; // 'Gelukte' query emuleren RegistreerGelukteVerpakkingQuery(ProductVerpakkingenContext); // Nieuwe productverpakking aanmaken NieuweProductVerpakking := TProductVerpakking.Create(); - NieuweProductVerpakking.CutOrder := CutOrder; { TODO : Zelf nummer bepalen, max nummer nemen en daarbij optellen } + NieuweProductVerpakking.CutOrder := BepaalNieuwCutOrderProductVerpakking(ProductVerpakkingen); NieuweProductVerpakking.ObjType := 'PR'; NieuweProductVerpakking.objref := IntToStr(Product.ProductNr); ProductVerpakkingenContext.AddProductVerpakking(NieuweProductVerpakking); end; -procedure TProductsAgent.DupliceerVerpakking(ProductVerpakking: TProductVerpakking; NieuweCutOrder: Integer; - UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); +procedure TProductsAgent.DupliceerVerpakking(ProductVerpakkingen: TEnumerable; + ProductVerpakking: TProductVerpakking; UserContext: TUserContext; ProductVerpakkingenContext: TProductVerpakkingenContext); var NieuweVerpakking: TProductVerpakking; begin // Verpakking dupliceren door verpakking opnieuw op te vragen (ander zouden we de originele verpakking aanpassen) // velden die door de server worden ingevuld te wissen en andere velden te updaten. // Nadien slaan we deze verpakking meteen op de server. - if (ProductVerpakking = nil) or (NieuweCutOrder < 0) then + if ProductVerpakking = nil then exit; NieuweVerpakking := GeefVerpakkingMetID(ProductVerpakking.ID, UserContext, ProductVerpakkingenContext); @@ -627,11 +628,12 @@ // Gelukt, data aanpassen. NieuweVerpakking.ID := ''; - NieuweVerpakking.CutOrder := NieuweCutOrder; { TODO : Zelf nummer bepalen, max nummer nemen en daarbij optellen } + NieuweVerpakking.CutOrder := BepaalNieuwCutOrderProductVerpakking(ProductVerpakkingen); // Opslaan - ProductVerpakkingenContext.AddProductVerpakking(NieuweVerpakking); OpslaanProductVerpakking(NieuweVerpakking, UserContext, ProductVerpakkingenContext); + if ProductVerpakkingenContext.IsOK then + ProductVerpakkingenContext.AddProductVerpakking(NieuweVerpakking); end; procedure TProductsAgent.OpslaanProductVerpakking(ProductVerpakking: TProductVerpakking; UserContext: TUserContext; @@ -719,6 +721,22 @@ end; end; +function TProductsAgent.BepaalNieuwCutOrderProductVerpakking(ProductVerpakkingen: TEnumerable): Integer; +var + MaxCutNummer: Integer; + ProductVerpakking: TProductVerpakking; +begin + MaxCutNummer := Low(Integer); + for ProductVerpakking in ProductVerpakkingen do + if ProductVerpakking.CutOrder > MaxCutNummer then + MaxCutNummer := ProductVerpakking.CutOrder; + + if MaxCutNummer > 0 then + Result := MaxCutNummer + 1 + else + Result := 0; +end; + procedure TProductsAgent.MapPxBoxDataNaarProductVerpakking(pxBoxDataObj: OptiServerService.pxBoxData; ProductVerpakking: TProductVerpakking); var Index: VerpakkingsDefinitie/UI/ProductDetailScherm.pas =================================================================== diff -u -r600 -r601 --- VerpakkingsDefinitie/UI/ProductDetailScherm.pas (.../ProductDetailScherm.pas) (revision 600) +++ VerpakkingsDefinitie/UI/ProductDetailScherm.pas (.../ProductDetailScherm.pas) (revision 601) @@ -89,7 +89,7 @@ procedure TFormProductDetail.ButtonNieuweVerpakkingClick(Sender: TObject); begin - FProductsAgent.NieuweVerpakking(ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen.Count + 1, + FProductsAgent.NieuweVerpakking(ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen, ApplicationContext.ProductsContext.GeselecteerdProduct, ApplicationContext.UserContext, ApplicationContext.ProductVerpakkingContext); @@ -98,8 +98,8 @@ procedure TFormProductDetail.ButtonDupliceerVerpakkingClick(Sender: TObject); begin - FProductsAgent.DupliceerVerpakking(ApplicationContext.ProductVerpakkingContext.GeselecteerdeVerpakking, - ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen.Count + 1, ApplicationContext.UserContext, + FProductsAgent.DupliceerVerpakking(ApplicationContext.ProductVerpakkingContext.ProductVerpakkingen, + ApplicationContext.ProductVerpakkingContext.GeselecteerdeVerpakking, ApplicationContext.UserContext, ApplicationContext.ProductVerpakkingContext); VerwerkAgentVerpakkingCall();