demo_hard/SallerWindow.axaml.cs

116 lines
3.4 KiB
C#
Raw Normal View History

2025-02-11 13:17:16 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2025-02-05 10:07:55 +00:00
using Avalonia;
using Avalonia.Controls;
2025-02-11 13:17:16 +00:00
using Avalonia.Interactivity;
2025-02-05 10:07:55 +00:00
using Avalonia.Markup.Xaml;
2025-02-11 13:17:16 +00:00
using demo_hard.Model;
2025-02-05 10:07:55 +00:00
namespace demo_hard;
public partial class SallerWindow : Window
{
2025-02-19 09:09:03 +00:00
private List<Service> SelectedServices = new();
2025-02-05 10:07:55 +00:00
public SallerWindow()
{
InitializeComponent();
2025-02-11 13:17:16 +00:00
OrderNubmber();
LoadClients();
LoadService();
SearchItems();
}
private void OrderNubmber()
{
2025-02-19 09:09:03 +00:00
using var context = new User2Context();
2025-02-11 13:17:16 +00:00
var OrderId = context.Orders.Max(o => o.Id) + 1;
if (context.Orders.Any(o => o.Id == OrderId)) throw new ArgumentException("Номера Id не должны совпадать");
if (OrderId < 1) throw new ArgumentException("OrderId must be greater than 1");
2025-02-19 09:09:03 +00:00
CompleteBox.ItemsSource = new string[] { OrderId.ToString() };
2025-02-11 13:17:16 +00:00
}
2025-02-19 09:09:03 +00:00
2025-02-11 13:17:16 +00:00
private void LoadClients()
{
2025-02-19 09:09:03 +00:00
using var context = new User2Context();
2025-02-11 13:17:16 +00:00
var client = context.Clients.ToList();
Clients_ComboBox.ItemsSource = client;
}
private void Clients_ComboBox_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (Clients_ComboBox.SelectedItem is Client selectedClient)
{
Console.WriteLine($"Вы выбрали: {selectedClient.Fio}");
}
}
private void Go_Back_Button(object? sender, RoutedEventArgs e)
{
new FunctionWindow().ShowDialog(this);
}
private void LoadService()
{
2025-02-19 09:09:03 +00:00
using var context = new User2Context();
2025-02-11 13:17:16 +00:00
var service = context.Services.ToList();
Service_Combobox.ItemsSource = service;
}
2025-02-19 09:09:03 +00:00
private void Service_Combobox_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (Service_Combobox.SelectedItem is Service selectedService)
{
Console.WriteLine($"Вы выбрали услугу: {selectedService.ServiceName}");
}
}
private void AddService_Button(object? sender, RoutedEventArgs e)
2025-02-11 13:17:16 +00:00
{
2025-02-19 09:09:03 +00:00
if (Service_Combobox.SelectedItem is Service selectedService && !SelectedServices.Contains(selectedService))
2025-02-11 13:17:16 +00:00
{
2025-02-19 09:09:03 +00:00
SelectedServices.Add(selectedService);
UpdateServiceList();
2025-02-11 13:17:16 +00:00
}
}
2025-02-19 09:09:03 +00:00
private void UpdateServiceList()
{
SelectedServicesListBox.ItemsSource = null;
SelectedServicesListBox.ItemsSource = SelectedServices.Select(s => s.ServiceName).ToList();
}
2025-02-11 13:17:16 +00:00
private void SearchItems()
{
2025-02-19 09:09:03 +00:00
using var context = new User2Context();
string searchText = SearchBox.Text?.ToLower() ?? "";
if (string.IsNullOrWhiteSpace(searchText))
2025-02-11 13:17:16 +00:00
{
SearchResultsListBox.ItemsSource = new List<string>();
2025-02-19 09:09:03 +00:00
return;
2025-02-11 13:17:16 +00:00
}
2025-02-19 09:09:03 +00:00
var clientRes = context.Clients
.Where(c => c.Fio.ToLower().Contains(searchText))
.Select(c => c.Fio);
var serviceRes = context.Services
.Where(s => s.ServiceName.ToLower().Contains(searchText))
.Select(s => s.ServiceName);
var results = clientRes.Concat(serviceRes).ToList();
2025-02-11 13:17:16 +00:00
SearchResultsListBox.ItemsSource = results;
}
2025-02-19 09:09:03 +00:00
private void SearchBox_Changed(object? sender, TextChangedEventArgs e)
2025-02-11 13:17:16 +00:00
{
SearchItems();
}
private void AddUser_Button(object? sender, RoutedEventArgs e)
{
2025-02-19 09:09:03 +00:00
new AddClient().ShowDialog(this);
2025-02-05 10:07:55 +00:00
}
2025-02-19 09:09:03 +00:00
}