ClassMain.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace OUP
  8. {
  9. class ClassMain : BaseViewModel
  10. {
  11. private ObservableCollection<Product> _products;
  12. private ObservableCollection<CashRegister> _cashRegisters;
  13. private RelayCommand _updateOpenWindow;
  14. private Product _selectedProduct;
  15. private CashRegister _cashRegister;
  16. private RelayCommand _update;
  17. public RelayCommand UpdateOpenWindow
  18. {
  19. get
  20. {
  21. return _updateOpenWindow ??
  22. (_updateOpenWindow = new RelayCommand((x) =>
  23. {
  24. if (x is CashRegister xx)
  25. {
  26. }
  27. }));
  28. }
  29. }
  30. public ObservableCollection<Product> Products
  31. {
  32. get
  33. {
  34. return _products;
  35. }
  36. set
  37. {
  38. _products = value;
  39. OnPropertyChanged();
  40. }
  41. }
  42. public Product SelectedProduct
  43. {
  44. get
  45. {
  46. return _selectedProduct;
  47. }
  48. set
  49. {
  50. _selectedProduct = value;
  51. OnPropertyChanged();
  52. }
  53. }
  54. public CashRegister SelectedCashRegister
  55. {
  56. get
  57. {
  58. return _cashRegister;
  59. }
  60. set
  61. {
  62. _cashRegister = value;
  63. OnPropertyChanged();
  64. }
  65. }
  66. public ObservableCollection<CashRegister> CashRegister
  67. {
  68. get
  69. {
  70. return _cashRegisters;
  71. }
  72. set
  73. {
  74. _cashRegisters = value;
  75. OnPropertyChanged();
  76. }
  77. }
  78. private void LoadCollection()
  79. {
  80. Products.Clear();
  81. Products = new ObservableCollection<Product>(Helper.GetContext().Product);
  82. }
  83. public ClassMain()
  84. {
  85. _products = new ObservableCollection<Product>(Helper.GetContext().Product);
  86. _cashRegisters = new ObservableCollection<CashRegister>(Helper.GetContext().CashRegister);
  87. }
  88. public RelayCommand Update
  89. {
  90. get
  91. {
  92. return _update ??
  93. (_update = new RelayCommand((x) =>
  94. {
  95. SelectedProduct.CashRegister = CashRegister;
  96. Helper.GetContext().SaveChanges();
  97. LoadCollection();
  98. }));
  99. }
  100. }
  101. }
  102. }