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.

87 lines
2.2 KiB
C#

using Admin.Core.IService;
using Admin.Core.Model;
using Aucma.Scada.UI.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using log4net;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Scada.UI.ViewModel
{
public partial class RecordViewModel : ObservableObject
{
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(RecordViewModel));
private readonly ISysUserInfoServices? _sysUserInfoService;
public RecordViewModel()
{
_sysUserInfoService = App.ServiceProvider.GetService<ISysUserInfoServices>();
}
private String search = String.Empty;
public String Search
{
get => search;
set => SetProperty(ref search, value);
}
private ObservableCollection<SysUserInfo> gridModelList;
//前端使用的属性
public ObservableCollection<SysUserInfo> GridModelList
{
get => gridModelList;
set => SetProperty(ref gridModelList, value);
}
#region 查询事件
/// <summary>
/// 查询事件
/// </summary>
[RelayCommand]
public async void Query()
{
var models = await _sysUserInfoService.QueryAsync();
if (!string.IsNullOrEmpty(Search))
{
models = models.Where(x => x.UserName.Contains(Search)).ToList();
}
GridModelList = new ObservableCollection<SysUserInfo>();
if (models != null)
{
models.ForEach(
arg =>
{
GridModelList.Add(arg);
}
);
}
}
#endregion
#region 重置
/// <summary>
/// 重置
/// </summary>
[RelayCommand]
public void Reset()
{
Search = String.Empty;
this.Query();
}
#endregion
}
}