diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs index d85bc13..335966f 100644 --- a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -18,12 +18,17 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopLogic _shopLogic; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly ITextileStorage _textileStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, ITextileStorage textileStorage) { _logger = logger; _orderStorage = orderStorage; - } + _shopLogic = shopLogic; + _textileStorage = textileStorage; + } public bool CreateOrder(OrderBindingModel model) { @@ -116,6 +121,21 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics return false; } model.Status = newStatus; + if (newStatus == OrderStatus.Выдан) + { + var textile = _textileStorage.GetElement(new() { Id = order.TextileId }); + if (textile == null) + { + _logger.LogWarning("Change status operation failed. Textile not found"); + return false; + } + if (!_shopLogic.DeliverTextiles(textile, order.Count)) + { + _logger.LogWarning("Change status operation failed. Textiles delivery operation failed"); + return false; + } + } + model.Status = newStatus; if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs index 79189aa..fb8ce1a 100644 --- a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ReportLogic.cs @@ -13,18 +13,21 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics private readonly ITextileStorage _textileStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; + - public ReportLogic(ITextileStorage textileStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, + public ReportLogic(ITextileStorage textileStorage, IComponentStorage componentStorage, IShopStorage shopStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _textileStorage = textileStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; @@ -57,7 +60,30 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics return list; } + public List GetShopTextiles() + { + var shops = _shopStorage.GetFullList(); + var list = new List(); + + foreach (var shop in shops) + { + var record = new ReportShopTextileViewModel + { + ShopName = shop.ShopName, + Textiles = new List<(string Textile, int Count)>(), + TotalCount = 0, + }; + foreach (var textile in shop.ShopTextiles) + { + record.Textiles.Add(new(textile.Value.Item1.TextileName, textile.Value.Item2)); + record.TotalCount += textile.Value.Item2; + } + + list.Add(record); + } + return list; + } public List GetOrders(ReportBindingModel model) { return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }) @@ -71,7 +97,17 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics }) .ToList(); } - + public List GetGroupedByDateOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date) + .Select(x => new ReportOrdersByDateViewModel + { + Date = x.Key, + Count = x.Count(), + Sum = x.Sum(y => y.Sum) + }) + .ToList(); + } public void SaveTextilesToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo @@ -81,7 +117,15 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics Textiles = _textileStorage.GetFullList() }); } - + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateShopsTable(new WordInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } public void SaveTextileComponentToExcelFile(ReportBindingModel model) { _saveToExcel.CreateReport(new ExcelInfo @@ -91,7 +135,15 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics TextileComponents = GetTextileComponents() }); } - + public void SaveShopTextileToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopTextiles = GetShopTextiles() + }); + } public void SaveOrdersToPdfFile(ReportBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo @@ -103,5 +155,14 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics Orders = GetOrders(model) }); } + public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDocWithGroupedOrders(new PdfInfo + { + FileName = model.FileName, + Title = "Заказы по датам", + GroupedOrders = GetGroupedByDateOrders() + }); + } } } diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ShopLogic.cs b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..559fe60 --- /dev/null +++ b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,233 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using Microsoft.Extensions.Logging; + + +namespace GarmentFactoryBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName: {ShopName}. Id: {Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName: {ShopName}. Id: {Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool MakeDelivery(ShopSearchModel shopModel, ITextileModel textile, int count) + { + if (shopModel == null) + { + throw new ArgumentNullException(nameof(shopModel)); + } + if (textile == null) + { + throw new ArgumentNullException(nameof(textile)); + } + if (count <= 0) + { + throw new ArgumentException("Должен быть хотя бы один товар", nameof(count)); + } + _logger.LogInformation("MakeDelivery(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + var shop = _shopStorage.GetElement(shopModel); + if (shop == null) + { + _logger.LogWarning("MakeDelivery(GetElement). Element not found"); + return false; + } + if (shop.TextilesMaximum - shop.ShopTextiles.Sum(x => x.Value.Item2) < count) + { + _logger.LogWarning("MakeShipment error. No space for new textiles"); + return false; + } + if (shop.ShopTextiles.ContainsKey(textile.Id)) + { + var shopT = shop.ShopTextiles[textile.Id]; + shopT.Item2 += count; + shop.ShopTextiles[textile.Id] = shopT; + _logger.LogInformation("MakeDelivery. Added {count} '{textile}' to '{ShopName}' shop", count, textile.TextileName, + shop.ShopName); + } + else + { + shop.ShopTextiles.Add(textile.Id, (textile, count)); + _logger.LogInformation("MakeDelivery. Added {count} new '{textile}' to '{ShopName}' shop", count, textile.TextileName, + shop.ShopName); + } + if (_shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + TextilesMaximum = shop.TextilesMaximum, + ShopTextiles = shop.ShopTextiles, + }) == null) + { + _logger.LogWarning("MakeDelivery. Update operation failed"); + return false; + } + return true; + } + public bool MakeSale(ITextileModel model, int count) + { + return _shopStorage.MakeSale(model, count); + } + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + 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 + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + public bool DeliverTextiles(ITextileModel textile, int count) + { + if (count <= 0) + { + _logger.LogWarning("Textiles delivery operation failed. Textile count <= 0"); + return false; + } + + var shopList = _shopStorage.GetFullList(); + int shopsCapacity = shopList.Sum(x => x.TextilesMaximum); + int currentTextiles = shopList.Select(x => x.ShopTextiles.Sum(y => y.Value.Item2)).Sum(); + int freePlaces = shopsCapacity - currentTextiles; + + if (freePlaces < count) + { + _logger.LogWarning("Textiles delivery operation failed. No space for new textiles"); + return false; + } + + foreach (var shop in shopList) + { + freePlaces = shop.TextilesMaximum - shop.ShopTextiles.Sum(x => x.Value.Item2); + if (freePlaces == 0) + { + continue; + } + if (freePlaces >= count) + { + if (MakeDelivery(new() { Id = shop.Id }, textile, count)) + { + count = 0; + } + else + { + _logger.LogWarning("Textiles delivery operation failed"); + return false; + } + } + else + { + if (MakeDelivery(new() { Id = shop.Id }, textile, freePlaces)) + { + count -= freePlaces; + } + else + { + _logger.LogWarning("Textiles delivery operation failed"); + return false; + } + } + if (count == 0) + { + return true; + } + } + return false; + } + } +} diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index f127966..11814de 100644 --- a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -80,7 +80,76 @@ namespace GarmentFactoryBusinessLogic.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 si in info.ShopTextiles) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = si.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (Textile, Count) in si.Textiles) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Textile, + 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 = si.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } // Создание excel-файла protected abstract void CreateExcel(ExcelInfo info); diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 978fe96..3f458a5 100644 --- a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -44,8 +44,34 @@ namespace GarmentFactoryBusinessLogic.OfficePackage SavePdf(info); } + public void CreateDocWithGroupedOrders(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - // Создание pdf-файла + CreateTable(new List { "5cm", "6cm", "5cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата", "Количество заказов", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var order in info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.Date.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.Right }); + + SavePdf(info); + } + // Создание pdf-файла protected abstract void CreatePdf(PdfInfo info); // Создание параграфа с текстом diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToWord.cs index c8a8edc..34def36 100644 --- a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -40,14 +40,59 @@ namespace GarmentFactoryBusinessLogic.OfficePackage SaveWord(info); } + public void CreateShopsTable(WordInfo info) + { + CreateWord(info); - // Создание doc-файла + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + CreateTable(new List { "3000", "3000", "3000" }); + + CreateRow(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { ("Название магазина", new WordTextProperties { Size = "24" }), + ("Адрес", new WordTextProperties { Size = "24" }), ("Дата открытия", new WordTextProperties { Size = "24" }) }, + TextProperties = new WordTextProperties + { + Size = "24", + Bold = true, + JustificationType = WordJustificationType.Center + } + }); + + foreach (var shop in info.Shops) + { + CreateRow(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (shop.ShopName, new WordTextProperties { Size = "22" }), + (shop.Address, new WordTextProperties { Size = "22" }), (shop.DateOpening.ToString(), new WordTextProperties { Size = "22" })}, + TextProperties = new WordTextProperties + { + Size = "22", + JustificationType = WordJustificationType.Center + } + }); + } + + SaveWord(info); + } + + // Создание doc-файла protected abstract void CreateWord(WordInfo info); // Создание абзаца с текстом protected abstract void CreateParagraph(WordParagraph paragraph); - - // Сохранение файла + protected abstract void CreateTable(List columns); + protected abstract void CreateRow(WordParagraph paragraph); + // Сохранение файла protected abstract void SaveWord(WordInfo info); } } diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 9eaea62..3e44450 100644 --- a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -14,5 +14,6 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public List TextileComponents { get; set; } = new(); + public List ShopTextiles { get; set; } = new(); } } diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 41244bb..45efac3 100644 --- a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -18,5 +18,6 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels public DateTime DateTo { get; set; } public List Orders { get; set; } = new(); + public List GroupedOrders { get; set; } = new(); } } diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 7000d62..d927eca 100644 --- a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -14,5 +14,6 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public List Textiles { get; set; } = new(); + public List Shops { get; set; } = new(); } } diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 5a9bea6..0656365 100644 --- a/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/GarmentFactory/GarmentFactoryBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -11,6 +11,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements { private WordprocessingDocument? _wordDocument; private Body? _docBody; + private Table? table; // Получение типа выравнивания private static JustificationValues GetJustificationValues(WordJustificationType type) @@ -104,6 +105,66 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements _docBody.AppendChild(docParagraph); } + protected override void CreateTable(List columns) + { + if (_docBody == null || columns == null) + { + return; + } + + table = new(); + TableProperties properties = new(); + properties.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed }); + properties.AppendChild(new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new LeftBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new RightBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new BottomBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 } + )); + properties.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto }); + table.AppendChild(properties); + + TableGrid tableGrid = new(); + foreach (var column in columns) + { + tableGrid.AppendChild(new GridColumn() { Width = column }); + } + table.AppendChild(tableGrid); + + _docBody.AppendChild(table); + } + + protected override void CreateRow(WordParagraph paragraph) + { + if (_docBody == null || table == null || paragraph == null) + { + return; + } + TableRow tableRow = new(); + foreach (var column in paragraph.Texts) + { + var tableParagraph = new Paragraph(); + tableParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + + var tableRun = new Run(); + var runProperties = new RunProperties(); + runProperties.AppendChild(new FontSize { Val = column.Item2.Size }); + if (column.Item2.Bold) + { + runProperties.AppendChild(new Bold()); + } + tableRun.AppendChild(runProperties); + tableRun.AppendChild(new Text { Text = column.Item1, Space = SpaceProcessingModeValues.Preserve }); + tableParagraph.AppendChild(tableRun); + + TableCell cell = new(); + cell.AppendChild(tableParagraph); + tableRow.AppendChild(cell); + } + table.AppendChild(tableRow); + } protected override void SaveWord(WordInfo info) { if (_docBody == null || _wordDocument == null) diff --git a/GarmentFactory/GarmentFactoryContracts/BindingModels/ShopBindingModel.cs b/GarmentFactory/GarmentFactoryContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..0a84eee --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,27 @@ +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopTextiles + { + get; + set; + } = new(); + public int TextilesMaximum { get; set; } + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs index 5d1f614..cc4b274 100644 --- a/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IReportLogic.cs @@ -6,13 +6,19 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts { //Получение списка компонент с указанием, в каких изделиях используются List GetTextileComponents(); + List GetShopTextiles(); // Получение списка заказов за определенный период List GetOrders(ReportBindingModel model); + List GetGroupedByDateOrders(); // Сохранение компонент в файл-Word void SaveTextilesToWordFile(ReportBindingModel model); // Сохранение компонент с указаеним продуктов в файл-Excel void SaveTextileComponentToExcelFile(ReportBindingModel model); // Сохранение заказов в файл-Pdf void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveShopsToWordFile(ReportBindingModel model); + void SaveShopTextileToExcelFile(ReportBindingModel model); + void SaveGroupedOrdersToPdfFile(ReportBindingModel model); + } } diff --git a/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..80b7aa1 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,28 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; + + +namespace GarmentFactoryContracts.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 MakeDelivery(ShopSearchModel shopModel, ITextileModel textile, int count); + bool MakeSale(ITextileModel model, int count); + bool DeliverTextiles(ITextileModel model, int count); + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/SearchModels/ShopSearchModel.cs b/GarmentFactory/GarmentFactoryContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..a04e63f --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs b/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..2aeadf5 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,28 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; + +namespace GarmentFactoryContracts.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 MakeSale(ITextileModel model, int count); + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/ViewModels/ReportOrdersByDateViewModel.cs b/GarmentFactory/GarmentFactoryContracts/ViewModels/ReportOrdersByDateViewModel.cs new file mode 100644 index 0000000..1e860e0 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/ViewModels/ReportOrdersByDateViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.ViewModels +{ + public class ReportOrdersByDateViewModel + { + public DateTime Date { get; set; } + + public int Count { get; set; } + + public double Sum { get; set; } + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/ViewModels/ReportShopTextileViewModel.cs b/GarmentFactory/GarmentFactoryContracts/ViewModels/ReportShopTextileViewModel.cs new file mode 100644 index 0000000..d285cde --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/ViewModels/ReportShopTextileViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.ViewModels +{ + public class ReportShopTextileViewModel + { + public string ShopName { get; set; } = string.Empty; + + public int TotalCount { get; set; } + + public List<(string Textile, int Count)> Textiles { get; set; } = new(); + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/ViewModels/ShopViewModel.cs b/GarmentFactory/GarmentFactoryContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..ec732fb --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,33 @@ +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopTextiles + { + get; + set; + } = new(); + + [DisplayName("Максимальное количество изделий")] + public int TextilesMaximum { get; set; } + } +} diff --git a/GarmentFactory/GarmentFactoryDataModels/Models/IShopModel.cs b/GarmentFactory/GarmentFactoryDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..5e531f2 --- /dev/null +++ b/GarmentFactory/GarmentFactoryDataModels/Models/IShopModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDataModels.Models +{ + public interface IShopModel: IId + { + string ShopName { get; } + + string Address { get; } + + DateTime DateOpening { get; } + + Dictionary ShopTextiles { get; } + int TextilesMaximum { get; } + } +} diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Implements/ShopStorage.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..3e3fb8e --- /dev/null +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,146 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDatabaseImplement.Models; +using GarmentFactoryDataModels.Models; +using Microsoft.EntityFrameworkCore; + +namespace GarmentFactoryDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public List GetFullList() + { + using var context = new GarmentFactoryDatabase(); + return context.Shops + .Include(x => x.Textiles) + .ThenInclude(x => x.Textile) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + using var context = new GarmentFactoryDatabase(); + return context.Shops + .Include(x => x.Textiles) + .ThenInclude(x => x.Textile) + .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 GarmentFactoryDatabase(); + return context.Shops + .Include(x => x.Textiles) + .ThenInclude(x => x.Textile) + .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 GarmentFactoryDatabase(); + 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 GarmentFactoryDatabase(); + 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.UpdateTextiles(context, model); + transaction.Commit(); + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new GarmentFactoryDatabase(); + var element = context.Shops + .Include(x => x.Textiles) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Shops.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public bool MakeSale(ITextileModel model, int count) + { + using var context = new GarmentFactoryDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + foreach (var shop in context.Shops.Include(x => x.Textiles).ThenInclude(x => x.Textile) + .Where(x => x.Textiles.Any(x => x.TextileId == model.Id)) + .ToList()) + { + var textile = shop.ShopTextiles[model.Id]; + int min = Math.Min(textile.Item2, count); + if (min == textile.Item2) + { + shop.ShopTextiles.Remove(model.Id); + } + else + { + shop.ShopTextiles[model.Id] = (textile.Item1, textile.Item2 - min); + } + shop.UpdateTextiles(context, new() { Id = shop.Id, ShopTextiles = shop.ShopTextiles }); + count -= min; + if (count == 0) + { + context.SaveChanges(); + transaction.Commit(); + return true; + } + } + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.Designer.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240419160846_ImplementerAddition.Designer.cs similarity index 67% rename from GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.Designer.cs rename to GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240419160846_ImplementerAddition.Designer.cs index 84c4a19..43b0609 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.Designer.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240419160846_ImplementerAddition.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace GarmentFactoryDatabaseImplement.Migrations { [DbContext(typeof(GarmentFactoryDatabase))] - [Migration("20240319190105_InitialCreate")] - partial class InitialCreate + [Migration("20240419160846_ImplementerAddition")] + partial class ImplementerAddition { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -78,6 +78,59 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TextilesMaximum") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.ShopTextile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("TextileId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("TextileId"); + + b.ToTable("ShopTextiles"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => { b.Property("Id") @@ -135,6 +188,25 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("Textile"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.ShopTextile", b => + { + b.HasOne("GarmentFactoryDatabaseImplement.Models.Shop", "Shop") + .WithMany("Textiles") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") + .WithMany("ShopTextiles") + .HasForeignKey("TextileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shop"); + + b.Navigation("Textile"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.TextileComponent", b => { b.HasOne("GarmentFactoryDatabaseImplement.Models.Component", "Component") @@ -159,11 +231,18 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("TextileComponents"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Shop", b => + { + b.Navigation("Textiles"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => { b.Navigation("Components"); b.Navigation("Orders"); + + b.Navigation("ShopTextiles"); }); #pragma warning restore 612, 618 } diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240419160846_ImplementerAddition.cs similarity index 65% rename from GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.cs rename to GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240419160846_ImplementerAddition.cs index 251274b..a18a2ae 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240419160846_ImplementerAddition.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace GarmentFactoryDatabaseImplement.Migrations { /// - public partial class InitialCreate : Migration + public partial class ImplementerAddition : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -26,6 +26,22 @@ namespace GarmentFactoryDatabaseImplement.Migrations table.PrimaryKey("PK_Components", 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), + DateOpening = table.Column(type: "datetime2", nullable: false), + TextilesMaximum = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Textiles", columns: table => new @@ -64,6 +80,33 @@ namespace GarmentFactoryDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "ShopTextiles", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopId = table.Column(type: "int", nullable: false), + TextileId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopTextiles", x => x.Id); + table.ForeignKey( + name: "FK_ShopTextiles_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopTextiles_Textiles_TextileId", + column: x => x.TextileId, + principalTable: "Textiles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "TextileComponents", columns: table => new @@ -96,6 +139,16 @@ namespace GarmentFactoryDatabaseImplement.Migrations table: "Orders", column: "TextileId"); + migrationBuilder.CreateIndex( + name: "IX_ShopTextiles_ShopId", + table: "ShopTextiles", + column: "ShopId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopTextiles_TextileId", + table: "ShopTextiles", + column: "TextileId"); + migrationBuilder.CreateIndex( name: "IX_TextileComponents_ComponentId", table: "TextileComponents", @@ -114,9 +167,15 @@ namespace GarmentFactoryDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Orders"); + migrationBuilder.DropTable( + name: "ShopTextiles"); + migrationBuilder.DropTable( name: "TextileComponents"); + migrationBuilder.DropTable( + name: "Shops"); + migrationBuilder.DropTable( name: "Components"); diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs index 5e471ac..46daa13 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs @@ -105,6 +105,59 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TextilesMaximum") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.ShopTextile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.Property("TextileId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ShopId"); + + b.HasIndex("TextileId"); + + b.ToTable("ShopTextiles"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => { b.Property("Id") @@ -170,6 +223,25 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("Textile"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.ShopTextile", b => + { + b.HasOne("GarmentFactoryDatabaseImplement.Models.Shop", "Shop") + .WithMany("Textiles") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") + .WithMany("ShopTextiles") + .HasForeignKey("TextileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shop"); + + b.Navigation("Textile"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.TextileComponent", b => { b.HasOne("GarmentFactoryDatabaseImplement.Models.Component", "Component") @@ -199,11 +271,18 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("TextileComponents"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Shop", b => + { + b.Navigation("Textiles"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => { b.Navigation("Components"); b.Navigation("Orders"); + + b.Navigation("ShopTextiles"); }); #pragma warning restore 612, 618 } diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Shop.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..1b679a5 --- /dev/null +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Shop.cs @@ -0,0 +1,115 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDatabaseImplement.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 DateOpening { get; set; } + + [Required] + public int TextilesMaximum { get; set; } + + private Dictionary? _shopTextiles = null; + + [NotMapped] + public Dictionary ShopTextiles + { + get + { + if (_shopTextiles == null) + { + _shopTextiles = Textiles + .ToDictionary(x => x.TextileId, x => (x.Textile as ITextileModel, x.Count)); + } + return _shopTextiles; + } + } + + [ForeignKey("ShopId")] + public virtual List Textiles { get; set; } = new(); + + public static Shop Create(GarmentFactoryDatabase context, ShopBindingModel model) + { + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + TextilesMaximum = model.TextilesMaximum, + Textiles = model.ShopTextiles.Select(x => new ShopTextile + { + Textile = context.Textiles.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + + public void Update(ShopBindingModel model) + { + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + TextilesMaximum = model.TextilesMaximum; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + TextilesMaximum = TextilesMaximum, + ShopTextiles = ShopTextiles + }; + + public void UpdateTextiles(GarmentFactoryDatabase context, ShopBindingModel model) + { + var shopTextiles = context.ShopTextiles.Where(rec => rec.ShopId == model.Id).ToList(); + if (shopTextiles != null && shopTextiles.Count > 0) + { + context.ShopTextiles.RemoveRange(shopTextiles.Where(rec => !model.ShopTextiles.ContainsKey(rec.TextileId))); + context.SaveChanges(); + foreach (var updateTextile in shopTextiles) + { + if (model.ShopTextiles.ContainsKey(updateTextile.TextileId)) + { + updateTextile.Count = model.ShopTextiles[updateTextile.TextileId].Item2; + model.ShopTextiles.Remove(updateTextile.TextileId); + } + } + context.SaveChanges(); + } + var shop = context.Shops.First(x => x.Id == Id); + foreach (var ic in model.ShopTextiles) + { + context.ShopTextiles.Add(new ShopTextile + { + Shop = shop, + Textile = context.Textiles.First(x => x.Id == ic.Key), + Count = ic.Value.Item2 + }); + context.SaveChanges(); + } + _shopTextiles = null; + } + } +} diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Models/ShopTextile.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Models/ShopTextile.cs new file mode 100644 index 0000000..6429cd2 --- /dev/null +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Models/ShopTextile.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDatabaseImplement.Models +{ + public class ShopTextile + { + public int Id { get; set; } + + [Required] + public int ShopId { get; set; } + + [Required] + public int TextileId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Textile Textile { get; set; } = new(); + + public virtual Shop Shop { get; set; } = new(); + } +} diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Textile.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Textile.cs index 76aa3ce..5fc28fd 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Textile.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Textile.cs @@ -34,7 +34,9 @@ namespace GarmentFactoryDatabaseImplement.Models public virtual List Components { get; set; } = new(); [ForeignKey("TextileId")] public virtual List Orders { get; set; } = new(); - public static Textile Create(GarmentFactoryDatabase context, + [ForeignKey("TextileId")] + public virtual List ShopTextiles { get; set; } = new(); + public static Textile Create(GarmentFactoryDatabase context, TextileBindingModel model) { return new Textile() diff --git a/GarmentFactory/GarmentFactoryFileImplement/DataFileSingleton.cs b/GarmentFactory/GarmentFactoryFileImplement/DataFileSingleton.cs index b01f348..903c096 100644 --- a/GarmentFactory/GarmentFactoryFileImplement/DataFileSingleton.cs +++ b/GarmentFactory/GarmentFactoryFileImplement/DataFileSingleton.cs @@ -16,10 +16,15 @@ namespace GarmentFactoryFileImplement private readonly string TextileFileName = "Textile.xml"; private readonly string ClientFileName = "Client.xml"; public List Components { get; private set; } + private readonly string ShopFileName = "Shop.xml"; + public List Components { get; private set; } public List Orders { get; private set; } public List Textils { get; private set; } public List Clients { get; private set; } public static DataFileSingleton GetInstance() + public List Textiles { get; private set; } + public List Shops { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) { @@ -28,16 +33,20 @@ namespace GarmentFactoryFileImplement return instance; } public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); - public void SaveTextils() => SaveData(Textils, TextileFileName, "Textils", x => x.GetXElement); + public void SaveTextiles() => SaveData(Textiles, TextileFileName, "Textiles", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); private DataFileSingleton() + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; - Textils = LoadData(TextileFileName, "Textile", x => Textile.Create(x)!)!; + Textiles = LoadData(TextileFileName, "Textile", x => Textile.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; } + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; + } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/GarmentFactory/GarmentFactoryFileImplement/Implements/ShopStorage.cs b/GarmentFactory/GarmentFactoryFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..2905553 --- /dev/null +++ b/GarmentFactory/GarmentFactoryFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,137 @@ +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryFileImplement.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.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Shops.Remove(element); + source.SaveShops(); + return element.GetViewModel; + } + return null; + } + + public bool MakeSale(ITextileModel model, int count) + { + var textile = source.Textiles.FirstOrDefault(x => x.Id == model.Id); + int countInShops = source.Shops.SelectMany(x => x.ShopTextiles).Sum(y => y.Key == model.Id ? y.Value.Item2 : 0); + + if (textile == null || countInShops < count) + { + return false; + } + + foreach (var shop in source.Shops) + { + var shopTextiles = shop.ShopTextiles.Where(x => x.Key == model.Id); + if (shopTextiles.Any()) + { + var shopTextile = shopTextiles.First(); + int min = Math.Min(shopTextile.Value.Item2, count); + if (min == shopTextile.Value.Item2) + { + shop.ShopTextiles.Remove(shopTextile.Key); + } + else + { + shop.ShopTextiles[shopTextile.Key] = (shopTextile.Value.Item1, shopTextile.Value.Item2 - min); + } + shop.Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + ShopTextiles = shop.ShopTextiles, + TextilesMaximum = shop.TextilesMaximum + }); + count -= min; + if (count <= 0) + { + break; + } + } + } + source.SaveShops(); + return true; + } + } +} diff --git a/GarmentFactory/GarmentFactoryFileImplement/Implements/TextileStorage.cs b/GarmentFactory/GarmentFactoryFileImplement/Implements/TextileStorage.cs index becfdfe..6706ff6 100644 --- a/GarmentFactory/GarmentFactoryFileImplement/Implements/TextileStorage.cs +++ b/GarmentFactory/GarmentFactoryFileImplement/Implements/TextileStorage.cs @@ -22,7 +22,7 @@ namespace GarmentFactoryFileImplement.Implements public List GetFullList() { - return source.Textils + return source.Textiles .Select(x => x.GetViewModel) .ToList(); } @@ -33,7 +33,7 @@ namespace GarmentFactoryFileImplement.Implements { return new(); } - return source.Textils + return source.Textiles .Where(x => x.TextileName.Contains(model.TextileName)) .Select(x => x.GetViewModel) .ToList(); @@ -45,7 +45,7 @@ namespace GarmentFactoryFileImplement.Implements { return null; } - return source.Textils + return source.Textiles .FirstOrDefault(x => (!string.IsNullOrEmpty(model.TextileName) && x.TextileName == model.TextileName) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; @@ -53,36 +53,36 @@ namespace GarmentFactoryFileImplement.Implements public TextileViewModel? Insert(TextileBindingModel model) { - model.Id = source.Textils.Count > 0 ? source.Textils.Max(x => x.Id) + 1 : 1; + model.Id = source.Textiles.Count > 0 ? source.Textiles.Max(x => x.Id) + 1 : 1; var newTextile = Textile.Create(model); if (newTextile == null) { return null; } - source.Textils.Add(newTextile); - source.SaveTextils(); + source.Textiles.Add(newTextile); + source.SaveTextiles(); return newTextile.GetViewModel; } public TextileViewModel? Update(TextileBindingModel model) { - var textile = source.Textils.FirstOrDefault(x => x.Id == model.Id); + var textile = source.Textiles.FirstOrDefault(x => x.Id == model.Id); if (textile == null) { return null; } textile.Update(model); - source.SaveTextils(); + source.SaveTextiles(); return textile.GetViewModel; } public TextileViewModel? Delete(TextileBindingModel model) { - var element = source.Textils.FirstOrDefault(x => x.Id == model.Id); + var element = source.Textiles.FirstOrDefault(x => x.Id == model.Id); if (element != null) { - source.Textils.Remove(element); - source.SaveTextils(); + source.Textiles.Remove(element); + source.SaveTextiles(); return element.GetViewModel; } return null; diff --git a/GarmentFactory/GarmentFactoryFileImplement/Models/Shop.cs b/GarmentFactory/GarmentFactoryFileImplement/Models/Shop.cs new file mode 100644 index 0000000..9c3a890 --- /dev/null +++ b/GarmentFactory/GarmentFactoryFileImplement/Models/Shop.cs @@ -0,0 +1,114 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace GarmentFactoryFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary Textiles { get; private set; } = new(); + + private Dictionary? _shopTextiles = null; + + public Dictionary ShopTextiles + { + get + { + if (_shopTextiles == null) + { + var source = DataFileSingleton.GetInstance(); + _shopTextiles = Textiles.ToDictionary(x => x.Key, + y => ((source.Textiles.FirstOrDefault(z => z.Id == y.Key) as ITextileModel)!, y.Value)); + } + return _shopTextiles; + } + } + + public int TextilesMaximum { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + Textiles = model.ShopTextiles.ToDictionary(x => x.Key, x => x.Value.Item2), + TextilesMaximum = model.TextilesMaximum + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + TextilesMaximum = Convert.ToInt32(element.Element("TextilesMaximum")!.Value), + Textiles = element.Element("ShopTextiles")!.Elements("ShopTextile") + .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + TextilesMaximum = model.TextilesMaximum; + Textiles = model.ShopTextiles.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopTextiles = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopTextiles = ShopTextiles, + TextilesMaximum = TextilesMaximum + }; + + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpening", DateOpening.ToString()), + new XElement("TextilesMaximum", TextilesMaximum.ToString()), + new XElement("ShopTextiles", + Textiles.Select(x => new XElement("ShopTextile", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + + } +} diff --git a/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs b/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs index 0ad6ea9..bac929f 100644 --- a/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs +++ b/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs @@ -14,11 +14,13 @@ namespace GarmentFactoryListImplement public List Orders { get; set; } public List Textiles { get; set; } public List Clients { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Textiles = new List(); + Shops = new List(); Clients = new List(); } public static DataListSingleton GetInstance() diff --git a/GarmentFactory/GarmentFactoryListImplement/Implements/ShopStorage.cs b/GarmentFactory/GarmentFactoryListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..6e10e7f --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/Implements/ShopStorage.cs @@ -0,0 +1,120 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using GarmentFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + 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 ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && + shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public bool MakeSale(ITextileModel model, int count) + { + throw new NotImplementedException(); + } + } +} diff --git a/GarmentFactory/GarmentFactoryListImplement/Models/Shop.cs b/GarmentFactory/GarmentFactoryListImplement/Models/Shop.cs new file mode 100644 index 0000000..9f4565d --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/Models/Shop.cs @@ -0,0 +1,67 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary ShopTextiles + { + get; + private set; + } = new Dictionary(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + ShopTextiles = model.ShopTextiles + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ShopTextiles = model.ShopTextiles; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopTextiles = ShopTextiles + }; + + public int TextilesMaximum { get; private set; } + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormMain.cs b/GarmentFactory/GarmentFactoryView/FormMain.cs index fcaa4e1..1081366 100644 --- a/GarmentFactory/GarmentFactoryView/FormMain.cs +++ b/GarmentFactory/GarmentFactoryView/FormMain.cs @@ -41,8 +41,6 @@ namespace GarmentFactoryView dataGridView.DataSource = list; dataGridView.Columns["TextileId"].Visible = false; dataGridView.Columns["TextileName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -188,10 +186,56 @@ namespace GarmentFactoryView } } - private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e) + private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) + var service = Program.ServiceProvider?.GetService(typeof(FormMakeDelivery)); + if (service is FormMakeDelivery form) + { + form.ShowDialog(); + } + } + + private void ПродажаИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTextileSale)); + if (service is FormTextileSale form) + { + form.ShowDialog(); + } + } + + private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void СписокМагазиновToolStripMenuItem_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 ЗагруженностьМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopTextiles)); + if (service is FormReportShopTextiles form) + { + form.ShowDialog(); + } + } + + private void ЗаказыПоДатамToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); + if (service is FormReportGroupedOrders form) { form.ShowDialog(); } diff --git a/GarmentFactory/GarmentFactoryView/FormMakeDelivery.Designer.cs b/GarmentFactory/GarmentFactoryView/FormMakeDelivery.Designer.cs new file mode 100644 index 0000000..34ef823 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormMakeDelivery.Designer.cs @@ -0,0 +1,145 @@ +namespace GarmentFactoryView +{ + partial class FormMakeDelivery + { + /// + /// 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() + { + labelShop = new Label(); + labelProduct = new Label(); + labelCount = new Label(); + comboBoxShop = new ComboBox(); + comboBoxTextile = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(21, 9); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(76, 20); + labelShop.TabIndex = 0; + labelShop.Text = "Магазин :"; + // + // labelProduct + // + labelProduct.AutoSize = true; + labelProduct.Location = new Point(21, 55); + labelProduct.Name = "labelProduct"; + labelProduct.Size = new Size(73, 20); + labelProduct.TabIndex = 1; + labelProduct.Text = "Продукт :"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(21, 99); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 2; + labelCount.Text = "Количество :"; + // + // comboBoxShop + // + comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(124, 6); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(276, 28); + comboBoxShop.TabIndex = 3; + // + // comboBoxTextile + // + comboBoxTextile.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxTextile.FormattingEnabled = true; + comboBoxTextile.Location = new Point(124, 52); + comboBoxTextile.Name = "comboBoxTextile"; + comboBoxTextile.Size = new Size(276, 28); + comboBoxTextile.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(124, 99); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(276, 27); + textBoxCount.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(183, 148); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(290, 148); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormMakeDelivery + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(426, 196); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxTextile); + Controls.Add(comboBoxShop); + Controls.Add(labelCount); + Controls.Add(labelProduct); + Controls.Add(labelShop); + Name = "FormMakeDelivery"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Пополнение магазина"; + Load += FormMakeDelivery_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelShop; + private Label labelProduct; + private Label labelCount; + private ComboBox comboBoxShop; + private ComboBox comboBoxTextile; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormMakeDelivery.cs b/GarmentFactory/GarmentFactoryView/FormMakeDelivery.cs new file mode 100644 index 0000000..069d8e0 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormMakeDelivery.cs @@ -0,0 +1,124 @@ +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.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 GarmentFactoryView +{ + public partial class FormMakeDelivery : Form + { + private readonly ILogger _logger; + + private readonly ITextileLogic _logicTextile; + + private readonly IShopLogic _logicShop; + public FormMakeDelivery(ILogger logger, ITextileLogic logicTextile, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicTextile = logicTextile; + _logicShop = logicShop; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxTextile.SelectedValue == null) + { + MessageBox.Show("Выберите продукт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop replenishment"); + try + { + var textile = _logicTextile.ReadElement(new TextileSearchModel + { Id = Convert.ToInt32(comboBoxTextile.SelectedValue) }); + if (textile == null) + { + throw new Exception("Мороженое не найдено."); + } + var operationResult = _logicShop.MakeDelivery(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + textile, + 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, "Shop replenishment error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormMakeDelivery_Load(object sender, EventArgs e) + { + _logger.LogInformation("Textile loading"); + try + { + var list = _logicTextile.ReadList(null); + if (list != null) + { + comboBoxTextile.DisplayMember = "TextileName"; + comboBoxTextile.ValueMember = "Id"; + comboBoxTextile.DataSource = list; + comboBoxTextile.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Textiles loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Shops loading"); + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormMakeDelivery.resx b/GarmentFactory/GarmentFactoryView/FormMakeDelivery.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormMakeDelivery.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/GarmentFactory/GarmentFactoryView/FormReportGroupedOrders.cs b/GarmentFactory/GarmentFactoryView/FormReportGroupedOrders.cs new file mode 100644 index 0000000..4a3ad51 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormReportGroupedOrders.cs @@ -0,0 +1,72 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; + +namespace GarmentFactoryView +{ + 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("ReportGroupedOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonCreateReport_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetGroupedByDateOrders(); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + + reportViewer.RefreshReport(); + _logger.LogInformation("Loading list of grouped orders"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Loading list of grouped orders error"); + 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("Saving list of grouped orders"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Saving list of grouped orders error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormReportGroupedOrders.designer.cs b/GarmentFactory/GarmentFactoryView/FormReportGroupedOrders.designer.cs new file mode 100644 index 0000000..398a591 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormReportGroupedOrders.designer.cs @@ -0,0 +1,91 @@ +namespace GarmentFactoryView +{ + 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(); + buttonCreateReport = new Button(); + panel.SuspendLayout(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonToPdf); + panel.Controls.Add(buttonCreateReport); + 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(188, 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; + // + // buttonCreateReport + // + buttonCreateReport.Location = new Point(11, 8); + buttonCreateReport.Margin = new Padding(4, 3, 4, 3); + buttonCreateReport.Name = "buttonCreateReport"; + buttonCreateReport.Size = new Size(139, 27); + buttonCreateReport.TabIndex = 4; + buttonCreateReport.Text = "Сформировать"; + buttonCreateReport.UseVisualStyleBackColor = true; + buttonCreateReport.Click += ButtonCreateReport_Click; + // + // FormReportGroupedOrders + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1031, 647); + Controls.Add(panel); + Margin = new Padding(4, 3, 4, 3); + Name = "FormReportGroupedOrders"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказы по датам"; + panel.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.Panel panel; + private System.Windows.Forms.Button buttonToPdf; + private System.Windows.Forms.Button buttonCreateReport; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormReportGroupedOrders.resx b/GarmentFactory/GarmentFactoryView/FormReportGroupedOrders.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/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/GarmentFactory/GarmentFactoryView/FormReportShopTextiles.cs b/GarmentFactory/GarmentFactoryView/FormReportShopTextiles.cs new file mode 100644 index 0000000..f9a70e4 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormReportShopTextiles.cs @@ -0,0 +1,76 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryView +{ + public partial class FormReportShopTextiles : Form + { + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportShopTextiles(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + + private void ButtonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopTextileToExcelFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Saving information on store workload"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Saving information on store workload error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + + private void FormReportShopTextiles_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopTextiles(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Textiles) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Loading information on store workload"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Loading information on store workload error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormReportShopTextiles.designer.cs b/GarmentFactory/GarmentFactoryView/FormReportShopTextiles.designer.cs new file mode 100644 index 0000000..d5af195 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormReportShopTextiles.designer.cs @@ -0,0 +1,120 @@ +namespace GarmentFactoryView +{ + partial class FormReportShopTextiles + { + /// + /// 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(); + ColumnIceCream = 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, ColumnIceCream, ColumnCount }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 63); + dataGridView.Margin = new Padding(5, 4, 5, 4); + 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.CellContentClick += dataGridView_CellContentClick; + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(15, 13); + buttonSaveToExcel.Margin = new Padding(5, 4, 5, 4); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(213, 36); + buttonSaveToExcel.TabIndex = 1; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += ButtonSaveToExcel_Click; + // + // ColumnShop + // + ColumnShop.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnShop.HeaderText = "Магазин"; + ColumnShop.MinimumWidth = 6; + ColumnShop.Name = "ColumnShop"; + ColumnShop.ReadOnly = true; + // + // ColumnIceCream + // + ColumnIceCream.HeaderText = "Изделие"; + ColumnIceCream.MinimumWidth = 6; + ColumnIceCream.Name = "ColumnIceCream"; + ColumnIceCream.ReadOnly = true; + ColumnIceCream.Width = 200; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; + // + // FormReportShopTextiles + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(704, 743); + Controls.Add(buttonSaveToExcel); + Controls.Add(dataGridView); + Margin = new Padding(5, 4, 5, 4); + Name = "FormReportShopTextiles"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Загруженность магазинов"; + Load += FormReportShopTextiles_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button buttonSaveToExcel; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnIceCream; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormReportShopTextiles.resx b/GarmentFactory/GarmentFactoryView/FormReportShopTextiles.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormReportShopTextiles.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/GarmentFactory/GarmentFactoryView/FormShop.Designer.cs b/GarmentFactory/GarmentFactoryView/FormShop.Designer.cs new file mode 100644 index 0000000..22e41e5 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormShop.Designer.cs @@ -0,0 +1,243 @@ +namespace GarmentFactoryView +{ + 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(); + textBoxName = new TextBox(); + labelAddress = new Label(); + textBoxAddress = new TextBox(); + dateTimePicker = new DateTimePicker(); + labelOpeningDate = new Label(); + groupBoxTextiles = new GroupBox(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelMaxTextile = new Label(); + textBoxMaximum = new TextBox(); + groupBoxTextiles.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(16, 13); + labelName.Margin = new Padding(5, 0, 5, 0); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 1; + labelName.Text = "Название :"; + // + // textBoxName + // + textBoxName.Location = new Point(105, 9); + textBoxName.Margin = new Padding(5, 4, 5, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(287, 27); + textBoxName.TabIndex = 2; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(16, 53); + labelAddress.Margin = new Padding(5, 0, 5, 0); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(58, 20); + labelAddress.TabIndex = 3; + labelAddress.Text = "Адрес :"; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(105, 49); + textBoxAddress.Margin = new Padding(5, 4, 5, 4); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(287, 27); + textBoxAddress.TabIndex = 4; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(144, 88); + dateTimePicker.Margin = new Padding(3, 4, 3, 4); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(249, 27); + dateTimePicker.TabIndex = 5; + // + // labelOpeningDate + // + labelOpeningDate.AutoSize = true; + labelOpeningDate.Location = new Point(16, 92); + labelOpeningDate.Margin = new Padding(5, 0, 5, 0); + labelOpeningDate.Name = "labelOpeningDate"; + labelOpeningDate.Size = new Size(117, 20); + labelOpeningDate.TabIndex = 6; + labelOpeningDate.Text = "Дата открытия :"; + // + // groupBoxTextiles + // + groupBoxTextiles.Controls.Add(dataGridView); + groupBoxTextiles.Location = new Point(5, 168); + groupBoxTextiles.Margin = new Padding(5, 4, 5, 4); + groupBoxTextiles.Name = "groupBoxTextiles"; + groupBoxTextiles.Padding = new Padding(5, 4, 5, 4); + groupBoxTextiles.Size = new Size(536, 397); + groupBoxTextiles.TabIndex = 7; + groupBoxTextiles.TabStop = false; + groupBoxTextiles.Text = "Мороженое"; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(5, 24); + dataGridView.Margin = new Padding(5, 4, 5, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(522, 369); + dataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Название продукта"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; + // + // buttonSave + // + buttonSave.Location = new Point(301, 592); + buttonSave.Margin = new Padding(5, 4, 5, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(421, 592); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelMaxTextile + // + labelMaxTextile.AutoSize = true; + labelMaxTextile.Location = new Point(16, 137); + labelMaxTextile.Name = "labelMaxTextile"; + labelMaxTextile.Size = new Size(150, 20); + labelMaxTextile.TabIndex = 10; + labelMaxTextile.Text = "Максимум изделия :"; + // + // textBoxMaximum + // + textBoxMaximum.Location = new Point(173, 134); + textBoxMaximum.Name = "textBoxMaximum"; + textBoxMaximum.Size = new Size(219, 27); + textBoxMaximum.TabIndex = 11; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(546, 641); + Controls.Add(textBoxMaximum); + Controls.Add(labelMaxTextile); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxTextiles); + Controls.Add(labelOpeningDate); + Controls.Add(dateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(labelAddress); + Controls.Add(textBoxName); + Controls.Add(labelName); + Margin = new Padding(3, 4, 3, 4); + Name = "FormShop"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Магазин"; + Load += FormShop_Load; + groupBoxTextiles.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Label labelAddress; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private Label labelOpeningDate; + private GroupBox groupBoxTextiles; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + private Label labelMaxTextile; + private TextBox textBoxMaximum; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormShop.cs b/GarmentFactory/GarmentFactoryView/FormShop.cs new file mode 100644 index 0000000..4246681 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormShop.cs @@ -0,0 +1,133 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopTextiles; + + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopTextiles = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Shop loading"); + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Value = view.DateOpening; + textBoxMaximum.Text = view.TextilesMaximum.ToString(); + _shopTextiles = view.ShopTextiles ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Shop textiles loading"); + try + { + if (_shopTextiles != null) + { + dataGridView.Rows.Clear(); + foreach (var textile in _shopTextiles) + { + dataGridView.Rows.Add(new object[] { textile.Key, textile.Value.Item1.TextileName, textile.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop textiles loading error"); + 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; + } + if (string.IsNullOrEmpty(dateTimePicker.Text)) + { + MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxMaximum.Text)) + { + MessageBox.Show("Заполните максимальное количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop saving"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value, + TextilesMaximum = Convert.ToInt32(textBoxMaximum.Text), + ShopTextiles = _shopTextiles + }; + 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, "Shop saving error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormShop.resx b/GarmentFactory/GarmentFactoryView/FormShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/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/GarmentFactory/GarmentFactoryView/FormShops.Designer.cs b/GarmentFactory/GarmentFactoryView/FormShops.Designer.cs new file mode 100644 index 0000000..29f0802 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormShops.Designer.cs @@ -0,0 +1,126 @@ +namespace GarmentFactoryView +{ + 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(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(408, 360); + dataGridView.TabIndex = 2; + // + // buttonUpd + // + buttonUpd.Location = new Point(432, 152); + buttonUpd.Margin = new Padding(4, 3, 4, 3); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(88, 27); + buttonUpd.TabIndex = 12; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(432, 105); + buttonDel.Margin = new Padding(4, 3, 4, 3); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(88, 27); + buttonDel.TabIndex = 11; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(432, 58); + buttonEdit.Margin = new Padding(4, 3, 4, 3); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(88, 27); + buttonEdit.TabIndex = 10; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(432, 14); + buttonAdd.Margin = new Padding(4, 3, 4, 3); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 27); + buttonAdd.TabIndex = 9; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(541, 360); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormShops.cs b/GarmentFactory/GarmentFactoryView/FormShops.cs new file mode 100644 index 0000000..3876200 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormShops.cs @@ -0,0 +1,104 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryView +{ + 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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopTextiles"].Visible = false; + } + _logger.LogInformation("Shops loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + 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 ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Deletion of shop"); + try + { + if (!_logic.Delete(new ShopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormShops.resx b/GarmentFactory/GarmentFactoryView/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/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/GarmentFactory/GarmentFactoryView/FormTextileSale.Designer.cs b/GarmentFactory/GarmentFactoryView/FormTextileSale.Designer.cs new file mode 100644 index 0000000..ac24756 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextileSale.Designer.cs @@ -0,0 +1,121 @@ +namespace GarmentFactoryView +{ + partial class FormTextileSale + { + /// + /// 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() + { + labelTextile = new Label(); + labelCount = new Label(); + buttonSale = new Button(); + buttonCancel = new Button(); + comboBoxTextile = new ComboBox(); + textBoxCount = new TextBox(); + SuspendLayout(); + // + // labelTextile + // + labelTextile.AutoSize = true; + labelTextile.Location = new Point(25, 33); + labelTextile.Name = "labelTextile"; + labelTextile.Size = new Size(75, 20); + labelTextile.TabIndex = 0; + labelTextile.Text = "Изделие :"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(25, 81); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество :"; + // + // buttonSale + // + buttonSale.Location = new Point(212, 124); + buttonSale.Name = "buttonSale"; + buttonSale.Size = new Size(101, 36); + buttonSale.TabIndex = 2; + buttonSale.Text = "Продать"; + buttonSale.UseVisualStyleBackColor = true; + buttonSale.Click += ButtonSale_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(328, 124); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // comboBoxTextile + // + comboBoxTextile.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxTextile.FormattingEnabled = true; + comboBoxTextile.Location = new Point(132, 30); + comboBoxTextile.Name = "comboBoxTextile"; + comboBoxTextile.Size = new Size(297, 28); + comboBoxTextile.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(132, 78); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(297, 27); + textBoxCount.TabIndex = 5; + // + // FormTextileSale + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(464, 176); + Controls.Add(textBoxCount); + Controls.Add(comboBoxTextile); + Controls.Add(buttonCancel); + Controls.Add(buttonSale); + Controls.Add(labelCount); + Controls.Add(labelTextile); + Name = "FormTextileSale"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Продажа изделий"; + Load += FormTextileSale_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelTextile; + private Label labelCount; + private Button buttonSale; + private Button buttonCancel; + private ComboBox comboBoxTextile; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormTextileSale.cs b/GarmentFactory/GarmentFactoryView/FormTextileSale.cs new file mode 100644 index 0000000..629ba12 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextileSale.cs @@ -0,0 +1,95 @@ +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.BindingModels; +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 GarmentFactoryView +{ + public partial class FormTextileSale : Form + { + private readonly ILogger _logger; + + private readonly ITextileLogic _logicTextile; + + private readonly IShopLogic _logicShop; + public FormTextileSale(ILogger logger, ITextileLogic logicTextile, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicTextile = logicTextile; + _logicShop = logicShop; + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void ButtonSale_Click(object sender, EventArgs e) + { + if (comboBoxTextile.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Textile sale"); + try + { + var operationResult = _logicShop.MakeSale( + new TextileBindingModel + { + Id = Convert.ToInt32(comboBoxTextile.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, "Textile sale error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormTextileSale_Load(object sender, EventArgs e) + { + _logger.LogInformation("Textiles loading"); + try + { + var list = _logicTextile.ReadList(null); + if (list != null) + { + comboBoxTextile.DisplayMember = "TextileName"; + comboBoxTextile.ValueMember = "Id"; + comboBoxTextile.DataSource = list; + comboBoxTextile.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Textiles loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormTextileSale.resx b/GarmentFactory/GarmentFactoryView/FormTextileSale.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormTextileSale.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/GarmentFactory/GarmentFactoryView/GarmentFactoryView.csproj b/GarmentFactory/GarmentFactoryView/GarmentFactoryView.csproj index 0ffbeaa..eb5fd2f 100644 --- a/GarmentFactory/GarmentFactoryView/GarmentFactoryView.csproj +++ b/GarmentFactory/GarmentFactoryView/GarmentFactoryView.csproj @@ -28,6 +28,9 @@ + + Always + Always diff --git a/GarmentFactory/GarmentFactoryView/Program.cs b/GarmentFactory/GarmentFactoryView/Program.cs index 8d30f4c..e1db9c2 100644 --- a/GarmentFactory/GarmentFactoryView/Program.cs +++ b/GarmentFactory/GarmentFactoryView/Program.cs @@ -34,17 +34,26 @@ namespace GarmentFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); +<<<<<<< HEAD services.AddTransient(); +======= + services.AddTransient(); +>>>>>>> laba4_hard services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); +<<<<<<< HEAD services.AddTransient(); +======= +>>>>>>> laba4_hard services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -52,9 +61,18 @@ namespace GarmentFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); +<<<<<<< HEAD services.AddTransient(); +======= + services.AddTransient(); + services.AddTransient(); +>>>>>>> laba4_hard } } diff --git a/GarmentFactory/GarmentFactoryView/ReportGroupedOrders.rdlc b/GarmentFactory/GarmentFactoryView/ReportGroupedOrders.rdlc new file mode 100644 index 0000000..d620022 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/ReportGroupedOrders.rdlc @@ -0,0 +1,424 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + GarmentFactoryShopContractsViewModels + /* Local Query */ + + + + Date + System.DateTime + + + Count + System.Int32 + + + Sum + System.Decimal + + + + GarmentFactoryShopContracts.ViewModels + ReportOrdersByDateViewModel + GarmentFactoryShopContracts.ViewModels.ReportOrdersByDateViewModel, GarmentFactoryShopContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Заказы по датам + + + + + + + 1cm + 21cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 6.01401cm + + + 6.56042cm + + + 6.12687cm + + + + + 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!Date.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Count.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 1.95474cm + 1.16099cm + 1.2cm + 18.7013cm + 1 + + + + + + true + true + + + + + Всего: + + + + + + + 4cm + 11.23542cm + 0.6cm + 2.5cm + 2 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + 4cm + 13.73542cm + 0.6cm + 6.12687cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm +