lab2
This commit is contained in:
11
KPO_Lab.sln
11
KPO_Lab.sln
@@ -3,7 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34202.233
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tool", "Tool/Tool.csproj", "{73C85CBC-5C3A-4F43-8B10-1462B52F709E}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tool", "Tool\Tool.csproj", "{73C85CBC-5C3A-4F43-8B10-1462B52F709E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab2", "Lab2\Lab2.csproj", "{BC81743D-B4D3-4D25-A966-AD697757E98C}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{73C85CBC-5C3A-4F43-8B10-1462B52F709E} = {73C85CBC-5C3A-4F43-8B10-1462B52F709E}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -15,6 +20,10 @@ Global
|
||||
{73C85CBC-5C3A-4F43-8B10-1462B52F709E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{73C85CBC-5C3A-4F43-8B10-1462B52F709E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{73C85CBC-5C3A-4F43-8B10-1462B52F709E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BC81743D-B4D3-4D25-A966-AD697757E98C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BC81743D-B4D3-4D25-A966-AD697757E98C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BC81743D-B4D3-4D25-A966-AD697757E98C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BC81743D-B4D3-4D25-A966-AD697757E98C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
9
Lab2/App.xaml
Normal file
9
Lab2/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<Application x:Class="Lab2.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Lab2"
|
||||
StartupUri="src/Form/MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
11
Lab2/App.xaml.cs
Normal file
11
Lab2/App.xaml.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace Lab2
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
||||
18
Lab2/Lab2.csproj
Normal file
18
Lab2/Lab2.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Tool\Tool.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Page Include="App.xaml" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
10
Lab2/src/AssemblyInfo.cs
Normal file
10
Lab2/src/AssemblyInfo.cs
Normal 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)
|
||||
)]
|
||||
41
Lab2/src/Form/CreateLawnmower.xaml
Normal file
41
Lab2/src/Form/CreateLawnmower.xaml
Normal file
@@ -0,0 +1,41 @@
|
||||
<Window x:Class="Lab2.CreateLawnmower"
|
||||
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:Lab2"
|
||||
mc:Ignorable="d"
|
||||
Title="CreateLawnmower" Height="400" Width="200" Closing="Window_Closing">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Content="Name:" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_nameTextBox" Grid.Row="0" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Material:" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<ComboBox x:Name="_materialComboBox" Grid.Row="1" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Weight:" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_weightTextBox" Grid.Row="2" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Power:" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_powerTextBox" Grid.Row="3" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Fuel capacity:" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_fuelСapacityTextBox" Grid.Row="4" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Button Click="SaveButton_Click" Content="Save" Grid.Row="5" Grid.Column="1" Margin="5,5,5,5" />
|
||||
</Grid>
|
||||
</Window>
|
||||
95
Lab2/src/Form/CreateLawnmower.xaml.cs
Normal file
95
Lab2/src/Form/CreateLawnmower.xaml.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
|
||||
namespace Lab2
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CreateLawnmower.xaml
|
||||
/// </summary>
|
||||
public partial class CreateLawnmower : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// Определяет, сохранять ли изменения
|
||||
/// </summary>
|
||||
private bool _save;
|
||||
/// <summary>
|
||||
/// Газонокосилка для редактирования
|
||||
/// </summary>
|
||||
private Lawnmower _lawnmower;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="parLawnmower">Газонокосилка для редактирования</param>
|
||||
/// <exception cref="ArgumentNullException">Выбрасывается, когда газонокосилка равна null</exception>
|
||||
public CreateLawnmower(Lawnmower parLawnmower)
|
||||
{
|
||||
if (parLawnmower == null)
|
||||
throw new ArgumentNullException(nameof(parLawnmower));
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
_materialComboBox.ItemsSource = Enum.GetValues(typeof(Material));
|
||||
|
||||
_lawnmower = parLawnmower;
|
||||
|
||||
Title = $"Lawnmower {_lawnmower.Id}";
|
||||
SyncFields();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Синхронизирует поля формы с данными
|
||||
/// </summary>
|
||||
private void SyncFields()
|
||||
{
|
||||
_nameTextBox.Text = _lawnmower.Name;
|
||||
_materialComboBox.SelectedItem = _lawnmower.Material;
|
||||
_weightTextBox.Text = _lawnmower.Weight.ToString(CultureInfo.CurrentCulture);
|
||||
_powerTextBox.Text = _lawnmower.Power.ToString();
|
||||
_fuelСapacityTextBox.Text = _lawnmower.FuelCapacity.ToString(CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Синхронизирует данные с полей формы
|
||||
/// </summary>
|
||||
private void SyncData()
|
||||
{
|
||||
_lawnmower.Name = _nameTextBox.Text;
|
||||
_lawnmower.Material = (Material)_materialComboBox.SelectedItem;
|
||||
_lawnmower.Weight = Convert.ToDouble(_weightTextBox.Text, CultureInfo.CurrentCulture);
|
||||
_lawnmower.Power = Convert.ToUInt32(_powerTextBox.Text);
|
||||
_lawnmower.FuelCapacity = (float)Convert.ToDouble(_fuelСapacityTextBox.Text, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик нажатия на кнопку "Save"
|
||||
/// </summary>
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_save = true;
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события закрытия окна
|
||||
/// </summary>
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
if (!_save)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
SyncData();
|
||||
DialogResult = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Lab2/src/Form/CreateScissors.xaml
Normal file
41
Lab2/src/Form/CreateScissors.xaml
Normal file
@@ -0,0 +1,41 @@
|
||||
<Window x:Class="Lab2.CreateScissors"
|
||||
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:Lab2"
|
||||
mc:Ignorable="d"
|
||||
Title="CreateScissors" Height="400" Width="200" Closing="Window_Closing">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Content="Name:" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_nameTextBox" Grid.Row="0" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Material:" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<ComboBox x:Name="_materialComboBox" Grid.Row="1" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Weight:" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_weightTextBox" Grid.Row="2" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Handle length:" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_handleLengthTextBox" Grid.Row="3" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Blade size:" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_bladeSizeTextBox" Grid.Row="4" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Button Click="SaveButton_Click" Content="Save" Grid.Row="5" Grid.Column="1" Margin="5,5,5,5" />
|
||||
</Grid>
|
||||
</Window>
|
||||
95
Lab2/src/Form/CreateScissors.xaml.cs
Normal file
95
Lab2/src/Form/CreateScissors.xaml.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
|
||||
namespace Lab2
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CreateScissors.xaml
|
||||
/// </summary>
|
||||
public partial class CreateScissors : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// Определяет, сохранять ли изменения
|
||||
/// </summary>
|
||||
private bool _save;
|
||||
/// <summary>
|
||||
/// Ножницы для редактирования
|
||||
/// </summary>
|
||||
private Scissors _scissors;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="parScissors">Ножницы для редактирования</param>
|
||||
/// <exception cref="ArgumentNullException">Выбрасывается, когда ножницы равны null</exception>
|
||||
public CreateScissors(Scissors parScissors)
|
||||
{
|
||||
if (parScissors == null)
|
||||
throw new ArgumentNullException(nameof(parScissors));
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
_materialComboBox.ItemsSource = Enum.GetValues(typeof(Material));
|
||||
|
||||
_scissors = parScissors;
|
||||
|
||||
Title = $"Scissors {_scissors.Id}";
|
||||
SyncFields();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Синхронизирует поля формы с данными
|
||||
/// </summary>
|
||||
private void SyncFields()
|
||||
{
|
||||
_nameTextBox.Text = _scissors.Name;
|
||||
_materialComboBox.SelectedItem = _scissors.Material;
|
||||
_weightTextBox.Text = _scissors.Weight.ToString(CultureInfo.CurrentCulture);
|
||||
_handleLengthTextBox.Text = _scissors.HandleLength.ToString(CultureInfo.CurrentCulture);
|
||||
_bladeSizeTextBox.Text = _scissors.BladeSize.ToString(CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Синхронизирует данные с полей формы
|
||||
/// </summary>
|
||||
private void SyncData()
|
||||
{
|
||||
_scissors.Name = _nameTextBox.Text;
|
||||
_scissors.Material = (Material)_materialComboBox.SelectedItem;
|
||||
_scissors.Weight = Convert.ToDouble(_weightTextBox.Text, CultureInfo.CurrentCulture);
|
||||
_scissors.HandleLength = (float)Convert.ToDouble(_handleLengthTextBox.Text, CultureInfo.CurrentCulture);
|
||||
_scissors.BladeSize = Convert.ToDouble(_bladeSizeTextBox.Text, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик нажатия на кнопку "Save"
|
||||
/// </summary>
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_save = true;
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события закрытия окна
|
||||
/// </summary>
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
if (!_save)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
SyncData();
|
||||
DialogResult = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Lab2/src/Form/CreateScythe.xaml
Normal file
41
Lab2/src/Form/CreateScythe.xaml
Normal file
@@ -0,0 +1,41 @@
|
||||
<Window x:Class="Lab2.CreateScythe"
|
||||
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:Lab2"
|
||||
mc:Ignorable="d"
|
||||
Title="CreateScythe" Height="400" Width="200" Closing="Window_Closing">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Content="Name:" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_nameTextBox" Grid.Row="0" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Material:" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<ComboBox x:Name="_materialComboBox" Grid.Row="1" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Weight:" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_weightTextBox" Grid.Row="2" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Handle length:" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_handleLengthTextBox" Grid.Row="3" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Blade type:" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<ComboBox x:Name="_bladeTypeComboBox" Grid.Row="4" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Button Click="SaveButton_Click" Content="Save" Grid.Row="5" Grid.Column="1" Margin="5,5,5,5" />
|
||||
</Grid>
|
||||
</Window>
|
||||
96
Lab2/src/Form/CreateScythe.xaml.cs
Normal file
96
Lab2/src/Form/CreateScythe.xaml.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
|
||||
namespace Lab2
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CreateScythe.xaml
|
||||
/// </summary>
|
||||
public partial class CreateScythe : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// Определяет, сохранять ли изменения
|
||||
/// </summary>
|
||||
private bool _save;
|
||||
/// <summary>
|
||||
/// Коса для редактирования
|
||||
/// </summary>
|
||||
private Scythe _scythe;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="parScythe">Коса для редактирования</param>
|
||||
/// <exception cref="ArgumentNullException">Выбрасывается, когда коса равна null</exception>
|
||||
public CreateScythe(Scythe parScythe)
|
||||
{
|
||||
if (parScythe == null)
|
||||
throw new ArgumentNullException(nameof(parScythe));
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
_materialComboBox.ItemsSource = Enum.GetValues(typeof(Material));
|
||||
_bladeTypeComboBox.ItemsSource = Enum.GetValues(typeof(BladeType));
|
||||
|
||||
_scythe = parScythe;
|
||||
|
||||
Title = $"Scythe {_scythe.Id}";
|
||||
SyncFields();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Синхронизирует поля формы с данными
|
||||
/// </summary>
|
||||
private void SyncFields()
|
||||
{
|
||||
_nameTextBox.Text = _scythe.Name;
|
||||
_materialComboBox.SelectedItem = _scythe.Material;
|
||||
_weightTextBox.Text = _scythe.Weight.ToString(CultureInfo.CurrentCulture);
|
||||
_handleLengthTextBox.Text = _scythe.HandleLength.ToString(CultureInfo.CurrentCulture);
|
||||
_bladeTypeComboBox.SelectedItem = _scythe.BladeType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Синхронизирует данные с полей формы
|
||||
/// </summary>
|
||||
private void SyncData()
|
||||
{
|
||||
_scythe.Name = _nameTextBox.Text;
|
||||
_scythe.Material = (Material)_materialComboBox.SelectedItem;
|
||||
_scythe.Weight = Convert.ToDouble(_weightTextBox.Text, CultureInfo.CurrentCulture);
|
||||
_scythe.HandleLength = (float)Convert.ToDouble(_handleLengthTextBox.Text, CultureInfo.CurrentCulture);
|
||||
_scythe.BladeType = (BladeType)_bladeTypeComboBox.SelectedItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события нажатия на кнопку "Save"
|
||||
/// </summary>
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_save = true;
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события закрытия окна
|
||||
/// </summary>
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
if (!_save)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
SyncData();
|
||||
DialogResult = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Lab2/src/Form/CreateTrimmer.xaml
Normal file
41
Lab2/src/Form/CreateTrimmer.xaml
Normal file
@@ -0,0 +1,41 @@
|
||||
<Window x:Class="Lab2.CreateTrimmer"
|
||||
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:Lab2"
|
||||
mc:Ignorable="d"
|
||||
Title="CreateTrimmer" Height="400" Width="200" Closing="Window_Closing">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Content="Name:" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_nameTextBox" Grid.Row="0" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Material:" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<ComboBox x:Name="_materialComboBox" Grid.Row="1" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Weight:" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_weightTextBox" Grid.Row="2" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Power:" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<TextBox x:Name="_powerTextBox" Grid.Row="3" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Label Content="Mode:" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<ComboBox x:Name="_modeComboBox" Grid.Row="4" Grid.Column="1" Margin="5,5,5,5" />
|
||||
|
||||
<Button Click="SaveButton_Click" Content="Save" Grid.Row="5" Grid.Column="1" Margin="5,5,5,5" />
|
||||
</Grid>
|
||||
</Window>
|
||||
96
Lab2/src/Form/CreateTrimmer.xaml.cs
Normal file
96
Lab2/src/Form/CreateTrimmer.xaml.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
|
||||
namespace Lab2
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CreateTrimmer.xaml
|
||||
/// </summary>
|
||||
public partial class CreateTrimmer : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// Определяет, сохранять ли изменения
|
||||
/// </summary>
|
||||
private bool _save;
|
||||
/// <summary>
|
||||
/// Триммер для редактирования
|
||||
/// </summary>
|
||||
private readonly Trimmer _trimmer;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="parTrimmer">Триммер для редактирования</param>
|
||||
/// <exception cref="ArgumentNullException">Выбрасывается, когда триммер равен null</exception>
|
||||
public CreateTrimmer(Trimmer parTrimmer)
|
||||
{
|
||||
if (parTrimmer == null)
|
||||
throw new ArgumentNullException(nameof(parTrimmer));
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
_materialComboBox.ItemsSource = Enum.GetValues(typeof(Material));
|
||||
_modeComboBox.ItemsSource = Enum.GetValues(typeof(TrimmerMode));
|
||||
|
||||
_trimmer = parTrimmer;
|
||||
|
||||
Title = $"Trimmer {_trimmer.Id}";
|
||||
SyncFields();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Синхронизирует поля формы с данными
|
||||
/// </summary>
|
||||
private void SyncFields()
|
||||
{
|
||||
_nameTextBox.Text = _trimmer.Name;
|
||||
_materialComboBox.SelectedItem = _trimmer.Material;
|
||||
_weightTextBox.Text = _trimmer.Weight.ToString(CultureInfo.CurrentCulture);
|
||||
_powerTextBox.Text = _trimmer.Power.ToString();
|
||||
_modeComboBox.SelectedItem = _trimmer.Mode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Синхронизирует данные с полей формы
|
||||
/// </summary>
|
||||
private void SyncData()
|
||||
{
|
||||
_trimmer.Name = _nameTextBox.Text;
|
||||
_trimmer.Material = (Material)_materialComboBox.SelectedItem;
|
||||
_trimmer.Weight = Convert.ToDouble(_weightTextBox.Text, CultureInfo.CurrentCulture);
|
||||
_trimmer.Power = Convert.ToUInt32(_powerTextBox.Text);
|
||||
_trimmer.Mode = (TrimmerMode)_modeComboBox.SelectedItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события нажатия на кнопку "Save"
|
||||
/// </summary>
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_save = true;
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события закрытия окна
|
||||
/// </summary>
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
if (!_save)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
SyncData();
|
||||
DialogResult = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Lab2/src/Form/MainWindow.xaml
Normal file
37
Lab2/src/Form/MainWindow.xaml
Normal file
@@ -0,0 +1,37 @@
|
||||
<Window x:Class="Lab2.MainWindow"
|
||||
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:Lab2"
|
||||
mc:Ignorable="d"
|
||||
Title="Laboratory work #2" Height="450" Width="800">
|
||||
<Grid>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="100*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<DataGrid x:Name="_dataGrid" d:ItemsSource="{d:SampleData ItemCount=5}" RenderTransformOrigin="0.5,0" Grid.Row="1"/>
|
||||
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1.15*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="1.1*"/>
|
||||
<ColumnDefinition Width="1.45*"/>
|
||||
<ColumnDefinition Width="0.8*"/>
|
||||
<ColumnDefinition Width="0.8*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Click="CreateScissorsButton_Click" Content="Add Scissors" Grid.Column="0" Margin="5,5,5,5" />
|
||||
<Button Click="CreateScytheButton_Click" Content="Add Scythe" Grid.Column="1" Margin="5,5,5,5" />
|
||||
<Button Click="CreateTrimmerButton_Click" Content="Add Trimmer" Grid.Column="2" Margin="5,5,5,5" />
|
||||
<Button Click="CreateLawnmowerButton_Click" Content="Add Lawnmower" Grid.Column="3" Margin="5,5,5,5" />
|
||||
<Button Click="EditSelectedButton_Click" Content="Edit" Grid.Column="4" Margin="5,5,5,5" />
|
||||
<Button Click="DeleteSelectedButton_Click" Content="Delete" Grid.Column="5" Margin="5,5,5,5" />
|
||||
<Button Click="GenerateButton_Click" Content="Generate" Grid.Column="6" Margin="5,5,5,5" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
201
Lab2/src/Form/MainWindow.xaml.cs
Normal file
201
Lab2/src/Form/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Lab2
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// Коллекция инструментов
|
||||
/// </summary>
|
||||
private ObservableCollection<Tool> _tools = new();
|
||||
|
||||
/// <summary>
|
||||
/// Случайный генератор
|
||||
/// </summary>
|
||||
private Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_dataGrid.ItemsSource = _tools;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверяет, является ли индекс валидным
|
||||
/// </summary>
|
||||
/// <param name="parIndex"> Индекс </param>
|
||||
/// <returns> True, если индекс валиден, иначе - false </returns>
|
||||
private bool IsValidIndex(int parIndex)
|
||||
{
|
||||
return _tools.Count > 0 && parIndex >= 0 && parIndex < _tools.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает выбранный инструмент
|
||||
/// </summary>
|
||||
/// <returns> Выбранный инструмент </returns>
|
||||
private Tool? GetSelectedItem()
|
||||
{
|
||||
if (!IsValidIndex(_dataGrid.SelectedIndex))
|
||||
return null;
|
||||
|
||||
return _tools[_dataGrid.SelectedIndex];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Открывает форму редактирования
|
||||
/// </summary>
|
||||
/// <param name="parTool"> Инструмент </param>
|
||||
/// <returns> True, если редактирование прошло успешно, иначе - false </returns>
|
||||
private bool ShowEditForm(Tool parTool)
|
||||
{
|
||||
Window? form = parTool switch
|
||||
{
|
||||
Scissors scissors => new CreateScissors(scissors),
|
||||
Scythe scythe => new CreateScythe(scythe),
|
||||
Trimmer trimmer => new CreateTrimmer(trimmer),
|
||||
Lawnmower lawnmower => new CreateLawnmower(lawnmower),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
if (form == null)
|
||||
return false;
|
||||
|
||||
var result = form.ShowDialog();
|
||||
|
||||
_dataGrid.Items.Refresh();
|
||||
|
||||
return result ?? false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Генерирует случайный триммер
|
||||
/// </summary>
|
||||
/// <returns>Случайный триммер</returns>
|
||||
private Trimmer GenerateTrimmer()
|
||||
{
|
||||
return new Trimmer($"Tr{_random.Next(0, 100)}", (Material)_random.Next(0, 3), _random.Next(1, 100), (uint)_random.Next(1, 100));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Генерирует случайную газонокосилку
|
||||
/// </summary>
|
||||
/// <returns>Случайная газонокосилка</returns>
|
||||
private Lawnmower GenerateLawnmower()
|
||||
{
|
||||
return new Lawnmower($"La{_random.Next(0, 100)}", (Material)_random.Next(0, 3), _random.Next(1, 100), (uint)_random.Next(1, 100), _random.Next(1, 100));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Генерирует случайные ножницы
|
||||
/// </summary>
|
||||
/// <returns>Случайные ножницы</returns>
|
||||
private Scissors GenerateScissors()
|
||||
{
|
||||
return new Scissors($"Si{_random.Next(0, 100)}", (Material)_random.Next(0, 3), _random.Next(1, 100), (uint)_random.Next(1, 100), _random.Next(1, 100));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Генерирует случайную косу
|
||||
/// </summary>
|
||||
/// <returns>Случайная коса</returns>
|
||||
private Scythe GenerateScythe()
|
||||
{
|
||||
return new Scythe($"Sc{_random.Next(0, 100)}", (Material)_random.Next(0, 3), _random.Next(1, 100), (uint)_random.Next(1, 100), (BladeType)_random.Next(0, 3));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события нажатия на кнопку "Add Scissors"
|
||||
/// </summary>
|
||||
private void CreateScissorsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var scissors = new Scissors("", Material.Wood, 1, 1, 1);
|
||||
|
||||
if (ShowEditForm(scissors))
|
||||
_tools.Add(scissors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события нажатия на кнопку "Add Scythe"
|
||||
/// </summary>
|
||||
private void CreateScytheButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var scythe = new Scythe("", Material.Wood, 1, 1, BladeType.Straight);
|
||||
|
||||
if (ShowEditForm(scythe))
|
||||
_tools.Add(scythe);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события нажатия на кнопку "Add Trimmer"
|
||||
/// </summary>
|
||||
private void CreateTrimmerButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var trimmer = new Trimmer("", Material.Wood, 1, 1);
|
||||
|
||||
if (ShowEditForm(trimmer))
|
||||
_tools.Add(trimmer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события нажатия на кнопку "Add Lawnmower"
|
||||
/// </summary>
|
||||
private void CreateLawnmowerButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var lawnmower = new Lawnmower("", Material.Wood, 1, 1, 1);
|
||||
|
||||
if (ShowEditForm(lawnmower))
|
||||
_tools.Add(lawnmower);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события нажатия на кнопку "Edit"
|
||||
/// </summary>
|
||||
private void EditSelectedButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var item = GetSelectedItem();
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
ShowEditForm(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события нажатия на кнопку "Delete"
|
||||
/// </summary>
|
||||
private void DeleteSelectedButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!IsValidIndex(_dataGrid.SelectedIndex))
|
||||
return;
|
||||
|
||||
_tools.RemoveAt(_dataGrid.SelectedIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события нажатия на кнопку "Generate"
|
||||
/// </summary>
|
||||
private void GenerateButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Tool tool = _random.Next(0, 4) switch
|
||||
{
|
||||
0 => GenerateScissors(),
|
||||
1 => GenerateScythe(),
|
||||
2 => GenerateTrimmer(),
|
||||
3 => GenerateLawnmower(),
|
||||
_ => GenerateScissors(),
|
||||
};
|
||||
|
||||
_tools.Add(tool);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class Tool
|
||||
/// <summary>
|
||||
/// Материал инструмента
|
||||
/// </summary>
|
||||
public Material Material => _material;
|
||||
public Material Material { get => _material; set => _material = value; }
|
||||
/// <summary>
|
||||
/// Вес инструмента
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user