Добавлен отчет в word-формате

This commit is contained in:
Данияр Аглиуллов 2023-03-02 02:49:25 +04:00
parent e982cdde12
commit bb405202d7
8 changed files with 155 additions and 118 deletions

View File

@ -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" })
("Название", 3000),
("Дата", null),
("Адрес открытия", 4500),
},
TextProperties = new WordTextProperties
info.Shops
.Select(x => new List<string>
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
x.Name,
Convert.ToString(x.DateOpening),
x.Address,
})
.ToList());
SaveWord(info);
}
@ -57,6 +55,13 @@ namespace ConfectioneryBusinessLogic.OfficePackage
/// <returns></returns>
protected abstract void CreateParagraph(WordParagraph paragraph);
/// <summary>
/// Создание таблицы в файле
/// </summary>
/// <param name="nameAndWidthColumns">Строчка заголовок таблицы, определяет текст и ширину каждого столбца</param>
/// <param name="rows">The rows.</param>
protected abstract void CreateTable(List<(string, int?)> nameAndWidthColumns, List<List<string>> rows);
/// <summary>
/// Сохранение файла
/// </summary>

View File

@ -11,6 +11,6 @@ namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<PastryViewModel> Pastries { get; set; } = new();
public List<ShopViewModel> Shops { get; set; } = new();
}
}

View File

@ -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<List<string>> rows)
{
if (_docBody == null)
{
return;
}
Table table = new();
TableProperties tblProp = new TableProperties(
new TableBorders(
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(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);
}
}
}

View File

@ -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
}
/// <summary>
/// Сохранение изделий в файл-Word
/// Сохранение магазинов в файл-Word
/// </summary>
/// <param name="model"></param>
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()
});
}

View File

@ -28,26 +28,26 @@
/// </summary>
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;

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -25,7 +25,7 @@ namespace ConfectioneryContracts.BusinessLogicsContracts
/// Сохранение компонент в файл-Word
/// </summary>
/// <param name="model"></param>
void SavePastriesToWordFile(ReportBindingModel model);
void SaveShopsToWordFile(ReportBindingModel model);
/// <summary>
/// Сохранение компонент с указаеним продуктов в файл-Excel
/// </summary>