TransferEdit.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Linq;
  3. using InABox.Mobile;
  4. using Xamarin.Forms;
  5. using Xamarin.Forms.Xaml;
  6. namespace PRS.Mobile
  7. {
  8. public class StockTransactionSavedArgs : EventArgs
  9. {
  10. public StockTransaction Transaction { get; private set; }
  11. public StockTransactionSavedArgs(StockTransaction transaction)
  12. {
  13. Transaction = transaction;
  14. }
  15. }
  16. public delegate void StockTransactionSavedEvent(object sender, StockTransactionSavedArgs args);
  17. [XamlCompilation(XamlCompilationOptions.Compile)]
  18. public partial class TransferEdit
  19. {
  20. public event StockTransactionSavedEvent? TransactionSaved;
  21. public TransferEdit(StockTransaction transaction, StockTransactions otherTransactions)
  22. {
  23. InitializeComponent();
  24. ViewModel.Transaction = transaction;
  25. ViewModel.OtherTransactions = otherTransactions;
  26. }
  27. private void _tick_OnClicked(object sender, MobileMenuButtonClickedEventArgs args)
  28. {
  29. TransactionSaved?.Invoke(this, new StockTransactionSavedArgs(ViewModel.Transaction));
  30. Navigation.PopAsync();
  31. }
  32. private void IncreaseQty_Clicked(object sender, MobileButtonClickEventArgs args)
  33. {
  34. if ((sender as MobileButton)?.BindingContext is StockTransactionAllocation alloc)
  35. alloc.Quantity = Math.Min(alloc.Maximum, alloc.Quantity + 1);
  36. //ViewModel.Transaction.Quantity += 1.0;
  37. }
  38. private void DecreaseQty_Clicked(object sender, MobileButtonClickEventArgs args)
  39. {
  40. if ((sender as MobileButton)?.BindingContext is StockTransactionAllocation alloc)
  41. alloc.Quantity = Math.Max(0, alloc.Quantity - 1);
  42. //ViewModel.Transaction.Quantity -= 1.0;
  43. }
  44. private void SelectLocation_Clicked(object sender, MobileButtonClickEventArgs args)
  45. {
  46. ShowPopup(() =>
  47. SelectionView.Execute<StockLocationShell>(
  48. columns =>
  49. {
  50. columns.Add(new MobileGridTextColumn<StockLocationShell>()
  51. { Column = x => x.Code, Width = GridLength.Auto });
  52. columns.Add(new MobileGridTextColumn<StockLocationShell>()
  53. { Column = x => x.Description, Width = GridLength.Star });
  54. },
  55. refresh => App.Data.StockLocations.Refresh(false),
  56. locations =>
  57. {
  58. ViewModel.Transaction.Target.LocationID = locations?.FirstOrDefault()?.ID ?? Guid.Empty;
  59. ViewModel.Transaction.Target.LocationCode = locations?.FirstOrDefault()?.Code ?? string.Empty;
  60. ViewModel.Transaction.Target.LocationDescription = locations?.FirstOrDefault()?.Description ?? string.Empty;
  61. DismissPopup();
  62. })
  63. );
  64. }
  65. private void SelectStyle_Clicked(object sender, MobileButtonClickEventArgs args)
  66. {
  67. ShowPopup(() =>
  68. SelectionView.Execute<ProductStyleShell>(
  69. columns =>
  70. {
  71. columns.Add(new MobileGridTextColumn<ProductStyleShell>()
  72. { Column = x => x.Code, Width = GridLength.Auto });
  73. columns.Add(new MobileGridTextColumn<ProductStyleShell>()
  74. { Column = x => x.Description, Width = GridLength.Star });
  75. },
  76. refresh => App.Data.ProductStyles.Refresh(false),
  77. styles =>
  78. {
  79. ViewModel.Transaction.Target.StyleID = styles?.FirstOrDefault()?.ID ?? Guid.Empty;
  80. ViewModel.Transaction.Target.StyleCode = styles?.FirstOrDefault()?.Code ?? string.Empty;
  81. ViewModel.Transaction.Target.StyleDescription = styles?.FirstOrDefault()?.Description ?? string.Empty;
  82. DismissPopup();
  83. })
  84. );
  85. }
  86. private void SelectJob_Clicked(object sender, MobileButtonClickEventArgs args)
  87. {
  88. ShowPopup(() =>
  89. SelectionView.Execute<JobShell>(
  90. columns =>
  91. {
  92. columns.Add(new MobileGridTextColumn<JobShell>()
  93. { Column = x => x.JobNumber, Width = GridLength.Auto });
  94. columns.Add(new MobileGridTextColumn<JobShell>()
  95. { Column = x => x.Name, Width = GridLength.Star });
  96. },
  97. refresh => App.Data.Jobs.Refresh(false),
  98. jobs =>
  99. {
  100. ViewModel.Transaction.Target.JobID = jobs?.FirstOrDefault()?.ID ?? Guid.Empty;
  101. ViewModel.Transaction.Target.JobNumber = jobs?.FirstOrDefault()?.JobNumber ?? string.Empty;
  102. ViewModel.Transaction.Target.JobName = jobs?.FirstOrDefault()?.Name ?? string.Empty;
  103. DismissPopup();
  104. })
  105. );
  106. }
  107. }
  108. }