FrameDetailsPage.xaml.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Comal.Classes;
  6. using InABox.Clients;
  7. using InABox.Core;
  8. using Xamarin.Forms;
  9. using XF.Material.Forms.UI;
  10. using XF.Material.Forms.UI.Dialogs;
  11. namespace comal.timesheets
  12. {
  13. public partial class FrameDetailsPage : ContentPage
  14. {
  15. ScannerPage scanner = null;
  16. DeliveryItem _item = null;
  17. public FrameDetailsPage(String code)
  18. {
  19. InitializeComponent();
  20. NavigationPage.SetHasBackButton(this, false);
  21. ToolbarItems.Clear();
  22. ToolbarItems.Add(new ToolbarItem("Back", "", () =>
  23. {
  24. Navigation.PopAsync();
  25. }));
  26. LoadData(code);
  27. }
  28. protected override async void OnAppearing()
  29. {
  30. base.OnAppearing();
  31. //if (scanner != null)
  32. //{
  33. // await LoadData(scanner.Result);
  34. // scanner = null;
  35. //}
  36. }
  37. Dictionary<Button, Guid> pdfs = new Dictionary<Button, Guid>();
  38. private async void LoadData(String code)
  39. {
  40. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  41. {
  42. DeliveryItem item = null;
  43. CoreTable items = new Client<DeliveryItem>().Query(
  44. new Filter<DeliveryItem>(x => x.Barcode).IsEqualTo(code),
  45. new Columns<DeliveryItem>(
  46. x => x.Description,
  47. x => x.ManufacturingPacketLink.Location,
  48. x => x.JobLink.JobNumber,
  49. x => x.JobLink.Name,
  50. x => x.ManufacturingPacketLink.SetoutLink.Number,
  51. x => x.ManufacturingPacketLink.SetoutLink.Description,
  52. x => x.ManufacturingPacketLink.Serial
  53. ));
  54. if (items.Rows.Any())
  55. {
  56. item = items.Rows.FirstOrDefault().ToObject<DeliveryItem>();
  57. Task.Run(() =>
  58. {
  59. CoreTable docs = new Client<SetoutDocument>().Query(
  60. new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(item.ManufacturingPacketLink.SetoutLink.ID).And(x => x.Superceded).IsEqualTo(DateTime.MinValue),
  61. new Columns<SetoutDocument>(x => x.DocumentLink.FileName, x => x.DocumentLink.ID)
  62. );
  63. foreach (var row in docs.Rows)
  64. {
  65. if (string.IsNullOrWhiteSpace(row.Get<SetoutDocument, string>(x => x.DocumentLink.FileName)))
  66. continue;
  67. MaterialButton button = new MaterialButton();
  68. button.Text = row.Get<SetoutDocument, String>(x => x.DocumentLink.FileName);
  69. button.Padding = new Thickness(0, 10, 0, 10);
  70. button.ButtonType = MaterialButtonType.Elevated;
  71. button.Clicked += ViewPDF;
  72. button.HorizontalOptions = LayoutOptions.FillAndExpand;
  73. pdfs[button] = row.Get<SetoutDocument, Guid>(x => x.DocumentLink.ID);
  74. }
  75. Device.BeginInvokeOnMainThread(() =>
  76. {
  77. this.documents.Children.Clear();
  78. foreach (var button in pdfs.Keys)
  79. this.documents.Children.Add(button);
  80. });
  81. });
  82. }
  83. else
  84. item = new DeliveryItem();
  85. Device.BeginInvokeOnMainThread(() =>
  86. {
  87. if (item != null)
  88. this.BindingContext = item;
  89. });
  90. }
  91. }
  92. private void ViewPDF(object sender, EventArgs e)
  93. {
  94. MaterialButton button = sender as MaterialButton;
  95. if (pdfs.ContainsKey(button))
  96. {
  97. var page = new FrameDocumentPage(pdfs[button], button.Text);
  98. Navigation.PushAsync(page);
  99. }
  100. }
  101. void ScanBarcode_Clicked(System.Object sender, System.EventArgs e)
  102. {
  103. scanner = new ScannerPage();
  104. Navigation.PushAsync(scanner);
  105. }
  106. }
  107. }