FrameDocumentPage.xaml.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using InABox.Clients;
  6. using InABox.Core;
  7. using Xamarin.Forms;
  8. namespace comal.timesheets
  9. {
  10. public partial class FrameDocumentPage
  11. {
  12. private Guid _documentid = Guid.Empty;
  13. public FrameDocumentPage(Guid documentid, String filename)
  14. {
  15. InitializeComponent();
  16. NavigationPage.SetHasBackButton(this, false);
  17. ToolbarItems.Clear();
  18. ToolbarItems.Add(new ToolbarItem("Back", "", () =>
  19. {
  20. Navigation.PopAsync();
  21. }));
  22. Title = filename;
  23. pdf.Toolbar.Enabled = false;
  24. _documentid = documentid;
  25. new Client<Document>().Query(
  26. new Filter<Document>(x => x.ID).IsEqualTo(_documentid),
  27. null,
  28. null,
  29. (docs, error) =>
  30. {
  31. LoadDocument(docs);
  32. }
  33. );
  34. }
  35. private void LoadDocument(CoreTable docs)
  36. {
  37. if (docs.Rows.Any())
  38. {
  39. byte[] data = docs.Rows.First().Get<Document, byte[]>(x => x.Data);
  40. MemoryStream ms = new MemoryStream(data);
  41. Device.BeginInvokeOnMainThread(() =>
  42. {
  43. this.pdf.LoadDocument(ms);
  44. });
  45. }
  46. }
  47. }
  48. }