/// <summary> /// 右移 /// </summary> protected void btnRight_Click(object sender, EventArgs e) { var userList = new List<User>(); int[] keys = userGrid.SelectedRowIndexArray; List<object[]> list = new List<object[]>(); for (int i = 0; i < keys.Length; i++) { list.Add(userGrid.DataKeys[keys[i]]); } List<object[]> selected = rightGrid.DataKeys; for (int i = 0; i < selected.Count; i++) { userList.Add(new User { Id = selected[i][0].ToString(), Name = selected[i][1].ToString(), Code = selected[i][2].ToString() }); } #region 判断右边的Grid是否已含员工信息 for (int i = 0; i < list.Count; i++) { bool contains = false; for (int j = 0; j < selected.Count; j++) { if (list[i][0].Equals(selected[j][0])) { contains = true; break; } } if (!contains) { var user = new User { Id = list[i][0].ToString(), Name = list[i][1].ToString(), Code = list[i][2].ToString() }; userList.Add(user); } } #endregion rightGrid.DataSource = userList; rightGrid.DataBind(); }
private void Import(List<UserInfo> list) { string resultMsg = string.Empty; var departments = departmentDao.Entities.ToList(); var users = userDao.Entities.ToList(); User form; var i = 1; foreach (var item in list) { form = users.Where(m => m.Code == item.Code).FirstOrDefault(); if (form == null) { form = new User(); } form.Code = item.Code.Trim(); form.Departments = new List<Department>(); form.Email = item.Email; form.JobName = item.JobName; if (!string.IsNullOrWhiteSpace(item.LeaderCode)) form.LeaderId = users.Where(m => m.Code == item.LeaderCode.Trim()).FirstOrDefault().Id; form.Name = item.Name.Trim(); form.NameEn = item.NameEn.Trim(); form.Phone = item.Phone; if(string.IsNullOrWhiteSpace(form.Id)) { commandService.Send(new CreateUser( form.Code, form.Name, form.NameEn, form.Email, form.Phone, form.JobName, form.LeaderId, string.IsNullOrWhiteSpace(item.Departments.Trim()) ? null : item.Departments.Trim().Split(',') )); } else { commandService.Send(new UpdateUser( form.Id, form.Code, form.Name, form.NameEn, form.Email, form.Phone, form.JobName, form.LeaderId, form.UseAble, string.IsNullOrWhiteSpace(item.Departments.Trim()) ? null : item.Departments.Trim().Split(',') )); } users.Add(form); } }