orderLogic_1

This commit is contained in:
VictoriaPresnyakova 2023-02-06 15:42:50 +04:00
parent 311bcca65f
commit 3684e616dc
3 changed files with 114 additions and 86 deletions

View File

@ -28,7 +28,7 @@
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.Button buttonReady;
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();
@ -38,20 +38,19 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
buttonReady = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// buttonReady
//
buttonReady.Location = new System.Drawing.Point(1273, 225);
buttonReady.Name = "buttonReady";
buttonReady.Size = new System.Drawing.Size(215, 34);
buttonReady.TabIndex = 3;
buttonReady.Text = "Заказ готов";
buttonReady.UseVisualStyleBackColor = true;
buttonReady.Click += new System.EventHandler(this.buttonReady_Click);
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
//
@ -126,14 +125,14 @@
// компонентыToolStripMenuItem
//
this.компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(218, 34);
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(218, 34);
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);
//
@ -144,14 +143,14 @@
this.ClientSize = new System.Drawing.Size(1530, 450);
this.Controls.Add(this.buttonRefresh);
this.Controls.Add(this.buttonPut);
this.Controls.Add(buttonReady);
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.Text = "Изготовление Драгоценностей";
this.Load += new System.EventHandler(this.FormMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip.ResumeLayout(false);
@ -172,5 +171,6 @@
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem изделияToolStripMenuItem;
private Button buttonReady;
}
}

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
@ -117,4 +57,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -1,7 +1,10 @@
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.BusinessLogicsContracts;
using JewelryStoreContracts.SearchModels;
using JewelryStoreContracts.StoragesContracts;
using JewelryStoreContracts.ViewModels;
using JewelryStoreDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,35 +14,117 @@ using System.Threading.Tasks;
namespace JewelryStoreBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic //TODO реализовать интерфейс
{
// Класс с логикой для заказов будет отвечать за получение списка заказов,
//создания заказа и смены его статусов.Следует учитывать, что у заказа можно
//менять статус на новый, если его текущий статус предшествует новому
//(например, в статус «Готов» можно переводить, если заказ находится в статусе
//«Выполняется»).
{
// Класс с логикой для заказов будет отвечать за получение списка заказов,
//создания заказа и смены его статусов.Следует учитывать, что у заказа можно
//менять статус на новый, если его текущий статус предшествует новому
//(например, в статус «Готов» можно переводить, если заказ находится в статусе
//«Выполняется»).
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public bool CreateOrder(OrderBindingModel model)
{
throw new NotImplementedException();
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) return false;
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool DeliveryOrder(OrderBindingModel model)
{
throw new NotImplementedException();
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;
}
public bool FinishOrder(OrderBindingModel model)
{
throw new NotImplementedException();
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;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
throw new NotImplementedException();
_logger.LogInformation("ReadList. 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)
{
throw new NotImplementedException();
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;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.JewelId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор драгоценности", nameof(model.JewelId));
}
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);
}
}
}