Imagara %!s(int64=3) %!d(string=hai) anos
pai
achega
1cb57e0491

+ 1 - 1
PartsWarehouse/EDM.Designer.cs

@@ -1,4 +1,4 @@
-// Создание кода T4 для модели "C:\Users\gr692_gav\source\repos\PartsWarehouse\PartsWarehouse\EDM.edmx" включено. 
+// Создание кода T4 для модели "C:\Users\milic\source\repos\PartsWarehouse\PartsWarehouse\EDM.edmx" включено. 
 // Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора
 // на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель
 // открыта в конструкторе.

+ 4 - 4
PartsWarehouse/EDM.edmx.diagram

@@ -5,10 +5,10 @@
     <!-- Diagram content (shape and connector positions) -->
     <edmx:Diagrams>
       <Diagram DiagramId="3e84710fb915458c9ceb6f55a728192a" Name="Diagram1">
-        <EntityTypeShape EntityType="gr692_gavModel.Car" Width="1.5" PointX="0.75" PointY="4.5" IsExpanded="true" />
-        <EntityTypeShape EntityType="gr692_gavModel.Parts" Width="1.5" PointX="3" PointY="4" IsExpanded="true" />
-        <EntityTypeShape EntityType="gr692_gavModel.User" Width="1.5" PointX="3.75" PointY="0.75" IsExpanded="true" />
-        <EntityTypeShape EntityType="gr692_gavModel.UserCar" Width="1.5" PointX="6" PointY="4.5" IsExpanded="true" />
+        <EntityTypeShape EntityType="gr692_gavModel.Car" Width="1.5" PointX="4.5" PointY="3.625" IsExpanded="true" />
+        <EntityTypeShape EntityType="gr692_gavModel.Parts" Width="1.5" PointX="0.875" PointY="3.125" IsExpanded="true" />
+        <EntityTypeShape EntityType="gr692_gavModel.User" Width="1.5" PointX="0.875" PointY="0.625" IsExpanded="true" />
+        <EntityTypeShape EntityType="gr692_gavModel.UserCar" Width="1.5" PointX="4.625" PointY="0.5" IsExpanded="true" />
         <AssociationConnector Association="gr692_gavModel.FK_Parts_Car" ManuallyRouted="false" />
         <AssociationConnector Association="gr692_gavModel.FK_UserCar_Car" ManuallyRouted="false" />
         <AssociationConnector Association="gr692_gavModel.FK_UserCar_User" ManuallyRouted="false" />

+ 5 - 7
PartsWarehouse/ErrorWindow.xaml

@@ -6,7 +6,8 @@
         xmlns:local="clr-namespace:PartsWarehouse"
         mc:Ignorable="d"
         Title="ErrorWindow" 
-        Height="120" 
+        MinHeight="120" 
+        Height="120"
         Width="300" 
         WindowStartupLocation="CenterScreen" 
         WindowStyle="None" 
@@ -18,9 +19,9 @@
                HorizontalAlignment="Center" 
                Margin="19,10,19,0" 
                VerticalAlignment="Top" 
-               Height="55" 
-               Width="262" 
-               Foreground="White">
+               Width="262"
+                   Background="{x:Null}"
+                   Foreground="{StaticResource TextColor}">
         </TextBlock>
         <Button Content="Закрыть" 
                 VerticalAlignment="Bottom" 
@@ -29,8 +30,5 @@
                 Width="130" 
                 Margin="0,0,0,15" 
                 Click="BackClick"/>
-        <Border BorderBrush="Black"
-                BorderThickness="2">
-        </Border>
     </Grid>
 </Window>

+ 6 - 4
PartsWarehouse/ImagesManip.cs

@@ -23,11 +23,13 @@ namespace PartsWarehouse
         public static BitmapImage SelectImage()
         {
             #region Выбор картинки
-            OpenFileDialog op = new OpenFileDialog();
-            op.Title = "Выбрать изображение";
-            op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
+            OpenFileDialog op = new OpenFileDialog
+            {
+                Title = "Выбрать изображение",
+                Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                         "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
-                        "Portable Network Graphic (*.png)|*.png";
+                        "Portable Network Graphic (*.png)|*.png"
+            };
             if (op.ShowDialog() == true)
                 return new BitmapImage(new Uri(op.FileName));
             else

+ 134 - 10
PartsWarehouse/PartInfoPage.xaml

@@ -5,15 +5,17 @@
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       xmlns:local="clr-namespace:PartsWarehouse"
       mc:Ignorable="d" 
-      d:DesignHeight="450" d:DesignWidth="800"
+      d:DesignHeight="450" 
+      d:DesignWidth="800"
       Title="PartInfoPage"
       Background="#32353B">
 
     <Grid Background="#2F3136"
           Margin="10">
         <Grid.RowDefinitions>
-            <RowDefinition/>
-            <RowDefinition/>
+            <RowDefinition Height="215*"/>
+            <RowDefinition Height="173*"/>
+            <RowDefinition Height="42*"/>
         </Grid.RowDefinitions>
 
         <Grid Grid.Row="0">
@@ -23,26 +25,148 @@
             </Grid.ColumnDefinitions>
 
             <Image Name="PartImage"
-                       Grid.Column="0"
-                       Margin="10"
-                       Source="/Resources/NotFound.png">
+                   Grid.Column="0"
+                   Margin="10"
+                   MouseDown="PartImage_MouseDown">
             </Image>
 
             <Grid Grid.Column="1"
                   Margin="10"
                   Background="#FF44464D">
                 <Grid.RowDefinitions>
-                    <RowDefinition Height="17*"/>
-                    <RowDefinition Height="22*"/>
+                    <RowDefinition/>
+                    <RowDefinition/>
+                    <RowDefinition/>
+                    <RowDefinition/>
                 </Grid.RowDefinitions>
+                <StackPanel Grid.Row="0"
+                            Orientation="Horizontal">
+                    <TextBox Name="PartManufacturer"
+                             Text="Производитель"
+                             FontSize="22"
+                             Background="{x:Null}"
+                             BorderBrush="{x:Null}"
+                             MinWidth="50"
+                             PreviewMouseDown="PartManufacturer_PreviewMouseDown"
+                             LostFocus="PartManufacturer_LostFocus">
+                    </TextBox>
+                    <TextBox Name="PartName"
+                         Text="Название детали"
+                         FontSize="22"
+                             MinWidth="50"
+                         Background="{x:Null}"
+                         BorderBrush="{x:Null}"
+                         PreviewMouseDown="PartNameManufacturer_PreviewMouseDown"
+                         LostFocus="PartNameManufacturer_LostFocus">
+                    </TextBox>
+                </StackPanel>
 
+                <StackPanel Grid.Row="1" 
+                            Orientation="Horizontal">
+                    <Label Content="Осталось: "
+                           FontSize="22">
+                    </Label>
+                    <TextBox Name="PartRemain"
+                             MinWidth="35"
+                             Height="35"
+                             FontSize="22"
+                             Background="{x:Null}">
+                    </TextBox>
+                </StackPanel>
+                <StackPanel Grid.Row="2"
+                            Orientation="Horizontal">
+                    <Label Content="Цена: "
+                           FontSize="22">
+                    </Label>
+                    <TextBox Name="PartPrice"
+                             MinWidth="35"
+                             Height="35"
+                             FontSize="22"
+                             Background="{x:Null}">
+                    </TextBox>
+                    <Label Content="руб."
+                           FontSize="22">
+                    </Label>
+                </StackPanel>
+                <StackPanel Grid.Row="3"
+                            Orientation="Horizontal">
+                    <Label Content="Модель: "
+                           FontSize="22">
+                    </Label>
+                    <TextBox Name="PartNum"
+                             MinWidth="35"
+                             Height="35"
+                             FontSize="22"
+                             Background="{x:Null}">
+                    </TextBox>
+                </StackPanel>
             </Grid>
         </Grid>
 
-        <Grid Grid.Row="1">
-
+        <Grid Grid.Row="1"
+              Background="#FF44464D">
+            <Grid.RowDefinitions>
+                <RowDefinition/>
+                <RowDefinition/>
+                <RowDefinition/>
+                <RowDefinition/>
+            </Grid.RowDefinitions>
+            <TextBox Name="PartCar"
+                     Grid.Row="0"
+                     Text="Подходит к:"
+                             FontSize="22"
+                             Background="{x:Null}"
+                             BorderBrush="{x:Null}"
+                             MinWidth="50">
+            </TextBox>
+            <TextBox Name="PartType"
+                     Grid.Row="1"
+                     Text="Тип"
+                             FontSize="22"
+                             Background="{x:Null}"
+                             BorderBrush="{x:Null}"
+                             MinWidth="50">
+            </TextBox>
+            <TextBox Name="PartIsOriginal"
+                     Grid.Row="2"
+                     Text="Оригинал/Не оригинал"
+                             FontSize="22"
+                             Background="{x:Null}"
+                             BorderBrush="{x:Null}"
+                             MinWidth="50">
+            </TextBox>
+            
+            <TextBox Name="PartDesc"
+                       Grid.Row="3"
+                       Text="Описание"
+                       PreviewMouseDown="PartDesc_PreviewMouseDown"
+                       LostFocus="PartDesc_LostFocus"
+                       Foreground="{StaticResource TextColor}"
+                     FontSize="22"
+                             Background="{x:Null}"
+                             BorderBrush="{x:Null}"
+                             MinWidth="50">
+            </TextBox>
         </Grid>
 
+        <Grid Grid.Row="2">
+            <StackPanel Orientation="Horizontal" 
+                        HorizontalAlignment="Center">
+                <Button Width="120"
+                        Margin="5,0,5,0"
+                        Content="Назад"
+                        FontSize="20"
+                        Click="BackButton">
+                </Button>
+                <Button Width="120"
+                        Margin="5,0,5,0"
+                        Content="Сохранить"
+                        FontSize="20"
+                        Click="SaveButton">
+                </Button>
+            </StackPanel>
+
+        </Grid>
 
 
 

+ 130 - 11
PartsWarehouse/PartInfoPage.xaml.cs

@@ -1,32 +1,151 @@
 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 PartsWarehouse
 {
     public partial class PartInfoPage : Page
     {
         Parts part;
+        bool newPart;
         public PartInfoPage(int partId)
         {
             InitializeComponent();
-            part = cnt.db.Parts.Where(item => item.IdPart == partId).FirstOrDefault();
-            if (part.Image == null)
-                PartImage.Source = new BitmapImage(new Uri("../Resources/NotFound.png", UriKind.RelativeOrAbsolute));
+            if (cnt.db.Parts.Select(item => item.IdPart).Contains(partId))
+            {
+                newPart = false;
+                part = cnt.db.Parts.Where(item => item.IdPart == partId).FirstOrDefault();
+                if (part.Image == null)
+                    PartImage.Source = new BitmapImage(new Uri("../Resources/NotFound.png", UriKind.RelativeOrAbsolute));
+                else
+                    PartImage.Source = ImagesManip.NewImage(part);
+                PartName.Text = part.Name;
+                PartDesc.Text = part.Description;
+                PartPrice.Text = part.Price.ToString();
+                PartRemain.Text = part.Remain.ToString();
+                PartNum.Text = part.PartNum.ToString();
+                PartCar.Text = $"{part.Car.Company} {part.Car.Name}";
+                PartType.Text = part.Type;
+                PartIsOriginal.Text = part.Original;
+                PartManufacturer.Text = part.Manufacturer;
+            }
             else
-                PartImage.Source = ImagesManip.NewImage(part);
+            {
+                newPart = true;
+                PartImage.Source = new BitmapImage(new Uri("../Resources/Plus.png", UriKind.RelativeOrAbsolute));
+            }
+        }
+
+        private void PartNameManufacturer_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+
+        }
+
+        private void PartNameManufacturer_LostFocus(object sender, RoutedEventArgs e)
+        {
+
+        }
+
+        private void PartDesc_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+
+        }
+
+        private void PartDesc_LostFocus(object sender, RoutedEventArgs e)
+        {
+
+        }
+        private void PartManufacturer_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+
+        }
+
+        private void PartManufacturer_LostFocus(object sender, RoutedEventArgs e)
+        {
+
+        }
+
+        private void PartImage_MouseDown(object sender, MouseButtonEventArgs e)
+        {
+            try
+            {
+                BitmapImage image = ImagesManip.SelectImage();
+                if (image != null)
+                    PartImage.Source = image;
+            }
+            catch (Exception ex)
+            {
+                new ErrorWindow(ex.ToString()).ShowDialog();
+            }
+
+        }
+
+        private void BackButton(object sender, RoutedEventArgs e)
+        {
+            NavigationService.Navigate(new СatalogPage());
+        }
+        private void SaveButton(object sender, RoutedEventArgs e)
+        {
+            if (!newPart)
+            {
+                try
+                {
+                    part.Image = ImagesManip.BitmapSourceToByteArray((BitmapSource)PartImage.Source);
+                    part.Name = PartName.Text;
+                    part.Remain = Convert.ToInt32(PartRemain.Text);
+                    part.Price = Convert.ToDouble(PartPrice.Text);
+                    part.PartNum = Convert.ToInt32(PartNum.Text);
+                    part.Description = PartDesc.Text;
+                    part.Manufacturer = PartManufacturer.Text;
+                    string manufacturer = PartCar.Text.Substring(0, PartCar.Text.IndexOf(' ')),
+                           name = PartCar.Text.Substring(PartCar.Text.IndexOf(' ') + 1, PartCar.Text.Length - PartCar.Text.IndexOf(' ') - 1);
+                    part.IdCar = cnt.db.Parts.Where(item => item.Car.Company == manufacturer && item.Car.Name == name).Select(item => item.IdCar).FirstOrDefault();
+                    part.Type = PartType.Text;
+                    part.Original = PartIsOriginal.Text;
+                    cnt.db.SaveChanges();
+                    NavigationService.Navigate(new СatalogPage());
+                }
+                catch (Exception ex)
+                {
+                    MessageBox.Show(ex.ToString());
+                }
+            }
+            else
+            {
+                try
+                {
+                    string manufacturer = PartCar.Text.Substring(0, PartCar.Text.IndexOf(' ')),
+                           name = PartCar.Text.Substring(PartCar.Text.IndexOf(' ') + 1, PartCar.Text.Length - PartCar.Text.IndexOf(' ') - 1);
+                    MessageBox.Show($"|{manufacturer}|{name}|");
+                    Parts part = new Parts()
+                    {
+                        IdPart = cnt.db.Parts.Select(p => p.IdPart).DefaultIfEmpty(0).Max() + 1,
+                        IdCar = cnt.db.Parts.Where(item => item.Car.Company == manufacturer && item.Car.Name == name).Select(item => item.IdCar).FirstOrDefault(),
+                    Type = PartType.Text,
+                        Name = PartName.Text,
+                        Manufacturer = PartManufacturer.Text,
+                        Description = PartDesc.Text,
+                        //Image = PartImage.Source != null ? ImagesManip.BitmapSourceToByteArray((BitmapSource)PartImage.Source) : null,
+                        Remain = Convert.ToInt32(PartRemain.Text),
+                        Price = Convert.ToDouble(PartPrice.Text),
+                        PartNum = Convert.ToInt32(PartNum.Text),
+                        Original = PartIsOriginal.Text
+                    };
+                    cnt.db.Parts.Add(part);
+                    cnt.db.SaveChanges();
+                    NavigationService.Navigate(new СatalogPage());
+                }
+                catch (Exception ex)
+                {
+                    MessageBox.Show(ex.ToString());
+                }
+            }
 
         }
     }
+
 }

+ 1 - 0
PartsWarehouse/PartsWarehouse.csproj

@@ -211,6 +211,7 @@
       <DependentUpon>EDM.edmx</DependentUpon>
       <LastGenOutput>EDM.cs</LastGenOutput>
     </Content>
+    <Resource Include="Resources\Plus.png" />
     <Resource Include="Resources\NotFound.png" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

+ 27 - 20
PartsWarehouse/ProfilePage.xaml.cs

@@ -42,17 +42,21 @@ namespace PartsWarehouse
 
             try
             {
-                Grid addCarGrid = new Grid();
-                addCarGrid.Height = 35;
-                addCarGrid.Width = 485;
-                addCarGrid.Margin = new Thickness(10, 0, 10, 0);
+                Grid addCarGrid = new Grid
+                {
+                    Height = 35,
+                    Width = 485,
+                    Margin = new Thickness(10, 0, 10, 0)
+                };
 
-                Button addCarButton = new Button();
-                addCarButton.Width = 35;
-                addCarButton.Height = 35;
-                addCarButton.FontSize=16;
-                addCarButton.Content = "+";
-                addCarButton.FontWeight = FontWeights.Black;
+                Button addCarButton = new Button
+                {
+                    Width = 35,
+                    Height = 35,
+                    FontSize = 16,
+                    Content = "+",
+                    FontWeight = FontWeights.Black,
+                };
                 addCarButton.Click += AddNewCar;
 
                 CarsListBox.Items.Add(addCarGrid);
@@ -70,17 +74,20 @@ namespace PartsWarehouse
         }
         private void AddCar(string company, string name, int generation, string vin)
         {
-            Grid messageGrid = new Grid();
-            messageGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x44, 0x46, 0x4D));
-            messageGrid.Height = 35;
-            messageGrid.Width = 480;
-            messageGrid.Margin = new Thickness(10, 5, 10, 5);
-
+            Grid messageGrid = new Grid
+            {
+                Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x44, 0x46, 0x4D)),
+                Height = 35,
+                Width = 480,
+                Margin = new Thickness(10, 5, 10, 5)
+            };
 
-            Label carLabel = new Label();
-            carLabel.Content = company + " " + name + " " + generation + "gen." + " (vin: " + vin + ")";
-            carLabel.HorizontalAlignment = HorizontalAlignment.Left;
-            carLabel.Margin = new Thickness(5);
+            Label carLabel = new Label
+            {
+                Content = company + " " + name + " " + generation + "gen." + " (vin: " + vin + ")",
+                HorizontalAlignment = HorizontalAlignment.Left,
+                Margin = new Thickness(5)
+            };
 
             messageGrid.Children.Add(carLabel);
 

+ 1 - 1
PartsWarehouse/RegisterWindow.xaml.cs

@@ -42,7 +42,7 @@ namespace PartsWarehouse
                         Password = Encrypt.GetHash(PassBox.Password),
                     };
                     cnt.db.User.Add(newUser);
-                    cnt.db.SaveChanges(); ;
+                    cnt.db.SaveChanges();
                     new ErrorWindow("Успешная регистрация").ShowDialog();
                     new LoginWindow().Show();
                     this.Close();

BIN=BIN
PartsWarehouse/Resources/Plus.png


+ 8 - 1
PartsWarehouse/Session.cs

@@ -2,7 +2,14 @@
 {
     public class Session
     {
-        public static int userId = 1; //{ get; set; }
+        public static int userId { get; set; }
         public static int carId { get; set; }
+        public static string partCarCompany { get; set; }
+        public static string partCarName { get; set; }
+        public static string partCarGeneration { get; set; }
+        public static string partType { get; set; }
+        public static string partName { get; set; }
+        public static string partNum { get; set; }
+        public static string partIsOriginal { get; set; }
     }
 }

+ 4 - 7
PartsWarehouse/Styles/Style.xaml

@@ -2,13 +2,10 @@
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     x:Class="PartsWarehouse.Style">
 
-
-    <LinearGradientBrush x:Key="TextColor">
-        <GradientStopCollection>
-            <GradientStop Color="White" Offset="0"/>
-        </GradientStopCollection>
-    </LinearGradientBrush>
-
+    <SolidColorBrush x:Key="TextColor" 
+                     Color="White">
+    </SolidColorBrush>
+    
     <Style TargetType="Label">
         <Setter Property="Foreground" Value="White"/>
     </Style>

+ 41 - 28
PartsWarehouse/СatalogPage.xaml

@@ -17,88 +17,101 @@
         <Border CornerRadius="15" 
                 Background="#2F3136" 
                 Margin="5">
-            <Grid Grid.Row="0">
-                <Grid.RowDefinitions>
-                    <RowDefinition/>
-                    <RowDefinition/>
-                </Grid.RowDefinitions>
+            <StackPanel Grid.Row="0"
+                        Orientation="Horizontal"
+                        HorizontalAlignment="Center">
+                <Grid Grid.Row="0">
+                    <Grid.RowDefinitions>
+                        <RowDefinition/>
+                        <RowDefinition/>
+                    </Grid.RowDefinitions>
 
-                <StackPanel Orientation="Horizontal"
+
+                    <StackPanel Orientation="Horizontal"
                             Grid.Row="0"
                             HorizontalAlignment="Center">
-                    <TextBox Name="CarCompanyBox"
+                        <TextBox Name="CarCompanyBox"
                              Margin="5"
                              Width="120"
                              Text="Марка"
                              PreviewMouseDown="CarCompanyBox_PreviewMouseLeftButtonUp"
                              LostFocus="CarCompanyBox_LostFocus">
-                    </TextBox>
+                        </TextBox>
 
-                    <TextBox Name="CarNameBox"
+                        <TextBox Name="CarNameBox"
                              Margin="5"
                              Width="120"
                              Text="Название"
                              PreviewMouseDown="CarNameBox_PreviewMouseLeftButtonUp"
                              LostFocus="CarNameBox_LostFocus">
-                    </TextBox>
+                        </TextBox>
 
-                    <TextBox Name="CarGenerationBox"
+                        <TextBox Name="CarGenerationBox"
                              Margin="5"
                              Width="120"
                              Text="Поколение"
                              PreviewMouseDown="CarGenerationBox_PreviewMouseLeftButtonUp"
                              LostFocus="CarGenerationBox_LostFocus">
 
-                    </TextBox>
+                        </TextBox>
 
-                    <TextBox Name="PartTypeBox"
+                        <TextBox Name="PartTypeBox"
                              Margin="5"
                              Width="120"
                              Text="Тип запчасти"
                              PreviewMouseDown="PartTypeBox_PreviewMouseLeftButtonUp"
                              LostFocus="PartTypeBox_LostFocus">
 
-                    </TextBox>
-                </StackPanel>
+                        </TextBox>
+                    </StackPanel>
 
-                <StackPanel Orientation="Horizontal"
+                    <StackPanel Orientation="Horizontal"
                             Grid.Row="1"
                             HorizontalAlignment="Center">
-                    <TextBox Name="NameBox"
+                        <TextBox Name="NameBox"
                               Margin="5"
                               Width="120"
                               Text="Название запчасти"
                              PreviewMouseDown="NameBox_PreviewMouseLeftButtonUp"
                              LostFocus="NameBox_LostFocus">
 
-                    </TextBox>
+                        </TextBox>
 
-                    <TextBox Name="ModelBox"
+                        <TextBox Name="ModelBox"
                              Margin="5"
                              Width="120"
                              Text="Модель"
                              PreviewMouseDown="ModelBox_PreviewMouseLeftButtonUp"
                              LostFocus="ModelBox_LostFocus">
-                    </TextBox>
+                        </TextBox>
 
-                    <TextBox Name="OriginalBox"
+                        <TextBox Name="OriginalBox"
                              Margin="5"
                              Width="120"
                              Text="Оригинал: Не важно"
                              PreviewMouseDown="OriginalBox_PreviewMouseLeftButtonUp"
                              LostFocus="OriginalBox_LostFocus">
-                    </TextBox>
+                        </TextBox>
 
-                    <Button Name="FindPartButton"
+                        <Button Name="FindPartButton"
                             Margin="5"
                             Width="120"
                             Content="Поиск"
                             Click="FindPartButton_Click">
-                    </Button>
-
-                </StackPanel>
-
-            </Grid>
+                        </Button>
+
+                    </StackPanel>
+
+                </Grid>
+                <Button Height="45"
+                        Width="45"
+                        Content="+"
+                        FontSize="30"
+                        Click="AddPartButton_Click">
+                </Button>
+            </StackPanel>
+            
+            
         </Border>
 
         <ListBox Name="PartsListBox"

+ 114 - 32
PartsWarehouse/СatalogPage.xaml.cs

@@ -20,8 +20,31 @@ namespace PartsWarehouse
                 CarNameBox.Text = carName;
                 CarGenerationBox.Text = carGeneration.ToString();
             }
-        }
+            #region history
+            if (Session.partCarCompany != null)
+                CarCompanyBox.Text = Session.partCarCompany;
+
+            if (Session.partCarName != null)
+                CarNameBox.Text = Session.partCarName;
+
+            if (Session.partCarGeneration != null)
+                CarGenerationBox.Text = Session.partCarGeneration;
+
+            if (Session.partName != null)
+                NameBox.Text = Session.partName;
+
+            if (Session.partNum != null)
+                ModelBox.Text = Session.partNum;
+
+            if (Session.partCarCompany != null)
+                CarCompanyBox.Text = Session.partCarCompany;
 
+            if (Session.partIsOriginal != null)
+                OriginalBox.Text = Session.partIsOriginal;
+            #endregion
+            PartsUpdate();
+        }
+        #region LostAndPreview
         private void CarCompanyBox_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
         {
             CarCompanyBox.Text = string.Empty;
@@ -99,13 +122,26 @@ namespace PartsWarehouse
                 OriginalBox.Text = "Оригинал: Не важно";
         }
 
+        #endregion
         private void FindPartButton_Click(object sender, RoutedEventArgs e)
         {
             PartsUpdate();
         }
         private void OpenPartInfoPage(object sender, RoutedEventArgs e)
         {
-            NavigationService.Navigate(new PartInfoPage(1));
+            try
+            {
+                int partIdFromSender = Convert.ToInt32(((Label)sender).Content.ToString());
+                Parts part = cnt.db.Parts.Where(item => item.PartNum == partIdFromSender).FirstOrDefault();
+                if (part != null)
+                {
+                    NavigationService.Navigate(new PartInfoPage(part.IdPart));
+                }
+            }
+            catch (Exception ex)
+            {
+                new ErrorWindow(ex.ToString()).ShowDialog();
+            }
         }
         private void PartsUpdate()
         {
@@ -114,19 +150,40 @@ namespace PartsWarehouse
                 PartsListBox.Items.Clear();
                 var list = cnt.db.Parts.ToList();
                 if (CarCompanyBox.Text != "Марка")
+                {
                     list = list.Where(item => item.Car.Company == CarCompanyBox.Text).ToList();
+                    Session.partCarCompany = CarCompanyBox.Text;
+                }
                 if (CarNameBox.Text != "Название")
+                {
                     list = list.Where(item => item.Car.Name == CarNameBox.Text).ToList();
+                    Session.partCarName = CarNameBox.Text;
+                }
                 if (CarGenerationBox.Text != "Поколение")
+                {
                     list = list.Where(item => item.Car.Generation == Convert.ToInt32(CarGenerationBox.Text)).ToList();
+                    Session.partCarGeneration = CarGenerationBox.Text;
+                }
                 if (PartTypeBox.Text != "Тип запчасти")
+                {
                     list = list.Where(item => item.Type == PartTypeBox.Text).ToList();
+                    Session.partType = PartTypeBox.Text;
+                }
                 if (NameBox.Text != "Название запчасти")
+                {
                     list = list.Where(item => item.Name == NameBox.Text).ToList();
+                    Session.partName = NameBox.Text;
+                }
                 if (ModelBox.Text != "Модель")
+                {
                     list = list.Where(item => item.PartNum == Convert.ToInt32(ModelBox.Text)).ToList();
+                    Session.partNum = ModelBox.Text;
+                }
                 if (OriginalBox.Text != "Оригинал: Не важно")
+                {
                     list = list.Where(item => item.Original == OriginalBox.Text).ToList();
+                    Session.partIsOriginal = OriginalBox.Text;
+                }
                 foreach (Parts part in list)
                 {
                     BitmapImage img = new BitmapImage();
@@ -145,49 +202,74 @@ namespace PartsWarehouse
         }
         private void AddPart(string name, string desc, int partNum, BitmapImage imageSource, int remain, double price)
         {
-            Grid partGrid = new Grid();
-            partGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x40, 0x44, 0x4B));
-            partGrid.Height = 45;
-            partGrid.Width = 590;
-            partGrid.Margin = new Thickness(10, 5, 10, 5);
-
-            Image partImage = new Image();
-            partImage.Source = imageSource;
-            partImage.Width = 35;
-            partImage.Height = 35;
-            partImage.Margin = new Thickness(5);
-            partImage.HorizontalAlignment = HorizontalAlignment.Left;
+            Grid partGrid = new Grid
+            {
+                Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x40, 0x44, 0x4B)),
+                Height = 45,
+                Width = 590,
+                Margin = new Thickness(10, 5, 10, 5)
+            };
+
+            Image partImage = new Image
+            {
+                Source = imageSource,
+                Width = 35,
+                Height = 35,
+                Margin = new Thickness(5),
+                HorizontalAlignment = HorizontalAlignment.Left
+            };
+
             partGrid.Children.Add(partImage);
 
-            StackPanel stackpanel = new StackPanel();
-            stackpanel.Orientation = Orientation.Horizontal;
+            StackPanel stackpanel = new StackPanel
+            {
+                Orientation = Orientation.Horizontal
+            };
 
-            Label partNameLabel = new Label();
-            partNameLabel.Content = name;
-            partNameLabel.Foreground = Brushes.White;
-            partNameLabel.FontWeight = FontWeights.Bold;
-            partNameLabel.HorizontalAlignment = HorizontalAlignment.Left;
-            partNameLabel.VerticalAlignment = VerticalAlignment.Top;
-            partNameLabel.Margin = new Thickness(40, 0, 0, 0);
+            Label partNameLabel = new Label
+            {
+                Content = name,
+                Foreground = Brushes.White,
+                FontWeight = FontWeights.Bold,
+                HorizontalAlignment = HorizontalAlignment.Left,
+                VerticalAlignment = VerticalAlignment.Top,
+                Margin = new Thickness(40, 0, 0, 0)
+            };
 
-            Label partNumLabel = new Label();
-            partNumLabel.Content = $"модель: {partNum}, остаток {remain} по {price}руб.";
-            partNumLabel.Foreground = Brushes.White;
+            Label partNumLabel = new Label
+            {
+                Content = partNum.ToString(),
+                Foreground = Brushes.White,
+            };
             partNumLabel.MouseDown += OpenPartInfoPage;
 
+            Label partRemainPrice = new Label
+            {
+                Content = $"Осталось: {price} по {remain}руб.",
+                Foreground = Brushes.White,
+            };
+
             stackpanel.Children.Add(partNameLabel);
             stackpanel.Children.Add(partNumLabel);
+            stackpanel.Children.Add(partRemainPrice);
             partGrid.Children.Add(stackpanel);
 
-            Label descLabel = new Label();
-            descLabel.Content = desc;
-            descLabel.Foreground = Brushes.White;
-            descLabel.HorizontalAlignment = HorizontalAlignment.Left;
-            descLabel.VerticalAlignment = VerticalAlignment.Bottom;
-            descLabel.Margin = new Thickness(40, 0, 0, 0);
+            Label descLabel = new Label
+            {
+                Content = desc,
+                Foreground = Brushes.White,
+                HorizontalAlignment = HorizontalAlignment.Left,
+                VerticalAlignment = VerticalAlignment.Bottom,
+                Margin = new Thickness(40, 0, 0, 0)
+            };
             partGrid.Children.Add(descLabel);
 
             PartsListBox.Items.Add(partGrid);
         }
+
+        private void AddPartButton_Click(object sender, RoutedEventArgs e)
+        {
+            NavigationService.Navigate(new PartInfoPage(cnt.db.Parts.Select(p => p.IdPart).DefaultIfEmpty(0).Max() + 1));
+        }
     }
 }