diff --git a/LawFim/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs b/LawFim/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs index 4ed7d5a..3f08b3e 100644 --- a/LawFim/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/LawFim/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs @@ -25,6 +25,8 @@ namespace LawFirmBusinessLogic.BusinessLogics private readonly AbstractSaveToWordVisitsLawyer _saveToWordVisitLawyer; private readonly AbstractSaveToPdfConsultationHearing _saveToPdfConsultationHearing; + private readonly AbstractSaveToPdfClientCaseHearing _saveToPdfClientCaseHearing; + public ReportLogic(IClientStorage clientStorage, IHearingStorage hearingStorage, IVisitStorage visitStorage, ICaseStorage caseStorage, ILawyerStorage lawyerStorage, IConsultationStorage consultationStorage, @@ -241,6 +243,45 @@ namespace LawFirmBusinessLogic.BusinessLogics return list; } + public List GetCaseHearing(ReportClientCaseHearingBindingModel model) + { + var list = new List(); + var clients = _clientStorage.GetFilteredList(new ClientSearchModel { ExecutorId = model.ExecutorId }); + var cases = _caseStorage.GetFilteredList(new CaseSearchModel { ExecutorId = model.ExecutorId, DateFrom = model.DateFrom }); + var hearings = _hearingStorage.GetFilteredList(new HearingSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }); + var visits = _visitStorage.GetFilteredList(new VisitSearchModel { ExecutorId = model.ExecutorId }); + foreach (ClientViewModel client in clients) + { + var record = new ReportClientCaseHearingViewModel + { + ClientName = client.FIO + }; + + foreach (var cas in cases) + { + if (cas.CaseClients.ContainsKey(client.Id)) + { + record.Case.Add(new(cas.DateCreate, cas.Name)); + } + } + foreach (var visit in visits) + { + if (visit.VisitClients.ContainsKey(client.Id)) + { + foreach (var hear in hearings) + { + if (visit.HearingId.Equals(hear.Id)) + { + record.Hearing.Add(new(hear.HearingDate, hear.Judge)); + } + } + } + } + list.Add(record); + } + return list; + } + public void SaveClientsConsultationToExcelFile(ReportBindingModel model) { _saveToExcelClientsConsultation.CreateReport(new ExcelClientsConsultationInfo @@ -305,5 +346,17 @@ namespace LawFirmBusinessLogic.BusinessLogics }); } + + public void SaveClientCaseHearingToPdfFile(ReportClientCaseHearingBindingModel model) + { + _saveToPdfClientCaseHearing.CreateDoc(new PDFClientCaseHearingInfo + { + FileName = model.FileName, + Title = "Отчёт по клиентам по делам и консультациям", + DateFrom = model.DateFrom, + DateTo = model.DateTo, + ClientCaseHearing = GetCaseHearing(model) + }); + } } } diff --git a/LawFim/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs b/LawFim/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs index 67c3356..53bd6e6 100644 --- a/LawFim/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs +++ b/LawFim/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs @@ -25,7 +25,7 @@ namespace LawFirmBusinessLogic.MailWorker objMailMessage.Body = info.Text; objMailMessage.SubjectEncoding = Encoding.UTF8; objMailMessage.BodyEncoding = Encoding.UTF8; - Attachment attachment = new Attachment("C:\\ReportsCourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf)); + Attachment attachment = new Attachment("E:\\reports\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf)); objMailMessage.Attachments.Add(attachment); objSmtpClient.UseDefaultCredentials = false; diff --git a/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClientCaseHearing.cs b/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClientCaseHearing.cs new file mode 100644 index 0000000..ac192aa --- /dev/null +++ b/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClientCaseHearing.cs @@ -0,0 +1,120 @@ +using LawFirmBusinessLogic.OfficePackages.HelperEnums; +using LawFirmBusinessLogic.OfficePackages.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackages +{ + public abstract class AbstractSaveToPdfClientCaseHearing + { + public void CreateDoc(PDFClientCaseHearingInfo 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 { "3cm", "5cm", "5cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Клиент", "Дело", "Дата начала дела" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var ch in info.ClientCaseHearing) + { + CreateRow(new PdfRowParameters + { + Texts = new List { ch.ClientName, " ", " " }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + + }); + foreach (var cas in ch.Case) + CreateRow(new PdfRowParameters + { + Texts = new List { " ", cas.CaseName, cas.CaseDate.ToShortDateString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateRow(new PdfRowParameters + { + Texts = new List { " ", " ", "Итого: " + ch.Case.Count.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Rigth + }); + } + + CreateTable(new List { "3cm", "5cm", "5cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Клиент", "Суд", "Дата слушания" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var ch in info.ClientCaseHearing) + { + CreateRow(new PdfRowParameters + { + Texts = new List { ch.ClientName, " ", " " }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + + }); + foreach (var hear in ch.Hearing) + CreateRow(new PdfRowParameters + { + Texts = new List { " ", hear.Judge, hear.HearingDate.ToShortDateString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + CreateRow(new PdfRowParameters + { + Texts = new List { " ", " ", "Итого: " + ch.Hearing.Count.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Rigth + }); + } + SavePdf(info); + } + /// + /// Создание doc-файла + /// + /// + protected abstract void CreatePdf(PDFClientCaseHearingInfo info); + /// + /// Создание параграфа с текстом + /// + /// + /// + protected abstract void CreateParagraph(PdfParagraph paragraph); + /// + /// Создание таблицы + /// + /// + /// + protected abstract void CreateTable(List columns); + /// + /// Создание и заполнение строки + /// + /// + protected abstract void CreateRow(PdfRowParameters rowParameters); + /// + /// Сохранение файла + /// + /// + protected abstract void SavePdf(PDFClientCaseHearingInfo info); + } +} diff --git a/LawFim/LawFirmBusinessLogic/OfficePackages/HelperModels/PDFClientCaseHearingInfo.cs b/LawFim/LawFirmBusinessLogic/OfficePackages/HelperModels/PDFClientCaseHearingInfo.cs new file mode 100644 index 0000000..8d52080 --- /dev/null +++ b/LawFim/LawFirmBusinessLogic/OfficePackages/HelperModels/PDFClientCaseHearingInfo.cs @@ -0,0 +1,18 @@ +using LawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackages.HelperModels +{ + public class PDFClientCaseHearingInfo + { + 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 ClientCaseHearing { get; set; } = new(); + } +} diff --git a/LawFim/LawFirmBusinessLogic/OfficePackages/Implements/SaveToPdfClientCaseHearing.cs b/LawFim/LawFirmBusinessLogic/OfficePackages/Implements/SaveToPdfClientCaseHearing.cs new file mode 100644 index 0000000..567d633 --- /dev/null +++ b/LawFim/LawFirmBusinessLogic/OfficePackages/Implements/SaveToPdfClientCaseHearing.cs @@ -0,0 +1,101 @@ +using LawFirmBusinessLogic.OfficePackages.HelperEnums; +using LawFirmBusinessLogic.OfficePackages.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.Rendering; +using VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment; + +namespace LawFirmBusinessLogic.OfficePackages.Implements +{ + public class SaveToPdfClientCaseHearing : AbstractSaveToPdfClientCaseHearing + { + private Document? _document; + private Section? _section; + private MigraDoc.DocumentObjectModel.Tables.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, + }; + } + /// + /// Создание стилей для документа + /// + /// + 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(PDFClientCaseHearingInfo 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 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(PDFClientCaseHearingInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } +} diff --git a/LawFim/LawFirmContracts/BindingModels/ReportClientCaseHearingModel.cs b/LawFim/LawFirmContracts/BindingModels/ReportClientCaseHearingModel.cs new file mode 100644 index 0000000..9dcbd5f --- /dev/null +++ b/LawFim/LawFirmContracts/BindingModels/ReportClientCaseHearingModel.cs @@ -0,0 +1,11 @@ +namespace LawFirmContracts.BindingModels +{ + public class ReportClientCaseHearingBindingModel + { + public string FileName { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } = DateTime.Now; + public DateTime DateTo { get; set; } = DateTime.Now; + public int? ExecutorId { get; set; } + public string? Email { get; set; } + } +} diff --git a/LawFim/LawFirmContracts/ViewModels/ReportClientCaseHearingViewModel.cs b/LawFim/LawFirmContracts/ViewModels/ReportClientCaseHearingViewModel.cs new file mode 100644 index 0000000..3fa5931 --- /dev/null +++ b/LawFim/LawFirmContracts/ViewModels/ReportClientCaseHearingViewModel.cs @@ -0,0 +1,9 @@ +namespace LawFirmContracts.ViewModels +{ + public class ReportClientCaseHearingViewModel + { + public string ClientName { get; set; } = string.Empty; + public List<(DateTime CaseDate, string CaseName)> Case { get; set; } = new(); + public List<(DateTime HearingDate, string Judge)> Hearing { get; set; } = new(); + } +}