ISEbd-21 Melnikov I. O. Lab Work 07 Base #24

Closed
Igor-Melnikov wants to merge 7 commits from lab7 into lab6
12 changed files with 251 additions and 16 deletions
Showing only changes of commit 3d7f4731a1 - Show all commits

View File

@ -5,7 +5,7 @@
<add key="SmtpClientPort" value="587" />
<add key="PopHost" value="pop.gmail.com" />
<add key="PopPort" value="995" />
<add key="MailLogin" value="ulsturpplab7@gmail.com" />
<add key="MailPassword" value="ihnm riqo ysxz bxqb" />
<add key="MailLogin" value="igors20111@gmail.com" />
<add key="MailPassword" value="xzjt gzal aoek rjmp" />
</appSettings>
</configuration>

View File

@ -0,0 +1,90 @@
namespace BlacksmithWorkshopView
{
partial class FormMails
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.refToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(0, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(802, 426);
this.dataGridView.TabIndex = 0;
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.refToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(800, 24);
this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1";
//
// refToolStripMenuItem
//
this.refToolStripMenuItem.Name = "refToolStripMenuItem";
this.refToolStripMenuItem.Size = new System.Drawing.Size(73, 20);
this.refToolStripMenuItem.Text = "Обновить";
this.refToolStripMenuItem.Click += new System.EventHandler(this.RefToolStripMenuItem_Click);
//
// FormMails
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormMails";
this.Text = "Письма";
this.Load += new System.EventHandler(this.FormMails_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private DataGridView dataGridView;
private MenuStrip menuStrip1;
private ToolStripMenuItem refToolStripMenuItem;
}
}

View File

@ -0,0 +1,41 @@
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace BlacksmithWorkshopView
{
public partial class FormMails : Form
{
private readonly ILogger _logger;
private readonly IMessageInfoLogic _messageLogic;
public FormMails(ILogger<FormMails> logger, IMessageInfoLogic messageLogic)
{
_logger = logger;
_messageLogic = messageLogic;
InitializeComponent();
}
private void LoadData()
{
try
{
_logger.LogInformation("Загрузка списка писем");
dataGridView.DataSource = _messageLogic.ReadList(null);
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
catch (Exception ex)
{
_logger.LogWarning("Ошибка загрузки писем");
MessageBox.Show($"Не удалось загрузить письма: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormMails_Load(object sender, EventArgs e)
{
LoadData();
}
private void RefToolStripMenuItem_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,63 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -43,6 +43,7 @@
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.mailsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -52,7 +53,8 @@
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.refbooksToolStripMenuItem,
this.reportsToolStripMenuItem,
this.doWorkToolStripMenuItem});
this.doWorkToolStripMenuItem,
this.mailsToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1795, 24);
@ -179,6 +181,13 @@
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// mailsToolStripMenuItem
//
this.mailsToolStripMenuItem.Name = "mailsToolStripMenuItem";
this.mailsToolStripMenuItem.Size = new System.Drawing.Size(62, 20);
this.mailsToolStripMenuItem.Text = "Письма";
this.mailsToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -218,5 +227,6 @@
private ToolStripMenuItem clientsToolStripMenuItem;
private ToolStripMenuItem implementersToolStripMenuItem;
private ToolStripMenuItem doWorkToolStripMenuItem;
private ToolStripMenuItem mailsToolStripMenuItem;
}
}

View File

@ -13,7 +13,7 @@ namespace BlacksmithWorkshopView
private readonly IReportLogic _reportLogic;
private readonly IImplementerLogic _implementerLogic;
private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IImplementerLogic implementerLogic)
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IImplementerLogic implementerLogic, IMessageInfoLogic messageInfoLogic)
{
InitializeComponent();
_logger = logger;
@ -204,5 +204,15 @@ namespace BlacksmithWorkshopView
{
_workProcess.DoWork(_implementerLogic, _orderLogic);
}
private void MailsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMails));
if (service is FormMails form)
{
form.ShowDialog();
LoadData();
}
}
}
}

View File

@ -35,7 +35,7 @@ namespace BlacksmithWorkshopView
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"]),
SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]),
PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
});
@ -86,6 +86,7 @@ namespace BlacksmithWorkshopView
services.AddTransient<FormClients>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormImplementers>();
services.AddTransient<FormMails>();
}
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
}

View File

@ -6,6 +6,7 @@ using BlacksmithWorkshopContracts.ViewModels;
using DocumentFormat.OpenXml.InkML;
using Microsoft.Extensions.Logging;
using System.Net;
using System.Text.RegularExpressions;
namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
{
@ -104,6 +105,14 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
{
throw new InvalidOperationException("Клиент с таким адресом электронной почты уже есть");
}
if (!Regex.IsMatch(model.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
{
throw new ArgumentException("Некорретно введенный email", nameof(model.Email));
}
if (!Regex.IsMatch(model.Password, @"^(?=.*\d)(?=.*\W)(?=.*[^\d\s]).+$"))
{
throw new ArgumentException("Некорректно введенный пароль. Пароль должен содержать хотя бы одну букву, цифру и не буквенный символ", nameof(model.Password));
}
}
}
}

View File

@ -68,6 +68,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
}
if (_orderStorage.Update(model) != null)
{
SendMail(vm?.ClientId ?? 0, $"Информация о заказе №{model.Id}", $"Заказ №{model.Id} {model.Status}");
return true;
}
}
@ -82,7 +83,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) != null)
{
SendMail(model.ClientId, $"Новый заказ создан. Номер заказа #{model.Id}", $"Заказ #{model.Id} от {model.DateCreate} на сумму {model.Sum} принят");
SendMail(model.ClientId, $"Новый заказ создан. Номер заказа: {model.Id}", $"Заказ №{model.Id} от {model.DateCreate} на сумму {model.Sum} принят");
return true;
}
}

View File

@ -44,6 +44,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
return null;
}
context.MessageInfos.Add(newMessage);
if (newMessage == null || context.MessageInfos.Any(x => x.MessageId.Equals(model.MessageId)))
{
return null;
}
context.SaveChanges();
return newMessage.GetViewModel;
}

View File

@ -41,17 +41,23 @@ builder.Services.AddSwaggerGen(c =>
var app = builder.Build();
var MailLogin = builder.Configuration.GetSection("MailLogin").Value;
var mailSender = app.Services.GetService<AbstractMailWorker>();
var MailLogin = builder.Configuration.GetSection("MailLogin").Value ?? string.Empty;
var MailPassword = builder.Configuration.GetSection("MailPassword").Value ?? string.Empty;
var SmtpClientHost = builder.Configuration.GetSection("SmtpClientHost").Value ?? string.Empty;
var SmtpClientPort = Convert.ToInt32(builder.Configuration.GetSection("SmtpClientPort").Value);
var PopHost = builder.Configuration.GetSection("PopHost").Value ?? string.Empty;
var PopPort = Convert.ToInt32(builder.Configuration.GetSection("PopPort").Value);
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"])
MailLogin = builder.Configuration.GetSection("MailLogin").Value ?? string.Empty,
MailPassword = builder.Configuration.GetSection("MailPassword").Value ?? string.Empty,
SmtpClientHost = builder.Configuration.GetSection("SmtpClientHost").Value ?? string.Empty,
SmtpClientPort = Convert.ToInt32(builder.Configuration.GetSection("SmtpClientPort").Value),
PopHost = builder.Configuration.GetSection("PopHost").Value ?? string.Empty,
PopPort = Convert.ToInt32(builder.Configuration.GetSection("PopPort").Value)
});
// Configure the HTTP request pipeline.

View File

@ -10,6 +10,6 @@
"SmtpClientPort": "587",
"PopHost": "pop.gmail.com",
"PopPort": "995",
"MailLogin": "ulsturpplab7@gmail.com",
"MailPassword": "ihnm riqo ysxz bxqb"
"MailLogin": "igors20111@gmail.com",
"MailPassword": "xzjt gzal aoek rjmp"
}