1
0

2 Commits 586eb5b1ce ... 930f767ab7

Autor SHA1 Nachricht Datum
  MeseryGG 930f767ab7 Отображение чека готово vor 7 Monaten
  MeseryGG acce1dcb65 Новый заказ добавляется vor 7 Monaten

+ 21 - 0
OOO_WriteAndClear/DBModels/UserPartialClass.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OOO_WriteAndClear.DBModels
+{
+    public partial class User
+    {
+        public override string ToString()
+        {
+            return UserSurname 
+                + " " 
+                + 
+                UserName 
+                + " " 
+                + UserPatronymic;
+        }
+    }
+}

+ 11 - 0
OOO_WriteAndClear/EventBus/Signals/ShowOrderTalonSignal.cs

@@ -0,0 +1,11 @@
+using OOO_WriteAndClear.DBModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OOO_WriteAndClear.EventBus.Signals
+{
+    public record class ShowOrderTalonSignal(Order Order) : ISignal;
+}

+ 5 - 2
OOO_WriteAndClear/MVP/MVPInterfaces/IOrderCartWindowContract.cs

@@ -21,6 +21,9 @@ namespace OOO_WriteAndClear.MVP.MVPInterfaces
 
         public interface IPresenter
         {
+            Order CurrentOrder { get; }
+
+
             void SetCurrentOrderFormerer(OrderFormerer orderFormerer);
 
             void AddProductUnitIntoOrder(string productArticle);
@@ -31,7 +34,7 @@ namespace OOO_WriteAndClear.MVP.MVPInterfaces
 
             ICollection<PickupPoint> GetAllPickupPoints();
 
-            void AddOrderInSystem();
+            void AddOrderInSystem(PickupPoint selectedPickupPoint);
         }
 
         public interface IModel
@@ -47,7 +50,7 @@ namespace OOO_WriteAndClear.MVP.MVPInterfaces
 
             ICollection<PickupPoint> GetAllPickupPoints();
 
-            void AddOrderInSystem();
+            void AddOrderInSystem(PickupPoint selectedPickupPoint);
         }
     }
 }

+ 15 - 1
OOO_WriteAndClear/MVP/Models/OrderCartWindowModel.cs

@@ -1,5 +1,6 @@
 using OOO_WriteAndClear.DBModels;
 using OOO_WriteAndClear.MVP.MVPInterfaces;
+using System.Windows;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -50,8 +51,21 @@ namespace OOO_WriteAndClear.MVP.Models
             };
         }
 
-        public void AddOrderInSystem()
+        public void AddOrderInSystem(PickupPoint selectedPickupPoint)
         {
+            OrderFormerer.Order.OrderPickupPoint = selectedPickupPoint;
+            User currentUser = (User)Application.Current.Resources["CurrentUser"];
+            if (currentUser.UserId == -1)
+                OrderFormerer.Order.OrderCustomer = "";
+            else
+                OrderFormerer.Order.OrderCustomer = currentUser.ToString();
+            Order AddingOrder = OrderFormerer.PrepareOrderForAdd();
+            using (VorobiewTradeContext db = new VorobiewTradeContext())
+            {
+                db.Orders.Add(AddingOrder);
+                db.SaveChanges();
+            }
+            OrderFormerer.Order.OrderId = AddingOrder.OrderId;
         }
 
         #endregion

+ 43 - 0
OOO_WriteAndClear/MVP/Models/OrderFormerer/OrderFormerer.cs

@@ -89,6 +89,33 @@ namespace OOO_WriteAndClear.MVP.Models.OrderFormerer
             _order.OrderProducts.Where(a => a.ProductArticleNumber
             == product.ProductArticleNumber).ToList().Count > 0;
 
+        public Order PrepareOrderForAdd()
+        {
+            int DeliveryDelay = GenerateDeliveryDelay();
+            Order order = new Order()
+            {
+                OrderReceiveCode = GenerateReceiveCode(),
+                OrderCustomer = Order.OrderCustomer,
+                OrderStatusId = 1,
+                OrderCreateDate = DateTime.Now,
+                OrderDeliveryDate = DateTime.Now.AddDays(DeliveryDelay),
+                OrderPickupPointId = Order.OrderPickupPoint.PickupPointId,
+                OrderProducts = new List<OrderProduct>()
+            };
+            Order.OrderCreateDate = order.OrderCreateDate;
+            Order.OrderDeliveryDate = order.OrderDeliveryDate;
+            Order.OrderReceiveCode = order.OrderReceiveCode;
+            foreach(var OrderProduct in Order.OrderProducts)
+            {
+                order.OrderProducts.Add(new OrderProduct() 
+                { 
+                    ProductArticleNumber = OrderProduct.ProductArticleNumber,
+                    ProductAmount = OrderProduct.ProductAmount
+                });
+            }
+            return order;
+        }
+
 
         private Order _order;
 
@@ -100,5 +127,21 @@ namespace OOO_WriteAndClear.MVP.Models.OrderFormerer
         /// <returns>null - если заказа не существует; OrderProduct - если существует</returns>
         private OrderProduct? GetOrderItem(Product product) =>
             _order.OrderProducts.Where(a => a.ProductArticleNumber == product.ProductArticleNumber).FirstOrDefault();
+
+        private int GenerateReceiveCode()
+            => new Random().Next(100, 1000);
+
+        private int GenerateDeliveryDelay()
+        {
+            bool IsShortageInStock = false;
+            foreach (var product in Order.OrderProducts)
+            {
+                if(product.ProductArticleNumberNavigation.ProductQuantityInStock < 3)
+                {
+                    return 6;
+                }
+            }
+            return 3;
+        }
     }
 }

+ 5 - 2
OOO_WriteAndClear/MVP/Presenters/OrderCartWindowPresenter.cs

@@ -21,6 +21,9 @@ namespace OOO_WriteAndClear.MVP.Presenters
 
         #region Реализация IOrderCartWindowContract.IPresenter
 
+        public Order CurrentOrder => _model.OrderFormerer.Order;
+
+
         public void SetCurrentOrderFormerer(OrderFormerer orderFormerer)
         {
             _model.OrderFormerer = orderFormerer;
@@ -45,9 +48,9 @@ namespace OOO_WriteAndClear.MVP.Presenters
             UpdateOrderData(_model.OrderFormerer.Order);
         }
 
-        public void AddOrderInSystem()
+        public void AddOrderInSystem(PickupPoint selectedPickupPoint)
         {
-            _model.AddOrderInSystem();
+            _model.AddOrderInSystem(selectedPickupPoint);
         }
 
         public ICollection<PickupPoint> GetAllPickupPoints() => 

+ 6 - 0
OOO_WriteAndClear/MVP/Views/MainApplicationWindow.xaml.cs

@@ -38,6 +38,7 @@ namespace OOO_WriteAndClear.Views
             EventBus.EventBus.GetService().Subscribe<GoToProductsUserControlSignal>(GoToProductsUserControl);
             EventBus.EventBus.GetService().Subscribe<GoToOrdersUserControlSignal>(GoToOrdersUserControl);
             EventBus.EventBus.GetService().Subscribe<BackToFeaturesMenuUserControlSignal>(BackToMenuFeatures);
+            EventBus.EventBus.GetService().Subscribe<ShowOrderTalonSignal>(ShowOrderTalon);
         }
 
 
@@ -88,6 +89,11 @@ namespace OOO_WriteAndClear.Views
             _displayingUserControlManager.DisplayingUserControl = new FeaturesMenuUserControl();
         }
 
+        private void ShowOrderTalon(ShowOrderTalonSignal signal)
+        {
+            new OrderReceipt(signal.Order).ShowDialog();
+        }
+
         private void AddUserInAppResources(User user)
         {
             if (Application.Current.Resources.Contains("CurrentUser"))

+ 2 - 1
OOO_WriteAndClear/MVP/Views/OrderCartWindow.xaml

@@ -158,7 +158,8 @@
                     <GroupBox Margin="0 10 0 0"
                               Header="Пункт выдачи">
 
-                        <ComboBox x:Name="PickupPointComboBox"/>
+                        <ComboBox x:Name="PickupPointComboBox"
+                                  SelectionChanged="PickupPointComboBox_SelectionChanged"/>
 
                     </GroupBox>
 

+ 25 - 0
OOO_WriteAndClear/MVP/Views/OrderCartWindow.xaml.cs

@@ -1,4 +1,6 @@
 using OOO_WriteAndClear.DBModels;
+using OOO_WriteAndClear.EventBus;
+using OOO_WriteAndClear.EventBus.Signals;
 using OOO_WriteAndClear.MVP.Models.OrderFormerer;
 using OOO_WriteAndClear.MVP.MVPInterfaces;
 using OOO_WriteAndClear.MVP.Presenters;
@@ -146,7 +148,28 @@ namespace OOO_WriteAndClear.MVP.Views
         /// <param name="e">параметры события</param>
         private void FormOrder_ButtonClick(object sender, RoutedEventArgs e)
         {
+            if (_presenter.CurrentOrder.OrderProducts.Count == 0)
+            {
+                MessageBox.Show("Корзина пуста!", "Корзина", MessageBoxButton.OK);
+                return;
+            }
+            if (_selectedPickupPoint is null)
+            {
+                MessageBox.Show("Пункт выдачи не выбран!", "Пункт выдачи", MessageBoxButton.OK);
+                return;
+            }
+            _presenter.AddOrderInSystem(_selectedPickupPoint);
+            EventBus.EventBus.GetService().Invoke(new ShowOrderTalonSignal(_presenter.CurrentOrder));
+        }
 
+        /// <summary>
+        /// Смена пункта выдачи заказа в comboBox
+        /// </summary>
+        /// <param name="sender">ComboBox заказа</param>
+        /// <param name="e">параметры события</param>
+        private void PickupPointComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            _selectedPickupPoint = (PickupPoint)PickupPointComboBox.SelectedItem;
         }
 
         #endregion
@@ -154,6 +177,8 @@ namespace OOO_WriteAndClear.MVP.Views
 
         private IOrderCartWindowContract.IPresenter _presenter;
 
+        private PickupPoint? _selectedPickupPoint = null;
+
         private string _orderCostWithoutDiscount;
         private string _orderDiscount;
         private string _orderCostWithDiscount;

+ 134 - 0
OOO_WriteAndClear/MVP/Views/OrderReceipt.xaml

@@ -0,0 +1,134 @@
+<Window x:Class="OOO_WriteAndClear.MVP.Views.OrderReceipt"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:OOO_WriteAndClear.MVP.Views"
+        mc:Ignorable="d"
+        Title="Пиши-стирай | Талон заказа" Height="450" Width="800">
+
+    <Window.Resources>
+        
+        <Style x:Key="OrdersListViewStyle" TargetType="{x:Type ListView}">
+
+            <Setter Property="BorderThickness" Value="0"/>
+            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
+
+            <Setter Property="ItemTemplate">
+                <Setter.Value>
+                    <DataTemplate DataType="db_models:Order">
+                        <Border Padding="10"
+                        BorderThickness="1" BorderBrush="Black"
+                        CornerRadius="10">
+                            <Grid HorizontalAlignment="Stretch">
+
+                                <Grid.ColumnDefinitions>
+                                    <ColumnDefinition Width="1*"/>
+                                    <ColumnDefinition Width="1*"/>
+                                </Grid.ColumnDefinitions>
+
+                                <Grid.RowDefinitions>
+                                    <RowDefinition Height="auto"/>
+                                    <RowDefinition/>
+                                    <RowDefinition Height="auto"/>
+                                </Grid.RowDefinitions>
+
+                                <TextBlock Grid.ColumnSpan="2"
+                                   HorizontalAlignment="Center" VerticalAlignment="Top"
+                                   Text="{Binding OrderId, StringFormat=Номер заказа №{0}}" />
+
+                                <StackPanel Grid.Row="1" Grid.Column="0"
+                                    Margin="0 5 0 0"
+                                    Orientation="Vertical">
+
+                                    <TextBlock Text="{Binding OrderCustomer, StringFormat=Заказчик: {0}, TargetNullValue=NA}"/>
+
+                                    <TextBlock Text="{Binding OrderCreateDate, StringFormat=Дата создания: {0}}"/>
+
+                                    <TextBlock Text="{Binding OrderDeliveryDate, StringFormat=Дата готовности: {0}}"/>
+
+                                    <TextBlock Text="{Binding OrderPickupPoint.PickupPointAdress, StringFormat=Адресс пункта выдачи: {0}}"
+                                       TextWrapping="Wrap"/>
+
+                                    <TextBlock Text="{Binding OrderCostWithoutDiscount, StringFormat=Цена без скидки {0:f2} руб.}"/>
+
+                                    <TextBlock Text="{Binding OrderReceiveCode, StringFormat=Код получения заказа: {0}}"/>
+
+                                </StackPanel>
+
+                                <Border Grid.Column="1" Grid.Row="1"
+                                Margin="0 5 0 0">
+                                    <DataGrid 
+                                ItemsSource="{Binding OrderProducts}"
+                                IsReadOnly="True"
+                                AutoGenerateColumns="False"
+                                Background="White"
+                                CanUserResizeColumns="False">
+
+                                        <DataGrid.Columns>
+
+                                            <DataGridTextColumn Header="Количество" 
+                                                    CanUserSort="False"
+                                                    Binding="{Binding ProductAmount}"/>
+
+                                            <DataGridTextColumn Header="Артикул" 
+                                                    CanUserSort="False"
+                                                    Binding="{Binding ProductArticleNumber}"/>
+
+                                            <DataGridTextColumn Header="Продукт" 
+                                                    CanUserSort="False"
+                                                    Binding="{Binding ProductArticleNumberNavigation.ProductName}"/>
+
+                                            <DataGridTextColumn Header="Цена без скидки" 
+                                                    CanUserSort="False"
+                                                    Binding="{Binding PriceWithoutDiscount, StringFormat={}{0:f2} руб.}"/>
+
+                                            <DataGridTextColumn Header="Цена со скидкой" 
+                                                    CanUserSort="False"
+                                                    Binding="{Binding Price, StringFormat={}{0:f2} руб.}"/>
+
+                                        </DataGrid.Columns>
+
+                                    </DataGrid>
+                                </Border>
+
+                                <TextBlock Grid.Row="2" Grid.ColumnSpan="2"
+                                   HorizontalAlignment="Center"
+                                   Margin="0 5 0 0"
+                                   Text="{Binding OrderCost, StringFormat=Итог: {0:f2} руб.}"/>
+
+                                <TextBlock Grid.Row="2" Grid.ColumnSpan="2"
+                                   HorizontalAlignment="Right"
+                                   Margin="0 5 0 0"
+                                   Text="{Binding OrderDiscountPercent, StringFormat=Суммарная скидка: {0:p2}}"/>
+
+                            </Grid>
+                        </Border>
+                    </DataTemplate>
+                </Setter.Value>
+            </Setter>
+
+        </Style>
+        
+    </Window.Resources>
+    
+    <Grid>
+
+        <Grid.RowDefinitions>
+            <RowDefinition Height="auto"/>
+            <RowDefinition/>
+        </Grid.RowDefinitions>
+
+        <Label Grid.Row="0"
+               HorizontalAlignment="Center"
+               FontSize="18" FontWeight="Bold"
+               Content="Талон заказа"/>
+
+        <ListView x:Name="ConfirmedOrder"
+                  Grid.Row="1"
+                  Style="{StaticResource OrdersListViewStyle}" 
+                  d:ItemsSource="{d:SampleData ItemCount=5}"/>
+
+    </Grid>
+    
+</Window>

+ 29 - 0
OOO_WriteAndClear/MVP/Views/OrderReceipt.xaml.cs

@@ -0,0 +1,29 @@
+using OOO_WriteAndClear.DBModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace OOO_WriteAndClear.MVP.Views
+{
+    /// <summary>
+    /// Логика взаимодействия для OrderReceipt.xaml
+    /// </summary>
+    public partial class OrderReceipt : Window
+    {
+        public OrderReceipt(Order order)
+        {
+            InitializeComponent();
+            ConfirmedOrder.ItemsSource = new List<Order>() { order };
+        }
+    }
+}