Page 407 Resource Picture
- App
- Base Application
- Namespace
- Microsoft.Projects.Resources.Resource
- Versions
- 17-28
- Source table
- 156
Versions171819202122232425262728
Source29
Source in 29
src/Layers/W1/BaseApp/Projects/Resources/Resource/ResourcePicture.Page.al181 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.Projects.Resources.Resource;
using System.Device;
using System.IO;
page 407 "Resource Picture"
{
Caption = 'Resource Picture';
DeleteAllowed = false;
InsertAllowed = false;
LinksAllowed = false;
PageType = CardPart;
SourceTable = Resource;
layout
{
area(content)
{
field(Image; Rec.Image)
{
ApplicationArea = Jobs;
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;
OnImportPictureBeforeImportFile(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';
DeleteExportEnabled: Boolean;
MimeTypeTok: Label 'image/jpeg', Locked = true;
procedure TakeNewPicture()
var
PictureInstream: InStream;
PictureDescription: Text;
begin
OnBeforeTakePicture(Rec);
Rec.TestField(Rec."No.");
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;
[IntegrationEvent(false, false)]
local procedure OnBeforeTakePicture(var Resource: Record Resource)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnImportPictureBeforeImportFile(var Resource: Record Resource; FileName: Text)
begin
end;
}