using System; using System.Collections.Generic; using System.Data; using System.Windows.Forms; using UAS_MES_NEW.CustomControl.AccordionMenu; using UAS_MES_NEW.CustomControl.DataGrid_View; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.Employee { public partial class Employee_Group : Form { DataHelper dh; DataTable dt; DataTable Dbfind; DataTable Dbfind1; AutoSizeFormClass asc = new AutoSizeFormClass(); public Employee_Group() { InitializeComponent(); } private void 人员分组_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); dh = SystemInf.dh; //手动加入第一列全选列 DataGridViewCheckBoxColumn dgvc = new DataGridViewCheckBoxColumn(); dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; dgvc.Width = 90; dgvc.Name = "全选"; DataGridViewCheckBoxHeaderCell ch1 = new DataGridViewCheckBoxHeaderCell(UserGroupDGV, dgvc); dgvc.HeaderCell = ch1; this.UserGroupDGV.Columns.Insert(0, dgvc); ug_code.FormName = Name; ug_code.TableName = "CS$USERGROUP"; ug_code.SelectField = "ug_code # 分组编号,ug_name # 分组名称,ug_inman # 录入人,ug_indate #录入日期"; ug_code.SetValueField = new string[] { "ug_code" }; ug_code.DbChange += Ug_code_Dbchage; ug_name.FormName = Name; ug_name.TableName = "CS$USERGROUP"; ug_name.SelectField = "ug_code # 分组编号,ug_name # 分组名称,ug_inman # 录入人,ug_indate #录入日期"; ug_name.SetValueField = new string[] { "ug_name" }; ug_name.DbChange += Ug_name_Dbchage; ug_code.KeyDown += KeyDownEvent; ug_name.KeyDown += KeyDownEvent; } private void Ug_name_Dbchage(object sender, EventArgs e) { Dbfind = ug_name.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); } private void Ug_code_Dbchage(object sender, EventArgs e) { Dbfind1 = ug_code.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind1); } private void 人员分组_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void Screen_Click(object sender, EventArgs e) { 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"); BaseUtil.FillDgvWithDataTable(UserGroupDGV, dt); } private void DeleteGroup_Click(object sender, EventArgs e) { string ConfirmDelete = MessageBox.Show(this.ParentForm, "删除分组会一并删除组员和权限,确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (ConfirmDelete == "Yes") { //UserGroup的ID List DeleteID = new List(); //分组编号 List DeleteCode = new List(); for (int i = 0; i < UserGroupDGV.Rows.Count; i++) { if (UserGroupDGV.Rows[i].Cells["全选"].FormattedValue.ToString() == "True") { DeleteID.Add(UserGroupDGV.Rows[i].Cells["ug_id"].Value.ToString()); DeleteCode.Add(UserGroupDGV.Rows[i].Cells["ug_code"].Value.ToString()); } } dh.BatchInsert("delete from cs$usergroup where ug_id=:ug_id", new string[] { "ug_id" }, DeleteID.ToArray()); dh.BatchInsert("delete from cs$empgroup where eg_groupcode=:ug_code", new string[] { "ug_code" }, DeleteCode.ToArray()); dh.BatchInsert("delete from cs$usergrouppower where ugp_groupcode=:ug_code", new string[] { "ug_code" }, DeleteCode.ToArray()); MessageBox.Show("删除分组成功"); Screen.PerformClick(); } } private void NewGroup_Click(object sender, EventArgs e) { Employee_NewGroup NewWin = new Employee_NewGroup(); BaseUtil.SetFormCenter(NewWin); NewWin.FormClosed += Screen_Click; NewWin.ShowDialog(); } private void UserGroupDGV_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { string CallerUser = "Employee!DataGroup"; string CallerPower = "Employee!PowerGroup"; if (UserGroupDGV.Columns[e.ColumnIndex].Name == "UserSetting" && !AccordionMenu.OpenedFormName.ContainsKey(CallerUser)) { AccordionMenu.OpenedFormName.Add(CallerUser, 101); TabControl tc = (TabControl)this.Parent.Parent; TabPage tb = new TabPage { Name = CallerUser, Tag = CallerUser, Text = "人员查看" }; tc.TabPages.Add(tb); string ug_code = UserGroupDGV.Rows[e.RowIndex].Cells["ug_code1"].Value.ToString(); string ug_name = UserGroupDGV.Rows[e.RowIndex].Cells["ug_name1"].Value.ToString(); Employee_ChooseUserToGroup NewUser = new Employee_ChooseUserToGroup(ug_code, ug_name); NewUser.TopLevel = false; tc.SelectedTab = tb; tb.Controls.Add(NewUser); NewUser.WindowState = FormWindowState.Maximized; NewUser.Show(); } else if (UserGroupDGV.Columns[e.ColumnIndex].Name == "PowerSetting" && !AccordionMenu.OpenedFormName.ContainsKey(CallerPower)) { AccordionMenu.OpenedFormName.Add(CallerPower, 101); TabControl tc = (TabControl)this.Parent.Parent; //如果窗体不存在进行打开 TabPage tb = new TabPage { Tag = CallerPower, Name = CallerPower, Text = "权限控制" }; tc.TabPages.Add(tb); string ug_code = UserGroupDGV.Rows[e.RowIndex].Cells["ug_code1"].Value.ToString(); string ug_name = UserGroupDGV.Rows[e.RowIndex].Cells["ug_name1"].Value.ToString(); Employee_Power NewPower = new Employee_Power(ug_code, ug_name); NewPower.TopLevel = false; tc.SelectedTab = tb; tb.Controls.Add(NewPower); NewPower.WindowState = FormWindowState.Maximized; NewPower.Show(); } } } private void KeyDownEvent(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { Screen.PerformClick(); } } } }