StoreRequiList.xaml.cs 5.4 KB

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