StoreRequiItem.xaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Comal.Classes;
  7. using Xamarin.Forms;
  8. using Xamarin.Forms.Xaml;
  9. namespace comal.timesheets.CustomControls
  10. {
  11. [XamlCompilation(XamlCompilationOptions.Compile)]
  12. public partial class StoreRequiItem : ContentView
  13. {
  14. public delegate void ZeroSelected(int _ID);
  15. public delegate void ParseError();
  16. public event ParseError OnParseError;
  17. public event ZeroSelected OnZeroSelected;
  18. public Guid ProductID { get; set; }
  19. public string ProductCode { get; set; }
  20. public string ProductName { get; set; }
  21. public string LocationName { get; set; }
  22. public double Quantity { get; set; }
  23. public int ID { get; set; }
  24. public Guid RequiItemID { get; set; }
  25. public Guid HoldingID { get; set; }
  26. public bool Packs { get; set; }
  27. public StoreRequiItem(ProductShell _product, double qty, string itemLocation, Guid _holdingID)
  28. {
  29. InitializeComponent();
  30. Quantity = qty;
  31. HoldingID = _holdingID;
  32. RequiItemID = Guid.Empty;
  33. LocationName = itemLocation;
  34. UpdateRow(_product);
  35. }
  36. private void UpdateRow(ProductShell _product)
  37. {
  38. ProductID = _product.ID;
  39. ProductCode = _product.Code;
  40. ProductName = _product.Name;
  41. locationLbl.Text = LocationName;
  42. productLbl.Text = ProductName + " (" + ProductCode + ")";
  43. qtyLbl.Text = Quantity.ToString();
  44. }
  45. public void UpdateShelf()
  46. {
  47. }
  48. #region Buttons
  49. private void ReduceQtyBtn_Clicked(object sender, EventArgs e)
  50. {
  51. if (Quantity <= 1)
  52. {
  53. OnZeroSelected?.Invoke(ID);
  54. return;
  55. }
  56. else
  57. {
  58. Quantity--;
  59. qtyLbl.Text = Quantity.ToString();
  60. }
  61. }
  62. private void IncreaseQtyBtn_Clicked(object sender, EventArgs e)
  63. {
  64. Quantity++;
  65. qtyLbl.Text = Quantity.ToString();
  66. }
  67. private void qtyEntry_Changed(object sender, EventArgs e)
  68. {
  69. try
  70. {
  71. double i = Convert.ToDouble(qtyLbl.Text);
  72. if (i > 0.0)
  73. {
  74. Quantity = i;
  75. }
  76. else
  77. {
  78. qtyLbl.Text = "1";
  79. Quantity = 1;
  80. }
  81. }
  82. catch
  83. {
  84. if (string.IsNullOrWhiteSpace(qtyLbl.Text))
  85. { }
  86. else
  87. OnParseError?.Invoke();
  88. }
  89. }
  90. #endregion
  91. private StoreRequiItem()
  92. {
  93. }
  94. }
  95. }