StoreRequiList.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Comal.Classes;
  7. using comal.timesheets.StoreRequis;
  8. using InABox.Clients;
  9. using InABox.Core;
  10. using InABox.Mobile;
  11. using Xamarin.Forms;
  12. using Xamarin.Forms.Xaml;
  13. using ZXing.PDF417.Internal;
  14. using static comal.timesheets.RequiItems;
  15. namespace comal.timesheets
  16. {
  17. [XamlCompilation(XamlCompilationOptions.Compile)]
  18. public partial class StoreRequiList
  19. {
  20. List<RequiShell> requiShells = new List<RequiShell>();
  21. public StoreRequiList()
  22. {
  23. InitializeComponent();
  24. HoldingsLoaded = true;
  25. if (Device.RuntimePlatform.Equals(Device.iOS))
  26. {
  27. imageBtn0.Margin = new Thickness(0);
  28. imageBtn0.VerticalOptions = LayoutOptions.FillAndExpand;
  29. imageBtn0.HeightRequest = 160;
  30. takerequinow.Margin = new Thickness(0);
  31. takerequinow.VerticalOptions = LayoutOptions.FillAndExpand;
  32. takerequinow.HeightRequest = 160;
  33. storereqimg.Margin = new Thickness(0);
  34. storereqimg.HeightRequest = 120;
  35. }
  36. }
  37. protected override void OnAppearing()
  38. {
  39. LoadList();
  40. base.OnAppearing();
  41. }
  42. private void LoadList()
  43. {
  44. Task.Run(() =>
  45. {
  46. requiShells.Clear();
  47. CoreTable table = DoRequisitionQuery();
  48. while (table == null)
  49. table = DoRequisitionQuery();
  50. foreach (var row in table.Rows)
  51. {
  52. RequiShell requiShell = new RequiShell();
  53. requiShell.ID = row.Get<Requisition, Guid>(x => x.ID);
  54. requiShell.Number = "No. " + row.Get<Requisition,int>(x => x.Number);
  55. requiShell.Due = "Due " + row.Get<Requisition, DateTime>(x => x.Due).ToString("dd MMM yy");
  56. requiShell.Contact = "Contact: " + row.Get<Requisition, string>(x => x.RequestedBy.Name);
  57. requiShell.Job = "(" + row.Get<Requisition, string>(x => x.JobLink.JobNumber) + ") " + row.Get<Requisition, string>(x => x.JobLink.Name);
  58. requiShell.Request = row.Get<Requisition, string>(x => x.Request);
  59. string notes = CheckNotes(row.Get<Requisition, string[]>(x => x.Notes));
  60. requiShell.Request = requiShell.Request + System.Environment.NewLine + notes;
  61. requiShells.Add(requiShell);
  62. }
  63. Device.BeginInvokeOnMainThread(() =>
  64. {
  65. requisListView.ItemsSource = null;
  66. requisListView.ItemsSource = requiShells;
  67. listLbl.Text = "List of Unfilled Requis (" + requiShells.Count + ")";
  68. });
  69. });
  70. }
  71. private CoreTable DoRequisitionQuery()
  72. {
  73. try
  74. {
  75. return new Client<Requisition>().Query(
  76. new Filter<Requisition>(x => x.Filled).IsEqualTo(DateTime.MinValue),
  77. new Columns<Requisition>(
  78. x => x.ID,
  79. x => x.Number,
  80. x => x.Due,
  81. x => x.RequestedBy.Name,
  82. x => x.JobLink.JobNumber,
  83. x => x.JobLink.Name,
  84. x => x.Request,
  85. x => x.Notes
  86. ),
  87. new SortOrder<Requisition>(x => x.Due)
  88. );
  89. }
  90. catch (Exception ex)
  91. {
  92. InABox.Mobile.MobileLogging.Log(ex);
  93. return null;
  94. }
  95. }
  96. private string CheckNotes(string[] notes)
  97. {
  98. string combinednotes = "----------" + System.Environment.NewLine + "NOTES: " + System.Environment.NewLine;
  99. if (notes.Count() > 0)
  100. {
  101. foreach (var note in notes)
  102. {
  103. combinednotes = combinednotes + note + System.Environment.NewLine;
  104. }
  105. }
  106. return combinednotes;
  107. }
  108. private void Requi_Clicked(object sender, EventArgs e)
  109. {
  110. RequiShell requiShell = requisListView.SelectedItem as RequiShell;
  111. StoreRequiScannerPage storeRequiScannerPage = new StoreRequiScannerPage(requiShell.ID);
  112. Navigation.PushAsync(storeRequiScannerPage);
  113. }
  114. private void TakeStockNow_Tapped(object sender, EventArgs e)
  115. {
  116. StoreRequiScannerPage page = new StoreRequiScannerPage(Guid.Empty);
  117. Navigation.PushAsync(page);
  118. }
  119. private void NewRequiRequest_Tapped(object sender, EventArgs e)
  120. {
  121. StoreRequiConfirmationPage storeRequiConfirmationPage = new StoreRequiConfirmationPage();
  122. Navigation.PushAsync(storeRequiConfirmationPage);
  123. }
  124. }
  125. public class RequiShell
  126. {
  127. public Guid ID { get; set; }
  128. public string Number { get; set; }
  129. public string Due { get; set; }
  130. public string Contact { get; set; }
  131. public string Job { get; set; }
  132. public string Request { get; set; }
  133. public RequiShell()
  134. {
  135. ID = Guid.Empty;
  136. Number = "";
  137. Due = "";
  138. Due = "";
  139. Job = "";
  140. Request = "";
  141. }
  142. }
  143. }