Слил кактку в Доте
This commit is contained in:
commit
0e35a55b94
@ -17,10 +17,14 @@ namespace ComputersShopBusinessLogic.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 IComputerStorage _computerStorage;
|
||||||
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IComputerStorage computerStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
_computerStorage = computerStorage;
|
||||||
}
|
}
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -52,16 +56,29 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
model.Status = newStatus;
|
model.Status = newStatus;
|
||||||
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
if (model.Status == OrderStatus.Готов)
|
||||||
|
{
|
||||||
|
|
||||||
|
model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||||
|
var computer = _computerStorage.GetElement(new() { Id = viewModel.ComputerId });
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(computer));
|
||||||
|
}
|
||||||
|
if (!_shopLogic.AddComputers(computer, viewModel.Count))
|
||||||
|
{
|
||||||
|
throw new Exception($"AddComputers operation failed - нет места");
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
model.DateImplement = viewModel.DateImplement;
|
model.DateImplement = viewModel.DateImplement;
|
||||||
}
|
}
|
||||||
CheckModel(model);
|
CheckModel(model, false);
|
||||||
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;
|
||||||
|
@ -0,0 +1,242 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.BusinessLogicContracts;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.StoragesContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopBusinessLogic.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 bool AddComputer(ShopSearchModel model, IComputerModel computer, int quantity)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quantity <= 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity));
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("AddComputerInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
|
||||||
|
var element = _shopStorage.GetElement(model);
|
||||||
|
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AddComputerInShop element not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.Capacity - element.Computers.Select(x => x.Value.Item2).Sum() < quantity)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("В магазине не хватает места", nameof(quantity));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.Computers.TryGetValue(computer.Id, out var pair))
|
||||||
|
{
|
||||||
|
element.Computers[computer.Id] = (computer, quantity + pair.Item2);
|
||||||
|
_logger.LogInformation("AddComputerInShop. Has been added {quantity} {Computer} in {ShopName}", quantity, computer.ComputerName, element.ShopName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
element.Computers[computer.Id] = (computer, quantity);
|
||||||
|
_logger.LogInformation("AddPastryInShop. Has been added {quantity} new Computer {Computer} in {ShopName}", quantity, computer.ComputerName, element.ShopName);
|
||||||
|
}
|
||||||
|
|
||||||
|
_shopStorage.Update(new()
|
||||||
|
{
|
||||||
|
Id = element.Id,
|
||||||
|
ShopAddress = element.ShopAddress,
|
||||||
|
ShopName = element.ShopName,
|
||||||
|
DateOpening = element.DateOpening,
|
||||||
|
Computers = element.Computers,
|
||||||
|
Capacity = element.Capacity,
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddComputers(IComputerModel computer, int quantity)
|
||||||
|
{
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(computer));
|
||||||
|
}
|
||||||
|
if (quantity <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Количество документов должно быть больше 0", nameof(quantity));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("AddComputers. ShopName:{ShopName}. Id:{Id}", computer.ComputerName, computer.Id);
|
||||||
|
var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.Computers.Select(x => x.Value.Item2).Sum()).Sum();
|
||||||
|
if (allFreeQuantity < quantity)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AddComputers operation failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
|
{
|
||||||
|
int freeQuantity = shop.Capacity - shop.Computers.Select(x => x.Value.Item2).Sum();
|
||||||
|
if (freeQuantity <= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (freeQuantity < quantity)
|
||||||
|
{
|
||||||
|
if (!AddComputer(new() { Id = shop.Id }, computer, freeQuantity))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AddComputers operation failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
quantity -= freeQuantity;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!AddComputer(new() { Id = shop.Id }, computer, quantity))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AddComputers operation failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
quantity = 0;
|
||||||
|
}
|
||||||
|
if (quantity == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_logger.LogWarning("AddComputers operation failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
model.Computers = new();
|
||||||
|
|
||||||
|
if (_shopStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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 bool SellComputers(IComputerModel computer, int quantity)
|
||||||
|
{
|
||||||
|
return _shopStorage.SellComputers(computer, quantity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_shopStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update 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}.ShopAdress:{1}. Id: {2}", model.ShopName, model.ShopAddress, 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("Магазин с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ShopBindingModel : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ShopName { get; set; } = string.Empty;
|
||||||
|
public string ShopAddress { get; set; } = string.Empty;
|
||||||
|
public DateTime DateOpening { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||||
|
public Dictionary<int, (IComputerModel, int)> Computers { get; set; } = new();
|
||||||
|
public int Capacity { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopContracts.BusinessLogicContracts
|
||||||
|
{
|
||||||
|
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 AddComputer(ShopSearchModel model, IComputerModel computer, int quantity);
|
||||||
|
bool AddComputers(IComputerModel computer, int quantity);
|
||||||
|
bool SellComputers(IComputerModel computer, int quantity);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ShopSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? ShopName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopContracts.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 SellComputers(IComputerModel model, int quantity);
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,7 @@ namespace ComputersShopContracts.ViewModels
|
|||||||
[DisplayName("Статус")]
|
[DisplayName("Статус")]
|
||||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||||
[DisplayName("Дата создания")]
|
[DisplayName("Дата создания")]
|
||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||||
[DisplayName("Дата выполнения")]
|
[DisplayName("Дата выполнения")]
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ShopViewModel : IShopModel
|
||||||
|
{
|
||||||
|
public Dictionary<int, (IComputerModel, int)> Computers { get; set; } = new();
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Название магазина")]
|
||||||
|
public string ShopName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Адрес магазина")]
|
||||||
|
public string ShopAddress { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Дата открытия")]
|
||||||
|
public DateTime DateOpening { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||||
|
[DisplayName("Вместимость магазина")]
|
||||||
|
public int Capacity { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ namespace ComputersShopDataBaseImplement
|
|||||||
{
|
{
|
||||||
if (optionsBuilder.IsConfigured == false)
|
if (optionsBuilder.IsConfigured == false)
|
||||||
{
|
{
|
||||||
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=ComputersShopDatabaseFull;Username=postgres;Password=adam200396789");
|
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=ComputersShopDatabaseHard;Username=postgres;Password=adam200396789");
|
||||||
}
|
}
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
@ -22,6 +22,8 @@ namespace ComputersShopDataBaseImplement
|
|||||||
public virtual DbSet<Computer> Computers { set; get; }
|
public virtual DbSet<Computer> Computers { set; get; }
|
||||||
public virtual DbSet<ComputerComponent> ComputerComponents { set; get; }
|
public virtual DbSet<ComputerComponent> ComputerComponents { set; get; }
|
||||||
public virtual DbSet<Order> Orders { set; get; }
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
|
public virtual DbSet<ShopComputer> ShopComputers { set; get; }
|
||||||
|
public virtual DbSet<Shop> Shops { set; get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,154 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.StoragesContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataBaseImplement.Models;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopDataBaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ComputersShopDataBase();
|
||||||
|
var element = context.Shops
|
||||||
|
.Include(x => x.shopComputers)
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Shops.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new ComputersShopDataBase();
|
||||||
|
return context.Shops
|
||||||
|
.Include(x => x.shopComputers)
|
||||||
|
.ThenInclude(x => x.Computer)
|
||||||
|
.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();
|
||||||
|
}
|
||||||
|
using var context = new ComputersShopDataBase();
|
||||||
|
return context.Shops
|
||||||
|
.Include(x => x.shopComputers)
|
||||||
|
.ThenInclude(x => x.Computer)
|
||||||
|
.Where(x => x.ShopName.Contains(model.ShopName))
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new ComputersShopDataBase();
|
||||||
|
return context.Shops
|
||||||
|
.Include(x => x.shopComputers)
|
||||||
|
.ThenInclude(x => x.Computer)
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ComputersShopDataBase();
|
||||||
|
var newComputer = Shop.Create(context, model);
|
||||||
|
if (newComputer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Shops.Add(newComputer);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newComputer.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SellComputers(IComputerModel model, int quantity)
|
||||||
|
{
|
||||||
|
using var context = new ComputersShopDataBase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<Shop> shopsWithComputer = context.Shops.Include(x => x.shopComputers).ThenInclude(x => x.Computer).Where(x => x.shopComputers.Any(x => x.ComputerId == model.Id)).ToList();
|
||||||
|
foreach (var shop in shopsWithComputer)
|
||||||
|
{
|
||||||
|
int computerInShopCount = shop.Computers[model.Id].Item2;
|
||||||
|
if (quantity - computerInShopCount >= 0)
|
||||||
|
{
|
||||||
|
quantity -= computerInShopCount;
|
||||||
|
context.ShopComputers.Remove(shop.shopComputers.FirstOrDefault(x => x.ComputerId == model.Id)!);
|
||||||
|
shop.Computers.Remove(model.Id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shop.Computers[model.Id] = (model, computerInShopCount - quantity);
|
||||||
|
quantity = 0;
|
||||||
|
shop.UpdateComputers(context, new()
|
||||||
|
{
|
||||||
|
Id = shop.Id,
|
||||||
|
Computers = shop.Computers
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (quantity == 0)
|
||||||
|
{
|
||||||
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transaction.Rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ComputersShopDataBase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var shop = context.Shops.FirstOrDefault(rec =>
|
||||||
|
rec.Id == model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
shop.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
shop.UpdateComputers(context, model);
|
||||||
|
transaction.Commit();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace ComputersShopDataBaseImplement.Migrations
|
namespace ComputersShopDataBaseImplement.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ComputersShopDataBase))]
|
[DbContext(typeof(ComputersShopDataBase))]
|
||||||
[Migration("20230227200236_Init")]
|
[Migration("20230504182237_InitMig")]
|
||||||
partial class Init
|
partial class InitMig
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -124,6 +124,59 @@ namespace ComputersShopDataBaseImplement.Migrations
|
|||||||
b.ToTable("Orders");
|
b.ToTable("Orders");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Capacity")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateOpening")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("ShopAddress")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ShopName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Shops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ShopComputer", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ComputerId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("ShopId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComputerId");
|
||||||
|
|
||||||
|
b.HasIndex("ShopId");
|
||||||
|
|
||||||
|
b.ToTable("ShopComputers");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ComputerComponent", b =>
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ComputerComponent", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("ComputersShopDataBaseImplement.Models.Component", "Component")
|
b.HasOne("ComputersShopDataBaseImplement.Models.Component", "Component")
|
||||||
@ -145,13 +198,30 @@ namespace ComputersShopDataBaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b =>
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer")
|
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", null)
|
||||||
.WithMany("Orders")
|
.WithMany("Orders")
|
||||||
.HasForeignKey("ComputerId")
|
.HasForeignKey("ComputerId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ShopComputer", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ComputerId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("ComputersShopDataBaseImplement.Models.Shop", "Shop")
|
||||||
|
.WithMany("shopComputers")
|
||||||
|
.HasForeignKey("ShopId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Computer");
|
b.Navigation("Computer");
|
||||||
|
|
||||||
|
b.Navigation("Shop");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b =>
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b =>
|
||||||
@ -165,6 +235,11 @@ namespace ComputersShopDataBaseImplement.Migrations
|
|||||||
|
|
||||||
b.Navigation("Orders");
|
b.Navigation("Orders");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("shopComputers");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace ComputersShopDataBaseImplement.Migrations
|
namespace ComputersShopDataBaseImplement.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class Init : Migration
|
public partial class InitMig : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
@ -40,6 +40,22 @@ namespace ComputersShopDataBaseImplement.Migrations
|
|||||||
table.PrimaryKey("PK_Computers", x => x.Id);
|
table.PrimaryKey("PK_Computers", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Shops",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
ShopName = table.Column<string>(type: "text", nullable: false),
|
||||||
|
ShopAddress = table.Column<string>(type: "text", nullable: false),
|
||||||
|
DateOpening = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
Capacity = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "ComputerComponents",
|
name: "ComputerComponents",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@ -91,6 +107,33 @@ namespace ComputersShopDataBaseImplement.Migrations
|
|||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ShopComputers",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
ShopId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
ComputerId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ShopComputers", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ShopComputers_Computers_ComputerId",
|
||||||
|
column: x => x.ComputerId,
|
||||||
|
principalTable: "Computers",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ShopComputers_Shops_ShopId",
|
||||||
|
column: x => x.ShopId,
|
||||||
|
principalTable: "Shops",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_ComputerComponents_ComponentId",
|
name: "IX_ComputerComponents_ComponentId",
|
||||||
table: "ComputerComponents",
|
table: "ComputerComponents",
|
||||||
@ -105,6 +148,16 @@ namespace ComputersShopDataBaseImplement.Migrations
|
|||||||
name: "IX_Orders_ComputerId",
|
name: "IX_Orders_ComputerId",
|
||||||
table: "Orders",
|
table: "Orders",
|
||||||
column: "ComputerId");
|
column: "ComputerId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ShopComputers_ComputerId",
|
||||||
|
table: "ShopComputers",
|
||||||
|
column: "ComputerId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ShopComputers_ShopId",
|
||||||
|
table: "ShopComputers",
|
||||||
|
column: "ShopId");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -116,11 +169,17 @@ namespace ComputersShopDataBaseImplement.Migrations
|
|||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Orders");
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ShopComputers");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Components");
|
name: "Components");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Computers");
|
name: "Computers");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Shops");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -121,6 +121,59 @@ namespace ComputersShopDataBaseImplement.Migrations
|
|||||||
b.ToTable("Orders");
|
b.ToTable("Orders");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Capacity")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateOpening")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("ShopAddress")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ShopName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Shops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ShopComputer", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ComputerId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("ShopId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComputerId");
|
||||||
|
|
||||||
|
b.HasIndex("ShopId");
|
||||||
|
|
||||||
|
b.ToTable("ShopComputers");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ComputerComponent", b =>
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ComputerComponent", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("ComputersShopDataBaseImplement.Models.Component", "Component")
|
b.HasOne("ComputersShopDataBaseImplement.Models.Component", "Component")
|
||||||
@ -142,13 +195,30 @@ namespace ComputersShopDataBaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b =>
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer")
|
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", null)
|
||||||
.WithMany("Orders")
|
.WithMany("Orders")
|
||||||
.HasForeignKey("ComputerId")
|
.HasForeignKey("ComputerId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.ShopComputer", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ComputerId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("ComputersShopDataBaseImplement.Models.Shop", "Shop")
|
||||||
|
.WithMany("shopComputers")
|
||||||
|
.HasForeignKey("ShopId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Computer");
|
b.Navigation("Computer");
|
||||||
|
|
||||||
|
b.Navigation("Shop");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b =>
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b =>
|
||||||
@ -162,6 +232,11 @@ namespace ComputersShopDataBaseImplement.Migrations
|
|||||||
|
|
||||||
b.Navigation("Orders");
|
b.Navigation("Orders");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("shopComputers");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
109
ComputersShop/ComputersShopDataBaseImplement/Models/Shop.cs
Normal file
109
ComputersShop/ComputersShopDataBaseImplement/Models/Shop.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace ComputersShopDataBaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string ShopName { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string ShopAddress { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public DateTime DateOpening { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int Capacity { get; set; }
|
||||||
|
|
||||||
|
private Dictionary<int, (IComputerModel, int)>? _computers = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IComputerModel, int)> Computers
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_computers == null)
|
||||||
|
{
|
||||||
|
_computers = shopComputers
|
||||||
|
.ToDictionary(rec => rec.ComputerId,
|
||||||
|
rec => (rec.Computer as IComputerModel,
|
||||||
|
rec.Count));
|
||||||
|
}
|
||||||
|
return _computers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[ForeignKey("ShopId")]
|
||||||
|
public virtual List<ShopComputer> shopComputers { get; set; } = new();
|
||||||
|
public static Shop Create(ComputersShopDataBase context, ShopBindingModel model)
|
||||||
|
{
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
ShopAddress = model.ShopAddress,
|
||||||
|
DateOpening = model.DateOpening,
|
||||||
|
Capacity = model.Capacity,
|
||||||
|
shopComputers = model.Computers.Select(x => new ShopComputer
|
||||||
|
{
|
||||||
|
Computer = context.Computers.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
ShopAddress = model.ShopAddress;
|
||||||
|
DateOpening = model.DateOpening;
|
||||||
|
Capacity = model.Capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
ShopAddress = ShopAddress,
|
||||||
|
DateOpening = DateOpening,
|
||||||
|
Capacity = Capacity,
|
||||||
|
Computers = Computers
|
||||||
|
};
|
||||||
|
|
||||||
|
public void UpdateComputers(ComputersShopDataBase context, ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var computers = context.ShopComputers.Where(rec => rec.ShopId == model.Id).ToList();
|
||||||
|
if (computers != null && computers.Count > 0)
|
||||||
|
{
|
||||||
|
context.ShopComputers.RemoveRange(computers.Where(rec => !model.Computers.ContainsKey(rec.ComputerId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
foreach (var computer in computers)
|
||||||
|
{
|
||||||
|
computer.Count = model.Computers[computer.ComputerId].Item2;
|
||||||
|
model.Computers.Remove(computer.ComputerId);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var shop = context.Shops.First(x => x.Id == Id);
|
||||||
|
foreach (var id in model.Computers)
|
||||||
|
{
|
||||||
|
context.ShopComputers.Add(new ShopComputer
|
||||||
|
{
|
||||||
|
Shop = shop,
|
||||||
|
Computer = context.Computers.First(x => x.Id == id.Key),
|
||||||
|
Count = id.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_computers = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection.Metadata;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopDataBaseImplement.Models
|
||||||
|
{
|
||||||
|
public class ShopComputer
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int ShopId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int ComputerId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
public virtual Computer Computer { get; set; } = new();
|
||||||
|
|
||||||
|
public virtual Shop Shop { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
17
ComputersShop/ComputersShopDataModels/Models/IShopModel.cs
Normal file
17
ComputersShop/ComputersShopDataModels/Models/IShopModel.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IShopModel : IId
|
||||||
|
{
|
||||||
|
public string ShopName { get; }
|
||||||
|
public string ShopAddress { get; }
|
||||||
|
DateTime DateOpening { get; }
|
||||||
|
public int Capacity { get; }
|
||||||
|
Dictionary<int, (IComputerModel, int)> Computers { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -14,10 +14,12 @@ namespace ComputersShopFileImplement
|
|||||||
private readonly string ComponentFileName = "Component.xml";
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
private readonly string OrderFileName = "Order.xml";
|
private readonly string OrderFileName = "Order.xml";
|
||||||
private readonly string ComputerFileName = "Computer.xml";
|
private readonly string ComputerFileName = "Computer.xml";
|
||||||
public List<Component> Components { get; private set; }
|
private readonly string ShopFileName = "Shop.xml";
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
public List<Computer> Computers { get; private set; }
|
public List<Computer> Computers { get; private set; }
|
||||||
public static DataFileSingleton GetInstance()
|
public List<Shop> Shops { get; private set; }
|
||||||
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
{
|
{
|
||||||
@ -28,12 +30,14 @@ namespace ComputersShopFileImplement
|
|||||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||||
public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", x => x.GetXElement);
|
public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", x => x.GetXElement);
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
private DataFileSingleton()
|
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||||
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
Computers = LoadData(ComputerFileName, "Computer", x => Computer.Create(x)!)!;
|
Computers = LoadData(ComputerFileName, "Computer", x => Computer.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.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)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
|
@ -0,0 +1,132 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.StoragesContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using ComputersShopFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
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 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 bool SellComputers(IComputerModel model, int quantity)
|
||||||
|
{
|
||||||
|
int hasCount = 0;
|
||||||
|
|
||||||
|
source.Shops.ForEach(x =>
|
||||||
|
{
|
||||||
|
if (x.Computers.TryGetValue(model.Id, out var pair))
|
||||||
|
{
|
||||||
|
hasCount += pair.Item2;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (hasCount < quantity) return false;
|
||||||
|
|
||||||
|
source.Shops.ForEach(x =>
|
||||||
|
{
|
||||||
|
if (x.Computers.TryGetValue(model.Id, out var pair))
|
||||||
|
{
|
||||||
|
if (quantity >= pair.Item2)
|
||||||
|
{
|
||||||
|
quantity -= pair.Item2;
|
||||||
|
x.Computers[model.Id] = (model, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x.Computers[model.Id] = (model, pair.Item2 - quantity);
|
||||||
|
quantity = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
x.Update(new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
ShopAddress = x.ShopAddress,
|
||||||
|
Capacity = x.Capacity,
|
||||||
|
DateOpening = x.DateOpening,
|
||||||
|
ShopName = x.ShopName,
|
||||||
|
Computers = x.Computers
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
source.SaveShops();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -77,11 +77,7 @@ namespace ComputersShopFileImplement.Models
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ComputerId = model.ComputerId;
|
|
||||||
Count = model.Count;
|
|
||||||
Sum = model.Sum;
|
|
||||||
Status = model.Status;
|
Status = model.Status;
|
||||||
DateCreate = model.DateCreate;
|
|
||||||
DateImplement = model.DateImplement;
|
DateImplement = model.DateImplement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
108
ComputersShop/ComputersShopFileImplement/Models/Shop.cs
Normal file
108
ComputersShop/ComputersShopFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ComputersShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ShopName { get; private set; } = string.Empty;
|
||||||
|
public string ShopAddress { get; private set; } = string.Empty;
|
||||||
|
public DateTime DateOpening { get; private set; }
|
||||||
|
public int Capacity { get; private set; }
|
||||||
|
public Dictionary<int, int> ComputersCount = new();
|
||||||
|
public Dictionary<int, (IComputerModel, int)>? _computers = null;
|
||||||
|
public Dictionary<int, (IComputerModel, int)> Computers
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_computers == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_computers = ComputersCount.ToDictionary(
|
||||||
|
x => x.Key,
|
||||||
|
y => ((source.Computers.FirstOrDefault(z => z.Id == y.Key) as IComputerModel)!,
|
||||||
|
y.Value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _computers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
ShopAddress = model.ShopAddress,
|
||||||
|
DateOpening = model.DateOpening,
|
||||||
|
Capacity = model.Capacity,
|
||||||
|
ComputersCount = model.Computers.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,
|
||||||
|
ShopAddress = element.Element("ShopAddress")!.Value,
|
||||||
|
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
|
||||||
|
Capacity = Convert.ToInt32(element.Element("Capacity")!.Value),
|
||||||
|
ComputersCount = element.Element("Computers")!.Elements("Computer")
|
||||||
|
.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;
|
||||||
|
ShopAddress = model.ShopAddress;
|
||||||
|
DateOpening = model.DateOpening;
|
||||||
|
Capacity = model.Capacity;
|
||||||
|
ComputersCount = model.Computers.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_computers = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
ShopAddress = ShopAddress,
|
||||||
|
DateOpening = DateOpening,
|
||||||
|
Capacity = Capacity,
|
||||||
|
Computers = Computers
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Shop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ShopName", ShopName),
|
||||||
|
new XElement("ShopAddress", ShopAddress),
|
||||||
|
new XElement("DateOpening", DateOpening.ToString()),
|
||||||
|
new XElement("Capacity", Capacity.ToString()),
|
||||||
|
new XElement("Computers", ComputersCount.Select(x =>
|
||||||
|
new XElement("Computer",
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
new XElement("Value", x.Value)))
|
||||||
|
.ToArray()));
|
||||||
|
}
|
||||||
|
}
|
@ -13,11 +13,13 @@ namespace ComputersShopListImplement
|
|||||||
public List<Component> Components { get; set; }
|
public List<Component> Components { get; set; }
|
||||||
public List<Order> Orders { get; set; }
|
public List<Order> Orders { get; set; }
|
||||||
public List<Computer> Computers { get; set; }
|
public List<Computer> Computers { get; set; }
|
||||||
|
public List<Shop> Shops { get; set; }
|
||||||
private DataListSingleton()
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Components = new List<Component>();
|
Components = new List<Component>();
|
||||||
Orders = new List<Order>();
|
Orders = new List<Order>();
|
||||||
Computers = new List<Computer>();
|
Computers = new List<Computer>();
|
||||||
|
Shops = new List<Shop>();
|
||||||
}
|
}
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,131 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.StoragesContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using ComputersShopListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
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 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 bool SellComputers(IComputerModel model, int quantity)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var Shop in _source.Shops)
|
||||||
|
{
|
||||||
|
if (Shop.Id == model.Id)
|
||||||
|
{
|
||||||
|
Shop.Update(model);
|
||||||
|
return Shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
61
ComputersShop/ComputersShopListImplement/Models/Shop.cs
Normal file
61
ComputersShop/ComputersShopListImplement/Models/Shop.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputersShopListImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public string ShopName { get; private set; } = string.Empty;
|
||||||
|
public string ShopAddress { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime DateOpening { get; private set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (IComputerModel, int)> Computers { get; private set; } = new();
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
ShopAddress = model.ShopAddress,
|
||||||
|
DateOpening = model.DateOpening,
|
||||||
|
Computers = new()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
ShopAddress = model.ShopAddress;
|
||||||
|
DateOpening = model.DateOpening;
|
||||||
|
Computers = model.Computers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
ShopAddress = ShopAddress,
|
||||||
|
DateOpening = DateOpening,
|
||||||
|
Computers = Computers
|
||||||
|
};
|
||||||
|
|
||||||
|
public int Capacity => throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
44
ComputersShop/ComputersShopView/FormMain.Designer.cs
generated
44
ComputersShop/ComputersShopView/FormMain.Designer.cs
generated
@ -1,26 +1,26 @@
|
|||||||
namespace ComputersShopView
|
namespace ComputersShopView
|
||||||
{
|
{
|
||||||
partial class FormMain
|
partial class FormMain
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private System.ComponentModel.IContainer components = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
@ -186,7 +186,7 @@
|
|||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private MenuStrip menuStrip;
|
private MenuStrip menuStrip;
|
||||||
private ToolStripMenuItem справочникToolStripMenuItem;
|
private ToolStripMenuItem справочникToolStripMenuItem;
|
||||||
@ -198,9 +198,5 @@
|
|||||||
private Button buttonRef;
|
private Button buttonRef;
|
||||||
private ToolStripMenuItem computerToolStripMenuItem;
|
private ToolStripMenuItem computerToolStripMenuItem;
|
||||||
private ToolStripMenuItem componentsToolStripMenuItem;
|
private ToolStripMenuItem componentsToolStripMenuItem;
|
||||||
private ToolStripMenuItem отчётыToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem списокКомпонентовToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem компонентыПоКомпьютерамToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -97,7 +97,7 @@ namespace ComputersShopView
|
|||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
}
|
}
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -127,7 +127,7 @@ namespace ComputersShopView
|
|||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
}
|
}
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -157,7 +157,7 @@ namespace ComputersShopView
|
|||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Заказ №{id} выдан", id);
|
_logger.LogInformation("Заказ №{id} выдан", id);
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
@ -168,35 +168,6 @@ namespace ComputersShopView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ComponentsDocxToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
|
||||||
if (dialog.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
_reportLogic.SaveComputersToWordFile(new ReportBindingModel { FileName = dialog.FileName });
|
|
||||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ComputerComponentsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportComputerComponents));
|
|
||||||
if (service is FormReportComputerComponents form)
|
|
||||||
{
|
|
||||||
form.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
|
|
||||||
if (service is FormReportOrders form)
|
|
||||||
{
|
|
||||||
form.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonRef_Click(object sender, EventArgs e)
|
private void ButtonRef_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
|
124
ComputersShop/ComputersShopView/FormSellComputers.Designer.cs
generated
Normal file
124
ComputersShop/ComputersShopView/FormSellComputers.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
namespace ComputersShopView
|
||||||
|
{
|
||||||
|
partial class FormSellComputers
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
ButtonCancel = new Button();
|
||||||
|
comboBoxDocuments = new ComboBox();
|
||||||
|
numericUpDownCount = new NumericUpDown();
|
||||||
|
labelDocument = new Label();
|
||||||
|
labelCount = new Label();
|
||||||
|
ButtonSave = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
ButtonCancel.Location = new Point(233, 60);
|
||||||
|
ButtonCancel.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
ButtonCancel.Name = "ButtonCancel";
|
||||||
|
ButtonCancel.Size = new Size(82, 22);
|
||||||
|
ButtonCancel.TabIndex = 1;
|
||||||
|
ButtonCancel.Text = "Отмена";
|
||||||
|
ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
ButtonCancel.Click += ButtonCancel_Click;
|
||||||
|
//
|
||||||
|
// comboBoxDocuments
|
||||||
|
//
|
||||||
|
comboBoxDocuments.FormattingEnabled = true;
|
||||||
|
comboBoxDocuments.Location = new Point(89, 6);
|
||||||
|
comboBoxDocuments.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
comboBoxDocuments.Name = "comboBoxDocuments";
|
||||||
|
comboBoxDocuments.Size = new Size(226, 23);
|
||||||
|
comboBoxDocuments.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// numericUpDownCount
|
||||||
|
//
|
||||||
|
numericUpDownCount.Location = new Point(90, 33);
|
||||||
|
numericUpDownCount.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
numericUpDownCount.Name = "numericUpDownCount";
|
||||||
|
numericUpDownCount.Size = new Size(225, 23);
|
||||||
|
numericUpDownCount.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// labelDocument
|
||||||
|
//
|
||||||
|
labelDocument.AutoSize = true;
|
||||||
|
labelDocument.Location = new Point(12, 9);
|
||||||
|
labelDocument.Name = "labelDocument";
|
||||||
|
labelDocument.Size = new Size(71, 15);
|
||||||
|
labelDocument.TabIndex = 4;
|
||||||
|
labelDocument.Text = "Компьютер";
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
labelCount.AutoSize = true;
|
||||||
|
labelCount.Location = new Point(11, 35);
|
||||||
|
labelCount.Name = "labelCount";
|
||||||
|
labelCount.Size = new Size(72, 15);
|
||||||
|
labelCount.TabIndex = 5;
|
||||||
|
labelCount.Text = "Количество";
|
||||||
|
//
|
||||||
|
// ButtonSave
|
||||||
|
//
|
||||||
|
ButtonSave.Location = new Point(145, 60);
|
||||||
|
ButtonSave.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
ButtonSave.Name = "ButtonSave";
|
||||||
|
ButtonSave.Size = new Size(82, 22);
|
||||||
|
ButtonSave.TabIndex = 6;
|
||||||
|
ButtonSave.Text = "Сохранить";
|
||||||
|
ButtonSave.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSave.Click += ButtonSave_Click;
|
||||||
|
//
|
||||||
|
// FormSellComputers
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(326, 93);
|
||||||
|
Controls.Add(ButtonSave);
|
||||||
|
Controls.Add(labelCount);
|
||||||
|
Controls.Add(labelDocument);
|
||||||
|
Controls.Add(numericUpDownCount);
|
||||||
|
Controls.Add(comboBoxDocuments);
|
||||||
|
Controls.Add(ButtonCancel);
|
||||||
|
Margin = new Padding(3, 2, 3, 2);
|
||||||
|
Name = "FormSellComputers";
|
||||||
|
Text = "Продажа компьютеров";
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private Button ButtonCancel;
|
||||||
|
private ComboBox comboBoxDocuments;
|
||||||
|
private NumericUpDown numericUpDownCount;
|
||||||
|
private Label labelDocument;
|
||||||
|
private Label labelCount;
|
||||||
|
private Button ButtonSave;
|
||||||
|
}
|
||||||
|
}
|
86
ComputersShop/ComputersShopView/FormSellComputers.cs
Normal file
86
ComputersShop/ComputersShopView/FormSellComputers.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
using ComputersShopContracts.BusinessLogicContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ComputersShopView
|
||||||
|
{
|
||||||
|
public partial class FormSellComputers : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _shopLogic;
|
||||||
|
private readonly IComputerLogic _computerLogic;
|
||||||
|
private readonly List<ComputerViewModel>? _listComputer;
|
||||||
|
public FormSellComputers(ILogger<FormSellComputers> logger, IShopLogic shopLogic, IComputerLogic computerLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
_computerLogic = computerLogic;
|
||||||
|
_listComputer = computerLogic.ReadList(null);
|
||||||
|
if (_listComputer != null)
|
||||||
|
{
|
||||||
|
comboBoxDocuments.DisplayMember = "ComputerName";
|
||||||
|
comboBoxDocuments.ValueMember = "Id";
|
||||||
|
comboBoxDocuments.DataSource = _listComputer;
|
||||||
|
comboBoxDocuments.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxDocuments.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 comp = _computerLogic.ReadElement(new()
|
||||||
|
{
|
||||||
|
Id = (int)comboBoxDocuments.SelectedValue
|
||||||
|
});
|
||||||
|
if (comp == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Компьютер не найден. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
var operationResult = _shopLogic.SellComputers(
|
||||||
|
computer: comp,
|
||||||
|
quantity: (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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/ComputersShopView/FormSellComputers.resx
Normal file
60
ComputersShop/ComputersShopView/FormSellComputers.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
222
ComputersShop/ComputersShopView/FormShop.Designer.cs
generated
Normal file
222
ComputersShop/ComputersShopView/FormShop.Designer.cs
generated
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
namespace ComputersShopView
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
dateTimePicker = new DateTimePicker();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
ButtonSave = new Button();
|
||||||
|
ButtonCancel = new Button();
|
||||||
|
numericUpDownCapacity = new NumericUpDown();
|
||||||
|
labelCapacity = new Label();
|
||||||
|
ID = new DataGridViewTextBoxColumn();
|
||||||
|
DocumentName = new DataGridViewTextBoxColumn();
|
||||||
|
Price = new DataGridViewTextBoxColumn();
|
||||||
|
Count = new DataGridViewTextBoxColumn();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelShop
|
||||||
|
//
|
||||||
|
labelShop.AutoSize = true;
|
||||||
|
labelShop.Location = new Point(10, 16);
|
||||||
|
labelShop.Name = "labelShop";
|
||||||
|
labelShop.Size = new Size(54, 15);
|
||||||
|
labelShop.TabIndex = 0;
|
||||||
|
labelShop.Text = "Магазин";
|
||||||
|
//
|
||||||
|
// labelAddress
|
||||||
|
//
|
||||||
|
labelAddress.AutoSize = true;
|
||||||
|
labelAddress.Location = new Point(156, 16);
|
||||||
|
labelAddress.Name = "labelAddress";
|
||||||
|
labelAddress.Size = new Size(40, 15);
|
||||||
|
labelAddress.TabIndex = 1;
|
||||||
|
labelAddress.Text = "Адрес";
|
||||||
|
//
|
||||||
|
// labelDate
|
||||||
|
//
|
||||||
|
labelDate.AutoSize = true;
|
||||||
|
labelDate.Location = new Point(375, 16);
|
||||||
|
labelDate.Name = "labelDate";
|
||||||
|
labelDate.Size = new Size(87, 15);
|
||||||
|
labelDate.TabIndex = 2;
|
||||||
|
labelDate.Text = "Дата открытия";
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
textBoxName.Location = new Point(10, 33);
|
||||||
|
textBoxName.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
textBoxName.Name = "textBoxName";
|
||||||
|
textBoxName.Size = new Size(140, 23);
|
||||||
|
textBoxName.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// textBoxAddress
|
||||||
|
//
|
||||||
|
textBoxAddress.Location = new Point(156, 33);
|
||||||
|
textBoxAddress.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
textBoxAddress.Name = "textBoxAddress";
|
||||||
|
textBoxAddress.Size = new Size(216, 23);
|
||||||
|
textBoxAddress.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// dateTimePicker
|
||||||
|
//
|
||||||
|
dateTimePicker.Location = new Point(375, 33);
|
||||||
|
dateTimePicker.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
dateTimePicker.Name = "dateTimePicker";
|
||||||
|
dateTimePicker.Size = new Size(123, 23);
|
||||||
|
dateTimePicker.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, DocumentName, Price, Count });
|
||||||
|
dataGridView.Location = new Point(10, 58);
|
||||||
|
dataGridView.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.RowTemplate.Height = 29;
|
||||||
|
dataGridView.Size = new Size(623, 248);
|
||||||
|
dataGridView.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// ButtonSave
|
||||||
|
//
|
||||||
|
ButtonSave.Location = new Point(429, 310);
|
||||||
|
ButtonSave.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
ButtonSave.Name = "ButtonSave";
|
||||||
|
ButtonSave.Size = new Size(97, 22);
|
||||||
|
ButtonSave.TabIndex = 7;
|
||||||
|
ButtonSave.Text = "Сохранить";
|
||||||
|
ButtonSave.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSave.Click += ButtonSave_Click;
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
ButtonCancel.Location = new Point(551, 310);
|
||||||
|
ButtonCancel.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
ButtonCancel.Name = "ButtonCancel";
|
||||||
|
ButtonCancel.Size = new Size(82, 22);
|
||||||
|
ButtonCancel.TabIndex = 8;
|
||||||
|
ButtonCancel.Text = "Отмена";
|
||||||
|
ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
ButtonCancel.Click += ButtonCancel_Click;
|
||||||
|
//
|
||||||
|
// numericUpDownCapacity
|
||||||
|
//
|
||||||
|
numericUpDownCapacity.Location = new Point(513, 33);
|
||||||
|
numericUpDownCapacity.Name = "numericUpDownCapacity";
|
||||||
|
numericUpDownCapacity.Size = new Size(120, 23);
|
||||||
|
numericUpDownCapacity.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// labelCapacity
|
||||||
|
//
|
||||||
|
labelCapacity.AutoSize = true;
|
||||||
|
labelCapacity.Location = new Point(513, 16);
|
||||||
|
labelCapacity.Name = "labelCapacity";
|
||||||
|
labelCapacity.Size = new Size(80, 15);
|
||||||
|
labelCapacity.TabIndex = 10;
|
||||||
|
labelCapacity.Text = "Вместимость";
|
||||||
|
//
|
||||||
|
// ID
|
||||||
|
//
|
||||||
|
ID.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
ID.HeaderText = "ID";
|
||||||
|
ID.MinimumWidth = 6;
|
||||||
|
ID.Name = "ID";
|
||||||
|
ID.Visible = false;
|
||||||
|
//
|
||||||
|
// DocumentName
|
||||||
|
//
|
||||||
|
DocumentName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
DocumentName.HeaderText = "Название компьютера";
|
||||||
|
DocumentName.MinimumWidth = 6;
|
||||||
|
DocumentName.Name = "DocumentName";
|
||||||
|
//
|
||||||
|
// Price
|
||||||
|
//
|
||||||
|
Price.HeaderText = "Стоимость";
|
||||||
|
Price.Name = "Price";
|
||||||
|
//
|
||||||
|
// Count
|
||||||
|
//
|
||||||
|
Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
Count.HeaderText = "Количество";
|
||||||
|
Count.MinimumWidth = 6;
|
||||||
|
Count.Name = "Count";
|
||||||
|
//
|
||||||
|
// FormShop
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(648, 338);
|
||||||
|
Controls.Add(labelCapacity);
|
||||||
|
Controls.Add(numericUpDownCapacity);
|
||||||
|
Controls.Add(ButtonCancel);
|
||||||
|
Controls.Add(ButtonSave);
|
||||||
|
Controls.Add(dataGridView);
|
||||||
|
Controls.Add(dateTimePicker);
|
||||||
|
Controls.Add(textBoxAddress);
|
||||||
|
Controls.Add(textBoxName);
|
||||||
|
Controls.Add(labelDate);
|
||||||
|
Controls.Add(labelAddress);
|
||||||
|
Controls.Add(labelShop);
|
||||||
|
Margin = new Padding(3, 2, 3, 2);
|
||||||
|
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 dateTimePicker;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Button ButtonSave;
|
||||||
|
private Button ButtonCancel;
|
||||||
|
private NumericUpDown numericUpDownCapacity;
|
||||||
|
private Label labelCapacity;
|
||||||
|
private DataGridViewTextBoxColumn ID;
|
||||||
|
private DataGridViewTextBoxColumn DocumentName;
|
||||||
|
private DataGridViewTextBoxColumn Price;
|
||||||
|
private DataGridViewTextBoxColumn Count;
|
||||||
|
}
|
||||||
|
}
|
128
ComputersShop/ComputersShopView/FormShop.cs
Normal file
128
ComputersShop/ComputersShopView/FormShop.cs
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.BusinessLogicContracts;
|
||||||
|
using ComputersShopContracts.SearchModels;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using ComputersShopDataModels.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ComputersShopView
|
||||||
|
{
|
||||||
|
public partial class FormShop : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _logic;
|
||||||
|
private int? _id;
|
||||||
|
private Dictionary<int, (IComputerModel, int)> _shopComputers;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_shopComputers = new Dictionary<int, (IComputerModel, 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.ShopAddress.ToString();
|
||||||
|
dateTimePicker.Text = view.DateOpening.ToString();
|
||||||
|
numericUpDownCapacity.Value = view.Capacity;
|
||||||
|
_shopComputers = view.Computers ?? new Dictionary<int, (IComputerModel, int)>();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка компонент магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_shopComputers != null)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
foreach (var pc in _shopComputers)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComputerName, pc.Value.Item1.Price, pc.Value.Item2 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки изделий магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
ShopName = textBoxName.Text,
|
||||||
|
ShopAddress = textBoxAddress.Text,
|
||||||
|
DateOpening = DateTime.SpecifyKind(DateTime.Parse(dateTimePicker.Text), DateTimeKind.Utc),
|
||||||
|
Capacity = (int)numericUpDownCapacity.Value,
|
||||||
|
Computers = _shopComputers
|
||||||
|
};
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
ComputersShop/ComputersShopView/FormShop.resx
Normal file
63
ComputersShop/ComputersShopView/FormShop.resx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="Price.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
142
ComputersShop/ComputersShopView/FormShopReplenishment.Designer.cs
generated
Normal file
142
ComputersShop/ComputersShopView/FormShopReplenishment.Designer.cs
generated
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
namespace ComputersShopView
|
||||||
|
{
|
||||||
|
partial class FormShopReplenishment
|
||||||
|
{
|
||||||
|
/// <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.ShopNameLabel = new System.Windows.Forms.Label();
|
||||||
|
this.ComputerNameLabel = new System.Windows.Forms.Label();
|
||||||
|
this.CountLabel = new System.Windows.Forms.Label();
|
||||||
|
this.сomboBoxShopName = new System.Windows.Forms.ComboBox();
|
||||||
|
this.comboBoxComputerName = new System.Windows.Forms.ComboBox();
|
||||||
|
this.CountTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// ShopNameLabel
|
||||||
|
//
|
||||||
|
this.ShopNameLabel.AutoSize = true;
|
||||||
|
this.ShopNameLabel.Location = new System.Drawing.Point(12, 9);
|
||||||
|
this.ShopNameLabel.Name = "ShopNameLabel";
|
||||||
|
this.ShopNameLabel.Size = new System.Drawing.Size(119, 15);
|
||||||
|
this.ShopNameLabel.TabIndex = 0;
|
||||||
|
this.ShopNameLabel.Text = "Название магазина: ";
|
||||||
|
//
|
||||||
|
// ComputerNameLabel
|
||||||
|
//
|
||||||
|
this.ComputerNameLabel.AutoSize = true;
|
||||||
|
this.ComputerNameLabel.Location = new System.Drawing.Point(12, 37);
|
||||||
|
this.ComputerNameLabel.Name = "ComputerNameLabel";
|
||||||
|
this.ComputerNameLabel.Size = new System.Drawing.Size(137, 15);
|
||||||
|
this.ComputerNameLabel.TabIndex = 1;
|
||||||
|
this.ComputerNameLabel.Text = "Название компьютера: ";
|
||||||
|
//
|
||||||
|
// CountLabel
|
||||||
|
//
|
||||||
|
this.CountLabel.AutoSize = true;
|
||||||
|
this.CountLabel.Location = new System.Drawing.Point(12, 66);
|
||||||
|
this.CountLabel.Name = "CountLabel";
|
||||||
|
this.CountLabel.Size = new System.Drawing.Size(78, 15);
|
||||||
|
this.CountLabel.TabIndex = 2;
|
||||||
|
this.CountLabel.Text = "Количество: ";
|
||||||
|
//
|
||||||
|
// сomboBoxShopName
|
||||||
|
//
|
||||||
|
this.сomboBoxShopName.FormattingEnabled = true;
|
||||||
|
this.сomboBoxShopName.Location = new System.Drawing.Point(155, 6);
|
||||||
|
this.сomboBoxShopName.Name = "сomboBoxShopName";
|
||||||
|
this.сomboBoxShopName.Size = new System.Drawing.Size(192, 23);
|
||||||
|
this.сomboBoxShopName.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// comboBoxComputerName
|
||||||
|
//
|
||||||
|
this.comboBoxComputerName.FormattingEnabled = true;
|
||||||
|
this.comboBoxComputerName.Location = new System.Drawing.Point(155, 35);
|
||||||
|
this.comboBoxComputerName.Name = "comboBoxComputerName";
|
||||||
|
this.comboBoxComputerName.Size = new System.Drawing.Size(192, 23);
|
||||||
|
this.comboBoxComputerName.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// CountTextBox
|
||||||
|
//
|
||||||
|
this.CountTextBox.Location = new System.Drawing.Point(155, 64);
|
||||||
|
this.CountTextBox.Name = "CountTextBox";
|
||||||
|
this.CountTextBox.Size = new System.Drawing.Size(192, 23);
|
||||||
|
this.CountTextBox.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(191, 108);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||||
|
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(272, 108);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonCancel.TabIndex = 7;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormShopReplenishment
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(359, 150);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.CountTextBox);
|
||||||
|
this.Controls.Add(this.comboBoxComputerName);
|
||||||
|
this.Controls.Add(this.сomboBoxShopName);
|
||||||
|
this.Controls.Add(this.CountLabel);
|
||||||
|
this.Controls.Add(this.ComputerNameLabel);
|
||||||
|
this.Controls.Add(this.ShopNameLabel);
|
||||||
|
this.Name = "FormShopReplenishment";
|
||||||
|
this.Text = "Пополнение магазина";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label ShopNameLabel;
|
||||||
|
private Label ComputerNameLabel;
|
||||||
|
private Label CountLabel;
|
||||||
|
private ComboBox сomboBoxShopName;
|
||||||
|
private ComboBox comboBoxComputerName;
|
||||||
|
private TextBox CountTextBox;
|
||||||
|
private Button buttonSave;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
104
ComputersShop/ComputersShopView/FormShopReplenishment.cs
Normal file
104
ComputersShop/ComputersShopView/FormShopReplenishment.cs
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
using ComputersShopContracts.BusinessLogicContracts;
|
||||||
|
using ComputersShopContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ComputersShopView
|
||||||
|
{
|
||||||
|
public partial class FormShopReplenishment : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _shopLogic;
|
||||||
|
private readonly IComputerLogic _computerLogic;
|
||||||
|
private readonly List<ShopViewModel>? _listStores;
|
||||||
|
private readonly List<ComputerViewModel>? _listcomputers;
|
||||||
|
public FormShopReplenishment(ILogger<FormShopReplenishment> logger, IShopLogic shopLogic, IComputerLogic computerLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
_computerLogic = computerLogic;
|
||||||
|
_logger = logger;
|
||||||
|
_listStores = shopLogic.ReadList(null);
|
||||||
|
if (_listStores != null)
|
||||||
|
{
|
||||||
|
сomboBoxShopName.DisplayMember = "ShopName";
|
||||||
|
сomboBoxShopName.ValueMember = "Id";
|
||||||
|
сomboBoxShopName.DataSource = _listStores;
|
||||||
|
сomboBoxShopName.SelectedItem = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_listcomputers = computerLogic.ReadList(null);
|
||||||
|
if (_listcomputers != null)
|
||||||
|
{
|
||||||
|
comboBoxComputerName.DisplayMember = "ComputerName";
|
||||||
|
comboBoxComputerName.ValueMember = "Id";
|
||||||
|
comboBoxComputerName.DataSource = _listcomputers;
|
||||||
|
comboBoxComputerName.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (сomboBoxShopName.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comboBoxComputerName.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите компьютер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Добавление компьютер в магазин");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var computer = _computerLogic.ReadElement(new()
|
||||||
|
{
|
||||||
|
Id = (int)comboBoxComputerName.SelectedValue
|
||||||
|
});
|
||||||
|
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Не найден компьютер. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var resultOperation = _shopLogic.AddComputer(
|
||||||
|
model: new() { Id = (int)сomboBoxShopName.SelectedValue },
|
||||||
|
computer: computer,
|
||||||
|
quantity: Convert.ToInt32(CountTextBox.Text)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!resultOperation)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при добавлении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка сохранения компьютера");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/ComputersShopView/FormShopReplenishment.resx
Normal file
60
ComputersShop/ComputersShopView/FormShopReplenishment.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
114
ComputersShop/ComputersShopView/FormShops.Designer.cs
generated
Normal file
114
ComputersShop/ComputersShopView/FormShops.Designer.cs
generated
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
namespace ComputersShopView
|
||||||
|
{
|
||||||
|
partial class FormShops
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonChange = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDelete = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.RowTemplate.Height = 25;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(539, 426);
|
||||||
|
this.dataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(585, 12);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(121, 40);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.AddButton_Click);
|
||||||
|
//
|
||||||
|
// buttonChange
|
||||||
|
//
|
||||||
|
this.buttonChange.Location = new System.Drawing.Point(585, 67);
|
||||||
|
this.buttonChange.Name = "buttonChange";
|
||||||
|
this.buttonChange.Size = new System.Drawing.Size(121, 40);
|
||||||
|
this.buttonChange.TabIndex = 2;
|
||||||
|
this.buttonChange.Text = "Изменить";
|
||||||
|
this.buttonChange.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonChange.Click += new System.EventHandler(this.ChangeButton_Click);
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
this.buttonDelete.Location = new System.Drawing.Point(585, 122);
|
||||||
|
this.buttonDelete.Name = "buttonDelete";
|
||||||
|
this.buttonDelete.Size = new System.Drawing.Size(121, 40);
|
||||||
|
this.buttonDelete.TabIndex = 3;
|
||||||
|
this.buttonDelete.Text = "Удалить";
|
||||||
|
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDelete.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||||
|
//
|
||||||
|
// buttonUpdate
|
||||||
|
//
|
||||||
|
this.buttonUpdate.Location = new System.Drawing.Point(585, 179);
|
||||||
|
this.buttonUpdate.Name = "buttonUpdate";
|
||||||
|
this.buttonUpdate.Size = new System.Drawing.Size(121, 40);
|
||||||
|
this.buttonUpdate.TabIndex = 4;
|
||||||
|
this.buttonUpdate.Text = "Обновить";
|
||||||
|
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpdate.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||||
|
//
|
||||||
|
// FormShops
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(718, 450);
|
||||||
|
this.Controls.Add(this.buttonUpdate);
|
||||||
|
this.Controls.Add(this.buttonDelete);
|
||||||
|
this.Controls.Add(this.buttonChange);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Name = "FormShops";
|
||||||
|
this.Text = "Магазины";
|
||||||
|
this.Load += new System.EventHandler(this.FormShops_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private Button buttonChange;
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonUpdate;
|
||||||
|
}
|
||||||
|
}
|
122
ComputersShop/ComputersShopView/FormShops.cs
Normal file
122
ComputersShop/ComputersShopView/FormShops.cs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
using ComputersShopContracts.BindingModels;
|
||||||
|
using ComputersShopContracts.BusinessLogicContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ComputersShopView
|
||||||
|
{
|
||||||
|
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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Computers"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Загрузка магазинов");
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазинов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteButton_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 ChangeButton_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 AddButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||||
|
|
||||||
|
if (service is FormShop form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/ComputersShopView/FormShops.resx
Normal file
60
ComputersShop/ComputersShopView/FormShops.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -39,6 +39,7 @@ namespace ComputersShopView
|
|||||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||||
services.AddTransient<IComputerStorage, ComputerStorage>();
|
services.AddTransient<IComputerStorage, ComputerStorage>();
|
||||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
|
services.AddTransient<IShopStorage, ShopStorage>();
|
||||||
|
|
||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
services.AddTransient<IComputerLogic, ComputerLogic>();
|
services.AddTransient<IComputerLogic, ComputerLogic>();
|
||||||
@ -56,6 +57,10 @@ namespace ComputersShopView
|
|||||||
services.AddTransient<FormComputer>();
|
services.AddTransient<FormComputer>();
|
||||||
services.AddTransient<FormComputers>();
|
services.AddTransient<FormComputers>();
|
||||||
services.AddTransient<FormComputerComponent>();
|
services.AddTransient<FormComputerComponent>();
|
||||||
|
services.AddTransient<FormShop>();
|
||||||
|
services.AddTransient<FormShops>();
|
||||||
|
services.AddTransient<FormShopReplenishment>();
|
||||||
|
services.AddTransient<FormSellComputers>();
|
||||||
services.AddTransient<FormReportComputerComponents>();
|
services.AddTransient<FormReportComputerComponents>();
|
||||||
services.AddTransient<FormReportOrders>();
|
services.AddTransient<FormReportOrders>();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user