|
@@ -1,6 +1,15 @@
|
|
|
+using Comal.Classes;
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
+using InABox.Avalonia;
|
|
|
using InABox.Avalonia.Components;
|
|
|
+using InABox.Avalonia.Dialogs;
|
|
|
+using InABox.Core;
|
|
|
+using Microsoft.Extensions.Logging.Abstractions;
|
|
|
+using Microsoft.Maui.Devices;
|
|
|
using PRS.Avalonia.Components;
|
|
|
+using System;
|
|
|
+using System.Linq;
|
|
|
+using System.Threading.Tasks;
|
|
|
|
|
|
namespace PRS.Avalonia.Modules;
|
|
|
|
|
@@ -11,11 +20,11 @@ public partial class EquipmentModuleViewModel : ModuleViewModel
|
|
|
public EquipmentModuleViewModel()
|
|
|
{
|
|
|
Modules = new AvaloniaModuleCollection();
|
|
|
- Modules.Add<EquipmentScannerViewModel>(
|
|
|
- "Equipment Scanner",
|
|
|
- "Identify Equipment from a barcode",
|
|
|
+ Modules.Add(
|
|
|
+ "Equipment Scanner",
|
|
|
+ "Identify Equipment from a barcode",
|
|
|
Images.barcode,
|
|
|
- isVisible: false);
|
|
|
+ Scanner_Tapped);
|
|
|
|
|
|
Modules.Add<EquipmentListViewModel>(
|
|
|
"Equipment List",
|
|
@@ -34,4 +43,56 @@ public partial class EquipmentModuleViewModel : ModuleViewModel
|
|
|
}
|
|
|
|
|
|
public override string Title => "Equipment";
|
|
|
+
|
|
|
+ private void Scanner_Tapped()
|
|
|
+ {
|
|
|
+ Navigation.Navigate<ScannerViewModel>(model =>
|
|
|
+ {
|
|
|
+ model.ItemScanned = async (results) =>
|
|
|
+ {
|
|
|
+ Guid? equipmentID = null;
|
|
|
+ foreach(var barCode in results)
|
|
|
+ {
|
|
|
+ if (Guid.TryParse(barCode.RawValue, out var eID))
|
|
|
+ {
|
|
|
+ equipmentID = eID;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(equipmentID is null)
|
|
|
+ {
|
|
|
+ Vibration.Vibrate();
|
|
|
+ await Task.Delay(200);
|
|
|
+ Vibration.Vibrate();
|
|
|
+ await Task.Delay(1000);
|
|
|
+ //await MessageDialog.ShowMessage("Invalid Code");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Vibration.Vibrate();
|
|
|
+ var model = new EquipmentModel(
|
|
|
+ DataAccess,
|
|
|
+ () => new Filter<Equipment>(x => x.ID).IsEqualTo(equipmentID),
|
|
|
+ () => DefaultCacheFileName<EquipmentShell>());
|
|
|
+ await model.RefreshAsync(true);
|
|
|
+
|
|
|
+ var equipment = model.FirstOrDefault();
|
|
|
+ if(equipment is null)
|
|
|
+ {
|
|
|
+ // await MessageDialog.ShowMessage("Cannot load equipment!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Navigation.Navigate<EquipmentDetailsViewModel>(model =>
|
|
|
+ {
|
|
|
+ model.Shell = equipment;
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|