PunkPC 8 miesięcy temu
rodzic
commit
f94e5809bf

+ 7 - 0
AppSkakunov/AppSkakunov.csproj

@@ -85,6 +85,9 @@
     <Compile Include="OrderStatus.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
+    <Compile Include="PagesApp\OrdersApp.xaml.cs">
+      <DependentUpon>OrdersApp.xaml</DependentUpon>
+    </Compile>
     <Compile Include="PagesApp\PageUserGuestApp.xaml.cs">
       <DependentUpon>PageUserGuestApp.xaml</DependentUpon>
     </Compile>
@@ -126,6 +129,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="PagesApp\OrdersApp.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="PagesApp\PageUserGuestApp.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 47 - 0
AppSkakunov/PagesApp/OrdersApp.xaml

@@ -0,0 +1,47 @@
+<Page x:Class="AppSkakunov.PagesApp.OrdersApp"
+      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+      xmlns:local="clr-namespace:AppSkakunov.PagesApp"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="OrdersApp">
+
+    <Grid Background="White">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="*"/>
+            <RowDefinition Height="10*"/>
+        </Grid.RowDefinitions>
+
+        <StackPanel Height="30" HorizontalAlignment="Center" Orientation="Horizontal" Grid.Row="0">
+            <Button Content="Вернутся к товарам" Click="BackToProduct"/>
+            <ComboBox SelectionChanged="SortOrFilter" Name="SortOrders" Margin="10,0,0,0" Width="150"/>
+            <ComboBox SelectionChanged="SortOrFilter" Name="FilterOrders" Margin="10,0,0,0" Width="150"/>
+        </StackPanel>
+
+        <ListView Grid.Row="1" Name="OrderList" d:ItemsSource="{d:SampleData ItemCount=5}">
+            <ListView.ItemsPanel>
+                <ItemsPanelTemplate>
+                    <WrapPanel Orientation="Vertical" HorizontalAlignment="Center"/>
+                </ItemsPanelTemplate>
+            </ListView.ItemsPanel>
+            <ListView.ItemTemplate>
+                <DataTemplate>
+                    <Border Uid="{Binding OrderID}" Loaded="BgrLoad" Width="800" Height="200"  BorderThickness="1" BorderBrush="Black">
+                        <StackPanel>
+                            <TextBlock Text="{Binding StringFormat=Номер заказа: {0}, Path=OrderID}"/>
+                            <TextBlock Text="{Binding StringFormat=Дата оформления: {0}, Path=OrderCreateDate}"/>
+                            <TextBlock Text="{Binding  StringFormat=Дата доставки: {0}, Path=OrderDeliveryDate}"/>
+                            <TextBlock Text="Состав заказа: " FontWeight="Bold"/>
+                            <TextBlock Uid="{Binding OrderID}" Loaded="WhatInOrder"/>
+                            <TextBlock Uid="{Binding OrderID}" Loaded="TotalPromo"/>
+                            <TextBlock Uid="{Binding OrderID}" Loaded="OrderCost"/>
+                        </StackPanel>
+                    </Border>
+                </DataTemplate>
+            </ListView.ItemTemplate>
+        </ListView>
+    </Grid>
+</Page>
+

+ 173 - 0
AppSkakunov/PagesApp/OrdersApp.xaml.cs

@@ -0,0 +1,173 @@
+using System;
+using System.Collections.Generic;
+using System.Data.SqlClient;
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace AppSkakunov.PagesApp
+{
+    /// <summary>
+    /// Логика взаимодействия для OrdersApp.xaml
+    /// </summary>
+    public partial class OrdersApp : Page
+    {
+        TradeSKakunovEntities DB = new TradeSKakunovEntities();
+        int id;
+        public OrdersApp(int id)
+        {
+            InitializeComponent();
+            OrderList.ItemsSource = DB.Order.ToList();
+            SortOrders.ItemsSource = new List<string>() { "Без сортировки", "По возрастанию цены", "По убыванию цены" };
+            FilterOrders.ItemsSource = new List<string>() { "Без фильтрации", "Скидка 0%-10%", "Скидка 10%-15%", "Скидка более 15%" };
+            SortOrders.SelectedIndex = 0;
+            FilterOrders.SelectedIndex = 0;
+            this.id = id;
+        }
+
+        private void WhatInOrder(object sender, RoutedEventArgs e)
+        {
+            TextBlock tb = (TextBlock)sender;
+            int id = Convert.ToInt32(tb.Uid);
+            string WhatIn = "";
+            foreach (OrderProduct op in DB.OrderProduct)
+            {
+                if (op.OrderID == id)
+                {
+                    WhatIn += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductName).FirstOrDefault() + " ";
+                    WhatIn += op.ProductAmount + " " + DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.UnitsOfMeasurement.UnitName).FirstOrDefault() + "\n";
+                }
+            }
+            tb.Text = WhatIn;
+        }
+        private void OrderCost(object sender, RoutedEventArgs e)
+        {
+            TextBlock tb = (TextBlock)sender;
+            int id = Convert.ToInt32(tb.Uid);
+            decimal? TotalCost = 0;
+            foreach (OrderProduct op in DB.OrderProduct)
+            {
+                if (op.OrderID == id)
+                {
+                    TotalCost += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductCost).FirstOrDefault() *
+                        op.ProductAmount;
+                }
+            }
+            tb.Text = "Стоимость заказа: " + string.Format("{0:C2}", TotalCost);
+        }
+
+        private void TotalPromo(object sender, RoutedEventArgs e)
+        {
+            TextBlock tb = (TextBlock)sender;
+            int id = Convert.ToInt32(tb.Uid);
+            int? Promo = 0;
+            foreach (OrderProduct op in DB.OrderProduct)
+            {
+                if (op.OrderID == id)
+                {
+                    Promo += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductMaxDiscountAmount).FirstOrDefault();
+                }
+            }
+            tb.Text = "Общая скидка составляет: " + Promo.ToString() + "%";
+        }
+
+        private void BgrLoad(object sender, RoutedEventArgs e)
+        {
+            Border br = (Border)sender;
+            int id = Convert.ToInt32(br.Uid);
+            Product pr = DB.OrderProduct.Where(x => x.OrderID == id).Select(x => x.Product).FirstOrDefault();
+            if (pr.ProductQuantityInStock > 3)
+            {
+                br.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#bbbbbb");
+            }
+            if (pr.ProductQuantityInStock == 0)
+            {
+                br.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#140f0b");
+            }
+        }
+
+        public void Filter()
+        {
+            List<Order> UpdateOrders = DB.Order.ToList();
+            if (SortOrders.SelectedIndex != 0)
+            {
+                decimal? TotalCost = 0;
+                foreach (Order or in UpdateOrders)
+                {
+                    TotalCost = 0;
+                    foreach (OrderProduct op in DB.OrderProduct)
+                    {
+                        if (op.OrderID == or.OrderID)
+                        {
+                            TotalCost += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductCost).FirstOrDefault() *
+                                op.ProductAmount;
+                        }
+                    }
+                    or.OrderReceivingCode = Convert.ToInt32(TotalCost);
+                }
+                switch (SortOrders.SelectedIndex)
+                {
+                    case 1:
+                        UpdateOrders = UpdateOrders.OrderBy(x => x.OrderReceivingCode).ToList();
+                        break;
+                    case 2:
+                        UpdateOrders = UpdateOrders.OrderByDescending(x => x.OrderReceivingCode).ToList();
+                        break;
+                    default:
+                        break;
+                }
+            }
+
+            if (FilterOrders.SelectedIndex != 0)
+            {
+                int? TotalPromo = 0;
+                foreach (Order or in UpdateOrders)
+                {
+                    TotalPromo = 0;
+                    foreach (OrderProduct op in DB.OrderProduct)
+                    {
+                        if (op.OrderID == or.OrderID)
+                        {
+                            TotalPromo += DB.Product.Where(x => x.ProductArticleNumber == op.ProductArticleNumber).Select(x => x.ProductMaxDiscountAmount).FirstOrDefault();
+                        }
+                    }
+                    or.OrderPickupPoint = Convert.ToInt32(TotalPromo);
+                }
+                switch (FilterOrders.SelectedIndex)
+                {
+                    case 1:
+                        UpdateOrders = UpdateOrders.Where(x => x.OrderPickupPoint >= 0 && x.OrderPickupPoint < 10).ToList();
+                        break;
+                    case 2:
+                        UpdateOrders = UpdateOrders.Where(x => x.OrderPickupPoint >= 10 && x.OrderPickupPoint < 15).ToList();
+                        break;
+                    case 3:
+                        UpdateOrders = UpdateOrders.Where(x => x.OrderPickupPoint >= 15).ToList();
+                        break;
+                    default:
+                        break;
+                }
+            }
+            OrderList.ItemsSource = UpdateOrders;
+        }
+
+        private void SortOrFilter(object sender, SelectionChangedEventArgs e)
+        {
+            Filter();
+        }
+
+        private void BackToProduct(object sender, RoutedEventArgs e)
+        {
+            MainFrame.mFrame.Navigate(new PageUserGuestApp(id));
+        }
+    }
+}

+ 13 - 6
AppSkakunov/PagesApp/PageUserGuestApp.xaml

@@ -15,7 +15,8 @@
             <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
         <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
-            <Button Height="30" Click="CartGo" Name="ToCart" Content="Корзина" Visibility="Hidden"/>
+            <Button Height="30" Click="BackToAuth" Content="Выйти"/>
+            <Button Margin="20,0,0,0" Height="30" Click="CartGo" Name="ToCart" Content="Корзина"/>
             <ComboBox SelectionChanged="SortFilterChanged" Name="SortByName" Height="30" Margin="10,0,0,0" Width="200"/>
             <ComboBox SelectionChanged="SortFilterChanged" Name="FilterByPromo" Height="30" Margin="10,0,0,0"  Width="200"/>
             <TextBox VerticalContentAlignment="Center" TextChanged="SearchChanged" Name="SearchByName" Height="30" TextAlignment="Center"  Margin="10,0,0,0"  Width="200"/>
@@ -59,10 +60,16 @@
             </ListView.ItemTemplate>
         </ListView>
 
-        <StackPanel Name="ButtonsForAdmin" Visibility="Hidden" HorizontalAlignment="Center" Orientation="Horizontal" Grid.Row="2">
-            <Button Width="70" Height="30" Content="Добавить"/>
-            <Button Margin="10,0,0,0" Height="30" Width="90" Content="Редактировать"/>
-            <Button Margin="10,0,0,0" Height="30" Width="70" Content="Удалить"/>
+        <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Grid.Row="2">
+            <StackPanel Name="ButtonsForAdmin" Visibility="Hidden" HorizontalAlignment="Center" Orientation="Horizontal" Grid.Row="2">
+                <Button Width="70" Height="30" Content="Добавить"/>
+                <Button Margin="10,0,0,0" Height="30" Width="90" Content="Редактировать"/>
+                <Button Margin="10,0,0,0" Height="30" Width="70" Content="Удалить"/>
+            </StackPanel>
+
+            <StackPanel Margin="10,0,0,0" Name="ViewOrder" HorizontalAlignment="Center" Orientation="Horizontal" Grid.Row="2">
+                <Button Width="150" Height="30" Click="ViewOrders" Content="Посмотреть заказы"/>
+            </StackPanel>
         </StackPanel>
     </Grid>
-</Page>
+</Page>

+ 33 - 6
AppSkakunov/PagesApp/PageUserGuestApp.xaml.cs

@@ -25,15 +25,18 @@ namespace AppSkakunov.PagesApp
     public partial class PageUserGuestApp : Page
     {
         TradeSKakunovEntities DB = new TradeSKakunovEntities();
-
+        int AllData;
+        int id;
         public PageUserGuestApp()
         {
             InitializeComponent();
             ProductList.ItemsSource = DB.Product.ToList();
-            FilterByPromo.ItemsSource = new List<string>() { "Все", "Скаидка 0-9,99%", "Скидка 10-14,99%", "Скидка 15% и более" };
+            FilterByPromo.ItemsSource = new List<string>() { "Все", "Скидка 0-9,99%", "Скидка 10-14,99%", "Скидка 15% и более" };
             SortByName.ItemsSource = new List<string>() { "Без сортировки", "По имени А-Я", "По имени Я-А" };
             SortByName.SelectedIndex = 0;
             FilterByPromo.SelectedIndex = 0;
+            AllData = ProductList.Items.Count;
+            AmountOfData.Text = AllData + " из " + "30" + " товаров";
         }
 
         public PageUserGuestApp(int id)
@@ -44,11 +47,17 @@ namespace AppSkakunov.PagesApp
             if (user.UserRole == 1)
             {
                 ButtonsForAdmin.Visibility = Visibility.Visible;
+                ViewOrder.Visibility = Visibility.Visible;
+            }
+            if (user.UserRole == 3)
+            {
+                ViewOrder.Visibility = Visibility.Visible;
             }
             FilterByPromo.ItemsSource = new List<string>() { "Все", "Скидка 0-9,99%", "Скидка 10-14,99%", "Скидка 15% и более" };
             SortByName.ItemsSource = new List<string>() { "Без сортировки", "По имени А-Я", "По имени Я-А" };
             SortByName.SelectedIndex = 0;
             FilterByPromo.SelectedIndex = 0;
+            this.id = id;
         }
 
         public void BackgroundLoad(object sender, RoutedEventArgs e)
@@ -58,7 +67,7 @@ namespace AppSkakunov.PagesApp
             Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
             if (pr.ProductMaxDiscountAmount > 15)
             {
-                bgr.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#7fff00");
+                bgr.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#66ff00");
             }
         }
 
@@ -133,9 +142,10 @@ namespace AppSkakunov.PagesApp
             }
             if (!string.IsNullOrEmpty(SearchByName.Text))
             {
-                products = products.Where(x => x.ProductName.Contains(FilterByPromo.Text)).ToList();
+                products = products.Where(x => x.ProductName.ToUpper().Contains(SearchByName.Text.ToUpper())).ToList();
             }
             ProductList.ItemsSource = products;
+            AmountOfData.Text = products.Count() + " из " + "30" + " товаров";
         }
 
         private void SortFilterChanged(object sender, SelectionChangedEventArgs e)
@@ -147,6 +157,7 @@ namespace AppSkakunov.PagesApp
         {
             Filter();
         }
+
         private void CartAdd(object sender, RoutedEventArgs e)
         {
             MenuItem bt = (MenuItem)sender;
@@ -175,10 +186,26 @@ namespace AppSkakunov.PagesApp
         private void CartGo(object sender, RoutedEventArgs e)
         {
             ShoppingBasketApp ct = new ShoppingBasketApp();
-            ct.ShowDialog();
+            if (ShoppingBasketApp.Products.Count > 0)
+            {
+                ct.ShowDialog();
+            }
+            else
+            {
+                MessageBox.Show("Вы не можете перейти в пустую корзину");
+            }
+        }
+
+        private void ViewOrders(object sender, RoutedEventArgs e)
+        {
+            MainFrame.mFrame.Navigate(new OrdersApp(id));
+        }
+
+        private void BackToAuth(object sender, RoutedEventArgs e)
+        {
+            MainFrame.mFrame.Navigate(new Authorization());
         }
     }
 
 }
 
-

+ 7 - 6
AppSkakunov/WindowsApp/ShoppingBasketApp.xaml.cs

@@ -53,7 +53,7 @@ namespace AppSkakunov.WindowsApp
             Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
             if (pr.ProductMaxDiscountAmount > 0)
             {
-                tb.Text = "Цена за единицу: " + string.Format("{0:C2}", pr.ProductCost - (pr.ProductCost / 100 * pr.ProductMaxDiscountAmount));
+                tb.Text = "Цена за единицу товара: " + string.Format("{0:C2}", pr.ProductCost - (pr.ProductCost / 100 * pr.ProductMaxDiscountAmount));
             }
         }
 
@@ -112,7 +112,7 @@ namespace AppSkakunov.WindowsApp
             {
                 TotalCost += (p.ProductCost - (p.ProductCost / 100 * p.ProductMaxDiscountAmount)) * ProductsApp.Where(x => x.Article == p.ProductArticleNumber).Select(x => x.Amount).First();
             }
-            CostOrder.Text = "Стоимость заказа: " + string.Format("{0:C2}", TotalCost);
+            CostOrder.Text = "Стоимость заказа составляет: " + string.Format("{0:C2}", TotalCost);
             CartList.ItemsSource = Products.ToList();
         }
 
@@ -133,7 +133,7 @@ namespace AppSkakunov.WindowsApp
                 TotalCost += (p.ProductCost - (p.ProductCost / 100 * p.ProductMaxDiscountAmount)) * ProductsApp.Where(x => x.Article == p.ProductArticleNumber).Select(x => x.Amount).First();
 
             }
-            CostOrder.Text = "Стоимость заказа: " + string.Format("{0:C2}", TotalCost);
+            CostOrder.Text = "Стоимость заказа составляет: " + string.Format("{0:C2}", TotalCost);
             CartList.ItemsSource = Products.ToList();
         }
 
@@ -154,7 +154,7 @@ namespace AppSkakunov.WindowsApp
             {
                 TotalCost += (p.ProductCost - (p.ProductCost / 100 * p.ProductMaxDiscountAmount)) * ProductsApp.Where(x => x.Article == p.ProductArticleNumber).Select(x => x.Amount).First();
             }
-            CostOrder.Text = "Стоимость заказа: " + string.Format("{0:C2}", TotalCost);
+            CostOrder.Text = "Стоимость заказа составляет: " + string.Format("{0:C2}", TotalCost);
             CartList.ItemsSource = Products.ToList();
         }
 
@@ -194,8 +194,9 @@ namespace AppSkakunov.WindowsApp
                 DB.OrderProduct.Add(newOrderProduct);
             }
             DB.SaveChanges();
-            MessageBox.Show("Заказ был сформирован, код получения: " + newOrder.OrderReceivingCode + " \nПункт выдачи находится по адресу: " +
-                DB.PickupPoints.Where(x => x.PickupID == newOrder.OrderPickupPoint).Select(x => x.PuckupAddress).FirstOrDefault());
+            MessageBox.Show("Заказ был оформлен, код получения: " + newOrder.OrderReceivingCode + " \nАдрес пункта выдачи: " +
+                        DB.PickupPoints.Where(x => x.PickupID == newOrder.OrderPickupPoint).Select(x => x.PuckupAddress).FirstOrDefault() +
+                        "\nЗаказ будет доставлен " + newOrder.OrderDeliveryDate.ToShortDateString());
         }
     }