版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

116 строки
4.4 KiB

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