/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_0206.cs
* 2.功能描述:用户功能权限设置
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2015/11/04 1.00 新建
*******************************************************************************/
using System;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.Library;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Client.Controls;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
public partial class F_MST_0206 : FormBase
{
#region 成员变量
// 传过来的用户ID
private int _userID;
//页面的数据源
DataSet _userFunctionRightData;
//页面的数据源
DataSet _userFunctionRightData2;
// 系统功能ID
private string _functionCode = string.Empty;
// 系统功能ID
private string _functionCode2 = string.Empty;
// 是否需要触发After Check事件(性能改善)
private bool _needActionCheck = false;
// 是否需要触发After Check事件(性能改善)
private bool _needActionCheck2 = false;
// 用户授权方式 1:按站点 2:按用户
private int _licenseType;
// 保存时,用于返回超过授权站点数的明细
private string _overLicenseNumberFunctions;
// 是否不限制功能权限
private bool isFunctionCodeAll = false;
// 数据表的数据源
private DataTable _dtDataGird = null;
// 数据表的数据源
private DataTable _dtDataGird2 = null;
private string _userCodeValue;
private string _userCodeValue2;
private bool _ShowFlag = true;
private bool _ShowFlag2 = true;
#endregion
#region 构造函数
///
/// 构造函数
///
///
public F_MST_0206()
{
InitializeComponent();
// 设置标题
this.Text = FormTitles.F_MST_0203;
// 工具栏按钮文本赋值
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
this.dgvFunctionUsers.AutoGenerateColumns = false;
//this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
this.dgvFunctionUsers2.AutoGenerateColumns = false;
this.dgvFunctionUsers2.Columns["UserName1"].ReadOnly = true;
this.dgvFunctionUsers2.Columns["OrganizationName1"].ReadOnly = true;
// 隐藏二期功能
this.tabControl1.TabPages.Remove(this.tabPage2);
}
///
/// 构造函数
///
///
/// 用户编码
public F_MST_0206(int userID, string userCode)
{
InitializeComponent();
this._userID = userID;
// 设置标题
this.Text = FormTitles.F_MST_0203;
// 工具栏按钮文本赋值
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
this.dgvFunctionUsers.AutoGenerateColumns = false;
this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
this.dgvFunctionUsers2.AutoGenerateColumns = false;
this.dgvFunctionUsers2.Columns["UserName1"].ReadOnly = true;
this.dgvFunctionUsers2.Columns["OrganizationName1"].ReadOnly = true;
// 隐藏二期功能
this.tabControl1.TabPages.Remove(this.tabPage2);
}
#endregion
#region 事件
///
/// 页面加载事件
///
///
///
private void F_MST_0203_Load(object sender, EventArgs e)
{
try
{
// 保存按钮不可用
//this.btnSave.Enabled = false;
// 取得用户权限并赋值
this._needActionCheck = false;
this.SetControlsDataSource();
this._needActionCheck = true;
// 二期
// 取得用户权限并赋值
this._needActionCheck2 = false;
this.SetControlsDataSource2();
this._needActionCheck2 = true;
//加载用户列表
DataSet functionUsers = (DataSet)DoAsync(new BaseAsyncMethod(GetFunctionUsers));
//this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
//this.btnCancel.Enabled = true;
if (functionUsers != null)
{
this.dgvFunctionUsers.AutoGenerateColumns = false;
this.dgvFunctionUsers.DataSource = functionUsers.Tables[0];
//this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
this._dtDataGird = functionUsers.Tables[0];
//
DataView dv = functionUsers.Tables[0].DefaultView;
dv.RowFilter = "FunctionCode='-100'";
this.dgvFunctionUsers.DataSource = dv.ToTable();
}
//加载用户列表
DataSet functionUsers2 = (DataSet)DoAsync(new BaseAsyncMethod(GetFunctionUsers2));
//this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
//this.btnCancel.Enabled = true;
if (functionUsers2 != null)
{
this.dgvFunctionUsers2.AutoGenerateColumns = false;
this.dgvFunctionUsers2.DataSource = functionUsers2.Tables[0];
//this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
this.dgvFunctionUsers2.Columns["UserName1"].ReadOnly = true;
this.dgvFunctionUsers2.Columns["OrganizationName1"].ReadOnly = true;
this._dtDataGird2 = functionUsers2.Tables[0];
//
DataView dv = functionUsers2.Tables[0].DefaultView;
dv.RowFilter = "FunctionCode='-100'";
this.dgvFunctionUsers2.DataSource = dv.ToTable();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 功能权限选择之后,需要检查是否选择了子节点和父节点
///
///
///
private void tvwFunction_AfterCheck(object sender, TreeViewEventArgs e)
{
try
{
//if (this._needActionCheck)
//{
// this.CheckControl(e);
// // 将后台数据源的选择状态改变
// int functionID = Convert.ToInt32(e.Node.Tag);
// foreach (DataRow dataRow in _userFunctionRightData.Tables[0].Rows)
// {
// if (functionID == Convert.ToInt32(dataRow["FunctionCode"]))
// {
// dataRow["Choose"] = e.Node.Checked;
// break;
// }
// }
// // 保存按钮状态改变
// this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
//}
}
catch (Exception ex)
{
this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 功能权限树形选择之后显示该功能权限所有的使用用户
///
///
///
private void tvwFunction_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
//if (e.Node.Name == Constant.INT_IS_ONE.ToString())
//{
// this._functionCode = e.Node.Tag.ToString();
// this.btnSave.Enabled = false;
// this.btnCancel.Enabled = false;
// DataSet functionUsers = (DataSet)DoAsync(new BaseAsyncMethod(GetFunctionUsers));
// this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
// this.btnCancel.Enabled = true;
// if (functionUsers != null)
// {
// this.dgvFunctionUsers.AutoGenerateColumns = false;
// this.dgvFunctionUsers.DataSource = functionUsers.Tables[0];
// this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
// this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
// this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
// }
//}
if (e.Node.Name == Constant.INT_IS_ONE.ToString() || e.Node.Name == Constant.INT_IS_ZERO.ToString())
{
this._functionCode = e.Node.Tag.ToString();
lblShow.Text = "当前选择的功能权限:" + e.Node.Text;
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "FunctionCode='" + this._functionCode + "'";
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
//this.btnSave.Enabled = false;
//this.btnCancel.Enabled = false;
//DataSet functionUsers = (DataSet)DoAsync(new BaseAsyncMethod(GetFunctionUsers));
//this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
//this.btnCancel.Enabled = true;
//if (functionUsers != null)
//{
// this.dgvFunctionUsers.AutoGenerateColumns = false;
// this.dgvFunctionUsers.DataSource = functionUsers.Tables[0];
// this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
// this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
// this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
//}
}
}
catch (Exception ex)
{
//this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 页面关闭时,需要确认是否关闭窗体
///
///
///
private void F_MST_0203_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
// 判断数据是否被修改过,修改过需要提示保存消息
if (DataJudge.IsChange(this._userFunctionRightData))
{
DialogResult result = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
// 保存数据
btnSave_Click(sender, e);
}
else if (result == DialogResult.Cancel)
{
e.Cancel = true;
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 功能树全部展开
///
///
///
private void btnFunctionExpandAll_Click(object sender, EventArgs e)
{
this.tvwFunction.ExpandAll();
}
///
/// 功能树全部关闭
///
///
///
private void btnFunctionCollapseAll_Click(object sender, EventArgs e)
{
this.tvwFunction.CollapseAll();
}
///
/// 关闭按钮按下事件
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 保存用户的功能权限
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
FunRightResultEntity returnAffectRows = (FunRightResultEntity)DoAsync(new BaseAsyncMethod(SaveUserFunctionRight));
this._overLicenseNumberFunctions = returnAffectRows.LicenseFunctions;
// 将DataGridView单元格的可写状态设置成不可写的
//this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
// 保存设置好的 系统功能 隐藏价格
if (returnAffectRows.OperationStatus > Constant.INT_IS_ZERO)
{
this._userFunctionRightData.AcceptChanges();
// 提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "功能权限", "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else if (returnAffectRows.OperationStatus == Constant.INT_IS_ZERO)
{
// 提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "功能权限", "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
// 提示信息
string functionOver = "";
if (_overLicenseNumberFunctions.Length > 100)
{
functionOver = _overLicenseNumberFunctions.Substring(0, 99) + "......";
}
else
{
functionOver = _overLicenseNumberFunctions;
}
MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
"以下的功能超出了授权功能数:\r\n" + functionOver),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 为功能权限树形赋值
///
private void SetControlsDataSource()
{
try
{
// 根据用户ID取得用户的权限信息
DataSet userRightData = SystemModuleProxy.Service.GetFunctionRight();
if (userRightData == null || userRightData.Tables.Count < Constant.INT_IS_ONE)
{
return;
}
this._userFunctionRightData = new DataSet();
DataTable functionTable = userRightData.Tables[0].Copy();
//if (functionTable.Rows.Count>0)
//{
// DataRow[] drAll = functionTable.Select("FunctionCode='[ALL]'");
// if(drAll.Length>0)
// {
// this.isFunctionCodeAll = true;//加载时是选中的,为了是判断保存按钮是否可用
// this.chkFunctionCodeAll.Checked = true;
// }
//}
// 取得license文件中的功能权限
//DataTable licenseFunction = new DataTable();
//if (LogInUserInfo.CurrentUser.CurrentLicenseInfo == null || LogInUserInfo.CurrentUser.CurrentLicenseInfo.Tables.Count < 2)
//{
// return;
//}
//licenseFunction = LogInUserInfo.CurrentUser.CurrentLicenseInfo.Tables[1].Copy();
//_licenseType = Convert.ToInt32(LogInUserInfo.CurrentUser.CurrentLicenseInfo.Tables[0].Rows[0]["LicenseTypeID"]);
//// 剔除没有授权的功能
//for (int i = 0; i < functionTable.Rows.Count; i++)
//{
// DataRow[] filter = licenseFunction.Select("FunctionCode = '" + functionTable.Rows[i]["FunctionCode"] + "'");
// if (filter.Length < 1)
// {
// functionTable.Rows[i].Delete();
// }
// else
// {
// functionTable.Rows[i]["LicensesNumber"] = filter[0]["FunctionNumber"].ToString();
// }
//}
functionTable.AcceptChanges();
this._userFunctionRightData.Tables.Add(functionTable);
InitFunctionTreeView(this._userFunctionRightData.Tables[0]);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 为功能权限树形赋值
///
private void SetControlsDataSource2()
{
try
{
// 根据用户ID取得用户的权限信息
DataSet userRightData = SystemModuleProxy.Service.GetFunctionRight();
if (userRightData == null || userRightData.Tables.Count < Constant.INT_IS_ONE)
{
return;
}
this._userFunctionRightData2 = new DataSet();
DataTable functionTable = userRightData.Tables[1].Copy();
functionTable.AcceptChanges();
this._userFunctionRightData2.Tables.Add(functionTable);
InitFunctionTreeView2(this._userFunctionRightData2.Tables[0]);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据取得的数据生成权限树
///
///
private void InitFunctionTreeView(DataTable treeTable)
{
try
{
// 初期显示时,滚动条没有显示全部的tree节点。 by chenxy 2014-05-25
this.tvwFunction.Scrollable = false;
TreeNode node = null;
//DataRow[] warehouseRows = treeTable.Select("LEN(FunctionCode) = 2");
DataRow[] warehouseRows = treeTable.Select("LEN(FUNCTIONLEVEL) = 2");
// 递归生成功能权限树
this.InitTreeView(treeTable, warehouseRows, node);
// 初期显示时,滚动条没有显示全部的tree节点。 by chenxy 2014-05-25
this.tvwFunction.Scrollable = true;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据取得的数据生成权限树
///
///
private void InitFunctionTreeView2(DataTable treeTable)
{
try
{
// 初期显示时,滚动条没有显示全部的tree节点。
this.tvwFunction2.Scrollable = false;
TreeNode node = null;
//DataRow[] warehouseRows = treeTable.Select("LEN(FunctionCode) = 2");
DataRow[] warehouseRows = treeTable.Select("LEN(FUNCTIONLEVEL) = 3");
// 递归生成功能权限树
this.InitTreeView2(treeTable, warehouseRows, node);
// 初期显示时,滚动条没有显示全部的tree节点。
this.tvwFunction2.Scrollable = true;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 递归创建树
///
///
///
///
private void InitTreeView(DataTable treeTable, DataRow[] rows, TreeNode node)
{
try
{
foreach (DataRow row in rows)
{
TreeNode sNode;
if (node == null)
{
sNode = new TreeNode();
if (row["FunctionFlag"].ToString() == Constant.INT_IS_ONE.ToString())
{
sNode.Text = "[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString();
// + " ( " + row["UseLincenseNumber"].ToString() + " / " + row["LicensesNumber"].ToString() + " )";
}
else
{
sNode.Text = "[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString();
}
sNode.Name = row["FunctionFlag"].ToString();
sNode.Tag = row["FunctionCode"].ToString();
if (row["Choose"].ToString() == Constant.INT_IS_ONE.ToString())
{
sNode.Checked = true;
}
this.tvwFunction.Nodes.Add(sNode);
}
else
{
if (row["FunctionFlag"].ToString() == Constant.INT_IS_ONE.ToString())
{
sNode = node.Nodes.Add("[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString());
//+ " ( " + row["UseLincenseNumber"].ToString() + " / " + row["LicensesNumber"].ToString() + " )");
}
else
{
sNode = node.Nodes.Add("[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString());
}
sNode.Name = row["FunctionFlag"].ToString();
sNode.Tag = row["FunctionCode"].ToString();
if (row["Choose"].ToString() == Constant.INT_IS_ONE.ToString())
{
sNode.Checked = true;
}
}
//string filterExpression = "FunctionCode LIKE '" + row["FunctionCode"].ToString()
// + "%' AND LEN(FunctionCode) = " + (row["FunctionCode"].ToString().Length + 2);
string filterExpression = "FUNCTIONLEVEL LIKE '" + row["FUNCTIONLEVEL"].ToString()
+ "%' AND LEN(FUNCTIONLEVEL) = " + (row["FUNCTIONLEVEL"].ToString().Length + 2);
DataRow[] subRows = treeTable.Select(filterExpression);
// 递归方法
InitTreeView(treeTable, subRows, sNode);
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 递归创建树
///
///
///
///
private void InitTreeView2(DataTable treeTable, DataRow[] rows, TreeNode node)
{
try
{
foreach (DataRow row in rows)
{
TreeNode sNode;
if (node == null)
{
sNode = new TreeNode();
if (row["FunctionFlag"].ToString() == Constant.INT_IS_ONE.ToString())
{
sNode.Text = "[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString()
+ " ( " + row["UseLincenseNumber"].ToString() + " / " + row["LicensesNumber"].ToString() + " )";
}
else
{
sNode.Text = "[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString();
}
sNode.Name = row["FunctionFlag"].ToString();
sNode.Tag = row["FunctionCode"].ToString();
if (row["Choose"].ToString() == Constant.INT_IS_ONE.ToString())
{
sNode.Checked = true;
}
this.tvwFunction2.Nodes.Add(sNode);
}
else
{
if (row["FunctionFlag"].ToString() == Constant.INT_IS_ONE.ToString())
{
sNode = node.Nodes.Add("[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString()
+ " ( " + row["UseLincenseNumber"].ToString() + " / " + row["LicensesNumber"].ToString() + " )");
}
else
{
sNode = node.Nodes.Add("[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString());
}
sNode.Name = row["FunctionFlag"].ToString();
sNode.Tag = row["FunctionCode"].ToString();
if (row["Choose"].ToString() == Constant.INT_IS_ONE.ToString())
{
sNode.Checked = true;
}
}
string filterExpression = "FUNCTIONLEVEL LIKE '" + row["FUNCTIONLEVEL"].ToString()
+ "%' AND LEN(FUNCTIONLEVEL) = " + (row["FUNCTIONLEVEL"].ToString().Length + 3);
DataRow[] subRows = treeTable.Select(filterExpression);
// 递归方法
InitTreeView2(treeTable, subRows, sNode);
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 递归选中节点或者取消选中节点
///
///
///
private void CheckSubNodes(TreeNode treeNode, bool nodeChecked)
{
foreach (TreeNode node in treeNode.Nodes)
{
node.Checked = nodeChecked;
if (node.Nodes.Count > Constant.INT_IS_ZERO)
{
this.CheckSubNodes(node, nodeChecked);
}
}
}
///
/// 节点 Checked 属性控制
///
///
private void CheckControl(TreeViewEventArgs e)
{
if (e.Action != TreeViewAction.Unknown)
{
if (e.Node != null && !Convert.IsDBNull(e.Node))
{
CheckParentNode(e.Node);
if (e.Node.Nodes.Count > Constant.INT_IS_ZERO)
{
CheckAllChildNodes(e.Node, e.Node.Checked);
}
}
}
}
///
/// 改变父节点的选中状态,此处为所有子节点不选中时才取消父节点选中,可以根据需要修改
///
///
private static void CheckParentNode(TreeNode curNode)
{
bool bChecked = false;
if (curNode.Parent != null)
{
foreach (TreeNode node in curNode.Parent.Nodes)
{
if (node.Checked)
{
bChecked = true;
break;
}
}
if (bChecked)
{
curNode.Parent.Checked = true;
CheckParentNode(curNode.Parent);
}
else
{
curNode.Parent.Checked = false;
CheckParentNode(curNode.Parent);
}
}
}
///
/// 改变所有子节点的状态
///
///
///
private static void CheckAllChildNodes(TreeNode pn, bool IsChecked)
{
foreach (TreeNode tn in pn.Nodes)
{
tn.Checked = IsChecked;
if (tn.Nodes.Count > Constant.INT_IS_ZERO)
{
CheckAllChildNodes(tn, IsChecked);
}
}
}
///
/// 根据系统功能ID取得使用该功能的用户列表
///
///
private DataSet GetFunctionUsers()
{
try
{
return SystemModuleProxy.Service.GetFunctionUsersList();
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据系统功能ID取得使用该功能的用户列表
///
///
private DataSet GetFunctionUsers2()
{
try
{
return SystemModuleProxy.Service.GetFunctionUsersTwoList();
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 保存用户的功能权限
///
///
/// 执行更新影响的数据行数
/// 大于0:正常操作,返回
/// 等于0:无任何影响行数
/// -1:更新的功能权限有超过授权站点数
///
private FunRightResultEntity SaveUserFunctionRight()
{
try
{
this._dtDataGird.Merge(this._dtDataGird2);
return SystemModuleProxy.Service.SaveUserFunctionRightList(this._dtDataGird);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
///
/// 绑定原来数据只能删除不能编辑
///
private void BindReadOnly()
{
foreach (DataGridViewRow row in this.dgvFunctionUsers.Rows)
{
if (row.Cells["AddFlag"].Value != null)
{
//if (row.Cells["AddFlag"].Value.ToString() == "0")
//{
row.Cells["UserCode"].ReadOnly = true;
//}
}
}
this.dgvFunctionUsers.IsSetInputColumnsColor = true;
}
///
/// 绑定原来数据只能删除不能编辑
///
private void BindReadOnly2()
{
foreach (DataGridViewRow row in this.dgvFunctionUsers2.Rows)
{
if (row.Cells["AddFlag1"].Value != null)
{
//if (row.Cells["AddFlag"].Value.ToString() == "0")
//{
row.Cells["UserCode1"].ReadOnly = true;
//}
}
}
this.dgvFunctionUsers2.IsSetInputColumnsColor = true;
}
private void dgvFunctionUsers_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
if (this.dgvFunctionUsers.Rows.Count <= 1)
{
return;
}
DataGridViewColumn columnItem = this.dgvFunctionUsers.Columns[e.ColumnIndex];
if ("UserCode".Equals(columnItem.Name))
{
_userCodeValue = this.dgvFunctionUsers.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void dgvFunctionUsers_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (this.dgvFunctionUsers.Rows.Count <= 1 || !_ShowFlag)
{
return;
}
DataGridViewRow rowItem = this.dgvFunctionUsers.Rows[e.RowIndex];
DataGridViewColumn columnItem = this.dgvFunctionUsers.Columns[e.ColumnIndex];
string OrganizationName = this.dgvFunctionUsers.Rows[e.RowIndex].Cells["OrganizationName"].Value.ToString();
// 用编号获取产品信息
if ("UserCode".Equals(columnItem.Name))
{
_ShowFlag = false;
DataTable dtNew = FormUtility.BindUserRowDataSource(this.dgvFunctionUsers,
e.RowIndex, columnItem.Name, _userCodeValue);
if (dtNew != null && dtNew.Rows.Count > 0)
{
foreach (DataRow r in dtNew.Rows)
{
DataRow[] isR = this._dtDataGird.Select("FunctionCode='" + this._functionCode + "' and UserID=" + r["UserID"]);
if (isR.Length == 0)
{
DataRow drNew = this._dtDataGird.NewRow();
drNew["UserID"] = r["UserID"];
drNew["UserCode"] = r["UserCode"];
drNew["UserName"] = r["UserName"];
drNew["OrganizationName"] = r["OrganizationName"];
drNew["FunctionCode"] = this._functionCode;
drNew["AddFlag"] = 1;
this._dtDataGird.Rows.Add(drNew);
dgvFunctionUsers.Rows[e.RowIndex].Cells["UserCode"].ReadOnly = true;
// BindReadOnly();
}
}
}
//this.btnSave.Enabled = DataJudge.IsChange(this._dtDataGird);
this.btnSave.Enabled = true;
//this.dgvFunctionUsers.Rows[e.RowIndex].Cells["FunctionCode"].Value = this._functionCode;
//this._dtDataGird.AcceptChanges();
// 设置可输入单元格的颜色
this.dgvFunctionUsers.IsSetInputColumnsColor = true;
}
_ShowFlag = true;
}
catch (Exception ex)
{
//_ShowFlag = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void dgvFunctionUsers_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
{
//if(e.Row!=null)
//{
// string functionCode = this.dgvFunctionUsers.Rows[e.Row.Index].Cells["functionCode"].Value.ToString();
// string userID = this.dgvFunctionUsers.Rows[e.Row.Index].Cells["userID"].Value.ToString();
// DataRow[] isR = this._dtDataGird.Select("FunctionCode='" + functionCode + "' and UserID=" + userID);
// isR[0].Delete();
//}
//this.btnSave.Enabled = true;
}
private void dgvFunctionUsers_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
if (e.Row.Index != -1)
{
DataTable dt = this.dgvFunctionUsers.DataSource as DataTable;
string functionCode = dt.Rows[e.Row.Index]["FunctionCode"].ToString();
string userID = dt.Rows[e.Row.Index]["userID"].ToString();
//DataGridViewRow rowItem = this.dgvFunctionUsers.Rows[e.Row.Index];
//string functionCode = rowItem.Cells["FunctionCode"].Value.ToString();
//string userID = this.dgvFunctionUsers.Rows[e.Row.Index].Cells["userID"].Value.ToString();
DataRow[] isR = this._dtDataGird.Select("FunctionCode='" + functionCode + "' and UserID=" + userID);
isR[0].Delete();
this.btnSave.Enabled = true;
}
}
private void dgvFunctionUsers_Sorted(object sender, EventArgs e)
{
BindReadOnly();
}
private void tvwFunction2_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
if (e.Node.Name == Constant.INT_IS_ONE.ToString() || e.Node.Name == Constant.INT_IS_ZERO.ToString())
{
this._functionCode2 = e.Node.Tag.ToString();
lblShow.Text = "当前选择的功能权限:" + e.Node.Text;
DataView dv = this._dtDataGird2.DefaultView;
dv.RowFilter = "FunctionCode='" + this._functionCode2 + "'";
this.dgvFunctionUsers2.DataSource = dv.ToTable();
BindReadOnly2();
}
}
catch (Exception ex)
{
//this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void dgvFunctionUsers2_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
if (this.dgvFunctionUsers2.Rows.Count <= 1)
{
return;
}
DataGridViewColumn columnItem = this.dgvFunctionUsers2.Columns[e.ColumnIndex];
if ("UserCode1".Equals(columnItem.Name))
{
_userCodeValue2 = this.dgvFunctionUsers2.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void dgvFunctionUsers2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (this.dgvFunctionUsers2.Rows.Count <= 1 || !_ShowFlag)
{
return;
}
DataGridViewRow rowItem = this.dgvFunctionUsers2.Rows[e.RowIndex];
DataGridViewColumn columnItem = this.dgvFunctionUsers2.Columns[e.ColumnIndex];
string OrganizationName = this.dgvFunctionUsers2.Rows[e.RowIndex].Cells["OrganizationName1"].Value.ToString();
// 用编号获取产品信息
if ("UserCode1".Equals(columnItem.Name))
{
_ShowFlag2 = false;
DataTable dtNew = FormUtility.BindUserRowDataSource2(this.dgvFunctionUsers2,
e.RowIndex, columnItem.Name, _userCodeValue2);
if (dtNew != null && dtNew.Rows.Count > 0)
{
foreach (DataRow r in dtNew.Rows)
{
DataRow[] isR = this._dtDataGird2.Select("FunctionCode='" + this._functionCode2 + "' and UserID=" + r["UserID"]);
if (isR.Length == 0)
{
DataRow drNew = this._dtDataGird2.NewRow();
drNew["UserID"] = r["UserID"];
drNew["UserCode"] = r["UserCode"];
drNew["UserName"] = r["UserName"];
drNew["OrganizationName"] = r["OrganizationName"];
drNew["FunctionCode"] = this._functionCode2;
drNew["AddFlag"] = 1;
this._dtDataGird2.Rows.Add(drNew);
dgvFunctionUsers2.Rows[e.RowIndex].Cells["UserCode1"].ReadOnly = true;
// BindReadOnly();
}
}
}
//this.btnSave.Enabled = DataJudge.IsChange(this._dtDataGird2);
this.btnSave.Enabled = true;
//this.dgvFunctionUsers.Rows[e.RowIndex].Cells["FunctionCode"].Value = this._functionCode;
//this._dtDataGird.AcceptChanges();
// 设置可输入单元格的颜色
this.dgvFunctionUsers2.IsSetInputColumnsColor = true;
}
_ShowFlag2 = true;
}
catch (Exception ex)
{
//_ShowFlag = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void dgvFunctionUsers2_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
if (e.Row.Index != -1)
{
DataTable dt = this.dgvFunctionUsers2.DataSource as DataTable;
string functionCode = dt.Rows[e.Row.Index]["FunctionCode"].ToString();
string userID = dt.Rows[e.Row.Index]["userID"].ToString();
DataRow[] isR = this._dtDataGird2.Select("FunctionCode='" + functionCode + "' and UserID=" + userID);
isR[0].Delete();
this.btnSave.Enabled = true;
}
}
}
}