StoreRequiScannerPage.xaml.cs 26 KB

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