Готовая 2 лабораторная (Усложненная)
This commit is contained in:
parent
81ab13fe86
commit
31bcb77f01
@ -4,6 +4,7 @@ using IceCreamShopContracts.SearchModels;
|
|||||||
using IceCreamShopContracts.StoragesContracts;
|
using IceCreamShopContracts.StoragesContracts;
|
||||||
using IceCreamShopContracts.ViewModels;
|
using IceCreamShopContracts.ViewModels;
|
||||||
using IceCreamShopDataModels.Enums;
|
using IceCreamShopDataModels.Enums;
|
||||||
|
using IceCreamShopDataModels.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace IceCreamShopBusinessLogic.BusinessLogics
|
namespace IceCreamShopBusinessLogic.BusinessLogics
|
||||||
@ -14,10 +15,20 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
private readonly IIceCreamStorage _iceCreamStorage;
|
||||||
|
|
||||||
|
private readonly IShopStorage _shopStorage;
|
||||||
|
|
||||||
|
private readonly IShopLogic _shopLogic;
|
||||||
|
|
||||||
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IIceCreamStorage iceCreamStorage,
|
||||||
|
IShopStorage shopStorage, IShopLogic shopLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_iceCreamStorage = iceCreamStorage;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
@ -106,15 +117,26 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
|||||||
newStatus, order.Status);
|
newStatus, order.Status);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
model.IceCreamId = order.IceCreamId;
|
if (newStatus == OrderStatus.Выдан)
|
||||||
model.Count = order.Count;
|
{
|
||||||
model.Sum = order.Sum;
|
var iceCream = _iceCreamStorage.GetElement(new IceCreamSearchModel() { Id = order.IceCreamId });
|
||||||
model.DateCreate = order.DateCreate;
|
if (iceCream == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Change status operation failed. Ice cream not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!DeliverIceCreams(iceCream, order.Count))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Change status operation failed. Ice creams delivery operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
model.Status = newStatus;
|
model.Status = newStatus;
|
||||||
if (model.Status == OrderStatus.Готов)
|
if (model.Status == OrderStatus.Готов)
|
||||||
{
|
{
|
||||||
model.DateImplement = DateTime.Now;
|
model.DateImplement = DateTime.Now;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
model.DateImplement = order.DateImplement;
|
model.DateImplement = order.DateImplement;
|
||||||
}
|
}
|
||||||
@ -125,5 +147,65 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool DeliverIceCreams(IIceCreamModel iceCream, int count)
|
||||||
|
{
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Ice creams delivery operation failed. Ice cream count <= 0");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var shopList = _shopStorage.GetFullList();
|
||||||
|
int shopsCapacity = shopList.Sum(x => x.IceCreamsMaximum);
|
||||||
|
int currentIceCreams = shopList.Select(x => x.ShopIceCreams.Select(y => y.Value.Item2).Sum()).Sum();
|
||||||
|
int freePlaces = shopsCapacity - currentIceCreams;
|
||||||
|
|
||||||
|
if (freePlaces < count)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Ice creams delivery operation failed. No space for new ice creams");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var shop in shopList)
|
||||||
|
{
|
||||||
|
freePlaces = shop.IceCreamsMaximum - shop.ShopIceCreams.Sum(x => x.Value.Item2);
|
||||||
|
if (freePlaces == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (freePlaces >= count)
|
||||||
|
{
|
||||||
|
if (_shopLogic.MakeShipment(new() { Id = shop.Id }, iceCream, count))
|
||||||
|
{
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Ice creams delivery operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_shopLogic.MakeShipment(new() { Id = shop.Id }, iceCream, freePlaces))
|
||||||
|
{
|
||||||
|
count -= freePlaces;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Ice creams delivery operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,11 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
|||||||
_logger.LogWarning("MakeShipment(GetElement). Element not found");
|
_logger.LogWarning("MakeShipment(GetElement). Element not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (shop.IceCreamsMaximum - shop.ShopIceCreams.Sum(x => x.Value.Item2) < count)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("MakeShipment error. No space for new ice creams");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (shop.ShopIceCreams.ContainsKey(iceCream.Id))
|
if (shop.ShopIceCreams.ContainsKey(iceCream.Id))
|
||||||
{
|
{
|
||||||
var shopIC = shop.ShopIceCreams[iceCream.Id];
|
var shopIC = shop.ShopIceCreams[iceCream.Id];
|
||||||
@ -125,6 +130,7 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
|||||||
ShopName = shop.ShopName,
|
ShopName = shop.ShopName,
|
||||||
Address = shop.Address,
|
Address = shop.Address,
|
||||||
DateOpening = shop.DateOpening,
|
DateOpening = shop.DateOpening,
|
||||||
|
IceCreamsMaximum = shop.IceCreamsMaximum,
|
||||||
ShopIceCreams = shop.ShopIceCreams,
|
ShopIceCreams = shop.ShopIceCreams,
|
||||||
}) == null)
|
}) == null)
|
||||||
{
|
{
|
||||||
@ -134,6 +140,11 @@ namespace IceCreamShopBusinessLogic.BusinessLogics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool MakeSale(IIceCreamModel model, int count)
|
||||||
|
{
|
||||||
|
return _shopStorage.MakeSale(model, count);
|
||||||
|
}
|
||||||
|
|
||||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
|
@ -17,5 +17,7 @@ namespace IceCreamShopContracts.BindingModels
|
|||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new();
|
} = new();
|
||||||
|
|
||||||
|
public int IceCreamsMaximum { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,5 +18,7 @@ namespace IceCreamShopContracts.BusinessLogicsContracts
|
|||||||
bool Delete(ShopBindingModel model);
|
bool Delete(ShopBindingModel model);
|
||||||
|
|
||||||
bool MakeShipment(ShopSearchModel shopModel, IIceCreamModel iceCream, int count);
|
bool MakeShipment(ShopSearchModel shopModel, IIceCreamModel iceCream, int count);
|
||||||
|
|
||||||
|
bool MakeSale(IIceCreamModel model, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using IceCreamShopContracts.BindingModels;
|
using IceCreamShopContracts.BindingModels;
|
||||||
using IceCreamShopContracts.SearchModels;
|
using IceCreamShopContracts.SearchModels;
|
||||||
using IceCreamShopContracts.ViewModels;
|
using IceCreamShopContracts.ViewModels;
|
||||||
|
using IceCreamShopDataModels.Models;
|
||||||
|
|
||||||
namespace IceCreamShopContracts.StoragesContracts
|
namespace IceCreamShopContracts.StoragesContracts
|
||||||
{
|
{
|
||||||
@ -17,5 +18,7 @@ namespace IceCreamShopContracts.StoragesContracts
|
|||||||
ShopViewModel? Update(ShopBindingModel model);
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
|
|
||||||
ShopViewModel? Delete(ShopBindingModel model);
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
|
|
||||||
|
bool MakeSale(IIceCreamModel model, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,5 +21,8 @@ namespace IceCreamShopContracts.ViewModels
|
|||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new();
|
} = new();
|
||||||
|
|
||||||
|
[DisplayName("Максимальное количество мороженого")]
|
||||||
|
public int IceCreamsMaximum { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,7 @@
|
|||||||
DateTime DateOpening { get; }
|
DateTime DateOpening { get; }
|
||||||
|
|
||||||
Dictionary<int, (IIceCreamModel, int)> ShopIceCreams { get; }
|
Dictionary<int, (IIceCreamModel, int)> ShopIceCreams { get; }
|
||||||
|
|
||||||
|
int IceCreamsMaximum { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,16 @@ namespace IceCreamShopFileImplement
|
|||||||
|
|
||||||
private readonly string IceCreamFileName = "IceCream.xml";
|
private readonly string IceCreamFileName = "IceCream.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<IceCream> IceCreams { get; private set; }
|
public List<IceCream> IceCreams { get; private set; }
|
||||||
|
|
||||||
|
public List<Shop> Shops { get; private set; }
|
||||||
|
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
@ -34,11 +38,14 @@ namespace IceCreamShopFileImplement
|
|||||||
|
|
||||||
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)!)!;
|
||||||
IceCreams = LoadData(IceCreamFileName, "IceCream", x => IceCream.Create(x)!)!;
|
IceCreams = LoadData(IceCreamFileName, "IceCream", x => IceCream.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)
|
||||||
|
134
IceCreamShop/IceCreamShopFileImplement/Implements/ShopStorage.cs
Normal file
134
IceCreamShop/IceCreamShopFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
using IceCreamShopContracts.BindingModels;
|
||||||
|
using IceCreamShopContracts.SearchModels;
|
||||||
|
using IceCreamShopContracts.StoragesContracts;
|
||||||
|
using IceCreamShopContracts.ViewModels;
|
||||||
|
using IceCreamShopDataModels.Models;
|
||||||
|
using IceCreamShopFileImplement.Models;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace IceCreamShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Shops
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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 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 element = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Shops.Remove(element);
|
||||||
|
source.SaveShops();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MakeSale(IIceCreamModel model, int count)
|
||||||
|
{
|
||||||
|
var iceCream = source.IceCreams.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
int countInShops = source.Shops.Select(x => x.ShopIceCreams.Any(y => y.Key == model.Id)
|
||||||
|
? x.ShopIceCreams.Where(y => y.Key == model.Id).First().Value.Item2 : 0).Sum();
|
||||||
|
|
||||||
|
if (iceCream == null || countInShops < count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var shop in source.Shops)
|
||||||
|
{
|
||||||
|
var shopIceCreams = shop.ShopIceCreams.Where(x => x.Key == model.Id);
|
||||||
|
if (shopIceCreams.Any())
|
||||||
|
{
|
||||||
|
var shopIceCream = shopIceCreams.First();
|
||||||
|
int min = Math.Min(shopIceCream.Value.Item2, count);
|
||||||
|
if (min == shopIceCream.Value.Item2)
|
||||||
|
{
|
||||||
|
shop.ShopIceCreams.Remove(shopIceCream.Key);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shop.ShopIceCreams[shopIceCream.Key] = (shopIceCream.Value.Item1, shopIceCream.Value.Item2 - min);
|
||||||
|
}
|
||||||
|
shop.Update(new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = shop.ShopName,
|
||||||
|
Address = shop.Address,
|
||||||
|
DateOpening = shop.DateOpening,
|
||||||
|
ShopIceCreams = shop.ShopIceCreams,
|
||||||
|
IceCreamsMaximum = shop.IceCreamsMaximum
|
||||||
|
});
|
||||||
|
count -= min;
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
source.SaveShops();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
108
IceCreamShop/IceCreamShopFileImplement/Models/Shop.cs
Normal file
108
IceCreamShop/IceCreamShopFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
using IceCreamShopContracts.BindingModels;
|
||||||
|
using IceCreamShopContracts.ViewModels;
|
||||||
|
using IceCreamShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace IceCreamShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
public string ShopName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Address { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime DateOpening { get; private set; }
|
||||||
|
|
||||||
|
public Dictionary<int, int> IceCreams { get; private set; } = new();
|
||||||
|
|
||||||
|
private Dictionary<int, (IIceCreamModel, int)>? _shopIceCreams = null;
|
||||||
|
|
||||||
|
public Dictionary<int, (IIceCreamModel, int)> ShopIceCreams
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopIceCreams == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_shopIceCreams = IceCreams.ToDictionary(x => x.Key,
|
||||||
|
y => ((source.IceCreams.FirstOrDefault(z => z.Id == y.Key) as IIceCreamModel)!, y.Value));
|
||||||
|
}
|
||||||
|
return _shopIceCreams;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int IceCreamsMaximum { get; private set; }
|
||||||
|
|
||||||
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
Address = model.Address,
|
||||||
|
DateOpening = model.DateOpening,
|
||||||
|
IceCreams = model.ShopIceCreams.ToDictionary(x => x.Key, x => x.Value.Item2),
|
||||||
|
IceCreamsMaximum = model.IceCreamsMaximum
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Shop? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ShopName = element.Element("ShopName")!.Value,
|
||||||
|
Address = element.Element("Address")!.Value,
|
||||||
|
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
|
||||||
|
IceCreamsMaximum = Convert.ToInt32(element.Element("IceCreamsMaximum")!.Value),
|
||||||
|
IceCreams = element.Element("ShopIceCreams")!.Elements("ShopIceCream")
|
||||||
|
.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Address = model.Address;
|
||||||
|
DateOpening = model.DateOpening;
|
||||||
|
IceCreamsMaximum = model.IceCreamsMaximum;
|
||||||
|
IceCreams = model.ShopIceCreams.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_shopIceCreams = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Address = Address,
|
||||||
|
DateOpening = DateOpening,
|
||||||
|
ShopIceCreams = ShopIceCreams,
|
||||||
|
IceCreamsMaximum = IceCreamsMaximum
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Shop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ShopName", ShopName),
|
||||||
|
new XElement("Address", Address),
|
||||||
|
new XElement("DateOpening", DateOpening.ToString()),
|
||||||
|
new XElement("IceCreamsMaximum", IceCreamsMaximum.ToString()),
|
||||||
|
new XElement("ShopIceCreams",
|
||||||
|
IceCreams.Select(x => new XElement("ShopIceCream",
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
new XElement("Value", x.Value))).ToArray()));
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
using IceCreamShopContracts.SearchModels;
|
using IceCreamShopContracts.SearchModels;
|
||||||
using IceCreamShopContracts.StoragesContracts;
|
using IceCreamShopContracts.StoragesContracts;
|
||||||
using IceCreamShopContracts.ViewModels;
|
using IceCreamShopContracts.ViewModels;
|
||||||
|
using IceCreamShopDataModels.Models;
|
||||||
using IceCreamShopListImplement.Models;
|
using IceCreamShopListImplement.Models;
|
||||||
|
|
||||||
namespace IceCreamShopListImplement.Implements
|
namespace IceCreamShopListImplement.Implements
|
||||||
@ -104,6 +105,11 @@ namespace IceCreamShopListImplement.Implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool MakeSale(IIceCreamModel model, int count)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ namespace IceCreamShopListImplement.Models
|
|||||||
private set;
|
private set;
|
||||||
} = new Dictionary<int, (IIceCreamModel, int)>();
|
} = new Dictionary<int, (IIceCreamModel, int)>();
|
||||||
|
|
||||||
|
public int IceCreamsMaximum { get; private set; }
|
||||||
|
|
||||||
public static Shop? Create(ShopBindingModel? model)
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -32,7 +34,8 @@ namespace IceCreamShopListImplement.Models
|
|||||||
ShopName = model.ShopName,
|
ShopName = model.ShopName,
|
||||||
Address = model.Address,
|
Address = model.Address,
|
||||||
DateOpening = model.DateOpening,
|
DateOpening = model.DateOpening,
|
||||||
ShopIceCreams = model.ShopIceCreams
|
ShopIceCreams = model.ShopIceCreams,
|
||||||
|
IceCreamsMaximum = model.IceCreamsMaximum
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +49,7 @@ namespace IceCreamShopListImplement.Models
|
|||||||
Address = model.Address;
|
Address = model.Address;
|
||||||
DateOpening = model.DateOpening;
|
DateOpening = model.DateOpening;
|
||||||
ShopIceCreams = model.ShopIceCreams;
|
ShopIceCreams = model.ShopIceCreams;
|
||||||
|
IceCreamsMaximum -= model.IceCreamsMaximum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShopViewModel GetViewModel => new()
|
public ShopViewModel GetViewModel => new()
|
||||||
@ -54,7 +58,8 @@ namespace IceCreamShopListImplement.Models
|
|||||||
ShopName = ShopName,
|
ShopName = ShopName,
|
||||||
Address = Address,
|
Address = Address,
|
||||||
DateOpening = DateOpening,
|
DateOpening = DateOpening,
|
||||||
ShopIceCreams = ShopIceCreams
|
ShopIceCreams = ShopIceCreams,
|
||||||
|
IceCreamsMaximum = IceCreamsMaximum
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
127
IceCreamShop/IceCreamShopView/FormIceCreamSale.Designer.cs
generated
Normal file
127
IceCreamShop/IceCreamShopView/FormIceCreamSale.Designer.cs
generated
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
namespace IceCreamShopView
|
||||||
|
{
|
||||||
|
partial class FormIceCreamSale
|
||||||
|
{
|
||||||
|
/// <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();
|
||||||
|
buttonSale = new Button();
|
||||||
|
textBoxCount = new TextBox();
|
||||||
|
labelCount = new Label();
|
||||||
|
comboBoxIceCream = new ComboBox();
|
||||||
|
labelIceCream = new Label();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(253, 83);
|
||||||
|
buttonCancel.Margin = new Padding(4, 3, 4, 3);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(88, 27);
|
||||||
|
buttonCancel.TabIndex = 17;
|
||||||
|
buttonCancel.Text = "Отмена";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCancel.Click += ButtonCancel_Click;
|
||||||
|
//
|
||||||
|
// buttonSale
|
||||||
|
//
|
||||||
|
buttonSale.Location = new Point(159, 83);
|
||||||
|
buttonSale.Margin = new Padding(4, 3, 4, 3);
|
||||||
|
buttonSale.Name = "buttonSale";
|
||||||
|
buttonSale.Size = new Size(88, 27);
|
||||||
|
buttonSale.TabIndex = 16;
|
||||||
|
buttonSale.Text = "Продать";
|
||||||
|
buttonSale.UseVisualStyleBackColor = true;
|
||||||
|
buttonSale.Click += ButtonSale_Click;
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
textBoxCount.Location = new Point(101, 51);
|
||||||
|
textBoxCount.Margin = new Padding(4, 3, 4, 3);
|
||||||
|
textBoxCount.Name = "textBoxCount";
|
||||||
|
textBoxCount.Size = new Size(252, 23);
|
||||||
|
textBoxCount.TabIndex = 15;
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
labelCount.AutoSize = true;
|
||||||
|
labelCount.Location = new Point(13, 54);
|
||||||
|
labelCount.Margin = new Padding(4, 0, 4, 0);
|
||||||
|
labelCount.Name = "labelCount";
|
||||||
|
labelCount.Size = new Size(78, 15);
|
||||||
|
labelCount.TabIndex = 14;
|
||||||
|
labelCount.Text = "Количество :";
|
||||||
|
//
|
||||||
|
// comboBoxIceCream
|
||||||
|
//
|
||||||
|
comboBoxIceCream.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxIceCream.FormattingEnabled = true;
|
||||||
|
comboBoxIceCream.Location = new Point(101, 15);
|
||||||
|
comboBoxIceCream.Margin = new Padding(4, 3, 4, 3);
|
||||||
|
comboBoxIceCream.Name = "comboBoxIceCream";
|
||||||
|
comboBoxIceCream.Size = new Size(252, 23);
|
||||||
|
comboBoxIceCream.TabIndex = 13;
|
||||||
|
//
|
||||||
|
// labelIceCream
|
||||||
|
//
|
||||||
|
labelIceCream.AutoSize = true;
|
||||||
|
labelIceCream.Location = new Point(13, 19);
|
||||||
|
labelIceCream.Margin = new Padding(4, 0, 4, 0);
|
||||||
|
labelIceCream.Name = "labelIceCream";
|
||||||
|
labelIceCream.Size = new Size(80, 15);
|
||||||
|
labelIceCream.TabIndex = 12;
|
||||||
|
labelIceCream.Text = "Мороженое :";
|
||||||
|
//
|
||||||
|
// FormIceCreamSale
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(373, 123);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSale);
|
||||||
|
Controls.Add(textBoxCount);
|
||||||
|
Controls.Add(labelCount);
|
||||||
|
Controls.Add(comboBoxIceCream);
|
||||||
|
Controls.Add(labelIceCream);
|
||||||
|
Name = "FormIceCreamSale";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Продажа мороженого";
|
||||||
|
Load += FormIceCreamSale_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSale;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private Label labelCount;
|
||||||
|
private ComboBox comboBoxIceCream;
|
||||||
|
private Label labelIceCream;
|
||||||
|
}
|
||||||
|
}
|
87
IceCreamShop/IceCreamShopView/FormIceCreamSale.cs
Normal file
87
IceCreamShop/IceCreamShopView/FormIceCreamSale.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using IceCreamShopContracts.BusinessLogicsContracts;
|
||||||
|
using IceCreamShopContracts.BindingModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace IceCreamShopView
|
||||||
|
{
|
||||||
|
public partial class FormIceCreamSale : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly IIceCreamLogic _logicIceCream;
|
||||||
|
|
||||||
|
private readonly IShopLogic _logicShop;
|
||||||
|
|
||||||
|
public FormIceCreamSale(ILogger<FormMakeShipment> logger, IIceCreamLogic logicIceCream, IShopLogic logicShop)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicIceCream = logicIceCream;
|
||||||
|
_logicShop = logicShop;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormIceCreamSale_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Ice creams loading");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logicIceCream.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
comboBoxIceCream.DisplayMember = "IceCreamName";
|
||||||
|
comboBoxIceCream.ValueMember = "Id";
|
||||||
|
comboBoxIceCream.DataSource = list;
|
||||||
|
comboBoxIceCream.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ice creams loading error");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSale_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxIceCream.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Ice cream sale");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicShop.MakeSale(
|
||||||
|
new IceCreamBindingModel
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(comboBoxIceCream.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, "Ice cream sale error");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
IceCreamShop/IceCreamShopView/FormIceCreamSale.resx
Normal file
120
IceCreamShop/IceCreamShopView/FormIceCreamSale.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -78,6 +78,15 @@ namespace IceCreamShopView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void продажаМороженогоToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormIceCreamSale));
|
||||||
|
if (service is FormIceCreamSale form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||||
|
17
IceCreamShop/IceCreamShopView/FormMain.designer.cs
generated
17
IceCreamShop/IceCreamShopView/FormMain.designer.cs
generated
@ -40,13 +40,14 @@
|
|||||||
buttonCreateOrder = new Button();
|
buttonCreateOrder = new Button();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
buttonUpd = new Button();
|
buttonUpd = new Button();
|
||||||
|
продажаМороженогоToolStripMenuItem = new ToolStripMenuItem();
|
||||||
menuStrip.SuspendLayout();
|
menuStrip.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// menuStrip
|
// menuStrip
|
||||||
//
|
//
|
||||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem });
|
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продажаМороженогоToolStripMenuItem });
|
||||||
menuStrip.Location = new Point(0, 0);
|
menuStrip.Location = new Point(0, 0);
|
||||||
menuStrip.Name = "menuStrip";
|
menuStrip.Name = "menuStrip";
|
||||||
menuStrip.Padding = new Padding(7, 2, 0, 2);
|
menuStrip.Padding = new Padding(7, 2, 0, 2);
|
||||||
@ -64,21 +65,21 @@
|
|||||||
// компонентыToolStripMenuItem
|
// компонентыToolStripMenuItem
|
||||||
//
|
//
|
||||||
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||||
компонентыToolStripMenuItem.Size = new Size(180, 22);
|
компонентыToolStripMenuItem.Size = new Size(145, 22);
|
||||||
компонентыToolStripMenuItem.Text = "Компоненты";
|
компонентыToolStripMenuItem.Text = "Компоненты";
|
||||||
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// мороженоеToolStripMenuItem
|
// мороженоеToolStripMenuItem
|
||||||
//
|
//
|
||||||
мороженоеToolStripMenuItem.Name = "мороженоеToolStripMenuItem";
|
мороженоеToolStripMenuItem.Name = "мороженоеToolStripMenuItem";
|
||||||
мороженоеToolStripMenuItem.Size = new Size(180, 22);
|
мороженоеToolStripMenuItem.Size = new Size(145, 22);
|
||||||
мороженоеToolStripMenuItem.Text = "Мороженое";
|
мороженоеToolStripMenuItem.Text = "Мороженое";
|
||||||
мороженоеToolStripMenuItem.Click += МороженоеToolStripMenuItem_Click;
|
мороженоеToolStripMenuItem.Click += МороженоеToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// магазиныToolStripMenuItem
|
// магазиныToolStripMenuItem
|
||||||
//
|
//
|
||||||
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||||
магазиныToolStripMenuItem.Size = new Size(180, 22);
|
магазиныToolStripMenuItem.Size = new Size(145, 22);
|
||||||
магазиныToolStripMenuItem.Text = "Магазины";
|
магазиныToolStripMenuItem.Text = "Магазины";
|
||||||
магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click;
|
магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
@ -166,6 +167,13 @@
|
|||||||
buttonUpd.UseVisualStyleBackColor = true;
|
buttonUpd.UseVisualStyleBackColor = true;
|
||||||
buttonUpd.Click += ButtonUpd_Click;
|
buttonUpd.Click += ButtonUpd_Click;
|
||||||
//
|
//
|
||||||
|
// продажаМороженогоToolStripMenuItem
|
||||||
|
//
|
||||||
|
продажаМороженогоToolStripMenuItem.Name = "продажаМороженогоToolStripMenuItem";
|
||||||
|
продажаМороженогоToolStripMenuItem.Size = new Size(143, 20);
|
||||||
|
продажаМороженогоToolStripMenuItem.Text = "Продажа мороженого";
|
||||||
|
продажаМороженогоToolStripMenuItem.Click += продажаМороженогоToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
@ -205,6 +213,7 @@
|
|||||||
private System.Windows.Forms.Button buttonUpd;
|
private System.Windows.Forms.Button buttonUpd;
|
||||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||||
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
|
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem продажаМороженогоToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
IceCreamShop/IceCreamShopView/FormShop.Designer.cs
generated
32
IceCreamShop/IceCreamShopView/FormShop.Designer.cs
generated
@ -41,6 +41,8 @@
|
|||||||
ColumnCount = new DataGridViewTextBoxColumn();
|
ColumnCount = new DataGridViewTextBoxColumn();
|
||||||
buttonSave = new Button();
|
buttonSave = new Button();
|
||||||
buttonCancel = new Button();
|
buttonCancel = new Button();
|
||||||
|
textBoxMaximum = new TextBox();
|
||||||
|
labelMaximum = new Label();
|
||||||
groupBoxIceCreams.SuspendLayout();
|
groupBoxIceCreams.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -101,7 +103,7 @@
|
|||||||
// groupBoxIceCreams
|
// groupBoxIceCreams
|
||||||
//
|
//
|
||||||
groupBoxIceCreams.Controls.Add(dataGridView);
|
groupBoxIceCreams.Controls.Add(dataGridView);
|
||||||
groupBoxIceCreams.Location = new Point(4, 100);
|
groupBoxIceCreams.Location = new Point(5, 138);
|
||||||
groupBoxIceCreams.Margin = new Padding(4, 3, 4, 3);
|
groupBoxIceCreams.Margin = new Padding(4, 3, 4, 3);
|
||||||
groupBoxIceCreams.Name = "groupBoxIceCreams";
|
groupBoxIceCreams.Name = "groupBoxIceCreams";
|
||||||
groupBoxIceCreams.Padding = new Padding(4, 3, 4, 3);
|
groupBoxIceCreams.Padding = new Padding(4, 3, 4, 3);
|
||||||
@ -150,7 +152,7 @@
|
|||||||
//
|
//
|
||||||
// buttonSave
|
// buttonSave
|
||||||
//
|
//
|
||||||
buttonSave.Location = new Point(255, 394);
|
buttonSave.Location = new Point(256, 434);
|
||||||
buttonSave.Margin = new Padding(4, 3, 4, 3);
|
buttonSave.Margin = new Padding(4, 3, 4, 3);
|
||||||
buttonSave.Name = "buttonSave";
|
buttonSave.Name = "buttonSave";
|
||||||
buttonSave.Size = new Size(88, 27);
|
buttonSave.Size = new Size(88, 27);
|
||||||
@ -161,7 +163,7 @@
|
|||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
buttonCancel.Location = new Point(359, 394);
|
buttonCancel.Location = new Point(360, 434);
|
||||||
buttonCancel.Margin = new Padding(4, 3, 4, 3);
|
buttonCancel.Margin = new Padding(4, 3, 4, 3);
|
||||||
buttonCancel.Name = "buttonCancel";
|
buttonCancel.Name = "buttonCancel";
|
||||||
buttonCancel.Size = new Size(88, 27);
|
buttonCancel.Size = new Size(88, 27);
|
||||||
@ -170,11 +172,31 @@
|
|||||||
buttonCancel.UseVisualStyleBackColor = true;
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
buttonCancel.Click += ButtonCancel_Click;
|
buttonCancel.Click += ButtonCancel_Click;
|
||||||
//
|
//
|
||||||
|
// textBoxMaximum
|
||||||
|
//
|
||||||
|
textBoxMaximum.Location = new Point(169, 97);
|
||||||
|
textBoxMaximum.Margin = new Padding(4, 3, 4, 3);
|
||||||
|
textBoxMaximum.Name = "textBoxMaximum";
|
||||||
|
textBoxMaximum.Size = new Size(175, 23);
|
||||||
|
textBoxMaximum.TabIndex = 11;
|
||||||
|
//
|
||||||
|
// labelMaximum
|
||||||
|
//
|
||||||
|
labelMaximum.AutoSize = true;
|
||||||
|
labelMaximum.Location = new Point(14, 100);
|
||||||
|
labelMaximum.Margin = new Padding(4, 0, 4, 0);
|
||||||
|
labelMaximum.Name = "labelMaximum";
|
||||||
|
labelMaximum.Size = new Size(147, 15);
|
||||||
|
labelMaximum.TabIndex = 10;
|
||||||
|
labelMaximum.Text = "Максимум мороженого :";
|
||||||
|
//
|
||||||
// FormShop
|
// FormShop
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(478, 432);
|
ClientSize = new Size(478, 468);
|
||||||
|
Controls.Add(textBoxMaximum);
|
||||||
|
Controls.Add(labelMaximum);
|
||||||
Controls.Add(buttonCancel);
|
Controls.Add(buttonCancel);
|
||||||
Controls.Add(buttonSave);
|
Controls.Add(buttonSave);
|
||||||
Controls.Add(groupBoxIceCreams);
|
Controls.Add(groupBoxIceCreams);
|
||||||
@ -209,5 +231,7 @@
|
|||||||
private DataGridViewTextBoxColumn ColumnCount;
|
private DataGridViewTextBoxColumn ColumnCount;
|
||||||
private Button buttonSave;
|
private Button buttonSave;
|
||||||
private Button buttonCancel;
|
private Button buttonCancel;
|
||||||
|
private TextBox textBoxMaximum;
|
||||||
|
private Label labelMaximum;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -39,6 +39,7 @@ namespace IceCreamShopView
|
|||||||
textBoxName.Text = view.ShopName;
|
textBoxName.Text = view.ShopName;
|
||||||
textBoxAddress.Text = view.Address;
|
textBoxAddress.Text = view.Address;
|
||||||
dateTimePicker.Value = view.DateOpening;
|
dateTimePicker.Value = view.DateOpening;
|
||||||
|
textBoxMaximum.Text = view.IceCreamsMaximum.ToString();
|
||||||
_shopIceCreams = view.ShopIceCreams ?? new Dictionary<int, (IIceCreamModel, int)>();
|
_shopIceCreams = view.ShopIceCreams ?? new Dictionary<int, (IIceCreamModel, int)>();
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
@ -89,6 +90,11 @@ namespace IceCreamShopView
|
|||||||
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxMaximum.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните максимальное количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
_logger.LogInformation("Shop saving");
|
_logger.LogInformation("Shop saving");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -98,6 +104,7 @@ namespace IceCreamShopView
|
|||||||
ShopName = textBoxName.Text,
|
ShopName = textBoxName.Text,
|
||||||
Address = textBoxAddress.Text,
|
Address = textBoxAddress.Text,
|
||||||
DateOpening = dateTimePicker.Value,
|
DateOpening = dateTimePicker.Value,
|
||||||
|
IceCreamsMaximum = Convert.ToInt32(textBoxMaximum.Text),
|
||||||
ShopIceCreams = _shopIceCreams
|
ShopIceCreams = _shopIceCreams
|
||||||
};
|
};
|
||||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
|
@ -55,6 +55,7 @@ namespace IceCreamShopView
|
|||||||
services.AddTransient<FormShop>();
|
services.AddTransient<FormShop>();
|
||||||
services.AddTransient<FormShops>();
|
services.AddTransient<FormShops>();
|
||||||
services.AddTransient<FormMakeShipment>();
|
services.AddTransient<FormMakeShipment>();
|
||||||
|
services.AddTransient<FormIceCreamSale>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user