4 и 5 проекты / Второй этап Lab_1

This commit is contained in:
Максим Егоров 2024-10-17 01:33:01 +04:00
parent f48e352abe
commit 271960d460
16 changed files with 401 additions and 173 deletions

View File

@ -9,6 +9,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingFactoryDataModels", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingFactoryContracts", "SewingFactoryContracts\SewingFactoryContracts.csproj", "{D979DF0C-B534-4563-97E5-04389DB2F6B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingFactoryListImplement", "SewingFactoryListImplement\SewingFactoryListImplement.csproj", "{31EA02DD-1E53-4FB5-A729-EF5D3F50E27D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingFactoryBusinessLogic", "SewingFactoryBusinessLogic\SewingFactoryBusinessLogic.csproj", "{909C9D71-212E-4544-BC3F-919BF60CBC14}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -27,6 +31,14 @@ Global
{D979DF0C-B534-4563-97E5-04389DB2F6B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D979DF0C-B534-4563-97E5-04389DB2F6B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D979DF0C-B534-4563-97E5-04389DB2F6B9}.Release|Any CPU.Build.0 = Release|Any CPU
{31EA02DD-1E53-4FB5-A729-EF5D3F50E27D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31EA02DD-1E53-4FB5-A729-EF5D3F50E27D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31EA02DD-1E53-4FB5-A729-EF5D3F50E27D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31EA02DD-1E53-4FB5-A729-EF5D3F50E27D}.Release|Any CPU.Build.0 = Release|Any CPU
{909C9D71-212E-4544-BC3F-919BF60CBC14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{909C9D71-212E-4544-BC3F-919BF60CBC14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{909C9D71-212E-4544-BC3F-919BF60CBC14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{909C9D71-212E-4544-BC3F-919BF60CBC14}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,115 @@
using Microsoft.Extensions.Logging;
using SewingFactoryContracts.BindingModels;
using SewingFactoryContracts.BusinessLogicContracts;
using SewingFactoryContracts.SearchModels;
using SewingFactoryContracts.StoragesContracts;
using SewingFactoryContracts.ViewModels;
namespace SewingFactoryBusinessLogic.BusinessLogics
{
public class ComponentLogic : IComponentLogic
{
private readonly ILogger _logger;
private readonly IComponentStorage _componentStorage;
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
{
_logger = logger;
_componentStorage = componentStorage;
}
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
{
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:(Id))", model?.ComponentName, model?.Id);
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ComponentViewModel? ReadElement(ComponentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id})", model?.ComponentName, model?.Id);
var element = _componentStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadList element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id})", element.Id);
return element;
}
public bool Create(ComponentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ComponentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ComponentBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id})", model.Id);
if (_componentStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ComponentBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if(string.IsNullOrEmpty(model.ComponentName))
{
throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName));
}
if (model.Cost <= 0)
{
throw new ArgumentException("Цена компонента должна быть больше 0", nameof(model.Cost));
}
_logger.LogInformation("Component. ComponentName:(ComponentName}. Cost:{Cost}. Id:{Id})", model.ComponentName, model.Cost, model.Id);
var element = _componentStorage.GetElement(new ComponentSearchModel
{
ComponentName = model.ComponentName,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Компонента с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,35 @@
using SewingFactoryContracts.BindingModels;
using SewingFactoryContracts.BusinessLogicContracts;
using SewingFactoryContracts.SearchModels;
using SewingFactoryContracts.ViewModels;
namespace SewingFactoryBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
public bool CreateOrder(OrderBindingModel model)
{
throw new NotImplementedException();
}
public bool DeliveryOrder(OrderBindingModel model)
{
throw new NotImplementedException();
}
public bool FinishOrder(OrderBindingModel model)
{
throw new NotImplementedException();
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
throw new NotImplementedException();
}
public bool TakeOrderInWork(OrderBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,35 @@
using SewingFactoryContracts.BindingModels;
using SewingFactoryContracts.BusinessLogicContracts;
using SewingFactoryContracts.SearchModels;
using SewingFactoryContracts.ViewModels;
namespace SewingFactoryBusinessLogic.BusinessLogics
{
public class TextileLogic : ITextileLogic
{
public bool Create(TextileBindingModel model)
{
throw new NotImplementedException();
}
public bool Delete(TextileBindingModel model)
{
throw new NotImplementedException();
}
public TextileViewModel? ReadElement(TextileSearchModel model)
{
throw new NotImplementedException();
}
public List<TextileViewModel>? ReadList(TextileSearchModel? model)
{
throw new NotImplementedException();
}
public bool Update(TextileBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SewingFactoryContracts\SewingFactoryContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -9,7 +9,9 @@ namespace SewingFactoryContracts.BindingModels
{
public class OrderBindingModel
{
public int TextileID { get; set; }
public int Id { get; set; }
public int TextileId { get; set; }
public int Count { get; set; }

View File

@ -13,7 +13,7 @@ namespace SewingFactoryContracts.ViewModels
public int Id { get; set; }
public int TextileID { get; set; }
public int TextileId { get; set; }
[DisplayName("Изделие")]
public string TextileName { get; set; } = string.Empty;

View File

@ -12,4 +12,4 @@ namespace SewingFactoryDataModels.Models
double Cost { get; }
}
}
}

View File

@ -9,7 +9,7 @@ namespace SewingFactoryDataModels.Models
{
public interface IOrderModel : IId
{
int TextileID { get; }
int TextileId{ get; }
int Count { get; }

View File

@ -0,0 +1,43 @@
using SewingFactoryContracts.BindingModels;
using SewingFactoryContracts.ViewModels;
using SewingFactoryDataModels;
using SewingFactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingFactoryListImplement.Models
{
internal class Component : IComponentModel
{
public int Id { get; set; }
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; set; }
public static Component? Create(ComponentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
}
}

View File

@ -0,0 +1,70 @@
using SewingFactoryContracts.BindingModels;
using SewingFactoryContracts.ViewModels;
using SewingFactoryDataModels;
using SewingFactoryDataModels.Enums;
using SewingFactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingFactoryListImplement.Models
{
internal class Order : IOrderModel
{
public int Id { get; private set; }
public int TextileId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
TextileId = model.TextileId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
TextileId = TextileId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
TextileId = TextileId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
}

View File

@ -0,0 +1,54 @@
using SewingFactoryContracts.BindingModels;
using SewingFactoryContracts.ViewModels;
using SewingFactoryDataModels;
using SewingFactoryDataModels.Models;
namespace SewingFactoryListImplement.Models
{
internal class Textile : ITextileModel
{
public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty;
public double Price { get; private set; }
public string TextileName { get; private set; } = string.Empty;
public Dictionary<int, (IComponentModel, int)> TextileComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
public static Textile? Create(TextileBindingModel? model)
{
if (model == null)
{
return null;
}
return new Textile()
{
Id = model.Id,
TextileName = model.TextileName,
Price = model.Price,
TextileComponents = model.TextileComponents
};
}
public void Update(TextileBindingModel? model)
{
if (model == null)
{
return;
}
TextileName = model.TextileName;
Price = model.Price;
TextileComponents = TextileComponents;
}
public TextileViewModel GetViewModel => new()
{
Id = Id,
TextileName = TextileName,
Price = Price,
TextileComponents = TextileComponents
};
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SewingFactoryContracts\SewingFactoryContracts.csproj" />
<ProjectReference Include="..\SewingFactoryDataModels\SewingFactoryDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -1,39 +0,0 @@
namespace SewingFactoryView
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace SewingFactoryView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

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