StoreRequiList.xaml.cs 5.6 KB

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