From 0f6d88a4ada15302135fafc7ea8fffaf70565503 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Tue, 24 May 2022 10:02:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D1=8F=D0=B5?= =?UTF-8?q?=D1=82=20=D0=B2=D0=B8=D0=B4=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D1=8B=20=D1=81=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AdministrationForm.Designer.cs | 1 + AdministrationForm.cs | 58 +++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/AdministrationForm.Designer.cs b/AdministrationForm.Designer.cs index 28fcfd1..d8f15ad 100644 --- a/AdministrationForm.Designer.cs +++ b/AdministrationForm.Designer.cs @@ -181,6 +181,7 @@ this.deleteUserButton.TabIndex = 2; this.deleteUserButton.Text = "Удалить"; this.deleteUserButton.UseVisualStyleBackColor = true; + this.deleteUserButton.Click += new System.EventHandler(this.deleteUserButton_Click); // // AdministrationForm // diff --git a/AdministrationForm.cs b/AdministrationForm.cs index b05cdcf..0c51b88 100644 --- a/AdministrationForm.cs +++ b/AdministrationForm.cs @@ -34,8 +34,15 @@ namespace AwesomeEmailExtractor AdminUtils adminUtils = new AdminUtils(Globals.currentUser); var users = adminUtils.GetAllUsers(); + usersDataGridView.DataSource = users; - usersDataGridView.DataSource = users; + List columns = new List() { "ID", "Логин", "Роль" }; + + for (int i = 0; i < usersDataGridView.Columns.Count; i++) + { + usersDataGridView.Columns[i].HeaderText = columns[i]; + usersDataGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } } private void browseButton_Click(object sender, EventArgs e) @@ -80,5 +87,54 @@ namespace AwesomeEmailExtractor MessageBox.Show("Выберите 1 пользователя для редактирования!"); } } + + private void deleteUserButton_Click(object sender, EventArgs e) + { + bool selfDelete = false; + + if (usersDataGridView.SelectedRows.Count > 0) + { + DialogResult result = MessageBox.Show("Вы уверены что хотите удалить аккаунты?", "Удаление аккаунтов", MessageBoxButtons.YesNo); + + if (result == DialogResult.Yes) + { + for (int i = 0; i < usersDataGridView.SelectedRows.Count; i++) + { + var user = usersDataGridView.SelectedRows[i].DataBoundItem as User; + if (user.ID != Globals.currentUser.ID) + { + user.Delete(); + } + else + { + selfDelete = true; + } + } + + if (selfDelete) + { + DialogResult result2 = MessageBox.Show("Вы уверены что хотите удалить СВОЙ аккаунт?", "Удаление аккаунта", MessageBoxButtons.YesNo); + + if (result2 == DialogResult.Yes) + { + Globals.currentUser.Delete(); + MessageBox.Show("Аккаунт удален!"); + + this.Close(); + + AuthorizationForm authorization = FormManager.Current.CreateForm(); + FormManager.Current.Navigate(this.Owner, authorization); + } + } + } + AdminUtils adminUtils = new AdminUtils(Globals.currentUser); + var users = adminUtils.GetAllUsers(); + usersDataGridView.DataSource = users; + } + else + { + MessageBox.Show("Выберите хотя бы одного пользователя для удаления!"); + } + } } }