Adding Customers now works.

This commit is contained in:
2024-05-05 18:14:31 +02:00
parent 39fb1aaffa
commit 04f7e998cb
12 changed files with 279 additions and 25 deletions

View File

@@ -0,0 +1,8 @@
{
"profiles": {
"WSL": {
"commandName": "WSL2",
"distributionName": ""
}
}
}

View File

@@ -0,0 +1,56 @@
using WD7UVN_HFT_2023241.Models;
using System.ComponentModel;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
using System;
namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{
public class CreateNewCustomerViewModel : ObservableRecipient
{
public Action CloseAction { get; set; }
public event Action<Customer> NewCustomerCreated;
public Customer newCustomer;
public Customer NewCustomer
{
get { return newCustomer; }
set
{
SetProperty(ref newCustomer, value);
(CreateCommand as RelayCommand).NotifyCanExecuteChanged();
}
}
public ICommand CreateCommand { get; set; }
public static bool IsInDesignMode
{
get
{
var prop = DesignerProperties.IsInDesignModeProperty;
return (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue;
}
}
public CreateNewCustomerViewModel()
{
newCustomer = new Customer();
if (!IsInDesignMode)
{
CreateCommand = new RelayCommand(() =>
{
NewCustomerCreated?.Invoke(NewCustomer);
CloseAction();
},
() =>
{
return NewCustomer != null;
});
}
}
}
}

View File

@@ -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
{
@@ -16,10 +17,16 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
public MaintainerTeam SelectedMaintainerTeam
{
get { return selectedMaintainerTeam; }
set { SetProperty(ref selectedMaintainerTeam, value); (UpdateMaintainerTeamCommand as RelayCommand).NotifyCanExecuteChanged(); }
set
{
SetProperty(ref selectedMaintainerTeam, value);
(UpdateMaintainerTeamCommand as RelayCommand).NotifyCanExecuteChanged();
(GetColleaguesCommand as RelayCommand).NotifyCanExecuteChanged();
}
}
public ICommand UpdateMaintainerTeamCommand { get; set; }
public ICommand GetColleaguesCommand { get; set; }
public static bool IsInDesignMode
{
@@ -44,6 +51,16 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{
return SelectedMaintainerTeam != null;
});
GetColleaguesCommand = new RelayCommand(() =>
{
Window window = new GetColleagues(SelectedMaintainerTeam);
window.Show();
},
() =>
{
return SelectedMaintainerTeam != 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 GetColleaguesViewModel : ObservableRecipient
{
public RestCollection<Employee> Employees { get; set; }
public static bool IsInDesignMode
{
get
{
var prop = DesignerProperties.IsInDesignModeProperty;
return (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue;
}
}
public GetColleaguesViewModel(MaintainerTeam e)
{
if (!IsInDesignMode)
{
Employees = new RestCollection<Employee>("http://localhost:5000/", "api/WhoWorksInMaintainerTeam?id=" + e.ID.ToString(), "hub", true);
}
}
}
}

View File

@@ -31,6 +31,9 @@
<Compile Update="Windows\GetAll\GetAllServices.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\NonCRUD\GetColleagues.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\NonCRUD\GetMaintainers.xaml.cs">
<SubType>Code</SubType>
</Compile>
@@ -69,6 +72,9 @@
<Page Update="MainWindow.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\NonCRUD\GetColleagues.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\NonCRUD\GetMaintainers.xaml">
<SubType>Designer</SubType>
</Page>

View File

@@ -5,8 +5,61 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WD7UVN_SzTGUI_2023242.Client.WPF.Windows"
mc:Ignorable="d"
Title="CreateNewCustomer" Height="450" Width="800">
Title="CreateNewCustomer" Height="550" Width="350">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="9*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<ListBox 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>
<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 NewCustomer.ID}" />
<Label Grid.Row="1" Grid.Column="0" Content="Name:" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding NewCustomer.NAME}" />
<Label Grid.Row="2" Grid.Column="0" Content="Email:" />
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding NewCustomer.EMAIL}" />
<Label Grid.Row="3" Grid.Column="0" Content="Phone:" />
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding NewCustomer.PHONE}" />
<Label Grid.Row="4" Grid.Column="0" Content="Service:" />
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding NewCustomer.SERVICE_ID}" />
</Grid>
</StackPanel>
</Border>
</ListBox>
<Button Grid.Row="1" Content="Create" Command="{Binding CreateCommand}"/>
</Grid>
</Window>

View File

@@ -1,27 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WD7UVN_HFT_2023241.Models;
using WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels;
namespace WD7UVN_SzTGUI_2023242.Client.WPF.Windows
{
/// <summary>
/// Interaction logic for CreateNewCustomer.xaml
/// </summary>
public partial class CreateNewCustomer : Window
{
public CreateNewCustomer()
public CreateNewCustomer(CreateNewCustomerViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
viewModel.CloseAction = new Action(() => this.Close());
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Windows;
using WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels;
namespace WD7UVN_SzTGUI_2023242.Client.WPF.Windows
{
@@ -14,7 +15,19 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.Windows
private void CreateNewCustomer(object sender, RoutedEventArgs e)
{
Window window = new CreateNewCustomer();
CreateNewCustomerViewModel viewModel = new CreateNewCustomerViewModel();
viewModel.NewCustomerCreated += (newCustomer) =>
{
var getAllCustomersViewModel = (GetAllCustomersViewModel)DataContext;
if (getAllCustomersViewModel != null)
{
Application.Current.Dispatcher.Invoke(() =>
{
getAllCustomersViewModel.Customers.Add(newCustomer);
});
}
};
Window window = new CreateNewCustomer(viewModel);
window.Show();
}
}

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 MaintainerTeams}" Grid.Row="0" SelectedItem="{Binding SelectedMaintainerTeam}">
<ListBox.ItemContainerStyle>
@@ -64,9 +64,10 @@
</ListBox.ItemTemplate>
</ListBox>
<UniformGrid Rows="2" Grid.Row="1">
<UniformGrid Rows="3" Grid.Row="1">
<Button Content="Edit selected" Command="{Binding UpdateMaintainerTeamCommand}"/>
<Button Content="Create new" Click="CreateNewMaintainerTeam" />
<Button Content="Who works in this team" Command="{Binding GetColleaguesCommand}" />
</UniformGrid>
</Grid>
</Window>

View File

@@ -0,0 +1,67 @@
<Window x:Class="WD7UVN_SzTGUI_2023242.Client.WPF.Windows.GetColleagues"
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="Members of team" 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

@@ -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 GetColleagues : Window
{
private readonly GetColleaguesViewModel viewModel;
public GetColleagues(MaintainerTeam m)
{
InitializeComponent();
viewModel = new GetColleaguesViewModel(m);
this.DataContext = viewModel;
}
}
}

View File

@@ -4,9 +4,6 @@ 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;