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.

150 lines
4.2 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Business;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* 版权所有 (c) 2024 WenJY 保留所有权利。
* CLR版本4.0.30319.42000
* 机器名称LAPTOP-E0N2L34V
* 命名空间SlnMesnac.WPF.ViewModel
* 唯一标识a5944d3a-5653-4b07-bc01-6782c056b849
*
* 创建者WenJY
* 电子邮箱wenjy@mesnac.com
* 创建时间2024-04-15 10:42:25
* 版本V1.0.0
* 描述:
*
*--------------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.ViewModel
{
public class BaseConfigInfoViewModel : ViewModelBase
{
private readonly ConfigInfoBusiness _configInfoBusiness;
public BaseConfigInfoViewModel()
{
_configInfoBusiness = App.ServiceProvider.GetService<ConfigInfoBusiness>();
QuerySearchCommand = new RelayCommand<string>(Query);
DeleteCommand = new RelayCommand<int>(Delete);
ResetSearchCommand = new RelayCommand(ResetSearch);
}
private string _searchStr = string.Empty;
public string SearchStr
{
get { return _searchStr; }
set
{
_searchStr = value;
RaisePropertyChanged(nameof(SearchStr));
}
}
private ObservableCollection<BaseConfigInfo> tablesDataGrid;
public ObservableCollection<BaseConfigInfo> TablesDataGrid
{
get { return tablesDataGrid; }
set { tablesDataGrid = value; RaisePropertyChanged(() => TablesDataGrid); }
}
public RelayCommand<string> QuerySearchCommand { get; set; }
public RelayCommand<int> DeleteCommand { get; set; }
public RelayCommand ResetSearchCommand { get;set; }
/// <summary>
/// 查询事件
/// </summary>
/// <param name="search"></param>
private void Query(string search)
{
List<BaseConfigInfo> configInfos = _configInfoBusiness.GetConfigInfos();
if (configInfos != null)
{
if (!string.IsNullOrEmpty(search))
{
configInfos = configInfos.Where(x=>x.ConfigName == search).ToList();
}
TablesDataGrid = new ObservableCollection<BaseConfigInfo>();
configInfos.ForEach(t => {
TablesDataGrid.Add(t);
});
}
}
public void Save(string configKey, string configName, string configValue)
{
BaseConfigInfo baseConfig = new BaseConfigInfo()
{
ConfigKey = configKey,
ConfigName = configName,
ConfigValue = configValue,
CreateTime = DateTime.Now,
};
_configInfoBusiness.SaveConfigInfo(baseConfig);
Query(string.Empty);
}
public void Edit(string configId,string configKey, string configName, string configValue)
{
BaseConfigInfo baseConfig = new BaseConfigInfo()
{
ConfigId = Convert.ToInt32(configId),
ConfigKey = configKey,
ConfigName = configName,
ConfigValue = configValue,
CreateTime = DateTime.Now,
};
_configInfoBusiness.UpdateConfigInfo(baseConfig);
Query(string.Empty);
}
private void Delete(int configId)
{
_configInfoBusiness.DeleteConfigInfo(configId);
Query(string.Empty);
}
private void ResetSearch()
{
SearchStr = string.Empty;
Query(string.Empty);
}
}
}