| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084 |
- /*******************************************************************************
- * 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 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="userID"></param>
- 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);
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="userCode">用户编码</param>
- 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 事件
- /// <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;
- //加载用户列表
- 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);
- }
- }
- /// <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);
- // // 将后台数据源的选择状态改变
- // 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);
- }
- }
- /// <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.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);
- }
- }
- /// <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;
- // 保存设置好的 系统功能 隐藏价格
- 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.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;
- }
- }
- /// <summary>
- /// 为功能权限树形赋值
- /// </summary>
- 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;
- }
- }
- /// <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节点。
- 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;
- }
- }
- /// <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)
- {
- 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);
- }
- }
- }
- /// <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.GetFunctionUsersList();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 根据系统功能ID取得使用该功能的用户列表
- /// </summary>
- /// <returns></returns>
- private DataSet GetFunctionUsers2()
- {
- try
- {
- return SystemModuleProxy.Service.GetFunctionUsersTwoList();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 保存用户的功能权限
- /// </summary>
- /// <returns>
- /// 执行更新影响的数据行数
- /// 大于0:正常操作,返回
- /// 等于0:无任何影响行数
- /// -1:更新的功能权限有超过授权站点数
- /// </returns>
- private FunRightResultEntity SaveUserFunctionRight()
- {
- try
- {
- this._dtDataGird.Merge(this._dtDataGird2);
- return SystemModuleProxy.Service.SaveUserFunctionRightList(this._dtDataGird);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- /// <summary>
- /// 绑定原来数据只能删除不能编辑
- /// </summary>
- 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;
- }
- /// <summary>
- /// 绑定原来数据只能删除不能编辑
- /// </summary>
- 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;
- }
- }
- }
- }
|