diff --git a/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs new file mode 100644 index 0000000..bd0089c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs @@ -0,0 +1,62 @@ +namespace FurnitureAssembly +{ + partial class FormMail + { + /// + /// 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.dataGridViewMail = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewMail)).BeginInit(); + this.SuspendLayout(); + // + // dataGridViewMail + // + this.dataGridViewMail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewMail.Location = new System.Drawing.Point(0, 0); + this.dataGridViewMail.Name = "dataGridViewMail"; + this.dataGridViewMail.RowTemplate.Height = 25; + this.dataGridViewMail.Size = new System.Drawing.Size(801, 449); + this.dataGridViewMail.TabIndex = 0; + // + // FormMail + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataGridViewMail); + this.Name = "FormMail"; + this.Text = "Письма"; + this.Load += new System.EventHandler(this.FormMail_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewMail)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridViewMail; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMail.cs b/FurnitureAssembly/FurnitureAssembly/FormMail.cs new file mode 100644 index 0000000..fd2afdb --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormMail.cs @@ -0,0 +1,41 @@ +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + + +namespace FurnitureAssembly +{ + public partial class FormMail : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + public FormMail(ILogger logger, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormMail_Load(object sender, EventArgs e) + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridViewMail.DataSource = list; + dataGridViewMail.Columns["ClientId"].Visible = false; + dataGridViewMail.Columns["MessageId"].Visible = false; + dataGridViewMail.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка писем"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки писем"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormMail.resx b/FurnitureAssembly/FurnitureAssembly/FormMail.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormMail.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs index 6f60dff..2087b46 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs @@ -43,6 +43,7 @@ this.FurnituresComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.doWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.mailToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -91,7 +92,8 @@ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, this.отчетыToolStripMenuItem, - this.doWorkToolStripMenuItem}); + this.doWorkToolStripMenuItem, + this.mailToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1065, 24); @@ -175,6 +177,13 @@ this.doWorkToolStripMenuItem.Text = "Запуск работ"; this.doWorkToolStripMenuItem.Click += new System.EventHandler(this.doWorkToolStripMenuItem_Click); // + // mailToolStripMenuItem + // + this.mailToolStripMenuItem.Name = "mailToolStripMenuItem"; + this.mailToolStripMenuItem.Size = new System.Drawing.Size(62, 20); + this.mailToolStripMenuItem.Text = "Письма"; + this.mailToolStripMenuItem.Click += new System.EventHandler(this.mailToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -214,5 +223,6 @@ private ToolStripMenuItem ClientsMenuItem; private ToolStripMenuItem ImplementersToolStripMenuItem; private ToolStripMenuItem doWorkToolStripMenuItem; + private ToolStripMenuItem mailToolStripMenuItem; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 6fbada7..21806d5 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -219,5 +219,14 @@ namespace FurnitureAssembly Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); } + + private void mailToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMail)); + if (service is FormMail form) + { + form.ShowDialog(); + } + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 24a6528..775c796 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -7,6 +7,8 @@ using FurnitureAssemblyDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using FurnitureAssemblyBusinessLogic.MailWorker; +using FurnitureAssemblyContracts.BindingModels; namespace FurnitureAssembly { @@ -26,6 +28,35 @@ namespace FurnitureAssembly var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); + try + { + var mailSender = + _serviceProvider.GetService(); + mailSender?.MailConfig(new MailConfigBindingModel + { + MailLogin = + System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? + string.Empty, + MailPassword = + System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? + string.Empty, + SmtpClientHost = + System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? + string.Empty, + SmtpClientPort = + Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), + PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) + }); + // + var timer = new System.Threading.Timer(new + TimerCallback(MailCheck!), null, 0, 100000); + } + catch (Exception ex) + { + var logger = _serviceProvider.GetService(); + logger?.LogError(ex, " "); + } Application.Run(_serviceProvider.GetRequiredService()); } @@ -42,6 +73,7 @@ namespace FurnitureAssembly services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -50,6 +82,9 @@ namespace FurnitureAssembly services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + + services.AddSingleton(); services.AddTransient(); @@ -68,6 +103,9 @@ namespace FurnitureAssembly services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } + + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } \ No newline at end of file