StoreRequiScannerPage.xaml.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. using comal.timesheets.StoreRequis;
  2. using Comal.Classes;
  3. using InABox.Clients;
  4. using InABox.Core;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using InABox.Mobile;
  11. using Xamarin.Essentials;
  12. using Xamarin.Forms;
  13. using Xamarin.Forms.Xaml;
  14. using XF.Material.Forms.UI.Dialogs;
  15. using static comal.timesheets.RequiItems;
  16. using LogType = InABox.Core.LogType;
  17. namespace comal.timesheets
  18. {
  19. [XamlCompilation(XamlCompilationOptions.Compile)]
  20. public partial class StoreRequiScannerPage
  21. {
  22. #region Fields / Constructor
  23. public delegate bool OnScanEvent(object sender, string barcode);
  24. public event OnScanEvent OnScan;
  25. List<StoreRequiItemShell> shells = new List<StoreRequiItemShell>();
  26. List<StoreRequiItemShell> oldShells = new List<StoreRequiItemShell>();
  27. Requisition requisition = new Requisition();
  28. bool loading = false;
  29. Dictionary<StoreRequiItemShell, string> itemRowScannerRawResultPairs = new Dictionary<StoreRequiItemShell, string>();
  30. Dictionary<StoreRequiItemShell, string> itemRowScannerProcessedResultPairs = new Dictionary<StoreRequiItemShell, string>();
  31. bool firstLoad = true;
  32. bool containsNotes = false;
  33. public StoreRequiScannerPage(Guid requiID)
  34. {
  35. InitializeComponent();
  36. ConfigAll(requiID);
  37. }
  38. #endregion
  39. #region Config
  40. void ConfigAll(Guid requiID)
  41. {
  42. NavigationPage.SetHasBackButton(this, false);
  43. SetScannerOptions();
  44. if (requiID != Guid.Empty)
  45. {
  46. requisition.ID = requiID;
  47. LoadExistingRequi();
  48. }
  49. if (!HoldingsLoaded)
  50. {
  51. Timer t = null;
  52. t = new Timer(new TimerCallback((object o) =>
  53. {
  54. if (HoldingsLoaded)
  55. {
  56. Device.BeginInvokeOnMainThread(() =>
  57. {
  58. ConfigDisplay();
  59. });
  60. t.Dispose();
  61. }
  62. }), null, 0, 500);
  63. }
  64. else
  65. {
  66. loadingLbl.IsVisible = false;
  67. addBtn.IsEnabled = true;
  68. Task.Run(() =>
  69. {
  70. Thread.Sleep(1500);
  71. Device.BeginInvokeOnMainThread(() => { ConfigDisplay(); });
  72. });
  73. }
  74. }
  75. void SetScannerOptions()
  76. {
  77. var options = new ZXing.Mobile.MobileBarcodeScanningOptions()
  78. {
  79. PossibleFormats = new List<ZXing.BarcodeFormat>() { ZXing.BarcodeFormat.QR_CODE },
  80. AutoRotate = false,
  81. TryInverted = true,
  82. TryHarder = true,
  83. };
  84. _scanView.Options = options;
  85. _scanView.IsAnalyzing = true;
  86. _scanView.IsScanning = true;
  87. _scanView.AutoFocus();
  88. _scanView.OnScanResult += ScanView_OnScanResult;
  89. }
  90. protected override void OnAppearing()
  91. {
  92. base.OnAppearing();
  93. if (!firstLoad)
  94. _scanView.IsAnalyzing = true;
  95. }
  96. protected override void OnDisappearing()
  97. {
  98. _scanView.IsAnalyzing = false;
  99. base.OnDisappearing();
  100. }
  101. async void LoadExistingRequi()
  102. {
  103. await Task.Run(() =>
  104. {
  105. CoreTable table = QueryRequi();
  106. while(table == null)
  107. table = QueryRequi();
  108. requisition = table.Rows.FirstOrDefault().ToObject<Requisition>();
  109. string notes = CheckNotes(requisition.Notes);
  110. if (!string.IsNullOrWhiteSpace(requisition.Request) || !string.IsNullOrWhiteSpace(notes))
  111. {
  112. StoreRequiItemShell shell1 = new StoreRequiItemShell()
  113. {
  114. IsNotes = true,
  115. IsNotNotes = false,
  116. BorderColor = Color.FromHex("#9f4576")
  117. };
  118. shell1.Summary = !string.IsNullOrWhiteSpace(requisition.Request) ? "REQUEST: " + requisition.Request + System.Environment.NewLine : "";
  119. shell1.Summary = shell1.Summary + notes;
  120. shells.Insert(0, shell1);
  121. containsNotes = true;
  122. }
  123. });
  124. await Task.Run(() =>
  125. {
  126. CoreTable table = QueryRequiItems();
  127. while(table == null)
  128. table = QueryRequiItems();
  129. if (table.Rows.Any())
  130. {
  131. Device.BeginInvokeOnMainThread(() => { saveBtn.IsVisible = true; });
  132. foreach (CoreRow row in table.Rows)
  133. {
  134. StoreRequiItemShell shell = new StoreRequiItemShell()
  135. {
  136. ID = row.Get<RequisitionItem, Guid>(x => x.ID),
  137. ProductID = row.Get<RequisitionItem, Guid>(x => x.Product.ID),
  138. ProductName = row.Get<RequisitionItem, string>(x => x.Product.Name),
  139. ProductCode = row.Get<RequisitionItem, string>(x => x.Product.Code),
  140. Quantity = row.Get<RequisitionItem, double>(x => x.Quantity),
  141. LocationID = row.Get<RequisitionItem, Guid>(x => x.Location.ID),
  142. LocationName = row.Get<RequisitionItem, string>(x => x.Location.Description),
  143. Picked = row.Get<RequisitionItem, DateTime>(x => x.Picked),
  144. };
  145. shells.Add(shell);
  146. oldShells.Add(shell);
  147. }
  148. }
  149. Device.BeginInvokeOnMainThread(() =>
  150. {
  151. requiItemListView.ItemsSource = shells;
  152. if (containsNotes)
  153. {
  154. countLbl.Text = "Number of items: " + (shells.Count - 1);
  155. }
  156. else
  157. {
  158. countLbl.Text = "Number of items: " + shells.Count;
  159. }
  160. });
  161. });
  162. }
  163. private CoreTable QueryRequi()
  164. {
  165. try
  166. {
  167. return new Client<Requisition>().Query(
  168. new Filter<Requisition>(x => x.ID).IsEqualTo(requisition.ID)
  169. );
  170. }
  171. catch (Exception ex)
  172. {
  173. InABox.Mobile.MobileLogging.Log(ex);
  174. return null;
  175. }
  176. }
  177. private CoreTable QueryRequiItems()
  178. {
  179. try
  180. {
  181. return new Client<RequisitionItem>().Query
  182. (
  183. new Filter<RequisitionItem>(x => x.RequisitionLink.ID).IsEqualTo(requisition.ID),
  184. new Columns<RequisitionItem>(
  185. x => x.ID,
  186. x => x.Product.ID,
  187. x => x.Product.Name,
  188. x => x.Product.Code,
  189. x => x.Quantity,
  190. x => x.Location.ID,
  191. x => x.Location.Description,
  192. x => x.Picked
  193. )
  194. );
  195. }
  196. catch (Exception ex)
  197. {
  198. InABox.Mobile.MobileLogging.Log(ex);
  199. return null;
  200. }
  201. }
  202. private string CheckNotes(string[] notes)
  203. {
  204. string combinednotes = "----------" + System.Environment.NewLine + "NOTES: " + System.Environment.NewLine;
  205. if (notes.Count() > 0)
  206. {
  207. foreach (var note in notes)
  208. {
  209. combinednotes = combinednotes + note + System.Environment.NewLine;
  210. }
  211. }
  212. return combinednotes;
  213. }
  214. void ConfigDisplay()
  215. {
  216. loadingLbl.IsVisible = false;
  217. addBtn.IsEnabled = true;
  218. double width = scannerGrid.Width / 6;
  219. double height = scannerGrid.Height / 6;
  220. lblv1.WidthRequest = height / 2;
  221. lblh1.IsVisible = true;
  222. lblv1.IsVisible = true;
  223. lblv2.WidthRequest = height / 2;
  224. lblh2.IsVisible = true;
  225. lblv2.IsVisible = true;
  226. lblv3.WidthRequest = height / 2;
  227. lblh3.IsVisible = true;
  228. lblv3.IsVisible = true;
  229. lblv4.WidthRequest = height / 2;
  230. lblh4.IsVisible = true;
  231. lblv4.IsVisible = true;
  232. scannerGrid.RaiseChild(lblv1);
  233. scannerGrid.RaiseChild(lblh1);
  234. scannerGrid.RaiseChild(lblv2);
  235. scannerGrid.RaiseChild(lblh2);
  236. scannerGrid.RaiseChild(lblv3);
  237. scannerGrid.RaiseChild(lblh3);
  238. scannerGrid.RaiseChild(lblv4);
  239. scannerGrid.RaiseChild(lblh4);
  240. firstLoad = false;
  241. }
  242. #endregion
  243. #region Scanning
  244. private void ScanView_OnScanResult(ZXing.Result result)
  245. {
  246. Device.BeginInvokeOnMainThread(async () =>
  247. {
  248. if (!loading)
  249. {
  250. loading = true;
  251. if (RequiItems.HoldingsLoaded)
  252. {
  253. bool bOK = true;
  254. if (OnScan != null)
  255. bOK = OnScan(this, result.Text);
  256. if (bOK)
  257. {
  258. if (!itemRowScannerRawResultPairs.Values.Contains(result.Text))
  259. {
  260. if (!itemRowScannerProcessedResultPairs.Values.Contains(result.Text))
  261. {
  262. Vibration.Vibrate();
  263. var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
  264. player.Load("requiitemadded.mp3");
  265. player.Play();
  266. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Adding"))
  267. {
  268. string rawResult = result.Text;
  269. Tuple<string, double> tuple = ProcessResult(result.Text);
  270. LoadProduct(tuple, rawResult);
  271. }
  272. }
  273. else
  274. {
  275. loading = false;
  276. }
  277. }
  278. else
  279. {
  280. loading = false;
  281. }
  282. }
  283. else
  284. {
  285. loading = false;
  286. }
  287. }
  288. else
  289. {
  290. loading = false;
  291. }
  292. }
  293. });
  294. }
  295. private Tuple<string, double> ProcessResult(string result)
  296. {
  297. double qty = 1;
  298. if (result.Contains("*"))
  299. {
  300. try
  301. {
  302. int i = result.IndexOf("*");
  303. string remainder = result.Substring(i);
  304. result = result.Remove(i);
  305. string s1 = remainder.Substring(1);
  306. qty = Convert.ToDouble(s1);
  307. }
  308. catch
  309. {
  310. loading = false;
  311. }
  312. }
  313. Tuple<string, double> tuple = new Tuple<string, double>(result, qty);
  314. return tuple;
  315. }
  316. private void LoadProduct(Tuple<string, double> processedResultQtyTuple, string rawResult)
  317. {
  318. Device.BeginInvokeOnMainThread(async () =>
  319. {
  320. //lookup product in productshells cache
  321. ProductShell product = App.Data.Products.FirstOrDefault(x => x.Code.Equals(processedResultQtyTuple.Item1));
  322. //lookup holding for product in holdings cache
  323. try
  324. {
  325. var list = CreateHoldingsList(product.ID);
  326. if (list.Count == 1) //one stockholding - auto choose holding
  327. AddStoreRequiItemShell(list.First(), product, rawResult, processedResultQtyTuple);
  328. else if (list.Count > 1) //more than one stockholding - user choose shelf
  329. UserSelectFromList(list, product, rawResult, processedResultQtyTuple);
  330. else if (list.Count == 0)
  331. DisplayAlert("No Holdings Found for Product", "", "OK");
  332. loading = false;
  333. }
  334. catch (Exception e)
  335. {
  336. DisplayAlert("Error", e.Message, "OK");
  337. loading = false;
  338. return;
  339. }
  340. });
  341. }
  342. private void UserSelectFromList(List<StockHoldingShell> list, ProductShell product, string rawResult, Tuple<string, double> processedResultQtyTuple)
  343. {
  344. Dictionary<string, Guid> holdingLocationIDs = new Dictionary<string, Guid>();
  345. foreach (StockHoldingShell holding in list)
  346. {
  347. if (!holdingLocationIDs.ContainsKey(holding.LocationName))
  348. holdingLocationIDs.Add(holding.LocationName, holding.LocationID);
  349. }
  350. List<string> options = holdingLocationIDs.Keys.ToList();
  351. ListSelectionPage page = new ListSelectionPage(options);
  352. page.OnSimpleListTapped += (locationName) =>
  353. {
  354. AddStoreRequiItemShell(list.Find(x => x.LocationName == locationName), product, rawResult, processedResultQtyTuple);
  355. };
  356. Navigation.PushAsync(page);
  357. }
  358. private List<StockHoldingShell> CreateHoldingsList(Guid productID)
  359. {
  360. List<StockHoldingShell> list = new List<StockHoldingShell>();
  361. CoreTable table = DoHoldingsQuery(productID);
  362. while (table == null)
  363. table = DoHoldingsQuery(productID);
  364. foreach (CoreRow row in table.Rows)
  365. {
  366. if (row.Get<StockHolding, double>(x => x.Units) == 0.0)
  367. continue;
  368. list.Add(CreateHoldingShell(row));
  369. }
  370. return list;
  371. }
  372. private CoreTable DoHoldingsQuery(Guid productID)
  373. {
  374. try
  375. {
  376. return new Client<StockHolding>().Query(
  377. new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(productID),
  378. new Columns<StockHolding>(
  379. x => x.ID,
  380. x => x.Product.ID,
  381. x => x.Location.ID,
  382. x => x.Location.Description,
  383. x => x.Units,
  384. x => x.Job.ID,
  385. x => x.Job.JobNumber,
  386. x => x.Job.Name,
  387. x => x.Style.ID,
  388. x => x.Style.Code,
  389. x => x.Style.Description,
  390. x => x.Dimensions.Unit.ID,
  391. x => x.Dimensions.Unit.HasQuantity,
  392. x => x.Dimensions.Unit.HasLength,
  393. x => x.Dimensions.Unit.HasHeight,
  394. x => x.Dimensions.Unit.HasWeight,
  395. x => x.Dimensions.Unit.HasWidth,
  396. x => x.Dimensions.Quantity,
  397. x => x.Dimensions.Length,
  398. x => x.Dimensions.Height,
  399. x => x.Dimensions.Weight,
  400. x => x.Dimensions.Width,
  401. x => x.Dimensions.Unit.Format,
  402. x => x.Dimensions.Unit.Formula,
  403. x => x.Dimensions.UnitSize
  404. )
  405. );
  406. }
  407. catch (Exception ex)
  408. {
  409. InABox.Mobile.MobileLogging.Log(ex);
  410. return null;
  411. }
  412. }
  413. private StockHoldingShell CreateHoldingShell(CoreRow row)
  414. {
  415. StockHoldingShell holding = new StockHoldingShell()
  416. {
  417. ProductID = row.Get<StockHolding, Guid>(x => x.Product.ID),
  418. LocationID = row.Get<StockHolding, Guid>(x => x.Location.ID),
  419. LocationName = row.Get<StockHolding, string>(x => x.Location.Description),
  420. Units = row.Get<StockHolding, double>(x => x.Units),
  421. JobID = row.Get<StockHolding, Guid>(x => x.Job.ID),
  422. JobNumber = row.Get<StockHolding, string>(x => x.Job.JobNumber),
  423. JobName = row.Get<StockHolding, string>(x => x.Job.Name),
  424. StyleID = row.Get<StockHolding, Guid>(x => x.Style.ID),
  425. StyleCode = row.Get<StockHolding, string>(x => x.Style.Code),
  426. StyleName = row.Get<StockHolding, string>(x => x.Style.Description)
  427. };
  428. holding.DimensionsUnitID = row.Get<StockHolding, Guid>(x => x.Dimensions.Unit.ID);
  429. holding.DimensionsHasQuantity = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasQuantity);
  430. holding.DimensionsHasLength = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasLength);
  431. holding.DimensionsHasHeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasHeight);
  432. holding.DimensionsHasWeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWeight);
  433. holding.DimensionsHasWidth = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWidth);
  434. holding.DimensionsQuantity = row.Get<StockHolding, double>(x => x.Dimensions.Quantity);
  435. holding.DimensionsLength = row.Get<StockHolding, double>(x => x.Dimensions.Length);
  436. holding.DimensionsHeight = row.Get<StockHolding, double>(x => x.Dimensions.Height);
  437. holding.DimensionsWeight = row.Get<StockHolding, double>(x => x.Dimensions.Weight);
  438. holding.DimensionsWidth = row.Get<StockHolding, double>(x => x.Dimensions.Width);
  439. holding.DimensionsUnitFormat = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Format);
  440. holding.DimensionsUnitFormula = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Formula);
  441. holding.DimensionsUnitSize = row.Get<StockHolding, string>(x => x.Dimensions.UnitSize);
  442. holding.LocationName = holding.LocationName + " (Units: " + holding.Units + ")" +
  443. Environment.NewLine + "Style: " + holding.StyleName
  444. + Environment.NewLine + "Job: " + holding.JobNumber
  445. + Environment.NewLine + "Size: " + holding.DimensionsUnitSize;
  446. return holding;
  447. }
  448. private void AddStoreRequiItemShell(StockHoldingShell holding, ProductShell product, string rawResult, Tuple<string, double> processedResultQtyTuple)
  449. {
  450. StoreRequiItemShell shell = new StoreRequiItemShell
  451. {
  452. ProductID = product.ID,
  453. ProductName = product.Name,
  454. ProductCode = product.Code,
  455. Quantity = 1,
  456. LocationID = holding.LocationID,
  457. LocationName = holding.LocationName,
  458. StyleID = holding.StyleID,
  459. JobID = holding.StyleID
  460. };
  461. shell.Dimensions.Unit.ID = holding.DimensionsUnitID;
  462. shell.Dimensions.Unit.HasQuantity = holding.DimensionsHasQuantity;
  463. shell.Dimensions.Unit.HasLength = holding.DimensionsHasLength;
  464. shell.Dimensions.Unit.HasHeight = holding.DimensionsHasHeight;
  465. shell.Dimensions.Unit.HasWeight = holding.DimensionsHasWeight;
  466. shell.Dimensions.Unit.HasWidth = holding.DimensionsHasWidth;
  467. shell.Dimensions.Quantity = holding.DimensionsQuantity;
  468. shell.Dimensions.Length = holding.DimensionsLength;
  469. shell.Dimensions.Height = holding.DimensionsHeight;
  470. shell.Dimensions.Weight = holding.DimensionsWeight;
  471. shell.Dimensions.Width = holding.DimensionsWidth;
  472. shell.Dimensions.Unit.Format = holding.DimensionsUnitFormat;
  473. shell.Dimensions.Unit.Formula = holding.DimensionsUnitFormula;
  474. shell.Dimensions.UnitSize = holding.DimensionsUnitSize;
  475. shells.Add(shell);
  476. itemRowScannerRawResultPairs.Add(shell, rawResult);
  477. itemRowScannerProcessedResultPairs.Add(shell, processedResultQtyTuple.Item1);
  478. requiItemListView.ItemsSource = null;
  479. requiItemListView.ItemsSource = shells;
  480. countLbl.IsVisible = true;
  481. if (containsNotes)
  482. {
  483. countLbl.Text = "Number of items: " + (shells.Count - 1);
  484. }
  485. else
  486. {
  487. countLbl.Text = "Number of items: " + shells.Count;
  488. }
  489. saveBtn.IsVisible = true;
  490. loading = false;
  491. }
  492. #endregion
  493. #region Button Presses
  494. private async void ExitBtn_Clicked(object sender, EventArgs e)
  495. {
  496. if (shells.Count > 0)
  497. {
  498. if (containsNotes && shells.Count > 1)
  499. {
  500. string chosenOption = await DisplayActionSheet("Leave without saving?", "Cancel", null, "Yes", "No");
  501. switch (chosenOption)
  502. {
  503. case "Cancel":
  504. return;
  505. case "Yes":
  506. Navigation.PopAsync();
  507. break;
  508. case "No":
  509. return;
  510. default:
  511. return;
  512. }
  513. }
  514. else if (containsNotes && shells.Count == 1)
  515. {
  516. Navigation.PopAsync();
  517. }
  518. else
  519. {
  520. string chosenOption = await DisplayActionSheet("Leave without saving?", "Cancel", null, "Yes", "No");
  521. switch (chosenOption)
  522. {
  523. case "Cancel":
  524. return;
  525. case "Yes":
  526. Navigation.PopAsync();
  527. break;
  528. case "No":
  529. return;
  530. default:
  531. return;
  532. }
  533. }
  534. }
  535. else
  536. Navigation.PopAsync();
  537. }
  538. void SaveBtn_Clicked(object sender, EventArgs e)
  539. {
  540. StoreRequiConfirmationPage page = new StoreRequiConfirmationPage(requisition, shells, oldShells);
  541. page.OnSaveSelected += () => { Navigation.PopAsync(); };
  542. Navigation.PushAsync(page);
  543. }
  544. private async void RequiItem_Tapped(object sender, EventArgs e)
  545. {
  546. var shell = requiItemListView.SelectedItem as StoreRequiItemShell;
  547. if (shell == null) return;
  548. await RequiItemTappedAsync(shell);
  549. }
  550. private async Task RequiItemTappedAsync(StoreRequiItemShell shell)
  551. {
  552. string pickstatus = shell.Picked == DateTime.MinValue ? "not picked" : "picked (" + shell.Picked.ToString("dd MMM yy") + ")";
  553. string options = shell.Picked == DateTime.MinValue ? ". Mark as Picked?" : ". Remove Picked status?";
  554. string chosenOption = await DisplayActionSheet("Line is " + pickstatus + options, "Cancel", null, "Yes", "No");
  555. if (chosenOption != "Yes")
  556. return;
  557. shell.Picked = shell.Picked == DateTime.MinValue ? DateTime.Today : DateTime.MinValue;
  558. shell.Colour = shell.Picked == DateTime.MinValue ? Color.Default : Color.FromHex("#8fbc8f");
  559. requiItemListView.ItemsSource = null;
  560. requiItemListView.ItemsSource = shells;
  561. }
  562. void ReduceQtyBtn_Clicked(object sender, EventArgs e)
  563. {
  564. var shell = ((TappedEventArgs)e).Parameter as StoreRequiItemShell;
  565. if (shell == null) return;
  566. if (shell.Quantity <= 1)
  567. {
  568. shells.Remove(shell);
  569. itemRowScannerRawResultPairs.Remove(shell);
  570. itemRowScannerProcessedResultPairs.Remove(shell);
  571. if (containsNotes)
  572. {
  573. countLbl.Text = "Number of items: " + (shells.Count - 1);
  574. if (shells.Count == 1)
  575. {
  576. saveBtn.IsVisible = false;
  577. }
  578. }
  579. else
  580. {
  581. countLbl.Text = "Number of items: " + shells.Count;
  582. if (shells.Count == 0)
  583. {
  584. saveBtn.IsVisible = false;
  585. }
  586. }
  587. }
  588. else
  589. {
  590. shell.Quantity--;
  591. }
  592. requiItemListView.ItemsSource = null;
  593. requiItemListView.ItemsSource = shells;
  594. }
  595. void IncreaseQtyBtn_Clicked(object sender, EventArgs e)
  596. {
  597. var shell = ((TappedEventArgs)e).Parameter as StoreRequiItemShell;
  598. if (shell == null)
  599. return;
  600. shell.Quantity++;
  601. requiItemListView.ItemsSource = null;
  602. requiItemListView.ItemsSource = shells;
  603. }
  604. void AddItem_Clicked(object sender, EventArgs e)
  605. {
  606. if (App.Data.Products.Loaded)
  607. {
  608. if (loading)
  609. return;
  610. loading = true;
  611. var products = new ProductSelectionPage(
  612. (product) =>
  613. {
  614. Tuple<string, double> tuple = new Tuple<string, double>(product.Code, 1);
  615. LoadProduct(new Tuple<string, double>(product.Code, 1), product.Code);
  616. }
  617. );
  618. Navigation.PushAsync(products);
  619. }
  620. }
  621. void Qty_Changed(object sender, EventArgs e)
  622. {
  623. }
  624. #endregion
  625. }
  626. }