diff --git a/AdministrationForm.Designer.cs b/AdministrationForm.Designer.cs new file mode 100644 index 0000000..57697b1 --- /dev/null +++ b/AdministrationForm.Designer.cs @@ -0,0 +1,392 @@ +namespace AwesomeEmailExtractor +{ + partial class AdministrationForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.mainTabControl = new System.Windows.Forms.TabControl(); + this.mainSettingsTabPage = new System.Windows.Forms.TabPage(); + this.label1 = new System.Windows.Forms.Label(); + this.browseButton = new System.Windows.Forms.Button(); + this.pathToJournalTextBox = new System.Windows.Forms.TextBox(); + this.usersTabPage = new System.Windows.Forms.TabPage(); + this.usersDataGridView = new System.Windows.Forms.DataGridView(); + this.panel2 = new System.Windows.Forms.Panel(); + this.deleteUserButton = new System.Windows.Forms.Button(); + this.editUserButton = new System.Windows.Forms.Button(); + this.journalTabPage = new System.Windows.Forms.TabPage(); + this.panel3 = new System.Windows.Forms.Panel(); + this.journalDataGridView = new System.Windows.Forms.DataGridView(); + this.panel4 = new System.Windows.Forms.Panel(); + this.deleteJournalButton = new System.Windows.Forms.Button(); + this.panel1 = new System.Windows.Forms.Panel(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.label2 = new System.Windows.Forms.Label(); + this.messageRichTextBox = new System.Windows.Forms.RichTextBox(); + this.userLabel = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.dateLabel = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.actionLabel = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.sqliteCommand1 = new Microsoft.Data.Sqlite.SqliteCommand(); + this.mainTabControl.SuspendLayout(); + this.mainSettingsTabPage.SuspendLayout(); + this.usersTabPage.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.usersDataGridView)).BeginInit(); + this.panel2.SuspendLayout(); + this.journalTabPage.SuspendLayout(); + this.panel3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.journalDataGridView)).BeginInit(); + this.panel4.SuspendLayout(); + this.panel1.SuspendLayout(); + this.tableLayoutPanel1.SuspendLayout(); + this.SuspendLayout(); + // + // mainTabControl + // + this.mainTabControl.Controls.Add(this.mainSettingsTabPage); + this.mainTabControl.Controls.Add(this.usersTabPage); + this.mainTabControl.Controls.Add(this.journalTabPage); + this.mainTabControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.mainTabControl.Location = new System.Drawing.Point(0, 0); + this.mainTabControl.Name = "mainTabControl"; + this.mainTabControl.SelectedIndex = 0; + this.mainTabControl.Size = new System.Drawing.Size(998, 557); + this.mainTabControl.TabIndex = 0; + // + // mainSettingsTabPage + // + this.mainSettingsTabPage.Controls.Add(this.label1); + this.mainSettingsTabPage.Controls.Add(this.browseButton); + this.mainSettingsTabPage.Controls.Add(this.pathToJournalTextBox); + this.mainSettingsTabPage.Location = new System.Drawing.Point(4, 22); + this.mainSettingsTabPage.Name = "mainSettingsTabPage"; + this.mainSettingsTabPage.Padding = new System.Windows.Forms.Padding(3); + this.mainSettingsTabPage.Size = new System.Drawing.Size(990, 531); + this.mainSettingsTabPage.TabIndex = 0; + this.mainSettingsTabPage.Text = "Общие настройки"; + this.mainSettingsTabPage.UseVisualStyleBackColor = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(8, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(140, 13); + this.label1.TabIndex = 2; + this.label1.Text = "Путь к файлу с журналом:"; + // + // browseButton + // + this.browseButton.Location = new System.Drawing.Point(678, 26); + this.browseButton.Name = "browseButton"; + this.browseButton.Size = new System.Drawing.Size(106, 23); + this.browseButton.TabIndex = 1; + this.browseButton.Text = "Обзор"; + this.browseButton.UseVisualStyleBackColor = true; + this.browseButton.Click += new System.EventHandler(this.browseButton_Click); + // + // pathToJournalTextBox + // + this.pathToJournalTextBox.Enabled = false; + this.pathToJournalTextBox.Location = new System.Drawing.Point(8, 28); + this.pathToJournalTextBox.Name = "pathToJournalTextBox"; + this.pathToJournalTextBox.Size = new System.Drawing.Size(664, 20); + this.pathToJournalTextBox.TabIndex = 0; + // + // usersTabPage + // + this.usersTabPage.Controls.Add(this.usersDataGridView); + this.usersTabPage.Controls.Add(this.panel2); + this.usersTabPage.Location = new System.Drawing.Point(4, 22); + this.usersTabPage.Name = "usersTabPage"; + this.usersTabPage.Padding = new System.Windows.Forms.Padding(3); + this.usersTabPage.Size = new System.Drawing.Size(990, 531); + this.usersTabPage.TabIndex = 1; + this.usersTabPage.Text = "Пользователи"; + this.usersTabPage.UseVisualStyleBackColor = true; + // + // usersDataGridView + // + this.usersDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.usersDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.usersDataGridView.Location = new System.Drawing.Point(3, 31); + this.usersDataGridView.Name = "usersDataGridView"; + this.usersDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.usersDataGridView.Size = new System.Drawing.Size(984, 497); + this.usersDataGridView.TabIndex = 0; + // + // panel2 + // + this.panel2.Controls.Add(this.deleteUserButton); + this.panel2.Controls.Add(this.editUserButton); + this.panel2.Dock = System.Windows.Forms.DockStyle.Top; + this.panel2.Location = new System.Drawing.Point(3, 3); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(984, 28); + this.panel2.TabIndex = 2; + // + // deleteUserButton + // + this.deleteUserButton.Location = new System.Drawing.Point(140, 3); + this.deleteUserButton.Name = "deleteUserButton"; + this.deleteUserButton.Size = new System.Drawing.Size(131, 20); + this.deleteUserButton.TabIndex = 2; + this.deleteUserButton.Text = "Удалить"; + this.deleteUserButton.UseVisualStyleBackColor = true; + this.deleteUserButton.Click += new System.EventHandler(this.deleteUserButton_Click); + // + // editUserButton + // + this.editUserButton.Location = new System.Drawing.Point(3, 3); + this.editUserButton.Name = "editUserButton"; + this.editUserButton.Size = new System.Drawing.Size(131, 20); + this.editUserButton.TabIndex = 1; + this.editUserButton.Text = "Редактировать"; + this.editUserButton.UseVisualStyleBackColor = true; + this.editUserButton.Click += new System.EventHandler(this.editUserButton_Click); + // + // journalTabPage + // + this.journalTabPage.Controls.Add(this.panel3); + this.journalTabPage.Controls.Add(this.panel1); + this.journalTabPage.Location = new System.Drawing.Point(4, 22); + this.journalTabPage.Name = "journalTabPage"; + this.journalTabPage.Size = new System.Drawing.Size(990, 531); + this.journalTabPage.TabIndex = 2; + this.journalTabPage.Text = "Журнал"; + this.journalTabPage.UseVisualStyleBackColor = true; + this.journalTabPage.Click += new System.EventHandler(this.journalTabPage_Click); + // + // panel3 + // + this.panel3.Controls.Add(this.journalDataGridView); + this.panel3.Controls.Add(this.panel4); + this.panel3.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel3.Location = new System.Drawing.Point(0, 0); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(536, 531); + this.panel3.TabIndex = 2; + // + // journalDataGridView + // + this.journalDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.journalDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.journalDataGridView.Location = new System.Drawing.Point(0, 37); + this.journalDataGridView.Name = "journalDataGridView"; + this.journalDataGridView.ReadOnly = true; + this.journalDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.journalDataGridView.Size = new System.Drawing.Size(536, 494); + this.journalDataGridView.TabIndex = 0; + this.journalDataGridView.SelectionChanged += new System.EventHandler(this.journalDataGridView_SelectionChanged); + // + // panel4 + // + this.panel4.Controls.Add(this.deleteJournalButton); + this.panel4.Dock = System.Windows.Forms.DockStyle.Top; + this.panel4.Location = new System.Drawing.Point(0, 0); + this.panel4.Name = "panel4"; + this.panel4.Size = new System.Drawing.Size(536, 37); + this.panel4.TabIndex = 1; + // + // deleteJournalButton + // + this.deleteJournalButton.Location = new System.Drawing.Point(8, 3); + this.deleteJournalButton.Name = "deleteJournalButton"; + this.deleteJournalButton.Size = new System.Drawing.Size(131, 20); + this.deleteJournalButton.TabIndex = 3; + this.deleteJournalButton.Text = "Удалить"; + this.deleteJournalButton.UseVisualStyleBackColor = true; + this.deleteJournalButton.Click += new System.EventHandler(this.deleteJournalButton_Click); + // + // panel1 + // + this.panel1.Controls.Add(this.tableLayoutPanel1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Right; + this.panel1.Location = new System.Drawing.Point(536, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(454, 531); + this.panel1.TabIndex = 1; + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.Controls.Add(this.label2, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.messageRichTextBox, 1, 3); + this.tableLayoutPanel1.Controls.Add(this.userLabel, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.label4, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.dateLabel, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.label3, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.actionLabel, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.label5, 0, 3); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 4; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(454, 531); + this.tableLayoutPanel1.TabIndex = 6; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(3, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(36, 13); + this.label2.TabIndex = 0; + this.label2.Text = "Дата:"; + // + // messageRichTextBox + // + this.messageRichTextBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.messageRichTextBox.Location = new System.Drawing.Point(103, 93); + this.messageRichTextBox.Name = "messageRichTextBox"; + this.messageRichTextBox.ReadOnly = true; + this.messageRichTextBox.Size = new System.Drawing.Size(348, 435); + this.messageRichTextBox.TabIndex = 3; + this.messageRichTextBox.Text = ""; + // + // userLabel + // + this.userLabel.AutoSize = true; + this.userLabel.Location = new System.Drawing.Point(103, 30); + this.userLabel.Name = "userLabel"; + this.userLabel.Size = new System.Drawing.Size(0, 13); + this.userLabel.TabIndex = 5; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(3, 60); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(54, 13); + this.label4.TabIndex = 2; + this.label4.Text = "Событие:"; + // + // dateLabel + // + this.dateLabel.AutoSize = true; + this.dateLabel.Location = new System.Drawing.Point(103, 0); + this.dateLabel.Name = "dateLabel"; + this.dateLabel.Size = new System.Drawing.Size(0, 13); + this.dateLabel.TabIndex = 4; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(3, 30); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(83, 13); + this.label3.TabIndex = 1; + this.label3.Text = "Пользователь:"; + // + // actionLabel + // + this.actionLabel.AutoSize = true; + this.actionLabel.Location = new System.Drawing.Point(103, 60); + this.actionLabel.Name = "actionLabel"; + this.actionLabel.Size = new System.Drawing.Size(0, 13); + this.actionLabel.TabIndex = 6; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(3, 90); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(68, 13); + this.label5.TabIndex = 7; + this.label5.Text = "Сообщение:"; + // + // sqliteCommand1 + // + this.sqliteCommand1.CommandTimeout = 30; + this.sqliteCommand1.Connection = null; + this.sqliteCommand1.Transaction = null; + this.sqliteCommand1.UpdatedRowSource = System.Data.UpdateRowSource.None; + // + // AdministrationForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(998, 557); + this.Controls.Add(this.mainTabControl); + this.Name = "AdministrationForm"; + this.Text = "Администрирование"; + this.Load += new System.EventHandler(this.AdministrationForm_Load); + this.mainTabControl.ResumeLayout(false); + this.mainSettingsTabPage.ResumeLayout(false); + this.mainSettingsTabPage.PerformLayout(); + this.usersTabPage.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.usersDataGridView)).EndInit(); + this.panel2.ResumeLayout(false); + this.journalTabPage.ResumeLayout(false); + this.panel3.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.journalDataGridView)).EndInit(); + this.panel4.ResumeLayout(false); + this.panel1.ResumeLayout(false); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TabControl mainTabControl; + private System.Windows.Forms.TabPage mainSettingsTabPage; + private System.Windows.Forms.TabPage usersTabPage; + private System.Windows.Forms.TabPage journalTabPage; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button browseButton; + private System.Windows.Forms.TextBox pathToJournalTextBox; + private System.Windows.Forms.DataGridView usersDataGridView; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.DataGridView journalDataGridView; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Button deleteUserButton; + private System.Windows.Forms.Button editUserButton; + private System.Windows.Forms.Panel panel3; + private Microsoft.Data.Sqlite.SqliteCommand sqliteCommand1; + private System.Windows.Forms.Panel panel4; + private System.Windows.Forms.RichTextBox messageRichTextBox; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button deleteJournalButton; + private System.Windows.Forms.Label userLabel; + private System.Windows.Forms.Label dateLabel; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Label actionLabel; + private System.Windows.Forms.Label label5; + } +} \ No newline at end of file diff --git a/AdministrationForm.cs b/AdministrationForm.cs new file mode 100644 index 0000000..a8cae5f --- /dev/null +++ b/AdministrationForm.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Microsoft.Data.Sqlite; + +namespace AwesomeEmailExtractor +{ + public partial class AdministrationForm : Form + { + public AdministrationForm() + { + InitializeComponent(); + } + + private void AdministrationForm_Load(object sender, EventArgs e) + { + + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "SELECT * FROM app_settings"; + + var reader = command.ExecuteReader(); + + var Row = reader.Read(); + + pathToJournalTextBox.Text = reader.GetString(0); + + AdminUtils adminUtils = new AdminUtils(Globals.currentUser); + + var users = adminUtils.GetAllUsers(); + 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; + } + + var logs = Logs.GetLogsList(); + journalDataGridView.DataSource = logs; + + columns = new List() { "ID", "Пользователь", "Дата", "Событие", "Сообщение" }; + + for (int i = 0; i < journalDataGridView.Columns.Count; i++) + { + journalDataGridView.Columns[i].HeaderText = columns[i]; + journalDataGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + + private void browseButton_Click(object sender, EventArgs e) + { + FileDialog dialog = new SaveFileDialog(); + dialog.Filter = "SQLite база с журналом (*.db)|*.db"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + pathToJournalTextBox.Text = dialog.FileName; + + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "UPDATE app_settings SET logs_db_path = @path"; + command.Parameters.AddWithValue("@path", pathToJournalTextBox.Text); + command.ExecuteNonQuery(); + } + + } + + private void journalTabPage_Click(object sender, EventArgs e) + { + + } + + private void journalDataGridView_SelectionChanged(object sender, EventArgs e) + { + if (journalDataGridView.SelectedRows.Count > 0) + { + var row = journalDataGridView.SelectedRows[0].DataBoundItem as Logs.LogData; + + dateLabel.Text = row.Date; + userLabel.Text = $"{row.User.Login} ({row.User.ID}) - {row.User.Role}"; + actionLabel.Text = row.Action.ToString(); + messageRichTextBox.Text = row.Message; + } + else + { + dateLabel.Text = ""; + actionLabel.Text = ""; + userLabel.Text = ""; + messageRichTextBox.Text = ""; + } + } + + private void editUserButton_Click(object sender, EventArgs e) + { + if (usersDataGridView.SelectedRows.Count == 1) + { + var user = usersDataGridView.SelectedRows[0].DataBoundItem as User; + + var form = new EditUserForm(); + form.User = user; + + form.ShowDialog(); + + AdminUtils adminUtils = new AdminUtils(Globals.currentUser); + var users = adminUtils.GetAllUsers(); + usersDataGridView.DataSource = users; + + var logs = Logs.GetLogsList(); + journalDataGridView.DataSource = logs; + } else + { + 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, MessageBoxIcon.Warning); + + 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, MessageBoxIcon.Warning); + + if (result2 == DialogResult.Yes) + { + Globals.currentUser.Delete(); + MessageBox.Show("Аккаунт удален!", "Аккаунт удален", MessageBoxButtons.OK, MessageBoxIcon.Information); + + 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; + + var logs = Logs.GetLogsList(); + journalDataGridView.DataSource = logs; + } + } + else + { + MessageBox.Show("Выберите хотя бы одного пользователя для удаления!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void deleteJournalButton_Click(object sender, EventArgs e) + { + if (journalDataGridView.SelectedRows.Count > 0) + { + DialogResult result = MessageBox.Show("Вы уверены что хотите удалить записи в журнале?", "Удаление записей в журнале", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); + + if (result == DialogResult.Yes) + { + for (int i = 0; i < journalDataGridView.SelectedRows.Count; i++) + { + var logData = journalDataGridView.SelectedRows[i].DataBoundItem as Logs.LogData; + logData.Delete(); + } + var logs = Logs.GetLogsList(); + journalDataGridView.DataSource = logs; + } + } + else + { + MessageBox.Show("Выберите хотя бы одну запись для удаления!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/AdministrationForm.resx b/AdministrationForm.resx new file mode 100644 index 0000000..56dd26f --- /dev/null +++ b/AdministrationForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + False + + + 17, 17 + + \ No newline at end of file diff --git a/Authorization.cs b/Authorization.cs index 81f550d..e64cfa9 100644 --- a/Authorization.cs +++ b/Authorization.cs @@ -28,7 +28,7 @@ namespace AwesomeEmailExtractor return new User(reader.GetInt32(0), reader.GetString(1), (UserRoles)reader.GetInt32(2)); } - throw new Exception("Пользователь не найден!"); + throw new Exception("Неверные данные для входа!"); } public static User Register(string login, string password) @@ -86,7 +86,14 @@ namespace AwesomeEmailExtractor Login = login; Role = role; } - + + public User(User user) + { + ID = user.ID; + Login = user.Login; + Role = user.Role; + } + public void Delete() { SqliteCommand command = new SqliteCommand(); @@ -113,6 +120,11 @@ namespace AwesomeEmailExtractor command.ExecuteNonQuery(); } + + public override string ToString() + { + return Login; + } } public class AdminUtils @@ -125,11 +137,6 @@ namespace AwesomeEmailExtractor } public void setRole(string login, UserRoles role) { - if (User.Role != UserRoles.ADMIN) - { - throw new Exception("Недостаточно прав!"); - } - SqliteCommand command = new SqliteCommand(); command.Connection = Globals.db; command.CommandText = "UPDATE users SET role_id = @role WHERE login = @login"; @@ -142,7 +149,6 @@ namespace AwesomeEmailExtractor command.ExecuteNonQuery(); } - public void deleteUser(string login) { if (User.Role != UserRoles.ADMIN) @@ -159,7 +165,7 @@ namespace AwesomeEmailExtractor command.ExecuteNonQuery(); } - public List getAllUsers() + public List GetAllUsers() { if (User.Role != UserRoles.ADMIN) { @@ -168,7 +174,7 @@ namespace AwesomeEmailExtractor SqliteCommand command = new SqliteCommand(); command.Connection = Globals.db; - command.CommandText = "SELECT * FROM users"; + command.CommandText = "SELECT id, login, role_id FROM users"; SqliteDataReader reader = command.ExecuteReader(); @@ -181,5 +187,34 @@ namespace AwesomeEmailExtractor return users; } + + public void editUser(User user) + { + if (User.Role != UserRoles.ADMIN) + { + throw new Exception("Недостаточно прав!"); + } + + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "UPDATE users SET login = @login, role_id = @role_id WHERE id = @id"; + + SqliteParameter idParam = new SqliteParameter("@id", user.ID); + command.Parameters.Add(idParam); + + SqliteParameter loginParam = new SqliteParameter("@login", user.Login); + command.Parameters.Add(loginParam); + + SqliteParameter roleParam = new SqliteParameter("@role_id", user.Role); + command.Parameters.Add(roleParam); + + command.ExecuteNonQuery(); + } + + public void editUser(User user, string password) + { + editUser(user); + user.ChangePassword(password); + } } } diff --git a/AuthorizationForm.cs b/AuthorizationForm.cs index 741cb61..c90e44d 100644 --- a/AuthorizationForm.cs +++ b/AuthorizationForm.cs @@ -21,6 +21,12 @@ namespace AwesomeEmailExtractor { try { + if (string.IsNullOrEmpty(entryLogin.Text) || string.IsNullOrEmpty(entryPassword.Text)) + { + MessageBox.Show("Введите логин и пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + Globals.currentUser = Authorization.Login(entryLogin.Text, entryPassword.Text); Logs.Log(Globals.currentUser, Logs.Action.Login, new Dictionary()); @@ -29,7 +35,7 @@ namespace AwesomeEmailExtractor } catch (Exception ex) { - MessageBox.Show(ex.Message); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj index d078b5e..27aeed3 100644 --- a/AwesomeEmailExtractor.csproj +++ b/AwesomeEmailExtractor.csproj @@ -76,6 +76,12 @@ + + Form + + + AdministrationForm.cs + Form @@ -83,9 +89,27 @@ AuthorizationForm.cs + + Form + + + EditUserForm.cs + + + Form + + + HelpForm.cs + + + Form + + + JournalForm.cs + Form @@ -107,9 +131,22 @@ SettingsForm.cs + + AdministrationForm.cs + Designer + AuthorizationForm.cs + + EditUserForm.cs + + + HelpForm.cs + + + JournalForm.cs + MainForm.cs diff --git a/EditUserForm.Designer.cs b/EditUserForm.Designer.cs new file mode 100644 index 0000000..8ab7af2 --- /dev/null +++ b/EditUserForm.Designer.cs @@ -0,0 +1,155 @@ +namespace AwesomeEmailExtractor +{ + partial class EditUserForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.idTextBox = new System.Windows.Forms.TextBox(); + this.loginTextBox = new System.Windows.Forms.TextBox(); + this.passwordTextBox = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.submitButton = new System.Windows.Forms.Button(); + this.roleComboBox = new System.Windows.Forms.ComboBox(); + this.label4 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // idTextBox + // + this.idTextBox.Enabled = false; + this.idTextBox.Location = new System.Drawing.Point(65, 8); + this.idTextBox.Name = "idTextBox"; + this.idTextBox.Size = new System.Drawing.Size(129, 20); + this.idTextBox.TabIndex = 0; + // + // loginTextBox + // + this.loginTextBox.Location = new System.Drawing.Point(65, 34); + this.loginTextBox.Name = "loginTextBox"; + this.loginTextBox.Size = new System.Drawing.Size(129, 20); + this.loginTextBox.TabIndex = 1; + // + // passwordTextBox + // + this.passwordTextBox.Location = new System.Drawing.Point(65, 60); + this.passwordTextBox.Name = "passwordTextBox"; + this.passwordTextBox.Size = new System.Drawing.Size(129, 20); + this.passwordTextBox.TabIndex = 2; + this.passwordTextBox.UseSystemPasswordChar = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(14, 11); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(21, 13); + this.label1.TabIndex = 3; + this.label1.Text = "ID:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(14, 37); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(41, 13); + this.label2.TabIndex = 4; + this.label2.Text = "Логин:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(14, 63); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(48, 13); + this.label3.TabIndex = 5; + this.label3.Text = "Пароль:"; + // + // submitButton + // + this.submitButton.Location = new System.Drawing.Point(17, 118); + this.submitButton.Name = "submitButton"; + this.submitButton.Size = new System.Drawing.Size(177, 23); + this.submitButton.TabIndex = 6; + this.submitButton.Text = "Подтвердить"; + this.submitButton.UseVisualStyleBackColor = true; + this.submitButton.Click += new System.EventHandler(this.submitButton_Click); + // + // roleComboBox + // + this.roleComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.roleComboBox.FormattingEnabled = true; + this.roleComboBox.Location = new System.Drawing.Point(65, 86); + this.roleComboBox.Name = "roleComboBox"; + this.roleComboBox.Size = new System.Drawing.Size(129, 21); + this.roleComboBox.TabIndex = 7; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(17, 89); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(35, 13); + this.label4.TabIndex = 8; + this.label4.Text = "Роль:"; + // + // EditUserForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(210, 153); + this.Controls.Add(this.label4); + this.Controls.Add(this.roleComboBox); + this.Controls.Add(this.submitButton); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.passwordTextBox); + this.Controls.Add(this.loginTextBox); + this.Controls.Add(this.idTextBox); + this.MaximizeBox = false; + this.Name = "EditUserForm"; + this.Text = "Редактирование"; + this.Load += new System.EventHandler(this.EditUserForm_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox idTextBox; + private System.Windows.Forms.TextBox loginTextBox; + private System.Windows.Forms.TextBox passwordTextBox; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button submitButton; + private System.Windows.Forms.ComboBox roleComboBox; + private System.Windows.Forms.Label label4; + } +} \ No newline at end of file diff --git a/EditUserForm.cs b/EditUserForm.cs new file mode 100644 index 0000000..49a170b --- /dev/null +++ b/EditUserForm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AwesomeEmailExtractor +{ + public partial class EditUserForm : Form + { + public User User { get; set; } + + public EditUserForm() + { + InitializeComponent(); + } + + + + private void EditUserForm_Load(object sender, EventArgs e) + { + idTextBox.Text = User.ID.ToString(); + loginTextBox.Text = User.Login; + + + roleComboBox.Items.Add(UserRoles.DEFAULT.ToString()); + roleComboBox.Items.Add(UserRoles.ADMIN.ToString()); + + roleComboBox.SelectedIndex = (int)User.Role; + } + + private void submitButton_Click(object sender, EventArgs e) + { + if (loginTextBox.Text.Length == 0) + { + MessageBox.Show("Логин не может быть пустым!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + AdminUtils adminUtils = new AdminUtils(Globals.currentUser); + + User editedUser = new User(User.ID, loginTextBox.Text, (UserRoles)roleComboBox.SelectedIndex); + + if (passwordTextBox.Text != "") + { + adminUtils.editUser(editedUser, passwordTextBox.Text); + } + else + { + + adminUtils.editUser(editedUser); + } + + this.Close(); + } + } +} diff --git a/EditUserForm.resx b/EditUserForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/EditUserForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ExtactEmailsAlgorithm.cs b/ExtactEmailsAlgorithm.cs index 4509198..c7831f1 100644 --- a/ExtactEmailsAlgorithm.cs +++ b/ExtactEmailsAlgorithm.cs @@ -12,7 +12,7 @@ namespace AwesomeEmailExtractor public static int Extract(string inputText, out List uniqueEmails) { // Регулярное выражение для поиска почтовых адресов - string pattern = @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"; + string pattern = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"; // Находим каждый почтовый адрес в тексте var matches = Regex.Matches(inputText, pattern, RegexOptions.IgnoreCase); diff --git a/Globals.cs b/Globals.cs index 9ba88dd..940c8ae 100644 --- a/Globals.cs +++ b/Globals.cs @@ -66,12 +66,12 @@ namespace AwesomeEmailExtractor command.CommandText = "CREATE TABLE IF NOT EXISTS logs_actions (id INTEGER PRIMARY KEY, name TEXT NOT NULL)"; command.ExecuteNonQuery(); - command.CommandText = "INSERT OR IGNORE INTO logs_actions (id, name) VALUES (0, 'Выполнение'), (1, 'Вход'), (2, 'Регистрация');"; + command.CommandText = "CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, date TEXT NOT NULL, action INTEGER NOT NULL, message TEXT NOT NULL);"; command.ExecuteNonQuery(); - command.CommandText = "CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, date TEXT NOT NULL, action INTEGER NOT NULL, message TEXT NOT NULL, FOREIGN KEY(action) REFERENCES logs_actions(id));"; + command.CommandText = "ATTACH DATABASE @dbpath AS appDB"; + command.Parameters.AddWithValue("@dbpath", Globals.getAppDatabase()); command.ExecuteNonQuery(); - } public static void CreateTables() diff --git a/HelpForm.Designer.cs b/HelpForm.Designer.cs new file mode 100644 index 0000000..3a5fd06 --- /dev/null +++ b/HelpForm.Designer.cs @@ -0,0 +1,76 @@ +namespace AwesomeEmailExtractor +{ + partial class HelpForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(HelpForm)); + this.label1 = new System.Windows.Forms.Label(); + this.panel1 = new System.Windows.Forms.Panel(); + this.panel1.SuspendLayout(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label1.Location = new System.Drawing.Point(3, 9); + this.label1.Name = "label1"; + this.label1.Padding = new System.Windows.Forms.Padding(5); + this.label1.Size = new System.Drawing.Size(649, 358); + this.label1.TabIndex = 0; + this.label1.Text = resources.GetString("label1.Text"); + // + // panel1 + // + this.panel1.Controls.Add(this.label1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(652, 393); + this.panel1.TabIndex = 1; + // + // HelpForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(652, 393); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.Name = "HelpForm"; + this.Text = "Справка"; + this.panel1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Panel panel1; + } +} \ No newline at end of file diff --git a/HelpForm.cs b/HelpForm.cs new file mode 100644 index 0000000..e1d6279 --- /dev/null +++ b/HelpForm.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AwesomeEmailExtractor +{ + public partial class HelpForm : Form + { + public HelpForm() + { + InitializeComponent(); + } + } +} diff --git a/HelpForm.resx b/HelpForm.resx new file mode 100644 index 0000000..391bb3d --- /dev/null +++ b/HelpForm.resx @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Программный продукт AwesomeEmailExtractor будет востребован в тех случаях, когда необхимо из текста получить список уникальных e-mail-ов. +Для того, чтобы получить список, необходимо ввести исходный текст и нажать кнопку "Выполнить". После этого, в правой части окна появится список из уникальных e-mail-ов. +При необходимости можно экспортировать результат выполнения программы с помощью меню "Файл" > "Экспортировать результат". +Во время своей работы программа ведет журнал активности пользователя. Это может быть полезно, чтобы узнать, какие до этого были результаты выполнения. "Аккаунт" -> "Журнал". +Для смены пароля или удаления аккаунта необходимо выбрать в меню "Аккаунт" -> "Настройки". +Для администраторов доступны некоторые особые возможности, их можно найти в меню "Аккаунт" -> "Администрирование". + + \ No newline at end of file diff --git a/JournalForm.Designer.cs b/JournalForm.Designer.cs new file mode 100644 index 0000000..918a063 --- /dev/null +++ b/JournalForm.Designer.cs @@ -0,0 +1,175 @@ +namespace AwesomeEmailExtractor +{ + partial class JournalForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.panel1 = new System.Windows.Forms.Panel(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.label1 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.dataLabel = new System.Windows.Forms.Label(); + this.actionLabel = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.panel1.SuspendLayout(); + this.tableLayoutPanel1.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView1.Location = new System.Drawing.Point(10, 10); + this.dataGridView1.MultiSelect = false; + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.ReadOnly = true; + this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView1.Size = new System.Drawing.Size(414, 451); + this.dataGridView1.TabIndex = 0; + this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged); + // + // panel1 + // + this.panel1.Controls.Add(this.tableLayoutPanel1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Right; + this.panel1.Location = new System.Drawing.Point(424, 10); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(458, 451); + this.panel1.TabIndex = 1; + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 29.2876F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 70.7124F)); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.label3, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.richTextBox1, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.dataLabel, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.actionLabel, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.label2, 0, 1); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.Padding = new System.Windows.Forms.Padding(10); + this.tableLayoutPanel1.RowCount = 3; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(458, 451); + this.tableLayoutPanel1.TabIndex = 8; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 10); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(36, 13); + this.label1.TabIndex = 2; + this.label1.Text = "Дата:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(13, 50); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(68, 13); + this.label3.TabIndex = 4; + this.label3.Text = "Сообщение:"; + // + // richTextBox1 + // + this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.richTextBox1.Location = new System.Drawing.Point(141, 53); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.ReadOnly = true; + this.richTextBox1.Size = new System.Drawing.Size(304, 385); + this.richTextBox1.TabIndex = 7; + this.richTextBox1.Text = ""; + // + // dataLabel + // + this.dataLabel.AutoSize = true; + this.dataLabel.Location = new System.Drawing.Point(141, 10); + this.dataLabel.Name = "dataLabel"; + this.dataLabel.Size = new System.Drawing.Size(54, 13); + this.dataLabel.TabIndex = 5; + this.dataLabel.Text = "dataLabel"; + // + // actionLabel + // + this.actionLabel.AutoSize = true; + this.actionLabel.Location = new System.Drawing.Point(141, 30); + this.actionLabel.Name = "actionLabel"; + this.actionLabel.Size = new System.Drawing.Size(62, 13); + this.actionLabel.TabIndex = 6; + this.actionLabel.Text = "actionLabel"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(13, 30); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(54, 13); + this.label2.TabIndex = 3; + this.label2.Text = "Событие:"; + // + // JournalForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(892, 471); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.panel1); + this.Name = "JournalForm"; + this.Padding = new System.Windows.Forms.Padding(10); + this.Text = "Журнал"; + this.Load += new System.EventHandler(this.JournalForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.panel1.ResumeLayout(false); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.RichTextBox richTextBox1; + private System.Windows.Forms.Label dataLabel; + private System.Windows.Forms.Label actionLabel; + private System.Windows.Forms.Label label2; + } +} \ No newline at end of file diff --git a/JournalForm.cs b/JournalForm.cs new file mode 100644 index 0000000..fbec8ef --- /dev/null +++ b/JournalForm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AwesomeEmailExtractor +{ + public partial class JournalForm : Form + { + public JournalForm() + { + InitializeComponent(); + } + + private void JournalForm_Load(object sender, EventArgs e) + { + var logs = Logs.GetLogsList(Globals.currentUser); + + dataGridView1.DataSource = logs; + + List columns = new List() { "Дата", "Событие", "Сообщение" }; + + dataGridView1.Columns["id"].Visible = false; + dataGridView1.Columns["user"].Visible = false; + + for (int i = 0; i < columns.Count; i++) + { + dataGridView1.Columns[i + 2].HeaderText = columns[i]; + }; + + dataGridView1.Columns["message"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + private void dataGridView1_SelectionChanged(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count > 0) + { + dataLabel.Text = dataGridView1.SelectedRows[0].Cells["date"].Value.ToString(); + actionLabel.Text = dataGridView1.SelectedRows[0].Cells["action"].Value.ToString(); + richTextBox1.Text = dataGridView1.SelectedRows[0].Cells["message"].Value.ToString(); + } else { + dataLabel.Text = ""; + actionLabel.Text = ""; + richTextBox1.Text = ""; + } + } + } +} diff --git a/JournalForm.resx b/JournalForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JournalForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Logs.cs b/Logs.cs index 9b0a52d..059a1b1 100644 --- a/Logs.cs +++ b/Logs.cs @@ -10,17 +10,32 @@ namespace AwesomeEmailExtractor public class Logs { public class LogData { - public User user; - public string date; - public Action action; - public string message; + public int ID { get; set; } + public User User { get; set; } + public string Date { get; set; } + public Action Action { get; set; } + public string Message { get; set; } + + public void Delete() + { + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.logsDb; + command.CommandText = "DELETE FROM logs WHERE id = @id;"; + + SqliteParameter idParam = new SqliteParameter("@id", ID); + command.Parameters.Add(idParam); + + command.ExecuteNonQuery(); + } } public enum Action { Execute, Login, - Registration + Registration, + DeleteAccount, + ChangePassword } public static void Log(User user, Action action, Dictionary options) @@ -37,48 +52,63 @@ namespace AwesomeEmailExtractor command.ExecuteNonQuery(); } - public static List GetLogs(User user) + public static List GetLogsList(User user) { - SqliteCommand command = new SqliteCommand(); - command.Connection = Globals.logsDb; - - command.CommandText = "SELECT date, action, message FROM logs WHERE user_id = @user_id ORDER BY date DESC"; - command.Parameters.AddWithValue("@user_id", user.ID); - - SqliteDataReader reader = command.ExecuteReader(); + SqliteDataReader reader = GetLogsDataReader(user); List logs = new List(); while (reader.Read()) { logs.Add(new LogData() { - user = user, - date = reader.GetString(0), - action = (Action)reader.GetInt32(1), - message = reader.GetString(2) + ID = Convert.ToInt32(reader["id"]), + User = user, + Date = Convert.ToString(reader["date"]), + Action = (Action)Convert.ToInt32(reader["action"]), + Message = Convert.ToString(reader["message"]), }); } + reader.Close(); + return logs; } - public static List GetLogs() + private static SqliteDataReader GetLogsDataReader(User user) { + if (Globals.currentUser.ID != user.ID && Globals.currentUser.Role != UserRoles.ADMIN) + { + throw new Exception("У вас нет прав на просмотр логов"); + } + + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.logsDb; + command.CommandText = "SELECT id, date, action, message FROM logs WHERE user_id = @user_id ORDER BY date DESC"; + command.Parameters.AddWithValue("@user_id", user.ID); + + return command.ExecuteReader(); + } + + public static List GetLogsList() + { + if (Globals.currentUser.Role != UserRoles.ADMIN) + { + throw new Exception("У вас нет прав на просмотр логов"); + } + SqliteCommand command = new SqliteCommand(); command.Connection = Globals.logsDb; - command.CommandText = "ATTACH DATABASE @dbpath AS appDB"; - command.Parameters.AddWithValue("@dbpath", Globals.getAppDatabase()); - command.ExecuteNonQuery(); command.CommandText = @" - SELECT + SELECT + logs.id, user_id, - CASE WHEN appDB.users.login is NULL THEN 'Deleted_' || user_id ELSE appDB.users.login END AS login - appDB.users.role, + CASE WHEN appDB.users.login is NULL THEN 'Deleted_' || user_id ELSE appDB.users.login END AS login, + CASE WHEN appDB.users.role_id is NULL THEN 0 ELSE appDB.users.role_id END AS role_id, date, action, message - from logs LEFT JOIN appDB.users on logs.user_id = appDB.users.id ORDER BY date DESC"; + from logs LEFT JOIN appDB.users on logs.user_id = appDB.users.id ORDER BY date DESC;"; SqliteDataReader reader = command.ExecuteReader(); @@ -87,10 +117,15 @@ namespace AwesomeEmailExtractor { logs.Add(new LogData() { - user = new User(reader.GetInt32(0), reader.GetString(1), (UserRoles)reader.GetInt32(2)), - date = reader.GetString(3), - action = (Action)reader.GetInt32(4), - message = reader.GetString(5) + ID = Convert.ToInt32(reader["id"]), + User = new User( + Convert.ToInt32(reader["user_id"]), + Convert.ToString(reader["login"]), + (UserRoles)Convert.ToInt32(reader["role_id"]) + ), + Date = Convert.ToString(reader["date"]), + Action = (Action)Convert.ToInt32(reader["action"]), + Message = Convert.ToString(reader["message"]) }); } @@ -118,8 +153,28 @@ namespace AwesomeEmailExtractor { return "Пользователь зарегистрировался в системе."; } + if (action == Action.DeleteAccount) + { + return "Пользователь удалил аккаунт из системы."; + } + if (action == Action.ChangePassword) + { + return "Пользователь сменил пароль."; + } return ""; } + + public static void DeleteLog(LogData logData) + { + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.logsDb; + + command.CommandText = "DELETE FROM logsDB WHERE id = @id"; + + command.Parameters.AddWithValue("@id", logData.ID); + + command.ExecuteNonQuery(); + } } } diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index f949bab..027b542 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -36,7 +36,9 @@ this.toolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportResultToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.аккаунтToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.journalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.administrationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -52,12 +54,9 @@ this.uniqueListBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.uniqueListBox.FormattingEnabled = true; this.uniqueListBox.ItemHeight = 20; - this.uniqueListBox.Items.AddRange(new object[] { - "alice@example.com", - "bob@example.com"}); this.uniqueListBox.Location = new System.Drawing.Point(424, 32); this.uniqueListBox.Name = "uniqueListBox"; - this.uniqueListBox.Size = new System.Drawing.Size(225, 304); + this.uniqueListBox.Size = new System.Drawing.Size(225, 324); this.uniqueListBox.TabIndex = 0; // // sourceRichTextBox @@ -70,8 +69,7 @@ this.sourceRichTextBox.Name = "sourceRichTextBox"; this.sourceRichTextBox.Size = new System.Drawing.Size(406, 288); this.sourceRichTextBox.TabIndex = 1; - this.sourceRichTextBox.Text = "Алиса (alice@example.com) послылает Бобу (bob@example.com) сообщение.\nАдрес bob@e" + - "xample.com Алиса нашла на сайте example.com"; + this.sourceRichTextBox.Text = ""; // // executeButton // @@ -93,9 +91,9 @@ this.resultCountLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.resultCountLabel.Location = new System.Drawing.Point(12, 323); this.resultCountLabel.Name = "resultCountLabel"; - this.resultCountLabel.Size = new System.Drawing.Size(303, 24); + this.resultCountLabel.Size = new System.Drawing.Size(363, 24); this.resultCountLabel.TabIndex = 3; - this.resultCountLabel.Text = "Количество e-mail-ов в тексте: 3"; + this.resultCountLabel.Text = "Введите текст и нажмите \"Выполнить\""; // // resultStatusStrip // @@ -109,8 +107,7 @@ // toolStripStatusLabel // this.toolStripStatusLabel.Name = "toolStripStatusLabel"; - this.toolStripStatusLabel.Size = new System.Drawing.Size(42, 17); - this.toolStripStatusLabel.Text = "Успех!"; + this.toolStripStatusLabel.Size = new System.Drawing.Size(0, 17); // // menuStrip1 // @@ -126,13 +123,23 @@ // // fileToolStripMenuItem // + this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.exportResultToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(48, 20); this.fileToolStripMenuItem.Text = "Файл"; // + // exportResultToolStripMenuItem + // + this.exportResultToolStripMenuItem.Name = "exportResultToolStripMenuItem"; + this.exportResultToolStripMenuItem.Size = new System.Drawing.Size(219, 22); + this.exportResultToolStripMenuItem.Text = "Экспортировать результат"; + this.exportResultToolStripMenuItem.Click += new System.EventHandler(this.exportResultToolStripMenuItem_Click); + // // аккаунтToolStripMenuItem // this.аккаунтToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.journalToolStripMenuItem, this.settingsToolStripMenuItem, this.administrationToolStripMenuItem, this.exitToolStripMenuItem}); @@ -140,6 +147,13 @@ this.аккаунтToolStripMenuItem.Size = new System.Drawing.Size(63, 20); this.аккаунтToolStripMenuItem.Text = "Аккаунт"; // + // journalToolStripMenuItem + // + this.journalToolStripMenuItem.Name = "journalToolStripMenuItem"; + this.journalToolStripMenuItem.Size = new System.Drawing.Size(189, 22); + this.journalToolStripMenuItem.Text = "Журнал"; + this.journalToolStripMenuItem.Click += new System.EventHandler(this.journalToolStripMenuItem_Click); + // // settingsToolStripMenuItem // this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; @@ -152,6 +166,7 @@ this.administrationToolStripMenuItem.Name = "administrationToolStripMenuItem"; this.administrationToolStripMenuItem.Size = new System.Drawing.Size(189, 22); this.administrationToolStripMenuItem.Text = "Администрирование"; + this.administrationToolStripMenuItem.Click += new System.EventHandler(this.administrationToolStripMenuItem_Click); // // exitToolStripMenuItem // @@ -165,6 +180,7 @@ this.helpToolStripMenuItem.Name = "helpToolStripMenuItem"; this.helpToolStripMenuItem.Size = new System.Drawing.Size(65, 20); this.helpToolStripMenuItem.Text = "Справка"; + this.helpToolStripMenuItem.Click += new System.EventHandler(this.helpToolStripMenuItem_Click); // // MainForm // @@ -180,7 +196,7 @@ this.MainMenuStrip = this.menuStrip1; this.MinimumSize = new System.Drawing.Size(642, 438); this.Name = "MainForm"; - this.Text = "Main Form"; + this.Text = "Главное окно"; this.resultStatusStrip.ResumeLayout(false); this.resultStatusStrip.PerformLayout(); this.menuStrip1.ResumeLayout(false); @@ -205,6 +221,8 @@ private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem administrationToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem journalToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem exportResultToolStripMenuItem; } } diff --git a/MainForm.cs b/MainForm.cs index 5ebee65..4c66113 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -12,6 +12,9 @@ namespace AwesomeEmailExtractor { public partial class MainForm : Form { + public int count; + public List uniqueEmails; + public MainForm() { InitializeComponent(); @@ -36,10 +39,10 @@ namespace AwesomeEmailExtractor uniqueListBox.DataSource = null; // Объявляем список уникальных e-mail-ов - List uniqueEmails = new List(); + uniqueEmails = new List(); // Вызываем метод для извлечения e-mail-ов - int count = ExtactEmailsAlgorithm.Extract(sourceText, out uniqueEmails); + count = ExtactEmailsAlgorithm.Extract(sourceText, out uniqueEmails); // Выводим результат toolStripStatusLabel.Text = "Успех!"; @@ -68,5 +71,45 @@ namespace AwesomeEmailExtractor AuthorizationForm authorization = FormManager.Current.CreateForm(); FormManager.Current.Navigate(this, authorization); } + + private void journalToolStripMenuItem_Click(object sender, EventArgs e) + { + JournalForm journalForm = FormManager.Current.CreateForm(); + journalForm.ShowDialog(this); + } + + private void administrationToolStripMenuItem_Click(object sender, EventArgs e) + { + AdministrationForm administrationForm = FormManager.Current.CreateForm(); + administrationForm.ShowDialog(this); + } + + private void exportResultToolStripMenuItem_Click(object sender, EventArgs e) + { + // Показать окно с выбором файла + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Текстовый файл (*.txt)|*.txt"; + saveFileDialog.FileName = "Результат.txt"; + + var res = saveFileDialog.ShowDialog(); + + + // Сохранить результат в файл + if (res == DialogResult.OK) + { + string fileName = saveFileDialog.FileName; + string resultText = $"Количество e-mail-ов в тексте: {count}\nСписок уникальных e-mail-ов:\n{string.Join("\n", uniqueEmails)}"; + + System.IO.File.WriteAllText(fileName, resultText); + + MessageBox.Show("E-mail-ы успешно сохранены в файл", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void helpToolStripMenuItem_Click(object sender, EventArgs e) + { + HelpForm helpForm = FormManager.Current.CreateForm(); + helpForm.ShowDialog(this); + } } } diff --git a/RegistrationForm.Designer.cs b/RegistrationForm.Designer.cs index 7fe7ef6..67bec00 100644 --- a/RegistrationForm.Designer.cs +++ b/RegistrationForm.Designer.cs @@ -139,6 +139,7 @@ this.Controls.Add(this.registerButton); this.Controls.Add(this.loginButton); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; this.Name = "RegistrationForm"; this.Text = "Зарегистрироваться"; this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.RegistrationForm_FormClosed); diff --git a/RegistrationForm.cs b/RegistrationForm.cs index 308f39b..2811cd5 100644 --- a/RegistrationForm.cs +++ b/RegistrationForm.cs @@ -19,9 +19,15 @@ namespace AwesomeEmailExtractor private void registerButton_Click(object sender, EventArgs e) { + if (string.IsNullOrEmpty(entryLogin.Text) || string.IsNullOrEmpty(entryPassword.Text)) + { + MessageBox.Show("Введите логин и пароль!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (!string.Equals(entryPassword.Text, entryRePassword.Text)) { - MessageBox.Show("Пароли не совпадают!"); + MessageBox.Show("Пароли не совпадают!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } @@ -35,7 +41,7 @@ namespace AwesomeEmailExtractor } catch (Exception ex) { - MessageBox.Show(ex.Message); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/SettingsForm.Designer.cs b/SettingsForm.Designer.cs index e4c61bf..eaa86a8 100644 --- a/SettingsForm.Designer.cs +++ b/SettingsForm.Designer.cs @@ -104,6 +104,7 @@ this.Controls.Add(this.entryNewPassword); this.Controls.Add(this.changePasswordButton); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; this.Name = "SettingsForm"; this.Text = "Настройки"; this.ResumeLayout(false); diff --git a/SettingsForm.cs b/SettingsForm.cs index 9d3aaac..d131561 100644 --- a/SettingsForm.cs +++ b/SettingsForm.cs @@ -19,12 +19,13 @@ namespace AwesomeEmailExtractor private void deleteAccountButton_Click(object sender, EventArgs e) { - DialogResult result = MessageBox.Show("Вы уверены что хотите удалить аккаунт?", "Удаление аккаунта", MessageBoxButtons.YesNo); + DialogResult result = MessageBox.Show("Вы уверены что хотите удалить аккаунт?", "Удаление аккаунта", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { Globals.currentUser.Delete(); - MessageBox.Show("Аккаунт удален!"); + Logs.Log(Globals.currentUser, Logs.Action.DeleteAccount, new Dictionary()); + MessageBox.Show("Аккаунт удален!", "Аккаунт удален", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); @@ -35,14 +36,21 @@ namespace AwesomeEmailExtractor private void changePasswordButton_Click(object sender, EventArgs e) { + if (string.IsNullOrEmpty(entryNewPassword.Text)) + { + MessageBox.Show("Введите пароль!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (!string.Equals(entryNewPassword.Text, entryRePassword.Text)) { - MessageBox.Show("Пароли не совпадают!"); + MessageBox.Show("Пароли не совпадают!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Globals.currentUser.ChangePassword(entryNewPassword.Text); - MessageBox.Show("Пароль изменен!"); + Logs.Log(Globals.currentUser, Logs.Action.ChangePassword, new Dictionary()); + MessageBox.Show("Пароль изменен!", "Пароль изменен", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }