Отчёт по магазинам в word
This commit is contained in:
parent
1f48e676f2
commit
2e66e6e59f
11
GarmentFactory/FormMain.Designer.cs
generated
11
GarmentFactory/FormMain.Designer.cs
generated
@ -46,6 +46,7 @@
|
||||
textilesToolStripMenuItem = new ToolStripMenuItem();
|
||||
textileComponentsToolStripMenuItem = new ToolStripMenuItem();
|
||||
ordersToolStripMenuItem = new ToolStripMenuItem();
|
||||
магазиныВDocToolStripMenuItem = new ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
@ -182,7 +183,7 @@
|
||||
//
|
||||
// отчётыToolStripMenuItem
|
||||
//
|
||||
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { textilesToolStripMenuItem, textileComponentsToolStripMenuItem, ordersToolStripMenuItem });
|
||||
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { textilesToolStripMenuItem, textileComponentsToolStripMenuItem, ordersToolStripMenuItem, магазиныВDocToolStripMenuItem });
|
||||
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
|
||||
отчётыToolStripMenuItem.Size = new Size(73, 24);
|
||||
отчётыToolStripMenuItem.Text = "Отчёты";
|
||||
@ -208,6 +209,13 @@
|
||||
ordersToolStripMenuItem.Text = "Заказы";
|
||||
ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
|
||||
//
|
||||
// магазиныВDocToolStripMenuItem
|
||||
//
|
||||
магазиныВDocToolStripMenuItem.Name = "магазиныВDocToolStripMenuItem";
|
||||
магазиныВDocToolStripMenuItem.Size = new Size(274, 26);
|
||||
магазиныВDocToolStripMenuItem.Text = "Магазины в doc";
|
||||
магазиныВDocToolStripMenuItem.Click += магазиныВDocToolStripMenuItem_Click;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
@ -251,5 +259,6 @@
|
||||
private ToolStripMenuItem textilesToolStripMenuItem;
|
||||
private ToolStripMenuItem textileComponentsToolStripMenuItem;
|
||||
private ToolStripMenuItem ordersToolStripMenuItem;
|
||||
private ToolStripMenuItem магазиныВDocToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -211,5 +211,15 @@ namespace GarmentFactoryView
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void магазиныВDocToolStripMenuItem_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GarmentFactoryContracts.ViewModels;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.BusinessLogics
|
||||
{
|
||||
@ -18,16 +19,18 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
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, IOrderStorage orderStorage, IShopStorage shopStorage,
|
||||
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||
{
|
||||
_textileStorage = textileStorage;
|
||||
_componentStorage = componentStorage;
|
||||
_orderStorage = orderStorage;
|
||||
_shopStorage = shopStorage;
|
||||
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
@ -106,5 +109,55 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics
|
||||
Orders = GetOrders(model)
|
||||
});
|
||||
}
|
||||
|
||||
public List<ReportShopsViewModel> GetShops()
|
||||
{
|
||||
return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel
|
||||
{
|
||||
ShopName = x.ShopName,
|
||||
Textiles = x.ShopTextiles.Select(x => (x.Value.Item1.TextileName, x.Value.Item2)).ToList(),
|
||||
TotalCount = x.ShopTextiles.Select(x => x.Value.Item2).Sum()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
//public List<ReportGroupOrdersViewModel> GetGroupedOrders()
|
||||
//{
|
||||
// return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupOrdersViewModel
|
||||
// {
|
||||
// Date = x.Key,
|
||||
// OrdersCount = x.Count(),
|
||||
// OrdersSum = x.Select(y => y.Sum).Sum()
|
||||
// }).ToList();
|
||||
//}
|
||||
|
||||
public void SaveShopsToWordFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToWord.CreateShopsDoc(new WordShopInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список магазинов",
|
||||
Shops = _shopStorage.GetFullList()
|
||||
});
|
||||
}
|
||||
|
||||
//public void SaveShopsToExcelFile(ReportBindingModel model)
|
||||
//{
|
||||
// _saveToExcel.CreateShopTextilesReport(new ExcelShop
|
||||
// {
|
||||
// FileName = model.FileName,
|
||||
// Title = "Наполненость магазинов",
|
||||
// ShopTextiles = GetShops()
|
||||
// });
|
||||
//}
|
||||
|
||||
//public void SaveGroupedOrdersToPdfFile(ReportBindingModel model)
|
||||
//{
|
||||
// _saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo
|
||||
// {
|
||||
// FileName = model.FileName,
|
||||
// Title = "Список заказов сгруппированных по дате заказов",
|
||||
// GroupedOrders = GetGroupedOrders()
|
||||
// });
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -43,11 +45,52 @@ namespace GarmentFactoryBusinessLogic.OfficePackage
|
||||
SaveWord(info);
|
||||
}
|
||||
|
||||
public void CreateShopsDoc(WordShopInfo 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
|
||||
}
|
||||
});
|
||||
|
||||
CreateTable(new List<string> { "3000", "3000", "3000" });
|
||||
CreateRow(new WordRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Название", "Адрес", "Дата открытия" },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
Bold = true,
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var shop in info.Shops)
|
||||
{
|
||||
CreateRow(new WordRowParameters
|
||||
{
|
||||
Texts = new List<string> { shop.ShopName, shop.Address, shop.DateOpen.ToString() },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "22",
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SaveWord(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание doc-файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void CreateWord(WordInfo info);
|
||||
protected abstract void CreateWord(IDocumentInfo info);
|
||||
|
||||
/// <summary>
|
||||
/// Создание абзаца с текстом
|
||||
@ -60,6 +103,9 @@ namespace GarmentFactoryBusinessLogic.OfficePackage
|
||||
/// Сохранение файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void SaveWord(WordInfo info);
|
||||
protected abstract void SaveWord(IDocumentInfo info);
|
||||
|
||||
protected abstract void CreateTable(List<string> colums);
|
||||
protected abstract void CreateRow(WordRowParameters rowParameters);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using GarmentFactoryContracts.ViewModels;
|
||||
using GarmentFactoryBusinessLogic.OfficePackage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -7,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordInfo
|
||||
public class WordInfo : IDocumentInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
@ -0,0 +1,15 @@
|
||||
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordRowParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
public WordTextProperties TextProperties { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using GarmentFactoryContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordShopInfo : IDocumentInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ShopViewModel> Shops { get; set; } = new();
|
||||
}
|
||||
}
|
14
GarmentFactoryBusinessLogic/OfficePackage/IDocument.cs
Normal file
14
GarmentFactoryBusinessLogic/OfficePackage/IDocument.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryBusinessLogic.OfficePackage
|
||||
{
|
||||
public interface IDocumentInfo
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string Title { get; set; }
|
||||
}
|
||||
}
|
@ -85,7 +85,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected override void CreateWord(WordInfo info)
|
||||
protected override void CreateWord(IDocumentInfo info)
|
||||
{
|
||||
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
@ -123,7 +123,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements
|
||||
_docBody.AppendChild(docParagraph);
|
||||
}
|
||||
|
||||
protected override void SaveWord(WordInfo info)
|
||||
protected override void SaveWord(IDocumentInfo info)
|
||||
{
|
||||
if (_docBody == null || _wordDocument == null)
|
||||
{
|
||||
@ -135,5 +135,77 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements
|
||||
|
||||
_wordDocument.Close();
|
||||
}
|
||||
|
||||
private Table? _lastTable;
|
||||
protected override void CreateTable(List<string> columns)
|
||||
{
|
||||
if (_docBody == null)
|
||||
return;
|
||||
|
||||
_lastTable = new Table();
|
||||
|
||||
var tableProp = new TableProperties();
|
||||
tableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed });
|
||||
tableProp.AppendChild(new TableBorders(
|
||||
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 }
|
||||
));
|
||||
tableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto });
|
||||
_lastTable.AppendChild(tableProp);
|
||||
|
||||
TableGrid tableGrid = new TableGrid();
|
||||
foreach (var column in columns)
|
||||
{
|
||||
tableGrid.AppendChild(new GridColumn() { Width = column });
|
||||
}
|
||||
_lastTable.AppendChild(tableGrid);
|
||||
|
||||
_docBody.AppendChild(_lastTable);
|
||||
}
|
||||
|
||||
protected override void CreateRow(WordRowParameters rowParameters)
|
||||
{
|
||||
if (_docBody == null || _lastTable == null)
|
||||
return;
|
||||
|
||||
TableRow docRow = new TableRow();
|
||||
foreach (var column in rowParameters.Texts)
|
||||
{
|
||||
var docParagraph = new Paragraph();
|
||||
WordParagraph paragraph = new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (column, rowParameters.TextProperties) },
|
||||
TextProperties = rowParameters.TextProperties
|
||||
};
|
||||
|
||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
||||
|
||||
foreach (var run in paragraph.Texts)
|
||||
{
|
||||
var docRun = new Run();
|
||||
|
||||
var properties = new RunProperties();
|
||||
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
||||
if (run.Item2.Bold)
|
||||
{
|
||||
properties.AppendChild(new Bold());
|
||||
}
|
||||
docRun.AppendChild(properties);
|
||||
|
||||
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
|
||||
|
||||
docParagraph.AppendChild(docRun);
|
||||
}
|
||||
|
||||
TableCell docCell = new TableCell();
|
||||
docCell.AppendChild(docParagraph);
|
||||
docRow.AppendChild(docCell);
|
||||
}
|
||||
_lastTable.AppendChild(docRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,5 +20,9 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts
|
||||
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
|
||||
void SaveShopsToWordFile(ReportBindingModel model);
|
||||
//void SaveShopsToExcelFile(ReportBindingModel model);
|
||||
//void SaveGroupedOrdersToPdfFile(ReportBindingModel model);
|
||||
|
||||
}
|
||||
}
|
||||
|
15
GarmentFactoryContracts/ViewModels/ReportShopsViewModel.cs
Normal file
15
GarmentFactoryContracts/ViewModels/ReportShopsViewModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GarmentFactoryContracts.ViewModels
|
||||
{
|
||||
public class ReportShopsViewModel
|
||||
{
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
public int TotalCount { get; set; }
|
||||
public List<(string textile, int count)> Textiles { get; set; } = new();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user