Skip to content

Commit

Permalink
WatchList.WPF - Add window "DataReplaceMessage" and change interface …
Browse files Browse the repository at this point in the history
…app. (#97)
  • Loading branch information
Stan-Kudri authored Nov 26, 2024
1 parent 2d9415f commit d2a0699
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 37 deletions.
6 changes: 5 additions & 1 deletion WatchList.WPF/Data/ViewModelLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ public CinemaPageViewModel CinemaPageViewModel
public MergeDatabaseViewModel MergeDatabaseViewModel
=> _provider!.GetRequiredService<MergeDatabaseViewModel>();

public DataReplaceMessageViewModel DataReplaceMessageViewModel
=> _provider!.GetRequiredService<DataReplaceMessageViewModel>();

public static IServiceCollection AddViewModels(ServiceCollection serviceCollection)
=> serviceCollection
.AddTransient<CinemaWindowViewModel>()
.AddTransient<CinemaPageViewModel>()
.AddTransient<MergeDatabaseViewModel>();
.AddTransient<MergeDatabaseViewModel>()
.AddTransient<DataReplaceMessageViewModel>();

public static void Init(ServiceProvider provider) => _provider = provider;
}
Expand Down
1 change: 1 addition & 0 deletions WatchList.WPF/Extension/AppServiceDIExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using WatchList.WPF.Models.ModelDataLoad;
using WatchList.WPF.Models.Sorter;
using WatchList.WPF.Views;
using WatchList.WPF.Views.Message;

namespace WatchList.WPF.Extension
{
Expand Down
2 changes: 1 addition & 1 deletion WatchList.WPF/Models/BindingBaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class BindingBaseModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
public void OnPropertyChanged([CallerMemberName] string? propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
16 changes: 16 additions & 0 deletions WatchList.WPF/Models/ModelDataLoad/DialogReplaceQuestionManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using WatchList.Core.Model.QuestionResult;

namespace WatchList.WPF.Models.ModelDataLoad
{
public class DialogReplaceQuestionManager
{
public DialogReplaceQuestionManager()
{
}

public DialogReplaceItemQuestion DialogReplaceItemQuestion { get; private set; } = DialogReplaceItemQuestion.Unknown;

public void UpdateData(DialogReplaceItemQuestion dialogReplaceItemQuestion)
=> DialogReplaceItemQuestion = dialogReplaceItemQuestion;
}
}
58 changes: 58 additions & 0 deletions WatchList.WPF/ViewModel/DataReplaceMessageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Windows;
using CommunityToolkit.Mvvm.Input;
using WatchList.Core.Model.QuestionResult;
using WatchList.WPF.Models.ModelDataLoad;

namespace WatchList.WPF.ViewModel
{
public class DataReplaceMessageViewModel
{
public const string Question = "The append item is a duplicate.Replace element?";

private readonly string _titleLabel;

public DataReplaceMessageViewModel(string titleItem, DialogReplaceQuestionManager questionResult)
{
_titleLabel = titleItem;
ResultQuestion = questionResult;
}

public string QuestionLabel => Question;
public string TitleLabel => _titleLabel;

public DialogReplaceQuestionManager ResultQuestion { get; private set; }

public RelayCommand<Window> MoveYesCommand => new(MoveYesClick);
public RelayCommand<Window> MoveAllYesCommand => new(MoveAllYesClick);
public RelayCommand<Window> MoveNoCommand => new(MoveNoClick);
public RelayCommand<Window> MoveAllNoCommand => new(MoveAllNoClick);

private void MoveYesClick(Window window)
{
ResultQuestion.UpdateData(DialogReplaceItemQuestion.Yes);
window.DialogResult = true;
window?.Close();
}

private void MoveAllYesClick(Window window)
{
ResultQuestion.UpdateData(DialogReplaceItemQuestion.AllYes);
window.DialogResult = true;
window?.Close();
}

private void MoveNoClick(Window window)
{
ResultQuestion.UpdateData(DialogReplaceItemQuestion.No);
window.DialogResult = true;
window?.Close();
}

private void MoveAllNoClick(Window window)
{
ResultQuestion.UpdateData(DialogReplaceItemQuestion.AllNo);
window.DialogResult = true;
window?.Close();
}
}
}
12 changes: 2 additions & 10 deletions WatchList.WPF/ViewModel/MergeDatabaseViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using CommunityToolkit.Mvvm.Input;
using WatchList.Core.Model.ItemCinema.Components;
Expand All @@ -8,12 +6,13 @@
using WatchList.Core.Model.Load.ItemActions;
using WatchList.Core.Service.Component;
using WatchList.WPF.Commands;
using WatchList.WPF.Models;
using WatchList.WPF.Models.ModelDataLoad;
using WatchList.WPF.Models.ModelDataLoad.LoadModel;

namespace WatchList.WPF.ViewModel
{
public class MergeDatabaseViewModel : INotifyPropertyChanged
public class MergeDatabaseViewModel : BindingBaseModel
{
private readonly FiileLoaderDB _fiileLoader;
private readonly IMessageBox _messageBox;
Expand Down Expand Up @@ -157,12 +156,5 @@ private List<DuplicateLoadingRules> GetDuplicateLoadingRules()
}

private void CloseWindow(Window window) => window?.Close();

public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string prop = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
}
}
2 changes: 1 addition & 1 deletion WatchList.WPF/Views/CinemaPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Title="CinemaPage"
DataContext="{Binding CinemaPageViewModel, Source={StaticResource ViewModelLocator}}"
MinHeight="300" MinWidth="300">
<Grid Background="#FF1B3F40">
<Grid Background="SteelBlue">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="*"/>
Expand Down
2 changes: 1 addition & 1 deletion WatchList.WPF/Views/MergeDatabaseWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
d:DesignHeight="240" d:DesignWidth="420"
Title="Loading data" Foreground="Black"
DataContext="{Binding MergeDatabaseViewModel, Source={StaticResource ViewModelLocator}}">
<Grid x:Name="MergeDBPage" Background="#FFD7FFFC">
<Grid x:Name="MergeDBPage" Background="LightGray">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
Expand Down
73 changes: 73 additions & 0 deletions WatchList.WPF/Views/Message/DataReplaceMessageWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<mah:MetroWindow
x:Name="ReplaceItemWindow"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
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:WatchList.WPF.Views.Message"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" x:Class="WatchList.WPF.Views.Message.DataReplaceMessageWindow"
mc:Ignorable="d"
Title="DataReplaceMessageWindow" Height="200" Width="600"
ResizeMode="NoResize"
DataContext="{Binding DataReplaceMessageViewModel, Source={StaticResource ViewModelLocator}}">
<Grid Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="4"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content = "{Binding QuestionLabel}"/>
<Label Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="4"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content = "{Binding TitleLabel}"/>
<StackPanel Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="4" Orientation="Horizontal" HorizontalAlignment="Center">
<ui:Button Content="Yes"
HorizontalAlignment="Center"
Margin="4,4,4,4"
MinWidth="90"
MinHeight="30"
VerticalAlignment="Center"
Command="{Binding MoveYesCommand}"
CommandParameter="{Binding ElementName=ReplaceItemWindow}"/>
<ui:Button Content="All Yes"
HorizontalAlignment="Center"
Margin="4,4,4,4"
MinWidth="90"
MinHeight="30"
VerticalAlignment="Center"
Command="{Binding MoveAllYesCommand}"
CommandParameter="{Binding ElementName=ReplaceItemWindow}"/>
<ui:Button Content="No"
HorizontalAlignment="Center"
Margin="4,4,4,4"
MinWidth="90"
MinHeight="30"
VerticalAlignment="Center"
Command="{Binding MoveNoCommand}"
CommandParameter="{Binding ElementName=ReplaceItemWindow}"/>
<ui:Button Content="All No"
HorizontalAlignment="Center"
Margin="4,4,4,4"
MinWidth="90"
MinHeight="30"
VerticalAlignment="Center"
Command="{Binding MoveAllNoCommand}"
CommandParameter="{Binding ElementName=ReplaceItemWindow}"/>
</StackPanel>
</Grid>
</mah:MetroWindow>
17 changes: 17 additions & 0 deletions WatchList.WPF/Views/Message/DataReplaceMessageWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using WatchList.WPF.Models.ModelDataLoad;
using WatchList.WPF.ViewModel;

namespace WatchList.WPF.Views.Message
{
/// <summary>
/// Interaction logic for DataReplaceMessageWindow.xaml
/// </summary>
public partial class DataReplaceMessageWindow
{
public DataReplaceMessageWindow(string titleName, DialogReplaceQuestionManager replaceQuestionManager)
{
InitializeComponent();
DataContext = new DataReplaceMessageViewModel(titleName, replaceQuestionManager);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
using System.Windows;
using WatchList.Core.Model.QuestionResult;
using WatchList.Core.Service.Component;
using WatchList.WPF.Models.ModelDataLoad;
using MessageBoxWindow = System.Windows.MessageBox;

namespace WatchList.WPF.Views
namespace WatchList.WPF.Views.Message
{
/// <summary>
/// Interaction logic for MessageWindow.xaml
/// </summary>
public partial class MessageWindow : Window, IMessageBox
public class MessageWindow : Window, IMessageBox
{
public MessageWindow()
{
InitializeComponent();
}

public Task<DialogReplaceItemQuestion> ShowDataReplaceQuestion(string titleItem)
{
return Task.FromResult(DialogReplaceItemQuestion.AllYes);
var replaceQuestionManager = new DialogReplaceQuestionManager();
var windowDataReplaceItem = new DataReplaceMessageWindow(titleItem, replaceQuestionManager);

return windowDataReplaceItem.ShowDialog() == true
? Task.FromResult(replaceQuestionManager.DialogReplaceItemQuestion)
: Task.FromResult(DialogReplaceItemQuestion.Unknown);
}

public Task ShowError(string message)
Expand Down
12 changes: 0 additions & 12 deletions WatchList.WPF/Views/MessageWindow.xaml

This file was deleted.

1 change: 1 addition & 0 deletions WatchList.WPF/WatchList.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="DevExpressMvvm" Version="24.1.6" />
<PackageReference Include="MahApps.Metro" Version="2.4.10" />
<PackageReference Include="MaterialDesignColors" Version="3.1.0" />
<PackageReference Include="MaterialDesignThemes" Version="5.1.0" />
Expand Down

0 comments on commit d2a0699

Please sign in to comment.