using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Input; using Avalonia.Markup.Xaml; using DemoService.Models; using System.Collections.Generic; using System.Linq; using Avalonia.Media.TextFormatting; using Avalonia.Media.Imaging; using System; namespace DemoService; public partial class ServiceWindow : Window { private bool AdminMode; private List displayList = Utils.Context.Services; public ServiceWindow() { InitializeComponent(); ServicesListBox.ItemsSource = displayList; UserServicesListBox.ItemsSource = displayList; ServicesListBox.Background = Colors.lightYellow; UserServicesListBox.Background = Colors.lightYellow; SortComboBox.SelectedIndex = 0; FilterComboBox.SelectedIndex = 0; Icon = new WindowIcon(new Bitmap(AppDomain.CurrentDomain.BaseDirectory + "/Assets/service_logo.ico")); } public ServiceWindow(bool AdminMode) { InitializeComponent(); this.AdminMode = AdminMode; switch (this.AdminMode) { case true: ServicesListBox.ItemsSource = displayList; UserServicesListBox.IsVisible = false; ServicesListBox.Background = Colors.lightYellow; break; case false: AddButton.IsVisible = false; UserServicesListBox.ItemsSource = displayList; ServicesListBox.IsVisible = false; UserServicesListBox.Background = Colors.lightYellow; break; } SortComboBox.SelectedIndex = 0; FilterComboBox.SelectedIndex = 0; Icon = new WindowIcon(new Bitmap(AppDomain.CurrentDomain.BaseDirectory + "/Assets/service_logo.ico")); } public void AddButtonClick(object sender, RoutedEventArgs args) { AddEditWindow addEditWindow = new(AdminMode); 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; }*/ private void AddButton_Click(object? sender, RoutedEventArgs e) { AddEditWindow addEditWindow = new(); addEditWindow.Show(); Close(); } private void SortComboBox_SelectionChanged(object? sender, SelectionChangedEventArgs e) { DisplayService(); } private void SearchTextBox_KeyUp(object? sender, KeyEventArgs e) { DisplayService(); } private void FilterComboBox_SelectionChanged(object? sender, SelectionChangedEventArgs e) { DisplayService(); } private void DisplayService() { displayList = Utils.Context.Services; switch (SortComboBox.SelectedIndex) { case 0: break; case 1: displayList = displayList.OrderBy(service => service.Cost).ToList(); break; case 2: displayList = displayList.OrderByDescending(service => service.Cost).ToList(); break; } switch (FilterComboBox.SelectedIndex) { case 0: break; case 1: displayList = displayList.Where(x => x.Discount >= 0 && x.Discount < (decimal)0.05).ToList(); break; case 2: displayList = displayList.Where(x => x.Discount >= (decimal)0.05 && x.Discount < (decimal)0.15).ToList(); break; case 3: displayList = displayList.Where(x => x.Discount >= (decimal)0.15 && x.Discount < (decimal)0.30).ToList(); break; case 4: displayList = displayList.Where(x => x.Discount >= (decimal)0.30 && x.Discount < (decimal)0.70).ToList(); break; case 5: displayList = displayList.Where(x => x.Discount >= (decimal)0.70 && x.Discount < (decimal)1.00).ToList(); break; } if (!string.IsNullOrEmpty(SearchTextBox.Text)) { displayList = displayList.Where(x => x.Title.ToLower().Contains(SearchTextBox.Text.ToLower())).ToList(); } ServicesListBox.ItemsSource = displayList; } }