|
@@ -14,18 +14,26 @@ namespace Sessioa.Pages
|
|
|
public partial class OrderCard : Page
|
|
|
{
|
|
|
List<Product> products = (List<Product>)Application.Current.Properties["ListOrderUser"];
|
|
|
+ List<PointsOfIssue> points = BaseClass.C_Base.PointsOfIssue.ToList();
|
|
|
+ List<StatusOrder> statesOrder = BaseClass.C_Base.StatusOrder.ToList();
|
|
|
Dictionary<string, int> keyValuePairs = (Dictionary<string, int>)(Application.Current.Properties["ListOrderCountUser"]);
|
|
|
User user = null;
|
|
|
+ Order orderEdit = null;
|
|
|
+ bool state = false;
|
|
|
public OrderCard(User userSign)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
user = userSign;
|
|
|
LB_ProductsOrder.ItemsSource = products;
|
|
|
- if (keyValuePairs.Count == 0)
|
|
|
+ OrderTitle.Text = $"Заказ #{BaseClass.C_Base.Order.OrderByDescending(x => x.OrderID).First().OrderID + 1}";
|
|
|
+ if (keyValuePairs != null)
|
|
|
{
|
|
|
- foreach (Product product in products)
|
|
|
+ if (keyValuePairs.Count == 0)
|
|
|
{
|
|
|
- keyValuePairs.Add($"{product.ProductArticleNumber}", 1);
|
|
|
+ foreach (Product product in products)
|
|
|
+ {
|
|
|
+ keyValuePairs.Add($"{product.ProductArticleNumber}", 1);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -39,12 +47,50 @@ namespace Sessioa.Pages
|
|
|
catch { }
|
|
|
}
|
|
|
}
|
|
|
- CB_Punkt.ItemsSource = BaseClass.C_Base.PointsOfIssue.ToList();
|
|
|
+ CB_Punkt.ItemsSource = points;
|
|
|
CB_Punkt.DisplayMemberPath = "PointName";
|
|
|
CB_Punkt.SelectedValuePath = "PointID";
|
|
|
ItogoSkidka();
|
|
|
}
|
|
|
+ public OrderCard(User userSign, int order_ID)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ state = true;
|
|
|
+ user = userSign;
|
|
|
+ if (user.UserRole < 2)
|
|
|
+ {
|
|
|
+ B_Save.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+ orderEdit = BaseClass.C_Base.Order.FirstOrDefault(x => x.OrderID == order_ID);
|
|
|
+ OrderTitle.Text = $"Заказ #{orderEdit.OrderID}";
|
|
|
+ if (orderEdit != null)
|
|
|
+ {
|
|
|
+ foreach (OrderProduct op in BaseClass.C_Base.OrderProduct.Where(x => x.OrderID == orderEdit.OrderID).ToList())
|
|
|
+ {
|
|
|
+ products.Add(op.Product);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ keyValuePairs.Add($"{op.Product.ProductArticleNumber}", op.ProductCount);
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LB_ProductsOrder.ItemsSource = products;
|
|
|
+ B_Save.Content = "Сохранить";
|
|
|
+ CB_Punkt.Visibility = Visibility.Collapsed;
|
|
|
+ TB_Punkt.Visibility = Visibility.Visible;
|
|
|
+ TB_Punkt.Text = $"{points[orderEdit.OrderPickupPoint - 1].PointName}";
|
|
|
|
|
|
+ StateOrder.ItemsSource = statesOrder;
|
|
|
+ StateOrder.DisplayMemberPath = "StatusTitle";
|
|
|
+ StateOrder.SelectedValuePath = "StatusId";
|
|
|
+ StateOrder.SelectedItem = statesOrder[BaseClass.C_Base.Order.FirstOrDefault(x => x.OrderID == order_ID).OrderStatus - 1];
|
|
|
+
|
|
|
+ if (orderEdit.OrderDeliveryDate != null)
|
|
|
+ DP_Order.SelectedDate = orderEdit.OrderDeliveryDate;
|
|
|
+ OrderCode.Text = $"Код выдачи: {orderEdit.IssueCode}";
|
|
|
+ ItogoSkidka();
|
|
|
+ }
|
|
|
private void countPr_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
TextBlock textBlock = (TextBlock)sender;
|
|
@@ -77,53 +123,74 @@ namespace Sessioa.Pages
|
|
|
|
|
|
private void B_Back_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- Application.Current.Properties["ListOrderCountUser"] = keyValuePairs;
|
|
|
- FrameClass.C_Frame.Navigate(new ProductsPage(user));
|
|
|
+ if (state == false)
|
|
|
+ {
|
|
|
+ Application.Current.Properties["ListOrderCountUser"] = keyValuePairs;
|
|
|
+ FrameClass.C_Frame.Navigate(new ProductsPage(user));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Application.Current.Properties["ListOrderCountUser"] = new Dictionary<string, int>();
|
|
|
+ Application.Current.Properties["ListOrderUser"] = new List<Product>();
|
|
|
+ FrameClass.C_Frame.Navigate(new OrderNew(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>();
|
|
|
- if(CB_Punkt.SelectedIndex == -1)
|
|
|
- MessageBox.Show("Выберите пункт выдачи.", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
- else
|
|
|
+ if (state == false)
|
|
|
{
|
|
|
- try
|
|
|
+ Application.Current.Properties["ListOrderUser"] = new List<Product>();
|
|
|
+ Application.Current.Properties["ListOrderCountUser"] = new Dictionary<string, int>();
|
|
|
+ if (CB_Punkt.SelectedIndex == -1)
|
|
|
+ MessageBox.Show("Выберите пункт выдачи.", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ else
|
|
|
{
|
|
|
- Random rnd = new Random();
|
|
|
- int code = rnd.Next(100, 999);
|
|
|
- Order newOrder = new Order()
|
|
|
- {
|
|
|
- //OrderID = BaseClass.C_Base.Order.OrderByDescending(x => x.OrderID).FirstOrDefault().OrderID + 1,
|
|
|
- OrderStatus = 2,
|
|
|
- OrderDate = DateTime.Now,
|
|
|
- OrderPickupPoint = ((PointsOfIssue)CB_Punkt.SelectedItem).PointID,
|
|
|
- UserID = user.UserID,
|
|
|
- IssueCode = code
|
|
|
- };
|
|
|
- BaseClass.C_Base.Order.Add(newOrder);
|
|
|
- BaseClass.C_Base.SaveChanges();
|
|
|
- foreach (KeyValuePair<string, int> pair in keyValuePairs)
|
|
|
+ try
|
|
|
{
|
|
|
- OrderProduct op = new OrderProduct()
|
|
|
+ Random rnd = new Random();
|
|
|
+ int code = rnd.Next(100, 999);
|
|
|
+ Order newOrder = new Order()
|
|
|
{
|
|
|
- OrderID = newOrder.OrderID,
|
|
|
- ProductArticleNumber = pair.Key,
|
|
|
- ProductCount = pair.Value
|
|
|
+ //OrderID = BaseClass.C_Base.Order.OrderByDescending(x => x.OrderID).FirstOrDefault().OrderID + 1,
|
|
|
+ OrderStatus = 2,
|
|
|
+ OrderDate = DateTime.Now,
|
|
|
+ OrderPickupPoint = ((PointsOfIssue)CB_Punkt.SelectedItem).PointID,
|
|
|
+ UserID = user.UserID,
|
|
|
+ IssueCode = code
|
|
|
};
|
|
|
- BaseClass.C_Base.OrderProduct.Add(op);
|
|
|
+ BaseClass.C_Base.Order.Add(newOrder);
|
|
|
+ BaseClass.C_Base.SaveChanges();
|
|
|
+ foreach (KeyValuePair<string, int> pair in keyValuePairs)
|
|
|
+ {
|
|
|
+ OrderProduct op = new OrderProduct()
|
|
|
+ {
|
|
|
+ OrderID = newOrder.OrderID,
|
|
|
+ ProductArticleNumber = pair.Key,
|
|
|
+ ProductCount = pair.Value
|
|
|
+ };
|
|
|
+ BaseClass.C_Base.OrderProduct.Add(op);
|
|
|
+ }
|
|
|
+ BaseClass.C_Base.SaveChanges();
|
|
|
+ MessageBoxResult res = MessageBox.Show($"Заказ оформлен. Код для выдачи: {code}. Отследить заказ можно в разделе \"Заказы\" на странице товаров.", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ if (res == MessageBoxResult.OK)
|
|
|
+ FrameClass.C_Frame.Navigate(new ProductsPage(user));
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ MessageBoxResult res = MessageBox.Show("что-то сломалось.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
}
|
|
|
- BaseClass.C_Base.SaveChanges();
|
|
|
- MessageBoxResult res = MessageBox.Show($"Заказ оформлен. Код для выдачи: {code}. Отследить заказ можно в разделе \"Мои заказы\" на странице продуктов.", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
- if (res == MessageBoxResult.OK)
|
|
|
- FrameClass.C_Frame.Navigate(new ProductsPage(user));
|
|
|
- }
|
|
|
- catch
|
|
|
- {
|
|
|
- MessageBoxResult res = MessageBox.Show("что-то сломалось.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ orderEdit.OrderStatus = ((StatusOrder)StateOrder.SelectedItem).StatusId;
|
|
|
+ if (DP_Order.SelectedDate != null)
|
|
|
+ orderEdit.OrderDeliveryDate = DP_Order.SelectedDate;
|
|
|
+ BaseClass.C_Base.SaveChanges();
|
|
|
+ MessageBoxResult res = MessageBox.Show("Изменения внесены.", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ FrameClass.C_Frame.Navigate(new OrderNew(user));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void Back_B_Click(object sender, RoutedEventArgs e)
|
|
@@ -189,11 +256,11 @@ namespace Sessioa.Pages
|
|
|
public void ItogoSkidka()
|
|
|
{
|
|
|
decimal itogoBezSkidki = 0;
|
|
|
- foreach(Product item in products)
|
|
|
+ foreach (Product item in products)
|
|
|
{
|
|
|
- foreach(KeyValuePair<string, int> pair in keyValuePairs)
|
|
|
+ foreach (KeyValuePair<string, int> pair in keyValuePairs)
|
|
|
{
|
|
|
- if(pair.Key == item.ProductArticleNumber)
|
|
|
+ if (pair.Key == item.ProductArticleNumber)
|
|
|
{
|
|
|
itogoBezSkidki += item.ProductCost * pair.Value;
|
|
|
}
|
|
@@ -206,7 +273,7 @@ namespace Sessioa.Pages
|
|
|
{
|
|
|
if (pair.Key == item.ProductArticleNumber)
|
|
|
{
|
|
|
- if(item.ProductDiscountAmount != null)
|
|
|
+ if (item.ProductDiscountAmount != null)
|
|
|
{
|
|
|
itogoSoSkidkoy += (item.ProductCost - (item.ProductCost * ((decimal)item.ProductDiscountAmount / 100))) * pair.Value;
|
|
|
}
|
|
@@ -219,5 +286,49 @@ namespace Sessioa.Pages
|
|
|
TB_ItogoSkidka.Text = $"Скидка {ITOGO}%";
|
|
|
TB_Itogo.Text = $"{(double)itogoSoSkidkoy} ₽";
|
|
|
}
|
|
|
+
|
|
|
+ private void SP_EditOrder_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ StackPanel sp = (StackPanel)sender;
|
|
|
+ if (state == false || user.UserRole < 2)
|
|
|
+ sp.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Back_B_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Button btn = (Button)sender;
|
|
|
+ if (state == true)
|
|
|
+ btn.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Next_B_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Button btn = (Button)sender;
|
|
|
+ if (state == true)
|
|
|
+ btn.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OrderCode_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ TextBlock tb = (TextBlock)sender;
|
|
|
+ if (state == false)
|
|
|
+ tb.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DelProduct_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ foreach(KeyValuePair<string, int> item in keyValuePairs)
|
|
|
+ {
|
|
|
+ Product tmp = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == ((Product)LB_ProductsOrder.SelectedItem).ProductArticleNumber);
|
|
|
+ if(item.Key == tmp.ProductArticleNumber)
|
|
|
+ {
|
|
|
+ keyValuePairs.Remove(item.Key);
|
|
|
+ products.Remove(tmp);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LB_ProductsOrder.ItemsSource = null;
|
|
|
+ LB_ProductsOrder.ItemsSource = products;
|
|
|
+ }
|
|
|
}
|
|
|
}
|