stuff
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Windows;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using WD7UVN_SzTGUI_2023242.Client.WPF.Windows;
|
||||
|
||||
namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
|
||||
{
|
||||
@@ -42,7 +43,7 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
|
||||
{
|
||||
if (!IsInDesignMode)
|
||||
{
|
||||
Employees = new RestCollection<Employee>("http://localhost:5000/", "api/GetSubordinates", "hub");
|
||||
Employees = new RestCollection<Employee>("http://localhost:5000/", "api/Employee", "hub");
|
||||
|
||||
UpdateEmployeeCommand = new RelayCommand(() =>
|
||||
{
|
||||
@@ -61,6 +62,16 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
|
||||
{
|
||||
return SelectedEmployee != null;
|
||||
});
|
||||
|
||||
GetSubordinatesCommand = new RelayCommand(() =>
|
||||
{
|
||||
Window window = new GetSubordinates(SelectedEmployee);
|
||||
window.Show();
|
||||
},
|
||||
() =>
|
||||
{
|
||||
return SelectedEmployee != null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
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 GetSubordinatesViewModel : ObservableRecipient
|
||||
{
|
||||
public RestCollection<Employee> Employees { get; set; }
|
||||
|
||||
private Employee selectedEmployee;
|
||||
|
||||
public Employee SelectedEmployee
|
||||
{
|
||||
get { return selectedEmployee; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref selectedEmployee, value);
|
||||
(UpdateEmployeeCommand as RelayCommand).NotifyCanExecuteChanged();
|
||||
(DeleteEmployeeCommand as RelayCommand).NotifyCanExecuteChanged();
|
||||
(GetSubordinatesCommand as RelayCommand).NotifyCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand UpdateEmployeeCommand { get; set; }
|
||||
public ICommand DeleteEmployeeCommand { get; set; }
|
||||
public ICommand GetSubordinatesCommand { get; set; }
|
||||
|
||||
public static bool IsInDesignMode
|
||||
{
|
||||
get
|
||||
{
|
||||
var prop = DesignerProperties.IsInDesignModeProperty;
|
||||
return (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public GetSubordinatesViewModel(Employee e)
|
||||
{
|
||||
if (!IsInDesignMode)
|
||||
{
|
||||
Employees = new RestCollection<Employee>("http://localhost:5000/", "api/GetSubordinates/" + e.ID.ToString(), "hub");
|
||||
|
||||
UpdateEmployeeCommand = new RelayCommand(() =>
|
||||
{
|
||||
Employees.Update(SelectedEmployee);
|
||||
},
|
||||
() =>
|
||||
{
|
||||
return SelectedEmployee != null;
|
||||
});
|
||||
|
||||
DeleteEmployeeCommand = new RelayCommand(() =>
|
||||
{
|
||||
Employees.Delete(SelectedEmployee.ID);
|
||||
},
|
||||
() =>
|
||||
{
|
||||
return SelectedEmployee != null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<Window x:Class="WD7UVN_SzTGUI_2023242.Client.WPF.Windows.GetSubordinates"
|
||||
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="Employees" Height="550" Width="350">
|
||||
|
||||
<Window.DataContext>
|
||||
<local:GetSubordinatesViewModel/>
|
||||
</Window.DataContext>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="9*" />
|
||||
<RowDefinition Height="1*" />
|
||||
</Grid.RowDefinitions>
|
||||
<ListBox ItemsSource="{Binding Employees}" Grid.Row="0" SelectedItem="{Binding SelectedEmployee}">
|
||||
<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>
|
||||
|
||||
<UniformGrid Rows="3" Grid.Row="1">
|
||||
<Button Content="Edit selected" Command="{Binding UpdateEmployeeCommand}"/>
|
||||
<Button Content="Delete selected" Command="{Binding DeleteEmployeeCommand}"/>
|
||||
<Button Content="Get subordinates"/>
|
||||
</UniformGrid>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Windows;
|
||||
using WD7UVN_HFT_2023241.Models;
|
||||
using WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels;
|
||||
|
||||
namespace WD7UVN_SzTGUI_2023242.Client.WPF.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for GetAllEmployees.xaml
|
||||
/// </summary>
|
||||
public partial class GetSubordinates : Window
|
||||
{
|
||||
private readonly GetSubordinatesViewModel viewModel;
|
||||
public GetSubordinates(Employee e)
|
||||
{
|
||||
InitializeComponent();
|
||||
viewModel = new GetSubordinatesViewModel(e);
|
||||
this.DataContext = viewModel;
|
||||
}
|
||||
|
||||
private void CreateNewEmployee(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Window window = new CreateNewEmployee();
|
||||
window.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user