diff --git a/Authorization.cs b/Authorization.cs
index 81f550d..deec387 100644
--- a/Authorization.cs
+++ b/Authorization.cs
@@ -113,6 +113,11 @@ namespace AwesomeEmailExtractor
command.ExecuteNonQuery();
}
+
+ new public string ToString()
+ {
+ return this.Login;
+ }
}
public class AdminUtils
diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj
index d078b5e..35b5fad 100644
--- a/AwesomeEmailExtractor.csproj
+++ b/AwesomeEmailExtractor.csproj
@@ -86,6 +86,12 @@
+
+ Form
+
+
+ JournalForm.cs
+
Form
@@ -110,6 +116,9 @@
AuthorizationForm.cs
+
+ JournalForm.cs
+
MainForm.cs
diff --git a/Globals.cs b/Globals.cs
index 9ba88dd..a953706 100644
--- a/Globals.cs
+++ b/Globals.cs
@@ -72,6 +72,9 @@ namespace AwesomeEmailExtractor
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.ExecuteNonQuery();
+ command.CommandText = "ATTACH DATABASE @dbpath AS appDB";
+ command.Parameters.AddWithValue("@dbpath", Globals.getAppDatabase());
+ command.ExecuteNonQuery();
}
public static void CreateTables()
diff --git a/JournalForm.Designer.cs b/JournalForm.Designer.cs
new file mode 100644
index 0000000..443a006
--- /dev/null
+++ b/JournalForm.Designer.cs
@@ -0,0 +1,174 @@
+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.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
+ this.dataLabel = new System.Windows.Forms.Label();
+ this.actionLabel = new System.Windows.Forms.Label();
+ this.richTextBox1 = new System.Windows.Forms.RichTextBox();
+ this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+ ((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;
+ //
+ // 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 = "Дата:";
+ //
+ // 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 = "Событие:";
+ //
+ // 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 = "Сообщение:";
+ //
+ // 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";
+ //
+ // richTextBox1
+ //
+ this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.richTextBox1.Location = new System.Drawing.Point(141, 53);
+ this.richTextBox1.Name = "richTextBox1";
+ this.richTextBox1.Size = new System.Drawing.Size(304, 385);
+ this.richTextBox1.TabIndex = 7;
+ this.richTextBox1.Text = "";
+ //
+ // 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;
+ //
+ // 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..55208ab
--- /dev/null
+++ b/JournalForm.cs
@@ -0,0 +1,43 @@
+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;
+ dataGridView1.Columns[0].Visible = false;
+ dataGridView1.Columns[3].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();
+ } 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..e9f61a3 100644
--- a/Logs.cs
+++ b/Logs.cs
@@ -10,10 +10,10 @@ namespace AwesomeEmailExtractor
public class Logs
{
public class LogData {
- public User user;
- public string date;
- public Action action;
- public string message;
+ public User User { get; set; }
+ public string Date { get; set; }
+ public Action Action { get; set; }
+ public string Message { get; set; }
}
public enum Action
@@ -37,33 +37,49 @@ 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)
+ User = user,
+ Date = reader.GetString(0),
+ Action = (Action)reader.GetInt32(1),
+ Message = reader.GetString(2)
});
}
+ 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 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";
@@ -87,10 +103,10 @@ 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)
+ 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)
});
}
diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs
index f949bab..75c2d4b 100644
--- a/MainForm.Designer.cs
+++ b/MainForm.Designer.cs
@@ -41,6 +41,7 @@
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();
@@ -57,7 +58,7 @@
"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
@@ -133,6 +134,7 @@
// аккаунтToolStripMenuItem
//
this.аккаунтToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.journalToolStripMenuItem,
this.settingsToolStripMenuItem,
this.administrationToolStripMenuItem,
this.exitToolStripMenuItem});
@@ -166,6 +168,13 @@
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);
@@ -205,6 +214,7 @@
private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem administrationToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem journalToolStripMenuItem;
}
}
diff --git a/MainForm.cs b/MainForm.cs
index 5ebee65..4a6e3e8 100644
--- a/MainForm.cs
+++ b/MainForm.cs
@@ -68,5 +68,11 @@ 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);
+ }
}
}