WhoUsesService done

This commit is contained in:
2024-05-05 17:20:27 +02:00
parent 0f93e5fd25
commit 39fb1aaffa
6 changed files with 130 additions and 2 deletions

View File

@@ -24,6 +24,7 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
(DeleteServiceCommand as RelayCommand).NotifyCanExecuteChanged();
(GetResponsibleEmployeeCommand as RelayCommand).NotifyCanExecuteChanged();
(GetMaintainersCommand as RelayCommand).NotifyCanExecuteChanged();
(GetUserCommand as RelayCommand).NotifyCanExecuteChanged();
}
}
@@ -31,6 +32,7 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
public ICommand DeleteServiceCommand { get; set; }
public ICommand GetResponsibleEmployeeCommand { get; set; }
public ICommand GetMaintainersCommand { get; set; }
public ICommand GetUserCommand { get; set; }
public static bool IsInDesignMode
{
@@ -84,6 +86,16 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{
return SelectedService != null;
});
GetUserCommand = new RelayCommand(() =>
{
Window window = new GetUsers(SelectedService);
window.Show();
},
() =>
{
return SelectedService != null;
});
}
}
}

View File

@@ -0,0 +1,29 @@
using WD7UVN_HFT_2023241.Models;
using System.ComponentModel;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{
public class GetUsersViewModel : ObservableRecipient
{
public RestCollection<Customer> Clients { get; set; }
public static bool IsInDesignMode
{
get
{
var prop = DesignerProperties.IsInDesignModeProperty;
return (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue;
}
}
public GetUsersViewModel(Service e)
{
if (!IsInDesignMode)
{
Clients = new RestCollection<Customer>("http://localhost:5000/", "api/WhoUsesService?id=" + e.ID.ToString(), "hub", true);
}
}
}
}

View File

@@ -37,6 +37,9 @@
<Compile Update="Windows\NonCRUD\GetResponsibleEmployee.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\NonCRUD\GetUsers.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="Windows\Create\CreateNewCustomer.xaml">
@@ -72,5 +75,8 @@
<Page Update="Windows\NonCRUD\GetResponsibleEmployee.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\NonCRUD\GetUsers.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>

View File

@@ -13,8 +13,8 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="9*" />
<RowDefinition Height="1*" />
<RowDefinition Height="8*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<ListBox ItemsSource="{Binding Services}" Grid.Row="0" SelectedItem="{Binding SelectedService}">
<ListBox.ItemContainerStyle>
@@ -90,6 +90,7 @@
<Button Content="Delete selected" Command="{Binding DeleteServiceCommand}"/>
<Button Content="Get responsible employee" Command="{Binding GetResponsibleEmployeeCommand}"/>
<Button Content="Get all maintainers" Command="{Binding GetMaintainersCommand}"/>
<Button Content="Who uses this service" Command="{Binding GetUserCommand}"/>
</UniformGrid>
</Grid>
</Window>

View File

@@ -0,0 +1,63 @@
<Window x:Class="WD7UVN_SzTGUI_2023242.Client.WPF.Windows.GetUsers"
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="Users of service" Height="550" Width="350">
<Grid>
<ListBox ItemsSource="{Binding Clients}" 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="*" />
</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="Service ID:" />
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding SERVICE_ID}" />
</Grid>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</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 GetUsers : Window
{
private readonly GetUsersViewModel viewModel;
public GetUsers(Service s)
{
InitializeComponent();
viewModel = new GetUsersViewModel(s);
this.DataContext = viewModel;
}
}
}