コード例 #1
0
        private async void dataGridViewSearch_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 3 && e.RowIndex < dataGridViewSearch.RowCount && e.RowIndex >= 0)
            {
                ClientUser   clientUser = (ClientUser)dataGridViewSearch.Rows[e.RowIndex].DataBoundItem;
                User         user       = MapToServiceUser(clientUser);
                EditUserForm form       = new EditUserForm(user, _user);
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    dataGridViewSearch.Rows[e.RowIndex].Cells[0].Value = user.Login;
                    dataGridViewSearch.Rows[e.RowIndex].Cells[1].Value = user.FullName;
                    dataGridViewSearch.Rows[e.RowIndex].Cells[2].Value = user.Roles.First().RoleName;
                }
            }
            else
            if (e.ColumnIndex == 4 && e.RowIndex < dataGridViewSearch.RowCount && e.RowIndex >= 0)
            {
                ClientUser clientUser = (ClientUser)dataGridViewSearch.Rows[e.RowIndex].DataBoundItem;
                if (clientUser.Id == _user.Id)
                {
                    MessageBox.Show(this, "You can not delete yourself!");
                    return;
                }
                User         user         = MapToServiceUser(clientUser);
                DialogResult dialogResult = MessageBox.Show(
                    this,
                    string.Format("Are you sure to delete '{0}' user?", user.FullName),
                    "Delete user",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Information,
                    MessageBoxDefaultButton.Button1);

                if (dialogResult == DialogResult.Yes)
                {
                    try
                    {
                        AuthenticationServiceClient client = new AuthenticationServiceClient();
                        Form frm = new ProgressForm();
                        frm.Show();
                        OperationResult serviceResult = await client.DeleteUserAsync(user);

                        frm.Close();
                        if (!serviceResult.Success)
                        {
                            MessageBox.Show(this, "Users not found!");
                        }
                        else
                        {
                            dataGridViewSearch.Rows.RemoveAt(e.RowIndex);
                        }
                    }
                    catch (FaultException exc)
                    {
                        MessageBox.Show(exc.Message);
                    }
                }
            }
        }