Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
242fc5eb91 | |||
d62fea0c1f | |||
fdd1193799 | |||
b5bbb21858 | |||
7772bf7f38 | |||
315ebdf4a5 | |||
97b1187f1b | |||
00033ec12b | |||
c1dcce61b0 |
108
AbstractShopBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
108
AbstractShopBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace DinerBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ComponentLogic : IComponentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_componentStorage = componentStorage;
|
||||
}
|
||||
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id);
|
||||
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public ComponentViewModel? ReadElement(ComponentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id}", model.ComponentName, model.Id);
|
||||
var element = _componentStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_componentStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ComponentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия компонента",
|
||||
nameof(model.ComponentName));
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
_logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
|
||||
var element = _componentStorage.GetElement(new ComponentSearchModel{
|
||||
ComponentName = model.ComponentName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
147
AbstractShopBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
147
AbstractShopBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
@ -0,0 +1,147 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
using DinerDataModels.Models;
|
||||
using DinerDataModels.Enum;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace DinerBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
|
||||
{
|
||||
_orderStorage = orderStorage;
|
||||
_logger = logger;
|
||||
_shopStorage = shopStorage;
|
||||
|
||||
}
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (model.Status != OrderStatus.Неизвестен) return false;
|
||||
model.Status = OrderStatus.Принят;
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
}
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Готов);
|
||||
}
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
Id = model.Id,
|
||||
});
|
||||
if (order == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(order));
|
||||
}
|
||||
if (!_shopStorage.RestockingShops(new SupplyBindingModel
|
||||
{
|
||||
SnackId = order.SnackId,
|
||||
Count = order.Count
|
||||
}))
|
||||
{
|
||||
throw new ArgumentException("Недостаточно места");
|
||||
}
|
||||
return ChangeStatus(model, OrderStatus.Выдан);
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.SnackId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Неверный идентификатор компонента", nameof(model.SnackId));
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество компонентов должно быть больше 0", nameof(model.Count));
|
||||
}
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
_logger.LogInformation("Order. ProductId: {ProductId}. Count: {Count}. Sum: {Sum}. Id: {Id}", model.SnackId, model.Count, model.Sum, model.Id);
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Изделие с таким идентификатором уже есть");
|
||||
}
|
||||
}
|
||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel()
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (element == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(element));
|
||||
}
|
||||
model.DateCreate = element.DateCreate;
|
||||
model.SnackId = element.SnackId;
|
||||
model.DateImplement = element.DateImplement;
|
||||
model.Status = element.Status;
|
||||
model.Count = element.Count;
|
||||
model.Sum = element.Sum;
|
||||
if (requiredStatus - model.Status == 1)
|
||||
{
|
||||
model.Status = requiredStatus;
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
model.DateImplement = DateTime.Now;
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
||||
throw new ArgumentException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
143
AbstractShopBusinessLogic/BusinessLogics/ReportLogic.cs
Normal file
143
AbstractShopBusinessLogic/BusinessLogics/ReportLogic.cs
Normal file
@ -0,0 +1,143 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels;
|
||||
using DinerBusinessLogic.OfficePackage;
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels.Word;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels.Excel;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels.PDF;
|
||||
|
||||
namespace DinerBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ReportLogic : IReportLogic
|
||||
{
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
private readonly ISnackStorage _snackStorage;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
private readonly AbstractSaveToWord _saveToWord;
|
||||
private readonly AbstractSaveToPdf _saveToPdf;
|
||||
|
||||
public ReportLogic(ISnackStorage snackStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage,
|
||||
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||
{
|
||||
_snackStorage = snackStorage;
|
||||
_componentStorage = componentStorage;
|
||||
_orderStorage = orderStorage;
|
||||
_shopStorage = shopStorage;
|
||||
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToPdf = saveToPdf;
|
||||
}
|
||||
public List<ReportSnackComponentViewModel> GetSnackComponents()
|
||||
{
|
||||
return _snackStorage.GetFullList().Select(x => new ReportSnackComponentViewModel
|
||||
{
|
||||
SnackName = x.SnackName,
|
||||
Components = x.SnackComponents.Select(x => (x.Value.Item1.ComponentName, x.Value.Item2)).ToList(),
|
||||
TotalCount = x.SnackComponents.Select(x => x.Value.Item2).Sum()
|
||||
}).ToList();
|
||||
}
|
||||
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
|
||||
{
|
||||
return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo })
|
||||
.Select(x => new ReportOrdersViewModel
|
||||
{
|
||||
Id = x.Id,
|
||||
DateCreate = x.DateCreate,
|
||||
SnackName = x.SnackName,
|
||||
Sum = x.Sum,
|
||||
Status= x.Status.ToString()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
public void SaveSnacksToWordFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToWord.CreateSnackDoc(new WordSnackInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список закуска",
|
||||
Snacks = _snackStorage.GetFullList()
|
||||
});
|
||||
}
|
||||
public void SaveSnackComponentToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToExcel.CreateReport(new ExcelInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список закусок",
|
||||
SnackComponents = GetSnackComponents()
|
||||
});
|
||||
}
|
||||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToPdf.CreateDoc(new PdfInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список заказов",
|
||||
DateFrom = model.DateFrom!.Value,
|
||||
DateTo = model.DateTo!.Value,
|
||||
Orders = GetOrders(model)
|
||||
});
|
||||
}
|
||||
|
||||
public List<ReportShopsViewModel> GetShops()
|
||||
{
|
||||
return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel
|
||||
{
|
||||
ShopName = x.ShopName,
|
||||
Snacks = x.ShopSnacks.Select(x => (x.Value.Item1.SnackName, x.Value.Item2)).ToList(),
|
||||
TotalCount = x.ShopSnacks.Select(x => x.Value.Item2).Sum()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public List<ReportGroupOrdersViewModel> GetGroupedOrders()
|
||||
{
|
||||
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupOrdersViewModel
|
||||
{
|
||||
Date = x.Key,
|
||||
OrdersCount = x.Count(),
|
||||
OrdersSum = x.Select(y => y.Sum).Sum()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public void SaveShopsToWordFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToWord.CreateShopsDoc(new WordShopInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список магазинов",
|
||||
Shops = _shopStorage.GetFullList()
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveShopsToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToExcel.CreateShopSnacksReport(new ExcelShop
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Наполненость магазинов",
|
||||
ShopSnacks = GetShops()
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveGroupedOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список заказов сгруппированных по дате заказов",
|
||||
GroupedOrders = GetGroupedOrders()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
185
AbstractShopBusinessLogic/BusinessLogics/ShopLogic.cs
Normal file
185
AbstractShopBusinessLogic/BusinessLogics/ShopLogic.cs
Normal file
@ -0,0 +1,185 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DinerListImplement.Implements;
|
||||
|
||||
namespace DinerBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ShopLogic : IShopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
private readonly ISnackStorage _snackStorage;
|
||||
|
||||
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage, ISnackStorage snackStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_shopStorage = shopStorage;
|
||||
_snackStorage = snackStorage;
|
||||
}
|
||||
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id);
|
||||
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
|
||||
var element = _shopStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_shopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_shopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_shopStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool MakeSupply(SupplyBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество изделий должно быть больше 0");
|
||||
}
|
||||
var shop = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
Id = model.ShopId
|
||||
});
|
||||
if (shop == null)
|
||||
{
|
||||
throw new ArgumentException("Магазина не существует");
|
||||
}
|
||||
if (shop.ShopSnacks.ContainsKey(model.SnackId))
|
||||
{
|
||||
var oldValue = shop.ShopSnacks[model.SnackId];
|
||||
oldValue.Item2 += model.Count;
|
||||
shop.ShopSnacks[model.SnackId] = oldValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
var snack = _snackStorage.GetElement(new SnackSearchModel
|
||||
{
|
||||
Id = model.SnackId
|
||||
});
|
||||
if (snack == null)
|
||||
{
|
||||
throw new ArgumentException($"Поставка: Товар с id:{model.SnackId} не найденн");
|
||||
}
|
||||
shop.ShopSnacks.Add(model.SnackId, (snack, model.Count));
|
||||
}
|
||||
_shopStorage.Update(new ShopBindingModel()
|
||||
{
|
||||
Id = shop.Id,
|
||||
ShopName = shop.ShopName,
|
||||
Adress = shop.Adress,
|
||||
OpeningDate = shop.OpeningDate,
|
||||
ShopSnacks = shop.ShopSnacks,
|
||||
SnackMaxCount = shop.SnackMaxCount,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Adress))
|
||||
{
|
||||
throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName));
|
||||
}
|
||||
_logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id);
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
ShopName = model.ShopName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
public bool Sale(SupplySearchModel model)
|
||||
{
|
||||
if (!model.SnackId.HasValue || !model.Count.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_logger.LogInformation("Check snack count in all shops");
|
||||
if (_shopStorage.Sale(model))
|
||||
{
|
||||
_logger.LogInformation("Selling sucsess");
|
||||
return true;
|
||||
}
|
||||
_logger.LogInformation("Selling failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
108
AbstractShopBusinessLogic/BusinessLogics/SnackLogic.cs
Normal file
108
AbstractShopBusinessLogic/BusinessLogics/SnackLogic.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace DinerBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class SnackLogic : ISnackLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISnackStorage _snackStorage;
|
||||
public SnackLogic(ILogger<SnackLogic> logger, ISnackStorage snackStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_snackStorage = snackStorage;
|
||||
}
|
||||
public List<SnackViewModel>? ReadList(SnackSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. BouquetName:{BouquetName}.Id:{ Id}", model?.SnackName, model?.Id);
|
||||
var list = model == null ? _snackStorage.GetFullList() : _snackStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public SnackViewModel? ReadElement(SnackSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. BouquetName:{BouquetName}.Id:{ Id}", model.SnackName, model.Id);
|
||||
var element = _snackStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(SnackBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_snackStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(SnackBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_snackStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(SnackBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_snackStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(SnackBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.SnackName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия изделия",
|
||||
nameof(model.SnackName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("Product. BouquetName:{BouquetName}.Cost:{ Cost}. Id: { Id}", model.SnackName, model.Price, model.Id);
|
||||
var element = _snackStorage.GetElement(new SnackSearchModel
|
||||
{
|
||||
SnackName = model.SnackName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Изделие с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
AbstractShopBusinessLogic/DinerBusinessLogic.csproj
Normal file
21
AbstractShopBusinessLogic/DinerBusinessLogic.csproj
Normal file
@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="NPOI" Version="2.6.2" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AbstractShopContracts\DinerContracts.csproj" />
|
||||
<ProjectReference Include="..\Diner\AbstractShopListImplement\DinerListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
282
AbstractShopBusinessLogic/Implements/SaveToExcel.cs
Normal file
282
AbstractShopBusinessLogic/Implements/SaveToExcel.cs
Normal file
@ -0,0 +1,282 @@
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using DocumentFormat.OpenXml.Office2013.Excel;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DinerBusinessLogic.OfficePackage;
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.Implements
|
||||
{
|
||||
public class SaveToExcel : AbstractSaveToExcel
|
||||
{
|
||||
private SpreadsheetDocument? _spreadsheetDocument;
|
||||
private SharedStringTablePart? _shareStringPart;
|
||||
private Worksheet? _worksheet;
|
||||
|
||||
private static void CreateStyles(WorkbookPart workbookpart)
|
||||
{
|
||||
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
||||
sp.Stylesheet = new Stylesheet();
|
||||
|
||||
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
|
||||
|
||||
var fontUsual = new Font();
|
||||
fontUsual.Append(new FontSize() { Val = 12D });
|
||||
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
|
||||
fontUsual.Append(new FontName() { Val = "Times New Roman" });
|
||||
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
|
||||
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||
|
||||
var fontTitle = new Font();
|
||||
fontTitle.Append(new Bold());
|
||||
fontTitle.Append(new FontSize() { Val = 14D });
|
||||
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
|
||||
fontTitle.Append(new FontName() { Val = "Times New Roman" });
|
||||
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
|
||||
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||
|
||||
fonts.Append(fontUsual);
|
||||
fonts.Append(fontTitle);
|
||||
|
||||
var fills = new Fills() { Count = 2U };
|
||||
|
||||
var fill1 = new Fill();
|
||||
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
||||
|
||||
var fill2 = new Fill();
|
||||
fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 });
|
||||
|
||||
fills.Append(fill1);
|
||||
fills.Append(fill2);
|
||||
|
||||
var borders = new Borders() { Count = 2U };
|
||||
|
||||
var borderNoBorder = new Border();
|
||||
borderNoBorder.Append(new LeftBorder());
|
||||
borderNoBorder.Append(new RightBorder());
|
||||
borderNoBorder.Append(new TopBorder());
|
||||
borderNoBorder.Append(new BottomBorder());
|
||||
borderNoBorder.Append(new DiagonalBorder());
|
||||
|
||||
var borderThin = new Border();
|
||||
|
||||
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
||||
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin };
|
||||
rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
|
||||
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin };
|
||||
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||
|
||||
borderThin.Append(leftBorder);
|
||||
borderThin.Append(rightBorder);
|
||||
borderThin.Append(topBorder);
|
||||
borderThin.Append(bottomBorder);
|
||||
borderThin.Append(new DiagonalBorder());
|
||||
|
||||
borders.Append(borderNoBorder);
|
||||
borders.Append(borderThin);
|
||||
|
||||
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
|
||||
var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U };
|
||||
|
||||
cellStyleFormats.Append(cellFormatStyle);
|
||||
|
||||
var cellFormats = new CellFormats() { Count = 3U };
|
||||
var cellFormatFont = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true };
|
||||
var cellFormatFontAndBorder = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 1U, FormatId = 0U, ApplyFont = true, ApplyBorder = true };
|
||||
var cellFormatTitle = new CellFormat() { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true };
|
||||
|
||||
cellFormats.Append(cellFormatFont);
|
||||
cellFormats.Append(cellFormatFontAndBorder);
|
||||
cellFormats.Append(cellFormatTitle);
|
||||
|
||||
var cellStyles = new CellStyles() { Count = 1U };
|
||||
|
||||
cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U });
|
||||
|
||||
var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U };
|
||||
|
||||
var tableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" };
|
||||
|
||||
var stylesheetExtensionList = new StylesheetExtensionList();
|
||||
|
||||
var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" };
|
||||
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
|
||||
stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" });
|
||||
|
||||
var stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" };
|
||||
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
|
||||
stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" });
|
||||
|
||||
stylesheetExtensionList.Append(stylesheetExtension1);
|
||||
stylesheetExtensionList.Append(stylesheetExtension2);
|
||||
|
||||
sp.Stylesheet.Append(fonts);
|
||||
sp.Stylesheet.Append(fills);
|
||||
sp.Stylesheet.Append(borders);
|
||||
sp.Stylesheet.Append(cellStyleFormats);
|
||||
sp.Stylesheet.Append(cellFormats);
|
||||
sp.Stylesheet.Append(cellStyles);
|
||||
sp.Stylesheet.Append(differentialFormats);
|
||||
sp.Stylesheet.Append(tableStyles);
|
||||
sp.Stylesheet.Append(stylesheetExtensionList);
|
||||
}
|
||||
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
|
||||
{
|
||||
return styleInfo switch
|
||||
{
|
||||
ExcelStyleInfoType.Title => 2U,
|
||||
ExcelStyleInfoType.TextWithBroder => 1U,
|
||||
ExcelStyleInfoType.Text => 0U,
|
||||
_ => 0U,
|
||||
};
|
||||
}
|
||||
protected override void CreateExcel(IDocument info)
|
||||
{
|
||||
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
|
||||
// Создаем книгу (в ней хранятся листы)
|
||||
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
||||
workbookpart.Workbook = new Workbook();
|
||||
|
||||
CreateStyles(workbookpart);
|
||||
|
||||
// Получаем/создаем хранилище текстов для книги
|
||||
_shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
|
||||
? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
|
||||
: _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
|
||||
|
||||
// Создаем SharedStringTable, если его нет
|
||||
if (_shareStringPart.SharedStringTable == null)
|
||||
{
|
||||
_shareStringPart.SharedStringTable = new SharedStringTable();
|
||||
}
|
||||
|
||||
// Создаем лист в книгу
|
||||
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||
worksheetPart.Worksheet = new Worksheet(new SheetData());
|
||||
|
||||
// Добавляем лист в книгу
|
||||
var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
|
||||
var sheet = new Sheet()
|
||||
{
|
||||
Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
||||
SheetId = 1,
|
||||
Name = "Лист"
|
||||
};
|
||||
sheets.Append(sheet);
|
||||
|
||||
_worksheet = worksheetPart.Worksheet;
|
||||
}
|
||||
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
|
||||
{
|
||||
if (_worksheet == null || _shareStringPart == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var sheetData = _worksheet.GetFirstChild<SheetData>();
|
||||
if (sheetData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Ищем строку, либо добавляем ее
|
||||
Row row;
|
||||
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
|
||||
{
|
||||
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
row = new Row() { RowIndex = excelParams.RowIndex };
|
||||
sheetData.Append(row);
|
||||
}
|
||||
|
||||
// Ищем нужную ячейку
|
||||
Cell cell;
|
||||
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
|
||||
{
|
||||
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Все ячейки должны быть последовательно друг за другом расположены
|
||||
// нужно определить, после какой вставлять
|
||||
Cell? refCell = null;
|
||||
foreach (Cell rowCell in row.Elements<Cell>())
|
||||
{
|
||||
if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0)
|
||||
{
|
||||
refCell = rowCell;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var newCell = new Cell() { CellReference = excelParams.CellReference };
|
||||
row.InsertBefore(newCell, refCell);
|
||||
|
||||
cell = newCell;
|
||||
}
|
||||
|
||||
// вставляем новый текст
|
||||
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
|
||||
_shareStringPart.SharedStringTable.Save();
|
||||
|
||||
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
|
||||
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
|
||||
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
|
||||
}
|
||||
protected override void MergeCells(ExcelMergeParameters excelParams)
|
||||
{
|
||||
if (_worksheet == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MergeCells mergeCells;
|
||||
|
||||
if (_worksheet.Elements<MergeCells>().Any())
|
||||
{
|
||||
mergeCells = _worksheet.Elements<MergeCells>().First();
|
||||
}
|
||||
else
|
||||
{
|
||||
mergeCells = new MergeCells();
|
||||
|
||||
if (_worksheet.Elements<CustomSheetView>().Any())
|
||||
{
|
||||
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<CustomSheetView>().First());
|
||||
}
|
||||
else
|
||||
{
|
||||
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<SheetData>().First());
|
||||
}
|
||||
}
|
||||
|
||||
var mergeCell = new MergeCell()
|
||||
{
|
||||
Reference = new StringValue(excelParams.Merge)
|
||||
};
|
||||
mergeCells.Append(mergeCell);
|
||||
}
|
||||
protected override void SaveExcel(IDocument info)
|
||||
{
|
||||
if (_spreadsheetDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
|
||||
_spreadsheetDocument.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
108
AbstractShopBusinessLogic/Implements/SaveToPdf.cs
Normal file
108
AbstractShopBusinessLogic/Implements/SaveToPdf.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using DinerBusinessLogic.OfficePackage;
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.Implements
|
||||
{
|
||||
public class SaveToPdf : AbstractSaveToPdf
|
||||
{
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private Table? _table;
|
||||
|
||||
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||
PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify,
|
||||
};
|
||||
}
|
||||
private static void DefineStyles(Document document)
|
||||
{
|
||||
var style = document.Styles["Normal"];
|
||||
style.Font.Name = "Times New Roman";
|
||||
style.Font.Size = 14;
|
||||
|
||||
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
||||
style.Font.Bold = true;
|
||||
}
|
||||
protected override void CreatePdf(IDocument info)
|
||||
{
|
||||
_document = new Document();
|
||||
DefineStyles(_document);
|
||||
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
protected override void CreateParagraph(PdfParagraph pdfParagraph)
|
||||
{
|
||||
if (_section == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var paragraph = _section.AddParagraph(pdfParagraph.Text);
|
||||
paragraph.Format.SpaceAfter = "1cm";
|
||||
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
|
||||
paragraph.Style = pdfParagraph.Style;
|
||||
}
|
||||
protected override void CreateTable(List<string> columns)
|
||||
{
|
||||
if (_document == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_table = _document.LastSection.AddTable();
|
||||
|
||||
foreach (var elem in columns)
|
||||
{
|
||||
_table.AddColumn(elem);
|
||||
}
|
||||
}
|
||||
protected override void CreateRow(PdfRowParameters rowParameters)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var row = _table.AddRow();
|
||||
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
||||
{
|
||||
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
|
||||
|
||||
if (!string.IsNullOrEmpty(rowParameters.Style))
|
||||
{
|
||||
row.Cells[i].Style = rowParameters.Style;
|
||||
}
|
||||
|
||||
Unit borderWidth = 0.5;
|
||||
|
||||
row.Cells[i].Borders.Left.Width = borderWidth;
|
||||
row.Cells[i].Borders.Right.Width = borderWidth;
|
||||
row.Cells[i].Borders.Top.Width = borderWidth;
|
||||
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||
|
||||
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
|
||||
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
}
|
||||
protected override void SavePdf(IDocument info)
|
||||
{
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
}
|
||||
}
|
193
AbstractShopBusinessLogic/Implements/SaveToWord.cs
Normal file
193
AbstractShopBusinessLogic/Implements/SaveToWord.cs
Normal file
@ -0,0 +1,193 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using DinerBusinessLogic.OfficePackage;
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels.Word;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.Implements
|
||||
{
|
||||
public class SaveToWord : AbstractSaveToWord
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
private Body? _docBody;
|
||||
|
||||
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
WordJustificationType.Both => JustificationValues.Both,
|
||||
WordJustificationType.Center => JustificationValues.Center,
|
||||
_ => JustificationValues.Left,
|
||||
};
|
||||
}
|
||||
private static SectionProperties CreateSectionProperties()
|
||||
{
|
||||
var properties = new SectionProperties();
|
||||
|
||||
var pageSize = new PageSize
|
||||
{
|
||||
Orient = PageOrientationValues.Portrait
|
||||
};
|
||||
|
||||
properties.AppendChild(pageSize);
|
||||
|
||||
return properties;
|
||||
}
|
||||
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||
{
|
||||
if (paragraphProperties == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var properties = new ParagraphProperties();
|
||||
|
||||
properties.AppendChild(new Justification()
|
||||
{
|
||||
Val = GetJustificationValues(paragraphProperties.JustificationType)
|
||||
});
|
||||
|
||||
properties.AppendChild(new SpacingBetweenLines
|
||||
{
|
||||
LineRule = LineSpacingRuleValues.Auto
|
||||
});
|
||||
|
||||
properties.AppendChild(new Indentation());
|
||||
|
||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||
{
|
||||
paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size });
|
||||
}
|
||||
properties.AppendChild(paragraphMarkRunProperties);
|
||||
|
||||
return properties;
|
||||
}
|
||||
protected override void CreateWord(IDocument info)
|
||||
{
|
||||
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = new Document();
|
||||
_docBody = mainPart.Document.AppendChild(new Body());
|
||||
}
|
||||
protected override void CreateParagraph(WordParagraph paragraph)
|
||||
{
|
||||
if (_docBody == null || paragraph == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var docParagraph = new Paragraph();
|
||||
|
||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
||||
|
||||
foreach (var run in paragraph.Texts)
|
||||
{
|
||||
var docRun = new Run();
|
||||
|
||||
var properties = new RunProperties();
|
||||
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
||||
if (run.Item2.Bold)
|
||||
{
|
||||
properties.AppendChild(new Bold());
|
||||
}
|
||||
docRun.AppendChild(properties);
|
||||
|
||||
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
|
||||
|
||||
docParagraph.AppendChild(docRun);
|
||||
}
|
||||
|
||||
_docBody.AppendChild(docParagraph);
|
||||
}
|
||||
protected override void SaveWord(IDocument info)
|
||||
{
|
||||
if (_docBody == null || _wordDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_docBody.AppendChild(CreateSectionProperties());
|
||||
|
||||
_wordDocument.MainDocumentPart!.Document.Save();
|
||||
|
||||
_wordDocument.Dispose();
|
||||
}
|
||||
|
||||
private Table? _lastTable;
|
||||
protected override void CreateTable(List<string> columns)
|
||||
{
|
||||
if (_docBody == null)
|
||||
return;
|
||||
|
||||
_lastTable = new Table();
|
||||
|
||||
var tableProp = new TableProperties();
|
||||
tableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed });
|
||||
tableProp.AppendChild(new TableBorders(
|
||||
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 }
|
||||
));
|
||||
tableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto });
|
||||
_lastTable.AppendChild(tableProp);
|
||||
|
||||
TableGrid tableGrid = new TableGrid();
|
||||
foreach (var column in columns)
|
||||
{
|
||||
tableGrid.AppendChild(new GridColumn() { Width = column });
|
||||
}
|
||||
_lastTable.AppendChild(tableGrid);
|
||||
|
||||
_docBody.AppendChild(_lastTable);
|
||||
}
|
||||
protected override void CreateRow(WordRowParameters rowParameters)
|
||||
{
|
||||
if (_docBody == null || _lastTable == null)
|
||||
return;
|
||||
|
||||
TableRow docRow = new TableRow();
|
||||
foreach (var column in rowParameters.Texts)
|
||||
{
|
||||
var docParagraph = new Paragraph();
|
||||
WordParagraph paragraph = new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (column, rowParameters.TextProperties) },
|
||||
TextProperties = rowParameters.TextProperties
|
||||
};
|
||||
|
||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
||||
|
||||
foreach (var run in paragraph.Texts)
|
||||
{
|
||||
var docRun = new Run();
|
||||
|
||||
var properties = new RunProperties();
|
||||
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
||||
if (run.Item2.Bold)
|
||||
{
|
||||
properties.AppendChild(new Bold());
|
||||
}
|
||||
docRun.AppendChild(properties);
|
||||
|
||||
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
|
||||
|
||||
docParagraph.AppendChild(docRun);
|
||||
}
|
||||
|
||||
TableCell docCell = new TableCell();
|
||||
docCell.AppendChild(docParagraph);
|
||||
docRow.AppendChild(docCell);
|
||||
}
|
||||
_lastTable.AppendChild(docRow);
|
||||
}
|
||||
}
|
||||
}
|
162
AbstractShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs
Normal file
162
AbstractShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs
Normal file
@ -0,0 +1,162 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels.Excel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToExcel
|
||||
{
|
||||
public void CreateReport(ExcelInfo info)
|
||||
{
|
||||
CreateExcel(info);
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = 1,
|
||||
Text = info.Title,
|
||||
StyleInfo = ExcelStyleInfoType.Title
|
||||
});
|
||||
|
||||
MergeCells(new ExcelMergeParameters
|
||||
{
|
||||
CellFromName = "A1",
|
||||
CellToName = "C1"
|
||||
});
|
||||
|
||||
uint rowIndex = 2;
|
||||
foreach (var pc in info.SnackComponents)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = pc.SnackName,
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
|
||||
foreach (var (Component, Count) in pc.Components)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = Component,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = Count.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = "Итого",
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = pc.TotalCount.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
SaveExcel(info);
|
||||
}
|
||||
|
||||
public void CreateShopSnacksReport(ExcelShop info)
|
||||
{
|
||||
CreateExcel(info);
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = 1,
|
||||
Text = info.Title,
|
||||
StyleInfo = ExcelStyleInfoType.Title
|
||||
});
|
||||
|
||||
MergeCells(new ExcelMergeParameters
|
||||
{
|
||||
CellFromName = "A1",
|
||||
CellToName = "C1"
|
||||
});
|
||||
|
||||
uint rowIndex = 2;
|
||||
foreach (var sr in info.ShopSnacks)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = sr.ShopName,
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
|
||||
foreach (var (Snack, Count) in sr.Snacks)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = Snack,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = Count.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = "Итого",
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = sr.TotalCount.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
SaveExcel(info);
|
||||
}
|
||||
|
||||
protected abstract void CreateExcel(IDocument info);
|
||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||
protected abstract void SaveExcel(IDocument info);
|
||||
}
|
||||
}
|
78
AbstractShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs
Normal file
78
AbstractShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels.PDF;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToPdf
|
||||
{
|
||||
public void CreateDoc(PdfInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
|
||||
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Номер", "Дата заказа", "Закуска", "Статус", "Сумма" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
|
||||
foreach (var order in info.Orders)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.SnackName, order.Status.ToString(), order.Sum.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth });
|
||||
|
||||
SavePdf(info);
|
||||
}
|
||||
|
||||
public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
CreateTable(new List<string> { "4cm", "3cm", "2cm" });
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Дата заказа", "Кол-во", "Сумма" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
|
||||
|
||||
foreach (var groupedOrder in info.GroupedOrders)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { groupedOrder.Date.ToShortDateString(), groupedOrder.OrdersCount.ToString(), groupedOrder.OrdersSum.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
|
||||
CreateParagraph(new PdfParagraph { Text = $"Итого: {info.GroupedOrders.Sum(x => x.OrdersSum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
SavePdf(info);
|
||||
}
|
||||
|
||||
protected abstract void CreatePdf(IDocument info);
|
||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||
protected abstract void SavePdf(IDocument info);
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels;
|
||||
using DinerBusinessLogic.OfficePackage.HelperModels.Word;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToWord
|
||||
{
|
||||
public void CreateSnackDoc(WordSnackInfo info)
|
||||
{
|
||||
CreateWord(info);
|
||||
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var snack in info.Snacks)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> {
|
||||
(snack.SnackName, new WordTextProperties { Size = "24", Bold = true}),
|
||||
("\t"+snack.Price.ToString(), new WordTextProperties{Size = "24"})
|
||||
},
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SaveWord(info);
|
||||
}
|
||||
|
||||
public void CreateShopsDoc(WordShopInfo info)
|
||||
{
|
||||
CreateWord(info);
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
|
||||
CreateTable(new List<string> { "3000", "3000", "3000" });
|
||||
CreateRow(new WordRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Название", "Адрес", "Дата открытия" },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
Bold = true,
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var shop in info.Shops)
|
||||
{
|
||||
CreateRow(new WordRowParameters
|
||||
{
|
||||
Texts = new List<string> { shop.ShopName, shop.Adress, shop.OpeningDate.ToString() },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "22",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SaveWord(info);
|
||||
}
|
||||
protected abstract void CreateWord(IDocument info);
|
||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||
protected abstract void SaveWord(IDocument info);
|
||||
protected abstract void CreateTable(List<string> colums);
|
||||
protected abstract void CreateRow(WordRowParameters rowParameters);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum ExcelStyleInfoType
|
||||
{
|
||||
Title,
|
||||
Text,
|
||||
TextWithBroder
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum PdfParagraphAlignmentType
|
||||
{
|
||||
Center,
|
||||
Left,
|
||||
Rigth
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum WordJustificationType
|
||||
{
|
||||
Center,
|
||||
Both
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelCellParameters
|
||||
{
|
||||
public string ColumnName { get; set; } = string.Empty;
|
||||
public uint RowIndex { get; set; }
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string CellReference => $"{ColumnName}{RowIndex}";
|
||||
public ExcelStyleInfoType StyleInfo { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelInfo : IDocument
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ReportSnackComponentViewModel> SnackComponents { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelMergeParameters
|
||||
{
|
||||
public string CellFromName { get; set; } = string.Empty;
|
||||
public string CellToName { get; set; } = string.Empty;
|
||||
public string Merge => $"{CellFromName}:{CellToName}";
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels.Excel
|
||||
{
|
||||
public class ExcelShop : IDocument
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ReportShopsViewModel> ShopSnacks { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels.PDF
|
||||
{
|
||||
public class PdfGroupedOrdersInfo : IDocument
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public List<ReportGroupOrdersViewModel> GroupedOrders { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfInfo : IDocument
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public List<ReportOrdersViewModel> Orders { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfParagraph
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfRowParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordParagraph
|
||||
{
|
||||
public List<(string, WordTextProperties)> Texts { get; set; } = new();
|
||||
public WordTextProperties? TextProperties { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels.Word
|
||||
{
|
||||
public class WordRowParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
public WordTextProperties TextProperties { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels.Word
|
||||
{
|
||||
public class WordShopInfo : IDocument
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ShopViewModel> Shops { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordSnackInfo : IDocument
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<SnackViewModel> Snacks { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using DinerBusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordTextProperties
|
||||
{
|
||||
public string Size { get; set; } = string.Empty;
|
||||
public bool Bold { get; set; }
|
||||
public WordJustificationType JustificationType { get; set; }
|
||||
}
|
||||
}
|
14
AbstractShopBusinessLogic/OfficePackage/IDocument.cs
Normal file
14
AbstractShopBusinessLogic/OfficePackage/IDocument.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerBusinessLogic.OfficePackage
|
||||
{
|
||||
public interface IDocument
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string Title { get; set; }
|
||||
}
|
||||
}
|
12
AbstractShopContracts/BindingModels/ComponentBindingModel.cs
Normal file
12
AbstractShopContracts/BindingModels/ComponentBindingModel.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using DinerDataModels.Models;
|
||||
|
||||
namespace DinerContracts.BindingModels
|
||||
{
|
||||
public class ComponentBindingModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
|
||||
}
|
18
AbstractShopContracts/BindingModels/OrderBindingModel.cs
Normal file
18
AbstractShopContracts/BindingModels/OrderBindingModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using DinerDataModels.Enum;
|
||||
using DinerDataModels.Models;
|
||||
|
||||
|
||||
namespace DinerContracts.BindingModels
|
||||
{
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int SnackId { get; set; }
|
||||
public string SnackName { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set;}
|
||||
}
|
||||
}
|
15
AbstractShopContracts/BindingModels/ReportBindingModel.cs
Normal file
15
AbstractShopContracts/BindingModels/ReportBindingModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.BindingModels
|
||||
{
|
||||
public class ReportBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
19
AbstractShopContracts/BindingModels/ShopBindingModel.cs
Normal file
19
AbstractShopContracts/BindingModels/ShopBindingModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using DinerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.BindingModels
|
||||
{
|
||||
public class ShopBindingModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
public string Adress { get; set; } = string.Empty;
|
||||
public DateTime OpeningDate { get; set; } = DateTime.Now;
|
||||
public Dictionary<int, (ISnackModel, int)> ShopSnacks { get; set; } = new();
|
||||
public int SnackMaxCount { get; set; }
|
||||
}
|
||||
}
|
14
AbstractShopContracts/BindingModels/SnackBindingModel.cs
Normal file
14
AbstractShopContracts/BindingModels/SnackBindingModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using DinerDataModels.Models;
|
||||
|
||||
|
||||
namespace DinerContracts.BindingModels
|
||||
{
|
||||
public class SnackBindingModel : ISnackModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string SnackName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> SnackComponents { get; set; } = new();
|
||||
}
|
||||
|
||||
}
|
16
AbstractShopContracts/BindingModels/SupplyBindingModel.cs
Normal file
16
AbstractShopContracts/BindingModels/SupplyBindingModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using DinerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.BindingModels
|
||||
{
|
||||
public class SupplyBindingModel : ISupplyModel
|
||||
{
|
||||
public int ShopId { get; set; }
|
||||
public int SnackId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.ViewModels;
|
||||
|
||||
|
||||
namespace DinerContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IComponentLogic
|
||||
{
|
||||
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
|
||||
ComponentViewModel? ReadElement(ComponentSearchModel model);
|
||||
bool Create(ComponentBindingModel model);
|
||||
bool Update(ComponentBindingModel model);
|
||||
bool Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
15
AbstractShopContracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
15
AbstractShopContracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.ViewModels;
|
||||
|
||||
namespace DinerContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IOrderLogic
|
||||
{
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
bool DeliveryOrder(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.ViewModels;
|
||||
using DinerContracts.SearchModels;
|
||||
|
||||
namespace DinerContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IReportLogic
|
||||
{
|
||||
List<ReportSnackComponentViewModel> GetSnackComponents();
|
||||
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
|
||||
List<ReportShopsViewModel> GetShops();
|
||||
List<ReportGroupOrdersViewModel> GetGroupedOrders();
|
||||
void SaveSnacksToWordFile(ReportBindingModel model);
|
||||
void SaveSnackComponentToExcelFile(ReportBindingModel model);
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
void SaveShopsToWordFile(ReportBindingModel model);
|
||||
void SaveShopsToExcelFile(ReportBindingModel model);
|
||||
void SaveGroupedOrdersToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
}
|
22
AbstractShopContracts/BusinessLogicsContracts/IShopLogic.cs
Normal file
22
AbstractShopContracts/BusinessLogicsContracts/IShopLogic.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IShopLogic
|
||||
{
|
||||
List<ShopViewModel>? ReadList(ShopSearchModel? model);
|
||||
ShopViewModel? ReadElement(ShopSearchModel model);
|
||||
bool Create(ShopBindingModel model);
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool MakeSupply(SupplyBindingModel model);
|
||||
bool Sale(SupplySearchModel model);
|
||||
}
|
||||
}
|
15
AbstractShopContracts/BusinessLogicsContracts/ISnackLogic.cs
Normal file
15
AbstractShopContracts/BusinessLogicsContracts/ISnackLogic.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.ViewModels;
|
||||
|
||||
namespace DinerContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface ISnackLogic
|
||||
{
|
||||
List<SnackViewModel>? ReadList(SnackSearchModel? model);
|
||||
SnackViewModel? ReadElement(SnackSearchModel model);
|
||||
bool Create(SnackBindingModel model);
|
||||
bool Update(SnackBindingModel model);
|
||||
bool Delete(SnackBindingModel model);
|
||||
}
|
||||
}
|
13
AbstractShopContracts/DinerContracts.csproj
Normal file
13
AbstractShopContracts/DinerContracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AbstractShopDataModels\DinerDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,8 @@
|
||||
namespace DinerContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ComponentName { get; set; }
|
||||
}
|
||||
}
|
9
AbstractShopContracts/SearchModels/OrderSearchModel.cs
Normal file
9
AbstractShopContracts/SearchModels/OrderSearchModel.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace DinerContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
14
AbstractShopContracts/SearchModels/ShopSearchModel.cs
Normal file
14
AbstractShopContracts/SearchModels/ShopSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.SearchModels
|
||||
{
|
||||
public class ShopSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ShopName { get; set; }
|
||||
}
|
||||
}
|
8
AbstractShopContracts/SearchModels/SnackSearchModel.cs
Normal file
8
AbstractShopContracts/SearchModels/SnackSearchModel.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace DinerContracts.SearchModels
|
||||
{
|
||||
public class SnackSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? SnackName { get; set; }
|
||||
}
|
||||
}
|
14
AbstractShopContracts/SearchModels/SupplySearchModel.cs
Normal file
14
AbstractShopContracts/SearchModels/SupplySearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.SearchModels
|
||||
{
|
||||
public class SupplySearchModel
|
||||
{
|
||||
public int? SnackId { get; set; }
|
||||
public int? Count { get; set; }
|
||||
}
|
||||
}
|
16
AbstractShopContracts/StoragesContracts/IComponentStorage.cs
Normal file
16
AbstractShopContracts/StoragesContracts/IComponentStorage.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.ViewModels;
|
||||
|
||||
namespace DinerContracts.StoragesContracts
|
||||
{
|
||||
public interface IComponentStorage
|
||||
{
|
||||
List<ComponentViewModel> GetFullList();
|
||||
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
|
||||
ComponentViewModel? GetElement(ComponentSearchModel model);
|
||||
ComponentViewModel? Insert(ComponentBindingModel model);
|
||||
ComponentViewModel? Update(ComponentBindingModel model);
|
||||
ComponentViewModel? Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
17
AbstractShopContracts/StoragesContracts/IOrderStorage.cs
Normal file
17
AbstractShopContracts/StoragesContracts/IOrderStorage.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.ViewModels;
|
||||
|
||||
namespace DinerContracts.StoragesContracts
|
||||
{
|
||||
public interface IOrderStorage
|
||||
{
|
||||
List<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
|
||||
}
|
||||
}
|
23
AbstractShopContracts/StoragesContracts/IShopStorage.cs
Normal file
23
AbstractShopContracts/StoragesContracts/IShopStorage.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.StoragesContracts
|
||||
{
|
||||
public interface IShopStorage
|
||||
{
|
||||
List<ShopViewModel> GetFullList();
|
||||
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
||||
ShopViewModel? GetElement(ShopSearchModel model);
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool Sale(SupplySearchModel model);
|
||||
bool RestockingShops(SupplyBindingModel model);
|
||||
}
|
||||
}
|
17
AbstractShopContracts/StoragesContracts/ISnackStorage.cs
Normal file
17
AbstractShopContracts/StoragesContracts/ISnackStorage.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.ViewModels;
|
||||
|
||||
namespace DinerContracts.StoragesContracts
|
||||
{
|
||||
public interface ISnackStorage
|
||||
{
|
||||
List<SnackViewModel> GetFullList();
|
||||
List<SnackViewModel> GetFilteredList(SnackSearchModel model);
|
||||
SnackViewModel? GetElement(SnackSearchModel model);
|
||||
SnackViewModel? Insert(SnackBindingModel model);
|
||||
SnackViewModel? Update(SnackBindingModel model);
|
||||
SnackViewModel? Delete(SnackBindingModel model);
|
||||
|
||||
}
|
||||
}
|
14
AbstractShopContracts/ViewModels/ComponentViewModel.cs
Normal file
14
AbstractShopContracts/ViewModels/ComponentViewModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.ComponentModel;
|
||||
using DinerDataModels.Models;
|
||||
|
||||
namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название компонента")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
25
AbstractShopContracts/ViewModels/OrderViewModel.cs
Normal file
25
AbstractShopContracts/ViewModels/OrderViewModel.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System.ComponentModel;
|
||||
using DinerDataModels.Models;
|
||||
using DinerDataModels.Enum;
|
||||
|
||||
namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int SnackId { get; set; }
|
||||
[DisplayName("Изделие")]
|
||||
public string SnackName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class ReportGroupOrdersViewModel
|
||||
{
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public int OrdersCount { get; set; }
|
||||
public double OrdersSum { get; set; }
|
||||
}
|
||||
}
|
17
AbstractShopContracts/ViewModels/ReportOrdersViewModel.cs
Normal file
17
AbstractShopContracts/ViewModels/ReportOrdersViewModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class ReportOrdersViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public string SnackName { get; set; } = string.Empty;
|
||||
public double Sum { get; set; }
|
||||
public string Status { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class ReportShopsViewModel
|
||||
{
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
public int TotalCount { get; set; }
|
||||
public List<(string Snack, int count)> Snacks { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class ReportSnackComponentViewModel
|
||||
{
|
||||
public string SnackName { get; set; } = string.Empty;
|
||||
public int TotalCount { get; set; }
|
||||
public List<(string Component, int Count)> Components { get; set; } = new();
|
||||
}
|
||||
}
|
24
AbstractShopContracts/ViewModels/ShopViewModel.cs
Normal file
24
AbstractShopContracts/ViewModels/ShopViewModel.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using DinerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class ShopViewModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название")]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
[DisplayName("Адрес")]
|
||||
public string Adress { get; set; } = string.Empty;
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
public Dictionary<int, (ISnackModel, int)> ShopSnacks { get; set; } = new();
|
||||
[DisplayName("Вместимость")]
|
||||
public int SnackMaxCount { get; set; }
|
||||
}
|
||||
}
|
16
AbstractShopContracts/ViewModels/SnackViewModel.cs
Normal file
16
AbstractShopContracts/ViewModels/SnackViewModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using DinerDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class SnackViewModel : ISnackModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название изделия")]
|
||||
public string SnackName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> SnackComponents { get; set; } = new();
|
||||
}
|
||||
|
||||
}
|
9
AbstractShopDataModels/DinerDataModels.csproj
Normal file
9
AbstractShopDataModels/DinerDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
11
AbstractShopDataModels/Enum/OrderStatus.cs
Normal file
11
AbstractShopDataModels/Enum/OrderStatus.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace DinerDataModels.Enum
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
Неизвестен = -1,
|
||||
Принят = 0,
|
||||
Выполняется = 1,
|
||||
Готов = 2,
|
||||
Выдан = 3
|
||||
}
|
||||
}
|
7
AbstractShopDataModels/IId.cs
Normal file
7
AbstractShopDataModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace DinerDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
8
AbstractShopDataModels/Models/IComponentModel.cs
Normal file
8
AbstractShopDataModels/Models/IComponentModel.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace DinerDataModels.Models
|
||||
{
|
||||
public interface IComponentModel : IId
|
||||
{
|
||||
string ComponentName { get; }
|
||||
double Cost { get; }
|
||||
}
|
||||
}
|
14
AbstractShopDataModels/Models/IOrderModel.cs
Normal file
14
AbstractShopDataModels/Models/IOrderModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using DinerDataModels.Enum;
|
||||
|
||||
namespace DinerDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int Id { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get;}
|
||||
}
|
||||
}
|
19
AbstractShopDataModels/Models/IShopModel.cs
Normal file
19
AbstractShopDataModels/Models/IShopModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using DinerDataModels;
|
||||
using DinerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerDataModels.Models
|
||||
{
|
||||
public interface IShopModel : IId
|
||||
{
|
||||
string ShopName { get; }
|
||||
string Adress { get; }
|
||||
DateTime OpeningDate { get; }
|
||||
Dictionary<int, (ISnackModel, int)> ShopSnacks { get; }
|
||||
public int SnackMaxCount { get; }
|
||||
}
|
||||
}
|
9
AbstractShopDataModels/Models/ISnackModel.cs
Normal file
9
AbstractShopDataModels/Models/ISnackModel.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace DinerDataModels.Models
|
||||
{
|
||||
public interface ISnackModel : IId
|
||||
{
|
||||
string SnackName { get; }
|
||||
double Price { get; }
|
||||
Dictionary<int, (IComponentModel, int)> SnackComponents { get; }
|
||||
}
|
||||
}
|
15
AbstractShopDataModels/Models/ISupplyModel.cs
Normal file
15
AbstractShopDataModels/Models/ISupplyModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerDataModels.Models
|
||||
{
|
||||
public interface ISupplyModel
|
||||
{
|
||||
int ShopId { get; }
|
||||
int SnackId { get; }
|
||||
int Count { get; }
|
||||
}
|
||||
}
|
33
Diner/AbstractShopListImplement/DataListSingleton.cs
Normal file
33
Diner/AbstractShopListImplement/DataListSingleton.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using DinerListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Snack> Products { get; set; }
|
||||
public List<Shop> Shops { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Products = new List<Snack>();
|
||||
Shops = new List<Shop>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DataListSingleton();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
14
Diner/AbstractShopListImplement/DinerListImplement.csproj
Normal file
14
Diner/AbstractShopListImplement/DinerListImplement.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="..\..\AbstractShopContracts\DinerContracts.csproj" />
|
||||
<ProjectReference Include="..\..\AbstractShopDataModels\DinerDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
102
Diner/AbstractShopListImplement/Implements/ComponentStorage.cs
Normal file
102
Diner/AbstractShopListImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
using DinerListImplement.Models;
|
||||
|
||||
namespace DinerListImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public ComponentStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ComponentViewModel>();
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
result.Add(component.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
var result = new List<ComponentViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if (component.ComponentName.Contains(model.ComponentName))
|
||||
{
|
||||
result.Add(component.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.ComponentName) &&
|
||||
component.ComponentName == model.ComponentName) ||
|
||||
(model.Id.HasValue && component.Id == model.Id))
|
||||
{
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if (model.Id <= component.Id)
|
||||
{
|
||||
model.Id = component.Id + 1;
|
||||
}
|
||||
}
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Components.Add(newComponent);
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if (component.Id == model.Id)
|
||||
{
|
||||
component.Update(model);
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Components.Count; ++i)
|
||||
{
|
||||
if (_source.Components[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Components[i];
|
||||
_source.Components.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
115
Diner/AbstractShopListImplement/Implements/OrderStorage.cs
Normal file
115
Diner/AbstractShopListImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
using DinerListImplement.Models;
|
||||
using DinerListImplement;
|
||||
|
||||
namespace DinerListImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public OrderStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
result.Add(AttachDinerName(order.GetViewModel));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
if (model == null || !model.Id.HasValue)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
result.Add(AttachDinerName(order.GetViewModel));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (model.Id.HasValue && order.Id == model.Id)
|
||||
{
|
||||
return AttachDinerName(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (model.Id <= order.Id)
|
||||
{
|
||||
model.Id = order.Id + 1;
|
||||
}
|
||||
}
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Orders.Add(newOrder);
|
||||
return AttachDinerName(newOrder.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
order.Update(model);
|
||||
return AttachDinerName(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Orders.Count; ++i)
|
||||
{
|
||||
if (_source.Orders[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Orders[i];
|
||||
_source.Orders.RemoveAt(i);
|
||||
return AttachDinerName(element.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private OrderViewModel AttachDinerName(OrderViewModel model)
|
||||
{
|
||||
foreach (var snack in _source.Products)
|
||||
{
|
||||
if (snack.Id == model.SnackId)
|
||||
{
|
||||
model.SnackName = snack.SnackName;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
122
Diner/AbstractShopListImplement/Implements/ShopStorage.cs
Normal file
122
Diner/AbstractShopListImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,122 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
using DinerListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerListImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public ShopStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ShopViewModel>();
|
||||
foreach (var shop in _source.Shops)
|
||||
{
|
||||
result.Add(shop.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
var result = new List<ShopViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var shop in _source.Shops)
|
||||
{
|
||||
if (shop.ShopName.Contains(model.ShopName))
|
||||
{
|
||||
result.Add(shop.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var shop in _source.Shops)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) ||
|
||||
(model.Id.HasValue && shop.Id == model.Id))
|
||||
{
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var shop in _source.Shops)
|
||||
{
|
||||
if (model.Id <= shop.Id)
|
||||
{
|
||||
model.Id = shop.Id + 1;
|
||||
}
|
||||
}
|
||||
var newShop = Shop.Create(model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Shops.Add(newShop);
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
foreach (var shop in _source.Shops)
|
||||
{
|
||||
if (shop.Id == model.Id)
|
||||
{
|
||||
shop.Update(model);
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Shops.Count; ++i)
|
||||
{
|
||||
if (_source.Shops[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Shops[i];
|
||||
_source.Shops.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public bool Sale(SupplySearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool RestockingShops(SupplyBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
104
Diner/AbstractShopListImplement/Implements/SnackStorage.cs
Normal file
104
Diner/AbstractShopListImplement/Implements/SnackStorage.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
using DinerListImplement.Models;
|
||||
|
||||
namespace DinerListImplement.Implements
|
||||
{
|
||||
public class SnackStorage : ISnackStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public SnackStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public SnackViewModel? Delete(SnackBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Products.Count; ++i)
|
||||
{
|
||||
if (_source.Products[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Products[i];
|
||||
_source.Products.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public SnackViewModel? GetElement(SnackSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SnackName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var product in _source.Products)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.SnackName) && product.SnackName == model.SnackName) || (model.Id.HasValue && product.Id == model.Id))
|
||||
{
|
||||
return product.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<SnackViewModel> GetFilteredList(SnackSearchModel model)
|
||||
{
|
||||
var result = new List<SnackViewModel>();
|
||||
if (string.IsNullOrEmpty(model.SnackName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var product in _source.Products)
|
||||
{
|
||||
if (product.SnackName.Contains(model.SnackName))
|
||||
{
|
||||
result.Add(product.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<SnackViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<SnackViewModel>();
|
||||
foreach (var product in _source.Products)
|
||||
{
|
||||
result.Add(product.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public SnackViewModel? Insert(SnackBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var product in _source.Products)
|
||||
{
|
||||
if (model.Id <= product.Id)
|
||||
{
|
||||
model.Id = product.Id + 1;
|
||||
}
|
||||
}
|
||||
var newProduct = Snack.Create(model);
|
||||
if (newProduct == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Products.Add(newProduct);
|
||||
return newProduct.GetViewModel;
|
||||
}
|
||||
|
||||
public SnackViewModel? Update(SnackBindingModel model)
|
||||
{
|
||||
foreach (var product in _source.Products)
|
||||
{
|
||||
if (product.Id == model.Id)
|
||||
{
|
||||
product.Update(model);
|
||||
return product.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
41
Diner/AbstractShopListImplement/Models/Component.cs
Normal file
41
Diner/AbstractShopListImplement/Models/Component.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.ViewModels;
|
||||
using DinerDataModels.Models;
|
||||
|
||||
namespace DinerListImplement.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 void Update(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
58
Diner/AbstractShopListImplement/Models/Order.cs
Normal file
58
Diner/AbstractShopListImplement/Models/Order.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.ViewModels;
|
||||
using DinerDataModels.Enum;
|
||||
using DinerDataModels.Models;
|
||||
|
||||
namespace DinerListImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string SnackName { get; private set; }
|
||||
public int SnackID { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; }
|
||||
public DateTime DateCreate { get; private set; }
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
SnackName = model.SnackName,
|
||||
SnackID = model.SnackId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement;
|
||||
if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SnackId = SnackID,
|
||||
SnackName = SnackName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
}
|
||||
}
|
59
Diner/AbstractShopListImplement/Models/Shop.cs
Normal file
59
Diner/AbstractShopListImplement/Models/Shop.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using DinerDataModels.Models;
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerListImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
public string Adress { get; private set; } = string.Empty;
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
public Dictionary<int, (ISnackModel, int)> ShopSnacks { get; private set; } = new();
|
||||
public int SnackMaxCount { get; private set; }
|
||||
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Adress = model.Adress,
|
||||
OpeningDate = model.OpeningDate,
|
||||
SnackMaxCount = model.SnackMaxCount,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShopName = model.ShopName;
|
||||
Adress = model.Adress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
SnackMaxCount = model.SnackMaxCount;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Adress = Adress,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopSnacks = ShopSnacks,
|
||||
SnackMaxCount = SnackMaxCount,
|
||||
};
|
||||
}
|
||||
}
|
49
Diner/AbstractShopListImplement/Models/Snack.cs
Normal file
49
Diner/AbstractShopListImplement/Models/Snack.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.ViewModels;
|
||||
using DinerDataModels.Models;
|
||||
|
||||
namespace DinerListImplement.Models
|
||||
{
|
||||
public class Snack : ISnackModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string SnackName { get; private set; } = string.Empty;
|
||||
public double Price { get; private set; }
|
||||
public Dictionary<int, (IComponentModel, int)> SnackComponents
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<int, (IComponentModel, int)>();
|
||||
public static Snack? Create(SnackBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Snack()
|
||||
{
|
||||
Id = model.Id,
|
||||
SnackName = model.SnackName,
|
||||
Price = model.Price,
|
||||
SnackComponents = model.SnackComponents
|
||||
};
|
||||
}
|
||||
public void Update(SnackBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SnackName = model.SnackName;
|
||||
Price = model.Price;
|
||||
SnackComponents = model.SnackComponents;
|
||||
}
|
||||
public SnackViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SnackName = SnackName,
|
||||
Price = Price,
|
||||
SnackComponents = SnackComponents
|
||||
};
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -1,9 +1,21 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32825.248
|
||||
VisualStudioVersion = 17.3.32819.101
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Diner", "Diner.csproj", "{23C9B122-7EEF-4651-88E0-1A0C4A5D342A}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerView", "Diner\DinerView.csproj", "{65DDF152-0786-40A2-8CAD-091C19000D84}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerDataModels", "..\AbstractShopDataModels\DinerDataModels.csproj", "{1AA0331A-FF61-4CA9-8273-51DF0A9ABBEC}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerContracts", "..\AbstractShopContracts\DinerContracts.csproj", "{86956F83-EF92-432E-B2DA-7E719873AC98}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerBusinessLogic", "..\AbstractShopBusinessLogic\DinerBusinessLogic.csproj", "{DDA6A507-23B7-4CB2-B5CF-3FBBB687D43C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerListImplement", "AbstractShopListImplement\DinerListImplement.csproj", "{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DinerFileImplement", "DinerFileImplement\DinerFileImplement.csproj", "{13294C1E-C8DF-4E4B-B645-A61900A797EB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DinerDatabaseImplement", "DinerDatabaseImplements\DinerDatabaseImplement.csproj", "{BE778091-B058-4BDD-8AEE-2773F4E00979}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -11,15 +23,39 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{23C9B122-7EEF-4651-88E0-1A0C4A5D342A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{23C9B122-7EEF-4651-88E0-1A0C4A5D342A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{23C9B122-7EEF-4651-88E0-1A0C4A5D342A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{23C9B122-7EEF-4651-88E0-1A0C4A5D342A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{65DDF152-0786-40A2-8CAD-091C19000D84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{65DDF152-0786-40A2-8CAD-091C19000D84}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{65DDF152-0786-40A2-8CAD-091C19000D84}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{65DDF152-0786-40A2-8CAD-091C19000D84}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1AA0331A-FF61-4CA9-8273-51DF0A9ABBEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1AA0331A-FF61-4CA9-8273-51DF0A9ABBEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1AA0331A-FF61-4CA9-8273-51DF0A9ABBEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1AA0331A-FF61-4CA9-8273-51DF0A9ABBEC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{86956F83-EF92-432E-B2DA-7E719873AC98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{86956F83-EF92-432E-B2DA-7E719873AC98}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{86956F83-EF92-432E-B2DA-7E719873AC98}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{86956F83-EF92-432E-B2DA-7E719873AC98}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DDA6A507-23B7-4CB2-B5CF-3FBBB687D43C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DDA6A507-23B7-4CB2-B5CF-3FBBB687D43C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DDA6A507-23B7-4CB2-B5CF-3FBBB687D43C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DDA6A507-23B7-4CB2-B5CF-3FBBB687D43C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{13294C1E-C8DF-4E4B-B645-A61900A797EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{13294C1E-C8DF-4E4B-B645-A61900A797EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{13294C1E-C8DF-4E4B-B645-A61900A797EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{13294C1E-C8DF-4E4B-B645-A61900A797EB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BE778091-B058-4BDD-8AEE-2773F4E00979}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BE778091-B058-4BDD-8AEE-2773F4E00979}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BE778091-B058-4BDD-8AEE-2773F4E00979}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BE778091-B058-4BDD-8AEE-2773F4E00979}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {5ED0C012-8FB3-4A50-B469-47606ADB8FC8}
|
||||
SolutionGuid = {78CA589A-698F-4822-A1DB-E616926BB9B3}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
49
Diner/Diner/DinerView.csproj
Normal file
49
Diner/Diner/DinerView.csproj
Normal file
@ -0,0 +1,49 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="FormSellSnack" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.14">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
|
||||
<PackageReference Include="ReportViewerCore.WinForms" Version="15.1.7" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\AbstractShopBusinessLogic\DinerBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\..\AbstractShopContracts\DinerContracts.csproj" />
|
||||
<ProjectReference Include="..\..\AbstractShopDataModels\DinerDataModels.csproj" />
|
||||
<ProjectReference Include="..\AbstractShopListImplement\DinerListImplement.csproj" />
|
||||
<ProjectReference Include="..\DinerDatabaseImplements\DinerDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\DinerFileImplement\DinerFileImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
119
Diner/Diner/FormComponent.Designer.cs
generated
Normal file
119
Diner/Diner/FormComponent.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace Diner
|
||||
{
|
||||
partial class FormComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.labelPrice = new System.Windows.Forms.Label();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.textBoxPrice = new System.Windows.Forms.TextBox();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(27, 26);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(80, 20);
|
||||
this.labelName.TabIndex = 0;
|
||||
this.labelName.Text = "Название:";
|
||||
//
|
||||
// labelPrice
|
||||
//
|
||||
this.labelPrice.AutoSize = true;
|
||||
this.labelPrice.Location = new System.Drawing.Point(27, 64);
|
||||
this.labelPrice.Name = "labelPrice";
|
||||
this.labelPrice.Size = new System.Drawing.Size(48, 20);
|
||||
this.labelPrice.TabIndex = 1;
|
||||
this.labelPrice.Text = "Цена:";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(113, 23);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(317, 27);
|
||||
this.textBoxName.TabIndex = 2;
|
||||
//
|
||||
// textBoxPrice
|
||||
//
|
||||
this.textBoxPrice.Location = new System.Drawing.Point(113, 61);
|
||||
this.textBoxPrice.Name = "textBoxPrice";
|
||||
this.textBoxPrice.Size = new System.Drawing.Size(172, 27);
|
||||
this.textBoxPrice.TabIndex = 3;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(224, 105);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonSave.TabIndex = 4;
|
||||
this.buttonSave.Text = "Создать";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(336, 105);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCancel.TabIndex = 5;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormComponent
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(470, 162);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxPrice);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.labelPrice);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Name = "FormComponent";
|
||||
this.Text = "Компонент";
|
||||
this.Load += new System.EventHandler(this.FormComponent_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelName;
|
||||
private Label labelPrice;
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxPrice;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
88
Diner/Diner/FormComponent.cs
Normal file
88
Diner/Diner/FormComponent.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using DinerContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualBasic.Logging;
|
||||
|
||||
namespace Diner
|
||||
{
|
||||
public partial class FormComponent : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentLogic _logic;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
public FormComponent(ILogger<FormComponent> logger, IComponentLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
private void FormComponent_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Ïîëó÷åíèå êîìïîíåíòà");
|
||||
var view = _logic.ReadElement(new ComponentSearchModel
|
||||
{
|
||||
Id =
|
||||
_id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.ComponentName;
|
||||
textBoxPrice.Text = view.Cost.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Îøèáêà ïîëó÷åíèÿ êîìïîíåíòà");
|
||||
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Çàïîëíèòå íàçâàíèå", "Îøèáêà",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Ñîõðàíåíèå êîìïîíåíòà");
|
||||
try
|
||||
{
|
||||
var model = new ComponentBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ComponentName = textBoxName.Text,
|
||||
Cost = Convert.ToDouble(textBoxPrice.Text)
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||
_logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Îøèáêà ïðè ñîõðàíåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
|
||||
}
|
||||
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî", "Ñîîáùåíèå",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Îøèáêà ñîõðàíåíèÿ êîìïîíåíòà");
|
||||
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
Diner/Diner/FormComponent.resx
Normal file
60
Diner/Diner/FormComponent.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
116
Diner/Diner/FormComponents.Designer.cs
generated
Normal file
116
Diner/Diner/FormComponents.Designer.cs
generated
Normal file
@ -0,0 +1,116 @@
|
||||
namespace Diner
|
||||
{
|
||||
partial class FormComponents
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonUpd = new System.Windows.Forms.Button();
|
||||
this.buttonDel = new System.Windows.Forms.Button();
|
||||
this.buttonRef = new System.Windows.Forms.Button();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(559, 31);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonAdd.TabIndex = 0;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// buttonUpd
|
||||
//
|
||||
this.buttonUpd.Location = new System.Drawing.Point(559, 84);
|
||||
this.buttonUpd.Name = "buttonUpd";
|
||||
this.buttonUpd.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonUpd.TabIndex = 1;
|
||||
this.buttonUpd.Text = "Изменить";
|
||||
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
this.buttonDel.Location = new System.Drawing.Point(559, 138);
|
||||
this.buttonDel.Name = "buttonDel";
|
||||
this.buttonDel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonDel.TabIndex = 2;
|
||||
this.buttonDel.Text = "Удалить";
|
||||
this.buttonDel.UseVisualStyleBackColor = true;
|
||||
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||
//
|
||||
// buttonRef
|
||||
//
|
||||
this.buttonRef.Location = new System.Drawing.Point(559, 189);
|
||||
this.buttonRef.Name = "buttonRef";
|
||||
this.buttonRef.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonRef.TabIndex = 3;
|
||||
this.buttonRef.Text = "Обновить";
|
||||
this.buttonRef.UseVisualStyleBackColor = true;
|
||||
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(0, 1);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.Size = new System.Drawing.Size(529, 442);
|
||||
this.dataGridView.TabIndex = 4;
|
||||
//
|
||||
// FormComponents
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(680, 450);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Controls.Add(this.buttonRef);
|
||||
this.Controls.Add(this.buttonDel);
|
||||
this.Controls.Add(this.buttonUpd);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Name = "FormComponents";
|
||||
this.Text = "Компоненты";
|
||||
this.Load += new System.EventHandler(this.FormComponents_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonAdd;
|
||||
private Button buttonUpd;
|
||||
private Button buttonDel;
|
||||
private Button buttonRef;
|
||||
private DataGridView dataGridView;
|
||||
}
|
||||
}
|
103
Diner/Diner/FormComponents.cs
Normal file
103
Diner/Diner/FormComponents.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Diner
|
||||
{
|
||||
public partial class FormComponents : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentLogic _logic;
|
||||
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
private void FormComponents_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Загрузка компонентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
form.Id =
|
||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id =
|
||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Удаление компонента");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ComponentBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonRef_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
60
Diner/Diner/FormComponents.resx
Normal file
60
Diner/Diner/FormComponents.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
144
Diner/Diner/FormCreateOrder.Designer.cs
generated
Normal file
144
Diner/Diner/FormCreateOrder.Designer.cs
generated
Normal file
@ -0,0 +1,144 @@
|
||||
namespace Diner
|
||||
{
|
||||
partial class FormCreateOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.labelProduct = new System.Windows.Forms.Label();
|
||||
this.labelCount = new System.Windows.Forms.Label();
|
||||
this.labelPrice = new System.Windows.Forms.Label();
|
||||
this.comboBoxProduct = new System.Windows.Forms.ComboBox();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.textBoxSum = new System.Windows.Forms.TextBox();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelProduct
|
||||
//
|
||||
this.labelProduct.AutoSize = true;
|
||||
this.labelProduct.Location = new System.Drawing.Point(47, 21);
|
||||
this.labelProduct.Name = "labelProduct";
|
||||
this.labelProduct.Size = new System.Drawing.Size(71, 20);
|
||||
this.labelProduct.TabIndex = 0;
|
||||
this.labelProduct.Text = "Изделие:";
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(47, 62);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(93, 20);
|
||||
this.labelCount.TabIndex = 1;
|
||||
this.labelCount.Text = "Количество:";
|
||||
//
|
||||
// labelPrice
|
||||
//
|
||||
this.labelPrice.AutoSize = true;
|
||||
this.labelPrice.Location = new System.Drawing.Point(47, 104);
|
||||
this.labelPrice.Name = "labelPrice";
|
||||
this.labelPrice.Size = new System.Drawing.Size(58, 20);
|
||||
this.labelPrice.TabIndex = 2;
|
||||
this.labelPrice.Text = "Сумма:";
|
||||
//
|
||||
// comboBoxProduct
|
||||
//
|
||||
this.comboBoxProduct.FormattingEnabled = true;
|
||||
this.comboBoxProduct.Location = new System.Drawing.Point(149, 18);
|
||||
this.comboBoxProduct.Name = "comboBoxProduct";
|
||||
this.comboBoxProduct.Size = new System.Drawing.Size(246, 28);
|
||||
this.comboBoxProduct.TabIndex = 3;
|
||||
this.comboBoxProduct.SelectedIndexChanged += new System.EventHandler(this.ComboBoxProduct_SelectedIndexChanged);
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(149, 59);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(246, 27);
|
||||
this.textBoxCount.TabIndex = 4;
|
||||
this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
|
||||
//
|
||||
// textBoxSum
|
||||
//
|
||||
this.textBoxSum.Location = new System.Drawing.Point(149, 101);
|
||||
this.textBoxSum.Name = "textBoxSum";
|
||||
this.textBoxSum.Size = new System.Drawing.Size(246, 27);
|
||||
this.textBoxSum.TabIndex = 5;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(178, 153);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonSave.TabIndex = 6;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(301, 153);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormCreateOrder
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(420, 205);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxSum);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.comboBoxProduct);
|
||||
this.Controls.Add(this.labelPrice);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Controls.Add(this.labelProduct);
|
||||
this.Name = "FormCreateOrder";
|
||||
this.Text = "Заказ";
|
||||
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelProduct;
|
||||
private Label labelCount;
|
||||
private Label labelPrice;
|
||||
private ComboBox comboBoxProduct;
|
||||
private TextBox textBoxCount;
|
||||
private TextBox textBoxSum;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
119
Diner/Diner/FormCreateOrder.cs
Normal file
119
Diner/Diner/FormCreateOrder.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using DinerContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Data;
|
||||
|
||||
namespace Diner
|
||||
{
|
||||
public partial class FormCreateOrder : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISnackLogic _logicP;
|
||||
private readonly IOrderLogic _logicO;
|
||||
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISnackLogic logicP, IOrderLogic logicO)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicP = logicP;
|
||||
_logicO = logicO;
|
||||
}
|
||||
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Загрузка изделий для заказа");
|
||||
try
|
||||
{
|
||||
var list = _logicP.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxProduct.DisplayMember = "Snack";
|
||||
comboBoxProduct.ValueMember = "Id";
|
||||
comboBoxProduct.DataSource = list.Select(c => c.SnackName).ToList();
|
||||
comboBoxProduct.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка изделий");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void CalcSum()
|
||||
{
|
||||
if (comboBoxProduct.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = Convert.ToInt32(comboBoxProduct.SelectedIndex + 1);
|
||||
var product = _logicP.ReadElement(new SnackSearchModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
int count = Convert.ToInt32(textBoxCount.Text);
|
||||
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
|
||||
_logger.LogInformation("Расчет суммы заказа");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void TextBoxCount_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
CalcSum();
|
||||
}
|
||||
private void ComboBoxProduct_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
CalcSum();
|
||||
}
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxProduct.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Создание заказа");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||
{
|
||||
SnackId = Convert.ToInt32(comboBoxProduct.SelectedIndex + 1),
|
||||
SnackName = comboBoxProduct.SelectedValue.ToString(),
|
||||
Count = Convert.ToInt32(textBoxCount.Text),
|
||||
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
|
||||
}
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
Diner/Diner/FormCreateOrder.resx
Normal file
60
Diner/Diner/FormCreateOrder.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
142
Diner/Diner/FormCreateSupply.Designer.cs
generated
Normal file
142
Diner/Diner/FormCreateSupply.Designer.cs
generated
Normal file
@ -0,0 +1,142 @@
|
||||
namespace Diner
|
||||
{
|
||||
partial class FormCreateSupply
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
comboBoxShop = new ComboBox();
|
||||
labelShop = new Label();
|
||||
labelPizza = new Label();
|
||||
comboBoxSnack = new ComboBox();
|
||||
labelCount = new Label();
|
||||
textBoxCount = new TextBox();
|
||||
buttonCancel = new Button();
|
||||
buttonSave = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBoxShop
|
||||
//
|
||||
comboBoxShop.FormattingEnabled = true;
|
||||
comboBoxShop.Location = new Point(115, 12);
|
||||
comboBoxShop.Name = "comboBoxShop";
|
||||
comboBoxShop.Size = new Size(344, 28);
|
||||
comboBoxShop.TabIndex = 0;
|
||||
//
|
||||
// labelShop
|
||||
//
|
||||
labelShop.AutoSize = true;
|
||||
labelShop.Location = new Point(12, 15);
|
||||
labelShop.Name = "labelShop";
|
||||
labelShop.Size = new Size(76, 20);
|
||||
labelShop.TabIndex = 1;
|
||||
labelShop.Text = "Магазин: ";
|
||||
//
|
||||
// labelPizza
|
||||
//
|
||||
labelPizza.AutoSize = true;
|
||||
labelPizza.Location = new Point(12, 49);
|
||||
labelPizza.Name = "labelPizza";
|
||||
labelPizza.Size = new Size(75, 20);
|
||||
labelPizza.TabIndex = 2;
|
||||
labelPizza.Text = "Изделие: ";
|
||||
//
|
||||
// comboBoxSnack
|
||||
//
|
||||
comboBoxSnack.FormattingEnabled = true;
|
||||
comboBoxSnack.Location = new Point(115, 46);
|
||||
comboBoxSnack.Name = "comboBoxSnack";
|
||||
comboBoxSnack.Size = new Size(344, 28);
|
||||
comboBoxSnack.TabIndex = 3;
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(12, 83);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(97, 20);
|
||||
labelCount.TabIndex = 4;
|
||||
labelCount.Text = "Количество: ";
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
textBoxCount.Location = new Point(115, 80);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(344, 27);
|
||||
textBoxCount.TabIndex = 5;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(300, 113);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(116, 39);
|
||||
buttonCancel.TabIndex = 6;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(168, 113);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(116, 39);
|
||||
buttonSave.TabIndex = 7;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// FormCreateSupply
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(471, 164);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(comboBoxSnack);
|
||||
Controls.Add(labelPizza);
|
||||
Controls.Add(labelShop);
|
||||
Controls.Add(comboBoxShop);
|
||||
Name = "FormCreateSupply";
|
||||
Text = "Создание поставки";
|
||||
Load += FormCreateSupply_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxShop;
|
||||
private Label labelShop;
|
||||
private Label labelPizza;
|
||||
private ComboBox comboBoxSnack;
|
||||
private Label labelCount;
|
||||
private TextBox textBoxCount;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
}
|
||||
}
|
99
Diner/Diner/FormCreateSupply.cs
Normal file
99
Diner/Diner/FormCreateSupply.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections;
|
||||
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;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace Diner
|
||||
{
|
||||
public partial class FormCreateSupply : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISnackLogic _logicP;
|
||||
private readonly IShopLogic _logicS;
|
||||
private List<ShopViewModel> _shopList = new List<ShopViewModel>();
|
||||
private List<SnackViewModel> _snackList = new List<SnackViewModel>();
|
||||
|
||||
public FormCreateSupply(ILogger<FormCreateSupply> logger, ISnackLogic logicP, IShopLogic logicS)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicP = logicP;
|
||||
_logicS = logicS;
|
||||
}
|
||||
|
||||
private void FormCreateSupply_Load(object sender, EventArgs e)
|
||||
{
|
||||
_shopList = _logicS.ReadList(null);
|
||||
_snackList = _logicP.ReadList(null);
|
||||
if (_shopList != null)
|
||||
{
|
||||
comboBoxShop.DisplayMember = "ShopName";
|
||||
comboBoxShop.ValueMember = "Id";
|
||||
comboBoxShop.DataSource = _shopList;
|
||||
comboBoxShop.SelectedItem = null;
|
||||
_logger.LogInformation("Загрузка магазинов для поставок");
|
||||
}
|
||||
if (_snackList != null)
|
||||
{
|
||||
comboBoxSnack.DisplayMember = "SnackName";
|
||||
comboBoxSnack.ValueMember = "Id";
|
||||
comboBoxSnack.DataSource = _snackList;
|
||||
comboBoxSnack.SelectedItem = null;
|
||||
_logger.LogInformation("Загрузка закуски для поставок");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxShop.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxSnack.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите закуску", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Создание поставки");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicS.MakeSupply(new SupplyBindingModel
|
||||
{
|
||||
ShopId = Convert.ToInt32(comboBoxShop.SelectedValue),
|
||||
SnackId = Convert.ToInt32(comboBoxSnack.SelectedValue),
|
||||
Count = 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
Diner/Diner/FormCreateSupply.resx
Normal file
120
Diner/Diner/FormCreateSupply.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>
|
304
Diner/Diner/FormMain.Designer.cs
generated
Normal file
304
Diner/Diner/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,304 @@
|
||||
namespace Diner
|
||||
{
|
||||
partial class FormMain
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain));
|
||||
dataGridView = new DataGridView();
|
||||
buttonCreateOrder = new Button();
|
||||
buttonTakeOrderInWork = new Button();
|
||||
buttonOrderReady = new Button();
|
||||
buttonIssuedOrder = new Button();
|
||||
buttonRef = new Button();
|
||||
toolStrip1 = new ToolStrip();
|
||||
toolStripLabel1 = new ToolStripDropDownButton();
|
||||
componentsToolStripMenuItem = new ToolStripMenuItem();
|
||||
snacksToolStripMenuItem = new ToolStripMenuItem();
|
||||
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||
toolStripDropDownButton1 = new ToolStripDropDownButton();
|
||||
поставкаToolStripMenuItem = new ToolStripMenuItem();
|
||||
SellToolStripMenuItem = new ToolStripMenuItem();
|
||||
отчётыToolStripMenuItem = new ToolStripDropDownButton();
|
||||
изделияToolStripMenuItem = new ToolStripMenuItem();
|
||||
списокИзделийToolStripMenuItem = new ToolStripMenuItem();
|
||||
закускаСИнгридентамиToolStripMenuItem = new ToolStripMenuItem();
|
||||
магазинToolStripMenuItem = new ToolStripMenuItem();
|
||||
информацияToolStripMenuItem = new ToolStripMenuItem();
|
||||
загруженностьToolStripMenuItem = new ToolStripMenuItem();
|
||||
заказыToolStripMenuItem = new ToolStripMenuItem();
|
||||
заказыToolStripMenuItem1 = new ToolStripMenuItem();
|
||||
заказыПоГруппамToolStripMenuItem = new ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
toolStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(0, 27);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(986, 421);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonCreateOrder
|
||||
//
|
||||
buttonCreateOrder.Location = new Point(1040, 88);
|
||||
buttonCreateOrder.Name = "buttonCreateOrder";
|
||||
buttonCreateOrder.Size = new Size(202, 29);
|
||||
buttonCreateOrder.TabIndex = 1;
|
||||
buttonCreateOrder.Text = "Создать заказ";
|
||||
buttonCreateOrder.UseVisualStyleBackColor = true;
|
||||
buttonCreateOrder.Click += ButtonCreateOrder_Click;
|
||||
//
|
||||
// buttonTakeOrderInWork
|
||||
//
|
||||
buttonTakeOrderInWork.Location = new Point(1040, 136);
|
||||
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
||||
buttonTakeOrderInWork.Size = new Size(202, 29);
|
||||
buttonTakeOrderInWork.TabIndex = 2;
|
||||
buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
||||
buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
|
||||
//
|
||||
// buttonOrderReady
|
||||
//
|
||||
buttonOrderReady.Location = new Point(1040, 184);
|
||||
buttonOrderReady.Name = "buttonOrderReady";
|
||||
buttonOrderReady.Size = new Size(202, 29);
|
||||
buttonOrderReady.TabIndex = 3;
|
||||
buttonOrderReady.Text = "Заказ готов";
|
||||
buttonOrderReady.UseVisualStyleBackColor = true;
|
||||
buttonOrderReady.Click += ButtonOrderReady_Click;
|
||||
//
|
||||
// buttonIssuedOrder
|
||||
//
|
||||
buttonIssuedOrder.Location = new Point(1040, 237);
|
||||
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
||||
buttonIssuedOrder.Size = new Size(202, 29);
|
||||
buttonIssuedOrder.TabIndex = 4;
|
||||
buttonIssuedOrder.Text = "Заказ выдан";
|
||||
buttonIssuedOrder.UseVisualStyleBackColor = true;
|
||||
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
|
||||
//
|
||||
// buttonRef
|
||||
//
|
||||
buttonRef.Location = new Point(1040, 287);
|
||||
buttonRef.Name = "buttonRef";
|
||||
buttonRef.Size = new Size(202, 29);
|
||||
buttonRef.TabIndex = 5;
|
||||
buttonRef.Text = "Обновить список";
|
||||
buttonRef.UseVisualStyleBackColor = true;
|
||||
buttonRef.Click += ButtonRef_Click;
|
||||
//
|
||||
// toolStrip1
|
||||
//
|
||||
toolStrip1.ImageScalingSize = new Size(20, 20);
|
||||
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripLabel1, toolStripDropDownButton1, отчётыToolStripMenuItem });
|
||||
toolStrip1.Location = new Point(0, 0);
|
||||
toolStrip1.Name = "toolStrip1";
|
||||
toolStrip1.Size = new Size(1280, 27);
|
||||
toolStrip1.TabIndex = 6;
|
||||
toolStrip1.Text = "toolStrip1";
|
||||
//
|
||||
// toolStripLabel1
|
||||
//
|
||||
toolStripLabel1.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, snacksToolStripMenuItem, магазиныToolStripMenuItem });
|
||||
toolStripLabel1.Name = "toolStripLabel1";
|
||||
toolStripLabel1.Size = new Size(117, 24);
|
||||
toolStripLabel1.Text = "Справочники";
|
||||
//
|
||||
// componentsToolStripMenuItem
|
||||
//
|
||||
componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
|
||||
componentsToolStripMenuItem.Size = new Size(182, 26);
|
||||
componentsToolStripMenuItem.Text = "Компоненты";
|
||||
componentsToolStripMenuItem.Click += ComponentToolStripMenuItem_Click;
|
||||
//
|
||||
// snacksToolStripMenuItem
|
||||
//
|
||||
snacksToolStripMenuItem.Name = "snacksToolStripMenuItem";
|
||||
snacksToolStripMenuItem.Size = new Size(182, 26);
|
||||
snacksToolStripMenuItem.Text = "Закуски";
|
||||
snacksToolStripMenuItem.Click += ProductToolStripMenuItem_Click;
|
||||
//
|
||||
// магазиныToolStripMenuItem
|
||||
//
|
||||
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||
магазиныToolStripMenuItem.Size = new Size(182, 26);
|
||||
магазиныToolStripMenuItem.Text = "Магазины";
|
||||
магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click;
|
||||
//
|
||||
// toolStripDropDownButton1
|
||||
//
|
||||
toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text;
|
||||
toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem, SellToolStripMenuItem });
|
||||
toolStripDropDownButton1.ImageTransparentColor = Color.Magenta;
|
||||
toolStripDropDownButton1.Name = "toolStripDropDownButton1";
|
||||
toolStripDropDownButton1.Size = new Size(95, 24);
|
||||
toolStripDropDownButton1.Text = "Операции";
|
||||
//
|
||||
// поставкаToolStripMenuItem
|
||||
//
|
||||
поставкаToolStripMenuItem.Name = "поставкаToolStripMenuItem";
|
||||
поставкаToolStripMenuItem.Size = new Size(156, 26);
|
||||
поставкаToolStripMenuItem.Text = "Поставка";
|
||||
поставкаToolStripMenuItem.Click += transactionToolStripMenuItem_Click;
|
||||
//
|
||||
// SellToolStripMenuItem
|
||||
//
|
||||
SellToolStripMenuItem.Name = "SellToolStripMenuItem";
|
||||
SellToolStripMenuItem.Size = new Size(156, 26);
|
||||
SellToolStripMenuItem.Text = "Продажа";
|
||||
SellToolStripMenuItem.Click += SellToolStripMenuItem_Click;
|
||||
//
|
||||
// отчётыToolStripMenuItem
|
||||
//
|
||||
отчётыToolStripMenuItem.DisplayStyle = ToolStripItemDisplayStyle.Text;
|
||||
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { изделияToolStripMenuItem, магазинToolStripMenuItem, заказыToolStripMenuItem });
|
||||
отчётыToolStripMenuItem.Image = (Image)resources.GetObject("отчётыToolStripMenuItem.Image");
|
||||
отчётыToolStripMenuItem.ImageTransparentColor = Color.Magenta;
|
||||
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
|
||||
отчётыToolStripMenuItem.Size = new Size(73, 24);
|
||||
отчётыToolStripMenuItem.Text = "Отчёты";
|
||||
//
|
||||
// изделияToolStripMenuItem
|
||||
//
|
||||
изделияToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокИзделийToolStripMenuItem, закускаСИнгридентамиToolStripMenuItem });
|
||||
изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
|
||||
изделияToolStripMenuItem.Size = new Size(224, 26);
|
||||
изделияToolStripMenuItem.Text = "Закуска";
|
||||
//
|
||||
// списокИзделийToolStripMenuItem
|
||||
//
|
||||
списокИзделийToolStripMenuItem.Name = "списокИзделийToolStripMenuItem";
|
||||
списокИзделийToolStripMenuItem.Size = new Size(260, 26);
|
||||
списокИзделийToolStripMenuItem.Text = "Список закусок";
|
||||
списокИзделийToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
|
||||
//
|
||||
// закускаСИнгридентамиToolStripMenuItem
|
||||
//
|
||||
закускаСИнгридентамиToolStripMenuItem.Name = "закускаСИнгридентамиToolStripMenuItem";
|
||||
закускаСИнгридентамиToolStripMenuItem.Size = new Size(260, 26);
|
||||
закускаСИнгридентамиToolStripMenuItem.Text = "Закуска с ингридентами";
|
||||
закускаСИнгридентамиToolStripMenuItem.Click += ComponentSnackToolStripMenuItem_Click;
|
||||
//
|
||||
// магазинToolStripMenuItem
|
||||
//
|
||||
магазинToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { информацияToolStripMenuItem, загруженностьToolStripMenuItem });
|
||||
магазинToolStripMenuItem.Name = "магазинToolStripMenuItem";
|
||||
магазинToolStripMenuItem.Size = new Size(224, 26);
|
||||
магазинToolStripMenuItem.Text = "Магазин";
|
||||
//
|
||||
// информацияToolStripMenuItem
|
||||
//
|
||||
информацияToolStripMenuItem.Name = "информацияToolStripMenuItem";
|
||||
информацияToolStripMenuItem.Size = new Size(224, 26);
|
||||
информацияToolStripMenuItem.Text = "Информация";
|
||||
информацияToolStripMenuItem.Click += InfoToolStripMenuItem_Click;
|
||||
//
|
||||
// загруженностьToolStripMenuItem
|
||||
//
|
||||
загруженностьToolStripMenuItem.Name = "загруженностьToolStripMenuItem";
|
||||
загруженностьToolStripMenuItem.Size = new Size(224, 26);
|
||||
загруженностьToolStripMenuItem.Text = "Загруженность";
|
||||
загруженностьToolStripMenuItem.Click += BusyShopsToolStripMenuItem_Click;
|
||||
//
|
||||
// заказыToolStripMenuItem
|
||||
//
|
||||
заказыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заказыToolStripMenuItem1, заказыПоГруппамToolStripMenuItem });
|
||||
заказыToolStripMenuItem.Name = "заказыToolStripMenuItem";
|
||||
заказыToolStripMenuItem.Size = new Size(224, 26);
|
||||
заказыToolStripMenuItem.Text = "Заказы";
|
||||
//
|
||||
// заказыToolStripMenuItem1
|
||||
//
|
||||
заказыToolStripMenuItem1.Name = "заказыToolStripMenuItem1";
|
||||
заказыToolStripMenuItem1.Size = new Size(226, 26);
|
||||
заказыToolStripMenuItem1.Text = "Заказы";
|
||||
заказыToolStripMenuItem1.Click += OrdersToolStripMenuItem_Click;
|
||||
//
|
||||
// заказыПоГруппамToolStripMenuItem
|
||||
//
|
||||
заказыПоГруппамToolStripMenuItem.Name = "заказыПоГруппамToolStripMenuItem";
|
||||
заказыПоГруппамToolStripMenuItem.Size = new Size(226, 26);
|
||||
заказыПоГруппамToolStripMenuItem.Text = "Заказы по группам";
|
||||
заказыПоГруппамToolStripMenuItem.Click += GroupOrdersToolStripMenuItem_Click;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1280, 450);
|
||||
Controls.Add(toolStrip1);
|
||||
Controls.Add(buttonRef);
|
||||
Controls.Add(buttonIssuedOrder);
|
||||
Controls.Add(buttonOrderReady);
|
||||
Controls.Add(buttonTakeOrderInWork);
|
||||
Controls.Add(buttonCreateOrder);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormMain";
|
||||
Text = "Закусочная";
|
||||
Load += FormMain_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
toolStrip1.ResumeLayout(false);
|
||||
toolStrip1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonCreateOrder;
|
||||
private Button buttonTakeOrderInWork;
|
||||
private Button buttonOrderReady;
|
||||
private Button buttonIssuedOrder;
|
||||
private Button buttonRef;
|
||||
private ToolStrip toolStrip1;
|
||||
private ToolStripDropDownButton toolStripLabel1;
|
||||
private ToolStripMenuItem componentsToolStripMenuItem;
|
||||
private ToolStripMenuItem snacksToolStripMenuItem;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private ToolStripDropDownButton toolStripDropDownButton1;
|
||||
private ToolStripMenuItem поставкаToolStripMenuItem;
|
||||
private ToolStripMenuItem SellToolStripMenuItem;
|
||||
private ToolStripDropDownButton отчётыToolStripMenuItem;
|
||||
private ToolStripMenuItem изделияToolStripMenuItem;
|
||||
private ToolStripMenuItem списокИзделийToolStripMenuItem;
|
||||
private ToolStripMenuItem закускаСИнгридентамиToolStripMenuItem;
|
||||
private ToolStripMenuItem магазинToolStripMenuItem;
|
||||
private ToolStripMenuItem информацияToolStripMenuItem;
|
||||
private ToolStripMenuItem загруженностьToolStripMenuItem;
|
||||
private ToolStripMenuItem заказыToolStripMenuItem;
|
||||
private ToolStripMenuItem заказыToolStripMenuItem1;
|
||||
private ToolStripMenuItem заказыПоГруппамToolStripMenuItem;
|
||||
}
|
||||
}
|
230
Diner/Diner/FormMain.cs
Normal file
230
Diner/Diner/FormMain.cs
Normal file
@ -0,0 +1,230 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using DinerDataModels.Enum;
|
||||
using DinerView;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DinerBusinessLogic.BusinessLogics;
|
||||
|
||||
namespace Diner
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
private readonly IReportLogic _reportLogic;
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
_reportLogic = reportLogic;
|
||||
}
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
// прописать логику
|
||||
try
|
||||
{
|
||||
var list = _orderLogic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка заказов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ComponentToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||
if (service is FormComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void ProductToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSnacks));
|
||||
if (service is FormSnacks form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
if (service is FormCreateOrder form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonOrderReady_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_reportLogic.SaveSnacksToWordFile(new ReportBindingModel { FileName = dialog.FileName });
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
|
||||
private void ComponentSnackToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportSnackComponents));
|
||||
if (service is FormReportSnackComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
|
||||
if (service is FormReportOrders form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
_logger.LogInformation("Заказ No{id} выдан", id);
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonRef_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
private void shopsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||
if (service is FormShops form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void transactionToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply));
|
||||
if (service is FormCreateSupply form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void SellToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSellSnack));
|
||||
if (service is FormSellSnack form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void InfoToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName });
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
|
||||
private void BusyShopsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportShop));
|
||||
if (service is FormReportShop form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void GroupOrdersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders));
|
||||
if (service is FormReportGroupedOrders form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
135
Diner/Diner/FormMain.resx
Normal file
135
Diner/Diner/FormMain.resx
Normal file
@ -0,0 +1,135 @@
|
||||
<?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>
|
||||
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="отчётыToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||
YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEKSURBVEhL3ZG9DsFQHMXvczDZvIOtXsHObuhqkViI3Quw
|
||||
6CYmNoMYJJ0NBiFFIoIytOuf0+TeXP3yde+iyS+3OcP53Z4y3/dJJ4HAsiwyTVMp6BQCBIZhKAWdEcHV
|
||||
vSlBmeB82NFy1KLluEWOPRC5MoHdMWhazwi4RJlALgf4EuT6BI+5kCsTrGddUY658E+QvyXYHq9UnRyC
|
||||
U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T
|
||||
luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM
|
||||
qgAAAABJRU5ErkJggg==
|
||||
</value>
|
||||
</data>
|
||||
</root>
|
86
Diner/Diner/FormReportGroupedOrders.Designer.cs
generated
Normal file
86
Diner/Diner/FormReportGroupedOrders.Designer.cs
generated
Normal file
@ -0,0 +1,86 @@
|
||||
namespace Diner
|
||||
{
|
||||
partial class FormReportGroupedOrders
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.panel = new System.Windows.Forms.Panel();
|
||||
this.buttonToPDF = new System.Windows.Forms.Button();
|
||||
this.buttonMake = new System.Windows.Forms.Button();
|
||||
this.panel.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel
|
||||
//
|
||||
this.panel.Controls.Add(this.buttonToPDF);
|
||||
this.panel.Controls.Add(this.buttonMake);
|
||||
this.panel.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.panel.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel.Name = "panel";
|
||||
this.panel.Size = new System.Drawing.Size(970, 52);
|
||||
this.panel.TabIndex = 1;
|
||||
//
|
||||
// buttonToPDF
|
||||
//
|
||||
this.buttonToPDF.Location = new System.Drawing.Point(486, 12);
|
||||
this.buttonToPDF.Name = "buttonToPDF";
|
||||
this.buttonToPDF.Size = new System.Drawing.Size(411, 29);
|
||||
this.buttonToPDF.TabIndex = 5;
|
||||
this.buttonToPDF.Text = "В PDF";
|
||||
this.buttonToPDF.UseVisualStyleBackColor = true;
|
||||
this.buttonToPDF.Click += new System.EventHandler(this.buttonToPDF_Click);
|
||||
//
|
||||
// buttonMake
|
||||
//
|
||||
this.buttonMake.Location = new System.Drawing.Point(49, 12);
|
||||
this.buttonMake.Name = "buttonMake";
|
||||
this.buttonMake.Size = new System.Drawing.Size(377, 29);
|
||||
this.buttonMake.TabIndex = 4;
|
||||
this.buttonMake.Text = "Сформировать";
|
||||
this.buttonMake.UseVisualStyleBackColor = true;
|
||||
this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click);
|
||||
//
|
||||
// FormReportGroupedOrders
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(970, 450);
|
||||
this.Controls.Add(this.panel);
|
||||
this.Name = "FormReportGroupedOrders";
|
||||
this.Text = "Отчёт по группированным заказам ";
|
||||
this.panel.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel panel;
|
||||
private Button buttonToPDF;
|
||||
private Button buttonMake;
|
||||
}
|
||||
}
|
78
Diner/Diner/FormReportGroupedOrders.cs
Normal file
78
Diner/Diner/FormReportGroupedOrders.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Reporting.WinForms;
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
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 Diner
|
||||
{
|
||||
public partial class FormReportGroupedOrders : Form
|
||||
{
|
||||
private readonly ReportViewer reportViewer;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IReportLogic _logic;
|
||||
|
||||
public FormReportGroupedOrders(ILogger<FormReportGroupedOrders> logger, IReportLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
reportViewer = new ReportViewer
|
||||
{
|
||||
Dock = DockStyle.Fill
|
||||
};
|
||||
reportViewer.LocalReport.LoadReportDefinition(new FileStream("C:\\Users\\ogoro\\source\\repos\\PIbd_23_Kislitsa_E.D_Diner\\Diner\\Diner\\ReportGroupedOrders.rdlc", FileMode.Open));
|
||||
Controls.Clear();
|
||||
Controls.Add(reportViewer);
|
||||
Controls.Add(panel);
|
||||
}
|
||||
private void ButtonMake_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dataSource = _logic.GetGroupedOrders();
|
||||
var source = new ReportDataSource("DataSetGroupedOrders", dataSource);
|
||||
reportViewer.LocalReport.DataSources.Clear();
|
||||
reportViewer.LocalReport.DataSources.Add(source);
|
||||
|
||||
reportViewer.RefreshReport();
|
||||
_logger.LogInformation("Загрузка списка группированных заказов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка группированных заказов на период");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonToPDF_Click(object sender, EventArgs e)
|
||||
{
|
||||
using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" };
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.SaveGroupedOrdersToPdfFile(new ReportBindingModel
|
||||
{
|
||||
FileName = dialog.FileName,
|
||||
});
|
||||
_logger.LogInformation("Сохранение списка группированных заказов");
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения списка группированных заказов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
Diner/Diner/FormReportGroupedOrders.resx
Normal file
60
Diner/Diner/FormReportGroupedOrders.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
131
Diner/Diner/FormReportOrders.Designer.cs
generated
Normal file
131
Diner/Diner/FormReportOrders.Designer.cs
generated
Normal file
@ -0,0 +1,131 @@
|
||||
namespace Diner
|
||||
{
|
||||
partial class FormReportOrders
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.panel = new System.Windows.Forms.Panel();
|
||||
this.labelFrom = new System.Windows.Forms.Label();
|
||||
this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker();
|
||||
this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker();
|
||||
this.labelTo = new System.Windows.Forms.Label();
|
||||
this.buttonMake = new System.Windows.Forms.Button();
|
||||
this.buttonToPDF = new System.Windows.Forms.Button();
|
||||
this.panel.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel
|
||||
//
|
||||
this.panel.Controls.Add(this.buttonToPDF);
|
||||
this.panel.Controls.Add(this.buttonMake);
|
||||
this.panel.Controls.Add(this.dateTimePickerTo);
|
||||
this.panel.Controls.Add(this.labelTo);
|
||||
this.panel.Controls.Add(this.dateTimePickerFrom);
|
||||
this.panel.Controls.Add(this.labelFrom);
|
||||
this.panel.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.panel.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel.Name = "panel";
|
||||
this.panel.Size = new System.Drawing.Size(958, 52);
|
||||
this.panel.TabIndex = 0;
|
||||
//
|
||||
// labelFrom
|
||||
//
|
||||
this.labelFrom.AutoSize = true;
|
||||
this.labelFrom.Location = new System.Drawing.Point(12, 14);
|
||||
this.labelFrom.Name = "labelFrom";
|
||||
this.labelFrom.Size = new System.Drawing.Size(18, 20);
|
||||
this.labelFrom.TabIndex = 0;
|
||||
this.labelFrom.Text = "C";
|
||||
//
|
||||
// dateTimePickerFrom
|
||||
//
|
||||
this.dateTimePickerFrom.Location = new System.Drawing.Point(36, 9);
|
||||
this.dateTimePickerFrom.Name = "dateTimePickerFrom";
|
||||
this.dateTimePickerFrom.Size = new System.Drawing.Size(199, 27);
|
||||
this.dateTimePickerFrom.TabIndex = 1;
|
||||
//
|
||||
// dateTimePickerTo
|
||||
//
|
||||
this.dateTimePickerTo.Location = new System.Drawing.Point(300, 9);
|
||||
this.dateTimePickerTo.Name = "dateTimePickerTo";
|
||||
this.dateTimePickerTo.Size = new System.Drawing.Size(199, 27);
|
||||
this.dateTimePickerTo.TabIndex = 3;
|
||||
//
|
||||
// labelTo
|
||||
//
|
||||
this.labelTo.AutoSize = true;
|
||||
this.labelTo.Location = new System.Drawing.Point(254, 14);
|
||||
this.labelTo.Name = "labelTo";
|
||||
this.labelTo.Size = new System.Drawing.Size(27, 20);
|
||||
this.labelTo.TabIndex = 2;
|
||||
this.labelTo.Text = "по";
|
||||
//
|
||||
// buttonMake
|
||||
//
|
||||
this.buttonMake.Location = new System.Drawing.Point(542, 10);
|
||||
this.buttonMake.Name = "buttonMake";
|
||||
this.buttonMake.Size = new System.Drawing.Size(165, 29);
|
||||
this.buttonMake.TabIndex = 4;
|
||||
this.buttonMake.Text = "Сформировать";
|
||||
this.buttonMake.UseVisualStyleBackColor = true;
|
||||
this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click);
|
||||
//
|
||||
// buttonToPDF
|
||||
//
|
||||
this.buttonToPDF.Location = new System.Drawing.Point(781, 9);
|
||||
this.buttonToPDF.Name = "buttonToPDF";
|
||||
this.buttonToPDF.Size = new System.Drawing.Size(165, 29);
|
||||
this.buttonToPDF.TabIndex = 5;
|
||||
this.buttonToPDF.Text = "В PDF";
|
||||
this.buttonToPDF.UseVisualStyleBackColor = true;
|
||||
this.buttonToPDF.Click += new System.EventHandler(this.ButtonToPdf_Click);
|
||||
//
|
||||
// FormReportOrders
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(958, 450);
|
||||
this.Controls.Add(this.panel);
|
||||
this.Name = "FormReportOrders";
|
||||
this.Text = "Заказы";
|
||||
this.panel.ResumeLayout(false);
|
||||
this.panel.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel panel;
|
||||
private Button buttonToPDF;
|
||||
private Button buttonMake;
|
||||
private DateTimePicker dateTimePickerTo;
|
||||
private Label labelTo;
|
||||
private DateTimePicker dateTimePickerFrom;
|
||||
private Label labelFrom;
|
||||
}
|
||||
}
|
96
Diner/Diner/FormReportOrders.cs
Normal file
96
Diner/Diner/FormReportOrders.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Reporting.WinForms;
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
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 Diner
|
||||
{
|
||||
public partial class FormReportOrders : Form
|
||||
{
|
||||
private readonly ReportViewer reportViewer;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IReportLogic _logic;
|
||||
|
||||
public FormReportOrders(ILogger<FormReportOrders> logger, IReportLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
reportViewer = new ReportViewer
|
||||
{
|
||||
Dock = DockStyle.Fill
|
||||
};
|
||||
reportViewer.LocalReport.LoadReportDefinition(new FileStream("C:\\Users\\ogoro\\source\\repos\\PIbd_23_Kislitsa_E.D_Diner\\Diner\\Diner\\ReportOrder.rdlc", FileMode.Open));
|
||||
Controls.Clear();
|
||||
Controls.Add(reportViewer);
|
||||
Controls.Add(panel);
|
||||
}
|
||||
private void ButtonMake_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
|
||||
{
|
||||
MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var dataSource = _logic.GetOrders(new ReportBindingModel
|
||||
{
|
||||
DateFrom = dateTimePickerFrom.Value,
|
||||
DateTo = dateTimePickerTo.Value
|
||||
});
|
||||
var source = new ReportDataSource("DataSetOrders", dataSource);
|
||||
reportViewer.LocalReport.DataSources.Clear();
|
||||
reportViewer.LocalReport.DataSources.Add(source);
|
||||
var parameters = new[] { new ReportParameter("ReportParameterPeriod",
|
||||
$"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") };
|
||||
reportViewer.LocalReport.SetParameters(parameters);
|
||||
|
||||
reportViewer.RefreshReport();
|
||||
_logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка заказов на период");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonToPdf_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
|
||||
{
|
||||
MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" };
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.SaveOrdersToPdfFile(new ReportBindingModel
|
||||
{
|
||||
FileName = dialog.FileName,
|
||||
DateFrom = dateTimePickerFrom.Value,
|
||||
DateTo = dateTimePickerTo.Value
|
||||
});
|
||||
_logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString());
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения списка заказов на период");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
Diner/Diner/FormReportOrders.resx
Normal file
60
Diner/Diner/FormReportOrders.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user