5 Commits

Author SHA1 Message Date
Marselchi
415df9030b залил 2024-06-17 21:08:40 +04:00
83143fffa4 Merge pull request 'накидываю первую' (#11) from lab1_hard into lab2_hard
Reviewed-on: #11
2024-06-17 20:35:35 +04:00
Marselchi
926a9fa37e Первая сложная типа 2024-04-21 17:13:29 +04:00
Marselchi
8820635bd5 Всё без форм 2024-04-07 20:30:19 +04:00
Marselchi
22eda2809c Фулл вторая лаба получается 2024-03-10 21:25:34 +04:00
38 changed files with 2845 additions and 26 deletions

View File

@@ -3,15 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.8.34408.163 VisualStudioVersion = 17.8.34408.163
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShipyardDataModels", "ShipyardDataModels\ShipyardDataModels.csproj", "{260F4D58-9D03-457C-B522-CE27360CDD31}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShipyardDataModels", "ShipyardDataModels\ShipyardDataModels.csproj", "{260F4D58-9D03-457C-B522-CE27360CDD31}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShipyardContracts", "ShipyardContracts\ShipyardContracts.csproj", "{C2E0380E-51D2-4B27-A385-459E91DC75CD}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShipyardContracts", "ShipyardContracts\ShipyardContracts.csproj", "{C2E0380E-51D2-4B27-A385-459E91DC75CD}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShipyardBusinessLogic", "ShipyardBusinessLogic\ShipyardBusinessLogic.csproj", "{652CC6F7-1097-46F4-B516-A010D6D747EA}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShipyardBusinessLogic", "ShipyardBusinessLogic\ShipyardBusinessLogic.csproj", "{652CC6F7-1097-46F4-B516-A010D6D747EA}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShipyardListImplement", "ShipyardListImplement\ShipyardListImplement.csproj", "{0F6E8B4C-CD20-4371-8316-E13FDA31AE57}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShipyardListImplement", "ShipyardListImplement\ShipyardListImplement.csproj", "{0F6E8B4C-CD20-4371-8316-E13FDA31AE57}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShipyardView", "ShipyardView\ShipyardView.csproj", "{BE881F13-7D8F-43B7-AA58-18BBE668FA79}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShipyardView", "ShipyardView\ShipyardView.csproj", "{BE881F13-7D8F-43B7-AA58-18BBE668FA79}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShipyardFileImplement", "ShipyardFileImplement\ShipyardFileImplement.csproj", "{804C4D1B-2098-4653-8CBA-F5931605A28D}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -39,6 +41,10 @@ Global
{BE881F13-7D8F-43B7-AA58-18BBE668FA79}.Debug|Any CPU.Build.0 = Debug|Any CPU {BE881F13-7D8F-43B7-AA58-18BBE668FA79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE881F13-7D8F-43B7-AA58-18BBE668FA79}.Release|Any CPU.ActiveCfg = Release|Any CPU {BE881F13-7D8F-43B7-AA58-18BBE668FA79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE881F13-7D8F-43B7-AA58-18BBE668FA79}.Release|Any CPU.Build.0 = Release|Any CPU {BE881F13-7D8F-43B7-AA58-18BBE668FA79}.Release|Any CPU.Build.0 = Release|Any CPU
{804C4D1B-2098-4653-8CBA-F5931605A28D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{804C4D1B-2098-4653-8CBA-F5931605A28D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{804C4D1B-2098-4653-8CBA-F5931605A28D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{804C4D1B-2098-4653-8CBA-F5931605A28D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -12,10 +12,14 @@ namespace ShipyardBusinessLogic.BusinessLogics
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage) private readonly IShopLogic _shopLogic;
private readonly IShipStorage _shipStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IShipStorage shipStorage)
{ {
_logger = logger; _logger = logger;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_shopLogic = shopLogic;
_shipStorage = shipStorage;
} }
public List<OrderViewModel>? ReadList(OrderSearchModel? model) public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{ {
@@ -72,13 +76,29 @@ namespace ShipyardBusinessLogic.BusinessLogics
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{ {
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (viewModel == null)
{
throw new ArgumentNullException(nameof(model));
}
if (viewModel.Status + 1 != newStatus) if (viewModel.Status + 1 != newStatus)
{ {
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false; return false;
} }
model.Status = newStatus; model.Status = newStatus;
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; if (model.Status == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now;
var ship = _shipStorage.GetElement(new() { Id = viewModel.ShipId });
if (ship == null)
{
throw new ArgumentNullException(nameof(ship));
}
if (!_shopLogic.AddShips(ship, viewModel.Count))
{
throw new Exception($"AddShips operation failed");
}
}
else else
{ {
model.DateImplement = viewModel.DateImplement; model.DateImplement = viewModel.DateImplement;
@@ -87,7 +107,7 @@ namespace ShipyardBusinessLogic.BusinessLogics
if (_orderStorage.Update(model) == null) if (_orderStorage.Update(model) == null)
{ {
model.Status--; model.Status--;
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Change status operation failed");
return false; return false;
} }
return true; return true;

View File

@@ -0,0 +1,206 @@
using Microsoft.Extensions.Logging;
using ShipyardContracts.BindingModels;
using ShipyardContracts.BusinessLogicsContracts;
using ShipyardContracts.SearchModels;
using ShipyardContracts.ViewModels;
using ShipyardContracts.StoragesContracts;
using ShipyardDataModels.Models;
namespace ShipyardBusinessLogic.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 List<ShopViewModel>? ReadList(ShopSearchModel? model)
{
_logger.LogInformation("ReadList. ShopName: {ShopName}. Id: {Id}", model?.ShopName, 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 ShopViewModel? ReadElement(ShopSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ShopName: {ShopName}. Id: {Id}", model.ShopName, 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 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);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
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.ShopName))
{
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
}
_logger.LogInformation("Shop. ShopName:{0}. Address:{1}. Id:{2}",
model.ShopName, model.Address, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
{
ShopName = model.ShopName
});
if (element != null && element.Id != model.Id && element.ShopName == model.ShopName)
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool AddShip(ShopSearchModel model, IShipModel ship, int count)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (count <= 0)
{
return false;
throw new ArgumentException("Количество кораблей должно быть больше 0", nameof(count));
}
_logger.LogInformation("AddShip. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id);
var element = _shopStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("AddShip element not found");
return false;
}
if (element.Capacity - element.ShopShips.Select(x => x.Value.Item2).Sum() < count)
{
throw new ArgumentNullException("В магазине не хватает места", nameof(count));
}
if (element.ShopShips.TryGetValue(ship.Id, out var pair))
{
element.ShopShips[ship.Id] = (ship, count + pair.Item2);
_logger.LogInformation("AddShip. Added {count} {ship} to '{ShopName}' shop",
count, ship.ShipName, element.ShopName);
}
else
{
element.ShopShips[ship.Id] = (ship, count);
_logger.LogInformation("AddShip. Added {count} new ship {ship} to '{ShopName}' shop",
count, ship.ShipName, element.ShopName);
}
_shopStorage.Update(new()
{
Id = element.Id,
Address = element.Address,
ShopName = element.ShopName,
DateOpen = element.DateOpen,
Capacity = element.Capacity,
ShopShips = element.ShopShips
});
return true;
}
public bool AddShips(IShipModel model, int count)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (count <= 0)
{
throw new ArgumentException("Количество кораблей должно быть больше 0", nameof(count));
}
_logger.LogInformation("AddShips. ShopName:{ShopName}. Id:{Id}", model.ShipName, model.Id);
var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.ShopShips.Select(x => x.Value.Item2).Sum()).Sum();
if (allFreeQuantity < count)
{
_logger.LogWarning("AddTravels operation failed.");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
int freeQuantity = shop.Capacity - shop.ShopShips.Select(x => x.Value.Item2).Sum();
if (freeQuantity <= 0)
{
continue;
}
if (freeQuantity < count)
{
if (!AddShip(new() { Id = shop.Id }, model, freeQuantity))
{
_logger.LogWarning("AddShips operation failed.");
return false;
}
count -= freeQuantity;
}
else
{
if (!AddShip(new() { Id = shop.Id }, model, count))
{
_logger.LogWarning("AddShips operation failed.");
return false;
}
count = 0;
}
if (count == 0)
{
return true;
}
}
_logger.LogWarning("AddShips operation failed.");
return false;
}
public bool SellShips(IShipModel model, int count)
{
return _shopStorage.SellShips(model, count);
}
}
}

View File

@@ -0,0 +1,14 @@
using ShipyardDataModels.Models;
namespace ShipyardContracts.BindingModels
{
public class ShopBindingModel : IShopModel
{
public string ShopName { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime DateOpen { get; set; } = DateTime.Now;
public int Capacity { get; set; }
public Dictionary<int, (IShipModel, int)> ShopShips { get; set; } = new();
public int Id { get; set; }
}
}

View File

@@ -0,0 +1,19 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.SearchModels;
using ShipyardContracts.ViewModels;
using ShipyardDataModels.Models;
namespace ShipyardContracts.BusinessLogicsContracts
{
public interface IShopLogic
{
List<ShopViewModel>? ReadList(ShopSearchModel? model);
ShopViewModel? ReadElement(ShopSearchModel model);
bool Create(ShopBindingModel model);
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool AddShip(ShopSearchModel model, IShipModel ship, int count);
bool AddShips(IShipModel model, int count);
bool SellShips(IShipModel model, int count);
}
}

View File

@@ -0,0 +1,8 @@
namespace ShipyardContracts.SearchModels
{
public class ShopSearchModel
{
public int? Id { get; set; }
public string? ShopName { get; set; }
}
}

View File

@@ -0,0 +1,18 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.SearchModels;
using ShipyardContracts.ViewModels;
using ShipyardDataModels.Models;
namespace ShipyardContracts.StoragesContracts
{
public interface IShopStorage
{
List<ShopViewModel> GetFullList();
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
ShopViewModel? GetElement(ShopSearchModel model);
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool SellShips(IShipModel model, int count);
}
}

View File

@@ -0,0 +1,21 @@
using ShipyardDataModels.Models;
using System.ComponentModel;
namespace ShipyardContracts.ViewModels
{
public class ShopViewModel : IShopModel
{
[DisplayName("Название магазина")]
public string ShopName { get; set; } = string.Empty;
[DisplayName("Адрес магазина")]
public string Address { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
public DateTime DateOpen { get; set; } = DateTime.Now;
[DisplayName("Вместимость магазина")]
public int Capacity { get; set; }
public Dictionary<int, (IShipModel, int)> ShopShips { get; set; } = new();
public int Id { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
namespace ShipyardDataModels.Models
{
public interface IShopModel : IId
{
string ShopName { get; }
string Address { get; }
DateTime DateOpen { get; }
public int Capacity { get; }
Dictionary<int, (IShipModel, int)> ShopShips { get; }
}
}

View File

@@ -0,0 +1,55 @@
using ShipyardFileImplement.Models;
using System.Xml.Linq;
namespace ShipyardFileImplement
{
public class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string DetailFileName = "Detail.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string ShipFileName = "Ship.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Detail> Details { get; private set; }
public List<Order> Orders { get; private set; }
public List<Ship> Ships { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
instance = new DataFileSingleton();
}
return instance;
}
public void SaveDetails() => SaveData(Details, DetailFileName, "Details", x => x.GetXElement);
public void SaveShips() => SaveData(Ships, ShipFileName, "Ships", 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()
{
Details = LoadData(DetailFileName, "Detail", x => Detail.Create(x)!)!;
Ships = LoadData(ShipFileName, "Ship", x => Ship.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);
}
}
}
}

View File

@@ -0,0 +1,81 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.StoragesContracts;
using ShipyardContracts.ViewModels;
using ShipyardContracts.SearchModels;
using ShipyardFileImplement.Models;
namespace ShipyardFileImplement.Implements
{
public class DetailStorage : IDetailStorage
{
private readonly DataFileSingleton source;
public DetailStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<DetailViewModel> GetFullList()
{
return source.Details.Select(x => x.GetViewModel).ToList();
}
public List<DetailViewModel> GetFilteredList(DetailSearchModel model)
{
if (string.IsNullOrEmpty(model.DetailName))
{
return new();
}
return source.Details
.Where(x => x.DetailName.Contains(model.DetailName))
.Select(x => x.GetViewModel)
.ToList();
}
public DetailViewModel? GetElement(DetailSearchModel model)
{
if (string.IsNullOrEmpty(model.DetailName) && !model.Id.HasValue)
{
return null;
}
return source.Details
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.DetailName) && x.DetailName ==
model.DetailName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public DetailViewModel? Insert(DetailBindingModel model)
{
model.Id = source.Details.Count > 0 ? source.Details.Max(x => x.Id) + 1 : 1;
var newComponent = Detail.Create(model);
if (newComponent == null)
{
return null;
}
source.Details.Add(newComponent);
source.SaveDetails();
return newComponent.GetViewModel;
}
public DetailViewModel? Update(DetailBindingModel model)
{
var component = source.Details.FirstOrDefault(x => x.Id ==
model.Id);
if (component == null)
{
return null;
}
component.Update(model);
source.SaveDetails();
return component.GetViewModel;
}
public DetailViewModel? Delete(DetailBindingModel model)
{
var element = source.Details.FirstOrDefault(x => x.Id ==
model.Id);
if (element != null)
{
source.Details.Remove(element);
source.SaveDetails();
return element.GetViewModel;
}
return null;
}
}
}

View File

@@ -0,0 +1,88 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.StoragesContracts;
using ShipyardContracts.ViewModels;
using ShipyardContracts.SearchModels;
using ShipyardFileImplement.Models;
namespace ShipyardFileImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton source;
public OrderStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
return source.Orders.Select(x => GetViewModel(x)).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return source.Orders.FirstOrDefault(x =>
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var ship = source.Ships.FirstOrDefault(x => x.Id == order.ShipId);
if (ship != null)
{
viewModel.ShipName = ship.ShipName;
}
return viewModel;
}
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 GetViewModel(newOrder);
}
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 GetViewModel(order);
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Orders.Remove(element);
source.SaveOrders();
return GetViewModel(element);
}
return null;
}
}
}

View File

@@ -0,0 +1,74 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.StoragesContracts;
using ShipyardContracts.ViewModels;
using ShipyardContracts.SearchModels;
using ShipyardFileImplement.Models;
namespace ShipyardFileImplement.Implements
{
public class ShipStorage : IShipStorage
{
private readonly DataFileSingleton source;
public ShipStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ShipViewModel> GetFullList()
{
return source.Ships.Select(x => x.GetViewModel).ToList();
}
public List<ShipViewModel> GetFilteredList(ShipSearchModel model)
{
if (string.IsNullOrEmpty(model.ShipName))
{
return new();
}
return source.Ships.Where(x =>
x.ShipName.Contains(model.ShipName)).Select(x => x.GetViewModel).ToList();
}
public ShipViewModel? GetElement(ShipSearchModel model)
{
if (string.IsNullOrEmpty(model.ShipName) && !model.Id.HasValue)
{
return null;
}
return source.Ships.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ShipName) && x.ShipName ==
model.ShipName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ShipViewModel? Insert(ShipBindingModel model)
{
model.Id = source.Ships.Count > 0 ? source.Ships.Max(x => x.Id) + 1 : 1;
var newShip = Ship.Create(model);
if (newShip == null)
{
return null;
}
source.Ships.Add(newShip);
source.SaveShips();
return newShip.GetViewModel;
}
public ShipViewModel? Update(ShipBindingModel model)
{
var ship = source.Ships.FirstOrDefault(x => x.Id == model.Id);
if (ship == null)
{
return null;
}
ship.Update(model);
source.SaveShips();
return ship.GetViewModel;
}
public ShipViewModel? Delete(ShipBindingModel model)
{
var element = source.Ships.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Ships.Remove(element);
source.SaveShips();
return element.GetViewModel;
}
return null;
}
}
}

View File

@@ -0,0 +1,119 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.SearchModels;
using ShipyardContracts.StoragesContracts;
using ShipyardContracts.ViewModels;
using ShipyardFileImplement.Models;
using ShipyardDataModels.Models;
namespace ShipyardFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton source;
public ShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
return source.Shops
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName))
{
return new();
}
return source.Shops
.Where(x => x.ShopName.Contains(model.ShopName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<ShopViewModel> GetFullList()
{
return source.Shops.Select(x => x.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)
{
source.Shops.Remove(shop);
source.SaveShops();
return shop.GetViewModel;
}
return null;
}
public bool SellShips(IShipModel model, int count)
{
int availableQuantity = source.Shops.Select(x => x.ShopShips.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum();
if (availableQuantity < count)
{
return false;
}
var shops = source.Shops.Where(x => x.ShopShips.ContainsKey(model.Id));
foreach (var shop in shops)
{
int countInCurrentShop = shop.ShopShips[model.Id].Item2;
if (countInCurrentShop <= count)
{
shop.ShopShips[model.Id] = (shop.ShopShips[model.Id].Item1, 0);
count -= countInCurrentShop;
}
else
{
shop.ShopShips[model.Id] = (shop.ShopShips[model.Id].Item1, countInCurrentShop - count);
count = 0;
}
Update(new ShopBindingModel
{
Id = shop.Id,
ShopName = shop.ShopName,
Address = shop.Address,
DateOpen = shop.DateOpen,
ShopShips = shop.ShopShips,
Capacity = shop.Capacity
});
if (count == 0)
{
return true;
}
}
return false;
}
}
}

View File

@@ -0,0 +1,60 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.ViewModels;
using ShipyardDataModels.Models;
using System.Xml.Linq;
namespace ShipyardFileImplement.Models
{
public class Detail : IDetailModel
{
public int Id { get; private set; }
public string DetailName { get; private set; } = string.Empty;
public double Cost { get; set; }
public static Detail? Create(DetailBindingModel model)
{
if (model == null)
{
return null;
}
return new Detail()
{
Id = model.Id,
DetailName = model.DetailName,
Cost = model.Cost
};
}
public static Detail? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Detail()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
DetailName = element.Element("DetailName")!.Value,
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
};
}
public void Update(DetailBindingModel model)
{
if (model == null)
{
return;
}
DetailName = model.DetailName;
Cost = model.Cost;
}
public DetailViewModel GetViewModel => new()
{
Id = Id,
DetailName = DetailName,
Cost = Cost
};
public XElement GetXElement => new("Detail",
new XAttribute("Id", Id),
new XElement("DetailName", DetailName),
new XElement("Cost", Cost.ToString()));
}
}

View File

@@ -0,0 +1,91 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.ViewModels;
using ShipyardDataModels.Enums;
using ShipyardDataModels.Models;
using System.Xml.Linq;
namespace ShipyardFileImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int ShipId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
ShipId = model.ShipId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
};
}
public static Order? Create(XElement element)
{
if (element == null)
{
return null;
}
var order = new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShipId = Convert.ToInt32(element.Element("ShipId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
};
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
order.DateImplement = dateImpl;
if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status))
{
return null;
}
order.Status = status;
return order;
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
ShipId = ShipId,
Count = Count,
Sum = Sum,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,
Status = Status,
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("ShipId", ShipId),
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()));
}
}

View File

@@ -0,0 +1,80 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.ViewModels;
using ShipyardDataModels.Models;
using System.Xml.Linq;
namespace ShipyardFileImplement.Models
{
public class Ship : IShipModel
{
public int Id { get; private set; }
public string ShipName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Details { get; private set; } = new();
private Dictionary<int, (IDetailModel, int)>? _shipDetails = null;
public Dictionary<int, (IDetailModel, int)> ShipDetails
{
get
{
if (_shipDetails == null)
{
var source = DataFileSingleton.GetInstance();
_shipDetails = Details.ToDictionary(x => x.Key, y => ((source.Details.FirstOrDefault(z => z.Id == y.Key) as IDetailModel)!, y.Value));
}
return _shipDetails;
}
}
public static Ship? Create(ShipBindingModel model)
{
if (model == null)
{
return null;
}
return new Ship()
{
Id = model.Id,
ShipName = model.ShipName,
Price = model.Price,
Details = model.ShipDetails.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Ship? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Ship()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShipName = element.Element("ShipName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Details = element.Element("ShipDetails")!.Elements("ShipDetail").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(ShipBindingModel model)
{
if (model == null)
{
return;
}
ShipName = model.ShipName;
Price = model.Price;
Details = model.ShipDetails.ToDictionary(x => x.Key, x => x.Value.Item2);
_shipDetails = null;
}
public ShipViewModel GetViewModel => new()
{
Id = Id,
ShipName = ShipName,
Price = Price,
ShipDetails = ShipDetails
};
public XElement GetXElement => new("Ship",
new XAttribute("Id", Id),
new XElement("ShipName", ShipName),
new XElement("Price", Price.ToString()),
new XElement("ShipDetails", ShipDetails.Select(x => new XElement("ShipDetails",
new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()));
}
}

View File

@@ -0,0 +1,103 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.ViewModels;
using ShipyardDataModels.Models;
using System.Xml.Linq;
namespace ShipyardFileImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime DateOpen { get; private set; }
public int Capacity { get; private set; }
public Dictionary<int, int> ShipsCount = new();
public Dictionary<int, (IShipModel, int)>? _ships = null;
public Dictionary<int, (IShipModel, int)> ShopShips
{
get
{
if (_ships == null)
{
var source = DataFileSingleton.GetInstance();
_ships = ShipsCount.ToDictionary(
x => x.Key,
y => ((source.Ships.FirstOrDefault(z => z.Id == y.Key) as IShipModel)!,
y.Value)
);
}
return _ships;
}
}
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateOpen = model.DateOpen,
Capacity = model.Capacity,
ShipsCount = model.ShopShips.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),
ShopName = element.Element("ShopName")!.Value,
Address = element.Element("Address")!.Value,
DateOpen = Convert.ToDateTime(element.Element("DateOpening")!.Value),
Capacity = Convert.ToInt32(element.Element("Capacity")!.Value),
ShipsCount = element.Element("Ships")!.Elements("Ship")
.ToDictionary(
x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Address = model.Address;
DateOpen = model.DateOpen;
Capacity = model.Capacity;
ShipsCount = model.ShopShips.ToDictionary(x => x.Key, x => x.Value.Item2);
_ships = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
DateOpen = DateOpen,
Capacity = Capacity,
ShopShips = ShopShips
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Address", Address),
new XElement("DateOpening", DateOpen.ToString()),
new XElement("Capacity", Capacity.ToString()),
new XElement("Ships", ShipsCount.Select(x =>
new XElement("Ship",
new XElement("Key", x.Key),
new XElement("Value", x.Value)))
.ToArray()));
}
}

View File

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

View File

@@ -8,13 +8,15 @@ namespace ShipyardListImplement
public List<Detail> Details { get; set; } public List<Detail> Details { get; set; }
public List<Order> Orders { get; set; } public List<Order> Orders { get; set; }
public List<Ship> Ships { get; set; } public List<Ship> Ships { get; set; }
private DataListSingleton() public List<Shop> Shops { get; set; }
{ private DataListSingleton()
Details = new List<Detail>(); {
Orders = new List<Order>(); Details = new List<Detail>();
Ships = new List<Ship>(); Orders = new List<Order>();
} Ships = new List<Ship>();
public static DataListSingleton GetInstance() Shops = new List<Shop>();
}
public static DataListSingleton GetInstance()
{ {
if (_instance == null) if (_instance == null)
{ {

View File

@@ -0,0 +1,113 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.SearchModels;
using ShipyardContracts.StoragesContracts;
using ShipyardContracts.ViewModels;
using ShipyardDataModels.Models;
using ShipyardListImplement.Models;
namespace ShipyardListImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataListSingleton _source;
public ShopStorage()
{
_source = DataListSingleton.GetInstance();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
foreach (var shop in _source.Shops)
{
if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (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.ShopName))
{
return result;
}
foreach (var shop in _source.Shops)
{
if (shop.ShopName.Contains(model.ShopName))
{
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 SellShips(IShipModel model, int count)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,55 @@
using ShipyardContracts.BindingModels;
using ShipyardContracts.ViewModels;
using ShipyardDataModels.Models;
namespace ShipyardListImplement.Models
{
public class Shop : IShopModel
{
public string ShopName { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime DateOpen { get; set; }
public int Capacity { get; private set; }
public int Id { get; set; }
public Dictionary<int, (IShipModel, int)> ShopShips { get; private set; } = new Dictionary<int, (IShipModel, int)>();
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateOpen = model.DateOpen,
ShopShips = model.ShopShips
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Address = model.Address;
DateOpen = model.DateOpen;
ShopShips = model.ShopShips;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
DateOpen = DateOpen,
ShopShips = ShopShips
};
}
}

View File

@@ -0,0 +1,145 @@
namespace ShipyardView
{
partial class FormAddShip
{
/// <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.labelShop = new System.Windows.Forms.Label();
this.labelShip = new System.Windows.Forms.Label();
this.labelCount = new System.Windows.Forms.Label();
this.comboBoxShop = new System.Windows.Forms.ComboBox();
this.comboBoxShip = new System.Windows.Forms.ComboBox();
this.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
this.ButtonSave = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
this.SuspendLayout();
//
// labelShop
//
this.labelShop.AutoSize = true;
this.labelShop.Location = new System.Drawing.Point(12, 31);
this.labelShop.Name = "labelShop";
this.labelShop.Size = new System.Drawing.Size(69, 20);
this.labelShop.TabIndex = 0;
this.labelShop.Text = "Магазин";
//
// labelShip
//
this.labelShip.AutoSize = true;
this.labelShip.Location = new System.Drawing.Point(12, 76);
this.labelShip.Name = "labelShip";
this.labelShip.Size = new System.Drawing.Size(69, 20);
this.labelShip.TabIndex = 1;
this.labelShip.Text = "Корабль";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(12, 127);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(90, 20);
this.labelCount.TabIndex = 2;
this.labelCount.Text = "Количество";
//
// comboBoxShop
//
this.comboBoxShop.FormattingEnabled = true;
this.comboBoxShop.Location = new System.Drawing.Point(111, 31);
this.comboBoxShop.Name = "comboBoxShop";
this.comboBoxShop.Size = new System.Drawing.Size(369, 28);
this.comboBoxShop.TabIndex = 3;
//
// comboBoxShip
//
this.comboBoxShip.FormattingEnabled = true;
this.comboBoxShip.Location = new System.Drawing.Point(111, 76);
this.comboBoxShip.Name = "comboBoxShip";
this.comboBoxShip.Size = new System.Drawing.Size(369, 28);
this.comboBoxShip.TabIndex = 4;
//
// numericUpDownCount
//
this.numericUpDownCount.Location = new System.Drawing.Point(111, 120);
this.numericUpDownCount.Name = "numericUpDownCount";
this.numericUpDownCount.Size = new System.Drawing.Size(369, 27);
this.numericUpDownCount.TabIndex = 5;
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(279, 167);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(94, 29);
this.ButtonSave.TabIndex = 6;
this.ButtonSave.Text = "Сохранить";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(386, 167);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(94, 29);
this.ButtonCancel.TabIndex = 7;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormAddShip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(492, 207);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.numericUpDownCount);
this.Controls.Add(this.comboBoxShip);
this.Controls.Add(this.comboBoxShop);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelShip);
this.Controls.Add(this.labelShop);
this.Name = "FormAddShip";
this.Text = "Добавление корабля в магазин";
this.Load += new System.EventHandler(this.FormAddShip_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelShop;
private Label labelShip;
private Label labelCount;
private ComboBox comboBoxShop;
private ComboBox comboBoxShip;
private NumericUpDown numericUpDownCount;
private Button ButtonSave;
private Button ButtonCancel;
}
}

View File

@@ -0,0 +1,108 @@
using Microsoft.Extensions.Logging;
using ShipyardContracts.BusinessLogicsContracts;
using ShipyardContracts.SearchModels;
namespace ShipyardView
{
public partial class FormAddShip : Form
{
private readonly ILogger _logger;
private readonly IShipLogic _logicShip;
private readonly IShopLogic _logicShop;
public FormAddShip(ILogger<FormAddShip> logger, IShipLogic logicShip, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicShip = logicShip;
_logicShop = logicShop;
}
private void FormAddShip_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка списка кораблей для пополнения");
try
{
var list = _logicShip.ReadList(null);
if (list != null)
{
comboBoxShip.DisplayMember = "ShipName";
comboBoxShip.ValueMember = "Id";
comboBoxShip.DataSource = list;
comboBoxShip.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка кораблей");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Загрузка списка магазинов для пополнения");
try
{
var list = _logicShop.ReadList(null);
if (list != null)
{
comboBoxShop.DisplayMember = "ShopName";
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(numericUpDownCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxShip.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 = _logicShop.AddShip(new ShopSearchModel
{
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
},
_logicShip.ReadElement(new ShipSearchModel()
{
Id = Convert.ToInt32(comboBoxShip.SelectedValue)
})!, Convert.ToInt32(numericUpDownCount.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();
}
}
}

View File

@@ -0,0 +1,120 @@
<?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>

View File

@@ -33,12 +33,15 @@
toolStripMenu = new ToolStripDropDownButton(); toolStripMenu = new ToolStripDropDownButton();
деталиToolStripMenuItem = new ToolStripMenuItem(); деталиToolStripMenuItem = new ToolStripMenuItem();
кораблиToolStripMenuItem = new ToolStripMenuItem(); кораблиToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView(); dataGridView = new DataGridView();
buttonCreateOrder = new Button(); buttonCreateOrder = new Button();
buttonTakeInWork = new Button(); buttonTakeInWork = new Button();
buttonReady = new Button(); buttonReady = new Button();
buttonIssue = new Button(); buttonIssue = new Button();
buttonRefresh = new Button(); buttonRefresh = new Button();
buttonAddShip = new Button();
buttonSellShip = new Button();
toolStrip.SuspendLayout(); toolStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
@@ -56,7 +59,7 @@
// toolStripMenu // toolStripMenu
// //
toolStripMenu.DisplayStyle = ToolStripItemDisplayStyle.Text; toolStripMenu.DisplayStyle = ToolStripItemDisplayStyle.Text;
toolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { деталиToolStripMenuItem, кораблиToolStripMenuItem }); toolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { деталиToolStripMenuItem, кораблиToolStripMenuItem, магазиныToolStripMenuItem });
toolStripMenu.Image = (Image)resources.GetObject("toolStripMenu.Image"); toolStripMenu.Image = (Image)resources.GetObject("toolStripMenu.Image");
toolStripMenu.ImageTransparentColor = Color.Magenta; toolStripMenu.ImageTransparentColor = Color.Magenta;
toolStripMenu.Name = "toolStripMenu"; toolStripMenu.Name = "toolStripMenu";
@@ -66,17 +69,24 @@
// деталиToolStripMenuItem // деталиToolStripMenuItem
// //
деталиToolStripMenuItem.Name = еталиToolStripMenuItem"; деталиToolStripMenuItem.Name = еталиToolStripMenuItem";
деталиToolStripMenuItem.Size = new Size(153, 26); деталиToolStripMenuItem.Size = new Size(224, 26);
деталиToolStripMenuItem.Text = "Детали"; деталиToolStripMenuItem.Text = "Детали";
деталиToolStripMenuItem.Click += ДеталиToolStripMenuItem_Click; деталиToolStripMenuItem.Click += ДеталиToolStripMenuItem_Click;
// //
// кораблиToolStripMenuItem // кораблиToolStripMenuItem
// //
кораблиToolStripMenuItem.Name = ораблиToolStripMenuItem"; кораблиToolStripMenuItem.Name = ораблиToolStripMenuItem";
кораблиToolStripMenuItem.Size = new Size(153, 26); кораблиToolStripMenuItem.Size = new Size(224, 26);
кораблиToolStripMenuItem.Text = "Корабли"; кораблиToolStripMenuItem.Text = "Корабли";
кораблиToolStripMenuItem.Click += КораблиToolStripMenuItem_Click; кораблиToolStripMenuItem.Click += КораблиToolStripMenuItem_Click;
// //
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(224, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click;
//
// dataGridView // dataGridView
// //
dataGridView.AllowUserToAddRows = false; dataGridView.AllowUserToAddRows = false;
@@ -90,7 +100,7 @@
dataGridView.RowHeadersWidth = 51; dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29; dataGridView.RowTemplate.Height = 29;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(984, 366); dataGridView.Size = new Size(984, 417);
dataGridView.TabIndex = 1; dataGridView.TabIndex = 1;
// //
// buttonCreateOrder // buttonCreateOrder
@@ -135,7 +145,7 @@
// //
// buttonRefresh // buttonRefresh
// //
buttonRefresh.Location = new Point(1032, 303); buttonRefresh.Location = new Point(1032, 350);
buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(178, 29); buttonRefresh.Size = new Size(178, 29);
buttonRefresh.TabIndex = 6; buttonRefresh.TabIndex = 6;
@@ -143,11 +153,33 @@
buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRef_Click; buttonRefresh.Click += ButtonRef_Click;
// //
// buttonAddShip
//
buttonAddShip.Location = new Point(1032, 293);
buttonAddShip.Name = "buttonAddShip";
buttonAddShip.Size = new Size(178, 29);
buttonAddShip.TabIndex = 7;
buttonAddShip.Text = "Добавить корабль";
buttonAddShip.UseVisualStyleBackColor = true;
buttonAddShip.Click += ButtonAddShip_Click;
//
// buttonSellShip
//
buttonSellShip.Location = new Point(1032, 396);
buttonSellShip.Name = "buttonSellShip";
buttonSellShip.Size = new Size(178, 29);
buttonSellShip.TabIndex = 8;
buttonSellShip.Text = "Продать корабль";
buttonSellShip.UseVisualStyleBackColor = true;
buttonSellShip.Click += ButtonSellShip_Click;
//
// FormMain // FormMain
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1251, 391); ClientSize = new Size(1251, 446);
Controls.Add(buttonSellShip);
Controls.Add(buttonAddShip);
Controls.Add(buttonRefresh); Controls.Add(buttonRefresh);
Controls.Add(buttonIssue); Controls.Add(buttonIssue);
Controls.Add(buttonReady); Controls.Add(buttonReady);
@@ -177,5 +209,8 @@
private ToolStripDropDownButton toolStripMenu; private ToolStripDropDownButton toolStripMenu;
private ToolStripMenuItem деталиToolStripMenuItem; private ToolStripMenuItem деталиToolStripMenuItem;
private ToolStripMenuItem кораблиToolStripMenuItem; private ToolStripMenuItem кораблиToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button buttonAddShip;
private Button buttonSellShip;
} }
} }

View File

@@ -132,6 +132,33 @@ namespace ShipyardView
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
}
private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void ButtonAddShip_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddShip));
if (service is FormAddShip form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonSellShip_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellShips));
if (service is FormSellShips form)
{
form.ShowDialog();
LoadData();
}
} }
private void ButtonRef_Click(object sender, EventArgs e) private void ButtonRef_Click(object sender, EventArgs e)
{ {

View File

@@ -0,0 +1,120 @@
namespace ShipyardView
{
partial class FormSellShips
{
/// <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.comboBoxShips = new System.Windows.Forms.ComboBox();
this.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
this.labelShip = new System.Windows.Forms.Label();
this.labelCount = new System.Windows.Forms.Label();
this.ButtonSave = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
this.SuspendLayout();
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(266, 153);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(94, 29);
this.ButtonCancel.TabIndex = 1;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// comboBoxShips
//
this.comboBoxShips.FormattingEnabled = true;
this.comboBoxShips.Location = new System.Drawing.Point(144, 38);
this.comboBoxShips.Name = "comboBoxShips";
this.comboBoxShips.Size = new System.Drawing.Size(216, 28);
this.comboBoxShips.TabIndex = 2;
//
// numericUpDownCount
//
this.numericUpDownCount.Location = new System.Drawing.Point(144, 102);
this.numericUpDownCount.Name = "numericUpDownCount";
this.numericUpDownCount.Size = new System.Drawing.Size(216, 27);
this.numericUpDownCount.TabIndex = 3;
//
// labelShip
//
this.labelShip.AutoSize = true;
this.labelShip.Location = new System.Drawing.Point(34, 38);
this.labelShip.Name = "labelShip";
this.labelShip.Size = new System.Drawing.Size(69, 20);
this.labelShip.TabIndex = 4;
this.labelShip.Text = "Корабль";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(34, 109);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(90, 20);
this.labelCount.TabIndex = 5;
this.labelCount.Text = "Количество";
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(144, 153);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(94, 29);
this.ButtonSave.TabIndex = 6;
this.ButtonSave.Text = "Сохранить";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// FormSellShips
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(373, 194);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelShip);
this.Controls.Add(this.numericUpDownCount);
this.Controls.Add(this.comboBoxShips);
this.Controls.Add(this.ButtonCancel);
this.Name = "FormSellShips";
this.Text = "Продажа кораблей";
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button ButtonCancel;
private ComboBox comboBoxShips;
private NumericUpDown numericUpDownCount;
private Label labelShip;
private Label labelCount;
private Button ButtonSave;
}
}

View File

@@ -0,0 +1,77 @@
using Microsoft.Extensions.Logging;
using ShipyardContracts.BusinessLogicsContracts;
using ShipyardContracts.ViewModels;
namespace ShipyardView
{
public partial class FormSellShips : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _shopLogic;
private readonly IShipLogic _shipLogic;
private readonly List<ShipViewModel>? _listShip;
public FormSellShips(ILogger<FormSellShips> logger, IShopLogic shopLogic, IShipLogic shipLogic)
{
InitializeComponent();
_logger = logger;
_shopLogic = shopLogic;
_shipLogic = shipLogic;
_listShip = shipLogic.ReadList(null);
if (_listShip != null)
{
comboBoxShips.DisplayMember = "ShipName";
comboBoxShips.ValueMember = "Id";
comboBoxShips.DataSource = _listShip;
comboBoxShips.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxShips.SelectedValue == null)
{
MessageBox.Show("Выберите корабль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(numericUpDownCount.Text))
{
MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Продажа поездок");
try
{
var ship = _shipLogic.ReadElement(new()
{
Id = (int)comboBoxShips.SelectedValue
});
if (ship == null)
{
throw new Exception("Корабль не найден. Дополнительная информация в логах.");
}
var operationResult = _shopLogic.SellShips(
model: ship,
count: (int)numericUpDownCount.Value
);
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();
}
}
}

View File

@@ -0,0 +1,120 @@
<?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>

213
Shipyard/ShipyardView/FormShop.Designer.cs generated Normal file
View File

@@ -0,0 +1,213 @@
namespace ShipyardView
{
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()
{
labelShop = new Label();
labelAddress = new Label();
labelDate = new Label();
textBoxName = new TextBox();
textBoxAddress = new TextBox();
dateTimePickerDateOpen = new DateTimePicker();
dataGridView = new DataGridView();
ID = new DataGridViewTextBoxColumn();
ShipName = new DataGridViewTextBoxColumn();
Count = new DataGridViewTextBoxColumn();
ButtonSave = new Button();
ButtonCancel = new Button();
numericUpDownCapacity = new NumericUpDown();
labelCapacity = new Label();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit();
SuspendLayout();
//
// labelShop
//
labelShop.AutoSize = true;
labelShop.Location = new Point(12, 21);
labelShop.Name = "labelShop";
labelShop.Size = new Size(69, 20);
labelShop.TabIndex = 0;
labelShop.Text = "Магазин";
//
// labelAddress
//
labelAddress.AutoSize = true;
labelAddress.Location = new Point(195, 21);
labelAddress.Name = "labelAddress";
labelAddress.Size = new Size(51, 20);
labelAddress.TabIndex = 1;
labelAddress.Text = "Адрес";
//
// labelDate
//
labelDate.AutoSize = true;
labelDate.Location = new Point(474, 21);
labelDate.Name = "labelDate";
labelDate.Size = new Size(110, 20);
labelDate.TabIndex = 2;
labelDate.Text = "Дата открытия";
//
// textBoxName
//
textBoxName.Location = new Point(12, 44);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(160, 27);
textBoxName.TabIndex = 3;
//
// textBoxAddress
//
textBoxAddress.Location = new Point(195, 44);
textBoxAddress.Name = "textBoxAddress";
textBoxAddress.Size = new Size(246, 27);
textBoxAddress.TabIndex = 4;
//
// dateTimePickerDateOpen
//
dateTimePickerDateOpen.Location = new Point(474, 44);
dateTimePickerDateOpen.Name = "dateTimePickerDateOpen";
dateTimePickerDateOpen.Size = new Size(195, 27);
dateTimePickerDateOpen.TabIndex = 5;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ShipName, Count });
dataGridView.Location = new Point(12, 77);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(870, 370);
dataGridView.TabIndex = 6;
//
// ID
//
ID.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ID.HeaderText = "ID";
ID.MinimumWidth = 6;
ID.Name = "ID";
ID.Visible = false;
//
// ShipName
//
ShipName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ShipName.HeaderText = "Название корабля";
ShipName.MinimumWidth = 6;
ShipName.Name = "ShipName";
//
// Count
//
Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
Count.HeaderText = "Количество";
Count.MinimumWidth = 6;
Count.Name = "Count";
//
// ButtonSave
//
ButtonSave.Location = new Point(652, 453);
ButtonSave.Name = "ButtonSave";
ButtonSave.Size = new Size(111, 29);
ButtonSave.TabIndex = 7;
ButtonSave.Text = "Сохранить";
ButtonSave.UseVisualStyleBackColor = true;
ButtonSave.Click += ButtonSave_Click;
//
// ButtonCancel
//
ButtonCancel.Location = new Point(788, 453);
ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Size = new Size(94, 29);
ButtonCancel.TabIndex = 8;
ButtonCancel.Text = "Отмена";
ButtonCancel.UseVisualStyleBackColor = true;
ButtonCancel.Click += ButtonCancel_Click;
//
// numericUpDownCapacity
//
numericUpDownCapacity.Location = new Point(701, 44);
numericUpDownCapacity.Name = "numericUpDownCapacity";
numericUpDownCapacity.Size = new Size(181, 27);
numericUpDownCapacity.TabIndex = 9;
//
// labelCapacity
//
labelCapacity.AutoSize = true;
labelCapacity.Location = new Point(701, 21);
labelCapacity.Name = "labelCapacity";
labelCapacity.Size = new Size(100, 20);
labelCapacity.TabIndex = 10;
labelCapacity.Text = "Вместимость";
//
// FormShop
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(906, 494);
Controls.Add(labelCapacity);
Controls.Add(numericUpDownCapacity);
Controls.Add(ButtonCancel);
Controls.Add(ButtonSave);
Controls.Add(dataGridView);
Controls.Add(dateTimePickerDateOpen);
Controls.Add(textBoxAddress);
Controls.Add(textBoxName);
Controls.Add(labelDate);
Controls.Add(labelAddress);
Controls.Add(labelShop);
Name = "FormShop";
Text = "Магазин";
Load += FormShop_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelShop;
private Label labelAddress;
private Label labelDate;
private TextBox textBoxName;
private TextBox textBoxAddress;
private DateTimePicker dateTimePickerDateOpen;
private DataGridView dataGridView;
private Button ButtonSave;
private Button ButtonCancel;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn ShipName;
private DataGridViewTextBoxColumn Count;
private NumericUpDown numericUpDownCapacity;
private Label labelCapacity;
}
}

View File

@@ -0,0 +1,129 @@
using Microsoft.Extensions.Logging;
using ShipyardContracts.BindingModels;
using ShipyardContracts.BusinessLogicsContracts;
using ShipyardContracts.SearchModels;
using ShipyardDataModels.Models;
namespace ShipyardView
{
public partial class FormShop : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
private int? _id;
private Dictionary<int, (IShipModel, int)> _shopShips;
public int Id { set { _id = value; } }
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_shopShips = new Dictionary<int, (IShipModel, int)>();
}
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.ShopName;
textBoxAddress.Text = view.Address.ToString();
dateTimePickerDateOpen.Text = view.DateOpen.ToString();
numericUpDownCapacity.Value = view.Capacity;
_shopShips = view.ShopShips ?? new Dictionary<int, (IShipModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка кораблей магазина");
try
{
if (_shopShips != null)
{
dataGridView.Rows.Clear();
foreach (var element in _shopShips)
{
dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.ShipName, element.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(dateTimePickerDateOpen.Text))
{
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (numericUpDownCapacity.Value <= 0)
{
MessageBox.Show("Вместимость должна быть больше нуля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpen = DateTime.Parse(dateTimePickerDateOpen.Text),
Capacity = (int)numericUpDownCapacity.Value,
ShopShips = _shopShips
};
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();
}
}
}

View File

@@ -0,0 +1,120 @@
<?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>

View File

@@ -0,0 +1,117 @@
namespace ShipyardView
{
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()
{
dataGridView = new DataGridView();
ButtonAdd = new Button();
ButtonUpd = new Button();
ButtonDel = new Button();
ButtonRef = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 0);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(631, 450);
dataGridView.TabIndex = 0;
//
// ButtonAdd
//
ButtonAdd.Location = new Point(670, 33);
ButtonAdd.Name = "ButtonAdd";
ButtonAdd.Size = new Size(106, 48);
ButtonAdd.TabIndex = 1;
ButtonAdd.Text = "Создать";
ButtonAdd.UseVisualStyleBackColor = true;
ButtonAdd.Click += ButtonAdd_Click;
//
// ButtonUpd
//
ButtonUpd.Location = new Point(670, 102);
ButtonUpd.Name = "ButtonUpd";
ButtonUpd.Size = new Size(106, 48);
ButtonUpd.TabIndex = 2;
ButtonUpd.Text = "Изменить";
ButtonUpd.UseVisualStyleBackColor = true;
ButtonUpd.Click += ButtonUpd_Click;
//
// ButtonDel
//
ButtonDel.Location = new Point(670, 165);
ButtonDel.Name = "ButtonDel";
ButtonDel.Size = new Size(106, 48);
ButtonDel.TabIndex = 3;
ButtonDel.Text = "Удалить";
ButtonDel.UseVisualStyleBackColor = true;
ButtonDel.Click += ButtonDel_Click;
//
// ButtonRef
//
ButtonRef.Location = new Point(670, 229);
ButtonRef.Name = "ButtonRef";
ButtonRef.Size = new Size(106, 48);
ButtonRef.TabIndex = 4;
ButtonRef.Text = "Обновить";
ButtonRef.UseVisualStyleBackColor = true;
ButtonRef.Click += ButtonRef_Click;
//
// FormShops
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(ButtonRef);
Controls.Add(ButtonDel);
Controls.Add(ButtonUpd);
Controls.Add(ButtonAdd);
Controls.Add(dataGridView);
Name = "FormShops";
Text = "Магазины";
Load += FormShops_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button ButtonAdd;
private Button ButtonUpd;
private Button ButtonDel;
private Button ButtonRef;
}
}

View File

@@ -0,0 +1,105 @@
using Microsoft.Extensions.Logging;
using ShipyardContracts.BindingModels;
using ShipyardContracts.BusinessLogicsContracts;
using System.Windows.Forms;
namespace ShipyardView
{
public partial class FormShops : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
public FormShops(ILogger<FormShops> 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["ShopShips"].Visible = false;
dataGridView.Columns["ShopName"].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(FormShop));
if (service is FormShop 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(FormShop));
if (service is FormShop 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 ShopBindingModel
{
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();
}
}
}

View File

@@ -0,0 +1,120 @@
<?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>

View File

@@ -1,9 +1,8 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using ShipyardBusinessLogic.BusinessLogics; using ShipyardBusinessLogic.BusinessLogics;
using ShipyardContracts.BusinessLogicsContracts; using ShipyardContracts.BusinessLogicsContracts;
using ShipyardContracts.StoragesContracts; using ShipyardContracts.StoragesContracts;
using ShipyardListImplement.Implements; using ShipyardFileImplement.Implements;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
namespace ShipyardView namespace ShipyardView
@@ -35,14 +34,20 @@ namespace ShipyardView
services.AddTransient<IShipStorage, ShipStorage>(); services.AddTransient<IShipStorage, ShipStorage>();
services.AddTransient<IDetailLogic, DetailLogic>(); services.AddTransient<IDetailLogic, DetailLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IShipLogic, ShipLogic>(); services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<FormMain>(); services.AddTransient<IShipLogic, ShipLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormDetail>(); services.AddTransient<FormDetail>();
services.AddTransient<FormDetails>(); services.AddTransient<FormDetails>();
services.AddTransient<FormCreateOrder>(); services.AddTransient<FormCreateOrder>();
services.AddTransient<FormShip>(); services.AddTransient<FormShip>();
services.AddTransient<FormShipDetail>(); services.AddTransient<FormShipDetail>();
services.AddTransient<FormShips>(); services.AddTransient<FormShips>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormAddShip>();
services.AddTransient<FormSellShips>();
} }
} }

View File

@@ -18,7 +18,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ShipyardBusinessLogic\ShipyardBusinessLogic.csproj" /> <ProjectReference Include="..\ShipyardBusinessLogic\ShipyardBusinessLogic.csproj" />
<ProjectReference Include="..\ShipyardListImplement\ShipyardListImplement.csproj" /> <ProjectReference Include="..\ShipyardFileImplement\ShipyardFileImplement.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>