Compare commits
8 Commits
main
...
LabWork02H
Author | SHA1 | Date | |
---|---|---|---|
76255378d1 | |||
74bffc351f | |||
b2f32aa6e4 | |||
8a7abdd88c | |||
7892937ffd | |||
be2156c59a | |||
7f0c80ff0c | |||
a5e8434111 |
13
AbstractComputerDataModel/ComputerShopDataModels.csproj
Normal file
13
AbstractComputerDataModel/ComputerShopDataModels.csproj
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
11
AbstractComputerDataModel/Enums/OrderStatus.cs
Normal file
11
AbstractComputerDataModel/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace ComputerShopDataModels.Enums
|
||||||
|
{
|
||||||
|
public enum OrderStatus
|
||||||
|
{
|
||||||
|
Неизвестен = -1,
|
||||||
|
Принят = 0,
|
||||||
|
Выполняется = 1,
|
||||||
|
Готов = 2,
|
||||||
|
Выдан = 3
|
||||||
|
}
|
||||||
|
}
|
14
AbstractComputerDataModel/Models/IComponentModel.cs
Normal file
14
AbstractComputerDataModel/Models/IComponentModel.cs
Normal file
@ -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 : IId
|
||||||
|
{
|
||||||
|
string ComponentName { get; }
|
||||||
|
double Cost { get; }
|
||||||
|
}
|
||||||
|
}
|
15
AbstractComputerDataModel/Models/IComputerModel.cs
Normal file
15
AbstractComputerDataModel/Models/IComputerModel.cs
Normal file
@ -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 : IId
|
||||||
|
{
|
||||||
|
string ComputerName { get; }
|
||||||
|
double Price { get; }
|
||||||
|
Dictionary<int, (IComponentModel, int)> ComputerComponents { get; }
|
||||||
|
}
|
||||||
|
}
|
13
AbstractComputerDataModel/Models/IId.cs
Normal file
13
AbstractComputerDataModel/Models/IId.cs
Normal file
@ -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
|
||||||
|
{
|
||||||
|
int Id { get; }
|
||||||
|
}
|
||||||
|
}
|
20
AbstractComputerDataModel/Models/IOrderModel.cs
Normal file
20
AbstractComputerDataModel/Models/IOrderModel.cs
Normal file
@ -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 : IId
|
||||||
|
{
|
||||||
|
int ComputerId { get; }
|
||||||
|
string ComputerName { get; }
|
||||||
|
int Count { get; }
|
||||||
|
double Sum { get; }
|
||||||
|
OrderStatus Status { get; }
|
||||||
|
DateTime DateCreate { get; }
|
||||||
|
DateTime? DateImplement { get; }
|
||||||
|
}
|
||||||
|
}
|
17
AbstractComputerDataModel/Models/IShopModel.cs
Normal file
17
AbstractComputerDataModel/Models/IShopModel.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IShopModel : IId
|
||||||
|
{
|
||||||
|
String Name { get; }
|
||||||
|
String Adress { get; }
|
||||||
|
DateTime OpeningDate { get; }
|
||||||
|
Dictionary<int, (IComputerModel, int)> ShopComputers { get; }
|
||||||
|
int MaxCountComputers { get; }
|
||||||
|
}
|
||||||
|
}
|
114
ComputerShopBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
114
ComputerShopBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
@ -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<ComponentLogic> logger, IComponentStorage componentStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_componentStorage = componentStorage;
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id);
|
||||||
|
var list = model == null ? _componentStorage.GetFullList() :
|
||||||
|
_componentStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? ReadElement(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id}", model.ComponentName, model.Id);
|
||||||
|
var element = _componentStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("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("Компонент с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
119
ComputerShopBusinessLogic/BusinessLogics/ComputerLogic.cs
Normal file
119
ComputerShopBusinessLogic/BusinessLogics/ComputerLogic.cs
Normal file
@ -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<ComputerLogic> 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<ComputerViewModel>? 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("Компьютер с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
200
ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
200
ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
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;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace ComputerShopBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class OrderLogic : IOrderLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
private readonly IShopStorage _shopStorage;
|
||||||
|
private readonly IShopLogic _shopLogic;
|
||||||
|
private readonly IComputerStorage _computerStorage;
|
||||||
|
|
||||||
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IComputerStorage computerStorage, IShopStorage shopStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_orderStorage = orderStorage;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
_computerStorage = computerStorage;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
if (newStatus == OrderStatus.Выдан)
|
||||||
|
{
|
||||||
|
var computer = _computerStorage.GetElement(new ComputerSearchModel() { Id = model.ComputerId });
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Computer not found.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (CheckThenSupplyMany(computer, model.Count) == false)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error.");
|
||||||
|
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 CheckThenSupplyMany(IComputerModel computer, int count)
|
||||||
|
{
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Check then supply operation error. Computer count < 0.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int freeSpace = 0;
|
||||||
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
|
{
|
||||||
|
freeSpace += shop.MaxCountComputers;
|
||||||
|
foreach (var doc in shop.ShopComputers)
|
||||||
|
{
|
||||||
|
freeSpace -= doc.Value.Item2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (freeSpace - count < 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Check then supply operation error. There's no place for new docs in shops.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
|
{
|
||||||
|
freeSpace = shop.MaxCountComputers;
|
||||||
|
foreach (var doc in shop.ShopComputers)
|
||||||
|
{
|
||||||
|
freeSpace -= doc.Value.Item2;
|
||||||
|
}
|
||||||
|
if (freeSpace == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (freeSpace - count >= 0)
|
||||||
|
{
|
||||||
|
if (_shopLogic.SupplyComputers(new() { Id = shop.Id }, computer, count)) count = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Supply error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (freeSpace - count < 0)
|
||||||
|
{
|
||||||
|
if (_shopLogic.SupplyComputers(new() { Id = shop.Id }, computer, freeSpace)) count -= freeSpace;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Supply error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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<OrderViewModel>? 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
190
ComputerShopBusinessLogic/BusinessLogics/ShopLogic.cs
Normal file
190
ComputerShopBusinessLogic/BusinessLogics/ShopLogic.cs
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.BusinessLogicsContracts;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StoragesContracts;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection.Metadata;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ShopLogic : IShopLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopStorage _shopStorage;
|
||||||
|
|
||||||
|
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. Shop Name:{0}.ID:{1}", model.Name, model.Id);
|
||||||
|
var element = _shopStorage.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<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. Shop Name:{0}.ID:{1} ", model?.Name, model?.Id);
|
||||||
|
|
||||||
|
var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||||
|
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SupplyComputers(ShopSearchModel model, IComputerModel computer, int count)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(computer));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Count of computers in supply myst be more than 0", nameof(count));
|
||||||
|
}
|
||||||
|
|
||||||
|
var shopElement = _shopStorage.GetElement(model);
|
||||||
|
if (shopElement == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Required shop element not found in storage");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
|
||||||
|
|
||||||
|
var countDocs = 0;
|
||||||
|
foreach (var doc in shopElement.ShopComputers)
|
||||||
|
{
|
||||||
|
countDocs += doc.Value.Item2;
|
||||||
|
}
|
||||||
|
if (shopElement.MaxCountComputers - countDocs >= count)
|
||||||
|
{
|
||||||
|
if (shopElement.ShopComputers.TryGetValue(computer.Id, out var sameComputer))
|
||||||
|
{
|
||||||
|
shopElement.ShopComputers[computer.Id] = (computer, sameComputer.Item2 + count);
|
||||||
|
_logger.LogInformation("Same computer found by supply. Added {0} of {1} in {2} shop", count, computer.ComputerName, shopElement.Name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shopElement.ShopComputers[computer.Id] = (computer, count);
|
||||||
|
_logger.LogInformation("New computer added by supply. Added {0} of {1} in {2} shop", count, computer.ComputerName, shopElement.Name);
|
||||||
|
}
|
||||||
|
_shopStorage.Update(new()
|
||||||
|
{
|
||||||
|
Id = shopElement.Id,
|
||||||
|
Name = shopElement.Name,
|
||||||
|
Adress = shopElement.Adress,
|
||||||
|
OpeningDate = shopElement.OpeningDate,
|
||||||
|
ShopComputers = shopElement.ShopComputers,
|
||||||
|
MaxCountComputers = shopElement.MaxCountComputers
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Required shop is overflowed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SellComputer(IComputerModel computer, int count)
|
||||||
|
{
|
||||||
|
;
|
||||||
|
return _shopStorage.SellComputer(computer, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_shopStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_shopStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
if (_shopStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Name))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name));
|
||||||
|
}
|
||||||
|
if (model.MaxCountComputers < 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Магазин с отрицательным количеством максимального количества компьютеров!");
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Shop. Name: {0}, Adress: {1}, ID: {2}", model.Name, model.Adress, model.Id);
|
||||||
|
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||||
|
{
|
||||||
|
Name = model.Name
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
ComputerShopBusinessLogic/ComputerShopBusinessLogic.csproj
Normal file
17
ComputerShopBusinessLogic/ComputerShopBusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ComputerShopContracts\ComputerShopContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
17
ComputerShopContracts/BindingModels/ComponentBindingModel.cs
Normal file
17
ComputerShopContracts/BindingModels/ComponentBindingModel.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
21
ComputerShopContracts/BindingModels/ComputerBindingModel.cs
Normal file
21
ComputerShopContracts/BindingModels/ComputerBindingModel.cs
Normal file
@ -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<int, (IComponentModel, int)> ComputerComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new();
|
||||||
|
}
|
||||||
|
}
|
22
ComputerShopContracts/BindingModels/OrderBindingModel.cs
Normal file
22
ComputerShopContracts/BindingModels/OrderBindingModel.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
23
ComputerShopContracts/BindingModels/ShopBindingModel.cs
Normal file
23
ComputerShopContracts/BindingModels/ShopBindingModel.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ShopBindingModel : IShopModel
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Adress { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime OpeningDate { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (IComputerModel, int)> ShopComputers { get; set; } = new();
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int MaxCountComputers { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -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<ComponentViewModel>? ReadList(ComponentSearchModel? model);
|
||||||
|
ComponentViewModel? ReadElement(ComponentSearchModel model);
|
||||||
|
bool Create(ComponentBindingModel model);
|
||||||
|
bool Update(ComponentBindingModel model);
|
||||||
|
bool Delete(ComponentBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -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<ComputerViewModel>? ReadList(ComputerSearchModel? model);
|
||||||
|
ComputerViewModel? ReadElement(ComputerSearchModel model);
|
||||||
|
bool Create(ComputerBindingModel model);
|
||||||
|
bool Update(ComputerBindingModel model);
|
||||||
|
bool Delete(ComputerBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
20
ComputerShopContracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
20
ComputerShopContracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
@ -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<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||||
|
bool CreateOrder(OrderBindingModel model);
|
||||||
|
bool TakeOrderInWork(OrderBindingModel model);
|
||||||
|
bool FinishOrder(OrderBindingModel model);
|
||||||
|
bool DeliveryOrder(OrderBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
23
ComputerShopContracts/BusinessLogicsContracts/IShopLogic.cs
Normal file
23
ComputerShopContracts/BusinessLogicsContracts/IShopLogic.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IShopLogic
|
||||||
|
{
|
||||||
|
ShopViewModel? ReadElement(ShopSearchModel model);
|
||||||
|
List<ShopViewModel>? ReadList(ShopSearchModel? model);
|
||||||
|
bool Create(ShopBindingModel model);
|
||||||
|
bool Update(ShopBindingModel model);
|
||||||
|
bool Delete(ShopBindingModel model);
|
||||||
|
bool SupplyComputers(ShopSearchModel model, IComputerModel computer, int count);
|
||||||
|
bool SellComputer(IComputerModel computer, int count);
|
||||||
|
}
|
||||||
|
}
|
17
ComputerShopContracts/ComputerShopContracts.csproj
Normal file
17
ComputerShopContracts/ComputerShopContracts.csproj
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractComputerDataModel\ComputerShopDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
14
ComputerShopContracts/SearchModels/ComponentSearchModel.cs
Normal file
14
ComputerShopContracts/SearchModels/ComponentSearchModel.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
14
ComputerShopContracts/SearchModels/ComputerSearchModel.cs
Normal file
14
ComputerShopContracts/SearchModels/ComputerSearchModel.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
13
ComputerShopContracts/SearchModels/OrderSearchModel.cs
Normal file
13
ComputerShopContracts/SearchModels/OrderSearchModel.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
14
ComputerShopContracts/SearchModels/ShopSearchModel.cs
Normal file
14
ComputerShopContracts/SearchModels/ShopSearchModel.cs
Normal file
@ -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 ShopSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
21
ComputerShopContracts/StoragesContracts/IComponentStorage.cs
Normal file
21
ComputerShopContracts/StoragesContracts/IComponentStorage.cs
Normal file
@ -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<ComponentViewModel> GetFullList();
|
||||||
|
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
|
||||||
|
ComponentViewModel? GetElement(ComponentSearchModel model);
|
||||||
|
ComponentViewModel? Insert(ComponentBindingModel model);
|
||||||
|
ComponentViewModel? Update(ComponentBindingModel model);
|
||||||
|
ComponentViewModel? Delete(ComponentBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
21
ComputerShopContracts/StoragesContracts/IComputerStorage.cs
Normal file
21
ComputerShopContracts/StoragesContracts/IComputerStorage.cs
Normal file
@ -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<ComputerViewModel> GetFullList();
|
||||||
|
List<ComputerViewModel> GetFilteredList(ComputerSearchModel model);
|
||||||
|
ComputerViewModel? GetElement(ComputerSearchModel model);
|
||||||
|
ComputerViewModel? Insert(ComputerBindingModel model);
|
||||||
|
ComputerViewModel? Update(ComputerBindingModel model);
|
||||||
|
ComputerViewModel? Delete(ComputerBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
21
ComputerShopContracts/StoragesContracts/IOrderStorage.cs
Normal file
21
ComputerShopContracts/StoragesContracts/IOrderStorage.cs
Normal file
@ -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<OrderViewModel> GetFullList();
|
||||||
|
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||||
|
OrderViewModel? GetElement(OrderSearchModel model);
|
||||||
|
OrderViewModel? Insert(OrderBindingModel model);
|
||||||
|
OrderViewModel? Update(OrderBindingModel model);
|
||||||
|
OrderViewModel? Delete(OrderBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
23
ComputerShopContracts/StoragesContracts/IShopStorage.cs
Normal file
23
ComputerShopContracts/StoragesContracts/IShopStorage.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IShopStorage
|
||||||
|
{
|
||||||
|
ShopViewModel? GetElement(ShopSearchModel model);
|
||||||
|
List<ShopViewModel> GetFullList();
|
||||||
|
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
||||||
|
ShopViewModel? Insert(ShopBindingModel model);
|
||||||
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
|
bool SellComputer(IComputerModel model, int count);
|
||||||
|
}
|
||||||
|
}
|
19
ComputerShopContracts/ViewModels/ComponentViewModel.cs
Normal file
19
ComputerShopContracts/ViewModels/ComponentViewModel.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
24
ComputerShopContracts/ViewModels/ComputerViewModel.cs
Normal file
24
ComputerShopContracts/ViewModels/ComputerViewModel.cs
Normal file
@ -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<int, (IComponentModel, int)> ComputerComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new();
|
||||||
|
}
|
||||||
|
}
|
31
ComputerShopContracts/ViewModels/OrderViewModel.cs
Normal file
31
ComputerShopContracts/ViewModels/OrderViewModel.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
26
ComputerShopContracts/ViewModels/ShopViewModel.cs
Normal file
26
ComputerShopContracts/ViewModels/ShopViewModel.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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 ShopViewModel
|
||||||
|
{
|
||||||
|
[DisplayName("Название магазина")]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Адрес")]
|
||||||
|
public string Adress { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Дата открытия")]
|
||||||
|
public DateTime OpeningDate { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (IComputerModel, int)> ShopComputers { get; set; } = new();
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Вместимость")]
|
||||||
|
public int MaxCountComputers { get; set; }
|
||||||
|
}
|
||||||
|
}
|
13
ComputerShopFileImplement/ComputerShopFileImplement.csproj
Normal file
13
ComputerShopFileImplement/ComputerShopFileImplement.csproj
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ComputerShopContracts\ComputerShopContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
61
ComputerShopFileImplement/DataFileSingleton.cs
Normal file
61
ComputerShopFileImplement/DataFileSingleton.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopFileImplement.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement
|
||||||
|
{
|
||||||
|
internal class DataFileSingleton
|
||||||
|
{
|
||||||
|
private static DataFileSingleton? instance;
|
||||||
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
|
private readonly string OrderFileName = "Order.xml";
|
||||||
|
private readonly string ComputerFileName = "Computer.xml";
|
||||||
|
private readonly string ShopFileName = "Shop.xml";
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
|
public List<Order> Orders { get; private set; }
|
||||||
|
public List<Computer> Computers { get; private set; }
|
||||||
|
public List<Shop> Shops { get; private set; }
|
||||||
|
public static DataFileSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new DataFileSingleton();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
public void SaveComponents() => SaveData(Components, ComponentFileName,
|
||||||
|
"Components", x => x.GetXElement);
|
||||||
|
public void SaveComputers() => SaveData(Computers, ComputerFileName,
|
||||||
|
"Computers", x => x.GetXElement);
|
||||||
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
|
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||||
|
private DataFileSingleton()
|
||||||
|
{
|
||||||
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
|
Computers = LoadData(ComputerFileName, "Computer", x => Computer.Create(x)!)!;
|
||||||
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
|
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||||
|
}
|
||||||
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||||
|
Func<XElement, T> selectFunction)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||||
|
}
|
||||||
|
return new List<T>();
|
||||||
|
}
|
||||||
|
private static void SaveData<T>(List<T> data, string filename, string
|
||||||
|
xmlNodeName, Func<T, XElement> selectFunction)
|
||||||
|
{
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
90
ComputerShopFileImplement/Implements/ComponentStorage.cs
Normal file
90
ComputerShopFileImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StoragesContracts;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopFileImplement.Models;
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComponentStorage : IComponentStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public ComponentStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Components
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel
|
||||||
|
model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Components
|
||||||
|
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Components
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
|
||||||
|
model.ComponentName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Components.Count > 0 ? source.Components.Max(x =>
|
||||||
|
x.Id) + 1 : 1;
|
||||||
|
var newComponent = Component.Create(model);
|
||||||
|
if (newComponent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Components.Add(newComponent);
|
||||||
|
source.SaveComponents();
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
var component = source.Components.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
component.Update(model);
|
||||||
|
source.SaveComponents();
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Components.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Components.Remove(element);
|
||||||
|
source.SaveComponents();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
86
ComputerShopFileImplement/Implements/ComputerStorage.cs
Normal file
86
ComputerShopFileImplement/Implements/ComputerStorage.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StoragesContracts;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopFileImplement.Models;
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComputerStorage : IComputerStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public ComputerStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComputerViewModel? GetElement(ComputerSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComputerName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Computers
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComputerName) && x.ComputerName == model.ComputerName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ComputerViewModel> GetFilteredList(ComputerSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComputerName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Computers
|
||||||
|
.Where(x => x.ComputerName.Contains(model.ComputerName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ComputerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Computers.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComputerViewModel? Insert(ComputerBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Computers.Count > 0 ? source.Computers.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newDoc = Computer.Create(model);
|
||||||
|
if (newDoc == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Computers.Add(newDoc);
|
||||||
|
source.SaveComputers();
|
||||||
|
return newDoc.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComputerViewModel? Update(ComputerBindingModel model)
|
||||||
|
{
|
||||||
|
var Computer = source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (Computer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Computer.Update(model);
|
||||||
|
source.SaveComputers();
|
||||||
|
return Computer.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComputerViewModel? Delete(ComputerBindingModel model)
|
||||||
|
{
|
||||||
|
var Computer = source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (Computer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Computers.Remove(Computer);
|
||||||
|
source.SaveComputers();
|
||||||
|
return Computer.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
87
ComputerShopFileImplement/Implements/OrderStorage.cs
Normal file
87
ComputerShopFileImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StoragesContracts;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopFileImplement.Models;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Orders
|
||||||
|
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Orders
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Orders.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Orders.Add(newOrder);
|
||||||
|
source.SaveOrders();
|
||||||
|
return newOrder.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
source.SaveOrders();
|
||||||
|
return order.GetViewModel;
|
||||||
|
}
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Orders.Remove(order);
|
||||||
|
source.SaveOrders();
|
||||||
|
return order.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
148
ComputerShopFileImplement/Implements/ShopStorage.cs
Normal file
148
ComputerShopFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StoragesContracts;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using ComputerShopFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Name))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Shops
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.Where(x => x.Name.Contains(model.Name ?? string.Empty))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Shops.Select(shop => shop.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newShop = Shop.Create(model);
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Shops.Add(newShop);
|
||||||
|
source.SaveShops();
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
shop.Update(model);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Shops.Remove(shop);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SellComputer(IComputerModel model, int count)
|
||||||
|
{
|
||||||
|
var computer = source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var countStore = count;
|
||||||
|
|
||||||
|
var shopComputers = source.Shops.SelectMany(shop => shop.ShopComputers.Where(doc => doc.Value.Item1.Id == computer.Id));
|
||||||
|
|
||||||
|
foreach (var doc in shopComputers)
|
||||||
|
{
|
||||||
|
count -= doc.Value.Item2;
|
||||||
|
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
count = countStore;
|
||||||
|
|
||||||
|
foreach (var shop in source.Shops)
|
||||||
|
{
|
||||||
|
var computers = shop.ShopComputers;
|
||||||
|
|
||||||
|
foreach (var doc in computers.Where(x => x.Value.Item1.Id == computer.Id))
|
||||||
|
{
|
||||||
|
var min = Math.Min(doc.Value.Item2, count);
|
||||||
|
computers[doc.Value.Item1.Id] = (doc.Value.Item1, doc.Value.Item2 - min);
|
||||||
|
count -= min;
|
||||||
|
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shop.Update(new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = shop.Id,
|
||||||
|
Name = shop.Name,
|
||||||
|
Adress = shop.Adress,
|
||||||
|
OpeningDate = shop.OpeningDate,
|
||||||
|
MaxCountComputers = shop.MaxCountComputers,
|
||||||
|
ShopComputers = computers
|
||||||
|
});
|
||||||
|
|
||||||
|
source.SaveShops();
|
||||||
|
|
||||||
|
if (count <= 0) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count <= 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
ComputerShopFileImplement/Models/Component.cs
Normal file
64
ComputerShopFileImplement/Models/Component.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement.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 static Component? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Component()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ComponentName = element.Element("ComponentName")!.Value,
|
||||||
|
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
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
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Component",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ComponentName", ComponentName),
|
||||||
|
new XElement("Cost", Cost.ToString()));
|
||||||
|
}
|
||||||
|
}
|
97
ComputerShopFileImplement/Models/Computer.cs
Normal file
97
ComputerShopFileImplement/Models/Computer.cs
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement.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<int, int> Components { get; private set; } = new();
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _productComponents = null;
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ComputerComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_productComponents == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_productComponents = Components.ToDictionary(x => x.Key, y =>
|
||||||
|
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
|
||||||
|
}
|
||||||
|
return _productComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static Computer? Create(ComputerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Computer()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComputerName = model.ComputerName,
|
||||||
|
Price = model.Price,
|
||||||
|
Components = model.ComputerComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Computer? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Computer()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ComputerName = element.Element("ComputerName")!.Value,
|
||||||
|
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||||
|
Components = element.Element("ComputerComponents")!.Elements("ComputerComponent").ToDictionary(x =>
|
||||||
|
Convert.ToInt32(x.Element("Key")?.Value), x =>
|
||||||
|
Convert.ToInt32(x.Element("Value")?.Value)
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ComputerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ComputerName = model.ComputerName;
|
||||||
|
Price = model.Price;
|
||||||
|
Components = model.ComputerComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_productComponents = null;
|
||||||
|
}
|
||||||
|
public ComputerViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ComputerName = ComputerName,
|
||||||
|
Price = Price,
|
||||||
|
ComputerComponents = ComputerComponents
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Computer",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ComputerName", ComputerName),
|
||||||
|
new XElement("Price", Price.ToString()),
|
||||||
|
new XElement("ComputerComponents", Components.Select(x =>
|
||||||
|
new XElement("ComputerComponent",
|
||||||
|
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
|
||||||
|
new XElement("Value", x.Value)))
|
||||||
|
|
||||||
|
.ToArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
110
ComputerShopFileImplement/Models/Order.cs
Normal file
110
ComputerShopFileImplement/Models/Order.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Enums;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement.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 static Order? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ComputerName = element.Element("ComputerName")!.Value,
|
||||||
|
ComputerId = Convert.ToInt32(element.Element("ComputerId")!.Value),
|
||||||
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
|
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||||
|
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||||
|
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new(
|
||||||
|
"Order",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ComputerName", ComputerName),
|
||||||
|
new XElement("ComputerId", ComputerId.ToString()),
|
||||||
|
new XElement("Count", Count.ToString()),
|
||||||
|
new XElement("Sum", Sum.ToString()),
|
||||||
|
new XElement("Status", Status.ToString()),
|
||||||
|
new XElement("DateCreate", DateCreate.ToString()),
|
||||||
|
new XElement("DateImplement", DateImplement.ToString())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
122
ComputerShopFileImplement/Models/Shop.cs
Normal file
122
ComputerShopFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
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;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Adress { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public int MaxCountComputers { get; private set; }
|
||||||
|
|
||||||
|
public DateTime OpeningDate { get; private set; }
|
||||||
|
|
||||||
|
public Dictionary<int, int> Computers { get; private set; } = new();
|
||||||
|
|
||||||
|
private Dictionary<int, (IComputerModel, int)>? _shopComputers = null;
|
||||||
|
|
||||||
|
public Dictionary<int, (IComputerModel, int)> ShopComputers
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopComputers == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_shopComputers = Computers.ToDictionary(
|
||||||
|
x => x.Key,
|
||||||
|
y => ((source.Computers.FirstOrDefault(z => z.Id == y.Key) as IComputerModel)!, y.Value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _shopComputers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Name = model.Name,
|
||||||
|
Adress = model.Adress,
|
||||||
|
MaxCountComputers = model.MaxCountComputers,
|
||||||
|
OpeningDate = model.OpeningDate,
|
||||||
|
Computers = model.ShopComputers.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Shop? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
Name = element.Element("Name")!.Value,
|
||||||
|
Adress = element.Element("Address")!.Value,
|
||||||
|
MaxCountComputers = Convert.ToInt32(element.Element("MaxCountComputers")!.Value),
|
||||||
|
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||||
|
Computers = element.Element("ShopComputers")!.Elements("ShopComputer").ToDictionary(
|
||||||
|
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||||
|
x => Convert.ToInt32(x.Element("Value")?.Value)
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Name = model.Name;
|
||||||
|
Adress = model.Adress;
|
||||||
|
OpeningDate = model.OpeningDate;
|
||||||
|
MaxCountComputers = model.MaxCountComputers;
|
||||||
|
if (model.ShopComputers.Count > 0)
|
||||||
|
{
|
||||||
|
Computers = model.ShopComputers.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_shopComputers = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
Adress = Adress,
|
||||||
|
OpeningDate = OpeningDate,
|
||||||
|
ShopComputers = ShopComputers,
|
||||||
|
MaxCountComputers = MaxCountComputers
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new(
|
||||||
|
"Shop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("Name", Name),
|
||||||
|
new XElement("Address", Adress),
|
||||||
|
new XElement("MaxCountComputers", MaxCountComputers),
|
||||||
|
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||||
|
new XElement("ShopComputers", Computers.Select(x =>
|
||||||
|
new XElement("ShopComputer",
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
new XElement("Value", x.Value)))
|
||||||
|
.ToArray()));
|
||||||
|
}
|
||||||
|
}
|
14
ComputerShopListImplement/ComputerShopListImplement.csproj
Normal file
14
ComputerShopListImplement/ComputerShopListImplement.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractComputerDataModel\ComputerShopDataModels.csproj" />
|
||||||
|
<ProjectReference Include="..\ComputerShopContracts\ComputerShopContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
108
ComputerShopListImplement/Implements/ComponentStorage.cs
Normal file
108
ComputerShopListImplement/Implements/ComponentStorage.cs
Normal file
@ -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<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ComponentViewModel>();
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
result.Add(component.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel
|
||||||
|
model)
|
||||||
|
{
|
||||||
|
var result = new List<ComponentViewModel>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
111
ComputerShopListImplement/Implements/ComputerStorage.cs
Normal file
111
ComputerShopListImplement/Implements/ComputerStorage.cs
Normal file
@ -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<ComputerViewModel> GetFilteredList(ComputerSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<ComputerViewModel>();
|
||||||
|
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<ComputerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ComputerViewModel>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
111
ComputerShopListImplement/Implements/OrderStorage.cs
Normal file
111
ComputerShopListImplement/Implements/OrderStorage.cs
Normal file
@ -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<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<OrderViewModel>();
|
||||||
|
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<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<OrderViewModel>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
124
ComputerShopListImplement/Implements/ShopStorage.cs
Normal file
124
ComputerShopListImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StoragesContracts;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using ComputerShopListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.Name) && shop.Name == model.Name) || (model.Id.HasValue && shop.Id == model.Id))
|
||||||
|
{
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<ShopViewModel>();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(model.Name))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (shop.Name.Contains(model.Name))
|
||||||
|
{
|
||||||
|
result.Add(shop.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ShopViewModel>();
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
result.Add(shop.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (model.Id <= shop.Id)
|
||||||
|
{
|
||||||
|
model.Id = shop.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var newShop = Shop.Create(model);
|
||||||
|
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Shops.Add(newShop);
|
||||||
|
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (shop.Id == model.Id)
|
||||||
|
{
|
||||||
|
shop.Update(model);
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Shops.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Shops[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Shops[i];
|
||||||
|
_source.Shops.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SellComputer(IComputerModel model, int count)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
ComputerShopListImplement/Models/Component.cs
Normal file
47
ComputerShopListImplement/Models/Component.cs
Normal file
@ -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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
54
ComputerShopListImplement/Models/Computer.cs
Normal file
54
ComputerShopListImplement/Models/Computer.cs
Normal file
@ -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<int, (IComponentModel, int)> ComputerComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
} = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
32
ComputerShopListImplement/Models/DataListSingleton.cs
Normal file
32
ComputerShopListImplement/Models/DataListSingleton.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
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<Component> Components { get; set; }
|
||||||
|
public List<Order> Orders { get; set; }
|
||||||
|
public List<Computer> Computers { get; set; }
|
||||||
|
public List<Shop> Shops { get; set; }
|
||||||
|
private DataListSingleton()
|
||||||
|
{
|
||||||
|
Components = new List<Component>();
|
||||||
|
Orders = new List<Order>();
|
||||||
|
Computers = new List<Computer>();
|
||||||
|
Shops = new List<Shop>();
|
||||||
|
}
|
||||||
|
public static DataListSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
{
|
||||||
|
_instance = new DataListSingleton();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
ComputerShopListImplement/Models/Order.cs
Normal file
78
ComputerShopListImplement/Models/Order.cs
Normal file
@ -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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
65
ComputerShopListImplement/Models/Shop.cs
Normal file
65
ComputerShopListImplement/Models/Shop.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
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 Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Adress { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime OpeningDate { get; private set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (IComputerModel, int)> ShopComputers { get; private set; } = new();
|
||||||
|
public int MaxCountComputers { get; private set; }
|
||||||
|
|
||||||
|
public static Shop? Create(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Name = model.Name,
|
||||||
|
Adress = model.Adress,
|
||||||
|
OpeningDate = model.OpeningDate,
|
||||||
|
ShopComputers = new(),
|
||||||
|
MaxCountComputers = model.MaxCountComputers
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Name = model.Name;
|
||||||
|
Adress = model.Adress;
|
||||||
|
OpeningDate = model.OpeningDate;
|
||||||
|
ShopComputers = model.ShopComputers;
|
||||||
|
MaxCountComputers = model.MaxCountComputers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
Adress = Adress,
|
||||||
|
OpeningDate = OpeningDate,
|
||||||
|
ShopComputers = ShopComputers,
|
||||||
|
MaxCountComputers = MaxCountComputers
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -8,4 +8,17 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractComputerDataModel\ComputerShopDataModels.csproj" />
|
||||||
|
<ProjectReference Include="..\ComputerShopBusinessLogic\ComputerShopBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\ComputerShopContracts\ComputerShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\ComputerShopFileImplement\ComputerShopFileImplement.csproj" />
|
||||||
|
<ProjectReference Include="..\ComputerShopListImplement\ComputerShopListImplement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -3,7 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.3.32819.101
|
VisualStudioVersion = 17.3.32819.101
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShop", "ComputersShop.csproj", "{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShop", "ComputersShop.csproj", "{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopDataModels", "..\AbstractComputerDataModel\ComputerShopDataModels.csproj", "{07BF1453-7129-45C4-AB54-AFC38F1E579D}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopContracts", "..\ComputerShopContracts\ComputerShopContracts.csproj", "{4684F24F-29DC-496C-803F-0877E5100939}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopBusinessLogic", "..\ComputerShopBusinessLogic\ComputerShopBusinessLogic.csproj", "{8A6D08BB-449A-4C35-81CA-F82B6293D241}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopListImplement", "..\ComputerShopListImplement\ComputerShopListImplement.csproj", "{D632C3A7-3E0E-4B53-B2B4-696A9F6B8D38}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopFileImplement", "..\ComputerShopFileImplement\ComputerShopFileImplement.csproj", "{AC377840-5B04-4C11-BBFA-C7933C40AB2C}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -15,6 +25,26 @@ Global
|
|||||||
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{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.ActiveCfg = Release|Any CPU
|
||||||
{7BE0F575-7A99-4161-BCD0-4F14E5AC7B95}.Release|Any CPU.Build.0 = 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
|
||||||
|
{AC377840-5B04-4C11-BBFA-C7933C40AB2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{AC377840-5B04-4C11-BBFA-C7933C40AB2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{AC377840-5B04-4C11-BBFA-C7933C40AB2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{AC377840-5B04-4C11-BBFA-C7933C40AB2C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
39
ComputersShop/Form1.Designer.cs
generated
39
ComputersShop/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace ComputersShop
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form1";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace ComputersShop
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<value>2.0</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="reader">
|
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
</root>
|
|
118
ComputersShop/FormComponent.Designer.cs
generated
Normal file
118
ComputersShop/FormComponent.Designer.cs
generated
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormComponent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.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;
|
||||||
|
}
|
||||||
|
}
|
96
ComputersShop/FormComponent.cs
Normal file
96
ComputersShop/FormComponent.cs
Normal file
@ -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<FormComponent> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/FormComponent.resx
Normal file
60
ComputersShop/FormComponent.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
115
ComputersShop/FormComponents.Designer.cs
generated
Normal file
115
ComputersShop/FormComponents.Designer.cs
generated
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormComponents
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.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;
|
||||||
|
}
|
||||||
|
}
|
105
ComputersShop/FormComponents.cs
Normal file
105
ComputersShop/FormComponents.cs
Normal file
@ -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<FormComponents> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/FormComponents.resx
Normal file
60
ComputersShop/FormComponents.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
227
ComputersShop/FormComputer.Designer.cs
generated
Normal file
227
ComputersShop/FormComputer.Designer.cs
generated
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormComputer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.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;
|
||||||
|
}
|
||||||
|
}
|
209
ComputersShop/FormComputer.cs
Normal file
209
ComputersShop/FormComputer.cs
Normal file
@ -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<int, (IComponentModel, int)> _productComponents;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
public FormComputer(ILogger<FormComputer> logger, IComputerLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_productComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
}
|
||||||
|
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<int, (IComponentModel, int)>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
66
ComputersShop/FormComputer.resx
Normal file
66
ComputersShop/FormComputer.resx
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="ComponentName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="ComponentAmount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
120
ComputersShop/FormComputerComponent.Designer.cs
generated
Normal file
120
ComputersShop/FormComputerComponent.Designer.cs
generated
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormComputerComponent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.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;
|
||||||
|
}
|
||||||
|
}
|
88
ComputersShop/FormComputerComponent.cs
Normal file
88
ComputersShop/FormComputerComponent.cs
Normal file
@ -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<ComponentViewModel>? _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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/FormComputerComponent.resx
Normal file
60
ComputersShop/FormComputerComponent.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
114
ComputersShop/FormComputers.Designer.cs
generated
Normal file
114
ComputersShop/FormComputers.Designer.cs
generated
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormComputers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.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;
|
||||||
|
}
|
||||||
|
}
|
113
ComputersShop/FormComputers.cs
Normal file
113
ComputersShop/FormComputers.cs
Normal file
@ -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<FormComputers> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/FormComputers.resx
Normal file
60
ComputersShop/FormComputers.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
144
ComputersShop/FormCreateOrder.Designer.cs
generated
Normal file
144
ComputersShop/FormCreateOrder.Designer.cs
generated
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormCreateOrder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.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;
|
||||||
|
}
|
||||||
|
}
|
122
ComputersShop/FormCreateOrder.cs
Normal file
122
ComputersShop/FormCreateOrder.cs
Normal file
@ -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<FormCreateOrder> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/FormCreateOrder.resx
Normal file
60
ComputersShop/FormCreateOrder.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
212
ComputersShop/FormMain.Designer.cs
generated
Normal file
212
ComputersShop/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormMain
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.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.магазины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.buttonSupplyShop = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSellComputers = 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});
|
||||||
|
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);
|
||||||
|
//
|
||||||
|
// магазины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);
|
||||||
|
//
|
||||||
|
// buttonSupplyShop
|
||||||
|
//
|
||||||
|
this.buttonSupplyShop.Location = new System.Drawing.Point(786, 155);
|
||||||
|
this.buttonSupplyShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonSupplyShop.Name = "buttonSupplyShop";
|
||||||
|
this.buttonSupplyShop.Size = new System.Drawing.Size(192, 22);
|
||||||
|
this.buttonSupplyShop.TabIndex = 8;
|
||||||
|
this.buttonSupplyShop.Text = "Пополнение магазина";
|
||||||
|
this.buttonSupplyShop.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click);
|
||||||
|
//
|
||||||
|
// buttonSellComputers
|
||||||
|
//
|
||||||
|
this.buttonSellComputers.Location = new System.Drawing.Point(786, 181);
|
||||||
|
this.buttonSellComputers.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonSellComputers.Name = "buttonSellComputers";
|
||||||
|
this.buttonSellComputers.Size = new System.Drawing.Size(192, 22);
|
||||||
|
this.buttonSellComputers.TabIndex = 9;
|
||||||
|
this.buttonSellComputers.Text = "Продажа компьютеров";
|
||||||
|
this.buttonSellComputers.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSellComputers.Click += new System.EventHandler(this.buttonSellComputers_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.buttonSellComputers);
|
||||||
|
this.Controls.Add(this.buttonSupplyShop);
|
||||||
|
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;
|
||||||
|
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||||
|
private Button buttonSupplyShop;
|
||||||
|
private Button buttonSellComputers;
|
||||||
|
}
|
||||||
|
}
|
206
ComputersShop/FormMain.cs
Normal file
206
ComputersShop/FormMain.cs
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
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<FormMain> 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 магазиныToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||||
|
if (service is FormShops 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<OrderStatus>(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<OrderStatus>(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<OrderStatus>(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();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSupplyShop_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply));
|
||||||
|
if (service is FormShopSupply form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSellComputers_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
|
||||||
|
if (service is FormShopSell form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
ComputersShop/FormMain.resx
Normal file
63
ComputersShop/FormMain.resx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
217
ComputersShop/FormShop.Designer.cs
generated
Normal file
217
ComputersShop/FormShop.Designer.cs
generated
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormShop
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.ColumnComputerName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
|
||||||
|
this.labelOpeningDate = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxAddress = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelAddress = new System.Windows.Forms.Label();
|
||||||
|
this.labelName = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxCapacity = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelCapacity = new System.Windows.Forms.Label();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(200, 375);
|
||||||
|
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(136, 22);
|
||||||
|
this.buttonCancel.TabIndex = 21;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(42, 375);
|
||||||
|
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(136, 22);
|
||||||
|
this.buttonSave.TabIndex = 20;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||||
|
this.ColumnId,
|
||||||
|
this.ColumnComputerName,
|
||||||
|
this.ColumnCount});
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(12, 143);
|
||||||
|
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(351, 225);
|
||||||
|
this.dataGridView.TabIndex = 19;
|
||||||
|
//
|
||||||
|
// ColumnId
|
||||||
|
//
|
||||||
|
this.ColumnId.HeaderText = "ID";
|
||||||
|
this.ColumnId.MinimumWidth = 6;
|
||||||
|
this.ColumnId.Name = "ColumnId";
|
||||||
|
this.ColumnId.Visible = false;
|
||||||
|
this.ColumnId.Width = 125;
|
||||||
|
//
|
||||||
|
// ColumnComputerName
|
||||||
|
//
|
||||||
|
this.ColumnComputerName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
this.ColumnComputerName.HeaderText = "Компьютер";
|
||||||
|
this.ColumnComputerName.MinimumWidth = 6;
|
||||||
|
this.ColumnComputerName.Name = "ColumnComputerName";
|
||||||
|
//
|
||||||
|
// ColumnCount
|
||||||
|
//
|
||||||
|
this.ColumnCount.HeaderText = "Количество";
|
||||||
|
this.ColumnCount.MinimumWidth = 6;
|
||||||
|
this.ColumnCount.Name = "ColumnCount";
|
||||||
|
this.ColumnCount.Width = 125;
|
||||||
|
//
|
||||||
|
// dateTimePicker
|
||||||
|
//
|
||||||
|
this.dateTimePicker.Location = new System.Drawing.Point(144, 64);
|
||||||
|
this.dateTimePicker.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.dateTimePicker.Name = "dateTimePicker";
|
||||||
|
this.dateTimePicker.Size = new System.Drawing.Size(219, 23);
|
||||||
|
this.dateTimePicker.TabIndex = 18;
|
||||||
|
//
|
||||||
|
// labelOpeningDate
|
||||||
|
//
|
||||||
|
this.labelOpeningDate.AutoSize = true;
|
||||||
|
this.labelOpeningDate.Location = new System.Drawing.Point(12, 67);
|
||||||
|
this.labelOpeningDate.Name = "labelOpeningDate";
|
||||||
|
this.labelOpeningDate.Size = new System.Drawing.Size(100, 15);
|
||||||
|
this.labelOpeningDate.TabIndex = 17;
|
||||||
|
this.labelOpeningDate.Text = "Время открытия:";
|
||||||
|
//
|
||||||
|
// textBoxAddress
|
||||||
|
//
|
||||||
|
this.textBoxAddress.Location = new System.Drawing.Point(88, 37);
|
||||||
|
this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.textBoxAddress.Name = "textBoxAddress";
|
||||||
|
this.textBoxAddress.Size = new System.Drawing.Size(276, 23);
|
||||||
|
this.textBoxAddress.TabIndex = 16;
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
this.textBoxName.Location = new System.Drawing.Point(88, 12);
|
||||||
|
this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.textBoxName.Name = "textBoxName";
|
||||||
|
this.textBoxName.Size = new System.Drawing.Size(276, 23);
|
||||||
|
this.textBoxName.TabIndex = 15;
|
||||||
|
//
|
||||||
|
// labelAddress
|
||||||
|
//
|
||||||
|
this.labelAddress.AutoSize = true;
|
||||||
|
this.labelAddress.Location = new System.Drawing.Point(12, 41);
|
||||||
|
this.labelAddress.Name = "labelAddress";
|
||||||
|
this.labelAddress.Size = new System.Drawing.Size(43, 15);
|
||||||
|
this.labelAddress.TabIndex = 14;
|
||||||
|
this.labelAddress.Text = "Адрес:";
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
this.labelName.AutoSize = true;
|
||||||
|
this.labelName.Location = new System.Drawing.Point(12, 14);
|
||||||
|
this.labelName.Name = "labelName";
|
||||||
|
this.labelName.Size = new System.Drawing.Size(62, 15);
|
||||||
|
this.labelName.TabIndex = 13;
|
||||||
|
this.labelName.Text = "Название:";
|
||||||
|
//
|
||||||
|
// textBoxCapacity
|
||||||
|
//
|
||||||
|
this.textBoxCapacity.Location = new System.Drawing.Point(117, 91);
|
||||||
|
this.textBoxCapacity.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.textBoxCapacity.Name = "textBoxCapacity";
|
||||||
|
this.textBoxCapacity.Size = new System.Drawing.Size(246, 23);
|
||||||
|
this.textBoxCapacity.TabIndex = 23;
|
||||||
|
//
|
||||||
|
// labelCapacity
|
||||||
|
//
|
||||||
|
this.labelCapacity.AutoSize = true;
|
||||||
|
this.labelCapacity.Location = new System.Drawing.Point(11, 93);
|
||||||
|
this.labelCapacity.Name = "labelCapacity";
|
||||||
|
this.labelCapacity.Size = new System.Drawing.Size(83, 15);
|
||||||
|
this.labelCapacity.TabIndex = 22;
|
||||||
|
this.labelCapacity.Text = "Вместимость:";
|
||||||
|
//
|
||||||
|
// FormShop
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(383, 399);
|
||||||
|
this.Controls.Add(this.textBoxCapacity);
|
||||||
|
this.Controls.Add(this.labelCapacity);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Controls.Add(this.dateTimePicker);
|
||||||
|
this.Controls.Add(this.labelOpeningDate);
|
||||||
|
this.Controls.Add(this.textBoxAddress);
|
||||||
|
this.Controls.Add(this.textBoxName);
|
||||||
|
this.Controls.Add(this.labelAddress);
|
||||||
|
this.Controls.Add(this.labelName);
|
||||||
|
this.Name = "FormShop";
|
||||||
|
this.Text = "FormShop";
|
||||||
|
this.Load += new System.EventHandler(this.FormShop_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSave;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private DateTimePicker dateTimePicker;
|
||||||
|
private Label labelOpeningDate;
|
||||||
|
private TextBox textBoxAddress;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private Label labelAddress;
|
||||||
|
private Label labelName;
|
||||||
|
private DataGridViewTextBoxColumn ColumnId;
|
||||||
|
private DataGridViewTextBoxColumn ColumnComputerName;
|
||||||
|
private DataGridViewTextBoxColumn ColumnCount;
|
||||||
|
private TextBox textBoxCapacity;
|
||||||
|
private Label labelCapacity;
|
||||||
|
}
|
||||||
|
}
|
143
ComputersShop/FormShop.cs
Normal file
143
ComputersShop/FormShop.cs
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.BusinessLogicsContracts;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
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 FormShop : Form
|
||||||
|
{
|
||||||
|
private readonly IShopLogic _logic;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private Dictionary<int, (IComputerModel, int)> _shopComputers;
|
||||||
|
private int? _id;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
|
||||||
|
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_shopComputers = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormShop_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var view = _logic.ReadElement(new ShopSearchModel
|
||||||
|
{
|
||||||
|
Id = _id.Value
|
||||||
|
});
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = view.Name;
|
||||||
|
textBoxAddress.Text = view.Adress;
|
||||||
|
_shopComputers = view.ShopComputers ?? new Dictionary<int, (IComputerModel, int)>();
|
||||||
|
textBoxCapacity.Text = view.MaxCountComputers.ToString();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка компьютеров магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_shopComputers != null)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
foreach (var pc in _shopComputers)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(new object[]
|
||||||
|
{
|
||||||
|
pc.Key,
|
||||||
|
pc.Value.Item1.ComputerName,
|
||||||
|
pc.Value.Item2
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxCapacity.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
Adress = textBoxAddress.Text,
|
||||||
|
OpeningDate = dateTimePicker.Value.Date,
|
||||||
|
ShopComputers = _shopComputers,
|
||||||
|
MaxCountComputers = Convert.ToInt32(textBoxCapacity.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
69
ComputersShop/FormShop.resx
Normal file
69
ComputersShop/FormShop.resx
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="ColumnId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="ColumnComputerName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
124
ComputersShop/FormShopSell.Designer.cs
generated
Normal file
124
ComputersShop/FormShopSell.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormShopSell
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSell = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxComputer = new System.Windows.Forms.ComboBox();
|
||||||
|
this.labelComputer = new System.Windows.Forms.Label();
|
||||||
|
this.labelCount = new System.Windows.Forms.Label();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(263, 99);
|
||||||
|
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
|
||||||
|
this.buttonCancel.TabIndex = 13;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||||
|
//
|
||||||
|
// buttonSell
|
||||||
|
//
|
||||||
|
this.buttonSell.Location = new System.Drawing.Point(157, 99);
|
||||||
|
this.buttonSell.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonSell.Name = "buttonSell";
|
||||||
|
this.buttonSell.Size = new System.Drawing.Size(82, 22);
|
||||||
|
this.buttonSell.TabIndex = 12;
|
||||||
|
this.buttonSell.Text = "Продажа";
|
||||||
|
this.buttonSell.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click);
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
this.textBoxCount.Location = new System.Drawing.Point(101, 48);
|
||||||
|
this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.textBoxCount.Name = "textBoxCount";
|
||||||
|
this.textBoxCount.Size = new System.Drawing.Size(139, 23);
|
||||||
|
this.textBoxCount.TabIndex = 11;
|
||||||
|
//
|
||||||
|
// comboBoxComputer
|
||||||
|
//
|
||||||
|
this.comboBoxComputer.FormattingEnabled = true;
|
||||||
|
this.comboBoxComputer.Location = new System.Drawing.Point(101, 11);
|
||||||
|
this.comboBoxComputer.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.comboBoxComputer.Name = "comboBoxComputer";
|
||||||
|
this.comboBoxComputer.Size = new System.Drawing.Size(244, 23);
|
||||||
|
this.comboBoxComputer.TabIndex = 10;
|
||||||
|
//
|
||||||
|
// labelComputer
|
||||||
|
//
|
||||||
|
this.labelComputer.AutoSize = true;
|
||||||
|
this.labelComputer.Location = new System.Drawing.Point(13, 11);
|
||||||
|
this.labelComputer.Name = "labelComputer";
|
||||||
|
this.labelComputer.Size = new System.Drawing.Size(74, 15);
|
||||||
|
this.labelComputer.TabIndex = 9;
|
||||||
|
this.labelComputer.Text = "Компьютер:";
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
this.labelCount.AutoSize = true;
|
||||||
|
this.labelCount.Location = new System.Drawing.Point(13, 50);
|
||||||
|
this.labelCount.Name = "labelCount";
|
||||||
|
this.labelCount.Size = new System.Drawing.Size(75, 15);
|
||||||
|
this.labelCount.TabIndex = 8;
|
||||||
|
this.labelCount.Text = "Количество:";
|
||||||
|
//
|
||||||
|
// FormShopSell
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(369, 136);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSell);
|
||||||
|
this.Controls.Add(this.textBoxCount);
|
||||||
|
this.Controls.Add(this.comboBoxComputer);
|
||||||
|
this.Controls.Add(this.labelComputer);
|
||||||
|
this.Controls.Add(this.labelCount);
|
||||||
|
this.Name = "FormShopSell";
|
||||||
|
this.Text = "FormShopSell";
|
||||||
|
this.Load += new System.EventHandler(this.FormShopSell_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSell;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private ComboBox comboBoxComputer;
|
||||||
|
private Label labelComputer;
|
||||||
|
private Label labelCount;
|
||||||
|
}
|
||||||
|
}
|
96
ComputersShop/FormShopSell.cs
Normal file
96
ComputersShop/FormShopSell.cs
Normal file
@ -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 FormShopSell : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComputerLogic _logicC;
|
||||||
|
private readonly IShopLogic _logicS;
|
||||||
|
|
||||||
|
public FormShopSell(ILogger<FormShopSell> logger, IComputerLogic logicC, IShopLogic logicS)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicC = logicC;
|
||||||
|
_logicS = logicS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormShopSell_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 buttonSell_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 = _logicS.SellComputer(
|
||||||
|
new ComputerBindingModel
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(comboBoxComputer.SelectedValue)
|
||||||
|
},
|
||||||
|
Convert.ToInt32(textBoxCount.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/FormShopSell.resx
Normal file
60
ComputersShop/FormShopSell.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
149
ComputersShop/FormShopSupply.Designer.cs
generated
Normal file
149
ComputersShop/FormShopSupply.Designer.cs
generated
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormShopSupply
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxComputer = new System.Windows.Forms.ComboBox();
|
||||||
|
this.comboBoxShop = new System.Windows.Forms.ComboBox();
|
||||||
|
this.labelComputerCount = new System.Windows.Forms.Label();
|
||||||
|
this.labelComputer = new System.Windows.Forms.Label();
|
||||||
|
this.labelShop = new System.Windows.Forms.Label();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(259, 134);
|
||||||
|
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
|
||||||
|
this.buttonCancel.TabIndex = 17;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(171, 134);
|
||||||
|
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(82, 22);
|
||||||
|
this.buttonSave.TabIndex = 16;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
this.textBoxCount.Location = new System.Drawing.Point(122, 89);
|
||||||
|
this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.textBoxCount.Name = "textBoxCount";
|
||||||
|
this.textBoxCount.Size = new System.Drawing.Size(110, 23);
|
||||||
|
this.textBoxCount.TabIndex = 15;
|
||||||
|
//
|
||||||
|
// comboBoxComputer
|
||||||
|
//
|
||||||
|
this.comboBoxComputer.FormattingEnabled = true;
|
||||||
|
this.comboBoxComputer.Location = new System.Drawing.Point(122, 49);
|
||||||
|
this.comboBoxComputer.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.comboBoxComputer.Name = "comboBoxComputer";
|
||||||
|
this.comboBoxComputer.Size = new System.Drawing.Size(220, 23);
|
||||||
|
this.comboBoxComputer.TabIndex = 14;
|
||||||
|
//
|
||||||
|
// comboBoxShop
|
||||||
|
//
|
||||||
|
this.comboBoxShop.FormattingEnabled = true;
|
||||||
|
this.comboBoxShop.Location = new System.Drawing.Point(122, 11);
|
||||||
|
this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.comboBoxShop.Name = "comboBoxShop";
|
||||||
|
this.comboBoxShop.Size = new System.Drawing.Size(220, 23);
|
||||||
|
this.comboBoxShop.TabIndex = 13;
|
||||||
|
//
|
||||||
|
// labelComputerCount
|
||||||
|
//
|
||||||
|
this.labelComputerCount.AutoSize = true;
|
||||||
|
this.labelComputerCount.Location = new System.Drawing.Point(15, 89);
|
||||||
|
this.labelComputerCount.Name = "labelComputerCount";
|
||||||
|
this.labelComputerCount.Size = new System.Drawing.Size(75, 15);
|
||||||
|
this.labelComputerCount.TabIndex = 12;
|
||||||
|
this.labelComputerCount.Text = "Количество:";
|
||||||
|
//
|
||||||
|
// labelComputer
|
||||||
|
//
|
||||||
|
this.labelComputer.AutoSize = true;
|
||||||
|
this.labelComputer.Location = new System.Drawing.Point(15, 51);
|
||||||
|
this.labelComputer.Name = "labelComputer";
|
||||||
|
this.labelComputer.Size = new System.Drawing.Size(74, 15);
|
||||||
|
this.labelComputer.TabIndex = 11;
|
||||||
|
this.labelComputer.Text = "Компьютер:";
|
||||||
|
//
|
||||||
|
// labelShop
|
||||||
|
//
|
||||||
|
this.labelShop.AutoSize = true;
|
||||||
|
this.labelShop.Location = new System.Drawing.Point(15, 11);
|
||||||
|
this.labelShop.Name = "labelShop";
|
||||||
|
this.labelShop.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.labelShop.Size = new System.Drawing.Size(57, 15);
|
||||||
|
this.labelShop.TabIndex = 10;
|
||||||
|
this.labelShop.Text = "Магазин:";
|
||||||
|
//
|
||||||
|
// FormShopSupply
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(371, 180);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.textBoxCount);
|
||||||
|
this.Controls.Add(this.comboBoxComputer);
|
||||||
|
this.Controls.Add(this.comboBoxShop);
|
||||||
|
this.Controls.Add(this.labelComputerCount);
|
||||||
|
this.Controls.Add(this.labelComputer);
|
||||||
|
this.Controls.Add(this.labelShop);
|
||||||
|
this.Name = "FormShopSupply";
|
||||||
|
this.Text = "FormShopSupply";
|
||||||
|
this.Load += new System.EventHandler(this.FormShopSupply_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSave;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private ComboBox comboBoxComputer;
|
||||||
|
private ComboBox comboBoxShop;
|
||||||
|
private Label labelComputerCount;
|
||||||
|
private Label labelComputer;
|
||||||
|
private Label labelShop;
|
||||||
|
}
|
||||||
|
}
|
125
ComputersShop/FormShopSupply.cs
Normal file
125
ComputersShop/FormShopSupply.cs
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
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 FormShopSupply : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComputerLogic _logicC;
|
||||||
|
private readonly IShopLogic _logicS;
|
||||||
|
public FormShopSupply(ILogger<FormShopSupply> logger, IComputerLogic logicC, IShopLogic logicS)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicC = logicC;
|
||||||
|
_logicS = logicS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormShopSupply_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Загрузка магазинов для пополнения");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logicS.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
comboBoxShop.DisplayMember = "Name";
|
||||||
|
comboBoxShop.ValueMember = "Id";
|
||||||
|
comboBoxShop.DataSource = list;
|
||||||
|
comboBoxShop.SelectedItem = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxComputer.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите компьютер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxShop.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Создание поставки");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicS.SupplyComputers(
|
||||||
|
new ShopSearchModel
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(comboBoxShop.SelectedValue),
|
||||||
|
Name = comboBoxShop.Text
|
||||||
|
},
|
||||||
|
new ComputerBindingModel
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(comboBoxComputer.SelectedValue),
|
||||||
|
ComputerName = comboBoxComputer.Text
|
||||||
|
},
|
||||||
|
Convert.ToInt32(textBoxCount.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/FormShopSupply.resx
Normal file
60
ComputersShop/FormShopSupply.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
120
ComputersShop/FormShops.Designer.cs
generated
Normal file
120
ComputersShop/FormShops.Designer.cs
generated
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormShops
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.buttonUpdate = 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.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonUpdate
|
||||||
|
//
|
||||||
|
this.buttonUpdate.Location = new System.Drawing.Point(551, 309);
|
||||||
|
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonUpdate.Name = "buttonUpdate";
|
||||||
|
this.buttonUpdate.Size = new System.Drawing.Size(133, 22);
|
||||||
|
this.buttonUpdate.TabIndex = 14;
|
||||||
|
this.buttonUpdate.Text = "Обновить";
|
||||||
|
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
this.buttonDelete.Location = new System.Drawing.Point(551, 64);
|
||||||
|
this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonDelete.Name = "buttonDelete";
|
||||||
|
this.buttonDelete.Size = new System.Drawing.Size(133, 22);
|
||||||
|
this.buttonDelete.TabIndex = 13;
|
||||||
|
this.buttonDelete.Text = "Удалить";
|
||||||
|
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
|
||||||
|
//
|
||||||
|
// buttonEdit
|
||||||
|
//
|
||||||
|
this.buttonEdit.Location = new System.Drawing.Point(551, 37);
|
||||||
|
this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonEdit.Name = "buttonEdit";
|
||||||
|
this.buttonEdit.Size = new System.Drawing.Size(133, 22);
|
||||||
|
this.buttonEdit.TabIndex = 12;
|
||||||
|
this.buttonEdit.Text = "Изменить";
|
||||||
|
this.buttonEdit.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(551, 11);
|
||||||
|
this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(133, 22);
|
||||||
|
this.buttonAdd.TabIndex = 11;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(12, 11);
|
||||||
|
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(491, 320);
|
||||||
|
this.dataGridView.TabIndex = 10;
|
||||||
|
//
|
||||||
|
// FormShops
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(695, 344);
|
||||||
|
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 = "FormShops";
|
||||||
|
this.Text = "FormShops";
|
||||||
|
this.Load += new System.EventHandler(this.FormShops_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonUpdate;
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonEdit;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
}
|
||||||
|
}
|
123
ComputersShop/FormShops.cs
Normal file
123
ComputersShop/FormShops.cs
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
public partial class FormShops : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _logic;
|
||||||
|
|
||||||
|
public FormShops(ILogger<FormComputers> logger, IShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormShops_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["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["ShopComputers"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Загрузка магазинов");
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазинов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||||
|
|
||||||
|
if (service is FormShop 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(FormShop));
|
||||||
|
|
||||||
|
if (service is FormShop 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 ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/FormShops.resx
Normal file
60
ComputersShop/FormShops.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -1,7 +1,17 @@
|
|||||||
|
using ComputerShopBusinessLogic.BusinessLogics;
|
||||||
|
using ComputerShopContracts.BusinessLogicsContracts;
|
||||||
|
using ComputerShopContracts.StoragesContracts;
|
||||||
|
using ComputerShopFileImplement.Implements;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
|
||||||
namespace ComputersShop
|
namespace ComputersShop
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
private static ServiceProvider? _serviceProvider;
|
||||||
|
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -11,7 +21,37 @@ namespace ComputersShop
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new Form1());
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
|
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||||
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddLogging(option =>
|
||||||
|
{
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddNLog("nlog.config");
|
||||||
|
});
|
||||||
|
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||||
|
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
|
services.AddTransient<IComputerStorage, ComputerStorage>();
|
||||||
|
services.AddTransient<IShopStorage, ShopStorage>();
|
||||||
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
services.AddTransient<IComputerLogic, ComputerLogic>();
|
||||||
|
services.AddTransient<IShopLogic, ShopLogic>();
|
||||||
|
services.AddTransient<FormMain>();
|
||||||
|
services.AddTransient<FormComponent>();
|
||||||
|
services.AddTransient<FormComponents>();
|
||||||
|
services.AddTransient<FormCreateOrder>();
|
||||||
|
services.AddTransient<FormComputer>();
|
||||||
|
services.AddTransient<FormComputerComponent>();
|
||||||
|
services.AddTransient<FormComputers>();
|
||||||
|
services.AddTransient<FormShop>();
|
||||||
|
services.AddTransient<FormShops>();
|
||||||
|
services.AddTransient<FormShopSupply>();
|
||||||
|
services.AddTransient<FormShopSell>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user