Начат MVVM, нужно переделать под обычную архитектуру

This commit is contained in:
2026-04-01 14:07:16 +05:00
parent 5969778dd8
commit dc35ce3325
17 changed files with 463 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
<Solution>
<Project Path="UP01Task2App/UP01Task2App.csproj" />
</Solution>

View File

@@ -0,0 +1,20 @@
<Application x:Class="UP01Task2App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:UP01Task2App"
StartupUri="Windows/ClientWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Styles/ButtonStyle.xaml" />
<ResourceDictionary
Source="Styles/TextBoxStyle.xaml" />
<ResourceDictionary
Source="Styles/DatePickerStyle.xaml" />
<ResourceDictionary
Source="Styles/ComboBoxStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace UP01Task2App
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View File

@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@@ -0,0 +1,58 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style
x:Key="ButtonStyle"
TargetType="Button">
<Setter
Property="Background"
Value="#4969d1" />
<Setter
Property="FontSize"
Value="16" />
<Setter
Property="Padding"
Value="0" />
<Setter Property="Height"
Value="35"/>
<Setter Property="Width"
Value="250"/>
<Setter
Property="Foreground"
Value="White" />
<Setter
Property="BorderThickness"
Value="0" />
<Setter
Property="Cursor"
Value="Hand"/>
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="Button">
<Border
x:Name="mainBorder"
Background="{TemplateBinding Background}"
CornerRadius="3"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger
Property="IsPressed"
Value="True">
<Setter
TargetName="mainBorder"
Property="Background"
Value="#000033" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,30 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="ComboBoxStyle"
TargetType="ComboBox">
<Setter
Property="Width"
Value="200"/>
<Setter
Property="Height"
Value="24"/>
<Setter
Property="HorizontalAlignment"
Value="Left"/>
<Setter
Property="Padding"
Value="0" />
<Setter
Property="FontSize"
Value="16" />
<Setter
Property="Padding"
Value="5,0,0,0" />
<Setter
Property="Cursor"
Value="Hand" />
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,26 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style
x:Key="DatePickerStyle"
TargetType="DatePicker">
<Setter
Property="Width"
Value="200" />
<Setter
Property="Height"
Value="24" />
<Setter
Property="FontSize"
Value="16" />
<Setter
Property="VerticalContentAlignment"
Value="Center" />
<Setter
Property="Padding"
Value="0"/>
<Setter
Property="HorizontalAlignment"
Value="Left"/>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,21 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="TextBoxStyle"
TargetType="TextBox">
<Setter
Property="Width"
Value="200"/>
<Setter
Property="Height"
Value="24"/>
<Setter
Property="FontSize"
Value="16" />
<Setter
Property="Padding"
Value="0" />
<Setter
Property="HorizontalAlignment"
Value="Left"/>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace UP01Task2App.ViewModels
{
using System.ComponentModel;
using System.Runtime.CompilerServices;
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Windows.Input;
public class RelayCommand : ICommand
{
private readonly Action _execute;
private readonly Func<bool> _canExecute;
public RelayCommand(Action execute, Func<bool> canExecute = null)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter) => _canExecute?.Invoke() ?? true;
public void Execute(object parameter) => _execute();
public event EventHandler CanExecuteChanged;
}

View File

@@ -0,0 +1,36 @@
<Window x:Class="UP01Task2App.Windows.AppointmentWindow"
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:UP01Task2App.Windows"
mc:Ignorable="d"
Title="Запись" Height="400" Width="300">
<StackPanel Margin="10" HorizontalAlignment="Center">
<TextBlock Text="Клиент:" FontWeight="Bold"/>
<TextBlock Text="{Binding SelectedClient.LastName}" Margin="0,0,0,10" FontSize="16"/>
<TextBlock Text="Тренировка"/>
<ComboBox ItemsSource="{Binding Specializations}"
SelectedItem="{Binding SelectedSpecialization}"
Style="{StaticResource ComboBoxStyle}"/>
<TextBlock Text="Тренер"/>
<ComboBox ItemsSource="{Binding Trainers}"
SelectedItem="{Binding SelectedTrainer}"
Style="{StaticResource ComboBoxStyle}"/>
<TextBlock Text="Дата"/>
<DatePicker SelectedDate="{Binding SelectedDate}"
Style="{StaticResource DatePickerStyle}"/>
<Button Content="Записать"
Command="{Binding SaveAppointmentCommand}"
Margin="0,30,0,0"
Width="200"
Style="{StaticResource ButtonStyle}"/>
</StackPanel>
</Window>

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
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 UP01Task2App.Windows
{
/// <summary>
/// Логика взаимодействия для AppointmentWindow.xaml
/// </summary>
public partial class AppointmentWindow : Window
{
public AppointmentWindow()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,37 @@
<Window x:Class="UP01Task2App.Windows.ClientAppointmentList"
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:UP01Task2App.Windows"
mc:Ignorable="d"
Title="ClientAppointmentList" Height="400" Width="460"
ResizeMode="CanMinimize">
<Grid>
<StackPanel Margin="10">
<TextBlock Text="Клиент:" FontWeight="Bold"/>
<TextBlock Text="{Binding SelectedClient.LastName}" Margin="0,0,0,10" FontSize="16"/>
<TextBlock Text="Список записей" FontSize="18" Margin="0,0,0,10"/>
<ListBox ItemsSource="{Binding Appointments}"
SelectedItem="{Binding SelectedAppointment}"
Height="200"
DisplayMemberPath="LastName"/>
<StackPanel Orientation="Horizontal">
<Button Content="Назад"
Command="{Binding BackCommand}"
Margin="10"
Width="200"
Style="{StaticResource ButtonStyle}"/>
<Button Content="Отменить запись"
Command="{Binding CancelAppointmentCommand}"
Margin="10"
Width="200"
Style="{StaticResource ButtonStyle}"/>
</StackPanel>
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
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 UP01Task2App.Windows
{
/// <summary>
/// Логика взаимодействия для ClientAppointmentList.xaml
/// </summary>
public partial class ClientAppointmentList : Window
{
public ClientAppointmentList()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,83 @@
<Window x:Class="UP01Task2App.Windows.ClientWindow"
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:UP01Task2App.Windows"
mc:Ignorable="d"
Title="Клиенты" Height="700" Width="600">
<StackPanel>
<StackPanel Margin="10">
<StackPanel Orientation="Horizontal">
<StackPanel HorizontalAlignment="Left">
<TextBlock Text="Фамилия"/>
<TextBox Text="{Binding LastName}" Style="{StaticResource TextBoxStyle}"/>
<TextBlock Text="Имя"/>
<TextBox Text="{Binding FirstName}" Style="{StaticResource TextBoxStyle}"/>
<TextBlock Text="Отчество"/>
<TextBox Text="{Binding MiddleName}" Style="{StaticResource TextBoxStyle}"/>
<TextBlock Text="Дата рождения"/>
<DatePicker SelectedDate="{Binding BirthDate}" Style="{StaticResource DatePickerStyle}" />
</StackPanel>
<StackPanel HorizontalAlignment="Right" Margin="20,0,0,0">
<TextBlock Text="Фактический адрес"/>
<TextBox Text="{Binding Address}" Style="{StaticResource TextBoxStyle}"/>
<TextBlock Text="Телефон"/>
<TextBox Text="{Binding Phone}" Style="{StaticResource TextBoxStyle}"/>
<TextBlock Text="Номер абонемента"/>
<TextBox Text="{Binding MembershipNumber}" Style="{StaticResource TextBoxStyle}"/>
<TextBlock Text="Пол"/>
<StackPanel Orientation="Horizontal" Margin="5">
<RadioButton Content="М" GroupName="rg1"/>
<RadioButton Content="Ж" GroupName="rg1"/>
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
<StackPanel Margin="10">
<TextBlock Text="Список клиентов" FontSize="18" Margin="0,0,0,10"/>
<ListBox ItemsSource="{Binding Clients}"
SelectedItem="{Binding SelectedClient}"
Height="250"
DisplayMemberPath="LastName"/>
<StackPanel Orientation="Horizontal"
Margin="10">
<StackPanel>
<Button Content="Добавить клиента"
Command="{Binding AddClientCommand}"
Style="{StaticResource ButtonStyle}"
Margin="10"/>
<Button Content="Изменить клиента"
Command="{Binding EditClientCommand}"
Style="{StaticResource ButtonStyle}"
Margin="10"/>
</StackPanel>
<StackPanel>
<Button Content="Запись клиента"
Command="{Binding AddAppointmentCommand}"
Style="{StaticResource ButtonStyle}"
Margin="10"/>
<Button Content="Просмотреть записи"
Command="{Binding ViewAppointmentsCommand}"
Style="{StaticResource ButtonStyle}"
Margin="10"/>
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</Window>

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
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 UP01Task2App.Windows
{
/// <summary>
/// Логика взаимодействия для ClientWindow.xaml
/// </summary>
public partial class ClientWindow : Window
{
public ClientWindow()
{
InitializeComponent();
}
}
}