Cart.xaml.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 GGwp
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для Cart.xaml
  18. /// </summary>
  19. public partial class Cart : Window
  20. {
  21. TradePrytovEntities DB = new TradePrytovEntities();
  22. public static List<Product> Products = new List<Product>();
  23. public static List<AmountProduct> AmountProduct = new List<AmountProduct>();
  24. public Cart()
  25. {
  26. InitializeComponent();
  27. CartList.ItemsSource = Products;
  28. }
  29. public Cart(int id)
  30. {
  31. InitializeComponent();
  32. CartList.ItemsSource = Products;
  33. }
  34. private void CostCalculate(object sender, RoutedEventArgs e)
  35. {
  36. TextBlock tb = (TextBlock)sender;
  37. string Article = tb.Uid.ToString();
  38. Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
  39. if (pr.ProductMaxDiscountAmount > 0)
  40. {
  41. tb.Text = "Цена: " + string.Format("{0:C2}", (pr.ProductCost - (pr.ProductCost / 100 * pr.ProductMaxDiscountAmount)));
  42. }
  43. }
  44. private void Photo(object sender, RoutedEventArgs e)
  45. {
  46. Image pic = (Image)sender;
  47. string Article = pic.Uid.ToString();
  48. string photoPath = DB.Product.Where(x => x.ProductArticleNumber == Article).Select(x => x.ProductPhoto).FirstOrDefault();
  49. if (photoPath != null && photoPath != "")
  50. {
  51. pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Pictures\\" + photoPath, UriKind.RelativeOrAbsolute));
  52. }
  53. else
  54. {
  55. pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Pictures\\picture.png", UriKind.RelativeOrAbsolute));
  56. }
  57. }
  58. private void AmountCalculate(object sender, RoutedEventArgs e)
  59. {
  60. TextBlock tb = (TextBlock)sender;
  61. string Article = tb.Uid.ToString();
  62. Product pr = Products.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
  63. int index = Products.IndexOf(pr);
  64. tb.Text = AmountProduct[index].Amount.ToString();
  65. }
  66. }
  67. }