Employee_ChooseUserToGroup.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using System;
  2. using System.Collections;
  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.Windows.Forms;
  10. using UAS_MES.CustomControl.DataGrid_View;
  11. using UAS_MES.DataOperate;
  12. using UAS_MES.Entity;
  13. using UAS_MES.PublicMethod;
  14. namespace UAS_MES.Employee
  15. {
  16. public partial class Employee_ChooseUserToGroup : Form
  17. {
  18. DataHelper dh;
  19. DataTable dt;
  20. LogStringBuilder sql = new LogStringBuilder();
  21. AutoSizeFormClass asc = new AutoSizeFormClass();
  22. public Employee_ChooseUserToGroup()
  23. {
  24. InitializeComponent();
  25. }
  26. public Employee_ChooseUserToGroup(string GroupCode)
  27. {
  28. InitializeComponent();
  29. }
  30. public Employee_ChooseUserToGroup(string GroupCode, string GroupName)
  31. {
  32. InitializeComponent();
  33. ug_code_title.Text = GroupCode;
  34. ug_name_title.Text = GroupName;
  35. em_code2.KeyDown += KeyDownEvent;
  36. em_name2.KeyDown += KeyDownEvent;
  37. em_name3.KeyDown += KeyDownEvent;
  38. em_code3.KeyDown += KeyDownEvent;
  39. }
  40. private void 人员选择_Load(object sender, EventArgs e)
  41. {
  42. dh = SystemInf.dh;
  43. //组内人员添加全选列
  44. DataGridViewCheckBoxColumn dgvc = new DataGridViewCheckBoxColumn();
  45. dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
  46. dgvc.Width = 90;
  47. dgvc.Name = "全选";
  48. DataGridViewCheckBoxHeaderCell ch1 = new DataGridViewCheckBoxHeaderCell(InGroupUser, dgvc);
  49. dgvc.HeaderCell = ch1;
  50. this.InGroupUser.Columns.Insert(0, dgvc);
  51. //组外人员添加全选列
  52. DataGridViewCheckBoxColumn dgvc1 = new DataGridViewCheckBoxColumn();
  53. dgvc1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
  54. dgvc1.Width = 90;
  55. dgvc1.Name = "全选";
  56. DataGridViewCheckBoxHeaderCell ch2 = new DataGridViewCheckBoxHeaderCell(OutGroupUser, dgvc1);
  57. dgvc1.HeaderCell = ch2;
  58. this.OutGroupUser.Columns.Insert(0, dgvc1);
  59. //组内人员用户编号放大镜
  60. em_code3.FormName = Name;
  61. em_code3.TableName = "employee";
  62. em_code3.SelectField = "em_code # 用户编号,em_name # 用户姓名,em_depart # 部门,em_position # 岗位,em_indate # 入职日期";
  63. em_code3.SetValueField = new string[] { "em_code3", "em_name3" };
  64. //组外人员用户编号放大镜
  65. em_code2.FormName = Name;
  66. em_code2.TableName = "employee";
  67. em_code2.SelectField = "em_code # 用户编号,em_name # 用户姓名,em_depart # 部门,em_position # 岗位,em_indate # 入职日期";
  68. em_code2.SetValueField = new string[] { "em_code2", "em_name2" };
  69. if (em_name3.Text != "" || ug_code_title.Text != "")
  70. ScreenInGroup.PerformClick();
  71. ScreenOutGroup.PerformClick();
  72. asc.controllInitializeSize(this);
  73. }
  74. private void UserIn_Click(object sender, EventArgs e)
  75. {
  76. List<string> MoveInUserCode = new List<string>();
  77. for (int i = 0; i < OutGroupUser.Rows.Count; i++)
  78. {
  79. if (OutGroupUser.Rows[i].Cells["全选"].FormattedValue.ToString() == "True")
  80. MoveInUserCode.Add(OutGroupUser.Rows[i].Cells["em_code1"].Value.ToString());
  81. }
  82. //存在修改的数据
  83. if (MoveInUserCode.ToArray().Length > 0)
  84. {
  85. string ConfirmAdd = MessageBox.Show(this.ParentForm, "确认添加所选人员到分组?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  86. if (ConfirmAdd == "Yes")
  87. {
  88. string ug_id = dh.getFieldDataByCondition("CS$USERGROUP", "ug_id", "ug_code='"+ ug_code_title.Text + "'").ToString();
  89. sql.Clear();
  90. sql.Append("insert into cs$empgroup (eg_id,eg_emcode,eg_groupcode,eg_name,eg_groupid)");
  91. sql.Append("values (cs$empgroup_seq.nextval,:em_code,'" + ug_code_title.Text + "','" + em_name3.Text + "','"+ ug_id + "')");
  92. dh.BatchInsert(sql.GetString(), new string[] { "em_code", }, MoveInUserCode.ToArray());
  93. ScreenInGroup.PerformClick();
  94. ScreenOutGroup.PerformClick();
  95. }
  96. }
  97. else
  98. MessageBox.Show("请先勾选人员");
  99. }
  100. private void UserOut_Click(object sender, EventArgs e)
  101. {
  102. List<string> MoveOutUserID = new List<string>();
  103. for (int i = 0; i < InGroupUser.Rows.Count; i++)
  104. {
  105. if (InGroupUser.Rows[i].Cells["全选"].FormattedValue.ToString() == "True")
  106. MoveOutUserID.Add(InGroupUser.Rows[i].Cells["eg_id"].Value.ToString());
  107. }
  108. if (MoveOutUserID.ToArray().Length > 0)
  109. {
  110. string ConfirmRemove = MessageBox.Show(this.ParentForm, "确认移除所选人员?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  111. if (ConfirmRemove == "Yes")
  112. {
  113. dh.BatchInsert("delete from cs$empgroup where eg_id=:eg_id", new string[] { "eg_id" }, MoveOutUserID.ToArray());
  114. ScreenInGroup.PerformClick();
  115. ScreenOutGroup.PerformClick();
  116. }
  117. }
  118. else
  119. MessageBox.Show("请先勾选人员");
  120. }
  121. /// <summary>
  122. /// 组内人员筛选
  123. /// </summary>
  124. /// <param name="sender"></param>
  125. /// <param name="e"></param>
  126. private void ScreenInGroup_Click(object sender, EventArgs e)
  127. {
  128. sql.Clear();
  129. sql.Append("select eg_id,em_code,em_name,em_indate,em_recorder from cs$empgroup ");
  130. sql.Append("left join employee on eg_emcode=em_code where em_code like ");
  131. sql.Append("'%" + em_code3.Text + "%' and em_name like '%" + em_name3.Text + "%' and eg_groupcode like '%" + ug_code_title.Text + "%'");
  132. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  133. BaseUtil.FillDgvWithDataTable(InGroupUser, dt);
  134. ScreenOutGroup.PerformClick();
  135. }
  136. /// <summary>
  137. /// 组外人员筛选
  138. /// </summary>
  139. /// <param name="sender"></param>
  140. /// <param name="e"></param>
  141. private void ScreenOutGroup_Click(object sender, EventArgs e)
  142. {
  143. sql.Clear();
  144. sql.Append("select distinct em_code,em_name,em_position,em_depart,em_id from employee left join ");
  145. sql.Append("cs$empgroup on eg_emcode=em_code and eg_groupcode='" + ug_code_title.Text + "'");
  146. if (ug_code_title.Text != "" || ug_name_title.Text != "")
  147. {
  148. sql.Append(" where ");
  149. if (ug_code_title.Text != "" && ug_name_title.Text == "")
  150. sql.Append("(eg_groupcode <> '" + ug_code_title.Text + "' or eg_groupcode is null)");
  151. else if (ug_name_title.Text == "" && ug_name_title.Text != "")
  152. sql.Append("(eg_name <> '" + ug_name_title.Text + "' or eg_name is null)");
  153. else if (ug_code_title.Text != "" && ug_name_title.Text != "")
  154. sql.Append("(eg_groupcode <> '" + ug_code_title.Text + "'or eg_groupcode is null) and (eg_name <> '" + ug_name_title.Text + "' or eg_name is null)");
  155. }
  156. if (sql.GetString().Contains("where"))
  157. {
  158. string condition = BaseUtil.GetScreenSqlCondition(em_code2, em_name2);
  159. if (condition != "")
  160. sql.Append(" and " + condition.Replace("where", ""));
  161. }
  162. else
  163. sql.Append(BaseUtil.GetScreenSqlCondition(em_code2, em_name2));
  164. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  165. BaseUtil.FillDgvWithDataTable(OutGroupUser, dt);
  166. }
  167. private void 人员选择_SizeChanged(object sender, EventArgs e)
  168. {
  169. asc.controlAutoSize(this);
  170. }
  171. private void KeyDownEvent(object sender, KeyEventArgs e)
  172. {
  173. if (e.KeyCode == Keys.Enter)
  174. {
  175. Control c = (Control)sender;
  176. if (c.Name == "em_code3" || c.Name == "em_name3")
  177. ScreenInGroup.PerformClick();
  178. else if (c.Name == "em_code2" || c.Name == "em_name2")
  179. ScreenOutGroup.PerformClick();
  180. }
  181. }
  182. }
  183. }