using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HighWayIot.Log4net; using HighWayIot.Repository.domain; using HighWayIot.Repository.service; using HighWayIot.Repository.service.Impl; 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 class RecordViewModel: ViewModelBase { private LogHelper logHelper = LogHelper.Instance; private ISysUserInfoService sysUserInfoService = new SysUserInfoServiceImpl(); public RecordViewModel() { } private String search = String.Empty; public String Search { get { return search; } set { search = value; RaisePropertyChanged(); } } private ObservableCollection gridModelList; //前端使用的属性 public ObservableCollection GridModelList { get { return gridModelList; } set { gridModelList = value; RaisePropertyChanged(); } } /// /// 查询事件 /// private RelayCommand _queryCommand; public RelayCommand QueryCommand { get { if (_queryCommand == null) _queryCommand = new RelayCommand(Query); return _queryCommand; } set { _queryCommand = value; RaisePropertyChanged(nameof(QueryCommand)); } } public void Query() { var models = sysUserInfoService.GetUserInfos(); if (!string.IsNullOrEmpty(Search)) { models = models.Where(x => x.userName.Contains(Search)).ToList(); } GridModelList = new ObservableCollection(); if (models != null) { models.ForEach( arg => { GridModelList.Add(arg); } ); } } /// /// 重置 /// private RelayCommand _resetCommand; public RelayCommand ResetCommand { get { if (_resetCommand == null) _resetCommand = new RelayCommand(Reset); return _resetCommand; } set { _resetCommand = value; RaisePropertyChanged(nameof(ResetCommand)); } } public void Reset() { Search = String.Empty; this.Query(); } } }