StoreRequiScannerPage.xaml.cs 28 KB

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