ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/common/SysManage/RoleList.aspx.cs

295 lines
9.9 KiB
C#
Raw Normal View History

2024-05-08 17:17:11 +08:00
namespace FineUIPro.Web.common.SysManage
{
using System;
using System.Data;
using System.Linq;
using BLL;
public partial class RoleList : PageBase
{
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
// 表头过滤
FilterDataRowItem = FilterDataRowItemImplement;
if (!IsPostBack)
{
btnNew.OnClientClick = Window1.GetShowReference("RoleListEdit.aspx") + "return false;";
btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!");
btnDelete.ConfirmText = String.Format("你确定要删除选中的&nbsp;<b><script>{0}</script></b>&nbsp;行数据吗?", Grid1.GetSelectedCountReference());
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = "SELECT RoleId,RoleName,IsAuditFlow,IsAPPLeaderRole,Def FROM dbo.Sys_Role";
DataTable tb = SQLHelper.GetDataTableRunText(strSql);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#region
/// <summary>
/// 过滤表头
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_FilterChange(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 根据表头信息过滤列表数据
/// </summary>
/// <param name="sourceObj"></param>
/// <param name="fillteredOperator"></param>
/// <param name="fillteredObj"></param>
/// <param name="column"></param>
/// <returns></returns>
private bool FilterDataRowItemImplement(object sourceObj, string fillteredOperator, object fillteredObj, string column)
{
bool valid = false;
if (column == "RoleName")
{
string sourceValue = sourceObj.ToString();
string fillteredValue = fillteredObj.ToString();
if (fillteredOperator == "equal" && sourceValue == fillteredValue)
{
valid = true;
}
else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
{
valid = true;
}
}
return valid;
}
#endregion
#region
/// <summary>
/// 批量删除数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click(object sender, EventArgs e)
{
if (GetButtonPower(BLL.Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var role = BLL.Sys_RoleService.GetRole(rowID);
if (role != null)
{
if (role.RoleType == "0")
{
ShowNotify("内置项,不允许删除!", MessageBoxIcon.Warning);
return;
}
else
{
if (judgementDelete(rowID, false))
{
BLL.Sys_RoleService.DeleteRole(rowID);
}
}
}
}
BindGrid();
BLL.Sys_LogService.AddLog(BLL.Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除角色信息");
ShowNotify("删除数据成功!(表格数据已重新绑定)");
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!");
}
}
/// <summary>
/// 删除数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
string rowID = Grid1.DataKeys[e.RowIndex][0].ToString();
if (GetButtonPower(BLL.Const.BtnDelete))
{
if (e.CommandName == "Delete")
{
var role = BLL.Sys_RoleService.GetRole(rowID);
if (role != null)
{
if (role.RoleType == "0")
{
ShowNotify("内置项,不允许删除!", MessageBoxIcon.Warning);
return;
}
else
{
if (judgementDelete(rowID, true))
{
BLL.Sys_RoleService.DeleteRole(rowID);
BindGrid();
ShowNotify("删除数据成功!(表格数据已重新绑定)");
}
}
}
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!");
}
}
#endregion
#region
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
/// <summary>
/// 分页显示条数下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#endregion
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
/// <summary>
/// 关闭窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 选择行事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelectRows_Click(object sender, EventArgs e)
{
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnEdit_Click(object sender, EventArgs e)
{
if (GetButtonPower(BLL.Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInParent("请至少选择一条记录!");
return;
}
string Id = Grid1.SelectedRowID;
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("RoleListEdit.aspx?roleId={0}", Id, "编辑 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
btnEdit_Click(null, null);
}
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private bool GetButtonPower(string button)
{
return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.RoleMenuId, button);
}
#region
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private bool judgementDelete(string id,bool isShow)
{
string content = string.Empty;
if (Funs.DB.Sys_User.FirstOrDefault(x => x.RoleId == id) != null)
{
content = "该角色已在【用户信息】中使用,不能删除!";
}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content);
}
return false;
}
}
#endregion
}
}