Создание отчетов

This commit is contained in:
Дарья Антонова 2023-04-08 23:14:49 +04:00
parent 7c3ca5ab34
commit e08ecb0fc7
4 changed files with 338 additions and 1 deletions

View File

@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicBusinessLogic.BusinessLogic.OfficePackage.Enums;
using VetClinicBusinessLogic.BusinessLogic.OfficePackage.Models;
namespace VetClinicBusinessLogic.BusinessLogic.OfficePackage
{
public abstract class ReportToExcel
{
public void CreateReportVisitService(ExcelInfoVisitService 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 pc in info.VisitServices)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.VisitDate.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var Component in pc.Services)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = Component,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = pc.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel(info);
}
public void CreateReportServiceVisit(ExcelInfoServiceVisit 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 pc in info.VisitServices)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.Name.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var Component in pc.Visits)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = Component.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = pc.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel(info);
}
/// <summary>
/// Создание excel-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateExcel(ExcelInfoVisitService 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(ExcelInfoVisitService info);
protected abstract void SaveExcel(ExcelInfoServiceVisit info);
protected abstract void CreateExcel(ExcelInfoServiceVisit info);
}
}

View File

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicBusinessLogic.BusinessLogic.OfficePackage.Enums;
using VetClinicBusinessLogic.BusinessLogic.OfficePackage.Models;
namespace VetClinicBusinessLogic.BusinessLogic.OfficePackage
{
public abstract class ReportToPdf
{
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle"
});
CreateParagraph(new PdfParagraph
{
Text = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
Style = "Normal"
});
CreateTable(new List<string> { "6cm", "6cm", "6cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Дата визита", "Сумма", "Имя клиента", },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var order in info.Visits)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { order.DateCreate.ToShortDateString(),order.Sum.ToString(), order.ClientName
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
SavePdf(info);
}
public void CreateDocService(PdfInfoService info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle"
});
CreateParagraph(new PdfParagraph
{
Text = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
Style = "Normal"
});
CreateTable(new List<string> { "8cm", "8cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Услуга", "Количество" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var order in info.Services.Services)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { order.Key,order.Value.ToString()
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph
{
Text = $"Оплачено за период: {info.Services.Sum}",
Style = "Normal"
});
SavePdf(info);
}
protected abstract void CreatePdf(PdfInfo info);
protected abstract void CreatePdf(PdfInfoService 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);
protected abstract void SavePdf(PdfInfoService info);
}
}

View File

@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicBusinessLogic.BusinessLogic.OfficePackage.Enums;
using VetClinicBusinessLogic.BusinessLogic.OfficePackage.Models;
namespace VetClinicBusinessLogic.BusinessLogic.OfficePackage
{
public abstract class ReportToWord
{
public void CreateDocVisitService(WordInfoVisitService 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 computer in info.VisitServices)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(computer.VisitDate + ": ", new WordTextProperties {
Size = "24",
Bold = true
})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
for (int i = 0; i < computer.Services.Count; i++)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(" "+(i+1)+")"+computer.Services[i], new WordTextProperties {
Size = "24",
Bold = true
})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
}
SaveWord(info);
}
public void CreateDocServiceVisit(WordInfoServiceVisit 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 computer in info.VisitServices)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(computer.Name + ": ", new WordTextProperties {
Size = "24",
Bold = true
})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
for (int i = 0; i < computer.Visits.Count; i++)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(" "+(i+1)+")"+computer.Visits[i], new WordTextProperties {
Size = "24",
Bold = true
})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
}
SaveWord(info);
}
protected abstract void CreateWord(WordInfoVisitService info);
protected abstract void CreateWord(WordInfoServiceVisit info);
protected abstract void SaveWord(WordInfoVisitService info);
protected abstract void CreateParagraph(WordParagraph paragraph);
protected abstract void SaveWord(WordInfoServiceVisit info);
}
}

View File

@ -1,4 +1,5 @@
using System;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;