53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Markup.Xaml;
|
|
using Lagerprogramm.Models;
|
|
using Lagerprogramm.ViewModels;
|
|
using Avalonia;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Lagerprogramm.Views;
|
|
|
|
public partial class DeductionsView : UserControl
|
|
{
|
|
public DeductionsView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private DeductionsViewModel? ViewModel => DataContext as DeductionsViewModel;
|
|
|
|
private async void OnSearchPart(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
if (ViewModel is null) return;
|
|
var button = sender as Button;
|
|
var line = button?.CommandParameter as TransactionLine;
|
|
if (line is null) return;
|
|
|
|
var window = TopLevel.GetTopLevel(this) as Window;
|
|
if (window is null) return;
|
|
var dialog = new PartSearchDialog();
|
|
var selectedPart = await dialog.ShowPartSearch(ViewModel.AppData.Parts, window);
|
|
if (selectedPart is not null)
|
|
line.PartInternalNumber = selectedPart.InternalPartNumber;
|
|
}
|
|
|
|
private async void OnSearchDeduction(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
if (ViewModel is null) return;
|
|
var window = TopLevel.GetTopLevel(this) as Window;
|
|
if (window is null) return;
|
|
var dialog = new DeductionSearchDialog();
|
|
var selectedDeduction = await dialog.ShowDeductionSearch(ViewModel.Deductions, window);
|
|
if (selectedDeduction is not null)
|
|
{
|
|
ViewModel.Date = selectedDeduction.Date;
|
|
ViewModel.Customer = selectedDeduction.Customer;
|
|
ViewModel.Comment = selectedDeduction.Comment;
|
|
ViewModel.GenerateDeliveryNote = selectedDeduction.GenerateDeliveryNote;
|
|
ViewModel.Lines.Clear();
|
|
foreach (var l in selectedDeduction.Lines)
|
|
ViewModel.Lines.Add(new TransactionLine { PartInternalNumber = l.PartInternalNumber, Quantity = l.Quantity });
|
|
}
|
|
}
|
|
}
|