Page 5104 Contact Picture
src/Layers/W1/BaseApp/CRM/Contact/ContactPicture.Page.al182 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.Contact;using System.Device;using System.IO;page 5104 "Contact Picture"{ Caption = 'Contact Picture'; DeleteAllowed = false; InsertAllowed = false; LinksAllowed = false; PageType = CardPart; SourceTable = Contact; layout { area(content) { field(Image; Rec.Image) { ApplicationArea = Basic, Suite; ShowCaption = false; } } } actions { area(processing) { action(TakePicture) { ApplicationArea = Basic, Suite; Caption = 'Take'; Image = Camera; ToolTip = 'Activate the camera on the device.'; Visible = CameraAvailable; trigger OnAction() begin TakeNewPicture(); end; } action(ImportPicture) { ApplicationArea = Basic, Suite; Caption = 'Import'; Image = Import; ToolTip = 'Import a picture file.'; trigger OnAction() var FileManagement: Codeunit "File Management"; FileName: Text; ClientFileName: Text; begin Rec.TestField("No."); Rec.TestField(Name); if Rec.Image.HasValue() then if not Confirm(OverrideImageQst) then exit; FileName := FileManagement.UploadFile(SelectPictureTxt, ClientFileName); if FileName = '' then exit; OnImportPictureOnBeforeStoreFile(Rec, FileName); Clear(Rec.Image); Rec.Image.ImportFile(FileName, ClientFileName); Rec.Modify(true); if FileManagement.DeleteServerFile(FileName) then; end; } action(ExportFile) { ApplicationArea = Basic, Suite; 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("No."); Rec.TestField(Name); ToFile := StrSubstNo('%1 %2.jpg', Rec."No.", Rec.Name); ExportPath := TemporaryPath + Rec."No." + Format(Rec.Image.MediaId); Rec.Image.ExportFile(ExportPath); FileManagement.ExportImage(ExportPath, ToFile); end; } action(DeletePicture) { ApplicationArea = Basic, Suite; Caption = 'Delete'; Enabled = DeleteExportEnabled; Image = Delete; ToolTip = 'Delete the record.'; trigger OnAction() begin Rec.TestField("No."); 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'; MimeTypeTok: Label 'image/jpeg', Locked = true; DeleteExportEnabled: Boolean; local procedure TakeNewPicture() var PictureInstream: InStream; PictureDescription: Text; begin Rec.TestField("No."); Rec.TestField(Name); OnTakePictureOnBeforeAddPicture(Rec); 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; [IntegrationEvent(false, false)] local procedure OnImportPictureOnBeforeStoreFile(var Contact: Record Contact; FileName: Text) begin end; [IntegrationEvent(false, false)] local procedure OnTakePictureOnBeforeAddPicture(var Contact: Record Contact) begin end;}