StocktakePage.xaml.cs 35 KB

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