FrameDetailsPage.xaml.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. x => x.SetoutLink.ID
  54. ));
  55. if (items.Rows.Any())
  56. {
  57. item = items.Rows.FirstOrDefault().ToObject<DeliveryItem>();
  58. if (item.SetoutLink.ID != Guid.Empty)
  59. Task.Run(() =>
  60. {
  61. CoreTable docs = new Client<SetoutDocument>().Query(
  62. new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(item.SetoutLink.ID)
  63. .And(x => x.Superceded).IsEqualTo(DateTime.MinValue),
  64. new Columns<SetoutDocument>(x => x.DocumentLink.FileName, x => x.DocumentLink.ID)
  65. );
  66. foreach (var row in docs.Rows)
  67. {
  68. if (string.IsNullOrWhiteSpace(row.Get<SetoutDocument, string>(x => x.DocumentLink.FileName)))
  69. continue;
  70. MaterialButton button = new MaterialButton();
  71. button.Text = row.Get<SetoutDocument, String>(x => x.DocumentLink.FileName);
  72. button.Padding = new Thickness(0, 10, 0, 10);
  73. button.ButtonType = MaterialButtonType.Elevated;
  74. button.Clicked += ViewPDF;
  75. button.HorizontalOptions = LayoutOptions.FillAndExpand;
  76. pdfs[button] = row.Get<SetoutDocument, Guid>(x => x.DocumentLink.ID);
  77. }
  78. Device.BeginInvokeOnMainThread(() =>
  79. {
  80. this.documents.Children.Clear();
  81. foreach (var button in pdfs.Keys)
  82. this.documents.Children.Add(button);
  83. });
  84. });
  85. }
  86. else
  87. item = new DeliveryItem();
  88. Device.BeginInvokeOnMainThread(() =>
  89. {
  90. if (item != null)
  91. this.BindingContext = item;
  92. });
  93. }
  94. }
  95. private void ViewPDF(object sender, EventArgs e)
  96. {
  97. MaterialButton button = sender as MaterialButton;
  98. if (pdfs.ContainsKey(button))
  99. {
  100. var page = new FrameDocumentPage(pdfs[button], button.Text);
  101. Navigation.PushAsync(page);
  102. }
  103. }
  104. void ScanBarcode_Clicked(System.Object sender, System.EventArgs e)
  105. {
  106. scanner = new ScannerPage();
  107. Navigation.PushAsync(scanner);
  108. }
  109. }
  110. }