add ComboBox and ListBox

This commit is contained in:
NikitaOnianov 2025-03-11 12:08:02 +03:00
parent b617f2e014
commit 4f43df675b
24 changed files with 123 additions and 109 deletions

View File

@ -4,11 +4,20 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="demo_blagodat.ChangeServices"
xmlns:vm="using:demo_blagodat.Models"
Title="Изменить услугу">
<ScrollViewer>
<StackPanel Spacing="15" Orientation="Vertical">
<TextBlock Text="Введите код сервиса:"/>
<TextBox x:Name="Name"/>
<TextBlock Text="Выберите Сервис"/>
<ComboBox Name="ListServices" SelectionChanged="ComboBox_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="vm:Service">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ServiceName}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<StackPanel Spacing="15" HorizontalAlignment="Center" Orientation="Horizontal">

View File

@ -5,90 +5,85 @@ using Avalonia.Markup.Xaml;
using demo_blagodat.Models;
using System.Linq;
using System;
using System.Collections.ObjectModel;
namespace demo_blagodat;
public partial class ChangeServices : Window
{
public Employee User;
static User11Context db = new User11Context();
ObservableCollection<Service> ServiceitemSource = new ObservableCollection<Service>(db.Services);
public ChangeServices(Employee user)
{
InitializeComponent();
User = user;
ListServices.ItemsSource = ServiceitemSource;
}
private void ComboBox_SelectionChanged(object? sender, Avalonia.Controls.SelectionChangedEventArgs e)
{
if (sender != null) { }
}
private void changeClient(object sender, RoutedEventArgs e)
{
try // Êîíñòðóêöèÿ äëÿ îáðàáîòêè èñêëþ÷åíèé
{
// Îáîçíà÷àåì êîíêðåòíîãî ïîëüçîâàòåëÿ
string? name = Name.Text;
// Ñîáèðàåì âñå äàííûå ñ ýêðàíà
string? newname = TextNewName.Text;
string? newcode = TextNewCode.Text;
decimal? newprice = Math.Round(decimal.TryParse(TextNewPrice.Text.Replace(".", ","), out decimal resalt) ? resalt : -1 , 2);
if (name != "")
if (ListServices.SelectedItem != null)
{
using (User11Context db = new User11Context()) // Ïîäêëþ÷åíèå ê ÁÄ
Service service = db.Services.Where(it => it == ListServices.SelectedItem).FirstOrDefault();
if (TextNewName.Text != "")
{
Service? service = db.Services.Where(it => it.ServiceName == name).FirstOrDefault();
if (service != null)
{
if (TextNewName.Text != "")
{
service.ServiceName = newname; // Ìåíÿåì ïàðàìåíò "Íàçâàíèå"
service.ServiceName = newname; // Ìåíÿåì ïàðàìåíò "Íàçâàíèå"
db.SaveChanges(); // Ñîõðàíÿåì èçìåíåíèÿ
db.SaveChanges(); // Ñîõðàíÿåì èçìåíåíèÿ
// Ñîîáùåíèå
MesAdd.Text = "Äàííûå èçìåíåíû";
MesAddError.Text = "";
}
if (TextNewCode.Text != "")
{
service.ServiceCode = newcode; // Ìåíÿåì ïàðàìåíò "Êîä"
db.SaveChanges(); // Ñîõðàíÿåì èçìåíåíèÿ
// Ñîîáùåíèå
MesAdd.Text = "Äàííûå èçìåíåíû";
MesAddError.Text = "";
}
if (newprice == -1)
{
// Ñîîáùåíèå
MesAdd.Text = "";
MesAddError.Text = "Íåïðàâèëüíàÿ öåíà";
}
else if (TextNewPrice.Text != "")
{
service.ServiceCostPerHour = (decimal) newprice;// Ìåíÿåì ïàðàìåíò "öåíà â ÷àñû"
db.SaveChanges(); // Ñîõðàíÿåì èçìåíåíèÿ
// Ñîîáùåíèå
MesAdd.Text = "Äàííûå èçìåíåíû";
MesAddError.Text = "";
}
if(TextNewName.Text == "" && TextNewCode.Text == "" && TextNewPrice.Text == "")
{
// Ñîîáùåíèå
MesAdd.Text = "";
MesAddError.Text = "Ââåäèòå íîâûå äàííûå";
}
check(service);
}
else
{
MesAdd.Text = "";
MesAddError.Text = "Òàêîãî ñåðâèñà íåò";
}
// Ñîîáùåíèå
MesAdd.Text = "Äàííûå èçìåíåíû";
MesAddError.Text = "";
}
if (TextNewCode.Text != "")
{
service.ServiceCode = newcode; // Ìåíÿåì ïàðàìåíò "Êîä"
db.SaveChanges(); // Ñîõðàíÿåì èçìåíåíèÿ
// Ñîîáùåíèå
MesAdd.Text = "Äàííûå èçìåíåíû";
MesAddError.Text = "";
}
if (newprice == -1)
{
// Ñîîáùåíèå
MesAdd.Text = "";
MesAddError.Text = "Íåïðàâèëüíàÿ öåíà";
}
else if (TextNewPrice.Text != "")
{
service.ServiceCostPerHour = (decimal)newprice;// Ìåíÿåì ïàðàìåíò "öåíà â ÷àñû"
db.SaveChanges(); // Ñîõðàíÿåì èçìåíåíèÿ
// Ñîîáùåíèå
MesAdd.Text = "Äàííûå èçìåíåíû";
MesAddError.Text = "";
}
if (TextNewName.Text == "" && TextNewCode.Text == "" && TextNewPrice.Text == "")
{
// Ñîîáùåíèå
MesAdd.Text = "";
MesAddError.Text = "Ââåäèòå íîâûå äàííûå";
}
check(service);
}
else
{
@ -115,14 +110,11 @@ public partial class ChangeServices : Window
private void check(Service service)
{
using (User11Context db = new User11Context()) // Ïîäêëþ÷åíèå ê ÁÄ
{
Service checkService = db.Services.Where(it => it.ServiceName == service.ServiceName).FirstOrDefault();
Service checkService = db.Services.Where(it => it.ServiceName == service.ServiceName).FirstOrDefault();
SelectName.Text = checkService.ServiceName;
SelectCode.Text = checkService.ServiceCode;
SelectPrice.Text = checkService.ServiceCostPerHour.ToString();
}
SelectName.Text = checkService.ServiceName;
SelectCode.Text = checkService.ServiceCode;
SelectPrice.Text = checkService.ServiceCostPerHour.ToString();
}
private void ExitClik(object sender, RoutedEventArgs e)

View File

@ -4,25 +4,40 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="demo_blagodat.DeleteServices"
xmlns:vm="using:demo_blagodat.Models"
Title="Удалить Сервис">
<ScrollViewer>
<StackPanel Orientation="Vertical">
<StackPanel Spacing="15" HorizontalAlignment="Center" Orientation="Vertical">
<StackPanel Orientation="Vertical">
<TextBlock Text="Введите название"/>
<TextBox Width="300" x:Name="TextName"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="Введите код услуги"/>
<TextBox Width="300" x:Name="TextCode"/>
</StackPanel>
<Border Background="Red"
CornerRadius="10"
Padding="20"
Margin="20"
Width="400"
Height="300"
>
<ScrollViewer>
<ListBox Name="ListServices" SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="vm:Service">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ServiceName}"/>
<TextBlock Text=" : "/>
<TextBlock Text="{Binding ServiceCode}"/>
<TextBlock Text=" : "/>
<TextBlock Text="{Binding ServiceCostPerHour}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</Border>
</StackPanel>
<StackPanel HorizontalAlignment="Center" Orientation="Vertical" VerticalAlignment="Center">
<Button Content="Удвлить Сервис" Click="deleteclient"/>
<Button Content="Удалить Сервис" Click="deleteService"/>
<Button Content="Вернуться назад" Click="ExitClik"/>
</StackPanel>
<StackPanel HorizontalAlignment="Center" Orientation="Vertical">

View File

@ -5,58 +5,56 @@ using Avalonia.Markup.Xaml;
using demo_blagodat.Models;
using System.Linq;
using System;
using System.Collections.ObjectModel;
namespace demo_blagodat;
public partial class DeleteServices : Window
{
public Employee User;
static User11Context db = new User11Context();
ObservableCollection<Service> ServicesitemSource = new ObservableCollection<Service>(db.Services);
public DeleteServices(Employee user)
{
InitializeComponent();
User = user;
ListServices.ItemsSource = ServicesitemSource;
}
private void deleteclient(object sender, RoutedEventArgs e)
private void ListBox_SelectionChanged(object? sender, Avalonia.Controls.SelectionChangedEventArgs e)
{
if(sender != null) { }
}
private void deleteService(object sender, RoutedEventArgs e)
{
try // Êîíñòðóêöèÿ äëÿ îáðàáîòêè èñêëþ÷åíèé
{
using (User11Context db = new User11Context()) // Ïîäêëþ÷åíèå ê ÁÄ
if (ListServices.SelectedItem != null) // Ïðîâåðÿåì íàëè÷èå âàæíûõ äàííûõ
{
// Ñîáèðàåì äàííûå ñ ýêðàíà
string? name = TextName.Text;
string? code = TextCode.Text;
Service service = db.Services.Where(it => it == ListServices.SelectedItem).FirstOrDefault(); // ñîçäà¸ì ýêçåìïëÿð êëàññà Service
if (name != null) // Ïðîâåðÿåì íàëè÷èå âàæíûõ äàííûõ
{
Service? service = db.Services.Where(it => it.ServiceName == name).FirstOrDefault(); // ñîçäà¸ì ýêçåìïëÿð êëàññà Service
// Óäàëÿåì ïîëüçîâàòåëÿ èç ÁÄ
db.Services.Remove(service);
if (service != null)
{
// Óäàëÿåì ïîëüçîâàòåëÿ èç ÁÄ
db.Services.Remove(service);
// Ñîõðàíÿåì èçìåíåíèÿ ÁÄ
db.SaveChanges();
// Ñîõðàíÿåì èçìåíåíèÿ ÁÄ
db.SaveChanges();
// Óäàëÿåì èç ñïèñêà
ServicesitemSource.Remove(ListServices.SelectedItem as Service);
// Ìåíÿåì ñîîáùåíèå
MesDelError.Text = "";
MesDel.Text = "Ñåðâèñ óäàë¸í";
}
else
{
MesDel.Text = "Òàêîãî ñåðâèñà íåò";
}
// Ìåíÿåì ñîîáùåíèå
MesDelError.Text = "";
MesDel.Text = "Ñåðâèñ óäàë¸í";
// Ñòåðàåì âñå äàííûå
TextName.Text = "";
}
else
{
// Ìåíÿåì ñîîáùåíèå
MesDel.Text = "";
MesDelError.Text = "Íóæíî äîáàâèòü íàçâàíèå èëè êîä!";
}
// Ñòåðàåì âñå äàííûå
ListServices.SelectedItem = null;
}
else
{
// Ìåíÿåì ñîîáùåíèå
MesDel.Text = "";
MesDelError.Text = "Íóæíî âûáðàòü ñåðâèñ";
}
}
catch (Exception ex)

View File

@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("demo_blagodat")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f63e4d41bce29f31e8cca027a20f1c4f0ddbad69")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b617f2e014bf246ac7062520a6d4188404b9fb0d")]
[assembly: System.Reflection.AssemblyProductAttribute("demo_blagodat")]
[assembly: System.Reflection.AssemblyTitleAttribute("demo_blagodat")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
d63b72aa80eb2f6a00640f99908a69b82a4fdfcb728d063234bb70a027739d4a
0f35feb508f4935218343a3a6854920d6f75ce11fafc95b97d8ed014f11dd19f