lab07 is done

This commit is contained in:
vladimir_zinovev 2024-05-16 19:54:23 +04:00
parent 4fd189daac
commit f78fa6e18c
16 changed files with 637 additions and 118 deletions

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<configuration> <configuration>
<appSettings> <appSettings>
<add key="SmtpClientHost" value="smtp.beget.com" /> <add key="SmtpClientHost" value="smtp.gmail.com" />
<add key="SmtpClientPort" value="465" /> <add key="SmtpClientPort" value="587" />
<add key="PopHost" value="pop3.beget.com" /> <add key="PopHost" value="pop.gmail.com" />
<add key="PopPort" value="995" /> <add key="PopPort" value="995" />
<add key="MailLogin" value="" /> <add key="MailLogin" value="@gmail.com" />
<add key="MailPassword" value= "Fa0d*HzV" /> <add key="MailPassword" value= "gsmp yceu sztw iqid" />
</appSettings> </appSettings>
</configuration> </configuration>

View File

@ -28,12 +28,42 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); dataGridView = new DataGridView();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
this.ClientSize = new System.Drawing.Size(800, 450); SuspendLayout();
this.Text = "FormMails"; //
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(13, 1);
dataGridView.Margin = new Padding(4, 2, 4, 2);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 82;
dataGridView.RowTemplate.Height = 41;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(1351, 789);
dataGridView.TabIndex = 2;
//
// FormMails
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1526, 795);
Controls.Add(dataGridView);
Name = "FormMails";
Text = "FormMails";
Load += FormMails_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
} }
#endregion #endregion
private DataGridView dataGridView;
} }
} }

View File

@ -1,4 +1,6 @@
using System; using FurnitureAssemblyContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@ -12,9 +14,46 @@ namespace FurnitureAssemblyView
{ {
public partial class FormMails : Form public partial class FormMails : Form
{ {
public FormMails() private readonly ILogger _logger;
private readonly IMessageInfoLogic _messageLogic;
public FormMails(ILogger<FormMails> logger, IMessageInfoLogic messageLogic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger;
_messageLogic = messageLogic;
}
private void FormMails_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
_logger.LogInformation("Загрузка писем");
try
{
var list = _messageLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Успешная загрузка писем");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки писем");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
} }
} }

View File

@ -34,6 +34,7 @@
мебельToolStripMenuItem = new ToolStripMenuItem(); мебельToolStripMenuItem = new ToolStripMenuItem();
клиентыToolStripMenuItem = new ToolStripMenuItem(); клиентыToolStripMenuItem = new ToolStripMenuItem();
исполнителиToolStripMenuItem = new ToolStripMenuItem(); исполнителиToolStripMenuItem = new ToolStripMenuItem();
письмаToolStripMenuItem = new ToolStripMenuItem();
отчетыToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem();
списокМебелиToolStripMenuItem = new ToolStripMenuItem(); списокМебелиToolStripMenuItem = new ToolStripMenuItem();
компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem();
@ -53,78 +54,84 @@
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem });
menuStrip1.Location = new Point(0, 0); menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1"; menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(3, 1, 0, 1); menuStrip1.Size = new Size(1631, 42);
menuStrip1.Size = new Size(878, 24);
menuStrip1.TabIndex = 0; menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1"; menuStrip1.Text = "menuStrip1";
// //
// справочникиToolStripMenuItem // справочникиToolStripMenuItem
// //
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заготовкиToolStripMenuItem, мебельToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заготовкиToolStripMenuItem, мебельToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, письмаToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(94, 22); справочникиToolStripMenuItem.Size = new Size(184, 38);
справочникиToolStripMenuItem.Text = "Справочники"; справочникиToolStripMenuItem.Text = "Справочники";
// //
// заготовкиToolStripMenuItem // заготовкиToolStripMenuItem
// //
заготовкиToolStripMenuItem.Name = аготовкиToolStripMenuItem"; заготовкиToolStripMenuItem.Name = аготовкиToolStripMenuItem";
заготовкиToolStripMenuItem.Size = new Size(149, 22); заготовкиToolStripMenuItem.Size = new Size(359, 44);
заготовкиToolStripMenuItem.Text = "Заготовки"; заготовкиToolStripMenuItem.Text = "Заготовки";
заготовкиToolStripMenuItem.Click += заготовкиToolStripMenuItem_Click; заготовкиToolStripMenuItem.Click += заготовкиToolStripMenuItem_Click;
// //
// мебельToolStripMenuItem // мебельToolStripMenuItem
// //
мебельToolStripMenuItem.Name = ебельToolStripMenuItem"; мебельToolStripMenuItem.Name = ебельToolStripMenuItem";
мебельToolStripMenuItem.Size = new Size(149, 22); мебельToolStripMenuItem.Size = new Size(359, 44);
мебельToolStripMenuItem.Text = "Мебель"; мебельToolStripMenuItem.Text = "Мебель";
мебельToolStripMenuItem.Click += мебельToolStripMenuItem_Click; мебельToolStripMenuItem.Click += мебельToolStripMenuItem_Click;
// //
// клиентыToolStripMenuItem // клиентыToolStripMenuItem
// //
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
клиентыToolStripMenuItem.Size = new Size(149, 22); клиентыToolStripMenuItem.Size = new Size(359, 44);
клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Text = "Клиенты";
клиентыToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; клиентыToolStripMenuItem.Click += ClientsToolStripMenuItem_Click;
// //
// исполнителиToolStripMenuItem // исполнителиToolStripMenuItem
// //
исполнителиToolStripMenuItem.Name = сполнителиToolStripMenuItem"; исполнителиToolStripMenuItem.Name = сполнителиToolStripMenuItem";
исполнителиToolStripMenuItem.Size = new Size(149, 22); исполнителиToolStripMenuItem.Size = new Size(359, 44);
исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Text = "Исполнители";
исполнителиToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; исполнителиToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click;
// //
// письмаToolStripMenuItem
//
письмаToolStripMenuItem.Name = "письмаToolStripMenuItem";
письмаToolStripMenuItem.Size = new Size(359, 44);
письмаToolStripMenuItem.Text = "Письма";
письмаToolStripMenuItem.Click += MailsToolStripMenuItem_Click;
//
// отчетыToolStripMenuItem // отчетыToolStripMenuItem
// //
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокМебелиToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокМебелиToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem });
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
отчетыToolStripMenuItem.Size = new Size(60, 22); отчетыToolStripMenuItem.Size = new Size(116, 38);
отчетыToolStripMenuItem.Text = "Отчеты"; отчетыToolStripMenuItem.Text = "Отчеты";
// //
// списокМебелиToolStripMenuItem // списокМебелиToolStripMenuItem
// //
списокМебелиToolStripMenuItem.Name = "списокМебелиToolStripMenuItem"; списокМебелиToolStripMenuItem.Name = "списокМебелиToolStripMenuItem";
списокМебелиToolStripMenuItem.Size = new Size(218, 22); списокМебелиToolStripMenuItem.Size = new Size(437, 44);
списокМебелиToolStripMenuItem.Text = "Список мебели"; списокМебелиToolStripMenuItem.Text = "Список мебели";
списокМебелиToolStripMenuItem.Click += FurnituresToolStripMenuItem_Click; списокМебелиToolStripMenuItem.Click += FurnituresToolStripMenuItem_Click;
// //
// компонентыПоИзделиямToolStripMenuItem // компонентыПоИзделиямToolStripMenuItem
// //
компонентыПоИзделиямToolStripMenuItem.Name = омпонентыПоИзделиямToolStripMenuItem"; компонентыПоИзделиямToolStripMenuItem.Name = омпонентыПоИзделиямToolStripMenuItem";
компонентыПоИзделиямToolStripMenuItem.Size = new Size(218, 22); компонентыПоИзделиямToolStripMenuItem.Size = new Size(437, 44);
компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям"; компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям";
компонентыПоИзделиямToolStripMenuItem.Click += FurnituresComponentsToolStripMenuItem_Click; компонентыПоИзделиямToolStripMenuItem.Click += FurnituresComponentsToolStripMenuItem_Click;
// //
// списокЗаказовToolStripMenuItem // списокЗаказовToolStripMenuItem
// //
списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
списокЗаказовToolStripMenuItem.Size = new Size(218, 22); списокЗаказовToolStripMenuItem.Size = new Size(437, 44);
списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Text = "Список заказов";
списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
// //
// запускРаботToolStripMenuItem // запускРаботToolStripMenuItem
// //
запускРаботToolStripMenuItem.Name = апускРаботToolStripMenuItem"; запускРаботToolStripMenuItem.Name = апускРаботToolStripMenuItem";
запускРаботToolStripMenuItem.Size = new Size(92, 22); запускРаботToolStripMenuItem.Size = new Size(179, 38);
запускРаботToolStripMenuItem.Text = "Запуск работ"; запускРаботToolStripMenuItem.Text = "Запуск работ";
запускРаботToolStripMenuItem.Click += doWorkToolStripMenuItem_Click; запускРаботToolStripMenuItem.Click += doWorkToolStripMenuItem_Click;
// //
@ -135,23 +142,23 @@
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(0, 30); dataGridView.Location = new Point(0, 64);
dataGridView.Margin = new Padding(2, 1, 2, 1); dataGridView.Margin = new Padding(4, 2, 4, 2);
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false; dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 82; dataGridView.RowHeadersWidth = 82;
dataGridView.RowTemplate.Height = 41; dataGridView.RowTemplate.Height = 41;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(666, 248); dataGridView.Size = new Size(1237, 529);
dataGridView.TabIndex = 1; dataGridView.TabIndex = 1;
// //
// ButtonCreateOrder // ButtonCreateOrder
// //
ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonCreateOrder.Location = new Point(682, 30); ButtonCreateOrder.Location = new Point(1267, 64);
ButtonCreateOrder.Margin = new Padding(2, 1, 2, 1); ButtonCreateOrder.Margin = new Padding(4, 2, 4, 2);
ButtonCreateOrder.Name = "ButtonCreateOrder"; ButtonCreateOrder.Name = "ButtonCreateOrder";
ButtonCreateOrder.Size = new Size(180, 22); ButtonCreateOrder.Size = new Size(334, 47);
ButtonCreateOrder.TabIndex = 2; ButtonCreateOrder.TabIndex = 2;
ButtonCreateOrder.Text = "Создать заказ"; ButtonCreateOrder.Text = "Создать заказ";
ButtonCreateOrder.UseVisualStyleBackColor = true; ButtonCreateOrder.UseVisualStyleBackColor = true;
@ -160,10 +167,10 @@
// ButtonIssuedOrder // ButtonIssuedOrder
// //
ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonIssuedOrder.Location = new Point(682, 67); ButtonIssuedOrder.Location = new Point(1267, 143);
ButtonIssuedOrder.Margin = new Padding(2, 1, 2, 1); ButtonIssuedOrder.Margin = new Padding(4, 2, 4, 2);
ButtonIssuedOrder.Name = "ButtonIssuedOrder"; ButtonIssuedOrder.Name = "ButtonIssuedOrder";
ButtonIssuedOrder.Size = new Size(180, 22); ButtonIssuedOrder.Size = new Size(334, 47);
ButtonIssuedOrder.TabIndex = 5; ButtonIssuedOrder.TabIndex = 5;
ButtonIssuedOrder.Text = "Заказ выдан"; ButtonIssuedOrder.Text = "Заказ выдан";
ButtonIssuedOrder.UseVisualStyleBackColor = true; ButtonIssuedOrder.UseVisualStyleBackColor = true;
@ -172,10 +179,10 @@
// ButtonRef // ButtonRef
// //
ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonRef.Location = new Point(682, 107); ButtonRef.Location = new Point(1267, 228);
ButtonRef.Margin = new Padding(2, 1, 2, 1); ButtonRef.Margin = new Padding(4, 2, 4, 2);
ButtonRef.Name = "ButtonRef"; ButtonRef.Name = "ButtonRef";
ButtonRef.Size = new Size(180, 22); ButtonRef.Size = new Size(334, 47);
ButtonRef.TabIndex = 6; ButtonRef.TabIndex = 6;
ButtonRef.Text = "Обновить список"; ButtonRef.Text = "Обновить список";
ButtonRef.UseVisualStyleBackColor = true; ButtonRef.UseVisualStyleBackColor = true;
@ -183,16 +190,16 @@
// //
// FormMain // FormMain
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(878, 278); ClientSize = new Size(1631, 593);
Controls.Add(ButtonRef); Controls.Add(ButtonRef);
Controls.Add(ButtonIssuedOrder); Controls.Add(ButtonIssuedOrder);
Controls.Add(ButtonCreateOrder); Controls.Add(ButtonCreateOrder);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Controls.Add(menuStrip1); Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1; MainMenuStrip = menuStrip1;
Margin = new Padding(2, 1, 2, 1); Margin = new Padding(4, 2, 4, 2);
Name = "FormMain"; Name = "FormMain";
Text = "Сборка мебели"; Text = "Сборка мебели";
Load += MainForm_Load; Load += MainForm_Load;
@ -220,5 +227,6 @@
private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem;
private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem;
private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem;
private ToolStripMenuItem письмаToolStripMenuItem;
} }
} }

View File

@ -257,5 +257,14 @@ namespace FurnitureAssemblyView
Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!,
_orderLogic); _orderLogic);
} }
private void MailsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMails));
if (service is FormMails form)
{
form.ShowDialog();
}
}
} }
} }

View File

@ -18,7 +18,7 @@
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data> <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value> <value>[base64 mime encoded serialized .NET Framework object]</value>
</data> </data>

View File

@ -1,4 +1,5 @@
using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyBusinessLogic.MailWorker;
using FurnitureAssemblyContracts.BindingModels;
using FurnitureAssemblyContracts.BusinessLogicsContracts; using FurnitureAssemblyContracts.BusinessLogicsContracts;
using FurnitureAssemblyContracts.SearchModels; using FurnitureAssemblyContracts.SearchModels;
using FurnitureAssemblyContracts.StoragesContracts; using FurnitureAssemblyContracts.StoragesContracts;
@ -17,22 +18,39 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage) private readonly AbstractMailWorker _mailWorker;
private readonly IClientLogic _clientLogic;
private readonly object locker = new object();
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic)
{ {
_logger = logger; _logger = logger;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_mailWorker = mailWorker;
_clientLogic = clientLogic;
} }
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) return false;
model.Status = OrderStatus.Принят; if (model.Status != OrderStatus.Неизвестен)
if (_orderStorage.Insert(model) == null)
{ {
_logger.LogWarning("Insert operation failed, incorrect order status");
return false;
}
model.Status = OrderStatus.Принят;
var result = _orderStorage.Insert(model);
if (result == null)
{
model.Status = OrderStatus.Неизвестен;
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
} }
SendOrderMessage(result.ClientId, $"Сборка мебели, Заказ №{result.Id}", $"Заказ №{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят");
return true; return true;
} }
@ -50,28 +68,43 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogic
} }
if (viewModel.Status + 1 != newStatus) if (viewModel.Status + 1 != newStatus)
{ {
_logger.LogWarning("Change status operation failed"); _logger.LogWarning("Status update operation failed. New status " + newStatus.ToString() + "incorrect");
return false; return false;
} }
model.Status = newStatus; model.Status = newStatus;
model.FurnitureId = viewModel.FurnitureId; model.FurnitureId = viewModel.FurnitureId;
model.Count = viewModel.Count; model.Count = viewModel.Count;
model.Sum = viewModel.Sum; model.Sum = viewModel.Sum;
model.DateCreate = viewModel.DateCreate; model.DateCreate = viewModel.DateCreate;
if (model.Status == OrderStatus.Готов) if (viewModel.ImplementerId.HasValue)
{ {
model.DateImplement = DateTime.Now.ToUniversalTime(); model.ImplementerId = viewModel.ImplementerId;
}
if (model.Status == OrderStatus.Выдан)
{
model.DateImplement = DateTime.Now;
} }
else else
{ {
model.DateImplement = viewModel.DateImplement; model.DateImplement = viewModel.DateImplement;
} }
CheckModel(model);
if (_orderStorage.Update(model) == null) CheckModel(model, false);
var result = _orderStorage.Update(model);
if (result == null)
{ {
_logger.LogWarning("Change status operation failed"); model.Status--;
_logger.LogWarning("Update operation failed");
return false; return false;
} }
SendOrderMessage(result.ClientId, $"Сборка мебели, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}");
return true; return true;
} }
@ -143,5 +176,23 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogic
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id); _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element; return element;
} }
private bool SendOrderMessage(int clientId, string subject, string text)
{
var client = _clientLogic.ReadElement(new() { Id = clientId });
if (client == null)
{
return false;
}
_mailWorker.MailSendAsync(new()
{
MailAddress = client.Email,
Subject = subject,
Text = text
});
return true;
}
} }
} }

View File

@ -7,7 +7,7 @@
} }
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Заказы</h1> <h1 class="display-4">Письма</h1>
</div> </div>
<div class="text-center"> <div class="text-center">
@{ @{

View File

@ -16,6 +16,8 @@ namespace FurnitureAssemblyDatabaseImplement
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
optionsBuilder.UseNpgsql("Host=localhost;Database=FurnitureAssemblyDatabaseFull;Username=postgres;Password=postgres"); optionsBuilder.UseNpgsql("Host=localhost;Database=FurnitureAssemblyDatabaseFull;Username=postgres;Password=postgres");
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);

View File

@ -29,38 +29,49 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
public ClientViewModel? GetElement(ClientSearchModel model) public ClientViewModel? GetElement(ClientSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
{
return null;
}
using var context = new FurnitureAssemblyDatabase(); using var context = new FurnitureAssemblyDatabase();
return context.Clients.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || if (model.Id.HasValue)
(model.Id.HasValue && x.Id == model.Id)) {
return context.Clients
.Include(x => x.Orders)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel; ?.GetViewModel;
} }
if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
{
return context.Clients
.Include(x => x.Orders)
.FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))
?.GetViewModel;
}
if (!string.IsNullOrEmpty(model.Email))
return context.Clients
.FirstOrDefault(x => x.Email == model.Email)
?.GetViewModel;
return null;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model) public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password)) if (string.IsNullOrEmpty(model.Email))
{ {
return new(); return new();
} }
using var context = new FurnitureAssemblyDatabase();
return context.Clients
.Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))
.Select(x => x.GetViewModel)
.ToList();
}
using var context = new FurnitureAssemblyDatabase();
return context.Clients
.Where(x => x.Email.Contains(model.Email))
.Select(x => x.GetViewModel).ToList();
}
public List<ClientViewModel> GetFullList() public List<ClientViewModel> GetFullList()
{ {
using var context = new FurnitureAssemblyDatabase(); using var context = new FurnitureAssemblyDatabase();
return context.Clients return context.Clients.Select(x => x.GetViewModel).ToList();
.Select(x => x.GetViewModel)
.ToList();
} }
public ClientViewModel? Insert(ClientBindingModel model) public ClientViewModel? Insert(ClientBindingModel model)
{ {
var newClient = Client.Create(model); var newClient = Client.Create(model);
@ -73,7 +84,6 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
context.SaveChanges(); context.SaveChanges();
return newClient.GetViewModel; return newClient.GetViewModel;
} }
public ClientViewModel? Update(ClientBindingModel model) public ClientViewModel? Update(ClientBindingModel model)
{ {
using var context = new FurnitureAssemblyDatabase(); using var context = new FurnitureAssemblyDatabase();

View File

@ -0,0 +1,298 @@
// <auto-generated />
using System;
using FurnitureAssemblyDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FurnitureAssemblyDatabaseImplement.Migrations
{
[DbContext(typeof(FurnitureAssemblyDatabase))]
[Migration("20240516134544_lab07")]
partial class lab07
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FurnitureName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Furnitures");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("FurnitureId")
.HasColumnType("integer");
b.Property<int>("WorkpieceId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("FurnitureId");
b.HasIndex("WorkpieceId");
b.ToTable("FurnitureWorkpieces");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Qualification")
.HasColumnType("integer");
b.Property<int>("WorkExperience")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b =>
{
b.Property<string>("MessageId")
.HasColumnType("text");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("ClientId")
.HasColumnType("integer");
b.Property<DateTime>("DateDelivery")
.HasColumnType("timestamp without time zone");
b.Property<string>("SenderName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
b.HasKey("MessageId");
b.HasIndex("ClientId");
b.ToTable("Messages");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp without time zone");
b.Property<int>("FurnitureId")
.HasColumnType("integer");
b.Property<int?>("ImplementerId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("FurnitureId");
b.HasIndex("ImplementerId");
b.ToTable("Orders");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<double>("Cost")
.HasColumnType("double precision");
b.Property<string>("WorkpieceName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Workpieces");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b =>
{
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
.WithMany("Workpieces")
.HasForeignKey("FurnitureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Workpiece", "Workpiece")
.WithMany("FurnitureWorkpieces")
.HasForeignKey("WorkpieceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Furniture");
b.Navigation("Workpiece");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b =>
{
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client")
.WithMany("Messages")
.HasForeignKey("ClientId");
b.Navigation("Client");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
{
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
.WithMany("Orders")
.HasForeignKey("FurnitureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.Navigation("Client");
b.Navigation("Furniture");
b.Navigation("Implementer");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b =>
{
b.Navigation("Messages");
b.Navigation("Orders");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
{
b.Navigation("Orders");
b.Navigation("Workpieces");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b =>
{
b.Navigation("FurnitureWorkpieces");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,69 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FurnitureAssemblyDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class lab07 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "DateImplement",
table: "Orders",
type: "timestamp without time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "DateCreate",
table: "Orders",
type: "timestamp without time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone");
migrationBuilder.AlterColumn<DateTime>(
name: "DateDelivery",
table: "Messages",
type: "timestamp without time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "DateImplement",
table: "Orders",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "DateCreate",
table: "Orders",
type: "timestamp with time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone");
migrationBuilder.AlterColumn<DateTime>(
name: "DateDelivery",
table: "Messages",
type: "timestamp with time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone");
}
}
}

View File

@ -133,7 +133,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<DateTime>("DateDelivery") b.Property<DateTime>("DateDelivery")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<string>("SenderName") b.Property<string>("SenderName")
.IsRequired() .IsRequired()
@ -165,10 +165,10 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<DateTime>("DateCreate") b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp without time zone");
b.Property<int>("FurnitureId") b.Property<int>("FurnitureId")
.HasColumnType("integer"); .HasColumnType("integer");
@ -235,7 +235,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b => modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.MessageInfo", b =>
{ {
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client") b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client")
.WithMany() .WithMany("Messages")
.HasForeignKey("ClientId"); .HasForeignKey("ClientId");
b.Navigation("Client"); b.Navigation("Client");
@ -244,7 +244,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
{ {
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client") b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client")
.WithMany() .WithMany("Orders")
.HasForeignKey("ClientId") .HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -266,6 +266,13 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
b.Navigation("Implementer"); b.Navigation("Implementer");
}); });
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b =>
{
b.Navigation("Messages");
b.Navigation("Orders");
});
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
{ {
b.Navigation("Orders"); b.Navigation("Orders");

View File

@ -4,6 +4,7 @@ using FurnitureAssemblyDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -19,6 +20,10 @@ namespace FurnitureAssemblyDatabaseImplement.Models
public string Email { get; private set; } = string.Empty; public string Email { get; private set; } = string.Empty;
[Required] [Required]
public string Password { get; private set; } = string.Empty; public string Password { get; private set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<MessageInfo> Messages { get; set; } = new();
public static Client? Create(ClientBindingModel model) public static Client? Create(ClientBindingModel model)
{ {
@ -26,6 +31,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models
{ {
return null; return null;
} }
return new Client() return new Client()
{ {
Id = model.Id, Id = model.Id,
@ -34,16 +40,6 @@ namespace FurnitureAssemblyDatabaseImplement.Models
Password = model.Password Password = model.Password
}; };
} }
public static Client Create(ClientViewModel model)
{
return new Client
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public void Update(ClientBindingModel model) public void Update(ClientBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -7,10 +7,10 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"SmtpClientHost": "smtp.beget.com", "SmtpClientHost": "smtp.gmail.com",
"SmtpClientPort": "465", "SmtpClientPort": "587",
"PopHost": "pop.beget.com", "PopHost": "pop.gmail.com",
"PopPort": "995", "PopPort": "995",
"MailLogin": "", "MailLogin": "@gmail.com",
"MailPassword": "Fa0d*HzV" "MailPassword": "gsmp yceu sztw iqid"
} }