210 lines
7.7 KiB
C#
210 lines
7.7 KiB
C#
using Avalonia.Controls;
|
|
using AvaloniaAppApplication.DTO;
|
|
using AvaloniaAppApplication.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using MsBox.Avalonia;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
namespace AvaloniaAppApplication
|
|
{
|
|
public partial class MainWindow : Window
|
|
{
|
|
public List<ServiceDTO> filteredServices = new List<ServiceDTO>();
|
|
public List<ServiceDTO> servicesList = new List<ServiceDTO>();
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
if (Manager.isAdmin == true)
|
|
{
|
|
AddServiceButton.IsVisible = true;
|
|
ViewClosestAppointments.IsVisible = true;
|
|
}
|
|
loadServices();
|
|
|
|
|
|
}
|
|
|
|
public void loadServices()
|
|
{
|
|
servicesList = Manager.context.Services.Select(s =>
|
|
new ServiceDTO
|
|
{
|
|
Id = s.Id,
|
|
Title = s.Title,
|
|
Discount = (float?)s.Discount,
|
|
Description = s.Description,
|
|
Durationinseconds = s.Durationinseconds,
|
|
ClientServices = s.Clientservices,
|
|
Cost = (float)s.Cost,
|
|
MainImagePath = s.Mainimagepath,
|
|
ImageBitmap = s.Mainimagepath != null ? new Avalonia.Media.Imaging.Bitmap(AppDomain.CurrentDomain.BaseDirectory.ToString() + s.Mainimagepath.Trim()) : null
|
|
}).ToList();
|
|
|
|
|
|
var comboPriceList = new List<string>() { "Ïî óìîë÷àíèþ", "Ïî âîçðàñòàíèþ öåíû", "Ïî óáûâàíèþ öåíû" };
|
|
var comboFilterList = new List<string>() { "Âñå âàðèàíòû", " îò 0 äî 5%", "îò 5% äî 15%", " îò 15% äî 30%", "îò 30% äî 70%", "îò 70% äî 100%" };
|
|
ComboPrice.ItemsSource = comboPriceList;
|
|
ComboDiscount.ItemsSource = comboFilterList;
|
|
ProductListBox.ItemsSource = servicesList;
|
|
|
|
DisplayedItemsNumber.Text = servicesList.Count.ToString();
|
|
TotalItemsNumber.Text = servicesList.Count.ToString();
|
|
|
|
ComboDiscount.SelectedIndex = -1;
|
|
ComboPrice.SelectedIndex = -1;
|
|
ServiceSearchTextBox.Text = null;
|
|
|
|
}
|
|
|
|
public void method()
|
|
{
|
|
var list = Manager.context.Services.ToList();
|
|
foreach ( var item in list )
|
|
{
|
|
if (item.Discount < 1)
|
|
item.Discount = item.Discount * 100;
|
|
}
|
|
Manager.context.SaveChanges();
|
|
}
|
|
private async void AddServiceButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
await new AddEditWindow().ShowDialog(this);
|
|
loadServices();
|
|
}
|
|
|
|
private void ServiceSearchTextBox_TextChanged(object? sender, Avalonia.Controls.TextChangedEventArgs e)
|
|
{
|
|
UpdateListBox();
|
|
}
|
|
|
|
private void ComboPrice_SelectionChanged(object? sender, Avalonia.Controls.SelectionChangedEventArgs e)
|
|
{
|
|
UpdateListBox();
|
|
|
|
}
|
|
|
|
private void ComboDiscount_SelectionChanged(object? sender, Avalonia.Controls.SelectionChangedEventArgs e)
|
|
{
|
|
UpdateListBox();
|
|
|
|
}
|
|
|
|
public void UpdateListBox()
|
|
{
|
|
filteredServices = servicesList;
|
|
|
|
// ïîèñê
|
|
if (!string.IsNullOrEmpty(ServiceSearchTextBox.Text))
|
|
{
|
|
string searchText = ServiceSearchTextBox.Text.ToLower().Trim();
|
|
filteredServices = filteredServices.Where(s => s.Title.ToLower().Trim().Contains(searchText) || s.Description != null && s.Description.ToLower().Trim().Contains(searchText)).ToList();
|
|
}
|
|
|
|
// ôèëüòðàöèÿ
|
|
if (ComboDiscount.SelectedIndex > 0)
|
|
{
|
|
switch (ComboDiscount.SelectedIndex)
|
|
{
|
|
case 1:
|
|
filteredServices = filteredServices.Where(s => s.Discount >= 0 && s.Discount < 5).ToList();
|
|
break;
|
|
case 2:
|
|
filteredServices = filteredServices.Where(s => s.Discount >= 5 && s.Discount < 15).ToList();
|
|
break;
|
|
|
|
case 3:
|
|
filteredServices = filteredServices.Where(s => s.Discount >= 15 && s.Discount < 30).ToList();
|
|
break;
|
|
|
|
case 4:
|
|
filteredServices = filteredServices.Where(s => s.Discount >= 30 && s.Discount < 70).ToList();
|
|
break;
|
|
|
|
case 5:
|
|
filteredServices = filteredServices.Where(s => s.Discount >= 70 && s.Discount < 100).ToList();
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
// ñîðòèðîâêà
|
|
switch (ComboPrice.SelectedIndex)
|
|
{
|
|
case 1:
|
|
filteredServices = filteredServices.OrderBy(s => s.CostWithDiscount).ToList();
|
|
break;
|
|
case 2:
|
|
filteredServices = filteredServices.OrderByDescending(s => s.CostWithDiscount).ToList();
|
|
break;
|
|
}
|
|
|
|
ProductListBox.ItemsSource = filteredServices;
|
|
DisplayedItemsNumber.Text = filteredServices.Count.ToString();
|
|
TotalItemsNumber.Text = servicesList.Count.ToString();
|
|
}
|
|
|
|
private async void EditButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
if (Manager.isAdmin == false)
|
|
{
|
|
var mes = MessageBoxManager.GetMessageBoxStandard("Îøèáêà!", "Òîëüêî àäìèíèñòðàòîð ìîæåò ïðàâèòü äàííûå!");
|
|
var res = await mes.ShowWindowDialogAsync(this);
|
|
return;
|
|
}
|
|
var serviceToEdit = (sender as Button).DataContext as ServiceDTO;
|
|
await new AddEditWindow(serviceToEdit).ShowDialog(this);
|
|
loadServices();
|
|
}
|
|
|
|
private async void DeleteButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
if (Manager.isAdmin == false)
|
|
{
|
|
|
|
var msss = MessageBoxManager.GetMessageBoxStandard("Îøèáêà!", "Òîëüêî àäìèíèñòðàòîð ìîæåò ïðàâèòü äàííûå!");
|
|
var bb = await msss.ShowWindowDialogAsync(this);
|
|
return;
|
|
}
|
|
|
|
|
|
var serviceFressed = (sender as Button).DataContext as ServiceDTO;
|
|
var serviceToDelete = Manager.context.Services.FirstOrDefault(s => s.Id == serviceFressed.Id);
|
|
var clientServicesToDelete = Manager.context.Clientservices
|
|
.Where(cs => cs.Serviceid == serviceToDelete.Id);
|
|
Manager.context.Clientservices.RemoveRange(clientServicesToDelete);
|
|
Manager.context.Services.Remove(serviceToDelete);
|
|
Manager.context.SaveChanges();
|
|
var mes = MessageBoxManager.GetMessageBoxStandard("OK!", "Èíôîðìàöèÿ óäàëåíà óñïåøíî!");
|
|
var res = await mes.ShowWindowDialogAsync(this);
|
|
loadServices();
|
|
return;
|
|
}
|
|
|
|
private async void LogOutButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
|
|
AuthWindow authW = new AuthWindow();
|
|
authW.Show();
|
|
Close();
|
|
}
|
|
|
|
private void MenuItem_Click_1(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
if (Manager.isAdmin == true)
|
|
{
|
|
var selectedService = (sender as MenuItem).DataContext as ServiceDTO;
|
|
if (selectedService != null)
|
|
new ClientServiceWindow(selectedService).ShowDialog(this);
|
|
}
|
|
}
|
|
|
|
private void Button_Click_2(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
new ClientAppointmentsWindow().ShowDialog(this);
|
|
}
|
|
}
|
|
} |