From 44826328b7ec6d7fc35bc72b03282e694588d677 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 16:50:56 +0400 Subject: [PATCH 01/24] without task --- JewelryStore/FormMain.Designer.cs | 346 +++++++++--------- JewelryStore/FormMain.cs | 37 +- .../BusinessLogics/WorkModeling.cs | 12 + .../BusinessLogicsContracts/IWorkProcess.cs | 12 + .../Models/IImplementerModel.cs | 12 + .../Controllers/ImplementerController.cs | 12 + 6 files changed, 250 insertions(+), 181 deletions(-) create mode 100644 JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 JewelryStoreDataModels/Models/IImplementerModel.cs create mode 100644 JewelryStoreRestApi/Controllers/ImplementerController.cs diff --git a/JewelryStore/FormMain.Designer.cs b/JewelryStore/FormMain.Designer.cs index b1d7cdc..a837582 100644 --- a/JewelryStore/FormMain.Designer.cs +++ b/JewelryStore/FormMain.Designer.cs @@ -28,180 +28,189 @@ /// private void InitializeComponent() { - this.buttonReady = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonCreate = new System.Windows.Forms.Button(); - this.buttonToWork = new System.Windows.Forms.Button(); - this.buttonPut = new System.Windows.Forms.Button(); - this.buttonRefresh = new System.Windows.Forms.Button(); - this.menuStrip = new System.Windows.Forms.MenuStrip(); - this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.списокЗаказзовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.menuStrip.SuspendLayout(); - this.SuspendLayout(); - // - // buttonReady - // - this.buttonReady.Location = new System.Drawing.Point(1273, 225); - this.buttonReady.Name = "buttonReady"; - this.buttonReady.Size = new System.Drawing.Size(215, 34); - this.buttonReady.TabIndex = 3; - this.buttonReady.Text = "Заказ готов"; - this.buttonReady.UseVisualStyleBackColor = true; - this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); - // - // dataGridView - // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(9, 52); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 62; - this.dataGridView.RowTemplate.Height = 33; - this.dataGridView.Size = new System.Drawing.Size(1227, 386); - this.dataGridView.TabIndex = 0; - // - // buttonCreate - // - this.buttonCreate.Location = new System.Drawing.Point(1273, 52); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(215, 34); - this.buttonCreate.TabIndex = 1; - this.buttonCreate.Text = "Создать заказ"; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); - // - // buttonToWork - // - this.buttonToWork.Location = new System.Drawing.Point(1273, 137); - this.buttonToWork.Name = "buttonToWork"; - this.buttonToWork.Size = new System.Drawing.Size(215, 34); - this.buttonToWork.TabIndex = 2; - this.buttonToWork.Text = "Отдать на выполнение"; - this.buttonToWork.UseVisualStyleBackColor = true; - this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click); - // - // buttonPut - // - this.buttonPut.Location = new System.Drawing.Point(1273, 308); - this.buttonPut.Name = "buttonPut"; - this.buttonPut.Size = new System.Drawing.Size(215, 34); - this.buttonPut.TabIndex = 4; - this.buttonPut.Text = "Заказ выдан"; - this.buttonPut.UseVisualStyleBackColor = true; - this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click); - // - // buttonRefresh - // - this.buttonRefresh.Location = new System.Drawing.Point(1273, 389); - this.buttonRefresh.Name = "buttonRefresh"; - this.buttonRefresh.Size = new System.Drawing.Size(215, 34); - this.buttonRefresh.TabIndex = 5; - this.buttonRefresh.Text = "Обновить список"; - this.buttonRefresh.UseVisualStyleBackColor = true; - this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); - // - // menuStrip - // - this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); - this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.buttonReady = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonToWork = new System.Windows.Forms.Button(); + this.buttonPut = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокЗаказзовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // buttonReady + // + this.buttonReady.Location = new System.Drawing.Point(1273, 225); + this.buttonReady.Name = "buttonReady"; + this.buttonReady.Size = new System.Drawing.Size(215, 34); + this.buttonReady.TabIndex = 3; + this.buttonReady.Text = "Заказ готов"; + this.buttonReady.UseVisualStyleBackColor = true; + this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(9, 52); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(1227, 386); + this.dataGridView.TabIndex = 0; + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(1273, 52); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(215, 34); + this.buttonCreate.TabIndex = 1; + this.buttonCreate.Text = "Создать заказ"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // buttonToWork + // + this.buttonToWork.Location = new System.Drawing.Point(1273, 137); + this.buttonToWork.Name = "buttonToWork"; + this.buttonToWork.Size = new System.Drawing.Size(215, 34); + this.buttonToWork.TabIndex = 2; + this.buttonToWork.Text = "Отдать на выполнение"; + this.buttonToWork.UseVisualStyleBackColor = true; + this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click); + // + // buttonPut + // + this.buttonPut.Location = new System.Drawing.Point(1273, 308); + this.buttonPut.Name = "buttonPut"; + this.buttonPut.Size = new System.Drawing.Size(215, 34); + this.buttonPut.TabIndex = 4; + this.buttonPut.Text = "Заказ выдан"; + this.buttonPut.UseVisualStyleBackColor = true; + this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(1273, 389); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(215, 34); + this.buttonRefresh.TabIndex = 5; + this.buttonRefresh.Text = "Обновить список"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, - this.отчетыToolStripMenuItem}); - this.menuStrip.Location = new System.Drawing.Point(0, 0); - this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(1530, 33); - this.menuStrip.TabIndex = 6; - this.menuStrip.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.отчетыToolStripMenuItem, + this.запускРаботToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(1530, 33); + this.menuStrip.TabIndex = 6; + this.menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, this.изделияToolStripMenuItem, this.клиентыToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); - this.справочникиToolStripMenuItem.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); - this.компонентыToolStripMenuItem.Text = "Компоненты"; - this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); - // - // изделияToolStripMenuItem - // - this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(270, 34); - this.изделияToolStripMenuItem.Text = "Драгоценности"; - this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click); - // - // отчетыToolStripMenuItem - // - this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.изделияToolStripMenuItem.Text = "Драгоценности"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click); + // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + // + // отчетыToolStripMenuItem + // + this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.списокКомпонентовToolStripMenuItem, this.компонентыПоИзделиямToolStripMenuItem, this.списокЗаказзовToolStripMenuItem}); - this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(88, 29); - this.отчетыToolStripMenuItem.Text = "Отчеты"; - // - // списокКомпонентовToolStripMenuItem - // - this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; - this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(325, 34); - this.списокКомпонентовToolStripMenuItem.Text = "Список изделий"; - this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.списокКомпонентовToolStripMenuItem_Click); - // - // компонентыПоИзделиямToolStripMenuItem - // - this.компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; - this.компонентыПоИзделиямToolStripMenuItem.Size = new System.Drawing.Size(325, 34); - this.компонентыПоИзделиямToolStripMenuItem.Text = "Изделия по компонентам"; - this.компонентыПоИзделиямToolStripMenuItem.Click += new System.EventHandler(this.компонентыПоИзделиямToolStripMenuItem_Click); - // - // списокЗаказзовToolStripMenuItem - // - this.списокЗаказзовToolStripMenuItem.Name = "списокЗаказзовToolStripMenuItem"; - this.списокЗаказзовToolStripMenuItem.Size = new System.Drawing.Size(325, 34); - this.списокЗаказзовToolStripMenuItem.Text = "Список заказов"; - this.списокЗаказзовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказзовToolStripMenuItem_Click); - // - // клиентыToolStripMenuItem - // - this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); - this.клиентыToolStripMenuItem.Text = "Клиенты"; - this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1530, 450); - this.Controls.Add(this.buttonRefresh); - this.Controls.Add(this.buttonPut); - this.Controls.Add(this.buttonReady); - this.Controls.Add(this.buttonToWork); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip); - this.MainMenuStrip = this.menuStrip; - this.Name = "FormMain"; - this.Text = "Изготовление Драгоценностей"; - this.Load += new System.EventHandler(this.FormMain_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.menuStrip.ResumeLayout(false); - this.menuStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); + this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(88, 29); + this.отчетыToolStripMenuItem.Text = "Отчеты"; + // + // списокКомпонентовToolStripMenuItem + // + this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; + this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(325, 34); + this.списокКомпонентовToolStripMenuItem.Text = "Список изделий"; + this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.списокКомпонентовToolStripMenuItem_Click); + // + // компонентыПоИзделиямToolStripMenuItem + // + this.компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; + this.компонентыПоИзделиямToolStripMenuItem.Size = new System.Drawing.Size(325, 34); + this.компонентыПоИзделиямToolStripMenuItem.Text = "Изделия по компонентам"; + this.компонентыПоИзделиямToolStripMenuItem.Click += new System.EventHandler(this.компонентыПоИзделиямToolStripMenuItem_Click); + // + // списокЗаказзовToolStripMenuItem + // + this.списокЗаказзовToolStripMenuItem.Name = "списокЗаказзовToolStripMenuItem"; + this.списокЗаказзовToolStripMenuItem.Size = new System.Drawing.Size(325, 34); + this.списокЗаказзовToolStripMenuItem.Text = "Список заказов"; + this.списокЗаказзовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказзовToolStripMenuItem_Click); + // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(136, 29); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1530, 450); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonPut); + this.Controls.Add(this.buttonReady); + this.Controls.Add(this.buttonToWork); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Изготовление Драгоценностей"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -222,5 +231,6 @@ private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказзовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; - } + private ToolStripMenuItem запускРаботToolStripMenuItem; + } } \ No newline at end of file diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs index c37b157..c8a6e2b 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -20,15 +20,16 @@ namespace JewelryStore private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; - + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -48,9 +49,9 @@ namespace JewelryStore dataGridView.Columns["JewelId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; - } + } - _logger.LogInformation("Загрузка заказов"); + _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) { @@ -231,13 +232,23 @@ namespace JewelryStore } } - private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } - } - } + private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } + + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + { + + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } } diff --git a/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs b/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..a3c2a8c --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + internal class WorkModeling + { + } +} diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs b/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..0583744 --- /dev/null +++ b/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + internal interface IWorkProcess + { + } +} diff --git a/JewelryStoreDataModels/Models/IImplementerModel.cs b/JewelryStoreDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..d2ad852 --- /dev/null +++ b/JewelryStoreDataModels/Models/IImplementerModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + internal interface IImplementerModel + { + } +} diff --git a/JewelryStoreRestApi/Controllers/ImplementerController.cs b/JewelryStoreRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..e6367c0 --- /dev/null +++ b/JewelryStoreRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; + +namespace JewelryStoreRestApi.Controllers +{ + public class ImplementerController : Controller + { + public IActionResult Index() + { + return View(); + } + } +} -- 2.25.1 From 5da4a4c8b258d0db6c9c96686c9e880d23137f2f Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:05:56 +0400 Subject: [PATCH 02/24] without task --- .../BusinessLogics/WorkModeling.cs | 140 +++++++++++++++++- .../BusinessLogicsContracts/IWorkProcess.cs | 7 +- .../Models/IImplementerModel.cs | 7 +- .../Controllers/ImplementerController.cs | 100 ++++++++++++- 4 files changed, 247 insertions(+), 7 deletions(-) diff --git a/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs b/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs index a3c2a8c..e969286 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs @@ -1,4 +1,9 @@ -using System; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +11,138 @@ using System.Threading.Tasks; namespace JewelryStoreBusinessLogic.BusinessLogics { - internal class WorkModeling + public class WorkModeling : IWorkProcess { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel { /*Status = OrderStatus.Принят*/ }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + /// + /// Иммитация работы исполнителя + /// + /// + /// + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + // ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + // ImplementerId = implementer.Id, + // Status = OrderStatus.Выполняется + })); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } } } diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs b/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs index 0583744..60b4065 100644 --- a/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs +++ b/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -6,7 +6,12 @@ using System.Threading.Tasks; namespace JewelryStoreContracts.BusinessLogicsContracts { - internal interface IWorkProcess + public interface IWorkProcess { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } } diff --git a/JewelryStoreDataModels/Models/IImplementerModel.cs b/JewelryStoreDataModels/Models/IImplementerModel.cs index d2ad852..5a48419 100644 --- a/JewelryStoreDataModels/Models/IImplementerModel.cs +++ b/JewelryStoreDataModels/Models/IImplementerModel.cs @@ -6,7 +6,12 @@ using System.Threading.Tasks; namespace JewelryStoreDataModels.Models { - internal interface IImplementerModel + public interface IImplementerModel : IId { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } } diff --git a/JewelryStoreRestApi/Controllers/ImplementerController.cs b/JewelryStoreRestApi/Controllers/ImplementerController.cs index e6367c0..9a318f4 100644 --- a/JewelryStoreRestApi/Controllers/ImplementerController.cs +++ b/JewelryStoreRestApi/Controllers/ImplementerController.cs @@ -1,12 +1,106 @@ -using Microsoft.AspNetCore.Mvc; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; namespace JewelryStoreRestApi.Controllers { + [Route("api/[controller]/[action]")] + [ApiController] public class ImplementerController : Controller { - public IActionResult Index() + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IImplementerLogic _logic; + + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) { - return View(); + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + //Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + //ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id); + throw; + } } } } -- 2.25.1 From d63de503ca4563550e38554175c6511164237d09 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:07:28 +0400 Subject: [PATCH 03/24] ImplementerBindingModel --- .../BindingModels/ImplementerBindingModel.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 JewelryStoreContracts/BindingModels/ImplementerBindingModel.cs diff --git a/JewelryStoreContracts/BindingModels/ImplementerBindingModel.cs b/JewelryStoreContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..5d9c8e3 --- /dev/null +++ b/JewelryStoreContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + } +} -- 2.25.1 From c4f9648e05a046b8e82ef0c6bdfa85bba06a21bb Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:08:44 +0400 Subject: [PATCH 04/24] IImplementerLogic --- .../IImplementerLogic.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..1688ab6 --- /dev/null +++ b/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + + bool Create(ImplementerBindingModel model); + + bool Update(ImplementerBindingModel model); + + bool Delete(ImplementerBindingModel model); + } +} -- 2.25.1 From e18572c2fb432082aed3fa50c87a63c35eacd3dd Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:09:26 +0400 Subject: [PATCH 05/24] ImplementerSearchModel --- .../SearchModels/ImplementerSearchModel.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs diff --git a/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs b/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..49b0f7c --- /dev/null +++ b/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public interface ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} -- 2.25.1 From ff34f4fa82635e5e3ba7a47c4270860ac6691fc8 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:10:23 +0400 Subject: [PATCH 06/24] IImplementerStorage --- .../StoragesContracts/IImplementerStorage.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs diff --git a/JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs b/JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..f4da32c --- /dev/null +++ b/JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,25 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + + List GetFilteredList(ImplementerSearchModel model); + + ImplementerViewModel? GetElement(ImplementerSearchModel model); + + ImplementerViewModel? Insert(ImplementerBindingModel model); + + ImplementerViewModel? Update(ImplementerBindingModel model); + + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} -- 2.25.1 From 26cd0166f192a91e7bd6e7f7410699398b3bc29a Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:11:16 +0400 Subject: [PATCH 07/24] ImplementerViewModel --- .../ViewModels/ImplementerViewModel.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 JewelryStoreContracts/ViewModels/ImplementerViewModel.cs diff --git a/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs b/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..f84e6f7 --- /dev/null +++ b/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} -- 2.25.1 From e4f3c762ae68f1cd408931b34258369d3c1b9ac6 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:12:04 +0400 Subject: [PATCH 08/24] contracts done lab 6 --- .../BusinessLogicsContracts/IImplementerLogic.cs | 2 ++ JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs index 1688ab6..342b189 100644 --- a/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs +++ b/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -1,4 +1,6 @@ using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; diff --git a/JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs b/JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs index f4da32c..da83b5f 100644 --- a/JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs +++ b/JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs @@ -1,5 +1,6 @@ using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; -- 2.25.1 From 3aeba1f75f450fff73af630968171a5bfdf40dc4 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:17:53 +0400 Subject: [PATCH 09/24] ImplementerLogic --- JewelryStore/Program.cs | 1 + .../BusinessLogics/ImplementerLogic.cs | 130 ++++++++++++++++++ .../SearchModels/ImplementerSearchModel.cs | 2 +- 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 JewelryStoreBusinessLogic/BusinessLogics/ImplementerLogic.cs diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index 344d316..1f9567f 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -49,6 +49,7 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/JewelryStoreBusinessLogic/BusinessLogics/ImplementerLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..5f2dfdd --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,130 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. FIO:{FIO}.Id:{ Id}", + model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, model?.Id); + var list = (model == null) ? _implementerStorage.GetFullList() : + _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.WorkExperience < 0) + { + throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs b/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs index 49b0f7c..72d4a52 100644 --- a/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs +++ b/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace JewelryStoreContracts.SearchModels { - public interface ImplementerSearchModel + public class ImplementerSearchModel { public int? Id { get; set; } -- 2.25.1 From 5f7feaae24c783485f51d2700dd9eb194a55b86f Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:21:01 +0400 Subject: [PATCH 10/24] Implementer --- .../Models/Implementer.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 JewelryStoreListImplement/Models/Implementer.cs diff --git a/JewelryStoreListImplement/Models/Implementer.cs b/JewelryStoreListImplement/Models/Implementer.cs new file mode 100644 index 0000000..d8c279a --- /dev/null +++ b/JewelryStoreListImplement/Models/Implementer.cs @@ -0,0 +1,62 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public int Id { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + } +} + -- 2.25.1 From 56f3b52c332943f560deb60befebb7ff1e84598a Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:22:00 +0400 Subject: [PATCH 11/24] ImplementerStorage --- .../Implements/ImplementerStorage.cs | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 JewelryStoreListImplement/Implements/ImplementerStorage.cs diff --git a/JewelryStoreListImplement/Implements/ImplementerStorage.cs b/JewelryStoreListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..6737fd4 --- /dev/null +++ b/JewelryStoreListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,131 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class ImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + + return element.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + return x.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null && + x.ImplementerFIO.Equals(model.ImplementerFIO) && + x.Password.Equals(model.Password)) + return x.GetViewModel; + + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + return x.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + List result = new(); + + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + + var res = Implementer.Create(model); + + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + + return implementer.GetViewModel; + } + } + return null; + } + } +} +} -- 2.25.1 From 46ae6a12265919abb257d1092a4bb878c9a5a043 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:22:47 +0400 Subject: [PATCH 12/24] list implement done --- JewelryStoreListImplement/DataListSingleton.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/JewelryStoreListImplement/DataListSingleton.cs b/JewelryStoreListImplement/DataListSingleton.cs index f3f9afa..a9b35b4 100644 --- a/JewelryStoreListImplement/DataListSingleton.cs +++ b/JewelryStoreListImplement/DataListSingleton.cs @@ -14,12 +14,14 @@ namespace JewelryStoreListImplement public List Orders { get; set; } public List Jewels { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Jewels = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { -- 2.25.1 From bd144c5b4a03bbb775abd3ba5c9a8163a1678f1a Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:24:02 +0400 Subject: [PATCH 13/24] Implementer --- JewelryStoreFileImplement/Models/Implementer.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 JewelryStoreFileImplement/Models/Implementer.cs diff --git a/JewelryStoreFileImplement/Models/Implementer.cs b/JewelryStoreFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..388d5da --- /dev/null +++ b/JewelryStoreFileImplement/Models/Implementer.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreFileImplement.Models +{ + internal class Implementer + { + } +} -- 2.25.1 From ffc368d51aa1f8a45043a0cbdadf2f9cfd131c8a Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:24:21 +0400 Subject: [PATCH 14/24] Implementer --- .../Models/Implementer.cs | 78 ++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/JewelryStoreFileImplement/Models/Implementer.cs b/JewelryStoreFileImplement/Models/Implementer.cs index 388d5da..e6b305f 100644 --- a/JewelryStoreFileImplement/Models/Implementer.cs +++ b/JewelryStoreFileImplement/Models/Implementer.cs @@ -1,12 +1,86 @@ -using System; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; namespace JewelryStoreFileImplement.Models { - internal class Implementer + public class Implementer : IImplementerModel { + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public int Id { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("FIO", ImplementerFIO), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); } } -- 2.25.1 From 28d03e79ed1de04a8963a0d92191f01b268b6612 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:25:20 +0400 Subject: [PATCH 15/24] ImplementerStorage --- .../Implements/ImplementerStorage.cs | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 JewelryStoreFileImplement/Implements/ImplementerStorage.cs diff --git a/JewelryStoreFileImplement/Implements/ImplementerStorage.cs b/JewelryStoreFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..b0c823a --- /dev/null +++ b/JewelryStoreFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,108 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null) + return _source.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + + if (model.ImplementerFIO != null) + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + + var res = Implementer.Create(model); + + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + + return res?.GetViewModel; + } + } +} + -- 2.25.1 From 5ca87aa12f4f2f343df5e67cf9170ccfd5e17aa0 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:26:54 +0400 Subject: [PATCH 16/24] file implement done lab 6 --- JewelryStoreFileImplement/DataFileSingleton.cs | 7 +++++++ JewelryStoreFileImplement/Implements/ImplementerStorage.cs | 1 + 2 files changed, 8 insertions(+) diff --git a/JewelryStoreFileImplement/DataFileSingleton.cs b/JewelryStoreFileImplement/DataFileSingleton.cs index 4479672..40f68f9 100644 --- a/JewelryStoreFileImplement/DataFileSingleton.cs +++ b/JewelryStoreFileImplement/DataFileSingleton.cs @@ -15,11 +15,14 @@ namespace JewelryStoreFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string JewelFileName = "Jewel.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; + public List Components { get; private set; } public List Orders { get; private set; } public List Jewels { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { @@ -33,6 +36,8 @@ namespace JewelryStoreFileImplement public void SaveJewels() => SaveData(Jewels, JewelFileName, "Jewels", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x => x.GetXElement); + private DataFileSingleton() { @@ -40,6 +45,8 @@ namespace JewelryStoreFileImplement Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; + } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/JewelryStoreFileImplement/Implements/ImplementerStorage.cs b/JewelryStoreFileImplement/Implements/ImplementerStorage.cs index b0c823a..16ff71e 100644 --- a/JewelryStoreFileImplement/Implements/ImplementerStorage.cs +++ b/JewelryStoreFileImplement/Implements/ImplementerStorage.cs @@ -2,6 +2,7 @@ using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; +using JewelryStoreFileImplement.Models; using System; using System.Collections.Generic; using System.Linq; -- 2.25.1 From 5efe8979065dedd2ed57166181dbc2a9bff55c66 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:40:22 +0400 Subject: [PATCH 17/24] Implementer model --- .../Models/Implementer.cs | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 JewelryStoreDatabaseImplement/Models/Implementer.cs diff --git a/JewelryStoreDatabaseImplement/Models/Implementer.cs b/JewelryStoreDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..71b05b5 --- /dev/null +++ b/JewelryStoreDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,71 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + + [Required] + public string Password { get; private set; } = string.Empty; + + [Required] + public int WorkExperience { get; private set; } + + [Required] + public int Qualification { get; private set; } + + public int Id { get; private set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; private set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + } +} + -- 2.25.1 From f7e65c05fa9ddc64d13421c9f7a40c179f9eaeab Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:44:59 +0400 Subject: [PATCH 18/24] order model changed lab 6 --- JewelryStoreContracts/BindingModels/OrderBindingModel.cs | 1 + JewelryStoreContracts/ViewModels/OrderViewModel.cs | 5 ++++- JewelryStoreDatabaseImplement/Models/Order.cs | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/JewelryStoreContracts/BindingModels/OrderBindingModel.cs b/JewelryStoreContracts/BindingModels/OrderBindingModel.cs index 77ed89e..9ec08a4 100644 --- a/JewelryStoreContracts/BindingModels/OrderBindingModel.cs +++ b/JewelryStoreContracts/BindingModels/OrderBindingModel.cs @@ -20,6 +20,7 @@ namespace JewelryStoreContracts.BindingModels public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } + public int? ImplementerId { get; set; } } } diff --git a/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/JewelryStoreContracts/ViewModels/OrderViewModel.cs index 2d03e3c..0335141 100644 --- a/JewelryStoreContracts/ViewModels/OrderViewModel.cs +++ b/JewelryStoreContracts/ViewModels/OrderViewModel.cs @@ -33,6 +33,9 @@ namespace JewelryStoreContracts.ViewModels public DateTime DateCreate { get; set; } = DateTime.Now; [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } - } + public int? ImplementerId { get; set; } + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + } } diff --git a/JewelryStoreDatabaseImplement/Models/Order.cs b/JewelryStoreDatabaseImplement/Models/Order.cs index 0e297d5..3bfbd59 100644 --- a/JewelryStoreDatabaseImplement/Models/Order.cs +++ b/JewelryStoreDatabaseImplement/Models/Order.cs @@ -20,6 +20,7 @@ namespace JewelryStoreDatabaseImplement.Models [Required] public int ClientId { get; set; } + public int? ImplementerId { get; private set; } public string JewelName { get; private set; } = string.Empty; @@ -39,6 +40,7 @@ namespace JewelryStoreDatabaseImplement.Models public virtual Jewel Jewel { get; set; } public virtual Client Client { get; set; } + public Implementer? Implementer { get; set; } public static Order? Create(OrderBindingModel? model) { @@ -52,6 +54,7 @@ namespace JewelryStoreDatabaseImplement.Models Id = model.Id, JewelId = model.JewelId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, JewelName = model.JewelName, Count = model.Count, Sum = model.Sum, @@ -87,13 +90,15 @@ namespace JewelryStoreDatabaseImplement.Models Id = Id, JewelId = JewelId, ClientId = ClientId, + ImplementerId = ImplementerId, ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, JewelName = context.Jewels.FirstOrDefault(x => x.Id == JewelId)?.JewelName ?? string.Empty, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty }; } } -- 2.25.1 From 30394150d8053058f69659b9fbab910e964a4970 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:46:53 +0400 Subject: [PATCH 19/24] ImplementerStorage --- .../Implements/ImplementerStorage.cs | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs diff --git a/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs b/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..f3a4061 --- /dev/null +++ b/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,121 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new JewelryStoreDataBase(); + + var res = context.Implementers + .FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new JewelryStoreDataBase(); + + if (model.Id.HasValue) + return context.Implementers + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + + if (model.ImplementerFIO != null) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + ?.GetViewModel; + + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + if (model.ImplementerFIO != null) + { + using var context = new JewelryStoreDataBase(); + + return context.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + using var context = new JewelryStoreDataBase(); + + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new JewelryStoreDataBase(); + + var res = Implementer.Create(model); + + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new JewelryStoreDataBase(); + + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + } +} + -- 2.25.1 From 374bc28468277c133677717475305eb2cf93412b Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:53:16 +0400 Subject: [PATCH 20/24] OrderStorage changed lab 6 --- .../SearchModels/OrderSearchModel.cs | 5 +- .../Implements/OrderStorage.cs | 74 ++++++++++++------- 2 files changed, 51 insertions(+), 28 deletions(-) diff --git a/JewelryStoreContracts/SearchModels/OrderSearchModel.cs b/JewelryStoreContracts/SearchModels/OrderSearchModel.cs index 4d22d58..2d0a8f4 100644 --- a/JewelryStoreContracts/SearchModels/OrderSearchModel.cs +++ b/JewelryStoreContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using JewelryStoreDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -13,5 +14,7 @@ namespace JewelryStoreContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public int? ImplementerId { get; set; } + public List? Statuses { get; set; } } } diff --git a/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs b/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs index 7c3cb80..f2c1d57 100644 --- a/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs +++ b/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs @@ -19,7 +19,7 @@ namespace JewelryStoreDatabaseImplement.Implements using var context = new JewelryStoreDataBase(); var element = context.Orders.Include(x => x.Jewel) - .Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id); + .Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { @@ -41,39 +41,55 @@ namespace JewelryStoreDatabaseImplement.Implements using var context = new JewelryStoreDataBase(); - return context.Orders.Include(x => x.Jewel) - .Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => + (model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) && + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || + model.Id.HasValue && x.Id == model.Id + ) + ?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (model.Id.HasValue) + { + var result = GetElement(model); + return result != null ? new() { result } : new(); + } + + using var context = new JewelryStoreDataBase(); + IQueryable? queryWhere = null; + + if (model.DateFrom.HasValue && model.DateTo.HasValue) + { + queryWhere = context.Orders + .Where(x => model.DateFrom <= x.DateCreate.Date && + x.DateCreate.Date <= model.DateTo); + } + + else if (model.Statuses != null) + { + queryWhere = context.Orders.Where(x => model.Statuses.Contains(x.Status)); + } + + else if (model.ClientId.HasValue) + { + queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId); + } + + else { return new(); } - using var context = new JewelryStoreDataBase(); - if (model.DateFrom.HasValue) - { - return context.Orders - .Include(x => x.Jewel) - .Include(x => x.Client) - .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) - .ToList(); - } - else if (model.ClientId.HasValue) - return context.Orders - .Include(x => x.Jewel) + + return queryWhere .Include(x => x.Client) - .Where(x => x.ClientId == model.ClientId) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); - return context.Orders - .Include(x => x.Jewel) - .Include(x => x.Client) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); } public List GetFullList() @@ -81,7 +97,7 @@ namespace JewelryStoreDatabaseImplement.Implements using var context = new JewelryStoreDataBase(); return context.Orders.Include(x => x.Jewel) - .Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + .Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -98,7 +114,11 @@ namespace JewelryStoreDatabaseImplement.Implements context.Orders.Add(newOrder); context.SaveChanges(); - return newOrder.GetViewModel; + return context.Orders.Include(x => x.Jewel) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == newOrder.Id) + ?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -106,7 +126,7 @@ namespace JewelryStoreDatabaseImplement.Implements using var context = new JewelryStoreDataBase(); var order = context.Orders.Include(x => x.Jewel) - .Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id); + .Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; -- 2.25.1 From 11474146ab5b9f4fc852817c14530b4094a36bac Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 18:54:12 +0400 Subject: [PATCH 21/24] db implement done lab 6 --- .../Implements/ImplementerStorage.cs | 1 + JewelryStoreDatabaseImplement/JewelryStoreDataBase.cs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs b/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs index f3a4061..886b090 100644 --- a/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs +++ b/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs @@ -2,6 +2,7 @@ using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; +using JewelryStoreDatabaseImplement.Models; using System; using System.Collections.Generic; using System.Linq; diff --git a/JewelryStoreDatabaseImplement/JewelryStoreDataBase.cs b/JewelryStoreDatabaseImplement/JewelryStoreDataBase.cs index cff4fa7..244174f 100644 --- a/JewelryStoreDatabaseImplement/JewelryStoreDataBase.cs +++ b/JewelryStoreDatabaseImplement/JewelryStoreDataBase.cs @@ -25,7 +25,9 @@ namespace JewelryStoreDatabaseImplement public virtual DbSet Jewels { set; get; } public virtual DbSet JewelComponents { set; get; } public virtual DbSet Orders { set; get; } - public virtual DbSet Clients { set; get; } + public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } + } } -- 2.25.1 From 903e904a7afadc61c757e48d2ad650a64532d847 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 17 Apr 2023 23:38:44 +0400 Subject: [PATCH 22/24] =?UTF-8?q?=D0=B2=D1=81=D0=B5=20=D1=81=D0=BB=D0=BE?= =?UTF-8?q?=D0=BC=D0=B0=D0=BB=D0=BE=D1=81=D1=8C,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/FormImplementer.Designer.cs | 167 ++++++++++++++++++ JewelryStore/FormImplementer.cs | 107 +++++++++++ JewelryStore/FormImplementer.resx | 120 +++++++++++++ JewelryStore/FormImplementers.Designer.cs | 114 ++++++++++++ JewelryStore/FormImplementers.cs | 120 +++++++++++++ JewelryStore/FormImplementers.resx | 120 +++++++++++++ JewelryStore/FormMain.Designer.cs | 20 ++- JewelryStore/FormMain.cs | 58 +++--- JewelryStore/Program.cs | 6 +- JewelryStore/nlog.config | 15 ++ .../BusinessLogics/OrderLogic.cs | 142 +++++++++------ .../BusinessLogics/WorkModeling.cs | 55 +++--- .../BusinessLogicsContracts/IOrderLogic.cs | 2 + .../ViewModels/OrderViewModel.cs | 2 +- JewelryStoreDataModels/Models/IOrderModel.cs | 4 +- ... 20230417191656_InitialCreate.Designer.cs} | 45 ++++- ...ate.cs => 20230417191656_InitialCreate.cs} | 30 ++++ .../JewelryStoreDataBaseModelSnapshot.cs | 43 +++++ JewelryStoreDatabaseImplement/Models/Order.cs | 2 + JewelryStoreFileImplement/Models/Order.cs | 1 + .../Implements/ImplementerStorage.cs | 2 +- JewelryStoreListImplement/Models/Order.cs | 3 + .../Controllers/ImplementerController.cs | 2 +- 23 files changed, 1060 insertions(+), 120 deletions(-) create mode 100644 JewelryStore/FormImplementer.Designer.cs create mode 100644 JewelryStore/FormImplementer.cs create mode 100644 JewelryStore/FormImplementer.resx create mode 100644 JewelryStore/FormImplementers.Designer.cs create mode 100644 JewelryStore/FormImplementers.cs create mode 100644 JewelryStore/FormImplementers.resx create mode 100644 JewelryStore/nlog.config rename JewelryStoreDatabaseImplement/Migrations/{20230403133347_InitialCreate.Designer.cs => 20230417191656_InitialCreate.Designer.cs} (82%) rename JewelryStoreDatabaseImplement/Migrations/{20230403133347_InitialCreate.cs => 20230417191656_InitialCreate.cs} (82%) diff --git a/JewelryStore/FormImplementer.Designer.cs b/JewelryStore/FormImplementer.Designer.cs new file mode 100644 index 0000000..e29f282 --- /dev/null +++ b/JewelryStore/FormImplementer.Designer.cs @@ -0,0 +1,167 @@ +namespace JewelryStore +{ + partial class FormImplementer + { + /// + /// 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() + { + this.FIOTextBox = new System.Windows.Forms.TextBox(); + this.PasswordTextBox = new System.Windows.Forms.TextBox(); + this.LabelFIO = new System.Windows.Forms.Label(); + this.LabelPassword = new System.Windows.Forms.Label(); + this.QualificationNumericUpDown = new System.Windows.Forms.NumericUpDown(); + this.WorkExpNumericUpDown = new System.Windows.Forms.NumericUpDown(); + this.LabelWorkExperience = new System.Windows.Forms.Label(); + this.LabelQualification = new System.Windows.Forms.Label(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.QualificationNumericUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.WorkExpNumericUpDown)).BeginInit(); + this.SuspendLayout(); + // + // FIOTextBox + // + this.FIOTextBox.Location = new System.Drawing.Point(112, 12); + this.FIOTextBox.Name = "FIOTextBox"; + this.FIOTextBox.Size = new System.Drawing.Size(170, 23); + this.FIOTextBox.TabIndex = 0; + // + // PasswordTextBox + // + this.PasswordTextBox.Location = new System.Drawing.Point(112, 49); + this.PasswordTextBox.Name = "PasswordTextBox"; + this.PasswordTextBox.Size = new System.Drawing.Size(170, 23); + this.PasswordTextBox.TabIndex = 1; + // + // LabelFIO + // + this.LabelFIO.AutoSize = true; + this.LabelFIO.Location = new System.Drawing.Point(12, 15); + this.LabelFIO.Name = "LabelFIO"; + this.LabelFIO.Size = new System.Drawing.Size(40, 15); + this.LabelFIO.TabIndex = 2; + this.LabelFIO.Text = "ФИО: "; + // + // LabelPassword + // + this.LabelPassword.AutoSize = true; + this.LabelPassword.Location = new System.Drawing.Point(12, 52); + this.LabelPassword.Name = "LabelPassword"; + this.LabelPassword.Size = new System.Drawing.Size(55, 15); + this.LabelPassword.TabIndex = 3; + this.LabelPassword.Text = "Пароль: "; + // + // QualificationNumericUpDown + // + this.QualificationNumericUpDown.Location = new System.Drawing.Point(112, 131); + this.QualificationNumericUpDown.Name = "QualificationNumericUpDown"; + this.QualificationNumericUpDown.Size = new System.Drawing.Size(170, 23); + this.QualificationNumericUpDown.TabIndex = 4; + // + // WorkExpNumericUpDown + // + this.WorkExpNumericUpDown.Location = new System.Drawing.Point(112, 90); + this.WorkExpNumericUpDown.Name = "WorkExpNumericUpDown"; + this.WorkExpNumericUpDown.Size = new System.Drawing.Size(170, 23); + this.WorkExpNumericUpDown.TabIndex = 5; + // + // LabelWorkExperience + // + this.LabelWorkExperience.AutoSize = true; + this.LabelWorkExperience.Location = new System.Drawing.Point(12, 92); + this.LabelWorkExperience.Name = "LabelWorkExperience"; + this.LabelWorkExperience.Size = new System.Drawing.Size(87, 15); + this.LabelWorkExperience.TabIndex = 6; + this.LabelWorkExperience.Text = "Опыт работы: "; + // + // LabelQualification + // + this.LabelQualification.AutoSize = true; + this.LabelQualification.Location = new System.Drawing.Point(12, 133); + this.LabelQualification.Name = "LabelQualification"; + this.LabelQualification.Size = new System.Drawing.Size(94, 15); + this.LabelQualification.TabIndex = 7; + this.LabelQualification.Text = "Квалификация: "; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(185, 169); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(97, 29); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(82, 169); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(97, 29); + this.ButtonSave.TabIndex = 9; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(306, 214); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.LabelQualification); + this.Controls.Add(this.LabelWorkExperience); + this.Controls.Add(this.WorkExpNumericUpDown); + this.Controls.Add(this.QualificationNumericUpDown); + this.Controls.Add(this.LabelPassword); + this.Controls.Add(this.LabelFIO); + this.Controls.Add(this.PasswordTextBox); + this.Controls.Add(this.FIOTextBox); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.QualificationNumericUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.WorkExpNumericUpDown)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox FIOTextBox; + private TextBox PasswordTextBox; + private Label LabelFIO; + private Label LabelPassword; + private NumericUpDown QualificationNumericUpDown; + private NumericUpDown WorkExpNumericUpDown; + private Label LabelWorkExperience; + private Label LabelQualification; + private Button ButtonCancel; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/JewelryStore/FormImplementer.cs b/JewelryStore/FormImplementer.cs new file mode 100644 index 0000000..241fcfa --- /dev/null +++ b/JewelryStore/FormImplementer.cs @@ -0,0 +1,107 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +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 JewelryStore +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(PasswordTextBox.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(FIOTextBox.Text)) + { + MessageBox.Show("Заполните фио", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = FIOTextBox.Text, + Password = PasswordTextBox.Text, + Qualification = (int)QualificationNumericUpDown.Value, + WorkExperience = (int)WorkExpNumericUpDown.Value, + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + FIOTextBox.Text = view.ImplementerFIO; + PasswordTextBox.Text = view.Password; + QualificationNumericUpDown.Value = view.Qualification; + WorkExpNumericUpDown.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} + diff --git a/JewelryStore/FormImplementer.resx b/JewelryStore/FormImplementer.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormImplementer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/JewelryStore/FormImplementers.Designer.cs b/JewelryStore/FormImplementers.Designer.cs new file mode 100644 index 0000000..cf210bf --- /dev/null +++ b/JewelryStore/FormImplementers.Designer.cs @@ -0,0 +1,114 @@ +namespace JewelryStore +{ + partial class FormImplementers + { + /// + /// 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() + { + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(632, 448); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(639, 12); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(98, 45); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(639, 63); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(98, 45); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(639, 114); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(98, 45); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(639, 165); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(98, 45); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(749, 450); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/JewelryStore/FormImplementers.cs b/JewelryStore/FormImplementers.cs new file mode 100644 index 0000000..22fa746 --- /dev/null +++ b/JewelryStore/FormImplementers.cs @@ -0,0 +1,120 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.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 JewelryStore +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + _logger.LogInformation("Удаление исполнителя"); + + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка исполнителей"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/JewelryStore/FormImplementers.resx b/JewelryStore/FormImplementers.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormImplementers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/JewelryStore/FormMain.Designer.cs b/JewelryStore/FormMain.Designer.cs index a837582..251d535 100644 --- a/JewelryStore/FormMain.Designer.cs +++ b/JewelryStore/FormMain.Designer.cs @@ -39,6 +39,7 @@ this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -50,11 +51,11 @@ // // buttonReady // - this.buttonReady.Location = new System.Drawing.Point(1273, 225); + this.buttonReady.Location = new System.Drawing.Point(1273, 298); this.buttonReady.Name = "buttonReady"; this.buttonReady.Size = new System.Drawing.Size(215, 34); this.buttonReady.TabIndex = 3; - this.buttonReady.Text = "Заказ готов"; + this.buttonReady.Text = "Заказ выдан"; this.buttonReady.UseVisualStyleBackColor = true; this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); // @@ -90,11 +91,11 @@ // // buttonPut // - this.buttonPut.Location = new System.Drawing.Point(1273, 308); + this.buttonPut.Location = new System.Drawing.Point(1273, 218); this.buttonPut.Name = "buttonPut"; this.buttonPut.Size = new System.Drawing.Size(215, 34); this.buttonPut.TabIndex = 4; - this.buttonPut.Text = "Заказ выдан"; + this.buttonPut.Text = "Заказ готов"; this.buttonPut.UseVisualStyleBackColor = true; this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click); // @@ -126,7 +127,8 @@ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, this.изделияToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -152,6 +154,13 @@ this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -232,5 +241,6 @@ private ToolStripMenuItem списокЗаказзовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs index c8a6e2b..1917875 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -48,7 +48,7 @@ namespace JewelryStore dataGridView.DataSource = list; dataGridView.Columns["JewelId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; - + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); @@ -100,14 +100,14 @@ namespace JewelryStore var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, - JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), - - JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), + //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), + //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), + //Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + //DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -136,13 +136,14 @@ namespace JewelryStore var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, - JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), - JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), + //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), + //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), + //Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + //DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -171,13 +172,14 @@ namespace JewelryStore OrderBindingModel { Id = id, - JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), - JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), + //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), + //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), + //Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + //DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -250,5 +252,15 @@ namespace JewelryStore MessageBoxButtons.OK, MessageBoxIcon.Information); } } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index 1f9567f..50bf9fa 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -42,8 +42,11 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -65,7 +68,8 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); - + services.AddTransient(); + services.AddTransient(); } } diff --git a/JewelryStore/nlog.config b/JewelryStore/nlog.config new file mode 100644 index 0000000..609afe6 --- /dev/null +++ b/JewelryStore/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs index 6bcfa52..7010a87 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -15,13 +15,9 @@ namespace JewelryStoreBusinessLogic.BusinessLogics { public class OrderLogic : IOrderLogic //TODO реализовать интерфейс { - // Класс с логикой для заказов будет отвечать за получение списка заказов, - //создания заказа и смены его статусов.Следует учитывать, что у заказа можно - //менять статус на новый, если его текущий статус предшествует новому - //(например, в статус «Готов» можно переводить, если заказ находится в статусе - //«Выполняется»). private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; @@ -31,100 +27,140 @@ namespace JewelryStoreBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) return false; + + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) { + model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } + return true; } + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var vmodel = _orderStorage.GetElement(new() { Id = model.Id }); + + if (vmodel == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if ((int)vmodel.Status + 1 != (int)newStatus) + { + throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " + + $"Текущий статус: {vmodel.Status} \n" + + $"Планируемый статус: {newStatus} \n" + + $"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}"); + } + + model.Status = newStatus; + model.DateCreate = vmodel.DateCreate; + + if (model.DateImplement == null) + model.DateImplement = vmodel.DateImplement; + + if (vmodel.ImplementerId.HasValue) + model.ImplementerId = vmodel.ImplementerId; + + model.JewelId = vmodel.JewelId; + model.Sum = vmodel.Sum; + model.Count = vmodel.Count; + + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + + return false; + } + + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + public bool DeliveryOrder(OrderBindingModel model) { - CheckModel(model); - if (model.Status != OrderStatus.Готов) return false; - - model.Status = OrderStatus.Выдан; model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; + return StatusUpdate(model, OrderStatus.Готов); } public bool FinishOrder(OrderBindingModel model) { - CheckModel(model); - if (model.Status != OrderStatus.Выполняется) return false; - - model.Status = OrderStatus.Готов; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; + return StatusUpdate(model, OrderStatus.Выдан); } public List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + _logger.LogInformation("Order. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) { _logger.LogWarning("ReadList return null list"); return null; } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - public bool TakeOrderInWork(OrderBindingModel model) + private bool CheckModel(OrderBindingModel model) { - CheckModel(model); - if (model.Status != OrderStatus.Принят) return false; - model.Status = OrderStatus.Выполняется; - if (_orderStorage.Update(model) == null) + if (model == null) { - _logger.LogWarning("Update operation failed"); - return false; + throw new ArgumentNullException(nameof(model)); } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.DateCreate > model.DateImplement) + { + throw new ArgumentException("Время создания заказа не может быть больше времени его выполнения", nameof(model.DateImplement)); + } + return true; } - private void CheckModel(OrderBindingModel model, bool withParams = true) + public OrderViewModel? ReadElement(OrderSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } - if (!withParams) + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + + var element = _orderStorage.GetElement(model); + + if (element == null) { - return; + _logger.LogWarning("ReadElement element not found"); + + return null; } - if (model.JewelId < 0) - { - throw new ArgumentNullException("Некорректный идентификатор драгоценности", nameof(model.JewelId)); - } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - if (model.Count <= 0) - { - throw new ArgumentNullException("Количество драгоценностей в заказе должно быть больше 0", nameof(model.Count)); - } - - if (model.Sum <= 0) - { - throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); - } - - _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. JewelId: { JewelId}", model.Id, model.Sum, model.JewelId); + return element; } - } } diff --git a/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs b/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs index e969286..433fe50 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs @@ -2,6 +2,7 @@ using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -34,31 +35,29 @@ namespace JewelryStoreBusinessLogic.BusinessLogics _logger.LogWarning("DoWork. Implementers is null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel { /*Status = OrderStatus.Принят*/ }); + + var orders = _orderLogic.ReadList(new OrderSearchModel { Statuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); if (orders == null || orders.Count == 0) { _logger.LogWarning("DoWork. Orders is null or empty"); return; } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) { Task.Run(() => WorkerWorkAsync(implementer, orders)); } } - /// - /// Иммитация работы исполнителя - /// - /// - /// private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) { if (_orderLogic == null || implementer == null) { return; } - await RunOrderInWork(implementer); + await RunOrderInWork(implementer, orders); await Task.Run(() => { @@ -67,77 +66,69 @@ namespace JewelryStoreBusinessLogic.BusinessLogics try { _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); - // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = order.Id, - // ImplementerId = implementer.Id + ImplementerId = implementer.Id }); - // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); - _orderLogic.FinishOrder(new OrderBindingModel + + _orderLogic.DeliveryOrder(new OrderBindingModel { Id = order.Id }); + + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } - // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) { _logger.LogWarning(ex, "Error try get work"); } - // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) { _logger.LogError(ex, "Error while do work"); throw; } - // отдыхаем - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } }); } - /// - /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) - /// - /// - /// - private async Task RunOrderInWork(ImplementerViewModel implementer) + private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders) { - if (_orderLogic == null || implementer == null) + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) { return; } try { - var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel - { - // ImplementerId = implementer.Id, - // Status = OrderStatus.Выполняется - })); + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется)); if (runOrder == null) { return; } _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); - // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); - _orderLogic.FinishOrder(new OrderBindingModel + _orderLogic.DeliveryOrder(new OrderBindingModel { Id = runOrder.Id }); - // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } - // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) { _logger.LogWarning(ex, "Error try get work"); } - // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) { _logger.LogError(ex, "Error while do work"); diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs index a403f30..5a905c5 100644 --- a/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,8 @@ namespace JewelryStoreContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); + bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/JewelryStoreContracts/ViewModels/OrderViewModel.cs index 0335141..4a61b37 100644 --- a/JewelryStoreContracts/ViewModels/OrderViewModel.cs +++ b/JewelryStoreContracts/ViewModels/OrderViewModel.cs @@ -35,7 +35,7 @@ namespace JewelryStoreContracts.ViewModels public DateTime? DateImplement { get; set; } public int? ImplementerId { get; set; } [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; + public string ImplementerFIO { get; set; } = string.Empty; } } diff --git a/JewelryStoreDataModels/Models/IOrderModel.cs b/JewelryStoreDataModels/Models/IOrderModel.cs index 62b66af..dafe1e6 100644 --- a/JewelryStoreDataModels/Models/IOrderModel.cs +++ b/JewelryStoreDataModels/Models/IOrderModel.cs @@ -12,8 +12,8 @@ namespace JewelryStoreDataModels.Models { int JewelId { get; } string JewelName { get; } - - int ClientId { get; } + int? ImplementerId { get; } + int ClientId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.Designer.cs b/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.Designer.cs similarity index 82% rename from JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.Designer.cs rename to JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.Designer.cs index c279e65..e696826 100644 --- a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.Designer.cs +++ b/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace JewelryStoreDatabaseImplement.Migrations { [DbContext(typeof(JewelryStoreDataBase))] - [Migration("20230403133347_InitialCreate")] + [Migration("20230417191656_InitialCreate")] partial class InitialCreate { /// @@ -70,6 +70,33 @@ namespace JewelryStoreDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Property("Id") @@ -136,6 +163,9 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("JewelId") .HasColumnType("int"); @@ -153,6 +183,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("JewelId"); b.ToTable("Orders"); @@ -185,6 +217,10 @@ namespace JewelryStoreDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") .WithMany("Orders") .HasForeignKey("JewelId") @@ -193,6 +229,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Jewel"); }); @@ -206,6 +244,11 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("JewelComponents"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Navigation("Components"); diff --git a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.cs b/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.cs similarity index 82% rename from JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.cs rename to JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.cs index 6702f40..3435bf1 100644 --- a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.cs +++ b/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.cs @@ -40,6 +40,22 @@ namespace JewelryStoreDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Jewels", columns: table => new @@ -89,6 +105,7 @@ namespace JewelryStoreDatabaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), JewelId = table.Column(type: "int", nullable: false), ClientId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true), JewelName = table.Column(type: "nvarchar(max)", nullable: false), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), @@ -105,6 +122,11 @@ namespace JewelryStoreDatabaseImplement.Migrations principalTable: "Clients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); table.ForeignKey( name: "FK_Orders_Jewels_JewelId", column: x => x.JewelId, @@ -128,6 +150,11 @@ namespace JewelryStoreDatabaseImplement.Migrations table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_JewelId", table: "Orders", @@ -149,6 +176,9 @@ namespace JewelryStoreDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Jewels"); } diff --git a/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs b/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs index ec2bacf..599816d 100644 --- a/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs +++ b/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace JewelryStoreDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Property("Id") @@ -133,6 +160,9 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("JewelId") .HasColumnType("int"); @@ -150,6 +180,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("JewelId"); b.ToTable("Orders"); @@ -182,6 +214,10 @@ namespace JewelryStoreDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") .WithMany("Orders") .HasForeignKey("JewelId") @@ -190,6 +226,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Jewel"); }); @@ -203,6 +241,11 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("JewelComponents"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Navigation("Components"); diff --git a/JewelryStoreDatabaseImplement/Models/Order.cs b/JewelryStoreDatabaseImplement/Models/Order.cs index 3bfbd59..97d4cfe 100644 --- a/JewelryStoreDatabaseImplement/Models/Order.cs +++ b/JewelryStoreDatabaseImplement/Models/Order.cs @@ -78,6 +78,8 @@ namespace JewelryStoreDatabaseImplement.Models Status = model.Status; DateCreate = model.DateCreate; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; + } public OrderViewModel GetViewModel diff --git a/JewelryStoreFileImplement/Models/Order.cs b/JewelryStoreFileImplement/Models/Order.cs index 627c3d0..23bcf7c 100644 --- a/JewelryStoreFileImplement/Models/Order.cs +++ b/JewelryStoreFileImplement/Models/Order.cs @@ -18,6 +18,7 @@ namespace JewelryStoreFileImplement.Models public int ClientId { get; private set; } public string JewelName { get; private set; } = string.Empty; + public int? ImplementerId { get; private set; } public int Count { get; private set; } diff --git a/JewelryStoreListImplement/Implements/ImplementerStorage.cs b/JewelryStoreListImplement/Implements/ImplementerStorage.cs index 6737fd4..42077eb 100644 --- a/JewelryStoreListImplement/Implements/ImplementerStorage.cs +++ b/JewelryStoreListImplement/Implements/ImplementerStorage.cs @@ -128,4 +128,4 @@ namespace JewelryStoreListImplement.Implements } } } -} + diff --git a/JewelryStoreListImplement/Models/Order.cs b/JewelryStoreListImplement/Models/Order.cs index 23c1fbb..18c0bbf 100644 --- a/JewelryStoreListImplement/Models/Order.cs +++ b/JewelryStoreListImplement/Models/Order.cs @@ -15,6 +15,8 @@ namespace JewelryStoreListImplement.Models public int JewelId { get; private set; } public string JewelName { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -71,5 +73,6 @@ namespace JewelryStoreListImplement.Models DateCreate = DateCreate, DateImplement = DateImplement }; + } } diff --git a/JewelryStoreRestApi/Controllers/ImplementerController.cs b/JewelryStoreRestApi/Controllers/ImplementerController.cs index 9a318f4..82ae8e5 100644 --- a/JewelryStoreRestApi/Controllers/ImplementerController.cs +++ b/JewelryStoreRestApi/Controllers/ImplementerController.cs @@ -65,7 +65,7 @@ namespace JewelryStoreRestApi.Controllers { return _order.ReadElement(new OrderSearchModel { - //ImplementerId = implementerId + ImplementerId = implementerId }); } catch (Exception ex) -- 2.25.1 From 1c0e7720e11b7de01bd90395ece5cd4f72f7a8a6 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 18 Apr 2023 14:17:07 +0400 Subject: [PATCH 23/24] =?UTF-8?q?c=D0=B4=D0=B0=D0=BD=D0=B0=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStoreContracts/ViewModels/OrderViewModel.cs | 8 +++++--- ...signer.cs => 20230418091905_InitialCreate.Designer.cs} | 2 +- ...6_InitialCreate.cs => 20230418091905_InitialCreate.cs} | 0 3 files changed, 6 insertions(+), 4 deletions(-) rename JewelryStoreDatabaseImplement/Migrations/{20230417191656_InitialCreate.Designer.cs => 20230418091905_InitialCreate.Designer.cs} (99%) rename JewelryStoreDatabaseImplement/Migrations/{20230417191656_InitialCreate.cs => 20230418091905_InitialCreate.cs} (100%) diff --git a/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/JewelryStoreContracts/ViewModels/OrderViewModel.cs index 4a61b37..fcb9cce 100644 --- a/JewelryStoreContracts/ViewModels/OrderViewModel.cs +++ b/JewelryStoreContracts/ViewModels/OrderViewModel.cs @@ -19,7 +19,10 @@ namespace JewelryStoreContracts.ViewModels [DisplayName("Драгоценность")] public string JewelName { get; set; } = string.Empty; - [DisplayName("Клиент")] + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; [DisplayName("Количество")] @@ -34,8 +37,7 @@ namespace JewelryStoreContracts.ViewModels [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } public int? ImplementerId { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; + } } diff --git a/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.Designer.cs b/JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.Designer.cs similarity index 99% rename from JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.Designer.cs rename to JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.Designer.cs index e696826..6fff767 100644 --- a/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.Designer.cs +++ b/JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace JewelryStoreDatabaseImplement.Migrations { [DbContext(typeof(JewelryStoreDataBase))] - [Migration("20230417191656_InitialCreate")] + [Migration("20230418091905_InitialCreate")] partial class InitialCreate { /// diff --git a/JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.cs b/JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.cs similarity index 100% rename from JewelryStoreDatabaseImplement/Migrations/20230417191656_InitialCreate.cs rename to JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.cs -- 2.25.1 From d34acc756102167bbb81d52fe786642f4e9f2511 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Thu, 4 May 2023 15:59:35 +0400 Subject: [PATCH 24/24] last fix --- JewelryStore/FormMain.cs | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs index 1917875..1c1f900 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -100,14 +100,6 @@ namespace JewelryStore var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, - //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), - //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), - //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), - //Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - //DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -136,14 +128,6 @@ namespace JewelryStore var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, - //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), - //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), - //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), - //Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - //DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -172,14 +156,6 @@ namespace JewelryStore OrderBindingModel { Id = id, - //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), - //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), - //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), - //Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - //DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { -- 2.25.1