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

111 lines
3.4 KiB
C#

using Aucma.Core.BoxFoam.Common;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using StackExchange.Profiling.Internal;
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.BoxFoam.ViewModels
{
public partial class SearchCriteriaViewModel : ObservableObject
{
private AppConfigHelper appConfig =new AppConfigHelper();
/// <summary>
/// 委托,关闭窗口
/// </summary>
/// <param name="message"></param>
public delegate void close();
public event close closeEvent;
/// <summary>
/// 刷新货道设置物料型号页面
/// </summary>
/// <param name="message"></param>
public delegate void RefreshPage();
public static event RefreshPage RefreshPageEvent;
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)
{
try
{
Console.WriteLine("==================初始配置文件数据"+ appConfig.searchItems);
Console.WriteLine("==================测试数据");
var config = ((Aucma.Core.BoxFoam.ViewModels.SearchCriteriaViewModel)((System.Windows.FrameworkElement)window).DataContext).Configurations;
var info = config.ToList();
Console.WriteLine("========待保存数据" + info.ToJson());
string items = string.Empty;
foreach (var configuration in info)
{
items += configuration.ToString() + "%";
}
appConfig.searchItems = string.Empty;
appConfig.searchItems = items;
Console.WriteLine("==========配置文件数据appConfig.searchItems" + appConfig.searchItems);
Init();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
#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");//刷新窗口
// 关闭窗口
closeEvent?.Invoke();
RefreshPageEvent?.Invoke();
}
#endregion
}
}