革博士V2程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
5.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace GeBoShi.UI.User
  11. {
  12. public partial class RightMgrFrm : Form
  13. {
  14. RoleService _Service = new RoleService();
  15. private List<Right> _RightList;
  16. User _FatherUser;
  17. public RightMgrFrm(User fatherUser)
  18. {
  19. InitializeComponent();
  20. this.uiTitel1.ShowContrlBox(false, false, true);
  21. this.uiTitel1.FatherForm = this;
  22. dataGridView1.AutoGenerateColumns = false;
  23. dataGridView2.AutoGenerateColumns = false;
  24. _FatherUser = fatherUser;
  25. }
  26. private void InitDataView()
  27. {
  28. _RightList = _Service.GetRightItems();
  29. dataGridView2.DataSource = new BindingSource(_RightList, null);
  30. var list = _Service.GetListNav();
  31. //tsslCount.Text = $"共 {list.Count} 条记录";
  32. dataGridView1.DataSource = new BindingSource(list, null);
  33. }
  34. private void RightMgrFrm_Load(object sender, EventArgs e)
  35. {
  36. InitDataView();
  37. }
  38. private void tsbtnSave_Click(object sender, EventArgs e)
  39. {
  40. dataGridView2.CurrentCell = null;//更新当前编辑单元格
  41. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Role>;
  42. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  43. foreach (var item in _RightList)
  44. {
  45. if (list[liIndex].RightList.FirstOrDefault(m => m.Id == item.Id) == null)
  46. {
  47. if (item.check)
  48. list[liIndex].RightList.Add(item);
  49. }
  50. else
  51. {
  52. if (!item.check)
  53. list[liIndex].RightList.Remove(item);
  54. }
  55. }
  56. if (_Service.UpdateNav(list[liIndex]))
  57. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  58. else
  59. MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  60. }
  61. private void tsbtnAdd_Click(object sender, EventArgs e)
  62. {
  63. NewRoleFrm frm = new NewRoleFrm(_FatherUser);
  64. if (frm.ShowDialog() == DialogResult.OK)
  65. InitDataView();
  66. }
  67. private void tsbtnDel_Click(object sender, EventArgs e)
  68. {
  69. try
  70. {
  71. if (this.dataGridView1.CurrentRow == null)
  72. return;
  73. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Role>;
  74. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  75. if (MessageBox.Show($"确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  76. {
  77. if (!_Service.DelNav(list[liIndex]))
  78. throw new Exception("删除失败!");
  79. MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  80. InitDataView();
  81. }
  82. }
  83. catch (Exception ex)
  84. {
  85. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  86. }
  87. }
  88. private void tsbtnClose_Click(object sender, EventArgs e)
  89. {
  90. this.Close();
  91. }
  92. private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  93. {
  94. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Role>;
  95. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  96. NewRoleFrm frm = new NewRoleFrm(_FatherUser, list[liIndex]);
  97. if (frm.ShowDialog(this) == DialogResult.OK)
  98. InitDataView();
  99. }
  100. private void dataGridView1_SelectionChanged(object sender, EventArgs e)
  101. {
  102. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Role>;
  103. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  104. foreach (var item in _RightList)
  105. item.check = list[liIndex].RightList.FirstOrDefault(m => m.Id == item.Id) != null;
  106. dataGridView2.Refresh();
  107. }
  108. private void toolStrip1_Paint(object sender, PaintEventArgs e)
  109. {
  110. if ((sender as ToolStrip).RenderMode == ToolStripRenderMode.System)
  111. {
  112. Rectangle rect = new Rectangle(0, 0, this.toolStrip1.Width, this.toolStrip1.Height - 2);
  113. e.Graphics.SetClip(rect);
  114. }
  115. }
  116. }
  117. }