EquipmentEditSpecificationsView.xaml.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using InABox.Clients;
  7. using InABox.Core;
  8. using InABox.Mobile;
  9. using Xamarin.Forms;
  10. using Xamarin.Forms.Xaml;
  11. using XF.Material.Forms.UI.Dialogs;
  12. namespace PRS.Mobile
  13. {
  14. [XamlCompilation(XamlCompilationOptions.Compile)]
  15. public partial class EquipmentEditSpecificationsView
  16. {
  17. public EquipmentEditSpecificationsView()
  18. {
  19. InitializeComponent();
  20. }
  21. public override void Refresh()
  22. {
  23. var document = ViewModel.SpecificationSheet.FirstOrDefault();
  24. if (document != null)
  25. _viewer.Load(document.FileName, document.Data);
  26. _viewer.IsVisible = document != null;
  27. _noviewer.IsVisible = document == null;
  28. }
  29. public async Task AddImage<T, TOptions>(TOptions options)
  30. where T : MobileImageSource<T,TOptions>
  31. where TOptions: MobileImageOptions<T>, new()
  32. {
  33. MobileDocument file = null;
  34. try
  35. {
  36. file = await MobileDocument.From<T>(options);
  37. }
  38. catch (Exception e)
  39. {
  40. await MaterialDialog.Instance.AlertAsync(e.Message, "ERROR");
  41. }
  42. if (file != null)
  43. {
  44. using (await MaterialDialog.Instance.LoadingDialogAsync("Saving Image"))
  45. {
  46. Document doc = new Document()
  47. {
  48. FileName = file.FileName,
  49. Data = file.Data,
  50. CRC = CoreUtils.CalculateCRC(file.Data),
  51. TimeStamp = DateTime.Now
  52. };
  53. new Client<Document>().Save(doc, "Created on Mobile Device");
  54. ViewModel.Item.SpecificationSheetID = doc.ID;
  55. ViewModel.Item.Save("Specification Sheet updated from Mobile Device");
  56. ViewModel.SpecificationSheet.Refresh(true);
  57. Dispatcher.BeginInvokeOnMainThread(Refresh);
  58. }
  59. }
  60. }
  61. }
  62. }