Imagara vor 3 Jahren
Ursprung
Commit
aa59af0446

+ 51 - 0
PartsWarehouse/ConfirmationWindow.xaml

@@ -0,0 +1,51 @@
+<Window x:Class="PartsWarehouse.ConfirmationWindow"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:PartsWarehouse"
+        mc:Ignorable="d"
+        Title="ConfirmationWindow" 
+        MinHeight="120" 
+        Height="120"
+        Width="300" 
+        WindowStartupLocation="CenterScreen" 
+        WindowStyle="None" 
+        ResizeMode="NoResize">
+    <Grid Background="#FF2D2D2D">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="27*"/>
+            <RowDefinition Height="13*"/>
+        </Grid.RowDefinitions>
+        <TextBlock Name="ErrorLabel" 
+               Text="Вы действительно хотите это сделать?" 
+               TextWrapping="Wrap"
+               HorizontalAlignment="Center" 
+               Margin="19,10,19,0" 
+               VerticalAlignment="Top" 
+               Width="262"
+                   Background="{x:Null}"
+                   Foreground="{StaticResource TextColor}">
+        </TextBlock>
+        <Grid Grid.Row="1">
+            <StackPanel Orientation="Horizontal"
+                        HorizontalAlignment="Center"
+                        VerticalAlignment="Center">
+                <Button Content="Да" 
+                VerticalAlignment="Bottom" 
+                HorizontalAlignment="Center" 
+                Height="30" 
+                Width="130" 
+                        Margin="0,0,5,0"
+                Click="YesButton"/>
+                <Button Content="Нет" 
+                VerticalAlignment="Bottom" 
+                HorizontalAlignment="Center" 
+                Height="30" 
+                Width="130"
+                        Margin="5,0,0,0"
+                Click="NoButton"/>
+            </StackPanel>
+        </Grid>
+    </Grid>
+</Window>

+ 39 - 0
PartsWarehouse/ConfirmationWindow.xaml.cs

@@ -0,0 +1,39 @@
+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 PartsWarehouse
+{
+    /// <summary>
+    /// Логика взаимодействия для ConfirmationWindow.xaml
+    /// </summary>
+    public partial class ConfirmationWindow : Window
+    {
+        public bool answer;
+        public ConfirmationWindow(bool _answer = false)
+        {
+            InitializeComponent();
+            answer = _answer;
+        }
+        private void YesButton(object sender, RoutedEventArgs e)
+        {
+            answer = true;
+            this.Close();
+        }
+        private void NoButton(object sender, RoutedEventArgs e)
+        {
+            answer = false;
+            this.Close();
+        }
+    }
+}

+ 2 - 3
PartsWarehouse/EDM.edmx

@@ -4,7 +4,7 @@
   <edmx:Runtime>
     <!-- SSDL content -->
     <edmx:StorageModels>
-      <Schema Namespace="Хранилище gr692_gavModel" Provider="System.Data.SqlClient" ProviderManifestToken="2012" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
+    <Schema Namespace="Хранилище gr692_gavModel" Provider="System.Data.SqlClient" ProviderManifestToken="2012" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
         <EntityType Name="Car">
           <Key>
             <PropertyRef Name="IdCar" />
@@ -101,8 +101,7 @@
             <End Role="UserCar" EntitySet="UserCar" />
           </AssociationSet>
         </EntityContainer>
-      </Schema>
-    </edmx:StorageModels>
+      </Schema></edmx:StorageModels>
     <!-- CSDL content -->
     <edmx:ConceptualModels>
       <Schema Namespace="gr692_gavModel" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">

+ 6 - 0
PartsWarehouse/PartInfoPage.xaml

@@ -160,6 +160,12 @@
                 </Button>
                 <Button Width="120"
                         Margin="5,0,5,0"
+                        Content="Удалить"
+                        FontSize="20"
+                        Click="DeleteButton">
+                </Button>
+                <Button Width="120"
+                        Margin="5,0,5,0"
                         Content="Сохранить"
                         FontSize="20"
                         Click="SaveButton">

+ 22 - 5
PartsWarehouse/PartInfoPage.xaml.cs

@@ -88,6 +88,24 @@ namespace PartsWarehouse
         {
             NavigationService.Navigate(new СatalogPage());
         }
+        private void DeleteButton(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                ConfirmationWindow confWindow = new ConfirmationWindow();
+                confWindow.ShowDialog();
+                if (confWindow.answer)
+                {
+                    cnt.db.Parts.Remove(part);
+                    cnt.db.SaveChanges();
+                    NavigationService.Navigate(new СatalogPage());
+                }
+            }
+            catch
+            {
+                MessageBox.Show("Ошибка удаления записи.");
+            }
+        }
         private void SaveButton(object sender, RoutedEventArgs e)
         {
             if (!newPart)
@@ -120,16 +138,15 @@ namespace PartsWarehouse
                 {
                     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,
+                        IdCar = cnt.db.Parts.Where(item => item.Car.Company == manufacturer && item.Car.Name == name).Select(item => item.Car.IdCar).FirstOrDefault(),
+                        Type = PartType.Text,
                         Name = PartName.Text,
                         Manufacturer = PartManufacturer.Text,
                         Description = PartDesc.Text,
-                        //Image = PartImage.Source != null ? ImagesManip.BitmapSourceToByteArray((BitmapSource)PartImage.Source) : null,
+                        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),
@@ -148,4 +165,4 @@ namespace PartsWarehouse
         }
     }
 
-}
+}

+ 7 - 0
PartsWarehouse/PartsWarehouse.csproj

@@ -71,6 +71,9 @@
       <DependentUpon>ChangePasswordWindow.xaml</DependentUpon>
     </Compile>
     <Compile Include="cnt.cs" />
+    <Compile Include="ConfirmationWindow.xaml.cs">
+      <DependentUpon>ConfirmationWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="EDM.Context.cs">
       <AutoGen>True</AutoGen>
       <DesignTime>True</DesignTime>
@@ -122,6 +125,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="ConfirmationWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="ErrorWindow.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 23 - 0
PartsWarehouse/sysdiagrams.cs

@@ -0,0 +1,23 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     Этот код создан по шаблону.
+//
+//     Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
+//     Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace PartsWarehouse
+{
+    using System;
+    using System.Collections.Generic;
+    
+    public partial class sysdiagrams
+    {
+        public string name { get; set; }
+        public int principal_id { get; set; }
+        public int diagram_id { get; set; }
+        public Nullable<int> version { get; set; }
+        public byte[] definition { get; set; }
+    }
+}