unit PalletScherm; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, System.IniFiles, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, DrieKnoppenScherm, Vcl.ActnList, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Imaging.pngimage; type TfmPalletScherm = class(TfmDrieKnoppenScherm) lblScanPallet: TLabel; imgPallet: TImage; edtPallet: TEdit; btnGenereerTbp: TButton; procedure FormShow(Sender: TObject); procedure actHomeExecute(Sender: TObject); procedure actVolgendeExecute(Sender: TObject); procedure edtPalletKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); procedure btnGenereerTbpClick(Sender: TObject); procedure FormActivate(Sender: TObject); private procedure SetContext; procedure SetModus(GescandeInput: string); procedure ResetPopups; function ValideerPalletCode(GescandeInput: string): boolean; public { Public declarations } end; var fmPalletScherm: TfmPalletScherm; implementation uses DnaCodeService, QRcodeNaarKenmerkenService, UiContext, Agent, ProScanMain, StrUtils, CommonFunctions; {$R *.dfm} procedure TfmPalletScherm.actHomeExecute(Sender: TObject); begin inherited; PostMessage(Self.Handle,WM_Close,0,0); (Self.Parent.Parent As TfmProScanHoofdscherm).NavigeerNaar(mrHome); end; procedure TfmPalletScherm.actVolgendeExecute(Sender: TObject); var fZoekViaPalletCodeResponse: ZoekViaPalletCodeResponse; fZoekViaToeleveringResponse: ZoekViaToeleveringResponse; fAgent: TAgent; begin SetModus(edtPallet.Text); if (UiContext.MoetTbpCodeGenereren = true) then begin ResetPopups; Self.ModalResult := mrDnaCode; end else if (UiContext.Modus = modusKAD) then begin Self.ModalResult := mrDnaCode; end else if (UiContext.Modus = modusVHOSS) then begin Self.ModalResult := mrDnaCode; end else if (ValideerPalletCode(edtPallet.Text) = true) then begin fAgent := TAgent.Create(UiContext); fZoekViaPalletCodeResponse := fAgent.ZoekViaPalletCode(edtPallet.Text); fAgent.Free; try if fZoekViaPalletCodeResponse.Header.Status = '200' then begin UiContext.Toelevering := fZoekViaPalletCodeResponse.DnaCodes[0].Toelevering; SetContext; if fZoekViaPalletCodeResponse.MeerdereToeleveringenToegestaan then Self.ModalResult := mrBestaandePallet else Self.ModalResult := mrDnaCode; end else begin //enkel leegmaken indien de huidige toelevering al compleet is fAgent := TAgent.Create(UiContext); try fZoekViaToeleveringResponse := fAgent.ZoekViaToelevering(UiContext.Toelevering); if fZoekViaToeleveringResponse.AantalInToelevering = fZoekViaToeleveringResponse.AantalReedsGescand then UiContext.Toelevering := ''; fZoekViaToeleveringResponse.Free; finally fAgent.Free; end; Self.ModalResult := mrDnaCode; end; finally fZoekViaPalletCodeResponse.Free; end; ResetPopups; end else begin Self.ModalResult := mrPallet; end; PostMessage(Self.Handle,WM_Close,0,0); (Self.Parent.Parent As TfmProScanHoofdscherm).NavigeerNaar(Self.ModalResult); end; function TfmPalletScherm.ValideerPalletCode(GescandeInput: string): boolean; var fValideerPalletCodeResponse: ValideerPalletCodeResponse; fAgent: TAgent; begin // pallet code valideren result := false; if (UiContext.MoetTbpCodeGenereren) then begin result := true; end else begin fAgent := TAgent.Create(UiContext); fValideerPalletCodeResponse := fAgent.ValideerPalletCode(edtPallet.Text); fAgent.Free; try if fValideerPalletCodeResponse.Header.Status <> '200' then begin Self.ModalResult := mrPallet; ToonPopupScherm(fValideerPalletCodeResponse.Header.Omschrijving, 'Probeer opnieuw'); edtPallet.Text := ''; SetContext; end else begin result := true; end; finally fValideerPalletCodeResponse.Free; end; end; end; procedure TfmPalletScherm.ResetPopups; begin UiContext.IsDirecteLeveringPopupGetoond := false; UiContext.IsWegwerpPalletPopupGetoond := false; UiContext.IsSSTPopupGetoond := false; UiContext.IsExportPopupGetoond := false; UiContext.IsBlumXsPopupGetoond := false; UiContext.IsKartonnenPalletPopupGetoond := false; UiContext.InternVhossId := ''; end; procedure TfmPalletScherm.btnGenereerTbpClick(Sender: TObject); begin inherited; edtPallet.Text := ''; UiContext.Toelevering := ''; UiContext.Pallet := ''; UiContext.MoetTbpCodeGenereren := true; actVolgendeExecute(Self); end; procedure TfmPalletScherm.edtPalletKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin inherited; SetContext; if Key = VK_RETURN then begin actVolgende.Execute; Key := 0; end; end; procedure TfmPalletScherm.FormActivate(Sender: TObject); begin inherited; ActiveControl := edtPallet; end; procedure TfmPalletScherm.FormShow(Sender: TObject); begin btnLinksOnder.Action := nil; btnCentraalOnder.Action := actHome; btnRechtsOnder.Action := actVolgende; edtPallet.Text := ''; edtPallet.SetFocus; UiContext.MoetTbpCodeGenereren := false; SetContext; inherited; end; procedure TfmPalletScherm.SetContext; begin if TCommonFunctions.IsKaderdeurLocatie(edtPallet.Text) then UiContext.Pallet := edtPallet.Text else UiContext.Pallet := UpperCase(edtPallet.Text); end; procedure TfmPalletScherm.SetModus(GescandeInput: string); begin if TCommonFunctions.IsKaderdeurLocatie(GescandeInput) then UiContext.Modus := modusKAD else if (Length(GescandeInput)=10) and StartsText('O1',GescandeInput) then UiContext.Modus := modusVHOSS else Uicontext.Modus := modusDefault; end; end.