F_MST_0203.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0203.cs
  5. * 2.功能描述:用户功能权限设置
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 张国印 2014/09/17 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Basics.Library;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.WCF.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  20. namespace Dongke.IBOSS.PRD.Client.SystemModule
  21. {
  22. /// <summary>
  23. /// 用户功能权限设置
  24. /// </summary>
  25. public partial class F_MST_0203 : FormBase
  26. {
  27. #region 成员变量
  28. // 传过来的用户ID
  29. private int _userID;
  30. //页面的数据源
  31. DataSet _userFunctionRightData;
  32. //页面的数据源
  33. DataSet _userFunctionRightData2;
  34. // 系统功能ID
  35. private string _functionCode = string.Empty;
  36. // 系统功能ID
  37. private string _functionCode2 = string.Empty;
  38. // 是否需要触发After Check事件(性能改善)
  39. private bool _needActionCheck = false;
  40. // 是否需要触发After Check事件(性能改善)
  41. private bool _needActionCheck2 = false;
  42. // 用户授权方式 1:按站点 2:按用户
  43. private int _licenseType;
  44. // 保存时,用于返回超过授权站点数的明细
  45. private string _overLicenseNumberFunctions;
  46. // 保存时,用于返回超过授权站点数的明细
  47. private string _overLicenseNumberFunctions2;
  48. // 是否不限制功能权限
  49. private bool isFunctionCodeAll = false;
  50. // 是否不限制功能权限
  51. private bool isFunctionCodeAll2 = false;
  52. #endregion
  53. #region 构造函数
  54. /// <summary>
  55. /// 构造函数
  56. /// </summary>
  57. /// <param name="userID"></param>
  58. public F_MST_0203(int userID)
  59. {
  60. InitializeComponent();
  61. this._userID = userID;
  62. // 设置标题
  63. this.Text = FormTitles.F_MST_0203;
  64. // 工具栏按钮文本赋值
  65. this.btnSave.Text = ButtonText.BTN_SAVE;
  66. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  67. this.dgvFunctionUsers.AutoGenerateColumns = false;
  68. this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
  69. this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
  70. this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
  71. // 隐藏二期功能
  72. this.tabControl1.TabPages.Remove(this.tabPage2);
  73. }
  74. /// <summary>
  75. /// 构造函数
  76. /// </summary>
  77. /// <param name="userID"></param>
  78. /// <param name="userCode">用户编码</param>
  79. public F_MST_0203(int userID, string userCode)
  80. {
  81. InitializeComponent();
  82. this._userID = userID;
  83. // 设置标题
  84. this.Text = FormTitles.F_MST_0203;
  85. // 工具栏按钮文本赋值
  86. this.btnSave.Text = ButtonText.BTN_SAVE;
  87. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  88. this.dgvFunctionUsers.AutoGenerateColumns = false;
  89. this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
  90. this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
  91. this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
  92. this.lblUserCode.Text += userCode;
  93. this.lblUserCode2.Text += userCode;
  94. // 隐藏二期功能
  95. this.tabControl1.TabPages.Remove(this.tabPage2);
  96. }
  97. #endregion
  98. #region 事件
  99. /// <summary>
  100. /// 页面加载事件
  101. /// </summary>
  102. /// <param name="sender"></param>
  103. /// <param name="e"></param>
  104. private void F_MST_0203_Load(object sender, EventArgs e)
  105. {
  106. try
  107. {
  108. // 保存按钮不可用
  109. //this.btnSave.Enabled = false;
  110. // 取得用户权限并赋值
  111. this._needActionCheck = false;
  112. this.SetControlsDataSource();
  113. this._needActionCheck = true;
  114. // 二期
  115. // 取得用户权限并赋值
  116. this._needActionCheck2 = false;
  117. this.SetControlsDataSource2();
  118. this._needActionCheck2 = true;
  119. }
  120. catch (Exception ex)
  121. {
  122. // 对异常进行共通处理
  123. ExceptionManager.HandleEventException(this.ToString(),
  124. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  125. }
  126. }
  127. /// <summary>
  128. /// 全选复选框勾选,功能节点树形全选或者全部取消
  129. /// </summary>
  130. /// <param name="sender"></param>
  131. /// <param name="e"></param>
  132. private void chkFunctionSelect_CheckedChanged(object sender, EventArgs e)
  133. {
  134. try
  135. {
  136. this._needActionCheck = false;
  137. foreach (DataRow dataRow in _userFunctionRightData.Tables[0].Rows)
  138. {
  139. dataRow["Choose"] = this.chkFunctionSelect.Checked;
  140. }
  141. TreeNodeCollection nodes = this.tvwFunction.Nodes;
  142. foreach (TreeNode node in nodes)
  143. {
  144. node.Checked = this.chkFunctionSelect.Checked;
  145. CheckSubNodes(node, this.chkFunctionSelect.Checked);
  146. }
  147. this._needActionCheck = true;
  148. // 保存按钮状态改变
  149. //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
  150. //this.btnSave.Enabled = true;
  151. }
  152. catch (Exception ex)
  153. {
  154. // 对异常进行共通处理
  155. ExceptionManager.HandleEventException(this.ToString(),
  156. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  157. }
  158. }
  159. /// <summary>
  160. /// 功能权限选择之后,需要检查是否选择了子节点和父节点
  161. /// </summary>
  162. /// <param name="sender"></param>
  163. /// <param name="e"></param>
  164. private void tvwFunction_AfterCheck(object sender, TreeViewEventArgs e)
  165. {
  166. try
  167. {
  168. if (this._needActionCheck)
  169. {
  170. this.CheckControl(e);
  171. // 将后台数据源的选择状态改变
  172. string functionCode = e.Node.Tag.ToString();
  173. foreach (DataRow dataRow in _userFunctionRightData.Tables[0].Rows)
  174. {
  175. if (functionCode == dataRow["FunctionCode"].ToString())
  176. {
  177. dataRow["Choose"] = e.Node.Checked;
  178. break;
  179. }
  180. }
  181. // 保存按钮状态改变
  182. // this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
  183. //this.btnSave.Enabled = true;
  184. }
  185. }
  186. catch (Exception ex)
  187. {
  188. this.btnSave.Enabled = true;
  189. this.btnCancel.Enabled = true;
  190. // 对异常进行共通处理
  191. ExceptionManager.HandleEventException(this.ToString(),
  192. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  193. }
  194. }
  195. /// <summary>
  196. /// 功能权限树形选择之后显示该功能权限所有的使用用户
  197. /// </summary>
  198. /// <param name="sender"></param>
  199. /// <param name="e"></param>
  200. private void tvwFunction_AfterSelect(object sender, TreeViewEventArgs e)
  201. {
  202. try
  203. {
  204. if (e.Node.Name == Constant.INT_IS_ONE.ToString())
  205. {
  206. this._functionCode = e.Node.Tag.ToString();
  207. this.btnSave.Enabled = false;
  208. this.btnCancel.Enabled = false;
  209. DataSet functionUsers = (DataSet)DoAsync(new BaseAsyncMethod(GetFunctionUsers));
  210. //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
  211. this.btnSave.Enabled = true;
  212. this.btnCancel.Enabled = true;
  213. if (functionUsers != null)
  214. {
  215. this.dgvFunctionUsers.AutoGenerateColumns = false;
  216. this.dgvFunctionUsers.DataSource = functionUsers.Tables[0];
  217. this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
  218. this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
  219. this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
  220. }
  221. }
  222. }
  223. catch (Exception ex)
  224. {
  225. //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
  226. this.btnSave.Enabled = true;
  227. this.btnCancel.Enabled = true;
  228. // 对异常进行共通处理
  229. ExceptionManager.HandleEventException(this.ToString(),
  230. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  231. }
  232. }
  233. /// <summary>
  234. /// 页面关闭时,需要确认是否关闭窗体
  235. /// </summary>
  236. /// <param name="sender"></param>
  237. /// <param name="e"></param>
  238. private void F_MST_0203_FormClosing(object sender, FormClosingEventArgs e)
  239. {
  240. try
  241. {
  242. // 判断数据是否被修改过,修改过需要提示保存消息
  243. if (DataJudge.IsChange(this._userFunctionRightData))
  244. {
  245. DialogResult result = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  246. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  247. if (result == DialogResult.Yes)
  248. {
  249. // 保存数据
  250. btnSave_Click(sender, e);
  251. }
  252. else if (result == DialogResult.Cancel)
  253. {
  254. e.Cancel = true;
  255. }
  256. }
  257. }
  258. catch (Exception ex)
  259. {
  260. // 对异常进行共通处理
  261. ExceptionManager.HandleEventException(this.ToString(),
  262. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  263. }
  264. }
  265. /// <summary>
  266. /// 功能树全部展开
  267. /// </summary>
  268. /// <param name="sender"></param>
  269. /// <param name="e"></param>
  270. private void btnFunctionExpandAll_Click(object sender, EventArgs e)
  271. {
  272. this.tvwFunction.ExpandAll();
  273. }
  274. /// <summary>
  275. /// 功能树全部关闭
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. private void btnFunctionCollapseAll_Click(object sender, EventArgs e)
  280. {
  281. this.tvwFunction.CollapseAll();
  282. }
  283. /// <summary>
  284. /// 关闭按钮按下事件
  285. /// </summary>
  286. /// <param name="sender"></param>
  287. /// <param name="e"></param>
  288. private void btnCancel_Click(object sender, EventArgs e)
  289. {
  290. this.Close();
  291. }
  292. /// <summary>
  293. /// 保存用户的功能权限
  294. /// </summary>
  295. /// <param name="sender"></param>
  296. /// <param name="e"></param>
  297. private void btnSave_Click(object sender, EventArgs e)
  298. {
  299. try
  300. {
  301. FunRightResultEntity returnAffectRows = (FunRightResultEntity)DoAsync(new BaseAsyncMethod(SaveUserFunctionRight));
  302. this._overLicenseNumberFunctions = returnAffectRows.LicenseFunctions;
  303. // 将DataGridView单元格的可写状态设置成不可写的
  304. this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
  305. this.dgvFunctionUsers.Columns["UserName"].ReadOnly = true;
  306. this.dgvFunctionUsers.Columns["OrganizationName"].ReadOnly = true;
  307. this._overLicenseNumberFunctions2 = returnAffectRows.LicenseFunctions;
  308. // 将DataGridView单元格的可写状态设置成不可写的
  309. this.dgvFunctionUsers2.Columns["UserCode2"].ReadOnly = true;
  310. this.dgvFunctionUsers2.Columns["UserName2"].ReadOnly = true;
  311. this.dgvFunctionUsers2.Columns["OrganizationName2"].ReadOnly = true;
  312. // 保存设置好的 系统功能 隐藏价格
  313. if (returnAffectRows.OperationStatus > Constant.INT_IS_ZERO)
  314. {
  315. this._userFunctionRightData.AcceptChanges();
  316. // 提示信息
  317. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "功能权限", "保存"),
  318. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  319. this.Close();
  320. }
  321. else if (returnAffectRows.OperationStatus == Constant.INT_IS_ZERO)
  322. {
  323. // 提示信息
  324. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "功能权限", "保存"),
  325. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  326. }
  327. else
  328. {
  329. // 提示信息
  330. string functionOver = "";
  331. if (_overLicenseNumberFunctions.Length > 100)
  332. {
  333. functionOver = _overLicenseNumberFunctions.Substring(0, 99) + "......";
  334. }
  335. else
  336. {
  337. functionOver = _overLicenseNumberFunctions;
  338. }
  339. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  340. "以下的功能超出了授权功能数:\r\n" + functionOver),
  341. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  342. }
  343. }
  344. catch (Exception ex)
  345. {
  346. // 对异常进行共通处理
  347. ExceptionManager.HandleEventException(this.ToString(),
  348. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  349. }
  350. }
  351. #endregion
  352. #region 私有方法
  353. /// <summary>
  354. /// 为功能权限树形赋值
  355. /// </summary>
  356. private void SetControlsDataSource()
  357. {
  358. try
  359. {
  360. // 根据用户ID取得用户的权限信息
  361. DataSet userRightData = SystemModuleProxy.Service.GetUserFunctionRightInfo(_userID);
  362. if (userRightData == null || userRightData.Tables.Count < Constant.INT_IS_ONE)
  363. {
  364. return;
  365. }
  366. this._userFunctionRightData = new DataSet();
  367. DataTable functionTable = userRightData.Tables[0].Copy();
  368. if (functionTable.Rows.Count > 0)
  369. {
  370. DataRow[] drAll = functionTable.Select("FunctionCode='[ALL]'");
  371. if (drAll.Length > 0)
  372. {
  373. this.isFunctionCodeAll = true;//加载时是选中的,为了是判断保存按钮是否可用
  374. this.chkFunctionCodeAll.Checked = true;
  375. }
  376. }
  377. // 取得license文件中的功能权限
  378. //DataTable licenseFunction = new DataTable();
  379. //if (LogInUserInfo.CurrentUser.CurrentLicenseInfo == null || LogInUserInfo.CurrentUser.CurrentLicenseInfo.Tables.Count < 2)
  380. //{
  381. // return;
  382. //}
  383. //licenseFunction = LogInUserInfo.CurrentUser.CurrentLicenseInfo.Tables[1].Copy();
  384. //_licenseType = Convert.ToInt32(LogInUserInfo.CurrentUser.CurrentLicenseInfo.Tables[0].Rows[0]["LicenseTypeID"]);
  385. //// 剔除没有授权的功能
  386. //for (int i = 0; i < functionTable.Rows.Count; i++)
  387. //{
  388. // DataRow[] filter = licenseFunction.Select("FunctionCode = '" + functionTable.Rows[i]["FunctionCode"] + "'");
  389. // if (filter.Length < 1)
  390. // {
  391. // functionTable.Rows[i].Delete();
  392. // }
  393. // else
  394. // {
  395. // functionTable.Rows[i]["LicensesNumber"] = filter[0]["FunctionNumber"].ToString();
  396. // }
  397. //}
  398. functionTable.AcceptChanges();
  399. this._userFunctionRightData.Tables.Add(functionTable);
  400. InitFunctionTreeView(this._userFunctionRightData.Tables[0]);
  401. }
  402. catch (Exception ex)
  403. {
  404. throw ex;
  405. }
  406. }
  407. /// <summary>
  408. /// 为功能权限树形赋值(二期)
  409. /// </summary>
  410. private void SetControlsDataSource2()
  411. {
  412. try
  413. {
  414. // 根据用户ID取得用户的权限信息
  415. DataSet userRightData = SystemModuleProxy.Service.GetUserFunctionRightTwoInfo(_userID);
  416. if (userRightData == null || userRightData.Tables.Count < Constant.INT_IS_ONE)
  417. {
  418. return;
  419. }
  420. this._userFunctionRightData2 = new DataSet();
  421. DataTable functionTable = userRightData.Tables[0].Copy();
  422. if (functionTable.Rows.Count > 0)
  423. {
  424. DataRow[] drAll = functionTable.Select("FunctionCode='[ALL2]'");
  425. if (drAll.Length > 0)
  426. {
  427. this.isFunctionCodeAll2 = true;//加载时是选中的,为了是判断保存按钮是否可用
  428. this.chkFunctionCodeAll2.Checked = true;
  429. }
  430. }
  431. functionTable.AcceptChanges();
  432. this._userFunctionRightData2.Tables.Add(functionTable);
  433. InitFunctionTreeView2(this._userFunctionRightData2.Tables[0]);
  434. }
  435. catch (Exception ex)
  436. {
  437. throw ex;
  438. }
  439. }
  440. /// <summary>
  441. /// 根据取得的数据生成权限树
  442. /// </summary>
  443. /// <param name="treeTable"></param>
  444. private void InitFunctionTreeView(DataTable treeTable)
  445. {
  446. try
  447. {
  448. // 初期显示时,滚动条没有显示全部的tree节点。 by chenxy 2014-05-25
  449. this.tvwFunction.Scrollable = false;
  450. TreeNode node = null;
  451. //DataRow[] warehouseRows = treeTable.Select("LEN(FunctionCode) = 2");
  452. DataRow[] warehouseRows = treeTable.Select("LEN(FUNCTIONLEVEL) = 2");
  453. // 递归生成功能权限树
  454. this.InitTreeView(treeTable, warehouseRows, node);
  455. // 初期显示时,滚动条没有显示全部的tree节点。 by chenxy 2014-05-25
  456. this.tvwFunction.Scrollable = true;
  457. }
  458. catch (Exception ex)
  459. {
  460. throw ex;
  461. }
  462. }
  463. /// <summary>
  464. /// 根据取得的数据生成权限树
  465. /// </summary>
  466. /// <param name="treeTable"></param>
  467. private void InitFunctionTreeView2(DataTable treeTable)
  468. {
  469. try
  470. {
  471. // 初期显示时,滚动条没有显示全部的tree节点。 by chenxy 2014-05-25
  472. this.tvwFunction2.Scrollable = false;
  473. TreeNode node = null;
  474. //DataRow[] warehouseRows = treeTable.Select("LEN(FunctionCode) = 2");
  475. DataRow[] warehouseRows = treeTable.Select("LEN(FUNCTIONLEVEL) = 3");
  476. // 递归生成功能权限树
  477. this.InitTreeView2(treeTable, warehouseRows, node);
  478. // 初期显示时,滚动条没有显示全部的tree节点。 by chenxy 2014-05-25
  479. this.tvwFunction2.Scrollable = true;
  480. }
  481. catch (Exception ex)
  482. {
  483. throw ex;
  484. }
  485. }
  486. /// <summary>
  487. /// 递归创建树
  488. /// </summary>
  489. /// <param name="treeTable"></param>
  490. /// <param name="rows"></param>
  491. /// <param name="node"></param>
  492. private void InitTreeView(DataTable treeTable, DataRow[] rows, TreeNode node)
  493. {
  494. try
  495. {
  496. foreach (DataRow row in rows)
  497. {
  498. TreeNode sNode;
  499. if (node == null)
  500. {
  501. sNode = new TreeNode();
  502. if (row["FunctionFlag"].ToString() == Constant.INT_IS_ONE.ToString())
  503. {
  504. sNode.Text = "[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString();
  505. //+ " ( " + row["UseLincenseNumber"].ToString() + " / " + row["LicensesNumber"].ToString() + " )";
  506. }
  507. else
  508. {
  509. sNode.Text = "[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString();
  510. }
  511. sNode.Name = row["FunctionFlag"].ToString();
  512. sNode.Tag = row["FunctionCode"].ToString();
  513. if (row["Choose"].ToString() == Constant.INT_IS_ONE.ToString())
  514. {
  515. sNode.Checked = true;
  516. }
  517. this.tvwFunction.Nodes.Add(sNode);
  518. }
  519. else
  520. {
  521. if (row["FunctionFlag"].ToString() == Constant.INT_IS_ONE.ToString())
  522. {
  523. sNode = node.Nodes.Add("[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString());
  524. //+ " ( " + row["UseLincenseNumber"].ToString() + " / " + row["LicensesNumber"].ToString() + " )");
  525. }
  526. else
  527. {
  528. sNode = node.Nodes.Add("[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString());
  529. }
  530. sNode.Name = row["FunctionFlag"].ToString();
  531. sNode.Tag = row["FunctionCode"].ToString();
  532. if (row["Choose"].ToString() == Constant.INT_IS_ONE.ToString())
  533. {
  534. sNode.Checked = true;
  535. }
  536. }
  537. //string filterExpression = "FunctionCode LIKE '" + row["FunctionCode"].ToString()
  538. // + "%' AND LEN(FunctionCode) = " + (row["FunctionCode"].ToString().Length + 2);
  539. string filterExpression = "FUNCTIONLEVEL LIKE '" + row["FUNCTIONLEVEL"].ToString()
  540. + "%' AND LEN(FUNCTIONLEVEL) = " + (row["FUNCTIONLEVEL"].ToString().Length + 2);
  541. DataRow[] subRows = treeTable.Select(filterExpression);
  542. // 递归方法
  543. InitTreeView(treeTable, subRows, sNode);
  544. }
  545. }
  546. catch (Exception ex)
  547. {
  548. throw ex;
  549. }
  550. }
  551. /// <summary>
  552. /// 递归创建树
  553. /// </summary>
  554. /// <param name="treeTable"></param>
  555. /// <param name="rows"></param>
  556. /// <param name="node"></param>
  557. private void InitTreeView2(DataTable treeTable, DataRow[] rows, TreeNode node)
  558. {
  559. try
  560. {
  561. foreach (DataRow row in rows)
  562. {
  563. TreeNode sNode;
  564. if (node == null)
  565. {
  566. sNode = new TreeNode();
  567. if (row["FunctionFlag"].ToString() == Constant.INT_IS_ONE.ToString())
  568. {
  569. sNode.Text = "[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString();
  570. //+ " ( " + row["UseLincenseNumber"].ToString() + " / " + row["LicensesNumber"].ToString() + " )";
  571. }
  572. else
  573. {
  574. sNode.Text = "[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString();
  575. }
  576. sNode.Name = row["FunctionFlag"].ToString();
  577. sNode.Tag = row["FunctionCode"].ToString();
  578. if (row["Choose"].ToString() == Constant.INT_IS_ONE.ToString())
  579. {
  580. sNode.Checked = true;
  581. }
  582. this.tvwFunction2.Nodes.Add(sNode);
  583. }
  584. else
  585. {
  586. if (row["FunctionFlag"].ToString() == Constant.INT_IS_ONE.ToString())
  587. {
  588. sNode = node.Nodes.Add("[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString());
  589. //+ " ( " + row["UseLincenseNumber"].ToString() + " / " + row["LicensesNumber"].ToString() + " )");
  590. }
  591. else
  592. {
  593. sNode = node.Nodes.Add("[" + row["FUNCTIONLEVEL"].ToString() + "] " + row["FunctionName"].ToString());
  594. }
  595. sNode.Name = row["FunctionFlag"].ToString();
  596. sNode.Tag = row["FunctionCode"].ToString();
  597. if (row["Choose"].ToString() == Constant.INT_IS_ONE.ToString())
  598. {
  599. sNode.Checked = true;
  600. }
  601. }
  602. string filterExpression = "FUNCTIONLEVEL LIKE '" + row["FUNCTIONLEVEL"].ToString()
  603. + "%' AND LEN(FUNCTIONLEVEL) = " + (row["FUNCTIONLEVEL"].ToString().Length + 3);
  604. DataRow[] subRows = treeTable.Select(filterExpression);
  605. // 递归方法
  606. InitTreeView2(treeTable, subRows, sNode);
  607. }
  608. }
  609. catch (Exception ex)
  610. {
  611. throw ex;
  612. }
  613. }
  614. /// <summary>
  615. /// 递归选中节点或者取消选中节点
  616. /// </summary>
  617. /// <param name="treeNode"></param>
  618. /// <param name="flag"></param>
  619. private void CheckSubNodes(TreeNode treeNode, bool nodeChecked)
  620. {
  621. foreach (TreeNode node in treeNode.Nodes)
  622. {
  623. node.Checked = nodeChecked;
  624. if (node.Nodes.Count >Constant.INT_IS_ZERO)
  625. {
  626. this.CheckSubNodes(node, nodeChecked);
  627. }
  628. }
  629. }
  630. /// <summary>
  631. /// 节点 Checked 属性控制
  632. /// </summary>
  633. /// <param name="e"></param>
  634. private void CheckControl(TreeViewEventArgs e)
  635. {
  636. if (e.Action != TreeViewAction.Unknown)
  637. {
  638. if (e.Node != null && !Convert.IsDBNull(e.Node))
  639. {
  640. CheckParentNode(e.Node);
  641. if (e.Node.Nodes.Count > Constant.INT_IS_ZERO)
  642. {
  643. CheckAllChildNodes(e.Node, e.Node.Checked);
  644. }
  645. }
  646. }
  647. }
  648. /// <summary>
  649. /// 改变父节点的选中状态,此处为所有子节点不选中时才取消父节点选中,可以根据需要修改
  650. /// </summary>
  651. /// <param name="curNode"></param>
  652. private static void CheckParentNode(TreeNode curNode)
  653. {
  654. bool bChecked = false;
  655. if (curNode.Parent != null)
  656. {
  657. if (curNode.Checked)
  658. {
  659. bChecked = true;
  660. }
  661. else
  662. {
  663. foreach (TreeNode node in curNode.Parent.Nodes)
  664. {
  665. if (node.Checked)
  666. {
  667. bChecked = true;
  668. break;
  669. }
  670. }
  671. }
  672. if (bChecked != curNode.Parent.Checked)
  673. {
  674. curNode.Parent.Checked = bChecked;
  675. CheckParentNode(curNode.Parent);
  676. }
  677. }
  678. }
  679. /// <summary>
  680. /// 改变所有子节点的状态
  681. /// </summary>
  682. /// <param name="pn"></param>
  683. /// <param name="IsChecked"></param>
  684. private static void CheckAllChildNodes(TreeNode pn, bool IsChecked)
  685. {
  686. foreach (TreeNode tn in pn.Nodes)
  687. {
  688. tn.Checked = IsChecked;
  689. if (tn.Nodes.Count > Constant.INT_IS_ZERO)
  690. {
  691. CheckAllChildNodes(tn, IsChecked);
  692. }
  693. }
  694. }
  695. /// <summary>
  696. /// 根据系统功能ID取得使用该功能的用户列表
  697. /// </summary>
  698. /// <returns></returns>
  699. private DataSet GetFunctionUsers()
  700. {
  701. try
  702. {
  703. return SystemModuleProxy.Service.GetFunctionUsers(_functionCode);
  704. }
  705. catch (Exception ex)
  706. {
  707. throw ex;
  708. }
  709. }
  710. /// <summary>
  711. /// 根据系统功能ID取得使用该功能的用户列表
  712. /// </summary>
  713. /// <returns></returns>
  714. private DataSet GetFunctionUsers2()
  715. {
  716. try
  717. {
  718. return SystemModuleProxy.Service.GetFunctionUsers(_functionCode2);
  719. }
  720. catch (Exception ex)
  721. {
  722. throw ex;
  723. }
  724. }
  725. /// <summary>
  726. /// 保存用户的功能权限
  727. /// </summary>
  728. /// <returns>
  729. /// 执行更新影响的数据行数
  730. /// 大于0:正常操作,返回
  731. /// 等于0:无任何影响行数
  732. /// -1:更新的功能权限有超过授权站点数
  733. /// </returns>
  734. private FunRightResultEntity SaveUserFunctionRight()
  735. {
  736. try
  737. {
  738. if (chkFunctionCodeAll.Checked)
  739. {
  740. if (this._userFunctionRightData.Tables[0].Select("FunctionCode='[ALL]'").Length == 0)
  741. {
  742. DataRow dr = this._userFunctionRightData.Tables[0].NewRow();
  743. dr["FunctionCode"] = "[ALL]";
  744. dr["Choose"] = 1;
  745. this._userFunctionRightData.Tables[0].Rows.Add(dr);
  746. }
  747. }
  748. else
  749. {
  750. if (this._userFunctionRightData.Tables[0].Select("FunctionCode='[ALL]'").Length > 0)
  751. {
  752. DataRow[] dr1 = this._userFunctionRightData.Tables[0].Select("FunctionCode='[ALL]'");
  753. this._userFunctionRightData.Tables[0].Rows.Remove(dr1[0]);
  754. }
  755. }
  756. // 二期
  757. if (chkFunctionCodeAll2.Checked)
  758. {
  759. if (this._userFunctionRightData2.Tables[0].Select("FunctionCode='[ALL2]'").Length == 0)
  760. {
  761. DataRow dr = this._userFunctionRightData2.Tables[0].NewRow();
  762. dr["FunctionCode"] = "[ALL2]";
  763. dr["Choose"] = 1;
  764. this._userFunctionRightData2.Tables[0].Rows.Add(dr);
  765. }
  766. }
  767. else
  768. {
  769. if (this._userFunctionRightData.Tables[0].Select("FunctionCode='[ALL2]'").Length > 0)
  770. {
  771. DataRow[] dr1 = this._userFunctionRightData.Tables[0].Select("FunctionCode='[ALL2]'");
  772. this._userFunctionRightData.Tables[0].Rows.Remove(dr1[0]);
  773. }
  774. }
  775. //return SystemModuleProxy.Service.SaveUserFunctionRight(this._userFunctionRightData, this._userID, this._licenseType);
  776. return SystemModuleProxy.Service.SaveUserFunctionTwoRight(this._userFunctionRightData, this._userID, this._licenseType, this._userFunctionRightData2);
  777. }
  778. catch (Exception ex)
  779. {
  780. throw ex;
  781. }
  782. }
  783. #endregion
  784. /// <summary>
  785. /// 不限制按钮选择事件
  786. /// </summary>
  787. /// <param name="sender"></param>
  788. /// <param name="e"></param>
  789. private void chkFunctionCodeAll_CheckedChanged(object sender, EventArgs e)
  790. {
  791. //try
  792. //{
  793. // if ((chkFunctionCodeAll.Checked && !this.isFunctionCodeAll) || (!chkFunctionCodeAll.Checked && this.isFunctionCodeAll))
  794. // {
  795. // // 保存按钮状态改变
  796. // this.btnSave.Enabled = true;
  797. // }
  798. // else
  799. // {
  800. // this.btnSave.Enabled = false;
  801. // }
  802. // this.btnSave.Enabled = true;
  803. //}
  804. //catch (Exception ex)
  805. //{
  806. // // 对异常进行共通处理
  807. // ExceptionManager.HandleEventException(this.ToString(),
  808. // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  809. //}
  810. }
  811. private void tvwFunction2_AfterSelect(object sender, TreeViewEventArgs e)
  812. {
  813. try
  814. {
  815. if (e.Node.Name == Constant.INT_IS_ONE.ToString())
  816. {
  817. this._functionCode2 = e.Node.Tag.ToString();
  818. this.btnSave.Enabled = false;
  819. this.btnCancel.Enabled = false;
  820. DataSet functionUsers = (DataSet)DoAsync(new BaseAsyncMethod(GetFunctionUsers2));
  821. //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData2);
  822. this.btnSave.Enabled = true;
  823. this.btnCancel.Enabled = true;
  824. if (functionUsers != null)
  825. {
  826. this.dgvFunctionUsers2.AutoGenerateColumns = false;
  827. this.dgvFunctionUsers2.DataSource = functionUsers.Tables[0];
  828. this.dgvFunctionUsers2.Columns["UserCode2"].ReadOnly = true;
  829. this.dgvFunctionUsers2.Columns["UserName2"].ReadOnly = true;
  830. this.dgvFunctionUsers2.Columns["OrganizationName2"].ReadOnly = true;
  831. }
  832. }
  833. }
  834. catch (Exception ex)
  835. {
  836. //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData2);
  837. this.btnSave.Enabled = true;
  838. this.btnCancel.Enabled = true;
  839. // 对异常进行共通处理
  840. ExceptionManager.HandleEventException(this.ToString(),
  841. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  842. }
  843. }
  844. private void tvwFunction2_AfterCheck(object sender, TreeViewEventArgs e)
  845. {
  846. try
  847. {
  848. if (this._needActionCheck2)
  849. {
  850. this.CheckControl(e);
  851. // 将后台数据源的选择状态改变
  852. string functionID = e.Node.Tag.ToString();
  853. foreach (DataRow dataRow in _userFunctionRightData2.Tables[0].Rows)
  854. {
  855. if (functionID ==dataRow["FunctionCode"].ToString())
  856. {
  857. dataRow["Choose"] = e.Node.Checked;
  858. break;
  859. }
  860. }
  861. // 保存按钮状态改变
  862. //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData2);
  863. this.btnSave.Enabled = true;
  864. }
  865. }
  866. catch (Exception ex)
  867. {
  868. this.btnSave.Enabled = true;
  869. this.btnCancel.Enabled = true;
  870. // 对异常进行共通处理
  871. ExceptionManager.HandleEventException(this.ToString(),
  872. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  873. }
  874. }
  875. private void chkFunctionSelect2_CheckedChanged(object sender, EventArgs e)
  876. {
  877. try
  878. {
  879. this._needActionCheck2 = false;
  880. foreach (DataRow dataRow in _userFunctionRightData2.Tables[0].Rows)
  881. {
  882. dataRow["Choose"] = this.chkFunctionSelect2.Checked;
  883. }
  884. TreeNodeCollection nodes = this.tvwFunction2.Nodes;
  885. foreach (TreeNode node in nodes)
  886. {
  887. node.Checked = this.chkFunctionSelect2.Checked;
  888. CheckSubNodes(node, this.chkFunctionSelect2.Checked);
  889. }
  890. this._needActionCheck2 = true;
  891. // 保存按钮状态改变
  892. //this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData2);
  893. this.btnSave.Enabled = true;
  894. }
  895. catch (Exception ex)
  896. {
  897. // 对异常进行共通处理
  898. ExceptionManager.HandleEventException(this.ToString(),
  899. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  900. }
  901. }
  902. private void btnFunctionExpandAll2_Click(object sender, EventArgs e)
  903. {
  904. this.tvwFunction2.ExpandAll();
  905. }
  906. private void btnFunctionCollapseAll2_Click(object sender, EventArgs e)
  907. {
  908. this.tvwFunction2.CollapseAll();
  909. }
  910. private void chkFunctionCodeAll2_CheckedChanged(object sender, EventArgs e)
  911. {
  912. //try
  913. //{
  914. // if (!this.btnSave.Enabled)
  915. // {
  916. // if ((chkFunctionCodeAll2.Checked && !this.isFunctionCodeAll2) || (!chkFunctionCodeAll2.Checked && this.isFunctionCodeAll2))
  917. // {
  918. // // 保存按钮状态改变
  919. // this.btnSave.Enabled = true;
  920. // }
  921. // else
  922. // {
  923. // this.btnSave.Enabled = false;
  924. // }
  925. // }
  926. // else
  927. // {
  928. // if(!chkFunctionCodeAll2.Checked)
  929. // {
  930. // // 保存按钮状态改变
  931. // this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData2);
  932. // }
  933. // }
  934. // this.btnSave.Enabled = true;
  935. //}
  936. //catch (Exception ex)
  937. //{
  938. // // 对异常进行共通处理
  939. // ExceptionManager.HandleEventException(this.ToString(),
  940. // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  941. //}
  942. }
  943. }
  944. }