diff --git a/CarpentryWorkshop/CarpentryWorkshop/App.config b/CarpentryWorkshop/CarpentryWorkshop/App.config new file mode 100644 index 0000000..99706ef --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/CarpentryWorkshopView.csproj b/CarpentryWorkshop/CarpentryWorkshop/CarpentryWorkshopView.csproj index 1f871b3..2dc7562 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/CarpentryWorkshopView.csproj +++ b/CarpentryWorkshop/CarpentryWorkshop/CarpentryWorkshopView.csproj @@ -60,4 +60,10 @@ + + + PreserveNewest + + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMails.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMails.Designer.cs new file mode 100644 index 0000000..8f62fcb --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMails.Designer.cs @@ -0,0 +1,62 @@ +namespace CarpentryWorkshopView +{ + 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.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(800, 450); + dataGridView.TabIndex = 0; + // + // FormMails + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "FormMails"; + Text = "Mails"; + Load += FormMails_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMails.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMails.cs new file mode 100644 index 0000000..e64e7c8 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMails.cs @@ -0,0 +1,40 @@ +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopView +{ + public partial class FormMails : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + + public FormMails(ILogger logger, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormMails_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, "Eror", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMails.resx b/CarpentryWorkshop/CarpentryWorkshop/FormMails.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/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/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs index b91e7c9..b15c876 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs @@ -39,6 +39,7 @@ компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); запускРаботToolStripMenuItem = new ToolStripMenuItem(); + mailsToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); ButtonCreateOrder = new Button(); ButtonIssuedOrder = new Button(); @@ -58,7 +59,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ИзделияToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ИзделияToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, mailsToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(94, 20); справочникиToolStripMenuItem.Text = "Справочники"; @@ -126,6 +127,13 @@ запускРаботToolStripMenuItem.Text = "Запуск Работ"; запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; // + // mailsToolStripMenuItem + // + mailsToolStripMenuItem.Name = "mailsToolStripMenuItem"; + mailsToolStripMenuItem.Size = new Size(180, 22); + mailsToolStripMenuItem.Text = "mails"; + mailsToolStripMenuItem.Click += mailsToolStripMenuItem_Click; + // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -205,5 +213,6 @@ private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem mailsToolStripMenuItem; } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs index 12da52b..a423db7 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs @@ -212,5 +212,13 @@ namespace CarpentryWorkshopView _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } + private void mailsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + if (service is FormMails form) + { + form.ShowDialog(); + } + } } } diff --git a/CarpentryWorkshop/CarpentryWorkshop/Program.cs b/CarpentryWorkshop/CarpentryWorkshop/Program.cs index 658d126..4c0d157 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/Program.cs @@ -4,6 +4,8 @@ using CarpentryWorkshopBusinessLogic.OfficePackage.Implements; using CarpentryWorkshopContracts.BusinessLogicsContracts; using CarpentryWorkshopContracts.StoragesContracts; using CarpentryWorkshopDatabaseImplement.Implements; +using CarpentryWorkshopBusinessLogic.MailWorker; +using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopView; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -28,10 +30,32 @@ namespace CarpentryWorkshop var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(ServiceCollection services) + 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 MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void ConfigureServices(ServiceCollection services) { services.AddLogging(option => { @@ -43,6 +67,7 @@ namespace CarpentryWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -51,6 +76,8 @@ namespace CarpentryWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddSingleton(); services.AddTransient(); services.AddTransient(); @@ -68,6 +95,7 @@ namespace CarpentryWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + } } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopClientApp/Controllers/HomeController.cs b/CarpentryWorkshop/CarpentryWorkshopClientApp/Controllers/HomeController.cs index e5bc725..a6311ca 100644 --- a/CarpentryWorkshop/CarpentryWorkshopClientApp/Controllers/HomeController.cs +++ b/CarpentryWorkshop/CarpentryWorkshopClientApp/Controllers/HomeController.cs @@ -143,5 +143,15 @@ namespace CarpentryWorkshopClientApp.Controllers var r = APIClient.GetRequest($"api/main/getwood?woodId={wood}"); return count * (r?.Price ?? 1); } - } + + [HttpGet] + public IActionResult Mails() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); + } + } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopClientApp/Views/Home/Mails.cshtml b/CarpentryWorkshop/CarpentryWorkshopClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..70c0ed4 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,54 @@ +@using CarpentryWorkshopContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Mails"; +} + +
+

Mails

+
+ + +
+ @{ + if (Model == null) + { +

Login bobr!

+ return; + } + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Mail's date' + + Title + + Text +
+ @Html.DisplayFor(modelItem => item.DateDelivery) + + @Html.DisplayFor(modelItem => item.Subject) + + @Html.DisplayFor(modelItem => item.Body) +
+ } +
\ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopClientApp/Views/Shared/_Layout.cshtml b/CarpentryWorkshop/CarpentryWorkshopClientApp/Views/Shared/_Layout.cshtml index 013ed14..70fc259 100644 --- a/CarpentryWorkshop/CarpentryWorkshopClientApp/Views/Shared/_Layout.cshtml +++ b/CarpentryWorkshop/CarpentryWorkshopClientApp/Views/Shared/_Layout.cshtml @@ -27,6 +27,9 @@ + diff --git a/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ClientController.cs b/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ClientController.cs index a915668..958040b 100644 --- a/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ClientController.cs +++ b/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ClientController.cs @@ -11,14 +11,15 @@ namespace CarpentryWorkshopRestApi.Controllers public class ClientController : Controller { private readonly ILogger _logger; - private readonly IClientLogic _logic; + private readonly IMessageInfoLogic _mailLogic; - public ClientController(IClientLogic logic, ILogger logger) + public ClientController(IClientLogic logic, ILogger logger, IMessageInfoLogic mailLogic) { _logger = logger; _logic = logic; - } + _mailLogic = mailLogic; + } [HttpGet] public ClientViewModel? Login(string login, string password) @@ -65,5 +66,22 @@ namespace CarpentryWorkshopRestApi.Controllers throw; } } - } + + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + } + } } diff --git a/CarpentryWorkshop/CarpentryWorkshopRestApi/Program.cs b/CarpentryWorkshop/CarpentryWorkshopRestApi/Program.cs index 1116a1f..726f9fb 100644 --- a/CarpentryWorkshop/CarpentryWorkshopRestApi/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshopRestApi/Program.cs @@ -2,7 +2,8 @@ using CarpentryWorkshopBusinessLogic.BusinessLogics; using CarpentryWorkshopContracts.BusinessLogicsContracts; using CarpentryWorkshopContracts.StoragesContracts; using CarpentryWorkshopDatabaseImplement.Implements; - +using CarpentryWorkshopBusinessLogic.MailWorker; +using CarpentryWorkshopContracts.BindingModels; using Microsoft.OpenApi.Models; var builder = WebApplication.CreateBuilder(args); @@ -13,10 +14,13 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddSingleton(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle @@ -32,6 +36,17 @@ builder.Services.AddSwaggerGen(c => var app = builder.Build(); +var mailSender = app.Services.GetService(); +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) +}); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/CarpentryWorkshop/CarpentryWorkshopRestApi/appsettings.json b/CarpentryWorkshop/CarpentryWorkshopRestApi/appsettings.json index 10f68b8..533dcb5 100644 --- a/CarpentryWorkshop/CarpentryWorkshopRestApi/appsettings.json +++ b/CarpentryWorkshop/CarpentryWorkshopRestApi/appsettings.json @@ -5,5 +5,12 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "gziraelc@gmail.com", + "MailPassword": "waav nuyn tqih ccel" }