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

View File

@ -11,6 +11,6 @@ namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{ {
public string FileName { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty;
public string Title { 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(); _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.SearchModels;
using ConfectioneryContracts.StoragesContract; using ConfectioneryContracts.StoragesContract;
using ConfectioneryContracts.ViewModels; using ConfectioneryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryBusinessLogic namespace ConfectioneryBusinessLogic
{ {
@ -21,18 +16,21 @@ namespace ConfectioneryBusinessLogic
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf; 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) AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{ {
_pastryStorage = PastryStorage; _pastryStorage = PastryStorage;
_componentStorage = componentStorage; _componentStorage = componentStorage;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_shopStorage = shopStorage;
_saveToExcel = saveToExcel; _saveToExcel = saveToExcel;
_saveToWord = saveToWord; _saveToWord = saveToWord;
@ -94,16 +92,16 @@ namespace ConfectioneryBusinessLogic
} }
/// <summary> /// <summary>
/// Сохранение изделий в файл-Word /// Сохранение магазинов в файл-Word
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
public void SavePastriesToWordFile(ReportBindingModel model) public void SaveShopsToWordFile(ReportBindingModel model)
{ {
_saveToWord.CreateDoc(new WordInfo _saveToWord.CreateDoc(new WordInfo
{ {
FileName = model.FileName, FileName = model.FileName,
Title = "Список изделий", Title = "Список магазинов",
Pastries = _pastryStorage.GetFullList() Shops = _shopStorage.GetFullList()
}); });
} }

View File

@ -28,26 +28,26 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.menuStrip1 = new System.Windows.Forms.MenuStrip(); menuStrip1 = new MenuStrip();
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); справочникиToolStripMenuItem = new ToolStripMenuItem();
this.pastryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); pastryToolStripMenuItem = new ToolStripMenuItem();
this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); componentToolStripMenuItem = new ToolStripMenuItem();
this.ShopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ShopsToolStripMenuItem = new ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView(); reportsToolStripMenuItem = new ToolStripMenuItem();
this.buttonCreateOrder = new System.Windows.Forms.Button(); reportShopsToolStripMenuItem = new ToolStripMenuItem();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); pastryComponentsToolStripMenuItem = new ToolStripMenuItem();
this.button2 = new System.Windows.Forms.Button(); ordersToolStripMenuItem = new ToolStripMenuItem();
this.button3 = new System.Windows.Forms.Button(); dataGridView = new DataGridView();
this.button4 = new System.Windows.Forms.Button(); buttonCreateOrder = new Button();
this.buttonAddPastryInShop = new System.Windows.Forms.Button(); buttonTakeOrderInWork = new Button();
this.buttonSellPastry = new System.Windows.Forms.Button(); button2 = new Button();
this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); button3 = new Button();
this.pastriesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); button4 = new Button();
this.pastryComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); buttonAddPastryInShop = new Button();
this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); buttonSellPastry = new Button();
this.menuStrip1.SuspendLayout(); menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
this.SuspendLayout(); SuspendLayout();
// //
// menuStrip1 // menuStrip1
// //
@ -60,13 +60,10 @@
// //
// справочникиToolStripMenuItem // справочникиToolStripMenuItem
// //
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pastryToolStripMenuItem, componentToolStripMenuItem, ShopsToolStripMenuItem });
this.pastryToolStripMenuItem, справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.componentToolStripMenuItem, справочникиToolStripMenuItem.Size = new Size(94, 20);
this.ShopsToolStripMenuItem}); справочникиToolStripMenuItem.Text = "Справочники";
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.справочникиToolStripMenuItem.Text = "Справочники";
// //
// pastryToolStripMenuItem // pastryToolStripMenuItem
// //
@ -82,19 +79,26 @@
componentToolStripMenuItem.Text = "Компоненты"; componentToolStripMenuItem.Text = "Компоненты";
componentToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; componentToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
// //
// ShopsToolStripMenuItem
//
ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem";
ShopsToolStripMenuItem.Size = new Size(145, 22);
ShopsToolStripMenuItem.Text = "Магазины";
ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click;
//
// reportsToolStripMenuItem // reportsToolStripMenuItem
// //
reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { pastriesToolStripMenuItem, pastryComponentsToolStripMenuItem, ordersToolStripMenuItem }); reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { reportShopsToolStripMenuItem, pastryComponentsToolStripMenuItem, ordersToolStripMenuItem });
reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; reportsToolStripMenuItem.Name = "reportsToolStripMenuItem";
reportsToolStripMenuItem.Size = new Size(60, 20); reportsToolStripMenuItem.Size = new Size(60, 20);
reportsToolStripMenuItem.Text = "Отчеты"; reportsToolStripMenuItem.Text = "Отчеты";
// //
// pastriesToolStripMenuItem // reportShopsToolStripMenuItem
// //
pastriesToolStripMenuItem.Name = "pastriesToolStripMenuItem"; reportShopsToolStripMenuItem.Name = "reportShopsToolStripMenuItem";
pastriesToolStripMenuItem.Size = new Size(215, 22); reportShopsToolStripMenuItem.Size = new Size(215, 22);
pastriesToolStripMenuItem.Text = "Список изделий"; reportShopsToolStripMenuItem.Text = "Список магазинов";
pastriesToolStripMenuItem.Click += PastriesToolStripMenuItem_Click_1; reportShopsToolStripMenuItem.Click += ReportShopsToolStripMenuItem_Click;
// //
// pastryComponentsToolStripMenuItem // pastryComponentsToolStripMenuItem
// //
@ -110,24 +114,15 @@
ordersToolStripMenuItem.Text = "Список заказов"; ordersToolStripMenuItem.Text = "Список заказов";
ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; 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 // dataGridView
// //
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
| System.Windows.Forms.AnchorStyles.Left) dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
| System.Windows.Forms.AnchorStyles.Right))); dataGridView.Location = new Point(12, 27);
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Name = "dataGridView";
this.dataGridView.Location = new System.Drawing.Point(12, 27); dataGridView.RowTemplate.Height = 25;
this.dataGridView.Name = "dataGridView"; dataGridView.Size = new Size(606, 399);
this.dataGridView.RowTemplate.Height = 25; dataGridView.TabIndex = 1;
this.dataGridView.Size = new System.Drawing.Size(606, 399);
this.dataGridView.TabIndex = 1;
// //
// buttonCreateOrder // buttonCreateOrder
// //
@ -186,50 +181,49 @@
// //
// buttonAddPastryInShop // buttonAddPastryInShop
// //
this.buttonAddPastryInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); buttonAddPastryInShop.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
this.buttonAddPastryInShop.Location = new System.Drawing.Point(624, 384); buttonAddPastryInShop.Location = new Point(624, 384);
this.buttonAddPastryInShop.Name = "buttonAddPastryInShop"; buttonAddPastryInShop.Name = "buttonAddPastryInShop";
this.buttonAddPastryInShop.Size = new System.Drawing.Size(147, 31); buttonAddPastryInShop.Size = new Size(147, 31);
this.buttonAddPastryInShop.TabIndex = 7; buttonAddPastryInShop.TabIndex = 7;
this.buttonAddPastryInShop.Text = "Пополнение магазина"; buttonAddPastryInShop.Text = "Пополнение магазина";
this.buttonAddPastryInShop.UseVisualStyleBackColor = true; buttonAddPastryInShop.UseVisualStyleBackColor = true;
this.buttonAddPastryInShop.Click += new System.EventHandler(this.ButtonAddPastryInShop_Click); buttonAddPastryInShop.Click += ButtonAddPastryInShop_Click;
// //
// buttonSellPastry // buttonSellPastry
// //
this.buttonSellPastry.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); buttonSellPastry.Anchor = AnchorStyles.Top | AnchorStyles.Right;
this.buttonSellPastry.Location = new System.Drawing.Point(624, 331); buttonSellPastry.Location = new Point(624, 331);
this.buttonSellPastry.Name = "buttonSellPastry"; buttonSellPastry.Name = "buttonSellPastry";
this.buttonSellPastry.Size = new System.Drawing.Size(147, 31); buttonSellPastry.Size = new Size(147, 31);
this.buttonSellPastry.TabIndex = 8; buttonSellPastry.TabIndex = 8;
this.buttonSellPastry.Text = "Продать изделие"; buttonSellPastry.Text = "Продать изделие";
this.buttonSellPastry.UseVisualStyleBackColor = true; buttonSellPastry.UseVisualStyleBackColor = true;
this.buttonSellPastry.Click += new System.EventHandler(this.ButtonSellPastry_Click); buttonSellPastry.Click += ButtonSellPastry_Click;
// //
// FormMain // FormMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(783, 438); ClientSize = new Size(783, 438);
this.Controls.Add(this.buttonSellPastry); Controls.Add(buttonSellPastry);
this.Controls.Add(this.buttonAddPastryInShop); Controls.Add(buttonAddPastryInShop);
this.Controls.Add(this.button4); Controls.Add(button4);
this.Controls.Add(this.button3); Controls.Add(button3);
this.Controls.Add(this.button2); Controls.Add(button2);
this.Controls.Add(this.buttonTakeOrderInWork); Controls.Add(buttonTakeOrderInWork);
this.Controls.Add(this.buttonCreateOrder); Controls.Add(buttonCreateOrder);
this.Controls.Add(this.dataGridView); Controls.Add(dataGridView);
this.Controls.Add(this.menuStrip1); Controls.Add(menuStrip1);
this.MainMenuStrip = this.menuStrip1; MainMenuStrip = menuStrip1;
this.Name = "FormMain"; Name = "FormMain";
this.Text = "Кондитерская"; Text = "Кондитерская";
this.Load += new System.EventHandler(this.FormMain_Load); Load += FormMain_Load;
this.menuStrip1.ResumeLayout(false); menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout(); menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
this.ResumeLayout(false); ResumeLayout(false);
this.PerformLayout(); PerformLayout();
} }
#endregion #endregion
@ -245,7 +239,7 @@
private ToolStripMenuItem pastryToolStripMenuItem; private ToolStripMenuItem pastryToolStripMenuItem;
private ToolStripMenuItem componentToolStripMenuItem; private ToolStripMenuItem componentToolStripMenuItem;
private ToolStripMenuItem reportsToolStripMenuItem; private ToolStripMenuItem reportsToolStripMenuItem;
private ToolStripMenuItem pastriesToolStripMenuItem; private ToolStripMenuItem reportShopsToolStripMenuItem;
private ToolStripMenuItem pastryComponentsToolStripMenuItem; private ToolStripMenuItem pastryComponentsToolStripMenuItem;
private ToolStripMenuItem ordersToolStripMenuItem; private ToolStripMenuItem ordersToolStripMenuItem;
private ToolStripMenuItem ShopsToolStripMenuItem; private ToolStripMenuItem ShopsToolStripMenuItem;

View File

@ -156,12 +156,12 @@ namespace ConfectioneryView
LoadData(); 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" }; using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK) 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); MessageBox.Show("Âûïîëíåíî", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
} }

View File

@ -28,7 +28,7 @@ namespace ConfectioneryView
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Pastries"].Visible = false; dataGridView.Columns["Shops"].Visible = false;
dataGridView.Columns["Name"].AutoSizeMode = dataGridView.Columns["Name"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill; DataGridViewAutoSizeColumnMode.Fill;
} }

View File

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