You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AUCMA_SCADA/Aucma.Core.OldBoxFoam/ViewModels/SearchCriteriaViewModel.cs

81 lines
2.3 KiB
C#

using Aucma.Core.OldBoxFoam.Common;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Aucma.Core.OldBoxFoam.ViewModels
{
public partial class SearchCriteriaViewModel : ObservableObject
{
private AppConfigHelper appConfig =new AppConfigHelper();
public SearchCriteriaViewModel()
{
Init();
}
#region 关闭当前页
[RelayCommand]
private void CloseWindow(object parameter)
{
var window = parameter as Window;
if (window != null)
{
window.Close();
}
}
#endregion
#region 保存数据
[RelayCommand]
private void SaveSearchCriteria(Object window)
{
var config = ((Aucma.Core.OldBoxFoam.ViewModels.SearchCriteriaViewModel)((System.Windows.FrameworkElement)window).DataContext).Configurations;
var info = config.ToList();
string items = string.Empty;
foreach (var configuration in info)
{
items += configuration.ToString() + "%";
}
appConfig.searchItems = string.Empty;
appConfig.searchItems = items;
Init();
}
#endregion
#region MyRegion
private ObservableCollection<string> _configurations = new ObservableCollection<string>();
public ObservableCollection<string> Configurations
{
get => _configurations;
set => SetProperty(ref _configurations, value);
}
#endregion
#region 初始化
private void Init()
{
Configurations = new ObservableCollection<string>();
var searchItems = appConfig.searchItems;
var split = searchItems.Split('%');
foreach (var item in split)
{
Configurations.Add(item);
}
WeakReferenceMessenger.Default.Send<string>("RefreshSearchItems");//刷新窗口
}
#endregion
}
}