using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using UAS_MES.CustomControl.DataGrid_View; using UAS_MES.DataOperate; using UAS_MES.Entity; using UAS_MES.PublicMethod; namespace UAS_MES.Employee { public partial class Employee_ChooseUserToGroup : Form { DataHelper dh; DataTable dt; LogStringBuilder sql = new LogStringBuilder(); AutoSizeFormClass asc = new AutoSizeFormClass(); public Employee_ChooseUserToGroup() { InitializeComponent(); } public Employee_ChooseUserToGroup(string GroupCode) { InitializeComponent(); } public Employee_ChooseUserToGroup(string GroupCode, string GroupName) { InitializeComponent(); ug_code_title.Text = GroupCode; ug_name_title.Text = GroupName; em_code2.KeyDown += KeyDownEvent; em_name2.KeyDown += KeyDownEvent; em_name3.KeyDown += KeyDownEvent; em_code3.KeyDown += KeyDownEvent; } private void 人员选择_Load(object sender, EventArgs e) { dh = SystemInf.dh; //组内人员添加全选列 DataGridViewCheckBoxColumn dgvc = new DataGridViewCheckBoxColumn(); dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; dgvc.Width = 90; dgvc.Name = "全选"; DataGridViewCheckBoxHeaderCell ch1 = new DataGridViewCheckBoxHeaderCell(InGroupUser, dgvc); dgvc.HeaderCell = ch1; this.InGroupUser.Columns.Insert(0, dgvc); //组外人员添加全选列 DataGridViewCheckBoxColumn dgvc1 = new DataGridViewCheckBoxColumn(); dgvc1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; dgvc1.Width = 90; dgvc1.Name = "全选"; DataGridViewCheckBoxHeaderCell ch2 = new DataGridViewCheckBoxHeaderCell(OutGroupUser, dgvc1); dgvc1.HeaderCell = ch2; this.OutGroupUser.Columns.Insert(0, dgvc1); //组内人员用户编号放大镜 em_code3.FormName = Name; em_code3.TableName = "employee"; em_code3.SelectField = "em_code # 用户编号,em_name # 用户姓名,em_depart # 部门,em_position # 岗位,em_indate # 入职日期"; em_code3.SetValueField = new string[] { "em_code3", "em_name3" }; //组外人员用户编号放大镜 em_code2.FormName = Name; em_code2.TableName = "employee"; em_code2.SelectField = "em_code # 用户编号,em_name # 用户姓名,em_depart # 部门,em_position # 岗位,em_indate # 入职日期"; em_code2.SetValueField = new string[] { "em_code2", "em_name2" }; if (em_name3.Text != "" || ug_code_title.Text != "") ScreenInGroup.PerformClick(); ScreenOutGroup.PerformClick(); asc.controllInitializeSize(this); } private void UserIn_Click(object sender, EventArgs e) { List MoveInUserCode = new List(); for (int i = 0; i < OutGroupUser.Rows.Count; i++) { if (OutGroupUser.Rows[i].Cells["全选"].FormattedValue.ToString() == "True") MoveInUserCode.Add(OutGroupUser.Rows[i].Cells["em_code1"].Value.ToString()); } //存在修改的数据 if (MoveInUserCode.ToArray().Length > 0) { string ConfirmAdd = MessageBox.Show(this.ParentForm, "确认添加所选人员到分组?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (ConfirmAdd == "Yes") { string ug_id = dh.getFieldDataByCondition("CS$USERGROUP", "ug_id", "ug_code='"+ ug_code_title.Text + "'").ToString(); sql.Clear(); sql.Append("insert into cs$empgroup (eg_id,eg_emcode,eg_groupcode,eg_name,eg_groupid)"); sql.Append("values (cs$empgroup_seq.nextval,:em_code,'" + ug_code_title.Text + "','" + em_name3.Text + "','"+ ug_id + "')"); dh.BatchInsert(sql.GetString(), new string[] { "em_code", }, MoveInUserCode.ToArray()); ScreenInGroup.PerformClick(); ScreenOutGroup.PerformClick(); } } else MessageBox.Show("请先勾选人员"); } private void UserOut_Click(object sender, EventArgs e) { List MoveOutUserID = new List(); for (int i = 0; i < InGroupUser.Rows.Count; i++) { if (InGroupUser.Rows[i].Cells["全选"].FormattedValue.ToString() == "True") MoveOutUserID.Add(InGroupUser.Rows[i].Cells["eg_id"].Value.ToString()); } if (MoveOutUserID.ToArray().Length > 0) { string ConfirmRemove = MessageBox.Show(this.ParentForm, "确认移除所选人员?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (ConfirmRemove == "Yes") { dh.BatchInsert("delete from cs$empgroup where eg_id=:eg_id", new string[] { "eg_id" }, MoveOutUserID.ToArray()); ScreenInGroup.PerformClick(); ScreenOutGroup.PerformClick(); } } else MessageBox.Show("请先勾选人员"); } /// /// 组内人员筛选 /// /// /// private void ScreenInGroup_Click(object sender, EventArgs e) { sql.Clear(); sql.Append("select eg_id,em_code,em_name,em_indate,em_recorder from cs$empgroup "); sql.Append("left join employee on eg_emcode=em_code where em_code like "); sql.Append("'%" + em_code3.Text + "%' and em_name like '%" + em_name3.Text + "%' and eg_groupcode like '%" + ug_code_title.Text + "%'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); BaseUtil.FillDgvWithDataTable(InGroupUser, dt); ScreenOutGroup.PerformClick(); } /// /// 组外人员筛选 /// /// /// private void ScreenOutGroup_Click(object sender, EventArgs e) { sql.Clear(); sql.Append("select distinct em_code,em_name,em_position,em_depart,em_id from employee left join "); sql.Append("cs$empgroup on eg_emcode=em_code and eg_groupcode='" + ug_code_title.Text + "'"); if (ug_code_title.Text != "" || ug_name_title.Text != "") { sql.Append(" where "); if (ug_code_title.Text != "" && ug_name_title.Text == "") sql.Append("(eg_groupcode <> '" + ug_code_title.Text + "' or eg_groupcode is null)"); else if (ug_name_title.Text == "" && ug_name_title.Text != "") sql.Append("(eg_name <> '" + ug_name_title.Text + "' or eg_name is null)"); else if (ug_code_title.Text != "" && ug_name_title.Text != "") 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)"); } if (sql.GetString().Contains("where")) { string condition = BaseUtil.GetScreenSqlCondition(em_code2, em_name2); if (condition != "") sql.Append(" and " + condition.Replace("where", "")); } else sql.Append(BaseUtil.GetScreenSqlCondition(em_code2, em_name2)); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); BaseUtil.FillDgvWithDataTable(OutGroupUser, dt); } private void 人员选择_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void KeyDownEvent(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { Control c = (Control)sender; if (c.Name == "em_code3" || c.Name == "em_name3") ScreenInGroup.PerformClick(); else if (c.Name == "em_code2" || c.Name == "em_name2") ScreenOutGroup.PerformClick(); } } } }