в процессе
This commit is contained in:
parent
d0cf79c5fd
commit
e407466cb1
@ -168,17 +168,16 @@ namespace JewelryStore
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStores));
|
||||
private void BusyShopsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportShop));
|
||||
if (service is FormReportShop form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
if (service is FormStores form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment));
|
||||
|
||||
@ -187,5 +186,32 @@ namespace JewelryStore
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_reportLogic.SavePizzasToWordFile(new ReportBindingModel { FileName = dialog.FileName });
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
private void InfoToolStripMenuItem_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 GroupOrdersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders));
|
||||
if (service is FormReportGroupedOrders form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JewelryStoreContracts.StoragesModels;
|
||||
|
||||
namespace JewelryStoreBusinessLogic.BusinessLogics
|
||||
{
|
||||
@ -18,23 +19,22 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
private readonly IJewelStorage _jewelStorage;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
private readonly IStoreStorage _shopStorage;
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
private readonly AbstractSaveToWord _saveToWord;
|
||||
private readonly AbstractSaveToPdf _saveToPdf;
|
||||
public ReportLogic(IJewelStorage jewelStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
|
||||
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||
IStoreStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||
{
|
||||
_jewelStorage = jewelStorage;
|
||||
_componentStorage = componentStorage;
|
||||
_orderStorage = orderStorage;
|
||||
_shopStorage = shopStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToPdf = saveToPdf;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение списка компонент с указанием, в каких изделиях используются
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
public List<ReportJewelComponentViewModel> GetJewelComponent()
|
||||
{
|
||||
return _jewelStorage.GetFullList().Select(x => new ReportJewelComponentViewModel
|
||||
@ -44,11 +44,7 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
|
||||
TotalCount = x.JewelComponents.Select(x => x.Value.Item2).Sum()
|
||||
}).ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение списка заказов за определенный период
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
|
||||
{
|
||||
return _orderStorage.GetFilteredList(new OrderSearchModel
|
||||
@ -65,10 +61,7 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
|
||||
|
||||
}).ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение компонент в файл-Word
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
|
||||
public void SaveJewelsToWordFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToWord.CreateDoc(new WordInfo
|
||||
@ -78,23 +71,17 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
|
||||
Jewels = _jewelStorage.GetFullList()
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
|
||||
public void SaveJewelComponentToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToExcel.CreateReport(new ExcelInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список компонент",
|
||||
Title = "Список компонентов",
|
||||
JewelComponents = GetJewelComponent()
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение заказов в файл-Pdf
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
|
||||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToPdf.CreateDoc(new PdfInfo
|
||||
@ -106,5 +93,54 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
|
||||
Orders = GetOrders(model)
|
||||
});
|
||||
}
|
||||
}
|
||||
public List<ReportShopsViewModel> GetShops()
|
||||
{
|
||||
return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel
|
||||
{
|
||||
ShopName = x.ShopName,
|
||||
Pizzas = x.ShopPizzas.Select(x => (x.Value.Item1.PizzaName, x.Value.Item2)).ToList(),
|
||||
TotalCount = x.ShopPizzas.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.CreateShopPizzasReport(new ExcelShop
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Наполненость магазинов",
|
||||
ShopPizzas = GetShops()
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveGroupedOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список заказов сгруппированных по дате заказов",
|
||||
GroupedOrders = GetGroupedOrders()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,26 +77,14 @@ namespace JewelryStoreBusinessLogic.OfficePackage
|
||||
}
|
||||
SaveExcel(info);
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание excel-файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
|
||||
protected abstract void CreateExcel(ExcelInfo info);
|
||||
/// <summary>
|
||||
/// Добавляем новую ячейку в лист
|
||||
/// </summary>
|
||||
/// <param name="cellParameters"></param>
|
||||
|
||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters
|
||||
excelParams);
|
||||
/// <summary>
|
||||
/// Объединение ячеек
|
||||
/// </summary>
|
||||
/// <param name="mergeParameters"></param>
|
||||
|
||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||
/// <summary>
|
||||
/// Сохранение файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
|
||||
protected abstract void SaveExcel(ExcelInfo info);
|
||||
}
|
||||
|
||||
|
@ -12,69 +12,66 @@ namespace JewelryStoreBusinessLogic.OfficePackage
|
||||
{
|
||||
public void CreateDoc(PdfInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = info.Title,
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"с { info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
CreateTable(new List<string> { "2cm", "3cm", "6cm", "4cm", "3cm" });
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Номер", "Дата заказа", "Изделие", "Статус", "Сумма" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
foreach (var order in info.Orders)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.JewelName, order.Status.ToString(), order.Sum.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t",
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Rigth
|
||||
});
|
||||
SavePdf(info);
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание doc-файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void CreatePdf(PdfInfo info);
|
||||
/// <summary>
|
||||
/// Создание параграфа с текстом
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="style"></param>
|
||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||
/// <summary>
|
||||
/// Создание таблицы
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="style"></param>
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
/// <summary>
|
||||
/// Создание и заполнение строки
|
||||
/// </summary>
|
||||
/// <param name="rowParameters"></param>
|
||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||
/// <summary>
|
||||
/// Сохранение файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void SavePdf(PdfInfo info);
|
||||
}
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
|
||||
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Номер", "Дата заказа", "Пицца", "Статус", "Сумма" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
|
||||
foreach (var order in info.Orders)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.PizzaName, order.Status.ToString(), order.Sum.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth });
|
||||
|
||||
SavePdf(info);
|
||||
}
|
||||
|
||||
public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
CreateTable(new List<string> { "4cm", "3cm", "2cm" });
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Дата заказа", "Кол-во", "Сумма" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
|
||||
|
||||
foreach (var groupedOrder in info.GroupedOrders)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { groupedOrder.Date.ToShortDateString(), groupedOrder.OrdersCount.ToString(), groupedOrder.OrdersSum.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
|
||||
CreateParagraph(new PdfParagraph { Text = $"Итого: {info.GroupedOrders.Sum(x => x.OrdersSum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
SavePdf(info);
|
||||
}
|
||||
|
||||
protected abstract void CreatePdf(IDocument info);
|
||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||
protected abstract void SavePdf(IDocument info);
|
||||
}
|
||||
}
|
||||
|
@ -12,48 +12,82 @@ namespace JewelryStoreBusinessLogic.OfficePackage
|
||||
{
|
||||
public void CreateDoc(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
|
||||
}
|
||||
});
|
||||
foreach (var jewel in info.Jewels)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> {
|
||||
(jewel.JewelName, new WordTextProperties { Size = "24", Bold = true}), ("\t"+jewel.Price.ToString(), new WordTextProperties{Size = "24"})
|
||||
},
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
SaveWord(info);
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание doc-файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void CreateWord(WordInfo info);
|
||||
/// <summary>
|
||||
/// Создание абзаца с текстом
|
||||
/// </summary>
|
||||
/// <param name="paragraph"></param>
|
||||
/// <returns></returns>
|
||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||
/// <summary>
|
||||
/// Сохранение файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void SaveWord(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
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var pizza in info.Jewels)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> {
|
||||
(pizza.JewelName, new WordTextProperties { Size = "24", Bold = true}),
|
||||
("\t"+pizza.Price.ToString(), new WordTextProperties{Size = "24"})
|
||||
},
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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.Adress, shop.OpeningDate.ToString() },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "22",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SaveWord(info);
|
||||
}
|
||||
|
||||
protected abstract void CreateWord(IDocument info);
|
||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||
protected abstract void SaveWord(IDocument info);
|
||||
protected abstract void CreateTable(List<string> colums);
|
||||
protected abstract void CreateRow(WordRowParameters rowParameters);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class ExcelShop : IDocument
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<ReportShopsViewModel> ShopPizzas { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using JewelryStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfGroupedOrdersInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public List<ReportGroupOrdersViewModel> GroupedOrders { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using JewelryStoreContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class WordShopInfo : IDocument
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public List<StoreViewModel> Shops { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JewelryStoreBusinessLogic.OfficePackage
|
||||
{
|
||||
public interface IDocument
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string Title { get; set; }
|
||||
}
|
||||
}
|
@ -19,10 +19,7 @@ namespace JewelryStoreBusinessLogic.OfficePackage.Implements
|
||||
private SpreadsheetDocument? _spreadsheetDocument;
|
||||
private SharedStringTablePart? _shareStringPart;
|
||||
private Worksheet? _worksheet;
|
||||
/// <summary>
|
||||
/// Настройка стилей для файла
|
||||
/// </summary>
|
||||
/// <param name="workbookpart"></param>
|
||||
|
||||
private static void CreateStyles(WorkbookPart workbookpart)
|
||||
{
|
||||
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
||||
|
@ -16,90 +16,97 @@ namespace JewelryStoreBusinessLogic.OfficePackage.Implements
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private Table? _table;
|
||||
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||
PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify,
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание стилей для документа
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
private static void DefineStyles(Document document)
|
||||
{
|
||||
var style = document.Styles["Normal"];
|
||||
style.Font.Name = "Times New Roman";
|
||||
style.Font.Size = 14;
|
||||
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
||||
style.Font.Bold = true;
|
||||
}
|
||||
protected override void CreatePdf(PdfInfo info)
|
||||
{
|
||||
_document = new Document();
|
||||
DefineStyles(_document);
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
protected override void CreateParagraph(PdfParagraph pdfParagraph)
|
||||
{
|
||||
if (_section == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var paragraph = _section.AddParagraph(pdfParagraph.Text);
|
||||
paragraph.Format.SpaceAfter = "1cm";
|
||||
paragraph.Format.Alignment =
|
||||
GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
|
||||
paragraph.Style = pdfParagraph.Style;
|
||||
}
|
||||
protected override void CreateTable(List<string> columns)
|
||||
{
|
||||
if (_document == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_table = _document.LastSection.AddTable();
|
||||
foreach (var elem in columns)
|
||||
{
|
||||
_table.AddColumn(elem);
|
||||
}
|
||||
}
|
||||
protected override void CreateRow(PdfRowParameters rowParameters)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var row = _table.AddRow();
|
||||
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
||||
{
|
||||
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
|
||||
if (!string.IsNullOrEmpty(rowParameters.Style))
|
||||
{
|
||||
row.Cells[i].Style = rowParameters.Style;
|
||||
}
|
||||
Unit borderWidth = 0.5;
|
||||
row.Cells[i].Borders.Left.Width = borderWidth;
|
||||
row.Cells[i].Borders.Right.Width = borderWidth;
|
||||
row.Cells[i].Borders.Top.Width = borderWidth;
|
||||
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||
row.Cells[i].Format.Alignment =
|
||||
GetParagraphAlignment(rowParameters.ParagraphAlignment);
|
||||
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
}
|
||||
protected override void SavePdf(PdfInfo info)
|
||||
{
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
}
|
||||
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||
PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify,
|
||||
};
|
||||
}
|
||||
|
||||
private static void DefineStyles(Document document)
|
||||
{
|
||||
var style = document.Styles["Normal"];
|
||||
style.Font.Name = "Times New Roman";
|
||||
style.Font.Size = 14;
|
||||
|
||||
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
||||
style.Font.Bold = true;
|
||||
}
|
||||
|
||||
protected override void CreatePdf(IDocument info)
|
||||
{
|
||||
_document = new Document();
|
||||
DefineStyles(_document);
|
||||
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
|
||||
protected override void CreateParagraph(PdfParagraph pdfParagraph)
|
||||
{
|
||||
if (_section == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var paragraph = _section.AddParagraph(pdfParagraph.Text);
|
||||
paragraph.Format.SpaceAfter = "1cm";
|
||||
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
|
||||
paragraph.Style = pdfParagraph.Style;
|
||||
}
|
||||
|
||||
protected override void CreateTable(List<string> columns)
|
||||
{
|
||||
if (_document == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_table = _document.LastSection.AddTable();
|
||||
|
||||
foreach (var elem in columns)
|
||||
{
|
||||
_table.AddColumn(elem);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CreateRow(PdfRowParameters rowParameters)
|
||||
{
|
||||
if (_table == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var row = _table.AddRow();
|
||||
for (int i = 0; i < rowParameters.Texts.Count; ++i)
|
||||
{
|
||||
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
|
||||
|
||||
if (!string.IsNullOrEmpty(rowParameters.Style))
|
||||
{
|
||||
row.Cells[i].Style = rowParameters.Style;
|
||||
}
|
||||
|
||||
Unit borderWidth = 0.5;
|
||||
|
||||
row.Cells[i].Borders.Left.Width = borderWidth;
|
||||
row.Cells[i].Borders.Right.Width = borderWidth;
|
||||
row.Cells[i].Borders.Top.Width = borderWidth;
|
||||
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||
|
||||
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
|
||||
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SavePdf(IDocument info)
|
||||
{
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,115 +15,183 @@ namespace JewelryStoreBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
private WordprocessingDocument? _wordDocument;
|
||||
private Body? _docBody;
|
||||
/// <summary>
|
||||
/// Получение типа выравнивания
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
private static JustificationValues
|
||||
GetJustificationValues(WordJustificationType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
WordJustificationType.Both => JustificationValues.Both,
|
||||
WordJustificationType.Center => JustificationValues.Center,
|
||||
_ => JustificationValues.Left,
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// Настройки страницы
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static SectionProperties CreateSectionProperties()
|
||||
{
|
||||
var properties = new SectionProperties();
|
||||
var pageSize = new PageSize
|
||||
{
|
||||
Orient = PageOrientationValues.Portrait
|
||||
};
|
||||
properties.AppendChild(pageSize);
|
||||
return properties;
|
||||
}
|
||||
/// <summary>
|
||||
/// Задание форматирования для абзаца
|
||||
/// </summary>
|
||||
/// <param name="paragraphProperties"></param>
|
||||
/// <returns></returns>
|
||||
private static ParagraphProperties?
|
||||
CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||
{
|
||||
if (paragraphProperties == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var properties = new ParagraphProperties();
|
||||
properties.AppendChild(new Justification()
|
||||
{
|
||||
Val =
|
||||
GetJustificationValues(paragraphProperties.JustificationType)
|
||||
});
|
||||
properties.AppendChild(new SpacingBetweenLines
|
||||
{
|
||||
LineRule = LineSpacingRuleValues.Auto
|
||||
});
|
||||
properties.AppendChild(new Indentation());
|
||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||
{
|
||||
paragraphMarkRunProperties.AppendChild(new FontSize
|
||||
{
|
||||
Val = paragraphProperties.Size
|
||||
});
|
||||
}
|
||||
properties.AppendChild(paragraphMarkRunProperties);
|
||||
return properties;
|
||||
}
|
||||
protected override void CreateWord(WordInfo info)
|
||||
{
|
||||
_wordDocument = WordprocessingDocument.Create(info.FileName,
|
||||
WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = new Document();
|
||||
_docBody = mainPart.Document.AppendChild(new Body());
|
||||
}
|
||||
protected override void CreateParagraph(WordParagraph paragraph)
|
||||
{
|
||||
if (_docBody == null || paragraph == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var docParagraph = new Paragraph();
|
||||
|
||||
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);
|
||||
}
|
||||
_docBody.AppendChild(docParagraph);
|
||||
}
|
||||
protected override void SaveWord(WordInfo info)
|
||||
{
|
||||
if (_docBody == null || _wordDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_docBody.AppendChild(CreateSectionProperties());
|
||||
_wordDocument.MainDocumentPart!.Document.Save();
|
||||
_wordDocument.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
WordJustificationType.Both => JustificationValues.Both,
|
||||
WordJustificationType.Center => JustificationValues.Center,
|
||||
_ => JustificationValues.Left,
|
||||
};
|
||||
}
|
||||
|
||||
private static SectionProperties CreateSectionProperties()
|
||||
{
|
||||
var properties = new SectionProperties();
|
||||
|
||||
var pageSize = new PageSize
|
||||
{
|
||||
Orient = PageOrientationValues.Portrait
|
||||
};
|
||||
|
||||
properties.AppendChild(pageSize);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||
{
|
||||
if (paragraphProperties == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var properties = new ParagraphProperties();
|
||||
|
||||
properties.AppendChild(new Justification()
|
||||
{
|
||||
Val = GetJustificationValues(paragraphProperties.JustificationType)
|
||||
});
|
||||
|
||||
properties.AppendChild(new SpacingBetweenLines
|
||||
{
|
||||
LineRule = LineSpacingRuleValues.Auto
|
||||
});
|
||||
|
||||
properties.AppendChild(new Indentation());
|
||||
|
||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||
{
|
||||
paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size });
|
||||
}
|
||||
properties.AppendChild(paragraphMarkRunProperties);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected override void CreateWord(IDocument info)
|
||||
{
|
||||
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||
mainPart.Document = new Document();
|
||||
_docBody = mainPart.Document.AppendChild(new Body());
|
||||
}
|
||||
|
||||
protected override void CreateParagraph(WordParagraph paragraph)
|
||||
{
|
||||
if (_docBody == null || paragraph == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var docParagraph = new Paragraph();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
_docBody.AppendChild(docParagraph);
|
||||
}
|
||||
|
||||
protected override void SaveWord(IDocument info)
|
||||
{
|
||||
if (_docBody == null || _wordDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_docBody.AppendChild(CreateSectionProperties());
|
||||
|
||||
_wordDocument.MainDocumentPart!.Document.Save();
|
||||
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
@ -10,32 +10,16 @@ namespace JewelryStoreContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IReportLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение списка компонент с указанием, в каких изделиях используются
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<ReportJewelComponentViewModel> GetJewelComponent();
|
||||
/// <summary>
|
||||
/// Получение списка заказов за определенный период
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение изделий в файл-Word
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void SaveJewelsToWordFile(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void SaveJewelComponentToExcelFile(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение заказов в файл-Pdf
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
List<ReportJewelComponentViewModel> GetPizzaComponents();
|
||||
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
|
||||
List<ReportShopsViewModel> GetShops();
|
||||
List<ReportGroupOrdersViewModel> GetGroupedOrders();
|
||||
void SavePizzasToWordFile(ReportBindingModel model);
|
||||
void SavePizzaComponentToExcelFile(ReportBindingModel model);
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
void SaveShopsToWordFile(ReportBindingModel model);
|
||||
void SaveShopsToExcelFile(ReportBindingModel model);
|
||||
void SaveGroupedOrdersToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JewelryStoreContracts.ViewModels
|
||||
{
|
||||
public class ReportShopsViewModel
|
||||
{
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
public int TotalCount { get; set; }
|
||||
public List<(string Jewel, int count)> Pizzas { get; set; } = new();
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ namespace JewelryStoreDatabaseImplement.Implements
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
|
||||
if (!model.DateFrom.HasValue || !model.DateTo.HasValue ||!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user