F_MST_0206.cs 44 KB

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