working on WhoIsResponsibleForService

This commit is contained in:
MiskolcziRichard
2024-05-04 20:33:50 +02:00
parent b0ba438336
commit 42b078a49a
7 changed files with 148 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using System.Windows.Input; using System.Windows.Input;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using WD7UVN_SzTGUI_2023242.Client.WPF.Windows;
namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{ {
@@ -16,10 +17,18 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
public Service SelectedService public Service SelectedService
{ {
get { return selectedService; } get { return selectedService; }
set { SetProperty(ref selectedService, value); (UpdateServiceCommand as RelayCommand).NotifyCanExecuteChanged(); } set
{
SetProperty(ref selectedService, value);
(UpdateServiceCommand as RelayCommand).NotifyCanExecuteChanged();
(DeleteServiceCommand as RelayCommand).NotifyCanExecuteChanged();
(GetResponsibleEmployeeCommand as RelayCommand).NotifyCanExecuteChanged();
}
} }
public ICommand UpdateServiceCommand { get; set; } public ICommand UpdateServiceCommand { get; set; }
public ICommand DeleteServiceCommand { get; set; }
public ICommand GetResponsibleEmployeeCommand { get; set; }
public static bool IsInDesignMode public static bool IsInDesignMode
{ {
@@ -44,6 +53,25 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{ {
return SelectedService != null; return SelectedService != null;
}); });
DeleteServiceCommand = new RelayCommand(() =>
{
Services.Delete(SelectedService.ID);
},
() =>
{
return SelectedService != null;
});
GetResponsibleEmployeeCommand = new RelayCommand(() =>
{
Window window = new GetResponsibleEmployee(SelectedService);
window.Show();
},
() =>
{
return SelectedService != null;
});
} }
} }
} }

View File

@@ -0,0 +1,32 @@
using WD7UVN_HFT_2023241.Models;
using System.ComponentModel;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{
public class GetResponsibleEmployeeViewModel : ObservableRecipient
{
//Hiába egyetlen eredmény van, meghagyom RestCollection-nek a SignalR miatt
public RestCollection<Service> Employees { get; set; }
public static bool IsInDesignMode
{
get
{
var prop = DesignerProperties.IsInDesignModeProperty;
return (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue;
}
}
public GetResponsibleEmployeeViewModel(Service s)
{
if (!IsInDesignMode)
{
Employees = new RestCollection<Service>("http://localhost:5000/", "api/WhoIsResponsibleForService?id=" + s.ID.ToString(), "hub", true);
}
}
}
}

View File

@@ -87,6 +87,8 @@
<UniformGrid Rows="2" Grid.Row="1"> <UniformGrid Rows="2" Grid.Row="1">
<Button Content="Edit selected" Command="{Binding UpdateServiceCommand}"/> <Button Content="Edit selected" Command="{Binding UpdateServiceCommand}"/>
<Button Content="Create new" Click="CreateNewService" /> <Button Content="Create new" Click="CreateNewService" />
<Button Content="Delete selected" Command="{Binding DeleteServiceCommand}"/>
<Button Content="Get responsible employee" Command="{Binding GetResponsibleEmployeeCommand}"/>
</UniformGrid> </UniformGrid>
</Grid> </Grid>
</Window> </Window>

View File

@@ -0,0 +1,17 @@
using System.Windows;
using WD7UVN_HFT_2023241.Models;
using WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels;
namespace WD7UVN_SzTGUI_2023242.Client.WPF.Windows
{
public partial class GetResponsibleEmployee : Window
{
private readonly GetResponsibleEmployeeViewModel viewModel;
public GetResponsibleEmployee(Service s)
{
InitializeComponent();
viewModel = new GetResponsibleEmployeeViewModel(s);
this.DataContext = viewModel;
}
}
}

View File

@@ -0,0 +1,67 @@
<Window x:Class="WD7UVN_SzTGUI_2023242.Client.WPF.Windows.GetResponsibleEmployee"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels"
mc:Ignorable="d"
Title="Employee(s) responsible for service" Height="550" Width="350">
<Grid>
<ListBox ItemsSource="{Binding Employees}" Grid.Row="0">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Black" BorderThickness="1" Margin="5">
<StackPanel>
<Grid>
<Grid.Resources>
<Style TargetType="TextBox">
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="8*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="ID:" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding ID}" IsReadOnly="True" Background="LightGray" />
<Label Grid.Row="1" Grid.Column="0" Content="Name:" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding NAME}" />
<Label Grid.Row="2" Grid.Column="0" Content="Email:" />
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding EMAIL}" />
<Label Grid.Row="3" Grid.Column="0" Content="Phone:" />
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding PHONE}" />
<Label Grid.Row="4" Grid.Column="0" Content="Team ID:" />
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding MAINTAINER_ID}" />
<Label Grid.Row="5" Grid.Column="0" Content="Manager ID:" />
<TextBox Grid.Row="5" Grid.Column="1" Text="{Binding MANAGER_ID}" />
</Grid>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>

View File

@@ -8,7 +8,7 @@
Title="Subordinates of employee" Height="550" Width="350"> Title="Subordinates of employee" Height="550" Width="350">
<Grid> <Grid>
<ListBox ItemsSource="{Binding Employees}" Grid.Row="0" SelectedItem="{Binding SelectedEmployee}"> <ListBox ItemsSource="{Binding Employees}" Grid.Row="0">
<ListBox.ItemContainerStyle> <ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem"> <Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="HorizontalContentAlignment" Value="Stretch"/>

View File

@@ -16,11 +16,5 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.Windows
viewModel = new GetSubordinatesViewModel(e); viewModel = new GetSubordinatesViewModel(e);
this.DataContext = viewModel; this.DataContext = viewModel;
} }
private void CreateNewEmployee(object sender, RoutedEventArgs e)
{
Window window = new CreateNewEmployee();
window.Show();
}
} }
} }