|
@@ -23,16 +23,27 @@ namespace GGwp
|
|
TradePrytovEntities DB = new TradePrytovEntities();
|
|
TradePrytovEntities DB = new TradePrytovEntities();
|
|
public static List<Product> Products = new List<Product>();
|
|
public static List<Product> Products = new List<Product>();
|
|
public static List<AmountProduct> AmountProduct = new List<AmountProduct>();
|
|
public static List<AmountProduct> AmountProduct = new List<AmountProduct>();
|
|
|
|
+ public decimal? TotalCost = 0;
|
|
public Cart()
|
|
public Cart()
|
|
{
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
CartList.ItemsSource = Products;
|
|
CartList.ItemsSource = Products;
|
|
|
|
+ foreach (Product p in Products)
|
|
|
|
+ {
|
|
|
|
+ TotalCost += p.ProductCost - (p.ProductCost / 100 * p.ProductMaxDiscountAmount);
|
|
|
|
+ }
|
|
|
|
+ CostOrder.Text = "Стоимость заказа: " + string.Format("{0:C2}", TotalCost);
|
|
}
|
|
}
|
|
|
|
|
|
public Cart(int id)
|
|
public Cart(int id)
|
|
{
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
CartList.ItemsSource = Products;
|
|
CartList.ItemsSource = Products;
|
|
|
|
+ foreach (Product p in Products)
|
|
|
|
+ {
|
|
|
|
+ TotalCost += p.ProductCost - (p.ProductCost / 100 * p.ProductMaxDiscountAmount);
|
|
|
|
+ }
|
|
|
|
+ CostOrder.Text = string.Format("{0:C2}", TotalCost);
|
|
}
|
|
}
|
|
|
|
|
|
private void CostCalculate(object sender, RoutedEventArgs e)
|
|
private void CostCalculate(object sender, RoutedEventArgs e)
|
|
@@ -70,5 +81,126 @@ namespace GGwp
|
|
tb.Text = AmountProduct[index].Amount.ToString();
|
|
tb.Text = AmountProduct[index].Amount.ToString();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void MinusAmount(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ Button bt = (Button)sender;
|
|
|
|
+ string article = bt.Uid.ToString();
|
|
|
|
+ Product pr = Products.Where(x => x.ProductArticleNumber == article).First();
|
|
|
|
+ AmountProduct pa = AmountProduct.Where(x => x.Article == article).First();
|
|
|
|
+ if ((pa.Amount - 1) == 0)
|
|
|
|
+ {
|
|
|
|
+ AmountProduct.Remove(pa);
|
|
|
|
+ Products.Remove(pr);
|
|
|
|
+ if (Products.Count == 0)
|
|
|
|
+ {
|
|
|
|
+ this.Close();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ foreach (AmountProduct pp in AmountProduct)
|
|
|
|
+ {
|
|
|
|
+ if (pp.Article == article)
|
|
|
|
+ {
|
|
|
|
+ pp.Amount--;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ TotalCost = 0;
|
|
|
|
+ foreach (Product p in Products)
|
|
|
|
+ {
|
|
|
|
+ TotalCost += (p.ProductCost - (p.ProductCost / 100 * p.ProductMaxDiscountAmount)) * AmountProduct.Where(x => x.Article == p.ProductArticleNumber).Select(x => x.Amount).First();
|
|
|
|
+ }
|
|
|
|
+ CostOrder.Text = "Стоимость заказа: " + string.Format("{0:C2}", TotalCost);
|
|
|
|
+ CartList.ItemsSource = Products.ToList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void PlusAmount(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ Button bt = (Button)sender;
|
|
|
|
+ string article = bt.Uid.ToString();
|
|
|
|
+ foreach (AmountProduct pa in AmountProduct)
|
|
|
|
+ {
|
|
|
|
+ if (pa.Article == article)
|
|
|
|
+ {
|
|
|
|
+ pa.Amount++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ TotalCost = 0;
|
|
|
|
+ foreach (Product p in Products)
|
|
|
|
+ {
|
|
|
|
+ TotalCost += (p.ProductCost - (p.ProductCost / 100 * p.ProductMaxDiscountAmount)) * AmountProduct.Where(x => x.Article == p.ProductArticleNumber).Select(x => x.Amount).First();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ CostOrder.Text = "Стоимость заказа: " + string.Format("{0:C2}", TotalCost);
|
|
|
|
+ CartList.ItemsSource = Products.ToList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void DeleteProduct(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ Button bt = (Button)sender;
|
|
|
|
+ string article = bt.Uid.ToString();
|
|
|
|
+ Product pr = Products.Where(x => x.ProductArticleNumber == article).First();
|
|
|
|
+ AmountProduct pa = AmountProduct.Where(x => x.Article == article).First();
|
|
|
|
+ AmountProduct.Remove(pa);
|
|
|
|
+ Products.Remove(pr);
|
|
|
|
+ if (Products.Count == 0)
|
|
|
|
+ {
|
|
|
|
+ this.Close();
|
|
|
|
+ }
|
|
|
|
+ TotalCost = 0;
|
|
|
|
+ foreach (Product p in Products)
|
|
|
|
+ {
|
|
|
|
+ TotalCost += (p.ProductCost - (p.ProductCost / 100 * p.ProductMaxDiscountAmount)) * AmountProduct.Where(x => x.Article == p.ProductArticleNumber).Select(x => x.Amount).First();
|
|
|
|
+ }
|
|
|
|
+ CostOrder.Text = "Стоимость заказа: " + string.Format("{0:C2}", TotalCost);
|
|
|
|
+ CartList.ItemsSource = Products.ToList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void CreateOrder(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ Random random = new Random();
|
|
|
|
+ Order newOrder = new Order();
|
|
|
|
+ newOrder.OrderCreateDate = DateTime.Now;
|
|
|
|
+ bool ThreeOrLess = false;
|
|
|
|
+ foreach (Product p in Products)
|
|
|
|
+ {
|
|
|
|
+ if (p.ProductQuantityInStock <= 3)
|
|
|
|
+ {
|
|
|
|
+ ThreeOrLess = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (ThreeOrLess)
|
|
|
|
+ {
|
|
|
|
+ newOrder.OrderDeliveryDate = DateTime.Now.AddDays(6);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ newOrder.OrderDeliveryDate = DateTime.Now.AddDays(3);
|
|
|
|
+ }
|
|
|
|
+ newOrder.OrderPickupPoint = random.Next(1, 36);
|
|
|
|
+ newOrder.OrderReceivingCode = random.Next(100, 999);
|
|
|
|
+ newOrder.OrderStatus = 1;
|
|
|
|
+ DB.Order.Add(newOrder);
|
|
|
|
+ //DB.SaveChanges();
|
|
|
|
+ int id = DB.Order.Where(x => x.OrderCreateDate == newOrder.OrderCreateDate).Select(x => x.OrderID).FirstOrDefault();
|
|
|
|
+ foreach (Product p in Products)
|
|
|
|
+ {
|
|
|
|
+ OrderProduct newOrderProduct = new OrderProduct();
|
|
|
|
+ newOrderProduct.OrderID = id;
|
|
|
|
+ newOrderProduct.ProductArticleNumber = p.ProductArticleNumber;
|
|
|
|
+ newOrderProduct.ProductAmount = AmountProduct.Where(x => x.Article == p.ProductArticleNumber).Select(x => x.Amount).FirstOrDefault();
|
|
|
|
+ DB.OrderProduct.Add(newOrderProduct);
|
|
|
|
+ }
|
|
|
|
+ DB.SaveChanges();
|
|
|
|
+ MessageBox.Show("Заказ был сформирован, код получения: " + newOrder.OrderReceivingCode + " \nПункт выдачи находится по адресу: " +
|
|
|
|
+ DB.PickupPoints.Where(x => x.PickupID == newOrder.OrderPickupPoint).Select(x => x.PuckupAddress).FirstOrDefault() +
|
|
|
|
+ "\nЗаказ будет доставлен " + newOrder.OrderDeliveryDate.ToShortDateString());
|
|
|
|
+ Products.Clear();
|
|
|
|
+ AmountProduct.Clear();
|
|
|
|
+ this.Close();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|