DemoService/ServiceWindow.axaml.cs

82 lines
2.3 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 bool? SortedMode;
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-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-05 13:11:39 +00:00
foreach (var service in ServicesListBox.ItemsSource)
{
}
}
public void AddButtonClick(object sender, RoutedEventArgs args)
{
AddEditWindow addEditWindow = new();
addEditWindow.Show();
Close();
}
private decimal? CostAfterDiscount(decimal previousCost, decimal? discount)
{
if (discount.HasValue || discount != 0)
{
decimal actualCost = previousCost - previousCost * discount.Value;
return actualCost;
}
return null;
2024-09-04 09:08:53 +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)
{
int selectedIndex = (sender as ComboBox).SelectedIndex;
switch (selectedIndex)
{
case 0: SortedMode = false; break;
case 1: SortedMode = true; break;
default: SortedMode = null; break;
}
DisplayService();
}
private void DisplayService()
{
switch (SortedMode)
{
case true:
displayList = displayList.OrderBy(service => service.Cost).ToList();
break;
case false:
displayList = displayList.OrderByDescending(service => service.Cost).ToList();
break;
}
ServicesListBox.ItemsSource = displayList.ToList();
}
2024-09-04 09:08:53 +00:00
}