diff --git a/AbstractComputerDataModel/ComputerShopDataModels.csproj b/AbstractComputerDataModel/ComputerShopDataModels.csproj
new file mode 100644
index 0000000..895206e
--- /dev/null
+++ b/AbstractComputerDataModel/ComputerShopDataModels.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/AbstractComputerDataModel/Enums/OrderStatus.cs b/AbstractComputerDataModel/Enums/OrderStatus.cs
new file mode 100644
index 0000000..4e6f746
--- /dev/null
+++ b/AbstractComputerDataModel/Enums/OrderStatus.cs
@@ -0,0 +1,11 @@
+namespace ComputerShopDataModels.Enums
+{
+ public enum OrderStatus
+ {
+ Неизвестен = -1,
+ Принят = 0,
+ Выполняется = 1,
+ Готов = 2,
+ Выдан = 3
+ }
+}
\ No newline at end of file
diff --git a/AbstractComputerDataModel/Models/IComponentModel.cs b/AbstractComputerDataModel/Models/IComponentModel.cs
new file mode 100644
index 0000000..a04c804
--- /dev/null
+++ b/AbstractComputerDataModel/Models/IComponentModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopDataModels.Models
+{
+ public interface IComponentModel
+ {
+ string ComponentName { get; }
+ double Cost { get; }
+ }
+}
diff --git a/AbstractComputerDataModel/Models/IComputerModel.cs b/AbstractComputerDataModel/Models/IComputerModel.cs
new file mode 100644
index 0000000..9d24edd
--- /dev/null
+++ b/AbstractComputerDataModel/Models/IComputerModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopDataModels.Models
+{
+ public interface IComputerModel
+ {
+ string ComputerName { get; }
+ double Price { get; }
+ Dictionary ComputerComponents { get; }
+ }
+}
diff --git a/AbstractComputerDataModel/Models/IId.cs b/AbstractComputerDataModel/Models/IId.cs
new file mode 100644
index 0000000..4994ee2
--- /dev/null
+++ b/AbstractComputerDataModel/Models/IId.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopDataModels.Models
+{
+ public interface IId
+ {
+ string Id { get; }
+ }
+}
diff --git a/AbstractComputerDataModel/Models/IOrderModel.cs b/AbstractComputerDataModel/Models/IOrderModel.cs
new file mode 100644
index 0000000..0562eb4
--- /dev/null
+++ b/AbstractComputerDataModel/Models/IOrderModel.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ComputerShopDataModels.Enums;
+
+namespace ComputerShopDataModels.Models
+{
+ public interface IOrderModel
+ {
+ int ComputerId { get; }
+ string ComputerName { get; }
+ int Count { get; }
+ double Sum { get; }
+ OrderStatus Status { get; }
+ DateTime DateCreate { get; }
+ DateTime? DateImplement { get; }
+ }
+}
diff --git a/ComputerShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/ComputerShopBusinessLogic/BusinessLogics/ComponentLogic.cs
new file mode 100644
index 0000000..81c8908
--- /dev/null
+++ b/ComputerShopBusinessLogic/BusinessLogics/ComponentLogic.cs
@@ -0,0 +1,114 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.BusinessLogicsContracts;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.StoragesContracts;
+using ComputerShopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Logging;
+
+namespace ComputerShopBusinessLogic.BusinessLogics
+{
+ public class ComponentLogic : IComponentLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentStorage _componentStorage;
+ public ComponentLogic(ILogger logger, IComponentStorage componentStorage)
+ {
+ _logger = logger;
+ _componentStorage = componentStorage;
+ }
+ public List? 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("ReadElement 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 ArgumentNullException("Цена компонента должна быть больше 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("Компонент с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/ComputerShopBusinessLogic/BusinessLogics/ComputerLogic.cs b/ComputerShopBusinessLogic/BusinessLogics/ComputerLogic.cs
new file mode 100644
index 0000000..1303d52
--- /dev/null
+++ b/ComputerShopBusinessLogic/BusinessLogics/ComputerLogic.cs
@@ -0,0 +1,119 @@
+using ComputerShopContracts.BusinessLogicsContracts;
+using ComputerShopContracts.StoragesContracts;
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.ViewModels;
+using ComputerShopContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopBusinessLogic.BusinessLogics
+{
+ public class ComputerLogic : IComputerLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IComputerStorage _computerStorage;
+
+ public ComputerLogic(ILogger logger, IComputerStorage computerStorage)
+ {
+ _logger = logger;
+ _computerStorage = computerStorage;
+ }
+
+ public bool Create(ComputerBindingModel model)
+ {
+ CheckModel(model);
+ if (_computerStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(ComputerBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_computerStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public ComputerViewModel? ReadElement(ComputerSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. ComputerName:{ComputerName}.Id:{ Id}", model.ComputerName, model.Id);
+ var element = _computerStorage.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(ComputerSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. ComputerName:{ComputerName}.Id:{ Id}", model?.ComputerName, model?.Id);
+ var list = model == null ? _computerStorage.GetFullList() : _computerStorage.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(ComputerBindingModel model)
+ {
+ CheckModel(model);
+ if (_computerStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(ComputerBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ComputerName))
+ {
+ throw new ArgumentNullException("Нет названия компьютера", nameof(model.ComputerName));
+ }
+ if (model.Price <= 0)
+ {
+ throw new ArgumentNullException("Стоимость компьютера должна быть больше 0", nameof(model.Price));
+ }
+ _logger.LogInformation("Computer. ComputerName:{ComputerName}.Price:{ Price}. Id: { Id}", model.ComputerName, model.Price, model.Id);
+ var element = _computerStorage.GetElement(new ComputerSearchModel
+ {
+ ComputerName = model.ComputerName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Компьютер с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs
new file mode 100644
index 0000000..28770f5
--- /dev/null
+++ b/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -0,0 +1,117 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.StoragesContracts;
+using ComputerShopContracts.BusinessLogicsContracts;
+using ComputerShopContracts.ViewModels;
+using ComputerShopDataModels.Enums;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopBusinessLogic.BusinessLogics
+{
+ public class OrderLogic : IOrderLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderStorage _orderStorage;
+
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ {
+ _logger = logger;
+ _orderStorage = orderStorage;
+ }
+
+ public bool CreateOrder(OrderBindingModel model)
+ {
+ CheckModel(model);
+ 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)
+ {
+ CheckModel(model);
+ if (model.Status + 1 != newStatus)
+ {
+ _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
+ return false;
+ }
+ model.Status = newStatus;
+ if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
+ if (_orderStorage.Update(model) == null)
+ {
+ model.Status--;
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool TakeOrderInWork(OrderBindingModel model)
+ {
+ return StatusUpdate(model, OrderStatus.Выполняется);
+ }
+
+ public bool DeliveryOrder(OrderBindingModel model)
+ {
+ return StatusUpdate(model, OrderStatus.Готов);
+ }
+
+ public bool FinishOrder(OrderBindingModel model)
+ {
+ return StatusUpdate(model, OrderStatus.Выдан);
+ }
+
+ public List? ReadList(OrderSearchModel? model)
+ {
+ _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;
+ }
+
+ private void CheckModel(OrderBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.ComputerId < 0)
+ {
+ throw new ArgumentNullException("Некорректный идентификатор компьютера", nameof(model.ComputerId));
+ }
+ 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}. ComputerId: { ComputerId}", model.Id, model.Sum, model.ComputerId);
+ }
+ }
+}
diff --git a/ComputerShopBusinessLogic/ComputerShopBusinessLogic.csproj b/ComputerShopBusinessLogic/ComputerShopBusinessLogic.csproj
new file mode 100644
index 0000000..b63d171
--- /dev/null
+++ b/ComputerShopBusinessLogic/ComputerShopBusinessLogic.csproj
@@ -0,0 +1,17 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ComputerShopContracts/BindingModels/ComponentBindingModel.cs b/ComputerShopContracts/BindingModels/ComponentBindingModel.cs
new file mode 100644
index 0000000..2855d00
--- /dev/null
+++ b/ComputerShopContracts/BindingModels/ComponentBindingModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ComputerShopDataModels.Models;
+
+namespace ComputerShopContracts.BindingModels
+{
+ public class ComponentBindingModel : IComponentModel
+ {
+ public int Id { get; set; }
+ public string ComponentName { get; set; } = string.Empty;
+ public double Cost { get; set; }
+ }
+}
diff --git a/ComputerShopContracts/BindingModels/ComputerBindingModel.cs b/ComputerShopContracts/BindingModels/ComputerBindingModel.cs
new file mode 100644
index 0000000..766356a
--- /dev/null
+++ b/ComputerShopContracts/BindingModels/ComputerBindingModel.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ComputerShopDataModels.Models;
+
+namespace ComputerShopContracts.BindingModels
+{
+ public class ComputerBindingModel : IComputerModel
+ {
+ public int Id { get; set; }
+ public string ComputerName { get; set; } = string.Empty;
+ public double Price { get; set; }
+ public Dictionary ComputerComponents
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/ComputerShopContracts/BindingModels/OrderBindingModel.cs b/ComputerShopContracts/BindingModels/OrderBindingModel.cs
new file mode 100644
index 0000000..b5fbb54
--- /dev/null
+++ b/ComputerShopContracts/BindingModels/OrderBindingModel.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ComputerShopDataModels.Models;
+using ComputerShopDataModels.Enums;
+
+namespace ComputerShopContracts.BindingModels
+{
+ public class OrderBindingModel : IOrderModel
+ {
+ public int Id { get; set; }
+ public int ComputerId { get; set; }
+ public string ComputerName { get; set; } = string.Empty;
+ public int Count { get; set; }
+ public double Sum { get; set; }
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+ public DateTime DateCreate { get; set; } = DateTime.Now;
+ public DateTime? DateImplement { get; set; }
+ }
+}
diff --git a/ComputerShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/ComputerShopContracts/BusinessLogicsContracts/IComponentLogic.cs
new file mode 100644
index 0000000..c143e6f
--- /dev/null
+++ b/ComputerShopContracts/BusinessLogicsContracts/IComponentLogic.cs
@@ -0,0 +1,20 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.BusinessLogicsContracts
+{
+ public interface IComponentLogic
+ {
+ List? ReadList(ComponentSearchModel? model);
+ ComponentViewModel? ReadElement(ComponentSearchModel model);
+ bool Create(ComponentBindingModel model);
+ bool Update(ComponentBindingModel model);
+ bool Delete(ComponentBindingModel model);
+ }
+}
diff --git a/ComputerShopContracts/BusinessLogicsContracts/IComputerLogic.cs b/ComputerShopContracts/BusinessLogicsContracts/IComputerLogic.cs
new file mode 100644
index 0000000..fb85d39
--- /dev/null
+++ b/ComputerShopContracts/BusinessLogicsContracts/IComputerLogic.cs
@@ -0,0 +1,20 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.BusinessLogicsContracts
+{
+ public interface IComputerLogic
+ {
+ List? ReadList(ComputerSearchModel? model);
+ ComputerViewModel? ReadElement(ComputerSearchModel model);
+ bool Create(ComputerBindingModel model);
+ bool Update(ComputerBindingModel model);
+ bool Delete(ComputerBindingModel model);
+ }
+}
diff --git a/ComputerShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/ComputerShopContracts/BusinessLogicsContracts/IOrderLogic.cs
new file mode 100644
index 0000000..1826ec0
--- /dev/null
+++ b/ComputerShopContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -0,0 +1,20 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.BusinessLogicsContracts
+{
+ public interface IOrderLogic
+ {
+ List? ReadList(OrderSearchModel? model);
+ bool CreateOrder(OrderBindingModel model);
+ bool TakeOrderInWork(OrderBindingModel model);
+ bool FinishOrder(OrderBindingModel model);
+ bool DeliveryOrder(OrderBindingModel model);
+ }
+}
diff --git a/ComputerShopContracts/ComputerShopContracts.csproj b/ComputerShopContracts/ComputerShopContracts.csproj
new file mode 100644
index 0000000..f838e9c
--- /dev/null
+++ b/ComputerShopContracts/ComputerShopContracts.csproj
@@ -0,0 +1,17 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ComputerShopContracts/SearchModels/ComponentSearchModel.cs b/ComputerShopContracts/SearchModels/ComponentSearchModel.cs
new file mode 100644
index 0000000..78421a7
--- /dev/null
+++ b/ComputerShopContracts/SearchModels/ComponentSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.SearchModels
+{
+ public class ComponentSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ComponentName { get; set; }
+ }
+}
diff --git a/ComputerShopContracts/SearchModels/ComputerSearchModel.cs b/ComputerShopContracts/SearchModels/ComputerSearchModel.cs
new file mode 100644
index 0000000..6b6ef33
--- /dev/null
+++ b/ComputerShopContracts/SearchModels/ComputerSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.SearchModels
+{
+ public class ComputerSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ComputerName { get; set; }
+ }
+}
diff --git a/ComputerShopContracts/SearchModels/OrderSearchModel.cs b/ComputerShopContracts/SearchModels/OrderSearchModel.cs
new file mode 100644
index 0000000..3265f29
--- /dev/null
+++ b/ComputerShopContracts/SearchModels/OrderSearchModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.SearchModels
+{
+ public class OrderSearchModel
+ {
+ public int? Id { get; set; }
+ }
+}
diff --git a/ComputerShopContracts/StoragesContracts/IComponentStorage.cs b/ComputerShopContracts/StoragesContracts/IComponentStorage.cs
new file mode 100644
index 0000000..9bb4eea
--- /dev/null
+++ b/ComputerShopContracts/StoragesContracts/IComponentStorage.cs
@@ -0,0 +1,21 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.StoragesContracts
+{
+ public interface IComponentStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ComponentSearchModel model);
+ ComponentViewModel? GetElement(ComponentSearchModel model);
+ ComponentViewModel? Insert(ComponentBindingModel model);
+ ComponentViewModel? Update(ComponentBindingModel model);
+ ComponentViewModel? Delete(ComponentBindingModel model);
+ }
+}
diff --git a/ComputerShopContracts/StoragesContracts/IComputerStorage.cs b/ComputerShopContracts/StoragesContracts/IComputerStorage.cs
new file mode 100644
index 0000000..88a1587
--- /dev/null
+++ b/ComputerShopContracts/StoragesContracts/IComputerStorage.cs
@@ -0,0 +1,21 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.StoragesContracts
+{
+ public interface IComputerStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ComputerSearchModel model);
+ ComputerViewModel? GetElement(ComputerSearchModel model);
+ ComputerViewModel? Insert(ComputerBindingModel model);
+ ComputerViewModel? Update(ComputerBindingModel model);
+ ComputerViewModel? Delete(ComputerBindingModel model);
+ }
+}
diff --git a/ComputerShopContracts/StoragesContracts/IOrderStorage.cs b/ComputerShopContracts/StoragesContracts/IOrderStorage.cs
new file mode 100644
index 0000000..a8d822f
--- /dev/null
+++ b/ComputerShopContracts/StoragesContracts/IOrderStorage.cs
@@ -0,0 +1,21 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.StoragesContracts
+{
+ public interface IOrderStorage
+ {
+ List GetFullList();
+ List GetFilteredList(OrderSearchModel model);
+ OrderViewModel? GetElement(OrderSearchModel model);
+ OrderViewModel? Insert(OrderBindingModel model);
+ OrderViewModel? Update(OrderBindingModel model);
+ OrderViewModel? Delete(OrderBindingModel model);
+ }
+}
diff --git a/ComputerShopContracts/ViewModels/ComponentViewModel.cs b/ComputerShopContracts/ViewModels/ComponentViewModel.cs
new file mode 100644
index 0000000..661912e
--- /dev/null
+++ b/ComputerShopContracts/ViewModels/ComponentViewModel.cs
@@ -0,0 +1,19 @@
+using ComputerShopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.ViewModels
+{
+ public class ComponentViewModel : IComponentModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название компонента")]
+ public string ComponentName { get; set; } = string.Empty;
+ [DisplayName("Цена")]
+ public double Cost { get; set; }
+ }
+}
diff --git a/ComputerShopContracts/ViewModels/ComputerViewModel.cs b/ComputerShopContracts/ViewModels/ComputerViewModel.cs
new file mode 100644
index 0000000..8022b33
--- /dev/null
+++ b/ComputerShopContracts/ViewModels/ComputerViewModel.cs
@@ -0,0 +1,24 @@
+using ComputerShopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.ViewModels
+{
+ public class ComputerViewModel : IComputerModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название изделия")]
+ public string ComputerName { get; set; } = string.Empty;
+ [DisplayName("Цена")]
+ public double Price { get; set; }
+ public Dictionary ComputerComponents
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/ComputerShopContracts/ViewModels/OrderViewModel.cs b/ComputerShopContracts/ViewModels/OrderViewModel.cs
new file mode 100644
index 0000000..bd75392
--- /dev/null
+++ b/ComputerShopContracts/ViewModels/OrderViewModel.cs
@@ -0,0 +1,31 @@
+using ComputerShopDataModels.Enums;
+using ComputerShopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopContracts.ViewModels
+{
+ public class OrderViewModel : IOrderModel
+ {
+ public int ComputerId { get; set; }
+
+ [DisplayName("Номер")]
+ public int Id { get; set; }
+ [DisplayName("Компьютер")]
+ public string ComputerName { get; set; } = string.Empty;
+ [DisplayName("Количество")]
+ public int Count { get; set; }
+ [DisplayName("Сумма")]
+ public double Sum { get; set; }
+ [DisplayName("Статус")]
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+ [DisplayName("Дата создания")]
+ public DateTime DateCreate { get; set; } = DateTime.Now;
+ [DisplayName("Дата выполнения")]
+ public DateTime? DateImplement { get; set; }
+ }
+}
diff --git a/ComputerShopListImplement/ComputerShopListImplement.csproj b/ComputerShopListImplement/ComputerShopListImplement.csproj
new file mode 100644
index 0000000..5cf7fb2
--- /dev/null
+++ b/ComputerShopListImplement/ComputerShopListImplement.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/ComputerShopListImplement/Implements/ComponentStorage.cs b/ComputerShopListImplement/Implements/ComponentStorage.cs
new file mode 100644
index 0000000..43d3775
--- /dev/null
+++ b/ComputerShopListImplement/Implements/ComponentStorage.cs
@@ -0,0 +1,108 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.StoragesContracts;
+using ComputerShopContracts.ViewModels;
+using ComputerShopListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopListImplement.Implements
+{
+ public class ComponentStorage : IComponentStorage
+ {
+ private readonly DataListSingleton _source;
+ public ComponentStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var component in _source.Components)
+ {
+ result.Add(component.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(ComponentSearchModel
+ model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ return result;
+ }
+ foreach (var component in _source.Components)
+ {
+ if (component.ComponentName.Contains(model.ComponentName))
+ {
+ result.Add(component.GetViewModel);
+ }
+ }
+ return result;
+ }
+ public ComponentViewModel? GetElement(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var component in _source.Components)
+ {
+ if ((!string.IsNullOrEmpty(model.ComponentName) &&
+ component.ComponentName == model.ComponentName) ||
+ (model.Id.HasValue && component.Id == model.Id))
+ {
+ return component.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComponentViewModel? Insert(ComponentBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var component in _source.Components)
+ {
+ if (model.Id <= component.Id)
+ {
+ model.Id = component.Id + 1;
+ }
+ }
+ var newComponent = Component.Create(model);
+ if (newComponent == null)
+ {
+ return null;
+ }
+ _source.Components.Add(newComponent);
+ return newComponent.GetViewModel;
+ }
+ public ComponentViewModel? Update(ComponentBindingModel model)
+ {
+ foreach (var component in _source.Components)
+ {
+ if (component.Id == model.Id)
+ {
+ component.Update(model);
+ return component.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComponentViewModel? Delete(ComponentBindingModel model)
+ {
+ for (int i = 0; i < _source.Components.Count; ++i)
+ {
+ if (_source.Components[i].Id == model.Id)
+ {
+ var element = _source.Components[i];
+ _source.Components.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/ComputerShopListImplement/Implements/ComputerStorage.cs b/ComputerShopListImplement/Implements/ComputerStorage.cs
new file mode 100644
index 0000000..981fa41
--- /dev/null
+++ b/ComputerShopListImplement/Implements/ComputerStorage.cs
@@ -0,0 +1,111 @@
+using ComputerShopContracts.StoragesContracts;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.ViewModels;
+using ComputerShopContracts.BindingModels;
+using ComputerShopListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection.Metadata;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopListImplement.Implements
+{
+ public class ComputerStorage : IComputerStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public ComputerStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public ComputerViewModel? GetElement(ComputerSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComputerName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var computer in _source.Computers)
+ {
+ if ((!string.IsNullOrEmpty(model.ComputerName) && computer.ComputerName == model.ComputerName) || (model.Id.HasValue && computer.Id == model.Id))
+ {
+ return computer.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public List GetFilteredList(ComputerSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.ComputerName))
+ {
+ return result;
+ }
+ foreach (var computer in _source.Computers)
+ {
+ if (computer.ComputerName.Contains(model.ComputerName))
+ {
+ result.Add(computer.GetViewModel);
+ }
+ }
+ return result;
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var computer in _source.Computers)
+ {
+ result.Add(computer.GetViewModel);
+ }
+ return result;
+ }
+
+ public ComputerViewModel? Insert(ComputerBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var computer in _source.Computers)
+ {
+ if (model.Id <= computer.Id)
+ {
+ model.Id = computer.Id + 1;
+ }
+ }
+ var newComp = Computer.Create(model);
+ if (newComp == null)
+ {
+ return null;
+ }
+ _source.Computers.Add(newComp);
+ return newComp.GetViewModel;
+ }
+
+ public ComputerViewModel? Update(ComputerBindingModel model)
+ {
+ foreach (var computer in _source.Computers)
+ {
+ if (computer.Id == model.Id)
+ {
+ computer.Update(model);
+ return computer.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComputerViewModel? Delete(ComputerBindingModel model)
+ {
+ for (int i = 0; i < _source.Computers.Count; ++i)
+ {
+ if (_source.Computers[i].Id == model.Id)
+ {
+ var element = _source.Computers[i];
+ _source.Computers.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/ComputerShopListImplement/Implements/OrderStorage.cs b/ComputerShopListImplement/Implements/OrderStorage.cs
new file mode 100644
index 0000000..db5d2c4
--- /dev/null
+++ b/ComputerShopListImplement/Implements/OrderStorage.cs
@@ -0,0 +1,111 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.SearchModels;
+using ComputerShopContracts.StoragesContracts;
+using ComputerShopContracts.ViewModels;
+using ComputerShopListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopListImplement.Implements
+{
+ public class OrderStorage : IOrderStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public OrderStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id.HasValue && order.Id == model.Id)
+ {
+ return order.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ var result = new List();
+ if (!model.Id.HasValue)
+ {
+ return result;
+ }
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ result.Add(order.GetViewModel);
+ }
+ }
+ return result;
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var order in _source.Orders)
+ {
+ result.Add(order.GetViewModel);
+ }
+ return result;
+ }
+
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id <= order.Id)
+ {
+ model.Id = order.Id + 1;
+ }
+ }
+ var newOrder = Order.Create(model);
+ if (newOrder == null)
+ {
+ return null;
+ }
+ _source.Orders.Add(newOrder);
+ return newOrder.GetViewModel;
+ }
+
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ order.Update(model);
+ return order.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ for (int i = 0; i < _source.Orders.Count; ++i)
+ {
+ if (_source.Orders[i].Id == model.Id)
+ {
+ var element = _source.Orders[i];
+ _source.Orders.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/ComputerShopListImplement/Models/Component.cs b/ComputerShopListImplement/Models/Component.cs
new file mode 100644
index 0000000..26058e4
--- /dev/null
+++ b/ComputerShopListImplement/Models/Component.cs
@@ -0,0 +1,47 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.ViewModels;
+using ComputerShopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopListImplement.Models
+{
+ public class Component : IComponentModel
+ {
+ public int Id { get; private 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 void Update(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComponentName = model.ComponentName;
+ Cost = model.Cost;
+ }
+ public ComponentViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ComponentName = ComponentName,
+ Cost = Cost
+ };
+ }
+}
diff --git a/ComputerShopListImplement/Models/Computer.cs b/ComputerShopListImplement/Models/Computer.cs
new file mode 100644
index 0000000..3b788da
--- /dev/null
+++ b/ComputerShopListImplement/Models/Computer.cs
@@ -0,0 +1,54 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.ViewModels;
+using ComputerShopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopListImplement.Models
+{
+ public class Computer : IComputerModel
+ {
+ public int Id { get; private set; }
+ public string ComputerName { get; private set; } = string.Empty;
+ public double Price { get; private set; }
+ public Dictionary ComputerComponents
+ {
+ get;
+ private set;
+ } = new Dictionary();
+ public static Computer? Create(ComputerBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Computer()
+ {
+ Id = model.Id,
+ ComputerName = model.ComputerName,
+ Price = model.Price,
+ ComputerComponents = model.ComputerComponents
+ };
+ }
+ public void Update(ComputerBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComputerName = model.ComputerName;
+ Price = model.Price;
+ ComputerComponents = model.ComputerComponents;
+ }
+ public ComputerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ComputerName = ComputerName,
+ Price = Price,
+ ComputerComponents = ComputerComponents
+ };
+ }
+}
diff --git a/ComputerShopListImplement/Models/DataListSingleton.cs b/ComputerShopListImplement/Models/DataListSingleton.cs
new file mode 100644
index 0000000..e71b814
--- /dev/null
+++ b/ComputerShopListImplement/Models/DataListSingleton.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopListImplement.Models
+{
+ public class DataListSingleton
+ {
+ private static DataListSingleton? _instance;
+ public List Components { get; set; }
+ public List Orders { get; set; }
+ public List Computers { get; set; }
+ private DataListSingleton()
+ {
+ Components = new List();
+ Orders = new List();
+ Computers = new List();
+ }
+ public static DataListSingleton GetInstance()
+ {
+ if (_instance == null)
+ {
+ _instance = new DataListSingleton();
+ }
+ return _instance;
+ }
+ }
+}
diff --git a/ComputerShopListImplement/Models/Order.cs b/ComputerShopListImplement/Models/Order.cs
new file mode 100644
index 0000000..346f79d
--- /dev/null
+++ b/ComputerShopListImplement/Models/Order.cs
@@ -0,0 +1,78 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.ViewModels;
+using ComputerShopDataModels.Enums;
+using ComputerShopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ComputerShopListImplement.Models
+{
+ public class Order : IOrderModel
+ {
+ public int ComputerId { get; private set; }
+
+ public string ComputerName { get; private set; } = string.Empty;
+
+ public int Count { get; private set; }
+
+ public double Sum { get; private set; }
+
+ public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+
+ public DateTime DateCreate { get; private set; } = DateTime.Now;
+
+ public DateTime? DateImplement { get; private set; }
+
+ public int Id { get; private set; }
+
+ public static Order? Create(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Order
+ {
+ ComputerId = model.ComputerId,
+ ComputerName = model.ComputerName,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement,
+ Id = model.Id,
+ };
+ }
+
+ public void Update(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComputerId = model.ComputerId;
+ ComputerName = model.ComputerName;
+ Count = model.Count;
+ Sum = model.Sum;
+ Status = model.Status;
+ DateCreate = model.DateCreate;
+ DateImplement = model.DateImplement;
+ Id = model.Id;
+ }
+
+ public OrderViewModel GetViewModel => new()
+ {
+ ComputerId = ComputerId,
+ ComputerName = ComputerName,
+ Count = Count,
+ Sum = Sum,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement,
+ Id = Id,
+ Status = Status,
+ };
+ }
+}
diff --git a/ComputersShop/ComputersShop.csproj b/ComputersShop/ComputersShop.csproj
index b57c89e..30b2ceb 100644
--- a/ComputersShop/ComputersShop.csproj
+++ b/ComputersShop/ComputersShop.csproj
@@ -8,4 +8,16 @@
enable
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ComputersShop/ComputersShop.sln b/ComputersShop/ComputersShop.sln
index 80ed8e2..1bb85c8 100644
--- a/ComputersShop/ComputersShop.sln
+++ b/ComputersShop/ComputersShop.sln
@@ -5,6 +5,14 @@ VisualStudioVersion = 17.3.32819.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShop", "ComputersShop.csproj", "{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopDataModels", "..\AbstractComputerDataModel\ComputerShopDataModels.csproj", "{07BF1453-7129-45C4-AB54-AFC38F1E579D}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopContracts", "..\ComputerShopContracts\ComputerShopContracts.csproj", "{4684F24F-29DC-496C-803F-0877E5100939}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopBusinessLogic", "..\ComputerShopBusinessLogic\ComputerShopBusinessLogic.csproj", "{8A6D08BB-449A-4C35-81CA-F82B6293D241}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopListImplement", "..\ComputerShopListImplement\ComputerShopListImplement.csproj", "{D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +23,22 @@ Global
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Release|Any CPU.Build.0 = Release|Any CPU
+ {07BF1453-7129-45C4-AB54-AFC38F1E579D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {07BF1453-7129-45C4-AB54-AFC38F1E579D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {07BF1453-7129-45C4-AB54-AFC38F1E579D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {07BF1453-7129-45C4-AB54-AFC38F1E579D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4684F24F-29DC-496C-803F-0877E5100939}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4684F24F-29DC-496C-803F-0877E5100939}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4684F24F-29DC-496C-803F-0877E5100939}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4684F24F-29DC-496C-803F-0877E5100939}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8A6D08BB-449A-4C35-81CA-F82B6293D241}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8A6D08BB-449A-4C35-81CA-F82B6293D241}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8A6D08BB-449A-4C35-81CA-F82B6293D241}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8A6D08BB-449A-4C35-81CA-F82B6293D241}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/ComputersShop/Form1.Designer.cs b/ComputersShop/Form1.Designer.cs
deleted file mode 100644
index 8127802..0000000
--- a/ComputersShop/Form1.Designer.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-namespace ComputersShop
-{
- partial class Form1
- {
- ///
- /// 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.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Form1";
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/ComputersShop/Form1.cs b/ComputersShop/Form1.cs
deleted file mode 100644
index 85dadf8..0000000
--- a/ComputersShop/Form1.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace ComputersShop
-{
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- }
-}
\ No newline at end of file
diff --git a/ComputersShop/Form1.resx b/ComputersShop/Form1.resx
deleted file mode 100644
index 1af7de1..0000000
--- a/ComputersShop/Form1.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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/ComputersShop/FormComponent.Designer.cs b/ComputersShop/FormComponent.Designer.cs
new file mode 100644
index 0000000..3ffc802
--- /dev/null
+++ b/ComputersShop/FormComponent.Designer.cs
@@ -0,0 +1,118 @@
+namespace ComputersShop
+{
+ partial class FormComponent
+ {
+ ///
+ /// 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.labelName = new System.Windows.Forms.Label();
+ this.labelPrice = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxCost = new System.Windows.Forms.TextBox();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(12, 25);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(62, 15);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Название:";
+ //
+ // labelPrice
+ //
+ this.labelPrice.AutoSize = true;
+ this.labelPrice.Location = new System.Drawing.Point(12, 63);
+ this.labelPrice.Name = "labelPrice";
+ this.labelPrice.Size = new System.Drawing.Size(38, 15);
+ this.labelPrice.TabIndex = 1;
+ this.labelPrice.Text = "Цена:";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(96, 22);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(238, 23);
+ this.textBoxName.TabIndex = 2;
+ //
+ // textBoxCost
+ //
+ this.textBoxCost.Location = new System.Drawing.Point(96, 60);
+ this.textBoxCost.Name = "textBoxCost";
+ this.textBoxCost.Size = new System.Drawing.Size(238, 23);
+ this.textBoxCost.TabIndex = 3;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(191, 96);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(97, 23);
+ this.buttonSave.TabIndex = 4;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(303, 96);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(97, 23);
+ this.buttonCancel.TabIndex = 5;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormComponent
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(412, 131);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCost);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelPrice);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormComponent";
+ this.Text = "FormComponent";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelPrice;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/ComputersShop/FormComponent.cs b/ComputersShop/FormComponent.cs
new file mode 100644
index 0000000..ac474f5
--- /dev/null
+++ b/ComputersShop/FormComponent.cs
@@ -0,0 +1,96 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.BusinessLogicsContracts;
+using ComputerShopContracts.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 ComputersShop
+{
+ public partial class FormComponent : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentLogic _logic;
+ private int? _id;
+ public int Id { set { _id = value; } }
+ public FormComponent(ILogger logger, IComponentLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormComponent_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation("Получение компонента");
+ var view = _logic.ReadElement(new ComponentSearchModel
+ {
+ Id =
+ _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.ComponentName;
+ textBoxCost.Text = view.Cost.ToString();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения компонента");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение компонента");
+ try
+ {
+ var model = new ComponentBindingModel
+ {
+ Id = _id ?? 0,
+ ComponentName = textBoxName.Text,
+ Cost = Convert.ToDouble(textBoxCost.Text)
+ };
+ 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();
+ }
+
+ }
+}
diff --git a/ComputersShop/FormComponent.resx b/ComputersShop/FormComponent.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/ComputersShop/FormComponent.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ComputersShop/FormComponents.Designer.cs b/ComputersShop/FormComponents.Designer.cs
new file mode 100644
index 0000000..1f4465f
--- /dev/null
+++ b/ComputersShop/FormComponents.Designer.cs
@@ -0,0 +1,115 @@
+namespace ComputersShop
+{
+ partial class FormComponents
+ {
+ ///
+ /// 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.buttonAdd = new System.Windows.Forms.Button();
+ this.buttonEdit = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonRef = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
+ this.dataGridView.Location = new System.Drawing.Point(0, 0);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(590, 450);
+ this.dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(641, 12);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(114, 37);
+ this.buttonAdd.TabIndex = 1;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // buttonEdit
+ //
+ this.buttonEdit.Location = new System.Drawing.Point(641, 55);
+ this.buttonEdit.Name = "buttonEdit";
+ this.buttonEdit.Size = new System.Drawing.Size(114, 37);
+ this.buttonEdit.TabIndex = 2;
+ this.buttonEdit.Text = "Изменить";
+ this.buttonEdit.UseVisualStyleBackColor = true;
+ this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(641, 98);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(114, 37);
+ this.buttonDelete.TabIndex = 3;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(641, 141);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(114, 37);
+ this.buttonRef.TabIndex = 4;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // FormComponents
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.buttonEdit);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormComponents";
+ this.Text = "Form1";
+ this.Load += new System.EventHandler(this.FormComponents_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonEdit;
+ private Button buttonDelete;
+ private Button buttonRef;
+ }
+}
\ No newline at end of file
diff --git a/ComputersShop/FormComponents.cs b/ComputersShop/FormComponents.cs
new file mode 100644
index 0000000..cbb372e
--- /dev/null
+++ b/ComputersShop/FormComponents.cs
@@ -0,0 +1,105 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace ComputersShop
+{
+ public partial class FormComponents : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentLogic _logic;
+ public FormComponents(ILogger logger, IComponentLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormComponents_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["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation(" ");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, " ");
+ MessageBox.Show(ex.Message, "", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
+ if (service is FormComponent form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
+ if (service is FormComponent form)
+ {
+ form.Id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+ private void ButtonDel_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 ComponentBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception(" . .");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, " ");
+ MessageBox.Show(ex.Message, "",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ComputersShop/FormComponents.resx b/ComputersShop/FormComponents.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/ComputersShop/FormComponents.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ComputersShop/FormComputer.Designer.cs b/ComputersShop/FormComputer.Designer.cs
new file mode 100644
index 0000000..f18e685
--- /dev/null
+++ b/ComputersShop/FormComputer.Designer.cs
@@ -0,0 +1,227 @@
+namespace ComputersShop
+{
+ partial class FormComputer
+ {
+ ///
+ /// 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.labelName = new System.Windows.Forms.Label();
+ this.labelCost = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxCost = new System.Windows.Forms.TextBox();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ComponentId = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ComponentName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ComponentAmount = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.groupBoxComponents = new System.Windows.Forms.GroupBox();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonEdit = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.groupBoxComponents.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(12, 18);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(62, 15);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Название:";
+ //
+ // labelCost
+ //
+ this.labelCost.AutoSize = true;
+ this.labelCost.Location = new System.Drawing.Point(12, 49);
+ this.labelCost.Name = "labelCost";
+ this.labelCost.Size = new System.Drawing.Size(70, 15);
+ this.labelCost.TabIndex = 1;
+ this.labelCost.Text = "Стоимость:";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(88, 15);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(306, 23);
+ this.textBoxName.TabIndex = 2;
+ //
+ // textBoxCost
+ //
+ this.textBoxCost.Location = new System.Drawing.Point(88, 49);
+ this.textBoxCost.Name = "textBoxCost";
+ this.textBoxCost.Size = new System.Drawing.Size(164, 23);
+ this.textBoxCost.TabIndex = 3;
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ComponentId,
+ this.ComponentName,
+ this.ComponentAmount});
+ this.dataGridView.Location = new System.Drawing.Point(6, 22);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(575, 349);
+ this.dataGridView.TabIndex = 4;
+ //
+ // ComponentId
+ //
+ this.ComponentId.HeaderText = "Id";
+ this.ComponentId.Name = "ComponentId";
+ this.ComponentId.Visible = false;
+ //
+ // ComponentName
+ //
+ this.ComponentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.ComponentName.HeaderText = "Название";
+ this.ComponentName.Name = "ComponentName";
+ //
+ // ComponentAmount
+ //
+ this.ComponentAmount.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
+ this.ComponentAmount.HeaderText = "Количество";
+ this.ComponentAmount.MinimumWidth = 100;
+ this.ComponentAmount.Name = "ComponentAmount";
+ //
+ // groupBoxComponents
+ //
+ this.groupBoxComponents.Controls.Add(this.buttonRef);
+ this.groupBoxComponents.Controls.Add(this.buttonDelete);
+ this.groupBoxComponents.Controls.Add(this.buttonEdit);
+ this.groupBoxComponents.Controls.Add(this.buttonAdd);
+ this.groupBoxComponents.Controls.Add(this.dataGridView);
+ this.groupBoxComponents.Location = new System.Drawing.Point(12, 91);
+ this.groupBoxComponents.Name = "groupBoxComponents";
+ this.groupBoxComponents.Size = new System.Drawing.Size(750, 377);
+ this.groupBoxComponents.TabIndex = 5;
+ this.groupBoxComponents.TabStop = false;
+ this.groupBoxComponents.Text = "Компоненты";
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(587, 172);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(157, 44);
+ this.buttonRef.TabIndex = 8;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(587, 122);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(157, 44);
+ this.buttonDelete.TabIndex = 7;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonEdit
+ //
+ this.buttonEdit.Location = new System.Drawing.Point(587, 72);
+ this.buttonEdit.Name = "buttonEdit";
+ this.buttonEdit.Size = new System.Drawing.Size(157, 44);
+ this.buttonEdit.TabIndex = 6;
+ this.buttonEdit.Text = "Изменить";
+ this.buttonEdit.UseVisualStyleBackColor = true;
+ this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(587, 22);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(157, 44);
+ this.buttonAdd.TabIndex = 5;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(617, 477);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(123, 29);
+ this.buttonCancel.TabIndex = 6;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(470, 477);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(123, 29);
+ this.buttonSave.TabIndex = 7;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.MouseCaptureChanged += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // FormComputer
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(774, 518);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.groupBoxComponents);
+ this.Controls.Add(this.textBoxCost);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelCost);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormComputer";
+ this.Text = "FormComputer";
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.groupBoxComponents.ResumeLayout(false);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelCost;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn ComponentId;
+ private DataGridViewTextBoxColumn ComponentName;
+ private DataGridViewTextBoxColumn ComponentAmount;
+ private GroupBox groupBoxComponents;
+ private Button buttonRef;
+ private Button buttonDelete;
+ private Button buttonEdit;
+ private Button buttonAdd;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/ComputersShop/FormComputer.cs b/ComputersShop/FormComputer.cs
new file mode 100644
index 0000000..775269c
--- /dev/null
+++ b/ComputersShop/FormComputer.cs
@@ -0,0 +1,209 @@
+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;
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.BusinessLogicsContracts;
+using ComputerShopContracts.SearchModels;
+using ComputerShopDataModels.Models;
+using Microsoft.Extensions.Logging;
+
+
+namespace ComputersShop
+{
+ public partial class FormComputer : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComputerLogic _logic;
+ private int? _id;
+ private Dictionary _productComponents;
+ public int Id { set { _id = value; } }
+ public FormComputer(ILogger logger, IComputerLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _productComponents = new Dictionary();
+ }
+ private void FormProduct_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка изделия");
+ try
+ {
+ var view = _logic.ReadElement(new ComputerSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.ComputerName;
+ textBoxCost.Text = view.Price.ToString();
+ _productComponents = view.ComputerComponents ?? new Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка компонент изделия");
+ try
+ {
+ if (_productComponents != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var pc in _productComponents)
+ {
+ dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
+ }
+ textBoxCost.Text = CalcPrice().ToString();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки компонент изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComputerComponent));
+ if (service is FormComputerComponent form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
+ if (_productComponents.ContainsKey(form.Id))
+ {
+ _productComponents[form.Id] = (form.ComponentModel, form.Count);
+ }
+ else
+ {
+ _productComponents.Add(form.Id, (form.ComponentModel, form.Count));
+ }
+ LoadData();
+ }
+ }
+ }
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service =
+ Program.ServiceProvider?.GetService(typeof(FormComputerComponent));
+ if (service is FormComputerComponent form)
+ {
+ int id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _productComponents[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
+ _productComponents[form.Id] = (form.ComponentModel, form.Count);
+ LoadData();
+ }
+ }
+ }
+ }
+ private void ButtonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ try
+ {
+ _logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value);_productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ LoadData();
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(textBoxCost.Text))
+ {
+ MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (_productComponents == null || _productComponents.Count == 0)
+ {
+ MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение изделия");
+ try
+ {
+ var model = new ComputerBindingModel
+ {
+ Id = _id ?? 0,
+ ComputerName = textBoxName.Text,
+ Price = Convert.ToDouble(textBoxCost.Text),
+ ComputerComponents = _productComponents
+ };
+ 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 double CalcPrice()
+ {
+ double price = 0;
+ foreach (var elem in _productComponents)
+ {
+ price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
+ }
+ return Math.Round(price * 1.1, 2);
+ }
+ }
+}
diff --git a/ComputersShop/FormComputer.resx b/ComputersShop/FormComputer.resx
new file mode 100644
index 0000000..e349ecb
--- /dev/null
+++ b/ComputersShop/FormComputer.resx
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/ComputersShop/FormComputerComponent.Designer.cs b/ComputersShop/FormComputerComponent.Designer.cs
new file mode 100644
index 0000000..1de2e0e
--- /dev/null
+++ b/ComputersShop/FormComputerComponent.Designer.cs
@@ -0,0 +1,120 @@
+namespace ComputersShop
+{
+ partial class FormComputerComponent
+ {
+ ///
+ /// 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.labelName = new System.Windows.Forms.Label();
+ this.labelAmount = new System.Windows.Forms.Label();
+ this.comboBoxComponent = new System.Windows.Forms.ComboBox();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(12, 28);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(72, 15);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Компонент:";
+ //
+ // labelAmount
+ //
+ this.labelAmount.AutoSize = true;
+ this.labelAmount.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.labelAmount.Location = new System.Drawing.Point(12, 74);
+ this.labelAmount.Name = "labelAmount";
+ this.labelAmount.Size = new System.Drawing.Size(75, 15);
+ this.labelAmount.TabIndex = 1;
+ this.labelAmount.Text = "Количество:";
+ //
+ // comboBoxComponent
+ //
+ this.comboBoxComponent.FormattingEnabled = true;
+ this.comboBoxComponent.Location = new System.Drawing.Point(93, 25);
+ this.comboBoxComponent.Name = "comboBoxComponent";
+ this.comboBoxComponent.Size = new System.Drawing.Size(195, 23);
+ this.comboBoxComponent.TabIndex = 2;
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(93, 74);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(195, 23);
+ this.textBoxCount.TabIndex = 3;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(272, 106);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 4;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(191, 106);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(75, 23);
+ this.buttonSave.TabIndex = 5;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // FormComputerComponent
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(359, 141);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxComponent);
+ this.Controls.Add(this.labelAmount);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormComputerComponent";
+ this.Text = "FormComputerComponent";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelAmount;
+ private ComboBox comboBoxComponent;
+ private TextBox textBoxCount;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/ComputersShop/FormComputerComponent.cs b/ComputersShop/FormComputerComponent.cs
new file mode 100644
index 0000000..0a1b09b
--- /dev/null
+++ b/ComputersShop/FormComputerComponent.cs
@@ -0,0 +1,88 @@
+using ComputerShopContracts.BusinessLogicsContracts;
+using ComputerShopContracts.ViewModels;
+using ComputerShopDataModels.Models;
+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 ComputersShop
+{
+ public partial class FormComputerComponent : Form
+ {
+ private readonly List? _list;
+ public int Id
+ {
+ get
+ {
+ return Convert.ToInt32(comboBoxComponent.SelectedValue);
+ }
+ set
+ {
+ comboBoxComponent.SelectedValue = value;
+ }
+ }
+
+ public IComponentModel? ComponentModel
+ {
+ get
+ {
+ if (_list == null)
+ {
+ return null;
+ }
+ foreach (var elem in _list)
+ {
+ if (elem.Id == Id)
+ {
+ return elem;
+ }
+ }
+ return null;
+ }
+ }
+
+ public int Count
+ {
+ get { return Convert.ToInt32(textBoxCount.Text); }
+ set { textBoxCount.Text = value.ToString(); }
+ }
+ public FormComputerComponent(IComponentLogic logic)
+ {
+ InitializeComponent();
+ _list = logic.ReadList(null);
+ if (_list != null)
+ {
+ comboBoxComponent.DisplayMember = "ComponentName";
+ comboBoxComponent.ValueMember = "Id";
+ comboBoxComponent.DataSource = _list;
+ comboBoxComponent.SelectedItem = null;
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxComponent.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/ComputersShop/FormComputerComponent.resx b/ComputersShop/FormComputerComponent.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/ComputersShop/FormComputerComponent.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ComputersShop/FormComputers.Designer.cs b/ComputersShop/FormComputers.Designer.cs
new file mode 100644
index 0000000..cf96b38
--- /dev/null
+++ b/ComputersShop/FormComputers.Designer.cs
@@ -0,0 +1,114 @@
+namespace ComputersShop
+{
+ partial class FormComputers
+ {
+ ///
+ /// 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.buttonAdd = new System.Windows.Forms.Button();
+ this.buttonEdit = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonUpdate = 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(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(439, 307);
+ this.dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(473, 12);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(149, 30);
+ this.buttonAdd.TabIndex = 1;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
+ //
+ // buttonEdit
+ //
+ this.buttonEdit.Location = new System.Drawing.Point(473, 48);
+ this.buttonEdit.Name = "buttonEdit";
+ this.buttonEdit.Size = new System.Drawing.Size(149, 30);
+ this.buttonEdit.TabIndex = 2;
+ this.buttonEdit.Text = "Изменить";
+ this.buttonEdit.UseVisualStyleBackColor = true;
+ this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(473, 84);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(149, 30);
+ this.buttonDelete.TabIndex = 3;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(473, 289);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(149, 30);
+ this.buttonUpdate.TabIndex = 4;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
+ //
+ // FormComputers
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(634, 331);
+ this.Controls.Add(this.buttonUpdate);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.buttonEdit);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormComputers";
+ this.Text = "FormComputers";
+ this.Load += new System.EventHandler(this.FormComputers_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonEdit;
+ private Button buttonDelete;
+ private Button buttonUpdate;
+ }
+}
\ No newline at end of file
diff --git a/ComputersShop/FormComputers.cs b/ComputersShop/FormComputers.cs
new file mode 100644
index 0000000..e550f0a
--- /dev/null
+++ b/ComputersShop/FormComputers.cs
@@ -0,0 +1,113 @@
+using Microsoft.Extensions.Logging;
+using ComputerShopContracts.BusinessLogicsContracts;
+using ComputerShopContracts.BindingModels;
+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 ComputersShop
+{
+ public partial class FormComputers : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComputerLogic _logic;
+ public FormComputers(ILogger logger, IComputerLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormComputers_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["ComputerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ComputerComponents"].Visible = false;
+ }
+ _logger.LogInformation("Загрузка компьютеров");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки компьютеров");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComputer));
+ if (service is FormComputer form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonEdit_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComputer));
+ if (service is FormComputer form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void buttonDelete_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 ComputerBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления компьютера");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void buttonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/ComputersShop/FormComputers.resx b/ComputersShop/FormComputers.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/ComputersShop/FormComputers.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ComputersShop/FormCreateOrder.Designer.cs b/ComputersShop/FormCreateOrder.Designer.cs
new file mode 100644
index 0000000..e19d281
--- /dev/null
+++ b/ComputersShop/FormCreateOrder.Designer.cs
@@ -0,0 +1,144 @@
+namespace ComputersShop
+{
+ partial class FormCreateOrder
+ {
+ ///
+ /// 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.labelComputerName = new System.Windows.Forms.Label();
+ this.labelAmount = new System.Windows.Forms.Label();
+ this.labelCost = new System.Windows.Forms.Label();
+ this.comboBoxComputer = new System.Windows.Forms.ComboBox();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.textBoxSum = new System.Windows.Forms.TextBox();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelComputerName
+ //
+ this.labelComputerName.AutoSize = true;
+ this.labelComputerName.Location = new System.Drawing.Point(24, 28);
+ this.labelComputerName.Name = "labelComputerName";
+ this.labelComputerName.Size = new System.Drawing.Size(56, 15);
+ this.labelComputerName.TabIndex = 0;
+ this.labelComputerName.Text = "Изделие:";
+ //
+ // labelAmount
+ //
+ this.labelAmount.AutoSize = true;
+ this.labelAmount.Location = new System.Drawing.Point(24, 71);
+ this.labelAmount.Name = "labelAmount";
+ this.labelAmount.Size = new System.Drawing.Size(75, 15);
+ this.labelAmount.TabIndex = 1;
+ this.labelAmount.Text = "Количество:";
+ //
+ // labelCost
+ //
+ this.labelCost.AutoSize = true;
+ this.labelCost.Location = new System.Drawing.Point(24, 111);
+ this.labelCost.Name = "labelCost";
+ this.labelCost.Size = new System.Drawing.Size(48, 15);
+ this.labelCost.TabIndex = 2;
+ this.labelCost.Text = "Сумма:";
+ //
+ // comboBoxComputer
+ //
+ this.comboBoxComputer.FormattingEnabled = true;
+ this.comboBoxComputer.Location = new System.Drawing.Point(102, 25);
+ this.comboBoxComputer.Name = "comboBoxComputer";
+ this.comboBoxComputer.Size = new System.Drawing.Size(249, 23);
+ this.comboBoxComputer.TabIndex = 3;
+ this.comboBoxComputer.SelectedIndexChanged += new System.EventHandler(this.ComboBoxProduct_SelectedIndexChanged);
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(105, 68);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(246, 23);
+ this.textBoxCount.TabIndex = 4;
+ this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
+ //
+ // textBoxSum
+ //
+ this.textBoxSum.Location = new System.Drawing.Point(105, 108);
+ this.textBoxSum.Name = "textBoxSum";
+ this.textBoxSum.Size = new System.Drawing.Size(246, 23);
+ this.textBoxSum.TabIndex = 5;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(274, 137);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 6;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(193, 137);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(75, 23);
+ this.buttonSave.TabIndex = 7;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // FormCreateOrder
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(361, 168);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.textBoxSum);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxComputer);
+ this.Controls.Add(this.labelCost);
+ this.Controls.Add(this.labelAmount);
+ this.Controls.Add(this.labelComputerName);
+ this.Name = "FormCreateOrder";
+ this.Text = "FormCreateOrder";
+ this.Load += new System.EventHandler(this.FormCreateOrder_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelComputerName;
+ private Label labelAmount;
+ private Label labelCost;
+ private ComboBox comboBoxComputer;
+ private TextBox textBoxCount;
+ private TextBox textBoxSum;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/ComputersShop/FormCreateOrder.cs b/ComputersShop/FormCreateOrder.cs
new file mode 100644
index 0000000..2e6bb32
--- /dev/null
+++ b/ComputersShop/FormCreateOrder.cs
@@ -0,0 +1,122 @@
+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;
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.BusinessLogicsContracts;
+using ComputerShopContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+
+namespace ComputersShop
+{
+ public partial class FormCreateOrder : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComputerLogic _logicC;
+ private readonly IOrderLogic _logicO;
+ public FormCreateOrder(ILogger logger, IComputerLogic logicC, IOrderLogic logicO)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicC = logicC;
+ _logicO = logicO;
+ }
+ private void FormCreateOrder_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка компьютеров для заказа");
+ try
+ {
+ var list = _logicC.ReadList(null);
+ if (list != null)
+ {
+ comboBoxComputer.DisplayMember = "ComputerName";
+ comboBoxComputer.ValueMember = "Id";
+ comboBoxComputer.DataSource = list;
+ comboBoxComputer.SelectedItem = null;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки списка компьютеров");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void CalcSum()
+ {
+ if (comboBoxComputer.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ try
+ {
+ int id = Convert.ToInt32(comboBoxComputer.SelectedValue);
+ var product = _logicC.ReadElement(new ComputerSearchModel
+ {
+ Id = id
+ });
+ int count = Convert.ToInt32(textBoxCount.Text);
+ textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
+ _logger.LogInformation("Расчет суммы заказа");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка расчета суммы заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void TextBoxCount_TextChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+ private void ComboBoxProduct_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxComputer.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Создание заказа");
+ try
+ {
+ var operationResult = _logicO.CreateOrder(new OrderBindingModel
+ {
+ ComputerId = Convert.ToInt32(comboBoxComputer.SelectedValue),
+ ComputerName = comboBoxComputer.Text,
+ Count = Convert.ToInt32(textBoxCount.Text),
+ Sum = Convert.ToDouble(textBoxSum.Text)
+ });
+ 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();
+ }
+ }
+}
diff --git a/ComputersShop/FormCreateOrder.resx b/ComputersShop/FormCreateOrder.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/ComputersShop/FormCreateOrder.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ComputersShop/FormMain.Designer.cs b/ComputersShop/FormMain.Designer.cs
new file mode 100644
index 0000000..89065ef
--- /dev/null
+++ b/ComputersShop/FormMain.Designer.cs
@@ -0,0 +1,174 @@
+namespace ComputersShop
+{
+ partial class FormMain
+ {
+ ///
+ /// 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.menuStrip1 = 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.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ButtonCreateOrder = new System.Windows.Forms.Button();
+ this.ButtonTakeOrderInWork = new System.Windows.Forms.Button();
+ this.ButtonOrderReady = new System.Windows.Forms.Button();
+ this.ButtonIssuedOrder = new System.Windows.Forms.Button();
+ this.ButtonRef = new System.Windows.Forms.Button();
+ this.menuStrip1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // menuStrip1
+ //
+ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.справочникиToolStripMenuItem});
+ this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip1.Name = "menuStrip1";
+ this.menuStrip1.Size = new System.Drawing.Size(1006, 24);
+ this.menuStrip1.TabIndex = 0;
+ this.menuStrip1.Text = "menuStrip1";
+ //
+ // справочникиToolStripMenuItem
+ //
+ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.компьютерыToolStripMenuItem,
+ this.компонентыToolStripMenuItem});
+ this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
+ this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
+ this.справочникиToolStripMenuItem.Text = "Справочники";
+ //
+ // компьютерыToolStripMenuItem
+ //
+ this.компьютерыToolStripMenuItem.Name = "компьютерыToolStripMenuItem";
+ this.компьютерыToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
+ this.компьютерыToolStripMenuItem.Text = "Компьютеры";
+ this.компьютерыToolStripMenuItem.Click += new System.EventHandler(this.КомпьютерыToolStripMenuItem_Click);
+ //
+ // компонентыToolStripMenuItem
+ //
+ this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
+ this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
+ this.компонентыToolStripMenuItem.Text = "Компоненты";
+ this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 27);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(739, 284);
+ this.dataGridView.TabIndex = 1;
+ //
+ // ButtonCreateOrder
+ //
+ this.ButtonCreateOrder.Location = new System.Drawing.Point(786, 40);
+ this.ButtonCreateOrder.Name = "ButtonCreateOrder";
+ this.ButtonCreateOrder.Size = new System.Drawing.Size(192, 23);
+ this.ButtonCreateOrder.TabIndex = 2;
+ this.ButtonCreateOrder.Text = "Создать заказ";
+ this.ButtonCreateOrder.UseVisualStyleBackColor = true;
+ this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
+ //
+ // ButtonTakeOrderInWork
+ //
+ this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(786, 69);
+ this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork";
+ this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(192, 23);
+ this.ButtonTakeOrderInWork.TabIndex = 3;
+ this.ButtonTakeOrderInWork.Text = "Отдать заказ на выполнение";
+ this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true;
+ this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
+ //
+ // ButtonOrderReady
+ //
+ this.ButtonOrderReady.Location = new System.Drawing.Point(786, 98);
+ this.ButtonOrderReady.Name = "ButtonOrderReady";
+ this.ButtonOrderReady.Size = new System.Drawing.Size(192, 23);
+ this.ButtonOrderReady.TabIndex = 4;
+ this.ButtonOrderReady.Text = "Заказ готов";
+ this.ButtonOrderReady.UseVisualStyleBackColor = true;
+ this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
+ //
+ // ButtonIssuedOrder
+ //
+ this.ButtonIssuedOrder.Location = new System.Drawing.Point(786, 127);
+ this.ButtonIssuedOrder.Name = "ButtonIssuedOrder";
+ this.ButtonIssuedOrder.Size = new System.Drawing.Size(192, 23);
+ this.ButtonIssuedOrder.TabIndex = 5;
+ this.ButtonIssuedOrder.Text = "Заказ выдан";
+ this.ButtonIssuedOrder.UseVisualStyleBackColor = true;
+ this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonOrderReady_Click);
+ //
+ // ButtonRef
+ //
+ this.ButtonRef.Location = new System.Drawing.Point(786, 288);
+ this.ButtonRef.Name = "ButtonRef";
+ this.ButtonRef.Size = new System.Drawing.Size(192, 23);
+ this.ButtonRef.TabIndex = 6;
+ this.ButtonRef.Text = "Обновить";
+ this.ButtonRef.UseVisualStyleBackColor = true;
+ this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // FormMain
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1006, 323);
+ this.Controls.Add(this.ButtonRef);
+ this.Controls.Add(this.ButtonIssuedOrder);
+ this.Controls.Add(this.ButtonOrderReady);
+ this.Controls.Add(this.ButtonTakeOrderInWork);
+ this.Controls.Add(this.ButtonCreateOrder);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.menuStrip1);
+ this.MainMenuStrip = this.menuStrip1;
+ this.Name = "FormMain";
+ this.Text = "FormMain";
+ this.Load += new System.EventHandler(this.FormMain_Load);
+ this.menuStrip1.ResumeLayout(false);
+ this.menuStrip1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private MenuStrip menuStrip1;
+ private ToolStripMenuItem справочникиToolStripMenuItem;
+ private ToolStripMenuItem компьютерыToolStripMenuItem;
+ private ToolStripMenuItem компонентыToolStripMenuItem;
+ private DataGridView dataGridView;
+ private Button ButtonCreateOrder;
+ private Button ButtonTakeOrderInWork;
+ private Button ButtonOrderReady;
+ private Button ButtonIssuedOrder;
+ private Button ButtonRef;
+ }
+}
\ No newline at end of file
diff --git a/ComputersShop/FormMain.cs b/ComputersShop/FormMain.cs
new file mode 100644
index 0000000..ed69259
--- /dev/null
+++ b/ComputersShop/FormMain.cs
@@ -0,0 +1,179 @@
+using ComputerShopContracts.BindingModels;
+using ComputerShopContracts.BusinessLogicsContracts;
+using ComputerShopDataModels.Enums;
+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 ComputersShop
+{
+ public partial class FormMain : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderLogic _orderLogic;
+ public FormMain(ILogger logger, IOrderLogic orderLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _orderLogic = orderLogic;
+ }
+
+ private void FormMain_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка заказов");
+ try
+ {
+ var list = _orderLogic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["ComputerId"].Visible = false;
+ }
+ _logger.LogInformation("Загрузка заказов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки заказов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs
+ e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
+ if (service is FormComponents form)
+ {
+ form.ShowDialog();
+ }
+ }
+ private void КомпьютерыToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComputers));
+ if (service is FormComputers form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void ButtonCreateOrder_Click(object sender, EventArgs e)
+ {
+ var service =
+ Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
+ if (service is FormCreateOrder form)
+ {
+ form.ShowDialog();
+ LoadData();
+ }
+ }
+ private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id);
+ try
+ {
+ var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel{
+ Id = id,
+ ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value),
+ ComputerName = dataGridView.SelectedRows[0].Cells["ComputerName"].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)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка передачи заказа в работу");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonOrderReady_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id);
+ try
+ {
+ var operationResult = _orderLogic.FinishOrder(new OrderBindingModel {
+ Id = id,
+ ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value),
+ ComputerName = dataGridView.SelectedRows[0].Cells["ComputerName"].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)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о готовности заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonIssuedOrder_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id);
+ try
+ {
+ var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel {
+ Id = id,
+ ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value),
+ ComputerName = dataGridView.SelectedRows[0].Cells["ComputerName"].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)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ _logger.LogInformation("Заказ No{id} выдан", id);
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о выдачи заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/ComputersShop/FormMain.resx b/ComputersShop/FormMain.resx
new file mode 100644
index 0000000..938108a
--- /dev/null
+++ b/ComputersShop/FormMain.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/ComputersShop/Program.cs b/ComputersShop/Program.cs
index 6394a0e..713a5f8 100644
--- a/ComputersShop/Program.cs
+++ b/ComputersShop/Program.cs
@@ -1,9 +1,19 @@
+using ComputerShopBusinessLogic.BusinessLogics;
+using ComputerShopContracts.BusinessLogicsContracts;
+using ComputerShopContracts.StoragesContracts;
+using ComputerShopListImplement.Implements;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+
namespace ComputersShop
{
internal static class Program
{
+ private static ServiceProvider? _serviceProvider;
+ public static ServiceProvider? ServiceProvider => _serviceProvider;
///
- /// The main entry point for the application.
+ /// The main entry point for the application.
///
[STAThread]
static void Main()
@@ -11,7 +21,32 @@ namespace ComputersShop
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new Form1());
+ var services = new ServiceCollection();
+ ConfigureServices(services);
+ _serviceProvider = services.BuildServiceProvider();
+ Application.Run(_serviceProvider.GetRequiredService());
}
+ private static void ConfigureServices(ServiceCollection services)
+ {
+ services.AddLogging(option =>
+ {
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddNLog("nlog.config");
+ });
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ }
+
}
}
\ No newline at end of file