diff --git a/Secure/SecureShop/App.config b/Secure/SecureShop/App.config new file mode 100644 index 0000000..55891ee --- /dev/null +++ b/Secure/SecureShop/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Secure/SecureShop/FormMain.Designer.cs b/Secure/SecureShop/FormMain.Designer.cs index 578c53d..a876c47 100644 --- a/Secure/SecureShop/FormMain.Designer.cs +++ b/Secure/SecureShop/FormMain.Designer.cs @@ -28,207 +28,204 @@ /// private void InitializeComponent() { - this.menuStrip = new System.Windows.Forms.MenuStrip(); - this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.FacilitiessToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.SecuresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ClientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ImplementersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.SecuresReportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.SecureFacilitiessReportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.OrdersReportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.StartWorkingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.buttonOrderReady = new System.Windows.Forms.Button(); - this.buttonIssuedOrder = new System.Windows.Forms.Button(); - this.buttonRef = new System.Windows.Forms.Button(); - this.menuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + FacilitiessToolStripMenuItem = new ToolStripMenuItem(); + SecuresToolStripMenuItem = new ToolStripMenuItem(); + ClientsToolStripMenuItem = new ToolStripMenuItem(); + ImplementersToolStripMenuItem = new ToolStripMenuItem(); + отчётыToolStripMenuItem = new ToolStripMenuItem(); + SecuresReportToolStripMenuItem = new ToolStripMenuItem(); + SecureFacilitiessReportToolStripMenuItem = new ToolStripMenuItem(); + OrdersReportToolStripMenuItem = new ToolStripMenuItem(); + StartWorkingToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + сообщенияToolStripMenuItem = new ToolStripMenuItem(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); // // menuStrip // - this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem, - this.отчётыToolStripMenuItem, - this.StartWorkingToolStripMenuItem}); - this.menuStrip.Location = new System.Drawing.Point(0, 0); - this.menuStrip.Name = "menuStrip"; - this.menuStrip.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); - this.menuStrip.Size = new System.Drawing.Size(1149, 24); - this.menuStrip.TabIndex = 0; - this.menuStrip.Text = "Справочники"; + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, StartWorkingToolStripMenuItem, сообщенияToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Padding = new Padding(5, 2, 0, 2); + menuStrip.Size = new Size(1149, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "Справочники"; // // справочникиToolStripMenuItem // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.FacilitiessToolStripMenuItem, - this.SecuresToolStripMenuItem, - this.ClientsToolStripMenuItem, - this.ImplementersToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); - this.справочникиToolStripMenuItem.Text = "Справочники"; + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { FacilitiessToolStripMenuItem, SecuresToolStripMenuItem, ClientsToolStripMenuItem, ImplementersToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; // // FacilitiessToolStripMenuItem // - this.FacilitiessToolStripMenuItem.Name = "FacilitiessToolStripMenuItem"; - this.FacilitiessToolStripMenuItem.Size = new System.Drawing.Size(200, 22); - this.FacilitiessToolStripMenuItem.Text = "Оборудование"; - this.FacilitiessToolStripMenuItem.Click += new System.EventHandler(this.FacilitiessToolStripMenuItem_Click); + FacilitiessToolStripMenuItem.Name = "FacilitiessToolStripMenuItem"; + FacilitiessToolStripMenuItem.Size = new Size(200, 22); + FacilitiessToolStripMenuItem.Text = "Оборудование"; + FacilitiessToolStripMenuItem.Click += FacilitiessToolStripMenuItem_Click; // // SecuresToolStripMenuItem // - this.SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem"; - this.SecuresToolStripMenuItem.Size = new System.Drawing.Size(200, 22); - this.SecuresToolStripMenuItem.Text = "Система безопасности"; - this.SecuresToolStripMenuItem.Click += new System.EventHandler(this.SecuresToolStripMenuItem_Click); + SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem"; + SecuresToolStripMenuItem.Size = new Size(200, 22); + SecuresToolStripMenuItem.Text = "Система безопасности"; + SecuresToolStripMenuItem.Click += SecuresToolStripMenuItem_Click; // // ClientsToolStripMenuItem // - this.ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; - this.ClientsToolStripMenuItem.Size = new System.Drawing.Size(200, 22); - this.ClientsToolStripMenuItem.Text = "Клиенты"; - this.ClientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); + ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; + ClientsToolStripMenuItem.Size = new Size(200, 22); + ClientsToolStripMenuItem.Text = "Клиенты"; + ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; // // ImplementersToolStripMenuItem // - this.ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; - this.ImplementersToolStripMenuItem.Size = new System.Drawing.Size(200, 22); - this.ImplementersToolStripMenuItem.Text = "Исполнители"; - this.ImplementersToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click); + ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; + ImplementersToolStripMenuItem.Size = new Size(200, 22); + ImplementersToolStripMenuItem.Text = "Исполнители"; + ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; // // отчётыToolStripMenuItem // - this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.SecuresReportToolStripMenuItem, - this.SecureFacilitiessReportToolStripMenuItem, - this.OrdersReportToolStripMenuItem}); - this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; - this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); - this.отчётыToolStripMenuItem.Text = "Отчёты"; + отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SecuresReportToolStripMenuItem, SecureFacilitiessReportToolStripMenuItem, OrdersReportToolStripMenuItem }); + отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; + отчётыToolStripMenuItem.Size = new Size(60, 20); + отчётыToolStripMenuItem.Text = "Отчёты"; // // SecuresReportToolStripMenuItem // - this.SecuresReportToolStripMenuItem.Name = "SecuresReportToolStripMenuItem"; - this.SecuresReportToolStripMenuItem.Size = new System.Drawing.Size(236, 22); - this.SecuresReportToolStripMenuItem.Text = "Список систем безопасности"; - this.SecuresReportToolStripMenuItem.Click += new System.EventHandler(this.SecuresReportToolStripMenuItem_Click); + SecuresReportToolStripMenuItem.Name = "SecuresReportToolStripMenuItem"; + SecuresReportToolStripMenuItem.Size = new Size(236, 22); + SecuresReportToolStripMenuItem.Text = "Список систем безопасности"; + SecuresReportToolStripMenuItem.Click += SecuresReportToolStripMenuItem_Click; // // SecureFacilitiessReportToolStripMenuItem // - this.SecureFacilitiessReportToolStripMenuItem.Name = "SecureFacilitiessReportToolStripMenuItem"; - this.SecureFacilitiessReportToolStripMenuItem.Size = new System.Drawing.Size(236, 22); - this.SecureFacilitiessReportToolStripMenuItem.Text = "Оборудование по СБ"; - this.SecureFacilitiessReportToolStripMenuItem.Click += new System.EventHandler(this.SecureFacilitiessReportToolStripMenuItem_Click); + SecureFacilitiessReportToolStripMenuItem.Name = "SecureFacilitiessReportToolStripMenuItem"; + SecureFacilitiessReportToolStripMenuItem.Size = new Size(236, 22); + SecureFacilitiessReportToolStripMenuItem.Text = "Оборудование по СБ"; + SecureFacilitiessReportToolStripMenuItem.Click += SecureFacilitiessReportToolStripMenuItem_Click; // // OrdersReportToolStripMenuItem // - this.OrdersReportToolStripMenuItem.Name = "OrdersReportToolStripMenuItem"; - this.OrdersReportToolStripMenuItem.Size = new System.Drawing.Size(236, 22); - this.OrdersReportToolStripMenuItem.Text = "Список заказов"; - this.OrdersReportToolStripMenuItem.Click += new System.EventHandler(this.OrdersReportToolStripMenuItem_Click); + OrdersReportToolStripMenuItem.Name = "OrdersReportToolStripMenuItem"; + OrdersReportToolStripMenuItem.Size = new Size(236, 22); + OrdersReportToolStripMenuItem.Text = "Список заказов"; + OrdersReportToolStripMenuItem.Click += OrdersReportToolStripMenuItem_Click; // // StartWorkingToolStripMenuItem // - this.StartWorkingToolStripMenuItem.Name = "StartWorkingToolStripMenuItem"; - this.StartWorkingToolStripMenuItem.Size = new System.Drawing.Size(92, 20); - this.StartWorkingToolStripMenuItem.Text = "Запуск работ"; - this.StartWorkingToolStripMenuItem.Click += new System.EventHandler(this.StartWorkingToolStripMenuItem_Click); + StartWorkingToolStripMenuItem.Name = "StartWorkingToolStripMenuItem"; + StartWorkingToolStripMenuItem.Size = new Size(92, 20); + StartWorkingToolStripMenuItem.Text = "Запуск работ"; + StartWorkingToolStripMenuItem.Click += StartWorkingToolStripMenuItem_Click; // // dataGridView // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 26); - this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(957, 305); - this.dataGridView.TabIndex = 1; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 26); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(957, 305); + dataGridView.TabIndex = 1; // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(975, 34); - this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(170, 22); - this.buttonCreateOrder.TabIndex = 2; - this.buttonCreateOrder.Text = "Создать заказ"; - this.buttonCreateOrder.UseVisualStyleBackColor = true; - this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + buttonCreateOrder.Location = new Point(975, 34); + buttonCreateOrder.Margin = new Padding(3, 2, 3, 2); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(170, 22); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; // // buttonTakeOrderInWork // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(975, 60); - this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(170, 22); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + buttonTakeOrderInWork.Location = new Point(975, 60); + buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(170, 22); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; // // buttonOrderReady // - this.buttonOrderReady.Location = new System.Drawing.Point(975, 86); - this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(170, 22); - this.buttonOrderReady.TabIndex = 4; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + buttonOrderReady.Location = new Point(975, 86); + buttonOrderReady.Margin = new Padding(3, 2, 3, 2); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(170, 22); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; // // buttonIssuedOrder // - this.buttonIssuedOrder.Location = new System.Drawing.Point(975, 112); - this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonIssuedOrder.Name = "buttonIssuedOrder"; - this.buttonIssuedOrder.Size = new System.Drawing.Size(170, 22); - this.buttonIssuedOrder.TabIndex = 5; - this.buttonIssuedOrder.Text = "Заказ выдан"; - this.buttonIssuedOrder.UseVisualStyleBackColor = true; - this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + buttonIssuedOrder.Location = new Point(975, 112); + buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(170, 22); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(975, 138); - this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(170, 22); - this.buttonRef.TabIndex = 6; - this.buttonRef.Text = "Обновить"; - this.buttonRef.UseVisualStyleBackColor = true; - this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + buttonRef.Location = new Point(975, 138); + buttonRef.Margin = new Padding(3, 2, 3, 2); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(170, 22); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // сообщенияToolStripMenuItem + // + сообщенияToolStripMenuItem.Name = "сообщенияToolStripMenuItem"; + сообщенияToolStripMenuItem.Size = new Size(85, 20); + сообщенияToolStripMenuItem.Text = "Сообщения"; + сообщенияToolStripMenuItem.Click += сообщенияToolStripMenuItem_Click; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1149, 338); - this.Controls.Add(this.buttonRef); - this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); - this.Controls.Add(this.buttonCreateOrder); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip); - this.MainMenuStrip = this.menuStrip; - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.Name = "FormMain"; - this.Text = "Магазин систем безопасности"; - this.Load += new System.EventHandler(this.FormMain_Load); - this.menuStrip.ResumeLayout(false); - this.menuStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1149, 338); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Margin = new Padding(3, 2, 3, 2); + Name = "FormMain"; + Text = "Магазин систем безопасности"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -250,5 +247,6 @@ private ToolStripMenuItem ClientsToolStripMenuItem; private ToolStripMenuItem ImplementersToolStripMenuItem; private ToolStripMenuItem StartWorkingToolStripMenuItem; + private ToolStripMenuItem сообщенияToolStripMenuItem; } } \ No newline at end of file diff --git a/Secure/SecureShop/FormMain.cs b/Secure/SecureShop/FormMain.cs index 05d0f9a..81da752 100644 --- a/Secure/SecureShop/FormMain.cs +++ b/Secure/SecureShop/FormMain.cs @@ -2,6 +2,7 @@ using SecureShopContracts.BindingModels; using SecureShopContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using SecureShopView; namespace SecureShopView { @@ -214,5 +215,14 @@ namespace SecureShopView _workProcessLogic.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } + + private void сообщенияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMessages)); + if (service is FormMessages form) + { + form.ShowDialog(); + } + } } } \ No newline at end of file diff --git a/Secure/SecureShop/FormMessages.Designer.cs b/Secure/SecureShop/FormMessages.Designer.cs new file mode 100644 index 0000000..54c7e53 --- /dev/null +++ b/Secure/SecureShop/FormMessages.Designer.cs @@ -0,0 +1,61 @@ +namespace SecureShopView +{ + partial class FormMessages + { + /// + /// 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.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(776, 426); + dataGridView.TabIndex = 0; + // + // FormMessages + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "FormMessages"; + Text = "Сообщения"; + Load += FormMessages_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Secure/SecureShop/FormMessages.cs b/Secure/SecureShop/FormMessages.cs new file mode 100644 index 0000000..a459344 --- /dev/null +++ b/Secure/SecureShop/FormMessages.cs @@ -0,0 +1,53 @@ +using SecureShopContracts.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 SecureShopView +{ + public partial class FormMessages : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + + public FormMessages(ILogger logger, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormMessages_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["MessageId"].Visible = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + } + _logger.LogInformation("Загрузка сообщений"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки сообщений"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/Secure/SecureShop/FormMessages.resx b/Secure/SecureShop/FormMessages.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Secure/SecureShop/FormMessages.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Secure/SecureShop/Program.cs b/Secure/SecureShop/Program.cs index 990aac5..f0afd7e 100644 --- a/Secure/SecureShop/Program.cs +++ b/Secure/SecureShop/Program.cs @@ -1,4 +1,4 @@ -using SecureShopBusinessLogic.BusinessLogics; +using SecureShopBusinessLogic.BusinessLogics; using SecureShopContracts.BusinessLogicsContracts; using SecureShopContracts.StoragesContracts; using Microsoft.Extensions.DependencyInjection; @@ -7,7 +7,9 @@ using NLog.Extensions.Logging; using SecureShopBusinessLogic.OfficePackage; using SecureShopBusinessLogic.OfficePackage.Implements; using SecureShopDatabaseImplement.Implements; -using SecureShopView; +using SecureShopBusinessLogic.MailWorker; +using SecureShopContracts.BindingModels; + namespace SecureShopView { @@ -27,6 +29,25 @@ namespace SecureShopView 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()); } private static void ConfigureServices(ServiceCollection services) @@ -40,11 +61,16 @@ namespace SecureShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddSingleton(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -64,6 +90,6 @@ namespace SecureShopView services.AddTransient(); services.AddTransient(); } - + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } \ No newline at end of file diff --git a/Secure/SecureShop/SecureShopView.csproj b/Secure/SecureShop/SecureShopView.csproj index bc055fc..8936793 100644 --- a/Secure/SecureShop/SecureShopView.csproj +++ b/Secure/SecureShop/SecureShopView.csproj @@ -9,13 +9,13 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + @@ -32,5 +32,10 @@ Always + + + Always + + \ No newline at end of file diff --git a/Secure/SecureShopBusinessLogic/BusinessLogics/ClientLogic.cs b/Secure/SecureShopBusinessLogic/BusinessLogics/ClientLogic.cs index 03fdfe6..cc446c5 100644 --- a/Secure/SecureShopBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/Secure/SecureShopBusinessLogic/BusinessLogics/ClientLogic.cs @@ -4,6 +4,7 @@ using SecureShopContracts.SearchModels; using SecureShopContracts.StoragesContracts; using SecureShopContracts.ViewModels; using Microsoft.Extensions.Logging; +using System.Text.RegularExpressions; namespace SecureShopBusinessLogic.BusinessLogics { @@ -96,8 +97,17 @@ namespace SecureShopBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет имени клиента", nameof(model.ClientFIO)); } - _logger.LogInformation("Client. ClientFIO:{ClientFIO}. Id: {Id}", model.ClientFIO, model.Id); - var element = _clientStorage.GetElement(new ClientSearchModel + if (!Regex.IsMatch(model.Email, @"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" + + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$", RegexOptions.IgnoreCase)) + { + throw new ArgumentException("Некорректная почта, сынок", nameof(model.Email)); + } + if (!Regex.IsMatch(model.Password, @"^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$", RegexOptions.IgnoreCase) || model.Password.Length < 10 || model.Password.Length > 50) + { + throw new ArgumentException("Думай лучше. Плохой пароль", nameof(model.Password)); + } + _logger.LogInformation("Client. ClientFIO:{ClientFIO}. Id: {Id}", model.ClientFIO, model.Id); + var element = _clientStorage.GetElement(new ClientSearchModel { Email = model.Email }); diff --git a/Secure/SecureShopBusinessLogic/BusinessLogics/OrderLogic.cs b/Secure/SecureShopBusinessLogic/BusinessLogics/OrderLogic.cs index efd4704..4818612 100644 --- a/Secure/SecureShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/Secure/SecureShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -3,6 +3,7 @@ using SecureShopContracts.BusinessLogicsContracts; using SecureShopContracts.SearchModels; using SecureShopContracts.StoragesContracts; using SecureShopContracts.ViewModels; +using SecureShopBusinessLogic.MailWorker; using SecureShopDataModels.Enums; using Microsoft.Extensions.Logging; @@ -12,11 +13,15 @@ namespace SecureShopBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly AbstractMailWorker _abstractMailWorker; + private readonly IClientStorage _clientStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker abstractMailWorker, IClientStorage clientStorage) { _logger = logger; _orderStorage = orderStorage; + _abstractMailWorker = abstractMailWorker; + _clientStorage = clientStorage; } public List? ReadList(OrderSearchModel? model) @@ -66,11 +71,19 @@ namespace SecureShopBusinessLogic.BusinessLogics return false; } model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) + var order = _orderStorage.Insert(model); + if (order == null) { _logger.LogWarning("Insert operation failed"); return false; } + var client = _clientStorage.GetElement(new() { Id = order.ClientId }); + if (client == null) + { + _logger.LogWarning("Client not found"); + return false; + } + SendMail(client.Email, $"Новый заказ создан. Номер заказа - {order.Id}", $"Заказ №{order.Id} от {order.DateCreate} на сумму {order.Sum:C2} принят."); return true; } @@ -104,11 +117,19 @@ namespace SecureShopBusinessLogic.BusinessLogics model.DateImplement = viewModel.DateImplement; } CheckModel(model); - if (_orderStorage.Update(model) == null) + var order = _orderStorage.Update(model); + if (order == null) { _logger.LogWarning("Change status operation failed"); return false; } + var client = _clientStorage.GetElement(new() { Id = order.ClientId }); + if (client == null) + { + _logger.LogWarning("Client not found"); + return false; + } + SendMail(client.Email, $"Заказ №{order.Id}", $"Заказ №{order.Id} изменил статус на {order.Status}."); return true; } @@ -128,6 +149,15 @@ namespace SecureShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } + public void SendMail(string email, string title, string body) + { + _abstractMailWorker.MailSendAsync(new() + { + MailAddress = email, + Subject = title, + Text = body + }); + } public bool TakeOrderInWork(OrderBindingModel model) { diff --git a/Secure/SecureShopBusinessLogic/MailWorker/AbstractMailWorker.cs b/Secure/SecureShopBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..42cc9ff --- /dev/null +++ b/Secure/SecureShopBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,95 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace SecureShopBusinessLogic.MailWorker +{ + public abstract class AbstractMailWorker + { + protected string _mailLogin = string.Empty; + + protected string _mailPassword = string.Empty; + + protected string _smtpClientHost = string.Empty; + + protected int _smtpClientPort; + + protected string _popHost = string.Empty; + + protected int _popPort; + + private readonly IMessageInfoLogic _messageInfoLogic; + + private readonly ILogger _logger; + + private readonly IClientLogic _clientLogic; + public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) + { + _logger = logger; + _messageInfoLogic = messageInfoLogic; + _clientLogic = clientLogic; + } + + public void MailConfig(MailConfigBindingModel config) + { + _mailLogin = config.MailLogin; + _mailPassword = config.MailPassword; + _smtpClientHost = config.SmtpClientHost; + _smtpClientPort = config.SmtpClientPort; + _popHost = config.PopHost; + _popPort = config.PopPort; + _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + } + + public async void MailSendAsync(MailSendInfoBindingModel info) + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0) + { + return; + } + + if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text)) + { + return; + } + + _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); + await SendMailAsync(info); + } + + public async void MailCheck() + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_popHost) || _popPort == 0) + { + return; + } + + if (_messageInfoLogic == null) + { + return; + } + + var list = await ReceiveMailAsync(); + _logger.LogDebug("Check Mail: {Count} new mails", list.Count); + foreach (var mail in list) + { + mail.ClientId = _clientLogic.ReadElement(new() { Email = mail.SenderName })?.Id; + _messageInfoLogic.Create(mail); + } + } + + protected abstract Task SendMailAsync(MailSendInfoBindingModel info); + + protected abstract Task> ReceiveMailAsync(); + } +} \ No newline at end of file diff --git a/Secure/SecureShopBusinessLogic/MailWorker/MailKitWorker.cs b/Secure/SecureShopBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..09ec5dc --- /dev/null +++ b/Secure/SecureShopBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,78 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using MailKit.Net.Pop3; +using MailKit.Security; +using Microsoft.Extensions.Logging; +using System.Net; +using System.Net.Mail; +using System.Text; + +namespace SecureShopBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { } + + protected override async Task SendMailAsync(MailSendInfoBindingModel info) + { + using var objMailMessage = new MailMessage(); + using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort); + try + { + objMailMessage.From = new MailAddress(_mailLogin); + objMailMessage.To.Add(new MailAddress(info.MailAddress)); + objMailMessage.Subject = info.Subject; + objMailMessage.Body = info.Text; + objMailMessage.SubjectEncoding = Encoding.UTF8; + objMailMessage.BodyEncoding = Encoding.UTF8; + + objSmtpClient.UseDefaultCredentials = false; + objSmtpClient.EnableSsl = true; + objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword); + + await Task.Run(() => objSmtpClient.Send(objMailMessage)); + } + catch (Exception) + { + throw; + } + } + + protected override async Task> ReceiveMailAsync() + { + var list = new List(); + using var client = new Pop3Client(); + await Task.Run(() => + { + try + { + client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect); + client.Authenticate(_mailLogin, _mailPassword); + for (int i = 0; i < client.Count; i++) + { + var message = client.GetMessage(i); + foreach (var mail in message.From.Mailboxes) + { + list.Add(new MessageInfoBindingModel + { + DateDelivery = message.Date.DateTime, + MessageId = message.MessageId, + SenderName = mail.Address, + Subject = message.Subject, + Body = message.TextBody + }); + } + } + } + catch (AuthenticationException) + { } + finally + { + client.Disconnect(true); + } + }); + return list; + } + } +} diff --git a/Secure/SecureShopBusinessLogic/SecureShopBusinessLogic.csproj b/Secure/SecureShopBusinessLogic/SecureShopBusinessLogic.csproj index ec2c2b2..66a064e 100644 --- a/Secure/SecureShopBusinessLogic/SecureShopBusinessLogic.csproj +++ b/Secure/SecureShopBusinessLogic/SecureShopBusinessLogic.csproj @@ -8,7 +8,8 @@ - + + diff --git a/Secure/SecureShopClientApp/Controllers/HomeController.cs b/Secure/SecureShopClientApp/Controllers/HomeController.cs index a75ccd0..c874c9e 100644 --- a/Secure/SecureShopClientApp/Controllers/HomeController.cs +++ b/Secure/SecureShopClientApp/Controllers/HomeController.cs @@ -6,7 +6,7 @@ using System.Diagnostics; namespace SecureShopClientApp.Controllers { - public class HomeController : Controller + public class HomeController : Controller { private readonly ILogger _logger; @@ -143,5 +143,14 @@ namespace SecureShopClientApp.Controllers var iceCr = APIClient.GetRequest($"api/main/getsecure?secureId={secure}"); return count * (iceCr?.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/Secure/SecureShopClientApp/Views/Home/Mails.cshtml b/Secure/SecureShopClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..f51c396 --- /dev/null +++ b/Secure/SecureShopClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,54 @@ +@using SecureShopContracts.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/Secure/SecureShopClientApp/Views/Shared/_Layout.cshtml b/Secure/SecureShopClientApp/Views/Shared/_Layout.cshtml index 807cf36..67d6e12 100644 --- a/Secure/SecureShopClientApp/Views/Shared/_Layout.cshtml +++ b/Secure/SecureShopClientApp/Views/Shared/_Layout.cshtml @@ -25,6 +25,9 @@ + diff --git a/Secure/SecureShopContracts/BindingModels/MailConfigBindingModel.cs b/Secure/SecureShopContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..cdbee2a --- /dev/null +++ b/Secure/SecureShopContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,17 @@ +namespace SecureShopContracts.BindingModels +{ + public class MailConfigBindingModel + { + public string MailLogin { get; set; } = string.Empty; + + public string MailPassword { get; set; } = string.Empty; + + public string SmtpClientHost { get; set; } = string.Empty; + + public int SmtpClientPort { get; set; } + + public string PopHost { get; set; } = string.Empty; + + public int PopPort { get; set; } + } +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/BindingModels/MailSendInfoBindingModel.cs b/Secure/SecureShopContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..9824d2b --- /dev/null +++ b/Secure/SecureShopContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,11 @@ +namespace SecureShopContracts.BindingModels +{ + public class MailSendInfoBindingModel + { + public string MailAddress { get; set; } = string.Empty; + + public string Subject { get; set; } = string.Empty; + + public string Text { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/BindingModels/MessageInfoBindingModel.cs b/Secure/SecureShopContracts/BindingModels/MessageInfoBindingModel.cs new file mode 100644 index 0000000..3998437 --- /dev/null +++ b/Secure/SecureShopContracts/BindingModels/MessageInfoBindingModel.cs @@ -0,0 +1,19 @@ +using SecureShopDataModels.Models; + +namespace SecureShopContracts.BindingModels +{ + public class MessageInfoBindingModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + public string SenderName { get; set; } = string.Empty; + + public string Subject { get; set; } = string.Empty; + + public string Body { get; set; } = string.Empty; + + public DateTime DateDelivery { get; set; } + } +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/BindingModels/MessageInfoLogic.cs b/Secure/SecureShopContracts/BindingModels/MessageInfoLogic.cs new file mode 100644 index 0000000..3f853a3 --- /dev/null +++ b/Secure/SecureShopContracts/BindingModels/MessageInfoLogic.cs @@ -0,0 +1,44 @@ +using Microsoft.Extensions.Logging; +using SecureShopContracts.BindingModels; +using SecureShopContracts.BusinessLogicsContracts; +using SecureShopContracts.SearchModels; +using SecureShopContracts.StoragesContracts; +using SecureShopContracts.ViewModels; + +namespace SecureShopBusinessLogic.BusinessLogics +{ + public class MessageInfoLogic : IMessageInfoLogic + { + private readonly ILogger _logger; + private readonly IMessageInfoStorage _messageInfoStorage; + + public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage) + { + _logger = logger; + _messageInfoStorage = messageInfoStorage; + } + + public bool Create(MessageInfoBindingModel model) + { + if (_messageInfoStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public List? ReadList(MessageInfoSearchModel? model) + { + _logger.LogInformation("ReadList. MessageId:{MessageId}", model?.MessageId); + var list = model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list.OrderByDescending(x => x.DateDelivery).ToList(); + } + } +} diff --git a/Secure/SecureShopContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/Secure/SecureShopContracts/BusinessLogicsContracts/IMessageInfoLogic.cs new file mode 100644 index 0000000..5adb4f1 --- /dev/null +++ b/Secure/SecureShopContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -0,0 +1,13 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; +using SecureShopContracts.ViewModels; + +namespace SecureShopContracts.BusinessLogicsContracts +{ + public interface IMessageInfoLogic + { + List? ReadList(MessageInfoSearchModel? model); + + bool Create(MessageInfoBindingModel model); + } +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/SearchModels/MessageInfoSearchModel.cs b/Secure/SecureShopContracts/SearchModels/MessageInfoSearchModel.cs new file mode 100644 index 0000000..61b625d --- /dev/null +++ b/Secure/SecureShopContracts/SearchModels/MessageInfoSearchModel.cs @@ -0,0 +1,9 @@ +namespace SecureShopContracts.SearchModels +{ + public class MessageInfoSearchModel + { + public int? ClientId { get; set; } + + public string? MessageId { get; set; } + } +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/SecureShopContracts.csproj b/Secure/SecureShopContracts/SecureShopContracts.csproj index 62e450e..fff1b33 100644 --- a/Secure/SecureShopContracts/SecureShopContracts.csproj +++ b/Secure/SecureShopContracts/SecureShopContracts.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/Secure/SecureShopContracts/StoragesContracts/IMessageInfoStorage.cs b/Secure/SecureShopContracts/StoragesContracts/IMessageInfoStorage.cs new file mode 100644 index 0000000..a13a83e --- /dev/null +++ b/Secure/SecureShopContracts/StoragesContracts/IMessageInfoStorage.cs @@ -0,0 +1,17 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; +using SecureShopContracts.ViewModels; + +namespace SecureShopContracts.StoragesContracts +{ + public interface IMessageInfoStorage + { + List GetFullList(); + + List GetFilteredList(MessageInfoSearchModel model); + + MessageInfoViewModel? GetElement(MessageInfoSearchModel model); + + MessageInfoViewModel? Insert(MessageInfoBindingModel model); + } +} \ No newline at end of file diff --git a/Secure/SecureShopContracts/ViewModels/MessageInfoViewModel.cs b/Secure/SecureShopContracts/ViewModels/MessageInfoViewModel.cs new file mode 100644 index 0000000..a01f902 --- /dev/null +++ b/Secure/SecureShopContracts/ViewModels/MessageInfoViewModel.cs @@ -0,0 +1,24 @@ +using SecureShopDataModels.Models; +using System.ComponentModel; + +namespace SecureShopContracts.ViewModels +{ + public class MessageInfoViewModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + [DisplayName("Отправитель")] + public string SenderName { get; set; } = string.Empty; + + [DisplayName("Дата письма")] + public DateTime DateDelivery { get; set; } + + [DisplayName("Заголовок")] + public string Subject { get; set; } = string.Empty; + + [DisplayName("Текст")] + public string Body { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/Secure/SecureShopDataModels/Models/IMessageInfoModel.cs b/Secure/SecureShopDataModels/Models/IMessageInfoModel.cs new file mode 100644 index 0000000..79a899b --- /dev/null +++ b/Secure/SecureShopDataModels/Models/IMessageInfoModel.cs @@ -0,0 +1,17 @@ +namespace SecureShopDataModels.Models +{ + public interface IMessageInfoModel + { + string MessageId { get; } + + int? ClientId { get; } + + string SenderName { get; } + + DateTime DateDelivery { get; } + + string Subject { get; } + + string Body { get; } + } +} \ No newline at end of file diff --git a/Secure/SecureShopDatabaseImplement/Implements/MessageInfoStorage.cs b/Secure/SecureShopDatabaseImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..2825339 --- /dev/null +++ b/Secure/SecureShopDatabaseImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,49 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; +using SecureShopContracts.StoragesContracts; +using SecureShopContracts.ViewModels; +using SecureShopDatabaseImplement.Models; + +namespace SecureShopDatabaseImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + using var context = new SecureShopDatabase(); + return context.MessageInfos + .FirstOrDefault(x => !string.IsNullOrEmpty(x.MessageId) && x.MessageId == model.MessageId) + ?.GetViewModel; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + using var context = new SecureShopDatabase(); + return context.MessageInfos + .Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new SecureShopDatabase(); + return context.MessageInfos + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + using var context = new SecureShopDatabase(); + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + context.MessageInfos.Add(newMessage); + context.SaveChanges(); + return newMessage.GetViewModel; + } + } +} diff --git a/Secure/SecureShopDatabaseImplement/Models/Client.cs b/Secure/SecureShopDatabaseImplement/Models/Client.cs index 20da592..807d113 100644 --- a/Secure/SecureShopDatabaseImplement/Models/Client.cs +++ b/Secure/SecureShopDatabaseImplement/Models/Client.cs @@ -18,8 +18,9 @@ namespace SecureShopDatabaseImplement.Models [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); - - public static Client? Create(ClientBindingModel model) + [ForeignKey("ClientId")] + public virtual List MessageInfos { get; set; } = new(); + public static Client? Create(ClientBindingModel model) { if (model == null) { diff --git a/Secure/SecureShopDatabaseImplement/Models/MessageInfo.cs b/Secure/SecureShopDatabaseImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..c5d93f3 --- /dev/null +++ b/Secure/SecureShopDatabaseImplement/Models/MessageInfo.cs @@ -0,0 +1,52 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.ViewModels; +using SecureShopDataModels.Models; +using System.ComponentModel.DataAnnotations; + +namespace SecureShopDatabaseImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + [Key] + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + [Required] + public string SenderName { get; set; } = string.Empty; + [Required] + public DateTime DateDelivery { get; set; } = DateTime.Now; + [Required] + public string Subject { get; set; } = string.Empty; + [Required] + public string Body { get; set; } = string.Empty; + + public virtual Client? Client { get; set; } + + public static MessageInfo? Create(MessageInfoBindingModel? model) + { + if (model == null) + { + return null; + } + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body + }; + } +} diff --git a/Secure/SecureShopDatabaseImplement/SecureShopDatabase.cs b/Secure/SecureShopDatabaseImplement/SecureShopDatabase.cs index 59f3911..9347523 100644 --- a/Secure/SecureShopDatabaseImplement/SecureShopDatabase.cs +++ b/Secure/SecureShopDatabaseImplement/SecureShopDatabase.cs @@ -25,5 +25,7 @@ namespace SecureShopDatabaseImplement public virtual DbSet Clients { set; get; } public virtual DbSet Implementers { set; get; } + + public virtual DbSet MessageInfos { set; get; } } } diff --git a/Secure/SecureShopDatabaseImplement/SecureShopDatabaseImplement.csproj b/Secure/SecureShopDatabaseImplement/SecureShopDatabaseImplement.csproj index d3b339f..8c2fe53 100644 --- a/Secure/SecureShopDatabaseImplement/SecureShopDatabaseImplement.csproj +++ b/Secure/SecureShopDatabaseImplement/SecureShopDatabaseImplement.csproj @@ -7,9 +7,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Secure/SecureShopFileImplement/DataFileSingleton.cs b/Secure/SecureShopFileImplement/DataFileSingleton.cs index e98b77d..7706fed 100644 --- a/Secure/SecureShopFileImplement/DataFileSingleton.cs +++ b/Secure/SecureShopFileImplement/DataFileSingleton.cs @@ -11,9 +11,11 @@ namespace SecureShopFileImplement private readonly string SecureFileName = "Secure.xml"; public List Facilitiess { get; private set; } private readonly string ClientFileName = "Client.xml"; + private readonly string MessageInfoFileName = "MessageInfo.xml"; public List Orders { get; private set; } public List Secures { get; private set; } public List Clients { get; private set; } + public List MessageInfos { get; private set; } public static DataFileSingleton GetInstance() { @@ -28,12 +30,15 @@ namespace SecureShopFileImplement public void SaveSecures() => SaveData(Secures, SecureFileName, "Secures", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveMessageInfos() => SaveData(MessageInfos, MessageInfoFileName, "MessageInfos", x => x.GetXElement); + private DataFileSingleton() { Facilitiess = LoadData(FacilitiesFileName, "Facilities", x => Facilities.Create(x)!)!; Secures = LoadData(SecureFileName, "Secure", x => Secure.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + MessageInfos = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/Secure/SecureShopFileImplement/Implements/MessageInfoStorage.cs b/Secure/SecureShopFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..d7a283c --- /dev/null +++ b/Secure/SecureShopFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,57 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; +using SecureShopContracts.StoragesContracts; +using SecureShopContracts.ViewModels; +using SecureShopFileImplement.Models; + +namespace SecureShopFileImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataFileSingleton _source; + + public MessageInfoStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (!string.IsNullOrEmpty(model.MessageId)) + { + return _source.MessageInfos + .FirstOrDefault(x => x.MessageId == model.MessageId) + ?.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + if (model.ClientId.HasValue) + { + return _source.MessageInfos + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + return _source.MessageInfos.Select(x => x.GetViewModel).ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + _source.MessageInfos.Add(newMessage); + _source.SaveClients(); + return newMessage.GetViewModel; + } + } +} diff --git a/Secure/SecureShopFileImplement/Implements/OrderStorage.cs b/Secure/SecureShopFileImplement/Implements/OrderStorage.cs index bc99fec..11a9d98 100644 --- a/Secure/SecureShopFileImplement/Implements/OrderStorage.cs +++ b/Secure/SecureShopFileImplement/Implements/OrderStorage.cs @@ -26,6 +26,10 @@ namespace SecureShopFileImplement.Implements { return _source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => GetViewModel(x)).ToList(); } + if (model.Status.HasValue) + { + return _source.Orders.Where(x => x.Status == model.Status).Select(x => GetViewModel(x)).ToList(); + } if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) { return _source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) @@ -36,6 +40,14 @@ namespace SecureShopFileImplement.Implements } public OrderViewModel? GetElement(OrderSearchModel model) { + if (model.ImplementerId.HasValue && model.Status.HasValue) + { + return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)?.GetViewModel; + } + if (model.ImplementerId.HasValue) + { + return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel; + } if (!model.Id.HasValue) { return null; diff --git a/Secure/SecureShopFileImplement/Models/MessageInfo.cs b/Secure/SecureShopFileImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..45c6981 --- /dev/null +++ b/Secure/SecureShopFileImplement/Models/MessageInfo.cs @@ -0,0 +1,67 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.ViewModels; +using SecureShopDataModels.Models; +using System.Xml.Linq; + +namespace SecureShopFileImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + public string SenderName { get; set; } = string.Empty; + + public DateTime DateDelivery { get; set; } = DateTime.Now; + + public string Subject { get; set; } = string.Empty; + + public string Body { get; set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body + }; + } + + public static MessageInfo? Create(XElement element) + { + if (element == null) + { + return null; + } + return new MessageInfo() + { + MessageId = element.Element("MessageId")!.Value, + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + SenderName = element.Element("MessageId")!.Value, + DateDelivery = DateTime.ParseExact(element.Element("DateDelivery")!.Value, "G", null), + Subject = element.Element("MessageId")!.Value, + Body = element.Element("MessageId")!.Value + }; + } + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body + }; + + public XElement GetXElement => new("MessageInfo", new XAttribute("MessageId", MessageId), new XElement("ClientId", ClientId), new XElement("SenderName", SenderName), new XElement("DateDelivery", DateDelivery), new XElement("Subject", Subject), new XElement("Body", Body)); + } +} \ No newline at end of file diff --git a/Secure/SecureShopListImplement/DataListSingleton.cs b/Secure/SecureShopListImplement/DataListSingleton.cs index d4e626f..14ff39a 100644 --- a/Secure/SecureShopListImplement/DataListSingleton.cs +++ b/Secure/SecureShopListImplement/DataListSingleton.cs @@ -10,6 +10,7 @@ namespace SecureShopListImplement public List Secures { get; set; } public List Clients { get; set; } public List Implementers { get; set; } + public List MessageInfos { get; set; } private DataListSingleton() { @@ -17,6 +18,7 @@ namespace SecureShopListImplement Orders = new List(); Secures = new List(); Clients = new List(); + MessageInfos = new(); Implementers = new(); } diff --git a/Secure/SecureShopListImplement/Implements/MessageInfoStorage.cs b/Secure/SecureShopListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..84ee222 --- /dev/null +++ b/Secure/SecureShopListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,65 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.SearchModels; +using SecureShopContracts.StoragesContracts; +using SecureShopContracts.ViewModels; +using SecureShopListImplement.Models; + +namespace SecureShopListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton _source; + + public MessageInfoStorage() + { + _source = DataListSingleton.GetInstance(); + } + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + foreach (var elem in _source.MessageInfos) + { + if (!string.IsNullOrEmpty(model.MessageId) && model.MessageId == elem.MessageId) + return elem.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + var result = new List(); + if (model.ClientId.HasValue) + { + foreach (var message in _source.MessageInfos) + { + if (message.ClientId.HasValue && message.ClientId == model.ClientId) + { + result.Add(message.GetViewModel); + } + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var message in _source.MessageInfos) + { + result.Add(message.GetViewModel); + } + return result; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + _source.MessageInfos.Add(newMessage); + return newMessage.GetViewModel; + } + } +} diff --git a/Secure/SecureShopListImplement/Implements/OrderStorage.cs b/Secure/SecureShopListImplement/Implements/OrderStorage.cs index 3b5c4f1..6341d46 100644 --- a/Secure/SecureShopListImplement/Implements/OrderStorage.cs +++ b/Secure/SecureShopListImplement/Implements/OrderStorage.cs @@ -39,6 +39,17 @@ namespace SecureShopListImplement.Implements } return result; } + if (model.Status.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Status == model.Status) + { + result.Add(GetViewModel(order)); + } + } + return result; + } if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) { foreach (var order in _source.Orders) diff --git a/Secure/SecureShopListImplement/Models/MessageInfo.cs b/Secure/SecureShopListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..78b72fa --- /dev/null +++ b/Secure/SecureShopListImplement/Models/MessageInfo.cs @@ -0,0 +1,47 @@ +using SecureShopContracts.BindingModels; +using SecureShopContracts.ViewModels; +using SecureShopDataModels.Models; + +namespace SecureShopListImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + public static MessageInfo? Create(MessageInfoBindingModel? model) + { + if (model == null) + { + return null; + } + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body + }; + } +} diff --git a/Secure/SecureShopRestApi/Controllers/ClientController.cs b/Secure/SecureShopRestApi/Controllers/ClientController.cs index ca8c1ad..12d9ab3 100644 --- a/Secure/SecureShopRestApi/Controllers/ClientController.cs +++ b/Secure/SecureShopRestApi/Controllers/ClientController.cs @@ -14,10 +14,13 @@ namespace SecureShopRestApi.Controllers private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger logger) + private readonly IMessageInfoLogic _mailLogic; + + public ClientController(IClientLogic logic, ILogger logger, IMessageInfoLogic mailLogic) { _logger = logger; _logic = logic; + _mailLogic = mailLogic; } [HttpGet] @@ -38,6 +41,23 @@ namespace SecureShopRestApi.Controllers } } + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + } + [HttpPost] public void Register(ClientBindingModel model) { diff --git a/Secure/SecureShopRestApi/Program.cs b/Secure/SecureShopRestApi/Program.cs index ec5fcf5..3bd8c2b 100644 --- a/Secure/SecureShopRestApi/Program.cs +++ b/Secure/SecureShopRestApi/Program.cs @@ -1,4 +1,6 @@ using SecureShopBusinessLogic.BusinessLogics; +using SecureShopBusinessLogic.MailWorker; +using SecureShopContracts.BindingModels; using SecureShopContracts.BusinessLogicsContracts; using SecureShopContracts.StoragesContracts; using SecureShopDatabaseImplement.Implements; @@ -13,11 +15,15 @@ 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 @@ -29,6 +35,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/Secure/SecureShopRestApi/SecureShopRestApi.csproj b/Secure/SecureShopRestApi/SecureShopRestApi.csproj index 037ff67..6233b63 100644 --- a/Secure/SecureShopRestApi/SecureShopRestApi.csproj +++ b/Secure/SecureShopRestApi/SecureShopRestApi.csproj @@ -8,7 +8,7 @@ - + diff --git a/Secure/SecureShopRestApi/appsettings.json b/Secure/SecureShopRestApi/appsettings.json index 10f68b8..7ca1394 100644 --- a/Secure/SecureShopRestApi/appsettings.json +++ b/Secure/SecureShopRestApi/appsettings.json @@ -5,5 +5,11 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "vertolet.kirill73@gmail.com", + "MailPassword": "xehc ozzy jxqa gtvt" }