Переглянути джерело

Сделан макет заказа и заготовка для сортировки

ВоробьевКЕ 7 місяців тому
батько
коміт
86a44e1fd1

+ 2 - 0
OOO_WriteAndClear/DBModels/OrderPartialClass.cs

@@ -15,5 +15,7 @@ namespace OOO_WriteAndClear.DBModels
             OrderProducts.Sum(a => a.ProductArticleNumberNavigation.ProductCost * a.ProductAmount);
 
         public decimal OrderDiscount => OrderCostWithoutDiscount - OrderCost;
+
+        public decimal OrderDiscountPercent => 1 - (OrderCost / OrderCostWithoutDiscount);
     }
 }

+ 8 - 0
OOO_WriteAndClear/DBModels/OrderProductPartialClass.cs

@@ -8,6 +8,14 @@ namespace OOO_WriteAndClear.DBModels
 {
     public partial class OrderProduct : ICloneable
     {
+        public decimal Price => 
+            ProductArticleNumberNavigation.CurrentPrice 
+            * ProductAmount;
+
+        public decimal PriceWithoutDiscount => 
+            ProductArticleNumberNavigation.ProductCost 
+            * ProductAmount;
+
         public object Clone()
         {
             return MemberwiseClone();

+ 2 - 2
OOO_WriteAndClear/DBModels/VorobiewTradeContext.cs

@@ -39,8 +39,8 @@ public partial class VorobiewTradeContext : DbContext
 
     protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 #warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
-        => optionsBuilder.UseSqlServer("Server=ngknn.ru;Database=VorobiewTrade;user id=23П;Password=12357;Trusted_Connection=false;TrustServerCertificate=Yes;");
-    //optionsBuilder.UseSqlServer("Server=sql;Database=VorobiewTrade;user id=23П;Password=12357;Trusted_Connection=false;TrustServerCertificate=Yes;");
+        => optionsBuilder.UseSqlServer("Server=sql;Database=VorobiewTrade;user id=23П;Password=12357;Trusted_Connection=false;TrustServerCertificate=Yes;");
+    //optionsBuilder.UseSqlServer("Server=ngknn.ru;Database=VorobiewTrade;user id=23П;Password=12357;Trusted_Connection=false;TrustServerCertificate=Yes;");
 
     protected override void OnModelCreating(ModelBuilder modelBuilder)
     {

+ 33 - 0
OOO_WriteAndClear/MVP/MVPInterfaces/IOrdersUserControlContract.cs

@@ -0,0 +1,33 @@
+using OOO_WriteAndClear.DBModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OOO_WriteAndClear.MVP.MVPInterfaces
+{
+    public interface IOrdersUserControlContract
+    {
+        public interface View
+        {
+
+        }
+
+        public interface Presenter
+        {
+            ICollection<Order> Orders { get; }
+
+
+            void UpdateOrdersFromDB();
+        }
+
+        public interface Model
+        {
+            ICollection<Order> Orders { get; }
+
+
+            void UpdateOrdersFromDB();
+        }
+    }
+}

+ 41 - 0
OOO_WriteAndClear/MVP/Models/OrdersUserControlModel.cs

@@ -0,0 +1,41 @@
+using Microsoft.EntityFrameworkCore;
+using OOO_WriteAndClear.DBModels;
+using OOO_WriteAndClear.MVP.MVPInterfaces;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OOO_WriteAndClear.MVP.Models
+{
+    public class OrdersUserControlModel : IOrdersUserControlContract.Model
+    {
+        public OrdersUserControlModel() 
+        {
+            _orders = new List<Order>();
+            _ordersFromDB = new List<Order>();
+        }
+
+
+        public ICollection<Order> Orders => _orders;
+
+
+        public void UpdateOrdersFromDB()
+        {
+            using(VorobiewTradeContext db = new VorobiewTradeContext())
+            {
+                _ordersFromDB = db.Orders.Include(a => a.OrderProducts)
+                                         .ThenInclude(a => a.ProductArticleNumberNavigation)
+                                         .Include(a => a.OrderPickupPoint)
+                                         .Include(a => a.OrderStatus)
+                                         .ToList();
+            }
+            _orders = _ordersFromDB;
+        }
+
+
+        private ICollection<Order> _orders;
+        private ICollection<Order> _ordersFromDB;
+    }
+}

+ 34 - 0
OOO_WriteAndClear/MVP/Presenters/OrdersUserControlPresenter.cs

@@ -0,0 +1,34 @@
+using OOO_WriteAndClear.DBModels;
+using OOO_WriteAndClear.MVP.Models;
+using OOO_WriteAndClear.MVP.MVPInterfaces;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OOO_WriteAndClear.MVP.Presenters
+{
+    public class OrdersUserControlPresenter : IOrdersUserControlContract.Presenter
+    {
+        public OrdersUserControlPresenter(IOrdersUserControlContract.View view) 
+        {
+            _view = view;
+            _model = new OrdersUserControlModel();
+        }
+
+
+        public ICollection<Order> Orders => _model.Orders;
+
+
+        public void UpdateOrdersFromDB()
+        {
+            _model.UpdateOrdersFromDB();
+        }
+
+
+        private IOrdersUserControlContract.View _view;
+
+        private IOrdersUserControlContract.Model _model;
+    }
+}

+ 114 - 7
OOO_WriteAndClear/MVP/Views/OrdersUserControl.xaml

@@ -4,9 +4,11 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:OOO_WriteAndClear.MVP.Views"
+             xmlns:db_models="clr-namespace:OOO_WriteAndClear.DBModels"
              mc:Ignorable="d" d:Background="White"
              d:DesignHeight="450" d:DesignWidth="800"
-             FontFamily="Comic Sans MS">
+             FontFamily="Comic Sans MS"
+             Loaded="OrdersUserControlLoaded">
 
     <UserControl.Resources>
         
@@ -25,7 +27,110 @@
                 </Setter.Value>
             </Setter>
         </Style>
-        
+
+        <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 OrderStatus.OrderStatusName, StringFormat=Статус: {0}}"/>
+
+                                    <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>
+
     </UserControl.Resources>
     
     <Border Padding="10">
@@ -84,20 +189,22 @@
 
                     <GroupBox Margin="0 0 10 0"
                               Header="Фильтрация по суммарной скидке">
-                        <ComboBox x:Name="FilterComboBox"
-                                  />
+                        <ComboBox x:Name="FilterComboBox"/>
                     </GroupBox>
 
                     <GroupBox Header="Сортировка по цене">
-                        <ComboBox x:Name="SortComboBox"
-                                  />
+                        <ComboBox x:Name="SortComboBox"/>
                     </GroupBox>
 
                 </StackPanel>
 
             </Grid>
 
-            <ListView Grid.Row="2"/>
+            <ListView x:Name="OrderListView"
+                      Grid.Row="2"
+                      HorizontalContentAlignment="Stretch"
+                      Style="{StaticResource OrdersListViewStyle}"
+                      d:ItemsSource="{d:SampleData ItemCount=5}"/>
 
         </Grid>
     </Border>

+ 53 - 1
OOO_WriteAndClear/MVP/Views/OrdersUserControl.xaml.cs

@@ -1,5 +1,8 @@
 using OOO_WriteAndClear.DBModels;
 using OOO_WriteAndClear.EventBus.Signals;
+using OOO_WriteAndClear.MVP.Models.ProductsUserControlModel;
+using OOO_WriteAndClear.MVP.MVPInterfaces;
+using OOO_WriteAndClear.MVP.Presenters;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -20,11 +23,12 @@ namespace OOO_WriteAndClear.MVP.Views
     /// <summary>
     /// Логика взаимодействия для OrdersUserControl.xaml
     /// </summary>
-    public partial class OrdersUserControl : UserControl
+    public partial class OrdersUserControl : UserControl, IOrdersUserControlContract.View
     {
         public OrdersUserControl()
         {
             InitializeComponent();
+            _presenter = new OrdersUserControlPresenter(this);
             SetUserData();
         }
 
@@ -42,5 +46,53 @@ namespace OOO_WriteAndClear.MVP.Views
                 + user.UserPatronymic;
             DisplayingUserRole.Text = user.UserRoleNavigation.RoleName;
         }
+
+        private void OrdersUserControlLoaded(object sender, RoutedEventArgs e)
+        {
+            UpdateOrdersListView();
+            SetFilterComboBox();
+            SetSortingComboBox();
+        }
+
+        private void UpdateOrdersListView()
+        {
+            Task.Run(() =>
+            {
+                _presenter.UpdateOrdersFromDB();
+                Dispatcher.BeginInvoke(new Action(() =>
+                {
+                    OrderListView.ItemsSource = _presenter.Orders;
+                }));
+            });
+        }
+
+        private void SetFilterComboBox()
+        {
+            FilterComboBox.ItemsSource = Filters;
+            FilterComboBox.SelectedIndex = 0;
+        }
+
+        private void SetSortingComboBox()
+        {
+            SortComboBox.ItemsSource = SortingVarients;
+            SortComboBox.SelectedIndex = 0;
+        }
+
+
+        private List<FilterByDiscountParameters> Filters = new List<FilterByDiscountParameters>()
+        {
+            new FilterByDiscountParameters(0, 100),
+            new FilterByDiscountParameters(0, 10),
+            new FilterByDiscountParameters(10, 15),
+            new FilterByDiscountParameters(15, 100),
+        };
+
+        private List<string> SortingVarients = new List<string>()
+        {
+            "По возрастанию",
+            "По убыванию"
+        };
+
+        private IOrdersUserControlContract.Presenter _presenter;
     }
 }