FinalDemo/Hard_Demo/NewOrderWindow.axaml.cs

42 lines
1.3 KiB
C#
Raw Permalink Normal View History

2025-03-09 15:00:01 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Hard_Demo.Models;
namespace Hard_Demo;
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> 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 руб.";
}
private void ButtonBack_OnClick(object? sender, RoutedEventArgs e)
{
new OrderWindow().ShowDialog(this);
}
}