131 lines
3.9 KiB
C#
131 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using demo_hard.Models;
|
|
using Tmds.DBus.Protocol;
|
|
|
|
namespace demo_hard;
|
|
|
|
public partial class OrderWindow : Window
|
|
{
|
|
private ObservableCollection<int> _ordersIds = new();
|
|
private ObservableCollection<string> _clientsNames = new();
|
|
private ObservableCollection<string> _servicesNames = new();
|
|
private List<Service> SelectedServices = new();
|
|
public List<int> OrderIdList;
|
|
public List<string> ClientNamesList;
|
|
public List<string> ServicesList;
|
|
|
|
public OrderWindow()
|
|
{
|
|
InitializeComponent();
|
|
SearchItems();
|
|
using var context = new User2Context();
|
|
|
|
OrderIdList = context.Orders.Select(it => it.Id).ToList();
|
|
|
|
var services = context.Services.ToList();
|
|
serviceName.ItemsSource = services;
|
|
|
|
var clients = context.Clients.ToList();
|
|
clientName.ItemsSource = clients;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SearchItems()
|
|
{
|
|
using var context = new User2Context();
|
|
string searchText = SearchBox.Text?.ToLower() ?? "";
|
|
if (string.IsNullOrWhiteSpace(searchText))
|
|
{
|
|
SearchResultsList.ItemsSource = new List<string>();
|
|
return;
|
|
}
|
|
|
|
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();
|
|
SearchResultsList.ItemsSource = results;
|
|
}
|
|
|
|
private void SearchBox_OnTextChanged(object? sender, TextChangedEventArgs e)
|
|
{
|
|
SearchItems();
|
|
}
|
|
|
|
private void AddService_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (serviceName.SelectedItem is Service selectedService && !SelectedServices.Contains(selectedService))
|
|
{
|
|
SelectedServices.Add(selectedService);
|
|
UpdateServiceList();
|
|
}
|
|
}
|
|
|
|
private void UpdateServiceList()
|
|
{
|
|
SelectedServicesListBox.ItemsSource = null;
|
|
SelectedServicesListBox.ItemsSource = SelectedServices.Select(s => s.ServiceName).ToList();
|
|
}
|
|
|
|
|
|
private void Go_Back_Button(object? sender, RoutedEventArgs e)
|
|
{
|
|
new FunctionWindow().ShowDialog(this);
|
|
}
|
|
|
|
private void AddUser_Button(object? sender, RoutedEventArgs e)
|
|
{
|
|
new AddClient().ShowDialog(this);
|
|
}
|
|
|
|
private void Create_Order(object? sender, RoutedEventArgs e)
|
|
{
|
|
|
|
Client selectedClient = clientName.SelectedItem as Client;
|
|
List<Service> selectedServices = new List<Service>(SelectedServices);
|
|
var duration = int.Parse(Duration.Text);
|
|
using var context = new User2Context();
|
|
List<int> orderNumbers = new List<int>();
|
|
Client client = selectedClient;
|
|
foreach (var service in selectedServices)
|
|
{
|
|
|
|
orderNumbers = new List<int>(context.Orders.Select(o=>o.Id));
|
|
|
|
var newOrder = new Order
|
|
{
|
|
Id = orderNumbers.Count+1,
|
|
OrderCode = client.ClientCode + "/" + DateTime.Now.ToString("dd/MM/yyyy"),
|
|
OrderDate = DateOnly.FromDateTime(DateTime.Now),
|
|
OrderTime = TimeOnly.FromDateTime(DateTime.Now),
|
|
ClientCode = client.ClientCode,
|
|
ServiceId = service.Id,
|
|
Status = "Новая",
|
|
DateClose = null,
|
|
RentalTime = duration
|
|
};
|
|
context.Orders.Add(newOrder);
|
|
context.SaveChanges();
|
|
}
|
|
|
|
|
|
|
|
if (selectedClient != null && duration!=null && selectedServices.Any())
|
|
{
|
|
new NewOrderWindow(selectedClient, selectedServices, duration).ShowDialog(this);
|
|
}
|
|
}
|
|
} |