You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
5.2 KiB
190 lines
5.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.Linq;
|
|
using System.Data.Entity;
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
using FineUI;
|
|
using EntityFramework.Extensions;
|
|
|
|
namespace SCP.admin
|
|
{
|
|
public partial class power : PageBase
|
|
{
|
|
#region ViewPower
|
|
|
|
/// <summary>
|
|
/// 本页面的浏览权限,空字符串表示本页面不受权限控制
|
|
/// </summary>
|
|
public override string ViewPower
|
|
{
|
|
get
|
|
{
|
|
return "CorePowerView";
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Page_Load
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
LoadData();
|
|
}
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
// 权限检查
|
|
CheckPowerWithButton("CorePowerNew", btnNew);
|
|
//CheckPowerDeleteWithButton(btnDeleteSelected);
|
|
|
|
//ResolveDeleteButtonForGrid(btnDeleteSelected, Grid1);
|
|
|
|
btnNew.OnClientClick = Window1.GetShowReference("~/admin/power_new.aspx", "新增权限");
|
|
|
|
|
|
// 每页记录数
|
|
Grid1.PageSize = ConfigHelper.PageSize;
|
|
ddlGridPageSize.SelectedValue = ConfigHelper.PageSize.ToString();
|
|
|
|
|
|
BindGrid();
|
|
}
|
|
|
|
private void BindGrid()
|
|
{
|
|
IQueryable<Power> q = DB.Powers;
|
|
|
|
// 在权限名称中搜索
|
|
string searchText = ttbSearchMessage.Text.Trim();
|
|
if (!String.IsNullOrEmpty(searchText))
|
|
{
|
|
q = q.Where(p => p.Name.Contains(searchText) || p.Title.Contains(searchText));
|
|
}
|
|
|
|
// 在查询添加之后,排序和分页之前获取总记录数
|
|
Grid1.RecordCount = q.Count();
|
|
|
|
// 排列和数据库分页
|
|
q = SortAndPage<Power>(q, Grid1);
|
|
|
|
Grid1.DataSource = q;
|
|
Grid1.DataBind();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
protected void ttbSearchMessage_Trigger2Click(object sender, EventArgs e)
|
|
{
|
|
ttbSearchMessage.ShowTrigger1 = true;
|
|
BindGrid();
|
|
}
|
|
|
|
protected void ttbSearchMessage_Trigger1Click(object sender, EventArgs e)
|
|
{
|
|
ttbSearchMessage.Text = String.Empty;
|
|
ttbSearchMessage.ShowTrigger1 = false;
|
|
BindGrid();
|
|
}
|
|
|
|
protected void Grid1_PreDataBound(object sender, EventArgs e)
|
|
{
|
|
// 数据绑定之前,进行权限检查
|
|
CheckPowerWithWindowField("CorePowerEdit", Grid1, "editField");
|
|
CheckPowerWithLinkButtonField("CorePowerDelete", Grid1, "deleteField");
|
|
}
|
|
|
|
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
|
{
|
|
Grid1.SortDirection = e.SortDirection;
|
|
Grid1.SortField = e.SortField;
|
|
BindGrid();
|
|
}
|
|
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
Grid1.PageIndex = e.NewPageIndex;
|
|
BindGrid();
|
|
}
|
|
|
|
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
|
|
{
|
|
int powerID = GetSelectedDataKeyID(Grid1);
|
|
|
|
if (e.CommandName == "Delete")
|
|
{
|
|
// 在操作之前进行权限检查
|
|
if (!CheckPower("CorePowerDelete"))
|
|
{
|
|
CheckPowerFailWithAlert();
|
|
return;
|
|
}
|
|
|
|
int roleCount = DB.Roles.Where(r => r.Powers.Any(p => p.ID == powerID)).Count();
|
|
if (roleCount > 0)
|
|
{
|
|
Alert.ShowInTop("删除失败!需要先清空使用此权限的角色!");
|
|
return;
|
|
}
|
|
|
|
// 执行数据库操作
|
|
DB.Powers.Where(r => r.ID == powerID).Delete();
|
|
|
|
BindGrid();
|
|
}
|
|
}
|
|
|
|
|
|
//protected void btnDeleteSelected_Click(object sender, EventArgs e)
|
|
//{
|
|
// // 在操作之前进行权限检查
|
|
// if (!CheckPower("CorePowerDelete"))
|
|
// {
|
|
// CheckPowerFailWithAlert();
|
|
// return;
|
|
// }
|
|
|
|
// // 从每个选中的行中获取ID(在Grid1中定义的DataKeyNames)
|
|
// List<int> ids = GetSelectedDataKeyIDs(Grid1);
|
|
|
|
|
|
// int roleCount = DB.Roles.Where(r => r.Powers.Any(p => ids.Contains(p.ID))).Count();
|
|
// if (roleCount > 0)
|
|
// {
|
|
// Alert.ShowInTop("删除失败!需要先清空使用此权限的角色!");
|
|
// return;
|
|
// }
|
|
|
|
// // 执行数据库操作
|
|
// DB.Powers.Delete(p => ids.Contains(p.ID));
|
|
|
|
|
|
// // 重新绑定表格
|
|
// BindGrid();
|
|
//}
|
|
|
|
|
|
protected void Window1_Close(object sender, EventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
|
|
protected void ddlGridPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Grid1.PageSize = Convert.ToInt32(ddlGridPageSize.SelectedValue);
|
|
|
|
BindGrid();
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|