mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 14:51:44 +01:00
Added: QR Code in Page
This commit is contained in:
parent
a4b6aa9da1
commit
ee71cd0c5a
141
Borepin/Borepin/PageModel/ScanURNPageModel.cs
Normal file
141
Borepin/Borepin/PageModel/ScanURNPageModel.cs
Normal file
@ -0,0 +1,141 @@
|
||||
using Borepin.Base;
|
||||
using Borepin.Service.BFFH;
|
||||
using FabAccessAPI.Schema;
|
||||
using Prism.Commands;
|
||||
using Prism.Navigation;
|
||||
using Prism.Services;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms;
|
||||
using ZXing;
|
||||
|
||||
namespace Borepin.PageModel
|
||||
{
|
||||
class ScanURNPageModel : ConnectionModelBase
|
||||
{
|
||||
#region Private Fields
|
||||
private object _Instance;
|
||||
#endregion
|
||||
|
||||
#region Contructors
|
||||
public ScanURNPageModel(INavigationService navigationService, IPageDialogService pageDialogService, IBFFHService bffhService) : base(navigationService, pageDialogService, bffhService)
|
||||
{
|
||||
AbortCommand = new DelegateCommand(async () => await AbortCommandExecute().ConfigureAwait(true));
|
||||
ScannedCommand = new DelegateCommand(async () => await ScannedCommandExecuteAsync().ConfigureAwait(false));
|
||||
|
||||
IsVisible = true;
|
||||
IsScanning = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Data
|
||||
public override async Task LoadData()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
private Result _ScanResult;
|
||||
public Result ScanResult
|
||||
{
|
||||
get => _ScanResult;
|
||||
set => SetProperty(ref _ScanResult, value);
|
||||
}
|
||||
|
||||
private bool _IsScanning;
|
||||
public bool IsScanning
|
||||
{
|
||||
get => _IsScanning;
|
||||
set => SetProperty(ref _IsScanning, value);
|
||||
}
|
||||
|
||||
private bool _IsVisible;
|
||||
public bool IsVisible
|
||||
{
|
||||
get => _IsVisible;
|
||||
set => SetProperty(ref _IsVisible, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Commands
|
||||
private ICommand _ScannedCommand;
|
||||
|
||||
public ICommand ScannedCommand
|
||||
{
|
||||
get => _ScannedCommand;
|
||||
set => SetProperty(ref _ScannedCommand, value);
|
||||
}
|
||||
|
||||
public async Task ScannedCommandExecuteAsync()
|
||||
{
|
||||
IsScanning = false;
|
||||
|
||||
string id = await QRToID(ScanResult.Text).ConfigureAwait(false);
|
||||
|
||||
if (id != null)
|
||||
{
|
||||
NavigationParameters parameters = new NavigationParameters
|
||||
{
|
||||
{ "id", id },
|
||||
};
|
||||
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
INavigationResult result = await _NavigationService.NavigateAsync("../MachinePage", parameters).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
|
||||
IsScanning = true;
|
||||
}
|
||||
|
||||
public async Task<string> QRToID(string value)
|
||||
{
|
||||
if (!_BFFHService.IsConnected)
|
||||
{
|
||||
IsConnected = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
IMachineSystem machineInterface = (await _BFFHService.GetSession().ConfigureAwait(false)).MachineSystem;
|
||||
MachineSystem.IInfoInterface infoInterface = await machineInterface.Info().ConfigureAwait(false);
|
||||
|
||||
Machine machine = await infoInterface.GetMachineURN(value).ConfigureAwait(false);
|
||||
|
||||
if (machine == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return machine.Id;
|
||||
}
|
||||
|
||||
private ICommand _AbortCommand;
|
||||
public ICommand AbortCommand
|
||||
{
|
||||
get => _AbortCommand;
|
||||
set => SetProperty(ref _AbortCommand, value);
|
||||
}
|
||||
public async Task AbortCommandExecute()
|
||||
{
|
||||
IsScanning = false;
|
||||
IsVisible = false;
|
||||
|
||||
await _NavigationService.GoBackAsync().ConfigureAwait(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region INavigationService
|
||||
public override void OnNavigatedFrom(INavigationParameters parameters)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void OnNavigatedTo(INavigationParameters parameters)
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user