add data output to the screen
This commit is contained in:
parent
b8d93e0a74
commit
46e85e6311
@ -2,23 +2,11 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600"
|
||||||
x:Class="demo_blagodat.DeleteClient"
|
x:Class="demo_blagodat.DeleteClient"
|
||||||
|
x:CompileBindings="False"
|
||||||
Title="Удалить клиента">
|
Title="Удалить клиента">
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel>
|
||||||
<StackPanel Spacing="15" HorizontalAlignment="Center" Orientation="Vertical">
|
|
||||||
|
|
||||||
<StackPanel Orientation="Vertical">
|
|
||||||
<TextBlock Text="Введите ФИО"/>
|
|
||||||
<TextBox Width="300" x:Name="TextName"/>
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
<StackPanel Orientation="Vertical">
|
|
||||||
<TextBlock Text="Введите Паспорт"/>
|
|
||||||
<TextBox Width="300" x:Name="TextPassport"/>
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
<StackPanel HorizontalAlignment="Center" Orientation="Vertical" VerticalAlignment="Center">
|
<StackPanel HorizontalAlignment="Center" Orientation="Vertical" VerticalAlignment="Center">
|
||||||
<Button Content="Удвлить Клиента" Click="deleteclient"/>
|
<Button Content="Удвлить Клиента" Click="deleteclient"/>
|
||||||
@ -28,5 +16,15 @@
|
|||||||
<TextBlock x:Name="MesDelError" Text="" Foreground="Red"/>
|
<TextBlock x:Name="MesDelError" Text="" Foreground="Red"/>
|
||||||
<TextBlock x:Name="MesDel" Text="" Foreground="Green"/>
|
<TextBlock x:Name="MesDel" Text="" Foreground="Green"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
<ListBox Name="Items" SelectionChanged="ListBox_SelectionChanged">
|
||||||
|
<ListBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding ClientName}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListBox.ItemTemplate>
|
||||||
|
</ListBox>
|
||||||
|
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -3,61 +3,48 @@ using Avalonia.Controls;
|
|||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using demo_blagodat.Models;
|
using demo_blagodat.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace demo_blagodat;
|
namespace demo_blagodat;
|
||||||
|
|
||||||
public partial class DeleteClient : Window
|
public partial class DeleteClient : Window
|
||||||
{
|
{
|
||||||
|
static User11Context db = new User11Context();
|
||||||
|
ObservableCollection<Client> itemSource = new ObservableCollection<Client>(db.Clients);
|
||||||
public Employee User;
|
public Employee User;
|
||||||
|
|
||||||
|
public DeleteClient()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public DeleteClient(Employee user)
|
public DeleteClient(Employee user)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
User = user;
|
User = user;
|
||||||
|
Items.ItemsSource = itemSource;
|
||||||
|
}
|
||||||
|
private void ListBox_SelectionChanged(object? sender, Avalonia.Controls.SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if(sender != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void deleteclient(object sender, RoutedEventArgs e)
|
private void deleteclient(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
try // Êîíñòðóêöèÿ äëÿ îáðàáîòêè èñêëþ÷åíèé
|
try // Êîíñòðóêöèÿ äëÿ îáðàáîòêè èñêëþ÷åíèé
|
||||||
{
|
{
|
||||||
using (User11Context db = new User11Context()) // Подключение к БД
|
if (sender != null)
|
||||||
{
|
{
|
||||||
// Собираем все данные с экрана
|
db.Clients.Remove(Items.SelectedItem as Client);
|
||||||
string? name = TextName.Text;
|
itemSource.Remove(Items.SelectedItem as Client);
|
||||||
//string pas = TextPassport.Text;
|
db.SaveChanges();
|
||||||
|
// Ìåíÿåì ñîîáùåíèå
|
||||||
|
MesDel.Text = "Êëèåíò óäàë¸í";
|
||||||
if (name != null) // Проверяем наличие важных данных
|
MesDelError.Text = "";
|
||||||
{
|
|
||||||
Client? client = db.Clients.Where(it => it.ClientName == name).FirstOrDefault(); // создаём экземпляр класса Client
|
|
||||||
|
|
||||||
if (client != null)
|
|
||||||
{
|
|
||||||
// Удаляем пользователя из БД
|
|
||||||
db.Clients.Remove(client);
|
|
||||||
|
|
||||||
// Сохраняем изменения БД
|
|
||||||
db.SaveChanges();
|
|
||||||
|
|
||||||
// Меняем сообщение
|
|
||||||
MesDelError.Text = "";
|
|
||||||
MesDel.Text = "Клиент удалён";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MesDel.Text = "Такого клиента нет";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Стераем все данные
|
|
||||||
TextName.Text = "";
|
|
||||||
TextPassport.Text = "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Меняем сообщение
|
|
||||||
MesDel.Text = "";
|
|
||||||
MesDelError.Text = "Нужно добавить все данные клиента!\nМожно игнорировать только почту.";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -67,7 +54,7 @@ public partial class DeleteClient : Window
|
|||||||
|
|
||||||
// Ìåíÿåì ñîîáùåíèå
|
// Ìåíÿåì ñîîáùåíèå
|
||||||
MesDel.Text = "";
|
MesDel.Text = "";
|
||||||
MesDelError.Text = "Проверьте данные";
|
MesDelError.Text = "Ïðîèçîøëà îøèáêà";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,10 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="demo_blagodat.DeleteEmployee"
|
x:Class="demo_blagodat.DeleteEmployee"
|
||||||
Title="DeleteEmployee">
|
x:CompileBindings="False"
|
||||||
|
Title="Удалить сотрудника">
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Vertical">
|
||||||
<StackPanel Spacing="15" HorizontalAlignment="Center" Orientation="Vertical">
|
|
||||||
|
|
||||||
<StackPanel Orientation="Vertical">
|
|
||||||
<TextBlock Text="Введите Логин "/>
|
|
||||||
<TextBox Width="300" x:Name="TextLogin"/>
|
|
||||||
</StackPanel>
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
<StackPanel HorizontalAlignment="Center" Orientation="Vertical" VerticalAlignment="Center">
|
<StackPanel HorizontalAlignment="Center" Orientation="Vertical" VerticalAlignment="Center">
|
||||||
<Button Content="Удвлить Сотрудника" Click="deleteEmployee"/>
|
<Button Content="Удвлить Сотрудника" Click="deleteEmployee"/>
|
||||||
<Button Content="Вернуться назад" Click="ExitClik"/>
|
<Button Content="Вернуться назад" Click="ExitClik"/>
|
||||||
@ -22,5 +16,15 @@
|
|||||||
<TextBlock x:Name="MesDelError" Text="" Foreground="Red"/>
|
<TextBlock x:Name="MesDelError" Text="" Foreground="Red"/>
|
||||||
<TextBlock x:Name="MesDel" Text="" Foreground="Green"/>
|
<TextBlock x:Name="MesDel" Text="" Foreground="Green"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
|
||||||
|
<ListBox Name="Items" SelectionChanged="ListBox_SelectionChanged">
|
||||||
|
<ListBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding EmployeesName}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListBox.ItemTemplate>
|
||||||
|
</ListBox>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -4,59 +4,48 @@ using Avalonia.Interactivity;
|
|||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using demo_blagodat.Models;
|
using demo_blagodat.Models;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace demo_blagodat;
|
namespace demo_blagodat;
|
||||||
|
|
||||||
public partial class DeleteEmployee : Window
|
public partial class DeleteEmployee : Window
|
||||||
{
|
{
|
||||||
|
static User11Context db = new User11Context();
|
||||||
|
ObservableCollection<Employee> itemSource = new ObservableCollection<Employee>(db.Employees);
|
||||||
public Employee User;
|
public Employee User;
|
||||||
|
|
||||||
|
public DeleteEmployee()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
public DeleteEmployee(Employee user)
|
public DeleteEmployee(Employee user)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
User = user;
|
User = user;
|
||||||
|
Items.ItemsSource = itemSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ListBox_SelectionChanged(object? sender, Avalonia.Controls.SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteEmployee(object sender, RoutedEventArgs e)
|
private void deleteEmployee(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
try // Êîíñòðóêöèÿ äëÿ îáðàáîòêè èñêëþ÷åíèé
|
try // Êîíñòðóêöèÿ äëÿ îáðàáîòêè èñêëþ÷åíèé
|
||||||
{
|
{
|
||||||
using (User11Context db = new User11Context()) // Подключение к БД
|
if (sender != null)
|
||||||
{
|
{
|
||||||
// Собираем все данные с экрана
|
db.Employees.Remove(Items.SelectedItem as Employee);
|
||||||
string? login = TextLogin.Text;
|
itemSource.Remove(Items.SelectedItem as Employee);
|
||||||
|
db.SaveChanges();
|
||||||
if (login != null) // Проверяем наличие важных данных
|
// Ìåíÿåì ñîîáùåíèå
|
||||||
{
|
MesDel.Text = "Ñîòðóäíèê óäàë¸í";
|
||||||
Employee? employee = db.Employees.Where(it => it.EmployeesLogin == login).FirstOrDefault();// создаём экземпляр класса Client
|
MesDelError.Text = "";
|
||||||
|
|
||||||
if (employee != null)
|
|
||||||
{
|
|
||||||
// Удаляем пользователя из БД
|
|
||||||
db.Employees.Remove(employee);
|
|
||||||
|
|
||||||
// Сохраняем изменения БД
|
|
||||||
db.SaveChanges();
|
|
||||||
|
|
||||||
// Меняем сообщение
|
|
||||||
MesDelError.Text = "";
|
|
||||||
MesDel.Text = "Сотрудник удалён";
|
|
||||||
TextLogin.Text = "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MesDel.Text = "";
|
|
||||||
MesDelError.Text = "Такого сотрудника нет";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Меняем сообщение
|
|
||||||
MesDel.Text = "";
|
|
||||||
MesDelError.Text = "Нужно ввести логин сотрудника";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
Loading…
Reference in New Issue
Block a user