diff --git a/Confectionery/ConfectioneryBusinessLogic/AbstractMailWorker.cs b/Confectionery/ConfectioneryBusinessLogic/AbstractMailWorker.cs index d8c4abf..ae7d120 100644 --- a/Confectionery/ConfectioneryBusinessLogic/AbstractMailWorker.cs +++ b/Confectionery/ConfectioneryBusinessLogic/AbstractMailWorker.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using ConfectioneryContracts.BindingModels; using System; using System.Collections.Generic; using System.Linq; @@ -8,7 +9,7 @@ using System.Threading.Tasks; namespace ConfectioneryBusinessLogic { - public class AbstractMailWorker + public abstract class AbstractMailWorker { protected string _mailLogin = string.Empty; protected string _mailPassword = string.Empty; diff --git a/Confectionery/ConfectioneryDatabaseImplement/MessageInfo.cs b/Confectionery/ConfectioneryDatabaseImplement/MessageInfo.cs index 1b357e2..926aa49 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/MessageInfo.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/MessageInfo.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryDatabaseImplement +namespace ConfectioneryDatabaseImplement.Models { public class MessageInfo : IMessageInfoModel { diff --git a/Confectionery/ConfectioneryDatabaseImplement/MessageInfoStorage.cs b/Confectionery/ConfectioneryDatabaseImplement/MessageInfoStorage.cs index 934db93..0092495 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/MessageInfoStorage.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/MessageInfoStorage.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; using ConfectioneryContracts.ViewModels; using System; using System.Collections.Generic; @@ -9,7 +10,7 @@ using System.Threading.Tasks; namespace ConfectioneryDatabaseImplement.Implements { - public class MessageInfoStorage + public class MessageInfoStorage : IMessageInfoStorage { public List GetFullList() { diff --git a/Confectionery/ConfectioneryFileImplement/MessageInfo.cs b/Confectionery/ConfectioneryFileImplement/MessageInfo.cs new file mode 100644 index 0000000..6889771 --- /dev/null +++ b/Confectionery/ConfectioneryFileImplement/MessageInfo.cs @@ -0,0 +1,80 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ConfectioneryFileImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public static MessageInfo? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Body = element.Attribute("Body")!.Value, + Subject = element.Attribute("Subject")!.Value, + ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), + MessageId = element.Attribute("MessageId")!.Value, + SenderName = element.Attribute("SenderName")!.Value, + DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value), + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + + public XElement GetXElement => new("MessageInfo", + new XAttribute("Body", Body), + new XAttribute("Subject", Subject), + new XAttribute("ClientId", ClientId), + new XAttribute("MessageId", MessageId), + new XAttribute("SenderName", SenderName), + new XAttribute("DateDelivery", DateDelivery) + ); + } +} diff --git a/Confectionery/ConfectioneryFileImplement/MessageInfoStorage.cs b/Confectionery/ConfectioneryFileImplement/MessageInfoStorage.cs index af0d5dd..87ae8e6 100644 --- a/Confectionery/ConfectioneryFileImplement/MessageInfoStorage.cs +++ b/Confectionery/ConfectioneryFileImplement/MessageInfoStorage.cs @@ -2,6 +2,7 @@ using ConfectioneryContracts.SearchModels; using ConfectioneryContracts.StoragesContracts; using ConfectioneryContracts.ViewModels; +using ConfectioneryFileImplement.Models; using ConfectioneryDatabaseImplement; using System; using System.Collections.Generic; diff --git a/Confectionery/ConfectioneryView/FormMail.Designer.cs b/Confectionery/ConfectioneryView/FormMail.Designer.cs new file mode 100644 index 0000000..dbfcbb2 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMail.Designer.cs @@ -0,0 +1,62 @@ +namespace ConfectioneryView +{ + 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() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = Color.AliceBlue; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.Size = new Size(998, 462); + dataGridView.TabIndex = 0; + // + // FormMail + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1022, 486); + Controls.Add(dataGridView); + Name = "FormMail"; + Text = "Письма"; + Load += FormMail_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMail.cs b/Confectionery/ConfectioneryView/FormMail.cs new file mode 100644 index 0000000..3def25c --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMail.cs @@ -0,0 +1,54 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 ConfectioneryView +{ + 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 LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["MessageId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["Body"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка почтовых собщений"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки почтовых сообщений"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormMail_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormMail.resx b/Confectionery/ConfectioneryView/FormMail.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMail.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/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index 62f9289..d3bb85a 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -45,6 +45,7 @@ buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); + mailToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -62,7 +63,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(24, 24); - menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, отчетыToolStripMenuItem, startWorkToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, отчетыToolStripMenuItem, startWorkToolStripMenuItem, mailToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1921, 33); @@ -194,6 +195,13 @@ buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += buttonRef_Click; // + // mailToolStripMenuItem + // + mailToolStripMenuItem.Name = "mailToolStripMenuItem"; + mailToolStripMenuItem.Size = new Size(78, 29); + mailToolStripMenuItem.Text = "Почта"; + mailToolStripMenuItem.Click += mailToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(10F, 25F); @@ -236,5 +244,6 @@ private ToolStripMenuItem clientsToolStripMenuItem; private ToolStripMenuItem implementersToolStripMenuItem; private ToolStripMenuItem startWorkToolStripMenuItem; + private ToolStripMenuItem mailToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index 3f8cdde..250c8c3 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -221,5 +221,14 @@ namespace ConfectioneryView _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } + + 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/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index 8d07ab7..24bde84 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using ConfectioneryBusinessLogic.BusinessLogics; using Microsoft.EntityFrameworkCore.Design; +using ConfectioneryContracts.BindingModels; namespace ConfectioneryView { @@ -27,7 +28,27 @@ namespace ConfectioneryView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); + 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, "Mails Problem"); + } + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) { @@ -39,6 +60,7 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -47,11 +69,13 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddSingleton(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -63,7 +87,9 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); } - } + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + } } \ No newline at end of file