79 lines
1.9 KiB
C#
79 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 PartnerWindow : Window
|
|
{
|
|
User8Context context = new User8Context();
|
|
|
|
public PartnerWindow()
|
|
{
|
|
InitializeComponent();
|
|
LoadPartners();
|
|
}
|
|
|
|
public void LoadPartners()
|
|
{
|
|
try
|
|
{
|
|
var products = context.Partners
|
|
.Include(pp => pp.Partnerproducts)
|
|
.Include(pt => pt.PartnerType)
|
|
.Select(pp => new
|
|
{
|
|
Id = pp.Id,
|
|
PartnerName = pp.PartnerName,
|
|
DirectorName = pp.DirectorName,
|
|
Phone = pp.Phone,
|
|
Rating = pp.Rating,
|
|
PartnerTypeString = pp.PartnerType.PartnerTypeName
|
|
|
|
})
|
|
.ToList();
|
|
|
|
PartnerLB.ItemsSource = products;
|
|
|
|
}
|
|
catch
|
|
{
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
public static int? CalculateDiscount(int? quantity)
|
|
{
|
|
if (quantity < 10000)
|
|
return 0;
|
|
if (quantity > 10000 && quantity <= 50000)
|
|
return 5;
|
|
if (quantity > 50000 && quantity <= 300000)
|
|
return 10;
|
|
if (quantity > 300000)
|
|
return 15;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
private async void Button_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
await new AddEditPartnerWindow().ShowDialog(this);
|
|
LoadPartners();
|
|
}
|
|
|
|
private async void ListBoxItem_DoubleTapped(object? sender, Avalonia.Input.TappedEventArgs e)
|
|
{
|
|
int ind = (int)(sender as ListBoxItem).Tag;
|
|
var clickedPartner = context.Partners.Find(ind);
|
|
if (clickedPartner != null)
|
|
{
|
|
await new AddEditPartnerWindow(clickedPartner).ShowDialog(this);
|
|
LoadPartners();
|
|
}
|
|
}
|
|
} |