Lab2hard
This commit is contained in:
parent
74bffc351f
commit
76255378d1
@ -12,5 +12,6 @@ namespace ComputerShopDataModels.Models
|
|||||||
String Adress { get; }
|
String Adress { get; }
|
||||||
DateTime OpeningDate { get; }
|
DateTime OpeningDate { get; }
|
||||||
Dictionary<int, (IComputerModel, int)> ShopComputers { get; }
|
Dictionary<int, (IComputerModel, int)> ShopComputers { get; }
|
||||||
|
int MaxCountComputers { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
|
||||||
namespace ComputerShopBusinessLogic.BusinessLogics
|
namespace ComputerShopBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
@ -17,11 +18,17 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
private readonly IShopStorage _shopStorage;
|
||||||
|
private readonly IShopLogic _shopLogic;
|
||||||
|
private readonly IComputerStorage _computerStorage;
|
||||||
|
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IComputerStorage computerStorage, IShopStorage shopStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
_computerStorage = computerStorage;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
@ -50,6 +57,21 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
|||||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (newStatus == OrderStatus.Выдан)
|
||||||
|
{
|
||||||
|
var computer = _computerStorage.GetElement(new ComputerSearchModel() { Id = model.ComputerId });
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Computer not found.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (CheckThenSupplyMany(computer, model.Count) == false)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
model.Status = newStatus;
|
model.Status = newStatus;
|
||||||
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
||||||
if (_orderStorage.Update(model) == null)
|
if (_orderStorage.Update(model) == null)
|
||||||
@ -61,6 +83,67 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool CheckThenSupplyMany(IComputerModel computer, int count)
|
||||||
|
{
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Check then supply operation error. Computer count < 0.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int freeSpace = 0;
|
||||||
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
|
{
|
||||||
|
freeSpace += shop.MaxCountComputers;
|
||||||
|
foreach (var doc in shop.ShopComputers)
|
||||||
|
{
|
||||||
|
freeSpace -= doc.Value.Item2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (freeSpace - count < 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Check then supply operation error. There's no place for new docs in shops.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
|
{
|
||||||
|
freeSpace = shop.MaxCountComputers;
|
||||||
|
foreach (var doc in shop.ShopComputers)
|
||||||
|
{
|
||||||
|
freeSpace -= doc.Value.Item2;
|
||||||
|
}
|
||||||
|
if (freeSpace == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (freeSpace - count >= 0)
|
||||||
|
{
|
||||||
|
if (_shopLogic.SupplyComputers(new() { Id = shop.Id }, computer, count)) count = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Supply error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (freeSpace - count < 0)
|
||||||
|
{
|
||||||
|
if (_shopLogic.SupplyComputers(new() { Id = shop.Id }, computer, freeSpace)) count -= freeSpace;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Supply error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public bool TakeOrderInWork(OrderBindingModel model)
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||||
|
@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection.Metadata;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -81,29 +82,47 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
|
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
|
||||||
|
|
||||||
if (shopElement.ShopComputers.TryGetValue(computer.Id, out var sameComputer))
|
var countDocs = 0;
|
||||||
|
foreach (var doc in shopElement.ShopComputers)
|
||||||
{
|
{
|
||||||
shopElement.ShopComputers[computer.Id] = (computer, sameComputer.Item2 + count);
|
countDocs += doc.Value.Item2;
|
||||||
_logger.LogInformation("Same computer found by supply. Added {0} of {1} in {2} shop", count, computer.ComputerName, shopElement.Name);
|
}
|
||||||
|
if (shopElement.MaxCountComputers - countDocs >= count)
|
||||||
|
{
|
||||||
|
if (shopElement.ShopComputers.TryGetValue(computer.Id, out var sameComputer))
|
||||||
|
{
|
||||||
|
shopElement.ShopComputers[computer.Id] = (computer, sameComputer.Item2 + count);
|
||||||
|
_logger.LogInformation("Same computer found by supply. Added {0} of {1} in {2} shop", count, computer.ComputerName, shopElement.Name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shopElement.ShopComputers[computer.Id] = (computer, count);
|
||||||
|
_logger.LogInformation("New computer added by supply. Added {0} of {1} in {2} shop", count, computer.ComputerName, shopElement.Name);
|
||||||
|
}
|
||||||
|
_shopStorage.Update(new()
|
||||||
|
{
|
||||||
|
Id = shopElement.Id,
|
||||||
|
Name = shopElement.Name,
|
||||||
|
Adress = shopElement.Adress,
|
||||||
|
OpeningDate = shopElement.OpeningDate,
|
||||||
|
ShopComputers = shopElement.ShopComputers,
|
||||||
|
MaxCountComputers = shopElement.MaxCountComputers
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shopElement.ShopComputers[computer.Id] = (computer, count);
|
_logger.LogWarning("Required shop is overflowed");
|
||||||
_logger.LogInformation("New computer added by supply. Added {0} of {1} in {2} shop", count, computer.ComputerName, shopElement.Name);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_shopStorage.Update(new()
|
|
||||||
{
|
|
||||||
Id = shopElement.Id,
|
|
||||||
Name = shopElement.Name,
|
|
||||||
Adress = shopElement.Adress,
|
|
||||||
OpeningDate = shopElement.OpeningDate,
|
|
||||||
ShopComputers = shopElement.ShopComputers
|
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SellComputer(IComputerModel computer, int count)
|
||||||
|
{
|
||||||
|
;
|
||||||
|
return _shopStorage.SellComputer(computer, count);
|
||||||
|
}
|
||||||
|
|
||||||
public bool Create(ShopBindingModel model)
|
public bool Create(ShopBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
@ -153,6 +172,10 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name));
|
throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name));
|
||||||
}
|
}
|
||||||
|
if (model.MaxCountComputers < 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Магазин с отрицательным количеством максимального количества компьютеров!");
|
||||||
|
}
|
||||||
_logger.LogInformation("Shop. Name: {0}, Adress: {1}, ID: {2}", model.Name, model.Adress, model.Id);
|
_logger.LogInformation("Shop. Name: {0}, Adress: {1}, ID: {2}", model.Name, model.Adress, model.Id);
|
||||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||||
{
|
{
|
||||||
|
@ -18,5 +18,6 @@ namespace ComputerShopContracts.BindingModels
|
|||||||
public Dictionary<int, (IComputerModel, int)> ShopComputers { get; set; } = new();
|
public Dictionary<int, (IComputerModel, int)> ShopComputers { get; set; } = new();
|
||||||
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public int MaxCountComputers { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,5 +18,6 @@ namespace ComputerShopContracts.BusinessLogicsContracts
|
|||||||
bool Update(ShopBindingModel model);
|
bool Update(ShopBindingModel model);
|
||||||
bool Delete(ShopBindingModel model);
|
bool Delete(ShopBindingModel model);
|
||||||
bool SupplyComputers(ShopSearchModel model, IComputerModel computer, int count);
|
bool SupplyComputers(ShopSearchModel model, IComputerModel computer, int count);
|
||||||
|
bool SellComputer(IComputerModel computer, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using ComputerShopContracts.BindingModels;
|
using ComputerShopContracts.BindingModels;
|
||||||
using ComputerShopContracts.SearchModels;
|
using ComputerShopContracts.SearchModels;
|
||||||
using ComputerShopContracts.ViewModels;
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -17,5 +18,6 @@ namespace ComputerShopContracts.StoragesContracts
|
|||||||
ShopViewModel? Insert(ShopBindingModel model);
|
ShopViewModel? Insert(ShopBindingModel model);
|
||||||
ShopViewModel? Update(ShopBindingModel model);
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
ShopViewModel? Delete(ShopBindingModel model);
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
|
bool SellComputer(IComputerModel model, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,5 +20,7 @@ namespace ComputerShopContracts.ViewModels
|
|||||||
public Dictionary<int, (IComputerModel, int)> ShopComputers { get; set; } = new();
|
public Dictionary<int, (IComputerModel, int)> ShopComputers { get; set; } = new();
|
||||||
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Вместимость")]
|
||||||
|
public int MaxCountComputers { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,11 @@ namespace ComputerShopFileImplement
|
|||||||
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";
|
||||||
|
private readonly string ShopFileName = "Shop.xml";
|
||||||
public List<Component> Components { get; private set; }
|
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 List<Shop> Shops { get; private set; }
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
@ -30,11 +32,13 @@ namespace ComputerShopFileImplement
|
|||||||
public void SaveComputers() => SaveData(Computers, ComputerFileName,
|
public void SaveComputers() => SaveData(Computers, ComputerFileName,
|
||||||
"Computers", x => x.GetXElement);
|
"Computers", x => x.GetXElement);
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
|
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||||
private DataFileSingleton()
|
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,
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||||
Func<XElement, T> selectFunction)
|
Func<XElement, T> selectFunction)
|
||||||
|
148
ComputerShopFileImplement/Implements/ShopStorage.cs
Normal file
148
ComputerShopFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StoragesContracts;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using ComputerShopFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.Name))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Shops
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.Where(x => x.Name.Contains(model.Name ?? string.Empty))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Shops.Select(shop => shop.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newShop = Shop.Create(model);
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Shops.Add(newShop);
|
||||||
|
source.SaveShops();
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
shop.Update(model);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Shops.Remove(shop);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SellComputer(IComputerModel model, int count)
|
||||||
|
{
|
||||||
|
var computer = source.Computers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var countStore = count;
|
||||||
|
|
||||||
|
var shopComputers = source.Shops.SelectMany(shop => shop.ShopComputers.Where(doc => doc.Value.Item1.Id == computer.Id));
|
||||||
|
|
||||||
|
foreach (var doc in shopComputers)
|
||||||
|
{
|
||||||
|
count -= doc.Value.Item2;
|
||||||
|
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
count = countStore;
|
||||||
|
|
||||||
|
foreach (var shop in source.Shops)
|
||||||
|
{
|
||||||
|
var computers = shop.ShopComputers;
|
||||||
|
|
||||||
|
foreach (var doc in computers.Where(x => x.Value.Item1.Id == computer.Id))
|
||||||
|
{
|
||||||
|
var min = Math.Min(doc.Value.Item2, count);
|
||||||
|
computers[doc.Value.Item1.Id] = (doc.Value.Item1, doc.Value.Item2 - min);
|
||||||
|
count -= min;
|
||||||
|
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shop.Update(new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = shop.Id,
|
||||||
|
Name = shop.Name,
|
||||||
|
Adress = shop.Adress,
|
||||||
|
OpeningDate = shop.OpeningDate,
|
||||||
|
MaxCountComputers = shop.MaxCountComputers,
|
||||||
|
ShopComputers = computers
|
||||||
|
});
|
||||||
|
|
||||||
|
source.SaveShops();
|
||||||
|
|
||||||
|
if (count <= 0) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count <= 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
122
ComputerShopFileImplement/Models/Shop.cs
Normal file
122
ComputerShopFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ComputerShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Adress { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public int MaxCountComputers { get; private set; }
|
||||||
|
|
||||||
|
public DateTime OpeningDate { get; private set; }
|
||||||
|
|
||||||
|
public Dictionary<int, int> Computers { get; private set; } = new();
|
||||||
|
|
||||||
|
private Dictionary<int, (IComputerModel, int)>? _shopComputers = null;
|
||||||
|
|
||||||
|
public Dictionary<int, (IComputerModel, int)> ShopComputers
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopComputers == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_shopComputers = Computers.ToDictionary(
|
||||||
|
x => x.Key,
|
||||||
|
y => ((source.Computers.FirstOrDefault(z => z.Id == y.Key) as IComputerModel)!, y.Value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _shopComputers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Name = model.Name,
|
||||||
|
Adress = model.Adress,
|
||||||
|
MaxCountComputers = model.MaxCountComputers,
|
||||||
|
OpeningDate = model.OpeningDate,
|
||||||
|
Computers = model.ShopComputers.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Shop? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
Name = element.Element("Name")!.Value,
|
||||||
|
Adress = element.Element("Address")!.Value,
|
||||||
|
MaxCountComputers = Convert.ToInt32(element.Element("MaxCountComputers")!.Value),
|
||||||
|
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||||
|
Computers = element.Element("ShopComputers")!.Elements("ShopComputer").ToDictionary(
|
||||||
|
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||||
|
x => Convert.ToInt32(x.Element("Value")?.Value)
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Name = model.Name;
|
||||||
|
Adress = model.Adress;
|
||||||
|
OpeningDate = model.OpeningDate;
|
||||||
|
MaxCountComputers = model.MaxCountComputers;
|
||||||
|
if (model.ShopComputers.Count > 0)
|
||||||
|
{
|
||||||
|
Computers = model.ShopComputers.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_shopComputers = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
Adress = Adress,
|
||||||
|
OpeningDate = OpeningDate,
|
||||||
|
ShopComputers = ShopComputers,
|
||||||
|
MaxCountComputers = MaxCountComputers
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new(
|
||||||
|
"Shop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("Name", Name),
|
||||||
|
new XElement("Address", Adress),
|
||||||
|
new XElement("MaxCountComputers", MaxCountComputers),
|
||||||
|
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||||
|
new XElement("ShopComputers", Computers.Select(x =>
|
||||||
|
new XElement("ShopComputer",
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
new XElement("Value", x.Value)))
|
||||||
|
.ToArray()));
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
using ComputerShopContracts.SearchModels;
|
using ComputerShopContracts.SearchModels;
|
||||||
using ComputerShopContracts.StoragesContracts;
|
using ComputerShopContracts.StoragesContracts;
|
||||||
using ComputerShopContracts.ViewModels;
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Models;
|
||||||
using ComputerShopListImplement.Models;
|
using ComputerShopListImplement.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -114,5 +115,10 @@ namespace ComputerShopListImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SellComputer(IComputerModel model, int count)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ namespace ComputerShopListImplement.Models
|
|||||||
public DateTime OpeningDate { get; private set; }
|
public DateTime OpeningDate { get; private set; }
|
||||||
|
|
||||||
public Dictionary<int, (IComputerModel, int)> ShopComputers { get; private set; } = new();
|
public Dictionary<int, (IComputerModel, int)> ShopComputers { get; private set; } = new();
|
||||||
|
public int MaxCountComputers { get; private set; }
|
||||||
|
|
||||||
public static Shop? Create(ShopBindingModel model)
|
public static Shop? Create(ShopBindingModel model)
|
||||||
{
|
{
|
||||||
@ -33,7 +34,8 @@ namespace ComputerShopListImplement.Models
|
|||||||
Name = model.Name,
|
Name = model.Name,
|
||||||
Adress = model.Adress,
|
Adress = model.Adress,
|
||||||
OpeningDate = model.OpeningDate,
|
OpeningDate = model.OpeningDate,
|
||||||
ShopComputers = new()
|
ShopComputers = new(),
|
||||||
|
MaxCountComputers = model.MaxCountComputers
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +49,7 @@ namespace ComputerShopListImplement.Models
|
|||||||
Adress = model.Adress;
|
Adress = model.Adress;
|
||||||
OpeningDate = model.OpeningDate;
|
OpeningDate = model.OpeningDate;
|
||||||
ShopComputers = model.ShopComputers;
|
ShopComputers = model.ShopComputers;
|
||||||
|
MaxCountComputers = model.MaxCountComputers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShopViewModel GetViewModel => new()
|
public ShopViewModel GetViewModel => new()
|
||||||
@ -55,7 +58,8 @@ namespace ComputerShopListImplement.Models
|
|||||||
Name = Name,
|
Name = Name,
|
||||||
Adress = Adress,
|
Adress = Adress,
|
||||||
OpeningDate = OpeningDate,
|
OpeningDate = OpeningDate,
|
||||||
ShopComputers = ShopComputers
|
ShopComputers = ShopComputers,
|
||||||
|
MaxCountComputers = MaxCountComputers
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
ComputersShop/FormMain.Designer.cs
generated
14
ComputersShop/FormMain.Designer.cs
generated
@ -40,6 +40,7 @@
|
|||||||
this.ButtonIssuedOrder = new System.Windows.Forms.Button();
|
this.ButtonIssuedOrder = new System.Windows.Forms.Button();
|
||||||
this.ButtonRef = new System.Windows.Forms.Button();
|
this.ButtonRef = new System.Windows.Forms.Button();
|
||||||
this.buttonSupplyShop = new System.Windows.Forms.Button();
|
this.buttonSupplyShop = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSellComputers = new System.Windows.Forms.Button();
|
||||||
this.menuStrip1.SuspendLayout();
|
this.menuStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -155,11 +156,23 @@
|
|||||||
this.buttonSupplyShop.UseVisualStyleBackColor = true;
|
this.buttonSupplyShop.UseVisualStyleBackColor = true;
|
||||||
this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click);
|
this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click);
|
||||||
//
|
//
|
||||||
|
// buttonSellComputers
|
||||||
|
//
|
||||||
|
this.buttonSellComputers.Location = new System.Drawing.Point(786, 181);
|
||||||
|
this.buttonSellComputers.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonSellComputers.Name = "buttonSellComputers";
|
||||||
|
this.buttonSellComputers.Size = new System.Drawing.Size(192, 22);
|
||||||
|
this.buttonSellComputers.TabIndex = 9;
|
||||||
|
this.buttonSellComputers.Text = "Продажа компьютеров";
|
||||||
|
this.buttonSellComputers.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSellComputers.Click += new System.EventHandler(this.buttonSellComputers_Click);
|
||||||
|
//
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(1006, 323);
|
this.ClientSize = new System.Drawing.Size(1006, 323);
|
||||||
|
this.Controls.Add(this.buttonSellComputers);
|
||||||
this.Controls.Add(this.buttonSupplyShop);
|
this.Controls.Add(this.buttonSupplyShop);
|
||||||
this.Controls.Add(this.ButtonRef);
|
this.Controls.Add(this.ButtonRef);
|
||||||
this.Controls.Add(this.ButtonIssuedOrder);
|
this.Controls.Add(this.ButtonIssuedOrder);
|
||||||
@ -194,5 +207,6 @@
|
|||||||
private Button ButtonRef;
|
private Button ButtonRef;
|
||||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||||
private Button buttonSupplyShop;
|
private Button buttonSupplyShop;
|
||||||
|
private Button buttonSellComputers;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -193,5 +193,14 @@ namespace ComputersShop
|
|||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonSellComputers_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
|
||||||
|
if (service is FormShopSell form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
ComputersShop/FormShop.Designer.cs
generated
31
ComputersShop/FormShop.Designer.cs
generated
@ -40,12 +40,14 @@
|
|||||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||||
this.labelAddress = new System.Windows.Forms.Label();
|
this.labelAddress = new System.Windows.Forms.Label();
|
||||||
this.labelName = new System.Windows.Forms.Label();
|
this.labelName = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxCapacity = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelCapacity = new System.Windows.Forms.Label();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
this.buttonCancel.Location = new System.Drawing.Point(200, 339);
|
this.buttonCancel.Location = new System.Drawing.Point(200, 375);
|
||||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
this.buttonCancel.Name = "buttonCancel";
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
this.buttonCancel.Size = new System.Drawing.Size(136, 22);
|
this.buttonCancel.Size = new System.Drawing.Size(136, 22);
|
||||||
@ -56,7 +58,7 @@
|
|||||||
//
|
//
|
||||||
// buttonSave
|
// buttonSave
|
||||||
//
|
//
|
||||||
this.buttonSave.Location = new System.Drawing.Point(42, 339);
|
this.buttonSave.Location = new System.Drawing.Point(42, 375);
|
||||||
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
this.buttonSave.Name = "buttonSave";
|
this.buttonSave.Name = "buttonSave";
|
||||||
this.buttonSave.Size = new System.Drawing.Size(136, 22);
|
this.buttonSave.Size = new System.Drawing.Size(136, 22);
|
||||||
@ -72,7 +74,7 @@
|
|||||||
this.ColumnId,
|
this.ColumnId,
|
||||||
this.ColumnComputerName,
|
this.ColumnComputerName,
|
||||||
this.ColumnCount});
|
this.ColumnCount});
|
||||||
this.dataGridView.Location = new System.Drawing.Point(12, 107);
|
this.dataGridView.Location = new System.Drawing.Point(12, 143);
|
||||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
this.dataGridView.Name = "dataGridView";
|
this.dataGridView.Name = "dataGridView";
|
||||||
this.dataGridView.RowHeadersWidth = 51;
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
@ -153,11 +155,30 @@
|
|||||||
this.labelName.TabIndex = 13;
|
this.labelName.TabIndex = 13;
|
||||||
this.labelName.Text = "Название:";
|
this.labelName.Text = "Название:";
|
||||||
//
|
//
|
||||||
|
// textBoxCapacity
|
||||||
|
//
|
||||||
|
this.textBoxCapacity.Location = new System.Drawing.Point(117, 91);
|
||||||
|
this.textBoxCapacity.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.textBoxCapacity.Name = "textBoxCapacity";
|
||||||
|
this.textBoxCapacity.Size = new System.Drawing.Size(246, 23);
|
||||||
|
this.textBoxCapacity.TabIndex = 23;
|
||||||
|
//
|
||||||
|
// labelCapacity
|
||||||
|
//
|
||||||
|
this.labelCapacity.AutoSize = true;
|
||||||
|
this.labelCapacity.Location = new System.Drawing.Point(11, 93);
|
||||||
|
this.labelCapacity.Name = "labelCapacity";
|
||||||
|
this.labelCapacity.Size = new System.Drawing.Size(83, 15);
|
||||||
|
this.labelCapacity.TabIndex = 22;
|
||||||
|
this.labelCapacity.Text = "Вместимость:";
|
||||||
|
//
|
||||||
// FormShop
|
// FormShop
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(383, 368);
|
this.ClientSize = new System.Drawing.Size(383, 399);
|
||||||
|
this.Controls.Add(this.textBoxCapacity);
|
||||||
|
this.Controls.Add(this.labelCapacity);
|
||||||
this.Controls.Add(this.buttonCancel);
|
this.Controls.Add(this.buttonCancel);
|
||||||
this.Controls.Add(this.buttonSave);
|
this.Controls.Add(this.buttonSave);
|
||||||
this.Controls.Add(this.dataGridView);
|
this.Controls.Add(this.dataGridView);
|
||||||
@ -190,5 +211,7 @@
|
|||||||
private DataGridViewTextBoxColumn ColumnId;
|
private DataGridViewTextBoxColumn ColumnId;
|
||||||
private DataGridViewTextBoxColumn ColumnComputerName;
|
private DataGridViewTextBoxColumn ColumnComputerName;
|
||||||
private DataGridViewTextBoxColumn ColumnCount;
|
private DataGridViewTextBoxColumn ColumnCount;
|
||||||
|
private TextBox textBoxCapacity;
|
||||||
|
private Label labelCapacity;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,6 +48,7 @@ namespace ComputersShop
|
|||||||
textBoxName.Text = view.Name;
|
textBoxName.Text = view.Name;
|
||||||
textBoxAddress.Text = view.Adress;
|
textBoxAddress.Text = view.Adress;
|
||||||
_shopComputers = view.ShopComputers ?? new Dictionary<int, (IComputerModel, int)>();
|
_shopComputers = view.ShopComputers ?? new Dictionary<int, (IComputerModel, int)>();
|
||||||
|
textBoxCapacity.Text = view.MaxCountComputers.ToString();
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,6 +101,11 @@ namespace ComputersShop
|
|||||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxCapacity.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
_logger.LogInformation("Сохранение магазина");
|
_logger.LogInformation("Сохранение магазина");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -109,7 +115,8 @@ namespace ComputersShop
|
|||||||
Name = textBoxName.Text,
|
Name = textBoxName.Text,
|
||||||
Adress = textBoxAddress.Text,
|
Adress = textBoxAddress.Text,
|
||||||
OpeningDate = dateTimePicker.Value.Date,
|
OpeningDate = dateTimePicker.Value.Date,
|
||||||
ShopComputers = _shopComputers
|
ShopComputers = _shopComputers,
|
||||||
|
MaxCountComputers = Convert.ToInt32(textBoxCapacity.Text)
|
||||||
};
|
};
|
||||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
|
@ -66,13 +66,4 @@
|
|||||||
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="ColumnId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="ColumnComputerName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
|
||||||
</metadata>
|
|
||||||
</root>
|
</root>
|
124
ComputersShop/FormShopSell.Designer.cs
generated
Normal file
124
ComputersShop/FormShopSell.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
partial class FormShopSell
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSell = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxComputer = new System.Windows.Forms.ComboBox();
|
||||||
|
this.labelComputer = new System.Windows.Forms.Label();
|
||||||
|
this.labelCount = new System.Windows.Forms.Label();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(263, 99);
|
||||||
|
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
|
||||||
|
this.buttonCancel.TabIndex = 13;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||||
|
//
|
||||||
|
// buttonSell
|
||||||
|
//
|
||||||
|
this.buttonSell.Location = new System.Drawing.Point(157, 99);
|
||||||
|
this.buttonSell.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.buttonSell.Name = "buttonSell";
|
||||||
|
this.buttonSell.Size = new System.Drawing.Size(82, 22);
|
||||||
|
this.buttonSell.TabIndex = 12;
|
||||||
|
this.buttonSell.Text = "Продажа";
|
||||||
|
this.buttonSell.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click);
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
this.textBoxCount.Location = new System.Drawing.Point(101, 48);
|
||||||
|
this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.textBoxCount.Name = "textBoxCount";
|
||||||
|
this.textBoxCount.Size = new System.Drawing.Size(139, 23);
|
||||||
|
this.textBoxCount.TabIndex = 11;
|
||||||
|
//
|
||||||
|
// comboBoxComputer
|
||||||
|
//
|
||||||
|
this.comboBoxComputer.FormattingEnabled = true;
|
||||||
|
this.comboBoxComputer.Location = new System.Drawing.Point(101, 11);
|
||||||
|
this.comboBoxComputer.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||||
|
this.comboBoxComputer.Name = "comboBoxComputer";
|
||||||
|
this.comboBoxComputer.Size = new System.Drawing.Size(244, 23);
|
||||||
|
this.comboBoxComputer.TabIndex = 10;
|
||||||
|
//
|
||||||
|
// labelComputer
|
||||||
|
//
|
||||||
|
this.labelComputer.AutoSize = true;
|
||||||
|
this.labelComputer.Location = new System.Drawing.Point(13, 11);
|
||||||
|
this.labelComputer.Name = "labelComputer";
|
||||||
|
this.labelComputer.Size = new System.Drawing.Size(74, 15);
|
||||||
|
this.labelComputer.TabIndex = 9;
|
||||||
|
this.labelComputer.Text = "Компьютер:";
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
this.labelCount.AutoSize = true;
|
||||||
|
this.labelCount.Location = new System.Drawing.Point(13, 50);
|
||||||
|
this.labelCount.Name = "labelCount";
|
||||||
|
this.labelCount.Size = new System.Drawing.Size(75, 15);
|
||||||
|
this.labelCount.TabIndex = 8;
|
||||||
|
this.labelCount.Text = "Количество:";
|
||||||
|
//
|
||||||
|
// FormShopSell
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(369, 136);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSell);
|
||||||
|
this.Controls.Add(this.textBoxCount);
|
||||||
|
this.Controls.Add(this.comboBoxComputer);
|
||||||
|
this.Controls.Add(this.labelComputer);
|
||||||
|
this.Controls.Add(this.labelCount);
|
||||||
|
this.Name = "FormShopSell";
|
||||||
|
this.Text = "FormShopSell";
|
||||||
|
this.Load += new System.EventHandler(this.FormShopSell_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSell;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private ComboBox comboBoxComputer;
|
||||||
|
private Label labelComputer;
|
||||||
|
private Label labelCount;
|
||||||
|
}
|
||||||
|
}
|
96
ComputersShop/FormShopSell.cs
Normal file
96
ComputersShop/FormShopSell.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using ComputerShopContracts.BindingModels;
|
||||||
|
using ComputerShopContracts.BusinessLogicsContracts;
|
||||||
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ComputersShop
|
||||||
|
{
|
||||||
|
public partial class FormShopSell : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComputerLogic _logicC;
|
||||||
|
private readonly IShopLogic _logicS;
|
||||||
|
|
||||||
|
public FormShopSell(ILogger<FormShopSell> logger, IComputerLogic logicC, IShopLogic logicS)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicC = logicC;
|
||||||
|
_logicS = logicS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormShopSell_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка компьютеров для продажи");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logicC.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
comboBoxComputer.DisplayMember = "ComputerName";
|
||||||
|
comboBoxComputer.ValueMember = "Id";
|
||||||
|
comboBoxComputer.DataSource = list;
|
||||||
|
comboBoxComputer.SelectedItem = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки списка компьютеров");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSell_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxComputer.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите компьютер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Создание продажи");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicS.SellComputer(
|
||||||
|
new ComputerBindingModel
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(comboBoxComputer.SelectedValue)
|
||||||
|
},
|
||||||
|
Convert.ToInt32(textBoxCount.Text)
|
||||||
|
);
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при создании продажи. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания продажи");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
ComputersShop/FormShopSell.resx
Normal file
60
ComputersShop/FormShopSell.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -51,6 +51,7 @@ namespace ComputersShop
|
|||||||
services.AddTransient<FormShop>();
|
services.AddTransient<FormShop>();
|
||||||
services.AddTransient<FormShops>();
|
services.AddTransient<FormShops>();
|
||||||
services.AddTransient<FormShopSupply>();
|
services.AddTransient<FormShopSupply>();
|
||||||
|
services.AddTransient<FormShopSell>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user