Compare commits

..

6 Commits
Deve ... master

Author SHA1 Message Date
Userok
0b7c5cc3fa 2024-12-27 16:15:01 +03:00
Userok
9ad2073e09 2024-12-27 16:07:13 +03:00
Userok
42f723d759 2024-12-27 15:48:34 +03:00
Userok
0db1698097 2024-12-27 14:47:18 +03:00
Userok
94849af572 2024-12-27 12:47:53 +03:00
17b761d0c0 Merge pull request 'Da' (#1) from Deve into master
Reviewed-on: #1
2024-12-27 09:06:20 +00:00
8 changed files with 281 additions and 11 deletions

View File

@ -11,7 +11,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" /> <PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.11" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.23" /> <PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
</ItemGroup> </ItemGroup>

View File

@ -17,7 +17,13 @@
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.--> <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.3" /> <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.11" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.23" /> <PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Update="Views\ServiceFormWindow.axaml.cs">
<DependentUpon>ServiceFormWindow.axaml</DependentUpon>
</Compile>
</ItemGroup>
</Project> </Project>

View File

@ -8,6 +8,6 @@ public class AppDbContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder oB) protected override void OnConfiguring(DbContextOptionsBuilder oB)
{ {
oB.UseSqlServer("Host=45.67.56.214;Port=5421;Username=user16;Password=dZ28IVE5;Database=user16"); oB.UseSqlServer("Server=45.67.56.214,5421;Database=user16;User Id=user16;Password=dZ28IVE5;");
} }
} }

View File

@ -1,7 +1,13 @@
namespace Demka_2.Use; using System;
using System.ComponentModel.DataAnnotations;
namespace Demka_2.Use;
public class Service public class Service
{ {
[Key]
public Guid guid { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string ImagePath { get; set; }
public decimal Price { get; set; } public decimal Price { get; set; }
public decimal Discount { get; set; } public decimal Discount { get; set; }
public int Duration { get; set; } public int Duration { get; set; }

View File

@ -1,7 +1,7 @@
<Window xmlns="https://github.com/avaloniaui" <Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Demka_2.Views.MainWindow" x:Class="Demka_2.Views.MainWindow"
Width="800" Height="600" Width="1200" Height="800"
Title="Список услуг"> Title="Список услуг">
<DockPanel> <DockPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="5"> <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="5">
@ -16,11 +16,22 @@
<TextBlock Text="70-100%" /> <TextBlock Text="70-100%" />
</ComboBox.Items> </ComboBox.Items>
</ComboBox> </ComboBox>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="5">
<TextBox Width="200" Watermark="Код администратора..." Name="AdminCodeBox" />
<Button Content="Войти как администратор" Name="AdminLoginButton" Margin="5" />
</StackPanel>
<Button Content="Сортировка ↑" Name="SortAscButton" Margin="5" /> <Button Content="Сортировка ↑" Name="SortAscButton" Margin="5" />
<Button Content="Сортировка ↓" Name="SortDescButton" /> <Button Content="Сортировка ↓" Name="SortDescButton" />
</StackPanel> </StackPanel>
<ListBox Name="ServiceList" Margin="5"> <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" Width="600">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Vertical" Background="{Binding BackgroundColor}" Margin="5"> <StackPanel Orientation="Vertical" Background="{Binding BackgroundColor}" Margin="5">
@ -35,7 +46,6 @@
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
<TextBlock Name="ServiceCountText" DockPanel.Dock="Bottom" Margin="50" HorizontalAlignment="Center" />
<TextBlock Name="ServiceCountText" DockPanel.Dock="Bottom" Margin="5" HorizontalAlignment="Center" />
</DockPanel> </DockPanel>
</Window> </Window>

View File

@ -4,6 +4,8 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Demka_2.Use; using Demka_2.Use;
using System; using System;
using Avalonia.Interactivity;
using DynamicData;
namespace Demka_2.Views; namespace Demka_2.Views;
@ -16,7 +18,12 @@ public partial class MainWindow : Window
private ComboBox _discountFilter; private ComboBox _discountFilter;
private ListBox _serviceList; private ListBox _serviceList;
private TextBlock _serviceCountText; private TextBlock _serviceCountText;
private TextBox _adminCodeBox;
private Button _adminLoginButton;
private StackPanel _adminControls;
private const string AdminCode = "0000";
private bool IsAdminMode = false;
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
@ -31,15 +38,40 @@ public partial class MainWindow : Window
_discountFilter = this.FindControl<ComboBox>("DiscountFilter"); _discountFilter = this.FindControl<ComboBox>("DiscountFilter");
_serviceList = this.FindControl<ListBox>("ServiceList"); _serviceList = this.FindControl<ListBox>("ServiceList");
_serviceCountText = this.FindControl<TextBlock>("ServiceCountText"); _serviceCountText = this.FindControl<TextBlock>("ServiceCountText");
_adminCodeBox = this.FindControl<TextBox>("AdminCodeBox");
_adminLoginButton = this.FindControl<Button>("AdminLoginButton");
_adminControls = this.FindControl<StackPanel>("AdminControls");
_serviceList.ItemsSource = FilteredServices; _serviceList.ItemsSource = FilteredServices;
_searchBox.TextChanged += SearchBox_TextChanged; _searchBox.TextChanged += SearchBox_TextChanged;
_discountFilter.SelectionChanged += DiscountFilter_SelectionChanged; _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() private void LoadServices()
{ {
using (var context = new AppDbContext()) /*using (var context = new AppDbContext())
{ {
var services = context.Services.ToList(); var services = context.Services.ToList();
foreach (var service in services) foreach (var service in services)
@ -47,7 +79,29 @@ public partial class MainWindow : Window
Services.Add(service); Services.Add(service);
} }
} }*/
Services.Add(new Service { Name = "Услуга 1", Price = 100, Duration = 30, Discount = 0 });
Services.Add(new Service { Name = "Услуга 2", Price = 200, Duration = 60, Discount = 10 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 40 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 60 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 80 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
Services.Add(new Service { Name = "Услуга 3", Price = 150, Duration = 45, Discount = 20 });
} }
private void UpdateFilteredServices() private void UpdateFilteredServices()
@ -91,6 +145,27 @@ public partial class MainWindow : Window
UpdateFilteredServices(); UpdateFilteredServices();
} }
public 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 (decimal min, decimal max)? ParseDiscountRange(string rangeText) private (decimal min, decimal max)? ParseDiscountRange(string rangeText)
{ {
return rangeText switch 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,142 @@
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
// {
// ShowMessage("Выберите услугу для редактирования.");
// }
//};
}
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);
}
}
public 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);
}
}
}
}