diff --git a/AdministrationForm.Designer.cs b/AdministrationForm.Designer.cs new file mode 100644 index 0000000..9e33c60 --- /dev/null +++ b/AdministrationForm.Designer.cs @@ -0,0 +1,391 @@ +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.journalTabPage = new System.Windows.Forms.TabPage(); + this.panel1 = new System.Windows.Forms.Panel(); + this.journalDataGridView = new System.Windows.Forms.DataGridView(); + this.editUserButton = new System.Windows.Forms.Button(); + this.panel2 = new System.Windows.Forms.Panel(); + this.deleteUserButton = new System.Windows.Forms.Button(); + this.sqliteCommand1 = new Microsoft.Data.Sqlite.SqliteCommand(); + this.panel3 = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.messageRichTextBox = new System.Windows.Forms.RichTextBox(); + this.panel4 = new System.Windows.Forms.Panel(); + this.deleteJournalButton = new System.Windows.Forms.Button(); + this.dateLabel = new System.Windows.Forms.Label(); + this.userLabel = new System.Windows.Forms.Label(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.actionLabel = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.mainTabControl.SuspendLayout(); + this.mainSettingsTabPage.SuspendLayout(); + this.usersTabPage.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.usersDataGridView)).BeginInit(); + this.journalTabPage.SuspendLayout(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.journalDataGridView)).BeginInit(); + this.panel2.SuspendLayout(); + this.panel3.SuspendLayout(); + this.panel4.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; + // + // 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); + // + // 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; + // + // 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); + // + // 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); + // + // 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); + // + // sqliteCommand1 + // + this.sqliteCommand1.CommandTimeout = 30; + this.sqliteCommand1.Connection = null; + this.sqliteCommand1.Transaction = null; + this.sqliteCommand1.UpdatedRowSource = System.Data.UpdateRowSource.None; + // + // 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; + // + // 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 = "Дата:"; + // + // 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 = "Пользователь:"; + // + // 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 = "Событие:"; + // + // messageRichTextBox + // + this.messageRichTextBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.messageRichTextBox.Location = new System.Drawing.Point(103, 93); + this.messageRichTextBox.Name = "messageRichTextBox"; + this.messageRichTextBox.Size = new System.Drawing.Size(348, 435); + this.messageRichTextBox.TabIndex = 3; + this.messageRichTextBox.Text = ""; + // + // 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); + // + // 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; + // + // 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; + // + // 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; + // + // 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 = "Сообщение:"; + // + // 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.journalTabPage.ResumeLayout(false); + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.journalDataGridView)).EndInit(); + this.panel2.ResumeLayout(false); + this.panel3.ResumeLayout(false); + this.panel4.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..27cb6fb --- /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); + + 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; + + var logs = Logs.GetLogsList(); + journalDataGridView.DataSource = logs; + } + } + else + { + MessageBox.Show("Выберите хотя бы одного пользователя для удаления!"); + } + } + + private void deleteJournalButton_Click(object sender, EventArgs e) + { + if (journalDataGridView.SelectedRows.Count > 0) + { + DialogResult result = MessageBox.Show("Вы уверены что хотите удалить записи в журнале?", "Удаление записей в журнале", MessageBoxButtons.YesNo); + + 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("Выберите хотя бы одну запись для удаления!"); + } + } + } +} 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 deec387..71c3b5a 100644 --- a/Authorization.cs +++ b/Authorization.cs @@ -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(); @@ -114,9 +121,9 @@ namespace AwesomeEmailExtractor command.ExecuteNonQuery(); } - new public string ToString() + public override string ToString() { - return this.Login; + return Login; } } @@ -130,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"; @@ -147,7 +149,6 @@ namespace AwesomeEmailExtractor command.ExecuteNonQuery(); } - public void deleteUser(string login) { if (User.Role != UserRoles.ADMIN) @@ -164,7 +165,7 @@ namespace AwesomeEmailExtractor command.ExecuteNonQuery(); } - public List getAllUsers() + public List GetAllUsers() { if (User.Role != UserRoles.ADMIN) { @@ -173,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(); @@ -186,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/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj index 35b5fad..d43c5bf 100644 --- a/AwesomeEmailExtractor.csproj +++ b/AwesomeEmailExtractor.csproj @@ -76,6 +76,12 @@ + + Form + + + AdministrationForm.cs + Form @@ -83,6 +89,12 @@ AuthorizationForm.cs + + Form + + + EditUserForm.cs + @@ -113,9 +125,16 @@ SettingsForm.cs + + AdministrationForm.cs + Designer + AuthorizationForm.cs + + EditUserForm.cs + JournalForm.cs diff --git a/EditUserForm.Designer.cs b/EditUserForm.Designer.cs new file mode 100644 index 0000000..9901122 --- /dev/null +++ b/EditUserForm.Designer.cs @@ -0,0 +1,154 @@ +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.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..73024ba --- /dev/null +++ b/EditUserForm.cs @@ -0,0 +1,55 @@ +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) + { + 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/JournalForm.cs b/JournalForm.cs index 55208ab..b45e7bd 100644 --- a/JournalForm.cs +++ b/JournalForm.cs @@ -22,17 +22,18 @@ namespace AwesomeEmailExtractor var logs = Logs.GetLogsList(Globals.currentUser); dataGridView1.DataSource = logs; - dataGridView1.Columns[0].Visible = false; - dataGridView1.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + // dataGridView1.Columns["id"].Visible = false; + // dataGridView1.Columns[1].Visible = false; + dataGridView1.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } private void dataGridView1_SelectionChanged(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { - dataLabel.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); - actionLabel.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString(); - richTextBox1.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString(); + 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 = ""; diff --git a/Logs.cs b/Logs.cs index e9f61a3..79e6250 100644 --- a/Logs.cs +++ b/Logs.cs @@ -10,10 +10,23 @@ namespace AwesomeEmailExtractor public class Logs { public class LogData { + 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 @@ -46,10 +59,11 @@ namespace AwesomeEmailExtractor { logs.Add(new LogData() { + ID = Convert.ToInt32(reader["id"]), User = user, - Date = reader.GetString(0), - Action = (Action)reader.GetInt32(1), - Message = reader.GetString(2) + Date = Convert.ToString(reader["date"]), + Action = (Action)Convert.ToInt32(reader["action"]), + Message = Convert.ToString(reader["message"]), }); } @@ -67,7 +81,7 @@ namespace AwesomeEmailExtractor 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.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(); @@ -82,19 +96,17 @@ namespace AwesomeEmailExtractor 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(); @@ -103,10 +115,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"]) }); } @@ -137,5 +154,17 @@ namespace AwesomeEmailExtractor 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 75c2d4b..19645ee 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -37,11 +37,11 @@ this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = 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(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.journalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.resultStatusStrip.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -142,6 +142,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"; @@ -154,6 +161,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 // @@ -168,13 +176,6 @@ this.helpToolStripMenuItem.Size = new System.Drawing.Size(65, 20); this.helpToolStripMenuItem.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); - // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); diff --git a/MainForm.cs b/MainForm.cs index 4a6e3e8..acb76cb 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -74,5 +74,11 @@ namespace AwesomeEmailExtractor JournalForm journalForm = FormManager.Current.CreateForm(); journalForm.ShowDialog(this); } + + private void administrationToolStripMenuItem_Click(object sender, EventArgs e) + { + AdministrationForm administrationForm = FormManager.Current.CreateForm(); + administrationForm.ShowDialog(this); + } } }