lisas 7 月之前
父节点
当前提交
9d0c3d4f48

+ 0 - 0
Reks/Pages/Authorization.xaml → Reks/Pages/Autarizacia.xaml


+ 1 - 1
Reks/Pages/Authorization.xaml.cs → Reks/Pages/Autarizacia.xaml.cs

@@ -39,7 +39,7 @@ namespace Reks.Pages
                 }
                 else if (user != null && CapaFlag == true)
                 {
-                    if (CapaText.Text.ToUpper() == "A4B1".ToUpper())
+                    if (CapaText.Text.ToUpper() == "X777".ToUpper())
                     {
                         MainFrame.mFrame.Navigate(new UserGuestPage(user.UserID));
                     }

+ 20 - 14
Reks/Pages/UserGuestPage.xaml → Reks/Pages/UserBlank.xaml

@@ -14,13 +14,23 @@
             <RowDefinition Height="10*"/>
             <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
-        <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
-            <Button Click="CartGo" Name="ToCart" Content="Корзина" Visibility="Hidden"/>
-            <ComboBox SelectionChanged="SortFilterChanged" Name="SortByName" Height="30" Margin="10,0,0,0" Width="300"/>
-            <ComboBox SelectionChanged="SortFilterChanged" Name="FilterByPromo" Height="30" Margin="10,0,0,0"  Width="300"/>
-            <TextBox TextChanged="SearchChanged" Name="SearchByName" Height="30" TextAlignment="Center"  Margin="10,0,0,0"  Width="300"/>
-            <TextBlock TextAlignment="Center"  Margin="10,0,0,0"  Name="AmountOfData"/>
+        <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" >
+            <Button Height="30" Click="BackToAuth" Content="Выйти"/>
+            <Button Margin="20,0,0,0" Height="30" Click="CartGo" Name="ToCart" Content="Корзина" Visibility="Hidden"/>
+            <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"/>
+            <TextBlock VerticalAlignment="Center" TextAlignment="Center"  Margin="10,0,0,0"  Name="AmountOfData"/>
+            <StackPanel Name="ButtonsForAdmin" Visibility="Hidden" HorizontalAlignment="Center" Orientation="Horizontal" Grid.Row="2" Margin="10,0,0,0">
+                <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" Visibility="Hidden" HorizontalAlignment="Center" Orientation="Horizontal" Grid.Row="2">
+                <Button Width="150" Height="30" Click="ViewOrders" Content="заказы"/>
+            </StackPanel>
         </StackPanel>
+        
 
         <ListView Grid.Row="1" Name="ProductList" d:ItemsSource="{d:SampleData ItemCount=5}">
 
@@ -32,16 +42,16 @@
 
             <ListView.ItemTemplate>
                 <DataTemplate>
-                    <Border  Width="800" Height="200"  BorderThickness="1" BorderBrush="Black">
+                    <Border  Width="1200" Height="200"  BorderThickness="1" BorderBrush="Green">
                         <StackPanel>
                             <StackPanel.ContextMenu>
                                 <ContextMenu>
                                     <MenuItem Header="Добавить в корзину" Uid="{Binding ProductArticleNumber}" Click="CartAdd"/>
                                 </ContextMenu>
                             </StackPanel.ContextMenu>
-                            <Grid Width="795" Height="195" Loaded="BackgroundLoad" Uid="{Binding ProductArticleNumber}">
+                            <Grid Width="1200" Height="195" Loaded="BackgroundLoad" Uid="{Binding ProductArticleNumber}">
                                 <StackPanel Orientation="Horizontal">
-                                    <Image Width="200" Height="195" Grid.Column="0" Uid="{Binding ProductArticleNumber}" Loaded="Photo"/>
+                                    <Image Width="200" Height="195" Uid="{Binding ProductArticleNumber}" Loaded="Photo"/>
                                     <StackPanel Margin="10,0,0,0" Width="300" HorizontalAlignment="Center" Grid.Column="1" Orientation="Vertical">
                                         <TextBlock Text="{Binding ProductName}"/>
                                         <TextBlock Text="{Binding ProductDescription}" TextWrapping="Wrap"/>
@@ -59,10 +69,6 @@
             </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>
+       
     </Grid>
 </Page>

+ 31 - 7
Reks/Pages/UserGuestPage.xaml.cs → Reks/Pages/UserBlank.xaml.cs

@@ -24,12 +24,13 @@ namespace Reks.Pages
     {
         TradeBase DB = new TradeBase();
         int AllData;
+        int id;
         public UserGuestPage()
         {
             InitializeComponent();
             ProductList.ItemsSource = DB.Product.ToList();
-            FilterByPromo.ItemsSource = new List<string>() { "Все", "Скаидка 0-9,99%", "Скидка 10-14,99%", "Скидка 15% и более" };
-            SortByName.ItemsSource = new List<string>() { "Без сортировки", "По имени А-Я", "По имени Я-А" };
+            FilterByPromo.ItemsSource = new List<string>() { "Все", "Скидка 0-9", "Скидка 10-14", "Скидка 15% и более" };
+            SortByName.ItemsSource = new List<string>() { "Без сортировки", "По названию от А-Я", "По названию от Я-А" };
             SortByName.SelectedIndex = 0;
             FilterByPromo.SelectedIndex = 0;
             AllData = ProductList.Items.Count;
@@ -44,11 +45,17 @@ namespace Reks.Pages
             if (user.UserRole == 1)
             {
                 ButtonsForAdmin.Visibility = Visibility.Visible;
+                ViewOrder.Visibility = Visibility.Visible;
             }
-            FilterByPromo.ItemsSource = new List<string>() { "Все", "Скидка 0-9,99%", "Скидка 10-14,99%", "Скидка 15% и более" };
-            SortByName.ItemsSource = new List<string>() { "Без сортировки", "По имени А-Я", "По имени Я-А" };
+            if (user.UserRole == 3)
+            {
+                ViewOrder.Visibility = Visibility.Visible;
+            }
+            FilterByPromo.ItemsSource = new List<string>() { "Все", "Скидка 0-9", "Скидка 10-14", "Скидка 15% и более" };
+            SortByName.ItemsSource = new List<string>() { "Без сортировки", "По названию от А-Я", "По названию от Я-А" };
             SortByName.SelectedIndex = 0;
             FilterByPromo.SelectedIndex = 0;
+            this.id = id;
         }
 
         public void BackgroundLoad(object sender, RoutedEventArgs e)
@@ -155,7 +162,7 @@ namespace Reks.Pages
             string article = bt.Uid.ToString();
             Product pr = DB.Product.Where(x => x.ProductArticleNumber == article).First();
             ProductAmount pa = new ProductAmount();
-            if (Cart.ProductsAmount.Count != 0 && Cart.ProductsAmount.Contains(pa))
+            if (Cart.Products.Count != 0 && Cart.Products.Contains(pr))
             {
                 pa = Cart.ProductsAmount.Where(x => x.Article == article).First();
             }
@@ -177,8 +184,25 @@ namespace Reks.Pages
         private void CartGo(object sender, RoutedEventArgs e)
         {
             Cart ct = new Cart();
-            ct.ShowDialog();
+            if (Cart.Products.Count > 0)
+            {
+                ct.ShowDialog();
+            }
+            else
+            {
+                MessageBox.Show("Корзина пустая");
+            }
+        }
+
+        private void ViewOrders(object sender, RoutedEventArgs e)
+        {
+            MainFrame.mFrame.Navigate(new Orders(id));
+        }
+
+        private void BackToAuth(object sender, RoutedEventArgs e)
+        {
+            MainFrame.mFrame.Navigate(new Authorization());
         }
     }
 
-}
+}

+ 46 - 0
Reks/Pages/Zakaz.xaml

@@ -0,0 +1,46 @@
+<Page x:Class="Reks.Pages.Orders"
+      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:Reks.Pages"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="Orders">
+
+    <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="1200" 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>

+ 172 - 0
Reks/Pages/Zakaz.xaml.cs

@@ -0,0 +1,172 @@
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace Reks.Pages
+{
+    /// <summary>
+    /// Логика взаимодействия для Orders.xaml
+    /// </summary>
+    public partial class Orders : Page
+    {
+        TradeBase DB = new TradeBase();
+        int id;
+        public Orders(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("#7CFC00");
+            }
+            if (pr.ProductQuantityInStock == 0)
+            {
+                br.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#008000");
+            }
+        }
+
+        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 UserGuestPage(id));
+        }
+    }
+}

二进制
Reks/Pictures/capcha.png


+ 16 - 9
Reks/Reks.csproj

@@ -85,11 +85,14 @@
     <Compile Include="OrderStatus.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
-    <Compile Include="Pages\Authorization.xaml.cs">
-      <DependentUpon>Authorization.xaml</DependentUpon>
+    <Compile Include="Pages\Autarizacia.xaml.cs">
+      <DependentUpon>Autarizacia.xaml</DependentUpon>
     </Compile>
-    <Compile Include="Pages\UserGuestPage.xaml.cs">
-      <DependentUpon>UserGuestPage.xaml</DependentUpon>
+    <Compile Include="Pages\Zakaz.xaml.cs">
+      <DependentUpon>Zakaz.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Pages\UserBlank.xaml.cs">
+      <DependentUpon>UserBlank.xaml</DependentUpon>
     </Compile>
     <Compile Include="PickupPoints.cs">
       <DependentUpon>Model1.tt</DependentUpon>
@@ -110,8 +113,8 @@
     <Compile Include="User.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
-    <Compile Include="Windows\Cart.xaml.cs">
-      <DependentUpon>Cart.xaml</DependentUpon>
+    <Compile Include="Windows\Corzina.xaml.cs">
+      <DependentUpon>Corzina.xaml</DependentUpon>
     </Compile>
     <Page Include="MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
@@ -125,15 +128,19 @@
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
-    <Page Include="Pages\Authorization.xaml">
+    <Page Include="Pages\Autarizacia.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="Pages\Zakaz.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
-    <Page Include="Pages\UserGuestPage.xaml">
+    <Page Include="Pages\UserBlank.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
-    <Page Include="Windows\Cart.xaml">
+    <Page Include="Windows\Corzina.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>

+ 0 - 74
Reks/Windows/Cart.xaml.cs

@@ -1,74 +0,0 @@
-using Reks;
-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 Reks.Windows
-{
-    /// <summary>
-    /// Логика взаимодействия для Cart.xaml
-    /// </summary>
-    public partial class Cart : Window
-    {
-        TradeBase DB = new TradeBase();
-        public static List<Product> Products = new List<Product>();
-        public static List<ProductAmount> ProductsAmount = new List<ProductAmount>();
-        public Cart()
-        {
-            InitializeComponent();
-            CartList.ItemsSource = Products;
-        }
-
-        public Cart(int id)
-        {
-            InitializeComponent();
-            CartList.ItemsSource = Products;
-        }
-
-        private void CostCalculate(object sender, RoutedEventArgs e)
-        {
-            TextBlock tb = (TextBlock)sender;
-            string Article = tb.Uid.ToString();
-            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)));
-            }
-        }
-
-        private void Photo(object sender, RoutedEventArgs e)
-        {
-            Image pic = (Image)sender;
-            string Article = pic.Uid.ToString();
-            string photoPath = DB.Product.Where(x => x.ProductArticleNumber == Article).Select(x => x.ProductPhoto).FirstOrDefault();
-            if (photoPath != null && photoPath != "")
-            {
-                pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Pictures\\" + photoPath, UriKind.RelativeOrAbsolute));
-            }
-            else
-            {
-                pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Pictures\\picture.png", UriKind.RelativeOrAbsolute));
-            }
-        }
-
-        private void AmountCalculate(object sender, RoutedEventArgs e)
-        {
-            TextBlock tb = (TextBlock)sender;
-            string Article = tb.Uid.ToString();
-            Product pr = Products.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
-            int index = Products.IndexOf(pr);
-            tb.Text = ProductsAmount[index].Amount.ToString();
-        }
-    }
-
-}

+ 17 - 17
Reks/Windows/Cart.xaml → Reks/Windows/Corzina.xaml

@@ -11,7 +11,7 @@
             <RowDefinition Height="10*"/>
             <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
-        <ListView Grid.Row="0" Name="CartList" >
+        <ListView Grid.Row="0" Name="CartList" d:ItemsSource="{d:SampleData ItemCount=5}" >
             <ListView.ItemsPanel>
                 <ItemsPanelTemplate>
                     <WrapPanel Orientation="Vertical" HorizontalAlignment="Center"/>
@@ -19,34 +19,34 @@
             </ListView.ItemsPanel>
             <ListView.ItemTemplate>
                 <DataTemplate>
-                    <Border  Width="800" Height="200"  BorderThickness="1" BorderBrush="Black">
-                        <StackPanel Orientation="Horizontal">
-                            <Grid Width="795" Height="195">
+                    <Border  Width="1200" Height="200"  BorderThickness="1" BorderBrush="Black">
+                        <Grid Width="1200" Height="195">
+                            <StackPanel Orientation="Horizontal">
                                 <Image Width="200" Height="195" Uid="{Binding ProductArticleNumber}" Loaded="Photo"/>
-                                <StackPanel Orientation="Horizontal">
-                                    <TextBlock Margin="10,0,0,0" Text="{Binding ProductArticleNumber}"/>
-                                    <TextBlock Margin="10,0,0,0" Text="{Binding ProductName}"/>
-                                    <TextBlock Margin="10,0,0,0" Uid="{Binding ProductArticleNumber}" Loaded="CostCalculate"/>
-                                    <TextBlock Margin="10,0,0,0" Text="{Binding ProductDescription}"/>
+                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
+                                    <TextBlock Margin="10,0,0,0" Width="100" TextWrapping="Wrap" Text="{Binding StringFormat=Артикль: {0}, Path=ProductArticleNumber}"/>
+                                    <TextBlock Margin="10,0,0,0" Width="100" TextWrapping="Wrap" Text="{Binding ProductName}"/>
+                                    <TextBlock Margin="10,0,0,0" Width="100" TextWrapping="Wrap" Uid="{Binding ProductArticleNumber}" Loaded="CostCalculate"/>
+                                    <TextBlock Margin="10,0,0,0" Width="100" TextWrapping="Wrap" Text="{Binding ProductDescription}"/>
                                     <StackPanel Margin="10,0,0,0" Orientation="Vertical">
                                         <StackPanel Orientation="Horizontal">
-                                            <Button Content="-"/>
+                                            <Button Uid="{Binding ProductArticleNumber}" Click="MinusAmount" Content="-"/>
                                             <TextBlock Margin="10,0,0,0" Uid="{Binding ProductArticleNumber}" Loaded="AmountCalculate"/>
-                                            <Button Margin="10,0,0,0" Content="+"/>
+                                            <Button Uid="{Binding ProductArticleNumber}" Click="PlusAmount" Margin="10,0,0,0" Content="+"/>
                                         </StackPanel>
-                                        <Button Margin="0,10,0,0" Content="Удалить"/>
+                                        <Button Uid="{Binding ProductArticleNumber}" Click="DeleteProduct" Margin="0,10,0,0" Content="Удалить"/>
                                     </StackPanel>
                                 </StackPanel>
-                            </Grid>
-                        </StackPanel>
+                            </StackPanel>
+                        </Grid>
                     </Border>
                 </DataTemplate>
             </ListView.ItemTemplate>
         </ListView>
 
         <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
-            <TextBlock Name="CostOrder"/>
-            <Button Margin="10,0,0,0" Content="Заказать"/>
+            <TextBlock VerticalAlignment="Center" Name="CostOrder"/>
+            <Button Click="CreateOrder" Height="30" Margin="10,0,0,0" Content="Заказать"/>
         </StackPanel>
     </Grid>
-</Window>
+</Window>

+ 203 - 0
Reks/Windows/Corzina.xaml.cs

@@ -0,0 +1,203 @@
+using Reks;
+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 Reks.Windows
+{
+    /// <summary>
+    /// Логика взаимодействия для Cart.xaml
+    /// </summary>
+    public partial class Cart : Window
+    {
+        TradeBase DB = new TradeBase();
+        public static List<Product> Products = new List<Product>();
+        public static List<ProductAmount> ProductsAmount = new List<ProductAmount>();
+        public decimal? TotalCost = 0;
+        public Cart()
+        {
+            InitializeComponent();
+            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)
+        {
+            InitializeComponent();
+            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)
+        {
+            TextBlock tb = (TextBlock)sender;
+            string Article = tb.Uid.ToString();
+            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));
+            }
+        }
+
+        private void Photo(object sender, RoutedEventArgs e)
+        {
+            Image pic = (Image)sender;
+            string Article = pic.Uid.ToString();
+            string photoPath = DB.Product.Where(x => x.ProductArticleNumber == Article).Select(x => x.ProductPhoto).FirstOrDefault();
+            if (photoPath != null && photoPath != "")
+            {
+                pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Pictures\\" + photoPath, UriKind.RelativeOrAbsolute));
+            }
+            else
+            {
+                pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Pictures\\picture.png", UriKind.RelativeOrAbsolute));
+            }
+        }
+
+        private void AmountCalculate(object sender, RoutedEventArgs e)
+        {
+            TextBlock tb = (TextBlock)sender;
+            string Article = tb.Uid.ToString();
+            Product pr = Products.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
+            int index = Products.IndexOf(pr);
+            tb.Text = ProductsAmount[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();
+            ProductAmount pa = ProductsAmount.Where(x => x.Article == article).First();
+            if ((pa.Amount - 1) == 0)
+            {
+                ProductsAmount.Remove(pa);
+                Products.Remove(pr);
+                if (Products.Count == 0)
+                {
+                    this.Close();
+                }
+            }
+            else
+            {
+
+                foreach (ProductAmount pp in ProductsAmount)
+                {
+                    if (pp.Article == article)
+                    {
+                        pp.Amount--;
+                    }
+                }
+            }
+            TotalCost = 0;
+            foreach (Product p in Products)
+            {
+                TotalCost += (p.ProductCost - (p.ProductCost / 100 * p.ProductMaxDiscountAmount)) * ProductsAmount.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 (ProductAmount pa in ProductsAmount)
+            {
+                if (pa.Article == article)
+                {
+                    pa.Amount++;
+                }
+            }
+            TotalCost = 0;
+            foreach (Product p in Products)
+            {
+                TotalCost += (p.ProductCost - (p.ProductCost / 100 * p.ProductMaxDiscountAmount)) * ProductsAmount.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();
+            ProductAmount pa = ProductsAmount.Where(x => x.Article == article).First();
+            ProductsAmount.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)) * ProductsAmount.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 = ProductsAmount.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());
+        }
+    }
+
+}