Browse Source

Вроде финал

danilka.ezhov.03@mail.ru 2 years ago
parent
commit
ddaeed4f46

+ 48 - 0
Calculation/Calculation.csproj

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{F0F0A58F-D770-436F-AFF2-BE12F31F7C76}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Calculation</RootNamespace>
+    <AssemblyName>Calculation</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Calculator.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 36 - 0
Calculation/Calculator.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Calculation
+{
+    public class Calculator
+    {
+        public int Calc(decimal price, int count)
+        {
+            int sale = 0;
+            if (count > 0 && price > 0)
+            {
+                if (count >= 3)
+                {
+                    sale = 5;
+                }
+                if (count >= 5)
+                {
+                    sale = 10;
+                }
+                if (count >= 10)
+                {
+                    sale = 15;
+                }
+                if (price / 500 >= 1)
+                {
+                    sale += Convert.ToInt32(Math.Floor(price / 500));
+                }
+            }
+            return sale;
+        }
+    }
+}

+ 36 - 0
Calculation/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// Общие сведения об этой сборке предоставляются следующим набором
+// набора атрибутов. Измените значения этих атрибутов для изменения сведений,
+// связанные со сборкой.
+[assembly: AssemblyTitle("Calculation")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Calculation")]
+[assembly: AssemblyCopyright("Copyright ©  2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
+// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
+// COM, задайте атрибуту ComVisible значение TRUE для этого типа.
+[assembly: ComVisible(false)]
+
+// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
+[assembly: Guid("f0f0a58f-d770-436f-aff2-be12f31f7c76")]
+
+// Сведения о версии сборки состоят из указанных ниже четырех значений:
+//
+//      Основной номер версии
+//      Дополнительный номер версии
+//      Номер сборки
+//      Редакция
+//
+// Можно задать все значения или принять номера сборки и редакции по умолчанию 
+// используя "*", как показано ниже:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 12 - 0
Exam19Apr.sln

@@ -5,6 +5,10 @@ VisualStudioVersion = 16.0.30907.101
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exam19Apr", "Exam19Apr\Exam19Apr.csproj", "{1372D800-4815-4E29-8829-F63222EEBDAA}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Calculation", "Calculation\Calculation.csproj", "{F0F0A58F-D770-436F-AFF2-BE12F31F7C76}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject1", "UnitTestProject1\UnitTestProject1.csproj", "{A62582D1-DC97-4A96-A0BC-7A41B3FC2AAA}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -15,6 +19,14 @@ Global
 		{1372D800-4815-4E29-8829-F63222EEBDAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{1372D800-4815-4E29-8829-F63222EEBDAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{1372D800-4815-4E29-8829-F63222EEBDAA}.Release|Any CPU.Build.0 = Release|Any CPU
+		{F0F0A58F-D770-436F-AFF2-BE12F31F7C76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F0F0A58F-D770-436F-AFF2-BE12F31F7C76}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F0F0A58F-D770-436F-AFF2-BE12F31F7C76}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F0F0A58F-D770-436F-AFF2-BE12F31F7C76}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A62582D1-DC97-4A96-A0BC-7A41B3FC2AAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A62582D1-DC97-4A96-A0BC-7A41B3FC2AAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A62582D1-DC97-4A96-A0BC-7A41B3FC2AAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A62582D1-DC97-4A96-A0BC-7A41B3FC2AAA}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 0 - 0
Exam19Apr/BaseConnect.cs → Exam19Apr/Classes/BaseConnect.cs


+ 0 - 0
Exam19Apr/LoadPages.cs → Exam19Apr/Classes/LoadPages.cs


+ 71 - 0
Exam19Apr/Classes/PartialBook.cs

@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Exam19Apr
+{
+    public partial class Books
+    {
+        public string CheckStoreCount
+        {
+            get
+            {
+                if (StoreCount > 5)
+                    return "Много";
+                else if (StoreCount == 0)
+                    return "Нет";
+                else
+                    return StoreCount.ToString();
+            }
+        }
+
+        public string CheckStockCount
+        {
+            get
+            {
+                if (StockCount > 5)
+                    return "Много";
+                else if (StockCount == 0)
+                    return "Нет";
+                else
+                    return StockCount.ToString();
+            }
+        }
+
+
+        public int Sale { get; set; }
+
+        public int FullCount { get; set; }
+        public decimal PriceSale
+        {
+            get
+            {
+                return Price - Price * (Convert.ToDecimal(Sale) / 100);
+            }
+        }
+
+        public string VisiblePriceSale
+        {
+            get
+            {
+                if (Sale == 0)
+                    return "Collapsed";
+                else
+                    return "Visible";
+            }
+        }
+
+        public string DecorationPrice
+        {
+            get
+            {
+                if (Sale > 0)
+                    return "Strikethrough";
+                else
+                    return "None";
+            }
+        }
+    }
+}

BIN
Exam19Apr/Covers/Долгая прогулка.jpg


BIN
Exam19Apr/Covers/Король шрамов.jpg


BIN
Exam19Apr/Covers/Красношейка.jpg


BIN
Exam19Apr/Covers/Крещение огнем.jpg


BIN
Exam19Apr/Covers/Мизери.jpg


BIN
Exam19Apr/Covers/Повелитель мух.jpg


BIN
Exam19Apr/Covers/Ритуал.jpg


BIN
Exam19Apr/Covers/Странствия убийцы.jpg


BIN
Exam19Apr/Covers/Творец заклинаний.jpg


BIN
Exam19Apr/Covers/Финист - ясный сокол.jpg


BIN
Exam19Apr/Covers/Цветы для Элджернона.jpg


+ 37 - 4
Exam19Apr/Exam19Apr.csproj

@@ -64,7 +64,7 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
-    <Page Include="MainWindow.xaml">
+    <Page Include="Pages\MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
@@ -72,15 +72,23 @@
       <DependentUpon>App.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="BaseConnect.cs" />
+    <Compile Include="Classes\BaseConnect.cs" />
     <Compile Include="Books.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
-    <Compile Include="LoadPages.cs" />
-    <Compile Include="MainWindow.xaml.cs">
+    <Compile Include="Classes\LoadPages.cs" />
+    <Compile Include="Pages\MainWindow.xaml.cs">
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Page Include="Pages\pgBooksCatalog.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="Pages\pgTrash.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Model1.Context.cs">
@@ -101,6 +109,13 @@
     <Compile Include="Ordering.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
+    <Compile Include="Classes\PartialBook.cs" />
+    <Compile Include="Pages\pgBooksCatalog.xaml.cs">
+      <DependentUpon>pgBooksCatalog.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Pages\pgTrash.xaml.cs">
+      <DependentUpon>pgTrash.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Properties\AssemblyInfo.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -135,6 +150,17 @@
     <None Include="App.config" />
   </ItemGroup>
   <ItemGroup>
+    <Resource Include="Covers\Долгая прогулка.jpg" />
+    <Resource Include="Covers\Король шрамов.jpg" />
+    <Resource Include="Covers\Красношейка.jpg" />
+    <Resource Include="Covers\Крещение огнем.jpg" />
+    <Resource Include="Covers\Мизери.jpg" />
+    <Resource Include="Covers\Повелитель мух.jpg" />
+    <Resource Include="Covers\Ритуал.jpg" />
+    <Resource Include="Covers\Странствия убийцы.jpg" />
+    <Resource Include="Covers\Творец заклинаний.jpg" />
+    <Resource Include="Covers\Финист - ясный сокол.jpg" />
+    <Resource Include="Covers\Цветы для Элджернона.jpg" />
     <Content Include="Model1.Context.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
       <LastGenOutput>Model1.Context.cs</LastGenOutput>
@@ -149,5 +175,12 @@
   <ItemGroup>
     <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Calculation\Calculation.csproj">
+      <Project>{f0f0a58f-d770-436f-aff2-be12f31f7c76}</Project>
+      <Name>Calculation</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 6 - 1
Exam19Apr/MainWindow.xaml → Exam19Apr/Pages/MainWindow.xaml

@@ -7,6 +7,11 @@
         mc:Ignorable="d"
         Title="MainWindow" Height="450" Width="800">
     <Grid>
-        
+        <Grid.RowDefinitions>
+            <RowDefinition Height="64*"/>
+            <RowDefinition Height="355*"/>
+        </Grid.RowDefinitions>
+        <TextBlock Text="Книжный магазин" FontSize="46px" HorizontalAlignment="Center" Grid.Row="0" Foreground="Aqua"></TextBlock>
+        <Frame Name="frmMane" NavigationUIVisibility="Hidden" Grid.Row="1" ></Frame>
     </Grid>
 </Window>

+ 2 - 0
Exam19Apr/MainWindow.xaml.cs → Exam19Apr/Pages/MainWindow.xaml.cs

@@ -23,6 +23,8 @@ namespace Exam19Apr
         public MainWindow()
         {
             InitializeComponent();
+            LoadPages.goPage = frmMane;
+            LoadPages.goPage.Navigate(new pgBooksCatalog());
         }
     }
 }

+ 80 - 0
Exam19Apr/Pages/pgBooksCatalog.xaml

@@ -0,0 +1,80 @@
+<Page x:Class="Exam19Apr.pgBooksCatalog"
+      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:Exam19Apr"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="pgBooksCatalog">
+    <Page.Resources>
+        <DataTemplate x:Key="outputBooks">
+            <Border BorderBrush="Black" BorderThickness="1,1,1,1">
+                <StackPanel Orientation="Horizontal" Width="600px">
+                    <StackPanel>
+                        <Image Source="{Binding Image}" Width="100px" Height="100px"></Image>
+                    </StackPanel>
+                    <StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Название: "></TextBlock>
+                            <TextBlock Text="{Binding Heading}"></TextBlock>
+                            <TextBlock Text=" | "></TextBlock>
+                            <TextBlock Text="Жанр: "></TextBlock>
+                            <TextBlock Text="{Binding Style}"></TextBlock>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Автор: "></TextBlock>
+                            <TextBlock Text="{Binding Writer}"></TextBlock>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Цена: "></TextBlock>
+                            <TextBlock Text="{Binding Price}"></TextBlock>
+                            <TextBlock Text="руб."></TextBlock>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Количество в магазине: "></TextBlock>
+                            <TextBlock Text="{Binding CheckStoreCount}"></TextBlock>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Количество в магазине: "></TextBlock>
+                            <TextBlock Text="{Binding CheckStockCount}"></TextBlock>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Описание: "></TextBlock>
+                            <TextBlock Text="{Binding Specification}" TextWrapping="Wrap" MaxWidth="400px"></TextBlock>
+                        </StackPanel>
+                        <Button Name="btnAddBok" Content="Добавить в корзину" Uid="{Binding id}" Click="btnAddBok_Click"></Button>
+                    </StackPanel>
+                </StackPanel>
+            </Border>
+        </DataTemplate>
+    </Page.Resources>
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition/>
+            <RowDefinition Height="4*"/>
+        </Grid.RowDefinitions>
+        <Border BorderBrush="Black" BorderThickness="1,1,1,1">
+            <StackPanel Grid.Row="0"  HorizontalAlignment="Right">
+                <StackPanel Orientation="Horizontal">
+                    <TextBlock Text="Количество выбранных книг: "></TextBlock>
+                    <TextBlock Name="tbCount"></TextBlock>
+                </StackPanel>
+                <StackPanel Orientation="Horizontal" >
+                    <TextBlock Text="Стоимость покупки: "></TextBlock>
+                    <TextBlock Name="tbPrice"></TextBlock>
+                    <TextBlock Text=" "></TextBlock>
+                    <TextBlock Name="tbSalePrice"></TextBlock>
+                    <TextBlock Text=" руб." Name="tbRub"></TextBlock>
+                </StackPanel>
+                <StackPanel Orientation="Horizontal" >
+                    <TextBlock Text="Размер скидки: "></TextBlock>
+                    <TextBlock Name="tbSale"></TextBlock>
+                    <TextBlock Text=" %" Name="tbPer"></TextBlock>
+                </StackPanel>
+                <Button Name="btnGoCart" Content="Корзина" Click="btnGoCart_Click"></Button>
+            </StackPanel>
+        </Border>
+        <ListBox Name="lbBooks" ItemTemplate="{StaticResource outputBooks}" Grid.Row="1"></ListBox>
+    </Grid>
+</Page>

+ 109 - 0
Exam19Apr/Pages/pgBooksCatalog.xaml.cs

@@ -0,0 +1,109 @@
+using Calculation;
+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 Exam19Apr
+{
+    /// <summary>
+    /// Логика взаимодействия для pgBooksCatalog.xaml
+    /// </summary>
+    public partial class pgBooksCatalog : Page
+    {
+        int count = 0;
+        decimal price = 0;
+        List<Books> books;
+        int Sale = 0;
+        public pgBooksCatalog()
+        {
+            InitializeComponent();
+            BaseConnect.BaseModel = new Entities();
+            lbBooks.ItemsSource = BaseConnect.BaseModel.Books.ToList();
+            books = new List<Books>();
+            tbPer.Visibility = Visibility.Collapsed;
+            tbRub.Visibility = Visibility.Collapsed;
+            tbSalePrice.Visibility = Visibility.Collapsed;
+        }
+        private void btnAddBok_Click(object sender, RoutedEventArgs e)
+        {
+
+            Button btn = (Button)sender;
+            int id = Convert.ToInt32(btn.Uid);
+            Books book = BaseConnect.BaseModel.Books.FirstOrDefault(x => x.id == id);
+            Books checkBook = books.FirstOrDefault(x => x.id == id);
+            int summ = BaseConnect.BaseModel.Books.Where(x => x.id == id).Sum(x => x.StockCount) + BaseConnect.BaseModel.Books.Where(x => x.id == id).Sum(x => x.StoreCount);
+            int summList = 0;
+            if (book.StockCount > 0 || book.StoreCount > 0)
+            {
+                if (checkBook == null)
+                {
+                    checkBook = book;
+                    checkBook.FullCount = 0;
+                    books.Add(checkBook);
+                }
+                if (book.StockCount + book.StoreCount > checkBook.FullCount)
+                {
+
+                    summList = books.Where(x => x.id == id).Sum(x => x.StockCount) + books.Where(x => x.id == id).Sum(x => x.StoreCount);
+                    checkBook.FullCount++;
+                        count++;
+                        tbCount.Text = count.ToString();
+                        price += book.Price;
+                        tbPrice.Text = price.ToString();
+                        if (tbPrice.Text != "" || tbSalePrice.Text != "")
+                        {
+                            tbRub.Visibility = Visibility.Visible;
+                        }
+                        lbBooks.Items.Refresh();
+                        tbPrice.Text = tbPrice.Text.Replace(".", ",");
+                        Calculator calc = new Calculator();
+                        int countTb = Convert.ToInt32(tbCount.Text);
+                        decimal priceTb = Convert.ToDecimal(tbPrice.Text);
+                        Sale = calc.Calc(priceTb, countTb);
+                        foreach (Books booke in books)
+                        {
+                            booke.Sale = Sale;
+                        }
+                }
+                else
+                    MessageBox.Show("Товар нельзя купить!");
+            }
+            else
+                MessageBox.Show("Товар нельзя купить!");
+
+
+
+
+            if (Sale > 0 && Sale <= 100)
+            {
+                tbPrice.TextDecorations = TextDecorations.Strikethrough;
+                tbPer.Visibility = Visibility.Visible;
+                tbSale.Visibility = Visibility.Visible;
+                tbSalePrice.Visibility = Visibility.Visible;
+                tbPer.Visibility = Visibility.Visible;
+                decimal salePrice;
+                salePrice = Convert.ToDecimal(tbPrice.Text) - Convert.ToDecimal(tbPrice.Text) * (Convert.ToDecimal(Sale) / 100);
+                tbSalePrice.Text = salePrice.ToString();
+                tbSale.Text = Sale.ToString();
+            }
+
+        }
+
+        private void btnGoCart_Click(object sender, RoutedEventArgs e)
+        {
+            LoadPages.goPage.Navigate(new pgTrash(books));
+        }
+    }
+}
+

+ 55 - 0
Exam19Apr/Pages/pgTrash.xaml

@@ -0,0 +1,55 @@
+<Page x:Class="Exam19Apr.pgTrash"
+      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:Exam19Apr"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="pgTrash">
+    <Page.Resources>
+        <DataTemplate x:Key="outputBooks">
+            <Border BorderBrush="Black" BorderThickness="1,1,1,1">
+                <StackPanel Orientation="Horizontal" Width="600px">
+                    <StackPanel>
+                        <Image Source="{Binding Image}" Width="100px" Height="100px"></Image>
+                    </StackPanel>
+                    <StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Название: "></TextBlock>
+                            <TextBlock Text="{Binding Heading}"></TextBlock>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Автор: "></TextBlock>
+                            <TextBlock Text="{Binding Writer}"></TextBlock>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Количество: "></TextBlock>
+                            <TextBox Text="{Binding FullCount}" TextChanged="TextBox_TextChanged" Uid="{Binding id}"></TextBox>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="Цена: "></TextBlock>
+                            <TextBlock Name="tbCost" Text="{Binding Price}" TextDecorations="{Binding DecorationPrice}"></TextBlock>
+                            <TextBlock Text=" "></TextBlock>
+                            <TextBlock Text="{Binding PriceSale}" Visibility="{Binding VisiblePriceSale}"></TextBlock>
+                            <TextBlock Text=" руб."></TextBlock>
+                        </StackPanel>
+                        <Button Name="btnDeleteBook" Content="Удалить" Click="btnDeleteBook_Click" Uid="{Binding id}"></Button>
+                    </StackPanel>
+                </StackPanel>
+            </Border>
+        </DataTemplate>
+    </Page.Resources>
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="4*"/>
+            <RowDefinition Height="1*"/>
+        </Grid.RowDefinitions>
+        <ListBox Name="lbBooksBuy" ItemTemplate="{StaticResource outputBooks}" Grid.Row="0"></ListBox>
+        <StackPanel Orientation="Horizontal"  Grid.Row="1">
+            <Button Name="btnBuy" Content="Купить" Width="40px" Click="btnBuy_Click"></Button>
+            <Button Name="btnDel" Content="Очистить" Width="40px" Click="btnDel_Click"></Button>
+            <Button Name="btnBack" Click="btnBack_Click" Content="Назад"></Button>
+        </StackPanel>
+    </Grid>
+</Page>

+ 152 - 0
Exam19Apr/Pages/pgTrash.xaml.cs

@@ -0,0 +1,152 @@
+using Calculation;
+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 Exam19Apr
+{
+    /// <summary>
+    /// Логика взаимодействия для pgTrash.xaml
+    /// </summary>
+    public partial class pgTrash : Page
+    {
+        List<Books> bookBuy;
+        bool CheckBack = true;
+        public pgTrash(List<Books> bookBuy)
+        {
+            InitializeComponent();
+            this.bookBuy = bookBuy;
+            lbBooksBuy.ItemsSource = bookBuy;
+        }
+        private void btnDeleteBook_Click(object sender, RoutedEventArgs e)
+        {
+            Button btn = (Button)sender;
+            int id = Convert.ToInt32(btn.Uid);
+            Books delBook = bookBuy.FirstOrDefault(x => x.id == id);
+            bookBuy.Remove(delBook);
+            lbBooksBuy.Items.Refresh();
+        }
+
+        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            try
+            {
+                TextBox tb = (TextBox)sender;
+                int id = Convert.ToInt32(tb.Uid);
+                Books book = bookBuy.FirstOrDefault(x => x.id == id);
+                int tmpValue = book.FullCount;
+                try
+                {
+                    Books checkCountBook = BaseConnect.BaseModel.Books.FirstOrDefault(x => x.id == id);
+                    int Base = checkCountBook.StoreCount + checkCountBook.StockCount;
+                    if (Base >= Convert.ToInt32(tb.Text))
+                    {
+                        Calculator cs = new Calculator();
+                        book.FullCount = Convert.ToInt32(tb.Text);
+                        int count = 0;
+                        decimal price = 0;
+                        foreach (Books bok in bookBuy)
+                        {
+                            price += bok.Price * bok.FullCount;
+                            count += bok.FullCount;
+
+                        }
+                        foreach (Books booke in bookBuy)
+                        {
+                            booke.Sale = cs.Calc(price, count);
+                        }
+                        lbBooksBuy.ItemsSource = bookBuy;
+                        lbBooksBuy.Items.Refresh();
+
+                    }
+                    else
+                    {
+                        MessageBox.Show("Такого кол-ва нет!");
+                        tb.Text = tmpValue.ToString();
+                    }
+
+                }
+                catch { }
+            }
+            catch 
+            {
+
+            }
+           
+        }
+        private void btnBuy_Click(object sender, RoutedEventArgs e)
+        {
+
+            int nOrder, count = 0, sale = 0;
+            bool flagMessageOrder = false;
+            if (BaseConnect.BaseModel.Ordering.Count() != 0)
+                nOrder = BaseConnect.BaseModel.Ordering.Max(x => x.SerialNumber) + 1;
+            else
+                nOrder = 1;
+           
+            decimal CountCost = 0;
+            foreach (Books book in bookBuy)
+            {
+
+                Books bk = BaseConnect.BaseModel.Books.FirstOrDefault(x => x.id == book.id);
+                if (bk.StoreCount >= book.FullCount)
+                {
+                    flagMessageOrder = true;
+                    bk.StoreCount -= book.FullCount;
+                    BaseConnect.BaseModel.SaveChanges();
+                }
+                else
+                {
+                    int res = book.FullCount - bk.StoreCount;
+                    bk.StoreCount = 0;
+                    bk.StockCount -= res;
+                    BaseConnect.BaseModel.SaveChanges();
+                }
+                Ordering or = new Ordering();
+                or.IdBooks = book.id;
+                or.SerialNumber = nOrder;
+                or.Count = book.FullCount;
+                count += book.FullCount;
+                sale = book.Sale;
+                CountCost += book.Price * book.FullCount;
+                or.DateOrdering = DateTime.Now;
+                BaseConnect.BaseModel.Ordering.Add(or);
+            }
+            if (flagMessageOrder)
+                MessageBox.Show("Номер заказа: " + nOrder + "\nЧасть заказа будет готова к выдаче: " + DateTime.Now.ToShortDateString() + "\nДругая часть заказа готова к выдаче: " + DateTime.Now.AddDays(3).ToShortDateString() + "\nЗаказ зарезервирован до: " + DateTime.Now.AddDays(7).ToShortDateString() + "\n Итоговое количество книг: " + count + "\nИтоговая цена:" + Math.Floor(CountCost - (CountCost * sale / 100)) + "\nСкидка:" + sale);
+            else
+            {
+                MessageBox.Show("Номер заказа: " + nOrder + "\nВыдача готова: " + DateTime.Now.ToShortDateString() + "\nЗаказ зарезервирован до: " + DateTime.Now.AddDays(7).ToShortDateString() + "\n Итоговое количество книг: " + count + "\nИтоговая цена:" + Math.Floor(CountCost - (CountCost * sale / 100)) + "\nСкидка:" + sale);
+            }
+            bookBuy.Clear();
+            lbBooksBuy.Items.Refresh();
+            CheckBack = false;
+        }
+
+        private void btnDel_Click(object sender, RoutedEventArgs e)
+        {
+            bookBuy.Clear();
+            lbBooksBuy.Items.Refresh();
+            CheckBack = false;
+        }
+
+        private void btnBack_Click(object sender, RoutedEventArgs e)
+        {
+            if (!CheckBack)
+                LoadPages.goPage.Navigate(new pgBooksCatalog());
+            else
+                LoadPages.goPage.GoBack();
+        }
+    }
+}

+ 20 - 0
UnitTestProject1/Properties/AssemblyInfo.cs

@@ -0,0 +1,20 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("UnitTestProject1")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("UnitTestProject1")]
+[assembly: AssemblyCopyright("Copyright ©  2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+[assembly: ComVisible(false)]
+
+[assembly: Guid("a62582d1-dc97-4a96-a0bc-7a41b3fc2aaa")]
+
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 91 - 0
UnitTestProject1/UnitTest1.cs

@@ -0,0 +1,91 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+using Calculation;
+
+namespace UnitTestProject1
+{
+    [TestClass]
+    public class UnitTest1
+    {
+        Calculator cs;
+
+        [TestMethod]
+        public void TestMethod1()
+        {
+            cs = new Calculator();
+            Assert.AreEqual(cs.Calc(13M, 14), cs.Calc(13M, 15));
+        }
+
+        [TestMethod]
+        public void TestMethod2()
+        {
+            cs = new Calculator();
+            Assert.AreEqual(cs.Calc(0M, 0), cs.Calc(0M, 2));
+        }
+
+        [TestMethod]
+        public void TestMethod3()
+        {
+            cs = new Calculator();
+            Assert.AreEqual(0, cs.Calc(0M, 0));
+        }
+
+        
+
+        [TestMethod]
+        public void TestMethod4()
+        {
+            cs = new Calculator();
+
+            Assert.AreEqual(0, cs.Calc(122.21M, Convert.ToInt32(10 * 0.2)));
+        }
+
+        [TestMethod]
+        public void TestMethod5()
+        {
+            cs = new Calculator();
+            int count = Convert.ToInt32(10 * 0.2);
+            decimal price = 122.21M;
+            Assert.AreEqual(1, cs.Calc(price * 5, count));
+        }
+
+        [TestMethod]
+        public void TestMethod6()
+        {
+            cs = new Calculator();
+            Assert.AreEqual(0, cs.Calc(0M, Convert.ToInt32(10 * 0.5)));
+        }
+
+        [TestMethod]
+        public void TestMethod7()
+        {
+            cs = new Calculator();
+            Assert.AreEqual(0, cs.Calc(12.5M, Convert.ToInt32(10 * 0.2)));
+        }
+
+
+        [TestMethod]
+        public void TestMethod8()
+        {
+            cs = new Calculator();
+            Assert.AreEqual(15, cs.Calc(0.3M, 10));
+        }
+
+
+        [TestMethod]
+        public void TestMethod9()
+        {
+            cs = new Calculator();
+
+            Assert.AreEqual(16, cs.Calc(750, 17));
+        }
+
+
+        [TestMethod]
+        public void TestMethod10()
+        {
+            cs = new Calculator();
+            Assert.AreEqual(0, cs.Calc(750, 0));
+        }
+    }
+}

+ 74 - 0
UnitTestProject1/UnitTestProject1.csproj

@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\packages\MSTest.TestAdapter.2.1.1\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.1\build\net45\MSTest.TestAdapter.props')" />
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{A62582D1-DC97-4A96-A0BC-7A41B3FC2AAA}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>UnitTestProject1</RootNamespace>
+    <AssemblyName>UnitTestProject1</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
+    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
+    <IsCodedUITest>False</IsCodedUITest>
+    <TestProjectType>UnitTest</TestProjectType>
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="UnitTest1.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Calculation\Calculation.csproj">
+      <Project>{f0f0a58f-d770-436f-aff2-be12f31f7c76}</Project>
+      <Name>Calculation</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их.  Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}.</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.1\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.1\build\net45\MSTest.TestAdapter.props'))" />
+    <Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.1\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.1\build\net45\MSTest.TestAdapter.targets'))" />
+  </Target>
+  <Import Project="..\packages\MSTest.TestAdapter.2.1.1\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.1\build\net45\MSTest.TestAdapter.targets')" />
+</Project>

+ 5 - 0
UnitTestProject1/packages.config

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="MSTest.TestAdapter" version="2.1.1" targetFramework="net472" />
+  <package id="MSTest.TestFramework" version="2.1.1" targetFramework="net472" />
+</packages>