1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Comal.Classes;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace PRS.Mobile
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class ScanModule
- {
- private ScanTagModel _tags;
- private ScanModel _scans;
-
- public ScanModule()
- {
- _scans = new ScanModel(App.Data,
- () => new Filter<Scan>(x => x.Employee.ID).IsEqualTo(App.Data.Me.ID)
- .And(x => x.Processed).IsEqualTo(false)
- ) { FileName = "scans.data" };
- _tags = new ScanTagModel(App.Data, null) { FileName = "scantags.data" };
-
- InitializeComponent();
- ProgressVisible = true;
- RefreshData(false, true);
- }
- private void RefreshData(bool force, bool async)
- {
- Task[] tasks = new Task[]
- {
- Task.Run(() => _scans.Refresh(force)),
- Task.Run(() => _tags.Refresh(force))
- };
- if (async)
- Task.WhenAll(tasks).ContinueWith((_) => Device.BeginInvokeOnMainThread(RefreshScreen));
- else
- {
- Task.WaitAll(tasks);
- RefreshScreen();
- }
- }
- private void RefreshScreen()
- {
- ProgressVisible = false;
- _documents.ItemsSource = null;
- _documents.ItemsSource = _scans;
- }
- private async Task<bool> ConfirmScan(ScanShell shell)
- {
- shell.EmployeeID = App.Data.Me.ID;
- if (!_tags.Any())
- return true;
- var tag = await DisplayActionSheet("Select Tag", "Cancel", null, _tags.Items.Select(x => x.Name).ToArray());
- shell.TagID = _tags.Items.FirstOrDefault(x => String.Equals(x.Name, tag))?.ID ?? Guid.Empty;
-
- return !string.Equals(tag,"Cancel");
- }
- private async void TakePhoto_Clicked(object sender, EventArgs e)
- {
- await _documents.AddImage<MobileDocumentCameraSource,ScanShell>(false, ConfirmScan);
- }
- private async void BrowseLibrary_Clicked(object sender, EventArgs e)
- {
- await _documents.AddImage<MobileDocumentLibrarySource,ScanShell>(false, ConfirmScan);
- }
- private void _documents_OnRefreshRequested(object sender, MobileListRefreshEventArgs args)
- {
- RefreshData(true,false);
- }
- }
- }
|