StoreRequiScannerPage.xaml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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. requisition = new Client<Requisition>().Query(
  104. new Filter<Requisition>(x => x.ID).IsEqualTo(requisition.ID)
  105. ).Rows.FirstOrDefault().ToObject<Requisition>();
  106. string notes = CheckNotes(requisition.Notes);
  107. if (!string.IsNullOrWhiteSpace(requisition.Request) || !string.IsNullOrWhiteSpace(notes))
  108. {
  109. StoreRequiItemShell shell1 = new StoreRequiItemShell()
  110. {
  111. IsNotes = true,
  112. IsNotNotes = false,
  113. BorderColor = Color.FromHex("#9f4576")
  114. };
  115. shell1.Summary = !string.IsNullOrWhiteSpace(requisition.Request) ? "REQUEST: " + requisition.Request + System.Environment.NewLine : "";
  116. shell1.Summary = shell1.Summary + notes;
  117. shells.Insert(0, shell1);
  118. containsNotes = true;
  119. }
  120. });
  121. await Task.Run(() =>
  122. {
  123. CoreTable table = new Client<RequisitionItem>().Query
  124. (
  125. new Filter<RequisitionItem>(x => x.RequisitionLink.ID).IsEqualTo(requisition.ID),
  126. new Columns<RequisitionItem>(
  127. x => x.ID,
  128. x => x.Product.ID,
  129. x => x.Product.Name,
  130. x => x.Product.Code,
  131. x => x.Quantity,
  132. x => x.Location.ID,
  133. x => x.Location.Description,
  134. x => x.Picked
  135. )
  136. );
  137. if (table.Rows.Any())
  138. {
  139. Device.BeginInvokeOnMainThread(() => { saveBtn.IsVisible = true; });
  140. foreach (CoreRow row in table.Rows)
  141. {
  142. StoreRequiItemShell shell = new StoreRequiItemShell()
  143. {
  144. ID = row.Get<RequisitionItem, Guid>(x => x.ID),
  145. ProductID = row.Get<RequisitionItem, Guid>(x => x.Product.ID),
  146. ProductName = row.Get<RequisitionItem, string>(x => x.Product.Name),
  147. ProductCode = row.Get<RequisitionItem, string>(x => x.Product.Code),
  148. Quantity = row.Get<RequisitionItem, double>(x => x.Quantity),
  149. LocationID = row.Get<RequisitionItem, Guid>(x => x.Location.ID),
  150. LocationName = row.Get<RequisitionItem, string>(x => x.Location.Description),
  151. Picked = row.Get<RequisitionItem, DateTime>(x => x.Picked),
  152. };
  153. shells.Add(shell);
  154. oldShells.Add(shell);
  155. }
  156. }
  157. Device.BeginInvokeOnMainThread(() =>
  158. {
  159. requiItemListView.ItemsSource = shells;
  160. if (containsNotes)
  161. {
  162. countLbl.Text = "Number of items: " + (shells.Count - 1);
  163. }
  164. else
  165. {
  166. countLbl.Text = "Number of items: " + shells.Count;
  167. }
  168. });
  169. });
  170. }
  171. private string CheckNotes(string[] notes)
  172. {
  173. string combinednotes = "----------" + System.Environment.NewLine + "NOTES: " + System.Environment.NewLine;
  174. if (notes.Count() > 0)
  175. {
  176. foreach (var note in notes)
  177. {
  178. combinednotes = combinednotes + note + System.Environment.NewLine;
  179. }
  180. }
  181. return combinednotes;
  182. }
  183. void ConfigDisplay()
  184. {
  185. loadingLbl.IsVisible = false;
  186. addBtn.IsEnabled = true;
  187. double width = scannerGrid.Width / 6;
  188. double height = scannerGrid.Height / 6;
  189. lblv1.WidthRequest = height / 2;
  190. lblh1.IsVisible = true;
  191. lblv1.IsVisible = true;
  192. lblv2.WidthRequest = height / 2;
  193. lblh2.IsVisible = true;
  194. lblv2.IsVisible = true;
  195. lblv3.WidthRequest = height / 2;
  196. lblh3.IsVisible = true;
  197. lblv3.IsVisible = true;
  198. lblv4.WidthRequest = height / 2;
  199. lblh4.IsVisible = true;
  200. lblv4.IsVisible = true;
  201. scannerGrid.RaiseChild(lblv1);
  202. scannerGrid.RaiseChild(lblh1);
  203. scannerGrid.RaiseChild(lblv2);
  204. scannerGrid.RaiseChild(lblh2);
  205. scannerGrid.RaiseChild(lblv3);
  206. scannerGrid.RaiseChild(lblh3);
  207. scannerGrid.RaiseChild(lblv4);
  208. scannerGrid.RaiseChild(lblh4);
  209. firstLoad = false;
  210. }
  211. #endregion
  212. #region Scanning
  213. private void ScanView_OnScanResult(ZXing.Result result)
  214. {
  215. Device.BeginInvokeOnMainThread(async () =>
  216. {
  217. if (!loading)
  218. {
  219. loading = true;
  220. if (RequiItems.HoldingsLoaded)
  221. {
  222. bool bOK = true;
  223. if (OnScan != null)
  224. bOK = OnScan(this, result.Text);
  225. if (bOK)
  226. {
  227. if (!itemRowScannerRawResultPairs.Values.Contains(result.Text))
  228. {
  229. if (!itemRowScannerProcessedResultPairs.Values.Contains(result.Text))
  230. {
  231. Vibration.Vibrate();
  232. var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
  233. player.Load("requiitemadded.mp3");
  234. player.Play();
  235. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Adding"))
  236. {
  237. string rawResult = result.Text;
  238. Tuple<string, double> tuple = ProcessResult(result.Text);
  239. LoadProduct(tuple, rawResult);
  240. }
  241. }
  242. else
  243. {
  244. loading = false;
  245. }
  246. }
  247. else
  248. {
  249. loading = false;
  250. }
  251. }
  252. else
  253. {
  254. loading = false;
  255. }
  256. }
  257. else
  258. {
  259. loading = false;
  260. }
  261. }
  262. });
  263. }
  264. private Tuple<string, double> ProcessResult(string result)
  265. {
  266. double qty = 1;
  267. if (result.Contains("*"))
  268. {
  269. try
  270. {
  271. int i = result.IndexOf("*");
  272. string remainder = result.Substring(i);
  273. result = result.Remove(i);
  274. string s1 = remainder.Substring(1);
  275. qty = Convert.ToDouble(s1);
  276. }
  277. catch
  278. {
  279. loading = false;
  280. }
  281. }
  282. Tuple<string, double> tuple = new Tuple<string, double>(result, qty);
  283. return tuple;
  284. }
  285. private void LoadProduct(Tuple<string, double> processedResultQtyTuple, string rawResult)
  286. {
  287. Device.BeginInvokeOnMainThread(async () =>
  288. {
  289. //lookup product in productshells cache
  290. ProductShell product = GlobalVariables.ProductShells.Find(x => x.Code.Equals(processedResultQtyTuple.Item1));
  291. //lookup holding for product in holdings cache
  292. try
  293. {
  294. var list = CreateHoldingsList(product.ID);
  295. if (list.Count == 1) //one stockholding - auto choose holding
  296. AddStoreRequiItemShell(list.First(), product, rawResult, processedResultQtyTuple);
  297. else if (list.Count > 1) //more than one stockholding - user choose shelf
  298. UserSelectFromList(list, product, rawResult, processedResultQtyTuple);
  299. else if (list.Count == 0)
  300. DisplayAlert("No Holdings Found for Product", "", "OK");
  301. loading = false;
  302. }
  303. catch (Exception e)
  304. {
  305. DisplayAlert("Error", e.Message, "OK");
  306. loading = false;
  307. return;
  308. }
  309. });
  310. }
  311. private void UserSelectFromList(List<StoreRequiIHoldingShell> list, ProductShell product, string rawResult, Tuple<string, double> processedResultQtyTuple)
  312. {
  313. Dictionary<string, Guid> holdingLocationIDs = new Dictionary<string, Guid>();
  314. foreach (StoreRequiIHoldingShell holding in list)
  315. {
  316. if (!holdingLocationIDs.ContainsKey(holding.LocationName))
  317. holdingLocationIDs.Add(holding.LocationName, holding.LocationID);
  318. }
  319. List<string> options = holdingLocationIDs.Keys.ToList();
  320. ListSelectionPage page = new ListSelectionPage(options);
  321. page.OnSimpleListTapped += (locationName) =>
  322. {
  323. AddStoreRequiItemShell(list.Find(x => x.LocationName == locationName), product, rawResult, processedResultQtyTuple);
  324. };
  325. Navigation.PushAsync(page);
  326. }
  327. private List<StoreRequiIHoldingShell> CreateHoldingsList(Guid productID)
  328. {
  329. List<StoreRequiIHoldingShell> list = new List<StoreRequiIHoldingShell>();
  330. CoreTable table = DoHoldingsQuery(productID);
  331. foreach (CoreRow row in table.Rows)
  332. {
  333. if (row.Get<StockHolding, double>(x => x.Units) == 0.0)
  334. continue;
  335. list.Add(CreateHoldingShell(row));
  336. }
  337. return list;
  338. }
  339. private CoreTable DoHoldingsQuery(Guid productID)
  340. {
  341. return new Client<StockHolding>().Query(
  342. new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(productID),
  343. new Columns<StockHolding>(
  344. x => x.ID,
  345. x => x.Product.ID,
  346. x => x.Location.ID,
  347. x => x.Location.Description,
  348. x => x.Units,
  349. x => x.Job.ID,
  350. x => x.Job.JobNumber,
  351. x => x.Job.Name,
  352. x => x.Style.ID,
  353. x => x.Style.Code,
  354. x => x.Style.Description,
  355. x => x.Dimensions.Unit.ID,
  356. x => x.Dimensions.Unit.HasQuantity,
  357. x => x.Dimensions.Unit.HasLength,
  358. x => x.Dimensions.Unit.HasHeight,
  359. x => x.Dimensions.Unit.HasWeight,
  360. x => x.Dimensions.Unit.HasWidth,
  361. x => x.Dimensions.Quantity,
  362. x => x.Dimensions.Length,
  363. x => x.Dimensions.Height,
  364. x => x.Dimensions.Weight,
  365. x => x.Dimensions.Width,
  366. x => x.Dimensions.Unit.Format,
  367. x => x.Dimensions.Unit.Formula,
  368. x => x.Dimensions.UnitSize
  369. )
  370. );
  371. }
  372. private StoreRequiIHoldingShell CreateHoldingShell(CoreRow row)
  373. {
  374. StoreRequiIHoldingShell holding = new StoreRequiIHoldingShell()
  375. {
  376. ProductID = row.Get<StockHolding, Guid>(x => x.Product.ID),
  377. LocationID = row.Get<StockHolding, Guid>(x => x.Location.ID),
  378. LocationName = row.Get<StockHolding, string>(x => x.Location.Description),
  379. Units = row.Get<StockHolding, double>(x => x.Units).ToString(),
  380. JobID = row.Get<StockHolding, Guid>(x => x.Job.ID),
  381. JobNumber = row.Get<StockHolding, string>(x => x.Job.JobNumber),
  382. JobName = row.Get<StockHolding, string>(x => x.Job.Name),
  383. StyleID = row.Get<StockHolding, Guid>(x => x.Style.ID),
  384. StyleCode = row.Get<StockHolding, string>(x => x.Style.Code),
  385. StyleDescription = row.Get<StockHolding, string>(x => x.Style.Description)
  386. };
  387. holding.Dimensions.Unit.ID = row.Get<StockHolding, Guid>(x => x.Dimensions.Unit.ID);
  388. holding.Dimensions.Unit.HasQuantity = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasQuantity);
  389. holding.Dimensions.Unit.HasLength = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasLength);
  390. holding.Dimensions.Unit.HasHeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasHeight);
  391. holding.Dimensions.Unit.HasWeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWeight);
  392. holding.Dimensions.Unit.HasWidth = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWidth);
  393. holding.Dimensions.Quantity = row.Get<StockHolding, double>(x => x.Dimensions.Quantity);
  394. holding.Dimensions.Length = row.Get<StockHolding, double>(x => x.Dimensions.Length);
  395. holding.Dimensions.Height = row.Get<StockHolding, double>(x => x.Dimensions.Height);
  396. holding.Dimensions.Weight = row.Get<StockHolding, double>(x => x.Dimensions.Weight);
  397. holding.Dimensions.Width = row.Get<StockHolding, double>(x => x.Dimensions.Width);
  398. holding.Dimensions.Unit.Format = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Format);
  399. holding.Dimensions.Unit.Formula = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Formula);
  400. holding.Dimensions.UnitSize = row.Get<StockHolding, string>(x => x.Dimensions.UnitSize);
  401. holding.LocationName = holding.LocationName + " (Units: " + holding.Units + ")" +
  402. Environment.NewLine + "Style: " + holding.StyleDescription
  403. + Environment.NewLine + "Job: " + holding.JobNumber
  404. + Environment.NewLine + "Size: " + holding.Dimensions.UnitSize;
  405. return holding;
  406. }
  407. private void AddStoreRequiItemShell(StoreRequiIHoldingShell holding, ProductShell product, string rawResult, Tuple<string, double> processedResultQtyTuple)
  408. {
  409. StoreRequiItemShell shell = new StoreRequiItemShell
  410. {
  411. ProductID = product.ID,
  412. ProductName = product.Name,
  413. ProductCode = product.Code,
  414. Quantity = 1,
  415. LocationID = holding.LocationID,
  416. LocationName = holding.LocationName,
  417. StyleID = holding.StyleID,
  418. JobID = holding.StyleID
  419. };
  420. shell.Dimensions.Unit.ID = holding.Dimensions.Unit.ID;
  421. shell.Dimensions.Unit.HasQuantity = holding.Dimensions.Unit.HasQuantity;
  422. shell.Dimensions.Unit.HasLength = holding.Dimensions.Unit.HasLength;
  423. shell.Dimensions.Unit.HasHeight = holding.Dimensions.Unit.HasHeight;
  424. shell.Dimensions.Unit.HasWeight = holding.Dimensions.Unit.HasWeight;
  425. shell.Dimensions.Unit.HasWidth = holding.Dimensions.Unit.HasWidth;
  426. shell.Dimensions.Quantity = holding.Dimensions.Quantity;
  427. shell.Dimensions.Length = holding.Dimensions.Length;
  428. shell.Dimensions.Height = holding.Dimensions.Height;
  429. shell.Dimensions.Weight = holding.Dimensions.Weight;
  430. shell.Dimensions.Width = holding.Dimensions.Width;
  431. shell.Dimensions.Unit.Format = holding.Dimensions.Unit.Format;
  432. shell.Dimensions.Unit.Formula = holding.Dimensions.Unit.Formula;
  433. shell.Dimensions.UnitSize = holding.Dimensions.UnitSize;
  434. shells.Add(shell);
  435. itemRowScannerRawResultPairs.Add(shell, rawResult);
  436. itemRowScannerProcessedResultPairs.Add(shell, processedResultQtyTuple.Item1);
  437. requiItemListView.ItemsSource = null;
  438. requiItemListView.ItemsSource = shells;
  439. countLbl.IsVisible = true;
  440. if (containsNotes)
  441. {
  442. countLbl.Text = "Number of items: " + (shells.Count - 1);
  443. }
  444. else
  445. {
  446. countLbl.Text = "Number of items: " + shells.Count;
  447. }
  448. saveBtn.IsVisible = true;
  449. loading = false;
  450. }
  451. #endregion
  452. #region Button Presses
  453. private async void ExitBtn_Clicked(object sender, EventArgs e)
  454. {
  455. if (shells.Count > 0)
  456. {
  457. if (containsNotes && shells.Count > 1)
  458. {
  459. string chosenOption = await DisplayActionSheet("Leave without saving?", "Cancel", null, "Yes", "No");
  460. switch (chosenOption)
  461. {
  462. case "Cancel":
  463. return;
  464. case "Yes":
  465. Navigation.PopAsync();
  466. break;
  467. case "No":
  468. return;
  469. default:
  470. return;
  471. }
  472. }
  473. else if (containsNotes && shells.Count == 1)
  474. {
  475. Navigation.PopAsync();
  476. }
  477. else
  478. {
  479. string chosenOption = await DisplayActionSheet("Leave without saving?", "Cancel", null, "Yes", "No");
  480. switch (chosenOption)
  481. {
  482. case "Cancel":
  483. return;
  484. case "Yes":
  485. Navigation.PopAsync();
  486. break;
  487. case "No":
  488. return;
  489. default:
  490. return;
  491. }
  492. }
  493. }
  494. else
  495. Navigation.PopAsync();
  496. }
  497. void SaveBtn_Clicked(object sender, EventArgs e)
  498. {
  499. StoreRequiConfirmationPage page = new StoreRequiConfirmationPage(requisition, shells, oldShells);
  500. page.OnSaveSelected += () => { Navigation.PopAsync(); };
  501. Navigation.PushAsync(page);
  502. }
  503. private async void RequiItem_Tapped(object sender, EventArgs e)
  504. {
  505. var shell = requiItemListView.SelectedItem as StoreRequiItemShell;
  506. if (shell == null) return;
  507. await RequiItemTappedAsync(shell);
  508. }
  509. private async Task RequiItemTappedAsync(StoreRequiItemShell shell)
  510. {
  511. string pickstatus = shell.Picked == DateTime.MinValue ? "not picked" : "picked (" + shell.Picked.ToString("dd MMM yy") + ")";
  512. string options = shell.Picked == DateTime.MinValue ? ". Mark as Picked?" : ". Remove Picked status?";
  513. string chosenOption = await DisplayActionSheet("Line is " + pickstatus + options, "Cancel", null, "Yes", "No");
  514. if (chosenOption != "Yes")
  515. return;
  516. shell.Picked = shell.Picked == DateTime.MinValue ? DateTime.Today : DateTime.MinValue;
  517. shell.Colour = shell.Picked == DateTime.MinValue ? Color.Default : Color.FromHex("#8fbc8f");
  518. requiItemListView.ItemsSource = null;
  519. requiItemListView.ItemsSource = shells;
  520. }
  521. void ReduceQtyBtn_Clicked(object sender, EventArgs e)
  522. {
  523. var shell = ((TappedEventArgs)e).Parameter as StoreRequiItemShell;
  524. if (shell == null) return;
  525. if (shell.Quantity <= 1)
  526. {
  527. shells.Remove(shell);
  528. itemRowScannerRawResultPairs.Remove(shell);
  529. itemRowScannerProcessedResultPairs.Remove(shell);
  530. if (containsNotes)
  531. {
  532. countLbl.Text = "Number of items: " + (shells.Count - 1);
  533. if (shells.Count == 1)
  534. {
  535. saveBtn.IsVisible = false;
  536. }
  537. }
  538. else
  539. {
  540. countLbl.Text = "Number of items: " + shells.Count;
  541. if (shells.Count == 0)
  542. {
  543. saveBtn.IsVisible = false;
  544. }
  545. }
  546. }
  547. else
  548. {
  549. shell.Quantity--;
  550. }
  551. requiItemListView.ItemsSource = null;
  552. requiItemListView.ItemsSource = shells;
  553. }
  554. void IncreaseQtyBtn_Clicked(object sender, EventArgs e)
  555. {
  556. var shell = ((TappedEventArgs)e).Parameter as StoreRequiItemShell;
  557. if (shell == null)
  558. return;
  559. shell.Quantity++;
  560. requiItemListView.ItemsSource = null;
  561. requiItemListView.ItemsSource = shells;
  562. }
  563. void AddItem_Clicked(object sender, EventArgs e)
  564. {
  565. if (GlobalVariables.ProductsLoaded)
  566. {
  567. if (loading)
  568. return;
  569. loading = true;
  570. ProductList products = new ProductList(GlobalVariables.ProductShells, true);
  571. products.OnProductSelected += () =>
  572. {
  573. Tuple<string, double> tuple = new Tuple<string, double>(products.SelectedProduct.Code, 1);
  574. LoadProduct(new Tuple<string, double>(products.SelectedProduct.Code, 1), products.SelectedProduct.Code);
  575. };
  576. Navigation.PushAsync(products);
  577. }
  578. }
  579. void Qty_Changed(object sender, EventArgs e)
  580. {
  581. }
  582. #endregion
  583. }
  584. [DoNotPersist]
  585. public class StoreRequiItemShell : Entity
  586. {
  587. public Guid ProductID { get; set; }
  588. public string ProductCode { get; set; }
  589. public string ProductName { get; set; }
  590. public string LocationName { get; set; }
  591. public double Quantity { get; set; }
  592. public Guid LocationID { get; set; }
  593. public Color BorderColor { get; set; }
  594. public bool IsNotes { get; set; }
  595. public bool IsNotNotes { get; set; }
  596. public string Summary { get; set; }
  597. public DateTime Picked { get; set; }
  598. public Color Colour { get; set; }
  599. public Guid JobID { get; set; }
  600. public Guid StyleID { get; set; }
  601. public StockDimensions Dimensions { get; set; }
  602. public StoreRequiItemShell()
  603. {
  604. ProductID = Guid.Empty;
  605. ProductCode = "";
  606. ProductName = "";
  607. LocationName = "";
  608. Quantity = 0;
  609. ID = Guid.Empty;
  610. LocationID = Guid.Empty;
  611. BorderColor = Color.FromHex("#15C7C1");
  612. IsNotes = false;
  613. IsNotNotes = true;
  614. Picked = DateTime.MinValue;
  615. Colour = Color.Default;
  616. JobID = Guid.Empty;
  617. StyleID = Guid.Empty;
  618. Dimensions = new StockDimensions(() => this);
  619. }
  620. }
  621. }