| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_0203.cs
- * 2.功能描述:用户功能权限设置
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 张国印 2014/09/17 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.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
- namespace Dongke.IBOSS.PRD.Client.SystemModule
- {
- /// <summary>
- /// 用户功能权限设置
- /// </summary>
- public partial class F_MST_0203 : 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 string _overLicenseNumberFunctions2;
- // 是否不限制功能权限
- private bool isFunctionCodeAll = false;
- // 是否不限制功能权限
- private bool isFunctionCodeAll2 = false;
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="userID"></param>
- public F_MST_0203(int userID)
- {
- 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["UserCode"].ReadOnly = true;
- this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
- this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
- // 隐藏二期功能
- this.tabControl1.TabPages.Remove(this.tabPage2);
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="userCode">用户编码</param>
- public F_MST_0203(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["UserCode"].ReadOnly = true;
- this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
- this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
- this.lblUserCode.Text += userCode;
- this.lblUserCode2.Text += userCode;
- // 隐藏二期功能
- this.tabControl1.TabPages.Remove(this.tabPage2);
- }
- #endregion
- #region 事件
- /// <summary>
- /// 页面加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 全选复选框勾选,功能节点树形全选或者全部取消
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void chkFunctionSelect_CheckedChanged(object sender, EventArgs e)
- {
- try
- {
- this._needActionCheck = false;
- foreach (DataRow dataRow in _userFunctionRightData.Tables[0].Rows)
- {
- dataRow["Choose"] = this.chkFunctionSelect.Checked;
- }
- TreeNodeCollection nodes = this.tvwFunction.Nodes;
- foreach (TreeNode node in nodes)
- {
- node.Checked = this.chkFunctionSelect.Checked;
- CheckSubNodes(node, this.chkFunctionSelect.Checked);
- }
- this._needActionCheck = true;
- // 保存按钮状态改变
- //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
- //this.btnSave.Enabled = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 功能权限选择之后,需要检查是否选择了子节点和父节点
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tvwFunction_AfterCheck(object sender, TreeViewEventArgs e)
- {
- try
- {
- if (this._needActionCheck)
- {
- this.CheckControl(e);
- // 将后台数据源的选择状态改变
- string functionCode = e.Node.Tag.ToString();
- foreach (DataRow dataRow in _userFunctionRightData.Tables[0].Rows)
- {
- if (functionCode == dataRow["FunctionCode"].ToString())
- {
- dataRow["Choose"] = e.Node.Checked;
- break;
- }
- }
- // 保存按钮状态改变
- // this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
- //this.btnSave.Enabled = true;
- }
- }
- catch (Exception ex)
- {
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 功能权限树形选择之后显示该功能权限所有的使用用户
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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.btnSave.Enabled = true;
- 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);
- }
- }
- /// <summary>
- /// 页面关闭时,需要确认是否关闭窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 功能树全部展开
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnFunctionExpandAll_Click(object sender, EventArgs e)
- {
- this.tvwFunction.ExpandAll();
- }
- /// <summary>
- /// 功能树全部关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnFunctionCollapseAll_Click(object sender, EventArgs e)
- {
- this.tvwFunction.CollapseAll();
- }
- /// <summary>
- /// 关闭按钮按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 保存用户的功能权限
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- this._overLicenseNumberFunctions2 = returnAffectRows.LicenseFunctions;
- // 将DataGridView单元格的可写状态设置成不可写的
- this.dgvFunctionUsers2.Columns["UserCode2"].ReadOnly = true;
- this.dgvFunctionUsers2.Columns["UserName2"].ReadOnly = true;
- this.dgvFunctionUsers2.Columns["OrganizationName2"].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 私有方法
- /// <summary>
- /// 为功能权限树形赋值
- /// </summary>
- private void SetControlsDataSource()
- {
- try
- {
- // 根据用户ID取得用户的权限信息
- DataSet userRightData = SystemModuleProxy.Service.GetUserFunctionRightInfo(_userID);
- 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;
- }
- }
- /// <summary>
- /// 为功能权限树形赋值(二期)
- /// </summary>
- private void SetControlsDataSource2()
- {
- try
- {
- // 根据用户ID取得用户的权限信息
- DataSet userRightData = SystemModuleProxy.Service.GetUserFunctionRightTwoInfo(_userID);
- if (userRightData == null || userRightData.Tables.Count < Constant.INT_IS_ONE)
- {
- return;
- }
- this._userFunctionRightData2 = new DataSet();
- DataTable functionTable = userRightData.Tables[0].Copy();
- if (functionTable.Rows.Count > 0)
- {
- DataRow[] drAll = functionTable.Select("FunctionCode='[ALL2]'");
- if (drAll.Length > 0)
- {
- this.isFunctionCodeAll2 = true;//加载时是选中的,为了是判断保存按钮是否可用
- this.chkFunctionCodeAll2.Checked = true;
- }
- }
- functionTable.AcceptChanges();
- this._userFunctionRightData2.Tables.Add(functionTable);
- InitFunctionTreeView2(this._userFunctionRightData2.Tables[0]);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 根据取得的数据生成权限树
- /// </summary>
- /// <param name="treeTable"></param>
- 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;
- }
- }
- /// <summary>
- /// 根据取得的数据生成权限树
- /// </summary>
- /// <param name="treeTable"></param>
- private void InitFunctionTreeView2(DataTable treeTable)
- {
- try
- {
- // 初期显示时,滚动条没有显示全部的tree节点。 by chenxy 2014-05-25
- 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节点。 by chenxy 2014-05-25
- this.tvwFunction2.Scrollable = true;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 递归创建树
- /// </summary>
- /// <param name="treeTable"></param>
- /// <param name="rows"></param>
- /// <param name="node"></param>
- 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;
- }
- }
- /// <summary>
- /// 递归创建树
- /// </summary>
- /// <param name="treeTable"></param>
- /// <param name="rows"></param>
- /// <param name="node"></param>
- 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;
- }
- }
- /// <summary>
- /// 递归选中节点或者取消选中节点
- /// </summary>
- /// <param name="treeNode"></param>
- /// <param name="flag"></param>
- 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);
- }
- }
- }
- /// <summary>
- /// 节点 Checked 属性控制
- /// </summary>
- /// <param name="e"></param>
- 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);
- }
- }
- }
- }
- /// <summary>
- /// 改变父节点的选中状态,此处为所有子节点不选中时才取消父节点选中,可以根据需要修改
- /// </summary>
- /// <param name="curNode"></param>
- private static void CheckParentNode(TreeNode curNode)
- {
- bool bChecked = false;
- if (curNode.Parent != null)
- {
- if (curNode.Checked)
- {
- bChecked = true;
- }
- else
- {
- foreach (TreeNode node in curNode.Parent.Nodes)
- {
- if (node.Checked)
- {
- bChecked = true;
- break;
- }
- }
- }
- if (bChecked != curNode.Parent.Checked)
- {
- curNode.Parent.Checked = bChecked;
- CheckParentNode(curNode.Parent);
- }
- }
- }
- /// <summary>
- /// 改变所有子节点的状态
- /// </summary>
- /// <param name="pn"></param>
- /// <param name="IsChecked"></param>
- 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);
- }
- }
- }
- /// <summary>
- /// 根据系统功能ID取得使用该功能的用户列表
- /// </summary>
- /// <returns></returns>
- private DataSet GetFunctionUsers()
- {
- try
- {
- return SystemModuleProxy.Service.GetFunctionUsers(_functionCode);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 根据系统功能ID取得使用该功能的用户列表
- /// </summary>
- /// <returns></returns>
- private DataSet GetFunctionUsers2()
- {
- try
- {
- return SystemModuleProxy.Service.GetFunctionUsers(_functionCode2);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 保存用户的功能权限
- /// </summary>
- /// <returns>
- /// 执行更新影响的数据行数
- /// 大于0:正常操作,返回
- /// 等于0:无任何影响行数
- /// -1:更新的功能权限有超过授权站点数
- /// </returns>
- private FunRightResultEntity SaveUserFunctionRight()
- {
- try
- {
- if (chkFunctionCodeAll.Checked)
- {
- if (this._userFunctionRightData.Tables[0].Select("FunctionCode='[ALL]'").Length == 0)
- {
- DataRow dr = this._userFunctionRightData.Tables[0].NewRow();
- dr["FunctionCode"] = "[ALL]";
- dr["Choose"] = 1;
- this._userFunctionRightData.Tables[0].Rows.Add(dr);
- }
- }
- else
- {
- if (this._userFunctionRightData.Tables[0].Select("FunctionCode='[ALL]'").Length > 0)
- {
- DataRow[] dr1 = this._userFunctionRightData.Tables[0].Select("FunctionCode='[ALL]'");
- this._userFunctionRightData.Tables[0].Rows.Remove(dr1[0]);
- }
- }
- // 二期
- if (chkFunctionCodeAll2.Checked)
- {
- if (this._userFunctionRightData2.Tables[0].Select("FunctionCode='[ALL2]'").Length == 0)
- {
- DataRow dr = this._userFunctionRightData2.Tables[0].NewRow();
- dr["FunctionCode"] = "[ALL2]";
- dr["Choose"] = 1;
- this._userFunctionRightData2.Tables[0].Rows.Add(dr);
- }
- }
- else
- {
- if (this._userFunctionRightData.Tables[0].Select("FunctionCode='[ALL2]'").Length > 0)
- {
- DataRow[] dr1 = this._userFunctionRightData.Tables[0].Select("FunctionCode='[ALL2]'");
- this._userFunctionRightData.Tables[0].Rows.Remove(dr1[0]);
- }
- }
- //return SystemModuleProxy.Service.SaveUserFunctionRight(this._userFunctionRightData, this._userID, this._licenseType);
- return SystemModuleProxy.Service.SaveUserFunctionTwoRight(this._userFunctionRightData, this._userID, this._licenseType, this._userFunctionRightData2);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- /// <summary>
- /// 不限制按钮选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void chkFunctionCodeAll_CheckedChanged(object sender, EventArgs e)
- {
- //try
- //{
- // if ((chkFunctionCodeAll.Checked && !this.isFunctionCodeAll) || (!chkFunctionCodeAll.Checked && this.isFunctionCodeAll))
- // {
- // // 保存按钮状态改变
- // this.btnSave.Enabled = true;
- // }
- // else
- // {
- // this.btnSave.Enabled = false;
- // }
- // this.btnSave.Enabled = true;
- //}
- //catch (Exception ex)
- //{
- // // 对异常进行共通处理
- // ExceptionManager.HandleEventException(this.ToString(),
- // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- //}
- }
- private void tvwFunction2_AfterSelect(object sender, TreeViewEventArgs e)
- {
- try
- {
- if (e.Node.Name == Constant.INT_IS_ONE.ToString())
- {
- this._functionCode2 = e.Node.Tag.ToString();
- this.btnSave.Enabled = false;
- this.btnCancel.Enabled = false;
- DataSet functionUsers = (DataSet)DoAsync(new BaseAsyncMethod(GetFunctionUsers2));
- //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData2);
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- if (functionUsers != null)
- {
- this.dgvFunctionUsers2.AutoGenerateColumns = false;
- this.dgvFunctionUsers2.DataSource = functionUsers.Tables[0];
- this.dgvFunctionUsers2.Columns["UserCode2"].ReadOnly = true;
- this.dgvFunctionUsers2.Columns["UserName2"].ReadOnly = true;
- this.dgvFunctionUsers2.Columns["OrganizationName2"].ReadOnly = true;
- }
- }
- }
- catch (Exception ex)
- {
- //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData2);
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- private void tvwFunction2_AfterCheck(object sender, TreeViewEventArgs e)
- {
- try
- {
- if (this._needActionCheck2)
- {
- this.CheckControl(e);
- // 将后台数据源的选择状态改变
- string functionID = e.Node.Tag.ToString();
- foreach (DataRow dataRow in _userFunctionRightData2.Tables[0].Rows)
- {
- if (functionID ==dataRow["FunctionCode"].ToString())
- {
- dataRow["Choose"] = e.Node.Checked;
- break;
- }
- }
- // 保存按钮状态改变
- //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData2);
- this.btnSave.Enabled = true;
- }
- }
- 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 chkFunctionSelect2_CheckedChanged(object sender, EventArgs e)
- {
- try
- {
- this._needActionCheck2 = false;
- foreach (DataRow dataRow in _userFunctionRightData2.Tables[0].Rows)
- {
- dataRow["Choose"] = this.chkFunctionSelect2.Checked;
- }
- TreeNodeCollection nodes = this.tvwFunction2.Nodes;
- foreach (TreeNode node in nodes)
- {
- node.Checked = this.chkFunctionSelect2.Checked;
- CheckSubNodes(node, this.chkFunctionSelect2.Checked);
- }
- this._needActionCheck2 = true;
- // 保存按钮状态改变
- //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData2);
- this.btnSave.Enabled = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- private void btnFunctionExpandAll2_Click(object sender, EventArgs e)
- {
- this.tvwFunction2.ExpandAll();
- }
- private void btnFunctionCollapseAll2_Click(object sender, EventArgs e)
- {
- this.tvwFunction2.CollapseAll();
- }
- private void chkFunctionCodeAll2_CheckedChanged(object sender, EventArgs e)
- {
- //try
- //{
- // if (!this.btnSave.Enabled)
- // {
- // if ((chkFunctionCodeAll2.Checked && !this.isFunctionCodeAll2) || (!chkFunctionCodeAll2.Checked && this.isFunctionCodeAll2))
- // {
- // // 保存按钮状态改变
- // this.btnSave.Enabled = true;
- // }
- // else
- // {
- // this.btnSave.Enabled = false;
- // }
- // }
- // else
- // {
- // if(!chkFunctionCodeAll2.Checked)
- // {
- // // 保存按钮状态改变
- // this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData2);
- // }
- // }
- // this.btnSave.Enabled = true;
- //}
- //catch (Exception ex)
- //{
- // // 对异常进行共通处理
- // ExceptionManager.HandleEventException(this.ToString(),
- // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- //}
- }
- }
- }
|