diff --git a/WatchList.WPF/Component/CustomDataGrid.cs b/WatchList.WPF/Component/CustomDataGrid.cs new file mode 100644 index 0000000..d2cb85d --- /dev/null +++ b/WatchList.WPF/Component/CustomDataGrid.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Windows; +using System.Windows.Controls; + +namespace WatchList.WPF.Component +{ + public class CustomDataGrid : DataGrid + { + public CustomDataGrid() + => SelectionChanged += CustomDataGrid_SelectionChanged; + + void CustomDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) + => SelectedItemsList = SelectedItems; + + public IList SelectedItemsList + { + get => (IList)GetValue(SelectedItemsListProperty); + set => SetValue(SelectedItemsListProperty, value); + } + + public static readonly DependencyProperty SelectedItemsListProperty + = DependencyProperty.Register("SelectedItemsList", typeof(IList), typeof(CustomDataGrid), new PropertyMetadata(null)); + } +} diff --git a/WatchList.WPF/Models/ModelDataLoad/DialogReplaceQuestionManager.cs b/WatchList.WPF/Models/ModelDataLoad/DialogReplaceQuestionManager.cs deleted file mode 100644 index c4165a8..0000000 --- a/WatchList.WPF/Models/ModelDataLoad/DialogReplaceQuestionManager.cs +++ /dev/null @@ -1,16 +0,0 @@ -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; - } -} diff --git a/WatchList.WPF/ViewModel/CinemaPageViewModel.cs b/WatchList.WPF/ViewModel/CinemaPageViewModel.cs index edd92d3..78c482f 100644 --- a/WatchList.WPF/ViewModel/CinemaPageViewModel.cs +++ b/WatchList.WPF/ViewModel/CinemaPageViewModel.cs @@ -1,3 +1,4 @@ +using System.Collections; using System.Collections.ObjectModel; using System.Windows; using DevExpress.Mvvm; @@ -20,6 +21,8 @@ namespace WatchList.WPF.ViewModel { public class CinemaPageViewModel : BindableBase { + private const string HighlightTheDesiredLine = "No items selected."; + private readonly WatchItemService _itemService; private readonly IMessageBox _messageBox; private readonly ILogger _logger; @@ -29,11 +32,13 @@ public class CinemaPageViewModel : BindableBase private readonly FilterItemModel _filterItem; private readonly ItemSearchRequest _searchRequests; + private readonly bool _isAscending = true; + private ObservableCollection _watchItems = new ObservableCollection(); private PagedList _pagedList; - private readonly bool _isAscending = true; + private IList _selectItems = new ArrayList(); private int _curPage; private int CurPage @@ -61,6 +66,12 @@ public CinemaPageViewModel(IMessageBox messageBox, LoadDataAsync(); } + public IList SelectItems + { + get => _selectItems; + set => SetValue(ref _selectItems, value); + } + public ObservableCollection WatchItems { get => _watchItems; @@ -85,7 +96,8 @@ public RelayCommandApp MoveToLastPage public RelayCommandApp AddItemCommand => new RelayCommandApp(async async => await MoveAddItem()); - + public RelayCommandApp DeleteItemsCommand + => new RelayCommandApp(async async => await DeleteItems()); public RelayCommandApp AddDataDBCommand => new RelayCommandApp(async async => await MoveAddData()); @@ -100,6 +112,31 @@ private async Task MoveAddItem() await LoadDataAsync(); } + private async Task DeleteItems() + { + if (SelectItems.Count == 0) + { + await _messageBox.ShowInfo(HighlightTheDesiredLine); + return; + } + + if (!await _messageBox.ShowQuestion("Delete select items?")) + { + return; + } + + foreach (var item in SelectItems) + { + var isWatchItem = item as WatchItem; + if (isWatchItem != null) + { + _itemService.Remove(isWatchItem.Id); + } + } + + await LoadDataAsync(); + } + private async Task MoveAddData() { var addDataWindow = new MergeDatabaseWindow(); diff --git a/WatchList.WPF/ViewModel/DataReplaceMessageVM.cs b/WatchList.WPF/ViewModel/DataReplaceMessageVM.cs index b0740df..5f255fb 100644 --- a/WatchList.WPF/ViewModel/DataReplaceMessageVM.cs +++ b/WatchList.WPF/ViewModel/DataReplaceMessageVM.cs @@ -1,7 +1,6 @@ using System.Windows; using CommunityToolkit.Mvvm.Input; using WatchList.Core.Model.QuestionResult; -using WatchList.WPF.Models.ModelDataLoad; namespace WatchList.WPF.ViewModel { @@ -11,16 +10,13 @@ public class DataReplaceMessageVM private readonly string _titleLabel; - public DataReplaceMessageVM(string titleItem, DialogReplaceQuestionManager questionResult) - { - _titleLabel = titleItem; - ResultQuestion = questionResult; - } + public DataReplaceMessageVM(string titleItem) + => _titleLabel = titleItem; public string QuestionLabel => Question; public string TitleLabel => _titleLabel; - public DialogReplaceQuestionManager ResultQuestion { get; private set; } + public DialogReplaceItemQuestion ResultQuestion { get; private set; } = DialogReplaceItemQuestion.Unknown; public RelayCommand MoveYesCommand => new(MoveYesClick); public RelayCommand MoveAllYesCommand => new(MoveAllYesClick); @@ -29,28 +25,28 @@ public DataReplaceMessageVM(string titleItem, DialogReplaceQuestionManager quest private void MoveYesClick(Window window) { - ResultQuestion.UpdateData(DialogReplaceItemQuestion.Yes); + ResultQuestion = DialogReplaceItemQuestion.Yes; window.DialogResult = true; window?.Close(); } private void MoveAllYesClick(Window window) { - ResultQuestion.UpdateData(DialogReplaceItemQuestion.AllYes); + ResultQuestion = DialogReplaceItemQuestion.AllYes; window.DialogResult = true; window?.Close(); } private void MoveNoClick(Window window) { - ResultQuestion.UpdateData(DialogReplaceItemQuestion.No); + ResultQuestion = DialogReplaceItemQuestion.No; window.DialogResult = true; window?.Close(); } private void MoveAllNoClick(Window window) { - ResultQuestion.UpdateData(DialogReplaceItemQuestion.AllNo); + ResultQuestion = DialogReplaceItemQuestion.AllNo; window.DialogResult = true; window?.Close(); } diff --git a/WatchList.WPF/Views/CinemaPage.xaml b/WatchList.WPF/Views/CinemaPage.xaml index 7c34dc7..4baab46 100644 --- a/WatchList.WPF/Views/CinemaPage.xaml +++ b/WatchList.WPF/Views/CinemaPage.xaml @@ -4,8 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" - xmlns:local="clr-namespace:WatchList.WPF.Views" - xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" + xmlns:local="clr-namespace:WatchList.WPF.Component" Title="CinemaPage" DataContext="{Binding CinemaPageViewModel, Source={StaticResource ViewModelLocator}}" MinHeight="300" MinWidth="300"> @@ -26,24 +25,28 @@ - - + + - - - + + +