From 1f5558c190d0335700155b7899f5653708c7396e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Sun, 5 May 2024 14:24:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20=D0=B2=D1=81?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB,=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=87=D1=82=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BA=D1=80=D0=B8=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ClientLogic.cs | 5 + .../BusinessLogics/MessageInfoLogic.cs | 2 +- .../Controllers/HomeController.cs | 13 +- .../Views/Home/Mails.cshtml | 52 ++++++++ .../Views/Home/_Layout.cshtml | 3 + .../Implements/ClientStorage.cs | 2 +- ... 20240505094524_InitMigration.Designer.cs} | 43 ++++++- ...ate.cs => 20240505094524_InitMigration.cs} | 31 ++++- .../CarRepairShopDatabaseModelSnapshot.cs | 39 ++++++ .../Controllers/ClientController.cs | 21 ++- CarRepairShop/CarRepairShopRestApi/Program.cs | 17 ++- .../CarRepairShopView/FormLetters.Designer.cs | 67 ++++++++++ .../CarRepairShopView/FormLetters.cs | 39 ++++++ .../CarRepairShopView/FormLetters.resx | 120 ++++++++++++++++++ .../CarRepairShopView/FormMain.Designer.cs | 23 +++- CarRepairShop/CarRepairShopView/FormMain.cs | 11 +- CarRepairShop/CarRepairShopView/Program.cs | 23 ++++ 17 files changed, 494 insertions(+), 17 deletions(-) create mode 100644 CarRepairShop/CarRepairShopClientApp/Views/Home/Mails.cshtml rename CarRepairShop/CarRepairShopDatabaseImplement/Migrations/{20240420181926_InitialCreate.Designer.cs => 20240505094524_InitMigration.Designer.cs} (85%) rename CarRepairShop/CarRepairShopDatabaseImplement/Migrations/{20240420181926_InitialCreate.cs => 20240505094524_InitMigration.cs} (84%) create mode 100644 CarRepairShop/CarRepairShopView/FormLetters.Designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormLetters.cs create mode 100644 CarRepairShop/CarRepairShopView/FormLetters.resx diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ClientLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ClientLogic.cs index 36f8ded..08db84d 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ClientLogic.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace CarRepairShopBusinessLogic.BusinessLogics @@ -97,6 +98,10 @@ namespace CarRepairShopBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO)); } + if (string.IsNullOrEmpty(model.Email) || !Regex.IsMatch(model.Email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", RegexOptions.IgnoreCase)) + { + throw new ArgumentNullException("Нет почты клиента", nameof(model.Email)); + } if (string.IsNullOrEmpty(model.Password)) { throw new ArgumentNullException("Нет пароля клиента", nameof(model.ClientFIO)); diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs index 0effa07..41914a3 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -18,7 +18,7 @@ namespace CarRepairShopBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly IMessageInfoStorage _storage; - public MessageInfoLogic(ILogger logger, IMessageInfoStorage storage) + public MessageInfoLogic(ILogger logger, IMessageInfoStorage storage) { _logger = logger; _storage = storage; diff --git a/CarRepairShop/CarRepairShopClientApp/Controllers/HomeController.cs b/CarRepairShop/CarRepairShopClientApp/Controllers/HomeController.cs index 0a67018..d08bad9 100644 --- a/CarRepairShop/CarRepairShopClientApp/Controllers/HomeController.cs +++ b/CarRepairShop/CarRepairShopClientApp/Controllers/HomeController.cs @@ -3,6 +3,7 @@ using CarRepairShopContracts.BindingModels; using CarRepairShopContracts.ViewModels; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.Extensions.Logging; using System.Diagnostics; namespace CarRepairShopClientApp.Controllers @@ -125,5 +126,15 @@ namespace CarRepairShopClientApp.Controllers var rep = APIClient.GetRequest($"api/main/getrepair?repairId={repair}"); return count * (rep?.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}")); + } + } } diff --git a/CarRepairShop/CarRepairShopClientApp/Views/Home/Mails.cshtml b/CarRepairShop/CarRepairShopClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..0464add --- /dev/null +++ b/CarRepairShop/CarRepairShopClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,52 @@ +@using CarRepairShopContracts.ViewModels +@model List + +@{ + ViewData["Title"] = "Mails"; +} +
+

Заказы

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

Авторизируйтесь

+ return; + } + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Дата письма + + Заголовок + + Текст +
+ @Html.DisplayFor(modelItem => + item.DateDelivery) + + @Html.DisplayFor(modelItem => + item.Subject) + + @Html.DisplayFor(modelItem => + item.Body) +
+ } +
\ No newline at end of file diff --git a/CarRepairShop/CarRepairShopClientApp/Views/Home/_Layout.cshtml b/CarRepairShop/CarRepairShopClientApp/Views/Home/_Layout.cshtml index 3af6d2a..f307b48 100644 --- a/CarRepairShop/CarRepairShopClientApp/Views/Home/_Layout.cshtml +++ b/CarRepairShop/CarRepairShopClientApp/Views/Home/_Layout.cshtml @@ -31,6 +31,9 @@ + diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/ClientStorage.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/ClientStorage.cs index 7f56f1f..d189ad5 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/ClientStorage.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/ClientStorage.cs @@ -31,7 +31,7 @@ namespace CarRepairShopDatabaseImplement.Implements } public ClientViewModel? GetElement(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email)) + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) { return null; } diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240420181926_InitialCreate.Designer.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240505094524_InitMigration.Designer.cs similarity index 85% rename from CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240420181926_InitialCreate.Designer.cs rename to CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240505094524_InitMigration.Designer.cs index 8b690cd..a4c99f7 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240420181926_InitialCreate.Designer.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240505094524_InitMigration.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace CarRepairShopDatabaseImplement.Migrations { [DbContext(typeof(CarRepairShopDatabase))] - [Migration("20240420181926_InitialCreate")] - partial class InitialCreate + [Migration("20240505094524_InitMigration")] + partial class InitMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -97,6 +97,36 @@ namespace CarRepairShopDatabaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -186,6 +216,15 @@ namespace CarRepairShopDatabaseImplement.Migrations b.ToTable("RepairComponents"); }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("CarRepairShopDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b => { b.HasOne("CarRepairShopDatabaseImplement.Models.Client", "Client") diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240420181926_InitialCreate.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240505094524_InitMigration.cs similarity index 84% rename from CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240420181926_InitialCreate.cs rename to CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240505094524_InitMigration.cs index bd036cb..f244d2a 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240420181926_InitialCreate.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240505094524_InitMigration.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace CarRepairShopDatabaseImplement.Migrations { /// - public partial class InitialCreate : Migration + public partial class InitMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -70,6 +70,27 @@ namespace CarRepairShopDatabaseImplement.Migrations table.PrimaryKey("PK_Repairs", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + ClientId = table.Column(type: "int", nullable: true), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + table.ForeignKey( + name: "FK_Messages_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + }); + migrationBuilder.CreateTable( name: "Orders", columns: table => new @@ -134,6 +155,11 @@ namespace CarRepairShopDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ClientId", table: "Orders", @@ -163,6 +189,9 @@ namespace CarRepairShopDatabaseImplement.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "Messages"); + migrationBuilder.DropTable( name: "Orders"); diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs index 7f581b0..8347d81 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs @@ -94,6 +94,36 @@ namespace CarRepairShopDatabaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -183,6 +213,15 @@ namespace CarRepairShopDatabaseImplement.Migrations b.ToTable("RepairComponents"); }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("CarRepairShopDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b => { b.HasOne("CarRepairShopDatabaseImplement.Models.Client", "Client") diff --git a/CarRepairShop/CarRepairShopRestApi/Controllers/ClientController.cs b/CarRepairShop/CarRepairShopRestApi/Controllers/ClientController.cs index f9f2030..3cf4679 100644 --- a/CarRepairShop/CarRepairShopRestApi/Controllers/ClientController.cs +++ b/CarRepairShop/CarRepairShopRestApi/Controllers/ClientController.cs @@ -13,11 +13,13 @@ namespace CarRepairShopRestApi.Controllers { 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) { _logic = logic; _logger = logger; + _mailLogic = mailLogic; } [HttpGet] @@ -65,5 +67,22 @@ namespace CarRepairShopRestApi.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/CarRepairShop/CarRepairShopRestApi/Program.cs b/CarRepairShop/CarRepairShopRestApi/Program.cs index 1d1cd72..8b0627e 100644 --- a/CarRepairShop/CarRepairShopRestApi/Program.cs +++ b/CarRepairShop/CarRepairShopRestApi/Program.cs @@ -1,5 +1,6 @@ using CarRepairShopBusinessLogic.BusinessLogics; using CarRepairShopBusinessLogic.MailWorker; +using CarRepairShopContracts.BindingModels; using CarRepairShopContracts.BusinessLogicsContracts; using CarRepairShopContracts.StoragesContracts; using CarRepairShopDatabaseImplement.Implements; @@ -16,16 +17,16 @@ 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 builder.Services.AddEndpointsApiExplorer(); @@ -40,6 +41,18 @@ 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/CarRepairShop/CarRepairShopView/FormLetters.Designer.cs b/CarRepairShop/CarRepairShopView/FormLetters.Designer.cs new file mode 100644 index 0000000..d73b464 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormLetters.Designer.cs @@ -0,0 +1,67 @@ +namespace CarRepairShopView +{ + partial class FormLetters + { + /// + /// 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.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(800, 450); + dataGridView.TabIndex = 2; + // + // FormLetters + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "FormLetters"; + Text = "Письма"; + Load += FormLetters_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormLetters.cs b/CarRepairShop/CarRepairShopView/FormLetters.cs new file mode 100644 index 0000000..76929e9 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormLetters.cs @@ -0,0 +1,39 @@ +using CarRepairShopContracts.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 CarRepairShopView +{ + public partial class FormLetters : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + + public FormLetters(ILogger logger, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormLetters_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка писем"); + var list = _logic.ReadList(null); + if(list != null ) + { + dataGridView.DataSource = list; + dataGridView.Columns["MessageId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; + } + } + } +} diff --git a/CarRepairShop/CarRepairShopView/FormLetters.resx b/CarRepairShop/CarRepairShopView/FormLetters.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormLetters.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/CarRepairShop/CarRepairShopView/FormMain.Designer.cs b/CarRepairShop/CarRepairShopView/FormMain.Designer.cs index bf7a664..5c0b4bb 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.Designer.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.Designer.cs @@ -38,18 +38,19 @@ OrdersToolStripMenuItem = new ToolStripMenuItem(); ClientsToolStripMenuItem = new ToolStripMenuItem(); workStartToolStripMenuItem = new ToolStripMenuItem(); + implementersToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); - implementersToolStripMenuItem = new ToolStripMenuItem(); + почтаToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // menuStrip1 // - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, ClientsToolStripMenuItem, workStartToolStripMenuItem, implementersToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, ClientsToolStripMenuItem, workStartToolStripMenuItem, implementersToolStripMenuItem, почтаToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1059, 24); @@ -119,6 +120,13 @@ workStartToolStripMenuItem.Text = "Запуск работ"; workStartToolStripMenuItem.Click += workStartToolStripMenuItem_Click; // + // implementersToolStripMenuItem + // + implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; + implementersToolStripMenuItem.Size = new Size(94, 20); + implementersToolStripMenuItem.Text = "Исполнители"; + implementersToolStripMenuItem.Click += implementersToolStripMenuItem_Click; + // // dataGridView // dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; @@ -167,12 +175,12 @@ buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += buttonRef_Click; // - // implementersToolStripMenuItem + // почтаToolStripMenuItem // - implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; - implementersToolStripMenuItem.Size = new Size(94, 20); - implementersToolStripMenuItem.Text = "Исполнители"; - implementersToolStripMenuItem.Click += implementersToolStripMenuItem_Click; + почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + почтаToolStripMenuItem.Size = new Size(53, 20); + почтаToolStripMenuItem.Text = "Почта"; + почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; // // FormMain // @@ -212,5 +220,6 @@ private ToolStripMenuItem ClientsToolStripMenuItem; private ToolStripMenuItem workStartToolStripMenuItem; private ToolStripMenuItem implementersToolStripMenuItem; + private ToolStripMenuItem почтаToolStripMenuItem; } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormMain.cs b/CarRepairShop/CarRepairShopView/FormMain.cs index 1ba6fda..541b841 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.cs @@ -208,7 +208,16 @@ namespace CarRepairShopView private void implementersToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if(service is FormImplementers form) + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + + private void почтаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormLetters)); + if (service is FormLetters form) { form.ShowDialog(); } diff --git a/CarRepairShop/CarRepairShopView/Program.cs b/CarRepairShop/CarRepairShopView/Program.cs index df547fe..0dc5a85 100644 --- a/CarRepairShop/CarRepairShopView/Program.cs +++ b/CarRepairShop/CarRepairShopView/Program.cs @@ -2,6 +2,7 @@ using CarRepairShopBusinessLogic.BusinessLogics; using CarRepairShopBusinessLogic.MailWorker; using CarRepairShopBusinessLogic.OfficePackage; using CarRepairShopBusinessLogic.OfficePackage.Implements; +using CarRepairShopContracts.BindingModels; using CarRepairShopContracts.BusinessLogicsContracts; using CarRepairShopContracts.StoragesContracts; using CarRepairShopDatabaseImplement.Implements; @@ -29,6 +30,26 @@ namespace CarRepairShopView 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()); } @@ -74,6 +95,8 @@ namespace CarRepairShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } \ No newline at end of file