添加项目文件。

This commit is contained in:
2026-04-30 11:34:41 +08:00
parent a8539ccaac
commit 80635aa46e
181 changed files with 16378 additions and 0 deletions

View File

@@ -0,0 +1,171 @@
using SamplePre.Models.Ext;
using SamplePre.Models.Tables;
using SamplePre.ProcessBll.BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace SamplePreSystem.UI.ViewModel.ConfigManager
{
public class PermissionViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
RolesBll rolesBll = new RolesBll();
config_role configRole;
public PermissionViewModel(RoleViewModel vm)
{
configRole = vm.ConfigRole;
RoleName = configRole.name;
GetData();
}
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string _roleName;
public string RoleName
{
get { return _roleName; }
set { _roleName = value; }
}
private List<TreeItemModel> _funList = new List<TreeItemModel>();
public List<TreeItemModel> FunList
{
get { return _funList; }
set { _funList = value;
OnPropertyChanged();
}
}
public void GetData()
{
var FunListTemp = rolesBll.GetFuncDataTree();
foreach (var item in FunListTemp.Where(p=>p.parent_id == 0))
{
// 根节点1
var root1 = new TreeItemModel { Id = item.id, Name = item.name };
foreach(var child in FunListTemp.Where(p => p.parent_id == item.id))
{
root1.Children.Add(new TreeItemModel { Id = child.id, Name = child.name, Parent = root1 });
}
FunList.Add(root1);
}
//选择中角色已有权限
List<int> ids = rolesBll.GetPermission(configRole.id);
LoadRolePermissions(ids);
}
/// <summary>
/// 加载指定角色已分配的权限(用于编辑角色权限)
/// </summary>
/// <param name="roleFunctionIds">角色已拥有的功能ID列表</param>
public void LoadRolePermissions(List<int> roleFunctionIds)
{
if (roleFunctionIds == null || roleFunctionIds.Count == 0) return;
foreach (var item in FunList)
{
bool isAll = true;
foreach (var fuc in item.Children)
{
if (roleFunctionIds.Contains(fuc.Id))
{
fuc.IsChecked = true;
//item.IsChecked = true;
}
else
{
isAll = false;
}
}
if(isAll)
{
item.IsChecked = true;
}
}
}
public bool SavePermission()
{
// 获取选中的功能ID列表
List<int> selectedIds = GetSelectedFunctionIds();
if (selectedIds.Count == 0)
{
MessageBox.Show("请至少选择一个功能权限!", "提示");
return false;
}
List<config_role_permisson> rolePermissonList = new List<config_role_permisson>();
foreach (int item in selectedIds)
{
config_role_permisson rolePermisson = new config_role_permisson();
rolePermisson.function_id = item;
rolePermisson.role_id = configRole.id;
rolePermissonList.Add(rolePermisson);
}
if (rolesBll.SavePermission(rolePermissonList) < 0)
{
MessageBox.Show("保存失败!");
return false;
}
return true;
}
private List<int> GetSelectedFunctionIds()
{
List<int> selectedIds = new List<int>();
foreach (var item in FunList)
{
foreach(var fuc in item.Children)
{
if(fuc.IsChecked)
{
//添加父节点功能id
if(!selectedIds.Contains(item.Id))
{
selectedIds.Add(item.Id);
}
selectedIds.Add(fuc.Id);
}
}
}
return selectedIds;
}
}
}

View File

@@ -0,0 +1,154 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using SamplePre.Models.Tables;
using SamplePre.ProcessBll.BLL;
using SamplePre.UIWpf.ConfigManager.chirld;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace SamplePreSystem.UI.ViewModel.ConfigManager
{
public partial class RoleViewModel : ObservableObject
{
RolesBll roleBll = new RolesBll();
public RoleViewModel()
{
GetData();
}
[ObservableProperty]
private List<config_role> rolesList;
[ObservableProperty]
private config_role configRole = new config_role();
public void GetData()
{
RolesList = roleBll.GetRoles();
}
/// <summary>
/// 保存角色
/// </summary>
public bool SaveRole()
{
if(string.IsNullOrEmpty(ConfigRole.name.Trim()))
{
MessageBox.Show("角色名称不能为空!");
return false;
}
if (string.IsNullOrEmpty(ConfigRole.id))
{
//new
ConfigRole.id = Guid.NewGuid().ToString();
if (roleBll.SaveRoleData(ConfigRole) < 0)
{
return false;
}
}
else
{
if (roleBll.UpdateRoleData(ConfigRole) < 0)
{
return false;
}
}
return true;
}
public bool DeleteRole()
{
if(!string.IsNullOrEmpty( ConfigRole.id ))
{
if (MessageBox.Show($"确定删除:{ConfigRole.name}", "提示",MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
if (roleBll.DeleteRole(ConfigRole) < 0)
{
MessageBox.Show("用户删除失败!");
return false;
}
//刷新用户
GetData();
return true;
}
}
return false;
}
/// <summary>
/// 添加角色
/// </summary>
[RelayCommand]
public void BtnAddClick()
{
ConfigRole = new config_role();
NewRoleWindow frm = new NewRoleWindow(this);
if (frm.ShowDialog() == true)
{
GetData();
}
}
/// <summary>
/// 编辑角色
/// </summary>
[RelayCommand]
public void BtnEditClick()
{
NewRoleWindow frm = new NewRoleWindow(this);
if (frm.ShowDialog() == true)
{
GetData();
}
}
/// <summary>
/// 删除角色
/// </summary>
[RelayCommand]
public void BtnDeleClick()
{
DeleteRole();
}
[RelayCommand]
public void BtnPermissonClick()
{
if (string.IsNullOrEmpty(ConfigRole.id)) return;
PermissionWindow frm = new PermissionWindow(this);
frm.ShowDialog();
}
}
}

View File

@@ -0,0 +1,253 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MaterialDesignThemes.Wpf;
using Models.Models;
using SamplePre.Models;
using SamplePre.Models.Models;
using SamplePre.ProcessBll.BLL;
using SamplePreSystem.UI.ConfigManager.chirld;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace SamplePreSystem.UI.ViewModel.ConfigManager
{
public partial class SysConfigMangerViewModel : ObservableObject
{
SystemBll systemBll = new SystemBll();
public SysConfigMangerViewModel()
{
GetDictClassData();
}
private List<TreeItemModel> _dictClassList = new List<TreeItemModel>();
public List<TreeItemModel> DictClassList
{
get { return _dictClassList; }
set {
SetProperty(ref _dictClassList, value);
}
}
private sys_dict_class _dictClass = new sys_dict_class();
public sys_dict_class DictClass
{
get { return _dictClass; }
set {
SetProperty(ref _dictClass, value);
}
}
/// <summary>
/// 获取字典分类数据
/// </summary>
public void GetDictClassData()
{
List<TreeItemModel> list = new List<TreeItemModel>();
//获取样本
var dictClassTemp = systemBll.QueryDictClassData();
var root1 = new TreeItemModel() { Id = 0, Name = "系统配置", IconKind = PackIconKind.DnsOutline };
foreach (var item in dictClassTemp)
{
root1.Children.Add(new TreeItemModel() { Id = item.id, Name = item.dict_type,Parent = root1 , IconKind = PackIconKind.FileDocumentOutline });
}
list.Add(root1);
DictClassList = list;
}
private List<sys_dict> _sysdicts = new List<sys_dict>();
public List<sys_dict> SysDicts
{
get { return _sysdicts; }
set {
SetProperty(ref _sysdicts, value);
}
}
private sys_dict _sysDict = new sys_dict();
public sys_dict SysDict
{
get { return _sysDict; }
set {
SetProperty(ref _sysDict, value);
}
}
/// <summary>
/// 查询字典明细
/// </summary>
/// <param name="standID"></param>
public void GetDictData(int classid)
{
//查询
SysDicts = systemBll.QueryDictByClassId(classid);
}
public bool NewAddDict()
{
if (string.IsNullOrEmpty(this.DictClass.dict_type))
{
MessageBox.Show("内容不能为空");
return false;
}
systemBll.SaveSysDictClass(DictClass);
//获取数据
GetDictClassData();
return true;
}
public void DeleteDict()
{
if (MessageBox.Show($"确定移除:{DictClass.dict_type}", "提示",MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
//判断是否有子配置项
if (this.systemBll.QueryDictByClassId(DictClass.id).Count > 0)
{
MessageBox.Show("存在配置子项目,不能删除!");
return;
}
if (this.systemBll.DelDictClassById(DictClass.id) <= 0)
{
MessageBox.Show("删除失败!");
return;
}
//获取数据
GetDictClassData();
}
}
public bool NewAddDictDetail()
{
if (SysDict == null || string.IsNullOrEmpty(this.SysDict.data_type) || string.IsNullOrEmpty(this.SysDict.data_value))
{
MessageBox.Show("内容不能为空");
return false;
}
SysDict.class_id = DictClass.id;
SysDict.id = Guid.NewGuid().ToString();
this.systemBll.SaveSysDict(SysDict);
//刷新
GetDictData(DictClass.id);
return true;
}
public void DeleteDictDetail()
{
if (MessageBox.Show($"确定移除:{SysDict.data_type}", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
//移除
this.systemBll.DelSysDictByid(SysDict);
//刷新
GetDictData(DictClass.id);
}
}
[RelayCommand]
public void AddClassClick()
{
//var vm = this.DataContext as SysConfigMangerViewModel;
//清空对象内容
DictClass = new SamplePre.Models.Models.sys_dict_class();
NewDictClassWindow frm = new NewDictClassWindow(this);
frm.ShowDialog();
}
[RelayCommand]
public void DelClassClick()
{
DeleteDict();
}
[RelayCommand]
public void TvDataSelectedItemChanged(RoutedPropertyChangedEventArgs<object> e)
{
//var vm = this.DataContext as SysConfigMangerViewModel;
var node = e.NewValue as TreeItemModel;
DictClass.dict_type = node.Name;
DictClass.id = node.Id;
GetDictData(node.Id);
}
[RelayCommand]
public void AddItemClick()
{
SysDict = new Models.Models.sys_dict();
if (DictClass.id == null || DictClass.id == 0)
{
MessageBox.Show("请先选择分类");
return;
}
NewDictDetailWindow frm = new NewDictDetailWindow(this);
frm.ShowDialog();
}
[RelayCommand]
public void DelItemClick()
{
DeleteDictDetail();
}
}
}

View File

@@ -0,0 +1,80 @@
using MaterialDesignThemes.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace SamplePreSystem.UI.ViewModel.ConfigManager
{
public class TreeItemModel : INotifyPropertyChanged
{
public bool IsUpdate = true;
private bool _isChecked;
public bool IsChecked
{
get { return _isChecked; }
set
{
_isChecked = value;
OnPropertyChanged();
if (Children.Count > 0)
{
SetChildrenCheck(value);
}
else
{
//if (Parent != null) Parent.IsChecked = value;
}
}
}
public int Id { get; set; }
public string Name { get; set; }
// 父节点改变子节点
private void SetChildrenCheck(bool isChecked)
{
foreach (var child in Children)
{
child.IsChecked = isChecked;
}
}
// 子节点改变后,更新父节点状态
private void UpdateParentState(bool isChecked)
{
if (Parent == null) return;
//bool anyChecked = Parent.Children.Any(x => x.IsChecked);
Parent.IsChecked = isChecked;
}
// 子节点
public List<TreeItemModel> Children { get; set; } = new List<TreeItemModel>();
// 父节点(用于联动)
public TreeItemModel Parent { get; set; }
public PackIconKind IconKind { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,286 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using SamplePre.Models.Ext;
using SamplePre.Models.Tables;
using SamplePre.ProcessBll.BLL;
using SamplePre.UIWpf.ConfigManager.chirld;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace SamplePreSystem.UI.ViewModel.ConfigManager
{
public partial class UsersViewModel : ObservableObject
{
UsersBll usersBll = new UsersBll();
// 关闭窗口的委托
public Action<bool> CloseAction { get; set; }
public UsersViewModel()
{
//获取用户数据
GetData();
}
private List<config_user_ext> _userList = new List<config_user_ext>();
public List<config_user_ext> UserList
{
get { return _userList; }
set {
SetProperty(ref _userList, value);
}
}
private config_user_ext _selectUser;
public config_user_ext SelectUser
{
get { return _selectUser; }
set { _selectUser = value; }
}
private config_user_ext _configUser =new config_user_ext();
public config_user_ext ConfigUser
{
get { return _configUser; }
set {
SetProperty(ref _configUser, value);
}
}
/// <summary>
/// 查询用户
/// </summary>
public void GetData()
{
UserList = usersBll.GetUsers();
}
private List<config_role_ext> roles = new List<config_role_ext>();
public List<config_role_ext> Roles
{
get { return roles; }
set {
SetProperty(ref roles, roles);
}
}
/// <summary>
/// 绑定角色数据
/// </summary>
public void InitCheckedListBox()
{
Roles.Clear();
var roleList = usersBll.GetRoles();
foreach (var item in roleList)
{
config_role_ext model = new config_role_ext();
model.id = item.id;
model.name = item.name;
model.description = item.description;
model.IsSelected = false;
Roles.Add(model);
}
if (!string.IsNullOrEmpty(ConfigUser.id))
{
//获取用户的角色
var userRoles = usersBll.GetUserRoles(ConfigUser.id);
foreach(var item in Roles)
{
if(userRoles.Where(p=>p.role_id == item.id).Count() > 0)
{
item.IsSelected = true;
}
}
}
}
private string isEnable = "启用";
public string IsEnable
{
get { return isEnable; }
set {
SetProperty(ref isEnable, isEnable);
}
}
public bool SaveUser()
{
if (ConfigUser == null) return false;
//ConfigUser.username = this.txtUserName.Text;
//ConfigUser.password = this.txtPwd.Text;
ConfigUser.is_enabled = IsEnable == "启用" ? true : false;
if (string.IsNullOrEmpty(ConfigUser.id))
{
//new
ConfigUser.id = Guid.NewGuid().ToString();
//选中的角色
var roles = GetCheckedData();
if (usersBll.SaveUserData(ConfigUser, roles) < 0)
{
return false;
}
}
else
{
//update
//选中的角色
var roles = GetCheckedData();
if (usersBll.UpdateUserData(ConfigUser, roles) < 0)
{
return false;
}
}
return true;
}
/// <summary>
/// 获取用户角色
/// </summary>
/// <returns></returns>
public List<config_user_role> GetCheckedData()
{
List<config_user_role> userRoles = new List<config_user_role>();
foreach (var role in Roles)
{
if(role.IsSelected)
{
//config_role item = cbRoles.GetItem(i) as config_role;
config_user_role configUserRole = new config_user_role();
configUserRole.role_id = role.id.ToString();
configUserRole.user_id = ConfigUser.id;
userRoles.Add(configUserRole);
}
}
return userRoles;
}
public bool DeleUser()
{
if(SelectUser != null)
{
config_user user = SelectUser;
if (MessageBox.Show($"是否真的删除{user.username}", "删除提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
if (usersBll.DeleteUser(user) < 0)
{
MessageBox.Show("用户删除失败!");
return false;
}
//刷新用户
GetData();
}
}
return true;
}
[RelayCommand]
public void BtnAddClick()
{
ConfigUser = new config_user_ext();
//初始化角色数据
InitCheckedListBox();
NewUserWindow frm = new NewUserWindow(this);
if (frm.ShowDialog() == true)
{
//刷新数据
GetData();
}
}
[RelayCommand]
public void BtnEditClick()
{
ConfigUser = SelectUser;
//初始化角色数据
InitCheckedListBox();
NewUserWindow frm = new NewUserWindow(this);
if (frm.ShowDialog() == true)
{
//刷新数据
GetData();
}
}
[RelayCommand]
public void BtnDeleClick()
{
DeleUser();
}
[RelayCommand]
public void BtnSaveUserClick()
{
if (SaveUser() == true)
{
this.CloseAction?.Invoke(true);
}
}
}
}