Răsfoiți Sursa

Удаление записи

Barsik Kato 2 ani în urmă
părinte
comite
766daa97f1
2 a modificat fișierele cu 23 adăugiri și 2 ștergeri
  1. 3 2
      Session1/Windows/EditAgent.xaml
  2. 20 0
      Session1/Windows/EditAgent.xaml.cs

+ 3 - 2
Session1/Windows/EditAgent.xaml

@@ -5,7 +5,7 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:Session1"
         mc:Ignorable="d"
-        Title="EditAgent" Height="480" Width="800">
+        Title="EditAgent" Height="499.5" Width="800">
     <Grid>
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="191*"/>
@@ -15,7 +15,7 @@
         <GroupBox Header="Изображение">
             <StackPanel Grid.Column="0" VerticalAlignment="Center">
                 <Image x:Name="agentImg" Height="150" Width="150"></Image>
-                <TextBox x:Name="imgPath" Width="150"></TextBox>
+                <TextBox x:Name="imgPath" Width="150" TextChanged="imgPath_TextChanged"></TextBox>
                 <Button x:Name="addImage" Width="150" Click="addImage_Click">Добавить изображение</Button>
             </StackPanel>
         </GroupBox>
@@ -50,6 +50,7 @@
                 </GroupBox>
                 <Button x:Name="save" Click="save_Click">Сохранить</Button>
                 <Button x:Name="cancel" Click="cancel_Click">Отмена</Button>
+                <Button x:Name="delete" Click="delete_Click">Удалить</Button>
             </StackPanel>
         </GroupBox>
         <GroupBox Header="История реализации" Grid.Column="2">

+ 20 - 0
Session1/Windows/EditAgent.xaml.cs

@@ -87,5 +87,25 @@ namespace Session1
             string filePath = openFileDialog.FileName;
             imgPath.Text = filePath;
         }
+
+        private void delete_Click(object sender, RoutedEventArgs e)
+        {
+            BaseConnect.baseModel.Agent.Remove(BaseConnect.baseModel.Agent.Where(x => x.ID == selectedAgent.ID).First());
+            try
+            {
+                BaseConnect.baseModel.SaveChanges();
+                MessageBox.Show("Запись успешно удалена.");
+                Close();
+            }
+            catch
+            {
+                MessageBox.Show("Не удалось удалить запись.");
+            }
+        }
+
+        private void imgPath_TextChanged(object sender, TextChangedEventArgs e)
+        {
+
+        }
     }
 }