namespace FineUIPro.Web.common.SysManage { using System; using System.Data; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web.UI; using BLL; public partial class UserList : PageBase { /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BLL.Base_UnitService.InitUnitDropDownList(drpUnit, true, null,Resources.Lan.PleaseSelect); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); if (CurrUser.Account == Const.Gly) { btnMenuUnLock.Hidden = false; } else { btnMenuUnLock.Hidden = true; } // 绑定表格 BindGrid(); } } #region 绑定数据/查询 /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT Users.UserId,Users.Account, Users.UserCode, Users.UserName, Users.IsPost, Users.Email,Users.RoleIds as RoleName,Unit.UnitName, Unit.UnitCode, Users.Phone FROM dbo.Sys_User AS Users LEFT JOIN dbo.Base_Unit AS Unit ON Users.UnitId =Unit.UnitId where Users.UserId !=@Gly "; List parms = new List(); parms.Add(new SqlParameter("@Gly", Const.GlyId)); if (!string.IsNullOrEmpty(this.txtUserName.Text)) { strSql += " and Users.UserName LIKE @UserName"; parms.Add(new SqlParameter("@UserName", "%" + this.txtUserName.Text.Trim() + "%")); } if (this.drpUnit.SelectedValue != Const._Null) { strSql += " and Users.UnitId = @UnitId"; parms.Add(new SqlParameter("@UnitId", this.drpUnit.SelectedValue)); } SqlParameter[] parameter = parms.ToArray(); DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 Grid1.RecordCount = dt.Rows.Count; var table = this.GetPagedDataTable(Grid1, dt); Grid1.DataSource = table; Grid1.DataBind(); } /// /// 查询 /// /// /// protected void btnQuery_Click(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 增加按钮事件 /// /// 增加按钮事件 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (GetButtonPower(BLL.Const.BtnAdd)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UserListEdit.aspx", "新增 - "))); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #region 编辑/查看/删除数据 /// /// 编辑 /// private void EditData() { if (GetButtonPower(BLL.Const.BtnModify)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent("请至少选择一条记录!"); return; } string Id = Grid1.SelectedRowID; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UserListEdit.aspx?userId={0}", Id, "编辑 - "))); } else { ShowNotify("您没有这个权限,请与管理员联系!"); } } /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { EditData(); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 解锁 /// /// /// protected void btnMenuUnLock_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Grid1.SelectedRowID)) { string userId = Grid1.SelectedRowID; Sys_UserService.UpdateErrorNum(userId, 0); Sys_UserService.UpdateLockTime(userId, null); ShowNotify("该用户解锁成功!", MessageBoxIcon.Success); } else { ShowNotify("请选择要解锁的用户!"); } } protected void btnMenuView_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UserView.aspx?userId={0}", Grid1.SelectedRowID, "查看 - "))); } /// /// 批量删除数据 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (GetButtonPower(BLL.Const.BtnDelete)) { if (Grid1.SelectedRowIndexArray.Length > 0) { string strShowNotify = string.Empty; foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var user = BLL.Sys_UserService.GetUsersByUserId(rowID); string content = judgementDelete(rowID); if (user != null) { if (string.IsNullOrEmpty(content)) { BLL.Sys_UserService.DeleteUser(rowID); BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.UserMenuId, Const.BtnDelete, rowID); } else { strShowNotify += Resources.Lan.UserName + ":" + user.UserName + content; } } } BindGrid(); if (!string.IsNullOrEmpty(strShowNotify)) { Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning); } else { ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success); } } } else { Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); return; } } #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 Window1_Close(object sender, EventArgs e) { BindGrid(); } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private bool GetButtonPower(string button) { return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.UserMenuId, button); } #endregion #region 格式化字符串 /// /// 转换热处理类型 /// /// /// protected string ConvertRoleName(object roleIds) { string roleNames = string.Empty; if (roleIds != null) { string[] roles = roleIds.ToString().Split('|'); foreach (string r in roles) { var q = BLL.Sys_RoleService.GetRole(r); if (q != null) { roleNames = roleNames + q.RoleName + ","; } } } if (roleNames.Length > 0) { roleNames = roleNames.Substring(0, roleNames.Length - 1); } return roleNames; } #endregion #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private string judgementDelete(string userId) { string content = string.Empty; if (Funs.DB.Project_User.FirstOrDefault(x => x.UserId== userId) != null) { content = "该用户已在【项目用户】中使用,不能删除!"; } return content; } #endregion } }