StoreRequiList.xaml.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. LoadHoldingsCache();
  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 async void LoadList()
  41. {
  42. await Task.Run(() =>
  43. {
  44. requiShells.Clear();
  45. CoreTable table = new Client<Requisition>().Query(
  46. new Filter<Requisition>(x => x.Filled).IsEqualTo(DateTime.MinValue),
  47. new Columns<Requisition>(
  48. x => x.ID, //0
  49. x => x.Number, //1
  50. x => x.Due, //2
  51. x => x.RequestedBy.Name, //3
  52. x => x.JobLink.JobNumber, //4
  53. x => x.JobLink.Name, //5
  54. x => x.Request //6
  55. ),
  56. new SortOrder<Requisition>(x => x.Due)
  57. );
  58. foreach (var row in table.Rows)
  59. {
  60. List<object> list = row.Values;
  61. if (list[0] == null) { list[0] = Guid.Empty; } //0
  62. if (list[1] == null) { list[1] = 0; } //1
  63. if (list[2] == null) { list[2] = DateTime.MinValue; } //2
  64. if (list[3] == null) { list[3] = ""; } //3
  65. if (list[4] == null) { list[4] = ""; } //4
  66. if (list[5] == null) { list[5] = ""; } //5
  67. if (list[6] == null) { list[6] = ""; } //6
  68. RequiShell requiShell = new RequiShell();
  69. requiShell.ID = Guid.Parse(list[0].ToString());
  70. requiShell.Number = "No. " + list[1].ToString();
  71. requiShell.Due = "Due " + DateTime.Parse(list[2].ToString()).ToString("dd MMM yy");
  72. requiShell.Contact = "Contact: " + list[3].ToString();
  73. requiShell.Job = "(" + list[4].ToString() + ") " + list[5].ToString();
  74. requiShell.Request = list[6].ToString();
  75. requiShells.Add(requiShell);
  76. }
  77. Device.BeginInvokeOnMainThread(() =>
  78. {
  79. requisListView.ItemsSource = null;
  80. requisListView.ItemsSource = requiShells;
  81. listLbl.Text = "List of Unfilled Requis (" + requiShells.Count + ")";
  82. });
  83. });
  84. }
  85. private void Requi_Clicked(object sender, EventArgs e)
  86. {
  87. RequiShell requiShell = requisListView.SelectedItem as RequiShell;
  88. StoreRequiScannerPage storeRequiScannerPage = new StoreRequiScannerPage(requiShell.ID);
  89. Navigation.PushAsync(storeRequiScannerPage);
  90. }
  91. private void TakeStockNow_Tapped(object sender, EventArgs e)
  92. {
  93. StoreRequiScannerPage page = new StoreRequiScannerPage(Guid.Empty);
  94. Navigation.PushAsync(page);
  95. }
  96. private void NewRequiRequest_Tapped(object sender, EventArgs e)
  97. {
  98. StoreRequiConfirmationPage storeRequiConfirmationPage = new StoreRequiConfirmationPage();
  99. Navigation.PushAsync(storeRequiConfirmationPage);
  100. }
  101. #region Utilities
  102. private async void LoadHoldingsCache()
  103. {
  104. await Task.Run(() =>
  105. {
  106. holdingsCache = new List<HoldingsCacheShell>();
  107. CoreTable table = new Client<StockHolding>().Query(
  108. new Filter<StockHolding>(x => x.Qty).IsGreaterThan(0),
  109. new Columns<StockHolding>(
  110. x => x.ID,
  111. x => x.Product.ID,
  112. x => x.Location.ID,
  113. x => x.Location.Description,
  114. x => x.Units,
  115. x => x.Job.ID,
  116. x => x.Job.JobNumber,
  117. x => x.Job.Name,
  118. x => x.Style.ID,
  119. x => x.Style.Code,
  120. x => x.Style.Description,
  121. x => x.Dimensions.Unit.ID,
  122. x => x.Dimensions.Unit.HasQuantity,
  123. x => x.Dimensions.Unit.HasLength,
  124. x => x.Dimensions.Unit.HasHeight,
  125. x => x.Dimensions.Unit.HasWeight,
  126. x => x.Dimensions.Unit.HasWidth,
  127. x => x.Dimensions.Quantity,
  128. x => x.Dimensions.Length,
  129. x => x.Dimensions.Height,
  130. x => x.Dimensions.Weight,
  131. x => x.Dimensions.Width,
  132. x => x.Dimensions.Unit.Format,
  133. x => x.Dimensions.Unit.Formula,
  134. x => x.Dimensions.UnitSize
  135. )
  136. );
  137. foreach (CoreRow row in table.Rows)
  138. {
  139. if (row.Get<StockHolding, double>(x => x.Units) == 0.0)
  140. continue;
  141. HoldingsCacheShell holding = new HoldingsCacheShell()
  142. {
  143. ProductID = row.Get<StockHolding, Guid>(x => x.Product.ID),
  144. LocationID = row.Get<StockHolding, Guid>(x => x.Location.ID),
  145. LocationName = row.Get<StockHolding, string>(x => x.Location.Description),
  146. Units = row.Get<StockHolding, double>(x => x.Units).ToString(),
  147. JobID = row.Get<StockHolding, Guid>(x => x.Job.ID),
  148. JobNumber = row.Get<StockHolding, string>(x => x.Job.JobNumber),
  149. JobName = row.Get<StockHolding, string>(x => x.Job.Name),
  150. StyleID = row.Get<StockHolding, Guid>(x => x.Style.ID),
  151. StyleCode = row.Get<StockHolding, string>(x => x.Style.Code),
  152. StyleDescription = row.Get<StockHolding, string>(x => x.Style.Description)
  153. };
  154. holding.Dimensions.Unit.ID = row.Get<StockHolding, Guid>(x => x.Dimensions.Unit.ID);
  155. holding.Dimensions.Unit.HasQuantity = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasQuantity);
  156. holding.Dimensions.Unit.HasLength = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasLength);
  157. holding.Dimensions.Unit.HasHeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasHeight);
  158. holding.Dimensions.Unit.HasWeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWeight);
  159. holding.Dimensions.Unit.HasWidth = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWidth);
  160. holding.Dimensions.Quantity = row.Get<StockHolding, double>(x => x.Dimensions.Quantity);
  161. holding.Dimensions.Length = row.Get<StockHolding, double>(x => x.Dimensions.Length);
  162. holding.Dimensions.Height = row.Get<StockHolding, double>(x => x.Dimensions.Height);
  163. holding.Dimensions.Weight = row.Get<StockHolding, double>(x => x.Dimensions.Weight);
  164. holding.Dimensions.Width = row.Get<StockHolding, double>(x => x.Dimensions.Width);
  165. holding.Dimensions.Unit.Format = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Format);
  166. holding.Dimensions.Unit.Formula = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Formula);
  167. holding.Dimensions.UnitSize = row.Get<StockHolding, string>(x => x.Dimensions.UnitSize);
  168. holding.LocationName = holding.LocationName + " (Units: " + holding.Units + ")" +
  169. Environment.NewLine + "Style: " + holding.StyleDescription
  170. + Environment.NewLine + "Job: " + holding.JobNumber
  171. + Environment.NewLine + "Size: " + holding.Dimensions.UnitSize;
  172. holdingsCache.Add(holding);
  173. }
  174. ;
  175. RequiItems.HoldingsLoaded = true;
  176. });
  177. }
  178. #endregion
  179. }
  180. public class RequiShell
  181. {
  182. public Guid ID { get; set; }
  183. public string Number { get; set; }
  184. public string Due { get; set; }
  185. public string Contact { get; set; }
  186. public string Job { get; set; }
  187. public string Request { get; set; }
  188. public RequiShell()
  189. {
  190. ID = Guid.Empty;
  191. Number = "";
  192. Due = "";
  193. Due = "";
  194. Job = "";
  195. Request = "";
  196. }
  197. }
  198. }