1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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 DocScannerModule
- {
- private DataEntryTagModel _tags;
- private DataEntryDocumentModel _dataEntriesDocument;
-
- public DocScannerModule()
- {
- _dataEntriesDocument = new DataEntryDocumentModel(App.Data,
- () => new Filter<DataEntryDocument>(x => x.Employee.ID).IsEqualTo(App.Data.Me.ID)
- .And(x => x.Archived).IsEqualTo(DateTime.MinValue)
- ) { FileName = "scans.data" };
- _tags = new DataEntryTagModel(App.Data, null) { FileName = "scantags.data" };
-
- InitializeComponent();
- ProgressVisible = true;
- RefreshData(false, true);
- }
- private void RefreshData(bool force, bool async)
- {
- _dataEntriesDocument.Refresh(force);
-
- Task[] tasks = new Task[]
- {
- //Task.Run(() => _dataEntriesDocument.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 = _dataEntriesDocument;
- }
- private async Task<bool> ConfirmScan(DataEntryDocumentShell documentShell)
- {
- documentShell.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());
- documentShell.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, MobileDocumentCameraOptions,DataEntryDocumentShell>(
- PhotoUtils.CreateCameraOptions(),
- ConfirmScan);
- }
- private async void BrowseLibrary_Clicked(object sender, EventArgs e)
- {
- await _documents.AddImage<MobileDocumentPhotoLibrarySource,MobileDocumentPhotoLibraryOptions,DataEntryDocumentShell>(
- PhotoUtils.CreatePhotoLibraryOptions(),
- ConfirmScan);
- }
- private void _documents_OnRefreshRequested(object sender, MobileListRefreshEventArgs args)
- {
- RefreshData(true,false);
- }
- }
- }
|