Employee_Group.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Windows.Forms;
  5. using UAS_MES_NEW.CustomControl.AccordionMenu;
  6. using UAS_MES_NEW.CustomControl.DataGrid_View;
  7. using UAS_MES_NEW.DataOperate;
  8. using UAS_MES_NEW.Entity;
  9. using UAS_MES_NEW.PublicMethod;
  10. namespace UAS_MES_NEW.Employee
  11. {
  12. public partial class Employee_Group : Form
  13. {
  14. DataHelper dh;
  15. DataTable dt;
  16. DataTable Dbfind;
  17. DataTable Dbfind1;
  18. AutoSizeFormClass asc = new AutoSizeFormClass();
  19. public Employee_Group()
  20. {
  21. InitializeComponent();
  22. }
  23. private void 人员分组_Load(object sender, EventArgs e)
  24. {
  25. asc.controllInitializeSize(this);
  26. dh = SystemInf.dh;
  27. //手动加入第一列全选列
  28. DataGridViewCheckBoxColumn dgvc = new DataGridViewCheckBoxColumn();
  29. dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
  30. dgvc.Width = 90;
  31. dgvc.Name = "全选";
  32. DataGridViewCheckBoxHeaderCell ch1 = new DataGridViewCheckBoxHeaderCell(UserGroupDGV, dgvc);
  33. dgvc.HeaderCell = ch1;
  34. this.UserGroupDGV.Columns.Insert(0, dgvc);
  35. ug_code.FormName = Name;
  36. ug_code.TableName = "CS$USERGROUP";
  37. ug_code.SelectField = "ug_code # 分组编号,ug_name # 分组名称,ug_inman # 录入人,ug_indate #录入日期";
  38. ug_code.SetValueField = new string[] { "ug_code" };
  39. ug_code.DbChange += Ug_code_Dbchage;
  40. ug_name.FormName = Name;
  41. ug_name.TableName = "CS$USERGROUP";
  42. ug_name.SelectField = "ug_code # 分组编号,ug_name # 分组名称,ug_inman # 录入人,ug_indate #录入日期";
  43. ug_name.SetValueField = new string[] { "ug_name" };
  44. ug_name.DbChange += Ug_name_Dbchage;
  45. ug_code.KeyDown += KeyDownEvent;
  46. ug_name.KeyDown += KeyDownEvent;
  47. }
  48. private void Ug_name_Dbchage(object sender, EventArgs e)
  49. {
  50. Dbfind = ug_name.ReturnData;
  51. BaseUtil.SetFormValue(this.Controls, Dbfind);
  52. }
  53. private void Ug_code_Dbchage(object sender, EventArgs e)
  54. {
  55. Dbfind1 = ug_code.ReturnData;
  56. BaseUtil.SetFormValue(this.Controls, Dbfind1);
  57. }
  58. private void 人员分组_SizeChanged(object sender, EventArgs e)
  59. {
  60. asc.controlAutoSize(this);
  61. }
  62. private void Screen_Click(object sender, EventArgs e)
  63. {
  64. dt = (DataTable)dh.ExecuteSql("select ug_code,ug_id,ug_name,'查看组内成员' UserSetting,'权限分配' PowerSetting from cs$usergroup " + BaseUtil.GetScreenSqlCondition(ug_code, ug_name) + " order by ug_code", "select");
  65. BaseUtil.FillDgvWithDataTable(UserGroupDGV, dt);
  66. }
  67. private void DeleteGroup_Click(object sender, EventArgs e)
  68. {
  69. string ConfirmDelete = MessageBox.Show(this.ParentForm, "删除分组会一并删除组员和权限,确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  70. if (ConfirmDelete == "Yes")
  71. {
  72. //UserGroup的ID
  73. List<string> DeleteID = new List<string>();
  74. //分组编号
  75. List<string> DeleteCode = new List<string>();
  76. for (int i = 0; i < UserGroupDGV.Rows.Count; i++)
  77. {
  78. if (UserGroupDGV.Rows[i].Cells["全选"].FormattedValue.ToString() == "True")
  79. {
  80. DeleteID.Add(UserGroupDGV.Rows[i].Cells["ug_id"].Value.ToString());
  81. DeleteCode.Add(UserGroupDGV.Rows[i].Cells["ug_code"].Value.ToString());
  82. }
  83. }
  84. dh.BatchInsert("delete from cs$usergroup where ug_id=:ug_id", new string[] { "ug_id" }, DeleteID.ToArray());
  85. dh.BatchInsert("delete from cs$empgroup where eg_groupcode=:ug_code", new string[] { "ug_code" }, DeleteCode.ToArray());
  86. dh.BatchInsert("delete from cs$usergrouppower where ugp_groupcode=:ug_code", new string[] { "ug_code" }, DeleteCode.ToArray());
  87. MessageBox.Show("删除分组成功");
  88. Screen.PerformClick();
  89. }
  90. }
  91. private void NewGroup_Click(object sender, EventArgs e)
  92. {
  93. Employee_NewGroup NewWin = new Employee_NewGroup();
  94. BaseUtil.SetFormCenter(NewWin);
  95. NewWin.FormClosed += Screen_Click;
  96. NewWin.ShowDialog();
  97. }
  98. private void UserGroupDGV_CellClick(object sender, DataGridViewCellEventArgs e)
  99. {
  100. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  101. {
  102. string CallerUser = "Employee!DataGroup";
  103. string CallerPower = "Employee!PowerGroup";
  104. if (UserGroupDGV.Columns[e.ColumnIndex].Name == "UserSetting" && !AccordionMenu.OpenedFormName.ContainsKey(CallerUser))
  105. {
  106. AccordionMenu.OpenedFormName.Add(CallerUser, 101);
  107. TabControl tc = (TabControl)this.Parent.Parent;
  108. TabPage tb = new TabPage { Name = CallerUser, Tag = CallerUser, Text = "人员查看" };
  109. tc.TabPages.Add(tb);
  110. string ug_code = UserGroupDGV.Rows[e.RowIndex].Cells["ug_code1"].Value.ToString();
  111. string ug_name = UserGroupDGV.Rows[e.RowIndex].Cells["ug_name1"].Value.ToString();
  112. Employee_ChooseUserToGroup NewUser = new Employee_ChooseUserToGroup(ug_code, ug_name);
  113. NewUser.TopLevel = false;
  114. tc.SelectedTab = tb;
  115. tb.Controls.Add(NewUser);
  116. NewUser.WindowState = FormWindowState.Maximized;
  117. NewUser.Show();
  118. }
  119. else if (UserGroupDGV.Columns[e.ColumnIndex].Name == "PowerSetting" && !AccordionMenu.OpenedFormName.ContainsKey(CallerPower))
  120. {
  121. AccordionMenu.OpenedFormName.Add(CallerPower, 101);
  122. TabControl tc = (TabControl)this.Parent.Parent;
  123. //如果窗体不存在进行打开
  124. TabPage tb = new TabPage { Tag = CallerPower, Name = CallerPower, Text = "权限控制" };
  125. tc.TabPages.Add(tb);
  126. string ug_code = UserGroupDGV.Rows[e.RowIndex].Cells["ug_code1"].Value.ToString();
  127. string ug_name = UserGroupDGV.Rows[e.RowIndex].Cells["ug_name1"].Value.ToString();
  128. Employee_Power NewPower = new Employee_Power(ug_code, ug_name);
  129. NewPower.TopLevel = false;
  130. tc.SelectedTab = tb;
  131. tb.Controls.Add(NewPower);
  132. NewPower.WindowState = FormWindowState.Maximized;
  133. NewPower.Show();
  134. }
  135. }
  136. }
  137. private void KeyDownEvent(object sender, KeyEventArgs e)
  138. {
  139. if (e.KeyCode == Keys.Enter)
  140. {
  141. Screen.PerformClick();
  142. }
  143. }
  144. }
  145. }