ab56a9bcf7
SVN-Revision: r240
536 lines
20 KiB
C#
536 lines
20 KiB
C#
using DevExpress.XtraEditors.Repository;
|
|
using DevExpress.XtraGrid.Columns;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Control;
|
|
using Lskj.Core;
|
|
using Lskj.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Lskj.PubUserTomodule
|
|
{
|
|
public partial class PersonnelInformation : UserControl
|
|
{
|
|
//是否初始化完成
|
|
public bool _isInitFinish = false;
|
|
//角色选中id
|
|
public string id = string.Empty;
|
|
/// <summary>
|
|
/// 全部的模块菜单
|
|
/// </summary>
|
|
public DataTable AllMenu = new DataTable();
|
|
/// <summary>
|
|
/// 顶部表格控件
|
|
/// </summary>
|
|
public GridControlEx roleControlEx { get { return this.RoleControlEx; } }
|
|
/// <summary>
|
|
/// 点击删除事件,刷新主页面的权限
|
|
/// </summary>
|
|
public event EventHandler onClickDeleteButton;
|
|
|
|
public PersonnelInformation()
|
|
{
|
|
InitializeComponent();
|
|
InitControls();
|
|
//personnelControlEx.GridView.FocusedRowObjectChanged += GridView_FocusedRowObjectChanged;//人员的点击加载全部信息
|
|
personnelControlEx.GridView.RowClick += GridView_FocusedRowObjectChanged;//人员的点击加载全部信息
|
|
splitMain.SplitterMoved += new System.EventHandler(this.OnTopSplitterMoved);
|
|
|
|
RoleControlEx.GridView.RowClick += GridView_RowClick;//角色点击加载对应模块权限
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 生成页面
|
|
/// </summary>
|
|
public void InitControls()
|
|
{
|
|
//获取全部模块菜单
|
|
AllMenu = PowerImpl.GetAllModulesDataSpecial();
|
|
|
|
|
|
|
|
//不可编辑
|
|
this.MenuControlEx.GridView.OptionsBehavior.Editable = false;
|
|
this.RoleControlEx.GridView.OptionsBehavior.Editable = false;
|
|
this.personnelControlEx.GridView.OptionsBehavior.Editable = false;
|
|
|
|
//this.AllModules.GridView.OptionsView.ColumnAutoWidth = true;
|
|
DataTable employeetable = PowerImpl.GetWorkEmployee();
|
|
this.personnelControlEx.GridControl.DataSource = employeetable;
|
|
|
|
GridColumn treeListColumnName = new GridColumn();
|
|
treeListColumnName.Caption = "主模块";
|
|
treeListColumnName.FieldName = "主模块";
|
|
treeListColumnName.MinWidth = 38;
|
|
treeListColumnName.Visible = true;
|
|
treeListColumnName.VisibleIndex = 0;
|
|
treeListColumnName.Width = 150;
|
|
|
|
GridColumn treeListColumnMenuId = new GridColumn();
|
|
treeListColumnMenuId.Caption = "菜单名字";
|
|
treeListColumnMenuId.FieldName = "菜单名字";
|
|
treeListColumnMenuId.Visible = true;
|
|
treeListColumnMenuId.VisibleIndex = 1;
|
|
treeListColumnMenuId.Width = 220;
|
|
|
|
|
|
RepositoryItemCheckEdit checkEdit = new RepositoryItemCheckEdit();
|
|
checkEdit.ValueChecked = "1";
|
|
checkEdit.ValueUnchecked = "0";
|
|
checkEdit.ValueGrayed = 3;
|
|
checkEdit.CheckedChanged += CheckEdit_CheckedChanged;
|
|
|
|
GridColumn treeListColumnReadflag = new GridColumn();
|
|
treeListColumnReadflag.ColumnEdit = checkEdit;
|
|
treeListColumnReadflag.Caption = "只读权限";
|
|
treeListColumnReadflag.FieldName = "Readflag";
|
|
treeListColumnReadflag.Name = "treeListColumnReadflagValue";
|
|
treeListColumnReadflag.Visible = true;
|
|
treeListColumnReadflag.VisibleIndex = 3;
|
|
|
|
GridColumn treeListColumnEditflag = new GridColumn();
|
|
treeListColumnEditflag.ColumnEdit = checkEdit;
|
|
treeListColumnEditflag.Caption = "操作权限";
|
|
treeListColumnEditflag.FieldName = "Editflag";
|
|
treeListColumnEditflag.Name = "treeListColumnEditflagValue";
|
|
treeListColumnEditflag.Visible = true;
|
|
treeListColumnEditflag.VisibleIndex = 2;
|
|
|
|
|
|
this.MenuControlEx.GridView.Columns.AddRange(new GridColumn[] {
|
|
treeListColumnMenuId,
|
|
treeListColumnName,
|
|
treeListColumnReadflag,
|
|
treeListColumnEditflag
|
|
});
|
|
|
|
GridColumn RoleIdColumn = new GridColumn();
|
|
RoleIdColumn.Caption = "编号";
|
|
RoleIdColumn.FieldName = "id";
|
|
RoleIdColumn.VisibleIndex = 1;
|
|
|
|
GridColumn RoleRolenameColumn = new GridColumn();
|
|
RoleRolenameColumn.Caption = "角色";
|
|
RoleRolenameColumn.FieldName = "roleName";
|
|
RoleRolenameColumn.VisibleIndex = 2;
|
|
RoleRolenameColumn.Width = 220;
|
|
|
|
this.RoleControlEx.GridView.Columns.AddRange(new GridColumn[] {
|
|
RoleIdColumn,
|
|
RoleRolenameColumn,
|
|
});
|
|
}
|
|
|
|
|
|
private void CheckEdit_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
DataRow mSelectRow = this.MenuControlEx.GridView.GetFocusedDataRow();
|
|
|
|
if (mSelectRow["Readflag"] + "" == "1") mSelectRow["Readflag"] = "0";
|
|
if (mSelectRow["Editflag"] + "" == "1") mSelectRow["Editflag"] = "0";
|
|
MenuControlEx.gridControl.RefreshDataSource();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 人员单击事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
public void GridView_FocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)//(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.btn_unfold.Enabled = this.btn_Delete.Enabled = false;
|
|
id = string.Empty;
|
|
DataRow dr = this.personnelControlEx.GridView.GetFocusedDataRow();
|
|
if (dr != null)
|
|
{
|
|
string UserId = dr["员工ID"] + "";
|
|
if (string.IsNullOrWhiteSpace(UserId))
|
|
{
|
|
MessageUtil.Show("员工ID获取错误,查询失败");
|
|
}
|
|
string msg = string.Empty;
|
|
//角色
|
|
DataTable RoleTable = GetPeopleData("0", UserId, out msg);
|
|
this.RoleControlEx.gridControl.DataSource = RoleTable;
|
|
//菜单
|
|
//DataTable MenuTable = GetPeopleData("1", UserId, out msg);
|
|
//this.MenuControlEx.gridControl.DataSource = MenuTable;
|
|
string tipMsg = string.Empty;
|
|
DataSet ds = BaseImpl.getAuthorityByEmpid(1, UserId, "", "", out tipMsg);
|
|
string editPurview = ds.Tables.Count > 0 ? ds.Tables[0].Rows[0]["pid"] + "" : string.Empty;
|
|
string[] EditPurview = editPurview.Trim().TrimEnd(',').Split(',');
|
|
|
|
DataSet ds2 = BaseImpl.getAuthorityByEmpid(2, UserId, "", "", out tipMsg);
|
|
string readPurview = ds2.Tables.Count > 0 ? ds2.Tables[0].Rows[0]["pid"] + "" : string.Empty;
|
|
string[] ReadPurview = readPurview.Trim().TrimEnd(',').Split(',');
|
|
|
|
GetNodeCheckedID(ReadPurview, EditPurview);
|
|
|
|
|
|
}
|
|
else {
|
|
this.RoleControlEx.gridControl.DataSource = null;
|
|
this.MenuControlEx.gridControl.DataSource = null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 角色表单击事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void GridView_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
|
|
{
|
|
DataRow mSelectRow = this.RoleControlEx.GridView.GetFocusedDataRow();
|
|
if (mSelectRow != null)
|
|
{
|
|
this.btn_unfold.Enabled = this.btn_Delete.Enabled = true;
|
|
id = mSelectRow["id"] + "";
|
|
DataRow DR = PowerImpl.GetRoleRow(id);
|
|
if (DR == null) return;
|
|
string[] ReadPurview = DR["ReadPurview"].ToString().Trim().TrimEnd(',').Split(',');
|
|
string[] EditPurview = DR["EditPurview"].ToString().Trim().TrimEnd(',').Split(',');
|
|
GetNodeCheckedID(ReadPurview, EditPurview);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取选择状态有权限的节点集合
|
|
/// </summary>
|
|
/// <param name="parentNode">父级节点</param>
|
|
private void GetNodeCheckedID(string[] ReadPurview, string[] EditPurview)
|
|
{
|
|
List<DataRow> rows = new List<DataRow>();
|
|
foreach (DataRow item in AllMenu.Rows)
|
|
{
|
|
if (EditPurview.Contains(item["MenuId"] + "") || ReadPurview.Contains(item["MenuId"] + ""))
|
|
{
|
|
if (ReadPurview.Contains(item["MenuId"] + ""))
|
|
{
|
|
item["Readflag"] = "1";
|
|
}
|
|
if (EditPurview.Contains(item["MenuId"] + ""))
|
|
{
|
|
item["editflag"] = "1";
|
|
}
|
|
if (!EditPurview.Contains(item["MenuId"] + ""))
|
|
{
|
|
item["editflag"] = "0";
|
|
}
|
|
if (!ReadPurview.Contains(item["MenuId"] + ""))
|
|
{
|
|
item["Readflag"] = "0";
|
|
}
|
|
rows.Add(item);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if (rows.Count > 0)
|
|
{
|
|
this.MenuControlEx.gridControl.DataSource = rows.CopyToDataTable();
|
|
}
|
|
else
|
|
{
|
|
this.MenuControlEx.gridControl.DataSource = AllMenu.Clone();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 根据人员id获取对应角色和菜单
|
|
/// </summary>
|
|
/// <param name="typetig">查询类型 0角色 1菜单</param>
|
|
/// <param name="UserId">员工编号</param>
|
|
/// <param name="tipMsg"></param>
|
|
/// <returns></returns>
|
|
public static DataTable GetPeopleData(string typetig, string UserId, out string tipMsg)
|
|
{
|
|
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
|
|
pMsg.Direction = ParameterDirection.InputOutput;
|
|
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
|
|
returnValue.Direction = ParameterDirection.ReturnValue;
|
|
|
|
SqlParameter[] p =
|
|
{
|
|
new SqlParameter("@typetig",SqlDbType.Int),
|
|
new SqlParameter("@employeeid",SqlDbType.Int),
|
|
pMsg,
|
|
returnValue,
|
|
};
|
|
p[0].Value = typetig;
|
|
p[1].Value = UserId;
|
|
p[2].Value = "";
|
|
|
|
DataTable dataTable= SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_SystemSetUserPurview_print", "temp", p).Tables[0];
|
|
|
|
tipMsg = pMsg.Value.ToString();
|
|
int result = Convert.ToInt32(returnValue.Value + "");
|
|
if (result == -1)
|
|
{
|
|
MessageUtil.Show("查询失败,原因:" + tipMsg);
|
|
return new DataTable();
|
|
}
|
|
|
|
return dataTable;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:初始化分割条位置</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-01-24</para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public void InitializeSplitterPosition()
|
|
{
|
|
try
|
|
{
|
|
string splitterPosition = IniHelper.Read("PersonnelInformation");
|
|
if (!string.IsNullOrEmpty(splitterPosition))
|
|
{
|
|
this.splitMain.SplitterPosition = Convert.ToInt32(splitterPosition);
|
|
}
|
|
else
|
|
{
|
|
this.splitMain.SplitterPosition = this.Height * 2;
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
}
|
|
finally {
|
|
_isInitFinish = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:分割条移动保存位置</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-06 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void OnTopSplitterMoved(object sender, EventArgs e)
|
|
{
|
|
if (this._isInitFinish)// 是否为初始化创建
|
|
{
|
|
IniHelper.Write("PersonnelInformation", this.splitMain.SplitterPosition + "");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 点击删除,删除选中人员的指定角色
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btn_Delete_Click(object sender, EventArgs e)
|
|
{
|
|
//人员
|
|
DataRow dr = this.personnelControlEx.GridView.GetFocusedDataRow();
|
|
if (dr != null && !string.IsNullOrWhiteSpace(id))
|
|
{
|
|
PowerImpl.deletRoleDate(dr["员工ID"] + "", id);
|
|
savedata(int.Parse(dr["员工ID"] + ""));
|
|
GridView_FocusedRowObjectChanged(null, null);
|
|
if (onClickDeleteButton != null) onClickDeleteButton(null, null);
|
|
}
|
|
else {
|
|
MessageUtil.Show("请选择需要删除的角色");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 执行保存时候的存储过程
|
|
/// </summary>
|
|
/// <param name="modid"></param>
|
|
/// <param name="tagid"></param>
|
|
/// <param name="mid"></param>
|
|
/// <returns></returns>
|
|
public int savedata(int operatorid)
|
|
{
|
|
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
|
|
pMsg.Direction = ParameterDirection.Output;
|
|
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
|
|
returnValue.Direction = ParameterDirection.ReturnValue;
|
|
SqlParameter[] param =
|
|
{
|
|
new SqlParameter("@operatorid",SqlDbType.VarChar,20),
|
|
pMsg,
|
|
returnValue
|
|
};
|
|
param[0].Value = operatorid;
|
|
BaseImpl.ExecProcedure("[p_SystemSetUserPurview]", param);
|
|
return Convert.ToInt32(returnValue.Value.ToString());
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加选中人员的角色权限
|
|
/// </summary>
|
|
public void AddRolePermissions(string RoleId)
|
|
{
|
|
DataRow dr = this.personnelControlEx.GridView.GetFocusedDataRow();
|
|
if (dr != null && !string.IsNullOrWhiteSpace(RoleId))
|
|
{
|
|
PowerImpl.DropDate(int.Parse(dr["员工ID"] + ""), dr["员工工号"] + "", dr["员工姓名"] + "", dr.Table.Columns.Contains("所属部门") ? dr["所属部门"] + "" : "", RoleId);
|
|
int rValue = saveRoledata(int.Parse(RoleId));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 设置选中角色权限
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btn_unfold_Click(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(id))
|
|
{
|
|
DataRow DR = PowerImpl.GetRoleRow(id);
|
|
string ReadPurview = DR["ReadPurview"].ToString();
|
|
string EditPurview = DR["EditPurview"].ToString();
|
|
FrmPermissionSetting form = new FrmPermissionSetting(EditPurview, ReadPurview);
|
|
form.onClickTheOKButton += new FrmPermissionSetting.ClickTheOKButton(UpdatePermissionModule);
|
|
DialogResult result = form.ShowDialog();
|
|
}
|
|
else {
|
|
MessageUtil.Show("请选择角色");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 模块权限设置框点击确定时,返回更新后的权限。
|
|
/// </summary>
|
|
/// <param name="EditPurview"></param>
|
|
/// <param name="ReadPurview"></param>
|
|
private void UpdatePermissionModule(List<string> EditPurview, List<string> ReadPurview)
|
|
{
|
|
GetNodeCheckedID(ReadPurview.ToArray(), EditPurview.ToArray());
|
|
|
|
string Readdate = string.Empty;
|
|
string Editdate = string.Empty;
|
|
|
|
//获取菜单表
|
|
DataTable masterdt = MenuControlEx.gridControl.DataSource as DataTable;
|
|
//菜单表中所有的模块按权限分类
|
|
for (int i = 0; i < masterdt.Rows.Count; i++)
|
|
{
|
|
if (masterdt.Rows[i]["ID"].ToString().Length > 4 && masterdt.Rows[i]["Editflag"] + "" == "1")
|
|
{
|
|
|
|
Editdate = Editdate + masterdt.Rows[i]["MenuId"] + ",";
|
|
|
|
}
|
|
else if (masterdt.Rows[i]["ID"].ToString().Length > 4 && masterdt.Rows[i]["Readflag"] + "" == "1")
|
|
{
|
|
Readdate = Readdate + masterdt.Rows[i]["MenuId"] + ",";
|
|
}
|
|
}
|
|
|
|
|
|
if (PowerImpl.SaveRoleDate(id, Readdate, Editdate))
|
|
{
|
|
|
|
int rValue = saveRoledata(int.Parse(id));
|
|
if (rValue == 0)
|
|
{
|
|
MessageUtil.Show("同步人员权限成功!");
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("同步人员权限失败!");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 执行保存角色权限时候的存储过程
|
|
/// </summary>
|
|
/// <param name="modid"></param>
|
|
/// <param name="tagid"></param>
|
|
/// <param name="mid"></param>
|
|
/// <returns></returns>
|
|
public int saveRoledata(int roleid)
|
|
{
|
|
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
|
|
pMsg.Direction = ParameterDirection.Output;
|
|
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
|
|
returnValue.Direction = ParameterDirection.ReturnValue;
|
|
SqlParameter[] param =
|
|
{
|
|
new SqlParameter("@roleid ",SqlDbType.VarChar,20),
|
|
pMsg,
|
|
returnValue
|
|
};
|
|
param[0].Value = roleid;
|
|
BaseImpl.ExecProcedure("p_SystemSetRoleUserPurview", param);
|
|
return Convert.ToInt32(returnValue.Value.ToString());
|
|
}
|
|
|
|
|
|
//复制当前人员权限
|
|
private void CopyPermissions_Click(object sender, EventArgs e)
|
|
{
|
|
DataRow dr = this.personnelControlEx.GridView.GetFocusedDataRow();
|
|
if (dr != null)
|
|
{
|
|
FrmCopyStaffPermission frm = new FrmCopyStaffPermission(dr["员工ID"] + "");
|
|
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
GridView_FocusedRowObjectChanged(null, null);
|
|
if (onClickDeleteButton != null) onClickDeleteButton(null, null);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|