DemoService/ServiceWindow.axaml.cs

80 lines
2.2 KiB
C#
Raw Normal View History

2024-09-04 09:08:53 +00:00
using Avalonia;
using Avalonia.Controls;
2024-09-05 13:11:39 +00:00
using Avalonia.Interactivity;
2024-09-04 09:08:53 +00:00
using Avalonia.Markup.Xaml;
2024-09-05 13:11:39 +00:00
using DemoService.Models;
2024-09-06 14:13:21 +00:00
using System.Collections.Generic;
using System.Linq;
2024-09-04 09:08:53 +00:00
namespace DemoService;
public partial class ServiceWindow : Window
{
2024-09-05 13:11:39 +00:00
private readonly bool AdminMode;
2024-09-06 14:13:21 +00:00
private List<Service> displayList = Utils.Context.Services;
2024-09-04 09:08:53 +00:00
public ServiceWindow()
{
InitializeComponent();
2024-09-06 14:13:21 +00:00
ServicesListBox.ItemsSource = displayList;
2024-09-09 06:46:08 +00:00
SortComboBox.SelectedIndex = 0;
2024-09-04 09:08:53 +00:00
}
public ServiceWindow(bool admin)
{
InitializeComponent();
2024-09-05 13:11:39 +00:00
AdminMode = admin;
if (!admin)
{
AddButton.IsVisible = false;
}
2024-09-06 14:13:21 +00:00
ServicesListBox.ItemsSource = displayList;
2024-09-09 06:46:08 +00:00
/*foreach (var service in ServicesListBox.ItemsSource)
2024-09-05 13:11:39 +00:00
{
2024-09-09 06:46:08 +00:00
}*/
SortComboBox.SelectedIndex = 0;
2024-09-05 13:11:39 +00:00
}
public void AddButtonClick(object sender, RoutedEventArgs args)
{
AddEditWindow addEditWindow = new();
addEditWindow.Show();
Close();
}
2024-09-09 06:46:08 +00:00
/*private decimal? CostAfterDiscount(decimal previousCost, decimal? discount)
2024-09-05 13:11:39 +00:00
{
if (discount.HasValue || discount != 0)
{
decimal actualCost = previousCost - previousCost * discount.Value;
return actualCost;
}
return null;
2024-09-09 06:46:08 +00:00
}*/
2024-09-06 14:13:21 +00:00
private void AddButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
AddEditWindow addEditWindow = new();
addEditWindow.Show();
Close();
}
private void SortComboBox_SelectionChanged(object? sender, Avalonia.Controls.SelectionChangedEventArgs e)
{
DisplayService();
}
2024-09-09 06:46:08 +00:00
2024-09-06 14:13:21 +00:00
private void DisplayService()
{
2024-09-09 06:46:08 +00:00
switch (SortComboBox.SelectedIndex)
2024-09-06 14:13:21 +00:00
{
2024-09-09 06:46:08 +00:00
case 0:
displayList = Utils.Context.Services;
break;
case 1:
2024-09-06 14:13:21 +00:00
displayList = displayList.OrderBy(service => service.Cost).ToList();
break;
2024-09-09 06:46:08 +00:00
case 2:
2024-09-06 14:13:21 +00:00
displayList = displayList.OrderByDescending(service => service.Cost).ToList();
break;
}
2024-09-09 06:46:08 +00:00
ServicesListBox.ItemsSource = displayList;
2024-09-06 14:13:21 +00:00
}
2024-09-04 09:08:53 +00:00
}