добавляет удаление данных из журнвала

This commit is contained in:
Maxim Slipenko 2022-05-24 12:41:18 +03:00
parent 0f6d88a4ad
commit 51b75c35c5
Signed by: Maks1mS
GPG Key ID: 7461AF39A8705FB8
7 changed files with 303 additions and 37 deletions

View File

@ -41,13 +41,30 @@
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
@ -59,7 +76,7 @@
this.mainTabControl.Location = new System.Drawing.Point(0, 0);
this.mainTabControl.Name = "mainTabControl";
this.mainTabControl.SelectedIndex = 0;
this.mainTabControl.Size = new System.Drawing.Size(800, 450);
this.mainTabControl.Size = new System.Drawing.Size(998, 557);
this.mainTabControl.TabIndex = 0;
//
// mainSettingsTabPage
@ -70,7 +87,7 @@
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(792, 424);
this.mainSettingsTabPage.Size = new System.Drawing.Size(990, 531);
this.mainSettingsTabPage.TabIndex = 0;
this.mainSettingsTabPage.Text = "Общие настройки";
this.mainSettingsTabPage.UseVisualStyleBackColor = true;
@ -109,7 +126,7 @@
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(792, 424);
this.usersTabPage.Size = new System.Drawing.Size(990, 531);
this.usersTabPage.TabIndex = 1;
this.usersTabPage.Text = "Пользователи";
this.usersTabPage.UseVisualStyleBackColor = true;
@ -121,16 +138,16 @@
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(786, 390);
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.Controls.Add(this.journalDataGridView);
this.journalTabPage.Location = new System.Drawing.Point(4, 22);
this.journalTabPage.Name = "journalTabPage";
this.journalTabPage.Size = new System.Drawing.Size(792, 424);
this.journalTabPage.Size = new System.Drawing.Size(990, 531);
this.journalTabPage.TabIndex = 2;
this.journalTabPage.Text = "Журнал";
this.journalTabPage.UseVisualStyleBackColor = true;
@ -138,20 +155,24 @@
//
// panel1
//
this.panel1.Controls.Add(this.tableLayoutPanel1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(497, 0);
this.panel1.Location = new System.Drawing.Point(536, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(295, 424);
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, 0);
this.journalDataGridView.Location = new System.Drawing.Point(0, 37);
this.journalDataGridView.Name = "journalDataGridView";
this.journalDataGridView.Size = new System.Drawing.Size(792, 424);
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
//
@ -170,7 +191,7 @@
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(786, 28);
this.panel2.Size = new System.Drawing.Size(984, 28);
this.panel2.TabIndex = 2;
//
// deleteUserButton
@ -183,11 +204,140 @@
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(800, 450);
this.ClientSize = new System.Drawing.Size(998, 557);
this.Controls.Add(this.mainTabControl);
this.Name = "AdministrationForm";
this.Text = "Администрирование";
@ -198,8 +348,13 @@
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);
}
@ -219,5 +374,18 @@
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;
}
}

View File

@ -43,6 +43,17 @@ namespace AwesomeEmailExtractor
usersDataGridView.Columns[i].HeaderText = columns[i];
usersDataGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
var logs = Logs.GetLogsList();
journalDataGridView.DataSource = logs;
columns = new List<string>() { "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)
@ -68,6 +79,26 @@ namespace AwesomeEmailExtractor
}
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)
@ -82,6 +113,9 @@ namespace AwesomeEmailExtractor
AdminUtils adminUtils = new AdminUtils(Globals.currentUser);
var users = adminUtils.GetAllUsers();
usersDataGridView.DataSource = users;
var logs = Logs.GetLogsList();
journalDataGridView.DataSource = logs;
} else
{
MessageBox.Show("Выберите 1 пользователя для редактирования!");
@ -126,15 +160,42 @@ namespace AwesomeEmailExtractor
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;
}
AdminUtils adminUtils = new AdminUtils(Globals.currentUser);
var users = adminUtils.GetAllUsers();
usersDataGridView.DataSource = users;
}
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("Выберите хотя бы одну запись для удаления!");
}
}
}
}

View File

@ -117,4 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="sqliteCommand1.DesignTimeVisible" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="sqliteCommand1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -121,9 +121,9 @@ namespace AwesomeEmailExtractor
command.ExecuteNonQuery();
}
new public string ToString()
public override string ToString()
{
return this.Login;
return Login;
}
}

View File

@ -127,6 +127,7 @@
</Compile>
<EmbeddedResource Include="AdministrationForm.resx">
<DependentUpon>AdministrationForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="AuthorizationForm.resx">
<DependentUpon>AuthorizationForm.cs</DependentUpon>

View File

@ -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 = "";

59
Logs.cs
View File

@ -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();
}
}
}