liyaobang 9f7c6206ca 提交rbac
提交设置右键错位的bug
2025-04-08 15:15:02 +08:00

224 lines
7.0 KiB
C#

using AntdUI;
using DH.RBAC.Common;
using DH.RBAC.Logic;
using DH.RBAC.Logic.Sys;
using DH.RBAC.Model.Sys;
using DH.RBAC.Page.Sys.User;
using DH.RBAC.Utility.Other;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DH.RBAC.Page.Sys.Role
{
[PageCode("sys-role")]
public partial class RolePage : MyPage
{
private SysRoleLogic roleLogic;
private SysUserRoleRelationLogic roleRelationLogic;
Window window;
public RolePage(Window _window)
{
window = _window;
InitializeComponent();
roleLogic = new SysRoleLogic();
roleRelationLogic = new SysUserRoleRelationLogic();
dataGridView.AutoGenerateColumns = false;
Load += RolePage_Initialize;
btnAdd.Click += btnAdd_Click;
btnUpdate.Click += btnModify_Click;
btnDelete.Click += btnDelete_Click;
btnPwd.Click += btnAuthorize_Click;
btnQuery.Click += btnQuery_Click;
}
/// <summary>
/// 界面初始化,查询显示数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RolePage_Initialize(object sender, EventArgs e)
{
btnQuery_Click(sender, e);
}
/// <summary>
/// 查询按钮事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void btnQuery_Click(object sender, EventArgs e)
{
int totalCount = 0;
List<SysRole> list = roleLogic.GetList(pagination.ActivePage, pagination.PageSize, txtKeywords.Text, ref totalCount);
pagination.TotalCount = totalCount;
dataGridView.DataSource = list;
}
/// <summary>
/// 关键字Enter键处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtKeywords_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
btnQuery_Click(sender, null);
}
/// <summary>
/// 新增角色按钮事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAdd_Click(object sender, EventArgs e)
{
AddRoleForm form = new AddRoleForm();
form.ParentPage = this;
form.Id = string.Empty;
FormHelper.ShowSubForm(form);
}
/// <summary>
/// 修改角色按钮事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnModify_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 0)
{
AntdUI.Message.warn(window, "请选择一行数据进行修改!", autoClose: 3);
return;
}
int index = dataGridView.SelectedIndex;
if (index < 0)
{
AntdUI.Message.warn(window, "请选择一行数据进行修改!", autoClose: 3);
return;
}
string id = dataGridView.Rows[index].Cells["RoleId"].Value.ToString();
AddRoleForm form = new AddRoleForm();
form.ParentPage = this;
form.Id = id;
FormHelper.ShowSubForm(form);
}
/// <summary>
/// 删除角色按钮事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 0)
{
AntdUI.Message.warn(window, "请选择一行数据进行删除!", autoClose: 3);
return;
}
int index = dataGridView.SelectedIndex;
if (index < 0)
{
AntdUI.Message.warn(window, "请选择一行数据进行删除!", autoClose: 3);
return;
}
string id = dataGridView.Rows[index].Cells["RoleId"].Value.ToString();
var result = AntdUI.Modal.open(window, "删除警告!", "您是否确定要删除该角色?", TType.Warn);
if (result == DialogResult.OK)
{
try
{
//判断这些权限是不是被用户绑定了,一旦绑定了,就不能删除,提示请先将用户解除绑定
List<string> ids = id.SplitToList();
List<SysUserRoleRelation> roleRelationList = roleRelationLogic.GetByRoles(ids);
if (roleRelationList.Count > 0)
{
AntdUI.Message.warn(window, "请先从用户中解除角色绑定!", autoClose: 3);
return;
}
int row = roleLogic.Delete(ids);
if (row == 0)
{
AntdUI.Message.warn(window, "对不起,操作失败!", autoClose: 3);
return;
}
//重新查询
btnQuery_Click(null, null);
}
catch
{
AntdUI.Message.warn(window, "网络或服务器异常,请稍后再试!", autoClose: 3);
}
}
}
/// <summary>
/// 角色授权按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAuthorize_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 0)
{
AntdUI.Message.warn(window, "请选择一行数据进行授权!", autoClose: 3);
return;
}
int index = dataGridView.SelectedIndex;
if (index < 0)
{
AntdUI.Message.warn(window, "请选择一行数据进行授权!", autoClose: 3);
return;
}
string id = dataGridView.Rows[index].Cells["RoleId"].Value.ToString();
RoleAuthorizeForm form = new RoleAuthorizeForm();
form.ParentPage = this;
form.Id = id;
FormHelper.ShowSubForm(form);
}
/// <summary>
/// 页码变更触发
/// </summary>
/// <param name="sender"></param>
/// <param name="pagingSource"></param>
/// <param name="pageIndex"></param>
/// <param name="count"></param>
private void pagination_PageChanged(object sender, object pagingSource, int pageIndex, int count)
{
btnQuery_Click(null, null);
}
private void btnUpdate_Click(object sender, EventArgs e)
{
}
}
}