/// <summary> /// 初始化方法 /// </summary> private void Bind() { try { if (department != null) { txtDepName.Text = department.NAME; if (string.IsNullOrEmpty(department.IMAGEID) == false) { imgPortrait.ResourceID = department.IMAGEID; imgPortrait.Refresh(); } btnLeader.Text = AutofacConfig.coreUserService.GetUserByID(department.MANAGER).USER_NAME; List <DataGridviewbyUser> listUser = new List <DataGridviewbyUser>(); List <coreUser> listDepUser = AutofacConfig.coreUserService.GetAll();//获取分配部门人员 //部门创建时ListView绑定数据 if (string.IsNullOrEmpty(department.DEPARTMENTID) == true) { if (listDepUser.Count > 0) { //将未分配部门且不是当前部门责任人的用户,添加到listUser中 foreach (coreUser user in listDepUser) { if ((string.IsNullOrEmpty(user.USER_DEPARTMENTID) == true) & (!department.MANAGER.Equals(user.USER_ID))) { DataGridviewbyUser depUser = new DataGridviewbyUser(); depUser.USER_ID = user.USER_ID; depUser.USER_NAME = user.USER_NAME; if (string.IsNullOrEmpty(user.USER_IMAGEID) == true) { switch (user.USER_SEX) { case (int)Sex.男: depUser.USER_IMAGEID = "boy"; break; case (int)Sex.女: depUser.USER_IMAGEID = "girl"; break; } } else { depUser.USER_IMAGEID = user.USER_IMAGEID; } depUser.USER_DEPARTMENTID = ""; depUser.DepName = ""; depUser.SelectCheck = false; listUser.Add(depUser); } } //将已分配部门且不是当前部门责任人的用户,添加到listUser中 foreach (coreUser user in listDepUser) { if ((string.IsNullOrEmpty(user.USER_DEPARTMENTID) == false) & (!department.MANAGER.Equals(user.USER_ID))) { DataGridviewbyUser depUser = new DataGridviewbyUser(); depUser.USER_ID = user.USER_ID; depUser.USER_NAME = user.USER_NAME; if (string.IsNullOrEmpty(user.USER_IMAGEID) == true) { switch (user.USER_SEX) { case (int)Sex.男: depUser.USER_IMAGEID = "boy"; break; case (int)Sex.女: depUser.USER_IMAGEID = "girl"; break; } } else { depUser.USER_IMAGEID = user.USER_IMAGEID; } depUser.USER_DEPARTMENTID = user.USER_DEPARTMENTID; string DepName = ""; if (AutofacConfig.DepartmentService.GetDepartmentByDepID(user.USER_DEPARTMENTID) != null) { DepName = AutofacConfig.DepartmentService.GetDepartmentByDepID(user.USER_DEPARTMENTID).NAME; } depUser.DepName = DepName; depUser.SelectCheck = false; listUser.Add(depUser); } } } } //部门编辑时ListView绑定数据 if (string.IsNullOrEmpty(department.DEPARTMENTID) == false) { if (listDepUser.Count > 0) { //将当前部门且不是当前部门责任人的用户,添加到listUser中 foreach (coreUser user in listDepUser) { if ((string.IsNullOrEmpty(user.USER_DEPARTMENTID) == false) & (department.DEPARTMENTID.Equals(user.USER_DEPARTMENTID)) & (!department.MANAGER.Equals(user.USER_ID))) { DataGridviewbyUser depUser = new DataGridviewbyUser(); depUser.USER_ID = user.USER_ID; depUser.USER_NAME = user.USER_NAME; if (string.IsNullOrEmpty(user.USER_IMAGEID) == true) { switch (user.USER_SEX) { case (int)Sex.男: depUser.USER_IMAGEID = "boy"; break; case (int)Sex.女: depUser.USER_IMAGEID = "girl"; break; } } else { depUser.USER_IMAGEID = user.USER_IMAGEID; } depUser.USER_DEPARTMENTID = department.DEPARTMENTID; depUser.DepName = department.NAME; depUser.SelectCheck = true; listUser.Add(depUser); } } //将未分配部门且不是当前部门责任人的用户,添加到listUser中 foreach (coreUser user in listDepUser) { if ((string.IsNullOrEmpty(user.USER_DEPARTMENTID) == true) & (!department.MANAGER.Equals(user.USER_ID))) { DataGridviewbyUser depUser = new DataGridviewbyUser(); depUser.USER_ID = user.USER_ID; depUser.USER_NAME = user.USER_NAME; if (string.IsNullOrEmpty(user.USER_IMAGEID) == true) { switch (user.USER_SEX) { case (int)Sex.男: depUser.USER_IMAGEID = "boy"; break; case (int)Sex.女: depUser.USER_IMAGEID = "girl"; break; } } else { depUser.USER_IMAGEID = user.USER_IMAGEID; } depUser.USER_DEPARTMENTID = ""; depUser.DepName = ""; depUser.SelectCheck = false; listUser.Add(depUser); } } //将已分配部门且不是当前部门的用户,添加到listUser中 foreach (coreUser user in listDepUser) { if ((string.IsNullOrEmpty(user.USER_DEPARTMENTID) == false) & (!department.DEPARTMENTID.Equals(user.USER_DEPARTMENTID)) & (!department.MANAGER.Equals(user.USER_ID))) { DataGridviewbyUser depUser = new DataGridviewbyUser(); depUser.USER_ID = user.USER_ID; depUser.USER_NAME = user.USER_NAME; if (string.IsNullOrEmpty(user.USER_IMAGEID) == true) { switch (user.USER_SEX) { case (int)Sex.男: depUser.USER_IMAGEID = "boy"; break; case (int)Sex.女: depUser.USER_IMAGEID = "girl"; break; } } else { depUser.USER_IMAGEID = user.USER_IMAGEID; } depUser.USER_DEPARTMENTID = user.USER_DEPARTMENTID; string DepName = AutofacConfig.DepartmentService.GetDepartmentByDepID(user.USER_DEPARTMENTID).NAME; depUser.DepName = DepName; depUser.SelectCheck = false; listUser.Add(depUser); } } } } gridUserData.Rows.Clear();//清空人员列表数据 if (listUser.Count > 0) { gridUserData.DataSource = listUser; //绑定ListView数据 gridUserData.DataBind(); upCheckState(); } } else { throw new Exception("请输入部门信息!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public string selectUser; //选中人员 #endregion /// <summary> /// ListView点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //private void gridATData_CellClick(object sender, GridViewCellEventArgs e) //{ // switch (Convert.ToBoolean(e.Cell.Items["Check"].DefaultValue)) // { // case true: // e.Cell.Items["Check"].DefaultValue = false; // break; // case false: // e.Cell.Items["Check"].DefaultValue = true; // break; // } // upCheckState(); //} /// <summary> /// 获取用户 /// </summary> private void GetATUser() { try { List <DataGridviewbyUser> listATUser = new List <DataGridviewbyUser>();//考勤用户集合 //如果有考勤选中用户,则添加到考勤用户集合listATUser,并默认用户状态为选中 if (string.IsNullOrEmpty(selectUser) == false) { string[] selectUsers = selectUser.Split(','); foreach (string user in selectUsers) { //UserDetailDto userdto = AutofacConfig.userService.GetUserByUserID(user); UserDetails userDetails = new UserDetails(); UserDetailDto userdto = userDetails.getUser(user); if (userdto != null) { DataGridviewbyUser atUser = new DataGridviewbyUser(); atUser.U_ID = userdto.U_ID; atUser.U_Name = userdto.U_Name; atUser.U_Portrait = userdto.U_Portrait; string depID = ""; string depName = ""; if (string.IsNullOrEmpty(userdto.U_DepID)) { DepDetailDto department = AutofacConfig.departmentService.GetDepartmentByDepID(userdto.U_DepID); if (department != null) { depID = department.Dep_ID; depID = department.Dep_Name; } } atUser.U_DepID = depID; atUser.U_DepName = depName; atUser.SelectCheck = true; listATUser.Add(atUser); } } } //编辑考勤模板且现考勤选中用户不包含当前考勤成员时,添加考勤用户到集合listATUser,并将用户状态默认为未选中 if (string.IsNullOrEmpty(ATNo) == false) { List <UserDto> listUser = AutofacConfig.attendanceService.GetATUser(ATNo); if (listUser.Count > 0) { foreach (UserDto user in listUser) { if (!(string.IsNullOrEmpty(selectUser) == false & selectUser.Split(',').Contains(user.U_ID) == true)) { DataGridviewbyUser atUser = new DataGridviewbyUser(); atUser.U_ID = user.U_ID; atUser.U_Name = user.U_Name; if (string.IsNullOrEmpty(user.U_Portrait) == true) { switch (user.U_Sex) { case (int)Sex.男: atUser.U_Portrait = "boy"; break; case (int)Sex.女: atUser.U_Portrait = "girl"; break; } } else { atUser.U_Portrait = user.U_Portrait; } string depID = ""; string depName = ""; if (string.IsNullOrEmpty(user.U_DepID)) { DepDetailDto department = AutofacConfig.departmentService.GetDepartmentByDepID(user.U_DepID); if (department != null) { depID = department.Dep_ID; depID = department.Dep_Name; } } atUser.U_DepID = depID; atUser.U_DepName = depName; atUser.SelectCheck = false; listATUser.Add(atUser); } } } } //如果未分配考勤模板的用户大于0时,添加到考勤用户集合listATUser List <UserDto> listNoATUser = AutofacConfig.attendanceService.GetNoATUser(); if (listNoATUser.Count > 0) { foreach (UserDto user in listNoATUser) { if ((string.IsNullOrEmpty(selectUser) == true) || (string.IsNullOrEmpty(selectUser) == false & selectUser.Split(',').Contains(user.U_ID) == false)) { DataGridviewbyUser atUser = new DataGridviewbyUser(); atUser.U_ID = user.U_ID; atUser.U_Name = user.U_Name; if (string.IsNullOrEmpty(user.U_Portrait) == true) { switch (user.U_Sex) { case (int)Sex.男: atUser.U_Portrait = "boy"; break; case (int)Sex.女: atUser.U_Portrait = "girl"; break; } } else { atUser.U_Portrait = user.U_Portrait; } string depID = ""; string depName = ""; if (string.IsNullOrEmpty(user.U_DepID)) { DepDetailDto department = AutofacConfig.departmentService.GetDepartmentByDepID(user.U_DepID); if (department != null) { depID = department.Dep_ID; depID = department.Dep_Name; } } atUser.U_DepID = depID; atUser.U_DepName = depName; atUser.SelectCheck = false; listATUser.Add(atUser); } } } gridATUserData.Rows.Clear();//清空人员列表数据 if (listATUser.Count > 0) { gridATUserData.DataSource = listATUser; //绑定ListView数据 gridATUserData.DataBind(); upCheckState(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }