cлияние веточек деревца
This commit is contained in:
commit
1834aabc65
@ -11,24 +11,25 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SushiBarBusinessLogic
|
namespace SushiBarBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
public class ReportLogic : IReportLogic
|
public class ReportLogic : IReportLogic
|
||||||
{
|
{
|
||||||
private readonly IComponentStorage _componentStorage;
|
private readonly IComponentStorage _componentStorage;
|
||||||
private readonly ISushiStorage _SushiStorage;
|
private readonly ISushiStorage _SushiStorage;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
private readonly IShopStorage _shopStorage;
|
||||||
private readonly AbstractSaveToExcel _saveToExcel;
|
private readonly AbstractSaveToExcel _saveToExcel;
|
||||||
private readonly AbstractSaveToWord _saveToWord;
|
private readonly AbstractSaveToWord _saveToWord;
|
||||||
private readonly AbstractSaveToPdf _saveToPdf;
|
private readonly AbstractSaveToPdf _saveToPdf;
|
||||||
|
|
||||||
public ReportLogic(ISushiStorage SushiStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
|
public ReportLogic(ISushiStorage SushiStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage,
|
||||||
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||||
{
|
{
|
||||||
_SushiStorage = SushiStorage;
|
_SushiStorage = SushiStorage;
|
||||||
_componentStorage = componentStorage;
|
_componentStorage = componentStorage;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
_saveToExcel = saveToExcel;
|
_saveToExcel = saveToExcel;
|
||||||
_saveToWord = saveToWord;
|
_saveToWord = saveToWord;
|
||||||
_saveToPdf = saveToPdf;
|
_saveToPdf = saveToPdf;
|
||||||
@ -89,5 +90,55 @@ namespace SushiBarBusinessLogic
|
|||||||
Orders = GetOrders(model)
|
Orders = GetOrders(model)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ReportShopsViewModel> GetShops()
|
||||||
|
{
|
||||||
|
return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel
|
||||||
|
{
|
||||||
|
ShopName = x.ShopName,
|
||||||
|
Sushis = x.ShopSushis.Select(x => (x.Value.Item1.SushiName, x.Value.Item2)).ToList(),
|
||||||
|
TotalCount = x.ShopSushis.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.CreateShopSushisReport(new ExcelShop
|
||||||
|
{
|
||||||
|
FileName = model.FileName,
|
||||||
|
Title = "Наполненость магазинов",
|
||||||
|
ShopSushis = GetShops()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveGroupedOrdersToPdfFile(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
_saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo
|
||||||
|
{
|
||||||
|
FileName = model.FileName,
|
||||||
|
Title = "Список заказов сгруппированных по дате заказов",
|
||||||
|
GroupedOrders = GetGroupedOrders()
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
186
SushiBar/SushiBarBusinessLogic_/BusinessLogics/ShopLogic.cs
Normal file
186
SushiBar/SushiBarBusinessLogic_/BusinessLogics/ShopLogic.cs
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace SushiBarBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ShopLogic : IShopLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopStorage _shopStorage;
|
||||||
|
private readonly ISushiStorage _sushiStorage;
|
||||||
|
|
||||||
|
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage, ISushiStorage sushiStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
|
_sushiStorage = sushiStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.ShopSushis.ContainsKey(model.SushiId))
|
||||||
|
{
|
||||||
|
var oldValue = shop.ShopSushis[model.SushiId];
|
||||||
|
oldValue.Item2 += model.Count;
|
||||||
|
shop.ShopSushis[model.SushiId] = oldValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var sushi = _sushiStorage.GetElement(new SushiSearchModel
|
||||||
|
{
|
||||||
|
Id = model.SushiId
|
||||||
|
});
|
||||||
|
if (sushi == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Поставка: Товар с id:{model.SushiId} не найденн");
|
||||||
|
}
|
||||||
|
shop.ShopSushis.Add(model.SushiId, (sushi, model.Count));
|
||||||
|
}
|
||||||
|
|
||||||
|
_shopStorage.Update(new ShopBindingModel()
|
||||||
|
{
|
||||||
|
Id = shop.Id,
|
||||||
|
ShopName = shop.ShopName,
|
||||||
|
Adress = shop.Adress,
|
||||||
|
OpeningDate = shop.OpeningDate,
|
||||||
|
ShopSushis = shop.ShopSushis,
|
||||||
|
SushiMaxCount = shop.SushiMaxCount,
|
||||||
|
});
|
||||||
|
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.SushiId.HasValue || !model.Count.HasValue)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Check sushi count in all shops");
|
||||||
|
if (_shopStorage.Sale(model))
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Selling sucsess");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Selling failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -92,11 +92,11 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.SushiName))
|
if (string.IsNullOrEmpty(model.SushiName))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Нет названия пиццы", nameof(model.SushiName));
|
throw new ArgumentNullException("Нет названия суши", nameof(model.SushiName));
|
||||||
}
|
}
|
||||||
if (model.Price <= 0)
|
if (model.Price <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Цена пиццы должна быть больше 0", nameof(model.Price));
|
throw new ArgumentNullException("Цена суши должна быть больше 0", nameof(model.Price));
|
||||||
}
|
}
|
||||||
if (model.SushiComponents == null || model.SushiComponents.Count == 0)
|
if (model.SushiComponents == null || model.SushiComponents.Count == 0)
|
||||||
{
|
{
|
||||||
@ -109,7 +109,7 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
});
|
});
|
||||||
if (element != null && element.Id != model.Id)
|
if (element != null && element.Id != model.Id)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Пицца с таким названием уже есть");
|
throw new InvalidOperationException("Суши с таким названием уже есть");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -83,7 +83,51 @@ namespace SushiBarBusinessLogic.MailWorker
|
|||||||
_messageInfoLogic.Create(mail);
|
_messageInfoLogic.Create(mail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
|
||||||
|
public async void MailSendReplyAsync(MailReplySendInfoBindingModel info)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text) || string.IsNullOrEmpty(info.ParentMessageId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogDebug("Send Mail as reply: {To}, {Subject}, {parentId}", info.MailAddress, info.Subject, info.ParentMessageId);
|
||||||
|
|
||||||
|
string? messageId = await SendMailAsync(info);
|
||||||
|
if (string.IsNullOrEmpty(messageId))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Непредвиденная ошибка при отправке сообщения в ответ");
|
||||||
|
}
|
||||||
|
if (_messageInfoLogic.Create(new MessageInfoBindingModel
|
||||||
|
{
|
||||||
|
MessageId = messageId,
|
||||||
|
DateDelivery = DateTime.Now,
|
||||||
|
SenderName = _mailLogin,
|
||||||
|
IsReply = true,
|
||||||
|
Subject = info.Subject,
|
||||||
|
Body = info.Text,
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
_messageInfoLogic.Update(new MessageInfoBindingModel()
|
||||||
|
{
|
||||||
|
MessageId = info.ParentMessageId,
|
||||||
|
ReplyMessageId = messageId,
|
||||||
|
IsReaded = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Task<string?> SendMailAsync(MailSendInfoBindingModel info);
|
||||||
protected abstract Task<List<MessageInfoBindingModel>> ReceiveMailAsync();
|
protected abstract Task<List<MessageInfoBindingModel>> ReceiveMailAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,24 +17,25 @@ namespace SushiBarBusinessLogic.MailWorker
|
|||||||
{
|
{
|
||||||
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic) : base(logger, messageInfoLogic) { }
|
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic) : base(logger, messageInfoLogic) { }
|
||||||
|
|
||||||
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
protected override async Task<string?> SendMailAsync(MailSendInfoBindingModel info)
|
||||||
{
|
{
|
||||||
|
string? resount = null;
|
||||||
using var objMailMessage = new MailMessage();
|
using var objMailMessage = new MailMessage();
|
||||||
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
objMailMessage.From = new MailAddress(_mailLogin);
|
ConfigurateSmtpClient(objSmtpClient);
|
||||||
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
CreateMessage(objMailMessage, info);
|
||||||
objMailMessage.Subject = info.Subject;
|
|
||||||
objMailMessage.Body = info.Text;
|
|
||||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
|
||||||
objMailMessage.BodyEncoding = Encoding.UTF8;
|
|
||||||
|
|
||||||
|
if (info is MailReplySendInfoBindingModel replyInfo)
|
||||||
|
{
|
||||||
|
objMailMessage.Headers.Add("In-Reply-To", replyInfo.ParentMessageId);
|
||||||
|
objMailMessage.Headers.Add("References", replyInfo.ParentMessageId);
|
||||||
|
|
||||||
objSmtpClient.UseDefaultCredentials = false;
|
string messageGuid = Guid.NewGuid().ToString();
|
||||||
objSmtpClient.EnableSsl = true;
|
objMailMessage.Headers.Add("Message-Id", messageGuid);
|
||||||
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
resount = messageGuid;
|
||||||
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
}
|
||||||
|
|
||||||
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
||||||
}
|
}
|
||||||
@ -42,6 +43,7 @@ namespace SushiBarBusinessLogic.MailWorker
|
|||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
return resount;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<List<MessageInfoBindingModel>> ReceiveMailAsync()
|
protected override async Task<List<MessageInfoBindingModel>> ReceiveMailAsync()
|
||||||
@ -79,5 +81,24 @@ namespace SushiBarBusinessLogic.MailWorker
|
|||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CreateMessage(MailMessage objMailMessage, MailSendInfoBindingModel info)
|
||||||
|
{
|
||||||
|
objMailMessage.From = new MailAddress(_mailLogin);
|
||||||
|
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
||||||
|
objMailMessage.Subject = info.Subject;
|
||||||
|
objMailMessage.Body = info.Text;
|
||||||
|
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||||
|
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigurateSmtpClient(SmtpClient objSmtpClient)
|
||||||
|
{
|
||||||
|
|
||||||
|
objSmtpClient.UseDefaultCredentials = false;
|
||||||
|
objSmtpClient.EnableSsl = true;
|
||||||
|
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||||
|
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -28,8 +28,12 @@ namespace SushiBarBusinessLogic
|
|||||||
}
|
}
|
||||||
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId}", model?.MessageId, model?.ClientId);
|
if (model == null)
|
||||||
var list = model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId}.PageLength:{PageLength}.PageCount:{PageIndex}", model?.MessageId, model?.ClientId, model?.PageLength, model?.PageIndex);
|
||||||
|
var list = _messageInfoStorage.GetFilteredList(model);
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadList return null list");
|
_logger.LogWarning("ReadList return null list");
|
||||||
@ -41,7 +45,8 @@ namespace SushiBarBusinessLogic
|
|||||||
public bool Create(MessageInfoBindingModel model)
|
public bool Create(MessageInfoBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
if (_messageInfoStorage.Insert(model) == null)
|
var message = _messageInfoStorage.Insert(model);
|
||||||
|
if (message == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
@ -54,27 +59,26 @@ namespace SushiBarBusinessLogic
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
if (!withParams)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(model.MessageId))
|
if (string.IsNullOrEmpty(model.MessageId))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Не указан id сообщения", nameof(model.MessageId));
|
throw new ArgumentNullException("Не указан id сообщения", nameof(model.MessageId));
|
||||||
}
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (string.IsNullOrEmpty(model.SenderName))
|
if (string.IsNullOrEmpty(model.SenderName))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Не указао почта", nameof(model.SenderName));
|
throw new ArgumentNullException("Не указао имя отправителя(электронная почта)", nameof(model.SenderName));
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.Subject))
|
if (string.IsNullOrEmpty(model.Subject))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Не указана тема", nameof(model.Subject));
|
throw new ArgumentNullException("Не указана темма", nameof(model.Subject));
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.Body))
|
if (string.IsNullOrEmpty(model.Body))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Не указан текст сообщения", nameof(model.Subject));
|
throw new ArgumentNullException("Не указан текст сообщения", nameof(model.Subject));
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("MessageInfo. MessageId:{MessageId}.SenderName:{SenderName}.Subject:{Subject}.Body:{Body}", model.MessageId, model.SenderName, model.Subject, model.Body);
|
_logger.LogInformation("MessageInfo. MessageId:{MessageId}.SenderName:{SenderName}.Subject:{Subject}.Body:{Body}", model.MessageId, model.SenderName, model.Subject, model.Body);
|
||||||
var element = _clientStorage.GetElement(new ClientSearchModel
|
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||||
{
|
{
|
||||||
@ -89,5 +93,33 @@ namespace SushiBarBusinessLogic
|
|||||||
model.ClientId = element.Id;
|
model.ClientId = element.Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessageInfoViewModel? ReadElement(MessageInfoSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. MessageId:{MessageId}", model?.MessageId);
|
||||||
|
var element = _messageInfoStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.MessageId);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, withParams: false);
|
||||||
|
if (_messageInfoStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,6 +13,7 @@ namespace SushiBarBusinessLogic.OfficePackage
|
|||||||
public void CreateReport(ExcelInfo info)
|
public void CreateReport(ExcelInfo info)
|
||||||
{
|
{
|
||||||
CreateExcel(info);
|
CreateExcel(info);
|
||||||
|
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
{
|
{
|
||||||
ColumnName = "A",
|
ColumnName = "A",
|
||||||
@ -20,40 +21,46 @@ namespace SushiBarBusinessLogic.OfficePackage
|
|||||||
Text = info.Title,
|
Text = info.Title,
|
||||||
StyleInfo = ExcelStyleInfoType.Title
|
StyleInfo = ExcelStyleInfoType.Title
|
||||||
});
|
});
|
||||||
|
|
||||||
MergeCells(new ExcelMergeParameters
|
MergeCells(new ExcelMergeParameters
|
||||||
{
|
{
|
||||||
CellFromName = "A1",
|
CellFromName = "A1",
|
||||||
CellToName = "C1"
|
CellToName = "C1"
|
||||||
});
|
});
|
||||||
|
|
||||||
uint rowIndex = 2;
|
uint rowIndex = 2;
|
||||||
foreach (var sc in info.SushiComponents)
|
foreach (var pc in info.SushiComponents)
|
||||||
{
|
{
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
{
|
{
|
||||||
ColumnName = "A",
|
ColumnName = "A",
|
||||||
RowIndex = rowIndex,
|
RowIndex = rowIndex,
|
||||||
Text = sc.SushiName,
|
Text = pc.SushiName,
|
||||||
StyleInfo = ExcelStyleInfoType.Text
|
StyleInfo = ExcelStyleInfoType.Text
|
||||||
});
|
});
|
||||||
rowIndex++;
|
rowIndex++;
|
||||||
foreach (var component in sc.Components)
|
|
||||||
|
foreach (var (Component, Count) in pc.Components)
|
||||||
{
|
{
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
{
|
{
|
||||||
ColumnName = "B",
|
ColumnName = "B",
|
||||||
RowIndex = rowIndex,
|
RowIndex = rowIndex,
|
||||||
Text = component.Item1,
|
Text = Component,
|
||||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||||
});
|
});
|
||||||
|
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
{
|
{
|
||||||
ColumnName = "C",
|
ColumnName = "C",
|
||||||
RowIndex = rowIndex,
|
RowIndex = rowIndex,
|
||||||
Text = component.Item2.ToString(),
|
Text = Count.ToString(),
|
||||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||||
});
|
});
|
||||||
|
|
||||||
rowIndex++;
|
rowIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
{
|
{
|
||||||
ColumnName = "A",
|
ColumnName = "A",
|
||||||
@ -65,33 +72,90 @@ namespace SushiBarBusinessLogic.OfficePackage
|
|||||||
{
|
{
|
||||||
ColumnName = "C",
|
ColumnName = "C",
|
||||||
RowIndex = rowIndex,
|
RowIndex = rowIndex,
|
||||||
Text = sc.TotalCount.ToString(),
|
Text = pc.TotalCount.ToString(),
|
||||||
StyleInfo = ExcelStyleInfoType.Text
|
StyleInfo = ExcelStyleInfoType.Text
|
||||||
});
|
});
|
||||||
rowIndex++;
|
rowIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveExcel(info);
|
SaveExcel(info);
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Создание excel-файла
|
public void CreateShopSushisReport(ExcelShop info)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="info"></param>
|
CreateExcel(info);
|
||||||
protected abstract void CreateExcel(ExcelInfo info);
|
|
||||||
/// <summary>
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
/// Добавляем новую ячейку в лист
|
{
|
||||||
/// </summary>
|
ColumnName = "A",
|
||||||
/// <param name="cellParameters"></param>
|
RowIndex = 1,
|
||||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters
|
Text = info.Title,
|
||||||
excelParams);
|
StyleInfo = ExcelStyleInfoType.Title
|
||||||
/// <summary>
|
});
|
||||||
/// Объединение ячеек
|
|
||||||
/// </summary>
|
MergeCells(new ExcelMergeParameters
|
||||||
/// <param name="mergeParameters"></param>
|
{
|
||||||
|
CellFromName = "A1",
|
||||||
|
CellToName = "C1"
|
||||||
|
});
|
||||||
|
|
||||||
|
uint rowIndex = 2;
|
||||||
|
foreach (var sr in info.ShopSushis)
|
||||||
|
{
|
||||||
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
|
{
|
||||||
|
ColumnName = "A",
|
||||||
|
RowIndex = rowIndex,
|
||||||
|
Text = sr.ShopName,
|
||||||
|
StyleInfo = ExcelStyleInfoType.Text
|
||||||
|
});
|
||||||
|
rowIndex++;
|
||||||
|
|
||||||
|
foreach (var (Sushi, Count) in sr.Sushis)
|
||||||
|
{
|
||||||
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
|
{
|
||||||
|
ColumnName = "B",
|
||||||
|
RowIndex = rowIndex,
|
||||||
|
Text = Sushi,
|
||||||
|
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 MergeCells(ExcelMergeParameters excelParams);
|
||||||
/// <summary>
|
protected abstract void SaveExcel(IDocument info);
|
||||||
/// Сохранение файла
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="info"></param>
|
|
||||||
protected abstract void SaveExcel(ExcelInfo info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,67 +13,65 @@ namespace SushiBarBusinessLogic.OfficePackage
|
|||||||
public void CreateDoc(PdfInfo info)
|
public void CreateDoc(PdfInfo info)
|
||||||
{
|
{
|
||||||
CreatePdf(info);
|
CreatePdf(info);
|
||||||
CreateParagraph(new PdfParagraph
|
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 });
|
||||||
Text = info.Title,
|
|
||||||
Style = "NormalTitle",
|
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
|
||||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|
||||||
});
|
|
||||||
CreateParagraph(new PdfParagraph
|
|
||||||
{
|
|
||||||
Text = $"с { info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style = "Normal",
|
|
||||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|
||||||
});
|
|
||||||
CreateTable(new List<string> { "1cm", "3cm", "4cm", "6cm", "3cm" });
|
|
||||||
CreateRow(new PdfRowParameters
|
CreateRow(new PdfRowParameters
|
||||||
{
|
{
|
||||||
Texts = new List<string> { "Номер", "Дата заказа", "Статус", "Изделие", "Сумма" },
|
Texts = new List<string> { "Номер", "Дата заказа", "Пицца", "Статус", "Сумма" },
|
||||||
Style = "NormalTitle",
|
Style = "NormalTitle",
|
||||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (var order in info.Orders)
|
foreach (var order in info.Orders)
|
||||||
{
|
{
|
||||||
CreateRow(new PdfRowParameters
|
CreateRow(new PdfRowParameters
|
||||||
{
|
{
|
||||||
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.Status.ToString(), order.SushiName, order.Sum.ToString() },
|
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.SushiName, order.Status.ToString(), order.Sum.ToString() },
|
||||||
Style = "Normal",
|
Style = "Normal",
|
||||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
CreateParagraph(new PdfParagraph
|
CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth });
|
||||||
{
|
|
||||||
Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t",
|
|
||||||
Style = "Normal",
|
|
||||||
ParagraphAlignment = PdfParagraphAlignmentType.Rigth
|
|
||||||
});
|
|
||||||
SavePdf(info);
|
SavePdf(info);
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Создание doc-файла
|
public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo info)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="info"></param>
|
CreatePdf(info);
|
||||||
protected abstract void CreatePdf(PdfInfo info);
|
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||||
/// <summary>
|
|
||||||
/// Создание параграфа с текстом
|
CreateTable(new List<string> { "4cm", "3cm", "2cm" });
|
||||||
/// </summary>
|
CreateRow(new PdfRowParameters
|
||||||
/// <param name="title"></param>
|
{
|
||||||
/// <param name="style"></param>
|
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 CreateParagraph(PdfParagraph paragraph);
|
||||||
/// <summary>
|
|
||||||
/// Создание таблицы
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="title"></param>
|
|
||||||
/// <param name="style"></param>
|
|
||||||
protected abstract void CreateTable(List<string> columns);
|
protected abstract void CreateTable(List<string> columns);
|
||||||
/// <summary>
|
|
||||||
/// Создание и заполнение строки
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="rowParameters"></param>
|
|
||||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||||
/// <summary>
|
protected abstract void SavePdf(IDocument info);
|
||||||
/// Сохранение файла
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="info"></param>
|
|
||||||
protected abstract void SavePdf(PdfInfo info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,21 +38,52 @@ namespace SushiBarBusinessLogic.OfficePackage
|
|||||||
}
|
}
|
||||||
SaveWord(info);
|
SaveWord(info);
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Создание doc-файла
|
public void CreateShopsDoc(WordShopInfo info)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="info"></param>
|
CreateWord(info);
|
||||||
protected abstract void CreateWord(WordInfo info);
|
CreateParagraph(new WordParagraph
|
||||||
/// <summary>
|
{
|
||||||
/// Создание абзаца с текстом
|
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
|
||||||
/// </summary>
|
TextProperties = new WordTextProperties
|
||||||
/// <param name="paragraph"></param>
|
{
|
||||||
/// <returns></returns>
|
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 CreateParagraph(WordParagraph paragraph);
|
||||||
/// <summary>
|
protected abstract void SaveWord(IDocument info);
|
||||||
/// Сохранение файла
|
protected abstract void CreateTable(List<string> colums);
|
||||||
/// </summary>
|
protected abstract void CreateRow(WordRowParameters rowParameters);
|
||||||
/// <param name="info"></param>
|
|
||||||
protected abstract void SaveWord(WordInfo info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
|
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
|
||||||
{
|
{
|
||||||
public class ExcelInfo
|
public class ExcelInfo : IDocument
|
||||||
{
|
{
|
||||||
public string FileName { get; set; } = string.Empty;
|
public string FileName { get; set; } = string.Empty;
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
public class ExcelShop : IDocument
|
||||||
|
{
|
||||||
|
public string FileName { get; set; } = string.Empty;
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public List<ReportShopsViewModel> ShopSushis { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
|
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
|
||||||
{
|
{
|
||||||
public class PdfInfo
|
public class PdfInfo : IDocument
|
||||||
{
|
{
|
||||||
public string FileName { get; set; } = string.Empty;
|
public string FileName { get; set; } = string.Empty;
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
|
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
|
||||||
{
|
{
|
||||||
public class WordInfo
|
public class WordInfo : IDocument
|
||||||
{
|
{
|
||||||
public string FileName { get; set; } = string.Empty;
|
public string FileName { get; set; } = string.Empty;
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
public class WordRowParameters
|
||||||
|
{
|
||||||
|
public List<string> Texts { get; set; } = new();
|
||||||
|
public WordTextProperties TextProperties { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
14
SushiBar/SushiBarBusinessLogic_/OfficePackage/IDocument.cs
Normal file
14
SushiBar/SushiBarBusinessLogic_/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 SushiBarBusinessLogic.OfficePackage
|
||||||
|
{
|
||||||
|
public interface IDocument
|
||||||
|
{
|
||||||
|
public string FileName { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -14,167 +14,110 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
private SpreadsheetDocument? _spreadsheetDocument;
|
private SpreadsheetDocument? _spreadsheetDocument;
|
||||||
private SharedStringTablePart? _shareStringPart;
|
private SharedStringTablePart? _shareStringPart;
|
||||||
private Worksheet? _worksheet;
|
private Worksheet? _worksheet;
|
||||||
/// <summary>
|
|
||||||
/// Настройка стилей для файла
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="workbookpart"></param>
|
|
||||||
private static void CreateStyles(WorkbookPart workbookpart)
|
private static void CreateStyles(WorkbookPart workbookpart)
|
||||||
{
|
{
|
||||||
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
||||||
sp.Stylesheet = new Stylesheet();
|
sp.Stylesheet = new Stylesheet();
|
||||||
|
|
||||||
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
|
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
|
||||||
|
|
||||||
var fontUsual = new Font();
|
var fontUsual = new Font();
|
||||||
fontUsual.Append(new FontSize() { Val = 12D });
|
fontUsual.Append(new FontSize() { Val = 12D });
|
||||||
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
|
||||||
{ Theme = 1U });
|
|
||||||
fontUsual.Append(new FontName() { Val = "Times New Roman" });
|
fontUsual.Append(new FontName() { Val = "Times New Roman" });
|
||||||
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
|
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
|
||||||
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||||
|
|
||||||
var fontTitle = new Font();
|
var fontTitle = new Font();
|
||||||
fontTitle.Append(new Bold());
|
fontTitle.Append(new Bold());
|
||||||
fontTitle.Append(new FontSize() { Val = 14D });
|
fontTitle.Append(new FontSize() { Val = 14D });
|
||||||
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
|
||||||
{ Theme = 1U });
|
|
||||||
fontTitle.Append(new FontName() { Val = "Times New Roman" });
|
fontTitle.Append(new FontName() { Val = "Times New Roman" });
|
||||||
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
|
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
|
||||||
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||||
|
|
||||||
fonts.Append(fontUsual);
|
fonts.Append(fontUsual);
|
||||||
fonts.Append(fontTitle);
|
fonts.Append(fontTitle);
|
||||||
|
|
||||||
var fills = new Fills() { Count = 2U };
|
var fills = new Fills() { Count = 2U };
|
||||||
|
|
||||||
var fill1 = new Fill();
|
var fill1 = new Fill();
|
||||||
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
||||||
|
|
||||||
var fill2 = new Fill();
|
var fill2 = new Fill();
|
||||||
fill2.Append(new PatternFill()
|
fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 });
|
||||||
{
|
|
||||||
PatternType = PatternValues.Gray125
|
|
||||||
});
|
|
||||||
fills.Append(fill1);
|
fills.Append(fill1);
|
||||||
fills.Append(fill2);
|
fills.Append(fill2);
|
||||||
|
|
||||||
var borders = new Borders() { Count = 2U };
|
var borders = new Borders() { Count = 2U };
|
||||||
|
|
||||||
var borderNoBorder = new Border();
|
var borderNoBorder = new Border();
|
||||||
borderNoBorder.Append(new LeftBorder());
|
borderNoBorder.Append(new LeftBorder());
|
||||||
borderNoBorder.Append(new RightBorder());
|
borderNoBorder.Append(new RightBorder());
|
||||||
borderNoBorder.Append(new TopBorder());
|
borderNoBorder.Append(new TopBorder());
|
||||||
borderNoBorder.Append(new BottomBorder());
|
borderNoBorder.Append(new BottomBorder());
|
||||||
borderNoBorder.Append(new DiagonalBorder());
|
borderNoBorder.Append(new DiagonalBorder());
|
||||||
|
|
||||||
var borderThin = new Border();
|
var borderThin = new Border();
|
||||||
|
|
||||||
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
||||||
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||||
{ Indexed = 64U });
|
|
||||||
var rightBorder = new RightBorder()
|
var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin };
|
||||||
{
|
rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||||
Style = BorderStyleValues.Thin
|
|
||||||
};
|
|
||||||
rightBorder.Append(new
|
|
||||||
DocumentFormat.OpenXml.Office2010.Excel.Color()
|
|
||||||
{ Indexed = 64U });
|
|
||||||
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
|
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
|
||||||
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
|
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||||
{ Indexed = 64U });
|
|
||||||
var bottomBorder = new BottomBorder()
|
var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin };
|
||||||
{
|
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||||
Style =
|
|
||||||
BorderStyleValues.Thin
|
|
||||||
};
|
|
||||||
bottomBorder.Append(new
|
|
||||||
DocumentFormat.OpenXml.Office2010.Excel.Color()
|
|
||||||
{ Indexed = 64U });
|
|
||||||
borderThin.Append(leftBorder);
|
borderThin.Append(leftBorder);
|
||||||
borderThin.Append(rightBorder);
|
borderThin.Append(rightBorder);
|
||||||
borderThin.Append(topBorder);
|
borderThin.Append(topBorder);
|
||||||
borderThin.Append(bottomBorder);
|
borderThin.Append(bottomBorder);
|
||||||
borderThin.Append(new DiagonalBorder());
|
borderThin.Append(new DiagonalBorder());
|
||||||
|
|
||||||
borders.Append(borderNoBorder);
|
borders.Append(borderNoBorder);
|
||||||
borders.Append(borderThin);
|
borders.Append(borderThin);
|
||||||
|
|
||||||
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
|
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
|
||||||
var cellFormatStyle = new CellFormat()
|
var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U };
|
||||||
{
|
|
||||||
NumberFormatId = 0U,
|
|
||||||
FontId
|
|
||||||
= 0U,
|
|
||||||
FillId = 0U,
|
|
||||||
BorderId = 0U
|
|
||||||
};
|
|
||||||
cellStyleFormats.Append(cellFormatStyle);
|
cellStyleFormats.Append(cellFormatStyle);
|
||||||
|
|
||||||
var cellFormats = new CellFormats() { Count = 3U };
|
var cellFormats = new CellFormats() { Count = 3U };
|
||||||
var cellFormatFont = new CellFormat()
|
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 };
|
||||||
NumberFormatId = 0U,
|
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 };
|
||||||
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(cellFormatFont);
|
||||||
cellFormats.Append(cellFormatFontAndBorder);
|
cellFormats.Append(cellFormatFontAndBorder);
|
||||||
cellFormats.Append(cellFormatTitle);
|
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()
|
var cellStyles = new CellStyles() { Count = 1U };
|
||||||
{
|
|
||||||
Count = 0U,
|
cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U });
|
||||||
DefaultTableStyle = "TableStyleMedium2",
|
|
||||||
DefaultPivotStyle = "PivotStyleLight16"
|
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 stylesheetExtensionList = new StylesheetExtensionList();
|
||||||
var stylesheetExtension1 = new StylesheetExtension()
|
|
||||||
{
|
var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" };
|
||||||
Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
|
|
||||||
};
|
|
||||||
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
|
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
|
||||||
stylesheetExtension1.Append(new SlicerStyles()
|
stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" });
|
||||||
{
|
|
||||||
DefaultSlicerStyle = "SlicerStyleLight1"
|
var stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" };
|
||||||
});
|
|
||||||
var stylesheetExtension2 = new StylesheetExtension()
|
|
||||||
{
|
|
||||||
Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}"
|
|
||||||
};
|
|
||||||
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
|
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
|
||||||
stylesheetExtension2.Append(new TimelineStyles()
|
stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" });
|
||||||
{
|
|
||||||
DefaultTimelineStyle = "TimeSlicerStyleLight1"
|
|
||||||
});
|
|
||||||
stylesheetExtensionList.Append(stylesheetExtension1);
|
stylesheetExtensionList.Append(stylesheetExtension1);
|
||||||
stylesheetExtensionList.Append(stylesheetExtension2);
|
stylesheetExtensionList.Append(stylesheetExtension2);
|
||||||
|
|
||||||
sp.Stylesheet.Append(fonts);
|
sp.Stylesheet.Append(fonts);
|
||||||
sp.Stylesheet.Append(fills);
|
sp.Stylesheet.Append(fills);
|
||||||
sp.Stylesheet.Append(borders);
|
sp.Stylesheet.Append(borders);
|
||||||
@ -185,11 +128,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
sp.Stylesheet.Append(tableStyles);
|
sp.Stylesheet.Append(tableStyles);
|
||||||
sp.Stylesheet.Append(stylesheetExtensionList);
|
sp.Stylesheet.Append(stylesheetExtensionList);
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Получение номера стиля из типа
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="styleInfo"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
|
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
|
||||||
{
|
{
|
||||||
return styleInfo switch
|
return styleInfo switch
|
||||||
@ -200,40 +139,44 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
_ => 0U,
|
_ => 0U,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
protected override void CreateExcel(ExcelInfo info)
|
|
||||||
|
protected override void CreateExcel(IDocument info)
|
||||||
{
|
{
|
||||||
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName,
|
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
|
||||||
SpreadsheetDocumentType.Workbook);
|
// Создаем книгу (в ней хранятся листы)
|
||||||
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
||||||
workbookpart.Workbook = new Workbook();
|
workbookpart.Workbook = new Workbook();
|
||||||
|
|
||||||
CreateStyles(workbookpart);
|
CreateStyles(workbookpart);
|
||||||
_shareStringPart =
|
|
||||||
_spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
|
// Получаем/создаем хранилище текстов для книги
|
||||||
?
|
_shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
|
||||||
_spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
|
? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
|
||||||
:
|
: _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
|
||||||
_spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
|
|
||||||
// Создаем SharedStringTable, если его нет
|
// Создаем SharedStringTable, если его нет
|
||||||
if (_shareStringPart.SharedStringTable == null)
|
if (_shareStringPart.SharedStringTable == null)
|
||||||
{
|
{
|
||||||
_shareStringPart.SharedStringTable = new SharedStringTable();
|
_shareStringPart.SharedStringTable = new SharedStringTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаем лист в книгу
|
// Создаем лист в книгу
|
||||||
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||||
worksheetPart.Worksheet = new Worksheet(new SheetData());
|
worksheetPart.Worksheet = new Worksheet(new SheetData());
|
||||||
|
|
||||||
// Добавляем лист в книгу
|
// Добавляем лист в книгу
|
||||||
var sheets =
|
var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
|
||||||
_spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
|
|
||||||
var sheet = new Sheet()
|
var sheet = new Sheet()
|
||||||
{
|
{
|
||||||
Id =
|
Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
||||||
_spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
|
||||||
SheetId = 1,
|
SheetId = 1,
|
||||||
Name = "Лист"
|
Name = "Лист"
|
||||||
};
|
};
|
||||||
sheets.Append(sheet);
|
sheets.Append(sheet);
|
||||||
|
|
||||||
_worksheet = worksheetPart.Worksheet;
|
_worksheet = worksheetPart.Worksheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
|
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
|
||||||
{
|
{
|
||||||
if (_worksheet == null || _shareStringPart == null)
|
if (_worksheet == null || _shareStringPart == null)
|
||||||
@ -245,6 +188,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ищем строку, либо добавляем ее
|
// Ищем строку, либо добавляем ее
|
||||||
Row row;
|
Row row;
|
||||||
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
|
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
|
||||||
@ -256,6 +200,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
row = new Row() { RowIndex = excelParams.RowIndex };
|
row = new Row() { RowIndex = excelParams.RowIndex };
|
||||||
sheetData.Append(row);
|
sheetData.Append(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ищем нужную ячейку
|
// Ищем нужную ячейку
|
||||||
Cell cell;
|
Cell cell;
|
||||||
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
|
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
|
||||||
@ -275,20 +220,22 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var newCell = new Cell()
|
|
||||||
{
|
var newCell = new Cell() { CellReference = excelParams.CellReference };
|
||||||
CellReference = excelParams.CellReference
|
|
||||||
};
|
|
||||||
row.InsertBefore(newCell, refCell);
|
row.InsertBefore(newCell, refCell);
|
||||||
|
|
||||||
cell = newCell;
|
cell = newCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
// вставляем новый текст
|
// вставляем новый текст
|
||||||
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
|
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
|
||||||
_shareStringPart.SharedStringTable.Save();
|
_shareStringPart.SharedStringTable.Save();
|
||||||
|
|
||||||
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
|
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
|
||||||
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
|
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
|
||||||
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
|
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void MergeCells(ExcelMergeParameters excelParams)
|
protected override void MergeCells(ExcelMergeParameters excelParams)
|
||||||
{
|
{
|
||||||
if (_worksheet == null)
|
if (_worksheet == null)
|
||||||
@ -296,6 +243,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MergeCells mergeCells;
|
MergeCells mergeCells;
|
||||||
|
|
||||||
if (_worksheet.Elements<MergeCells>().Any())
|
if (_worksheet.Elements<MergeCells>().Any())
|
||||||
{
|
{
|
||||||
mergeCells = _worksheet.Elements<MergeCells>().First();
|
mergeCells = _worksheet.Elements<MergeCells>().First();
|
||||||
@ -303,24 +251,25 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
mergeCells = new MergeCells();
|
mergeCells = new MergeCells();
|
||||||
|
|
||||||
if (_worksheet.Elements<CustomSheetView>().Any())
|
if (_worksheet.Elements<CustomSheetView>().Any())
|
||||||
{
|
{
|
||||||
_worksheet.InsertAfter(mergeCells,
|
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<CustomSheetView>().First());
|
||||||
_worksheet.Elements<CustomSheetView>().First());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_worksheet.InsertAfter(mergeCells,
|
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<SheetData>().First());
|
||||||
_worksheet.Elements<SheetData>().First());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var mergeCell = new MergeCell()
|
var mergeCell = new MergeCell()
|
||||||
{
|
{
|
||||||
Reference = new StringValue(excelParams.Merge)
|
Reference = new StringValue(excelParams.Merge)
|
||||||
};
|
};
|
||||||
mergeCells.Append(mergeCell);
|
mergeCells.Append(mergeCell);
|
||||||
}
|
}
|
||||||
protected override void SaveExcel(ExcelInfo info)
|
|
||||||
|
protected override void SaveExcel(IDocument info)
|
||||||
{
|
{
|
||||||
if (_spreadsheetDocument == null)
|
if (_spreadsheetDocument == null)
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
private Document? _document;
|
private Document? _document;
|
||||||
private Section? _section;
|
private Section? _section;
|
||||||
private Table? _table;
|
private Table? _table;
|
||||||
|
|
||||||
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
|
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
|
||||||
{
|
{
|
||||||
return type switch
|
return type switch
|
||||||
@ -21,24 +22,25 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
_ => ParagraphAlignment.Justify,
|
_ => ParagraphAlignment.Justify,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Создание стилей для документа
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="document"></param>
|
|
||||||
private static void DefineStyles(Document document)
|
private static void DefineStyles(Document document)
|
||||||
{
|
{
|
||||||
var style = document.Styles["Normal"];
|
var style = document.Styles["Normal"];
|
||||||
style.Font.Name = "Times New Roman";
|
style.Font.Name = "Times New Roman";
|
||||||
style.Font.Size = 14;
|
style.Font.Size = 14;
|
||||||
|
|
||||||
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
||||||
style.Font.Bold = true;
|
style.Font.Bold = true;
|
||||||
}
|
}
|
||||||
protected override void CreatePdf(PdfInfo info)
|
|
||||||
|
protected override void CreatePdf(IDocument info)
|
||||||
{
|
{
|
||||||
_document = new Document();
|
_document = new Document();
|
||||||
DefineStyles(_document);
|
DefineStyles(_document);
|
||||||
|
|
||||||
_section = _document.AddSection();
|
_section = _document.AddSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CreateParagraph(PdfParagraph pdfParagraph)
|
protected override void CreateParagraph(PdfParagraph pdfParagraph)
|
||||||
{
|
{
|
||||||
if (_section == null)
|
if (_section == null)
|
||||||
@ -50,6 +52,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
|
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
|
||||||
paragraph.Style = pdfParagraph.Style;
|
paragraph.Style = pdfParagraph.Style;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CreateTable(List<string> columns)
|
protected override void CreateTable(List<string> columns)
|
||||||
{
|
{
|
||||||
if (_document == null)
|
if (_document == null)
|
||||||
@ -57,11 +60,13 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_table = _document.LastSection.AddTable();
|
_table = _document.LastSection.AddTable();
|
||||||
|
|
||||||
foreach (var elem in columns)
|
foreach (var elem in columns)
|
||||||
{
|
{
|
||||||
_table.AddColumn(elem);
|
_table.AddColumn(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CreateRow(PdfRowParameters rowParameters)
|
protected override void CreateRow(PdfRowParameters rowParameters)
|
||||||
{
|
{
|
||||||
if (_table == null)
|
if (_table == null)
|
||||||
@ -72,20 +77,25 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
||||||
{
|
{
|
||||||
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
|
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(rowParameters.Style))
|
if (!string.IsNullOrEmpty(rowParameters.Style))
|
||||||
{
|
{
|
||||||
row.Cells[i].Style = rowParameters.Style;
|
row.Cells[i].Style = rowParameters.Style;
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit borderWidth = 0.5;
|
Unit borderWidth = 0.5;
|
||||||
|
|
||||||
row.Cells[i].Borders.Left.Width = borderWidth;
|
row.Cells[i].Borders.Left.Width = borderWidth;
|
||||||
row.Cells[i].Borders.Right.Width = borderWidth;
|
row.Cells[i].Borders.Right.Width = borderWidth;
|
||||||
row.Cells[i].Borders.Top.Width = borderWidth;
|
row.Cells[i].Borders.Top.Width = borderWidth;
|
||||||
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||||
|
|
||||||
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
|
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
|
||||||
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override void SavePdf(PdfInfo info)
|
|
||||||
|
protected override void SavePdf(IDocument info)
|
||||||
{
|
{
|
||||||
var renderer = new PdfDocumentRenderer(true)
|
var renderer = new PdfDocumentRenderer(true)
|
||||||
{
|
{
|
||||||
|
@ -11,13 +11,8 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
{
|
{
|
||||||
private WordprocessingDocument? _wordDocument;
|
private WordprocessingDocument? _wordDocument;
|
||||||
private Body? _docBody;
|
private Body? _docBody;
|
||||||
/// <summary>
|
|
||||||
/// Получение типа выравнивания
|
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||||
/// </summary>
|
|
||||||
/// <param name="type"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private static JustificationValues
|
|
||||||
GetJustificationValues(WordJustificationType type)
|
|
||||||
{
|
{
|
||||||
return type switch
|
return type switch
|
||||||
{
|
{
|
||||||
@ -26,59 +21,60 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
_ => JustificationValues.Left,
|
_ => JustificationValues.Left,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Настройки страницы
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
private static SectionProperties CreateSectionProperties()
|
private static SectionProperties CreateSectionProperties()
|
||||||
{
|
{
|
||||||
var properties = new SectionProperties();
|
var properties = new SectionProperties();
|
||||||
|
|
||||||
var pageSize = new PageSize
|
var pageSize = new PageSize
|
||||||
{
|
{
|
||||||
Orient = PageOrientationValues.Portrait
|
Orient = PageOrientationValues.Portrait
|
||||||
};
|
};
|
||||||
|
|
||||||
properties.AppendChild(pageSize);
|
properties.AppendChild(pageSize);
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Задание форматирования для абзаца
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="paragraphProperties"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||||
{
|
{
|
||||||
if (paragraphProperties == null)
|
if (paragraphProperties == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var properties = new ParagraphProperties();
|
var properties = new ParagraphProperties();
|
||||||
|
|
||||||
properties.AppendChild(new Justification()
|
properties.AppendChild(new Justification()
|
||||||
{
|
{
|
||||||
Val = GetJustificationValues(paragraphProperties.JustificationType)
|
Val = GetJustificationValues(paragraphProperties.JustificationType)
|
||||||
});
|
});
|
||||||
|
|
||||||
properties.AppendChild(new SpacingBetweenLines
|
properties.AppendChild(new SpacingBetweenLines
|
||||||
{
|
{
|
||||||
LineRule = LineSpacingRuleValues.Auto
|
LineRule = LineSpacingRuleValues.Auto
|
||||||
});
|
});
|
||||||
|
|
||||||
properties.AppendChild(new Indentation());
|
properties.AppendChild(new Indentation());
|
||||||
|
|
||||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||||
{
|
{
|
||||||
paragraphMarkRunProperties.AppendChild(new FontSize
|
paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size });
|
||||||
{
|
|
||||||
Val = paragraphProperties.Size
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
properties.AppendChild(paragraphMarkRunProperties);
|
properties.AppendChild(paragraphMarkRunProperties);
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
protected override void CreateWord(WordInfo info)
|
|
||||||
|
protected override void CreateWord(IDocument info)
|
||||||
{
|
{
|
||||||
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
||||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||||
mainPart.Document = new Document();
|
mainPart.Document = new Document();
|
||||||
_docBody = mainPart.Document.AppendChild(new Body());
|
_docBody = mainPart.Document.AppendChild(new Body());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CreateParagraph(WordParagraph paragraph)
|
protected override void CreateParagraph(WordParagraph paragraph)
|
||||||
{
|
{
|
||||||
if (_docBody == null || paragraph == null)
|
if (_docBody == null || paragraph == null)
|
||||||
@ -88,9 +84,11 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
var docParagraph = new Paragraph();
|
var docParagraph = new Paragraph();
|
||||||
|
|
||||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
||||||
|
|
||||||
foreach (var run in paragraph.Texts)
|
foreach (var run in paragraph.Texts)
|
||||||
{
|
{
|
||||||
var docRun = new Run();
|
var docRun = new Run();
|
||||||
|
|
||||||
var properties = new RunProperties();
|
var properties = new RunProperties();
|
||||||
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
||||||
if (run.Item2.Bold)
|
if (run.Item2.Bold)
|
||||||
@ -98,24 +96,97 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
|||||||
properties.AppendChild(new Bold());
|
properties.AppendChild(new Bold());
|
||||||
}
|
}
|
||||||
docRun.AppendChild(properties);
|
docRun.AppendChild(properties);
|
||||||
docRun.AppendChild(new Text
|
|
||||||
{
|
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
|
||||||
Text = run.Item1,
|
|
||||||
Space = SpaceProcessingModeValues.Preserve
|
|
||||||
});
|
|
||||||
docParagraph.AppendChild(docRun);
|
docParagraph.AppendChild(docRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
_docBody.AppendChild(docParagraph);
|
_docBody.AppendChild(docParagraph);
|
||||||
}
|
}
|
||||||
protected override void SaveWord(WordInfo info)
|
|
||||||
|
protected override void SaveWord(IDocument info)
|
||||||
{
|
{
|
||||||
if (_docBody == null || _wordDocument == null)
|
if (_docBody == null || _wordDocument == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_docBody.AppendChild(CreateSectionProperties());
|
_docBody.AppendChild(CreateSectionProperties());
|
||||||
|
|
||||||
_wordDocument.MainDocumentPart!.Document.Save();
|
_wordDocument.MainDocumentPart!.Document.Save();
|
||||||
_wordDocument.Dispose();
|
_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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,33 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
private readonly AbstractMailWorker _mailWorker;
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
static readonly object _locker = new object();
|
static readonly object _locker = new object();
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker)
|
private readonly IShopStorage _shopStorage;
|
||||||
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractMailWorker mailWorker)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
_mailWorker = mailWorker;
|
_mailWorker = mailWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||||
|
model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, model.Id);
|
||||||
|
var element = _orderStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
_logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||||
@ -40,6 +61,7 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
@ -56,7 +78,7 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
MailAddress = element.ClientEmail,
|
MailAddress = element.ClientEmail,
|
||||||
Subject = $"Изменение статуса заказа номер {element.Id}",
|
Subject = $"Изменение статуса заказа номер {element.Id}",
|
||||||
Text = $"Ваш заказ номер {element.Id} на суши {element.SushiName} от {element.DateCreate} на сумму {element.Sum} принят."
|
Text = $"Ваш заказ номер {element.Id} на пиццу {element.SushiName} от {element.DateCreate} на сумму {element.Sum} принят."
|
||||||
}));
|
}));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -76,7 +98,31 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
public bool DeliveryOrder(OrderBindingModel model)
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
return ChangeStatus(model, OrderStatus.Выдан);
|
lock (_locker)
|
||||||
|
{
|
||||||
|
(model, var element) = FillOrderBindingModel(model);
|
||||||
|
if (model.Status != OrderStatus.Готов && model.Status != OrderStatus.Ожидает)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-Выдан.", model.Status);
|
||||||
|
throw new InvalidOperationException($"Невозможно приствоить статус выдан заказу с текущим статусом {model.Status}");
|
||||||
|
}
|
||||||
|
if (!_shopStorage.RestockingShops(new SupplyBindingModel
|
||||||
|
{
|
||||||
|
SushiId = model.SushiId,
|
||||||
|
Count = model.Count
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
if (model.Status == OrderStatus.Готов)
|
||||||
|
{
|
||||||
|
model.Status = OrderStatus.Ожидает;
|
||||||
|
|
||||||
|
UpdateOrder(model, element);
|
||||||
|
}
|
||||||
|
throw new ArgumentException("Недостаточно места в магазинах для поставки");
|
||||||
|
}
|
||||||
|
model.Status = OrderStatus.Выдан;
|
||||||
|
return UpdateOrder(model, element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
@ -104,8 +150,22 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
_logger.LogInformation("Sushi. SushiId:{SushiId}.Count:{Count}.Sum:{Sum}Id:{Id}",
|
_logger.LogInformation("Sushi. SushiId:{SushiId}.Count:{Count}.Sum:{Sum}Id:{Id}",
|
||||||
model.SushiId, model.Count, model.Sum, model.Id);
|
model.SushiId, model.Count, model.Sum, model.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus)
|
private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus)
|
||||||
|
{
|
||||||
|
(model, var element) = FillOrderBindingModel(model);
|
||||||
|
|
||||||
|
if (requiredStatus - model.Status == 1)
|
||||||
|
{
|
||||||
|
model.Status = requiredStatus;
|
||||||
|
if (model.Status == OrderStatus.Готов)
|
||||||
|
model.DateImplement = DateTime.Now;
|
||||||
|
return UpdateOrder(model, element);
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
||||||
|
throw new InvalidOperationException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private (OrderBindingModel, OrderViewModel) FillOrderBindingModel(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model, false);
|
CheckModel(model, false);
|
||||||
var element = _orderStorage.GetElement(new OrderSearchModel()
|
var element = _orderStorage.GetElement(new OrderSearchModel()
|
||||||
@ -116,59 +176,38 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new InvalidOperationException(nameof(element));
|
throw new InvalidOperationException(nameof(element));
|
||||||
}
|
}
|
||||||
|
model.Id = element.Id;
|
||||||
model.DateCreate = element.DateCreate;
|
model.DateCreate = element.DateCreate;
|
||||||
model.SushiId = element.SushiId;
|
model.SushiId = element.SushiId;
|
||||||
model.DateImplement = element.DateImplement;
|
model.DateImplement = element.DateImplement;
|
||||||
model.ClientId = element.ClientId;
|
model.ClientId = element.ClientId;
|
||||||
|
model.Status = element.Status;
|
||||||
|
model.Count = element.Count;
|
||||||
|
model.Sum = element.Sum;
|
||||||
if (!model.ImplementerId.HasValue)
|
if (!model.ImplementerId.HasValue)
|
||||||
{
|
{
|
||||||
model.ImplementerId = element.ImplementerId;
|
model.ImplementerId = element.ImplementerId;
|
||||||
}
|
}
|
||||||
model.Status = element.Status;
|
return (model, element);
|
||||||
model.Count = element.Count;
|
|
||||||
model.Sum = element.Sum;
|
|
||||||
if (requiredStatus - model.Status == 1)
|
|
||||||
{
|
|
||||||
model.Status = requiredStatus;
|
|
||||||
if (model.Status == OrderStatus.Готов)
|
|
||||||
{
|
|
||||||
model.DateImplement = DateTime.Now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool UpdateOrder(OrderBindingModel model, OrderViewModel MailNotificationModel)
|
||||||
|
{
|
||||||
if (_orderStorage.Update(model) == null)
|
if (_orderStorage.Update(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Update operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
_logger.LogWarning("Update operation sucsess");
|
||||||
string DateInfo = model.DateImplement.HasValue ? $"Дата выполнения {model.DateImplement}" : "";
|
string DateInfo = model.DateImplement.HasValue ? $"Дата выполнения {model.DateImplement}" : "";
|
||||||
Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel
|
Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel
|
||||||
{
|
{
|
||||||
MailAddress = element.ClientEmail,
|
MailAddress = MailNotificationModel.ClientEmail,
|
||||||
Subject = $"Изменение статуса заказа номер {element.Id}",
|
Subject = $"Изменение статуса заказа номер {MailNotificationModel.Id}",
|
||||||
Text = $"Ваш заказ номер {element.Id} на суши {element.SushiName} от {element.DateCreate} на сумму {element.Sum} {model.Status}. {DateInfo}"
|
Text = $"Ваш заказ номер {MailNotificationModel.Id} на изделие {MailNotificationModel.SushiName} от" +
|
||||||
|
$" {MailNotificationModel.DateCreate} на сумму {MailNotificationModel.Sum} {model.Status}. {DateInfo}"
|
||||||
}));
|
}));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
|
||||||
throw new InvalidOperationException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
|
||||||
model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, model.Id);
|
|
||||||
var element = _orderStorage.GetElement(model);
|
|
||||||
if (element == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("ReadElement element not found");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,7 +36,8 @@ namespace SushiBarBusinessLogic
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят });
|
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят });
|
||||||
if (orders == null || orders.Count == 0)
|
|
||||||
|
if (orders == null )
|
||||||
{
|
{
|
||||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||||
return;
|
return;
|
||||||
@ -54,6 +55,7 @@ namespace SushiBarBusinessLogic
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await DeliverWaitingOrder(implementer);
|
||||||
await RunOrderInWork(implementer);
|
await RunOrderInWork(implementer);
|
||||||
|
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
@ -76,6 +78,7 @@ namespace SushiBarBusinessLogic
|
|||||||
{
|
{
|
||||||
Id = order.Id
|
Id = order.Id
|
||||||
});
|
});
|
||||||
|
_orderLogic.DeliveryOrder(new OrderBindingModel { Id = order.Id });
|
||||||
}
|
}
|
||||||
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
||||||
catch (InvalidOperationException ex)
|
catch (InvalidOperationException ex)
|
||||||
@ -135,5 +138,47 @@ namespace SushiBarBusinessLogic
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task DeliverWaitingOrder(ImplementerViewModel implementer)
|
||||||
|
{
|
||||||
|
if (_orderLogic == null || implementer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var waitingOrders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel
|
||||||
|
{
|
||||||
|
ImplementerId = implementer.Id,
|
||||||
|
Status = OrderStatus.Ожидает
|
||||||
|
}));
|
||||||
|
if (waitingOrders == null || waitingOrders.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("DeliverWaitingOrder. Find some waitig order for implementer:{id}.Count:{count}", implementer.Id, waitingOrders.Count);
|
||||||
|
foreach (var waitingOrder in waitingOrders)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("DeliverWaitingOrder. Trying to deliver order id:{id}", waitingOrder.Id);
|
||||||
|
var res = _orderLogic.DeliveryOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = waitingOrder.Id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "DeliverWaitingOrder. Fault");
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Error try deliver order");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error while do work");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,18 @@ namespace SushiBarClientApp
|
|||||||
public class APIClient
|
public class APIClient
|
||||||
{
|
{
|
||||||
private static readonly HttpClient _client = new();
|
private static readonly HttpClient _client = new();
|
||||||
|
|
||||||
|
public static string? Password { get; set; }
|
||||||
public static ClientViewModel? Client { get; set; } = null;
|
public static ClientViewModel? Client { get; set; } = null;
|
||||||
|
public static int MailPage { get; set; } = 1;
|
||||||
|
|
||||||
public static void Connect(IConfiguration configuration)
|
public static void Connect(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||||
_client.DefaultRequestHeaders.Accept.Clear();
|
_client.DefaultRequestHeaders.Accept.Clear();
|
||||||
_client.DefaultRequestHeaders.Accept.Add(new
|
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
MediaTypeWithQualityHeaderValue("application/json"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T? GetRequest<T>(string requestUrl)
|
public static T? GetRequest<T>(string requestUrl)
|
||||||
{
|
{
|
||||||
var response = _client.GetAsync(requestUrl);
|
var response = _client.GetAsync(requestUrl);
|
||||||
@ -31,12 +35,24 @@ namespace SushiBarClientApp
|
|||||||
throw new Exception(result);
|
throw new Exception(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PostRequest<T>(string requestUrl, T model)
|
public static void PostRequest<T>(string requestUrl, T model)
|
||||||
{
|
{
|
||||||
var json = JsonConvert.SerializeObject(model);
|
var json = JsonConvert.SerializeObject(model);
|
||||||
var data = new StringContent(json, Encoding.UTF8,
|
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
"application/json");
|
|
||||||
var response = _client.PostAsync(requestUrl, data);
|
var response = _client.PostAsync(requestUrl, data);
|
||||||
|
|
||||||
|
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||||
|
if (!response.Result.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
throw new Exception(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DeleteRequest(string requestUrl)
|
||||||
|
{
|
||||||
|
var response = _client.DeleteAsync(requestUrl);
|
||||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||||
if (!response.Result.IsSuccessStatusCode)
|
if (!response.Result.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
@ -44,5 +60,5 @@ namespace SushiBarClientApp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,19 +11,21 @@ namespace SushiBarClientApp.Controllers
|
|||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<HomeController> _logger;
|
private readonly ILogger<HomeController> _logger;
|
||||||
|
|
||||||
public HomeController(ILogger<HomeController> logger)
|
public HomeController(ILogger<HomeController> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
if (APIClient.Client == null)
|
if (APIClient.Client == null)
|
||||||
{
|
{
|
||||||
return Redirect("~/Home/Enter");
|
return Redirect("~/Home/Enter");
|
||||||
}
|
}
|
||||||
return
|
return View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
|
||||||
View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Privacy()
|
public IActionResult Privacy()
|
||||||
{
|
{
|
||||||
@ -33,6 +35,7 @@ namespace SushiBarClientApp.Controllers
|
|||||||
}
|
}
|
||||||
return View(APIClient.Client);
|
return View(APIClient.Client);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Privacy(string login, string password, string fio)
|
public void Privacy(string login, string password, string fio)
|
||||||
{
|
{
|
||||||
@ -40,70 +43,65 @@ namespace SushiBarClientApp.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(login) ||
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
||||||
{
|
{
|
||||||
throw new Exception("Введите логин, пароль и ФИО");
|
throw new Exception("Введите логин, пароль и ФИО");
|
||||||
}
|
}
|
||||||
APIClient.PostRequest("api/client/updatedata", new
|
APIClient.PostRequest("api/client/updatedata", new ClientBindingModel
|
||||||
ClientBindingModel
|
|
||||||
{
|
{
|
||||||
Id = APIClient.Client.Id,
|
Id = APIClient.Client.Id,
|
||||||
ClientFIO = fio,
|
ClientFIO = fio,
|
||||||
Email = login,
|
Email = login,
|
||||||
Password = password
|
Password = password
|
||||||
});
|
});
|
||||||
|
|
||||||
APIClient.Client.ClientFIO = fio;
|
APIClient.Client.ClientFIO = fio;
|
||||||
APIClient.Client.Email = login;
|
APIClient.Client.Email = login;
|
||||||
APIClient.Client.Password = password;
|
APIClient.Client.Password = password;
|
||||||
Response.Redirect("Index");
|
Response.Redirect("Index");
|
||||||
}
|
}
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None,
|
|
||||||
NoStore = true)]
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
public IActionResult Error()
|
public IActionResult Error()
|
||||||
{
|
{
|
||||||
return View(new ErrorViewModel
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||||
{
|
|
||||||
RequestId =
|
|
||||||
Activity.Current?.Id ?? HttpContext.TraceIdentifier
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Enter()
|
public IActionResult Enter()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Enter(string login, string password)
|
public void Enter(string login, string password)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(login) ||
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
||||||
string.IsNullOrEmpty(password))
|
|
||||||
{
|
{
|
||||||
throw new Exception("Введите логин и пароль");
|
throw new Exception("Введите логин и пароль");
|
||||||
}
|
}
|
||||||
APIClient.Client =
|
APIClient.Client = APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}");
|
||||||
APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}");
|
|
||||||
if (APIClient.Client == null)
|
if (APIClient.Client == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Неверный логин/пароль");
|
throw new Exception("Неверный логин/пароль");
|
||||||
}
|
}
|
||||||
Response.Redirect("Index");
|
Response.Redirect("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Register()
|
public IActionResult Register()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Register(string login, string password, string fio)
|
public void Register(string login, string password, string fio)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(login) ||
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
||||||
{
|
{
|
||||||
throw new Exception("Введите логин, пароль и ФИО");
|
throw new Exception("Введите логин, пароль и ФИО");
|
||||||
}
|
}
|
||||||
APIClient.PostRequest("api/client/register", new
|
APIClient.PostRequest("api/client/register", new ClientBindingModel
|
||||||
ClientBindingModel
|
|
||||||
{
|
{
|
||||||
ClientFIO = fio,
|
ClientFIO = fio,
|
||||||
Email = login,
|
Email = login,
|
||||||
@ -112,15 +110,16 @@ namespace SushiBarClientApp.Controllers
|
|||||||
Response.Redirect("Enter");
|
Response.Redirect("Enter");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Create()
|
public IActionResult Create()
|
||||||
{
|
{
|
||||||
ViewBag.Sushis =
|
ViewBag.Sushis = APIClient.GetRequest<List<SushiViewModel>>("api/main/getSushilist");
|
||||||
APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
|
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Create(int sushi, int count)
|
public void Create(int Sushi, int count)
|
||||||
{
|
{
|
||||||
if (APIClient.Client == null)
|
if (APIClient.Client == null)
|
||||||
{
|
{
|
||||||
@ -133,31 +132,31 @@ namespace SushiBarClientApp.Controllers
|
|||||||
APIClient.PostRequest("api/main/createorder", new OrderBindingModel
|
APIClient.PostRequest("api/main/createorder", new OrderBindingModel
|
||||||
{
|
{
|
||||||
ClientId = APIClient.Client.Id,
|
ClientId = APIClient.Client.Id,
|
||||||
SushiId = sushi,
|
SushiId = Sushi,
|
||||||
Count = count,
|
Count = count,
|
||||||
Sum = Calc(count, sushi)
|
Sum = Calc(count, Sushi)
|
||||||
});
|
});
|
||||||
Response.Redirect("Index");
|
Response.Redirect("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public double Calc(int count, int sushi)
|
public double Calc(int count, int Sushi)
|
||||||
{
|
{
|
||||||
var prod =
|
var sus = APIClient.GetRequest<SushiViewModel>($"api/main/getSushi?SushiId={Sushi}");
|
||||||
APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiId={sushi}"
|
return count * (sus?.Price ?? 1);
|
||||||
);
|
|
||||||
return count * (prod?.Price ?? 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Mails()
|
public IActionResult Mails(int page = 1)
|
||||||
{
|
{
|
||||||
if (APIClient.Client == null)
|
if (APIClient.Client == null)
|
||||||
{
|
{
|
||||||
return Redirect("~/Home/Enter");
|
return Redirect("~/Home/Enter");
|
||||||
}
|
}
|
||||||
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
page = Math.Max(page, 1);
|
||||||
|
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}&page={page}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
Номер
|
Номер
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Суши
|
Пицца
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Дата создания
|
Дата создания
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
@using SushiBarContracts.ViewModels
|
@using SushiBarContracts.ViewModels
|
||||||
|
|
||||||
@model List<MessageInfoViewModel>
|
@model List<MessageInfoViewModel>
|
||||||
|
@Url.ActionContext.RouteData.Values["page"]
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Mails";
|
ViewData["Title"] = "Mails";
|
||||||
@ -51,5 +52,23 @@
|
|||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div class="d-flex justify-content-center align-items-center">
|
||||||
|
@{
|
||||||
|
int page = int.Parse(Context.Request.Query["page"]);
|
||||||
|
<div class="m-1">
|
||||||
|
<input type="number" class="form-control" min="1" step="1" asp-action="Mails" name="page" value="@(page)" readonly>
|
||||||
|
</div>
|
||||||
|
if (page > 1)
|
||||||
|
{
|
||||||
|
<a name="page" class="btn btn-primary" type="button" asp-action="Mails" asp-route-page="@(page-1)"><-</a>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<p class="btn btn-primary my-auto"><-</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
<a name="" id="" class="btn btn-primary" type="button" asp-action="Mails" asp-route-page="@(page+1)">-></a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
74
SushiBar/SushiBarClientApp/Views/Home/Shop.cshtml
Normal file
74
SushiBar/SushiBarClientApp/Views/Home/Shop.cshtml
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
@using SushiBarDataModels.Models;
|
||||||
|
@using SushiBarContracts.ViewModels;
|
||||||
|
@model ShopSushiViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Shop";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
@{
|
||||||
|
if (Model == null)
|
||||||
|
{
|
||||||
|
<h2 class="display-4">Создание магазина</h2>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<h2 class="display-4">Изменение магазина</h2>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Название</label>
|
||||||
|
<input type="text" class="form-control" name="shopname" id="shopname" value="@(Model==null ? "" : Model.Shop?.ShopName)" />
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Адрес</label>
|
||||||
|
<input type="text" class="form-control" name="adress" id="adress" value="@(Model==null ? "" : Model.Shop?.Adress)" />
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="startDate">Дата открытия</label>
|
||||||
|
<input class="form-control" type="date" name="openingdate" id="openingdate" value="@(Model==null ? "" : Model.Shop?.OpeningDate.ToString("yyyy-MM-dd"))" />
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Вместимость</label>
|
||||||
|
<input type="number" min="0" step="1" pattern="[0-9]" class="form-control" name="maxcount" id="maxcount" value="@(Model==null ? "" : Model.Shop?.SushiMaxCount)" />
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 ">
|
||||||
|
<input class="btn btn-primary" type="submit" value="Сохранить">
|
||||||
|
@{
|
||||||
|
if (Model != null && Model.Shop != null)
|
||||||
|
{
|
||||||
|
<input class="btn btn-danger" asp-action="Delete" type="submit" value="Удалить" asp-route-Id="@(Model==null ? 0 : Model.Shop.Id.ToString())">
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
@{
|
||||||
|
if (Model != null && Model.Shop != null)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
<h6>Содержимое магазина</h6>
|
||||||
|
</div>
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Название</th>
|
||||||
|
<th>Количество</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in Model.ShopSushi)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>@Html.DisplayFor(modelItem => item.Value.Sushi.SushiName)</td>
|
||||||
|
<td>@Html.DisplayFor(modelItem => item.Value.Count)</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
}
|
||||||
|
}
|
22
SushiBar/SushiBarClientApp/Views/Home/Supply.cshtml
Normal file
22
SushiBar/SushiBarClientApp/Views/Home/Supply.cshtml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Supply";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Создание поставки</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Магазин</label>
|
||||||
|
<select class="form-select form-select-lg" id="shop" name="shop" asp-items="@(new SelectList(@ViewBag.Shops,"Id", "ShopName"))"></select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Пицца</label>
|
||||||
|
<select class="form-select form-select-lg" id="sushi" name="sushi" asp-items="@(new SelectList(@ViewBag.Sushis,"Id", "SushiName"))"></select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Колличество</label>
|
||||||
|
<input type="number" min="0" step="1" pattern="[0-9]" class="form-control" name="count" id="count">
|
||||||
|
</div>
|
||||||
|
<input class="btn btn-success" type="submit" value="Создать поставку">
|
||||||
|
<a class="btn btn-primary" href="./Index" role="button">Отмена</a>
|
||||||
|
</form>
|
@ -14,27 +14,28 @@
|
|||||||
<header>
|
<header>
|
||||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Суши-Бар</a>
|
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">SushiBarShopsApi</a>
|
||||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||||
aria-expanded="false" aria-label="Toggle navigation">
|
aria-expanded="false" aria-label="Toggle navigation">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
|
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||||
<ul class="navbar-nav flex-grow-1">
|
<ul class="navbar-nav flex-grow-1">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Заказы</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Главная</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Mails">Письма</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Mails" asp-route-page="1">Письма</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||||
|
@* <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Supply">Поставка</a> *@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -49,7 +50,7 @@
|
|||||||
|
|
||||||
<footer class="border-top footer text-muted">
|
<footer class="border-top footer text-muted">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
© 2024 - SushiBarClientApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
© 2024 - SushiBarShopApp - <a asp-area="" asp-controller="Home" asp-action="Index">Главная</a>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class MailReplySendInfoBindingModel : MailSendInfoBindingModel
|
||||||
|
{
|
||||||
|
public string ParentMessageId { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,9 @@ namespace SushiBarContracts.BindingModels
|
|||||||
public string Subject { get; set; } = string.Empty;
|
public string Subject { get; set; } = string.Empty;
|
||||||
public string Body { get; set; } = string.Empty;
|
public string Body { get; set; } = string.Empty;
|
||||||
public DateTime DateDelivery { get; set; }
|
public DateTime DateDelivery { get; set; }
|
||||||
|
public bool IsReaded { get; set; }
|
||||||
|
public string? ReplyMessageId { get; set; }
|
||||||
|
public bool IsReply { get; set; }
|
||||||
public int Id => throw new NotImplementedException();
|
public int Id => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
19
SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs
Normal file
19
SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SushiBarDataModels.Models;
|
||||||
|
|
||||||
|
namespace SushiBarContracts.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, (ISushiModel, int)> ShopSushis { get; set; } = new();
|
||||||
|
public int SushiMaxCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SushiBarDataModels.Models;
|
||||||
|
|
||||||
|
namespace SushiBarContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class SupplyBindingModel : ISupplyModel
|
||||||
|
{
|
||||||
|
public int ShopId { get; set; }
|
||||||
|
public int SushiId { get; set; }
|
||||||
|
public int Count { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,8 @@ namespace SushiBarContracts.BusinessLogicsContracts
|
|||||||
public interface IMessageInfoLogic
|
public interface IMessageInfoLogic
|
||||||
{
|
{
|
||||||
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
||||||
|
MessageInfoViewModel? ReadElement(MessageInfoSearchModel model);
|
||||||
bool Create(MessageInfoBindingModel model);
|
bool Create(MessageInfoBindingModel model);
|
||||||
|
bool Update(MessageInfoBindingModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,13 @@ namespace SushiBarContracts.BusinessLogicsContracts
|
|||||||
{
|
{
|
||||||
List<ReportSushiComponentViewModel> GetSushiComponents();
|
List<ReportSushiComponentViewModel> GetSushiComponents();
|
||||||
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
|
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
|
||||||
|
List<ReportShopsViewModel> GetShops();
|
||||||
|
List<ReportGroupOrdersViewModel> GetGroupedOrders();
|
||||||
void SaveSushisToWordFile(ReportBindingModel model);
|
void SaveSushisToWordFile(ReportBindingModel model);
|
||||||
void SaveSushiComponentToExcelFile(ReportBindingModel model);
|
void SaveSushiComponentToExcelFile(ReportBindingModel model);
|
||||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||||
|
void SaveShopsToWordFile(ReportBindingModel model);
|
||||||
|
void SaveShopsToExcelFile(ReportBindingModel model);
|
||||||
|
void SaveGroupedOrdersToPdfFile(ReportBindingModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace SushiBarContracts.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);
|
||||||
|
}
|
||||||
|
}
|
@ -10,5 +10,7 @@ namespace SushiBarContracts.SearchModels
|
|||||||
{
|
{
|
||||||
public int? ClientId { get; set; }
|
public int? ClientId { get; set; }
|
||||||
public string? MessageId { get; set; }
|
public string? MessageId { get; set; }
|
||||||
|
public int? PageLength { get; set; }
|
||||||
|
public int? PageIndex { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs
Normal file
14
SushiBar/SushiBarContracts/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 SushiBarContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ShopSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? ShopName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
SushiBar/SushiBarContracts/SearchModels/SupplySearchModel.cs
Normal file
14
SushiBar/SushiBarContracts/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 SushiBarContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class SupplySearchModel
|
||||||
|
{
|
||||||
|
public int? SushiId { get; set; }
|
||||||
|
public int? Count { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -15,5 +15,6 @@ namespace SushiBarContracts.StoragesContracts
|
|||||||
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
|
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
|
||||||
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
||||||
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
|
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
|
||||||
|
MessageInfoViewModel? Update(MessageInfoBindingModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs
Normal file
23
SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarContracts.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);
|
||||||
|
}
|
||||||
|
}
|
@ -31,5 +31,14 @@ namespace SushiBarContracts.ViewModels
|
|||||||
|
|
||||||
[Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
[Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||||
public string Body { get; set; } = string.Empty;
|
public string Body { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Прочитанно")]
|
||||||
|
public bool IsReaded { get; set; }
|
||||||
|
|
||||||
|
public string? ReplyMessageId { get; set; }
|
||||||
|
|
||||||
|
public IMessageInfoModel? Reply { get; set; }
|
||||||
|
|
||||||
|
public bool IsReply { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ReportGroupOrdersViewModel
|
||||||
|
{
|
||||||
|
public DateTime Date { get; set; } = DateTime.Now;
|
||||||
|
public int OrdersCount { get; set; }
|
||||||
|
public double OrdersSum { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ReportShopsViewModel
|
||||||
|
{
|
||||||
|
public string ShopName { get; set; } = string.Empty;
|
||||||
|
public int TotalCount { get; set; }
|
||||||
|
public List<(string Sushi, int count)> Sushis { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
14
SushiBar/SushiBarContracts/ViewModels/ShopSushiViewModel.cs
Normal file
14
SushiBar/SushiBarContracts/ViewModels/ShopSushiViewModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ShopSushiViewModel
|
||||||
|
{
|
||||||
|
public ShopViewModel Shop { get; set; } = new();
|
||||||
|
public Dictionary<int, SushiCount> ShopSushi { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
25
SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs
Normal file
25
SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SushiBarDataModels.Models;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace SushiBarContracts.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, (ISushiModel, int)> ShopSushis { get; set; } = new();
|
||||||
|
[DisplayName("Вместимость")]
|
||||||
|
public int SushiMaxCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
SushiBar/SushiBarContracts/ViewModels/SushiCount.cs
Normal file
14
SushiBar/SushiBarContracts/ViewModels/SushiCount.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class SushiCount
|
||||||
|
{
|
||||||
|
public SushiViewModel Sushi { get; set; }
|
||||||
|
public int Count { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ namespace SushiBarDataModels.Enums
|
|||||||
Принят = 0,
|
Принят = 0,
|
||||||
Выполняется = 1,
|
Выполняется = 1,
|
||||||
Готов = 2,
|
Готов = 2,
|
||||||
Выдан = 3
|
Ожидает = 3,
|
||||||
|
Выдан = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SushiBarDataModels.Models
|
namespace SushiBarDataModels.Models
|
||||||
{
|
{
|
||||||
public interface IMessageInfoModel : IId
|
public interface IMessageInfoModel
|
||||||
{
|
{
|
||||||
string MessageId { get; }
|
string MessageId { get; }
|
||||||
int? ClientId { get; }
|
int? ClientId { get; }
|
||||||
@ -14,5 +14,8 @@ namespace SushiBarDataModels.Models
|
|||||||
DateTime DateDelivery { get; }
|
DateTime DateDelivery { get; }
|
||||||
string Subject { get; }
|
string Subject { get; }
|
||||||
string Body { get; }
|
string Body { get; }
|
||||||
|
bool IsReaded { get; }
|
||||||
|
string? ReplyMessageId { get; }
|
||||||
|
bool IsReply { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
SushiBar/SushiBarDataModels/Models/IShopModel.cs
Normal file
17
SushiBar/SushiBarDataModels/Models/IShopModel.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IShopModel : IId
|
||||||
|
{
|
||||||
|
string ShopName { get; }
|
||||||
|
string Adress { get; }
|
||||||
|
DateTime OpeningDate { get; }
|
||||||
|
Dictionary<int, (ISushiModel, int)> ShopSushis { get; }
|
||||||
|
public int SushiMaxCount { get; }
|
||||||
|
}
|
||||||
|
}
|
15
SushiBar/SushiBarDataModels/Models/ISupplyModel.cs
Normal file
15
SushiBar/SushiBarDataModels/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 SushiBarDataModels.Models
|
||||||
|
{
|
||||||
|
public interface ISupplyModel
|
||||||
|
{
|
||||||
|
int ShopId { get; }
|
||||||
|
int SushiId { get; }
|
||||||
|
int Count { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -20,13 +20,23 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.ClientId.HasValue)
|
if (!model.ClientId.HasValue && !model.PageLength.HasValue && !model.PageIndex.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new SushiBarDatabase();
|
using var context = new SushiBarDatabase();
|
||||||
return context.MessageInfos.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
IEnumerable<MessageInfo> request = context.MessageInfos.Where(x => !x.IsReply);
|
||||||
|
if (model.ClientId.HasValue)
|
||||||
|
request = request.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId);
|
||||||
|
if (model.PageLength.HasValue)
|
||||||
|
{
|
||||||
|
int skipRows = model.PageIndex.HasValue ? (model.PageIndex.Value - 1) * model.PageLength.Value : 0;
|
||||||
|
request = request.Skip(skipRows).Take(model.PageLength.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return request.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.MessageId))
|
if (string.IsNullOrEmpty(model.MessageId))
|
||||||
@ -44,9 +54,29 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new SushiBarDatabase();
|
using var context = new SushiBarDatabase();
|
||||||
|
try
|
||||||
|
{
|
||||||
context.MessageInfos.Add(newMessage);
|
context.MessageInfos.Add(newMessage);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return newMessage.GetViewModel;
|
return newMessage.GetViewModel;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SushiBarDatabase();
|
||||||
|
var message = context.MessageInfos.FirstOrDefault(x => x.MessageId == model.MessageId);
|
||||||
|
if (message == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
message.Update(context, model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return message.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
186
SushiBar/SushiBarDatabaseImplement/Implements/ShopStorage.cs
Normal file
186
SushiBar/SushiBarDatabaseImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarDatabaseImplement.Models;
|
||||||
|
|
||||||
|
|
||||||
|
namespace SushiBarDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SushiBarDatabase();
|
||||||
|
return context.Shops.Include(x => x.Sushis).ThenInclude(x => x.Sushi).ToList().
|
||||||
|
Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SushiBarDatabase();
|
||||||
|
return context.Shops.Include(x => x.Sushis).ThenInclude(x => x.Sushi).Where(x => x.ShopName.Contains(model.ShopName)).
|
||||||
|
ToList().Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SushiBarDatabase();
|
||||||
|
return context.Shops.Include(x => x.Sushis).ThenInclude(x => x.Sushi)
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SushiBarDatabase();
|
||||||
|
var newShop = Shop.Create(context, model);
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Shops.Add(newShop);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SushiBarDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
shop.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
shop.UpdateSushis(context, model);
|
||||||
|
transaction.Commit();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SushiBarDatabase();
|
||||||
|
var shop = context.Shops.Include(x => x.Sushis).FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop != null)
|
||||||
|
{
|
||||||
|
context.Shops.Remove(shop);
|
||||||
|
context.SaveChanges();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RestockingShops(SupplyBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SushiBarDatabase();
|
||||||
|
var transaction = context.Database.BeginTransaction();
|
||||||
|
var Shops = context.Shops.Include(x => x.Sushis).ThenInclude(x => x.Sushi).ToList().
|
||||||
|
Where(x => x.SushiMaxCount > x.ShopSushis.Select(x => x.Value.Item2).Sum()).ToList();
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (Shop shop in Shops)
|
||||||
|
{
|
||||||
|
int difference = shop.SushiMaxCount - shop.ShopSushis.Select(x => x.Value.Item2).Sum();
|
||||||
|
int refill = Math.Min(difference, model.Count);
|
||||||
|
model.Count -= refill;
|
||||||
|
if (shop.ShopSushis.ContainsKey(model.SushiId))
|
||||||
|
{
|
||||||
|
var datePair = shop.ShopSushis[model.SushiId];
|
||||||
|
datePair.Item2 += refill;
|
||||||
|
shop.ShopSushis[model.SushiId] = datePair;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var sushi = context.Sushis.First(x => x.Id == model.SushiId);
|
||||||
|
shop.ShopSushis.Add(model.SushiId, (sushi, refill));
|
||||||
|
}
|
||||||
|
shop.SushisDictionatyUpdate(context);
|
||||||
|
if (model.Count == 0)
|
||||||
|
{
|
||||||
|
transaction.Commit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transaction.Rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Sale(SupplySearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new SushiBarDatabase();
|
||||||
|
var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var shops = context.Shops.Include(x => x.Sushis).ThenInclude(x => x.Sushi).ToList().
|
||||||
|
Where(x => x.ShopSushis.ContainsKey(model.SushiId.Value)).OrderByDescending(x => x.ShopSushis[model.SushiId.Value].Item2).ToList();
|
||||||
|
|
||||||
|
foreach (var shop in shops)
|
||||||
|
{
|
||||||
|
int residue = model.Count.Value - shop.ShopSushis[model.SushiId.Value].Item2;
|
||||||
|
if (residue > 0)
|
||||||
|
{
|
||||||
|
shop.ShopSushis.Remove(model.SushiId.Value);
|
||||||
|
shop.SushisDictionatyUpdate(context);
|
||||||
|
context.SaveChanges();
|
||||||
|
model.Count = residue;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (residue == 0)
|
||||||
|
shop.ShopSushis.Remove(model.SushiId.Value);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var dataPair = shop.ShopSushis[model.SushiId.Value];
|
||||||
|
dataPair.Item2 = -residue;
|
||||||
|
shop.ShopSushis[model.SushiId.Value] = dataPair;
|
||||||
|
}
|
||||||
|
|
||||||
|
shop.SushisDictionatyUpdate(context);
|
||||||
|
transaction.Commit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transaction.Rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,298 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
using SushiBarDatabaseImplement;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace SushiBarDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(SushiBarDatabase))]
|
|
||||||
[Migration("20240522110209_InitCreate")]
|
|
||||||
partial class InitCreate
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "7.0.17")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
|
||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDataModels.Models.Implementer", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("ImplementerFIO")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<string>("Password")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<int>("Qualification")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("WorkExperience")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Implementers");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("ClientFIO")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<string>("Email")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<string>("Password")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Clients");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("ComponentName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<double>("Cost")
|
|
||||||
.HasColumnType("float");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Components");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.MessageInfo", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("MessageId")
|
|
||||||
.HasColumnType("nvarchar(450)");
|
|
||||||
|
|
||||||
b.Property<string>("Body")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<int?>("ClientId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<DateTime>("DateDelivery")
|
|
||||||
.HasColumnType("datetime2");
|
|
||||||
|
|
||||||
b.Property<string>("SenderName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<string>("Subject")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.HasKey("MessageId");
|
|
||||||
|
|
||||||
b.HasIndex("ClientId");
|
|
||||||
|
|
||||||
b.ToTable("MessageInfos");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("ClientId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreate")
|
|
||||||
.HasColumnType("datetime2");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("DateImplement")
|
|
||||||
.HasColumnType("datetime2");
|
|
||||||
|
|
||||||
b.Property<int?>("ImplementerId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Status")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<double>("Sum")
|
|
||||||
.HasColumnType("float");
|
|
||||||
|
|
||||||
b.Property<int>("SushiId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ClientId");
|
|
||||||
|
|
||||||
b.HasIndex("ImplementerId");
|
|
||||||
|
|
||||||
b.HasIndex("SushiId");
|
|
||||||
|
|
||||||
b.ToTable("Orders");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<double>("Price")
|
|
||||||
.HasColumnType("float");
|
|
||||||
|
|
||||||
b.Property<string>("SushiName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Sushis");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("ComponentId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("SushiId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ComponentId");
|
|
||||||
|
|
||||||
b.HasIndex("SushiId");
|
|
||||||
|
|
||||||
b.ToTable("SushiComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.MessageInfo", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client")
|
|
||||||
.WithMany("ClientMessages")
|
|
||||||
.HasForeignKey("ClientId");
|
|
||||||
|
|
||||||
b.Navigation("Client");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client")
|
|
||||||
.WithMany("ClientOrders")
|
|
||||||
.HasForeignKey("ClientId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("SushiBarDataModels.Models.Implementer", "Implementer")
|
|
||||||
.WithMany("Order")
|
|
||||||
.HasForeignKey("ImplementerId");
|
|
||||||
|
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
|
|
||||||
.WithMany("Orders")
|
|
||||||
.HasForeignKey("SushiId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Client");
|
|
||||||
|
|
||||||
b.Navigation("Implementer");
|
|
||||||
|
|
||||||
b.Navigation("Sushi");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component")
|
|
||||||
.WithMany("SushiComponents")
|
|
||||||
.HasForeignKey("ComponentId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
|
|
||||||
.WithMany("Components")
|
|
||||||
.HasForeignKey("SushiId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Component");
|
|
||||||
|
|
||||||
b.Navigation("Sushi");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDataModels.Models.Implementer", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Order");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("ClientMessages");
|
|
||||||
|
|
||||||
b.Navigation("ClientOrders");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("SushiComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Components");
|
|
||||||
|
|
||||||
b.Navigation("Orders");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,214 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace SushiBarDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class InitCreate : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Clients",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Clients", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Components",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
Cost = table.Column<double>(type: "float", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Components", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Implementers",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
ImplementerFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
WorkExperience = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Qualification = table.Column<int>(type: "int", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Implementers", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Sushis",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
SushiName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
Price = table.Column<double>(type: "float", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Sushis", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "MessageInfos",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
|
||||||
ClientId = table.Column<int>(type: "int", nullable: true),
|
|
||||||
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
||||||
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
Body = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_MessageInfos", x => x.MessageId);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_MessageInfos_Clients_ClientId",
|
|
||||||
column: x => x.ClientId,
|
|
||||||
principalTable: "Clients",
|
|
||||||
principalColumn: "Id");
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Orders",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
ClientId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
SushiId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Count = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Sum = table.Column<double>(type: "float", nullable: false),
|
|
||||||
Status = table.Column<int>(type: "int", nullable: false),
|
|
||||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
||||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true),
|
|
||||||
ImplementerId = table.Column<int>(type: "int", nullable: true)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Orders_Clients_ClientId",
|
|
||||||
column: x => x.ClientId,
|
|
||||||
principalTable: "Clients",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Orders_Implementers_ImplementerId",
|
|
||||||
column: x => x.ImplementerId,
|
|
||||||
principalTable: "Implementers",
|
|
||||||
principalColumn: "Id");
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Orders_Sushis_SushiId",
|
|
||||||
column: x => x.SushiId,
|
|
||||||
principalTable: "Sushis",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "SushiComponents",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
SushiId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Count = table.Column<int>(type: "int", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_SushiComponents", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_SushiComponents_Components_ComponentId",
|
|
||||||
column: x => x.ComponentId,
|
|
||||||
principalTable: "Components",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_SushiComponents_Sushis_SushiId",
|
|
||||||
column: x => x.SushiId,
|
|
||||||
principalTable: "Sushis",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_MessageInfos_ClientId",
|
|
||||||
table: "MessageInfos",
|
|
||||||
column: "ClientId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Orders_ClientId",
|
|
||||||
table: "Orders",
|
|
||||||
column: "ClientId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Orders_ImplementerId",
|
|
||||||
table: "Orders",
|
|
||||||
column: "ImplementerId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Orders_SushiId",
|
|
||||||
table: "Orders",
|
|
||||||
column: "SushiId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_SushiComponents_ComponentId",
|
|
||||||
table: "SushiComponents",
|
|
||||||
column: "ComponentId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_SushiComponents_SushiId",
|
|
||||||
table: "SushiComponents",
|
|
||||||
column: "SushiId");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "MessageInfos");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Orders");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "SushiComponents");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Clients");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Implementers");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Components");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Sushis");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -109,6 +109,15 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
b.Property<DateTime>("DateDelivery")
|
b.Property<DateTime>("DateDelivery")
|
||||||
.HasColumnType("datetime2");
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<bool>("IsReaded")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<bool>("IsReply")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<string>("ReplyMessageId")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
b.Property<string>("SenderName")
|
b.Property<string>("SenderName")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
@ -121,6 +130,8 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasIndex("ClientId");
|
b.HasIndex("ClientId");
|
||||||
|
|
||||||
|
b.HasIndex("ReplyMessageId");
|
||||||
|
|
||||||
b.ToTable("MessageInfos");
|
b.ToTable("MessageInfos");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -167,6 +178,59 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
b.ToTable("Orders");
|
b.ToTable("Orders");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Adress")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("OpeningDate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("ShopName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int>("SushiMaxCount")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Shops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.ShopSushis", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ShopId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("SushiId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ShopId");
|
||||||
|
|
||||||
|
b.HasIndex("SushiId");
|
||||||
|
|
||||||
|
b.ToTable("ShopSushis");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -219,7 +283,13 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
.WithMany("ClientMessages")
|
.WithMany("ClientMessages")
|
||||||
.HasForeignKey("ClientId");
|
.HasForeignKey("ClientId");
|
||||||
|
|
||||||
|
b.HasOne("SushiBarDatabaseImplement.Models.MessageInfo", "Reply")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ReplyMessageId");
|
||||||
|
|
||||||
b.Navigation("Client");
|
b.Navigation("Client");
|
||||||
|
|
||||||
|
b.Navigation("Reply");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
||||||
@ -247,6 +317,25 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
b.Navigation("Sushi");
|
b.Navigation("Sushi");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.ShopSushis", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SushiBarDatabaseImplement.Models.Shop", "Shop")
|
||||||
|
.WithMany("Sushis")
|
||||||
|
.HasForeignKey("ShopId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("SushiId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Shop");
|
||||||
|
|
||||||
|
b.Navigation("Sushi");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component")
|
b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component")
|
||||||
@ -283,6 +372,11 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
b.Navigation("SushiComponents");
|
b.Navigation("SushiComponents");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Sushis");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Components");
|
b.Navigation("Components");
|
||||||
|
@ -57,9 +57,52 @@ namespace SushiBarDatabaseImplement.Models
|
|||||||
DateDelivery = model.DateDelivery,
|
DateDelivery = model.DateDelivery,
|
||||||
Subject = model.Subject,
|
Subject = model.Subject,
|
||||||
Body = model.Body,
|
Body = model.Body,
|
||||||
|
[Required]
|
||||||
|
public bool IsReaded { get; set; }
|
||||||
|
|
||||||
|
public string? ReplyMessageId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("ReplyMessageId")]
|
||||||
|
public virtual MessageInfo? Reply { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public bool IsReply { get; set; }
|
||||||
|
|
||||||
|
public static MessageInfo? Create(MessageInfoBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
MessageId = model.MessageId,
|
||||||
|
ClientId = model.ClientId,
|
||||||
|
SenderName = model.SenderName,
|
||||||
|
DateDelivery = model.DateDelivery,
|
||||||
|
Subject = model.Subject,
|
||||||
|
Body = model.Body,
|
||||||
|
IsReaded = model.IsReaded,
|
||||||
|
ReplyMessageId = model.ReplyMessageId,
|
||||||
|
IsReply = model.IsReply
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
public void Update(SushiBarDatabase context, MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
IsReaded = model.IsReaded;
|
||||||
|
ReplyMessageId = model.ReplyMessageId;
|
||||||
|
if (!string.IsNullOrEmpty(ReplyMessageId))
|
||||||
|
{
|
||||||
|
Reply = context.MessageInfos.First(x => x.MessageId == ReplyMessageId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public MessageInfoViewModel GetViewModel => new()
|
public MessageInfoViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
@ -71,4 +114,19 @@ namespace SushiBarDatabaseImplement.Models
|
|||||||
Body = Body
|
Body = Body
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
public MessageInfoViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
MessageId = MessageId,
|
||||||
|
ClientId = ClientId,
|
||||||
|
SenderName = SenderName,
|
||||||
|
DateDelivery = DateDelivery,
|
||||||
|
Subject = Subject,
|
||||||
|
Body = Body,
|
||||||
|
IsReaded = IsReaded,
|
||||||
|
ReplyMessageId = ReplyMessageId,
|
||||||
|
Reply = Reply,
|
||||||
|
IsReply = IsReply
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
119
SushiBar/SushiBarDatabaseImplement/Models/Shop.cs
Normal file
119
SushiBar/SushiBarDatabaseImplement/Models/Shop.cs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : 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; }
|
||||||
|
|
||||||
|
public int SushiMaxCount { get; set; }
|
||||||
|
|
||||||
|
private Dictionary<int, (ISushiModel, int)>? _shopSushis = null;
|
||||||
|
|
||||||
|
public Dictionary<int, (ISushiModel, int)> ShopSushis
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopSushis == null)
|
||||||
|
{
|
||||||
|
if (_shopSushis == null)
|
||||||
|
{
|
||||||
|
_shopSushis = Sushis
|
||||||
|
.ToDictionary(recSP => recSP.SushiId, recSP => (recSP.Sushi as ISushiModel, recSP.Count));
|
||||||
|
}
|
||||||
|
return _shopSushis;
|
||||||
|
}
|
||||||
|
return _shopSushis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ForeignKey("ShopId")]
|
||||||
|
public List<ShopSushis> Sushis { get; set; } = new();
|
||||||
|
|
||||||
|
public static Shop Create(SushiBarDatabase context, ShopBindingModel model)
|
||||||
|
{
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
Adress = model.Adress,
|
||||||
|
OpeningDate = model.OpeningDate,
|
||||||
|
Sushis = model.ShopSushis.Select(x => new ShopSushis
|
||||||
|
{
|
||||||
|
Sushi = context.Sushis.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList(),
|
||||||
|
SushiMaxCount = model.SushiMaxCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Adress = model.Adress;
|
||||||
|
OpeningDate = model.OpeningDate;
|
||||||
|
SushiMaxCount = model.SushiMaxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Adress = Adress,
|
||||||
|
OpeningDate = OpeningDate,
|
||||||
|
ShopSushis = ShopSushis,
|
||||||
|
SushiMaxCount = SushiMaxCount
|
||||||
|
};
|
||||||
|
|
||||||
|
public void UpdateSushis(SushiBarDatabase context, ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var ShopSushis = context.ShopSushis.Where(rec => rec.ShopId == model.Id).ToList();
|
||||||
|
if (ShopSushis != null && ShopSushis.Count > 0)
|
||||||
|
{
|
||||||
|
context.ShopSushis.RemoveRange(ShopSushis.Where(rec => !model.ShopSushis.ContainsKey(rec.SushiId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
ShopSushis = context.ShopSushis.Where(rec => rec.ShopId == model.Id).ToList();
|
||||||
|
foreach (var updateSushi in ShopSushis)
|
||||||
|
{
|
||||||
|
updateSushi.Count = model.ShopSushis[updateSushi.SushiId].Item2;
|
||||||
|
model.ShopSushis.Remove(updateSushi.SushiId);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var shop = context.Shops.First(x => x.Id == Id);
|
||||||
|
foreach (var ar in model.ShopSushis)
|
||||||
|
{
|
||||||
|
context.ShopSushis.Add(new ShopSushis
|
||||||
|
{
|
||||||
|
Shop = shop,
|
||||||
|
Sushi = context.Sushis.First(x => x.Id == ar.Key),
|
||||||
|
Count = ar.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_shopSushis = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SushisDictionatyUpdate(SushiBarDatabase context)
|
||||||
|
{
|
||||||
|
UpdateSushis(context, new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopSushis = ShopSushis,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
SushiBar/SushiBarDatabaseImplement/Models/ShopSushis.cs
Normal file
28
SushiBar/SushiBarDatabaseImplement/Models/ShopSushis.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using SushiBarDatabaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class ShopSushis
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int SushiId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int ShopId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
public virtual Shop Shop { get; set; } = new();
|
||||||
|
|
||||||
|
public virtual Sushi Sushi { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@
|
|||||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||||
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
|
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
|
||||||
<ProjectReference Include="..\SushiBarListImplement_\SushiBarListImplement.csproj" />
|
<ProjectReference Include="..\SushiBarListImplement_\SushiBarListImplement.csproj" />
|
||||||
|
<ProjectReference Include="..\SushiBarFileImplement\SushiBarFileImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||||
|
@ -25,6 +25,8 @@ namespace SushiBarDatabaseImplement
|
|||||||
public virtual DbSet<Order> Orders { set; get; }
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
public virtual DbSet<Client> Clients { set; get; }
|
public virtual DbSet<Client> Clients { set; get; }
|
||||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||||
|
public virtual DbSet<Shop> Shops { get; set; }
|
||||||
|
public virtual DbSet<ShopSushis> ShopSushis { get; set; }
|
||||||
public virtual DbSet<MessageInfo> MessageInfos { set; get; }
|
public virtual DbSet<MessageInfo> MessageInfos { set; get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ namespace SushiBarFileImplement
|
|||||||
private readonly string SushiFileName = "Sushi.xml";
|
private readonly string SushiFileName = "Sushi.xml";
|
||||||
private readonly string ClientFileName = "Client.xml";
|
private readonly string ClientFileName = "Client.xml";
|
||||||
private readonly string ImplementerFileName = "Implementer.xml";
|
private readonly string ImplementerFileName = "Implementer.xml";
|
||||||
|
private readonly string ShopFileName = "Shop.xml";
|
||||||
private readonly string MessageInfoFileName = "MessageInfo.xml";
|
private readonly string MessageInfoFileName = "MessageInfo.xml";
|
||||||
public List<Component> Components { get; private set; }
|
public List<Component> Components { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
@ -23,6 +24,7 @@ namespace SushiBarFileImplement
|
|||||||
public List<Client> Clients { get; private set; }
|
public List<Client> Clients { get; private set; }
|
||||||
public List<Implementer> Implementers { get; private set; }
|
public List<Implementer> Implementers { get; private set; }
|
||||||
public List<MessageInfo> Messages { get; private set; }
|
public List<MessageInfo> Messages { get; private set; }
|
||||||
|
public List<Shop> Shops { get; private set; }
|
||||||
|
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
@ -38,6 +40,7 @@ namespace SushiBarFileImplement
|
|||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||||
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
|
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||||
|
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||||
public void SaveMessages() => SaveData(Orders, ImplementerFileName, "Messages", x => x.GetXElement);
|
public void SaveMessages() => SaveData(Orders, ImplementerFileName, "Messages", x => x.GetXElement);
|
||||||
|
|
||||||
private DataFileSingleton()
|
private DataFileSingleton()
|
||||||
@ -48,6 +51,7 @@ namespace SushiBarFileImplement
|
|||||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||||
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
||||||
Messages = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!;
|
Messages = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!;
|
||||||
|
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
|
@ -30,10 +30,12 @@ namespace SushiBarFileImplement.Implements
|
|||||||
|
|
||||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||||
{
|
{
|
||||||
return _source.Messages
|
var res = _source.Messages.Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId).Select(x => x.GetViewModel);
|
||||||
.Where(x => x.ClientId == model.ClientId)
|
if (!(model.PageIndex.HasValue && model.PageLength.HasValue))
|
||||||
.Select(x => x.GetViewModel)
|
{
|
||||||
.ToList();
|
return res.ToList();
|
||||||
|
}
|
||||||
|
return res.Skip((model.PageIndex.Value - 1) * model.PageLength.Value).Take(model.PageLength.Value).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MessageInfoViewModel> GetFullList()
|
public List<MessageInfoViewModel> GetFullList()
|
||||||
@ -54,5 +56,16 @@ namespace SushiBarFileImplement.Implements
|
|||||||
_source.SaveMessages();
|
_source.SaveMessages();
|
||||||
return newMessage.GetViewModel;
|
return newMessage.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
var res = _source.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId));
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
res.Update(model);
|
||||||
|
_source.SaveMessages();
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
154
SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs
Normal file
154
SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SushiBarFileImplement.Models;
|
||||||
|
|
||||||
|
namespace SushiBarFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Shops.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Shops.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newShop = Shop.Create(model);
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Shops.Add(newShop);
|
||||||
|
source.SaveShops();
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
shop.Update(model);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop != null)
|
||||||
|
{
|
||||||
|
source.Shops.Remove(shop);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Sale(SupplySearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null || !model.SushiId.HasValue || !model.Count.HasValue)
|
||||||
|
return false;
|
||||||
|
int remainingSpace = source.Shops.Select(x => x.Sushis.ContainsKey(model.SushiId.Value) ? x.Sushis[model.SushiId.Value] : 0).Sum();
|
||||||
|
if (remainingSpace < model.Count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var shops = source.Shops.Where(x => x.Sushis.ContainsKey(model.SushiId.Value)).OrderByDescending(x => x.Sushis[model.SushiId.Value]).ToList();
|
||||||
|
foreach (var shop in shops)
|
||||||
|
{
|
||||||
|
int residue = model.Count.Value - shop.Sushis[model.SushiId.Value];
|
||||||
|
if (residue > 0)
|
||||||
|
{
|
||||||
|
shop.Sushis.Remove(model.SushiId.Value);
|
||||||
|
shop.SushisUpdate();
|
||||||
|
model.Count = residue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (residue == 0)
|
||||||
|
{
|
||||||
|
shop.Sushis.Remove(model.SushiId.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shop.Sushis[model.SushiId.Value] = -residue;
|
||||||
|
}
|
||||||
|
shop.SushisUpdate();
|
||||||
|
source.SaveShops();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
source.SaveShops();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RestockingShops(SupplyBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null || source.Shops.Select(x => x.SushiMaxCount - x.ShopSushis.Select(y => y.Value.Item2).Sum()).Sum() < model.Count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach (Shop shop in source.Shops)
|
||||||
|
{
|
||||||
|
int free_places = shop.SushiMaxCount - shop.ShopSushis.Select(x => x.Value.Item2).Sum();
|
||||||
|
if (free_places <= 0)
|
||||||
|
continue;
|
||||||
|
free_places = Math.Min(free_places, model.Count);
|
||||||
|
model.Count -= free_places;
|
||||||
|
if (shop.Sushis.ContainsKey(model.SushiId))
|
||||||
|
{
|
||||||
|
shop.Sushis[model.SushiId] += free_places;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shop.Sushis.Add(model.SushiId, free_places);
|
||||||
|
}
|
||||||
|
shop.SushisUpdate();
|
||||||
|
if (model.Count == 0)
|
||||||
|
{
|
||||||
|
source.SaveShops();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,9 @@ namespace SushiBarFileImplement.Models
|
|||||||
public string Subject { get; private set; } = string.Empty;
|
public string Subject { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public string Body { get; private set; } = string.Empty;
|
public string Body { get; private set; } = string.Empty;
|
||||||
|
public bool IsReaded { get; private set; }
|
||||||
|
public bool IsReply { get; private set; }
|
||||||
|
public string? ReplyMessageId { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||||
{
|
{
|
||||||
@ -33,11 +36,14 @@ namespace SushiBarFileImplement.Models
|
|||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Body = model.Body,
|
Body = model.Body,
|
||||||
|
IsReply = model.IsReply,
|
||||||
|
IsReaded = model.IsReaded,
|
||||||
Subject = model.Subject,
|
Subject = model.Subject,
|
||||||
ClientId = model.ClientId,
|
ClientId = model.ClientId,
|
||||||
MessageId = model.MessageId,
|
MessageId = model.MessageId,
|
||||||
SenderName = model.SenderName,
|
SenderName = model.SenderName,
|
||||||
DateDelivery = model.DateDelivery,
|
DateDelivery = model.DateDelivery,
|
||||||
|
ReplyMessageId = model.ReplyMessageId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,33 +56,50 @@ namespace SushiBarFileImplement.Models
|
|||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Body = element.Attribute("Body")!.Value,
|
Body = element.Attribute("Body")!.Value,
|
||||||
|
IsReply = Convert.ToBoolean(element.Attribute("IsReply")!.Value),
|
||||||
|
IsReaded = Convert.ToBoolean(element.Attribute("HasRead")!.Value),
|
||||||
Subject = element.Attribute("Subject")!.Value,
|
Subject = element.Attribute("Subject")!.Value,
|
||||||
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
||||||
MessageId = element.Attribute("MessageId")!.Value,
|
MessageId = element.Attribute("MessageId")!.Value,
|
||||||
|
ReplyMessageId = element.Attribute("ReplyMessageId")!.Value,
|
||||||
SenderName = element.Attribute("SenderName")!.Value,
|
SenderName = element.Attribute("SenderName")!.Value,
|
||||||
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
|
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Update(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
IsReply = model.IsReply;
|
||||||
|
IsReaded = model.IsReaded;
|
||||||
|
}
|
||||||
|
|
||||||
public MessageInfoViewModel GetViewModel => new()
|
public MessageInfoViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Body = Body,
|
Body = Body,
|
||||||
|
IsReply = IsReply,
|
||||||
|
IsReaded = IsReaded,
|
||||||
Subject = Subject,
|
Subject = Subject,
|
||||||
ClientId = ClientId,
|
ClientId = ClientId,
|
||||||
MessageId = MessageId,
|
MessageId = MessageId,
|
||||||
SenderName = SenderName,
|
SenderName = SenderName,
|
||||||
DateDelivery = DateDelivery,
|
DateDelivery = DateDelivery,
|
||||||
|
ReplyMessageId = ReplyMessageId,
|
||||||
};
|
};
|
||||||
|
|
||||||
public XElement GetXElement => new("MessageInfo",
|
public XElement GetXElement => new("MessageInfo",
|
||||||
new XAttribute("Body", Body),
|
new XAttribute("Body", Body),
|
||||||
|
new XAttribute("IsReply", IsReply),
|
||||||
|
new XAttribute("IsReaded", IsReaded),
|
||||||
new XAttribute("Subject", Subject),
|
new XAttribute("Subject", Subject),
|
||||||
new XAttribute("ClientId", ClientId),
|
new XAttribute("ClientId", ClientId),
|
||||||
new XAttribute("MessageId", MessageId),
|
new XAttribute("MessageId", MessageId),
|
||||||
|
new XAttribute("ReplyMessageId", ReplyMessageId),
|
||||||
new XAttribute("SenderName", SenderName),
|
new XAttribute("SenderName", SenderName),
|
||||||
new XAttribute("DateDelivery", DateDelivery)
|
new XAttribute("DateDelivery", DateDelivery)
|
||||||
);
|
);
|
||||||
|
|
||||||
public int Id => throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
112
SushiBar/SushiBarFileImplement/Models/Shop.cs
Normal file
112
SushiBar/SushiBarFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
using SushiBarDataModels.Models;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using SushiBarFileImplement;
|
||||||
|
|
||||||
|
namespace SushiBarFileImplement.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, int> Sushis { get; private set; } = new();
|
||||||
|
private Dictionary<int, (ISushiModel, int)>? _shopSushis = null;
|
||||||
|
|
||||||
|
public Dictionary<int, (ISushiModel, int)> ShopSushis
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopSushis == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_shopSushis = Sushis.ToDictionary(x => x.Key, y => ((source.Sushis.FirstOrDefault(z => z.Id == y.Key) as ISushiModel)!, y.Value));
|
||||||
|
}
|
||||||
|
return _shopSushis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int SushiMaxCount { 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,
|
||||||
|
Sushis = model.ShopSushis.ToDictionary(x => x.Key, x => x.Value.Item2),
|
||||||
|
SushiMaxCount = model.SushiMaxCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Shop? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ShopName = element.Element("ShopName")!.Value,
|
||||||
|
Adress = element.Element("Adress")!.Value,
|
||||||
|
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||||
|
Sushis = element.Element("ShopSushis")!.Elements("ShopSushi")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||||
|
x => Convert.ToInt32(x.Element("Value")?.Value)),
|
||||||
|
SushiMaxCount = Convert.ToInt32(element.Element("SushiMaxCount")!.Value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Adress = model.Adress;
|
||||||
|
OpeningDate = model.OpeningDate;
|
||||||
|
SushiMaxCount = model.SushiMaxCount;
|
||||||
|
Sushis = model.ShopSushis.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_shopSushis = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Adress = Adress,
|
||||||
|
OpeningDate = OpeningDate,
|
||||||
|
ShopSushis = ShopSushis,
|
||||||
|
SushiMaxCount = SushiMaxCount
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Shop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ShopName", ShopName),
|
||||||
|
new XElement("Adress", Adress),
|
||||||
|
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||||
|
new XElement("ShopSushis", Sushis.Select(
|
||||||
|
x => new XElement("ShopSushi", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()),
|
||||||
|
new XElement("SushiMaxCount", SushiMaxCount.ToString())
|
||||||
|
);
|
||||||
|
|
||||||
|
public void SushisUpdate()
|
||||||
|
{
|
||||||
|
_shopSushis = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,7 @@ namespace SushiBarListImplement
|
|||||||
public List<Client> Clients { get; set; }
|
public List<Client> Clients { get; set; }
|
||||||
public List<Implementer> Implementers { get; set; }
|
public List<Implementer> Implementers { get; set; }
|
||||||
public List<MessageInfo> Messages { get; set; }
|
public List<MessageInfo> Messages { get; set; }
|
||||||
|
public List<Shop> Shops { get; set; }
|
||||||
private DataListSingleton()
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Components = new List<Component>();
|
Components = new List<Component>();
|
||||||
@ -24,6 +25,7 @@ namespace SushiBarListImplement
|
|||||||
Clients = new List<Client>();
|
Clients = new List<Client>();
|
||||||
Implementers = new List<Implementer>();
|
Implementers = new List<Implementer>();
|
||||||
Messages = new List<MessageInfo>();
|
Messages = new List<MessageInfo>();
|
||||||
|
Shops = new List<Shop>();
|
||||||
}
|
}
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
|
@ -21,14 +21,14 @@ namespace SushiBarListImplement.Implements
|
|||||||
_source = DataListSingleton.GetInstance();
|
_source = DataListSingleton.GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MessageInfoViewModel> GetFullList()
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||||
{
|
{
|
||||||
List<MessageInfoViewModel> result = new();
|
foreach (var message in _source.Messages)
|
||||||
foreach (var item in _source.Messages)
|
|
||||||
{
|
{
|
||||||
result.Add(item.GetViewModel);
|
if (model.MessageId != null && model.MessageId.Equals(message.MessageId))
|
||||||
|
return message.GetViewModel;
|
||||||
}
|
}
|
||||||
return result;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||||
@ -41,20 +41,32 @@ namespace SushiBarListImplement.Implements
|
|||||||
result.Add(item.GetViewModel);
|
result.Add(item.GetViewModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(model.PageIndex.HasValue && model.PageLength.HasValue))
|
||||||
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
if (model.PageIndex * model.PageLength >= result.Count)
|
||||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
|
||||||
{
|
{
|
||||||
foreach (var message in _source.Messages)
|
|
||||||
{
|
|
||||||
if (model.MessageId != null && model.MessageId.Equals(message.MessageId))
|
|
||||||
{
|
|
||||||
return message.GetViewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
List<MessageInfoViewModel> filteredResult = new();
|
||||||
|
for (var i = (model.PageIndex.Value - 1) * model.PageLength.Value; i < model.PageIndex.Value * model.PageLength.Value; i++)
|
||||||
|
{
|
||||||
|
filteredResult.Add(result[i]);
|
||||||
|
}
|
||||||
|
return filteredResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MessageInfoViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
List<MessageInfoViewModel> result = new();
|
||||||
|
foreach (var item in _source.Messages)
|
||||||
|
{
|
||||||
|
result.Add(item.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||||
{
|
{
|
||||||
@ -66,5 +78,18 @@ namespace SushiBarListImplement.Implements
|
|||||||
_source.Messages.Add(newMessage);
|
_source.Messages.Add(newMessage);
|
||||||
return newMessage.GetViewModel;
|
return newMessage.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var message in _source.Messages)
|
||||||
|
{
|
||||||
|
if (message.MessageId.Equals(model.MessageId))
|
||||||
|
{
|
||||||
|
message.Update(model);
|
||||||
|
return message.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
123
SushiBar/SushiBarListImplement_/Implements/ShopStorage.cs
Normal file
123
SushiBar/SushiBarListImplement_/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SushiBarListImplement.Models;
|
||||||
|
|
||||||
|
namespace SushiBarListImplement.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,9 @@ namespace SushiBarListImplement.Models
|
|||||||
public string Subject { get; private set; } = string.Empty;
|
public string Subject { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public string Body { get; private set; } = string.Empty;
|
public string Body { get; private set; } = string.Empty;
|
||||||
|
public bool IsReaded { get; private set; }
|
||||||
|
public bool IsReply { get; private set; }
|
||||||
|
public string? ReplyMessageId { get; private set; }
|
||||||
|
|
||||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||||
{
|
{
|
||||||
@ -32,24 +35,38 @@ namespace SushiBarListImplement.Models
|
|||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Body = model.Body,
|
Body = model.Body,
|
||||||
|
IsReply = model.IsReply,
|
||||||
|
IsReaded = model.IsReaded,
|
||||||
Subject = model.Subject,
|
Subject = model.Subject,
|
||||||
ClientId = model.ClientId,
|
ClientId = model.ClientId,
|
||||||
MessageId = model.MessageId,
|
MessageId = model.MessageId,
|
||||||
SenderName = model.SenderName,
|
SenderName = model.SenderName,
|
||||||
DateDelivery = model.DateDelivery,
|
DateDelivery = model.DateDelivery,
|
||||||
|
ReplyMessageId = model.ReplyMessageId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Update(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
IsReply = model.IsReply;
|
||||||
|
IsReaded = model.IsReaded;
|
||||||
|
}
|
||||||
|
|
||||||
public MessageInfoViewModel GetViewModel => new()
|
public MessageInfoViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Body = Body,
|
Body = Body,
|
||||||
|
IsReply = IsReply,
|
||||||
|
IsReaded = IsReaded,
|
||||||
Subject = Subject,
|
Subject = Subject,
|
||||||
ClientId = ClientId,
|
ClientId = ClientId,
|
||||||
MessageId = MessageId,
|
MessageId = MessageId,
|
||||||
SenderName = SenderName,
|
SenderName = SenderName,
|
||||||
DateDelivery = DateDelivery,
|
DateDelivery = DateDelivery,
|
||||||
|
ReplyMessageId = ReplyMessageId,
|
||||||
};
|
};
|
||||||
|
|
||||||
public int Id => throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
59
SushiBar/SushiBarListImplement_/Models/Shop.cs
Normal file
59
SushiBar/SushiBarListImplement_/Models/Shop.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SushiBarListImplement.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, (ISushiModel, int)> ShopSushis { get; private set; } = new();
|
||||||
|
public int SushiMaxCount { 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,
|
||||||
|
SushiMaxCount = model.SushiMaxCount,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Adress = model.Adress;
|
||||||
|
OpeningDate = model.OpeningDate;
|
||||||
|
SushiMaxCount = model.SushiMaxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Adress = Adress,
|
||||||
|
OpeningDate = OpeningDate,
|
||||||
|
ShopSushis = ShopSushis,
|
||||||
|
SushiMaxCount = SushiMaxCount,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
12
SushiBar/SushiBarRestApi/APIConfig.cs
Normal file
12
SushiBar/SushiBarRestApi/APIConfig.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
namespace SushiBarRestApi
|
||||||
|
{
|
||||||
|
public class APIConfig
|
||||||
|
{
|
||||||
|
public static string? ShopPassword;
|
||||||
|
|
||||||
|
public static void LoadData(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
ShopPassword = configuration["ShopAPIPassword"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,9 @@ namespace SushiBarRestApi.Controllers
|
|||||||
public class ClientController : Controller
|
public class ClientController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly IClientLogic _logic;
|
private readonly IClientLogic _logic;
|
||||||
|
|
||||||
private readonly IMessageInfoLogic _mailLogic;
|
private readonly IMessageInfoLogic _mailLogic;
|
||||||
|
|
||||||
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
|
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
|
||||||
@ -25,6 +27,7 @@ namespace SushiBarRestApi.Controllers
|
|||||||
_logic = logic;
|
_logic = logic;
|
||||||
_mailLogic = mailLogic;
|
_mailLogic = mailLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ClientViewModel? Login(string login, string password)
|
public ClientViewModel? Login(string login, string password)
|
||||||
{
|
{
|
||||||
@ -42,6 +45,7 @@ namespace SushiBarRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Register(ClientBindingModel model)
|
public void Register(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
@ -55,6 +59,7 @@ namespace SushiBarRestApi.Controllers
|
|||||||
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
|
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void UpdateData(ClientBindingModel model)
|
public void UpdateData(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
@ -68,14 +73,17 @@ namespace SushiBarRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
public List<MessageInfoViewModel>? GetMessages(int clientId, int page, int pagesize = 1)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||||
{
|
{
|
||||||
ClientId = clientId
|
ClientId = clientId,
|
||||||
|
PageLength = pagesize,
|
||||||
|
PageIndex = page
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -84,7 +92,5 @@ namespace SushiBarRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
156
SushiBar/SushiBarRestApi/Controllers/ShopController.cs
Normal file
156
SushiBar/SushiBarRestApi/Controllers/ShopController.cs
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace SushiBarRestApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
public class ShopController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _shopLogic;
|
||||||
|
|
||||||
|
public ShopController(ILogger<ShopController> logger, IShopLogic shopLogic)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public bool Authentication(string password)
|
||||||
|
{
|
||||||
|
return CheckPassword(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<ShopViewModel>? GetShopList(string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _shopLogic.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public ShopSushiViewModel? GetShop(int shopId, string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var shop = _shopLogic.ReadElement(new ShopSearchModel { Id = shopId });
|
||||||
|
return new ShopSushiViewModel
|
||||||
|
{
|
||||||
|
Shop = shop,
|
||||||
|
ShopSushi = shop.ShopSushis.ToDictionary(x => x.Key, x => new SushiCount
|
||||||
|
{
|
||||||
|
Sushi = new SushiViewModel()
|
||||||
|
{
|
||||||
|
Id = x.Value.Item1.Id,
|
||||||
|
SushiName = x.Value.Item1.SushiName,
|
||||||
|
SushiComponents = x.Value.Item1.SushiComponents,
|
||||||
|
Price = x.Value.Item1.Price,
|
||||||
|
},
|
||||||
|
Count = x.Value.Item2
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения магазина");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateShop(ShopBindingModel model, string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_shopLogic.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания магазина");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateShop(ShopBindingModel model, string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_shopLogic.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления магазина");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteShop(int shopId, string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_shopLogic.Delete(new ShopBindingModel { Id = shopId });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления магазина");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void MakeSypply(SupplyBindingModel model, string password)
|
||||||
|
{
|
||||||
|
if (!CheckPassword(password))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_shopLogic.MakeSupply(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания поставки в магазин");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckPassword(string password)
|
||||||
|
{
|
||||||
|
return APIConfig.ShopPassword == password;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ using SushiBarBusinessLogic.BusinessLogics;
|
|||||||
using SushiBarContracts.BusinessLogicsContracts;
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
using SushiBarContracts.StoragesContracts;
|
using SushiBarContracts.StoragesContracts;
|
||||||
using SushiBarDatabaseImplement.Implements;
|
using SushiBarDatabaseImplement.Implements;
|
||||||
|
using SushiBarRestApi;
|
||||||
using SushiBarBusinessLogic.MailWorker;
|
using SushiBarBusinessLogic.MailWorker;
|
||||||
using SushiBarContracts.BindingModels;
|
using SushiBarContracts.BindingModels;
|
||||||
|
|
||||||
@ -14,11 +15,13 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|
||||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||||
|
builder.Services.AddTransient<IShopStorage, ShopStorage>();
|
||||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
builder.Services.AddTransient<ISushiStorage, SushiStorage>();
|
builder.Services.AddTransient<ISushiStorage, SushiStorage>();
|
||||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
builder.Services.AddTransient<ISushiLogic, SushiLogic>();
|
builder.Services.AddTransient<ISushiLogic, SushiLogic>();
|
||||||
|
builder.Services.AddTransient<IShopLogic, ShopLogic>();
|
||||||
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||||
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||||
builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||||
|
143
SushiBar/SushiBarView/FormCreateSupply.Designer.cs
generated
Normal file
143
SushiBar/SushiBarView/FormCreateSupply.Designer.cs
generated
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
namespace SushiBarView
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
this.comboBoxShop = new System.Windows.Forms.ComboBox();
|
||||||
|
this.labelShop = new System.Windows.Forms.Label();
|
||||||
|
this.labelSushi = new System.Windows.Forms.Label();
|
||||||
|
this.comboBoxSushi = new System.Windows.Forms.ComboBox();
|
||||||
|
this.labelCount = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// comboBoxShop
|
||||||
|
//
|
||||||
|
this.comboBoxShop.FormattingEnabled = true;
|
||||||
|
this.comboBoxShop.Location = new System.Drawing.Point(115, 12);
|
||||||
|
this.comboBoxShop.Name = "comboBoxShop";
|
||||||
|
this.comboBoxShop.Size = new System.Drawing.Size(344, 28);
|
||||||
|
this.comboBoxShop.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// labelShop
|
||||||
|
//
|
||||||
|
this.labelShop.AutoSize = true;
|
||||||
|
this.labelShop.Location = new System.Drawing.Point(12, 15);
|
||||||
|
this.labelShop.Name = "labelShop";
|
||||||
|
this.labelShop.Size = new System.Drawing.Size(76, 20);
|
||||||
|
this.labelShop.TabIndex = 1;
|
||||||
|
this.labelShop.Text = "Магазин: ";
|
||||||
|
//
|
||||||
|
// labelSushi
|
||||||
|
//
|
||||||
|
this.labelSushi.AutoSize = true;
|
||||||
|
this.labelSushi.Location = new System.Drawing.Point(12, 49);
|
||||||
|
this.labelSushi.Name = "labelSushi";
|
||||||
|
this.labelSushi.Size = new System.Drawing.Size(75, 20);
|
||||||
|
this.labelSushi.TabIndex = 2;
|
||||||
|
this.labelSushi.Text = "Изделие: ";
|
||||||
|
//
|
||||||
|
// comboBoxSushi
|
||||||
|
//
|
||||||
|
this.comboBoxSushi.FormattingEnabled = true;
|
||||||
|
this.comboBoxSushi.Location = new System.Drawing.Point(115, 46);
|
||||||
|
this.comboBoxSushi.Name = "comboBoxSushi";
|
||||||
|
this.comboBoxSushi.Size = new System.Drawing.Size(344, 28);
|
||||||
|
this.comboBoxSushi.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
this.labelCount.AutoSize = true;
|
||||||
|
this.labelCount.Location = new System.Drawing.Point(12, 83);
|
||||||
|
this.labelCount.Name = "labelCount";
|
||||||
|
this.labelCount.Size = new System.Drawing.Size(97, 20);
|
||||||
|
this.labelCount.TabIndex = 4;
|
||||||
|
this.labelCount.Text = "Количество: ";
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
this.textBoxCount.Location = new System.Drawing.Point(115, 80);
|
||||||
|
this.textBoxCount.Name = "textBoxCount";
|
||||||
|
this.textBoxCount.Size = new System.Drawing.Size(344, 27);
|
||||||
|
this.textBoxCount.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(300, 113);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(116, 39);
|
||||||
|
this.buttonCancel.TabIndex = 6;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(168, 113);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(116, 39);
|
||||||
|
this.buttonSave.TabIndex = 7;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// FormCreateSupply
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(471, 164);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.textBoxCount);
|
||||||
|
this.Controls.Add(this.labelCount);
|
||||||
|
this.Controls.Add(this.comboBoxSushi);
|
||||||
|
this.Controls.Add(this.labelSushi);
|
||||||
|
this.Controls.Add(this.labelShop);
|
||||||
|
this.Controls.Add(this.comboBoxShop);
|
||||||
|
this.Name = "FormCreateSupply";
|
||||||
|
this.Text = "Создание поставки";
|
||||||
|
this.Load += new System.EventHandler(this.FormCreateSupply_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private ComboBox comboBoxShop;
|
||||||
|
private Label labelShop;
|
||||||
|
private Label labelSushi;
|
||||||
|
private ComboBox comboBoxSushi;
|
||||||
|
private Label labelCount;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSave;
|
||||||
|
}
|
||||||
|
}
|
99
SushiBar/SushiBarView/FormCreateSupply.cs
Normal file
99
SushiBar/SushiBarView/FormCreateSupply.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
|
using SushiBarContracts.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 SushiBarView
|
||||||
|
{
|
||||||
|
public partial class FormCreateSupply : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ISushiLogic _logicP;
|
||||||
|
private readonly IShopLogic _logicS;
|
||||||
|
private List<ShopViewModel> _shopList = new List<ShopViewModel>();
|
||||||
|
private List<SushiViewModel> _sushiList = new List<SushiViewModel>();
|
||||||
|
|
||||||
|
public FormCreateSupply(ILogger<FormCreateSupply> logger, ISushiLogic logicP, IShopLogic logicS)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicP = logicP;
|
||||||
|
_logicS = logicS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormCreateSupply_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_shopList = _logicS.ReadList(null);
|
||||||
|
_sushiList = _logicP.ReadList(null);
|
||||||
|
if (_shopList != null)
|
||||||
|
{
|
||||||
|
comboBoxShop.DisplayMember = "ShopName";
|
||||||
|
comboBoxShop.ValueMember = "Id";
|
||||||
|
comboBoxShop.DataSource = _shopList;
|
||||||
|
comboBoxShop.SelectedItem = null;
|
||||||
|
_logger.LogInformation("Загрузка магазинов для поставок");
|
||||||
|
}
|
||||||
|
if (_sushiList != null)
|
||||||
|
{
|
||||||
|
comboBoxSushi.DisplayMember = "SushiName";
|
||||||
|
comboBoxSushi.ValueMember = "Id";
|
||||||
|
comboBoxSushi.DataSource = _sushiList;
|
||||||
|
comboBoxSushi.SelectedItem = null;
|
||||||
|
_logger.LogInformation("Загрузка суши для поставок");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxShop.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxSushi.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Создание поставки");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicS.MakeSupply(new SupplyBindingModel
|
||||||
|
{
|
||||||
|
ShopId = Convert.ToInt32(comboBoxShop.SelectedValue),
|
||||||
|
SushiId = Convert.ToInt32(comboBoxSushi.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
SushiBar/SushiBarView/FormCreateSupply.resx
Normal file
120
SushiBar/SushiBarView/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>
|
182
SushiBar/SushiBarView/FormLetter.Designer.cs
generated
Normal file
182
SushiBar/SushiBarView/FormLetter.Designer.cs
generated
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
namespace SushiBarView
|
||||||
|
{
|
||||||
|
partial class FormLetter
|
||||||
|
{
|
||||||
|
/// <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.textBoxEmail = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelAdress = new System.Windows.Forms.Label();
|
||||||
|
this.labelSubject = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxSubject = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelBody = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxBody = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonClose = new System.Windows.Forms.Button();
|
||||||
|
this.buttonReply = new System.Windows.Forms.Button();
|
||||||
|
this.labelDate = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxDate = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonSend = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// textBoxEmail
|
||||||
|
//
|
||||||
|
this.textBoxEmail.Location = new System.Drawing.Point(72, 6);
|
||||||
|
this.textBoxEmail.Name = "textBoxEmail";
|
||||||
|
this.textBoxEmail.ReadOnly = true;
|
||||||
|
this.textBoxEmail.Size = new System.Drawing.Size(186, 27);
|
||||||
|
this.textBoxEmail.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// labelAdress
|
||||||
|
//
|
||||||
|
this.labelAdress.AutoSize = true;
|
||||||
|
this.labelAdress.Location = new System.Drawing.Point(12, 9);
|
||||||
|
this.labelAdress.Name = "labelAdress";
|
||||||
|
this.labelAdress.Size = new System.Drawing.Size(54, 20);
|
||||||
|
this.labelAdress.TabIndex = 1;
|
||||||
|
this.labelAdress.Text = "Адрес:";
|
||||||
|
//
|
||||||
|
// labelSubject
|
||||||
|
//
|
||||||
|
this.labelSubject.AutoSize = true;
|
||||||
|
this.labelSubject.Location = new System.Drawing.Point(12, 55);
|
||||||
|
this.labelSubject.Name = "labelSubject";
|
||||||
|
this.labelSubject.Size = new System.Drawing.Size(47, 20);
|
||||||
|
this.labelSubject.TabIndex = 2;
|
||||||
|
this.labelSubject.Text = "Тема:";
|
||||||
|
//
|
||||||
|
// textBoxSubject
|
||||||
|
//
|
||||||
|
this.textBoxSubject.Location = new System.Drawing.Point(72, 52);
|
||||||
|
this.textBoxSubject.Name = "textBoxSubject";
|
||||||
|
this.textBoxSubject.ReadOnly = true;
|
||||||
|
this.textBoxSubject.Size = new System.Drawing.Size(552, 27);
|
||||||
|
this.textBoxSubject.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// labelBody
|
||||||
|
//
|
||||||
|
this.labelBody.AutoSize = true;
|
||||||
|
this.labelBody.Location = new System.Drawing.Point(12, 96);
|
||||||
|
this.labelBody.Name = "labelBody";
|
||||||
|
this.labelBody.Size = new System.Drawing.Size(104, 20);
|
||||||
|
this.labelBody.TabIndex = 4;
|
||||||
|
this.labelBody.Text = "Текст письма:";
|
||||||
|
//
|
||||||
|
// textBoxBody
|
||||||
|
//
|
||||||
|
this.textBoxBody.Location = new System.Drawing.Point(12, 119);
|
||||||
|
this.textBoxBody.Multiline = true;
|
||||||
|
this.textBoxBody.Name = "textBoxBody";
|
||||||
|
this.textBoxBody.ReadOnly = true;
|
||||||
|
this.textBoxBody.Size = new System.Drawing.Size(612, 186);
|
||||||
|
this.textBoxBody.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonClose
|
||||||
|
//
|
||||||
|
this.buttonClose.Location = new System.Drawing.Point(491, 326);
|
||||||
|
this.buttonClose.Name = "buttonClose";
|
||||||
|
this.buttonClose.Size = new System.Drawing.Size(111, 39);
|
||||||
|
this.buttonClose.TabIndex = 6;
|
||||||
|
this.buttonClose.Text = "Закрыть";
|
||||||
|
this.buttonClose.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonClose.Click += new System.EventHandler(this.buttonClose_Click);
|
||||||
|
//
|
||||||
|
// buttonReply
|
||||||
|
//
|
||||||
|
this.buttonReply.Location = new System.Drawing.Point(290, 326);
|
||||||
|
this.buttonReply.Name = "buttonReply";
|
||||||
|
this.buttonReply.Size = new System.Drawing.Size(177, 39);
|
||||||
|
this.buttonReply.TabIndex = 7;
|
||||||
|
this.buttonReply.Text = "Ответить";
|
||||||
|
this.buttonReply.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonReply.Click += new System.EventHandler(this.buttonReply_Click);
|
||||||
|
//
|
||||||
|
// labelDate
|
||||||
|
//
|
||||||
|
this.labelDate.AutoSize = true;
|
||||||
|
this.labelDate.Location = new System.Drawing.Point(278, 9);
|
||||||
|
this.labelDate.Name = "labelDate";
|
||||||
|
this.labelDate.Size = new System.Drawing.Size(127, 20);
|
||||||
|
this.labelDate.TabIndex = 8;
|
||||||
|
this.labelDate.Text = "Дата получения: ";
|
||||||
|
//
|
||||||
|
// textBoxDate
|
||||||
|
//
|
||||||
|
this.textBoxDate.Location = new System.Drawing.Point(411, 6);
|
||||||
|
this.textBoxDate.Name = "textBoxDate";
|
||||||
|
this.textBoxDate.ReadOnly = true;
|
||||||
|
this.textBoxDate.Size = new System.Drawing.Size(213, 27);
|
||||||
|
this.textBoxDate.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// buttonSend
|
||||||
|
//
|
||||||
|
this.buttonSend.Location = new System.Drawing.Point(149, 326);
|
||||||
|
this.buttonSend.Name = "buttonSend";
|
||||||
|
this.buttonSend.Size = new System.Drawing.Size(109, 39);
|
||||||
|
this.buttonSend.TabIndex = 10;
|
||||||
|
this.buttonSend.Text = "Отправить";
|
||||||
|
this.buttonSend.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSend.Visible = false;
|
||||||
|
this.buttonSend.Click += new System.EventHandler(this.buttonSend_Click);
|
||||||
|
//
|
||||||
|
// FormLetter
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(636, 377);
|
||||||
|
this.Controls.Add(this.buttonSend);
|
||||||
|
this.Controls.Add(this.textBoxDate);
|
||||||
|
this.Controls.Add(this.labelDate);
|
||||||
|
this.Controls.Add(this.buttonReply);
|
||||||
|
this.Controls.Add(this.buttonClose);
|
||||||
|
this.Controls.Add(this.textBoxBody);
|
||||||
|
this.Controls.Add(this.labelBody);
|
||||||
|
this.Controls.Add(this.textBoxSubject);
|
||||||
|
this.Controls.Add(this.labelSubject);
|
||||||
|
this.Controls.Add(this.labelAdress);
|
||||||
|
this.Controls.Add(this.textBoxEmail);
|
||||||
|
this.Name = "FormLetter";
|
||||||
|
this.Text = "Письмо";
|
||||||
|
this.Load += new System.EventHandler(this.FormLetter_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private TextBox textBoxEmail;
|
||||||
|
private Label labelAdress;
|
||||||
|
private Label labelSubject;
|
||||||
|
private TextBox textBoxSubject;
|
||||||
|
private Label labelBody;
|
||||||
|
private TextBox textBoxBody;
|
||||||
|
private Button buttonClose;
|
||||||
|
private Button buttonReply;
|
||||||
|
private Label labelDate;
|
||||||
|
private TextBox textBoxDate;
|
||||||
|
private Button buttonSend;
|
||||||
|
}
|
||||||
|
}
|
152
SushiBar/SushiBarView/FormLetter.cs
Normal file
152
SushiBar/SushiBarView/FormLetter.cs
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SushiBar;
|
||||||
|
using SushiBarBusinessLogic.MailWorker;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
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;
|
||||||
|
using System.Windows.Forms.VisualStyles;
|
||||||
|
|
||||||
|
namespace SushiBarView
|
||||||
|
{
|
||||||
|
public partial class FormLetter : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IMessageInfoLogic _logic;
|
||||||
|
private readonly AbstractMailWorker _worker;
|
||||||
|
|
||||||
|
public MessageInfoViewModel? model;
|
||||||
|
public string? messageId;
|
||||||
|
|
||||||
|
public FormLetter(ILogger<FormLetter> logger, IMessageInfoLogic logic, AbstractMailWorker worker)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_worker = worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormLetter_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(messageId))
|
||||||
|
{
|
||||||
|
ReloadLetter();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (model != null)
|
||||||
|
{
|
||||||
|
ConfigurateToCreateAnsver();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogError("Для формы не переданно сведений о письме, на которое отвечаем!");
|
||||||
|
DialogResult = DialogResult.Abort;
|
||||||
|
Close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReloadLetter()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка существующего письма с id:{}", messageId);
|
||||||
|
model = _logic.ReadElement(new MessageInfoSearchModel
|
||||||
|
{
|
||||||
|
MessageId = messageId
|
||||||
|
});
|
||||||
|
if (model != null)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Письмо найдено");
|
||||||
|
textBoxEmail.Text = model.SenderName;
|
||||||
|
textBoxDate.Text = model.DateDelivery.ToString();
|
||||||
|
textBoxSubject.Text = model.Subject;
|
||||||
|
textBoxBody.Text = model.Body;
|
||||||
|
|
||||||
|
|
||||||
|
if (model.IsReply)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Письмо само и есть ответ");
|
||||||
|
buttonReply.Visible = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(model.ReplyMessageId))
|
||||||
|
{
|
||||||
|
_logger.LogInformation("У письма есть ответ.");
|
||||||
|
buttonReply.Text = "Прочитать ответ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Письмо с таким id не удалось найти");
|
||||||
|
DialogResult = DialogResult.Abort;
|
||||||
|
Close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigurateToCreateAnsver()
|
||||||
|
{
|
||||||
|
textBoxEmail.Text = model.SenderName;
|
||||||
|
labelDate.Visible = false;
|
||||||
|
textBoxDate.Visible = false;
|
||||||
|
textBoxSubject.Text = $"re: {model.Subject}";
|
||||||
|
textBoxBody.ReadOnly = false;
|
||||||
|
buttonReply.Visible = false;
|
||||||
|
buttonSend.Visible = true;
|
||||||
|
_logger.LogInformation("Запущена форма создания нового письма - ответа");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonClose_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonReply_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormLetter));
|
||||||
|
if (service is FormLetter form)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(model.ReplyMessageId))
|
||||||
|
{
|
||||||
|
form.messageId = model.ReplyMessageId;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
form.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (form.ShowDialog() != DialogResult.Cancel)
|
||||||
|
{
|
||||||
|
buttonReply.Visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSend_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string subject = textBoxSubject.Text;
|
||||||
|
string text = textBoxBody.Text;
|
||||||
|
|
||||||
|
Task.Run(() => _worker.MailSendReplyAsync(new MailReplySendInfoBindingModel
|
||||||
|
{
|
||||||
|
MailAddress = model.SenderName,
|
||||||
|
Subject = subject,
|
||||||
|
Text = text,
|
||||||
|
ParentMessageId = model.MessageId,
|
||||||
|
}));
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
SushiBar/SushiBarView/FormLetter.resx
Normal file
120
SushiBar/SushiBarView/FormLetter.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>
|
74
SushiBar/SushiBarView/FormMail.Designer.cs
generated
74
SushiBar/SushiBarView/FormMail.Designer.cs
generated
@ -28,10 +28,26 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
this.panel1 = new System.Windows.Forms.Panel();
|
||||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.buttonOpen = new System.Windows.Forms.Button();
|
||||||
|
this.numericUpDownPage = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.buttonPreveous = new System.Windows.Forms.Button();
|
||||||
|
this.buttonNext = new System.Windows.Forms.Button();
|
||||||
|
this.panel1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownPage)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
|
// panel1
|
||||||
|
//
|
||||||
|
this.panel1.Controls.Add(this.dataGridView);
|
||||||
|
this.panel1.Location = new System.Drawing.Point(3, 1);
|
||||||
|
this.panel1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.panel1.Name = "panel1";
|
||||||
|
this.panel1.Size = new System.Drawing.Size(795, 431);
|
||||||
|
this.panel1.TabIndex = 0;
|
||||||
|
//
|
||||||
// dataGridView
|
// dataGridView
|
||||||
//
|
//
|
||||||
this.dataGridView.AllowUserToAddRows = false;
|
this.dataGridView.AllowUserToAddRows = false;
|
||||||
@ -43,25 +59,75 @@
|
|||||||
this.dataGridView.ReadOnly = true;
|
this.dataGridView.ReadOnly = true;
|
||||||
this.dataGridView.RowHeadersWidth = 51;
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
this.dataGridView.RowTemplate.Height = 29;
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
this.dataGridView.Size = new System.Drawing.Size(786, 270);
|
this.dataGridView.Size = new System.Drawing.Size(795, 431);
|
||||||
this.dataGridView.TabIndex = 0;
|
this.dataGridView.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// buttonOpen
|
||||||
|
//
|
||||||
|
this.buttonOpen.Location = new System.Drawing.Point(806, 80);
|
||||||
|
this.buttonOpen.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
|
this.buttonOpen.Name = "buttonOpen";
|
||||||
|
this.buttonOpen.Size = new System.Drawing.Size(107, 31);
|
||||||
|
this.buttonOpen.TabIndex = 1;
|
||||||
|
this.buttonOpen.Text = "Прочитать";
|
||||||
|
this.buttonOpen.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonOpen.Click += new System.EventHandler(this.buttonOpen_Click);
|
||||||
|
//
|
||||||
|
// numericUpDownPage
|
||||||
|
//
|
||||||
|
this.numericUpDownPage.Location = new System.Drawing.Point(825, 287);
|
||||||
|
this.numericUpDownPage.Name = "numericUpDownPage";
|
||||||
|
this.numericUpDownPage.Size = new System.Drawing.Size(85, 27);
|
||||||
|
this.numericUpDownPage.TabIndex = 4;
|
||||||
|
this.numericUpDownPage.ValueChanged += new System.EventHandler(this.numericUpDownPage_ValueChanged);
|
||||||
|
//
|
||||||
|
// buttonPreveous
|
||||||
|
//
|
||||||
|
this.buttonPreveous.Location = new System.Drawing.Point(825, 323);
|
||||||
|
this.buttonPreveous.Name = "buttonPreveous";
|
||||||
|
this.buttonPreveous.Size = new System.Drawing.Size(39, 29);
|
||||||
|
this.buttonPreveous.TabIndex = 5;
|
||||||
|
this.buttonPreveous.Text = "<-";
|
||||||
|
this.buttonPreveous.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonPreveous.Click += new System.EventHandler(this.buttonPreveous_Click);
|
||||||
|
//
|
||||||
|
// buttonNext
|
||||||
|
//
|
||||||
|
this.buttonNext.Location = new System.Drawing.Point(872, 323);
|
||||||
|
this.buttonNext.Name = "buttonNext";
|
||||||
|
this.buttonNext.Size = new System.Drawing.Size(39, 29);
|
||||||
|
this.buttonNext.TabIndex = 6;
|
||||||
|
this.buttonNext.Text = "->";
|
||||||
|
this.buttonNext.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonNext.Click += new System.EventHandler(this.buttonNext_Click);
|
||||||
//
|
//
|
||||||
// FormMail
|
// FormMail
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(786, 270);
|
this.ClientSize = new System.Drawing.Size(925, 428);
|
||||||
this.Controls.Add(this.dataGridView);
|
this.Controls.Add(this.buttonNext);
|
||||||
|
this.Controls.Add(this.buttonPreveous);
|
||||||
|
this.Controls.Add(this.numericUpDownPage);
|
||||||
|
this.Controls.Add(this.buttonOpen);
|
||||||
|
this.Controls.Add(this.panel1);
|
||||||
this.Name = "FormMail";
|
this.Name = "FormMail";
|
||||||
this.Text = "Письма";
|
this.Text = "Письма";
|
||||||
this.Load += new System.EventHandler(this.FormMail_Load);
|
this.Load += new System.EventHandler(this.FormMail_Load);
|
||||||
|
this.panel1.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownPage)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private Panel panel1;
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
|
private Button buttonOpen;
|
||||||
|
private NumericUpDown numericUpDownPage;
|
||||||
|
private Button buttonPreveous;
|
||||||
|
private Button buttonNext;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,10 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using DocumentFormat.OpenXml.Spreadsheet;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SushiBar;
|
||||||
|
using SushiBarBusinessLogic.BusinessLogics;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
using SushiBarContracts.BusinessLogicsContracts;
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
@ -16,6 +21,8 @@ namespace SushiBarView
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IMessageInfoLogic _logic;
|
private readonly IMessageInfoLogic _logic;
|
||||||
|
private int currentPage = 1;
|
||||||
|
private int pageLength = 2;
|
||||||
|
|
||||||
public FormMail(ILogger<FormMail> logger, IMessageInfoLogic logic)
|
public FormMail(ILogger<FormMail> logger, IMessageInfoLogic logic)
|
||||||
{
|
{
|
||||||
@ -28,6 +35,25 @@ namespace SushiBarView
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var list = _logic.ReadList(new MessageInfoSearchModel()
|
||||||
|
{
|
||||||
|
PageLength = pageLength,
|
||||||
|
PageIndex = currentPage
|
||||||
|
|
||||||
|
});
|
||||||
|
numericUpDownPage.Value = pageLength;
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["MessageId"].Visible = false;
|
||||||
|
dataGridView.Columns["ClientId"].Visible = false;
|
||||||
|
dataGridView.Columns["ReplyMessageId"].Visible = false;
|
||||||
|
dataGridView.Columns["Reply"].Visible = false;
|
||||||
|
dataGridView.Columns["IsReply"].Visible = false;
|
||||||
|
dataGridView.Columns["Body"].AutoSizeMode =
|
||||||
|
DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка почтовых собщений");
|
||||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||||
_logger.LogInformation("Загрузка почтовых собщений");
|
_logger.LogInformation("Загрузка почтовых собщений");
|
||||||
}
|
}
|
||||||
@ -42,5 +68,50 @@ namespace SushiBarView
|
|||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonOpen_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormLetter));
|
||||||
|
if (service is FormLetter form)
|
||||||
|
{
|
||||||
|
string? messageId = dataGridView.SelectedRows[0].Cells["MessageId"].Value.ToString();
|
||||||
|
if (messageId == null) return;
|
||||||
|
form.messageId = messageId;
|
||||||
|
|
||||||
|
if (!Convert.ToBoolean(dataGridView.SelectedRows[0].Cells["IsReaded"].Value))
|
||||||
|
{
|
||||||
|
_logic.Update(new MessageInfoBindingModel
|
||||||
|
{
|
||||||
|
MessageId = messageId,
|
||||||
|
IsReaded = true,
|
||||||
|
ReplyMessageId = dataGridView.SelectedRows[0].Cells["ReplyMessageId"].Value?.ToString()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonPreveous_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
currentPage = Math.Max(1, currentPage - 1);
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonNext_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
currentPage++;
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void numericUpDownPage_ValueChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pageLength = Math.Max(1, (int)numericUpDownPage.Value);
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
207
SushiBar/SushiBarView/FormMain.Designer.cs
generated
207
SushiBar/SushiBarView/FormMain.Designer.cs
generated
@ -40,13 +40,39 @@
|
|||||||
ClientToolStripMenuItem = new ToolStripMenuItem();
|
ClientToolStripMenuItem = new ToolStripMenuItem();
|
||||||
employersToolStripMenuItem = new ToolStripMenuItem();
|
employersToolStripMenuItem = new ToolStripMenuItem();
|
||||||
начатьРаботуToolStripMenuItem = new ToolStripMenuItem();
|
начатьРаботуToolStripMenuItem = new ToolStripMenuItem();
|
||||||
gToolStripMenuItem = new ToolStripMenuItem();
|
|
||||||
отчётыToolStripMenuItem = new ToolStripMenuItem();
|
отчётыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
componentsToolStripMenuItem1 = new ToolStripMenuItem();
|
componentsToolStripMenuItem1 = new ToolStripMenuItem();
|
||||||
componentSushiToolStripMenuItem1 = new ToolStripMenuItem();
|
//componentSushiToolStripMenuItem1 = new ToolStripMenuItem();
|
||||||
ordersToolStripMenuItem = new ToolStripMenuItem();
|
ordersToolStripMenuItem = new ToolStripMenuItem();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
создатьБэкапToolStripMenuItem = new ToolStripMenuItem();
|
gToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
menuStrip.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
ButtonCreateOrder = new Button();
|
||||||
|
ButtonOrderReady = new Button();
|
||||||
|
ButtonRef = new Button();
|
||||||
|
ButtonIssuedOrder = new Button();
|
||||||
|
ButtonTakeOrderInWork = new Button();
|
||||||
|
menuStrip = new MenuStrip();
|
||||||
|
toolStripMenuItem1 = new ToolStripMenuItem();
|
||||||
|
componentsToolStripMenuItemToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
sushiToolStripMenuItemToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
отчётыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
componentsToolStripMenuItem1 = new ToolStripMenuItem();
|
||||||
|
списокСушиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
сушиСИнгрToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
ordersToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
заказыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
заказыПоГруппамToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
магазиныToolStripMenuItem1 = new ToolStripMenuItem();
|
||||||
|
информацияToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
загруженностьToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
операцииToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
поставкаToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
продажаToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
menuStrip.SuspendLayout();
|
menuStrip.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -103,7 +129,13 @@
|
|||||||
//
|
//
|
||||||
// menuStrip
|
// menuStrip
|
||||||
//
|
//
|
||||||
menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem1, отчётыToolStripMenuItem, создатьБэкапToolStripMenuItem });
|
menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem1, отчётыToolStripMenuItem });
|
||||||
|
menuStrip.Location = new Point(0, 0);
|
||||||
|
menuStrip.Name = "menuStrip";
|
||||||
|
menuStrip.Size = new Size(922, 24);
|
||||||
|
menuStrip.TabIndex = 5;
|
||||||
|
menuStrip.Text = "menuStrip1";
|
||||||
|
menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem1, отчётыToolStripMenuItem, операцииToolStripMenuItem });
|
||||||
menuStrip.Location = new Point(0, 0);
|
menuStrip.Location = new Point(0, 0);
|
||||||
menuStrip.Name = "menuStrip";
|
menuStrip.Name = "menuStrip";
|
||||||
menuStrip.Size = new Size(922, 24);
|
menuStrip.Size = new Size(922, 24);
|
||||||
@ -116,52 +148,68 @@
|
|||||||
toolStripMenuItem1.Name = "toolStripMenuItem1";
|
toolStripMenuItem1.Name = "toolStripMenuItem1";
|
||||||
toolStripMenuItem1.Size = new Size(94, 20);
|
toolStripMenuItem1.Size = new Size(94, 20);
|
||||||
toolStripMenuItem1.Text = "Справочники";
|
toolStripMenuItem1.Text = "Справочники";
|
||||||
|
toolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItemToolStripMenuItem, sushiToolStripMenuItemToolStripMenuItem, магазиныToolStripMenuItem });
|
||||||
|
toolStripMenuItem1.Name = "toolStripMenuItem1";
|
||||||
|
toolStripMenuItem1.Size = new Size(94, 20);
|
||||||
|
toolStripMenuItem1.Text = "Справочники";
|
||||||
//
|
//
|
||||||
// componentsToolStripMenuItemToolStripMenuItem
|
// componentsToolStripMenuItemToolStripMenuItem
|
||||||
//
|
//
|
||||||
componentsToolStripMenuItemToolStripMenuItem.Name = "componentsToolStripMenuItemToolStripMenuItem";
|
componentsToolStripMenuItemToolStripMenuItem.Name = "componentsToolStripMenuItemToolStripMenuItem";
|
||||||
componentsToolStripMenuItemToolStripMenuItem.Size = new Size(154, 22);
|
componentsToolStripMenuItemToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
componentsToolStripMenuItemToolStripMenuItem.Text = "Компоненты";
|
||||||
|
componentsToolStripMenuItemToolStripMenuItem.Click += componentsToolStripMenuItem_Click;
|
||||||
|
componentsToolStripMenuItemToolStripMenuItem.Name = "componentsToolStripMenuItemToolStripMenuItem";
|
||||||
|
componentsToolStripMenuItemToolStripMenuItem.Size = new Size(145, 22);
|
||||||
componentsToolStripMenuItemToolStripMenuItem.Text = "Компоненты";
|
componentsToolStripMenuItemToolStripMenuItem.Text = "Компоненты";
|
||||||
componentsToolStripMenuItemToolStripMenuItem.Click += componentsToolStripMenuItem_Click;
|
componentsToolStripMenuItemToolStripMenuItem.Click += componentsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// sushiToolStripMenuItemToolStripMenuItem
|
// sushiToolStripMenuItemToolStripMenuItem
|
||||||
//
|
//
|
||||||
sushiToolStripMenuItemToolStripMenuItem.Name = "sushiToolStripMenuItemToolStripMenuItem";
|
sushiToolStripMenuItemToolStripMenuItem.Name = "sushiToolStripMenuItemToolStripMenuItem";
|
||||||
sushiToolStripMenuItemToolStripMenuItem.Size = new Size(154, 22);
|
sushiToolStripMenuItemToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
sushiToolStripMenuItemToolStripMenuItem.Text = "Суши";
|
||||||
|
sushiToolStripMenuItemToolStripMenuItem.Click += sushiToolStripMenuItem_Click;
|
||||||
|
sushiToolStripMenuItemToolStripMenuItem.Name = "sushiToolStripMenuItemToolStripMenuItem";
|
||||||
|
sushiToolStripMenuItemToolStripMenuItem.Size = new Size(145, 22);
|
||||||
sushiToolStripMenuItemToolStripMenuItem.Text = "Суши";
|
sushiToolStripMenuItemToolStripMenuItem.Text = "Суши";
|
||||||
sushiToolStripMenuItemToolStripMenuItem.Click += sushiToolStripMenuItem_Click;
|
sushiToolStripMenuItemToolStripMenuItem.Click += sushiToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// ClientToolStripMenuItem
|
// ClientToolStripMenuItem
|
||||||
//
|
//
|
||||||
ClientToolStripMenuItem.Name = "ClientToolStripMenuItem";
|
ClientToolStripMenuItem.Name = "ClientToolStripMenuItem";
|
||||||
ClientToolStripMenuItem.Size = new Size(154, 22);
|
ClientToolStripMenuItem.Size = new Size(180, 22);
|
||||||
ClientToolStripMenuItem.Text = "Клиенты";
|
ClientToolStripMenuItem.Text = "Клиенты";
|
||||||
ClientToolStripMenuItem.Click += ClientToolStripMenuItem_Click;
|
ClientToolStripMenuItem.Click += ClientToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// employersToolStripMenuItem
|
// employersToolStripMenuItem
|
||||||
//
|
//
|
||||||
employersToolStripMenuItem.Name = "employersToolStripMenuItem";
|
employersToolStripMenuItem.Name = "employersToolStripMenuItem";
|
||||||
employersToolStripMenuItem.Size = new Size(154, 22);
|
employersToolStripMenuItem.Size = new Size(180, 22);
|
||||||
employersToolStripMenuItem.Text = "Исполнители";
|
employersToolStripMenuItem.Text = "Исполнители";
|
||||||
employersToolStripMenuItem.Click += employersToolStripMenuItem_Click;
|
employersToolStripMenuItem.Click += employersToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// начатьРаботуToolStripMenuItem
|
// начатьРаботуToolStripMenuItem
|
||||||
//
|
//
|
||||||
начатьРаботуToolStripMenuItem.Name = "начатьРаботуToolStripMenuItem";
|
начатьРаботуToolStripMenuItem.Name = "начатьРаботуToolStripMenuItem";
|
||||||
начатьРаботуToolStripMenuItem.Size = new Size(154, 22);
|
начатьРаботуToolStripMenuItem.Size = new Size(180, 22);
|
||||||
начатьРаботуToolStripMenuItem.Text = "Начать работу";
|
начатьРаботуToolStripMenuItem.Text = "Начать работу";
|
||||||
начатьРаботуToolStripMenuItem.Click += startWorkToolStripMenuItem_Click;
|
начатьРаботуToolStripMenuItem.Click += startWorkToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// gToolStripMenuItem
|
// магазиныToolStripMenuItem
|
||||||
//
|
//
|
||||||
gToolStripMenuItem.Name = "gToolStripMenuItem";
|
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||||
gToolStripMenuItem.Size = new Size(154, 22);
|
магазиныToolStripMenuItem.Size = new Size(145, 22);
|
||||||
gToolStripMenuItem.Text = "Почта";
|
магазиныToolStripMenuItem.Text = "Магазины";
|
||||||
gToolStripMenuItem.Click += mailToolStripMenuItem_Click;
|
магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// отчётыToolStripMenuItem
|
// отчётыToolStripMenuItem
|
||||||
//
|
//
|
||||||
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem1, componentSushiToolStripMenuItem1, ordersToolStripMenuItem });
|
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem1, ordersToolStripMenuItem });
|
||||||
|
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
|
||||||
|
отчётыToolStripMenuItem.Size = new Size(60, 20);
|
||||||
|
отчётыToolStripMenuItem.Text = "Отчёты";
|
||||||
|
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem1, ordersToolStripMenuItem, магазиныToolStripMenuItem1 });
|
||||||
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
|
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
|
||||||
отчётыToolStripMenuItem.Size = new Size(60, 20);
|
отчётыToolStripMenuItem.Size = new Size(60, 20);
|
||||||
отчётыToolStripMenuItem.Text = "Отчёты";
|
отчётыToolStripMenuItem.Text = "Отчёты";
|
||||||
@ -172,13 +220,29 @@
|
|||||||
componentsToolStripMenuItem1.Size = new Size(201, 22);
|
componentsToolStripMenuItem1.Size = new Size(201, 22);
|
||||||
componentsToolStripMenuItem1.Text = "Суши";
|
componentsToolStripMenuItem1.Text = "Суши";
|
||||||
componentsToolStripMenuItem1.Click += ComponentsToolStripMenuItem_Click;
|
componentsToolStripMenuItem1.Click += ComponentsToolStripMenuItem_Click;
|
||||||
|
componentsToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { списокСушиToolStripMenuItem, сушиСИнгрToolStripMenuItem });
|
||||||
|
componentsToolStripMenuItem1.Name = "componentsToolStripMenuItem1";
|
||||||
|
componentsToolStripMenuItem1.Size = new Size(180, 22);
|
||||||
|
componentsToolStripMenuItem1.Text = "Суши";
|
||||||
|
componentsToolStripMenuItem1.Click += ComponentsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// componentSushiToolStripMenuItem1
|
// списокСушиToolStripMenuItem
|
||||||
//
|
//
|
||||||
componentSushiToolStripMenuItem1.Name = "componentSushiToolStripMenuItem1";
|
списокСушиToolStripMenuItem.Name = "списокСушиToolStripMenuItem";
|
||||||
|
списокСушиToolStripMenuItem.Size = new Size(201, 22);
|
||||||
|
списокСушиToolStripMenuItem.Text = "Список суши";
|
||||||
|
списокСушиToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// сушиСИнгрToolStripMenuItem
|
||||||
|
//
|
||||||
|
/* componentSushiToolStripMenuItem1.Name = "componentSushiToolStripMenuItem1";
|
||||||
componentSushiToolStripMenuItem1.Size = new Size(201, 22);
|
componentSushiToolStripMenuItem1.Size = new Size(201, 22);
|
||||||
componentSushiToolStripMenuItem1.Text = "Суши с компонентами";
|
componentSushiToolStripMenuItem1.Text = "Суши с компонентами";
|
||||||
componentSushiToolStripMenuItem1.Click += ComponentSushiToolStripMenuItem_Click;
|
componentSushiToolStripMenuItem1.Click += ComponentSushiToolStripMenuItem_Click;
|
||||||
|
сушиСИнгрToolStripMenuItem.Name = "сушиСИнгрToolStripMenuItem";
|
||||||
|
сушиСИнгрToolStripMenuItem.Size = new Size(201, 22);
|
||||||
|
сушиСИнгрToolStripMenuItem.Text = "Суши с компонентами";
|
||||||
|
сушиСИнгрToolStripMenuItem.Click += ComponentSushiToolStripMenuItem_Click;*/
|
||||||
//
|
//
|
||||||
// ordersToolStripMenuItem
|
// ordersToolStripMenuItem
|
||||||
//
|
//
|
||||||
@ -197,12 +261,98 @@
|
|||||||
dataGridView.Size = new Size(647, 344);
|
dataGridView.Size = new Size(647, 344);
|
||||||
dataGridView.TabIndex = 6;
|
dataGridView.TabIndex = 6;
|
||||||
//
|
//
|
||||||
// создатьБэкапToolStripMenuItem
|
// gToolStripMenuItem
|
||||||
//
|
//
|
||||||
создатьБэкапToolStripMenuItem.Name = "создатьБэкапToolStripMenuItem";
|
gToolStripMenuItem.Name = "gToolStripMenuItem";
|
||||||
создатьБэкапToolStripMenuItem.Size = new Size(97, 20);
|
gToolStripMenuItem.Size = new Size(180, 22);
|
||||||
создатьБэкапToolStripMenuItem.Text = "Создать бэкап";
|
gToolStripMenuItem.Text = "Почта";
|
||||||
создатьБэкапToolStripMenuItem.Click += createBackUpToolStripMenuItem_Click;
|
gToolStripMenuItem.Click += mailToolStripMenuItem_Click;
|
||||||
|
employersToolStripMenuItem.Name = "employersToolStripMenuItem";
|
||||||
|
employersToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
employersToolStripMenuItem.Text = "Исполнители";
|
||||||
|
employersToolStripMenuItem.Click += employersToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// начатьРаботуToolStripMenuItem
|
||||||
|
//
|
||||||
|
начатьРаботуToolStripMenuItem.Name = "начатьРаботуToolStripMenuItem";
|
||||||
|
начатьРаботуToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
начатьРаботуToolStripMenuItem.Text = "Начать работу";
|
||||||
|
начатьРаботуToolStripMenuItem.Click += startWorkToolStripMenuItem_Click;
|
||||||
|
ClientToolStripMenuItem.Name = "ClientToolStripMenuItem";
|
||||||
|
ClientToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
ClientToolStripMenuItem.Text = "Клиенты";
|
||||||
|
ClientToolStripMenuItem.Click += ClientToolStripMenuItem_Click;
|
||||||
|
ordersToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заказыToolStripMenuItem, заказыПоГруппамToolStripMenuItem });
|
||||||
|
ordersToolStripMenuItem.Name = "ordersToolStripMenuItem";
|
||||||
|
ordersToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
ordersToolStripMenuItem.Text = "Заказы";
|
||||||
|
ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// заказыToolStripMenuItem
|
||||||
|
//
|
||||||
|
заказыToolStripMenuItem.Name = "заказыToolStripMenuItem";
|
||||||
|
заказыToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
заказыToolStripMenuItem.Text = "Заказы";
|
||||||
|
заказыToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// заказыПоГруппамToolStripMenuItem
|
||||||
|
//
|
||||||
|
заказыПоГруппамToolStripMenuItem.Name = "заказыПоГруппамToolStripMenuItem";
|
||||||
|
заказыПоГруппамToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
заказыПоГруппамToolStripMenuItem.Text = "Заказы по группам";
|
||||||
|
заказыПоГруппамToolStripMenuItem.Click += GroupOrdersToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// магазиныToolStripMenuItem1
|
||||||
|
//
|
||||||
|
магазиныToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { информацияToolStripMenuItem, загруженностьToolStripMenuItem });
|
||||||
|
магазиныToolStripMenuItem1.Name = "магазиныToolStripMenuItem1";
|
||||||
|
магазиныToolStripMenuItem1.Size = new Size(180, 22);
|
||||||
|
магазиныToolStripMenuItem1.Text = "Магазины";
|
||||||
|
//
|
||||||
|
// информацияToolStripMenuItem
|
||||||
|
//
|
||||||
|
информацияToolStripMenuItem.Name = "информацияToolStripMenuItem";
|
||||||
|
информацияToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
информацияToolStripMenuItem.Text = "Информация ";
|
||||||
|
информацияToolStripMenuItem.Click += InfoToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// загруженностьToolStripMenuItem
|
||||||
|
//
|
||||||
|
загруженностьToolStripMenuItem.Name = "загруженностьToolStripMenuItem";
|
||||||
|
загруженностьToolStripMenuItem.Size = new Size(180, 22);
|
||||||
|
загруженностьToolStripMenuItem.Text = "Загруженность";
|
||||||
|
загруженностьToolStripMenuItem.Click += BusyShopsToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// операцииToolStripMenuItem
|
||||||
|
//
|
||||||
|
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem, продажаToolStripMenuItem });
|
||||||
|
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
|
||||||
|
операцииToolStripMenuItem.Size = new Size(75, 20);
|
||||||
|
операцииToolStripMenuItem.Text = "Операции";
|
||||||
|
//
|
||||||
|
// поставкаToolStripMenuItem
|
||||||
|
//
|
||||||
|
поставкаToolStripMenuItem.Name = "поставкаToolStripMenuItem";
|
||||||
|
поставкаToolStripMenuItem.Size = new Size(125, 22);
|
||||||
|
поставкаToolStripMenuItem.Text = "Поставка";
|
||||||
|
поставкаToolStripMenuItem.Click += transactionToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// продажаToolStripMenuItem
|
||||||
|
//
|
||||||
|
продажаToolStripMenuItem.Name = "продажаToolStripMenuItem";
|
||||||
|
продажаToolStripMenuItem.Size = new Size(125, 22);
|
||||||
|
продажаToolStripMenuItem.Text = "Продажа";
|
||||||
|
продажаToolStripMenuItem.Click += SellToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.BackgroundColor = Color.White;
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Location = new Point(12, 27);
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.RowTemplate.Height = 25;
|
||||||
|
dataGridView.Size = new Size(647, 344);
|
||||||
|
dataGridView.TabIndex = 6;
|
||||||
//
|
//
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
@ -241,12 +391,21 @@
|
|||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
private ToolStripMenuItem отчётыToolStripMenuItem;
|
private ToolStripMenuItem отчётыToolStripMenuItem;
|
||||||
private ToolStripMenuItem componentsToolStripMenuItem1;
|
private ToolStripMenuItem componentsToolStripMenuItem1;
|
||||||
private ToolStripMenuItem componentSushiToolStripMenuItem1;
|
|
||||||
private ToolStripMenuItem ordersToolStripMenuItem;
|
private ToolStripMenuItem ordersToolStripMenuItem;
|
||||||
private ToolStripMenuItem ClientToolStripMenuItem;
|
private ToolStripMenuItem ClientToolStripMenuItem;
|
||||||
private ToolStripMenuItem employersToolStripMenuItem;
|
private ToolStripMenuItem employersToolStripMenuItem;
|
||||||
private ToolStripMenuItem начатьРаботуToolStripMenuItem;
|
private ToolStripMenuItem начатьРаботуToolStripMenuItem;
|
||||||
private ToolStripMenuItem gToolStripMenuItem;
|
private ToolStripMenuItem gToolStripMenuItem;
|
||||||
private ToolStripMenuItem создатьБэкапToolStripMenuItem;
|
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem списокСушиToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem сушиСИнгрToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem заказыToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem заказыПоГруппамToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem магазиныToolStripMenuItem1;
|
||||||
|
private ToolStripMenuItem информацияToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem загруженностьToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem операцииToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem поставкаToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem продажаToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -54,7 +54,16 @@ namespace SushiBarView
|
|||||||
_logger.LogInformation("Загрузка заказов");
|
_logger.LogInformation("Загрузка заказов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
|
var list = _orderLogic.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["SushiId"].Visible = false;
|
||||||
|
dataGridView.Columns["ClientId"].Visible = false;
|
||||||
|
dataGridView.Columns["ClientEmail"].Visible = false;
|
||||||
|
dataGridView.Columns["ClientEmail"].Visible = false;
|
||||||
|
dataGridView.Columns["ImplementerId"].Visible = false;
|
||||||
|
}
|
||||||
_logger.LogInformation("Загрузка заказов");
|
_logger.LogInformation("Загрузка заказов");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -65,9 +74,14 @@ namespace SushiBarView
|
|||||||
}
|
}
|
||||||
private void componentsToolStripMenuItem_Click(object sender, EventArgs e)
|
private void componentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var form = DependencyManager.Instance.Resolve<FormComponents>();
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||||
|
if (service is FormComponents form)
|
||||||
|
{
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sushiToolStripMenuItem_Click(object sender, EventArgs e)
|
private void sushiToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var form = DependencyManager.Instance.Resolve<FormSushis>();
|
var form = DependencyManager.Instance.Resolve<FormSushis>();
|
||||||
@ -202,32 +216,64 @@ namespace SushiBarView
|
|||||||
}
|
}
|
||||||
private void mailToolStripMenuItem_Click(object sender, EventArgs e)
|
private void mailToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var form = DependencyManager.Instance.Resolve<FormMail>();
|
var service = Program.ServiceProvider?.GetService(typeof(FormMail));
|
||||||
|
if (service is FormMail form)
|
||||||
|
{
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
private void shopsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||||
|
if (service is FormShops form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void createBackUpToolStripMenuItem_Click(object sender, EventArgs e)
|
private void transactionToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply));
|
||||||
|
if (service is FormCreateSupply form)
|
||||||
{
|
{
|
||||||
if (_backUpLogic != null)
|
form.ShowDialog();
|
||||||
{
|
|
||||||
var fbd = new FolderBrowserDialog();
|
|
||||||
if (fbd.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
_backUpLogic.CreateBackUp(new BackUpSaveBinidngModel
|
|
||||||
{
|
|
||||||
FolderName = fbd.SelectedPath
|
|
||||||
});
|
|
||||||
MessageBox.Show("Бекап создан", "Сообщение",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
private void SellToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка создания бэкапа", MessageBoxButtons.OK,
|
var service = Program.ServiceProvider?.GetService(typeof(FormSellSushi));
|
||||||
MessageBoxIcon.Error);
|
if (service is FormSellSushi 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
86
SushiBar/SushiBarView/FormReportGroupedOrders.Designer.cs
generated
Normal file
86
SushiBar/SushiBarView/FormReportGroupedOrders.Designer.cs
generated
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
namespace SushiBarView
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
80
SushiBar/SushiBarView/FormReportGroupedOrders.cs
Normal file
80
SushiBar/SushiBarView/FormReportGroupedOrders.cs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Reporting.WinForms;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.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 SushiBarView
|
||||||
|
{
|
||||||
|
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("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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
SushiBar/SushiBarView/FormReportGroupedOrders.resx
Normal file
120
SushiBar/SushiBarView/FormReportGroupedOrders.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>
|
116
SushiBar/SushiBarView/FormReportShop.Designer.cs
generated
Normal file
116
SushiBar/SushiBarView/FormReportShop.Designer.cs
generated
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
namespace SushiBarView
|
||||||
|
{
|
||||||
|
partial class FormReportShop
|
||||||
|
{
|
||||||
|
/// <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.buttonSaveToExcel = new System.Windows.Forms.Button();
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.ColumnShop = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.ColumnSushi = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonSaveToExcel
|
||||||
|
//
|
||||||
|
this.buttonSaveToExcel.Location = new System.Drawing.Point(0, 6);
|
||||||
|
this.buttonSaveToExcel.Name = "buttonSaveToExcel";
|
||||||
|
this.buttonSaveToExcel.Size = new System.Drawing.Size(223, 29);
|
||||||
|
this.buttonSaveToExcel.TabIndex = 3;
|
||||||
|
this.buttonSaveToExcel.Text = "Сохранить в Excel";
|
||||||
|
this.buttonSaveToExcel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click);
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.AllowUserToAddRows = false;
|
||||||
|
this.dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridView.AllowUserToOrderColumns = true;
|
||||||
|
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||||
|
this.ColumnShop,
|
||||||
|
this.ColumnSushi,
|
||||||
|
this.ColumnCount});
|
||||||
|
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(0, 47);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.ReadOnly = true;
|
||||||
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(598, 403);
|
||||||
|
this.dataGridView.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// ColumnShop
|
||||||
|
//
|
||||||
|
this.ColumnShop.FillWeight = 130F;
|
||||||
|
this.ColumnShop.HeaderText = "Магазин";
|
||||||
|
this.ColumnShop.MinimumWidth = 6;
|
||||||
|
this.ColumnShop.Name = "ColumnShop";
|
||||||
|
this.ColumnShop.ReadOnly = true;
|
||||||
|
//
|
||||||
|
// ColumnSushi
|
||||||
|
//
|
||||||
|
this.ColumnSushi.FillWeight = 140F;
|
||||||
|
this.ColumnSushi.HeaderText = "Пицца";
|
||||||
|
this.ColumnSushi.MinimumWidth = 6;
|
||||||
|
this.ColumnSushi.Name = "ColumnSushi";
|
||||||
|
this.ColumnSushi.ReadOnly = true;
|
||||||
|
//
|
||||||
|
// ColumnCount
|
||||||
|
//
|
||||||
|
this.ColumnCount.FillWeight = 90F;
|
||||||
|
this.ColumnCount.HeaderText = "Количество";
|
||||||
|
this.ColumnCount.MinimumWidth = 6;
|
||||||
|
this.ColumnCount.Name = "ColumnCount";
|
||||||
|
this.ColumnCount.ReadOnly = true;
|
||||||
|
//
|
||||||
|
// FormReportShop
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(598, 450);
|
||||||
|
this.Controls.Add(this.buttonSaveToExcel);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Name = "FormReportShop";
|
||||||
|
this.Text = "Наполненость магазинов";
|
||||||
|
this.Load += new System.EventHandler(this.FormReportShop_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonSaveToExcel;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private DataGridViewTextBoxColumn ColumnShop;
|
||||||
|
private DataGridViewTextBoxColumn ColumnSushi;
|
||||||
|
private DataGridViewTextBoxColumn ColumnCount;
|
||||||
|
}
|
||||||
|
}
|
78
SushiBar/SushiBarView/FormReportShop.cs
Normal file
78
SushiBar/SushiBarView/FormReportShop.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.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 SushiBarView
|
||||||
|
{
|
||||||
|
public partial class FormReportShop : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IReportLogic _logic;
|
||||||
|
|
||||||
|
public FormReportShop(ILogger<FormReportShop> logger, IReportLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormReportShop_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dict = _logic.GetShops();
|
||||||
|
if (dict != null)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
foreach (var elem in dict)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" });
|
||||||
|
foreach (var listElem in elem.Sushis)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
|
||||||
|
}
|
||||||
|
dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount });
|
||||||
|
dataGridView.Rows.Add(Array.Empty<object>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка списка пицц по магазинам");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки списка пицц по магазинам");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSaveToExcel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" };
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logic.SaveShopsToExcelFile(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
SushiBar/SushiBarView/FormReportShop.resx
Normal file
120
SushiBar/SushiBarView/FormReportShop.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>
|
120
SushiBar/SushiBarView/FormSellSushi.Designer.cs
generated
Normal file
120
SushiBar/SushiBarView/FormSellSushi.Designer.cs
generated
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
namespace SushiBarView
|
||||||
|
{
|
||||||
|
partial class FormSellSushi
|
||||||
|
{
|
||||||
|
/// <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.labelSushi = new System.Windows.Forms.Label();
|
||||||
|
this.comboBoxSushi = new System.Windows.Forms.ComboBox();
|
||||||
|
this.labelCount = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonSell = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelSushi
|
||||||
|
//
|
||||||
|
this.labelSushi.AutoSize = true;
|
||||||
|
this.labelSushi.Location = new System.Drawing.Point(12, 14);
|
||||||
|
this.labelSushi.Name = "labelSushi";
|
||||||
|
this.labelSushi.Size = new System.Drawing.Size(75, 20);
|
||||||
|
this.labelSushi.TabIndex = 0;
|
||||||
|
this.labelSushi.Text = "Суши: ";
|
||||||
|
//
|
||||||
|
// comboBoxSushi
|
||||||
|
//
|
||||||
|
this.comboBoxSushi.FormattingEnabled = true;
|
||||||
|
this.comboBoxSushi.Location = new System.Drawing.Point(115, 11);
|
||||||
|
this.comboBoxSushi.Name = "comboBoxSushi";
|
||||||
|
this.comboBoxSushi.Size = new System.Drawing.Size(239, 28);
|
||||||
|
this.comboBoxSushi.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
this.labelCount.AutoSize = true;
|
||||||
|
this.labelCount.Location = new System.Drawing.Point(12, 55);
|
||||||
|
this.labelCount.Name = "labelCount";
|
||||||
|
this.labelCount.Size = new System.Drawing.Size(97, 20);
|
||||||
|
this.labelCount.TabIndex = 2;
|
||||||
|
this.labelCount.Text = "Количество: ";
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
this.textBoxCount.Location = new System.Drawing.Point(115, 52);
|
||||||
|
this.textBoxCount.Name = "textBoxCount";
|
||||||
|
this.textBoxCount.Size = new System.Drawing.Size(239, 27);
|
||||||
|
this.textBoxCount.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonSell
|
||||||
|
//
|
||||||
|
this.buttonSell.Location = new System.Drawing.Point(128, 99);
|
||||||
|
this.buttonSell.Name = "buttonSell";
|
||||||
|
this.buttonSell.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonSell.TabIndex = 4;
|
||||||
|
this.buttonSell.Text = "Продать";
|
||||||
|
this.buttonSell.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(242, 99);
|
||||||
|
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);
|
||||||
|
//
|
||||||
|
// FormSellSushi
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(366, 140);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSell);
|
||||||
|
this.Controls.Add(this.textBoxCount);
|
||||||
|
this.Controls.Add(this.labelCount);
|
||||||
|
this.Controls.Add(this.comboBoxSushi);
|
||||||
|
this.Controls.Add(this.labelSushi);
|
||||||
|
this.Name = "FormSellSushi";
|
||||||
|
this.Text = "Продажа суши";
|
||||||
|
this.Load += new System.EventHandler(this.FormSellingSushi_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label labelSushi;
|
||||||
|
private ComboBox comboBoxSushi;
|
||||||
|
private Label labelCount;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private Button buttonSell;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
88
SushiBar/SushiBarView/FormSellSushi.cs
Normal file
88
SushiBar/SushiBarView/FormSellSushi.cs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
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 SushiBarView
|
||||||
|
{
|
||||||
|
public partial class FormSellSushi : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ISushiLogic _logicP;
|
||||||
|
private readonly IShopLogic _logicS;
|
||||||
|
private List<SushiViewModel> _sushiList = new List<SushiViewModel>();
|
||||||
|
|
||||||
|
public FormSellSushi(ILogger<FormSellSushi> logger, ISushiLogic logicP, IShopLogic logicS)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicP = logicP;
|
||||||
|
_logicS = logicS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormSellingSushi_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_sushiList = _logicP.ReadList(null);
|
||||||
|
if (_sushiList != null)
|
||||||
|
{
|
||||||
|
comboBoxSushi.DisplayMember = "SushiName";
|
||||||
|
comboBoxSushi.ValueMember = "Id";
|
||||||
|
comboBoxSushi.DataSource = _sushiList;
|
||||||
|
comboBoxSushi.SelectedItem = null;
|
||||||
|
_logger.LogInformation("Загрузка суши для продажи");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSell_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (comboBoxSushi.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите суши", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Создание покупки");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool resout = _logicS.Sale(new SupplySearchModel
|
||||||
|
{
|
||||||
|
SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue),
|
||||||
|
Count = Convert.ToInt32(textBoxCount.Text)
|
||||||
|
});
|
||||||
|
if (resout)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Проверка пройдена, продажа проведена");
|
||||||
|
MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Проверка не пройдена");
|
||||||
|
MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
SushiBar/SushiBarView/FormSellSushi.resx
Normal file
120
SushiBar/SushiBarView/FormSellSushi.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>
|
222
SushiBar/SushiBarView/FormShop.Designer.cs
generated
Normal file
222
SushiBar/SushiBarView/FormShop.Designer.cs
generated
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
namespace SushiBarView
|
||||||
|
{
|
||||||
|
partial class FormShop
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.labelName = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxAdress = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelAdress = new System.Windows.Forms.Label();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.id = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.SushiName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
|
this.dateTimeOpen = new System.Windows.Forms.DateTimePicker();
|
||||||
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
|
this.numericUpSushiMaxCount = new System.Windows.Forms.NumericUpDown();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpSushiMaxCount)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
this.labelName.AutoSize = true;
|
||||||
|
this.labelName.Location = new System.Drawing.Point(11, 15);
|
||||||
|
this.labelName.Name = "labelName";
|
||||||
|
this.labelName.Size = new System.Drawing.Size(84, 20);
|
||||||
|
this.labelName.TabIndex = 0;
|
||||||
|
this.labelName.Text = "Название: ";
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
this.textBoxName.Location = new System.Drawing.Point(102, 12);
|
||||||
|
this.textBoxName.Name = "textBoxName";
|
||||||
|
this.textBoxName.Size = new System.Drawing.Size(276, 27);
|
||||||
|
this.textBoxName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// textBoxAdress
|
||||||
|
//
|
||||||
|
this.textBoxAdress.Location = new System.Drawing.Point(102, 59);
|
||||||
|
this.textBoxAdress.Name = "textBoxAdress";
|
||||||
|
this.textBoxAdress.Size = new System.Drawing.Size(427, 27);
|
||||||
|
this.textBoxAdress.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// labelAdress
|
||||||
|
//
|
||||||
|
this.labelAdress.AutoSize = true;
|
||||||
|
this.labelAdress.Location = new System.Drawing.Point(11, 61);
|
||||||
|
this.labelAdress.Name = "labelAdress";
|
||||||
|
this.labelAdress.Size = new System.Drawing.Size(58, 20);
|
||||||
|
this.labelAdress.TabIndex = 2;
|
||||||
|
this.labelAdress.Text = "Адрес: ";
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(451, 457);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(130, 44);
|
||||||
|
this.buttonCancel.TabIndex = 5;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(315, 457);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(130, 44);
|
||||||
|
this.buttonSave.TabIndex = 6;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.AllowUserToAddRows = false;
|
||||||
|
this.dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||||
|
this.id,
|
||||||
|
this.SushiName,
|
||||||
|
this.Count});
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(12, 185);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.ReadOnly = true;
|
||||||
|
this.dataGridView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
|
||||||
|
this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
|
||||||
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(569, 266);
|
||||||
|
this.dataGridView.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// id
|
||||||
|
//
|
||||||
|
this.id.HeaderText = "id";
|
||||||
|
this.id.MinimumWidth = 6;
|
||||||
|
this.id.Name = "id";
|
||||||
|
this.id.ReadOnly = true;
|
||||||
|
this.id.Visible = false;
|
||||||
|
//
|
||||||
|
// SushiName
|
||||||
|
//
|
||||||
|
this.SushiName.HeaderText = "Суши";
|
||||||
|
this.SushiName.MinimumWidth = 6;
|
||||||
|
this.SushiName.Name = "SushiName";
|
||||||
|
this.SushiName.ReadOnly = true;
|
||||||
|
//
|
||||||
|
// Count
|
||||||
|
//
|
||||||
|
this.Count.HeaderText = "Количество";
|
||||||
|
this.Count.MinimumWidth = 6;
|
||||||
|
this.Count.Name = "Count";
|
||||||
|
this.Count.ReadOnly = true;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(12, 103);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(110, 20);
|
||||||
|
this.label1.TabIndex = 8;
|
||||||
|
this.label1.Text = "Дата открытия";
|
||||||
|
//
|
||||||
|
// dateTimeOpen
|
||||||
|
//
|
||||||
|
this.dateTimeOpen.Location = new System.Drawing.Point(128, 103);
|
||||||
|
this.dateTimeOpen.Name = "dateTimeOpen";
|
||||||
|
this.dateTimeOpen.Size = new System.Drawing.Size(401, 27);
|
||||||
|
this.dateTimeOpen.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
this.label2.AutoSize = true;
|
||||||
|
this.label2.Location = new System.Drawing.Point(12, 148);
|
||||||
|
this.label2.Name = "label2";
|
||||||
|
this.label2.Size = new System.Drawing.Size(100, 20);
|
||||||
|
this.label2.TabIndex = 10;
|
||||||
|
this.label2.Text = "Вместимость";
|
||||||
|
//
|
||||||
|
// numericUpSushiMaxCount
|
||||||
|
//
|
||||||
|
this.numericUpSushiMaxCount.Location = new System.Drawing.Point(128, 146);
|
||||||
|
this.numericUpSushiMaxCount.Maximum = new decimal(new int[] {
|
||||||
|
10000,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpSushiMaxCount.Name = "numericUpSushiMaxCount";
|
||||||
|
this.numericUpSushiMaxCount.Size = new System.Drawing.Size(401, 27);
|
||||||
|
this.numericUpSushiMaxCount.TabIndex = 11;
|
||||||
|
//
|
||||||
|
// FormShop
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(593, 513);
|
||||||
|
this.Controls.Add(this.numericUpSushiMaxCount);
|
||||||
|
this.Controls.Add(this.label2);
|
||||||
|
this.Controls.Add(this.dateTimeOpen);
|
||||||
|
this.Controls.Add(this.label1);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.textBoxAdress);
|
||||||
|
this.Controls.Add(this.labelAdress);
|
||||||
|
this.Controls.Add(this.textBoxName);
|
||||||
|
this.Controls.Add(this.labelName);
|
||||||
|
this.Name = "FormShop";
|
||||||
|
this.Text = "Магазин";
|
||||||
|
this.Load += new System.EventHandler(this.FormShop_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpSushiMaxCount)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label labelName;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private TextBox textBoxAdress;
|
||||||
|
private Label labelAdress;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSave;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private DataGridViewTextBoxColumn id;
|
||||||
|
private DataGridViewTextBoxColumn SushiName;
|
||||||
|
private DataGridViewTextBoxColumn Count;
|
||||||
|
private Label label1;
|
||||||
|
private DateTimePicker dateTimeOpen;
|
||||||
|
private Label label2;
|
||||||
|
private NumericUpDown numericUpSushiMaxCount;
|
||||||
|
}
|
||||||
|
}
|
127
SushiBar/SushiBarView/FormShop.cs
Normal file
127
SushiBar/SushiBarView/FormShop.cs
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
using SushiBarDataModels.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.BusinessLogicsContracts;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
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 SushiBarView
|
||||||
|
{
|
||||||
|
public partial class FormShop : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _logic;
|
||||||
|
private int? _id;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
private Dictionary<int, (ISushiModel, int)> _ShopSushis;
|
||||||
|
private DateTime? _openingDate = null;
|
||||||
|
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_ShopSushis = new Dictionary<int, (ISushiModel, int)>();
|
||||||
|
}
|
||||||
|
private void FormShop_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var view = _logic.ReadElement(new ShopSearchModel
|
||||||
|
{
|
||||||
|
Id = _id.Value
|
||||||
|
});
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = view.ShopName;
|
||||||
|
textBoxAdress.Text = view.Adress;
|
||||||
|
dateTimeOpen.Value = view.OpeningDate;
|
||||||
|
numericUpSushiMaxCount.Value = view.SushiMaxCount;
|
||||||
|
_ShopSushis = view.ShopSushis ?? new Dictionary<int, (ISushiModel, int)>();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка изделий в магазине");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_ShopSushis != null)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
foreach (var sr in _ShopSushis)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.SushiName, sr.Value.Item2 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки изделий магазина");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxAdress.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение магазина");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
ShopName = textBoxName.Text,
|
||||||
|
Adress = textBoxAdress.Text,
|
||||||
|
OpeningDate = dateTimeOpen.Value,
|
||||||
|
SushiMaxCount = (int)numericUpSushiMaxCount.Value
|
||||||
|
};
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
SushiBar/SushiBarView/FormShop.resx
Normal file
120
SushiBar/SushiBarView/FormShop.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>
|
130
SushiBar/SushiBarView/FormShops.Designer.cs
generated
Normal file
130
SushiBar/SushiBarView/FormShops.Designer.cs
generated
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
namespace SushiBarView
|
||||||
|
{
|
||||||
|
partial class FormShops
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.ToolsPanel = new System.Windows.Forms.Panel();
|
||||||
|
this.buttonRef = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.ToolsPanel.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// ToolsPanel
|
||||||
|
//
|
||||||
|
this.ToolsPanel.Controls.Add(this.buttonRef);
|
||||||
|
this.ToolsPanel.Controls.Add(this.buttonDel);
|
||||||
|
this.ToolsPanel.Controls.Add(this.buttonUpd);
|
||||||
|
this.ToolsPanel.Controls.Add(this.buttonAdd);
|
||||||
|
this.ToolsPanel.Location = new System.Drawing.Point(608, 12);
|
||||||
|
this.ToolsPanel.Name = "ToolsPanel";
|
||||||
|
this.ToolsPanel.Size = new System.Drawing.Size(180, 426);
|
||||||
|
this.ToolsPanel.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
this.buttonRef.Location = new System.Drawing.Point(31, 206);
|
||||||
|
this.buttonRef.Name = "buttonRef";
|
||||||
|
this.buttonRef.Size = new System.Drawing.Size(126, 36);
|
||||||
|
this.buttonRef.TabIndex = 3;
|
||||||
|
this.buttonRef.Text = "Обновить";
|
||||||
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(31, 142);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(126, 36);
|
||||||
|
this.buttonDel.TabIndex = 2;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(31, 76);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(126, 36);
|
||||||
|
this.buttonUpd.TabIndex = 1;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(31, 16);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(126, 36);
|
||||||
|
this.buttonAdd.TabIndex = 0;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.AllowUserToAddRows = false;
|
||||||
|
this.dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.ReadOnly = true;
|
||||||
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(590, 426);
|
||||||
|
this.dataGridView.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// FormShops
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Controls.Add(this.ToolsPanel);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Name = "FormShops";
|
||||||
|
this.Text = "Магазины";
|
||||||
|
this.Load += new System.EventHandler(this.FormShops_Load);
|
||||||
|
this.ToolsPanel.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Panel ToolsPanel;
|
||||||
|
private Button buttonRef;
|
||||||
|
private Button buttonDel;
|
||||||
|
private Button buttonUpd;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
}
|
||||||
|
}
|
117
SushiBar/SushiBarView/FormShops.cs
Normal file
117
SushiBar/SushiBarView/FormShops.cs
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.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 SushiBarView
|
||||||
|
{
|
||||||
|
public partial class FormShops : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IShopLogic _logic;
|
||||||
|
|
||||||
|
public FormShops(ILogger<FormShops> logger, IShopLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormShops_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logic.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
dataGridView.Columns["ShopSushis"].Visible = false;
|
||||||
|
dataGridView.Columns["ShopName"].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(FormShop));
|
||||||
|
if (service is FormShop 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(FormShop));
|
||||||
|
if (service is FormShop 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 ShopBindingModel
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user