Сделано редактирование, но с плохим дизайном

This commit is contained in:
maksim 2024-12-01 18:08:18 +04:00
parent 1c04d20d13
commit 22b0af7ad5
5 changed files with 246 additions and 182 deletions

View File

@ -94,8 +94,8 @@ namespace EmployeeManagmentView.Employee
{
Id = selectedEmployeeId,
NameJob = JobNameTextBox.Text,
StartJob = StartJobPicker.SelectedDate,
EndJob = EndJobPicker.SelectedDate,
StartJob = StartJobPicker.SelectedDate.Value.ToUniversalTime(),
EndJob = EndJobPicker.SelectedDate.Value.ToUniversalTime(),
PartTimeJob = PartTimeTextBox.Text,
Bid = float.Parse(BidTextBox.Text),
PhysicalPersonsId = PhysicalPersonComboBox.SelectedValue as int?

View File

@ -8,26 +8,14 @@
Background="#0D2D4F">
<Grid Margin="0,0,0,-6">
<!-- Заголовок окна -->
<TextBlock Text="Редактирование зарплаты"
HorizontalAlignment="Center" VerticalAlignment="Top"
FontSize="18" FontWeight="Bold"
Foreground="#FFFFFF"
Margin="0,20,0,0" />
<!-- Основная сетка -->
<Grid Margin="0,70,0,60">
<Grid.RowDefinitions>
<!-- Поле выбора сотрудника -->
<RowDefinition Height="Auto" />
<!-- Поля редактирования зарплаты -->
<RowDefinition Height="5*" />
<!-- Кнопка сохранения -->
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Блок выбора сотрудника -->
<Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<!-- Блок поиска и выбора зарплаты -->
<Grid HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,70,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
@ -37,22 +25,24 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0"
Content="Выберите сотрудника" Foreground="White" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalContentAlignment="Center"/>
<ComboBox x:Name="EmployeeComboBox" Grid.Row="0" Grid.Column="1"
Width="400" Height="30"
VerticalAlignment="Top"
ToolTip="Выберите сотрудника"
SelectionChanged="EmployeeComboBox_SelectionChanged" />
<Label Grid.Row="0" Grid.Column="0" Content="Поиск зарплаты" Foreground="White" HorizontalAlignment="Right" Margin="0,0,10,0" />
<TextBox x:Name="SearchTextBox" Grid.Row="0" Grid.Column="1" Width="250" Height="30"
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Введите для поиска"
TextChanged="SearchTextBox_TextChanged" />
<Label Grid.Row="1" Grid.Column="0" Content="Выберите зарплату" Foreground="White" HorizontalAlignment="Right" Margin="0,10,10,0" />
<ComboBox x:Name="SalaryComboBox" Grid.Row="1" Grid.Column="1" Width="250" Height="30"
SelectionChanged="SalaryComboBox_SelectionChanged" />
</Grid>
<!-- Блок редактирования -->
<Grid Grid.Row="1" Margin="0,0,0,0">
<!-- Блок редактирования зарплаты -->
<Grid Margin="0,140,0,60">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
@ -61,39 +51,36 @@
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Margin="10">
<Label Content="Количество часов" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="CountHoursTextBox" Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Введите количество часов" />
<Label Content="Часы работы" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="CountHoursTextBox" Width="250" Height="40" Style="{StaticResource RoundedTextBoxStyle}" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" Margin="10">
<Label Content="Цена за час" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="PriceHourTextBox" Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Введите цену за час" />
<Label Content="Ставка за час" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="PriceHourTextBox" Width="250" Height="40" Style="{StaticResource RoundedTextBoxStyle}" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Margin="10">
<Label Content="Премия" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="PremiumTextBox" Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Введите премию" />
<TextBox x:Name="PremiumTextBox" Width="250" Height="40" Style="{StaticResource RoundedTextBoxStyle}" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" Margin="10">
<Label Content="Дата" Foreground="White" HorizontalAlignment="Center"/>
<DatePicker x:Name="DatePicker" Width="250" Height="40"
ToolTip="Выберите дату" />
<DatePicker x:Name="DatePicker" Width="250" Height="40" />
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0" Margin="10">
<Label Content="Выплачено?" Foreground="White" HorizontalAlignment="Center"/>
<CheckBox x:Name="PassedCheckBox" />
<StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="10">
<Label Content="Сохранить" Foreground="White" HorizontalAlignment="Center"/>
<CheckBox x:Name="PassedCheckBox" Content="Завершено" Foreground="White" />
</StackPanel>
<StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Margin="10">
<Label Content="Сотрудник" Foreground="White" HorizontalAlignment="Center"/>
<ComboBox x:Name="EmployeeComboBox" Width="250" Height="40" />
</StackPanel>
</Grid>
<!-- Кнопка сохранения -->
<Button Grid.Row="2" Content="Сохранить изменения"
Width="250" Height="40"
VerticalAlignment="Bottom"
Style="{StaticResource RoundedButtonStyle}"
<Button Grid.Row="4" Content="Сохранить изменения" Width="250" Height="40"
VerticalAlignment="Bottom" Style="{StaticResource RoundedButtonStyle}"
Background="#004890" Foreground="#FFFFFF"
Click="SaveButton_Click"
HorizontalAlignment="Center" Margin="0,10,0,0"/>
</Grid>
Click="SaveButton_Click" HorizontalAlignment="Center" Margin="0,10,0,0"/>
</Grid>
</Window>

View File

@ -21,59 +21,104 @@ namespace EmployeeManagmentView.Employee.Salary
/// </summary>
public partial class EditSalaryWindow : Window
{
private readonly ISalaryLogic _salaryLogic;
private readonly IEmployeeLogic _employeeLogic;
private List<EmployeeViewModel> _employees;
private readonly ISalaryLogic _salaryLogic; // Логика для работы с зарплатами
private readonly IEmployeeLogic _employeeLogic; // Логика для работы с сотрудниками
private List<SalaryViewModel> _salaries;
private List<EmployeeViewModel> _employees; // Список сотрудников
public EditSalaryWindow(ISalaryLogic salaryLogic, IEmployeeLogic employeeLogic)
{
_salaryLogic = salaryLogic;
_employeeLogic = employeeLogic;
InitializeComponent();
LoadSalaries();
LoadEmployees();
}
private void LoadSalaries()
{
_salaries = _salaryLogic.GetFullList();
SalaryComboBox.ItemsSource = _salaries;
SalaryComboBox.DisplayMemberPath = "EmployeeName";
SalaryComboBox.SelectedValuePath = "Id";
}
private void LoadEmployees()
{
_employees = _employeeLogic.GetFullList();
_employees = _employeeLogic.GetFullList(); // Получение списка всех сотрудников
EmployeeComboBox.ItemsSource = _employees;
EmployeeComboBox.DisplayMemberPath = "NameJob";
EmployeeComboBox.DisplayMemberPath = "FullName"; // Предполагается, что у сотрудника есть свойство FullName
EmployeeComboBox.SelectedValuePath = "Id";
}
private void EmployeeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
private void SalaryComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (SalaryComboBox.SelectedValue is int selectedSalaryId)
{
LoadSalary(selectedSalaryId);
}
}
private void LoadSalary(int salaryId)
{
var salary = _salaryLogic.GetElement(salaryId);
if (salary != null)
{
CountHoursTextBox.Text = salary.CountHours.ToString();
PriceHourTextBox.Text = salary.PriceHour.ToString();
PremiumTextBox.Text = salary.Premium?.ToString() ?? string.Empty;
DatePicker.SelectedDate = salary.Date;
PassedCheckBox.IsChecked = salary.Passed;
// Устанавливаем выбранного сотрудника
EmployeeComboBox.SelectedValue = salary.EmployeeId;
}
else
{
MessageBox.Show("Зарплата не найдена", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var searchText = SearchTextBox.Text.ToLower();
var filteredSalaries = _salaries
.Where(sal => sal.EmployeeName.ToLower().Contains(searchText))
.ToList();
SalaryComboBox.ItemsSource = filteredSalaries;
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
if (EmployeeComboBox.SelectedValue is int selectedEmployeeId)
{
try
{
var newSalary = new SalaryViewModel
if (SalaryComboBox.SelectedValue is int selectedSalaryId)
{
var updatedSalary = new SalaryViewModel
{
Id = selectedSalaryId,
CountHours = int.Parse(CountHoursTextBox.Text),
PriceHour = float.Parse(PriceHourTextBox.Text),
Premium = string.IsNullOrEmpty(PremiumTextBox.Text) ? (float?)null : float.Parse(PremiumTextBox.Text),
Date = DatePicker.SelectedDate,
Premium = float.TryParse(PremiumTextBox.Text, out var premium) ? premium : (float?)null,
Date = DatePicker.SelectedDate.Value.ToUniversalTime(),
Passed = PassedCheckBox.IsChecked ?? false,
EmployeeId = selectedEmployeeId
EmployeeId = (int?)EmployeeComboBox.SelectedValue // Устанавливаем выбранного сотрудника
};
_salaryLogic.Insert(newSalary);
MessageBox.Show("Зарплата успешно добавлена!");
_salaryLogic.Update(updatedSalary);
MessageBox.Show("Зарплата успешно обновлена!");
this.Close();
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
else
{
MessageBox.Show("Выберите сотрудника перед сохранением!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
MessageBox.Show("Выберите зарплату перед сохранением!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка при сохранении данных: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}

View File

@ -8,27 +8,16 @@
Background="#0D2D4F">
<Grid Margin="0,0,0,-6">
<!-- Заголовок окна -->
<TextBlock Text="Редактирование отпуска"
HorizontalAlignment="Center" VerticalAlignment="Top"
FontSize="18" FontWeight="Bold"
Foreground="#FFFFFF"
Margin="0,20,0,0" />
<!-- Основная сетка -->
<Grid Margin="0,70,0,60">
<!-- Блок поиска и выбора отпуска -->
<Grid HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,70,0,0">
<Grid.RowDefinitions>
<!-- Поле выбора сотрудника -->
<RowDefinition Height="Auto" />
<!-- Поля редактирования отпуска -->
<RowDefinition Height="5*" />
<!-- Кнопка сохранения -->
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Блок выбора сотрудника -->
<Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
@ -36,21 +25,23 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0"
Content="Выберите сотрудника" Foreground="White" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalContentAlignment="Center"/>
<ComboBox x:Name="EmployeeComboBox" Grid.Row="0" Grid.Column="1"
Width="400" Height="30"
VerticalAlignment="Top"
ToolTip="Выберите сотрудника"
SelectionChanged="EmployeeComboBox_SelectionChanged" />
<Label Grid.Row="0" Grid.Column="0" Content="Поиск отпуска" Foreground="White" HorizontalAlignment="Right" Margin="0,0,10,0" />
<TextBox x:Name="SearchTextBox" Grid.Row="0" Grid.Column="1" Width="250" Height="30"
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Введите для поиска"
TextChanged="SearchTextBox_TextChanged" />
<Label Grid.Row="1" Grid.Column="0" Content="Выберите отпуск" Foreground="White" HorizontalAlignment="Right" Margin="0,10,10,0" />
<ComboBox x:Name="VacationComboBox" Grid.Row="1" Grid.Column="1" Width="250" Height="30"
SelectionChanged="VacationComboBox_SelectionChanged" />
</Grid>
<!-- Блок редактирования -->
<Grid Grid.Row="1" Margin="0,0,0,0">
<!-- Блок редактирования отпуска -->
<Grid Margin="0,140,0,60">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
@ -60,28 +51,27 @@
<StackPanel Grid.Row="0" Grid.Column="0" Margin="10">
<Label Content="Дата начала" Foreground="White" HorizontalAlignment="Center"/>
<DatePicker x:Name="StartDatePicker" Width="250" Height="40"
ToolTip="Выберите дату начала" />
<DatePicker x:Name="StartDatePicker" Width="250" Height="40" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" Margin="10">
<Label Content="Дата окончания" Foreground="White" HorizontalAlignment="Center"/>
<DatePicker x:Name="EndDatePicker" Width="250" Height="40"
ToolTip="Выберите дату окончания" />
<DatePicker x:Name="EndDatePicker" Width="250" Height="40" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Margin="10">
<Label Content="Выплачено?" Foreground="White" HorizontalAlignment="Center"/>
<CheckBox x:Name="PassedCheckBox" />
<StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="10">
<Label Content="Сохранить" Foreground="White" HorizontalAlignment="Center"/>
<CheckBox x:Name="PassedCheckBox" Content="Завершено" Foreground="White" />
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="10">
<Label Content="Сотрудник" Foreground="White" HorizontalAlignment="Center"/>
<ComboBox x:Name="EmployeeComboBox" Width="250" Height="40" />
</StackPanel>
</Grid>
<!-- Кнопка сохранения -->
<Button Grid.Row="2" Content="Сохранить изменения"
Width="250" Height="40"
VerticalAlignment="Bottom"
Style="{StaticResource RoundedButtonStyle}"
<Button Grid.Row="3" Content="Сохранить изменения" Width="250" Height="40"
VerticalAlignment="Bottom" Style="{StaticResource RoundedButtonStyle}"
Background="#004890" Foreground="#FFFFFF"
Click="SaveButton_Click"
HorizontalAlignment="Center" Margin="0,10,0,0"/>
</Grid>
Click="SaveButton_Click" HorizontalAlignment="Center" Margin="0,10,0,0"/>
</Grid>
</Window>

View File

@ -21,59 +21,101 @@ namespace EmployeeManagmentView.Employee.Vacation
/// </summary>
public partial class EditVacationWindow : Window
{
private readonly IVacationLogic _vacationLogic;
private readonly IEmployeeLogic _employeeLogic;
private List<EmployeeViewModel> _employees;
private readonly IVacationLogic _vacationLogic; // Логика для работы с отпусками
private readonly IEmployeeLogic _employeeLogic; // Логика для работы с сотрудниками
private List<VacationViewModel> _vacations;
private List<EmployeeViewModel> _employees; // Список сотрудников
public EditVacationWindow(IVacationLogic vacationLogic, IEmployeeLogic employeeLogic)
{
_vacationLogic = vacationLogic;
_employeeLogic = employeeLogic;
InitializeComponent();
LoadVacations();
LoadEmployees();
}
private void LoadVacations()
{
_vacations = _vacationLogic.GetFullList();
VacationComboBox.ItemsSource = _vacations;
VacationComboBox.DisplayMemberPath = "EmployeeName";
VacationComboBox.SelectedValuePath = "Id";
}
private void LoadEmployees()
{
_employees = _employeeLogic.GetFullList();
_employees = _employeeLogic.GetFullList(); // Получение списка всех сотрудников
EmployeeComboBox.ItemsSource = _employees;
EmployeeComboBox.DisplayMemberPath = "NameJob";
EmployeeComboBox.DisplayMemberPath = "FullName"; // Предполагается, что у сотрудника есть свойство FullName
EmployeeComboBox.SelectedValuePath = "Id";
}
private void VacationComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (VacationComboBox.SelectedValue is int selectedVacationId)
{
LoadVacation(selectedVacationId);
}
}
private void LoadVacation(int vacationId)
{
var vacation = _vacationLogic.GetElement(vacationId);
if (vacation != null)
{
StartDatePicker.SelectedDate = vacation.StartData;
EndDatePicker.SelectedDate = vacation.EndData;
PassedCheckBox.IsChecked = vacation.Passed;
// Устанавливаем выбранного сотрудника
EmployeeComboBox.SelectedValue = vacation.EmployeeId;
}
else
{
MessageBox.Show("Отпуск не найден", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var searchText = SearchTextBox.Text.ToLower();
var filteredVacations = _vacations
.Where(vac => vac.EmployeeName.ToLower().Contains(searchText))
.ToList();
VacationComboBox.ItemsSource = filteredVacations;
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
if (EmployeeComboBox.SelectedValue is int selectedEmployeeId)
{
try
{
var newVacation = new VacationViewModel
if (VacationComboBox.SelectedValue is int selectedVacationId)
{
StartData = StartDatePicker.SelectedDate ?? DateTime.MinValue,
EndData = EndDatePicker.SelectedDate ?? DateTime.MinValue,
var updatedVacation = new VacationViewModel
{
Id = selectedVacationId,
StartData = StartDatePicker.SelectedDate.Value.ToUniversalTime(),
EndData = EndDatePicker.SelectedDate.Value.ToUniversalTime(),
Passed = PassedCheckBox.IsChecked ?? false,
EmployeeId = selectedEmployeeId
EmployeeId = (int?)EmployeeComboBox.SelectedValue // Устанавливаем выбранного сотрудника
};
_vacationLogic.Insert(newVacation);
MessageBox.Show("Отпуск успешно добавлен!");
_vacationLogic.Update(updatedVacation);
MessageBox.Show("Отпуск успешно обновлен!");
this.Close();
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
else
{
MessageBox.Show("Выберите сотрудника перед сохранением!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
MessageBox.Show("Выберите отпуск перед сохранением!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
private void EmployeeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
catch (Exception ex)
{
MessageBox.Show($"Ошибка при сохранении данных: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}