RelocatePage.xaml.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using Comal.Classes;
  6. using InABox.Clients;
  7. using InABox.Core;
  8. using Xamarin.Forms;
  9. using XF.Material.Forms.UI;
  10. using XF.Material.Forms.UI.Dialogs;
  11. using comal.timesheets.Products;
  12. using System.Threading.Tasks;
  13. using Xamarin.Forms.Xaml;
  14. namespace comal.timesheets
  15. {
  16. [XamlCompilation(XamlCompilationOptions.Compile)]
  17. public partial class RelocatePage : BasePage
  18. {
  19. Guid _warehouseid = Guid.Empty;
  20. String _warehousename = "Select Warehouse";
  21. Guid _areaid = Guid.Empty;
  22. String _areaname = "Select Area / Rack";
  23. Guid _locationid = Guid.Empty;
  24. String _locationname = "Select Location / Pack";
  25. Job job = new Job();
  26. public RelocatePage()
  27. {
  28. InitializeComponent();
  29. }
  30. protected override void OnAppearing()
  31. {
  32. base.OnAppearing();
  33. UpdateScreen();
  34. }
  35. private void Relocate_Clicked(object sender, EventArgs e)
  36. {
  37. if (_locationid == Guid.Empty)
  38. return;
  39. Filter<StockArea> areafilter = new Filter<StockArea>(X => X.Active).IsEqualTo(true);
  40. GenericSelectionPage page = new GenericSelectionPage(
  41. "Move Stock Location to:",
  42. new SelectionViewModel<StockArea>(
  43. areafilter,
  44. new Expression<Func<StockArea, object>>[] { X => X.Description },
  45. new Expression<Func<StockArea, object>>[] { x => x.Warehouse.ID, x => x.Warehouse.Description },
  46. new SortOrder<StockArea>(x => x.Description)
  47. )
  48. );
  49. page.OnItemSelected += async (row) =>
  50. {
  51. var area = row.ToObject<StockArea>();
  52. if (_areaid != area.ID)
  53. {
  54. string chosenOption = await DisplayActionSheet("Change this Location's Area?", "Cancel", null, "Yes", "No");
  55. switch (chosenOption)
  56. {
  57. case "No":
  58. break;
  59. case "Cancel":
  60. break;
  61. case "Yes":
  62. StockLocation location = new StockLocation();
  63. location.ID = _locationid;
  64. location.Area.ID = area.ID;
  65. location.Warehouse.ID = area.Warehouse.ID;
  66. new Client<StockLocation>().Save(location, "Updated Stock Area", (o, err) => { });
  67. _warehouseid = area.Warehouse.ID;
  68. _warehousename = area.Warehouse.Description;
  69. _areaid = area.ID;
  70. _areaname = area.Description;
  71. UpdateScreen();
  72. await warehouseBtn.TranslateTo(0, -15, 150);
  73. await warehouseBtn.TranslateTo(0, 0, 150);
  74. await areaBtn.TranslateTo(0, -15, 150);
  75. await areaBtn.TranslateTo(0, 0, 150);
  76. await locationBtn.TranslateTo(0, -15, 150);
  77. await locationBtn.TranslateTo(0, 0, 150);
  78. break;
  79. default:
  80. break;
  81. }
  82. }
  83. };
  84. Navigation.PushAsync(page);
  85. }
  86. #region Warehouse/Area/Location buttons clicked
  87. void Warehouse_Clicked(System.Object sender, System.EventArgs e)
  88. {
  89. GenericSelectionPage page = new GenericSelectionPage(
  90. "Select Warehouse",
  91. new SelectionViewModel<StockWarehouse>(
  92. new Filter<StockWarehouse>(X => X.Active).IsEqualTo(true),
  93. new Expression<Func<StockWarehouse, object>>[] { X => X.Description },
  94. new Expression<Func<StockWarehouse, object>>[] { },
  95. new SortOrder<StockWarehouse>(x => x.Description)
  96. )
  97. );
  98. page.OnItemSelected += (row) =>
  99. {
  100. var warehouse = row.ToObject<StockWarehouse>();
  101. if (_warehouseid != warehouse.ID)
  102. {
  103. _warehouseid = warehouse.ID;
  104. _warehousename = warehouse.Description;
  105. _areaid = Guid.Empty;
  106. _areaname = "Select Area";
  107. _locationid = Guid.Empty;
  108. _locationname = "Select Location";
  109. }
  110. };
  111. Navigation.PushAsync(page);
  112. }
  113. void Area_Clicked(System.Object sender, System.EventArgs e)
  114. {
  115. Filter<StockArea> areafilter = new Filter<StockArea>(X => X.Active).IsEqualTo(true);
  116. if (_warehouseid != Guid.Empty)
  117. areafilter = areafilter.And(x => x.Warehouse.ID).IsEqualTo(_warehouseid);
  118. GenericSelectionPage page = new GenericSelectionPage(
  119. "Select Area",
  120. new SelectionViewModel<StockArea>(
  121. areafilter,
  122. new Expression<Func<StockArea, object>>[] { X => X.Description },
  123. new Expression<Func<StockArea, object>>[] { x => x.Warehouse.ID, x => x.Warehouse.Description },
  124. new SortOrder<StockArea>(x => x.Description)
  125. )
  126. );
  127. page.OnItemSelected += (row) =>
  128. {
  129. var area = row.ToObject<StockArea>();
  130. if (_areaid != area.ID)
  131. {
  132. _warehouseid = area.Warehouse.ID;
  133. _warehousename = area.Warehouse.Description;
  134. _areaid = area.ID;
  135. _areaname = area.Description;
  136. _locationid = Guid.Empty;
  137. _locationname = "Select Location";
  138. }
  139. };
  140. Navigation.PushAsync(page);
  141. }
  142. void Location_Clicked(System.Object sender, System.EventArgs e)
  143. {
  144. Filter<StockLocation> filter = new Filter<StockLocation>(X => X.Active).IsEqualTo(true);
  145. if (_warehouseid != Guid.Empty)
  146. filter = filter.And(x => x.Warehouse.ID).IsEqualTo(_warehouseid);
  147. if (_areaid != Guid.Empty)
  148. filter = filter.And(x => x.Area.ID).IsEqualTo(_areaid);
  149. GenericSelectionPage page = new GenericSelectionPage(
  150. "Select Location",
  151. new SelectionViewModel<StockLocation>(
  152. filter,
  153. new Expression<Func<StockLocation, object>>[] { x => x.Code, X => X.Description },
  154. new Expression<Func<StockLocation, object>>[] { x => x.Area.Warehouse.ID, x => x.Area.Warehouse.Description, x => x.Area.ID, x => x.Area.Description,
  155. x => x.Job.ID, x => x.Job.JobNumber, x => x.Job.Name},
  156. new SortOrder<StockLocation>(x => x.Description)
  157. )
  158. );
  159. page.OnItemSelected += (row) =>
  160. {
  161. var location = row.ToObject<StockLocation>();
  162. if (_locationid != location.ID)
  163. {
  164. _warehouseid = location.Area.Warehouse.ID;
  165. _warehousename = location.Area.Warehouse.Description;
  166. _areaid = location.Area.ID;
  167. _areaname = location.Area.Description;
  168. _locationid = location.ID;
  169. _locationname = location.Description;
  170. job.ID = location.Job.ID;
  171. job.JobNumber = location.Job.JobNumber;
  172. job.Name = location.Job.Name;
  173. }
  174. };
  175. Navigation.PushAsync(page);
  176. }
  177. #endregion
  178. #region Warehouse/Area/Location Clear buttons
  179. void Warehouse_Clear_Clicked(System.Object sender, System.EventArgs e)
  180. {
  181. _warehouseid = Guid.Empty;
  182. _warehousename = "Select Warehouse";
  183. _areaid = Guid.Empty;
  184. _areaname = "Select Area";
  185. _locationid = Guid.Empty;
  186. _locationname = "Select Location";
  187. UpdateScreen();
  188. }
  189. void Area_Clear_Clicked(System.Object sender, System.EventArgs e)
  190. {
  191. _areaid = Guid.Empty;
  192. _areaname = "Select Area";
  193. _locationid = Guid.Empty;
  194. _locationname = "Select Location";
  195. UpdateScreen();
  196. }
  197. void Location_Clear_Clicked(System.Object sender, System.EventArgs e)
  198. {
  199. _locationid = Guid.Empty;
  200. _locationname = "Select Location";
  201. UpdateScreen();
  202. }
  203. #endregion
  204. private void UpdateScreen()
  205. {
  206. warehouseBtn.Text = _warehousename;
  207. warehouseBtn.SetValue(Grid.ColumnSpanProperty, _warehouseid == Guid.Empty ? 3 : 2);
  208. warehouseBtn.Margin = new Thickness(10, 10, _warehouseid == Guid.Empty ? 5 : 0, 0);
  209. warehouse_ClearBtn.IsVisible = _warehouseid != Guid.Empty;
  210. warehouse_ClearBtn.Margin = new Thickness(0, 10, 5, 0);
  211. areaBtn.Text = _areaname;
  212. areaBtn.SetValue(Grid.ColumnSpanProperty, _areaid == Guid.Empty ? 3 : 2);
  213. areaBtn.Margin = new Thickness(10, 0, _areaid == Guid.Empty ? 5 : 0, 0);
  214. area_ClearBtn.IsVisible = _areaid != Guid.Empty;
  215. area_ClearBtn.Margin = new Thickness(0, 0, 5, 0);
  216. locationBtn.Text = _locationname;
  217. locationBtn.SetValue(Grid.ColumnSpanProperty, _locationid != Guid.Empty ? 2 : 3);
  218. locationBtn.Margin = new Thickness(10, 0, _locationid == Guid.Empty ? 5 : 0, 0);
  219. location_ClearBtn.IsVisible = _locationid != Guid.Empty;
  220. location_ClearBtn.Margin = new Thickness(0, 0, 5, 0);
  221. }
  222. }
  223. }