using BLL;
using System;
using System.Data;
using System.Linq;
namespace FineUIPro.Web.SysManage
{
public partial class UserToEMial : PageBase
{
#region 加载
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetButtonPower();//权限设置
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
BindGrid();
}
}
///
/// 绑定数据
///
private void BindGrid()
{
string strSql = @"SELECT UserToEMial.UserToEmailId,
UserToEMial.UserId,
UserToEMial.IsLeader,
Roles.RoleName,
Users.UserName,
Users.Email,
Depart.DepartName "
+ @" FROM Sys_UserToEMial AS UserToEMial"
+ @" LEFT JOIN dbo.Sys_User AS Users ON Users.UserId = UserToEMial.UserId"
+ @" LEFT JOIN dbo.Sys_Role AS Roles ON Roles.RoleId = Users.RoleId"
+ @" LEFT JOIN dbo.Base_Depart AS Depart ON Depart.DepartId = Users.DepartId";
//SqlParameter[] parameter = new SqlParameter[]
// {
// new SqlParameter("@UserId",Const.GlyId)
//};
DataTable tb = SQLHelper.GetDataTableRunText(strSql, null);
// 2.获取当前分页数据
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region 分页、排序
///
/// 分页
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
///
/// 分页显示条数下拉框
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region 查找
///
/// 查找用户
///
///
///
protected void btnSelect_Click(object sender, EventArgs e)
{
string window = String.Format("SelectUserToEMail.aspx", "查找 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference() + Window1.GetShowReference(window));
}
#endregion
#region 删除数据
///
/// 批量删除数据
///
///
///
protected void btnDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
///
/// 右键删除事件
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
///
/// 删除方法
///
private void DeleteData()
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var userToEMial = BLL.Sys_UserToEMialService.GetUserToEmialById(rowID);
if (userToEMial != null)
{
if (judgementDelete(rowID, false))
{
BLL.Sys_UserToEMialService.DeleteUserToEMail(rowID);
}
}
}
BindGrid();
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete Set up evaluation users information");
ShowNotify("Deleted successfully!");
}
}
///
/// 判断是否可以删除
///
///
private bool judgementDelete(string id, bool isShow)
{
string content = string.Empty;
//if (Funs.DB.Sys_User.FirstOrDefault(x => x.RoleId == id) != null)
//{
// content = "This role is already in use in [user information] and cannot be deleted!";
//}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content);
}
return false;
}
}
#endregion
#region 关闭弹出窗口
///
/// 关闭窗口
///
///
///
protected void Window1_Close(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region 权限设置
///
/// 菜单按钮权限
///
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.UserToEMialMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSelect.Hidden = false;
}
}
}
#endregion
}
}