PIbd-21. Kryukov A.I. Lab work 02 hard #10
@ -10,6 +10,7 @@ using TypographyContracts.StoragesContracts;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TypographyDataModels.Models;
|
||||
|
||||
namespace TypographyBusinessLogic.BusinessLogics
|
||||
{
|
||||
@ -17,11 +18,17 @@ namespace TypographyBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly IPrintedStorage _printedStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IPrintedStorage printedStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopStorage = shopStorage;
|
||||
_shopLogic = shopLogic;
|
||||
_printedStorage = printedStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
@ -44,39 +51,28 @@ namespace TypographyBusinessLogic.BusinessLogics
|
||||
model.Status = OrderStatus.Принят;
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
model.Status = OrderStatus.Неизвестен;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
||||
private void CheckModel(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (element == null)
|
||||
if (model == null)
|
||||
{
|
||||
_logger.LogWarning("Read operation failed");
|
||||
return false;
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (element.Status != status - 1)
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
_logger.LogWarning("Status change operation failed");
|
||||
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
|
||||
throw new ArgumentNullException("Количество заказов должно быть больше нуля");
|
||||
}
|
||||
OrderStatus oldStatus = model.Status;
|
||||
model.Status = status;
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
model.DateImplement = DateTime.Now;
|
||||
if (_orderStorage.Update(model) == null)
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
model.Status = oldStatus;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
throw new ArgumentNullException("Цена заказа должна быть больше нуля");
|
||||
}
|
||||
return true;
|
||||
_logger.LogInformation("Order. OrderId:{Id}. Sum:{Sum}", model.Id, model.Sum);
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
@ -92,33 +88,97 @@ namespace TypographyBusinessLogic.BusinessLogics
|
||||
return ChangeStatus(model, OrderStatus.Выдан);
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
public bool CheckSupply(IPrintedModel printed, int count)
|
||||
{
|
||||
if (model == null)
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
_logger.LogWarning("Check supply operation error. Printed count < 0");
|
||||
return false;
|
||||
}
|
||||
if (!withParams)
|
||||
int Capacity = _shopStorage.GetFullList().Select(x => x.MaxCountPrinteds).Sum();
|
||||
int currentCount = _shopStorage.GetFullList().Select(x => x.ShopPrinteds.Select(y => y.Value.Item2).Sum()).Sum();
|
||||
int freeSpace = Capacity - currentCount;
|
||||
|
||||
if (freeSpace < count)
|
||||
{
|
||||
return;
|
||||
_logger.LogWarning("Check supply error. No place for new Printeds");
|
||||
return false;
|
||||
}
|
||||
if (model.PrintedId < 0)
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор закусок", nameof(model.PrintedId));
|
||||
freeSpace = shop.MaxCountPrinteds;
|
||||
foreach (var doc in shop.ShopPrinteds)
|
||||
{
|
||||
freeSpace -= doc.Value.Item2;
|
||||
}
|
||||
if (freeSpace == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (freeSpace >= count)
|
||||
{
|
||||
if (_shopLogic.MakeShipment(new()
|
||||
{
|
||||
Id = shop.Id
|
||||
}, printed, count))
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_shopLogic.MakeShipment(new() { Id = shop.Id }, printed, freeSpace))
|
||||
count -= freeSpace;
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
||||
{
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (element == null)
|
||||
{
|
||||
throw new ArgumentNullException("Количество закусок в заказе должно быть больше 0", nameof(model.Count));
|
||||
_logger.LogWarning("Find order failed");
|
||||
return false;
|
||||
}
|
||||
if (model.Sum <= 0)
|
||||
if (element.Status != status - 1)
|
||||
{
|
||||
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
||||
_logger.LogWarning("Status change failed");
|
||||
throw new InvalidOperationException("Невозможно перевести состояние заказа");
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
if (status == OrderStatus.Готов)
|
||||
{
|
||||
throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count));
|
||||
var printed = _printedStorage.GetElement(new PrintedSearchModel() { Id = model.PrintedId });
|
||||
if (printed == null)
|
||||
{
|
||||
_logger.LogWarning("Status change error. Printed not found");
|
||||
return false;
|
||||
}
|
||||
if (!CheckSupply(printed, model.Count))
|
||||
{
|
||||
_logger.LogWarning("Status change error. Shop doesnt have printedes");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id);
|
||||
model.Status = status;
|
||||
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
||||
_orderStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ namespace TypographyBusinessLogic
|
||||
public class ShopLogic : IShopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
|
||||
@ -25,117 +24,142 @@ namespace TypographyBusinessLogic
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ShopName: {ShopName}. Id: {Id}", model?.ShopName, model?.Id);
|
||||
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ShopName: {ShopName}. Id: {Id}", model.ShopName, model.Id);
|
||||
|
||||
_logger.LogInformation("ReadElement. Shop Name:{0}, ID:{1}", model.ShopName, model.Id);
|
||||
|
||||
var element = _shopStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
_logger.LogWarning("ReadElement. element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Shop Name:{0}, ID:{1} ", model?.ShopName, model?.Id);
|
||||
|
||||
var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool MakeShipment(ShopSearchModel model, IPrintedModel printed, int count)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (printed == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(printed));
|
||||
}
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Count of printeds in supply must be more than 0", nameof(count));
|
||||
}
|
||||
|
||||
var shopElement = _shopStorage.GetElement(model);
|
||||
if (shopElement == null)
|
||||
{
|
||||
_logger.LogWarning("Required shop element not found in storage");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.ShopName);
|
||||
|
||||
int countPrinteds = 0;
|
||||
foreach (var c in shopElement.ShopPrinteds)
|
||||
countPrinteds += c.Value.Item2;
|
||||
|
||||
if (count > shopElement.MaxCountPrinteds - countPrinteds)
|
||||
{
|
||||
_logger.LogWarning("Required shop will be overflowed");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (shopElement.ShopPrinteds.TryGetValue(printed.Id, out var samePrinted))
|
||||
{
|
||||
shopElement.ShopPrinteds[printed.Id] = (printed, samePrinted.Item2 + count);
|
||||
_logger.LogInformation("Same printed found by supply. Added {0} of {1} in {2} shop", count, printed.PrintedName, shopElement.ShopName);
|
||||
}
|
||||
else
|
||||
{
|
||||
shopElement.ShopPrinteds[printed.Id] = (printed, count);
|
||||
_logger.LogInformation("New printed added by supply. Added {0} of {1} in {2} shop", count, printed.PrintedName, shopElement.ShopName);
|
||||
}
|
||||
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
Id = shopElement.Id,
|
||||
ShopName = shopElement.ShopName,
|
||||
Address = shopElement.Address,
|
||||
MaxCountPrinteds = shopElement.MaxCountPrinteds,
|
||||
DateOpening = shopElement.DateOpening,
|
||||
ShopPrinteds = shopElement.ShopPrinteds
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_shopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_shopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
||||
|
||||
if (_shopStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool MakeShipment(ShopSearchModel shopModel, IPrintedModel iceCream, int count)
|
||||
{
|
||||
if (shopModel == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(shopModel));
|
||||
}
|
||||
if (iceCream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(iceCream));
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество товаров(мороженого) в магазине должно быть больше нуля", nameof(count));
|
||||
}
|
||||
_logger.LogInformation("MakeShipment(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id);
|
||||
var shop = _shopStorage.GetElement(shopModel);
|
||||
if (shop == null)
|
||||
{
|
||||
_logger.LogWarning("MakeShipment(GetElement). Element not found");
|
||||
return false;
|
||||
}
|
||||
if (shop.ShopPrinteds.ContainsKey(iceCream.Id))
|
||||
{
|
||||
var shopIC = shop.ShopPrinteds[iceCream.Id];
|
||||
shopIC.Item2 += count;
|
||||
shop.ShopPrinteds[iceCream.Id] = shopIC;
|
||||
_logger.LogInformation("MakeShipment. Added {count} '{iceCream}' to '{ShopName}' shop", count, iceCream.PrintedName,
|
||||
shop.ShopName);
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.ShopPrinteds.Add(iceCream.Id, (iceCream, count));
|
||||
_logger.LogInformation("MakeShipment. Added {count} new '{iceCream}' to '{ShopName}' shop", count, iceCream.PrintedName,
|
||||
shop.ShopName);
|
||||
}
|
||||
if (_shopStorage.Update(new ShopBindingModel()
|
||||
{
|
||||
Id = shop.Id,
|
||||
ShopName = shop.ShopName,
|
||||
Address = shop.Address,
|
||||
DateOpening = shop.DateOpening,
|
||||
ShopPrinteds = shop.ShopPrinteds,
|
||||
}) == null)
|
||||
{
|
||||
_logger.LogWarning("MakeShipment. Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -145,27 +169,38 @@ namespace TypographyBusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
|
||||
throw new ArgumentNullException("Нет названия магазина!", nameof(model.ShopName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Address))
|
||||
|
||||
if (model.MaxCountPrinteds < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Нет адреса магазина", nameof(model.Address));
|
||||
throw new InvalidOperationException("Отрицательное максимальное количество изделий!");
|
||||
}
|
||||
_logger.LogInformation("Shop. ShopName: {ShopName}. Address: {Address}. Id: {Id}", model.ShopName, model.Address, model.Id);
|
||||
|
||||
_logger.LogInformation("Shop. Name: {0}, Address: {1}, ID: {2}", model.ShopName, model.Address, model.Id);
|
||||
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
ShopName = model.ShopName
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
public bool SellPrinted(IPrintedModel printed, int count)
|
||||
{
|
||||
return _shopStorage.SellPrinted(printed, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ namespace TypographyContracts.BindingModels
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||
public int MaxCountPrinteds { get; set; }
|
||||
|
||||
public Dictionary<int, (IPrintedModel, int)> ShopPrinteds { get; set; } = new();
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ namespace TypographyContracts.BusinessLogicsContracts
|
||||
|
||||
bool Delete(ShopBindingModel model);
|
||||
|
||||
bool MakeShipment(ShopSearchModel shopModel, IPrintedModel iceCream, int count);
|
||||
bool MakeShipment(ShopSearchModel shopModel, IPrintedModel printed, int count);
|
||||
bool SellPrinted(IPrintedModel printed, int count);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.SearchModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDataModels.Models;
|
||||
|
||||
namespace TypographyContracts.StoragesContracts
|
||||
{
|
||||
@ -22,5 +23,6 @@ namespace TypographyContracts.StoragesContracts
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SellPrinted(IPrintedModel model, int count);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ namespace TypographyContracts.ViewModels
|
||||
|
||||
[DisplayName("Адрес")]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
[DisplayName("Максимальное количество изделий в магазине")]
|
||||
public int MaxCountPrinteds { get; set; }
|
||||
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||
|
@ -3,8 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TypographyDataModels.Enums;
|
||||
|
||||
namespace TypographyDataModels.Enums
|
||||
namespace TypographyDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
@ -13,6 +14,6 @@ namespace TypographyDataModels.Enums
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ namespace TypographyDataModels.Models
|
||||
string Address { get; }
|
||||
|
||||
DateTime DateOpening { get; }
|
||||
int MaxCountPrinteds { get; }
|
||||
|
||||
Dictionary<int, (IPrintedModel, int)> ShopPrinteds { get; }
|
||||
}
|
67
TypographyFileImplement/DataFileSingleton.cs
Normal file
67
TypographyFileImplement/DataFileSingleton.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using TypographyFileImplement.Models;
|
||||
|
||||
|
||||
namespace TypographyFileImplement
|
||||
{
|
||||
public class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? instance;
|
||||
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
|
||||
private readonly string PrintedFileName = "Printed.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Printed> Printeds { get; private set; }
|
||||
public List<Shop> Shops { get; private set; }
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new DataFileSingleton();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SavePrinteds() => SaveData(Printeds, PrintedFileName, "Printeds", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Printeds = LoadData(PrintedFileName, "Printed", x => Printed.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
}
|
||||
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
return
|
||||
XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||
}
|
||||
return new List<T>();
|
||||
}
|
||||
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
73
TypographyFileImplement/Implements/ComponentStorage.cs
Normal file
73
TypographyFileImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.SearchModels;
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyFileImplement.Models;
|
||||
|
||||
|
||||
namespace TypographyFileImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public ComponentStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
return source.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Components.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Components.Add(newComponent);
|
||||
source.SaveComponents();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
source.SaveComponents();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
var element = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Components.Remove(element);
|
||||
source.SaveComponents();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
83
TypographyFileImplement/Implements/OrderStorage.cs
Normal file
83
TypographyFileImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.SearchModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyFileImplement.Models;
|
||||
|
||||
namespace TypographyFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id));
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(newOrder);
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(order);
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Orders.Remove(element);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(element);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
var printed = source.Printeds.FirstOrDefault(x => x.Id == order.PrintedId);
|
||||
if (printed != null)
|
||||
{
|
||||
viewModel.PrintedName = printed.PrintedName;
|
||||
}
|
||||
return viewModel;
|
||||
}
|
||||
}
|
||||
}
|
82
TypographyFileImplement/Implements/PrintedStorage.cs
Normal file
82
TypographyFileImplement/Implements/PrintedStorage.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.SearchModels;
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyFileImplement.Models;
|
||||
|
||||
|
||||
namespace TypographyFileImplement.Implements
|
||||
{
|
||||
public class PrintedStorage : IPrintedStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public PrintedStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<PrintedViewModel> GetFullList()
|
||||
{
|
||||
return source.Printeds.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<PrintedViewModel> GetFilteredList(PrintedSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PrintedName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Printeds.Where(x => x.PrintedName.Contains(model.PrintedName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public PrintedViewModel? GetElement(PrintedSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PrintedName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Printeds.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PrintedName) &&
|
||||
x.PrintedName == model.PrintedName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public PrintedViewModel? Insert(PrintedBindingModel model)
|
||||
{
|
||||
model.Id = source.Printeds.Count > 0 ? source.Printeds.Max(x => x.Id) + 1 : 1;
|
||||
var newPrinted = Printed.Create(model);
|
||||
if (newPrinted == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Printeds.Add(newPrinted);
|
||||
source.SavePrinteds();
|
||||
return newPrinted.GetViewModel;
|
||||
}
|
||||
public PrintedViewModel? Update(PrintedBindingModel model)
|
||||
{
|
||||
var printed = source.Printeds.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (printed == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
printed.Update(model);
|
||||
source.SavePrinteds();
|
||||
return printed.GetViewModel;
|
||||
}
|
||||
public PrintedViewModel? Delete(PrintedBindingModel model)
|
||||
{
|
||||
var element = source.Printeds.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Printeds.Remove(element);
|
||||
source.SavePrinteds();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
137
TypographyFileImplement/Implements/ShopStorage.cs
Normal file
137
TypographyFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.SearchModels;
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDataModels.Models;
|
||||
using TypographyFileImplement.Models;
|
||||
|
||||
namespace TypographyFileImplement.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.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Shops
|
||||
.Select(x => x.GetViewModel)
|
||||
.Where(x => x.ShopName.Contains(model.ShopName ?? 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 SellPrinted(IPrintedModel model, int count)
|
||||
{
|
||||
var printed = source.Printeds.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (printed == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var shopPrinteds = source.Shops.SelectMany(shop => shop.ShopPrinteds.Where(c => c.Value.Item1.Id == printed.Id));
|
||||
|
||||
|
||||
int countStore = source.Shops
|
||||
.SelectMany(x => x.ShopPrinteds)
|
||||
.Where(y => y.Key == model.Id)
|
||||
.Sum(y => y.Value.Item2);
|
||||
|
||||
if (count > countStore)
|
||||
return false;
|
||||
|
||||
foreach (var shop in source.Shops)
|
||||
{
|
||||
var printeds = shop.ShopPrinteds;
|
||||
|
||||
foreach (var c in printeds.Where(x => x.Value.Item1.Id == printed.Id))
|
||||
{
|
||||
int min = Math.Min(c.Value.Item2, count);
|
||||
printeds[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min);
|
||||
count -= min;
|
||||
|
||||
if (count <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
shop.Update(new ShopBindingModel
|
||||
{
|
||||
Id = shop.Id,
|
||||
ShopName = shop.ShopName,
|
||||
Address = shop.Address,
|
||||
MaxCountPrinteds = shop.MaxCountPrinteds,
|
||||
DateOpening = shop.DateOpening,
|
||||
ShopPrinteds = printeds
|
||||
});
|
||||
|
||||
source.SaveShops();
|
||||
|
||||
if (count <= 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
64
TypographyFileImplement/Models/Component.cs
Normal file
64
TypographyFileImplement/Models/Component.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace TypographyFileImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
public static Component? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ComponentName = element.Element("ComponentName")!.Value,
|
||||
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
||||
};
|
||||
}
|
||||
public void Update(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
public XElement GetXElement => new("Component",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ComponentName", ComponentName),
|
||||
new XElement("Cost", Cost.ToString()));
|
||||
}
|
||||
}
|
88
TypographyFileImplement/Models/Order.cs
Normal file
88
TypographyFileImplement/Models/Order.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDataModels.Enums;
|
||||
using TypographyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace TypographyFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int PrintedId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
PrintedId = model.PrintedId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
}
|
||||
public static Order? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
PrintedId = Convert.ToInt32(element.Element("PrintedId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null :
|
||||
Convert.ToDateTime(element.Element("DateImplement")!.Value)
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PrintedId = PrintedId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
public XElement GetXElement =>
|
||||
new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("PrintedId", PrintedId.ToString()),
|
||||
new XElement("Count", PrintedId.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
new XElement("DateCreate", DateCreate.ToString()),
|
||||
new XElement("DateImplement", DateImplement.ToString())
|
||||
);
|
||||
}
|
||||
}
|
81
TypographyFileImplement/Models/Printed.cs
Normal file
81
TypographyFileImplement/Models/Printed.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using TypographyDataModels.Models;
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace TypographyFileImplement.Models
|
||||
{
|
||||
public class Printed : IPrintedModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string PrintedName { get; private set; } = string.Empty;
|
||||
public double Price { get; private set; }
|
||||
public Dictionary<int, int> Components { get; private set; } = new();
|
||||
private Dictionary<int, (IComponentModel, int)>? _srintedComponents = null;
|
||||
public Dictionary<int, (IComponentModel, int)> PrintedComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_srintedComponents == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_srintedComponents = Components.ToDictionary(x => x.Key, y =>
|
||||
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
|
||||
}
|
||||
return _srintedComponents;
|
||||
}
|
||||
}
|
||||
public static Printed? Create(PrintedBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Printed()
|
||||
{
|
||||
Id = model.Id,
|
||||
PrintedName = model.PrintedName,
|
||||
Price = model.Price,
|
||||
Components = model.PrintedComponents.ToDictionary(x => x.Key, x
|
||||
=> x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Printed? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Printed()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
PrintedName = element.Element("PrintedName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Components = element.Element("PrintedComponents")!.Elements("PrintedComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
public void Update(PrintedBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PrintedName = model.PrintedName;
|
||||
Price = model.Price;
|
||||
Components = model.PrintedComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_srintedComponents = null;
|
||||
}
|
||||
public PrintedViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PrintedName = PrintedName,
|
||||
Price = Price,
|
||||
PrintedComponents = PrintedComponents
|
||||
};
|
||||
public XElement GetXElement => new("Printed",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("PrintedName", PrintedName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("PrintedComponents", Components.Select(x => new XElement("PrintedComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()));
|
||||
}
|
||||
}
|
116
TypographyFileImplement/Models/Shop.cs
Normal file
116
TypographyFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDataModels.Models;
|
||||
|
||||
namespace TypographyFileImplement.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 int MaxCountPrinteds { get; private set; }
|
||||
public DateTime DateOpening { get; private set; }
|
||||
public Dictionary<int, int> Printeds { get; private set; } = new();
|
||||
private Dictionary<int, (IPrintedModel, int)>? _shopPrinteds = null;
|
||||
|
||||
public Dictionary<int, (IPrintedModel, int)> ShopPrinteds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopPrinteds == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_shopPrinteds = Printeds.ToDictionary(
|
||||
x => x.Key,
|
||||
y => ((source.Printeds.FirstOrDefault(z => z.Id == y.Key) as IPrintedModel)!, y.Value)
|
||||
);
|
||||
}
|
||||
return _shopPrinteds;
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
MaxCountPrinteds = model.MaxCountPrinteds,
|
||||
DateOpening = model.DateOpening,
|
||||
Printeds = model.ShopPrinteds.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Shop? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ShopName = element.Element("ShopName")!.Value,
|
||||
Address = element.Element("Address")!.Value,
|
||||
MaxCountPrinteds = Convert.ToInt32(element.Element("MaxCountPrinteds")!.Value),
|
||||
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
|
||||
Printeds = element.Element("ShopPrinteds")!.Elements("ShopPrinted").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;
|
||||
MaxCountPrinteds = model.MaxCountPrinteds;
|
||||
DateOpening = model.DateOpening;
|
||||
if (model.ShopPrinteds.Count > 0)
|
||||
{
|
||||
Printeds = model.ShopPrinteds.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_shopPrinteds = null;
|
||||
}
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
MaxCountPrinteds = MaxCountPrinteds,
|
||||
DateOpening = DateOpening,
|
||||
ShopPrinteds = ShopPrinteds,
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ShopName", ShopName),
|
||||
new XElement("Address", Address),
|
||||
new XElement("MaxCountPrinteds", MaxCountPrinteds),
|
||||
new XElement("DateOpening", DateOpening.ToString()),
|
||||
new XElement("ShopPrinteds", Printeds.Select(x =>
|
||||
new XElement("ShopPrinted",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
14
TypographyFileImplement/TypographyFileImplement.csproj
Normal file
14
TypographyFileImplement/TypographyFileImplement.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TypographyContracts\TypographyContracts.csproj" />
|
||||
<ProjectReference Include="..\TypographyDataModels\TypographyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -7,6 +7,7 @@ using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.SearchModels;
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDataModels.Models;
|
||||
using TypographyListImplement.Models;
|
||||
|
||||
namespace TypographyListImplement.Implements
|
||||
@ -110,5 +111,9 @@ namespace TypographyListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public bool SellPrinted(IPrintedModel printed, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TypographyContracts.BindingModels;
|
||||
@ -16,6 +17,7 @@ namespace TypographyListImplement.Models
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
public int MaxCountPrinteds { get; private set; }
|
||||
|
||||
public DateTime DateOpening { get; private set; }
|
||||
|
||||
@ -37,6 +39,7 @@ namespace TypographyListImplement.Models
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
DateOpening = model.DateOpening,
|
||||
MaxCountPrinteds = model.MaxCountPrinteds,
|
||||
ShopPrinteds = model.ShopPrinteds
|
||||
};
|
||||
}
|
||||
@ -50,6 +53,7 @@ namespace TypographyListImplement.Models
|
||||
ShopName = model.ShopName;
|
||||
Address = model.Address;
|
||||
DateOpening = model.DateOpening;
|
||||
MaxCountPrinteds = model.MaxCountPrinteds;
|
||||
ShopPrinteds = model.ShopPrinteds;
|
||||
}
|
||||
|
||||
@ -59,6 +63,7 @@ namespace TypographyListImplement.Models
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
DateOpening = DateOpening,
|
||||
MaxCountPrinteds = MaxCountPrinteds,
|
||||
ShopPrinteds = ShopPrinteds
|
||||
};
|
||||
}
|
||||
|
17
TypographyView/FormMain.Designer.cs
generated
17
TypographyView/FormMain.Designer.cs
generated
@ -34,6 +34,7 @@
|
||||
изделиеToolStripMenuItem = new ToolStripMenuItem();
|
||||
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
|
||||
продажаИзделийToolStripMenuItem = new ToolStripMenuItem();
|
||||
dataGridView = new DataGridView();
|
||||
buttonCreateOrder = new Button();
|
||||
buttonTakeOrderInWork = new Button();
|
||||
@ -47,7 +48,7 @@
|
||||
// menuStrip
|
||||
//
|
||||
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem });
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продажаИзделийToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(1146, 28);
|
||||
@ -64,21 +65,21 @@
|
||||
// компонентыToolStripMenuItem
|
||||
//
|
||||
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||
компонентыToolStripMenuItem.Size = new Size(224, 26);
|
||||
компонентыToolStripMenuItem.Size = new Size(182, 26);
|
||||
компонентыToolStripMenuItem.Text = "Компоненты";
|
||||
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
||||
//
|
||||
// изделиеToolStripMenuItem
|
||||
//
|
||||
изделиеToolStripMenuItem.Name = "изделиеToolStripMenuItem";
|
||||
изделиеToolStripMenuItem.Size = new Size(224, 26);
|
||||
изделиеToolStripMenuItem.Size = new Size(182, 26);
|
||||
изделиеToolStripMenuItem.Text = "Изделие";
|
||||
изделиеToolStripMenuItem.Click += ЗакускаToolStripMenuItem_Click;
|
||||
//
|
||||
// магазиныToolStripMenuItem
|
||||
//
|
||||
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||
магазиныToolStripMenuItem.Size = new Size(224, 26);
|
||||
магазиныToolStripMenuItem.Size = new Size(182, 26);
|
||||
магазиныToolStripMenuItem.Text = "Магазины";
|
||||
магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click;
|
||||
//
|
||||
@ -89,6 +90,13 @@
|
||||
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
|
||||
пополнениеМагазинаToolStripMenuItem.Click += ПополнениеМагазиныToolStripMenuItem_Click;
|
||||
//
|
||||
// продажаИзделийToolStripMenuItem
|
||||
//
|
||||
продажаИзделийToolStripMenuItem.Name = "продажаИзделийToolStripMenuItem";
|
||||
продажаИзделийToolStripMenuItem.Size = new Size(149, 24);
|
||||
продажаИзделийToolStripMenuItem.Text = "Продажа изделий";
|
||||
продажаИзделийToolStripMenuItem.Click += sellPrintedsToolStripMenuItem_Click;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
||||
@ -188,5 +196,6 @@
|
||||
private ToolStripMenuItem изделиеToolStripMenuItem;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
|
||||
private ToolStripMenuItem продажаИзделийToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TypographyDataModels.Enums;
|
||||
using AutomobilePlantView;
|
||||
|
||||
namespace TypographyView
|
||||
{
|
||||
@ -51,6 +52,14 @@ namespace TypographyView
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void sellPrintedsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
|
||||
if (service is FormShopSell form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
71
TypographyView/FormShop.Designer.cs
generated
71
TypographyView/FormShop.Designer.cs
generated
@ -36,11 +36,13 @@
|
||||
dateTimePicker = new DateTimePicker();
|
||||
groupBoxPrinted = new GroupBox();
|
||||
dataGridView = new DataGridView();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
Columnid = new DataGridViewTextBoxColumn();
|
||||
ColumnPrinted = new DataGridViewTextBoxColumn();
|
||||
ColumnCount = new DataGridViewTextBoxColumn();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
labelMaxCountPrinteds = new Label();
|
||||
textBoxMaxCount = new TextBox();
|
||||
groupBoxPrinted.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
@ -96,7 +98,7 @@
|
||||
// groupBoxPrinted
|
||||
//
|
||||
groupBoxPrinted.Controls.Add(dataGridView);
|
||||
groupBoxPrinted.Location = new Point(12, 129);
|
||||
groupBoxPrinted.Location = new Point(8, 201);
|
||||
groupBoxPrinted.Name = "groupBoxPrinted";
|
||||
groupBoxPrinted.Size = new Size(598, 292);
|
||||
groupBoxPrinted.TabIndex = 7;
|
||||
@ -108,33 +110,13 @@
|
||||
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Columnid, ColumnPrinted, ColumnCount });
|
||||
dataGridView.Location = new Point(0, 26);
|
||||
dataGridView.Location = new Point(6, 22);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(592, 260);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(330, 431);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(95, 34);
|
||||
buttonSave.TabIndex = 8;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(449, 431);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(95, 34);
|
||||
buttonCancel.TabIndex = 9;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// Columnid
|
||||
//
|
||||
Columnid.HeaderText = "Id";
|
||||
@ -157,11 +139,48 @@
|
||||
ColumnCount.Name = "ColumnCount";
|
||||
ColumnCount.Width = 125;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(343, 489);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(95, 34);
|
||||
buttonSave.TabIndex = 8;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(459, 489);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(95, 34);
|
||||
buttonCancel.TabIndex = 9;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// labelMaxCountPrinteds
|
||||
//
|
||||
labelMaxCountPrinteds.Location = new Point(8, 136);
|
||||
labelMaxCountPrinteds.Name = "labelMaxCountPrinteds";
|
||||
labelMaxCountPrinteds.Size = new Size(160, 40);
|
||||
labelMaxCountPrinteds.TabIndex = 10;
|
||||
labelMaxCountPrinteds.Text = "Максимальное количество изделий :";
|
||||
//
|
||||
// textBoxMaxCount
|
||||
//
|
||||
textBoxMaxCount.Location = new Point(174, 149);
|
||||
textBoxMaxCount.Name = "textBoxMaxCount";
|
||||
textBoxMaxCount.Size = new Size(250, 27);
|
||||
textBoxMaxCount.TabIndex = 11;
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(618, 477);
|
||||
ClientSize = new Size(618, 535);
|
||||
Controls.Add(textBoxMaxCount);
|
||||
Controls.Add(labelMaxCountPrinteds);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(groupBoxPrinted);
|
||||
@ -195,5 +214,7 @@
|
||||
private DataGridViewTextBoxColumn Columnid;
|
||||
private DataGridViewTextBoxColumn ColumnPrinted;
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
private Label labelMaxCountPrinteds;
|
||||
private TextBox textBoxMaxCount;
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ namespace TypographyView
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Shop loading");
|
||||
_logger.LogInformation("Загрузка магазина");
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
|
||||
@ -41,13 +41,14 @@ namespace TypographyView
|
||||
textBoxName.Text = view.ShopName;
|
||||
textBoxAddress.Text = view.Address;
|
||||
dateTimePicker.Value = view.DateOpening;
|
||||
textBoxMaxCount.Text= view.MaxCountPrinteds.ToString();
|
||||
_shopPrinteds = view.ShopPrinteds ?? new Dictionary<int, (IPrintedModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Shop loading error");
|
||||
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
@ -55,7 +56,7 @@ namespace TypographyView
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Shop printeds loading");
|
||||
_logger.LogInformation("Загрузка магазина");
|
||||
try
|
||||
{
|
||||
if (_shopPrinteds != null)
|
||||
@ -86,12 +87,17 @@ namespace TypographyView
|
||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxMaxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(dateTimePicker.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Shop saving");
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
try
|
||||
{
|
||||
var model = new ShopBindingModel
|
||||
@ -99,6 +105,7 @@ namespace TypographyView
|
||||
Id = _id ?? 0,
|
||||
ShopName = textBoxName.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
MaxCountPrinteds = Convert.ToInt32(textBoxMaxCount.Text),
|
||||
DateOpening = dateTimePicker.Value,
|
||||
ShopPrinteds = _shopPrinteds
|
||||
};
|
||||
@ -123,5 +130,7 @@ namespace TypographyView
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
124
TypographyView/FormShopSell.Designer.cs
generated
Normal file
124
TypographyView/FormShopSell.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
||||
namespace AutomobilePlantView
|
||||
{
|
||||
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()
|
||||
{
|
||||
labelPrinted = new Label();
|
||||
labelCount = new Label();
|
||||
comboBoxPrinted = new ComboBox();
|
||||
textBoxCount = new TextBox();
|
||||
buttonCancel = new Button();
|
||||
buttonSell = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelPrinted
|
||||
//
|
||||
labelPrinted.AutoSize = true;
|
||||
labelPrinted.Location = new Point(14, 12);
|
||||
labelPrinted.Name = "labelPrinted";
|
||||
labelPrinted.Size = new Size(71, 20);
|
||||
labelPrinted.TabIndex = 0;
|
||||
labelPrinted.Text = "Изделие:";
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(14, 51);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(93, 20);
|
||||
labelCount.TabIndex = 1;
|
||||
labelCount.Text = "Количество:";
|
||||
//
|
||||
// comboBoxPrinted
|
||||
//
|
||||
comboBoxPrinted.FormattingEnabled = true;
|
||||
comboBoxPrinted.Location = new Point(70, 8);
|
||||
comboBoxPrinted.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxPrinted.Name = "comboBoxPrinted";
|
||||
comboBoxPrinted.Size = new Size(370, 28);
|
||||
comboBoxPrinted.TabIndex = 2;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
textBoxCount.Location = new Point(70, 47);
|
||||
textBoxCount.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(370, 27);
|
||||
textBoxCount.TabIndex = 3;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(262, 85);
|
||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(86, 31);
|
||||
buttonCancel.TabIndex = 4;
|
||||
buttonCancel.Text = "Cancel";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// buttonSell
|
||||
//
|
||||
buttonSell.Location = new Point(354, 85);
|
||||
buttonSell.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonSell.Name = "buttonSell";
|
||||
buttonSell.Size = new Size(86, 31);
|
||||
buttonSell.TabIndex = 5;
|
||||
buttonSell.Text = "Sell";
|
||||
buttonSell.UseVisualStyleBackColor = true;
|
||||
buttonSell.Click += buttonSell_Click;
|
||||
//
|
||||
// FormShopSell
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(454, 124);
|
||||
Controls.Add(buttonSell);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(comboBoxPrinted);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(labelPrinted);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormShopSell";
|
||||
Text = "Sell";
|
||||
Load += FormShopSell_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelPrinted;
|
||||
private Label labelCount;
|
||||
private ComboBox comboBoxPrinted;
|
||||
private TextBox textBoxCount;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSell;
|
||||
}
|
||||
}
|
95
TypographyView/FormShopSell.cs
Normal file
95
TypographyView/FormShopSell.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AutomobilePlantView
|
||||
{
|
||||
public partial class FormShopSell : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPrintedLogic _logicPrinted;
|
||||
private readonly IShopLogic _logicShop;
|
||||
|
||||
public FormShopSell(ILogger<FormShopSell> logger, IPrintedLogic logicPrinted, IShopLogic logicShop)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicPrinted = logicPrinted;
|
||||
_logicShop = logicShop;
|
||||
}
|
||||
|
||||
private void FormShopSell_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Загрузка авто для продажи");
|
||||
try
|
||||
{
|
||||
var list = _logicPrinted.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxPrinted.DisplayMember = "PrintedName";
|
||||
comboBoxPrinted.ValueMember = "Id";
|
||||
comboBoxPrinted.DataSource = list;
|
||||
comboBoxPrinted.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 (comboBoxPrinted.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите авто", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Создание продажи");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicShop.SellPrinted(
|
||||
new PrintedBindingModel
|
||||
{
|
||||
Id = Convert.ToInt32(comboBoxPrinted.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();
|
||||
}
|
||||
}
|
||||
}
|
120
TypographyView/FormShopSell.resx
Normal file
120
TypographyView/FormShopSell.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>
|
@ -1,11 +1,12 @@
|
||||
using TypographyBusinessLogic.BusinessLogics;
|
||||
using TypographyContracts.BusinessLogicsContracts;
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyListImplement.Implements;
|
||||
using TypographyFileImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using TypographyBusinessLogic;
|
||||
using AutomobilePlantView;
|
||||
|
||||
namespace TypographyView
|
||||
{
|
||||
@ -54,7 +55,7 @@ namespace TypographyView
|
||||
services.AddTransient<FormMakeShipment>();
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
|
||||
services.AddTransient<FormShopSell>();
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
<ProjectReference Include="..\TypographyBusinessLogic\TypographyBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\TypographyContracts\TypographyContracts.csproj" />
|
||||
<ProjectReference Include="..\TypographyDataModels\TypographyDataModels.csproj" />
|
||||
<ProjectReference Include="..\TypographyFileImplement\TypographyFileImplement.csproj" />
|
||||
<ProjectReference Include="..\TypographyListImplement\TypographyListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyContracts", "..\T
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyBusinessLogic", "..\TypographyBusinessLogic\TypographyBusinessLogic.csproj", "{1057A33D-538D-4E7F-862B-1FF8E9E021A0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyFileImplement", "..\TypographyFileImplement\TypographyFileImplement.csproj", "{DCBDF361-C514-4319-A542-5629650E7E8A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -39,6 +41,10 @@ Global
|
||||
{1057A33D-538D-4E7F-862B-1FF8E9E021A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1057A33D-538D-4E7F-862B-1FF8E9E021A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1057A33D-538D-4E7F-862B-1FF8E9E021A0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DCBDF361-C514-4319-A542-5629650E7E8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DCBDF361-C514-4319-A542-5629650E7E8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DCBDF361-C514-4319-A542-5629650E7E8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DCBDF361-C514-4319-A542-5629650E7E8A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
x
Reference in New Issue
Block a user
Не используется