SGGL_SHJ/SGGL/FineUIPro.Web/SysManage/UserList.aspx.cs

356 lines
13 KiB
C#
Raw Normal View History

2022-09-05 16:36:31 +08:00
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
{
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
}
/// <summary>
/// 绑定数据
/// </summary>
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
2022-12-12 14:44:11 +08:00
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 + "'";
2022-09-05 16:36:31 +08:00
List<SqlParameter> listStr = new List<SqlParameter>();
//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
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
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
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
/// <summary>
/// 删除方法
/// </summary>
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
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
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();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
BindGrid();
}
#endregion
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
/// <summary>
/// 编辑数据方法
/// </summary>
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
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
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
/// <summary>
/// 参与项目情况
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../ Person / PersonIn.aspx", "导入 - ")));
}
#endregion
/// <summary>
/// 关闭导入弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
/// <summary>
/// 获取人员在当前项目的角色
/// </summary>
/// <param name="UserId"></param>
/// <returns></returns>
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();
}
}
}