frmRole.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Code.Extends;
  3. using NXWMS.Client.Model.AppModels.Condition;
  4. using NXWMS.Client.Model.AppModels.Condition.SysSettings;
  5. using NXWMS.Client.Model.AppModels.Result;
  6. using NXWMS.Client.Model.AppModels.Result.SysSettings;
  7. using NXWMS.Client.Model.CoreModels;
  8. using NXWMS.Client.String.Enums;
  9. using NXWMS.Commons;
  10. using NXWMS.Services;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Data;
  15. using System.Drawing;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Windows.Forms;
  19. namespace NXWMS.Forms.SysSettings
  20. {
  21. public partial class frmRole : KryptonForm
  22. {
  23. /// <summary>
  24. /// 界面最后执行操作
  25. /// </summary>
  26. private EnumOperation _LastOperation;
  27. /// <summary>
  28. /// 窗体类名
  29. /// </summary>
  30. private string _CrrentClassName;
  31. /// <summary>
  32. /// 客户端字段排序列表
  33. /// </summary>
  34. private List<ClientFieldOrderResult> _clientFieldOrderList;
  35. /// <summary>
  36. /// 菜单层级列表
  37. /// </summary>
  38. private List<MenuLevelResult> _menuLevelList;
  39. /// <summary>
  40. /// 选择行主键列表
  41. /// </summary>
  42. private List<string> _CheckRowIdList = new List<string>();
  43. /// <summary>
  44. /// 当前页面操作的主键
  45. /// </summary>
  46. private string _PrimaryKey = "ROLE_ID";
  47. public frmRole()
  48. {
  49. InitializeComponent();
  50. _CrrentClassName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName;
  51. InitData();
  52. InitControl();
  53. }
  54. protected override CreateParams CreateParams
  55. {
  56. get
  57. {
  58. CreateParams cp = base.CreateParams;
  59. cp.ExStyle |= 0x02000000;
  60. return cp;
  61. }
  62. }
  63. /// <summary>
  64. /// 控件初始化
  65. /// </summary>
  66. private void InitControl()
  67. {
  68. CheckForIllegalCrossThreadCalls = false;
  69. //groupOperation.LostFocus += new EventHandler(groupOperation_LostFocus);
  70. //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus);
  71. //界面数据初始化
  72. dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick);
  73. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  74. //菜单列表添加
  75. //treeViewMainMenu.Scrollable = true;
  76. //treeViewMainMenu.ShowPlusMinus = true;
  77. //treeViewMainMenu.ShowRootLines = true;
  78. //treeViewMainMenu.Nodes.Clear();
  79. var menuList = _menuLevelList.Where((x, i) => _menuLevelList.FindIndex(z => z.MainMenuId == x.MainMenuId) == i).Distinct().ToList();
  80. foreach (var item in (from x in menuList
  81. select new
  82. { x.MainMenuId, x.MainMenuName, x.MainMenuCode, x.MainMenuOrder, x.MainMenuURL }).Distinct())
  83. {
  84. var newTreeNode = new TreeNode
  85. {
  86. Checked = true,
  87. Name = item.MainMenuId.ToString(),
  88. Text = item.MainMenuName,
  89. };
  90. newTreeNode.Checked = false;
  91. //var f1 = treeViewMainMenu.Nodes.Add(newTreeNode);
  92. }
  93. //treeViewMainMenu.ExpandAll();
  94. //treeViewMainMenu.NodeMouseDoubleClick += new
  95. // TreeNodeMouseClickEventHandler(TreeMainMenuNodeDoubleClick);
  96. //暂时用代码限制长度,不用表配置之类做了..
  97. txtSearchRoleCode.SetControlBase(50);
  98. txtSearchRoleName.SetControlBase(100);
  99. //txtRoleCode.SetControlBase(50);
  100. //txtRoleName.SetControlBase(100);
  101. _pageSize = 20;
  102. _pageIndex = 1;
  103. }
  104. /// <summary>
  105. /// 选中授权
  106. /// </summary>
  107. private RolePermissionResult _selectRolePermission;
  108. /// <summary>
  109. /// 主菜单双击
  110. /// </summary>
  111. /// <param name="sender"></param>
  112. /// <param name="e"></param>
  113. public void TreeMainMenuNodeDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
  114. {
  115. var menuView = sender as KryptonTreeView;
  116. var selectedNode = menuView.SelectedNode;
  117. if (selectedNode == null)
  118. {
  119. return;
  120. }
  121. //菜单列表添加
  122. //treeViewMenu.Scrollable = true;
  123. //treeViewMenu.ShowPlusMinus = true;
  124. //treeViewMenu.ShowRootLines = true;
  125. //treeViewMenu.Nodes.Clear();
  126. _selectMainMenuIndex = e.Node.Index;
  127. foreach (var item in (from x in _menuLevelList.Where(m => m.MainMenuId == int.Parse(selectedNode.Name))
  128. select new
  129. { x.MenuCode, x.MenuName, x.MenuId, x.MenuOrder, x.MenuURL }).Distinct())
  130. {
  131. var newTreeNode = new TreeNode
  132. {
  133. Checked = true,
  134. Name = item.MenuId.ToString(),
  135. Text = item.MenuName,
  136. };
  137. newTreeNode.Checked = false;
  138. //var f1 = treeViewMenu.Nodes.Add(newTreeNode);
  139. }
  140. //treeViewMenu.ExpandAll();
  141. //授权打勾
  142. if (!_menuCheckList.Any())
  143. {
  144. _selectRolePermission = SysSettingsServices.roleService.GetPermissionInfo(new RolePermissionCondition
  145. {
  146. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  147. RoleId = _selectRoleId,
  148. }).Data;
  149. //foreach (TreeNode item in treeViewMainMenu.Nodes)
  150. //{
  151. // item.Checked = false;
  152. //}
  153. //foreach (TreeNode item in treeViewMenu.Nodes)
  154. //{
  155. // item.Checked = false;
  156. //}
  157. //foreach (var item in _selectRolePermission.RoleMenuList.Where(m => m.MainMenuId != null).Distinct().ToList())
  158. //{
  159. // if (treeViewMainMenu.Nodes[item.MainMenuId.Value.ToString()] != null)
  160. // {
  161. // treeViewMainMenu.Nodes[item.MainMenuId.Value.ToString()].Checked = true;
  162. // }
  163. // if (treeViewMenu.Nodes[item.MainMenuId.Value.ToString()] != null)
  164. // {
  165. // treeViewMenu.Nodes[item.MainMenuId.Value.ToString()].Checked = true;
  166. // }
  167. //}
  168. }
  169. else
  170. {
  171. //foreach (TreeNode item in treeViewMenu.Nodes)
  172. //{
  173. // item.Checked = false;
  174. //}
  175. //foreach (var item in _menuCheckList)
  176. //{
  177. // if (treeViewMenu.Nodes[item.ToString()] != null)
  178. // {
  179. // treeViewMenu.Nodes[item.ToString()].Checked = true;
  180. // }
  181. //}
  182. }
  183. //treeViewMenu.NodeMouseDoubleClick += new
  184. // TreeNodeMouseClickEventHandler(TreeMenuNodeDoubleClick);
  185. }
  186. /// <summary>
  187. /// 菜单双击
  188. /// </summary>
  189. /// <param name="sender"></param>
  190. /// <param name="e"></param>
  191. public void TreeMenuNodeDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
  192. {
  193. var menuView = sender as KryptonTreeView;
  194. var selectedNode = menuView.SelectedNode;
  195. if (selectedNode == null)
  196. {
  197. return;
  198. }
  199. _selectMenuIndex = e.Node.Index;
  200. //菜单列表添加
  201. //treeViewFunction.Scrollable = true;
  202. //treeViewFunction.ShowPlusMinus = true;
  203. //treeViewFunction.ShowRootLines = true;
  204. //treeViewFunction.Nodes.Clear();
  205. foreach (var item in (from x in _menuLevelList.Where(m => m.MenuId == int.Parse(selectedNode.Name) && m.FunctionCode != null)
  206. select new
  207. { x.FunctionCode, x.FunctionName, x.FunctionId, x.FunctionOrder, x.FunctionURL }).Distinct())
  208. {
  209. var newTreeNode = new TreeNode
  210. {
  211. Checked = true,
  212. Name = item.FunctionId.ToString(),
  213. Text = item.FunctionName,
  214. };
  215. newTreeNode.Checked = false;
  216. //var f1 = treeViewFunction.Nodes.Add(newTreeNode);
  217. }
  218. //treeViewFunction.ExpandAll();
  219. //foreach (TreeNode item in treeViewFunction.Nodes)
  220. //{
  221. // item.Checked = false;
  222. //}
  223. //授权打勾
  224. if (!_menuCheckList.Any())
  225. {
  226. var menuList = _selectRolePermission;
  227. foreach (var item in menuList.RoleMenuList.Where(m => m.MainMenuId != null))
  228. {
  229. //if (treeViewFunction.Nodes[item.MainMenuId.Value.ToString()] != null)
  230. //{
  231. // treeViewFunction.Nodes[item.MainMenuId.Value.ToString()].Checked = true;
  232. //}
  233. }
  234. }
  235. else
  236. {
  237. foreach (var item in _menuCheckList)
  238. {
  239. //if (treeViewFunction.Nodes[item.ToString()] != null)
  240. //{
  241. // treeViewFunction.Nodes[item.ToString()].Checked = true;
  242. //}
  243. }
  244. }
  245. }
  246. /// <summary>
  247. /// 获取授权菜单列表
  248. /// </summary>
  249. /// <returns></returns>
  250. private List<int> GetPermissionMenuIdList()
  251. {
  252. var permissionList = new List<int>();
  253. //foreach (TreeNode item in treeViewMainMenu.Nodes)
  254. //{
  255. // if (item.Checked)
  256. // {
  257. // permissionList.Add(Convert.ToInt32(item.Name));
  258. // }
  259. //}
  260. //foreach (TreeNode item in treeViewMenu.Nodes)
  261. //{
  262. // if (item.Checked)
  263. // {
  264. // permissionList.Add(Convert.ToInt32(item.Name));
  265. // }
  266. //}
  267. //foreach (TreeNode item in treeViewFunction.Nodes)
  268. //{
  269. // if (item.Checked)
  270. // {
  271. // permissionList.Add(Convert.ToInt32(item.Name));
  272. // }
  273. //}
  274. return permissionList;
  275. }
  276. /// <summary>
  277. /// 数据初始化
  278. /// </summary>
  279. private void InitData()
  280. {
  281. //获取数据源配置
  282. var result = ConfigServices.configService.GetDataViewOrderList(new ClientFieldOrderCondition { SourceCode = $"{_CrrentClassName}" });
  283. if (result.Status == OperateStatus.Success)
  284. {
  285. _clientFieldOrderList = result.Data;
  286. }
  287. //获取菜单层级
  288. var menuResult = SysSettingsServices.menuService.GetLevelList(new MenuLevelCondition { });
  289. if (menuResult.Status == OperateStatus.Success)
  290. {
  291. _menuLevelList = menuResult.Data;
  292. }
  293. _menuCheckList = new List<int>();
  294. }
  295. /// <summary>
  296. /// ESC撤销此次编辑操作
  297. /// </summary>
  298. /// <param name="msg"></param>
  299. /// <param name="keyData"></param>
  300. /// <returns></returns>
  301. protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  302. {
  303. int WM_KEYDOWN = 256;
  304. int WM_SYSKEYDOWN = 260;
  305. if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
  306. {
  307. switch (keyData)
  308. {
  309. case Keys.Escape:
  310. //if (groupOperation.Visible)
  311. //{
  312. // btnExit_Click(null, null);
  313. //}
  314. break;
  315. }
  316. }
  317. return false;
  318. }
  319. private void groupOperation_LostFocus(object sender, EventArgs e)
  320. {
  321. }
  322. private void groupOperation_GostFocus(object sender, EventArgs e)
  323. {
  324. //groupOperation.Values.Heading = _LastOperation.Display();
  325. //groupOperation.Values.Image = Image.FromFile(_LastOperation.ImagePath());
  326. //groupOperation.Text = $"{ _LastOperation.Display()}数据";
  327. //lbStatusMessage.Visible = true;
  328. }
  329. private int _pageSize;
  330. private int _pageIndex;
  331. private int _totalCount;
  332. private void btnSearch_Click(object sender, EventArgs e)
  333. {
  334. _pageIndex = 1;
  335. var loadfrm = new frmLoading();
  336. loadfrm.Show();
  337. var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize);
  338. pageTool.DataCount = _totalCount;
  339. if (!string.IsNullOrWhiteSpace(message))
  340. {
  341. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  342. }
  343. }
  344. private string LoadSearch(int pageIndex, int pageSize)
  345. {
  346. var result = SysSettingsServices.roleService.GetList(new RoleSearchCondition
  347. {
  348. RoleCode = txtSearchRoleCode.Text,
  349. RoleName = txtSearchRoleName.Text,
  350. PageIndex = pageIndex,
  351. PageSize = pageSize,
  352. IsUsed = chkSearchUse.Checked,
  353. });
  354. if (result.Status == OperateStatus.Success)
  355. {
  356. _totalCount = result.Data.TotalCount;
  357. _pageIndex = pageIndex;
  358. _pageSize = pageSize;
  359. if (result.Data.RowData.Any())
  360. {
  361. dataGridView.Columns.Clear();
  362. dataGridView.DataSource = result.Data.RowData.ToList();
  363. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
  364. }
  365. else
  366. {
  367. if (dataGridView.DataSource != null)
  368. {
  369. dataGridView.DataSource = new List<RoleResult>();
  370. }
  371. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  372. }
  373. return string.Empty;
  374. }
  375. else
  376. {
  377. return result.Message;
  378. }
  379. }
  380. private void btnAdd_Click(object sender, EventArgs e)
  381. {
  382. //if (!groupOperation.Visible)
  383. //{
  384. var frm = new ChildFrm.frmRoleEdit();
  385. frm.LastOperation = EnumOperation.Add;
  386. frm.tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
  387. frm.MenuLevelList = this._menuLevelList;
  388. frm.InitControl();
  389. if (frm.ShowDialog() == DialogResult.OK)
  390. {
  391. this.btnSearch_Click(null, null);
  392. }
  393. //richDescibe.Text = "";
  394. //_LastOperation = EnumOperation.Add;
  395. //txtRoleCode.Enabled = true;
  396. //kryptonNavigatorOperation.SelectedPage = kryptonPageInfo;
  397. //groupOperation.Visible = true;
  398. //groupOperation.Focus();
  399. //}
  400. }
  401. private int _selectIndex;
  402. private int _selectRoleId;
  403. private void btnEdit_Click(object sender, EventArgs e)
  404. {
  405. dataGridView_CellDoubleClick(null, null);
  406. }
  407. private void btnRemove_Click(object sender, EventArgs e)
  408. {
  409. if (_CheckRowIdList.Count == 0)
  410. {
  411. return;
  412. }
  413. if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  414. {
  415. _LastOperation = EnumOperation.Remove;
  416. var editResult = SysSettingsServices.roleService.Deleted(new RoleCondition
  417. {
  418. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  419. RoleIds = string.Join(",", _CheckRowIdList)
  420. });
  421. if (editResult.Status == OperateStatus.Success)
  422. {
  423. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  424. //groupOperation.Visible = false;
  425. btnSearch_Click(null, null);
  426. }
  427. }
  428. }
  429. private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  430. {
  431. SelectInit();
  432. if (_selectIndex >= 0)
  433. {
  434. var frm = new ChildFrm.frmRoleEdit();
  435. frm.LastOperation = EnumOperation.Edit;
  436. //txtRoleCode.Enabled = false;
  437. //kryptonNavigatorOperation.SelectedPage = kryptonPageInfo;
  438. frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  439. //richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  440. //dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  441. //groupOperation.Visible = true;
  442. _selectRolePermission = SysSettingsServices.roleService.GetPermissionInfo(new RolePermissionCondition
  443. {
  444. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  445. RoleId = _selectRoleId,
  446. }).Data;
  447. var menuList = _selectRolePermission;
  448. foreach (var item in menuList.RoleMenuList.Where(m => m.MainMenuId != null))
  449. {
  450. if (frm.treeViewMainMenu.Nodes[item.MainMenuId.Value.ToString()] != null)
  451. {
  452. frm. treeViewMainMenu.Nodes[item.MainMenuId.Value.ToString()].Checked = true;
  453. }
  454. }
  455. if (frm.ShowDialog()==DialogResult.OK)
  456. {
  457. this.btnSearch_Click(null, null);
  458. }
  459. }
  460. }
  461. private void SelectInit()
  462. {
  463. _selectIndex = dataGridView.SelectedRows[0].Index;
  464. if (_selectIndex >= 0)
  465. {
  466. _selectRoleId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  467. }
  468. }
  469. //private void btnSave_Click(object sender, EventArgs e)
  470. //{
  471. // if (string.IsNullOrWhiteSpace(txtRoleCode.Text))
  472. // {
  473. // KryptonMessageBox.Show($"请输入角色编码。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  474. // return;
  475. // }
  476. // if (string.IsNullOrWhiteSpace(txtRoleName.Text))
  477. // {
  478. // KryptonMessageBox.Show($"请输入角色名称。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  479. // return;
  480. // }
  481. // _menuCheckList = new List<int>();
  482. // switch (_LastOperation)
  483. // {
  484. // case EnumOperation.Add:
  485. // var addResult = SysSettingsServices.roleService.Add(new RoleCondition
  486. // {
  487. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  488. // IsUsed = chkUse.Checked,
  489. // RoleCode = txtRoleCode.Text,
  490. // RoleName = txtRoleName.Text,
  491. // Describe = richDescibe.Text,
  492. // PermissionMenuIdList = GetPermissionMenuIdList(),
  493. // });
  494. // if (addResult.Status == OperateStatus.Success)
  495. // {
  496. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  497. // groupOperation.Visible = false;
  498. // btnSearch_Click(null, null);
  499. // dataGridView.ClearSelection();
  500. // }
  501. // else
  502. // {
  503. // KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  504. // }
  505. // break;
  506. // case EnumOperation.Edit:
  507. // var editResult = SysSettingsServices.roleService.Edit(new RoleCondition
  508. // {
  509. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  510. // IsUsed = chkUse.Checked,
  511. // RoleCode = txtRoleCode.Text,
  512. // RoleName = txtRoleName.Text,
  513. // RoleId = _selectRoleId,
  514. // Describe = richDescibe.Text,
  515. // PermissionMenuIdList = GetPermissionMenuIdList(),
  516. // });
  517. // if (editResult.Status == OperateStatus.Success)
  518. // {
  519. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  520. // groupOperation.Visible = false;
  521. // btnSearch_Click(null, null);
  522. // dataGridView.ClearSelection();
  523. // }
  524. // else
  525. // {
  526. // KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  527. // }
  528. // break;
  529. // }
  530. //}
  531. private void btnExit_Click(object sender, EventArgs e)
  532. {
  533. if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()} 数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  534. {
  535. _menuCheckList = new List<int>();
  536. //groupOperation.Visible = false;
  537. }
  538. else
  539. {
  540. //groupOperation.Visible = true;
  541. //groupOperation.Focus();
  542. }
  543. }
  544. private Point mouse_offset;
  545. private void groupOperation_MouseDown(object sender, MouseEventArgs e)
  546. {
  547. mouse_offset = new Point(-e.X, -e.Y);
  548. }
  549. private void groupOperation_MouseMove(object sender, MouseEventArgs e)
  550. {
  551. ((Control)sender).Cursor = Cursors.Arrow;
  552. if (e.Button == MouseButtons.Left)
  553. {
  554. Point mousePos = MousePosition;
  555. mousePos.Offset(mouse_offset.X, mouse_offset.Y);
  556. ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
  557. Application.DoEvents();
  558. }
  559. }
  560. private void btnSearchExport_Click(object sender, EventArgs e)
  561. {
  562. this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault()}列表" + DateTime.Now.ToString("yyyyMMddHH"));
  563. }
  564. private int _selectMainMenuIndex;
  565. private int _selectMenuIndex;
  566. private int _selectFunctionIndex;
  567. /// <summary>
  568. /// 选中的所有菜单
  569. /// </summary>
  570. private List<int> _menuCheckList;
  571. private void treeViewMainMenu_AfterCheck(object sender, TreeViewEventArgs e)
  572. {
  573. if (e.Action == TreeViewAction.ByMouse)
  574. {
  575. //foreach (TreeNode child in treeViewMenu.Nodes)
  576. //{
  577. // child.Checked = e.Node.Checked;
  578. // if (!_menuCheckList.Where(s => s == int.Parse(child.Name)).Any())
  579. // {
  580. // if (child.Checked)
  581. // {
  582. // _menuCheckList.Add(int.Parse(child.Name));
  583. // }
  584. // }
  585. // else
  586. // {
  587. // if (!child.Checked)
  588. // {
  589. // _menuCheckList.Remove(int.Parse(child.Name));
  590. // }
  591. // }
  592. //}
  593. }
  594. }
  595. private void treeViewMenu_AfterCheck(object sender, TreeViewEventArgs e)
  596. {
  597. if (e.Action == TreeViewAction.ByMouse)
  598. {
  599. //foreach (TreeNode child in treeViewFunction.Nodes)
  600. //{
  601. // child.Checked = e.Node.Checked;
  602. // if (!_menuCheckList.Where(s => s == int.Parse(child.Name)).Any())
  603. // {
  604. // if (child.Checked)
  605. // {
  606. // _menuCheckList.Add(int.Parse(child.Name));
  607. // }
  608. // }
  609. // else
  610. // {
  611. // if (!child.Checked)
  612. // {
  613. // _menuCheckList.Remove(int.Parse(child.Name));
  614. // }
  615. // }
  616. //}
  617. int index = 0;
  618. //foreach (TreeNode child in treeViewMenu.Nodes)
  619. //{
  620. // if (child.Checked)
  621. // {
  622. // index++;
  623. // }
  624. //}
  625. //if (index > 0)
  626. //{
  627. // treeViewMainMenu.Nodes[_selectMainMenuIndex].Checked = true;
  628. //}
  629. //else
  630. //{
  631. // treeViewMainMenu.Nodes[_selectMainMenuIndex].Checked = false;
  632. //}
  633. }
  634. }
  635. private void treeViewFunction_AfterCheck(object sender, TreeViewEventArgs e)
  636. {
  637. if (e.Action == TreeViewAction.ByMouse)
  638. {
  639. _selectFunctionIndex = e.Node.Index;
  640. int index = 0;
  641. //foreach (TreeNode child in treeViewFunction.Nodes)
  642. //{
  643. // if (child.Checked)
  644. // {
  645. // index++;
  646. // }
  647. // if (!_menuCheckList.Where(s => s == int.Parse(child.Name)).Any())
  648. // {
  649. // if (child.Checked)
  650. // {
  651. // _menuCheckList.Add(int.Parse(child.Name));
  652. // }
  653. // }
  654. // else
  655. // {
  656. // if (!child.Checked)
  657. // {
  658. // _menuCheckList.Remove(int.Parse(child.Name));
  659. // }
  660. // }
  661. //}
  662. //if (index > 0)
  663. //{
  664. // treeViewMenu.Nodes[_selectMenuIndex].Checked = true;
  665. //}
  666. //else
  667. //{
  668. // treeViewMenu.Nodes[_selectMenuIndex].Checked = false;
  669. //}
  670. //index = 0;
  671. //foreach (TreeNode child in treeViewMenu.Nodes)
  672. //{
  673. // if (child.Checked)
  674. // {
  675. // index++;
  676. // }
  677. //}
  678. //if (index > 0)
  679. //{
  680. // treeViewMainMenu.Nodes[_selectMainMenuIndex].Checked = true;
  681. //}
  682. //else
  683. //{
  684. // treeViewMainMenu.Nodes[_selectMainMenuIndex].Checked = false;
  685. //}
  686. }
  687. }
  688. private void dataGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
  689. {
  690. e.Row.HeaderCell.Value = string.Format("{0}", (_pageIndex - 1) * _pageSize + e.Row.Index + 1);
  691. }
  692. private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
  693. {
  694. if (e.RowIndex >= 0 && e.ColumnIndex == 0)
  695. {
  696. if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
  697. {
  698. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  699. {
  700. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  701. }
  702. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  703. }
  704. else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
  705. {
  706. if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  707. {
  708. _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  709. }
  710. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
  711. }
  712. else
  713. {
  714. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  715. {
  716. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  717. }
  718. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  719. }
  720. }
  721. }
  722. private void pageTool_OnPageChange(int PageIndex, int PageSzie)
  723. {
  724. this.btnSearch_Click(null, null);
  725. }
  726. private void btnClear_Click(object sender, EventArgs e)
  727. {
  728. this.txtSearchRoleCode.Text = "";
  729. this.txtSearchRoleName.Text = "";
  730. this.chkSearchUse.Checked = true;
  731. }
  732. }
  733. }