102 lines
2.6 KiB
C#
102 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using demofinish.Model;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace demofinish;
|
|
|
|
public partial class HistoryWindow : Window
|
|
{
|
|
private ObservableCollection<Productsale> products = new ObservableCollection<Productsale>();
|
|
private ObservableCollection<Productsale> allProducts = new ObservableCollection<Productsale>();
|
|
|
|
public HistoryWindow()
|
|
{
|
|
InitializeComponent();
|
|
LoadInfo();
|
|
}
|
|
|
|
private void LoadInfo()
|
|
{
|
|
using var context = new User1Context();
|
|
|
|
var productSales = context.Productsales
|
|
.Include(ps => ps.Product)
|
|
.Include(ps => ps.Agent)
|
|
.ToList();
|
|
|
|
allProducts.Clear();
|
|
products.Clear();
|
|
|
|
foreach (var item in productSales)
|
|
{
|
|
allProducts.Add(item);
|
|
products.Add(item);
|
|
}
|
|
|
|
ProductListBox.ItemsSource = products;
|
|
|
|
|
|
SearchBox.ItemsSource = allProducts
|
|
.Select(p => p.Product.Title)
|
|
.Distinct()
|
|
.ToList();
|
|
}
|
|
|
|
private void SearchBox_OnTextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
var searchText = SearchBox.Text?.ToLower() ?? string.Empty;
|
|
|
|
if (string.IsNullOrWhiteSpace(searchText))
|
|
{
|
|
|
|
products.Clear();
|
|
foreach (var item in allProducts)
|
|
{
|
|
products.Add(item);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
var filtered = allProducts
|
|
.Where(p => p.Product.Title.ToLower().Contains(searchText))
|
|
.ToList();
|
|
|
|
products.Clear();
|
|
foreach (var item in filtered)
|
|
{
|
|
products.Add(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SearchBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (SearchBox.SelectedItem is string selectedProduct)
|
|
{
|
|
var filtered = allProducts
|
|
.Where(p => p.Product.Title.Equals(selectedProduct, StringComparison.OrdinalIgnoreCase))
|
|
.ToList();
|
|
|
|
products.Clear();
|
|
foreach (var item in filtered)
|
|
{
|
|
products.Add(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void AddNewPosition(object? sender, RoutedEventArgs e)
|
|
{
|
|
new AddNewPosition().ShowDialog(this);
|
|
}
|
|
|
|
private void BackClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
} |