diff --git a/ConfectionaryBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/ConfectionaryBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 642a23a..1e72c44 100644 --- a/ConfectionaryBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/ConfectionaryBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -24,22 +24,20 @@ namespace ConfectioneryBusinessLogic.OfficePackage } }); - foreach (var pastry in info.Pastries) + CreateTable(new() { - CreateParagraph(new WordParagraph - { - Texts = new List<(string, WordTextProperties)> - { - (pastry.PastryName , new WordTextProperties { Size = "24", Bold = true}), - (" - цена: " + pastry.Price.ToString(), new WordTextProperties { Size = "24" }) - }, - TextProperties = new WordTextProperties - { - Size = "24", - JustificationType = WordJustificationType.Both - } - }); - } + ("Название", 3000), + ("Дата", null), + ("Адрес открытия", 4500), + }, + info.Shops + .Select(x => new List + { + x.Name, + Convert.ToString(x.DateOpening), + x.Address, + }) + .ToList()); SaveWord(info); } @@ -57,6 +55,13 @@ namespace ConfectioneryBusinessLogic.OfficePackage /// protected abstract void CreateParagraph(WordParagraph paragraph); + /// + /// Создание таблицы в файле + /// + /// Строчка заголовок таблицы, определяет текст и ширину каждого столбца + /// The rows. + protected abstract void CreateTable(List<(string, int?)> nameAndWidthColumns, List> rows); + /// /// Сохранение файла /// diff --git a/ConfectionaryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/ConfectionaryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 18165c5..b3846a7 100644 --- a/ConfectionaryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/ConfectionaryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -11,6 +11,6 @@ namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List Pastries { get; set; } = new(); + public List Shops { get; set; } = new(); } } diff --git a/ConfectionaryBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/ConfectionaryBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 1ce67cd..af6a547 100644 --- a/ConfectionaryBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/ConfectionaryBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -131,5 +131,45 @@ namespace ConfectioneryBusinessLogic.OfficePackage.Implements _wordDocument.Close(); } + + private static TableCell GetTableCell(string text, int? widthCell = null) + { + + TableCell cell = new(new Paragraph(new Run(new Text(text)))); + if (widthCell != null) + { + cell.Append(new TableCellProperties() + { + TableCellWidth = new() { Width = widthCell.ToString() } + }); + } + return cell; + } + + protected override void CreateTable(List<(string, int?)> nameAndWidthColumns, List> rows) + { + if (_docBody == null) + { + return; + } + Table table = new(); + TableProperties tblProp = new TableProperties( + new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new BottomBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new LeftBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new RightBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 } + ) + ); + table.AppendChild(tblProp); + + table.Append(new TableRow(nameAndWidthColumns.Select(x => GetTableCell(x.Item1, x.Item2)))); + + table.Append(rows.Select(x => new TableRow(x.Select(y => GetTableCell(y))))); + + _docBody.Append(table); + } } } diff --git a/ConfectionaryBusinessLogic/ReportLogic.cs b/ConfectionaryBusinessLogic/ReportLogic.cs index a58b073..60df17c 100644 --- a/ConfectionaryBusinessLogic/ReportLogic.cs +++ b/ConfectionaryBusinessLogic/ReportLogic.cs @@ -5,11 +5,6 @@ using ConfectioneryContracts.BusinessLogicsContracts; using ConfectioneryContracts.SearchModels; using ConfectioneryContracts.StoragesContract; using ConfectioneryContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ConfectioneryBusinessLogic { @@ -21,18 +16,21 @@ namespace ConfectioneryBusinessLogic private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(IPastryStorage PastryStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, + public ReportLogic(IPastryStorage PastryStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _pastryStorage = PastryStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; @@ -94,16 +92,16 @@ namespace ConfectioneryBusinessLogic } /// - /// Сохранение изделий в файл-Word + /// Сохранение магазинов в файл-Word /// /// - public void SavePastriesToWordFile(ReportBindingModel model) + public void SaveShopsToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo { FileName = model.FileName, - Title = "Список изделий", - Pastries = _pastryStorage.GetFullList() + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() }); } diff --git a/Confectionery/FormMain.Designer.cs b/Confectionery/FormMain.Designer.cs index 9415f1f..6cd32ba 100644 --- a/Confectionery/FormMain.Designer.cs +++ b/Confectionery/FormMain.Designer.cs @@ -28,26 +28,26 @@ /// private void InitializeComponent() { - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.pastryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ShopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); - this.button3 = new System.Windows.Forms.Button(); - this.button4 = new System.Windows.Forms.Button(); - this.buttonAddPastryInShop = new System.Windows.Forms.Button(); - this.buttonSellPastry = new System.Windows.Forms.Button(); - this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.pastriesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.pastryComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + pastryToolStripMenuItem = new ToolStripMenuItem(); + componentToolStripMenuItem = new ToolStripMenuItem(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + reportsToolStripMenuItem = new ToolStripMenuItem(); + reportShopsToolStripMenuItem = new ToolStripMenuItem(); + pastryComponentsToolStripMenuItem = new ToolStripMenuItem(); + ordersToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + button2 = new Button(); + button3 = new Button(); + button4 = new Button(); + buttonAddPastryInShop = new Button(); + buttonSellPastry = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); // // menuStrip1 // @@ -60,13 +60,10 @@ // // справочникиToolStripMenuItem // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.pastryToolStripMenuItem, - this.componentToolStripMenuItem, - this.ShopsToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); - this.справочникиToolStripMenuItem.Text = "Справочники"; + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pastryToolStripMenuItem, componentToolStripMenuItem, ShopsToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; // // pastryToolStripMenuItem // @@ -82,19 +79,26 @@ componentToolStripMenuItem.Text = "Компоненты"; componentToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(145, 22); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // // reportsToolStripMenuItem // - reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pastriesToolStripMenuItem, pastryComponentsToolStripMenuItem, ordersToolStripMenuItem }); + reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { reportShopsToolStripMenuItem, pastryComponentsToolStripMenuItem, ordersToolStripMenuItem }); reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; reportsToolStripMenuItem.Size = new Size(60, 20); reportsToolStripMenuItem.Text = "Отчеты"; // - // pastriesToolStripMenuItem + // reportShopsToolStripMenuItem // - pastriesToolStripMenuItem.Name = "pastriesToolStripMenuItem"; - pastriesToolStripMenuItem.Size = new Size(215, 22); - pastriesToolStripMenuItem.Text = "Список изделий"; - pastriesToolStripMenuItem.Click += PastriesToolStripMenuItem_Click_1; + reportShopsToolStripMenuItem.Name = "reportShopsToolStripMenuItem"; + reportShopsToolStripMenuItem.Size = new Size(215, 22); + reportShopsToolStripMenuItem.Text = "Список магазинов"; + reportShopsToolStripMenuItem.Click += ReportShopsToolStripMenuItem_Click; // // pastryComponentsToolStripMenuItem // @@ -110,24 +114,15 @@ ordersToolStripMenuItem.Text = "Список заказов"; ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // - // ShopsToolStripMenuItem - // - this.ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; - this.ShopsToolStripMenuItem.Size = new System.Drawing.Size(145, 22); - this.ShopsToolStripMenuItem.Text = "Магазины"; - this.ShopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); - // // dataGridView // - this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 27); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(606, 399); - this.dataGridView.TabIndex = 1; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(606, 399); + dataGridView.TabIndex = 1; // // buttonCreateOrder // @@ -186,50 +181,49 @@ // // buttonAddPastryInShop // - this.buttonAddPastryInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonAddPastryInShop.Location = new System.Drawing.Point(624, 384); - this.buttonAddPastryInShop.Name = "buttonAddPastryInShop"; - this.buttonAddPastryInShop.Size = new System.Drawing.Size(147, 31); - this.buttonAddPastryInShop.TabIndex = 7; - this.buttonAddPastryInShop.Text = "Пополнение магазина"; - this.buttonAddPastryInShop.UseVisualStyleBackColor = true; - this.buttonAddPastryInShop.Click += new System.EventHandler(this.ButtonAddPastryInShop_Click); + buttonAddPastryInShop.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonAddPastryInShop.Location = new Point(624, 384); + buttonAddPastryInShop.Name = "buttonAddPastryInShop"; + buttonAddPastryInShop.Size = new Size(147, 31); + buttonAddPastryInShop.TabIndex = 7; + buttonAddPastryInShop.Text = "Пополнение магазина"; + buttonAddPastryInShop.UseVisualStyleBackColor = true; + buttonAddPastryInShop.Click += ButtonAddPastryInShop_Click; // // buttonSellPastry // - this.buttonSellPastry.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonSellPastry.Location = new System.Drawing.Point(624, 331); - this.buttonSellPastry.Name = "buttonSellPastry"; - this.buttonSellPastry.Size = new System.Drawing.Size(147, 31); - this.buttonSellPastry.TabIndex = 8; - this.buttonSellPastry.Text = "Продать изделие"; - this.buttonSellPastry.UseVisualStyleBackColor = true; - this.buttonSellPastry.Click += new System.EventHandler(this.ButtonSellPastry_Click); + buttonSellPastry.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonSellPastry.Location = new Point(624, 331); + buttonSellPastry.Name = "buttonSellPastry"; + buttonSellPastry.Size = new Size(147, 31); + buttonSellPastry.TabIndex = 8; + buttonSellPastry.Text = "Продать изделие"; + buttonSellPastry.UseVisualStyleBackColor = true; + buttonSellPastry.Click += ButtonSellPastry_Click; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(783, 438); - this.Controls.Add(this.buttonSellPastry); - this.Controls.Add(this.buttonAddPastryInShop); - this.Controls.Add(this.button4); - this.Controls.Add(this.button3); - this.Controls.Add(this.button2); - this.Controls.Add(this.buttonTakeOrderInWork); - this.Controls.Add(this.buttonCreateOrder); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip1); - this.MainMenuStrip = this.menuStrip1; - this.Name = "FormMain"; - this.Text = "Кондитерская"; - this.Load += new System.EventHandler(this.FormMain_Load); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(783, 438); + Controls.Add(buttonSellPastry); + Controls.Add(buttonAddPastryInShop); + Controls.Add(button4); + Controls.Add(button3); + Controls.Add(button2); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Кондитерская"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -245,7 +239,7 @@ private ToolStripMenuItem pastryToolStripMenuItem; private ToolStripMenuItem componentToolStripMenuItem; private ToolStripMenuItem reportsToolStripMenuItem; - private ToolStripMenuItem pastriesToolStripMenuItem; + private ToolStripMenuItem reportShopsToolStripMenuItem; private ToolStripMenuItem pastryComponentsToolStripMenuItem; private ToolStripMenuItem ordersToolStripMenuItem; private ToolStripMenuItem ShopsToolStripMenuItem; diff --git a/Confectionery/FormMain.cs b/Confectionery/FormMain.cs index 8ae6a40..6c01a25 100644 --- a/Confectionery/FormMain.cs +++ b/Confectionery/FormMain.cs @@ -156,12 +156,12 @@ namespace ConfectioneryView LoadData(); } - private void PastriesToolStripMenuItem_Click_1(object sender, EventArgs e) + private void ReportShopsToolStripMenuItem_Click(object sender, EventArgs e) { using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; if (dialog.ShowDialog() == DialogResult.OK) { - _reportLogic.SavePastriesToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + _reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); MessageBox.Show("", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } diff --git a/Confectionery/FormViewShops.cs b/Confectionery/FormViewShops.cs index 419130c..995d86e 100644 --- a/Confectionery/FormViewShops.cs +++ b/Confectionery/FormViewShops.cs @@ -28,7 +28,7 @@ namespace ConfectioneryView dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["Pastries"].Visible = false; + dataGridView.Columns["Shops"].Visible = false; dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } diff --git a/ConfectioneryContracts/BusinessLogicsContracts/IReportLogic.cs b/ConfectioneryContracts/BusinessLogicsContracts/IReportLogic.cs index 793b11c..22f0a4d 100644 --- a/ConfectioneryContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/ConfectioneryContracts/BusinessLogicsContracts/IReportLogic.cs @@ -25,7 +25,7 @@ namespace ConfectioneryContracts.BusinessLogicsContracts /// Сохранение компонент в файл-Word /// /// - void SavePastriesToWordFile(ReportBindingModel model); + void SaveShopsToWordFile(ReportBindingModel model); /// /// Сохранение компонент с указаеним продуктов в файл-Excel ///