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.Palletiz/ViewModels/SearchCriteriaViewModel.cs

93 lines
2.6 KiB
C#

using Aucma.Core.Palletiz.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.Palletiz.ViewModels
{
public partial class SearchCriteriaViewModel : ObservableObject
{
#region 更新完快捷方式查询刷新
/// <summary>
/// 更新完快捷方式查询刷新
/// </summary>
/// <returns></returns>
public delegate void RefreshConfigDelegate();
public static event RefreshConfigDelegate RefreshConfigDelegateEvent;
#endregion
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.Palletiz.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();
RefreshConfigDelegateEvent?.Invoke();
}
#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>("RefreshPalletizSearchItems");//刷新窗口
}
#endregion
}
}