This commit is contained in:
Userok 2024-12-27 14:47:18 +03:00
parent 94849af572
commit 0db1698097
6 changed files with 228 additions and 1 deletions

View File

@ -20,4 +20,10 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
</ItemGroup>
<ItemGroup>
<Compile Update="Views\ServiceFormWindow.axaml.cs">
<DependentUpon>ServiceFormWindow.axaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@ -5,6 +5,7 @@ public class Service
{
public Guid guid { get; set; }
public string Name { get; set; }
public string ImagePath { get; set; }
public decimal Price { get; set; }
public decimal Discount { get; set; }
public int Duration { get; set; }

View File

@ -15,11 +15,22 @@
<TextBlock Text="30-70%" />
<TextBlock Text="70-100%" />
</ComboBox.Items>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="5">
<TextBox Width="200" Watermark="Код администратора..." Name="AdminCodeBox" />
<Button Content="Войти как администратор" Name="AdminLoginButton" Margin="5" />
</StackPanel>
</ComboBox>
<Button Content="Сортировка ↑" Name="SortAscButton" Margin="5" />
<Button Content="Сортировка ↓" Name="SortDescButton" />
</StackPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" Margin="5" Name="AdminControls" IsVisible="False">
<Button Content="Добавить услугу" Name="AddServiceButton" Margin="5" />
<Button Content="Редактировать услугу" Name="EditServiceButton" Margin="5" />
<Button Content="Удалить услугу" Name="DeleteServiceButton" Margin="5" />
<Button Content="Открыть форму для добавления товаров" Name="OpenServiceFormWindow" Click="OpenServiceFormWindow_Click" Margin="5" />
</StackPanel>
<ListBox Name="ServiceList" Margin="5">
<ListBox.ItemTemplate>
<DataTemplate>

View File

@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Linq;
using Demka_2.Use;
using System;
using Avalonia.Interactivity;
namespace Demka_2.Views;
@ -16,7 +17,12 @@ public partial class MainWindow : Window
private ComboBox _discountFilter;
private ListBox _serviceList;
private TextBlock _serviceCountText;
private TextBox _adminCodeBox;
private Button _adminLoginButton;
private StackPanel _adminControls;
private const string AdminCode = "0000";
private bool IsAdminMode = false;
public MainWindow()
{
InitializeComponent();
@ -31,10 +37,35 @@ public partial class MainWindow : Window
_discountFilter = this.FindControl<ComboBox>("DiscountFilter");
_serviceList = this.FindControl<ListBox>("ServiceList");
_serviceCountText = this.FindControl<TextBlock>("ServiceCountText");
_adminCodeBox = this.FindControl<TextBox>("AdminCodeBox");
_adminLoginButton = this.FindControl<Button>("AdminLoginButton");
_adminControls = this.FindControl<StackPanel>("AdminControls");
_serviceList.ItemsSource = FilteredServices;
_searchBox.TextChanged += SearchBox_TextChanged;
_discountFilter.SelectionChanged += DiscountFilter_SelectionChanged;
_adminLoginButton.Click += AdminLoginButton_Click;
}
private void AdminLoginButton_Click(object? sender, EventArgs e)
{
if (_adminCodeBox.Text == AdminCode)
{
IsAdminMode = true;
_adminControls.IsVisible = true;
}
else
{
IsAdminMode = false;
_adminControls.IsVisible = false;
}
}
private void OpenServiceFormWindow_Click(object sender, RoutedEventArgs e)
{
var selectedService = _serviceList.SelectedItem as Service;
var serviceFormWindow = new ServiceFormWindow(selectedService, Services);
serviceFormWindow.Show();
}
private void LoadServices()
@ -91,6 +122,8 @@ public partial class MainWindow : Window
UpdateFilteredServices();
}
private (decimal min, decimal max)? ParseDiscountRange(string rangeText)
{
return rangeText switch

View File

@ -0,0 +1,31 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Demka_2.Views.ServiceFormWindow"
Width="1200"
Height="800"
Title="Редактор Услуг">
<StackPanel Margin="10">
<TextBlock Text="Название" />
<TextBox Name="NameTextBox" />
<TextBlock Text="Стоимость" Margin="0,10" />
<TextBox Name="PriceTextBox" />
<TextBlock Text="Скидка (%)" Margin="0,10" />
<TextBox Name="DiscountTextBox" />
<TextBlock Text="Длительность (минуты)" Margin="0,10" />
<TextBox Name="DurationTextBox" />
<TextBlock Text="Описание" Margin="0,10" />
<TextBox Name="DescriptionTextBox" AcceptsReturn="True" Height="80" />
<TextBlock Text="Изображение" Margin="0,10" />
<StackPanel Orientation="Horizontal">
<Image Name="ThumbnailImage" Width="100" Height="100" Margin="0,0,10,0" />
<Button Content="Выбрать изображение" Name="SelectImageButton" />
</StackPanel>
<Button Content="Сохранить" Name="SaveButton" Margin="0,20" HorizontalAlignment="Center" />
</StackPanel>
</Window>

View File

@ -0,0 +1,145 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media.Imaging;
using Demka_2.Use;
using System;
using System.Collections.ObjectModel;
using System.Linq;
namespace Demka_2.Views
{
public partial class ServiceFormWindow : Window
{
private Service _service;
private ObservableCollection<Service> _services;
public ServiceFormWindow(Service service, ObservableCollection<Service> services)
{
InitializeComponent();
_service = service;
_services = services;
LoadServiceData();
SaveButton.Click += SaveButton_Click;
SelectImageButton.Click += SelectImageButton_Click;
/*
* AddServiceButton.Click += (s, e) =>
{
var serviceForm = new ServiceFormWindow(new Service(), Services);
serviceForm.ShowDialog(this).ContinueWith(_ => UpdateFilteredServices());
};
EditServiceButton.Click += (s, e) =>
{
if (_serviceList.SelectedItem is Service selectedService)
{
var serviceForm = new ServiceFormWindow(selectedService, Services);
serviceForm.ShowDialog(this).ContinueWith(_ => UpdateFilteredServices());
}
else
{
MessageBox.Show("Выберите услугу для редактирования.");
}
};
*/
}
private void LoadServiceData()
{
NameTextBox.Text = _service.Name;
PriceTextBox.Text = _service.Price.ToString();
DiscountTextBox.Text = _service.Discount.ToString();
DurationTextBox.Text = _service.Duration.ToString();
DescriptionTextBox.Text = _service.Description;
if (!string.IsNullOrEmpty(_service.ImagePath))
{
ThumbnailImage.Source = new Bitmap(_service.ImagePath);
}
}
private async void ShowMessage(string message)
{
var messageBox = new Window
{
Title = "Сообщение",
Content = message,
Width = 300,
Height = 150,
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
var okButton = new Button { Content = "ОК" };
okButton.Click += (s, e) => messageBox.Close();
messageBox.Content = new StackPanel
{
Children = { new TextBlock { Text = message }, okButton }
};
await messageBox.ShowDialog(this);
}
private void SaveButton_Click(object? sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(NameTextBox.Text))
{
ShowMessage("Название услуги не может быть пустым.");
return;
}
if (_services.Any(s => s.Name == NameTextBox.Text && s.guid != _service.guid))
{
ShowMessage("Услуга с таким названием уже существует.");
return;
}
if (!decimal.TryParse(PriceTextBox.Text, out var price) || price < 0)
{
ShowMessage("Введите корректную стоимость.");
return;
}
if (!decimal.TryParse(DiscountTextBox.Text, out var discount) || discount < 0 || discount > 100)
{
ShowMessage("Введите корректную скидку (0-100%).");
return;
}
if (!int.TryParse(DurationTextBox.Text, out var duration) || duration <= 0 || duration > 240)
{
ShowMessage("Введите корректную длительность (1-240 минут).");
return;
}
_service.Name = NameTextBox.Text;
_service.Price = price;
_service.Discount = discount;
_service.Duration = duration;
_service.Description = DescriptionTextBox.Text;
if (_service.guid == Guid.Empty)
{
_service.guid = Guid.NewGuid();
_services.Add(_service);
}
this.Close();
}
private async void SelectImageButton_Click(object? sender, RoutedEventArgs e)
{
var openFileDialog = new OpenFileDialog
{
Filters = { new FileDialogFilter { Name = "Images", Extensions = { "jpg", "png" } } }
};
var result = await openFileDialog.ShowAsync(this);
if (result?.Length > 0)
{
var imagePath = result[0];
_service.ImagePath = imagePath;
ThumbnailImage.Source = new Bitmap(imagePath);
}
}
}
}