123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- using Sessioa.BaseModel;
- using Sessioa.Classes;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- namespace Sessioa.Pages
- {
- /// <summary>
- /// Логика взаимодействия для OrderCard.xaml
- /// </summary>
- public partial class OrderCard : Page
- {
- List<Product> products = (List<Product>)Application.Current.Properties["ListOrderUser"];
- Dictionary<string, int> keyValuePairs = (Dictionary<string, int>)(Application.Current.Properties["ListOrderCountUser"]);
- //{
- // {"djkdkla", 19 }
- //};
- User user = null;
- public OrderCard(User userSign)
- {
- InitializeComponent();
- user = userSign;
- LB_ProductsOrder.ItemsSource = products;
- if (keyValuePairs.Count == 0)
- {
- foreach (Product product in products)
- {
- keyValuePairs.Add($"{product.ProductArticleNumber}", 1);
- }
- }
- else
- {
- foreach (Product product in products)
- {
- try
- {
- keyValuePairs.Add($"{product.ProductArticleNumber}", 1);
- }
- catch { }
- }
- }
- ItogoSkidka();
- //keyValuePairs.Add("dawlk", 2718);
- //foreach(KeyValuePair<string, int> pair in keyValuePairs)
- //{
- // pair.Key; //1
- // pair.Value; //2
- //}
- }
- private void countPr_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock textBlock = (TextBlock)sender;
- Product product = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == textBlock.Uid);
- if (product.ProductDiscountAmount != null)
- textBlock.TextDecorations = TextDecorations.Strikethrough;
- }
- private void countDPr_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock textBlock = (TextBlock)sender;
- Product product = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == textBlock.Uid);
- if (product.ProductDiscountAmount != null)
- {
- textBlock.Visibility = Visibility.Visible;
- textBlock.Text = $" {(double)(product.ProductCost - product.ProductCost * product.ProductDiscountAmount / 100)} ₽";
- }
- }
- private void Discount_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock textBlock = (TextBlock)sender;
- Product product = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == textBlock.Uid);
- if (product.ProductDiscountAmount != null)
- {
- textBlock.Visibility = Visibility.Visible;
- textBlock.Text = $"Скидка {product.ProductDiscountAmount}%";
- }
- }
- private void B_Back_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Properties["ListOrderCountUser"] = keyValuePairs;
- FrameClass.C_Frame.Navigate(new ProductsPage(user));
- }
- private void B_Save_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Properties["ListOrderUser"] = new List<Product>();
- Application.Current.Properties["ListOrderCountUser"] = new Dictionary<string, int>();
- MessageBoxResult mbr = MessageBox.Show("Заказ оформлен.", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
- if (mbr == MessageBoxResult.OK)
- FrameClass.C_Frame.Navigate(new ProductsPage(user));
- }
- private void Back_B_Click(object sender, RoutedEventArgs e)
- {
- Button bBack = (Button)sender;
- Grid grid = (Grid)bBack.Parent;
- TextBlock textBlock = (TextBlock)grid.FindName("CountProduct");
- Product pr = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == bBack.Uid);
- if (pr != null)
- {
- foreach (KeyValuePair<string, int> pair in keyValuePairs)
- {
- if (pair.Key == bBack.Uid)
- {
- if (pair.Value > 1)
- {
- keyValuePairs[pair.Key]--;
- textBlock.Text = keyValuePairs[pair.Key].ToString();
- break;
- }
- }
- }
- }
- ItogoSkidka();
- }
- private void Next_B_Click(object sender, RoutedEventArgs e)
- {
- Button bNext = (Button)sender;
- Grid grid = (Grid)bNext.Parent;
- TextBlock textBlock = (TextBlock)grid.FindName("CountProduct");
- Product pr = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == bNext.Uid);
- if (pr != null)
- {
- foreach (KeyValuePair<string, int> pair in keyValuePairs)
- {
- if (pair.Key == bNext.Uid)
- {
- keyValuePairs[pair.Key]++;
- textBlock.Text = keyValuePairs[pair.Key].ToString();
- break;
- }
- }
- }
- ItogoSkidka();
- }
- private void CountProduct_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- if (keyValuePairs.Count > 0)
- {
- foreach (KeyValuePair<string, int> pair in keyValuePairs)
- {
- if (pair.Key == tb.Uid)
- {
- tb.Text = keyValuePairs[pair.Key].ToString();
- break;
- }
- }
- }
- }
- public void ItogoSkidka()
- {
- decimal itogoBezSkidki = 0;
- foreach(Product item in products)
- {
- foreach(KeyValuePair<string, int> pair in keyValuePairs)
- {
- if(pair.Key == item.ProductArticleNumber)
- {
- itogoBezSkidki += item.ProductCost * pair.Value;
- }
- }
- }
- decimal itogoSoSkidkoy = 0;
- foreach (Product item in products)
- {
- foreach (KeyValuePair<string, int> pair in keyValuePairs)
- {
- if (pair.Key == item.ProductArticleNumber)
- {
- if(item.ProductDiscountAmount != null)
- {
- itogoSoSkidkoy += (item.ProductCost - (item.ProductCost * ((decimal)item.ProductDiscountAmount / 100))) * pair.Value;
- }
- else
- itogoSoSkidkoy += item.ProductCost * pair.Value;
- }
- }
- }
- decimal ITOGO = Math.Round((1 - (itogoSoSkidkoy / itogoBezSkidki)) * 100, 2);
- TB_ItogoSkidka.Text = $"Скидка {ITOGO}%";
- TB_Itogo.Text = $"{(double)itogoSoSkidkoy} ₽";
- }
- }
- }
|