StocktakeModule.xaml.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. using Comal.Classes;
  2. using InABox.Clients;
  3. using InABox.Core;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Linq.Expressions;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using InABox.Mobile;
  13. using Xamarin.CommunityToolkit.Extensions;
  14. using Xamarin.CommunityToolkit.UI.Views;
  15. using Xamarin.Essentials;
  16. using Xamarin.Forms;
  17. using Xamarin.Forms.Xaml;
  18. using XF.Material.Forms.UI.Dialogs;
  19. using LogType = InABox.Core.LogType;
  20. namespace PRS.Mobile
  21. {
  22. [XamlCompilation(XamlCompilationOptions.Compile)]
  23. public partial class StocktakeModule : MobilePage
  24. {
  25. #region Fields, Constructor and OnAppearing
  26. List<StockLocationShell> stockLocationShells = new List<StockLocationShell>();
  27. List<StockHoldingShell> stockHoldingShells = new List<StockHoldingShell>();
  28. string DeviceType = "";
  29. StockLocationShell_Old openLocation = new StockLocationShell_Old();
  30. bool bOpening = false;
  31. Color stockHoldingCheckedColor = Color.FromHex("#3eb489");
  32. List<StockMovement> movementsToUpdate = new List<StockMovement>();
  33. public StocktakeModule(Guid locationid)
  34. {
  35. InitializeComponent();
  36. var idiom = DeviceInfo.Idiom;
  37. if (idiom.Equals(DeviceIdiom.Tablet))
  38. {
  39. DeviceType = "Tablet";
  40. }
  41. NavigationPage.SetHasBackButton(this, false);
  42. if (locationid != Guid.Empty)
  43. LoadLocation(locationid);
  44. }
  45. protected override void OnAppearing()
  46. {
  47. base.OnAppearing();
  48. bOpening = false;
  49. }
  50. #endregion
  51. #region Button Presses
  52. // private async void ExitWithoutSaving(object sender, EventArgs e)
  53. // {
  54. // if (openLocation.ID != Guid.Empty)
  55. // {
  56. // string chosenOption = await DisplayActionSheet("Leave without saving?", "Cancel", null, "Yes", "No");
  57. // switch (chosenOption)
  58. // {
  59. // case "Cancel":
  60. // return;
  61. // case "Yes":
  62. // Navigation.PopAsync();
  63. // break;
  64. // case "No":
  65. // return;
  66. // default:
  67. // return;
  68. // }
  69. // }
  70. // else
  71. // Navigation.PopAsync();
  72. // }
  73. // private void AddLocation_Clicked(object sender, EventArgs e)
  74. // {
  75. // if (bOpening)
  76. // return;
  77. // bOpening = true;
  78. // StockLocationSelectionPage stockLocationSelectionPage = new StockLocationSelectionPage( new Guid[] { }, true);
  79. // stockLocationSelectionPage.OnLocationSelected += (s, e) =>
  80. // {
  81. // foreach (StockLocationShell shell in e.Locations)
  82. // {
  83. // if (!stockLocationShells.Any(x => x.ID == shell.ID))
  84. // {
  85. // //shell.Color = Color.Default;
  86. // stockLocationShells.Add(shell);
  87. // //if (string.IsNullOrWhiteSpace(shell.NumberOfHoldings))
  88. // // FindHoldingNumber(shell);
  89. // }
  90. // }
  91. // Device.BeginInvokeOnMainThread(() =>
  92. // {
  93. // leftListView.ItemsSource = null;
  94. // leftListView.ItemsSource = stockLocationShells;
  95. // });
  96. // };
  97. //
  98. // Navigation.PushAsync(stockLocationSelectionPage);
  99. // }
  100. private void AddItem_Clicked(object sender, EventArgs e)
  101. {
  102. if (openLocation.ID != Guid.Empty)
  103. {
  104. // var selectionpage = new ProductSelectionPage((product) =>
  105. // {
  106. // StockHoldingShell shell = new StockHoldingShell();
  107. // shell.ProductCode = product.Code;
  108. // shell.Name = product.Name;
  109. // shell.ImageID = product.ImageID;
  110. // shell.ProductID = product.ID;
  111. // shell.DisplayJob = openLocation.JobNumber;
  112. // if (!string.IsNullOrWhiteSpace(openLocation.JobNumber))
  113. // {
  114. // shell.JobNumber = openLocation.JobNumber.Substring(6);
  115. // }
  116. // shell.JobID = openLocation.JobID;
  117. // shell.Units = 0;
  118. // shell.DisplayUnits = "Units: 0";
  119. // shell.StyleName = "Finish: Select";
  120. //
  121. // shell.DimensionsUnitID = product.DimensionsUnitID;
  122. // shell.DimensionsUnitCode = product.DimensionsUnit.Code;
  123. // shell.DimensionsUnitDescription = product.DimensionsUnit.Description;
  124. // shell.DimensionsQuantity = product.DimensionsQuantity;
  125. // shell.DimensionsLength = product.DimensionsLength;
  126. // shell.DimensionsWidth = product.DimensionsWidth;
  127. // shell.DimensionsHeight = product.DimensionsHeight;
  128. // shell.DimensionsWeight = product.DimensionsWeight;
  129. // shell.DimensionsValue = product.DimensionsValue;
  130. // shell.DimensionsUnitSize = product.DimensionsUnitSize;
  131. // shell.DimensionsHasHeight = product.DimensionsUnit.HasHeight;
  132. // shell.DimensionsHasLength = product.DimensionsUnit.HasLength;
  133. // shell.DimensionsHasWidth = product.DimensionsUnit.HasWidth;
  134. // shell.DimensionsHasWeight = product.DimensionsUnit.HasWeight;
  135. // shell.DimensionsHasQuantity = product.DimensionsUnit.HasQuantity;
  136. // shell.DimensionsUnitFormula = product.DimensionsUnit.Formula;
  137. // shell.DimensionsUnitFormat = product.DimensionsUnit.Format;
  138. //
  139. // stockHoldingShells.Add(shell);
  140. // rightListView.ItemsSource = null;
  141. // rightListView.ItemsSource = stockHoldingShells;
  142. // if (shell.ImageID != Guid.Empty)
  143. // LoadImage(shell);
  144. // });
  145. // Navigation.PushAsync(selectionpage);
  146. }
  147. else
  148. {
  149. string alert = "";
  150. if (stockLocationShells.Count == 0)
  151. {
  152. alert = "Add a location first";
  153. }
  154. else
  155. {
  156. alert = "Open a location first";
  157. }
  158. DisplayAlert("Alert", alert, "OK");
  159. }
  160. }
  161. #endregion
  162. #region Lists Tapped
  163. private async void LeftListView_Tapped(object sender, EventArgs e)// open/close a location
  164. {
  165. // StockLocationShell_Old stockLocationShell = leftListView.SelectedItem as StockLocationShell_Old;
  166. // if (openLocation.ID == stockLocationShell.ID) //close location and save movements
  167. // {
  168. // bool allComplete = true;
  169. // bool allIncomplete = true;
  170. // foreach (StockHoldingShell_Old shell in stockHoldingShells)
  171. // {
  172. // if (shell.Color != stockHoldingCheckedColor)
  173. // allComplete = false;
  174. // else
  175. // allIncomplete = false;
  176. // }
  177. // if (!allComplete && !allIncomplete)
  178. // {
  179. // DisplayAlert("Alert", "Not all holdings have been checked for this location / pack", "OK");
  180. // return;
  181. // }
  182. // if (allIncomplete)
  183. // {
  184. // openLocation.ID = Guid.Empty;
  185. // openLocation.Code = "";
  186. // openLocation.Description = "";
  187. // stockLocationShell.Color = Color.Default;
  188. // stockLocationShell.OpenCloseLocation = "Open";
  189. // int index = stockLocationShells.FindIndex(x => x.ID.Equals(stockLocationShell.ID));
  190. // stockLocationShells.RemoveAt(index);
  191. // stockLocationShells.Insert(index, stockLocationShell);
  192. //
  193. // leftListView.ItemsSource = null;
  194. // leftListView.ItemsSource = stockLocationShells;
  195. //
  196. // rightListView.ItemsSource = null;
  197. // stockHoldingShells.Clear();
  198. // rightCountLbl.Text = "Items: " + stockHoldingShells.Count();
  199. // movementsToUpdate.Clear();
  200. //
  201. // return;
  202. // }
  203. //
  204. // StockTakeCompletionPage stockTakeCompletionPage = new StockTakeCompletionPage(movementsToUpdate);
  205. // stockTakeCompletionPage.OnStockTakeCompleted += () =>
  206. // {
  207. // openLocation.ID = Guid.Empty;
  208. // openLocation.Code = "";
  209. // openLocation.Description = "";
  210. // stockLocationShell.Color = stockHoldingCheckedColor;
  211. // stockLocationShell.OpenCloseLocation = "Completed";
  212. //
  213. // int index = stockLocationShells.FindIndex(x => x.ID.Equals(stockLocationShell.ID));
  214. // stockLocationShells.RemoveAt(index);
  215. // stockLocationShells.Insert(index, stockLocationShell);
  216. //
  217. // leftListView.ItemsSource = null;
  218. // leftListView.ItemsSource = stockLocationShells;
  219. //
  220. // rightListView.ItemsSource = null;
  221. // stockHoldingShells.Clear();
  222. // rightCountLbl.Text = "Items: " + stockHoldingShells.Count();
  223. // movementsToUpdate.Clear();
  224. // };
  225. // Navigation.PushAsync(stockTakeCompletionPage);
  226. // }
  227. // else if (openLocation.ID == Guid.Empty) //open the location and load holdings
  228. // {
  229. // Filter<StockHolding> filter = new Filter<StockHolding>(x => x.Location.ID).IsEqualTo(stockLocationShell.ID);
  230. // openLocation.ID = stockLocationShell.ID;
  231. // openLocation.Code = stockLocationShell.Code;
  232. // openLocation.Description = stockLocationShell.Description;
  233. // stockLocationShell.Color = Color.Orange;
  234. // stockLocationShell.OpenCloseLocation = "Close";
  235. //
  236. // LoadHoldings(filter);
  237. //
  238. // int index = stockLocationShells.FindIndex(x => x.ID.Equals(stockLocationShell.ID));
  239. // stockLocationShells.RemoveAt(index);
  240. // stockLocationShells.Insert(index, stockLocationShell);
  241. //
  242. // leftListView.ItemsSource = null;
  243. // leftListView.ItemsSource = stockLocationShells;
  244. // }
  245. // else if (openLocation.ID != Guid.Empty)
  246. // {
  247. // DisplayAlert("Alert", "Currently Open Location must be closed first", "OK");
  248. // }
  249. }
  250. private void RightListView_Tapped(object sender, EventArgs e) //open popup to confirm, on closing turns green
  251. {
  252. // if (bOpening)
  253. // return;
  254. // bOpening = true;
  255. // var shell = rightListView.SelectedItem as StockHoldingShell_Old;
  256. // var originalShell = DuplicateShell(shell);
  257. //
  258. // var style = new ProductStyle { ID = shell.StyleID, Code = shell.StyleCode, Description = shell.Finish };
  259. // var job = new Job { ID = shell.JobID, JobNumber = shell.JobNumber };
  260. //
  261. // var popup = new RecTransferPopup(shell, job, job, true);
  262. //
  263. // var additionalmovement = new StockMovement();
  264. //
  265. // popup.OnRecTransferItemAccepted += () =>
  266. // {
  267. // var movement = new StockMovement();
  268. // movement.Dimensions.Unit.ID = shell.DimensionsUnitID;
  269. // movement.Dimensions.Quantity = shell.DimensionsQuantity;
  270. // movement.Dimensions.Length = shell.DimensionsLength;
  271. // movement.Dimensions.Width = shell.DimensionsWidth;
  272. // movement.Dimensions.Height = shell.DimensionsHeight;
  273. // movement.Dimensions.Weight = shell.DimensionsWeight;
  274. // movement.Dimensions.Unit.HasHeight = shell.DimensionsHasHeight;
  275. // movement.Dimensions.Unit.HasLength = shell.DimensionsHasLength;
  276. // movement.Dimensions.Unit.HasWidth = shell.DimensionsHasWidth;
  277. // movement.Dimensions.Unit.HasWeight = shell.DimensionsHasWeight;
  278. // movement.Dimensions.Unit.HasQuantity = shell.DimensionsHasQuantity;
  279. // movement.Dimensions.Unit.Code = shell.DimensionsUnitCode;
  280. // movement.Dimensions.Unit.Description = shell.DimensionsUnitDescription;
  281. // movement.Dimensions.Value = shell.DimensionsValue;
  282. // movement.Dimensions.Unit.Formula = shell.DimensionsUnitFormula;
  283. // movement.Dimensions.Unit.Format = shell.DimensionsUnitFormat;
  284. // movement.Dimensions.UnitSize = shell.DimensionsUnitSize;
  285. // movement.Product.ID = shell.ProductID;
  286. // movement.Product.Code = shell.Code;
  287. // movement.Product.Name = shell.Name;
  288. // movement.Employee.ID = App.Data.Me.ID;
  289. // movement.Employee.Name = App.Data.Me.Name;
  290. // movement.Location.ID = openLocation.ID;
  291. // movement.Location.Description = openLocation.Description;
  292. // movement.Location.Code = openLocation.Code;
  293. // movement.Job.ID = shell.JobID;
  294. // movement.Job.JobNumber = shell.JobNumber;
  295. // movement.Style.ID = shell.StyleID;
  296. // movement.Style.Code = shell.StyleCode;
  297. // movement.Style.Description = shell.Finish;
  298. // movement.Type = StockMovementType.StockTake;
  299. // movement.Balance = popup.Shell.Units;
  300. //
  301. // if (popup.Shell.Units < originalShell.Units)
  302. // {
  303. // movement.Issued = originalShell.Units - popup.Shell.Units;
  304. // movement.Notes = "Updated incorrect Qty during stocktake. Less Qty than expected.";
  305. // }
  306. // else if (popup.Shell.Units > originalShell.Units)
  307. // {
  308. // movement.Received = popup.Shell.Units - originalShell.Units;
  309. // movement.Notes = "Updated incorrect Qty during stocktake. More Qty than expected.";
  310. // }
  311. // else if (popup.Shell.Units == originalShell.Units)
  312. // {
  313. // movement.Received = 0;
  314. // movement.Issued = 0;
  315. // movement.Notes = "Confirmed correct Qty during stocktake.";
  316. // }
  317. //
  318. // //if style is changed, create a movement that issues everything from the original style
  319. // //in addition to the first movement created being changed to a receive of the entered qty in the new style
  320. // //no need to find the difference in Qty from the original. First movement qty issued should be 0
  321. // if (popup.Shell.StyleID != originalShell.StyleID)
  322. // {
  323. // additionalmovement.Dimensions.Unit.ID = shell.DimensionsUnitID;
  324. // additionalmovement.Dimensions.Quantity = shell.DimensionsQuantity;
  325. // additionalmovement.Dimensions.Length = shell.DimensionsLength;
  326. // additionalmovement.Dimensions.Width = shell.DimensionsWidth;
  327. // additionalmovement.Dimensions.Height = shell.DimensionsHeight;
  328. // additionalmovement.Dimensions.Weight = shell.DimensionsWeight;
  329. // additionalmovement.Dimensions.Unit.HasHeight = shell.DimensionsHasHeight;
  330. // additionalmovement.Dimensions.Unit.HasLength = shell.DimensionsHasLength;
  331. // additionalmovement.Dimensions.Unit.HasWidth = shell.DimensionsHasWidth;
  332. // additionalmovement.Dimensions.Unit.HasWeight = shell.DimensionsHasWeight;
  333. // additionalmovement.Dimensions.Unit.HasQuantity = shell.DimensionsHasQuantity;
  334. // additionalmovement.Dimensions.Unit.Code = shell.DimensionsUnitCode;
  335. // additionalmovement.Dimensions.Unit.Description = shell.DimensionsUnitDescription;
  336. // additionalmovement.Dimensions.Value = shell.DimensionsValue;
  337. // additionalmovement.Dimensions.Unit.Formula = shell.DimensionsUnitFormula;
  338. // additionalmovement.Dimensions.Unit.Format = shell.DimensionsUnitFormat;
  339. // additionalmovement.Dimensions.UnitSize = shell.DimensionsUnitSize;
  340. // additionalmovement.Product.ID = shell.ProductID;
  341. // additionalmovement.Product.Code = shell.Code;
  342. // additionalmovement.Product.Name = shell.Name;
  343. // additionalmovement.Employee.ID = App.Data.Me.ID;
  344. // additionalmovement.Employee.Name = App.Data.Me.Name;
  345. // additionalmovement.Location.ID = openLocation.ID;
  346. // additionalmovement.Location.Description = openLocation.Description;
  347. // additionalmovement.Location.Code = openLocation.Code;
  348. // additionalmovement.Job.ID = shell.JobID;
  349. // additionalmovement.Job.JobNumber = shell.JobNumber;
  350. // additionalmovement.Style.ID = originalShell.StyleID;
  351. // additionalmovement.Style.Code = originalShell.StyleCode;
  352. // additionalmovement.Style.Description = originalShell.Finish;
  353. // additionalmovement.Notes = movement.Notes + " Also changed finish during stocktake";
  354. //
  355. // additionalmovement.Transaction = movement.Transaction;
  356. //
  357. // additionalmovement.Issued = originalShell.Units;
  358. // additionalmovement.Type = StockMovementType.TransferOut;
  359. //
  360. // movementsToUpdate.Add(additionalmovement);
  361. //
  362. // movement.Issued = 0;
  363. // movement.Received = popup.Shell.Units;
  364. // movement.Type = StockMovementType.TransferIn;
  365. // movement.Notes += " Also changed finish during stocktake";
  366. // }
  367. //
  368. // movementsToUpdate.Add(movement);
  369. //
  370. // shell.Color = stockHoldingCheckedColor;
  371. // int index = stockHoldingShells.FindIndex(x => x.ID.Equals(shell.ID));
  372. // stockHoldingShells.RemoveAt(index);
  373. // stockHoldingShells.Insert(index, shell);
  374. // Device.BeginInvokeOnMainThread(() =>
  375. // {
  376. // rightListView.ItemsSource = null;
  377. // rightListView.ItemsSource = stockHoldingShells;
  378. // });
  379. // };
  380. //
  381. // Navigation.PushAsync(popup);
  382. }
  383. #endregion
  384. #region Utilities
  385. private async void FindHoldingNumber(StockLocationShell_Old shell)
  386. {
  387. //TODO replace code that showed number of holdings
  388. //Task.Run(() =>
  389. //{
  390. // CoreTable table = new Client<StockLocation>().Query(new Filter<StockLocation>(x => x.ID).IsEqualTo(shell.ID),
  391. // new Columns<StockLocation>(x => x.Holdings));
  392. // if (table.Rows.Any())
  393. // {
  394. // List<object> list = table.Rows.First().Values;
  395. // shell.NumberOfHoldings = "Holdings: " + list[0].ToString();
  396. // int index = stockLocationShells.FindIndex(x => x.ID.Equals(shell.ID));
  397. // stockLocationShells.RemoveAt(index);
  398. // stockLocationShells.Insert(index, shell);
  399. // Device.BeginInvokeOnMainThread(() =>
  400. // {
  401. // leftListView.ItemsSource = null;
  402. // leftListView.ItemsSource = stockLocationShells;
  403. // });
  404. // }
  405. //});
  406. }
  407. private async void LoadLocation(Guid locationid)
  408. {
  409. // using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  410. // {
  411. // CoreTable table = QueryLocation(locationid);
  412. // while (table == null)
  413. // table = QueryLocation(locationid);
  414. // if (table.Rows.Any())
  415. // {
  416. // StockLocation location = table.Rows.First().ToObject<StockLocation>();
  417. //
  418. // StockLocationShell_Old shell = new StockLocationShell_Old()
  419. // {
  420. // ID = locationid,
  421. // Description = location.Description,
  422. // Warehouse = "Warehouse: " + location.Warehouse.Description,
  423. // Area = "Area: " + location.Area.Description,
  424. // JobNumber = "Job: " + location.Job.JobNumber,
  425. // Code = location.Code,
  426. // NumberOfHoldings = "Holdings: LOADING...",
  427. // JobID = location.Job.ID,
  428. // JobName = location.Job.Name
  429. // };
  430. //
  431. // stockLocationShells.Add(shell);
  432. //
  433. // Device.BeginInvokeOnMainThread(() =>
  434. // {
  435. // leftListView.ItemsSource = null;
  436. // leftListView.ItemsSource = stockLocationShells;
  437. // });
  438. // FindHoldingNumber(shell);
  439. // }
  440. // }
  441. }
  442. private CoreTable QueryLocation(Guid locationid)
  443. {
  444. try
  445. {
  446. return new Client<StockLocation>().Query(new Filter<StockLocation>(x => x.ID).IsEqualTo(locationid),
  447. new Columns<StockLocation>(x => x.Description, x => x.Code, x => x.Warehouse.Description,
  448. x => x.Area.Description, x => x.Job.JobNumber)
  449. );
  450. }
  451. catch (Exception ex)
  452. {
  453. InABox.Mobile.MobileLogging.Log(ex);
  454. return null;
  455. }
  456. }
  457. private StockHoldingShell_Old DuplicateShell(StockHoldingShell_Old shell)
  458. {
  459. StockHoldingShell_Old NewShell = new StockHoldingShell_Old()
  460. {
  461. ID = shell.ID,
  462. Code = shell.Code,
  463. Name = shell.Name,
  464. DimensionsUnitID = shell.DimensionsUnitID,
  465. DimensionsQuantity = shell.DimensionsQuantity,
  466. DimensionsLength = shell.DimensionsLength,
  467. DimensionsWidth = shell.DimensionsWidth,
  468. DimensionsHeight = shell.DimensionsHeight,
  469. DimensionsWeight = shell.DimensionsWeight,
  470. DimensionsValue = shell.DimensionsValue,
  471. DimensionsHasHeight = shell.DimensionsHasHeight,
  472. DimensionsHasLength = shell.DimensionsHasLength,
  473. DimensionsHasQuantity = shell.DimensionsHasQuantity,
  474. DimensionsHasWidth = shell.DimensionsHasWidth,
  475. DimensionsHasWeight = shell.DimensionsHasWeight,
  476. DimensionsUnitCode = shell.DimensionsUnitCode,
  477. DimensionsUnitDescription = shell.DimensionsUnitDescription,
  478. DimensionsUnitFormat = shell.DimensionsUnitFormat,
  479. DimensionsUnitFormula = shell.DimensionsUnitFormula,
  480. DimensionsUnitSize = shell.DimensionsUnitSize,
  481. Finish = shell.Finish,
  482. Units = shell.Units,
  483. DisplayUnits = shell.DisplayUnits,
  484. JobID = shell.JobID,
  485. JobName = shell.JobName,
  486. JobNumber = shell.JobNumber,
  487. DisplayJob = shell.DisplayJob,
  488. StyleName = shell.StyleName,
  489. StyleID = shell.StyleID,
  490. StyleCode = shell.StyleCode,
  491. ProductID = shell.ProductID,
  492. DisplaySize = shell.DisplaySize,
  493. LastRowHeight = shell.LastRowHeight,
  494. ImageID = shell.ImageID,
  495. ImageSource = shell.ImageSource,
  496. ImageVisible = shell.ImageVisible,
  497. Color = shell.Color
  498. };
  499. return NewShell;
  500. }
  501. // private void LoadImage(StockHoldingShell_Old shell)
  502. // {
  503. // Task.Run(() =>
  504. // {
  505. // CoreTable table = QueryImage(shell);
  506. // while (table == null)
  507. // table = QueryImage(shell);
  508. //
  509. // if (table.Rows.Any())
  510. // {
  511. // CoreRow docrow = table.Rows.FirstOrDefault();
  512. // if (docrow != null)
  513. // {
  514. // byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
  515. // ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
  516. // if (src != null)
  517. // {
  518. // shell.ImageSource = src;
  519. // shell.ImageVisible = true;
  520. // if (DeviceType == "Tablet")
  521. // {
  522. // shell.LastRowHeight = 300;
  523. // }
  524. // else
  525. // {
  526. // shell.LastRowHeight = 150;
  527. // }
  528. // Device.BeginInvokeOnMainThread(() =>
  529. // {
  530. // rightListView.ItemsSource = null;
  531. // rightListView.ItemsSource = stockHoldingShells;
  532. // });
  533. // }
  534. // }
  535. // }
  536. // });
  537. // }
  538. // private CoreTable QueryImage(StockHoldingShell_Old shell)
  539. // {
  540. // try
  541. // {
  542. // return new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(shell.ImageID));
  543. // }
  544. // catch (Exception ex)
  545. // {
  546. // InABox.Mobile.MobileLogging.Log(ex);
  547. // return null;
  548. // }
  549. //
  550. // }
  551. //private void LoadImages()
  552. //{
  553. // Task.Run(() =>
  554. // {
  555. // List<Guid> imageids = new List<Guid>();
  556. // foreach (StockHoldingShell_Old shell in stockHoldingShells)
  557. // {
  558. // if (shell.ImageID != Guid.Empty)
  559. // {
  560. // imageids.Add(shell.ImageID);
  561. // }
  562. // }
  563. // if (imageids.Count == 0)
  564. // return;
  565. //
  566. // CoreTable table = QueryImages(imageids);
  567. // while (table == null)
  568. // table = QueryImages(imageids);
  569. //
  570. // foreach (CoreRow row in table.Rows)
  571. // {
  572. // var item = stockHoldingShells.FirstOrDefault(x => x.ImageID == row.Get<Document, Guid>(x => x.ID));
  573. // item.ImageVisible = true;
  574. // item.ImageSource = ImageSource.FromStream(() => new MemoryStream(row.Get<Document, byte[]>(x => x.Data)));
  575. // if (DeviceType == "Tablet")
  576. // {
  577. // item.LastRowHeight = 300;
  578. // }
  579. // else
  580. // {
  581. // item.LastRowHeight = 150;
  582. // }
  583. // }
  584. // Device.BeginInvokeOnMainThread(() =>
  585. // {
  586. // rightListView.ItemsSource = null;
  587. // rightListView.ItemsSource = stockHoldingShells;
  588. // });
  589. // });
  590. //}
  591. // private CoreTable QueryImages(List<Guid> imageids)
  592. // {
  593. // try
  594. // {
  595. // return new Client<Document>().Query(new Filter<Document>(x => x.ID).InList(imageids.ToArray()),
  596. // new Columns<Document>(x => x.ID, x => x.Data));
  597. // }
  598. // catch (Exception ex)
  599. // {
  600. // InABox.Mobile.MobileLogging.Log(ex);
  601. // return null;
  602. // }
  603. // }
  604. //private async void LoadHoldings(Filter<StockHolding> filter)
  605. //{
  606. // await Task.Run(() =>
  607. // {
  608. // CoreTable table = QueryStockHoldings(filter);
  609. // while(table == null)
  610. // table = QueryStockHoldings(filter);
  611. //
  612. // if (table.Rows.Any())
  613. // {
  614. // foreach (CoreRow row in table.Rows)
  615. // {
  616. // StockHoldingShell_Old shell = new StockHoldingShell_Old();
  617. //
  618. // shell.ID = row.Get<StockHolding, Guid>(x => x.Location.ID).ToString()
  619. // + row.Get<StockHolding, Guid>(x => x.Product.ID).ToString()
  620. // + row.Get<StockHolding, Guid>(x => x.Job.ID).ToString()
  621. // + row.Get<StockHolding, Guid>(x => x.Style.ID).ToString()
  622. // + row.Get<StockHolding, string>(x => x.Dimensions.UnitSize);
  623. // shell.Code = row.Get<StockHolding, string>(x => x.Product.Code);
  624. // shell.Name = row.Get<StockHolding, string>(x => x.Product.Name);
  625. // shell.Finish = row.Get<StockHolding, string>(x => x.Style.Description);
  626. // shell.StyleName = "Finish: " + shell.Finish;
  627. // shell.Units = row.Get<StockHolding, double>(x => x.Units);
  628. // shell.DimensionsUnitSize = row.Get<StockHolding, string>(x => x.Dimensions.UnitSize);
  629. // shell.DisplaySize = "UOM: " + shell.DimensionsUnitSize;
  630. // shell.DisplayUnits = "Units: " + shell.Units;
  631. // shell.JobID = row.Get<StockHolding, Guid>(x => x.Job.ID);
  632. // shell.JobName = row.Get<StockHolding, string>(x => x.Job.Name);
  633. // shell.JobNumber = row.Get<StockHolding, string>(x => x.Job.JobNumber);
  634. // shell.DisplayJob = "Job: " + shell.JobNumber;
  635. // shell.StyleID = row.Get<StockHolding, Guid>(x => x.Style.ID);
  636. // shell.StyleCode = row.Get<StockHolding, string>(x => x.Style.Code);
  637. // shell.ProductID = row.Get<StockHolding, Guid>(x => x.Product.ID);
  638. // shell.ImageID = row.Get<StockHolding, Guid>(x => x.Product.Image.ID);
  639. // shell.DimensionsUnitID = row.Get<StockHolding, Guid>(x => x.Dimensions.Unit.ID);
  640. // shell.DimensionsQuantity = row.Get<StockHolding, double>(x => x.Dimensions.Quantity);
  641. // shell.DimensionsLength = row.Get<StockHolding, double>(x => x.Dimensions.Length);
  642. // shell.DimensionsWidth = row.Get<StockHolding, double>(x => x.Dimensions.Width);
  643. // shell.DimensionsHeight = row.Get<StockHolding, double>(x => x.Dimensions.Height);
  644. // shell.DimensionsWeight = row.Get<StockHolding, double>(x => x.Dimensions.Weight);
  645. // shell.DimensionsValue = row.Get<StockHolding, double>(x => x.Dimensions.Value);
  646. // shell.DimensionsHasHeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasHeight);
  647. // shell.DimensionsHasWeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWeight);
  648. // shell.DimensionsHasLength = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasLength);
  649. // shell.DimensionsHasQuantity = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasQuantity);
  650. // shell.DimensionsHasWidth = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWidth);
  651. // shell.DimensionsUnitFormat = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Format);
  652. // shell.DimensionsUnitFormula = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Formula);
  653. //
  654. // if (!shell.Code.Contains("FREIGHT") && shell.Units != 0)
  655. // {
  656. // stockHoldingShells.Add(shell);
  657. // }
  658. //
  659. // }
  660. // LoadImages();
  661. // Device.BeginInvokeOnMainThread(() =>
  662. // {
  663. // rightCountLbl.Text = "Items: " + stockHoldingShells.Count();
  664. // rightListView.ItemsSource = null;
  665. // rightListView.ItemsSource = stockHoldingShells;
  666. // });
  667. // }
  668. // });
  669. //}
  670. // private CoreTable QueryStockHoldings(Filter<StockHolding> filter)
  671. // {
  672. // try
  673. // {
  674. // return new Client<StockHolding>().Query
  675. // (
  676. // filter,
  677. // new Columns<StockHolding>
  678. // (
  679. // x => x.ID,
  680. // x => x.Product.Code,
  681. // x => x.Product.Name,
  682. // x => x.Style.Description,
  683. // x => x.Units,
  684. // x => x.Location.ID,
  685. // x => x.Job.ID,
  686. // x => x.Job.Name,
  687. // x => x.Job.JobNumber,
  688. // x => x.Style.ID,
  689. // x => x.Style.Code,
  690. // x => x.Product.ID,
  691. // x => x.Product.Image.ID,
  692. // x => x.Dimensions.UnitSize,
  693. // x => x.Dimensions.Unit.ID,
  694. // x => x.Dimensions.Quantity,
  695. // x => x.Dimensions.Length,
  696. // x => x.Dimensions.Width,
  697. // x => x.Dimensions.Height,
  698. // x => x.Dimensions.Weight,
  699. // x => x.Dimensions.Value,
  700. // x => x.Dimensions.Unit.HasQuantity,
  701. // x => x.Dimensions.Unit.HasLength,
  702. // x => x.Dimensions.Unit.HasWeight,
  703. // x => x.Dimensions.Unit.HasWidth,
  704. // x => x.Dimensions.Unit.HasHeight,
  705. // x => x.Dimensions.Unit.Format,
  706. // x => x.Dimensions.Unit.Formula
  707. // ),
  708. // null
  709. // );
  710. // }
  711. // catch (Exception ex)
  712. // {
  713. // InABox.Mobile.MobileLogging.Log(ex);
  714. // return null;
  715. // }
  716. // }
  717. #endregion
  718. private void Holding_Clicked(object sender, EventArgs e)
  719. {
  720. throw new NotImplementedException();
  721. }
  722. private void TransactionImage_Clicked(object sender, EventArgs e)
  723. {
  724. throw new NotImplementedException();
  725. }
  726. private void Transaction_Clicked(object sender, EventArgs e)
  727. {
  728. throw new NotImplementedException();
  729. }
  730. private void DeleteTransaction_Clicked(object sender, MobileMenuButtonClickedEventArgs args)
  731. {
  732. throw new NotImplementedException();
  733. }
  734. private void Image_Clicked(object sender, EventArgs e)
  735. {
  736. throw new NotImplementedException();
  737. }
  738. private void Save_Clicked(object sender, MobileMenuButtonClickedEventArgs args)
  739. {
  740. throw new NotImplementedException();
  741. }
  742. private void Location_Clicked(object sender, MobileButtonClickEventArgs args)
  743. {
  744. StockLocationSelectionPage page = new StockLocationSelectionPage(
  745. new Guid[] { ViewModel?.Location?.ID ?? Guid.Empty },
  746. false,
  747. false);
  748. page.OnLocationSelected += (s, e) =>
  749. {
  750. var location = e.Locations.FirstOrDefault();
  751. ViewModel.Location = location ?? new StockLocationShell();
  752. };
  753. Navigation.PushAsync(page);
  754. }
  755. }
  756. public class StockLocationShell_Old
  757. {
  758. public Guid ID { get; set; }
  759. public string Description { get; set; }
  760. public string Code { get; set; }
  761. public string Warehouse { get; set; }
  762. public string Area { get; set; }
  763. public string NumberOfHoldings { get; set; }
  764. public string OpenCloseLocation { get; set; }
  765. public Color Color { get; set; }
  766. public string JobNumber { get; set; }
  767. public Guid JobID { get; set; }
  768. public String JobName { get; set; }
  769. public List<POItemShell> PoItems { get; set; }
  770. public string NumberOfReceivedItems { get; set; }
  771. public StockLocationShell_Old()
  772. {
  773. ID = Guid.Empty;
  774. Description = "";
  775. Warehouse = "";
  776. Area = "";
  777. NumberOfHoldings = "";
  778. OpenCloseLocation = "Open";
  779. Color = Color.Default;
  780. JobNumber = "";
  781. Code = "";
  782. PoItems = new List<POItemShell>();
  783. NumberOfReceivedItems = "";
  784. JobID = Guid.Empty;
  785. JobName = "";
  786. }
  787. }
  788. }