UpdateCostWindow.xaml.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace Lopushok
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для UpdateCostWindow.xaml
  18. /// </summary>
  19. public partial class UpdateCostWindow : Window
  20. {
  21. private List<Product> Products;
  22. public UpdateCostWindow(List<Product> products)
  23. {
  24. InitializeComponent();
  25. Products = products;
  26. TbCost.Text = Products.Average(x => x.MinCostForAgent).ToString();
  27. }
  28. private void BtnUpdate_Click(object sender, RoutedEventArgs e)
  29. {
  30. if (!decimal.TryParse(TbCost.Text, out decimal cost))
  31. {
  32. MessageBox.Show("Стоимость имеет неправильный формат!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
  33. return;
  34. }
  35. foreach (var item in Products)
  36. {
  37. item.MinCostForAgent = cost;
  38. }
  39. Helper.context.SaveChanges();
  40. Close();
  41. }
  42. }
  43. }