diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs index 911b91b..4850fe0 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs @@ -1,4 +1,6 @@ -using CaseAccountingContracts.BindingModels; +using CaseAccountingBusinessLogic.OfficePackage; +using CaseAccountingBusinessLogic.OfficePackage.HelperModels; +using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.SearchModels; using CaseAccountingContracts.StoragesContracts; @@ -17,13 +19,18 @@ namespace CaseAccountingBusinessLogic.BusinessLogics private readonly IHearingStorage _hearingStorage; private readonly ILawyerStorage _lawyerStorage; private readonly ISpecializationStorage _specializationStorage; + private readonly WordBuilderCustomer _wordBuilder; + private readonly ExcelBuilderCustomer _excelBuilder; - public ReportCustomerLogic(ICaseStorage caseStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, ISpecializationStorage specializationStorage) + public ReportCustomerLogic(ICaseStorage caseStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, ISpecializationStorage specializationStorage, + WordBuilderCustomer wordBuilder, ExcelBuilderCustomer excelBuilder) { _caseStorage = caseStorage; _hearingStorage = hearingStorage; _lawyerStorage = lawyerStorage; _specializationStorage = specializationStorage; + _wordBuilder = wordBuilder; + _excelBuilder = excelBuilder; } public List GetHearingSpecialization(ReportBindingModel model) @@ -47,32 +54,26 @@ namespace CaseAccountingBusinessLogic.BusinessLogics public List GetLawyerHearing(List models) { - var lawyers = new List(); - foreach (var model in models) - { - lawyers.Add(_lawyerStorage.GetElement(new LawyerSearchModel { Id = model.Id})); - } - var list = new List(); + throw new NotImplementedException(); + } - foreach(var lawyer in lawyers) + public List GetLawyersHearing(List lawyers) + { + var reportRecords = new List(); + foreach (var lawyer in lawyers) { - var record = new ReportLawyerHearingViewModel + var hearings = _lawyerStorage.GetLawyerCases(new() { Id = lawyer.Id }) + .SelectMany(_case => _caseStorage.GetCaseHearings(new() { Id = _case.Id })) + .Select(hearing => hearing.Information) + .ToList(); + ReportLawyerHearingViewModel reportRecord = new() { - Name = lawyer.Name, - Surname = lawyer.Surname, - Patronymic = lawyer.Patronymic, - Hearings = new List<(DateTime Date, string Information)>() + Lawyer = lawyer.Name + " " + lawyer.Surname + ", " + lawyer.Patronymic, + Hearings = hearings }; - var cases = _caseStorage.GetFullList() - .Where(x => x.Lawyers.ContainsKey(lawyer.Id)); - foreach (var _case in cases) - { - record.Hearings.Add((_hearingStorage.GetElement(new HearingSearchModel { CaseId = _case.Id}).Date, - _hearingStorage.GetElement(new HearingSearchModel { CaseId = _case.Id })?.Information ?? "Не удалось найти информацию.")); - } - list.Add(record); + reportRecords.Add(reportRecord); } - return list; + return reportRecords; } public void SaveHearingSpecializationToPdfFile(ReportBindingModel model) @@ -89,5 +90,28 @@ namespace CaseAccountingBusinessLogic.BusinessLogics { throw new NotImplementedException(); } + + public byte[] SaveListFile(LawyerHearingListBindingModel model) + { + byte[] file = Array.Empty(); + + string title = "Список слушаний по выбранным юристам"; + + if (model.FileType == "docx") + { + _wordBuilder.CreateDocument(); + _wordBuilder.CreateTitle(title); + _wordBuilder.CreateLawyersHearingTable(GetLawyersHearing(model.Lawyers)); + file = _wordBuilder.GetFile(); + } + else if (model.FileType == "xlsx") + { + _excelBuilder.CreateDocument(); + _excelBuilder.CreateTitle(title); + _excelBuilder.CreateLawyersHearingTable(GetLawyersHearing(model.Lawyers)); + file = _excelBuilder.GetFile(); + } + return file; + } } } diff --git a/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj b/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj index 01840d1..d3fd3a1 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj +++ b/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj @@ -13,6 +13,7 @@ + diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs index e29f4a5..d4c3201 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs @@ -5,7 +5,6 @@ using System.Text; using System.Threading.Tasks; using CaseAccountingBusinessLogic.OfficePackage.HelperModels; using CaseAccountingContracts.ViewModels; -using ComputersShopBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; @@ -291,7 +290,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage }); } - public void CreateLawyersHearingsTable(List data) + public void CreateLawyersHearingTable(List data) { if (worksheet == null || shareStringPart == null) { @@ -338,7 +337,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage StyleIndex = 1 }); currentRow++; - foreach (string discipline in student.Disciplines) + foreach (string hearing in lawyer.Hearings) { InsertCellInWorksheet(new ExcelCellData { @@ -351,7 +350,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage { ColumnName = "B", RowIndex = currentRow, - Text = discipline, + Text = hearing, StyleIndex = 1 }); currentRow++; diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelCellParameters.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelCellParameters.cs index 5f2b70a..6303cbb 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelCellParameters.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopBusinessLogic.OfficePackage.HelperModels +namespace CaseAccountingBusinessLogic.OfficePackage.HelperModels { public class ExcelCellParameters { diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelMergeParameters.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelMergeParameters.cs index 067ab3a..3ab91d3 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelMergeParameters.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopBusinessLogic.OfficePackage.HelperModels +namespace CaseAccountingBusinessLogic.OfficePackage.HelperModels { public class ExcelMergeParameters { diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfParagraph.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfParagraph.cs index 3dd00cb..1d4875e 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfParagraph.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfParagraph.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopBusinessLogic.OfficePackage.HelperModels +namespace CaseAccountingBusinessLogic.OfficePackage.HelperModels { public class PdfParagraph { diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfRowParameters.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfRowParameters.cs index 566f870..7b0a0f5 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfRowParameters.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfRowParameters.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopBusinessLogic.OfficePackage.HelperModels +namespace CaseAccountingBusinessLogic.OfficePackage.HelperModels { public class PdfRowParameters { diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/WordParagraph.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/WordParagraph.cs index 6a20259..a061f90 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/WordParagraph.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/WordParagraph.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopBusinessLogic.OfficePackage.HelperModels +namespace CaseAccountingBusinessLogic.OfficePackage.HelperModels { public class WordParagraph { diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/WordTextProperties.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/WordTextProperties.cs index a29117e..422cf48 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/WordTextProperties.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/WordTextProperties.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopBusinessLogic.OfficePackage.HelperModels +namespace CaseAccountingBusinessLogic.OfficePackage.HelperModels { public class WordTextProperties { diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderCustomer.cs new file mode 100644 index 0000000..2054d0f --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderCustomer.cs @@ -0,0 +1,174 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CaseAccountingContracts.ViewModels; + +namespace CaseAccountingBusinessLogic.OfficePackage.HelperModels +{ + public class WordBuilderCustomer + { + private readonly string tempFileName = "temp.docx"; + private WordprocessingDocument? wordDocument; + private Body? documentBody; + + public void CreateDocument() + { + wordDocument = WordprocessingDocument.Create(tempFileName, + WordprocessingDocumentType.Document); + MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + documentBody = mainPart.Document.AppendChild(new Body()); + } + + public void CreateParagraph(string text) + { + if (documentBody == null) + { + return; + } + Paragraph paragraph = new(); + Run run = new(); + run.AppendChild(new Text + { + Text = text + }); + paragraph.AppendChild(run); + documentBody.AppendChild(paragraph); + } + + public void CreateTitle(string text) + { + if (documentBody == null) + { + return; + } + Paragraph paragraph = new(); + Run run = new(); + RunProperties properties = new(); + properties.AppendChild(new Bold()); + run.AppendChild(properties); + run.AppendChild(new Text + { + Text = text + }); + paragraph.AppendChild(run); + documentBody.AppendChild(paragraph); + } + + private TableCell CreateTableCell(string text, bool inHead = false, int? cellWidth = null) + { + Run run = new(); + TableCell tableCell = new(); + TableCellProperties cellProperties = new() + { + TableCellWidth = new() + { + Width = cellWidth.ToString() + }, + TableCellMargin = new() + { + LeftMargin = new() + { + Width = "100" + } + } + }; + if (inHead) + { + Shading shading = new() + { + Color = "auto", + Fill = "e0e8ff", + Val = ShadingPatternValues.Clear + }; + cellProperties.Append(shading); + RunProperties properties = new(); + properties.AppendChild(new Bold()); + run.AppendChild(properties); + } + run.AppendChild(new Text + { + Text = text + }); + Paragraph paragraph = new(run); + tableCell.AppendChild(paragraph); + tableCell.Append(cellProperties); + return tableCell; + } + + protected void CreateTable(WordTableData tableData) + { + if (documentBody == null || tableData == null) + { + return; + } + var table = new Table(); + + TableProperties tableProperties = new( + new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 }, + new BottomBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 }, + new LeftBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 }, + new RightBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 } + ) + ); + table.AppendChild(tableProperties); + + table.Append(new TableRow(tableData.Columns.Select(x => CreateTableCell(x.Item1, true, x.Item2)))); + table.Append(tableData.Rows.Select(x => new TableRow(x.Select(y => CreateTableCell(y))))); + + documentBody.AppendChild(table); + } + + private void Save() + { + if (documentBody == null || wordDocument == null) + { + return; + } + wordDocument.MainDocumentPart!.Document.Save(); + wordDocument.Dispose(); + } + + public byte[] GetFile() + { + Save(); + byte[] file = File.ReadAllBytes(tempFileName); + File.Delete(tempFileName); + return file; + } + + public void CreateLawyersHearingTable(List data) + { + List> rows = new(); + foreach (ReportLawyerHearingViewModel lawyer in data) + { + List lawyerCells = new() { lawyer.Lawyer, "" }; + rows.Add(lawyerCells); + List hearingCells; + foreach (string hearing in lawyer.Hearings) + { + hearingCells = new() { "", hearing }; + rows.Add(hearingCells); + } + } + WordTableData wordTable = new() + { + Columns = new List<(string, int)>() + { + ("Юрист", 3000), + ("Слушание", 3000) + }, + Rows = rows + }; + CreateTable(wordTable); + } + } +} diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerHearingListBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerHearingListBindingModel.cs new file mode 100644 index 0000000..7fab4e6 --- /dev/null +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerHearingListBindingModel.cs @@ -0,0 +1,15 @@ +using CaseAccountingContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingContracts.BindingModels +{ + public class LawyerHearingListBindingModel + { + public string FileType { get; set; } = string.Empty; + public List Lawyers { get; set; } = new(); + } +} diff --git a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportCustomerLogic.cs b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportCustomerLogic.cs index 387673b..425e6e2 100644 --- a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportCustomerLogic.cs +++ b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportCustomerLogic.cs @@ -14,6 +14,8 @@ namespace CaseAccountingContracts.BusinessLogicContracts List GetHearingSpecialization(ReportBindingModel model); + byte[] SaveListFile(LawyerHearingListBindingModel model); + void SaveLawyerHearingToWordFile(ReportBindingModel model); void SaveLawyerHearingToExcelFile(ReportBindingModel model); diff --git a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs index ab32983..9570d06 100644 --- a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs +++ b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs @@ -17,5 +17,7 @@ namespace CaseAccountingContracts.StoragesContracts CaseViewModel? Insert(CaseBindingModel model); CaseViewModel? Update(CaseBindingModel model); CaseViewModel? Delete(CaseBindingModel model); + + List GetCaseHearings(CaseSearchModel model); } } diff --git a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ILawyerStorage.cs b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ILawyerStorage.cs index 3d65820..a331386 100644 --- a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ILawyerStorage.cs +++ b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ILawyerStorage.cs @@ -17,5 +17,7 @@ namespace CaseAccountingContracts.StoragesContracts LawyerViewModel? Insert(LawyerBindingModel model); LawyerViewModel? Update(LawyerBindingModel model); LawyerViewModel? Delete(LawyerBindingModel model); + + List GetLawyerCases(LawyerSearchModel model); } } diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/ReportLawyerHearingViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/ReportLawyerHearingViewModel.cs index f1c8579..fffbde4 100644 --- a/CaseAccounting/CaseAccountingContracts/ViewModels/ReportLawyerHearingViewModel.cs +++ b/CaseAccounting/CaseAccountingContracts/ViewModels/ReportLawyerHearingViewModel.cs @@ -8,12 +8,7 @@ namespace CaseAccountingContracts.ViewModels { public class ReportLawyerHearingViewModel { - public string Name { get; set; } = string.Empty; - - public string Surname { get; set; } = string.Empty; - - public string Patronymic { get; set; } = string.Empty; - - public List<(DateTime Date, string Information)> Hearings { get; set; } = new(); + public string Lawyer { get; set; } = string.Empty; + public List Hearings { get; set; } = new(); } } diff --git a/CaseAccounting/CaseAccountingCustomerView/APIUser.cs b/CaseAccounting/CaseAccountingCustomerView/APIUser.cs index 69d091d..4efbf98 100644 --- a/CaseAccounting/CaseAccountingCustomerView/APIUser.cs +++ b/CaseAccounting/CaseAccountingCustomerView/APIUser.cs @@ -39,5 +39,25 @@ namespace CaseAccountingCustomerView throw new Exception(result); } } + + public static O? PostRequestWithResult(string requestUrl, I model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + + var response = _client.PostAsync(requestUrl, data); + + var result = response.Result.Content.ReadAsStringAsync().Result; + + if (response.Result.IsSuccessStatusCode) + { + var temp = JsonConvert.DeserializeObject(result); + return temp; + } + else + { + return default; + } + } } } diff --git a/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs b/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs index da37694..d9d54e1 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs +++ b/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs @@ -100,5 +100,22 @@ namespace CaseAccountingCustomerView.Controllers { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } + + [HttpPost] + public int[]? HearingLawyerList([FromBody] LawyerHearingListBindingModel listModel) + { + if (APIUser.User == null) + { + return Array.Empty(); + } + byte[]? file = APIUser.PostRequestWithResult + ("api/reportcustomer/lawyerhearinglist", listModel); + return file!.Select(b => (int)b).ToArray(); + } + + public IActionResult HearingLawyerList() + { + return View(); + } } } \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Home/HearingLawyerList.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Home/HearingLawyerList.cshtml new file mode 100644 index 0000000..4451a2b --- /dev/null +++ b/CaseAccounting/CaseAccountingCustomerView/Views/Home/HearingLawyerList.cshtml @@ -0,0 +1,44 @@ +@{ + ViewData["Title"] = "Список слушаний по юристам"; +} + +

Список слушаний по юристам

+ +
+
+

+
+
+ + + + + + + +
+
+ + + + + + + + + + + + +
ИмяФамилияОтчествоОпыт работыСпециализация
+
+
+ + \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Shared/_Layout.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Shared/_Layout.cshtml index 97b2084..cf9eb64 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Views/Shared/_Layout.cshtml +++ b/CaseAccounting/CaseAccountingCustomerView/Views/Shared/_Layout.cshtml @@ -3,7 +3,7 @@ - @ViewData["Title"] - CaseAccountingCustomerView + @ViewData["Title"] - Юридическая фирма «Вас обманут» "Заказчик" @@ -12,7 +12,7 @@