Page 5108 Salesperson/Purchaser Picture
src/Layers/W1/BaseApp/CRM/Team/SalespersonPurchaserPicture.Page.al169 lines, Copyright (c) Microsoft Corporation. MIT
// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------namespace Microsoft.CRM.Team;using System.Device;using System.IO;page 5108 "Salesperson/Purchaser Picture"{ Caption = 'Salesperson/Purchaser Picture'; DeleteAllowed = false; InsertAllowed = false; LinksAllowed = false; PageType = CardPart; SourceTable = "Salesperson/Purchaser"; layout { area(content) { field(Image; Rec.Image) { ApplicationArea = Basic, Suite; ShowCaption = false; } } } actions { area(processing) { action(TakePicture) { ApplicationArea = All; Caption = 'Take'; Image = Camera; ToolTip = 'Activate the camera on the device.'; Visible = CameraAvailable; trigger OnAction() begin TakeNewPicture(); end; } action(ImportPicture) { ApplicationArea = All; Caption = 'Import'; Image = Import; ToolTip = 'Import a picture file.'; trigger OnAction() var FileManagement: Codeunit "File Management"; FileName: Text; ClientFileName: Text; begin Rec.TestField(Code); Rec.TestField(Name); if Rec.Image.HasValue() then if not Confirm(OverrideImageQst) then exit; FileName := FileManagement.UploadFile(SelectPictureTxt, ClientFileName); if FileName = '' then exit; Clear(Rec.Image); Rec.Image.ImportFile(FileName, ClientFileName); Rec.Modify(true); if FileManagement.DeleteServerFile(FileName) then; end; } action(ExportFile) { ApplicationArea = All; Caption = 'Export'; Enabled = DeleteExportEnabled; Image = Export; ToolTip = 'Export the picture to a file.'; trigger OnAction() var FileManagement: Codeunit "File Management"; ToFile: Text; ExportPath: Text; begin Rec.TestField(Code); Rec.TestField(Name); ToFile := StrSubstNo('%1 %2.jpg', Rec.Code, Rec.Name); ExportPath := TemporaryPath + Rec.Code + Format(Rec.Image.MediaId); Rec.Image.ExportFile(ExportPath); FileManagement.ExportImage(ExportPath, ToFile); end; } action(DeletePicture) { ApplicationArea = All; Caption = 'Delete'; Enabled = DeleteExportEnabled; Image = Delete; ToolTip = 'Delete the record.'; trigger OnAction() begin Rec.TestField(Code); if not Confirm(DeleteImageQst) then exit; Clear(Rec.Image); Rec.Modify(true); end; } } } trigger OnAfterGetCurrRecord() begin SetEditableOnPictureActions(); end; trigger OnOpenPage() begin CameraAvailable := Camera.IsAvailable(); end; var Camera: Codeunit Camera; CameraAvailable: Boolean; OverrideImageQst: Label 'The existing picture will be replaced. Do you want to continue?'; DeleteImageQst: Label 'Are you sure you want to delete the picture?'; SelectPictureTxt: Label 'Select a picture to upload'; DeleteExportEnabled: Boolean; MimeTypeTok: Label 'image/jpeg', Locked = true; procedure TakeNewPicture() var PictureInstream: InStream; PictureDescription: Text; begin Rec.TestField(Code); Rec.TestField(Name); if Rec.Image.HasValue() then if not Confirm(OverrideImageQst) then exit; if Camera.GetPicture(PictureInstream, PictureDescription) then begin Clear(Rec.Image); Rec.Image.ImportStream(PictureInstream, PictureDescription, MimeTypeTok); Rec.Modify(true) end; end; local procedure SetEditableOnPictureActions() begin DeleteExportEnabled := Rec.Image.HasValue; end;}