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