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.

153 lines
4.3 KiB
C#

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
* CLR4.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);
Query(string.Empty);
}
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,
IsFlag = 1,
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,
IsFlag = 1,
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);
}
}
}