Eliseev E.E. LabWork04_Hard #9
@ -0,0 +1,101 @@
|
||||
using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums;
|
||||
using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlacksmithWorkshopBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToExcel
|
||||
{
|
||||
//Создание отчета. Описание методов ниже
|
||||
public void CreateReport(ExcelInfo info)
|
||||
{
|
||||
CreateExcel(info);
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = 1,
|
||||
Text = info.Title,
|
||||
StyleInfo = ExcelStyleInfoType.Title
|
||||
});
|
||||
|
||||
MergeCells(new ExcelMergeParameters
|
||||
{
|
||||
CellFromName = "A1",
|
||||
CellToName = "C1"
|
||||
});
|
||||
|
||||
uint rowIndex = 2;
|
||||
|
||||
foreach (var mwp in info.ManufactureWorkPieces)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = mwp.WorkPieceName,
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
|
||||
foreach (var (Manufacure, Count) in mwp.Manufactures)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = Manufacure,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = Count.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = "Итого",
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = mwp.TotalCount.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
SaveExcel(info);
|
||||
}
|
||||
|
||||
//Создание excel-файла
|
||||
protected abstract void CreateExcel(ExcelInfo info);
|
||||
|
||||
//Добавляем новую ячейку в лист
|
||||
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
|
||||
|
||||
//Объединение ячеек
|
||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||
|
||||
//Сохранение файла
|
||||
protected abstract void SaveExcel(ExcelInfo info);
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums;
|
||||
using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlacksmithWorkshopBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToPdf
|
||||
{
|
||||
//публичный метод создания документа. Описание методов ниже
|
||||
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", "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.ManufactureName, order.Sum.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right
|
||||
});
|
||||
|
||||
SavePdf(info);
|
||||
}
|
||||
|
||||
/// Создание doc-файла
|
||||
protected abstract void CreatePdf(PdfInfo info);
|
||||
|
||||
/// Создание параграфа с текстом
|
||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||
|
||||
/// Создание таблицы
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
|
||||
/// Создание и заполнение строки
|
||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||
|
||||
/// Сохранение файла
|
||||
protected abstract void SavePdf(PdfInfo info);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums;
|
||||
using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlacksmithWorkshopBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToWord
|
||||
{
|
||||
//метод создания документа
|
||||
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 workPiece in info.WorkPieces)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (workPiece.WorkPieceName, new WordTextProperties { Size = "24", }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SaveWord(info);
|
||||
}
|
||||
|
||||
// Создание doc-файла
|
||||
protected abstract void CreateWord(WordInfo info);
|
||||
|
||||
// Создание абзаца с текстом
|
||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||
|
||||
// Сохранение файла
|
||||
protected abstract void SaveWord(WordInfo info);
|
||||
|
||||
}
|
||||
}
|
@ -16,6 +16,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums
|
||||
Text,
|
||||
|
||||
//текст в рамке
|
||||
TixtWithBorder
|
||||
TextWithBroder
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
//вспомогательное перечисление для оформления pdf документа
|
||||
public enum PdfParagraphAligmentType
|
||||
public enum PdfParagraphAlignmentType
|
||||
{
|
||||
//либо по центру
|
||||
Center,
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
//информация для объединения ячеек
|
||||
public class ExcelMergeParametrs
|
||||
public class ExcelMergeParameters
|
||||
{
|
||||
public string CellFromName { get; set; } = string.Empty;
|
||||
|
@ -15,6 +15,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
public string Style { get; set; } = string.Empty;
|
||||
|
||||
//информация по выравниванию текста в параграфе
|
||||
public PdfParagraphAligmentType ParagraphAligment { get; set; }
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
//информация по параметрам строк таблицы
|
||||
public class PdfRowParametrs
|
||||
public class PdfRowParameters
|
||||
{
|
||||
//набор текстов
|
||||
public List<string> Texts { get; set; } = new();
|
||||
@ -17,6 +17,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
public string Style { get; set; } = string.Empty;
|
||||
|
||||
//как выравниваем
|
||||
public PdfParagraphAligmentType ParagraphAligment { get; set; }
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels
|
||||
public class WordParagraph
|
||||
{
|
||||
//набор текстов в абзаце (для случая, если в абзаце текст разных стилей)
|
||||
public List<(string, WordParagraph)> Texts { get; set; } = new();
|
||||
public List<(string, WordTextProperties)> Texts { get; set; } = new();
|
||||
|
||||
//свойства параграфа, если они есть
|
||||
public WordTextProperties? TextProperties { get; set; }
|
||||
|
Loading…
Reference in New Issue
Block a user