HuNan_NOSqlSugar/DM_Weight/ViewModels/UserManagerWindowViewModel.cs

206 lines
6.2 KiB
C#
Raw Normal View History

2024-07-06 10:01:30 +08:00
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using DM_Weight.Models;
using DM_Weight.select;
using DM_Weight.util;
using SqlSugar;
using DM_Weight.Services;
namespace DM_Weight.ViewModels
{
public class UserManagerWindowViewModel : BindableBase, IConfirmNavigationRequest, IRegionMemberLifetime
{
private int _pageNum = 1;
public int PageNum
{
get => _pageNum;
set
{
SetProperty(ref _pageNum, value);
RequestData();
}
}
private int _pageCount = 1;
public int PageCount
{
get => _pageCount;
set
{
SetProperty(ref _pageCount, value);
}
}
private int _pageSize = 8;
public int PageSize
{
get => _pageSize;
set
{
SetProperty(ref _pageSize, value);
}
}
private int _totalCount = 0;
public int TotalCount
{
get => _totalCount;
set
{
SetProperty(ref _totalCount, value);
}
}
private List<UserList> _userList;
public List<UserList> UserList
{
get { return _userList; }
set { SetProperty(ref _userList, value); }
}
private UserList? _user;
public UserList? User
{
get { return _user; }
set { SetProperty(ref _user, value); }
}
private readonly IDialogService _dialogService;
//private SqlSugarScope SqlSugarHelper.Db;
SqlHelperService _sqlHelperService;
public UserManagerWindowViewModel(IDialogService dialogService, SqlSugarScope sqlSugarScope,SqlHelperService sqlHelperService)
{
_dialogService = dialogService;
//this.SqlSugarHelper.Db = sqlSugarScope;
_sqlHelperService= sqlHelperService;
}
private string? _searchValue;
/// <summary>
/// 查询条件 查询字段值
/// </summary>
public string? SearchValue
{
get { return _searchValue; }
set
{
SetProperty(ref _searchValue, value);
RequestData();
}
}
public DelegateCommand Query
{
get => new DelegateCommand(() =>
{
RequestData();
});
}
public DelegateCommand OpenFingerDialog
{
get => new DelegateCommand(() =>
{
DialogParameters dialogParameters = new DialogParameters();
dialogParameters.Add("User", User);
DialogServiceExtensions.ShowDialogHost(_dialogService, "FingerprintDialog", dialogParameters, DoDialogResult, "RootDialog");
});
}
public DelegateCommand OpenEditUserDialog
{
get => new DelegateCommand(() =>
{
DialogParameters dialogParameters = new DialogParameters();
dialogParameters.Add("User", User);
DialogServiceExtensions.ShowDialogHost(_dialogService, "EditUserDialog", dialogParameters, DoDialogResult2, "RootDialog");
});
}
public DelegateCommand OpenInsertUserDialog
{
get => new DelegateCommand(() =>
{
DialogParameters dialogParameters = new DialogParameters();
DialogServiceExtensions.ShowDialogHost(_dialogService, "EditUserDialog", dialogParameters, DoDialogResult2, "RootDialog");
});
}
public bool KeepAlive => true;
private void DoDialogResult(IDialogResult dialogResult)
{
// 委托 被动执行 被子窗口执行
// dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态
if (dialogResult.Result == ButtonResult.OK)
{
RequestData();
}
}
private void DoDialogResult2(IDialogResult dialogResult)
{
// 委托 被动执行 被子窗口执行
// dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态
if (dialogResult.Result == ButtonResult.OK)
{
RequestData();
}
}
//这个方法用于拦截请求,continuationCallback(true)就是不拦截continuationCallback(false)拦截本次操作
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
{
continuationCallback(true);
}
//接收导航传过来的参数
public void OnNavigatedTo(NavigationContext navigationContext)
{
//查询表格数据
RequestData();
}
void RequestData()
{
int totalcount = 0;
//UserList = SqlSugarHelper.Db.Queryable<UserList>()
// .Includes<RoleDm>(ul => ul.Role)
// .Where(ul => ul.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1"))
// .WhereIF(!String.IsNullOrEmpty(SearchValue) , (di) => di.Nickname.Contains(SearchValue))
// .ToPageList(PageNum, PageSize, ref totalcount)
// //.ToList()
// ;
UserList = _sqlHelperService.UserManagerInfo(SearchValue, PageNum, PageSize, ref totalcount);
TotalCount = totalcount;
}
//每次导航的时候该实列用不用重新创建true是不重新创建,false是重新创建
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
//这个方法用于拦截请求
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
}
}