StoreRequiList.xaml.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 static comal.timesheets.RequiItems;
  12. namespace comal.timesheets.StoreRequis
  13. {
  14. [XamlCompilation(XamlCompilationOptions.Compile)]
  15. public partial class StoreRequiList : ContentPage
  16. {
  17. List<RequiShell> requiShells = new List<RequiShell>();
  18. public StoreRequiList()
  19. {
  20. InitializeComponent();
  21. LoadHoldingsCache();
  22. if (Device.RuntimePlatform.Equals(Device.iOS))
  23. {
  24. imageBtn0.Margin = new Thickness(0);
  25. imageBtn0.VerticalOptions = LayoutOptions.FillAndExpand;
  26. imageBtn0.HeightRequest = 160;
  27. takerequinow.Margin = new Thickness(0);
  28. takerequinow.VerticalOptions = LayoutOptions.FillAndExpand;
  29. takerequinow.HeightRequest = 160;
  30. storereqimg.Margin = new Thickness(0);
  31. storereqimg.HeightRequest = 120;
  32. }
  33. }
  34. protected override void OnAppearing()
  35. {
  36. LoadList();
  37. base.OnAppearing();
  38. }
  39. private async void LoadList()
  40. {
  41. await Task.Run(() =>
  42. {
  43. requiShells.Clear();
  44. CoreTable table = new Client<Requisition>().Query(
  45. new Filter<Requisition>(x => x.Filled).IsEqualTo(DateTime.MinValue),
  46. new Columns<Requisition>(
  47. x => x.ID, //0
  48. x => x.Number, //1
  49. x => x.Due, //2
  50. x => x.RequestedBy.Name, //3
  51. x => x.JobLink.JobNumber, //4
  52. x => x.JobLink.Name, //5
  53. x => x.Request //6
  54. ),
  55. new SortOrder<Requisition>(x => x.Due)
  56. );
  57. foreach (var row in table.Rows)
  58. {
  59. List<object> list = row.Values;
  60. if (list[0] == null) { list[0] = Guid.Empty; } //0
  61. if (list[1] == null) { list[1] = 0; } //1
  62. if (list[2] == null) { list[2] = DateTime.MinValue; } //2
  63. if (list[3] == null) { list[3] = ""; } //3
  64. if (list[4] == null) { list[4] = ""; } //4
  65. if (list[5] == null) { list[5] = ""; } //5
  66. if (list[6] == null) { list[6] = ""; } //6
  67. RequiShell requiShell = new RequiShell();
  68. requiShell.ID = Guid.Parse(list[0].ToString());
  69. requiShell.Number = "No. " + list[1].ToString();
  70. requiShell.Due = "Due " + DateTime.Parse(list[2].ToString()).ToString("dd MMM yy");
  71. requiShell.Contact = "Contact: " + list[3].ToString();
  72. requiShell.Job = "(" + list[4].ToString() + ") " + list[5].ToString();
  73. requiShell.Request = list[6].ToString();
  74. requiShells.Add(requiShell);
  75. }
  76. Device.BeginInvokeOnMainThread(() =>
  77. {
  78. requisListView.ItemsSource = null;
  79. requisListView.ItemsSource = requiShells;
  80. listLbl.Text = "List of Unfilled Requis (" + requiShells.Count + ")";
  81. });
  82. });
  83. }
  84. private void Requi_Clicked(object sender, EventArgs e)
  85. {
  86. RequiShell requiShell = requisListView.SelectedItem as RequiShell;
  87. StoreRequiScannerPage storeRequiScannerPage = new StoreRequiScannerPage(requiShell.ID);
  88. Navigation.PushAsync(storeRequiScannerPage);
  89. }
  90. private void TakeStockNow_Tapped(object sender, EventArgs e)
  91. {
  92. StoreRequiScannerPage page = new StoreRequiScannerPage(Guid.Empty);
  93. Navigation.PushAsync(page);
  94. }
  95. private void NewRequiRequest_Tapped(object sender, EventArgs e)
  96. {
  97. StoreRequiConfirmationPage storeRequiConfirmationPage = new StoreRequiConfirmationPage();
  98. Navigation.PushAsync(storeRequiConfirmationPage);
  99. }
  100. #region Utilities
  101. private async void LoadHoldingsCache()
  102. {
  103. await Task.Run(() =>
  104. {
  105. holdingsCache = new List<HoldingsCacheShell>();
  106. CoreTable table = new Client<StockHolding>().Query(
  107. new Filter<StockHolding>(x => x.Qty).IsGreaterThan(0),
  108. new Columns<StockHolding>(
  109. x => x.ID, //0
  110. x => x.Product.ID, //1
  111. x => x.Location.ID, //2
  112. x => x.Location.Description, //3
  113. x => x.Units, //4
  114. x => x.Dimensions.UnitSize, //5
  115. x => x.Job.ID, //6
  116. x => x.Job.JobNumber, //7
  117. x => x.Job.Name, //8
  118. x => x.Style.ID, //9
  119. x => x.Style.Code, //10
  120. x => x.Style.Description //11
  121. )
  122. );
  123. foreach (CoreRow row in table.Rows)
  124. {
  125. List<object> list = row.Values;
  126. if (list[4] == null) { list[4] = 0.0; } //4
  127. double dble = 0.0;
  128. if (double.TryParse(list[4].ToString(), out dble))
  129. {
  130. if (dble != 0.0 && dble > 0) //filtering out zero quantities
  131. {
  132. if (list[0] == null) { list[0] = Guid.Empty; } //0
  133. if (list[1] == null) { list[1] = Guid.Empty; } //1
  134. if (list[2] == null) { list[2] = Guid.Empty; } //2
  135. if (list[3] == null) { list[3] = ""; } //3
  136. if (list[5] == null) { list[5] = ""; } //5
  137. if (list[6] == null) { list[6] = Guid.Empty; } //6
  138. if (list[7] == null) { list[7] = ""; } //7
  139. if (list[8] == null) { list[8] = ""; } //8
  140. if (list[9] == null) { list[9] = Guid.Empty; } //9
  141. if (list[10] == null) { list[10] = ""; } //10
  142. if (list[11] == null) { list[11] = ""; } //11
  143. HoldingsCacheShell holdingsCacheShell = new HoldingsCacheShell()
  144. {
  145. ID = Guid.Parse(list[0].ToString()),
  146. ProductID = Guid.Parse(list[1].ToString()),
  147. LocationID = Guid.Parse(list[2].ToString()),
  148. LocationName = list[3].ToString(),
  149. Units = double.Parse(list[4].ToString()).ToString(),
  150. DimensionsUnitSize = list[5].ToString(),
  151. JobID = Guid.Parse(list[6].ToString()),
  152. JobNumber = list[7].ToString(),
  153. JobName = list[8].ToString(),
  154. StyleID = Guid.Parse(list[9].ToString()),
  155. StyleCode = list[10].ToString(),
  156. StyleDescription = list[11].ToString(),
  157. };
  158. if (holdingsCacheShell.Units != "0")
  159. {
  160. holdingsCache.Add(holdingsCacheShell);
  161. }
  162. }
  163. }
  164. }
  165. RequiItems.HoldingsLoaded = true;
  166. });
  167. }
  168. #endregion
  169. }
  170. public class RequiShell
  171. {
  172. public Guid ID { get; set; }
  173. public string Number { get; set; }
  174. public string Due { get; set; }
  175. public string Contact { get; set; }
  176. public string Job { get; set; }
  177. public string Request { get; set; }
  178. public RequiShell()
  179. {
  180. ID = Guid.Empty;
  181. Number = "";
  182. Due = "";
  183. Due = "";
  184. Job = "";
  185. Request = "";
  186. }
  187. }
  188. }