diff --git a/SushiBar/App.config b/SushiBar/App.config new file mode 100644 index 0000000..c20b6ab --- /dev/null +++ b/SushiBar/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/SushiBar/FormMails.Designer.cs b/SushiBar/FormMails.Designer.cs new file mode 100644 index 0000000..3d6a761 --- /dev/null +++ b/SushiBar/FormMails.Designer.cs @@ -0,0 +1,63 @@ +namespace SushiBarView +{ + partial class FormMails + { + /// + /// 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.SkyBlue; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(800, 450); + dataGridView.TabIndex = 0; + // + // FormMails + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "FormMails"; + Text = "FormMails"; + Load += FormMails_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SushiBar/FormMails.cs b/SushiBar/FormMails.cs new file mode 100644 index 0000000..2d64b6f --- /dev/null +++ b/SushiBar/FormMails.cs @@ -0,0 +1,44 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBarView +{ + public partial class FormMails : Form + { + private readonly ILogger logger; + private readonly IMessageInfoLogic messageInfoLogic; + public FormMails(ILogger logger, IMessageInfoLogic messageInfoLogic) + { + this.logger = logger; + this.messageInfoLogic = messageInfoLogic; + InitializeComponent(); + } + + private void LoadData() + { + try + { + var list = messageInfoLogic.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("Load list of mails"); + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK); + logger.LogError("Load list of mails failed"); + } + } + + private void FormMails_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBar/FormMails.resx b/SushiBar/FormMails.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBar/FormMails.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/SushiBar/FormMain.Designer.cs b/SushiBar/FormMain.Designer.cs index f9c2517..e35c723 100644 --- a/SushiBar/FormMain.Designer.cs +++ b/SushiBar/FormMain.Designer.cs @@ -43,6 +43,7 @@ buttonCreateOrder = new Button(); buttonOrderIssued = new Button(); buttonRefreshOrders = new Button(); + списокПисемToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -50,7 +51,7 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { ToolStripMenuItemRef, отчетыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, запускРаботToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { ToolStripMenuItemRef, отчетыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, запускРаботToolStripMenuItem, списокПисемToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1316, 28); @@ -174,6 +175,13 @@ buttonRefreshOrders.UseVisualStyleBackColor = true; buttonRefreshOrders.Click += ButtonRef_Click; // + // списокПисемToolStripMenuItem + // + списокПисемToolStripMenuItem.Name = "списокПисемToolStripMenuItem"; + списокПисемToolStripMenuItem.Size = new Size(121, 24); + списокПисемToolStripMenuItem.Text = "Список писем"; + списокПисемToolStripMenuItem.Click += списокПисемToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -214,5 +222,6 @@ private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem списокПисемToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/FormMain.cs b/SushiBar/FormMain.cs index a439311..edcb1d9 100644 --- a/SushiBar/FormMain.cs +++ b/SushiBar/FormMain.cs @@ -162,5 +162,14 @@ namespace SushiBarView _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } + + private void списокПисемToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + if(service is FormMails form) + { + form.ShowDialog(); + } + } } } diff --git a/SushiBar/Program.cs b/SushiBar/Program.cs index f5e29b8..5a1c3dd 100644 --- a/SushiBar/Program.cs +++ b/SushiBar/Program.cs @@ -1,10 +1,13 @@ +using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using SushiBarBusinessLogic; using SushiBarBusinessLogic.BusinessLogic; +using SushiBarBusinessLogic.MailWorker; using SushiBarBusinessLogic.OfficePackage; using SushiBarBusinessLogic.OfficePackage.Implements; +using SushiBarContracts.BindingModel; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; using SushiBarDatabaseImplement.Implements; @@ -30,11 +33,28 @@ namespace SushiBar // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); - // PDF - // NuGet System.Text.Encoding.CodePages - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 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["SmtpClient Port"]), + 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()); } @@ -50,6 +70,7 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -58,6 +79,8 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -75,7 +98,8 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); - + services.AddTransient(); } + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } \ No newline at end of file