Почти доделал модуль. Надо его просто допилить

This commit is contained in:
maksim 2024-11-30 15:36:29 +04:00
parent 94277268fd
commit d299dc1a45
8 changed files with 392 additions and 13 deletions

View File

@ -0,0 +1,34 @@
<Window x:Class="EmployeeManagmentView.PhysicalPerson.DeletePhysicalPersonWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Удаление физического лица"
Height="400" Width="600"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Background="#0D2D4F">
<Grid>
<!-- Заголовок окна -->
<TextBlock Text="Список физических лиц для удаления"
HorizontalAlignment="Center" VerticalAlignment="Top"
FontSize="18" FontWeight="Bold"
Foreground="#FFFFFF"
Margin="0,20,0,0" />
<!-- Таблица для отображения -->
<DataGrid x:Name="PhysicalPersonsDataGrid"
Margin="20,60,20,80"
AutoGenerateColumns="True"
Background="#FFFFFF"
Foreground="#000000" />
<!-- Кнопка для удаления -->
<Button Content="Удалить"
HorizontalAlignment="Center" VerticalAlignment="Bottom"
Width="100" Height="40"
Margin="0,0,0,20"
Background="#FF4C4C"
Foreground="#FFFFFF"
Click="DeleteButton_Click"/>
</Grid>
</Window>

View File

@ -0,0 +1,40 @@
using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.ViewModels;
using System.Windows;
namespace EmployeeManagmentView.PhysicalPerson
{
public partial class DeletePhysicalPersonWindow : Window
{
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
public DeletePhysicalPersonWindow(IPhisicalPersonLogic phisicalPersonLogic)
{
_phisicalPersonLogic = phisicalPersonLogic;
InitializeComponent();
LoadPhysicalPersons();
}
private void LoadPhysicalPersons()
{
PhysicalPersonsDataGrid.ItemsSource = _phisicalPersonLogic.GetFullList();
}
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
if (PhysicalPersonsDataGrid.SelectedItem != null)
{
var selectedPerson = PhysicalPersonsDataGrid.SelectedItem as PhisicalPersonViewModel;
if (selectedPerson != null)
{
_phisicalPersonLogic.Delete(selectedPerson.Id); // Используем Id для удаления
LoadPhysicalPersons(); // Перезагружаем список
}
}
else
{
MessageBox.Show("Пожалуйста, выберите физическое лицо для удаления.");
}
}
}
}

View File

@ -0,0 +1,130 @@
<Window x:Class="EmployeeManagmentView.PhysicalPerson.EditPhysicalPersonWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Редактирование физического лица"
Height="600" Width="600"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Background="#0D2D4F">
<Grid>
<!-- Заголовок окна -->
<TextBlock Text="Редактирование физического лица"
HorizontalAlignment="Center" VerticalAlignment="Top"
FontSize="18" FontWeight="Bold"
Foreground="#FFFFFF"
Margin="0,20,0,0" />
<!-- Остальная часть как в AddPhysicalPersonWindow.xaml -->
<!-- Сетка для ввода данных в два столбца -->
<Grid Margin="0,60">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Поле для имени -->
<StackPanel Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<Label Content="Имя" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="NameTextBox"
Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}"
Margin="0,5"
ToolTip="Введите имя" HorizontalAlignment="Center"/>
</StackPanel>
<!-- Поле для фамилии -->
<StackPanel Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<Label Content="Фамилия" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="SurnameTextBox"
Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}"
Margin="0,5"
ToolTip="Введите фамилию" HorizontalAlignment="Center"/>
</StackPanel>
<!-- Поле для отчества -->
<StackPanel Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<Label Content="Отчество" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="PatronomicTextBox"
Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}"
Margin="0,5"
ToolTip="Введите отчество" HorizontalAlignment="Center"/>
</StackPanel>
<!-- Поле для выбора даты рождения -->
<StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<Label Content="Дата рождения" Foreground="White" HorizontalAlignment="Center"/>
<DatePicker x:Name="BirthdayPicker"
Width="250" Height="40"
Margin="0,5"
ToolTip="Выберите дату рождения" HorizontalAlignment="Center"/>
</StackPanel>
<!-- Поле для выбора пола -->
<StackPanel Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<Label Content="Пол" Foreground="White" HorizontalAlignment="Center"/>
<ComboBox x:Name="GenderComboBox"
Width="250" Height="40"
Margin="0,5"
ToolTip="Выберите пол"
Background="White" HorizontalAlignment="Center">
<ComboBoxItem Content="Мужчина"/>
<ComboBoxItem Content="Женщина"/>
</ComboBox>
</StackPanel>
<!-- Поле для адреса -->
<StackPanel Grid.Row="2" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<Label Content="Адрес" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="AddressTextBox"
Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}"
Margin="0,5"
ToolTip="Введите адрес" HorizontalAlignment="Center"/>
</StackPanel>
<!-- Поле для телефона -->
<StackPanel Grid.Row="3" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<Label Content="Телефон" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="TelephoneTextBox"
Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}"
Margin="0,5"
ToolTip="Введите номер телефона" HorizontalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Row="3" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<Label Content="Выберите физическое лицо" Foreground="White" HorizontalAlignment="Center"/>
<ComboBox x:Name="PhysicalPersonComboBox"
Width="400" Height="40"
SelectionChanged="PhysicalPersonComboBox_SelectionChanged"
ToolTip="Выберите физическое лицо" HorizontalAlignment="Center"/>
</StackPanel>
</Grid>
<!-- Кнопка для сохранения изменений -->
<Button Content="Сохранить изменения"
Width="250" Height="40"
VerticalAlignment="Bottom"
Style="{StaticResource RoundedButtonStyle}"
Background="#004890" Foreground="#FFFFFF"
Click="SaveButton_Click"
HorizontalAlignment="Center" Margin="0,10,0,10"/>
</Grid>
</Window>

View File

@ -0,0 +1,87 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.ViewModels;
namespace EmployeeManagmentView.PhysicalPerson
{
public partial class EditPhysicalPersonWindow : Window
{
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
private List<PhisicalPersonViewModel> _physicalPersons;
public EditPhysicalPersonWindow(IPhisicalPersonLogic phisicalPersonLogic)
{
_phisicalPersonLogic = phisicalPersonLogic;
InitializeComponent();
LoadPhysicalPersons();
}
// Загрузка всех физ.лиц в ComboBox
private void LoadPhysicalPersons()
{
_physicalPersons = _phisicalPersonLogic.GetFullList();
PhysicalPersonComboBox.ItemsSource = _physicalPersons;
PhysicalPersonComboBox.DisplayMemberPath = "Name"; // "FullName" - свойство с именем
PhysicalPersonComboBox.SelectedValuePath = "Id"; // "Id" - идентификатор физ.лица
}
// Событие при выборе физ.лица
private void PhysicalPersonComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (PhysicalPersonComboBox.SelectedValue is int selectedPersonId)
{
LoadPerson(selectedPersonId);
}
}
// Загрузка данных выбранного физ.лица в поля
private void LoadPerson(int personId)
{
var person = _phisicalPersonLogic.GetElement(personId);
if (person != null)
{
NameTextBox.Text = person.Name;
SurnameTextBox.Text = person.Surname;
PatronomicTextBox.Text = person.Patronymic;
BirthdayPicker.SelectedDate = person.Birthday;
GenderComboBox.Text = person.Gender;
AddressTextBox.Text = person.Address;
TelephoneTextBox.Text = person.Telephone;
}
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
if (PhysicalPersonComboBox.SelectedValue is int selectedPersonId)
{
try
{
var updatedPerson = new PhisicalPersonViewModel
{
Id = selectedPersonId,
Name = NameTextBox.Text,
Surname = SurnameTextBox.Text,
Patronymic = PatronomicTextBox.Text,
Birthday = BirthdayPicker.SelectedDate.Value.ToUniversalTime(),
Gender = GenderComboBox.Text,
Address = AddressTextBox.Text,
Telephone = TelephoneTextBox.Text
};
_phisicalPersonLogic.Update(updatedPerson);
MessageBox.Show("Данные успешно обновлены!");
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
else
{
MessageBox.Show("Выберите физическое лицо перед сохранением!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
}
}

View File

@ -21,7 +21,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Width="250" Height="40"
Margin="0,0,0,10"
Background="#004890" Foreground="#FFFFFF"
Style="{StaticResource RoundedButtonStyle}" />
Style="{StaticResource RoundedButtonStyle}"
Click ="OpenDeletePhysicalPersonWindow"/>
<!-- Кнопка "Добавление физического лица" -->
<Button Content="Добавление физического лица"
@ -36,13 +37,15 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Width="250" Height="40"
Margin="0,0,0,10"
Style="{StaticResource RoundedButtonStyle}"
Background="#004890" Foreground="#FFFFFF"/>
Background="#004890" Foreground="#FFFFFF"
Click="OpenEditPhysicalPersonWindow"/>
<!-- Кнопка "Просмотр физических лиц" -->
<Button Content="Просмотр физических лиц"
Width="250" Height="40"
Style="{StaticResource RoundedButtonStyle}"
Background="#004890" Foreground="#FFFFFF"/>
Background="#004890" Foreground="#FFFFFF"
Click="OpenViewPhysicalPersonsWindow"/>
</StackPanel>
</Grid>
</Window>

View File

@ -15,24 +15,62 @@ namespace EmployeeManagmentView.PhysicalPerson
private void OpenAddPhysicalPersonWindow(object sender, RoutedEventArgs e)
{
// Проверяем, если окно уже открыто
foreach (Window window in Application.Current.Windows)
{
if (window is AddPhysicalPersonWindow)
if (window is AddPhysicalPersonWindow existingWindow)
{
// Если окно уже открыто, активируем его и ставим на передний план
window.Activate();
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.Topmost = true; // Ставим окно на передний план
existingWindow.Activate();
return;
}
}
// Если окно не найдено, открываем новое
var physicalPersonWindow = new AddPhysicalPersonWindow(_phisicalPersonLogic);
physicalPersonWindow.Topmost = true;
physicalPersonWindow.Show();
var addWindow = new AddPhysicalPersonWindow(_phisicalPersonLogic);
addWindow.Show();
}
private void OpenDeletePhysicalPersonWindow(object sender, RoutedEventArgs e)
{
foreach (Window window in Application.Current.Windows)
{
if (window is DeletePhysicalPersonWindow existingWindow)
{
existingWindow.Activate();
return;
}
}
var deleteWindow = new DeletePhysicalPersonWindow(_phisicalPersonLogic);
deleteWindow.Show();
}
private void OpenEditPhysicalPersonWindow(object sender, RoutedEventArgs e)
{
foreach (Window window in Application.Current.Windows)
{
if (window is EditPhysicalPersonWindow existingWindow)
{
existingWindow.Activate();
return;
}
}
var editWindow = new EditPhysicalPersonWindow(_phisicalPersonLogic);
editWindow.Show();
}
private void OpenViewPhysicalPersonsWindow(object sender, RoutedEventArgs e)
{
foreach (Window window in Application.Current.Windows)
{
if (window is ViewPhysicalPersonsWindow existingWindow)
{
existingWindow.Activate();
return;
}
}
var viewWindow = new ViewPhysicalPersonsWindow(_phisicalPersonLogic);
viewWindow.Show();
}
}
}

View File

@ -0,0 +1,25 @@
<Window x:Class="EmployeeManagmentView.PhysicalPerson.ViewPhysicalPersonsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Список физических лиц"
Height="500" Width="600"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Background="#0D2D4F">
<Grid>
<!-- Заголовок окна -->
<TextBlock Text="Список физических лиц"
HorizontalAlignment="Center" VerticalAlignment="Top"
FontSize="18" FontWeight="Bold"
Foreground="#FFFFFF"
Margin="0,20,0,0" />
<!-- Таблица для отображения -->
<DataGrid x:Name="PhysicalPersonsDataGrid"
Margin="20,60,20,20"
AutoGenerateColumns="True"
Background="#FFFFFF"
Foreground="#000000" />
</Grid>
</Window>

View File

@ -0,0 +1,22 @@
using EmployeeManagmentContracts.BusinessLogicContracts;
using System.Windows;
namespace EmployeeManagmentView.PhysicalPerson
{
public partial class ViewPhysicalPersonsWindow : Window
{
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
public ViewPhysicalPersonsWindow(IPhisicalPersonLogic phisicalPersonLogic)
{
_phisicalPersonLogic = phisicalPersonLogic;
InitializeComponent();
LoadPhysicalPersons();
}
private void LoadPhysicalPersons()
{
PhysicalPersonsDataGrid.ItemsSource = _phisicalPersonLogic.GetFullList();
}
}
}