Первое переключение между экранами.

This commit is contained in:
maksim 2024-11-26 20:02:29 +04:00
parent 09714b4501
commit 1303ba8d80
15 changed files with 451 additions and 34 deletions

View File

@ -12,10 +12,10 @@
<Grid>
<!-- Тень кнопки -->
<Border Background="{TemplateBinding Background}"
CornerRadius="15"
BorderBrush="Transparent"
BorderThickness="0"
x:Name="ButtonBorder">
CornerRadius="15"
BorderBrush="Transparent"
BorderThickness="0"
x:Name="ButtonBorder">
<Border.Effect>
<DropShadowEffect Color="Black" BlurRadius="10" ShadowDepth="2" Opacity="0.4" />
</Border.Effect>
@ -29,8 +29,8 @@
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="ButtonBorder"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="#0066CC" Duration="0:0:0.2" />
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="#0066CC" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
@ -38,8 +38,8 @@
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="ButtonBorder"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="#004890" Duration="0:0:0.2" />
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="#004890" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
@ -63,5 +63,42 @@
</Setter.Value>
</Setter>
</Style>
<!-- Стиль для закругленного TextBox -->
<Style x:Key="RoundedTextBoxStyle" TargetType="TextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border Background="White"
CornerRadius="15"
BorderBrush="Gray"
BorderThickness="1">
<ScrollViewer Margin="5" x:Name="PART_ContentHost"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- Стиль для закругленного ComboBox -->
<Style x:Key="RoundedComboBoxStyle" TargetType="ComboBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Border Background="White"
CornerRadius="15"
BorderBrush="Gray"
BorderThickness="1">
<Grid>
<ToggleButton Grid.Column="2" Focusable="False"
ClickMode="Press" />
<ContentPresenter />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>

View File

@ -1,6 +1,6 @@
// <auto-generated />
using System;
using EmployeeManager.Data;
using EmployeeManager.Model.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

View File

@ -1,6 +1,6 @@
// <auto-generated />
using System;
using EmployeeManager.Data;
using EmployeeManager.Model.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

View File

@ -1,7 +1,7 @@
using EmployeeManager.Model;
using Microsoft.EntityFrameworkCore;
namespace EmployeeManager.Data
namespace EmployeeManager.Model.Data
{
public class ApplicationConext : DbContext
{

View File

@ -1,12 +1,113 @@
using System;
using System.Collections.Generic;
using EmployeeManager.Model.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeeManager.Model
{
public static class DataWorker
{
public static string CreatePhysicalPerson(string namePhysicalPersons, string surnamePhysicalPersons, string patronomicPhysicalPersons, DateTime birthday, string gender, string address, string telephone)
{
string result = "Возникла ошибка. Обратитесь в ЛАОД.";
using(ApplicationConext db = new ApplicationConext())
{
bool checkIsExist = db.PhysicalPersons.Any(
e => e.NamePhysicalPersons == namePhysicalPersons
&& e.SurnamePhysicalPersons == surnamePhysicalPersons
&& e.PatronomicPhysicalPersons == patronomicPhysicalPersons
&& e.Birthday == birthday
);
if (!checkIsExist)
{
PhysicalPerson newPhysicalPerson = new PhysicalPerson
{
NamePhysicalPersons = namePhysicalPersons,
SurnamePhysicalPersons = surnamePhysicalPersons,
PatronomicPhysicalPersons = patronomicPhysicalPersons,
Birthday = birthday,
Gender = gender,
Address = address,
Telephone = telephone
};
db.PhysicalPersons.Add(newPhysicalPerson);
db.SaveChanges();
result = "Физическое лицо добавлено.";
}
return result;
}
}
public static string CreateEmployee(string nameJob, DateTime startJob, DateTime? endJob, string? partTimeJob, float bid, PhysicalPerson? physicalPersons)
{
string result = "Возникла ошибка. Обратитесь в ЛАОД.";
using (ApplicationConext db = new ApplicationConext())
{
Employee newEmployee = new Employee
{
NameJob = nameJob,
StartJob = startJob,
EndJob = endJob,
PartTimeJob = partTimeJob,
Bid = bid,
PhysicalPersonsId = physicalPersons.Id
};
db.Employees.Add(newEmployee);
db.SaveChanges();
result = "Работник добавлен.";
return result;
}
}
public static string DeletePhysicalPerson(PhysicalPerson physicalPerson)
{
string result = "Возникла ошибка. Обратитесь в ЛАОД.";
using(ApplicationConext db = new ApplicationConext())
{
db.PhysicalPersons.Remove(physicalPerson);
db.SaveChanges();
result = "Физическое лицо удалено.";
}
return result;
}
public static string EditPhysicalPerson(PhysicalPerson oldPhysicalPerson, string newNamePhysicalPersons, string newSurnamePhysicalPersons, string newPatronomicPhysicalPersons, DateTime newBirthday, string newGender, string newAddress, string newTelephone)
{
string result = "Возникла ошибка. Обратитесь в ЛАОД.";
using (ApplicationConext db = new ApplicationConext())
{
PhysicalPerson physicalPerson = db.PhysicalPersons.FirstOrDefault(e => e.Id == oldPhysicalPerson.Id);
physicalPerson.SurnamePhysicalPersons = newSurnamePhysicalPersons;
physicalPerson.NamePhysicalPersons = newNamePhysicalPersons;
physicalPerson.PatronomicPhysicalPersons = newPatronomicPhysicalPersons;
physicalPerson.Birthday = newBirthday;
physicalPerson.Gender = newGender;
physicalPerson.Address = newAddress;
physicalPerson.Telephone = newTelephone;
}
return result;
}
public static List<PhysicalPerson> GetAllPhysicalPerson()
{
using (ApplicationConext db = new ApplicationConext())
{
var result = db.PhysicalPersons.ToList();
return result;
}
}
}
}

35
Model/RelayCommand.cs Normal file
View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace EmployeeManager.Model
{
public class RelayCommand : ICommand
{
private Action<object> _execute;
private Func<object, bool> _canExecute;
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute == null || _canExecute(parameter);
}
public void Execute(object parameter)
{
_execute(parameter);
}
}
}

View File

@ -16,7 +16,7 @@
<!-- Кнопка 1 -->
<Button Content="Работа с сотрудниками" Width="200" Height="50" Margin="0,10"
Background="#004890" Foreground="#FFFFFF" FontSize="16"
Style="{StaticResource RoundedButtonStyle}"/>
Style="{StaticResource RoundedButtonStyle}" Command="{Binding OpenPhysicalPersoManagementWindow}"/>
<!-- Кнопка 2 -->
<Button Content="Работа с физ. лицами" Width="200" Height="50" Margin="0,10"
Background="#004890" Foreground="#FFFFFF" FontSize="16"

View File

@ -1,4 +1,5 @@
using System.Text;
using EmployeeManager.ViewModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
@ -19,6 +20,7 @@ namespace EmployeeManager.View
public MainWindow()
{
InitializeComponent();
DataContext = new DataManageViewModel();
}
}
}

View File

@ -0,0 +1,78 @@
<Window x:Class="EmployeeManager.View.PhysicalPerson.AddPhysicalPersonWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Добавление физического лица"
Height="600" Width="400"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Background="#0D2D4F">
<Grid>
<!-- Заголовок окна -->
<TextBlock Text="Добавление физического лица"
HorizontalAlignment="Center" VerticalAlignment="Top"
FontSize="18" FontWeight="Bold"
Foreground="#FFFFFF"
Margin="0,20,0,0" />
<!-- Стек элементов для ввода данных -->
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<!-- Поле для имени -->
<TextBox x:Name="NameTextBox"
Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}"
Margin="0,10"
ToolTip="Введите имя" />
<!-- Поле для фамилии -->
<TextBox x:Name="SurnameTextBox"
Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}"
Margin="0,10"
ToolTip="Введите фамилию" />
<!-- Поле для отчества -->
<TextBox x:Name="PatronomicTextBox"
Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}"
Margin="0,10"
ToolTip="Введите отчество" />
<!-- Поле для выбора даты рождения -->
<DatePicker x:Name="BirthdayPicker"
Width="250" Height="40"
Margin="0,10"
ToolTip="Выберите дату рождения" />
<!-- Поле для выбора пола -->
<ComboBox x:Name="GenderComboBox"
Width="250" Height="40"
Style="{StaticResource RoundedComboBoxStyle}"
Margin="0,10"
ToolTip="Выберите пол">
<ComboBoxItem>Мужской</ComboBoxItem>
<ComboBoxItem>Женский</ComboBoxItem>
</ComboBox>
<!-- Поле для адреса -->
<TextBox x:Name="AddressTextBox"
Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}"
Margin="0,10"
ToolTip="Введите адрес" />
<!-- Поле для телефона -->
<TextBox x:Name="TelephoneTextBox"
Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}"
Margin="0,10"
ToolTip="Введите номер телефона" />
<!-- Кнопка для добавления физического лица -->
<Button Content="Добавить физическое лицо"
Width="250" Height="40"
Margin="0,10"
Style="{StaticResource RoundedButtonStyle}" />
</StackPanel>
</Grid>
</Window>

View File

@ -15,11 +15,11 @@ using System.Windows.Shapes;
namespace EmployeeManager.View.PhysicalPerson
{
/// <summary>
/// Логика взаимодействия для WorkInPhysicalPerson.xaml
/// Логика взаимодействия для AddPhysicalPersonWindow.xaml
/// </summary>
public partial class WorkInPhysicalPerson : Window
public partial class AddPhysicalPersonWindow : Window
{
public WorkInPhysicalPerson()
public AddPhysicalPersonWindow()
{
InitializeComponent();
}

View File

@ -0,0 +1,44 @@
<Window x:Class="EmployeeManager.View.PhysicalPerson.PhysicalPersoManagementWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Управление физическими лицами"
Height="300" Width="400"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Background="#0D2D4F">
<Grid>
<!-- Заголовок окна -->
<TextBlock Text="Управление физическими лицами"
HorizontalAlignment="Center" VerticalAlignment="Top"
FontSize="18" FontWeight="Bold"
Foreground="#FFFFFF"
Margin="0,20,0,0" />
<!-- Стек кнопок -->
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<!-- Кнопка "Удаление физического лица" -->
<Button Content="Удаление физического лица"
Width="250" Height="40"
Margin="0,0,0,10"
Style="{StaticResource RoundedButtonStyle}" />
<!-- Кнопка "Добавление физического лица" -->
<Button Content="Добавление физического лица"
Width="250" Height="40"
Margin="0,0,0,10"
Style="{StaticResource RoundedButtonStyle}"
Command="{Binding OpenAddPhysicalPersonWindow}"/>
<!-- Кнопка "Редактирование физического лица" -->
<Button Content="Редактирование физического лица"
Width="250" Height="40"
Margin="0,0,0,10"
Style="{StaticResource RoundedButtonStyle}" />
<!-- Кнопка "Просмотр физических лиц" -->
<Button Content="Просмотр физических лиц"
Width="250" Height="40"
Style="{StaticResource RoundedButtonStyle}" />
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,29 @@
using EmployeeManager.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace EmployeeManager.View.PhysicalPerson
{
/// <summary>
/// Логика взаимодействия для PhysicalPersoManagementWindow.xaml
/// </summary>
public partial class PhysicalPersoManagementWindow : Window
{
public PhysicalPersoManagementWindow()
{
InitializeComponent();
DataContext = new DataManageViewModel();
}
}
}

View File

@ -1,12 +0,0 @@
<Window x:Class="EmployeeManager.View.PhysicalPerson.WorkInPhysicalPerson"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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"
xmlns:local="clr-namespace:EmployeeManager.View.PhysicalPerson"
mc:Ignorable="d"
Title="WorkInPhysicalPerson" Height="450" Width="800">
<Grid>
</Grid>
</Window>

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows;
namespace EmployeeManager.View
{
public class TextBoxPlaceholderConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
string text = values[0] as string;
bool isFocused = (bool)values[1];
return string.IsNullOrEmpty(text) && !isFocused ? Visibility.Visible : Visibility.Collapsed;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,12 +1,89 @@
using System;
using EmployeeManager.Model;
using EmployeeManager.View.PhysicalPerson;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace EmployeeManager.ViewModel
{
internal class DataManageViewModel
public class DataManageViewModel : INotifyPropertyChanged
{
private List<PhysicalPerson> allPhysicalPeoples = DataWorker.GetAllPhysicalPerson();
public List<PhysicalPerson> AllPhysicalPeoples
{
get { return allPhysicalPeoples; }
set
{
allPhysicalPeoples = value;
NotifyPropertyChanged("AllPhysicalPeoples");
}
}
private RelayCommand openPhysicalPersoManagementWindow;
public RelayCommand OpenPhysicalPersoManagementWindow
{
get
{
return openPhysicalPersoManagementWindow ?? new RelayCommand(obj =>
{
OpenPhysicalPersoManagementWindowMethod();
}
);
}
}
private RelayCommand openAddPhysicalPersonWindow;
public RelayCommand OpenAddPhysicalPersonWindow
{
get
{
return openAddPhysicalPersonWindow ?? new RelayCommand(obj =>
{
OpenAddPhysicalPersonWindowMethod();
}
);
}
}
private void OpenPhysicalPersoManagementWindowMethod()
{
PhysicalPersoManagementWindow newPhysicalPersoManagementWindow = new PhysicalPersoManagementWindow();
SetCenterPositionAndOpen(newPhysicalPersoManagementWindow);
}
private void OpenAddPhysicalPersonWindowMethod()
{
AddPhysicalPersonWindow newAddPhysicalPersonWindow = new AddPhysicalPersonWindow();
SetCenterPositionAndOpen(newAddPhysicalPersonWindow);
}
private void SetCenterPositionAndOpen(Window window)
{
window.Owner = Application.Current.MainWindow;
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.ShowDialog();
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}