| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085 |
- /*******************************************************************************
- * 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;
- }
- }
- }
- }
|