68 lines
2.1 KiB
C#
68 lines
2.1 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Avalonia.Controls;
|
||
using Avalonia.Interactivity;
|
||
using demo_hard.Models;
|
||
|
||
namespace demo_hard;
|
||
|
||
public partial class NewOrderWindow : Window
|
||
{
|
||
|
||
public NewOrderWindow()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
public NewOrderWindow(Client client, List<Service> selectedServices, int duration )
|
||
{
|
||
InitializeComponent();
|
||
using var context = new User2Context();
|
||
List<int> allServices = new List<int>();
|
||
allServices = selectedServices.Select(service => service.Id).ToList();
|
||
List<int> orderNumbers = new List<int>();
|
||
orderNumbers = new List<int>(context.Orders.Select(o=>o.Id));
|
||
|
||
OrderNumberText.Text = orderNumbers.Count+1.ToString();
|
||
ClientCode.Text = client.ClientCode.ToString();
|
||
TimeOrder.Text = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
|
||
FIO.Text = client.Fio;
|
||
Address.Text = client.Address;
|
||
ServicesList.ItemsSource = selectedServices.Select(it => it.ServiceName).ToList();
|
||
var totalcost = selectedServices.Sum(it =>
|
||
{
|
||
var serviceCost = decimal.TryParse(it.ServiceCost, out var cost) ? cost : 0;
|
||
return cost;
|
||
});
|
||
Cost.Text = $"{totalcost}.00 руб.";
|
||
|
||
|
||
|
||
|
||
for (int i = 0; i < allServices.Count; i++)
|
||
{
|
||
|
||
|
||
var newOrder = new Order
|
||
{
|
||
Id = orderNumbers.Count+1,
|
||
OrderCode = ClientCode + "/" + DateTime.Now.ToString("dd/MM/yyyy"),
|
||
OrderDate = DateOnly.FromDateTime(DateTime.Now),
|
||
OrderTime = TimeOnly.FromDateTime(DateTime.Now),
|
||
ClientCode = client.ClientCode,
|
||
ServiceId = allServices[i],
|
||
Status = "Новая",
|
||
DateClose = null,
|
||
RentalTime = duration
|
||
};
|
||
context.Orders.Add(newOrder);
|
||
context.SaveChanges();
|
||
}
|
||
|
||
}
|
||
|
||
private void ButtonBack_OnClick(object? sender, RoutedEventArgs e)
|
||
{
|
||
new OrderWindow().ShowDialog(this);
|
||
}
|
||
} |