| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System;
- using System.Linq;
- using System.Threading.Tasks;
- using InABox.Clients;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI.Dialogs;
- namespace PRS.Mobile
- {
- public enum EmployeeQualificationImageType
- {
- Front,
- Back,
- Other
- }
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class EmployeeQualificationEditImagesView
- {
- public EmployeeQualificationEditImagesView()
- {
- InitializeComponent();
- }
- public override void Refresh()
- {
- if (ViewModel == null)
- return;
-
- _otherImages.ParentID = ViewModel.Item.ID;
- _otherImages.ItemsSource = ViewModel.Documents;
- var front = ViewModel.Photos.FirstOrDefault(x => x.ID == ViewModel.Item.FrontPhotoID);
- var back = ViewModel.Photos.FirstOrDefault(x => x.ID == ViewModel.Item.BackPhotoID);
- _frontImage.Load(front?.FileName, front?.Data);
- _backImage.Load(back?.FileName, back?.Data);
- }
- public EmployeeQualificationImageType ImageType =>
- _accordion.SelectedItem == _frontitem
- ? EmployeeQualificationImageType.Front
- : _accordion.SelectedItem == _backitem
- ? EmployeeQualificationImageType.Back
- : EmployeeQualificationImageType.Other;
-
- public async Task AddImage<T, TOptions>(TOptions options)
- where T : MobileImageSource<T,TOptions>
- where TOptions : MobileImageOptions<T>, new()
- {
- if (_accordion.SelectedItem == _otheritem)
- {
- await _otherImages.AddImage<T, TOptions, EmployeeQualificationDocumentShell>(options);
- return;
- }
-
- MobileDocument file = null;
- try
- {
- file = await MobileDocument.From(options);
- }
- catch (Exception e)
- {
- await MaterialDialog.Instance.AlertAsync(e.Message, "ERROR");
- }
-
- if (file != null)
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync("Saving Image"))
- {
- Document doc = new Document()
- {
- FileName = file.FileName,
- Data = file.Data,
- CRC = CoreUtils.CalculateCRC(file.Data),
- TimeStamp = DateTime.Now
- };
- new Client<Document>().Save(doc, "Created on Mobile Device");
-
- if (_accordion.SelectedItem == _frontitem)
- {
- ViewModel.Item.FrontPhotoID = doc.ID;
- ViewModel.Item.Save("Front Image Loaded from Mobile Device");
- _frontImage.Load(file.FileName,file.Data);
- }
-
- else if (_accordion.SelectedItem == _backitem)
- {
- ViewModel.Item.BackPhotoID = doc.ID;
- ViewModel.Item.Save("Back Image Loaded from Mobile Device");
- _backImage.Load(file.FileName,file.Data);
- }
- }
- }
- }
- }
- }
|