void AddUserRow(ExtUserRightInfo tag) { int index = dgvUsers.Rows.Add(string.Format(VCAPI.GetPrettyUserName(tag.userInfo)), tag.hasProjectAdminRight, tag.defaultUnitRight == VCAPI.VC_ACCESS_RIGHTS.UPLOAD ? VC_ACCESS_UPLOAD : (tag.defaultUnitRight == VCAPI.VC_ACCESS_RIGHTS.DOWNLOAD ? VC_ACCESS_DOWNLOAD : VC_ACCESS_NONE)); dgvUsers.Rows[index].Tag = tag; }
void btnAddUsers_Click(object sender, EventArgs e) { List <UserInfo> potUserInfos = new List <UserInfo>(); List <string> potUserNames = new List <string>(); List <long> inProUserIds = new List <long>(); List <UserInfo> allUsers; foreach (DataGridViewRow row in dgvUsers.Rows) { inProUserIds.Add((row.Tag as ExtUserRightInfo).userInfo.userId); } if (!_vcAPI.GetAllUsers(out allUsers)) { UserInfoHandler.ShowError(_vcAPI.GetErrorMessage()); return; } foreach (UserInfo userInfo in allUsers) { if (!inProUserIds.Contains(userInfo.userId)) { potUserInfos.Add(userInfo); potUserNames.Add(string.Format(VCAPI.GetPrettyUserName(userInfo))); } } VCUsersAdd vcUsersAdd = new VCUsersAdd(potUserNames); if (vcUsersAdd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return; } List <int> selectedIndices = vcUsersAdd.GetSelectedIndices(); if (selectedIndices.Count == 0) { return; } foreach (int selIndex in selectedIndices) { UserInfo addUserInfo = potUserInfos[selIndex]; ExtUserRightInfo tag = null; for (int remIndex = 0; remIndex < _usersToRemove.Count; ++remIndex) //check if user was in fact deleted during this section and is now re-added { if (_usersToRemove[remIndex].userInfo.userId == addUserInfo.userId) { tag = _usersToRemove[remIndex]; _usersToRemove.RemoveAt(remIndex); break; } } if (tag == null) { tag = new ExtUserRightInfo { userInfo = addUserInfo, added = true, defaultUnitRight = VCAPI.VC_ACCESS_RIGHTS.DOWNLOAD } } ; AddUserRow(tag); } } }