repo2403/ProductWindow.axaml.cs
2025-03-24 14:59:01 +03:00

67 lines
1.9 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using demka2025_sedelnikov.Context;
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace demka2025_sedelnikov;
public partial class ProductWindow : Window
{
User8Context context = new User8Context();
public ProductWindow()
{
InitializeComponent();
LoadProducts();
}
public void LoadProducts()
{
var products = context.Products
.Include(pp => pp.Partnerproducts)
.ThenInclude(pn => pn.Partner)
.Select(pp => new
{
Id = pp.Id,
ProductName = pp.ProductName,
Articul = pp.Articul,
MinCost = pp.MinCost,
ProductCoeffString = pp.Type.Coeff.ToString(),
ProductTypeString = pp.Type.ProductTypeName,
Partners = pp.Partnerproducts.Select(p => $"{p.Partner.PartnerName} - {p.Quantity}")
})
.ToList();
ProductsLB.ItemsSource = products;
}
public static string DefineColor(int? quantity)
{
if (quantity < 10000)
return "LightRed";
if (quantity > 10000 && quantity <= 60000)
return "LightOrange";
if (quantity > 60000)
return "LightGreen";
else
return "";
}
private async void Grid_DoubleTapped(object? sender, Avalonia.Input.TappedEventArgs e)
{
int ind = (int)
(sender as ListBoxItem).Tag;
var clickedProduct = context.Products.Find(ind);
if (clickedProduct != null)
{
await new AddEditProductWindow(clickedProduct).ShowDialog(this);
LoadProducts();
}
}
private async void Button_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
await new AddEditProductWindow().ShowDialog(this);
LoadProducts();
}
}