namespace FineUIPro.Web.SysManage { using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; public partial class UserList : PageBase { /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); UnitService.InitUnitDropDownList(this.drpUnit, string.Empty, false); Funs.FineUIPleaseSelect(drpUnit, "请选择单位"); DepartService.InitDepartDropDownList(this.drpDepart, false); Funs.FineUIPleaseSelect(this.drpDepart, "请选择部门"); ////权限按钮方法 this.GetButtonPower(); this.btnNew.OnClientClick = Window1.GetShowReference("../Person/PersonEdit.aspx") + "return false;"; // 绑定表格 this.BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT person.PersonId,person.Account,person.PersonName,person.JobNum,person.Password,Depart.DepartName,person.RoleIds ,person.CurrentProjectRoleId,person.Telephone,person.UnitId,person.IsPost,Unit.UnitName,Unit.UnitCode ,CASE WHEN person.IsPost=1 THEN '是' ELSE '否' END AS IsPostName,person.IdentityCard,person.Telephone From Person_Persons AS person LEFT JOIN Base_Unit AS Unit ON Unit.UnitId=person.UnitId LEFT JOIN Base_Depart AS Depart ON Depart.DepartId=person.DepartId WHERE RoleIds IS NOT NULL AND RoleIds != '' AND Account IS NOT NULL AND Account !='' AND person.PersonId !='" + Const.sysglyId + "' AND person.PersonId !='" + Const.hfnbdId + "' AND person.PersonId !='" + Const.sedinId + "'"; List listStr = new List(); //if (rbUnit.SelectedValue == "0") //{ // strSql += " AND person.UnitId = @ThisUnitId"; // listStr.Add(new SqlParameter("@ThisUnitId", Const.UnitId_SEDIN)); //} //if (rbUnit.SelectedValue == "1") //{ // strSql += " AND person.UnitId != @ThisUnitId"; // listStr.Add(new SqlParameter("@ThisUnitId", Const.UnitId_SEDIN)); //} if (!string.IsNullOrEmpty(this.txtPersonName.Text.Trim())) { strSql += " AND person.PersonName LIKE @PersonName"; listStr.Add(new SqlParameter("@PersonName", "%" + this.txtPersonName.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtAccount.Text.Trim())) { strSql += " AND person.Account LIKE @Account"; listStr.Add(new SqlParameter("@Account", "%" + this.txtAccount.Text.Trim() + "%")); } if (!BLL.CommonService.IsMainUnitOrAdmin(this.CurrUser.PersonId)) ///不是企业单位或者管理员 { strSql += " AND person.UnitId = @UnitId"; listStr.Add(new SqlParameter("@UnitId", this.CurrUser.UnitId)); } if (this.drpDepart.SelectedValue != BLL.Const._Null) { strSql += " AND person.DepartId = @DepartId"; listStr.Add(new SqlParameter("@DepartId", this.drpDepart.SelectedValue)); } if (this.drpUnit.SelectedValue != BLL.Const._Null) { strSql += " AND person.UnitId = @drpUnittId"; listStr.Add(new SqlParameter("@drpUnittId", this.drpUnit.SelectedValue)); } if (!string.IsNullOrEmpty(this.txtRoleName.Text.Trim())) { strSql += " AND Roles.RoleName LIKE @RoleName"; listStr.Add(new SqlParameter("@RoleName", "%" + this.txtRoleName.Text.Trim() + "%")); } //if (this.ckIsOutSideEmploy.Checked) //{ // strSql += " AND person.IsOutSideEmploy=1"; //} SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.UserMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnNew.Hidden = false; this.btnImport.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuEdit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDelete.Hidden = false; } } } #endregion #region 删除数据 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 删除方法 /// private void DeleteData() { 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.Person_PersonsService.GetPerson_PersonsById(rowID); if (user != null) { string cont = judgementDelete(rowID); if (string.IsNullOrEmpty(cont)) { BLL.LogService.AddSys_Log(this.CurrUser, user.JobNum, user.PersonId, BLL.Const.UserMenuId, BLL.Const.BtnDelete); BLL.Person_PersonsService.DeletePersonsById(rowID); } else { strShowNotify += "用户:" + user.PersonName + cont; } } } BindGrid(); if (!string.IsNullOrEmpty(strShowNotify)) { Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning); } else { ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } } #endregion #region 分页 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { 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) { BindGrid(); } #endregion /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string Id = Grid1.SelectedRowID; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../Person/PersonEdit.aspx?PersonId={0}", Id, "编辑 - "))); } #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private string judgementDelete(string id) { string content = string.Empty; if (Funs.DB.Person_QuarterCheck.FirstOrDefault(x => x.UserId == id) != null) { content += "已在【员工季度考核评价表】中使用,不能删除!"; } if (Funs.DB.SitePerson_Person.FirstOrDefault(x => x.PersonId == id) != null) { content += "已在【项目人员】中使用,不能删除!"; } if (Funs.DB.Law_LawRegulationList.FirstOrDefault(x => x.CompileMan == id) != null) { content += "已在【法律法规】中使用,不能删除!"; } if (Funs.DB.Law_HSSEStandardsList.FirstOrDefault(x => x.CompileMan == id) != null) { content += "已在【标准规范】中使用,不能删除!"; } if (Funs.DB.ProjectData_FlowOperate.FirstOrDefault(x => x.OperaterId == id) != null) { content += "已在【报表审核】中使用,不能删除!"; } return content; } #endregion /// /// 参与项目情况 /// /// /// protected void lbtnPro_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ParticipateProject.aspx?userId={0}", Grid1.SelectedRowID, "参与项目情况 - "), "参与项目", 1000, 520)); } protected string ConvertProject(object userId) { string projectName = string.Empty; if (userId != null) { var projectUsers = from x in Funs.DB.SitePerson_Person where x.PersonId == userId.ToString() select x; if (projectUsers.Count() == 1) { projectName = BLL.ProjectService.GetProjectByProjectId(projectUsers.FirstOrDefault().ProjectId).ProjectName; } else if (projectUsers.Count() > 1) { projectName = "查看"; } else { projectName = "无"; } } return projectName; } #region 导入 /// /// 导入按钮 /// /// /// protected void btnImport_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../ Person / PersonIn.aspx", "导入 - "))); } #endregion /// /// 关闭导入弹出窗口 /// /// /// protected void Window2_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } /// /// 获取人员在当前项目的角色 /// /// /// protected string ConvertProjectRoleName(object UserId) { string roleName = string.Empty; if (UserId != null) { var projectUser = BLL.SitePerson_PersonService.GetCurrProjectUserByUserId(UserId.ToString()); if (projectUser != null) { roleName = BLL.RoleService.getRoleNamesRoleIds(projectUser.RoleIds); } } return roleName; } protected void btSearch_Click(object sender, EventArgs e) { this.BindGrid(); } } }