diff --git a/ProjectFlowerShop/FormViewMail.Designer.cs b/ProjectFlowerShop/FormViewMail.Designer.cs new file mode 100644 index 0000000..5eb1ca1 --- /dev/null +++ b/ProjectFlowerShop/FormViewMail.Designer.cs @@ -0,0 +1,62 @@ +namespace ProjectFlowerShop +{ + partial class FormViewMail + { + /// + /// 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.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(776, 426); + dataGridView.TabIndex = 0; + // + // ViewMailForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "ViewMailForm"; + Text = "ViewMailForm"; + Load += ViewMailForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/FormViewMail.cs b/ProjectFlowerShop/FormViewMail.cs new file mode 100644 index 0000000..8e3d10d --- /dev/null +++ b/ProjectFlowerShop/FormViewMail.cs @@ -0,0 +1,48 @@ +using FlowerShopContracts.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 ProjectFlowerShop +{ + public partial class FormViewMail : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + public FormViewMail(ILogger logger, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ViewMailForm_Load(object sender, EventArgs e) + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["MessageId"].Visible = false; + dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка списка писем"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки писем"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } +} diff --git a/ProjectFlowerShop/FormViewMail.resx b/ProjectFlowerShop/FormViewMail.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectFlowerShop/FormViewMail.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/ProjectFlowerShop/MainForm.Designer.cs b/ProjectFlowerShop/MainForm.Designer.cs index 3605954..07caf38 100644 --- a/ProjectFlowerShop/MainForm.Designer.cs +++ b/ProjectFlowerShop/MainForm.Designer.cs @@ -45,6 +45,7 @@ ReadyButton = new Button(); IssuedButton = new Button(); RefreshButton = new Button(); + почтаToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); SuspendLayout(); @@ -61,7 +62,7 @@ // // ToolStripMenu // - ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, стартРаботToolStripMenuItem }); + ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, стартРаботToolStripMenuItem, почтаToolStripMenuItem }); ToolStripMenu.Name = "ToolStripMenu"; ToolStripMenu.Size = new Size(117, 24); ToolStripMenu.Text = "Справочники"; @@ -69,35 +70,35 @@ // КомпонентыStripMenuItem // КомпонентыStripMenuItem.Name = "КомпонентыStripMenuItem"; - КомпонентыStripMenuItem.Size = new Size(185, 26); + КомпонентыStripMenuItem.Size = new Size(224, 26); КомпонентыStripMenuItem.Text = "Компоненты"; КомпонентыStripMenuItem.Click += КомпонентыStripMenuItem_Click; // // ЦветыStripMenuItem // ЦветыStripMenuItem.Name = "ЦветыStripMenuItem"; - ЦветыStripMenuItem.Size = new Size(185, 26); + ЦветыStripMenuItem.Size = new Size(224, 26); ЦветыStripMenuItem.Text = "Цветы"; ЦветыStripMenuItem.Click += ЦветыStripMenuItem_Click; // // клиентыToolStripMenuItem // клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(185, 26); + клиентыToolStripMenuItem.Size = new Size(224, 26); клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; // // исполнителиToolStripMenuItem // исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(185, 26); + исполнителиToolStripMenuItem.Size = new Size(224, 26); исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; // // стартРаботToolStripMenuItem // стартРаботToolStripMenuItem.Name = "стартРаботToolStripMenuItem"; - стартРаботToolStripMenuItem.Size = new Size(185, 26); + стартРаботToolStripMenuItem.Size = new Size(224, 26); стартРаботToolStripMenuItem.Text = "Старт работ"; стартРаботToolStripMenuItem.Click += стартРаботToolStripMenuItem_Click; // @@ -188,6 +189,13 @@ RefreshButton.UseVisualStyleBackColor = true; RefreshButton.Click += RefreshButton_Click; // + // почтаToolStripMenuItem + // + почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + почтаToolStripMenuItem.Size = new Size(224, 26); + почтаToolStripMenuItem.Text = "Почта"; + почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; + // // MainForm // AutoScaleDimensions = new SizeF(8F, 20F); @@ -230,5 +238,6 @@ private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem стартРаботToolStripMenuItem; + private ToolStripMenuItem почтаToolStripMenuItem; } } \ No newline at end of file diff --git a/ProjectFlowerShop/MainForm.cs b/ProjectFlowerShop/MainForm.cs index cfe5499..103496a 100644 --- a/ProjectFlowerShop/MainForm.cs +++ b/ProjectFlowerShop/MainForm.cs @@ -245,5 +245,14 @@ namespace ProjectFlowerShop form.ShowDialog(); } } + + private void почтаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormViewMail)); + if (service is FormViewMail form) + { + form.ShowDialog(); + } + } } } diff --git a/ProjectFlowerShop/Program.cs b/ProjectFlowerShop/Program.cs index abe403a..c6924ed 100644 --- a/ProjectFlowerShop/Program.cs +++ b/ProjectFlowerShop/Program.cs @@ -1,4 +1,4 @@ -using FlowerShopBusinessLogic.BusinessLogic; +using FlowerShopBusinessLogic.BusinessLogic; using FlowerShopContracts.BusinessLogicsContracts; using FlowerShopContracts.StoragesContracts; using FlowerShopDatabaseImplement.Implements; @@ -11,6 +11,8 @@ using System.Drawing; using FlowerShopBusinessLogic; using FlowerShopBusinessLogic.OfficePackage.Implements; using FlowerShopBusinessLogic.OfficePackage; +using FlowerShopBusinessLogic.MailWorker; +using FlowerShopContracts.BindingModels; namespace ProjectFlowerShop { @@ -28,7 +30,38 @@ namespace ProjectFlowerShop 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, "Îøèáêà ðàáîòû ñ ïî÷òîé"); + } + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) { @@ -62,10 +95,13 @@ namespace ProjectFlowerShop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); services.AddTransient(); services.AddTransient(); } + private static void MailCheck(object obj) =>ServiceProvider?.GetService()?.MailCheck(); - } + } }