diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/OrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/OrderLogic.cs index e2d03fb..73bd581 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/OrderLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/OrderLogic.cs @@ -20,11 +20,17 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic private readonly IOrderStorage _orderStorage; + private readonly IShopLogic _shopLogic; + + private readonly IFurnitureStorage _furnitureStorage; + // Конструктор - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, IFurnitureStorage furnitureStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _furnitureStorage = furnitureStorage; } // Вывод отфильтрованного списка компонентов @@ -35,7 +41,7 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic // list хранит весь список в случае, если model пришло со значением null на вход метода var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if(list == null) + if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -52,7 +58,7 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic { CheckModel(model); - if(model.Status != OrderStatus.Неизвестен) + if (model.Status != OrderStatus.Неизвестен) { _logger.LogWarning("Insert operation failed, incorrect order status"); return false; @@ -60,7 +66,7 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic model.Status = OrderStatus.Принят; - if(_orderStorage.Insert(model) == null) + if (_orderStorage.Insert(model) == null) { model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); @@ -100,30 +106,30 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic } // Проверка на наличие товаров в заказе - if(model.Count <= 0) + if (model.Count <= 0) { throw new ArgumentNullException("В заказе не может быть 0 изделий", nameof(model.Count)); } // Проверка на наличие нормальной суммарной стоимости чека - if(model.Sum <= 0) + if (model.Sum <= 0) { throw new ArgumentNullException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); } // Проверка корректности id у изделий - if(model.FurnitureId < 0) + if (model.FurnitureId < 0) { throw new ArgumentNullException("Некорректный id у изделия", nameof(model.FurnitureId)); } // Проверка корректности дат - if(model.DateCreate > model.DateImplement) + if (model.DateCreate > model.DateImplement) { throw new InvalidOperationException("Дата создания должна быть более ранней, нежели дата завершения"); } - _logger.LogInformation("Order. OrderId:{Id}, Sum:{Sum}. FurnitureId:{Id}", model.Id, model.Sum, model.FurnitureId); + _logger.LogInformation("Order. OrderId:{Id}, Sum:{Sum}. FurnitureId:{Id}. Sum:{Sum}", model.Id, model.Sum, model.FurnitureId, model.Sum); } // Обновление статуса заказа @@ -132,13 +138,13 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); // Если не смогли найти указанный заказ по его Id - if(viewModel == null) + if (viewModel == null) { throw new ArgumentNullException(nameof(model)); } // Проверка на возможность обновления статуса на следующий - if(viewModel.Status + 1 != newOrderStatus) + if (viewModel.Status + 1 != newOrderStatus) { _logger.LogWarning("Status update operation failed. New status " + newOrderStatus.ToString() + "incorrect"); return false; @@ -147,9 +153,21 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic model.Status = newOrderStatus; // Проверка на выдачу - if(model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; + + var furniture = _furnitureStorage.GetElement(new() { Id = viewModel.FurnitureId }); + + if (furniture == null) + { + throw new ArgumentNullException(nameof(furniture)); + } + + if (!_shopLogic.AddFurnitures(furniture, viewModel.Count)) + { + throw new Exception($"Невозможно выдать изделия, магазины переполнены. Operation failed. Shop is full."); + } } else { @@ -159,7 +177,7 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic CheckModel(model, false); // Финальная проверка на возможность обновления - if(_orderStorage.Update(model) == null) + if (_orderStorage.Update(model) == null) { model.Status--; diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/ReportLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/ReportLogic.cs index f672ccd..5f64290 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/ReportLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/ReportLogic.cs @@ -20,6 +20,8 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; @@ -27,12 +29,12 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic private readonly AbstractSaveToPdf _saveToPdf; // Инициализируем поля класса через контейнер - public ReportLogic(IFurnitureStorage furnitureStorage, - IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, - AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + public ReportLogic(IFurnitureStorage furnitureStorage, IOrderStorage orderStorage, IShopStorage shopStorage, + AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _furnitureStorage = furnitureStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; @@ -67,6 +69,30 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic return list; } + // Получение списка изделий с указанием, в каких магазинах в наличии + public List GetShopFurnitures() + { + var shops = _shopStorage.GetFullList(); + var list = new List(); + + foreach (var shop in shops) + { + var record = new ReportShopFurnituresViewModel + { + ShopName = shop.ShopName, + Furnitures = new List>(), + TotalCount = 0 + }; + foreach (var furniturecount in shop.ShopFurnitures.Values) + { + record.Furnitures.Add(new Tuple(furniturecount.Item1.FurnitureName, furniturecount.Item2)); + record.TotalCount += furniturecount.Item2; + } + list.Add(record); + } + return list; + } + // Получение списка заказов за определённый период public List GetOrders(ReportBindingModel model) { @@ -81,6 +107,20 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic }).ToList(); } + // Получение списка заказов за весь период + public List GetGroupedOrders() + { + return _orderStorage.GetFullList() + .GroupBy(x => x.DateCreate.Date) + .Select(x => new ReportGroupedOrdersViewModel + { + DateCreate = x.Key, + Count = x.Count(), + Sum = x.Sum(x => x.Sum) + }) + .ToList(); + } + // Сохранение мебели в файл-Word public void SaveFurnituresToWordFile(ReportBindingModel model) { @@ -92,6 +132,17 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic }); } + // Сохранение магазинов в файл-Word + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateTableDoc(new WordInfo + { + FileName = model.FileName, + Title = "Таблица магазинов", + Shops = _shopStorage.GetFullList() + }); + } + // Сохранение заготовок с указанием изделий в файл_Excel public void SaveFurnitureWorkPieceToExcelFile(ReportBindingModel model) { @@ -103,6 +154,17 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic }); } + // Сохранение магазинов с указанием изделий в файл-Excel + public void SaveShopFurnituresToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список магазинов", + ShopFurnitures = GetShopFurnitures() + }); + } + // Сохранение заказов в файл-Pdf public void SaveOrdersToPdfFile(ReportBindingModel model) { @@ -115,5 +177,16 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic Orders = GetOrders(model) }); } + + //Сохранение заказов за весь период в файл-Pdf + public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateGroupedDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список заказов", + GroupedOrders = GetGroupedOrders() + }); + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/ShopLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/ShopLogic.cs new file mode 100644 index 0000000..c1d267c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/ShopLogic.cs @@ -0,0 +1,267 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.BussinessLogic +{ + // Класс, реализующий логику для магазинов + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + private readonly IShopStorage _shopStorage; + + // Конструктор + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + // Вывод конкретного магазина + 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 List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); + + // list хранит весь список в случае, если model пришло со значением null на вход метода + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + // Пополнение магазина + public bool AddFurniture(ShopSearchModel model, IFurnitureModel furniture, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (count <= 0) + { + throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count)); + } + + _logger.LogInformation("AddFurniture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); + var shop = _shopStorage.GetElement(model); + + if (shop == null) + { + _logger.LogWarning("Add Furniture operation failed"); + + return false; + } + + if (shop.MaxCountFurnitures - shop.ShopFurnitures.Select(x => x.Value.Item2).Sum() < count) + { + throw new ArgumentNullException("Слишком много изделий для одного магазина", nameof(count)); + } + + if (!shop.ShopFurnitures.ContainsKey(furniture.Id)) + { + shop.ShopFurnitures[furniture.Id] = (furniture, count); + } + else + { + shop.ShopFurnitures[furniture.Id] = (furniture, shop.ShopFurnitures[furniture.Id].Item2 + count); + } + + _shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + MaxCountFurnitures = shop.MaxCountFurnitures, + ShopFurnitures = shop.ShopFurnitures + }); + + return true; + } + + // Создание магазина + public bool Create(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + + return false; + } + + return true; + } + + // Обновление магазина + public bool Update(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + + return false; + } + + return true; + } + + // Удаление магазина + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + + return false; + } + + return true; + } + + // Проверка входного аргумента для методов Insert, Update и Delete + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + // При удалении передаём как параметр false + if (!withParams) + { + return; + } + + // Проверка на наличие названия магазина + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Отсутствует названия магазина", nameof(model.ShopName)); + } + + // Проверка на наличие адреса у магазина + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Отсутствует адреса магазина", nameof(model.Address)); + } + + _logger.LogInformation("Shop. ShopName:{ShopName}. Address:{Address}. Id: {Id}", model.ShopName, model.Address, model.Id); + + // Проверка на наличие такого же магазина в списке + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + + // Если элемент найден и его Id не совпадает с Id переданного объекта + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + + public bool AddFurnitures(IFurnitureModel model, int count) + { + if (count <= 0) + { + throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count)); + } + + _logger.LogInformation("AddFurnitures. Furniture: {Furniture}. Count: {Count}", model?.FurnitureName, count); + + var capacity = _shopStorage.GetFullList().Select(x => x.MaxCountFurnitures - x.ShopFurnitures.Select(x => x.Value.Item2).Sum()).Sum() - count; + + if (capacity < 0) + { + _logger.LogWarning("AddFurnitures operation failed. Sell {count} Furnitures ", -capacity); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + if (shop.MaxCountFurnitures - shop.ShopFurnitures.Select(x => x.Value.Item2).Sum() < count) + { + if (!AddFurniture(new() { Id = shop.Id }, model, shop.MaxCountFurnitures - shop.ShopFurnitures.Select(x => x.Value.Item2).Sum())) + { + _logger.LogWarning("AddFurnitures operation failed."); + + return false; + } + + count -= shop.MaxCountFurnitures - shop.ShopFurnitures.Select(x => x.Value.Item2).Sum(); + } + else + { + if (!AddFurniture(new() { Id = shop.Id }, model, count)) + { + _logger.LogWarning("AddFurnitures operation failed."); + + return false; + } + + count -= count; + } + + if (count == 0) + { + return true; + } + } + + return true; + } + + public bool SellFurnitures(IFurnitureModel model, int count) + { + return _shopStorage.SellFurnitures(model, count); + } + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj index 924efab..63180e5 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureAssemblyBusinessLogic.csproj @@ -1,21 +1,21 @@  - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - - - - - + + + + + + + - - - + + + diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 6732864..3dc42a9 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -86,6 +86,81 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage SaveExcel(info); } + public void CreateShopReport(ExcelInfo info) + { + CreateExcel(info); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + + uint rowIndex = 2; + + foreach (var sm in info.ShopFurnitures) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = sm.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + + rowIndex++; + + foreach (var (Furniture, Count) in sm.Furnitures) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Furniture, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + rowIndex++; + } + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = sm.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + + rowIndex++; + } + + SaveExcel(info); + } + // Создание Excel-файла protected abstract void CreateExcel(ExcelInfo info); diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 74e7261..0cf5a82 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -58,6 +58,36 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage SavePdf(info); } + public void CreateGroupedDoc(PdfInfo info) + { + CreatePdf(info); + + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "3cm", "3cm", "3cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата заказа", "Количество заказов", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var order in info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.DateCreate.ToShortDateString(), order.Count.ToString(), order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.GroupedOrders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + SavePdf(info); + } + /// Создание Pdf-файла protected abstract void CreatePdf(PdfInfo info); diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs index ee2ddf5..f353ff7 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -44,12 +44,41 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage SaveWord(info); } + public void CreateTableDoc(WordInfo wordInfo) + { + CreateWord(wordInfo); + + var list = new List(); + + foreach (var shop in wordInfo.Shops) + { + list.Add(shop.ShopName); + list.Add(shop.Address); + list.Add(shop.DateOpen.ToString()); + } + + var wordTable = new WordTable + { + Headers = new List { + "Название", + "Адрес", + "Дата открытия"}, + Texts = list + }; + + CreateTable(wordTable); + SaveWord(wordInfo); + } + // Создание Doc-файла protected abstract void CreateWord(WordInfo info); // Создание абзаца с текстом protected abstract void CreateParagraph(WordParagraph paragraph); + // Создание таблицы + protected abstract void CreateTable(WordTable info); + // Сохранение файла protected abstract void SaveWord(WordInfo info); } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 34b71b5..798f90d 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -18,5 +18,8 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels // Список заготовок по изделиям public List FurnitureWorkPieces { get; set; } = new(); + + // Список магазинов с изделиями + public List ShopFurnitures { get; set; } = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 7e9549d..cad79cb 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -20,5 +20,8 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels // Перечень заказов за указанный период для вывода/сохранения public List Orders { get; set; } = new(); + + // Перечень заказов за весь период для вывода и сохранения + public List GroupedOrders { get; set; } = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 987a54a..4ec499c 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -14,7 +14,10 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; - //список заготовок для вывода и сохранения + // Список заготовок для вывода и сохранения public List Furnitures { get; set; } = new(); + + // Список магазинов для вывода и сохранения + public List Shops { get; set; } = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs index 12c062a..9e469a1 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -12,7 +12,9 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels // Набор текстов в абзаце (для случая, если в абзаце текст разных стилей) public List<(string, WordTextProperties)> Texts { get; set; } = new(); - //свойства параграфа, если они есть + // Свойства параграфа, если они есть public WordTextProperties? TextProperties { get; set; } + + public List> RowTexts { get; set; } = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordTable.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordTable.cs new file mode 100644 index 0000000..520dde3 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordTable.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels +{ + public class WordTable + { + public List Headers { get; set; } = new(); + + public List Texts { get; set; } = new(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index 68128dc..1e38296 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -184,11 +184,8 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements }; var stylesheetExtensionList = new StylesheetExtensionList(); - var stylesheetExtension1 = new StylesheetExtension() - { - Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" - }; + var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); stylesheetExtension1.Append(new SlicerStyles() { @@ -331,6 +328,7 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements }; row.InsertBefore(newCell, refCell); + cell = newCell; } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 66e8513..933cbe0 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -73,10 +73,7 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements if (!string.IsNullOrEmpty(paragraphProperties.Size)) { - paragraphMarkRunProperties.AppendChild(new FontSize - { - Val = paragraphProperties.Size - }); + paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size }); } properties.AppendChild(paragraphMarkRunProperties); @@ -127,11 +124,7 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements docRun.AppendChild(properties); - docRun.AppendChild(new Text - { - Text = run.Item1, - Space = SpaceProcessingModeValues.Preserve - }); + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); docParagraph.AppendChild(docRun); } @@ -155,5 +148,109 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements _wordDocument.Dispose(); } + + protected override void CreateTable(WordTable table) + { + if (_docBody == null || table == null) + { + return; + } + + Table tab = new Table(); + + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }) + ); + + tab.AppendChild(props); + TableGrid tableGrid = new TableGrid(); + + for (int i = 0; i < table.Headers.Count; i++) + { + tableGrid.AppendChild(new GridColumn()); + } + + tab.AppendChild(tableGrid); + TableRow tableRow = new TableRow(); + + foreach (var text in table.Headers) + { + tableRow.AppendChild(CreateTableCell(text)); + } + + tab.AppendChild(tableRow); + + int height = table.Texts.Count / table.Headers.Count; + int width = table.Headers.Count; + + for (int i = 0; i < height; i++) + { + tableRow = new TableRow(); + + for (int j = 0; j < width; j++) + { + var element = table.Texts[i * table.Headers.Count + j]; + tableRow.AppendChild(CreateTableCell(element)); + } + + tab.AppendChild(tableRow); + } + + _docBody.AppendChild(tab); + + } + + private TableCell CreateTableCell(string element) + { + var tableParagraph = new Paragraph(); + + var run = new Run(); + + run.AppendChild(new Text + { + Text = element + }); + + tableParagraph.AppendChild(run); + var tableCell = new TableCell(); + tableCell.AppendChild(tableParagraph); + + return tableCell; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..2d081ce --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,25 @@ +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.BindingModels +{ + // Реализация сущности "Магазин" + public class ShopBindingModel : IShopModel + { + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpen { get; set; } = DateTime.Now; + + public Dictionary ShopFurnitures { get; set; } = new(); + + public int Id { get; set; } + + public int MaxCountFurnitures { get; set; } + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/WorkPieceBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/WorkPieceBindingModel.cs index ac6fd32..6a0b2ae 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/WorkPieceBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/WorkPieceBindingModel.cs @@ -15,4 +15,4 @@ namespace FurnitureAssemblyContracts.BindingModels public double Cost { get; set; } } -} +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IReportLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IReportLogic.cs index 3ab8a6f..da3f497 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IReportLogic.cs @@ -13,16 +13,31 @@ namespace FurnitureAssemblyContracts.BusinessLogicsContracts // Получение списка заготовок с указанием, в каких изделиях используются List GetFurnitureWorkPiece(); + //Получение списка мороженых с указанием, в каких магазинах в наличии + List GetShopFurnitures(); + // Получение списка заказов за определённый период List GetOrders(ReportBindingModel model); + //Получение списка заказов за весь период + List GetGroupedOrders(); + // Сохранение изделий в файл-Word void SaveFurnituresToWordFile(ReportBindingModel model); + //Сохранение магазинов в виде таблицы в файл-Word + void SaveShopsToWordFile(ReportBindingModel model); + // Сохранение заготовок с указанием изделий в файл-Excel void SaveFurnitureWorkPieceToExcelFile(ReportBindingModel model); + //Сохранение магазинов с указанием мороженых в файл-Excel + void SaveShopFurnituresToExcelFile(ReportBindingModel model); + // Сохранение заказов в файл-Pdf void SaveOrdersToPdfFile(ReportBindingModel model); + + //Сохранение заказов за весь период в файл-Pdf + void SaveGroupedOrdersToPdfFile(ReportBindingModel model); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..93bd241 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,32 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.BusinessLogicsContracts +{ + // Бизнес-логика для магазина + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + + ShopViewModel? ReadElement(ShopSearchModel model); + + bool Create(ShopBindingModel model); + + bool Update(ShopBindingModel model); + + bool Delete(ShopBindingModel model); + + bool AddFurniture(ShopSearchModel model, IFurnitureModel furniture, int count); + + bool SellFurnitures(IFurnitureModel model, int count); + + bool AddFurnitures(IFurnitureModel model, int count); + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/OrderSearchModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/OrderSearchModel.cs index de0a639..26fb864 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/OrderSearchModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/OrderSearchModel.cs @@ -15,6 +15,6 @@ namespace FurnitureAssemblyContracts.SearchModels // Два поля для возможности производить выборку public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set;} + public DateTime? DateTo { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ShopSearchModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..1bd651a --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.SearchModels +{ + // Для поиска сущности "Магазин" + public class ShopSearchModel + { + // Для поиска по идентификатору + public int? Id { get; set; } + + // Для поиска по названию + public string? ShopName { get; set; } + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..ad33710 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,30 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.StoragesContracts +{ + // Класс для хранилища магазинов + public interface IShopStorage + { + List GetFullList(); + + List GetFilteredList(ShopSearchModel model); + + ShopViewModel? GetElement(ShopSearchModel model); + + ShopViewModel? Insert(ShopBindingModel model); + + ShopViewModel? Update(ShopBindingModel model); + + ShopViewModel? Delete(ShopBindingModel model); + + bool SellFurnitures(IFurnitureModel model, int count); + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportGroupedOrdersViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportGroupedOrdersViewModel.cs new file mode 100644 index 0000000..6d62516 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportGroupedOrdersViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.ViewModels +{ + public class ReportGroupedOrdersViewModel + { + public DateTime DateCreate { get; set; } + + public int Count { get; set; } + + public double Sum { get; set; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportOrdersViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportOrdersViewModel.cs index 6533338..eae90d5 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportOrdersViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportOrdersViewModel.cs @@ -10,7 +10,7 @@ namespace FurnitureAssemblyContracts.ViewModels { public int Id { get; set; } - public DateTime DateCreate { get; set; } + public DateTime DateCreate { get; set; } public string FurnitureName { get; set; } = string.Empty; diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportShopFurnituresViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportShopFurnituresViewModel.cs new file mode 100644 index 0000000..0caf2cd --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportShopFurnituresViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.ViewModels +{ + public class ReportShopFurnituresViewModel + { + public string ShopName { get; set; } = string.Empty; + + public int TotalCount { get; set; } + + public List> Furnitures { get; set; } = new(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..c113fd8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,30 @@ +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.ViewModels +{ + // Класс для отображения пользователю информации о магазинах + public class ShopViewModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } = DateTime.Now; + + public Dictionary ShopFurnitures { get; set; } = new(); + + [DisplayName("Вместимость магазина")] + public int MaxCountFurnitures { get; set; } + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IShopModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..e961fa5 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IShopModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDataModels.Models +{ + // Интерфейс сущности "Магазин" + public interface IShopModel : IId + { + // Название магазина + string ShopName { get; } + + // Адрес магазина + string Address { get; } + + // Дата открытия магазина + DateTime DateOpen { get; } + + //максимальное кол-во изделий в магазине + int MaxCountFurnitures { get; } + + // Изделия в магазине + Dictionary ShopFurnitures { get; } + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs index ef1bba3..ed3df63 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs @@ -14,7 +14,7 @@ namespace FurnitureAssemblyDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=KatanaNik\SQLEXPRESS;Initial Catalog=FurnitureAssemblyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=KatanaNik\SQLEXPRESS;Initial Catalog=FurnitureAssemblyDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); @@ -27,5 +27,9 @@ namespace FurnitureAssemblyDatabaseImplement public virtual DbSet FurnitureWorkPieces { set; get; } public virtual DbSet Orders { set; get; } + + public virtual DbSet Shops { set; get; } + + public virtual DbSet ShopFurnitures { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs index d350e95..44ed3a7 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs @@ -97,13 +97,15 @@ namespace FurnitureAssemblyDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new FurnitureAssemblyDatabase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Orders.Include(x => x.Furniture).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { - // для более корректного отображения модели - var deletedElement = context.Orders.Include(x => x.Furniture) - .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + // для отображения корректной ViewModel-и + var deletedElement = context.Orders + .Include(x => x.Furniture) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; context.Orders.Remove(element); context.SaveChanges(); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..719f3cb --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,179 @@ +using FurnitureAssemblyDatabaseImplement.Models; +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public List GetFullList() + { + using var context = new FurnitureAssemblyDatabase(); + + return context.Shops + .Include(x => x.Furnitures) + .ThenInclude(x => x.Furniture) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + + using var context = new FurnitureAssemblyDatabase(); + + return context.Shops + .Include(x => x.Furnitures) + .ThenInclude(x => x.Furniture) + .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 null; + } + + using var context = new FurnitureAssemblyDatabase(); + + return context.Shops + .Include(x => x.Furnitures) + .ThenInclude(x => x.Furniture) + .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 FurnitureAssemblyDatabase(); + 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 FurnitureAssemblyDatabase(); + using var transaction = context.Database.BeginTransaction(); + + try + { + var shop = context.Shops.FirstOrDefault(rec => rec.Id == model.Id); + + if (shop == null) + { + return null; + } + + shop.Update(model); + context.SaveChanges(); + shop.UpdateFurnitures(context, model); + transaction.Commit(); + + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + + throw; + } + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new FurnitureAssemblyDatabase(); + + var element = context.Shops + .Include(x => x.Furnitures) + .FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Shops.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public bool SellFurnitures(IFurnitureModel model, int count) + { + using var context = new FurnitureAssemblyDatabase(); + using var transaction = context.Database.BeginTransaction(); + + try + { + var shops = context.ShopFurnitures + .Include(x => x.Shop) + .ToList() + .Where(rec => rec.FurnitureId == model.Id); + + if (shops == null) + { + return false; + } + + foreach (var shop in shops) + { + if (shop.Count < count) + { + count -= shop.Count; + shop.Count = 0; + } + else + { + shop.Count = shop.Count - count; + count -= count; + } + + if (count == 0) + { + context.SaveChanges(); + transaction.Commit(); + + return true; + } + } + + transaction.Rollback(); + + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240325045814_InitCreate.Designer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240503080524_InitialCreate.Designer.cs similarity index 67% rename from FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240325045814_InitCreate.Designer.cs rename to FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240503080524_InitialCreate.Designer.cs index 9fd79c6..2277a55 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240325045814_InitCreate.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240503080524_InitialCreate.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace FurnitureAssemblyDatabaseImplement.Migrations { [DbContext(typeof(FurnitureAssemblyDatabase))] - [Migration("20240325045814_InitCreate")] - partial class InitCreate + [Migration("20240503080524_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -104,6 +104,59 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpen") + .HasColumnType("datetime2"); + + b.Property("MaxCountFurnitures") + .HasColumnType("int"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("FurnitureId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopFurnitures"); + }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.WorkPiece", b => { b.Property("Id") @@ -154,13 +207,39 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.Navigation("Furniture"); }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Shops") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Shop", "Shop") + .WithMany("Furnitures") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Furniture"); + + b.Navigation("Shop"); + }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => { b.Navigation("Orders"); + b.Navigation("Shops"); + b.Navigation("WorkPieces"); }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Shop", b => + { + b.Navigation("Furnitures"); + }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.WorkPiece", b => { b.Navigation("FurnitureWorkPieces"); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240325045814_InitCreate.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240503080524_InitialCreate.cs similarity index 65% rename from FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240325045814_InitCreate.cs rename to FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240503080524_InitialCreate.cs index 571b046..fc73645 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240325045814_InitCreate.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240503080524_InitialCreate.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace FurnitureAssemblyDatabaseImplement.Migrations { /// - public partial class InitCreate : Migration + public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -25,6 +25,22 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations table.PrimaryKey("PK_Furnitures", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false), + DateOpen = table.Column(type: "datetime2", nullable: false), + MaxCountFurnitures = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + migrationBuilder.CreateTable( name: "WorkPieces", columns: table => new @@ -63,6 +79,33 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "ShopFurnitures", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopId = table.Column(type: "int", nullable: false), + FurnitureId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopFurnitures", x => x.Id); + table.ForeignKey( + name: "FK_ShopFurnitures_Furnitures_FurnitureId", + column: x => x.FurnitureId, + principalTable: "Furnitures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopFurnitures_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "FurnitureWorkPieces", columns: table => new @@ -104,6 +147,16 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations name: "IX_Orders_FurnitureId", table: "Orders", column: "FurnitureId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopFurnitures_FurnitureId", + table: "ShopFurnitures", + column: "FurnitureId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopFurnitures_ShopId", + table: "ShopFurnitures", + column: "ShopId"); } /// @@ -115,11 +168,17 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Orders"); + migrationBuilder.DropTable( + name: "ShopFurnitures"); + migrationBuilder.DropTable( name: "WorkPieces"); migrationBuilder.DropTable( name: "Furnitures"); + + migrationBuilder.DropTable( + name: "Shops"); } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs index 97e2bb5..ab2ddb6 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs @@ -101,6 +101,59 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpen") + .HasColumnType("datetime2"); + + b.Property("MaxCountFurnitures") + .HasColumnType("int"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("FurnitureId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopFurnitures"); + }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.WorkPiece", b => { b.Property("Id") @@ -151,13 +204,39 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.Navigation("Furniture"); }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Shops") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Shop", "Shop") + .WithMany("Furnitures") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Furniture"); + + b.Navigation("Shop"); + }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => { b.Navigation("Orders"); + b.Navigation("Shops"); + b.Navigation("WorkPieces"); }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Shop", b => + { + b.Navigation("Furnitures"); + }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.WorkPiece", b => { b.Navigation("FurnitureWorkPieces"); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs index b2f1f02..6c2e16c 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs @@ -47,6 +47,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models [ForeignKey("FurnitureId")] public virtual List Orders { get; set; } = new(); + [ForeignKey("FurnitureId")] + public virtual List Shops { get; set; } = new(); + public static Furniture Create(FurnitureAssemblyDatabase context, FurnitureBindingModel model) { return new Furniture() @@ -76,9 +79,6 @@ namespace FurnitureAssemblyDatabaseImplement.Models FurnitureWorkPieces = FurnitureWorkPieces }; - Dictionary IFurnitureModel.FurnitureWorkPieces => throw new NotImplementedException(); - - public void UpdateWorkPieces(FurnitureAssemblyDatabase context, FurnitureBindingModel model) { var furnitureWorkPieces = context.FurnitureWorkPieces.Where(rec => rec.FurnitureId == model.Id).ToList(); @@ -101,13 +101,13 @@ namespace FurnitureAssemblyDatabaseImplement.Models var furniture = context.Furnitures.First(x => x.Id == Id); - foreach(var pc in model.FurnitureWorkPieces) + foreach(var fwp in model.FurnitureWorkPieces) { context.FurnitureWorkPieces.Add(new FurnitureWorkPiece { Furniture = furniture, - WorkPiece = context.WorkPieces.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 + WorkPiece = context.WorkPieces.First(x => x.Id == fwp.Key), + Count = fwp.Value.Item2 }); context.SaveChanges(); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..67ff0dd --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Shop.cs @@ -0,0 +1,121 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDatabaseImplement; +using FurnitureAssemblyDatabaseImplement.Models; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; set; } + + [Required] + public string ShopName { get; set; } = string.Empty; + + [Required] + public string Address { get; set; } = string.Empty; + + [Required] + public DateTime DateOpen { get; set; } + + [Required] + public int MaxCountFurnitures { get; set; } + + private Dictionary? _shopFurnitures = null; + + [Required] + public Dictionary ShopFurnitures + { + get + { + if (_shopFurnitures == null) + { + _shopFurnitures = Furnitures.ToDictionary(recSI => recSI.FurnitureId, recSI => (recSI.Furniture as IFurnitureModel, recSI.Count)); + } + return _shopFurnitures; + } + } + + [ForeignKey("ShopId")] + public virtual List Furnitures { get; set; } = new(); + + public static Shop? Create(FurnitureAssemblyDatabase context, ShopBindingModel model) + { + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + Furnitures = model.ShopFurnitures.Select(x => new ShopFurniture + { + Furniture = context.Furnitures.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList(), + MaxCountFurnitures = model.MaxCountFurnitures + }; + } + + public void Update(ShopBindingModel model) + { + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + MaxCountFurnitures = model.MaxCountFurnitures; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + MaxCountFurnitures = MaxCountFurnitures, + ShopFurnitures = ShopFurnitures + }; + + public void UpdateFurnitures(FurnitureAssemblyDatabase context, ShopBindingModel model) + { + var shopFurnitures = context.ShopFurnitures.Where(rec => rec.ShopId == model.Id).ToList(); + + if (shopFurnitures != null && shopFurnitures.Count > 0) + { // удалили те, которых нет в модели + context.ShopFurnitures.RemoveRange(shopFurnitures.Where(rec => !model.ShopFurnitures.ContainsKey(rec.FurnitureId))); + context.SaveChanges(); + + // обновили количество у существующих записей + foreach (var _shopFurnitures in shopFurnitures) + { + _shopFurnitures.Count = model.ShopFurnitures[_shopFurnitures.FurnitureId].Item2; + model.ShopFurnitures.Remove(_shopFurnitures.FurnitureId); + } + + context.SaveChanges(); + } + + var shop = context.Shops.First(x => x.Id == Id); + + foreach (var sm in model.ShopFurnitures) + { + context.ShopFurnitures.Add(new ShopFurniture + { + Shop = shop, + Furniture = context.Furnitures.First(x => x.Id == sm.Key), + Count = sm.Value.Item2 + }); + + context.SaveChanges(); + } + + _shopFurnitures = null; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/ShopFurniture.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/ShopFurniture.cs new file mode 100644 index 0000000..5d1cc11 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/ShopFurniture.cs @@ -0,0 +1,28 @@ +using FurnitureAssemblyDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Models +{ + public class ShopFurniture + { + public int Id { get; set; } + + [Required] + public int ShopId { get; set; } + + [Required] + public int FurnitureId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Shop Shop { get; set; } = new(); + + public virtual Furniture Furniture { get; set; } = new(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs index c23286f..dae08a9 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs @@ -18,12 +18,16 @@ namespace FurnitureAssemblyFileImplement private readonly string FurnitureFileName = "Furniture.xml"; + private readonly string ShopFileName = "Shop.xml"; + public List WorkPieces { get; private set; } public List Orders { get; private set; } public List Furnitures { get; private set; } + public List Shops { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -40,12 +44,14 @@ namespace FurnitureAssemblyFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { WorkPieces = LoadData(WorkPieceFileName, "WorkPiece", x => WorkPiece.Create(x)!)!; Furnitures = LoadData(FurnitureFileName, "Furniture", x => Furniture.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/OrderStorage.cs index 48aa6b9..1832c6e 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/OrderStorage.cs @@ -31,7 +31,7 @@ namespace FurnitureAssemblyFileImplement.Implements if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) { return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => GetViewModel(x)).ToList(); + .Select(x => GetViewModel(x)).ToList(); } return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..b31cede --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,139 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyFileImplement.Implements +{ + // Реализация интерфейса хранилища магазинов + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton _source; + + public ShopStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return _source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public List 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.ShopName.Contains(model.ShopName) || x.Id == model.Id); + + if (shop == null) + { + return null; + } + + shop.Update(model); + _source.SaveShops(); + + return shop.GetViewModel; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + _source.Shops.Remove(element); + _source.SaveShops(); + + return element.GetViewModel; + } + + return null; + } + + public bool SellFurnitures(IFurnitureModel model, int count) + { + if (_source.Shops.Select(x => x.ShopFurnitures.FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum() < count) + { + return false; + } + + var list = _source.Shops.Where(x => x.ShopFurnitures.ContainsKey(model.Id)); + + foreach (var shop in list) + { + if (shop.ShopFurnitures[model.Id].Item2 < count) + { + count -= shop.ShopFurnitures[model.Id].Item2; + shop.ShopFurnitures[model.Id] = (shop.ShopFurnitures[model.Id].Item1, 0); + } + else + { + shop.ShopFurnitures[model.Id] = (shop.ShopFurnitures[model.Id].Item1, shop.ShopFurnitures[model.Id].Item2 - count); + count -= count; + } + + Update(new() + { + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + MaxCountFurnitures = shop.MaxCountFurnitures, + ShopFurnitures = shop.ShopFurnitures + }); + + if (count == 0) + { + return true; + } + } + + return true; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Shop.cs new file mode 100644 index 0000000..ed86277 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Shop.cs @@ -0,0 +1,111 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace FurnitureAssemblyFileImplement.Models +{ + // Класс, реализующий интерфейс модели магазина + public class Shop : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpen { get; set; } + + public int MaxCountFurnitures { get; set; } + + public Dictionary countFurniture { get; private set; } = new(); + + public Dictionary _furnitures = null; + + public Dictionary ShopFurnitures + { + get + { + if (_furnitures == null) + { + var source = DataFileSingleton.GetInstance(); + _furnitures = countFurniture.ToDictionary(x => x.Key, y => ((source.Furnitures.FirstOrDefault(z => z.Id == y.Key) as IFurnitureModel)!, y.Value)); + } + + return _furnitures; + } + } + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + MaxCountFurnitures = model.MaxCountFurnitures, + countFurniture = model.ShopFurnitures.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Shop? Create(XElement element) + + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value), + MaxCountFurnitures = Convert.ToInt32(element.Element("MaxCountFurnitures")!.Value), + countFurniture = element.Element("Furnitures")!.Elements("Furnitures").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + MaxCountFurnitures = model.MaxCountFurnitures; + countFurniture = model.ShopFurnitures.ToDictionary(x => x.Key, x => x.Value.Item2); + _furnitures = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + MaxCountFurnitures = MaxCountFurnitures, + ShopFurnitures = ShopFurnitures + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpen", DateOpen.ToString()), + new XElement("MaxCountFurnitures", MaxCountFurnitures.ToString()), + new XElement("Furnitures", countFurniture.Select(x => new XElement("Furnitures", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs index 1e72d6b..4740bc0 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs @@ -21,11 +21,15 @@ namespace FurnitureAssemblyListImplement // Список для хранения заказов public List Orders { get; set; } + //список для хранения Магазинов + public List Shops { get; set; } + public DataListSingleton() { WorkPiece = new List(); Furnitures = new List(); Orders = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..226151e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs @@ -0,0 +1,143 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement.Implements +{ + // Класс, реализующий интерфейс хранилища магазинов + public class ShopStorage : IShopStorage + { + // Поле для работы со списком магазинов + private readonly DataListSingleton _source; + + // Получение в конструкторе объекта DataListSingleton + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + // Получение элемента из списка заготовок + 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 List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + + 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 List GetFullList() + { + var result = new List(); + + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + + return result; + } + + // При создании магазина определяем для него новый id: ищем max id и прибавляем к нему 1 + 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 SellFurnitures(IFurnitureModel model, int count) + { + throw new NotImplementedException(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs index 92db798..2fccf76 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs @@ -28,6 +28,7 @@ namespace FurnitureAssemblyListImplement.Models public DateTime? DateImplement { get; private set; } + // Метод для создания объекта от класса-компонента на основе класса-BindingModel public static Order? Create(OrderBindingModel? model) { if(model == null) diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs new file mode 100644 index 0000000..ef019f2 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs @@ -0,0 +1,71 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement.Models +{ + // Класс, реализующий интерфейс модели магазина + public class Shop : IShopModel + { + // Методы set сделали приватными, чтобы исключить неразрешённые манипуляции + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpen { get; private set; } + + public int Id { get; private set; } + + public int MaxCountFurnitures { get; set; } + + public Dictionary ShopFurnitures { get; private set; } = + new Dictionary(); + + // Метод для создания объекта от класса-компонента на основе класса-BindingModel + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + ShopFurnitures = model.ShopFurnitures + }; + } + + // Метод изменения существующего объекта + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + ShopFurnitures = model.ShopFurnitures; + } + + // Метод для создания объекта класса ViewModel на основе данных объекта класса-компонента + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + ShopFurnitures = ShopFurnitures + }; + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.Designer.cs new file mode 100644 index 0000000..104793d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.Designer.cs @@ -0,0 +1,151 @@ +namespace FurnitureAssemblyView +{ + partial class FormAddFurniture + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelFurniture = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelShop = new System.Windows.Forms.Label(); + this.comboBoxFurniture = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // labelFurniture + // + this.labelFurniture.AutoSize = true; + this.labelFurniture.Location = new System.Drawing.Point(28, 58); + this.labelFurniture.Name = "labelFurniture"; + this.labelFurniture.Size = new System.Drawing.Size(56, 15); + this.labelFurniture.TabIndex = 0; + this.labelFurniture.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(28, 91); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(28, 23); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(57, 15); + this.labelShop.TabIndex = 2; + this.labelShop.Text = "Магазин:"; + // + // comboBoxFurniture + // + this.comboBoxFurniture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxFurniture.FormattingEnabled = true; + this.comboBoxFurniture.Location = new System.Drawing.Point(149, 55); + this.comboBoxFurniture.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxFurniture.Name = "comboBoxFurniture"; + this.comboBoxFurniture.Size = new System.Drawing.Size(230, 23); + this.comboBoxFurniture.TabIndex = 3; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(149, 88); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(230, 23); + this.textBoxCount.TabIndex = 4; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(209, 123); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(297, 123); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // comboBoxShop + // + this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(149, 23); + this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(230, 23); + this.comboBoxShop.TabIndex = 8; + // + // FormAddFurniture + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(394, 159); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxFurniture); + this.Controls.Add(this.labelShop); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelFurniture); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormAddFurniture"; + this.Text = "Пополнение магазина"; + this.Load += new System.EventHandler(this.FormAddFurniture_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelFurniture; + private Label labelCount; + private Label labelShop; + private ComboBox comboBoxFurniture; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxShop; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.cs b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.cs new file mode 100644 index 0000000..7ff52b0 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.cs @@ -0,0 +1,128 @@ +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FurnitureAssemblyView +{ + public partial class FormAddFurniture : Form + { + private readonly ILogger _logger; + private readonly IFurnitureLogic _logicI; + private readonly IShopLogic _logicS; + + public FormAddFurniture(ILogger logger, IFurnitureLogic logicI, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicI = logicI; + _logicS = logicS; + } + + private void FormAddFurniture_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка изделий для пополнения"); + + try + { + var list = _logicI.ReadList(null); + + if (list != null) + { + comboBoxFurniture.DisplayMember = "FurnitureName"; + comboBoxFurniture.ValueMember = "Id"; + comboBoxFurniture.DataSource = list; + comboBoxFurniture.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка списка магазинов для пополнения"); + try + { + var list = _logicS.ReadList(null); + + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + 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(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxFurniture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Пополнение магазина"); + + try + { + var operationResult = _logicS.AddFurniture(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + + _logicI.ReadElement(new FurnitureSearchModel() + { + Id = Convert.ToInt32(comboBoxFurniture.SelectedValue) + })!, Convert.ToInt32(textBoxCount.Text)); + + if (!operationResult) + { + throw new Exception("Ошибка при пополнении магазина. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.resx b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.Designer.cs index e7b3465..0200b5a 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.Designer.cs @@ -28,82 +28,83 @@ /// private void InitializeComponent() { - labelWorkPiece = new Label(); - labelCount = new Label(); - comboBoxWorkPiece = new ComboBox(); - textBoxCount = new TextBox(); - buttonSave = new Button(); - buttonCancel = new Button(); - SuspendLayout(); + this.labelWorkPiece = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxWorkPiece = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); // // labelWorkPiece // - labelWorkPiece.AutoSize = true; - labelWorkPiece.Location = new Point(31, 33); - labelWorkPiece.Name = "labelWorkPiece"; - labelWorkPiece.Size = new Size(81, 20); - labelWorkPiece.TabIndex = 0; - labelWorkPiece.Text = "Заготовка:"; + this.labelWorkPiece.AutoSize = true; + this.labelWorkPiece.Location = new System.Drawing.Point(31, 33); + this.labelWorkPiece.Name = "labelWorkPiece"; + this.labelWorkPiece.Size = new System.Drawing.Size(81, 20); + this.labelWorkPiece.TabIndex = 0; + this.labelWorkPiece.Text = "Заготовка:"; // // labelCount // - labelCount.AutoSize = true; - labelCount.Location = new Point(31, 79); - labelCount.Name = "labelCount"; - labelCount.Size = new Size(93, 20); - labelCount.TabIndex = 1; - labelCount.Text = "Количество:"; + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(31, 79); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; // // comboBoxWorkPiece // - comboBoxWorkPiece.FormattingEnabled = true; - comboBoxWorkPiece.Location = new Point(156, 30); - comboBoxWorkPiece.Name = "comboBoxWorkPiece"; - comboBoxWorkPiece.Size = new Size(320, 28); - comboBoxWorkPiece.TabIndex = 2; + this.comboBoxWorkPiece.FormattingEnabled = true; + this.comboBoxWorkPiece.Location = new System.Drawing.Point(156, 30); + this.comboBoxWorkPiece.Name = "comboBoxWorkPiece"; + this.comboBoxWorkPiece.Size = new System.Drawing.Size(320, 28); + this.comboBoxWorkPiece.TabIndex = 2; // // textBoxCount // - textBoxCount.Location = new Point(156, 76); - textBoxCount.Name = "textBoxCount"; - textBoxCount.Size = new Size(320, 27); - textBoxCount.TabIndex = 3; + this.textBoxCount.Location = new System.Drawing.Point(156, 76); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(320, 27); + this.textBoxCount.TabIndex = 3; // // buttonSave // - buttonSave.Location = new Point(236, 118); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(110, 38); - buttonSave.TabIndex = 4; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; + this.buttonSave.Location = new System.Drawing.Point(235, 118); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // buttonCancel // - buttonCancel.Location = new Point(363, 118); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(113, 38); - buttonCancel.TabIndex = 5; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; + this.buttonCancel.Location = new System.Drawing.Point(353, 118); + 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); // // FormFurnitureWorkPiece // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(526, 168); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(textBoxCount); - Controls.Add(comboBoxWorkPiece); - Controls.Add(labelCount); - Controls.Add(labelWorkPiece); - Name = "FormFurnitureWorkPiece"; - Text = "Заготовки для изделия"; - ResumeLayout(false); - PerformLayout(); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(526, 168); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxWorkPiece); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelWorkPiece); + this.Name = "FormFurnitureWorkPiece"; + this.Text = "Заготовки для изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.cs b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.cs index 4d8c935..ea61f85 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.cs @@ -18,11 +18,8 @@ namespace FurnitureAssemblyView { private readonly List? _list; - public int Id - { - get { return Convert.ToInt32(comboBoxWorkPiece.SelectedValue); } - set { comboBoxWorkPiece.SelectedValue = value; } - } + public int Id { get { return Convert.ToInt32(comboBoxWorkPiece.SelectedValue); } + set { comboBoxWorkPiece.SelectedValue = value; } } public IWorkPieceModel? WorkPieceModel { @@ -45,14 +42,8 @@ namespace FurnitureAssemblyView } } - public int Count - { - get { return Convert.ToInt32(textBoxCount.Text); } - set - { - textBoxCount.Text = value.ToString(); - } - } + public int Count { get { return Convert.ToInt32(textBoxCount.Text); } set { + textBoxCount.Text = value.ToString(); } } public FormFurnitureWorkPiece(IWorkPieceLogic logic) { @@ -60,7 +51,7 @@ namespace FurnitureAssemblyView _list = logic.ReadList(null); - if (_list != null) + if(_list != null) { comboBoxWorkPiece.DisplayMember = "WorkPieceName"; comboBoxWorkPiece.ValueMember = "Id"; @@ -74,14 +65,14 @@ namespace FurnitureAssemblyView if (string.IsNullOrEmpty(textBoxCount.Text)) { MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - + return; } if (comboBoxWorkPiece.SelectedValue == null) { MessageBox.Show("Выберите заготовку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - + return; } diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.resx b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.resx index af32865..f298a7b 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.resx +++ b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.resx @@ -1,64 +1,4 @@ - - - + diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitures.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitures.Designer.cs index d234812..6fec1fc 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitures.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitures.Designer.cs @@ -66,7 +66,7 @@ buttonDelete.UseVisualStyleBackColor = true; buttonDelete.Click += ButtonDelete_Click; // - // buttonRef + // buttonRefresh // buttonRefresh.Location = new Point(640, 245); buttonRefresh.Name = "buttonRef"; diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormMain.Designer.cs index 2da9a01..9cb76e7 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormMain.Designer.cs @@ -38,10 +38,16 @@ toolStripMenuItem = new ToolStripMenuItem(); workPieceToolStripMenuItem = new ToolStripMenuItem(); furnitureToolStripMenuItem = new ToolStripMenuItem(); - reportsToolStripMenuItem = new ToolStripMenuItem(); - workPiecesToolStripMenuItem = new ToolStripMenuItem(); - workPieceFurnituresToolStripMenuItem = new ToolStripMenuItem(); - ordersToolStripMenuItem = new ToolStripMenuItem(); + shopToolStripMenuItem = new ToolStripMenuItem(); + addFurnitureToolStripMenuItem = new ToolStripMenuItem(); + reportToolStripMenuItem = new ToolStripMenuItem(); + groupedOrdersReportToolStripMenuItem = new ToolStripMenuItem(); + ordersReportToolStripMenuItem = new ToolStripMenuItem(); + workloadStoresReportToolStripMenuItem = new ToolStripMenuItem(); + shopsReportToolStripMenuItem = new ToolStripMenuItem(); + reportManufactureToolStripMenuItem = new ToolStripMenuItem(); + workPieceManufacturesToolStripMenuItem = new ToolStripMenuItem(); + buttonSellFurniture = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -59,10 +65,10 @@ // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(887, 50); + buttonCreateOrder.Location = new Point(887, 38); buttonCreateOrder.Margin = new Padding(3, 2, 3, 2); buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(206, 34); + buttonCreateOrder.Size = new Size(216, 36); buttonCreateOrder.TabIndex = 1; buttonCreateOrder.Text = "Создать заказ"; buttonCreateOrder.UseVisualStyleBackColor = true; @@ -70,10 +76,10 @@ // // buttonTakeOrderInWork // - buttonTakeOrderInWork.Location = new Point(887, 107); + buttonTakeOrderInWork.Location = new Point(887, 96); buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2); buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(206, 36); + buttonTakeOrderInWork.Size = new Size(216, 34); buttonTakeOrderInWork.TabIndex = 2; buttonTakeOrderInWork.Text = "Отдать на выполнение"; buttonTakeOrderInWork.UseVisualStyleBackColor = true; @@ -81,10 +87,10 @@ // // buttonOrderReady // - buttonOrderReady.Location = new Point(887, 165); + buttonOrderReady.Location = new Point(887, 148); buttonOrderReady.Margin = new Padding(3, 2, 3, 2); buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(206, 31); + buttonOrderReady.Size = new Size(216, 33); buttonOrderReady.TabIndex = 3; buttonOrderReady.Text = "Заказ готов"; buttonOrderReady.UseVisualStyleBackColor = true; @@ -92,10 +98,10 @@ // // buttonIssuedOrder // - buttonIssuedOrder.Location = new Point(887, 217); + buttonIssuedOrder.Location = new Point(887, 201); buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2); buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(206, 33); + buttonIssuedOrder.Size = new Size(216, 32); buttonIssuedOrder.TabIndex = 4; buttonIssuedOrder.Text = "Заказ выдан"; buttonIssuedOrder.UseVisualStyleBackColor = true; @@ -103,19 +109,19 @@ // // buttonRefresh // - buttonRefresh.Location = new Point(887, 269); + buttonRefresh.Location = new Point(887, 250); buttonRefresh.Margin = new Padding(3, 2, 3, 2); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(206, 29); + buttonRefresh.Size = new Size(216, 31); buttonRefresh.TabIndex = 5; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRef_Click; + buttonRefresh.Click += ButtonRefresh_Click; // // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, reportsToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, reportToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Padding = new Padding(5, 2, 0, 2); @@ -125,7 +131,7 @@ // // toolStripMenuItem // - toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { workPieceToolStripMenuItem, furnitureToolStripMenuItem }); + toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { workPieceToolStripMenuItem, furnitureToolStripMenuItem, shopToolStripMenuItem, addFurnitureToolStripMenuItem }); toolStripMenuItem.Name = "toolStripMenuItem"; toolStripMenuItem.Size = new Size(94, 20); toolStripMenuItem.Text = "Справочники"; @@ -133,50 +139,97 @@ // workPieceToolStripMenuItem // workPieceToolStripMenuItem.Name = "workPieceToolStripMenuItem"; - workPieceToolStripMenuItem.Size = new Size(130, 22); + workPieceToolStripMenuItem.Size = new Size(198, 22); workPieceToolStripMenuItem.Text = "Заготовки"; workPieceToolStripMenuItem.Click += WorkPieceToolStripMenuItem_Click; // // furnitureToolStripMenuItem // furnitureToolStripMenuItem.Name = "furnitureToolStripMenuItem"; - furnitureToolStripMenuItem.Size = new Size(130, 22); + furnitureToolStripMenuItem.Size = new Size(198, 22); furnitureToolStripMenuItem.Text = "Изделия"; furnitureToolStripMenuItem.Click += FurnitureToolStripMenuItem_Click; // - // reportsToolStripMenuItem + // shopToolStripMenuItem // - reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { workPiecesToolStripMenuItem, workPieceFurnituresToolStripMenuItem, ordersToolStripMenuItem }); - reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; - reportsToolStripMenuItem.Size = new Size(60, 20); - reportsToolStripMenuItem.Text = "Отчёты"; + shopToolStripMenuItem.Name = "shopToolStripMenuItem"; + shopToolStripMenuItem.Size = new Size(198, 22); + shopToolStripMenuItem.Text = "Магазины"; + shopToolStripMenuItem.Click += ShopToolStripMenuItem_Click; // - // workPiecesToolStripMenuItem + // addFurnitureToolStripMenuItem // - workPiecesToolStripMenuItem.Name = "workPiecesToolStripMenuItem"; - workPiecesToolStripMenuItem.Size = new Size(203, 22); - workPiecesToolStripMenuItem.Text = "Список заготовок"; - workPiecesToolStripMenuItem.Click += WorkPiecesToolStripMenuItem_Click; + addFurnitureToolStripMenuItem.Name = "addFurnitureToolStripMenuItem"; + addFurnitureToolStripMenuItem.Size = new Size(198, 22); + addFurnitureToolStripMenuItem.Text = "Пополнение магазина"; + addFurnitureToolStripMenuItem.Click += AddFurnitureToolStripMenuItem_Click; // - // workPieceFurnituresToolStripMenuItem + // reportToolStripMenuItem // - workPieceFurnituresToolStripMenuItem.Name = "workPieceFurnituresToolStripMenuItem"; - workPieceFurnituresToolStripMenuItem.Size = new Size(203, 22); - workPieceFurnituresToolStripMenuItem.Text = "Заготовки по изделиям"; - workPieceFurnituresToolStripMenuItem.Click += WorkPieceFurnituresToolStripMenuItem_Click; + reportToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { groupedOrdersReportToolStripMenuItem, ordersReportToolStripMenuItem, workloadStoresReportToolStripMenuItem, shopsReportToolStripMenuItem, reportManufactureToolStripMenuItem, workPieceManufacturesToolStripMenuItem }); + reportToolStripMenuItem.Name = "reportToolStripMenuItem"; + reportToolStripMenuItem.Size = new Size(60, 20); + reportToolStripMenuItem.Text = "Отчёты"; // - // ordersToolStripMenuItem + // groupedOrdersReportToolStripMenuItem // - ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; - ordersToolStripMenuItem.Size = new Size(203, 22); - ordersToolStripMenuItem.Text = "Список заказов"; - ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + groupedOrdersReportToolStripMenuItem.Name = "groupedOrdersReportToolStripMenuItem"; + groupedOrdersReportToolStripMenuItem.Size = new Size(243, 22); + groupedOrdersReportToolStripMenuItem.Text = "Список заказов за весь период"; + groupedOrdersReportToolStripMenuItem.Click += GroupedOrdersReportToolStripMenuItem_Click; + // + // ordersReportToolStripMenuItem + // + ordersReportToolStripMenuItem.Name = "ordersReportToolStripMenuItem"; + ordersReportToolStripMenuItem.Size = new Size(243, 22); + ordersReportToolStripMenuItem.Text = "Список заказов"; + ordersReportToolStripMenuItem.Click += OrdersReportToolStripMenuItem_Click; + // + // workloadStoresReportToolStripMenuItem + // + workloadStoresReportToolStripMenuItem.Name = "workloadStoresReportToolStripMenuItem"; + workloadStoresReportToolStripMenuItem.Size = new Size(243, 22); + workloadStoresReportToolStripMenuItem.Text = "Загруженность магазинов"; + workloadStoresReportToolStripMenuItem.Click += WorkloadStoresReportToolStripMenuItem_Click; + // + // shopsReportToolStripMenuItem + // + shopsReportToolStripMenuItem.Name = "shopsReportToolStripMenuItem"; + shopsReportToolStripMenuItem.Size = new Size(243, 22); + shopsReportToolStripMenuItem.Text = "Таблица магазинов"; + shopsReportToolStripMenuItem.Click += ShopsReportToolStripMenuItem_Click; + // + // reportManufactureToolStripMenuItem + // + reportManufactureToolStripMenuItem.Name = "reportManufactureToolStripMenuItem"; + reportManufactureToolStripMenuItem.Size = new Size(243, 22); + reportManufactureToolStripMenuItem.Text = "Список изделий"; + reportManufactureToolStripMenuItem.Click += ReportFurnitureToolStripMenuItem_Click; + // + // workPieceManufacturesToolStripMenuItem + // + workPieceManufacturesToolStripMenuItem.Name = "workPieceManufacturesToolStripMenuItem"; + workPieceManufacturesToolStripMenuItem.Size = new Size(243, 22); + workPieceManufacturesToolStripMenuItem.Text = "Заготовки по изделиям"; + workPieceManufacturesToolStripMenuItem.Click += WorkPieceFurnituresToolStripMenuItem_Click; + // + // buttonSellFurniture + // + buttonSellFurniture.Location = new Point(887, 297); + buttonSellFurniture.Margin = new Padding(3, 2, 3, 2); + buttonSellFurniture.Name = "buttonSellFurniture"; + buttonSellFurniture.Size = new Size(216, 30); + buttonSellFurniture.TabIndex = 8; + buttonSellFurniture.Text = "Продажа изделий"; + buttonSellFurniture.UseVisualStyleBackColor = true; + buttonSellFurniture.Click += ButtonSellFurniture_Click; // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1135, 338); + Controls.Add(buttonSellFurniture); Controls.Add(buttonRefresh); Controls.Add(buttonIssuedOrder); Controls.Add(buttonOrderReady); @@ -208,9 +261,15 @@ private ToolStripMenuItem toolStripMenuItem; private ToolStripMenuItem workPieceToolStripMenuItem; private ToolStripMenuItem furnitureToolStripMenuItem; - private ToolStripMenuItem reportsToolStripMenuItem; - private ToolStripMenuItem workPiecesToolStripMenuItem; - private ToolStripMenuItem workPieceFurnituresToolStripMenuItem; - private ToolStripMenuItem ordersToolStripMenuItem; + private ToolStripMenuItem shopToolStripMenuItem; + private ToolStripMenuItem addFurnitureToolStripMenuItem; + private Button buttonSellFurniture; + private ToolStripMenuItem reportToolStripMenuItem; + private ToolStripMenuItem groupedOrdersReportToolStripMenuItem; + private ToolStripMenuItem ordersReportToolStripMenuItem; + private ToolStripMenuItem workloadStoresReportToolStripMenuItem; + private ToolStripMenuItem shopsReportToolStripMenuItem; + private ToolStripMenuItem reportManufactureToolStripMenuItem; + private ToolStripMenuItem workPieceManufacturesToolStripMenuItem; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormMain.cs b/FurnitureAssembly/FurnitureAssemblyView/FormMain.cs index 640eb59..cfdba3b 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormMain.cs @@ -181,7 +181,85 @@ namespace FurnitureAssemblyView } } - private void WorkPiecesToolStripMenuItem_Click(object sender, EventArgs e) + private void ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ShopToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + + private void AddFurnitureToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddFurniture)); + + if (service is FormAddFurniture form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void ButtonSellFurniture_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellFurniture)); + if (service is FormSellFurniture form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void GroupedOrdersReportToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); + + if (service is FormReportGroupedOrders form) + { + form.ShowDialog(); + } + } + + private void OrdersReportToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } + + private void WorkloadStoresReportToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopFurnitures)); + + if (service is FormReportShopFurnitures form) + { + form.ShowDialog(); + } + } + + private void ShopsReportToolStripMenuItem_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 ReportFurnitureToolStripMenuItem_Click(object sender, EventArgs e) { using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; @@ -205,20 +283,5 @@ namespace FurnitureAssemblyView form.ShowDialog(); } } - - private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } - - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } } } diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormReportFurnitureWorkPieces.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormReportFurnitureWorkPieces.Designer.cs index f32df70..af722bf 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormReportFurnitureWorkPieces.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormReportFurnitureWorkPieces.Designer.cs @@ -28,81 +28,92 @@ /// private void InitializeComponent() { - this.buttonSaveToExcel = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ColumWorkPiece = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnFurniture = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); + dataGridView = new DataGridView(); + buttonSaveToExcel = new Button(); + ColumnFurniture = new DataGridViewTextBoxColumn(); + ColumnWorkPiece = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); // - // buttonSaveToExcel + // dataGridView // - this.buttonSaveToExcel.Location = new System.Drawing.Point(33, 25); - this.buttonSaveToExcel.Name = "buttonSaveToExcel"; - this.buttonSaveToExcel.Size = new System.Drawing.Size(256, 29); - this.buttonSaveToExcel.TabIndex = 0; - this.buttonSaveToExcel.Text = "Сохранить в Excel"; - this.buttonSaveToExcel.UseVisualStyleBackColor = true; - this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click); + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToOrderColumns = true; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnFurniture, ColumnWorkPiece, ColumnCount }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 63); + dataGridView.Margin = new Padding(4, 5, 4, 5); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(704, 680); + dataGridView.TabIndex = 0; // - // dataGridView + // buttonSaveToExcel // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumWorkPiece, - this.ColumnFurniture, - this.ColumnCount}); - this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom; - this.dataGridView.Location = new System.Drawing.Point(0, 73); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(800, 395); - this.dataGridView.TabIndex = 1; + buttonSaveToExcel.Location = new Point(16, 18); + buttonSaveToExcel.Margin = new Padding(4, 5, 4, 5); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(212, 35); + buttonSaveToExcel.TabIndex = 1; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += ButtonSaveToExcel_Click; // - // ColumWorkPiece + // ColumnFurniture // - this.ColumWorkPiece.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ColumWorkPiece.HeaderText = "Заготовка"; - this.ColumWorkPiece.MinimumWidth = 6; - this.ColumWorkPiece.Name = "ColumWorkPiece"; + ColumnFurniture.HeaderText = "Изделие"; + ColumnFurniture.MinimumWidth = 6; + ColumnFurniture.Name = "ColumnFurniture"; + ColumnFurniture.ReadOnly = true; + ColumnFurniture.Width = 200; // - // ColumnFurniture + // ColumnWorkPiece // - this.ColumnFurniture.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ColumnFurniture.HeaderText = "Изделие"; - this.ColumnFurniture.MinimumWidth = 6; - this.ColumnFurniture.Name = "ColumnFurniture"; + ColumnWorkPiece.HeaderText = "Заготовка"; + ColumnWorkPiece.MinimumWidth = 6; + ColumnWorkPiece.Name = "ColumnWorkPiece"; + ColumnWorkPiece.ReadOnly = true; + ColumnWorkPiece.Width = 200; // // ColumnCount // - this.ColumnCount.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ColumnCount.HeaderText = "Количество"; - this.ColumnCount.MinimumWidth = 6; - this.ColumnCount.Name = "ColumnCount"; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; // // FormReportFurnitureWorkPieces // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 468); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.buttonSaveToExcel); - this.Name = "FormReportFurnitureWorkPieces"; - this.Text = "Заготовки по изделиям"; - this.Load += new System.EventHandler(this.FormReportFurnitureWorkPieces_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(704, 743); + Controls.Add(buttonSaveToExcel); + Controls.Add(dataGridView); + Margin = new Padding(4, 5, 4, 5); + Name = "FormReportFurnitureWorkPieces"; + Text = "Заготовки по изделиям"; + Load += FormReportFurnitureWorkPieces_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion + private DataGridView dataGridView; private Button buttonSaveToExcel; - private DataGridView dataGridView; private DataGridViewTextBoxColumn ColumWorkPiece; private DataGridViewTextBoxColumn ColumnFurniture; + private DataGridViewTextBoxColumn ColumnWorkPiece; private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormReportGroupedOrders.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormReportGroupedOrders.Designer.cs new file mode 100644 index 0000000..595f0a9 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormReportGroupedOrders.Designer.cs @@ -0,0 +1,92 @@ +namespace FurnitureAssemblyView +{ + partial class FormReportGroupedOrders + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel = new Panel(); + buttonToPdf = new Button(); + buttonMake = new Button(); + panel.SuspendLayout(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonToPdf); + panel.Controls.Add(buttonMake); + panel.Dock = DockStyle.Top; + panel.Location = new Point(0, 0); + panel.Margin = new Padding(4, 3, 4, 3); + panel.Name = "panel"; + panel.Size = new Size(1031, 40); + panel.TabIndex = 0; + // + // buttonToPdf + // + buttonToPdf.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonToPdf.Location = new Point(878, 8); + buttonToPdf.Margin = new Padding(4, 3, 4, 3); + buttonToPdf.Name = "buttonToPdf"; + buttonToPdf.Size = new Size(139, 27); + buttonToPdf.TabIndex = 5; + buttonToPdf.Text = "В Pdf"; + buttonToPdf.UseVisualStyleBackColor = true; + buttonToPdf.Click += ButtonToPdf_Click; + // + // buttonMake + // + buttonMake.Location = new Point(476, 8); + buttonMake.Margin = new Padding(4, 3, 4, 3); + buttonMake.Name = "buttonMake"; + buttonMake.Size = new Size(139, 27); + buttonMake.TabIndex = 4; + buttonMake.Text = "Сформировать"; + buttonMake.UseVisualStyleBackColor = true; + buttonMake.Click += ButtonMake_Click; + // + // FormReportOrders + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1031, 647); + Controls.Add(panel); + Margin = new Padding(4, 3, 4, 3); + Name = "FormReportOrders"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказы"; + panel.ResumeLayout(false); + panel.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonToPdf; + private Button buttonMake; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormReportGroupedOrders.cs b/FurnitureAssembly/FurnitureAssemblyView/FormReportGroupedOrders.cs new file mode 100644 index 0000000..9ae1ae1 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormReportGroupedOrders.cs @@ -0,0 +1,87 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +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 FurnitureAssemblyView +{ + public partial class FormReportGroupedOrders : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportGroupedOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + + _logger = logger; + _logic = logic; + + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + + reportViewer.LocalReport.LoadReportDefinition(new FileStream("E:\\TP\\Hard\\Lab4\\FurnitureAssembly\\FurnitureAssemblyView\\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); + } + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormReportGroupedOrders.resx b/FurnitureAssembly/FurnitureAssemblyView/FormReportGroupedOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormReportGroupedOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormReportOrders.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormReportOrders.Designer.cs index a0fc391..4b44802 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormReportOrders.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormReportOrders.Designer.cs @@ -31,10 +31,10 @@ panel = new Panel(); buttonToPdf = new Button(); buttonMake = new Button(); - label2 = new Label(); - label1 = new Label(); dateTimePickerTo = new DateTimePicker(); + labelTo = new Label(); dateTimePickerFrom = new DateTimePicker(); + labelFrom = new Label(); panel.SuspendLayout(); SuspendLayout(); // @@ -42,21 +42,24 @@ // panel.Controls.Add(buttonToPdf); panel.Controls.Add(buttonMake); - panel.Controls.Add(label2); - panel.Controls.Add(label1); panel.Controls.Add(dateTimePickerTo); + panel.Controls.Add(labelTo); panel.Controls.Add(dateTimePickerFrom); + panel.Controls.Add(labelFrom); panel.Dock = DockStyle.Top; panel.Location = new Point(0, 0); + panel.Margin = new Padding(4, 3, 4, 3); panel.Name = "panel"; - panel.Size = new Size(1112, 51); + panel.Size = new Size(1031, 40); panel.TabIndex = 0; // // buttonToPdf // - buttonToPdf.Location = new Point(894, 10); + buttonToPdf.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonToPdf.Location = new Point(878, 8); + buttonToPdf.Margin = new Padding(4, 3, 4, 3); buttonToPdf.Name = "buttonToPdf"; - buttonToPdf.Size = new Size(157, 29); + buttonToPdf.Size = new Size(139, 27); buttonToPdf.TabIndex = 5; buttonToPdf.Text = "В Pdf"; buttonToPdf.UseVisualStyleBackColor = true; @@ -64,55 +67,61 @@ // // buttonMake // - buttonMake.Location = new Point(612, 10); + buttonMake.Location = new Point(476, 8); + buttonMake.Margin = new Padding(4, 3, 4, 3); buttonMake.Name = "buttonMake"; - buttonMake.Size = new Size(157, 29); + buttonMake.Size = new Size(139, 27); buttonMake.TabIndex = 4; buttonMake.Text = "Сформировать"; buttonMake.UseVisualStyleBackColor = true; buttonMake.Click += ButtonMake_Click; // - // label2 - // - label2.AutoSize = true; - label2.Location = new Point(263, 17); - label2.Name = "label2"; - label2.Size = new Size(27, 20); - label2.TabIndex = 3; - label2.Text = "по"; - // - // label1 - // - label1.AutoSize = true; - label1.Location = new Point(25, 17); - label1.Name = "label1"; - label1.Size = new Size(18, 20); - label1.TabIndex = 2; - label1.Text = "С"; - // // dateTimePickerTo // - dateTimePickerTo.Location = new Point(313, 12); + dateTimePickerTo.Location = new Point(237, 7); + dateTimePickerTo.Margin = new Padding(4, 3, 4, 3); dateTimePickerTo.Name = "dateTimePickerTo"; - dateTimePickerTo.Size = new Size(169, 27); - dateTimePickerTo.TabIndex = 1; + dateTimePickerTo.Size = new Size(163, 23); + dateTimePickerTo.TabIndex = 3; + // + // labelTo + // + labelTo.AutoSize = true; + labelTo.Location = new Point(208, 10); + labelTo.Margin = new Padding(4, 0, 4, 0); + labelTo.Name = "labelTo"; + labelTo.Size = new Size(21, 15); + labelTo.TabIndex = 2; + labelTo.Text = "по"; // // dateTimePickerFrom // - dateTimePickerFrom.Location = new Point(65, 12); + dateTimePickerFrom.Location = new Point(37, 7); + dateTimePickerFrom.Margin = new Padding(4, 3, 4, 3); dateTimePickerFrom.Name = "dateTimePickerFrom"; - dateTimePickerFrom.Size = new Size(176, 27); - dateTimePickerFrom.TabIndex = 0; + dateTimePickerFrom.Size = new Size(163, 23); + dateTimePickerFrom.TabIndex = 1; + // + // labelFrom + // + labelFrom.AutoSize = true; + labelFrom.Location = new Point(14, 10); + labelFrom.Margin = new Padding(4, 0, 4, 0); + labelFrom.Name = "labelFrom"; + labelFrom.Size = new Size(15, 15); + labelFrom.TabIndex = 0; + labelFrom.Text = "С"; // // FormReportOrders // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1112, 450); + ClientSize = new Size(1031, 647); Controls.Add(panel); + Margin = new Padding(4, 3, 4, 3); Name = "FormReportOrders"; + StartPosition = FormStartPosition.CenterScreen; Text = "Заказы"; - Load += FormReportOrders_Load; panel.ResumeLayout(false); panel.PerformLayout(); ResumeLayout(false); @@ -121,11 +130,11 @@ #endregion private Panel panel; + private Button buttonToPdf; private Button buttonMake; - private Label label2; - private Label label1; private DateTimePicker dateTimePickerTo; + private Label labelTo; private DateTimePicker dateTimePickerFrom; - private Button buttonToPdf; + private Label labelFrom; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormReportOrders.cs b/FurnitureAssembly/FurnitureAssemblyView/FormReportOrders.cs index 2310a14..dcb09a7 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormReportOrders.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormReportOrders.cs @@ -46,9 +46,7 @@ namespace FurnitureAssemblyView { if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) { - MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try @@ -64,14 +62,14 @@ namespace FurnitureAssemblyView reportViewer.LocalReport.DataSources.Clear(); reportViewer.LocalReport.DataSources.Add(source); - var parameters = new[] { new ReportParameter("ReportParameterPeriod", + var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") }; - + reportViewer.LocalReport.SetParameters(parameters); + reportViewer.RefreshReport(); - _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), - dateTimePickerTo.Value.ToShortDateString()); + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); } catch (Exception ex) { @@ -85,14 +83,11 @@ namespace FurnitureAssemblyView if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) { MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - + return; } - using var dialog = new SaveFileDialog - { - Filter = "pdf|*.pdf" - }; + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; if (dialog.ShowDialog() == DialogResult.OK) { @@ -105,23 +100,16 @@ namespace FurnitureAssemblyView DateTo = dateTimePickerTo.Value }); - _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", - dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); - + _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); - + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } - - private void FormReportOrders_Load(object sender, EventArgs e) - { - - } } } diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormReportShopFurnitures.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormReportShopFurnitures.Designer.cs new file mode 100644 index 0000000..3422312 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormReportShopFurnitures.Designer.cs @@ -0,0 +1,118 @@ +namespace FurnitureAssemblyView +{ + partial class FormReportShopFurnitures + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonSaveToExcel = new Button(); + ColumnShop = new DataGridViewTextBoxColumn(); + ColumnFurniture = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToOrderColumns = true; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnShop, ColumnFurniture, ColumnCount }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 63); + dataGridView.Margin = new Padding(4, 5, 4, 5); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(704, 680); + dataGridView.TabIndex = 0; + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(16, 18); + buttonSaveToExcel.Margin = new Padding(4, 5, 4, 5); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(212, 35); + buttonSaveToExcel.TabIndex = 1; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += ButtonSaveToExcel_Click; + // + // ColumnShop + // + ColumnShop.HeaderText = "Магазин"; + ColumnShop.MinimumWidth = 6; + ColumnShop.Name = "ColumnShop"; + ColumnShop.ReadOnly = true; + ColumnShop.Width = 200; + // + // ColumnFurniture + // + ColumnFurniture.HeaderText = "Изделие"; + ColumnFurniture.MinimumWidth = 6; + ColumnFurniture.Name = "ColumnFurniture"; + ColumnFurniture.ReadOnly = true; + ColumnFurniture.Width = 200; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; + // + // FormReportShopFurnitures + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(704, 743); + Controls.Add(buttonSaveToExcel); + Controls.Add(dataGridView); + Margin = new Padding(4, 5, 4, 5); + Name = "FormReportShopFurnitures"; + Text = "Загруженность магазинов"; + Load += FormReportShopFurnitures_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonSaveToExcel; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnFurniture; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormReportShopFurnitures.cs b/FurnitureAssembly/FurnitureAssemblyView/FormReportShopFurnitures.cs new file mode 100644 index 0000000..7f39abf --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormReportShopFurnitures.cs @@ -0,0 +1,86 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FurnitureAssemblyView +{ + public partial class FormReportShopFurnitures : Form + { + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportShopFurnitures(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportShopFurnitures_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopFurnitures(); + + if (dict != null) + { + dataGridView.Rows.Clear(); + + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + + foreach (var listElem in elem.Furnitures) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + + _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.SaveShopFurnituresToExcelFile(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); + } + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormReportShopFurnitures.resx b/FurnitureAssembly/FurnitureAssemblyView/FormReportShopFurnitures.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormReportShopFurnitures.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.Designer.cs new file mode 100644 index 0000000..405e88c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.Designer.cs @@ -0,0 +1,125 @@ +namespace FurnitureAssemblyView +{ + partial class FormSellFurniture + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelFurniture = new Label(); + labelCount = new Label(); + comboBoxFurniture = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelFurniture + // + labelFurniture.AutoSize = true; + labelFurniture.Location = new Point(28, 24); + labelFurniture.Name = "labelFurniture"; + labelFurniture.Size = new Size(56, 15); + labelFurniture.TabIndex = 0; + labelFurniture.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(30, 64); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // comboBoxFurniture + // + comboBoxFurniture.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxFurniture.FormattingEnabled = true; + comboBoxFurniture.Location = new Point(149, 24); + comboBoxFurniture.Margin = new Padding(3, 2, 3, 2); + comboBoxFurniture.Name = "comboBoxFurniture"; + comboBoxFurniture.Size = new Size(230, 23); + comboBoxFurniture.TabIndex = 3; + // + // textBoxCount + // + textBoxCount.Location = new Point(149, 64); + textBoxCount.Margin = new Padding(3, 2, 3, 2); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(230, 23); + textBoxCount.TabIndex = 4; + // + // buttonSave + // + buttonSave.Location = new Point(169, 102); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 26); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(282, 102); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(97, 26); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSellFurniture + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(385, 135); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxFurniture); + Controls.Add(labelCount); + Controls.Add(labelFurniture); + Margin = new Padding(3, 2, 3, 2); + Name = "FormSellFurniture"; + Text = "Продажа изделий"; + Load += FormSellFurniture_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelFurniture; + private Label labelCount; + private ComboBox comboBoxFurniture; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.cs b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.cs new file mode 100644 index 0000000..eb70325 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.cs @@ -0,0 +1,100 @@ +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FurnitureAssemblyView +{ + public partial class FormSellFurniture : Form + { + private readonly ILogger _logger; + + private readonly IFurnitureLogic _logicI; + + private readonly IShopLogic _logicS; + + public FormSellFurniture(ILogger logger, IFurnitureLogic logicI, IShopLogic logicS) + { + InitializeComponent(); + + _logger = logger; + _logicI = logicI; + _logicS = logicS; + } + + private void FormSellFurniture_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка изделий для продажи"); + + try + { + var list = _logicI.ReadList(null); + if (list != null) + { + comboBoxFurniture.DisplayMember = "FurnitureName"; + comboBoxFurniture.ValueMember = "Id"; + comboBoxFurniture.DataSource = list; + comboBoxFurniture.SelectedItem = null; + } + } + 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(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxFurniture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Продажа изделия"); + + try + { + var operationResult = _logicS.SellFurnitures(_logicI.ReadElement(new FurnitureSearchModel() + { + Id = Convert.ToInt32(comboBoxFurniture.SelectedValue) + })!, Convert.ToInt32(textBoxCount.Text)); + + if (!operationResult) + { + throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах. Недостаточно изделий"); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка продажи изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.resx b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormShop.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormShop.Designer.cs new file mode 100644 index 0000000..0bfb5a5 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShop.Designer.cs @@ -0,0 +1,231 @@ +namespace FurnitureAssemblyView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelAddress = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + groupBoxFurniture = new GroupBox(); + dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + ColumnFurnitureName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelDate = new Label(); + dateTimePickerDate = new DateTimePicker(); + labelCount = new Label(); + numericUpDownCount = new NumericUpDown(); + groupBoxFurniture.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(18, 10); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(266, 9); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(43, 15); + labelAddress.TabIndex = 1; + labelAddress.Text = "Адрес:"; + // + // textBoxName + // + textBoxName.Location = new Point(94, 8); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(138, 23); + textBoxName.TabIndex = 2; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(318, 7); + textBoxAddress.Margin = new Padding(3, 2, 3, 2); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(138, 23); + textBoxAddress.TabIndex = 3; + // + // groupBoxFurniture + // + groupBoxFurniture.Controls.Add(dataGridView); + groupBoxFurniture.Location = new Point(12, 70); + groupBoxFurniture.Margin = new Padding(3, 2, 3, 2); + groupBoxFurniture.Name = "groupBoxFurniture"; + groupBoxFurniture.Padding = new Padding(3, 2, 3, 2); + groupBoxFurniture.Size = new Size(720, 206); + groupBoxFurniture.TabIndex = 4; + groupBoxFurniture.TabStop = false; + groupBoxFurniture.Text = "Изделия"; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ColumnFurnitureName, ColumnCount }); + dataGridView.Location = new Point(5, 20); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(709, 182); + dataGridView.TabIndex = 0; + // + // ID + // + ID.HeaderText = "ID"; + ID.MinimumWidth = 6; + ID.Name = "ID"; + ID.Visible = false; + ID.Width = 125; + // + // ColumnFurnitureName + // + ColumnFurnitureName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnFurnitureName.HeaderText = "Изделие"; + ColumnFurnitureName.MinimumWidth = 6; + ColumnFurnitureName.Name = "ColumnFurnitureName"; + ColumnFurnitureName.Resizable = DataGridViewTriState.True; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 125; + // + // buttonSave + // + buttonSave.Location = new Point(396, 286); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(151, 33); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(569, 286); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(146, 33); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(492, 9); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(90, 15); + labelDate.TabIndex = 7; + labelDate.Text = "Дата открытия:"; + // + // dateTimePickerDate + // + dateTimePickerDate.Location = new Point(596, 7); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(127, 23); + dateTimePickerDate.TabIndex = 9; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(18, 41); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(137, 15); + labelCount.TabIndex = 10; + labelCount.Text = "Вместимость магазина:"; + // + // numericUpDownCount + // + numericUpDownCount.Location = new Point(175, 40); + numericUpDownCount.Name = "numericUpDownCount"; + numericUpDownCount.Size = new Size(127, 23); + numericUpDownCount.TabIndex = 11; + // + // FormShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(744, 330); + Controls.Add(numericUpDownCount); + Controls.Add(labelCount); + Controls.Add(dateTimePickerDate); + Controls.Add(labelDate); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxFurniture); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelAddress); + Controls.Add(labelName); + Margin = new Padding(3, 2, 3, 2); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + groupBoxFurniture.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelAddress; + private TextBox textBoxName; + private TextBox textBoxAddress; + private GroupBox groupBoxFurniture; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private Label labelDate; + private DateTimePicker dateTimePickerDate; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnFurnitureName; + private DataGridViewTextBoxColumn ColumnCount; + private Label labelCount; + private NumericUpDown numericUpDownCount; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormShop.cs b/FurnitureAssembly/FurnitureAssemblyView/FormShop.cs new file mode 100644 index 0000000..b345fee --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShop.cs @@ -0,0 +1,139 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FurnitureAssemblyView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopFurnitures; + + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + + _logger = logger; + _logic = logic; + _shopFurnitures = new Dictionary(); + } + + 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; + textBoxAddress.Text = view.Address.ToString(); + dateTimePickerDate.Value = view.DateOpen; + numericUpDownCount.Value = view.MaxCountFurnitures; + _shopFurnitures = view.ShopFurnitures ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_shopFurnitures != null) + { + dataGridView.Rows.Clear(); + foreach (var element in _shopFurnitures) + { + dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.FurnitureName, element.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(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpen = dateTimePickerDate.Value.Date, + ShopFurnitures = _shopFurnitures, + MaxCountFurnitures = (int)numericUpDownCount.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(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormShop.resx b/FurnitureAssembly/FurnitureAssemblyView/FormShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormShops.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormShops.Designer.cs new file mode 100644 index 0000000..0b35002 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShops.Designer.cs @@ -0,0 +1,120 @@ +namespace FurnitureAssemblyView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(10, 9); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(444, 320); + dataGridView.TabIndex = 1; + // + // buttonAdd + // + buttonAdd.Location = new Point(465, 24); + buttonAdd.Margin = new Padding(3, 2, 3, 2); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(133, 35); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(465, 108); + buttonUpdate.Margin = new Padding(3, 2, 3, 2); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(133, 33); + buttonUpdate.TabIndex = 3; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(465, 183); + buttonDelete.Margin = new Padding(3, 2, 3, 2); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(133, 36); + buttonDelete.TabIndex = 4; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(465, 261); + buttonRefresh.Margin = new Padding(3, 2, 3, 2); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(133, 35); + buttonRefresh.TabIndex = 5; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(610, 338); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(3, 2, 3, 2); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormShops.cs b/FurnitureAssembly/FurnitureAssemblyView/FormShops.cs new file mode 100644 index 0000000..a8488f8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShops.cs @@ -0,0 +1,117 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FurnitureAssemblyView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + + public FormShops(ILogger 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["ShopFurnitures"].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 ButtonUpdate_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 ButtonDelete_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 ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormShops.resx b/FurnitureAssembly/FurnitureAssemblyView/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.Designer.cs index 287673e..ef8faab 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.Designer.cs @@ -28,83 +28,87 @@ /// private void InitializeComponent() { - this.labelName = new System.Windows.Forms.Label(); - this.labelPrice = new System.Windows.Forms.Label(); - this.textBoxName = new System.Windows.Forms.TextBox(); - this.textBoxCost = new System.Windows.Forms.TextBox(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.buttonSave = new System.Windows.Forms.Button(); - this.SuspendLayout(); + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); // // labelName // - this.labelName.AutoSize = true; - this.labelName.Location = new System.Drawing.Point(30, 24); - this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(80, 20); - this.labelName.TabIndex = 0; - this.labelName.Text = "Название:"; + labelName.AutoSize = true; + labelName.Location = new Point(26, 18); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; // // labelPrice // - this.labelPrice.AutoSize = true; - this.labelPrice.Location = new System.Drawing.Point(30, 65); - this.labelPrice.Name = "labelPrice"; - this.labelPrice.Size = new System.Drawing.Size(48, 20); - this.labelPrice.TabIndex = 1; - this.labelPrice.Text = "Цена:"; + labelPrice.AutoSize = true; + labelPrice.Location = new Point(26, 49); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(38, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена:"; // // textBoxName // - this.textBoxName.Location = new System.Drawing.Point(127, 21); - this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(293, 27); - this.textBoxName.TabIndex = 2; + textBoxName.Location = new Point(111, 16); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(257, 23); + textBoxName.TabIndex = 2; // // textBoxCost // - this.textBoxCost.Location = new System.Drawing.Point(127, 62); - this.textBoxCost.Name = "textBoxCost"; - this.textBoxCost.Size = new System.Drawing.Size(179, 27); - this.textBoxCost.TabIndex = 3; + textBoxCost.Location = new Point(111, 46); + textBoxCost.Margin = new Padding(3, 2, 3, 2); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(157, 23); + textBoxCost.TabIndex = 3; // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(326, 104); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(94, 29); - this.buttonCancel.TabIndex = 4; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + buttonCancel.Location = new Point(289, 78); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(105, 26); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(212, 104); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(94, 29); - this.buttonSave.TabIndex = 5; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + buttonSave.Location = new Point(171, 78); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(97, 26); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; // // FormWorkPiece // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(464, 153); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.textBoxCost); - this.Controls.Add(this.textBoxName); - this.Controls.Add(this.labelPrice); - this.Controls.Add(this.labelName); - this.Name = "FormWorkPiece"; - this.Text = "Заготовка"; - this.Load += new System.EventHandler(this.FormWorkPiece_Load); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(406, 115); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Margin = new Padding(3, 2, 3, 2); + Name = "FormWorkPiece"; + Text = "Заготовка"; + Load += FormWorkPiece_Load; + ResumeLayout(false); + PerformLayout(); } #endregion diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.resx b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.resx index f298a7b..af32865 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.resx +++ b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.resx @@ -1,4 +1,64 @@ - + + + diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.Designer.cs index 876791a..531cab9 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.Designer.cs @@ -38,9 +38,10 @@ // // buttonAdd // - buttonAdd.Location = new Point(641, 36); + buttonAdd.Location = new Point(561, 27); + buttonAdd.Margin = new Padding(3, 2, 3, 2); buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(116, 47); + buttonAdd.Size = new Size(100, 38); buttonAdd.TabIndex = 0; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; @@ -48,9 +49,10 @@ // // buttonUpdate // - buttonUpdate.Location = new Point(641, 102); + buttonUpdate.Location = new Point(561, 85); + buttonUpdate.Margin = new Padding(3, 2, 3, 2); buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(116, 47); + buttonUpdate.Size = new Size(100, 36); buttonUpdate.TabIndex = 1; buttonUpdate.Text = "Изменить"; buttonUpdate.UseVisualStyleBackColor = true; @@ -58,9 +60,10 @@ // // buttonDelete // - buttonDelete.Location = new Point(641, 168); + buttonDelete.Location = new Point(561, 143); + buttonDelete.Margin = new Padding(3, 2, 3, 2); buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(116, 47); + buttonDelete.Size = new Size(100, 34); buttonDelete.TabIndex = 2; buttonDelete.Text = "Удалить"; buttonDelete.UseVisualStyleBackColor = true; @@ -68,9 +71,10 @@ // // buttonRefresh // - buttonRefresh.Location = new Point(641, 239); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(116, 47); + buttonRefresh.Location = new Point(561, 197); + buttonRefresh.Margin = new Padding(3, 2, 3, 2); + buttonRefresh.Name = "buttonRef"; + buttonRefresh.Size = new Size(100, 34); buttonRefresh.TabIndex = 3; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -79,23 +83,25 @@ // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 12); + dataGridView.Location = new Point(10, 9); + dataGridView.Margin = new Padding(3, 2, 3, 2); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(604, 426); + dataGridView.Size = new Size(528, 320); dataGridView.TabIndex = 4; // // FormWorkPieces // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(781, 450); + ClientSize = new Size(683, 338); Controls.Add(dataGridView); Controls.Add(buttonRefresh); Controls.Add(buttonDelete); Controls.Add(buttonUpdate); Controls.Add(buttonAdd); + Margin = new Padding(3, 2, 3, 2); Name = "FormWorkPieces"; Text = "Заготовки"; Load += FormWorkPiece_Load; diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.cs b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.cs index 303f88b..6fedeeb 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.cs @@ -76,7 +76,7 @@ namespace FurnitureAssemblyView if (dataGridView.SelectedRows.Count == 1) { var service = Program.ServiceProvider?.GetService(typeof(FormWorkPiece)); - + if (service is FormWorkPiece form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/FurnitureAssembly/FurnitureAssemblyView/FurnitureAssemblyView.csproj b/FurnitureAssembly/FurnitureAssemblyView/FurnitureAssemblyView.csproj index b0292a8..42e1c03 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FurnitureAssemblyView.csproj +++ b/FurnitureAssembly/FurnitureAssemblyView/FurnitureAssemblyView.csproj @@ -9,15 +9,14 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + @@ -29,9 +28,9 @@ - + Always - + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/Program.cs b/FurnitureAssembly/FurnitureAssemblyView/Program.cs index 9550b23..814144c 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/Program.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/Program.cs @@ -43,10 +43,12 @@ namespace FurnitureAssemblyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -59,9 +61,16 @@ namespace FurnitureAssemblyView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/ReportGroupedOrders.rdlc b/FurnitureAssembly/FurnitureAssemblyView/ReportGroupedOrders.rdlc new file mode 100644 index 0000000..d996c93 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/ReportGroupedOrders.rdlc @@ -0,0 +1,410 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + FurnitureAssemblyContractsViewModels + /* Local Query */ + + + + DateCreate + System.DateTime + + + Count + System.Int32 + + + Sum + System.Decimal + + + + FurnitureAssemblyContracts.ViewModels + ReportGroupedOrdersViewModel + FurnitureAssemblyContracts.ViewModels.ReportGroupedOrdersViewModel, FurnitureAssemblyContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Заказы + + + + + + + 1cm + 10.19559cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 3.21438cm + + + 3.21438cm + + + 3.21438cm + + + + + 0.6cm + + + + + true + true + + + + + Дата создания + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Количество заказов + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма по заказам + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!DateCreate.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Count.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetGroupedOrders + 2.48391cm + 0.55245cm + 1.2cm + 9.64314cm + 1 + + + + + + true + true + + + + + Итого: + + + + + + + 4cm + 5.19559cm + 0.6cm + 2.5cm + 2 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetGroupedOrders") + + + + + + + 4cm + 7.69559cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.62292cm + - - - - - - ReportParameterPeriod - 1cm - 1cm + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + FurnitureAssemblyContractsViewModels + /* Local Query */ + + + + Id + System.Int32 + + + DateCreate + System.DateTime + + + FurnitureName + System.String + + + Sum + System.Decimal + + + OrderStatus + FurnitureAssemblyDataModels.OrderStatus + + + + FurnitureAssemblyContracts.ViewModels + ReportOrdersViewModel + FurnitureAssemblyContracts.ViewModels.ReportOrdersViewModel, ConfectioneryContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 1cm + 1cm + 21cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + Заказы + + + + + + + 1cm + 21cm + 1 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 2.5cm + + + 3.21438cm + + + 8.23317cm + + + 3.02917cm + + + 2.87042cm + + + + + 0.6cm + + + + + true + true + + + + + Номер + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Дата создания + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Изделие + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Статус заказа + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Id.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!DateCreate.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!FurnitureName.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrderStatus.Value + + + 2pt + 2pt + 2pt + 2pt + + + true + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 2.48391cm + 0.55245cm + 1.2cm + 19.84713cm + 2 + + + + + + true + true + + + + + Итого: + + + + + + + 4cm + 15.39958cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + 4cm + 17.89958cm + 0.6cm + 2.5cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm + - - Middle - 2pt - 2pt - 2pt - 2pt - - - - true - true - - - - - Заказы - - - - - - - 1cm - 21cm - 1 - - - Middle - 2pt - 2pt - 2pt - 2pt - - - - - - - 2.5cm - - - 3.21438cm - - - 8.23317cm - - - 3.02917cm - - - 2.87042cm - - - - - 0.6cm - - - - - true - true - - - - - Номер - - - - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Дата создания - - - - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Изделие - - - - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Статус заказа - - - - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Сумма - - - - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - 0.6cm - - - - - true - true - - - - - =Fields!Id.Value - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - =Fields!DateCreate.Value - - - - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - =Fields!FurnitureName.Value - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - =Fields!OrderStatus.Value - - - 2pt - 2pt - 2pt - 2pt - - - true - - - - - - true - true - - - - - =Fields!Sum.Value - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - - - - - - - - - - - - - - After - - - - - - - DataSetOrders - 2.48391cm - 0.55245cm - 1.2cm - 19.84713cm - 2 - - - - - - true - true - - - - - Итого: - - - - - - - 4cm - 15.39958cm - 0.6cm - 2.5cm - 3 - - - 2pt - 2pt - 2pt - 2pt - - - - true - true - - - - - =Sum(Fields!Sum.Value, "DataSetOrders") - - - - - - - 4cm - 17.89958cm - 0.6cm - 2.5cm - 4 - - - 2pt - 2pt - 2pt - 2pt - - - - 5.72875cm -