АсташинИА 7 months ago
parent
commit
1c74422347

+ 1 - 1
WriteErase/App.config

@@ -8,7 +8,7 @@
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
   </startup>
   <connectionStrings>
-    <add name="TradeEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=ngknn.ru;initial catalog=TradeAstashin;user id=33П;password=12357;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
+    <add name="TradeEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=sql;initial catalog=TradeAstashin;user id=33П;password=12357;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
   </connectionStrings>
   <entityFramework>
     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">

+ 1 - 0
WriteErase/MainWindow.xaml

@@ -5,6 +5,7 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:WriteErase"
         mc:Ignorable="d"
+        
         Title="MainWindow" Height="550" Width="800">
     <Grid>
         <Frame Name="FrameMainWindow" NavigationUIVisibility="Hidden"/>

+ 3 - 3
WriteErase/Pages/Auth.xaml

@@ -8,7 +8,7 @@
       d:DesignHeight="550" d:DesignWidth="800"
       Title="Auth">
 
-    <Grid Background="LightGray">
+    <Grid Background="#76e383">
         <Rectangle HorizontalAlignment="Center" Height="500"  Fill="White" VerticalAlignment="Center" Width="306" RadiusX="15" RadiusY="15"/>
         <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
             <TextBlock HorizontalAlignment="Center" FontWeight="DemiBold" Margin="0,10,0,0" FontSize="40">SIGN IN</TextBlock>
@@ -24,11 +24,11 @@
                     <TextBox Background="#0000" BorderBrush="#0000" Foreground="#4f4f4f" Name="CapaText"/>
                 </GroupBox>
             </StackPanel>
-            <Border BorderThickness="1" CornerRadius="7" BorderBrush="#bababa" Background="LightGray" Width="200" Height="28" Margin="0,30,0,0" >
+            <Border BorderThickness="1" CornerRadius="7" BorderBrush="#498c51" Background="#76e383" Width="200" Height="28" Margin="0,30,0,0" >
                 <Button Name="AuthUser" Click="GoAuth" Background="#0000" BorderBrush="#0000" Content="Sign in" FontSize="16"></Button>
             </Border>
             <TextBlock HorizontalAlignment="Center" FontWeight="DemiBold" Foreground="#4f4f4f" FontSize="11" Margin="0,5,0,0">Or</TextBlock>
-            <Border BorderThickness="1" CornerRadius="7" BorderBrush="#bababa" Background="LightGray"  Width="200" Height="28" Margin="0,5,0,0" >
+            <Border BorderThickness="1" CornerRadius="7" BorderBrush="#498c51" Background="#76e383"  Width="200" Height="28" Margin="0,5,0,0" >
                 <Button Name="AuthGuest" Click="GoGuest" Background="#0000" BorderBrush="#0000" Content="Sign in as a guest" FontSize="16"></Button>
             </Border>
         </StackPanel>

+ 59 - 1
WriteErase/Pages/Guest.xaml

@@ -8,7 +8,65 @@
       d:DesignHeight="450" d:DesignWidth="800"
       Title="Guest">
 
-    <Grid>
+    <Grid Background="White">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="1.7*"/>
+            <RowDefinition Height="10*"/>
+            <RowDefinition Height="*"/>
+        </Grid.RowDefinitions>
         
+        <StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal">
+            <GroupBox Header="Сортировка" Margin="10,0,0,0">
+                <ComboBox Foreground="#4f4f4f" FontSize="15" VerticalContentAlignment="Center" SelectionChanged="SortFilterChanged" Name="SortByName" Height="30" Margin="10,0,0,0" Width="200"/>
+            </GroupBox>
+            <GroupBox Header="Фильтр" Margin="5,0,0,0">
+                <ComboBox Foreground="#4f4f4f" FontSize="15" VerticalContentAlignment="Center" SelectionChanged="SortFilterChanged" Name="FilterByPromo" Height="30" Margin="10,0,0,0"  Width="200"/>
+            </GroupBox>
+            <GroupBox Header="Поиск" Margin="5,0,0,0">
+                <TextBox Background="#0000" FontSize="15" VerticalContentAlignment="Center" BorderBrush="#0000" Foreground="#4f4f4f" TextChanged="SearchChanged" Name="SearchByName" Height="30" TextAlignment="Left"  Margin="10,0,0,0"  Width="200"/>
+            </GroupBox>
+        </StackPanel>
+
+        <ListView Grid.Row="1" Name="ProductList" d:ItemsSource="{d:SampleData ItemCount=5}">
+            <ListView.ItemsPanel>
+                <ItemsPanelTemplate>
+                    <WrapPanel Orientation="Vertical" HorizontalAlignment="Center"/>
+                </ItemsPanelTemplate>
+            </ListView.ItemsPanel>
+            <ListView.ItemTemplate>
+                <DataTemplate>
+                    <Border  Width="800" Height="170" BorderThickness="1" BorderBrush="Black">
+                        <StackPanel>
+                            <Grid Width="800" Height="170"  Loaded="BackgroundLoad" Uid="{Binding ProductArticleNumber}">
+                                <StackPanel Orientation="Horizontal">
+                                    <Image Width="150" Height="150" Margin="10 0 0 0" Grid.Column="0" Uid="{Binding ProductArticleNumber}" Loaded="Photo"/>
+                                    <StackPanel Margin="20,0,0,0" Width="300" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="1" Orientation="Vertical">
+                                        <TextBlock FontSize="15" Text="{Binding ProductName}"/>
+                                        <TextBlock FontSize="15" Text="{Binding ProductDescription}" TextWrapping="Wrap"/>
+                                        <TextBlock FontSize="15" Text="{Binding StringFormat=Произоводитель: {0},Path=Manufacturers.ManufacturerName}"/>
+                                        <TextBlock FontSize="15" Text="{Binding ProductCost}"  Uid="{Binding ProductArticleNumber}" Loaded="StrikePrice"/>
+                                        <TextBlock FontSize="15" Text="{Binding ProductCost}"  Uid="{Binding ProductArticleNumber}" Loaded="PromoPrice"/>
+                                    </StackPanel>
+                                    <TextBlock FontSize="15" Margin="100,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Right" Grid.Column="2" Text="{Binding StringFormat=Скидка: {0}%, Path=ProductMaxDiscountAmount}"/>
+                                </StackPanel>
+                            </Grid>
+
+                        </StackPanel>
+                    </Border>
+                </DataTemplate>
+            </ListView.ItemTemplate>
+        </ListView>
+
+        <StackPanel Name="ButtonsForAdmin" Visibility="Hidden" HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal" Grid.Row="2">
+            <Border BorderThickness="1" CornerRadius="7" BorderBrush="#bababa" Background="LightGray" Width="80" Height="28" Margin="10,0,0,0" >
+                <Button Content="Добавить" Background="#0000" BorderBrush="#0000" FontSize="14"></Button>
+            </Border>
+            <Border BorderThickness="1" CornerRadius="7" BorderBrush="#bababa" Background="LightGray" Width="110" Height="28" Margin="5,0,0,0" >
+                <Button Content="Редактировать" Background="#0000" BorderBrush="#0000" FontSize="14"></Button>
+            </Border>
+            <Border BorderThickness="1" CornerRadius="7" BorderBrush="#bababa" Background="LightGray" Width="80" Height="28" Margin="5,0,0,0" >
+                <Button Content="Удалить" Background="#0000" BorderBrush="#0000" FontSize="14"></Button>
+            </Border>
+        </StackPanel>
     </Grid>
 </Page>

+ 120 - 0
WriteErase/Pages/Guest.xaml.cs

@@ -20,9 +20,129 @@ namespace WriteErase.Pages
     /// </summary>
     public partial class Guest : Page
     {
+
+        TradeEntities DB = new TradeEntities();
+
         public Guest()
         {
             InitializeComponent();
+            ProductList.ItemsSource = DB.Product.ToList();
+            FilterByPromo.ItemsSource = new List<string>() { "Все", "Скаидка 0-9,99%", "Скидка 10-14,99%", "Скидка 15% и более" };
+            SortByName.ItemsSource = new List<string>() { "Без сортировки", "По имени А-Я", "По имени Я-А" };
+            SortByName.SelectedIndex = 0;
+            FilterByPromo.SelectedIndex = 0;
+        }
+
+        public Guest(int id)
+        {
+            InitializeComponent();
+            ProductList.ItemsSource = DB.Product.ToList();
+            User user = DB.User.Where(x => x.UserID == id).FirstOrDefault();
+            if (user.UserRole == 1)
+            {
+                ButtonsForAdmin.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;
+        }
+
+        public void BackgroundLoad(object sender, RoutedEventArgs e)
+        {
+            Grid bgr = (Grid)sender;
+            string Article = bgr.Uid.ToString();
+            Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
+            if (pr.ProductMaxDiscountAmount > 15)
+            {
+                bgr.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#76e383");
+            }
+        }
+
+        public void StrikePrice(object sender, RoutedEventArgs e)
+        {
+            TextBlock tb = (TextBlock)sender;
+            string Article = tb.Uid.ToString();
+            Product pr = DB.Product.Where(x => x.ProductArticleNumber == Article).FirstOrDefault();
+            tb.Text = "Цена: " + string.Format("{0:C2}", pr.ProductCost);
+            if (pr.ProductMaxDiscountAmount > 0)
+            {
+                tb.TextDecorations = TextDecorations.Strikethrough;
+            }
+        }
+
+        public void PromoPrice(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)));
+                tb.FontWeight = FontWeights.Bold;
+            }
+        }
+
+        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 + "\\Picture\\" + photoPath, UriKind.RelativeOrAbsolute));
+            }
+            else
+            {
+                pic.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Picture\\picture.png", UriKind.RelativeOrAbsolute));
+            }
+        }
+
+        private void Filter()
+        {
+            List<Product> products = DB.Product.ToList();
+            if (SortByName.SelectedIndex != 0)
+            {
+                switch (SortByName.SelectedIndex)
+                {
+                    case 1:
+                        products = products.OrderBy(x => x.ProductName).ToList();
+                        break;
+                    case 2:
+                        products = products.OrderByDescending(x => x.ProductName).ToList();
+                        break;
+                }
+            }
+            if (FilterByPromo.SelectedIndex != 0)
+            {
+                switch (FilterByPromo.SelectedIndex)
+                {
+                    case 1:
+                        products = products.Where(x => x.ProductMaxDiscountAmount >= 0 && x.ProductMaxDiscountAmount < 10).ToList();
+                        break;
+                    case 2:
+                        products = products.Where(x => x.ProductMaxDiscountAmount >= 10 && x.ProductMaxDiscountAmount < 15).ToList();
+                        break;
+                    case 3:
+                        products = products.Where(x => x.ProductMaxDiscountAmount >= 15).ToList();
+                        break;
+                }
+            }
+            if (!string.IsNullOrEmpty(SearchByName.Text))
+            {
+                products = products.Where(x => x.ProductName.ToUpper().Contains(SearchByName.Text.ToUpper())).ToList();
+            }
+            ProductList.ItemsSource = products;
+        }
+
+        private void SortFilterChanged(object sender, SelectionChangedEventArgs e)
+        {
+            Filter();
+        }
+
+        private void SearchChanged(object sender, TextChangedEventArgs e)
+        {
+            Filter();
         }
     }
 }

+ 36 - 12
WriteErase/WriteErase.csproj

@@ -189,20 +189,44 @@
     <None Include="App.config" />
   </ItemGroup>
   <ItemGroup>
-    <Resource Include="Picture\captcha.jpg" />
+    <Content Include="Picture\captcha.jpg">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
   </ItemGroup>
   <ItemGroup>
-    <Resource Include="Picture\A346R4.jpg" />
-    <Resource Include="Picture\A543T6.jpg" />
-    <Resource Include="Picture\B730E2.jpg" />
-    <Resource Include="Picture\D419T7.png" />
-    <Resource Include="Picture\F719R5.jpg" />
-    <Resource Include="Picture\G278R6.png" />
-    <Resource Include="Picture\H452A3.png" />
-    <Resource Include="Picture\picture.png" />
-    <Resource Include="Picture\R259E6.jpg" />
-    <Resource Include="Picture\T564P5.jpg" />
-    <Resource Include="Picture\А112Т4.jpg" />
+    <Content Include="Picture\A346R4.jpg">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Picture\A543T6.jpg">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Picture\B730E2.jpg">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Picture\D419T7.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Picture\F719R5.jpg">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Picture\G278R6.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Picture\H452A3.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Picture\picture.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Picture\R259E6.jpg">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Picture\T564P5.jpg">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Picture\А112Т4.jpg">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
   </ItemGroup>
   <ItemGroup>
     <Content Include="Model1.Context.tt">