diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index 649d169..8039c88 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -32,11 +32,11 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.сушиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокИнгредиентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ингредиентыПоСушиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonSetToDone = new System.Windows.Forms.Button(); @@ -45,6 +45,7 @@ this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonAddSushiInShop = new System.Windows.Forms.Button(); this.buttonSellSushi = new System.Windows.Forms.Button(); + this.списокМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -84,12 +85,20 @@ this.сушиToolStripMenuItem.Text = "Суши"; this.сушиToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click); // + // shopsToolStripMenuItem + // + this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.shopsToolStripMenuItem.Text = "Магазины"; + this.shopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.списокИнгредиентовToolStripMenuItem, this.ингредиентыПоСушиToolStripMenuItem, - this.списокЗаказовToolStripMenuItem}); + this.списокЗаказовToolStripMenuItem, + this.списокМагазиновToolStripMenuItem}); this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); this.отчетыToolStripMenuItem.Text = "Отчеты"; @@ -115,13 +124,6 @@ this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); // - // shopsToolStripMenuItem - // - this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; - this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.shopsToolStripMenuItem.Text = "Магазины"; - this.shopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); - // // buttonUpdate // this.buttonUpdate.Location = new System.Drawing.Point(778, 212); @@ -211,6 +213,13 @@ this.buttonSellSushi.UseVisualStyleBackColor = true; this.buttonSellSushi.Click += new System.EventHandler(this.ButtonSellSushi_Click); // + // списокМагазиновToolStripMenuItem + // + this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(203, 22); + this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; + this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.ShopsReportToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -256,5 +265,6 @@ private ToolStripMenuItem shopsToolStripMenuItem; private Button buttonAddSushiInShop; private Button buttonSellSushi; + private ToolStripMenuItem списокМагазиновToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index e53c8f8..b1e1e0e 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -155,6 +155,16 @@ namespace SushiBarView } } + private void ShopsReportToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + private void SushiIngredientToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReportSushiIngredients)); diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ReportLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ReportLogic.cs index 4e63df3..12cb666 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ReportLogic.cs @@ -16,14 +16,16 @@ namespace SushiBarBusinessLogic.BusinessLogics private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(ISushiStorage productStorage, IIngredientStorage ingredientStorage, IOrderStorage orderStorage, - AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + public ReportLogic(ISushiStorage productStorage, IIngredientStorage ingredientStorage, IOrderStorage orderStorage, + AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf, IShopStorage shopStorage) { _sushiStorage = productStorage; _ingredientStorage = ingredientStorage; @@ -32,6 +34,7 @@ namespace SushiBarBusinessLogic.BusinessLogics _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; + _shopStorage = shopStorage; } /// @@ -103,6 +106,20 @@ namespace SushiBarBusinessLogic.BusinessLogics }); } + /// + /// Сохранение магазинов в файл-Word + /// + /// + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateShopsDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + /// /// Сохранение ингредиентов с указаеним суши в файл-Excel /// diff --git a/SushiBar/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/SushiBar/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 2b679b3..b761a4d 100644 --- a/SushiBar/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/SushiBar/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -23,7 +23,7 @@ namespace SushiBarBusinessLogic.OfficePackage { CreateParagraph(new WordParagraph { - Texts = new List<(string, WordTextProperties)> { + Texts = new List<(string, WordTextProperties)> { (sushi.SushiName+' ', new WordTextProperties { Size = "24", Bold = true }), (sushi.Price.ToString(), new WordTextProperties { Size = "24" }) }, @@ -38,12 +38,69 @@ namespace SushiBarBusinessLogic.OfficePackage SaveWord(info); } + public void CreateShopsDoc(WordInfo info) + { + CreateWord(info); + + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24" }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + List rows = new List(); + rows.Add(new WordRow + { + Texts = new List<(string, WordTextProperties)> { + ("Название", new WordTextProperties { Size = "24", Bold = true }), + ("Адрес", new WordTextProperties { Size = "24", Bold = true }), + ("Дата открытия", new WordTextProperties { Size = "24", Bold = true }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + + foreach (var shop in info.Shops) + { + rows.Add(new WordRow + { + Texts = new List<(string, WordTextProperties)> { + (shop.ShopName, new WordTextProperties { Size = "24" }), + (shop.Address, new WordTextProperties { Size = "24" }), + (shop.DateOpening.ToShortDateString(), new WordTextProperties { Size = "24" }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + + CreateTable(rows); + + SaveWord(info); + } + /// /// Создание doc-файла /// /// protected abstract void CreateWord(WordInfo info); + /// + /// Создание таблицы + /// + /// + protected abstract void CreateTable(List rows); + /// /// Создание абзаца с текстом /// diff --git a/SushiBar/SushiBarBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/SushiBar/SushiBarBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index dd7576f..0dbb004 100644 --- a/SushiBar/SushiBarBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/SushiBar/SushiBarBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -9,5 +9,7 @@ namespace SushiBarBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public List ListSushi { get; set; } = new(); + + public List Shops { get; set; } = new(); } } \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/OfficePackage/HelperModels/WordRow.cs b/SushiBar/SushiBarBusinessLogic/OfficePackage/HelperModels/WordRow.cs new file mode 100644 index 0000000..a534875 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/OfficePackage/HelperModels/WordRow.cs @@ -0,0 +1,9 @@ +namespace SushiBarBusinessLogic.OfficePackage.HelperModels +{ + public class WordRow + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + + public WordTextProperties? TextProperties { get; set; } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/SushiBar/SushiBarBusinessLogic/OfficePackage/Implements/SaveToWord.cs index d7653bc..2eed47e 100644 --- a/SushiBar/SushiBarBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/SushiBar/SushiBarBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -89,6 +89,60 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements _docBody = mainPart.Document.AppendChild(new Body()); } + protected override void CreateTable(List data) + { + if (_docBody == null || data == null) + { + return; + } + Table table = new Table(); + var tableProp = new TableProperties(); + tableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed }); + tableProp.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 } + )); + tableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto }); + table.AppendChild(tableProp); + TableGrid tableGrid = new TableGrid(); + for (int j = 0; j < data[0].Texts.Count; ++j) + { + tableGrid.AppendChild(new GridColumn() { Width = "3200" }); + } + table.AppendChild(tableGrid); + for (int i = 0; i < data.Count; ++i) + { + TableRow docRow = new TableRow(); + for (int j = 0; j < data[i].Texts.Count; ++j) + { + var docParagraph = new Paragraph(); + var docRun = new Run(); + var runProperties = new RunProperties(); + + docParagraph.AppendChild(CreateParagraphProperties(data[i].Texts[j].Item2)); + + runProperties.AppendChild(new RunFonts() { Ascii = "Times New Roman", ComplexScript = "Times New Roman", HighAnsi = "Times New Roman" }); + runProperties.AppendChild(new FontSize { Val = data[i].Texts[j].Item2.Size == null ? data[i].Texts[j].Item2.Size : "24" }); + if (data[i].Texts[j].Item2.Bold) + runProperties.AppendChild(new Bold()); + + docRun.AppendChild(runProperties); + docRun.AppendChild(new Text { Text = data[i].Texts[j].Item1.ToString(), Space = SpaceProcessingModeValues.Preserve }); + + docParagraph.AppendChild(docRun); + TableCell docCell = new TableCell(); + docCell.AppendChild(docParagraph); + docRow.AppendChild(docCell); + } + table.AppendChild(docRow); + } + _docBody.AppendChild(table); + } + protected override void CreateParagraph(WordParagraph paragraph) { if (_docBody == null || paragraph == null) diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs index 4260513..c519bb8 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IReportLogic.cs @@ -19,11 +19,17 @@ namespace SushiBarContracts.BusinessLogicsContracts List GetOrders(ReportBindingModel model); /// - /// Сохранение индгредиентов в файл-Word + /// Сохранение суши в файл-Word /// /// void SaveListSushiToWordFile(ReportBindingModel model); + /// + /// Сохранение магазинов в файл-Word + /// + /// + void SaveShopsToWordFile(ReportBindingModel model); + /// /// Сохранение индгредиентов с указаеним суши в файл-Excel ///