From cc28f399a48d603f909551b464fb72ea52e15938 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Fri, 19 May 2023 21:07:14 +0400 Subject: [PATCH 01/13] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D1=81=D1=8C=20=D0=BE=D1=82=D1=87=D1=91=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/DealBindingModel.cs | 7 +- .../Implements/DealStorage.cs | 4 +- .../Models/Deal.cs | 9 +- .../Controllers/DealController.cs | 21 +++- .../Views/Deal/Bind.cshtml | 37 +++++++ .../Views/Home/Deals.cshtml | 6 ++ .../wwwroot/js/deal/deal-bind.js | 97 +++++++++++++++++++ .../Controllers/DealController.cs | 22 ++++- 8 files changed, 194 insertions(+), 9 deletions(-) create mode 100644 CaseAccounting/CaseAccountingProviderView/Views/Deal/Bind.cshtml create mode 100644 CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-bind.js diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/DealBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/DealBindingModel.cs index e321d1d..6f2c914 100644 --- a/CaseAccounting/CaseAccountingContracts/BindingModels/DealBindingModel.cs +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/DealBindingModel.cs @@ -25,12 +25,17 @@ namespace CaseAccountingContracts.BindingModels public List CaseViewModels { get; set; } = new(); + public Dictionary Contracts { get; set; } = new(); + + public List ContractViewModels { get; set; } = new(); + public DealBindingModel() { } [JsonConstructor] - public DealBindingModel(Dictionary Cases) + public DealBindingModel(Dictionary Cases, Dictionary Contracts) { this.Cases = Cases.ToDictionary(x => x.Key, x => (ICaseModel)x.Value); + this.Contracts = Contracts.ToDictionary(x => x.Key, x => (IContractModel)x.Value); } } } diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/DealStorage.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/DealStorage.cs index 7c44a90..718ad0d 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/DealStorage.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/DealStorage.cs @@ -115,9 +115,9 @@ namespace CaseAccountingDataBaseImplement.Implements { return null; } - deal.Update(model); + deal.Update(context, model); context.SaveChanges(); - deal.UpdateCases(context, model); + if(model.Cases.Count > 0) deal.UpdateCases(context, model); transaction.Commit(); return deal.GetViewModel; } diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs index 7bc42a9..b3fde5e 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs @@ -72,7 +72,7 @@ namespace CaseAccountingDataBaseImplement.Models }; } - public void Update(DealBindingModel? model) + public void Update(CaseAccountingDatabase context, DealBindingModel? model) { if (model == null) { @@ -81,6 +81,13 @@ namespace CaseAccountingDataBaseImplement.Models Subject = model.Subject; Responsibilities = model.Responsibilities; Date = model.Date; + if (model.Contracts.Count > 0) + { + Contracts = model.Contracts.Select(x => new DealContract + { + Contract = context.Contracts.First(y => y.Id == x.Key) + }).ToList(); + } } public void UpdateCases(CaseAccountingDatabase context, DealBindingModel model) diff --git a/CaseAccounting/CaseAccountingProviderView/Controllers/DealController.cs b/CaseAccounting/CaseAccountingProviderView/Controllers/DealController.cs index f8b1c51..200646e 100644 --- a/CaseAccounting/CaseAccountingProviderView/Controllers/DealController.cs +++ b/CaseAccounting/CaseAccountingProviderView/Controllers/DealController.cs @@ -53,7 +53,14 @@ namespace CaseAccountingProviderView.Controllers throw new Exception("403"); } dealModel.UserId = APIUser.User.Id; - APIUser.PostRequest("api/deal/update", dealModel); + var contractdict = new Dictionary(); + foreach (var element in dealModel.ContractViewModels) + { + var contractModel = APIUser.GetRequest($"api/contract/get?id={element.Id}"); + contractdict.Add(element.Id, contractModel); + } + dealModel.Contracts = contractdict; + APIUser.PostRequest("api/deal/update", dealModel); Response.Redirect("/Home/Deals"); } @@ -127,5 +134,15 @@ namespace CaseAccountingProviderView.Controllers DealViewModel? dealModel = APIUser.GetRequest($"api/deal/get?id={id}"); return dealModel; } - } + + public List GetAllContracts() + { + if (APIUser.User == null) + { + return new(); + } + List? contractModel = APIUser.GetRequest>($"api/deal/getallcontracts"); + return contractModel ?? new(); + } + } } diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Deal/Bind.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Deal/Bind.cshtml new file mode 100644 index 0000000..9bb03da --- /dev/null +++ b/CaseAccounting/CaseAccountingProviderView/Views/Deal/Bind.cshtml @@ -0,0 +1,37 @@ +@{ + ViewData["Title"] = "Договор"; +} + +@{ +

Привязка контракта к договору

+ +
+
+

+
+
+ +

Номер:

+ + +
+
+ + + + + + + + + + +
Услуга:Цена:Дата:
+
+
+ + +} + diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Home/Deals.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Home/Deals.cshtml index 73b4f83..5279818 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Home/Deals.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Home/Deals.cshtml @@ -28,6 +28,9 @@ Дата составления + + Привязать запись + Изменить запись @@ -49,6 +52,9 @@ @item.Date.ToString("yyyy-MM-dd") + + Привязка + Изменить diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-bind.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-bind.js new file mode 100644 index 0000000..e3eaacc --- /dev/null +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-bind.js @@ -0,0 +1,97 @@ +const saveBtn = document.getElementById("save-button"); +const tbody = document.getElementById("scrollable-table__tbody"); +const currentDealId = document.getElementById("deal-data").dataset.id; + +var contracts = []; +var dataArray = []; +var currentDeal = null; + +window.addEventListener("load", async () => { + try { + await $.ajax({ + url: `/deal/getallcontracts`, + type: "GET", + contentType: "json" + }).done((result) => { + contracts = result; + console.log(contracts); + contracts.forEach((contract) => { + const { id, service, coast, date } = contract; + const row = tbody.insertRow(); + row.setAttribute("data-id", id); + + const cells = [service, coast, date]; + cells.forEach((value) => { + const cell = row.insertCell(); + cell.textContent = value; + }); + + row.addEventListener('click', () => addAndRemoveFromList(row)); + }); + }); + + await $.ajax({ + url: `/deal/get?id=${currentDealId}`, + type: "GET", + contentType: "json" + }).done((result) => { + currentDeal = result; + console.log(currentDeal) + }); + } catch (error) { + console.error(error); + } +}); + +saveBtn.addEventListener("click", () => { + if (!correctData()) { + return; + } + if (!validate()) { + return; + } +}); + +const correctData = function () { + + return true; +}; + +const validate = function () { + + return true; +}; + +saveBtn.addEventListener("click", () => { + let dealModel = { + "Id": currentDeal.id, + "Subject": currentDeal.subject, + "Responsibilities": currentDeal.responsibilities, + "Date": currentDeal.date, + "ContractViewModels": dataArray + }; + console.log(dealModel); + console.log(dataArray); + $.ajax({ + url: "/deal/update", + type: "POST", + contentType: "application/json", + data: JSON.stringify(dealModel) + }).done(() => { + window.location.href = "/Home/Deals"; + }); +}); + +const addAndRemoveFromList = (row) => { + var id = parseInt(row.dataset.id); + console.log(contracts.find(x => x.id === id)) + var index = dataArray.indexOf(contracts.find(x => x.id === id)); + if (index === -1) { + dataArray.push(contracts.find(x => x.id === id)); + row.classList.add("bg-primary"); + } else { + dataArray.splice(index, 1); + row.classList.remove("bg-primary"); + } + console.log(dataArray); +} \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs index 762d9eb..8423c40 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs @@ -1,4 +1,5 @@ -using CaseAccountingContracts.BindingModels; +using CaseAccountingBusinessLogic.BusinessLogics; +using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.SearchModels; using CaseAccountingContracts.ViewModels; @@ -11,10 +12,12 @@ namespace CaseAccountingRestApi.Controllers public class DealController : Controller { private readonly IDealLogic _logic; + private readonly IContractLogic _contractLogic; - public DealController(IDealLogic logic) + public DealController(IDealLogic logic, IContractLogic contractLogic) { _logic = logic; + _contractLogic = contractLogic; } [HttpGet] @@ -43,7 +46,20 @@ namespace CaseAccountingRestApi.Controllers } } - [HttpPost] + [HttpGet] + public List? GetAllContracts() + { + try + { + return _contractLogic.ReadList(null); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] public void Create(DealBindingModel model) { try From 7483e0682dec4c2958ba5c238cfe386285a2c83e Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Fri, 19 May 2023 22:33:41 +0400 Subject: [PATCH 02/13] =?UTF-8?q?=D0=A7=D0=B5=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CaseAccountingBusinessLogic.csproj | 2 +- .../AbstractSaveToExcelCustomer.cs | 12 - .../AbstractSaveToExcelProvider.cs | 12 - .../AbstractSaveToPdfCustomer.cs | 12 - .../AbstractSaveToPdfProvider.cs | 12 - .../AbstractSaveToWordCustomer.cs | 12 - .../AbstractSaveToWordProvider.cs | 12 - .../OfficePackage/ExcelBuilderProvider.cs | 356 ++++++++++++++++++ .../OfficePackage/WordBuilderProvider.cs | 170 +++++++++ .../Views/Home/GetList.cshtml | 45 +++ .../Views/Shared/_Layout.cshtml | 2 + .../wwwroot/js/report/reportlist.js | 0 12 files changed, 574 insertions(+), 73 deletions(-) delete mode 100644 CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelCustomer.cs delete mode 100644 CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelProvider.cs delete mode 100644 CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfCustomer.cs delete mode 100644 CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfProvider.cs delete mode 100644 CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordCustomer.cs delete mode 100644 CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordProvider.cs create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs create mode 100644 CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml create mode 100644 CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js diff --git a/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj b/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj index d0f81fd..02c99ca 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj +++ b/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj @@ -7,6 +7,7 @@ + @@ -18,7 +19,6 @@ - diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelCustomer.cs deleted file mode 100644 index ad98b9c..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelCustomer.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToExcelCustomer - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelProvider.cs deleted file mode 100644 index 681ddf1..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToExcelProvider - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfCustomer.cs deleted file mode 100644 index e5619ee..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfCustomer.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToPdfCustomer - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfProvider.cs deleted file mode 100644 index d8bc181..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToPdfProvider - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordCustomer.cs deleted file mode 100644 index f9bc408..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordCustomer.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToWordCustomer - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordProvider.cs deleted file mode 100644 index ff4597c..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToWordProvider - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs new file mode 100644 index 0000000..41b5f48 --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs @@ -0,0 +1,356 @@ +using UniversityBusinessLogic.OfficePackage.Models; +using UniversityContracts.ViewModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; + +namespace CaseAccountingBusinessLogic.OfficePackage +{ + public class ExcelBuilderProvider + { + private readonly string tempFileName = "temp.xlsx"; + private SpreadsheetDocument? spreadsheetDocument; + private SharedStringTablePart? shareStringPart; + private Worksheet? worksheet; + + private void CreateStyles(WorkbookPart workbookpart) + { + var sp = workbookpart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + + var fonts = new Fonts() { Count = 2U, KnownFonts = true }; + + var fontUsual = new Font(); + fontUsual.Append(new FontSize() { Val = 12D }); + fonts.Append(fontUsual); + + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 12D }); + fonts.Append(fontTitle); + + var fills = new Fills() { Count = 3U }; + + var fill1 = new Fill(); + fill1.Append(new PatternFill() + { + PatternType = PatternValues.None + }); + + var fill2 = new Fill(); + fill2.Append(new PatternFill() + { + PatternType = PatternValues.Gray125 + }); + + var fill3 = new Fill(); + fill3.Append(new PatternFill() + { + PatternType = PatternValues.Solid, + ForegroundColor = new() + { + Rgb = "e0e8ff" + } + }); + + var fill4 = new Fill(); + fill1.Append(new PatternFill() + { + PatternType = PatternValues.None + }); + + fills.Append(fill1); + fills.Append(fill2); + fills.Append(fill3); + fills.Append(fill4); + + var borders = new Borders() { Count = 2U }; + + var borderNoBorder = new Border(); + borderNoBorder.Append(new LeftBorder()); + borderNoBorder.Append(new RightBorder()); + borderNoBorder.Append(new TopBorder()); + borderNoBorder.Append(new BottomBorder()); + borderNoBorder.Append(new DiagonalBorder()); + + var borderThin = new Border(); + + var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin }; + rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }; + bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + borderThin.Append(leftBorder); + borderThin.Append(rightBorder); + borderThin.Append(topBorder); + borderThin.Append(bottomBorder); + borderThin.Append(new DiagonalBorder()); + + borders.Append(borderNoBorder); + borders.Append(borderThin); + + CellFormats cellFormats = new() { Count = 4U }; + CellFormat cellFormatEmpty = new() + { + FontId = 0U, + FillId = 0U, + BorderId = 1U, + ApplyFont = true + }; + CellFormat cellFormatDefault = new() + { + FontId = 0U, + FillId = 3U, + BorderId = 1U, + ApplyFont = true + }; + CellFormat cellFormatTitle = new() + { + FontId = 1U, + FillId = 2U, + BorderId = 1U, + ApplyFont = true, + ApplyBorder = true, + Alignment = new Alignment() + { + Vertical = VerticalAlignmentValues.Center, + Horizontal = HorizontalAlignmentValues.Center, + WrapText = true + } + }; + + cellFormats.Append(cellFormatEmpty); + cellFormats.Append(cellFormatDefault); + cellFormats.Append(cellFormatTitle); + + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellFormats); + } + + public void CreateDocument() + { + spreadsheetDocument = SpreadsheetDocument.Create(tempFileName, + SpreadsheetDocumentType.Workbook); + WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); + + CreateStyles(workbookpart); + + shareStringPart = spreadsheetDocument.WorkbookPart! + .GetPartsOfType() + .Any() + ? spreadsheetDocument.WorkbookPart + .GetPartsOfType() + .First() + : spreadsheetDocument.WorkbookPart + .AddNewPart(); + + if (shareStringPart.SharedStringTable == null) + { + shareStringPart.SharedStringTable = new SharedStringTable(); + } + + WorksheetPart worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + + Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + Sheet sheet = new() + { + Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + + worksheet = worksheetPart.Worksheet; + } + + public void InsertCellInWorksheet(ExcelCellData cellData) + { + if (worksheet == null || shareStringPart == null) + { + return; + } + var sheetData = worksheet.GetFirstChild(); + if (sheetData == null) + { + return; + } + + Row? row = sheetData.Elements() + .Where(r => r.RowIndex! == cellData.RowIndex) + .FirstOrDefault(); + if (row == null) + { + row = new Row() { RowIndex = cellData.RowIndex }; + sheetData.Append(row); + } + + Cell? cell = row.Elements() + .Where(c => c.CellReference!.Value == cellData.CellReference) + .FirstOrDefault(); + if (cell == null) + { + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, cellData.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + var newCell = new Cell() + { + CellReference = cellData.CellReference + }; + row.InsertBefore(newCell, refCell); + cell = newCell; + } + + shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(cellData.Text))); + shareStringPart.SharedStringTable.Save(); + cell.CellValue = new CellValue((shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = cellData.StyleIndex; + } + + private void MergeCells(ExcelMergeParameters excelParams) + { + if (worksheet == null) + { + return; + } + MergeCells mergeCells; + if (worksheet.Elements().Any()) + { + mergeCells = worksheet.Elements().First(); + } + else + { + mergeCells = new MergeCells(); + if (worksheet.Elements().Any()) + { + worksheet.InsertAfter(mergeCells, worksheet.Elements().First()); + } + else + { + worksheet.InsertAfter(mergeCells, worksheet.Elements().First()); + } + } + var mergeCell = new MergeCell() + { + Reference = new StringValue(excelParams.Merge) + }; + mergeCells.Append(mergeCell); + } + + private void Save() + { + if (spreadsheetDocument == null) + { + return; + } + spreadsheetDocument.WorkbookPart!.Workbook.Save(); + spreadsheetDocument.Dispose(); + } + + public byte[] GetFile() + { + Save(); + byte[] file = File.ReadAllBytes(tempFileName); + File.Delete(tempFileName); + return file; + } + + public void CreateTitle(string text) + { + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "B1" + }); + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "A", + RowIndex = 1, + Text = text, + StyleIndex = 0 + }); + } + + public void CreateStudentsDisciplineTable(List data) + { + if (worksheet == null || shareStringPart == null) + { + return; + } + + Columns columns = new(); + Column columnA = new() { Min = 1, Max = 1, Width = 30, CustomWidth = true }; + columns.Append(columnA); + Column columnB = new() { Min = 2, Max = 2, Width = 30, CustomWidth = true }; + columns.Append(columnB); + worksheet.InsertAt(columns, 0); + + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "A", + RowIndex = 2, + Text = "Студент", + StyleIndex = 2 + }); + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "B", + RowIndex = 2, + Text = "Дисциплина", + StyleIndex = 2 + }); + + uint currentRow = 3; + foreach (ReportStudentsDisciplineViewModel student in data) + { + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "A", + RowIndex = currentRow, + Text = student.Student, + StyleIndex = 1 + }); + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "B", + RowIndex = currentRow, + Text = "", + StyleIndex = 1 + }); + currentRow++; + foreach (string discipline in student.Disciplines) + { + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "A", + RowIndex = currentRow, + Text = "", + StyleIndex = 1 + }); + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "B", + RowIndex = currentRow, + Text = discipline, + StyleIndex = 1 + }); + currentRow++; + } + } + } + } +} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs new file mode 100644 index 0000000..bc9633c --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs @@ -0,0 +1,170 @@ +using UniversityBusinessLogic.OfficePackage.Models; +using UniversityContracts.ViewModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace CaseAccountingBusinessLogic.OfficePackage +{ + public class WordBuilderProvider + { + 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 CreateStudentsDisciplineTable(List data) + { + List> rows = new(); + foreach (ReportStudentsDisciplineViewModel student in data) + { + List studentCells = new() { student.Student, "" }; + rows.Add(studentCells); + List disciplineCells; + foreach (string discipline in student.Disciplines) + { + disciplineCells = new() { "", discipline }; + rows.Add(disciplineCells); + } + } + WordTableData wordTable = new() + { + Columns = new List<(string, int)>() + { + ("Студент", 3000), + ("Дисциплина", 3000) + }, + Rows = rows + }; + CreateTable(wordTable); + } + } +} diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml new file mode 100644 index 0000000..8279fe3 --- /dev/null +++ b/CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml @@ -0,0 +1,45 @@ +@{ + ViewData["Title"] = "Список специализаций по делам"; +} + +

Список специализаций по делам

+ +
+
+

+
+
+ + + + + + + +
+
+ + + + + + + + + + + + +
ИмяФамилияДата рожденияНомер студ. билетаСтатус обучения
+
+
+ + + diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml index 4c626ff..eb9d159 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml @@ -21,6 +21,8 @@ Дела Договора Слушания + Получение список + Получение отчёта diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js new file mode 100644 index 0000000..e69de29 From ba1d369a2d5f6d1799dd4f32188b2a3475094122 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Fri, 19 May 2023 22:34:30 +0400 Subject: [PATCH 03/13] =?UTF-8?q?C=D1=82=D1=80=D0=B0=D0=BD=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OfficePackage/ExcelBuilderProvider.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs index 41b5f48..1530ab6 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs @@ -1,5 +1,5 @@ -using UniversityBusinessLogic.OfficePackage.Models; -using UniversityContracts.ViewModels; +using CaseAccountingBusinessLogic.OfficePackage; +using CaseAccountingContracts.ViewModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; From 3134b5f6e11bf830e301398adc6118a3a70168b5 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 20 May 2023 00:24:04 +0400 Subject: [PATCH 04/13] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportProviderLogic.cs | 112 ++++++++++++++---- .../OfficePackage/ExcelBuilderCustomer.cs | 4 +- .../OfficePackage/ExcelBuilderProvider.cs | 16 +-- .../OfficePackage/WordBuilderProvider.cs | 24 ++-- .../CaseSpecializationListBindingModel.cs | 15 +++ .../IReportProviderLogic.cs | 6 +- .../ReportCaseSpecializationViewModel.cs | 5 +- .../CaseAccountingDatabase.cs | 4 +- .../CaseAccountingProviderView/APIUser.cs | 22 +++- .../Controllers/HomeController.cs | 27 +++-- ...t.cshtml => SpecializationCaselist.cshtml} | 19 ++- .../Views/Shared/_Layout.cshtml | 2 +- .../wwwroot/js/report/reportlist.js | 91 ++++++++++++++ .../Controllers/ReportProviderController.cs | 25 ++++ .../CaseAccountingRestApi/Program.cs | 6 + 15 files changed, 299 insertions(+), 79 deletions(-) create mode 100644 CaseAccounting/CaseAccountingContracts/BindingModels/CaseSpecializationListBindingModel.cs rename CaseAccounting/CaseAccountingProviderView/Views/Home/{GetList.cshtml => SpecializationCaselist.cshtml} (61%) create mode 100644 CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs index 74cdacf..773ba5d 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs @@ -1,4 +1,5 @@ -using CaseAccountingContracts.BindingModels; +using CaseAccountingBusinessLogic.OfficePackage; +using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.SearchModels; using CaseAccountingContracts.StoragesContracts; @@ -17,32 +18,66 @@ namespace CaseAccountingBusinessLogic.BusinessLogics private readonly ISpecializationStorage _specializationStorage; private readonly IHearingStorage _hearingStorage; private readonly ILawyerStorage _lawyerStorage; + private readonly WordBuilderProvider _wordBuilder; + private readonly ExcelBuilderProvider _excelBuilder; + /*private readonly PdfBuilderProvider _pdfBuilder; + private readonly MailSender _mailSender;*/ - public ReportProviderLogic(ICaseStorage caseStorage, ISpecializationStorage specializationStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage) + public ReportProviderLogic(ICaseStorage caseStorage, ISpecializationStorage specializationStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, WordBuilderProvider wordBuilder, ExcelBuilderProvider excelBuilder) { _caseStorage = caseStorage ?? throw new ArgumentNullException(nameof(caseStorage)); _specializationStorage = specializationStorage ?? throw new ArgumentNullException(nameof(specializationStorage)); _hearingStorage = hearingStorage ?? throw new ArgumentNullException(nameof(hearingStorage)); _lawyerStorage = lawyerStorage ?? throw new ArgumentNullException(nameof(lawyerStorage)); + _wordBuilder = wordBuilder ?? throw new ArgumentNullException(nameof(wordBuilder)); + _excelBuilder = excelBuilder ?? throw new ArgumentNullException(nameof(excelBuilder)); } public List GetCaseSpecialization(List models) { - var сases = new List(); + List list = new(); foreach (var model in models) - сases.Add(_caseStorage.GetElement(new CaseSearchModel { Id = model.Id })); - return сases.Select(x => new ReportCaseSpecializationViewModel { - CaseName = x.Name, - Applicant = x.Applicant, - Defendant = x.Defendant, - Date = x.Date, - Specialization = x.Specialization, - }).ToList(); + { + var specialization = _specializationStorage.GetElement(new SpecializationSearchModel { Id = model.SpecializationId }); + var caseModel = _caseStorage.GetElement(new CaseSearchModel { Id = model.Id }); + if (specialization == null) + { + throw new Exception("Некоректные данные по специализации"); + } + if (caseModel == null) + { + throw new Exception("Некоректные данные по делу"); + } + + bool hasSpec = false; + if (list.Count > 0) + { + foreach (var report in list) + { + if (hasSpec = report.Specialization.Equals(specialization.Name)) + { + report.Cases.Add("Дело #" + caseModel.Id.ToString()); + break; + } + } + } + if (!hasSpec) + { + var newElement = new ReportCaseSpecializationViewModel + { + Specialization = specialization.Name, + Cases = new() + }; + newElement.Cases.Add("Дело #" + caseModel.Id.ToString()); + list.Add(newElement); + } + } + return list; } public List GetHearingLawyer(ReportBindingModel model) { - var hearings = _hearingStorage + /*var hearings = _hearingStorage .GetFilteredList(new HearingSearchModel { UserId = model.UserId}) .Where(x => model.DateFrom <= x.Date && model.DateTo >= x.Date); var list = new List(); @@ -60,25 +95,50 @@ namespace CaseAccountingBusinessLogic.BusinessLogics } list.Add(record); } - return list; + return list;*/ + return new(); } - public void SaveCaseSpecializationToExcelFile(ReportBindingModel model) + public byte[] SaveListFile(CaseSpecializationListBindingModel model) { - throw new NotImplementedException(); - //TODO + byte[] file = Array.Empty(); + + string title = "Список дисциплин по выбранным студентам"; + + if (model.FileType == "docx") + { + _wordBuilder.CreateDocument(); + _wordBuilder.CreateTitle(title); + _wordBuilder.CreateCaseSpecializationTable(GetCaseSpecialization(model.Cases)); + file = _wordBuilder.GetFile(); + } + else if (model.FileType == "xlsx") + { + _excelBuilder.CreateDocument(); + _excelBuilder.CreateTitle(title); + _excelBuilder.CreateCaseSpecializationTable(GetCaseSpecialization(model.Cases)); + file = _excelBuilder.GetFile(); + } + return file; } - public void SaveCaseSpecializationToWordFile(ReportBindingModel model) + /*public void SendByMailStatusReport(ReportBindingModel reportModel) { - throw new NotImplementedException(); - //TODO - } - - public void SaveHearingLawyerToPdfFile(ReportBindingModel model) - { - throw new NotImplementedException(); - //TODO - } + byte[] file = _pdfBuilder.GetEducationStatusReportFile(new() + { + Title = "Отчет по статусам обучения", + DateFrom = reportModel.DateFrom, + DateTo = reportModel.DateTo, + Records = GetStreamStudentEdStatPeriod(reportModel) + }); + _mailSender.SendMailAsync(new() + { + MailAddress = reportModel.UserEmail, + Subject = "Отчет по статусам обучения", + Text = $"За период с {reportModel.DateFrom.ToShortDateString()} " + + $"по {reportModel.DateTo.ToShortDateString()}.", + File = file + }); + }*/ } } diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs index e29f4a5..0f943f2 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs @@ -291,7 +291,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage }); } - public void CreateLawyersHearingsTable(List data) + /*public void CreateLawyersHearingsTable(List data) { if (worksheet == null || shareStringPart == null) { @@ -357,6 +357,6 @@ namespace CaseAccountingBusinessLogic.OfficePackage currentRow++; } } - } + }*/ } } diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs index 1530ab6..e700285 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs @@ -1,5 +1,7 @@ using CaseAccountingBusinessLogic.OfficePackage; +using CaseAccountingBusinessLogic.OfficePackage.HelperModels; using CaseAccountingContracts.ViewModels; +using ComputersShopBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; @@ -285,7 +287,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage }); } - public void CreateStudentsDisciplineTable(List data) + public void CreateCaseSpecializationTable(List data) { if (worksheet == null || shareStringPart == null) { @@ -303,25 +305,25 @@ namespace CaseAccountingBusinessLogic.OfficePackage { ColumnName = "A", RowIndex = 2, - Text = "Студент", + Text = "Специализация:", StyleIndex = 2 }); InsertCellInWorksheet(new ExcelCellData { ColumnName = "B", RowIndex = 2, - Text = "Дисциплина", + Text = "Дела:", StyleIndex = 2 }); uint currentRow = 3; - foreach (ReportStudentsDisciplineViewModel student in data) + foreach (ReportCaseSpecializationViewModel specialization in data) { InsertCellInWorksheet(new ExcelCellData { ColumnName = "A", RowIndex = currentRow, - Text = student.Student, + Text = specialization.Specialization, StyleIndex = 1 }); InsertCellInWorksheet(new ExcelCellData @@ -332,7 +334,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage StyleIndex = 1 }); currentRow++; - foreach (string discipline in student.Disciplines) + foreach (string caseName in specialization.Cases) { InsertCellInWorksheet(new ExcelCellData { @@ -345,7 +347,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage { ColumnName = "B", RowIndex = currentRow, - Text = discipline, + Text = caseName, StyleIndex = 1 }); currentRow++; diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs index bc9633c..0343afc 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs @@ -1,5 +1,5 @@ -using UniversityBusinessLogic.OfficePackage.Models; -using UniversityContracts.ViewModels; +using CaseAccountingBusinessLogic.OfficePackage.HelperModels; +using CaseAccountingContracts.ViewModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; @@ -141,26 +141,26 @@ namespace CaseAccountingBusinessLogic.OfficePackage return file; } - public void CreateStudentsDisciplineTable(List data) + public void CreateCaseSpecializationTable(List data) { List> rows = new(); - foreach (ReportStudentsDisciplineViewModel student in data) + foreach (ReportCaseSpecializationViewModel specializationl in data) { - List studentCells = new() { student.Student, "" }; - rows.Add(studentCells); - List disciplineCells; - foreach (string discipline in student.Disciplines) + List specializationlCells = new() { specializationl.Specialization, "" }; + rows.Add(specializationlCells); + List caseCells; + foreach (string caseString in specializationl.Cases) { - disciplineCells = new() { "", discipline }; - rows.Add(disciplineCells); + caseCells = new() { "", caseString }; + rows.Add(caseCells); } } WordTableData wordTable = new() { Columns = new List<(string, int)>() { - ("Студент", 3000), - ("Дисциплина", 3000) + ("Специализация", 3000), + ("Дела", 3000) }, Rows = rows }; diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/CaseSpecializationListBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/CaseSpecializationListBindingModel.cs new file mode 100644 index 0000000..23f03b3 --- /dev/null +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/CaseSpecializationListBindingModel.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 CaseSpecializationListBindingModel + { + public string FileType { get; set; } = string.Empty; + public List Cases { get; set; } = new(); + } +} diff --git a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs index 678ce92..6e309b7 100644 --- a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs +++ b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs @@ -14,10 +14,6 @@ namespace CaseAccountingContracts.BusinessLogicContracts List GetHearingLawyer(ReportBindingModel model); - void SaveCaseSpecializationToWordFile(ReportBindingModel model); - - void SaveCaseSpecializationToExcelFile(ReportBindingModel model); - - void SaveHearingLawyerToPdfFile(ReportBindingModel model); + byte[] SaveListFile(CaseSpecializationListBindingModel model); } } diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/ReportCaseSpecializationViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/ReportCaseSpecializationViewModel.cs index 78b6a24..7e6e4c5 100644 --- a/CaseAccounting/CaseAccountingContracts/ViewModels/ReportCaseSpecializationViewModel.cs +++ b/CaseAccounting/CaseAccountingContracts/ViewModels/ReportCaseSpecializationViewModel.cs @@ -8,10 +8,7 @@ namespace CaseAccountingContracts.ViewModels { public class ReportCaseSpecializationViewModel { - public string CaseName { get; set; } = string.Empty; - public string Applicant { get; set; } = string.Empty; - public string Defendant { get; set; } = string.Empty; - public DateTime Date { get; set; } public string Specialization { get; set; } = string.Empty; + public List Cases { get; set; } = new(); } } diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs b/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs index 55243a9..75477ba 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs @@ -18,8 +18,8 @@ namespace CaseAccountingDataBaseImplement Host=localhost; Port=5432; Database=CaseAccountingDatabase; - Username=postgres; - Password=postgres"); + Username=courseuser; + Password=courseuser"); } base.OnConfiguring(optionsBuilder); } diff --git a/CaseAccounting/CaseAccountingProviderView/APIUser.cs b/CaseAccounting/CaseAccountingProviderView/APIUser.cs index b162554..987c8c3 100644 --- a/CaseAccounting/CaseAccountingProviderView/APIUser.cs +++ b/CaseAccounting/CaseAccountingProviderView/APIUser.cs @@ -43,5 +43,25 @@ namespace CaseAccountingProviderView 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 = _user.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/CaseAccountingProviderView/Controllers/HomeController.cs b/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs index 241b445..a699a99 100644 --- a/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs +++ b/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs @@ -35,7 +35,25 @@ namespace CaseAccountingProviderView.Controllers return View(); } - [HttpPost] + public IActionResult SpecializationCaselist() + { + return View(); + } + + [HttpPost] + public int[]? SpecializationCaselist([FromBody] CaseSpecializationListBindingModel listModel) + { + if (APIUser.User == null) + { + return Array.Empty(); + } + byte[]? file = APIUser.PostRequestWithResult + ("api/reportprovider/specializationcaselist", listModel); + return file!.Select(b => (int)b).ToArray(); + } + + + [HttpPost] public void Login(string login, string password) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) @@ -73,15 +91,8 @@ namespace CaseAccountingProviderView.Controllers { return Redirect("~/Home/Enter"); } - /*if (page == 0) - { - page = 1; - }*/ ViewBag.Cases = APIUser.GetRequest> ($"api/case/getallbyuser?userId={APIUser.User.Id}"); - /*ViewBag.Page = page; - ViewBag.NumberOfPages = APIUser.GetRequest - ($"api/student/getnumberofpages?userId={APIUser.User.Id}");*/ return View(); } diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Home/SpecializationCaselist.cshtml similarity index 61% rename from CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml rename to CaseAccounting/CaseAccountingProviderView/Views/Home/SpecializationCaselist.cshtml index 8279fe3..2df0d95 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Home/SpecializationCaselist.cshtml @@ -10,16 +10,12 @@ - - - - @@ -28,11 +24,12 @@ - - - - - + + + + + + diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml index eb9d159..2f647fa 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml @@ -21,7 +21,7 @@ ДелаДоговораСлушания - Получение список + Получение списокПолучение отчёта diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js index e69de29..b5115ef 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js @@ -0,0 +1,91 @@ +const createBtn = document.getElementById("create-button") +const tbody = document.getElementById("scrollable-table__tbody") +const nameInput = document.getElementById("name-input") +var fileType = document.getElementById("file-type") +var cases = [] +var dataArray = []; +const wordMIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; +const excelMIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + +window.addEventListener('load', async () => { + try { + await $.ajax({ + url: `/case/getallbyuser`, + type: "GET", + contentType: "json" + }).done((result) => { + cases = result; + cases.forEach((caseModel) => { + const { id, name, applicant, defendant, annotation, date, specialization } = caseModel; + const row = tbody.insertRow(); + row.setAttribute("data-id", id); + + const cells = [name, applicant, defendant, annotation, date, specialization]; + cells.forEach((value) => { + const cell = row.insertCell(); + cell.textContent = value; + }); + + row.addEventListener('click', () => addAndRemoveFromList(row)); + }); + }); + } catch (error) { + console.error(error); + } +}) + +createBtn.addEventListener('click', () => { + let listModel = { + "Cases": Array.from(dataArray), + "FileType": fileType.value + }; + $.ajax({ + url: "/home/specializationcaselist", + type: "POST", + contentType: "application/json", + data: JSON.stringify(listModel) + }).done((file) => { + let byteArray = new Uint8Array(file); + saveFile(byteArray, fileType); + }); +}) + +const saveFile = async function (bytes, fileType) { + if (window.showSaveFilePicker) { + let type; + if (fileType.value == "docx") { + type = { + description: "Microsoft Word (OpenXML)", + accept: { [wordMIME]: [".docx"] } + }; + } else if (fileType.value == "xlsx") { + type = { + description: "Microsoft Excel (OpenXML)", + accept: { [excelMIME]: [".xlsx"] } + }; + } + + const opts = { + suggestedName: `case-specialization-list.${fileType.value}`, + types: [type], + }; + const handle = await showSaveFilePicker(opts); + const writable = await handle.createWritable(); + await writable.write(bytes); + writable.close(); + } +} + +const addAndRemoveFromList = (row) => { + var id = parseInt(row.dataset.id); + console.log(cases.find(x => x.id === id)) + var index = dataArray.indexOf(cases.find(x => x.id === id)); + if (index === -1) { + dataArray.push(cases.find(x => x.id === id)); + row.classList.add("bg-primary"); + } else { + dataArray.splice(index, 1); + row.classList.remove("bg-primary"); + } + console.log(dataArray); +} diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs new file mode 100644 index 0000000..76d1df6 --- /dev/null +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs @@ -0,0 +1,25 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using Microsoft.AspNetCore.Mvc; + +namespace CaseAccountingRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ReportProviderController : Controller + { + private readonly IReportProviderLogic reportLogic; + + public ReportProviderController(IReportProviderLogic reportLogic) + { + this.reportLogic = reportLogic; + } + + [HttpPost] + public byte[] SpecializationCaselist(CaseSpecializationListBindingModel listModel) + { + byte[] file = reportLogic.SaveListFile(listModel); + return file; + } + } +} diff --git a/CaseAccounting/CaseAccountingRestApi/Program.cs b/CaseAccounting/CaseAccountingRestApi/Program.cs index f0ee39e..6ed555e 100644 --- a/CaseAccounting/CaseAccountingRestApi/Program.cs +++ b/CaseAccounting/CaseAccountingRestApi/Program.cs @@ -1,4 +1,5 @@ using CaseAccountingBusinessLogic.BusinessLogics; +using CaseAccountingBusinessLogic.OfficePackage; using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.StoragesContracts; using CaseAccountingDataBaseImplement.Implements; @@ -26,6 +27,11 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddControllers().AddNewtonsoftJson(); builder.Services.AddControllers(); From 740f8ec2efa427b507295965a056bbc885f4f147 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 20 May 2023 03:13:10 +0400 Subject: [PATCH 05/13] =?UTF-8?q?=D0=A3=D1=80=D0=B0,=20=D0=BF=D0=BE=D1=87?= =?UTF-8?q?=D1=82=D0=B8=20=D0=B2=D1=81=D1=91.=20=D0=A7=D1=91=20=D1=82?= =?UTF-8?q?=D0=B0=D0=BC=20=D1=81=20=D0=B4=D0=B5=D0=B4=D0=BB=D0=B0=D0=B9?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=3F=20=D0=9C=D0=B0=D1=82=D1=8C=20=D0=B6=D0=B8?= =?UTF-8?q?=D0=B2=D0=B0=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/MailSender.cs | 58 ++++++ .../BusinessLogics/ReportProviderLogic.cs | 49 +++-- .../CaseAccountingBusinessLogic.csproj | 1 + .../OfficePackage/ExcelBuilderCustomer.cs | 1 - .../OfficePackage/ExcelBuilderProvider.cs | 1 - .../HelperEnums/ExcelStyleInfoType.cs | 2 +- .../HelperEnums/PdfParagraphAlignmentType.cs | 2 +- .../HelperEnums/WordJustificationType.cs | 2 +- .../HelperModels/ExcelCellParameters.cs | 4 +- .../HelperModels/ExcelMergeParameters.cs | 2 +- .../HelperModels/PdfParagraph.cs | 4 +- .../HelperModels/PdfRowParameters.cs | 4 +- .../HelperModels/WordParagraph.cs | 2 +- .../HelperModels/WordTextProperties.cs | 4 +- .../OfficePackage/PdfBuilderProvider.cs | 183 ++++++++++++++++++ .../BindingModels/MailConfigBindingModel.cs | 16 ++ .../BindingModels/MailSendInfoBindingModel.cs | 16 ++ .../BindingModels/ReportBindingModel.cs | 9 +- .../IReportProviderLogic.cs | 2 + .../StoragesContracts/ILawyerStorage.cs | 1 + .../ViewModels/CaseLawyerViewModel.cs | 15 ++ .../ReportHearingLawyerViewModel.cs | 5 +- .../Implements/CaseStorage.cs | 2 +- .../Implements/HearingStorage.cs | 2 +- .../Implements/LawyerStorage.cs | 14 ++ .../Models/Case.cs | 8 +- .../Models/Deal.cs | 2 +- .../Models/Hearing.cs | 6 +- .../Controllers/HomeController.cs | 30 +++ .../Views/Home/GetReport.cshtml | 55 ++++++ .../Views/Shared/_Layout.cshtml | 2 +- .../wwwroot/js/report/reportpdf.js | 87 +++++++++ .../Controllers/ReportProviderController.cs | 14 ++ .../CaseAccountingRestApi/Program.cs | 14 ++ .../CaseAccountingRestApi/appsettings.json | 8 +- 35 files changed, 574 insertions(+), 53 deletions(-) create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/MailSender.cs create mode 100644 CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/PdfBuilderProvider.cs create mode 100644 CaseAccounting/CaseAccountingContracts/BindingModels/MailConfigBindingModel.cs create mode 100644 CaseAccounting/CaseAccountingContracts/BindingModels/MailSendInfoBindingModel.cs create mode 100644 CaseAccounting/CaseAccountingContracts/ViewModels/CaseLawyerViewModel.cs create mode 100644 CaseAccounting/CaseAccountingProviderView/Views/Home/GetReport.cshtml create mode 100644 CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportpdf.js diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/MailSender.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/MailSender.cs new file mode 100644 index 0000000..04aba61 --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/MailSender.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mail; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using CaseAccountingContracts.BindingModels; + +namespace CaseAccountingBusinessLogic.BusinessLogics +{ + public class MailSender + { + private string mailLogin = string.Empty; + private string mailPassword = string.Empty; + private string smtpClientHost = string.Empty; + private int smtpClientPort; + + public MailSender(){} + + public void MailConfig(MailConfigBindingModel config) + { + mailLogin = config.MailLogin; + mailPassword = config.MailPassword; + smtpClientHost = config.SmtpClientHost; + smtpClientPort = config.SmtpClientPort; + } + + public async void SendMailAsync(MailSendInfoBindingModel info) + { + using var objMailMessage = new MailMessage(); + using var objSmtpClient = new SmtpClient(smtpClientHost, smtpClientPort); + try + { + objMailMessage.From = new MailAddress(mailLogin); + objMailMessage.To.Add(new MailAddress(info.MailAddress)); + objMailMessage.Subject = info.Subject; + objMailMessage.Body = info.Text; + objMailMessage.SubjectEncoding = Encoding.UTF8; + objMailMessage.BodyEncoding = Encoding.UTF8; + + MemoryStream ms = new(info.File); + objMailMessage.Attachments.Add(new Attachment(ms, "report.pdf", "application/pdf")); + + objSmtpClient.UseDefaultCredentials = false; + objSmtpClient.EnableSsl = true; + objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + objSmtpClient.Credentials = new NetworkCredential(mailLogin, mailPassword); + + await Task.Run(() => objSmtpClient.Send(objMailMessage)); + } + catch (Exception) + { + throw; + } + } + } +} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs index 773ba5d..f89dcba 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportProviderLogic.cs @@ -1,4 +1,5 @@ -using CaseAccountingBusinessLogic.OfficePackage; +using CaseAccountingBusinessLogic.BusinessLogic.OfficePackage; +using CaseAccountingBusinessLogic.OfficePackage; using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.SearchModels; @@ -20,10 +21,12 @@ namespace CaseAccountingBusinessLogic.BusinessLogics private readonly ILawyerStorage _lawyerStorage; private readonly WordBuilderProvider _wordBuilder; private readonly ExcelBuilderProvider _excelBuilder; - /*private readonly PdfBuilderProvider _pdfBuilder; - private readonly MailSender _mailSender;*/ + private readonly PdfBuilderProvider _pdfBuilder; + private readonly MailSender _mailSender; - public ReportProviderLogic(ICaseStorage caseStorage, ISpecializationStorage specializationStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, WordBuilderProvider wordBuilder, ExcelBuilderProvider excelBuilder) + public ReportProviderLogic(ICaseStorage caseStorage, ISpecializationStorage specializationStorage, IHearingStorage hearingStorage, + ILawyerStorage lawyerStorage, WordBuilderProvider wordBuilder, ExcelBuilderProvider excelBuilder, + PdfBuilderProvider pdfBuilder, MailSender mailSender) { _caseStorage = caseStorage ?? throw new ArgumentNullException(nameof(caseStorage)); _specializationStorage = specializationStorage ?? throw new ArgumentNullException(nameof(specializationStorage)); @@ -31,6 +34,8 @@ namespace CaseAccountingBusinessLogic.BusinessLogics _lawyerStorage = lawyerStorage ?? throw new ArgumentNullException(nameof(lawyerStorage)); _wordBuilder = wordBuilder ?? throw new ArgumentNullException(nameof(wordBuilder)); _excelBuilder = excelBuilder ?? throw new ArgumentNullException(nameof(excelBuilder)); + _pdfBuilder = pdfBuilder ?? throw new ArgumentNullException(nameof(pdfBuilder)); + _mailSender = mailSender ?? throw new ArgumentNullException(nameof(mailSender)); } public List GetCaseSpecialization(List models) @@ -77,33 +82,37 @@ namespace CaseAccountingBusinessLogic.BusinessLogics public List GetHearingLawyer(ReportBindingModel model) { - /*var hearings = _hearingStorage - .GetFilteredList(new HearingSearchModel { UserId = model.UserId}) + var hearings = _hearingStorage + .GetFilteredList(new HearingSearchModel { UserId = model.UserId }) .Where(x => model.DateFrom <= x.Date && model.DateTo >= x.Date); var list = new List(); foreach (var hearing in hearings) { var record = new ReportHearingLawyerViewModel { - Information = hearing.Information, - Date = hearing.Date, - Lawyers = new List<(string Surname, string Name, string Patronymic)>() + Hearing = "Номер слушания #" + hearing.Id.ToString(), + CaseLawyers = new() }; - foreach (var lawyer in _caseStorage.GetElement(new CaseSearchModel { Id = hearing.CaseId }).Lawyers.Values) + var caseId = _caseStorage.GetElement(new CaseSearchModel { Id = hearing.CaseId }).Id; + foreach (var lawyer in _lawyerStorage.GetLawyerMTM(caseId)) { - record.Lawyers.Add((lawyer.Surname, lawyer.Name, lawyer.Patronymic)); + record.CaseLawyers.Add(new CaseLawyerViewModel + { + Case = "Дело #" + caseId.ToString(), + Date = hearing.Date, + Lawyer = lawyer.Surname + " " + lawyer.Name + " " + lawyer.Patronymic + }); } list.Add(record); } - return list;*/ - return new(); + return list; } public byte[] SaveListFile(CaseSpecializationListBindingModel model) { byte[] file = Array.Empty(); - string title = "Список дисциплин по выбранным студентам"; + string title = "Список специализаций по выбраным делам"; if (model.FileType == "docx") { @@ -122,23 +131,23 @@ namespace CaseAccountingBusinessLogic.BusinessLogics return file; } - /*public void SendByMailStatusReport(ReportBindingModel reportModel) + public void SendByMailStatusReport(ReportBindingModel reportModel) { - byte[] file = _pdfBuilder.GetEducationStatusReportFile(new() + byte[] file = _pdfBuilder.GetHearingLawyerReportFile(new() { - Title = "Отчет по статусам обучения", + Title = "Отчет по слушаниям", DateFrom = reportModel.DateFrom, DateTo = reportModel.DateTo, - Records = GetStreamStudentEdStatPeriod(reportModel) + Records = GetHearingLawyer(reportModel) }); _mailSender.SendMailAsync(new() { MailAddress = reportModel.UserEmail, - Subject = "Отчет по статусам обучения", + Subject = "Отчет по слушаниям", Text = $"За период с {reportModel.DateFrom.ToShortDateString()} " + $"по {reportModel.DateTo.ToShortDateString()}.", File = file }); - }*/ + } } } diff --git a/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj b/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj index 873c5fb..6483872 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj +++ b/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj @@ -9,6 +9,7 @@ + diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs index 0f943f2..cde1622 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; diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs index e700285..907d785 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs @@ -1,7 +1,6 @@ using CaseAccountingBusinessLogic.OfficePackage; using CaseAccountingBusinessLogic.OfficePackage.HelperModels; using CaseAccountingContracts.ViewModels; -using ComputersShopBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/ExcelStyleInfoType.cs index 744d794..5fcd55f 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/ExcelStyleInfoType.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopBusinessLogic.OfficePackage.HelperEnums +namespace CaseAccountingBusinessLogic.OfficePackage.HelperEnums { public enum ExcelStyleInfoType { diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs index 89705ef..1423613 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopBusinessLogic.OfficePackage.HelperEnums +namespace CaseAccountingBusinessLogic.OfficePackage.HelperEnums { public enum PdfParagraphAlignmentType { diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/WordJustificationType.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/WordJustificationType.cs index 8d6e0c8..1dbd40b 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/WordJustificationType.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperEnums/WordJustificationType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopBusinessLogic.OfficePackage.HelperEnums +namespace CaseAccountingBusinessLogic.OfficePackage.HelperEnums { public enum WordJustificationType { diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelCellParameters.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelCellParameters.cs index 5f2b70a..267e22c 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelCellParameters.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -1,11 +1,11 @@ -using ComputersShopBusinessLogic.OfficePackage.HelperEnums; +using CaseAccountingBusinessLogic.OfficePackage.HelperEnums; using System; using System.Collections.Generic; 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..6e9bb69 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfParagraph.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfParagraph.cs @@ -1,11 +1,11 @@ -using ComputersShopBusinessLogic.OfficePackage.HelperEnums; +using CaseAccountingBusinessLogic.OfficePackage.HelperEnums; using System; using System.Collections.Generic; 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..10191ab 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfRowParameters.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/PdfRowParameters.cs @@ -1,11 +1,11 @@ -using ComputersShopBusinessLogic.OfficePackage.HelperEnums; +using CaseAccountingBusinessLogic.OfficePackage.HelperEnums; using System; using System.Collections.Generic; 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..2d198c7 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/WordTextProperties.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/HelperModels/WordTextProperties.cs @@ -1,11 +1,11 @@ -using ComputersShopBusinessLogic.OfficePackage.HelperEnums; +using CaseAccountingBusinessLogic.OfficePackage.HelperEnums; using System; using System.Collections.Generic; 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/PdfBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/PdfBuilderProvider.cs new file mode 100644 index 0000000..3d93fe6 --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/PdfBuilderProvider.cs @@ -0,0 +1,183 @@ +using CaseAccountingBusinessLogic.OfficePackage; +using CaseAccountingBusinessLogic.OfficePackage.HelperEnums; +using CaseAccountingBusinessLogic.OfficePackage.HelperModels; +using CaseAccountingContracts.ViewModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; +using PdfSharp.Pdf; +using System.Text; + +namespace CaseAccountingBusinessLogic.BusinessLogic.OfficePackage +{ + public class PdfBuilderProvider + { + private readonly string tempFileName = "temp.pdf"; + 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, + _ => ParagraphAlignment.Justify, + }; + } + + private 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; + } + + public void CreateDocument() + { + document = new Document(); + DefineStyles(document); + section = document.AddSection(); + } + + public 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; + } + + public void CreateTable(List columns) + { + if (document == null) + { + return; + } + table = document.LastSection.AddTable(); + foreach (var elem in columns) + { + table.AddColumn(elem); + } + } + + public 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; + } + } + + private void Save() + { + + // Регистрация провайдера кодировки для кодировки 1252, без этого ошибОчка была + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + + var renderer = new PdfDocumentRenderer(true) + { + Document = document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(tempFileName); + } + + public byte[] GetFile() + { + Save(); + byte[] file = File.ReadAllBytes(tempFileName); + File.Delete(tempFileName); + return file; + } + + public byte[] GetHearingLawyerReportFile(PdfData data) + { + CreateDocument(); + + CreateParagraph(new PdfParagraph + { + Text = data.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + CreateParagraph(new PdfParagraph + { + Text = $"за период с {data.DateFrom.ToShortDateString()} " + + $"по {data.DateTo.ToShortDateString()}", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + CreateTable(new List { "4cm","5cm", "3cm", "3cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер слушания", "Дело", "Дата проведения", "Юрист" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var record in data.Records) + { + List casesAndLawyes = record.CaseLawyers; + int recordHeight = casesAndLawyes.Count + 1; + for (int i = 0; i < recordHeight; i++) + { + List cellsData = new() { "", "", "", "" }; + if (i == 0) + { + cellsData[0] = record.Hearing; + CreateRow(new PdfRowParameters + { + Texts = cellsData, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + continue; + } + int k = i - 1; + if (k < casesAndLawyes.Count) + { + cellsData[1] = casesAndLawyes[k].Case; + cellsData[2] = casesAndLawyes[k].Date.ToString("yyyy-MM-dd"); + cellsData[3] = casesAndLawyes[k].Lawyer; + } + CreateRow(new PdfRowParameters + { + Texts = cellsData, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + } + + return GetFile(); + } + } +} diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/MailConfigBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..b2b3fce --- /dev/null +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingContracts.BindingModels +{ + public class MailConfigBindingModel + { + public string MailLogin { get; set; } = string.Empty; + public string MailPassword { get; set; } = string.Empty; + public string SmtpClientHost { get; set; } = string.Empty; + public int SmtpClientPort { get; set; } + } +} diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/MailSendInfoBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..5b78eea --- /dev/null +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingContracts.BindingModels +{ + public class MailSendInfoBindingModel + { + public string MailAddress { get; set; } = string.Empty; + public string Subject { get; set; } = string.Empty; + public string Text { get; set; } = string.Empty; + public byte[] File { get; set; } = Array.Empty(); + } +} diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/ReportBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/ReportBindingModel.cs index c857950..aeacfe6 100644 --- a/CaseAccounting/CaseAccountingContracts/BindingModels/ReportBindingModel.cs +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/ReportBindingModel.cs @@ -9,12 +9,9 @@ namespace CaseAccountingContracts.BindingModels { public class ReportBindingModel { - public string FileName { get; set; } = string.Empty; - - public DateTime? DateFrom { get; set; } - - public DateTime? DateTo { get; set; } - + public string UserEmail { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } public int? UserId { get; set; } } } diff --git a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs index 6e309b7..6f14f75 100644 --- a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs +++ b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportProviderLogic.cs @@ -15,5 +15,7 @@ namespace CaseAccountingContracts.BusinessLogicContracts List GetHearingLawyer(ReportBindingModel model); byte[] SaveListFile(CaseSpecializationListBindingModel model); + + void SendByMailStatusReport(ReportBindingModel reportModel); } } diff --git a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ILawyerStorage.cs b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ILawyerStorage.cs index 3d65820..1d55fe9 100644 --- a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ILawyerStorage.cs +++ b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ILawyerStorage.cs @@ -17,5 +17,6 @@ namespace CaseAccountingContracts.StoragesContracts LawyerViewModel? Insert(LawyerBindingModel model); LawyerViewModel? Update(LawyerBindingModel model); LawyerViewModel? Delete(LawyerBindingModel model); + List GetLawyerMTM(int caseId); } } diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/CaseLawyerViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/CaseLawyerViewModel.cs new file mode 100644 index 0000000..49d274c --- /dev/null +++ b/CaseAccounting/CaseAccountingContracts/ViewModels/CaseLawyerViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingContracts.ViewModels +{ + public class CaseLawyerViewModel + { + public string Case { get; set; } = string.Empty; + public DateTime Date { get; set; } + public string Lawyer { get; set; } = string.Empty; + } +} diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/ReportHearingLawyerViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/ReportHearingLawyerViewModel.cs index 7f897e9..ced286b 100644 --- a/CaseAccounting/CaseAccountingContracts/ViewModels/ReportHearingLawyerViewModel.cs +++ b/CaseAccounting/CaseAccountingContracts/ViewModels/ReportHearingLawyerViewModel.cs @@ -8,8 +8,7 @@ namespace CaseAccountingContracts.ViewModels { public class ReportHearingLawyerViewModel { - public string Information { get; set; } = string.Empty; - public DateTime Date { get; set; } - public List<(string Surname, string Name, string Patronymic)> Lawyers { get; set; } = new(); + public string Hearing { get; set; } = string.Empty; + public List CaseLawyers { get; set; } = new(); } } diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs index 37922b7..22f6501 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs @@ -158,7 +158,7 @@ namespace CaseAccountingDataBaseImplement.Implements { return null; } - _case.Update(model); + _case.Update(context, model); context.SaveChanges(); _case.UpdateLawyers(context, model); transaction.Commit(); diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/HearingStorage.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/HearingStorage.cs index 1d8e806..114a79a 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/HearingStorage.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/HearingStorage.cs @@ -129,7 +129,7 @@ namespace CaseAccountingDataBaseImplement.Implements { return null; } - hearing.Update(model); + hearing.Update(context, model); context.SaveChanges(); return context.Hearings .Include(x => x.Case) diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/LawyerStorage.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/LawyerStorage.cs index 43f37c4..7fd00ed 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/LawyerStorage.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/LawyerStorage.cs @@ -89,6 +89,20 @@ namespace CaseAccountingDataBaseImplement.Implements .Select(x => x.GetViewModel).ToList(); } + public List GetLawyerMTM(int caseId) + { + using var context = new CaseAccountingDatabase(); + var lawyersId = context.CaseLawyers + .Where(x => x.CaseId == caseId) + .Select(x => x.LawyerId).ToList(); + return context.Lawyers + .Include(x => x.Specialization) + .Include(x => x.User) + .Where(X => lawyersId.Contains(X.Id)) + .Select(x => x.GetViewModel) + .ToList(); + } + public LawyerViewModel? Insert(LawyerBindingModel model) { using var context = new CaseAccountingDatabase(); diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Case.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Case.cs index de9098b..ceaee53 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Case.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Case.cs @@ -87,15 +87,19 @@ namespace CaseAccountingDataBaseImplement.Models }; } - public void Update(CaseBindingModel model) + public void Update(CaseAccountingDatabase context, CaseBindingModel model) { if (model == null) { return; } Name = model.Name; + Applicant = model.Applicant; + Defendant = model.Defendant; + SpecializationId = model.SpecializationId; + Specialization = context.Specializations.FirstOrDefault(x => x.Id == model.SpecializationId) ?? throw new Exception("Specialization не существует"); Annotation = model.Annotation; - Date = model.Date; + Date = DateTime.SpecifyKind(model.Date, DateTimeKind.Utc); } public void UpdateLawyers(CaseAccountingDatabase context, CaseBindingModel model) diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs index b3fde5e..f1e7060 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Deal.cs @@ -80,7 +80,7 @@ namespace CaseAccountingDataBaseImplement.Models } Subject = model.Subject; Responsibilities = model.Responsibilities; - Date = model.Date; + Date = DateTime.SpecifyKind(model.Date, DateTimeKind.Utc); if (model.Contracts.Count > 0) { Contracts = model.Contracts.Select(x => new DealContract diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Hearing.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Hearing.cs index 5fe3fef..7a2f7fe 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Hearing.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Hearing.cs @@ -47,14 +47,16 @@ namespace CaseAccountingDataBaseImplement.Models }; } - public void Update (HearingBindingModel? model) + public void Update (CaseAccountingDatabase context, HearingBindingModel? model) { if (model == null) { return; } Information = model.Information; - Date = model.Date; + CaseId = model.CaseId; + Case = context.Cases.FirstOrDefault(x => x.Id == model.CaseId) ?? throw new Exception("Case не существует"); + DateTime.SpecifyKind(model.Date, DateTimeKind.Utc); } public HearingViewModel GetViewModel => new() diff --git a/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs b/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs index a699a99..108f168 100644 --- a/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs +++ b/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs @@ -52,6 +52,36 @@ namespace CaseAccountingProviderView.Controllers return file!.Select(b => (int)b).ToArray(); } + public IActionResult GetReport() + { + return View(); + } + + [HttpPost] + public List? GetReport([FromBody] ReportBindingModel reportModel) + { + if (APIUser.User == null) + { + return new(); + } + reportModel.UserId = APIUser.User.Id; + reportModel.UserEmail = APIUser.User.Login; + List? list = APIUser.PostRequestWithResult> + ("api/reportprovider/getreportdata", reportModel); + return list; + } + + [HttpPost] + public void SendByMailStatusReport([FromBody] ReportBindingModel reportModel) + { + if (APIUser.User == null) + { + return; + } + reportModel.UserId = APIUser.User.Id; + reportModel.UserEmail = APIUser.User.Login; + APIUser.PostRequest("api/reportprovider/sendbymailstatusreport", reportModel); + } [HttpPost] public void Login(string login, string password) diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Home/GetReport.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Home/GetReport.cshtml new file mode 100644 index 0000000..ade05e5 --- /dev/null +++ b/CaseAccounting/CaseAccountingProviderView/Views/Home/GetReport.cshtml @@ -0,0 +1,55 @@ +@{ + ViewData["Title"] = "Отчет"; +} + +
+

Отчет по слушаниям

+
+ +
+
+

+
+
+ +
+
+

Дата начала:

+ +
+
+

Дата конца:

+ +
+ + +
+ +

+ За период с  + ... +  по  + ... +

+
+
ИмяФамилияДата рожденияНомер студ. билетаСтатус обученияНомер дела:Истец:Ответчик:Дата составления:Примечание:Специализация:
+ + + + + + + + + + +
Номер слушанияДелоДата проведенияЮрист
+ + +
+ + \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml index 2f647fa..7a2155b 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml @@ -22,7 +22,7 @@ Договора Слушания Получение список - Получение отчёта + Получение отчёта diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportpdf.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportpdf.js new file mode 100644 index 0000000..b8f1c92 --- /dev/null +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportpdf.js @@ -0,0 +1,87 @@ +const dateFromInput = document.getElementById("date-from-input"); +const dateToInput = document.getElementById("date-to-input"); +const generateButton = document.getElementById("generate-button"); +const sendByMailButton = document.getElementById("send-by-mail-button"); +const dateToSpan = document.getElementById("date-to-span"); +const dateFromSpan = document.getElementById("date-from-span"); +const tbody = document.getElementById("tbody"); + +generateButton.addEventListener("click", () => { + const dateFrom = new Date(dateFromInput.value); + const dateTo = new Date(dateToInput.value); + const reportModel = { + "DateFrom": dateFrom, + "DateTo": dateTo + }; + $.ajax({ + url: "/home/getreport", + type: "POST", + contentType: "application/json", + data: JSON.stringify(reportModel) + }).done((data) => { + dateFromSpan.innerHTML = reportModel["DateFrom"].toLocaleDateString(); + dateToSpan.innerHTML = reportModel["DateTo"].toLocaleDateString(); + renderTable(data); + }); +}); + +const formatDate = (dateString) => { + const date = new Date(dateString); + const year = date.getFullYear(); + const month = ('0' + (date.getMonth() + 1)).slice(-2); + const day = ('0' + date.getDate()).slice(-2); + return `${year}-${month}-${day}`; +}; + +sendByMailButton.addEventListener("click", () => { + const dateFrom = new Date(dateFromInput.value); + const dateTo = new Date(dateToInput.value); + const reportModel = { + "DateFrom": dateFrom, + "DateTo": dateTo + }; + $.ajax({ + url: "/home/sendbymailstatusreport", + type: "POST", + contentType: "application/json", + data: JSON.stringify(reportModel) + }).done(() => { + alert("Отчет успешно отправлен на вашу почту!") + }); +}); + + + +const renderTable = (data) => { + tbody.innerHTML = ""; + + for (var i = 0; i < data.length; i++) { + var hearingData = data[i]; + var hearingName = hearingData.hearing; + + for (var j = 0; j < hearingData.caseLawyers.length; j++) { + var info = hearingData.caseLawyers[j]; + + if (j === 0) { + var row = tbody.insertRow(); + var hearingNameCell = row.insertCell() + hearingNameCell.textContent = hearingName; + var caseNameCell = row.insertCell(); + var dateCell = row.insertCell(); + var lawyerCell = row.insertCell(); + tbody.appendChild(row) + } + + var row = tbody.insertRow(); + var hearingNameCell = row.insertCell() + var caseNameCell = row.insertCell(); + caseNameCell.textContent = info.case; + var dateCell = row.insertCell(); + dateCell.textContent = formatDate(info.date); + var lawyerCell = row.insertCell(); + lawyerCell.textContent = info.lawyer; + + tbody.appendChild(row); + } + } +} diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs index 76d1df6..594deac 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/ReportProviderController.cs @@ -1,5 +1,6 @@ using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace CaseAccountingRestApi.Controllers @@ -21,5 +22,18 @@ namespace CaseAccountingRestApi.Controllers byte[] file = reportLogic.SaveListFile(listModel); return file; } + + [HttpPost] + public List GetReportData(ReportBindingModel reportModel) + { + var list = reportLogic.GetHearingLawyer(reportModel); + return list; + } + + [HttpPost] + public void SendByMailStatusReport(ReportBindingModel reportModel) + { + reportLogic.SendByMailStatusReport(reportModel); + } } } diff --git a/CaseAccounting/CaseAccountingRestApi/Program.cs b/CaseAccounting/CaseAccountingRestApi/Program.cs index 6ed555e..2f6c3c2 100644 --- a/CaseAccounting/CaseAccountingRestApi/Program.cs +++ b/CaseAccounting/CaseAccountingRestApi/Program.cs @@ -1,5 +1,7 @@ +using CaseAccountingBusinessLogic.BusinessLogic.OfficePackage; using CaseAccountingBusinessLogic.BusinessLogics; using CaseAccountingBusinessLogic.OfficePackage; +using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.StoragesContracts; using CaseAccountingDataBaseImplement.Implements; @@ -31,6 +33,9 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddSingleton(); builder.Services.AddControllers().AddNewtonsoftJson(); @@ -48,6 +53,15 @@ builder.Services.AddSwaggerGen(c => var app = builder.Build(); +var mailSender = app.Services.GetService(); +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), +}); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/CaseAccounting/CaseAccountingRestApi/appsettings.json b/CaseAccounting/CaseAccountingRestApi/appsettings.json index 10f68b8..fbacc1d 100644 --- a/CaseAccounting/CaseAccountingRestApi/appsettings.json +++ b/CaseAccounting/CaseAccountingRestApi/appsettings.json @@ -5,5 +5,11 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "rpplabs098@gmail.com", + "MailPassword": "sxwf ohjr cgba wext" } From 9c75a284f7412bd81f949e3a09c43026ebb6491c Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 20 May 2023 04:01:37 +0400 Subject: [PATCH 06/13] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D1=81=D1=8C=20=D1=87=D1=83=D1=82=D1=8C-=D1=87=D1=83=D1=82?= =?UTF-8?q?=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/js/case/case-update.js | 29 +++++++++++++++++++ .../wwwroot/js/deal/deal-update.js | 16 ++++++++++ .../wwwroot/js/hearing/hearing-update.js | 17 +++++++++++ 3 files changed, 62 insertions(+) diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js index 952ab06..14d1791 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js @@ -9,8 +9,32 @@ const caseId = document.getElementById("vb-id").dataset.id; var specializations = []; +const formatDate = (dateString) => { + const date = new Date(dateString); + const year = date.getFullYear(); + const month = ('0' + (date.getMonth() + 1)).slice(-2); + const day = ('0' + date.getDate()).slice(-2); + return `${year}-${month}-${day}`; +}; + window.addEventListener("load", async () => { try { + let specializationId; + await $.ajax({ + url: `/case/get?id=${caseId}`, + type: "GET", + contentType: "json" + }).done((result) => { + nameInput.value = result.name; + applicantInput.value = result.applicant; + defendantInput.value = result.defendant; + annotationInput.value = result.annotation; + dateInput.value = formatDate(result.date); + specializationId = result.specializationId; + }); + + let specializationIndex; + await $.ajax({ url: `/case/getallspecializations`, type: "GET", @@ -22,9 +46,14 @@ window.addEventListener("load", async () => { option.value = specialization.id; option.innerHTML = specialization.name; specializationSelect.appendChild(option); + if(specialization.id === specializationId){ + specializationIndex = specializationSelect.selectedIndex; + } specializationSelect.selectedIndex = -1; }); }); + + specializationSelect.selectedIndex = specializationIndex; } catch (error) { console.error(error); } diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js index 9ca9a0f..f5ceec4 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js @@ -4,6 +4,22 @@ const responsibilitiesInput = document.getElementById("responsibilities-input"); const dateInput = document.getElementById("date-input"); const dealId = document.getElementById("vb-id").dataset.id; +window.addEventListener("load", async () => { + try { + await $.ajax({ + url: `/deal/get?id=${dealId}`, + type: "GET", + contentType: "json" + }).done((result) => { + subjectInput.value = result.subject; + responsibilitiesInput.value = result.responsibilities; + dateInput.value = new Date(result.date); + }); + } catch (error) { + console.error(error); + } +}); + updateBtn.addEventListener("click", () => { if (!correctData()) { return; diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js index 14101ea..32f48a0 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js @@ -8,6 +8,18 @@ var cases = []; window.addEventListener("load", async () => { try { + let caseId; + await $.ajax({ + url: `/hearing/get?id=${hearingId}`, + type: "GET", + contentType: "json" + }).done((result) => { + informationInput.value = result.information; + dateInput.value = new Date(result.date); + caseId = result.caseId; + }); + + let caseIndex; $.ajax({ url: "/case/getallbyuser", type: "GET", @@ -19,9 +31,14 @@ window.addEventListener("load", async () => { option.value = element.id; option.innerHTML = "Дело №" + element.id; caseSelect.appendChild(option); + if(element.id === caseId){ + caseIndex = caseSelect.selectedIndex; + } caseSelect.selectedIndex = -1; }); }); + + caseSelect.selectedIndex = caseIndex; } catch (error) { console.error(error); } From 636af51602c880b01b2851430ceae42c558af7ea Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 20 May 2023 04:14:14 +0400 Subject: [PATCH 07/13] =?UTF-8?q?=D0=9F=D0=BE=D1=84=D0=B8=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B1=D0=B0=D0=B3=D0=B8=20=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D0=BB=D0=B5=20=D1=81=D0=BB=D0=B8=D1=8F=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OfficePackage/ExcelBuilderCustomer.cs | 2 +- .../wwwroot/js/Specializations/specialization-update.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs index fb68a2a..d4c3201 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderCustomer.cs @@ -356,6 +356,6 @@ namespace CaseAccountingBusinessLogic.OfficePackage currentRow++; } } - }*/ + } } } diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Specializations/specialization-update.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Specializations/specialization-update.js index 2983f1d..59d230d 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Specializations/specialization-update.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Specializations/specialization-update.js @@ -1,5 +1,4 @@ -const updateBtn = - .getElementById("update-button"); +const updateBtn = document.getElementById("update-button"); const nameInput = document.getElementById("name-input") const specializationId = document.getElementById("spec-id").dataset.id From db5681fc25353cb13e42e60c0dcfd16d8ce120a8 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 20 May 2023 05:04:42 +0400 Subject: [PATCH 08/13] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B4=D0=B8=D0=B0=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/CaseLogic.cs | 5 ++ .../BusinessLogicContracts/ICaseLogic.cs | 1 + .../StoragesContracts/ICaseStorage.cs | 1 + .../SpecializationCasesViewModel.cs | 14 +++++ .../Implements/CaseStorage.cs | 17 ++++++ .../Controllers/CaseController.cs | 12 ++++- .../Controllers/HomeController.cs | 5 ++ .../Views/Home/Diagram.cshtml | 15 ++++++ .../Views/Shared/_Layout.cshtml | 1 + .../wwwroot/js/case/case-update.js | 13 +---- .../wwwroot/js/deal/deal-update.js | 12 ++++- .../wwwroot/js/diagram/diagram.js | 52 +++++++++++++++++++ .../wwwroot/js/hearing/hearing-update.js | 23 ++++---- .../Controllers/CaseController.cs | 15 +++++- 14 files changed, 159 insertions(+), 27 deletions(-) create mode 100644 CaseAccounting/CaseAccountingContracts/ViewModels/SpecializationCasesViewModel.cs create mode 100644 CaseAccounting/CaseAccountingProviderView/Views/Home/Diagram.cshtml create mode 100644 CaseAccounting/CaseAccountingProviderView/wwwroot/js/diagram/diagram.js diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/CaseLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/CaseLogic.cs index d4f6ae9..f18fee6 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/CaseLogic.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/CaseLogic.cs @@ -76,6 +76,11 @@ namespace CaseAccountingBusinessLogic.BusinessLogics return list; } + public List GetSpecializationCases() + { + return _caseStorage.GetSpecializationCases() ?? new List(); + } + public bool Update(CaseBindingModel model) { CheckModel(model); diff --git a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/ICaseLogic.cs b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/ICaseLogic.cs index 61eba68..9e315a0 100644 --- a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/ICaseLogic.cs +++ b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/ICaseLogic.cs @@ -16,5 +16,6 @@ namespace CaseAccountingContracts.BusinessLogicContracts bool Create(CaseBindingModel model); bool Update(CaseBindingModel model); bool Delete(CaseBindingModel model); + List GetSpecializationCases(); } } diff --git a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs index 9570d06..a119f8c 100644 --- a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs +++ b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs @@ -19,5 +19,6 @@ namespace CaseAccountingContracts.StoragesContracts CaseViewModel? Delete(CaseBindingModel model); List GetCaseHearings(CaseSearchModel model); + List? GetSpecializationCases(); } } diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/SpecializationCasesViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/SpecializationCasesViewModel.cs new file mode 100644 index 0000000..ec5af5a --- /dev/null +++ b/CaseAccounting/CaseAccountingContracts/ViewModels/SpecializationCasesViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CaseAccountingContracts.ViewModels +{ + public class SpecializationCasesViewModel + { + public int Count { get; set; } + public string Name { get; set; } = string.Empty; + } +} diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs index 1aefcda..c665ae2 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs @@ -185,5 +185,22 @@ namespace CaseAccountingDataBaseImplement.Implements return hearings; } + public List? GetSpecializationCases() + { + using var context = new CaseAccountingDatabase(); + var result = context.Specializations + .GroupJoin( + context.Cases, + status => status.Id, + caseModel => caseModel.SpecializationId, + (status, caseModels) => new SpecializationCasesViewModel + { + Name = status.Name, + Count = caseModels.Count() + }) + .ToList(); + + return result; + } } } diff --git a/CaseAccounting/CaseAccountingProviderView/Controllers/CaseController.cs b/CaseAccounting/CaseAccountingProviderView/Controllers/CaseController.cs index b8a7fbb..59afe56 100644 --- a/CaseAccounting/CaseAccountingProviderView/Controllers/CaseController.cs +++ b/CaseAccounting/CaseAccountingProviderView/Controllers/CaseController.cs @@ -129,5 +129,15 @@ namespace CaseAccountingProviderView.Controllers List? specializationModel = APIUser.GetRequest>($"api/case/getallspecializations"); return specializationModel ?? new(); } - } + + public List GetSpecializationCases() + { + if (APIUser.User == null) + { + return new(); + } + List? specializationCases = APIUser.GetRequest>($"api/case/getspecializationcases"); + return specializationCases ?? new(); + } + } } diff --git a/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs b/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs index 108f168..f94615e 100644 --- a/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs +++ b/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs @@ -40,6 +40,11 @@ namespace CaseAccountingProviderView.Controllers return View(); } + public IActionResult Diagram() + { + return View(); + } + [HttpPost] public int[]? SpecializationCaselist([FromBody] CaseSpecializationListBindingModel listModel) { diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Home/Diagram.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Home/Diagram.cshtml new file mode 100644 index 0000000..a125855 --- /dev/null +++ b/CaseAccounting/CaseAccountingProviderView/Views/Home/Diagram.cshtml @@ -0,0 +1,15 @@ + +
+

Круговая диаграмма

+
+ +
+ +
+ +
+
+ + + + diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml index 7a2155b..e3fdc9e 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml @@ -23,6 +23,7 @@ Слушания Получение список Получение отчёта + Формирование диаграммы diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js index 14d1791..fd188d6 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js @@ -19,7 +19,6 @@ const formatDate = (dateString) => { window.addEventListener("load", async () => { try { - let specializationId; await $.ajax({ url: `/case/get?id=${caseId}`, type: "GET", @@ -30,11 +29,8 @@ window.addEventListener("load", async () => { defendantInput.value = result.defendant; annotationInput.value = result.annotation; dateInput.value = formatDate(result.date); - specializationId = result.specializationId; }); - - let specializationIndex; - + await $.ajax({ url: `/case/getallspecializations`, type: "GET", @@ -46,14 +42,9 @@ window.addEventListener("load", async () => { option.value = specialization.id; option.innerHTML = specialization.name; specializationSelect.appendChild(option); - if(specialization.id === specializationId){ - specializationIndex = specializationSelect.selectedIndex; - } specializationSelect.selectedIndex = -1; }); }); - - specializationSelect.selectedIndex = specializationIndex; } catch (error) { console.error(error); } @@ -84,7 +75,7 @@ updateBtn.addEventListener("click", () => { "Name": nameInput.value, "Applicant": applicantInput.value, "Defendant": defendantInput.value, - "Date": new Date(dateInput.value), + "Date": dateInput.value, "Annotation": annotationInput.value, "SpecializationId": parseInt(specializationSelect.value), }; diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js index f5ceec4..fe91795 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js @@ -4,6 +4,14 @@ const responsibilitiesInput = document.getElementById("responsibilities-input"); const dateInput = document.getElementById("date-input"); const dealId = document.getElementById("vb-id").dataset.id; +const formatDate = (dateString) => { + const date = new Date(dateString); + const year = date.getFullYear(); + const month = ('0' + (date.getMonth() + 1)).slice(-2); + const day = ('0' + date.getDate()).slice(-2); + return `${year}-${month}-${day}`; +}; + window.addEventListener("load", async () => { try { await $.ajax({ @@ -13,7 +21,7 @@ window.addEventListener("load", async () => { }).done((result) => { subjectInput.value = result.subject; responsibilitiesInput.value = result.responsibilities; - dateInput.value = new Date(result.date); + dateInput.value = formatDate(result.date); }); } catch (error) { console.error(error); @@ -44,7 +52,7 @@ updateBtn.addEventListener("click", () => { "Id": parseInt(dealId), "Subject": subjectInput.value, "Responsibilities": responsibilitiesInput.value, - "Date": new Date(dateInput.value) + "Date": dateInput.value }; console.log(dealModel) $.ajax({ diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/diagram/diagram.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/diagram/diagram.js new file mode 100644 index 0000000..7ecbf31 --- /dev/null +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/diagram/diagram.js @@ -0,0 +1,52 @@ +var btnStatus = document.getElementById('btnStatus'); +var casespecializations = []; + +window.addEventListener('load', async () => { + await $.ajax({ + url: "/case/getspecializationcases", + type: "GET", + contentType: "json" + }).done((result) => { + casespecializations = result; + console.log(casespecializations); + }); +}) + +var ctx = document.getElementById('myChart').getContext('2d'); +var chart; + +function drawStatusChart() { + var edStatus = []; + var edCount = []; + console.log(casespecializations) + casespecializations.forEach((item) => { + edStatus.push(item.name); + }); + casespecializations.forEach((item) => { + edCount.push(item.count); + }); + var statusData = { + labels: edStatus, + datasets: [{ + data: edCount + }] + }; + + // Clear the previous chart if it exists + if (chart) { + chart.destroy(); + } + + chart = new Chart(ctx, { + type: 'pie', + data: statusData, + options: { + responsive: true + } + }); +} + +btnStatus.addEventListener('click', function () { + drawStatusChart(); +}); + diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js index 32f48a0..3ee7b8e 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js @@ -6,21 +6,25 @@ const hearingId = document.getElementById("vb-id").dataset.id; var cases = []; +const formatDate = (dateString) => { + const date = new Date(dateString); + const year = date.getFullYear(); + const month = ('0' + (date.getMonth() + 1)).slice(-2); + const day = ('0' + date.getDate()).slice(-2); + return `${year}-${month}-${day}`; +}; + window.addEventListener("load", async () => { try { - let caseId; await $.ajax({ url: `/hearing/get?id=${hearingId}`, type: "GET", contentType: "json" }).done((result) => { informationInput.value = result.information; - dateInput.value = new Date(result.date); - caseId = result.caseId; + dateInput.value = formatDate(result.date); }); - - let caseIndex; - $.ajax({ + await $.ajax({ url: "/case/getallbyuser", type: "GET", contentType: "json" @@ -31,14 +35,9 @@ window.addEventListener("load", async () => { option.value = element.id; option.innerHTML = "Дело №" + element.id; caseSelect.appendChild(option); - if(element.id === caseId){ - caseIndex = caseSelect.selectedIndex; - } caseSelect.selectedIndex = -1; }); }); - - caseSelect.selectedIndex = caseIndex; } catch (error) { console.error(error); } @@ -68,7 +67,7 @@ updateBtn.addEventListener("click", () => { "Id": parseInt(hearingId), "Information": informationInput.value, "CaseId": parseInt(caseSelect.value), - "Date": new Date(dateInput.value) + "Date": dateInput.value }; console.log(hearingModel) $.ajax({ diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs index 0e4ee2c..cf8bf50 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs @@ -59,7 +59,20 @@ namespace CaseAccountingRestApi.Controllers } } - [HttpPost] + [HttpGet] + public List GetSpecializationCases() + { + try + { + return _logic.GetSpecializationCases(); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] public void Create(CaseBindingModel model) { try From 92c6c1c5032694be2f04e883a433d6be796af3a1 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 20 May 2023 09:10:45 +0400 Subject: [PATCH 09/13] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/Case/Create.cshtml | 2 +- .../Views/Case/Update.cshtml | 2 +- .../Views/Deal/Create.cshtml | 2 +- .../Views/Deal/Update.cshtml | 2 +- .../Views/Hearing/Create.cshtml | 2 +- .../Views/Hearing/Update.cshtml | 2 +- .../wwwroot/js/case/case-create.js | 43 +++++++++++++------ .../wwwroot/js/case/case-update.js | 43 +++++++++++++------ .../wwwroot/js/deal/deal-bind.js | 20 ++++----- .../wwwroot/js/deal/deal-create.js | 42 ++++++++++++------ .../wwwroot/js/deal/deal-update.js | 33 ++++++++++---- .../wwwroot/js/hearing/hearing-create.js | 28 ++++++------ .../wwwroot/js/hearing/hearing-update.js | 18 ++++---- .../wwwroot/js/report/reportlist.js | 4 +- 14 files changed, 156 insertions(+), 87 deletions(-) diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Case/Create.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Case/Create.cshtml index 629984a..12a0aca 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Case/Create.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Case/Create.cshtml @@ -6,7 +6,7 @@
-

+

diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Case/Update.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Case/Update.cshtml index ab2d11d..1ba778b 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Case/Update.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Case/Update.cshtml @@ -14,7 +14,7 @@
-

+

diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Deal/Create.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Deal/Create.cshtml index 78666c5..1131767 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Deal/Create.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Deal/Create.cshtml @@ -6,7 +6,7 @@
-

+

diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Deal/Update.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Deal/Update.cshtml index 5740afe..f8dc2a3 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Deal/Update.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Deal/Update.cshtml @@ -14,7 +14,7 @@
-

+

diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Hearing/Create.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Hearing/Create.cshtml index 8e914d8..d689b05 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Hearing/Create.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Hearing/Create.cshtml @@ -6,7 +6,7 @@
-

+

diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Hearing/Update.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Hearing/Update.cshtml index 87b7e2f..5dcf48a 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Hearing/Update.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Hearing/Update.cshtml @@ -14,7 +14,7 @@
-

+

diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-create.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-create.js index af048a8..761e275 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-create.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-create.js @@ -5,6 +5,8 @@ const defendantInput = document.getElementById("defendant-input"); const annotationInput = document.getElementById("annotation-input"); const dateInput = document.getElementById("date-input"); const specializationSelect = document.getElementById("specialization-select"); +const errorP = document.getElementById("error-p"); +const errorDivShell = document.getElementById("error-div-shell"); var specializations = []; @@ -29,6 +31,35 @@ window.addEventListener("load", async () => { } }); +const correctData = function () { + + return true; +}; + +const validate = function () { + if (nameInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Название дела'"; + return false; + } + if (applicantInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Истец'"; + return false; + } + if (defendantInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Ответчик'"; + return false; + } + if (annotationInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Примечание'"; + return false; + } + return true; +}; + createBtn.addEventListener("click", () => { if (!correctData()) { return; @@ -36,19 +67,7 @@ createBtn.addEventListener("click", () => { if (!validate()) { return; } -}); -const correctData = function () { - - return true; -}; - -const validate = function () { - - return true; -}; - -createBtn.addEventListener("click", () => { let caseModel = { "Name": nameInput.value, "Applicant": applicantInput.value, diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js index fd188d6..c731be4 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js @@ -6,6 +6,8 @@ const annotationInput = document.getElementById("annotation-input"); const dateInput = document.getElementById("date-input"); const specializationSelect = document.getElementById("specialization-select"); const caseId = document.getElementById("vb-id").dataset.id; +const errorP = document.getElementById("error-p"); +const errorDivShell = document.getElementById("error-div-shell"); var specializations = []; @@ -50,6 +52,35 @@ window.addEventListener("load", async () => { } }); +const correctData = function () { + + return true; +}; + +const validate = function () { + if (nameInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Название дела'"; + return false; + } + if (applicantInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Истец'"; + return false; + } + if (defendantInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Ответчик'"; + return false; + } + if (annotationInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Примечание'"; + return false; + } + return true; +}; + updateBtn.addEventListener("click", () => { if (!correctData()) { return; @@ -57,19 +88,7 @@ updateBtn.addEventListener("click", () => { if (!validate()) { return; } -}); -const correctData = function () { - - return true; -}; - -const validate = function () { - - return true; -}; - -updateBtn.addEventListener("click", () => { let caseModel = { "Id": parseInt(caseId), "Name": nameInput.value, diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-bind.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-bind.js index e3eaacc..3f970ee 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-bind.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-bind.js @@ -43,15 +43,6 @@ window.addEventListener("load", async () => { } }); -saveBtn.addEventListener("click", () => { - if (!correctData()) { - return; - } - if (!validate()) { - return; - } -}); - const correctData = function () { return true; @@ -63,6 +54,13 @@ const validate = function () { }; saveBtn.addEventListener("click", () => { + if (!correctData()) { + return; + } + if (!validate()) { + return; + } + let dealModel = { "Id": currentDeal.id, "Subject": currentDeal.subject, @@ -88,10 +86,10 @@ const addAndRemoveFromList = (row) => { var index = dataArray.indexOf(contracts.find(x => x.id === id)); if (index === -1) { dataArray.push(contracts.find(x => x.id === id)); - row.classList.add("bg-primary"); + row.classList.add("bg-info"); } else { dataArray.splice(index, 1); - row.classList.remove("bg-primary"); + row.classList.remove("bg-info"); } console.log(dataArray); } \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-create.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-create.js index fefc4f5..c7ac42d 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-create.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-create.js @@ -3,6 +3,8 @@ const subjectInput = document.getElementById("subject-input"); const responsibilitiesInput = document.getElementById("responsibilities-input"); const dateInput = document.getElementById("date-input"); const tbody = document.getElementById("scrollable-table__tbody") +const errorP = document.getElementById("error-p"); +const errorDivShell = document.getElementById("error-div-shell"); var cases = []; var dataArray = []; @@ -34,6 +36,30 @@ window.addEventListener("load", async () => { } }); +const correctData = function () { + + return true; +}; + +const validate = function () { + if (subjectInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Предмет договора'"; + return false; + } + if (responsibilitiesInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Обязаности'"; + return false; + } + if (dataArray.length === 0) { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните список 'Дел'"; + return false; + } + return true; +}; + createBtn.addEventListener("click", () => { if (!correctData()) { return; @@ -41,19 +67,7 @@ createBtn.addEventListener("click", () => { if (!validate()) { return; } -}); -const correctData = function () { - - return true; -}; - -const validate = function () { - - return true; -}; - -createBtn.addEventListener("click", () => { let dealModel = { "Subject": subjectInput.value, "Responsibilities": responsibilitiesInput.value, @@ -77,10 +91,10 @@ const addAndRemoveFromList = (row) => { var index = dataArray.indexOf(cases.find(x => x.id === id)); if (index === -1) { dataArray.push(cases.find(x => x.id === id)); - row.classList.add("bg-primary"); + row.classList.add("bg-info"); } else { dataArray.splice(index, 1); - row.classList.remove("bg-primary"); + row.classList.remove("bg-info"); } console.log(dataArray); } \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js index fe91795..0927757 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/deal/deal-update.js @@ -3,6 +3,8 @@ const subjectInput = document.getElementById("subject-input"); const responsibilitiesInput = document.getElementById("responsibilities-input"); const dateInput = document.getElementById("date-input"); const dealId = document.getElementById("vb-id").dataset.id; +const errorP = document.getElementById("error-p"); +const errorDivShell = document.getElementById("error-div-shell"); const formatDate = (dateString) => { const date = new Date(dateString); @@ -28,15 +30,6 @@ window.addEventListener("load", async () => { } }); -updateBtn.addEventListener("click", () => { - if (!correctData()) { - return; - } - if (!validate()) { - return; - } -}); - const correctData = function () { return true; @@ -44,10 +37,32 @@ const correctData = function () { const validate = function () { + if (subjectInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Предмет договора'"; + return false; + } + if (responsibilitiesInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Обязаности'"; + return false; + } + if (dataArray.length === 0) { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните список 'Дел'"; + return false; + } return true; }; updateBtn.addEventListener("click", () => { + if (!correctData()) { + return; + } + if (!validate()) { + return; + } + let dealModel = { "Id": parseInt(dealId), "Subject": subjectInput.value, diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-create.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-create.js index 6a0c41b..d318c01 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-create.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-create.js @@ -2,6 +2,8 @@ const informationInput = document.getElementById("information-input"); const dateInput = document.getElementById("date-input"); const caseSelect = document.getElementById("case-select"); +const errorP = document.getElementById("error-p"); +const errorDivShell = document.getElementById("error-div-shell"); var cases = []; @@ -26,6 +28,20 @@ window.addEventListener("load", async () => { } }); +const correctData = function () { + + return true; +}; + +const validate = function () { + if (informationInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Информация по слушанию'"; + return false; + } + return true; +}; + createBtn.addEventListener("click", () => { if (!correctData()) { return; @@ -33,19 +49,7 @@ createBtn.addEventListener("click", () => { if (!validate()) { return; } -}); -const correctData = function () { - - return true; -}; - -const validate = function () { - - return true; -}; - -createBtn.addEventListener("click", () => { let hearingModel = { "Information": informationInput.value, "CaseId": parseInt(caseSelect.value), diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js index 3ee7b8e..1bf6d5f 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js @@ -3,6 +3,8 @@ const informationInput = document.getElementById("information-input"); const dateInput = document.getElementById("date-input"); const caseSelect = document.getElementById("case-select"); const hearingId = document.getElementById("vb-id").dataset.id; +const errorP = document.getElementById("error-p"); +const errorDivShell = document.getElementById("error-div-shell"); var cases = []; @@ -43,15 +45,6 @@ window.addEventListener("load", async () => { } }); -updateBtn.addEventListener("click", () => { - if (!correctData()) { - return; - } - if (!validate()) { - return; - } -}); - const correctData = function () { return true; @@ -63,6 +56,13 @@ const validate = function () { }; updateBtn.addEventListener("click", () => { + if (!correctData()) { + return; + } + if (!validate()) { + return; + } + let hearingModel = { "Id": parseInt(hearingId), "Information": informationInput.value, diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js index b5115ef..190e668 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js @@ -82,10 +82,10 @@ const addAndRemoveFromList = (row) => { var index = dataArray.indexOf(cases.find(x => x.id === id)); if (index === -1) { dataArray.push(cases.find(x => x.id === id)); - row.classList.add("bg-primary"); + row.classList.add("bg-info"); } else { dataArray.splice(index, 1); - row.classList.remove("bg-primary"); + row.classList.remove("bg-info"); } console.log(dataArray); } From 2cca5bd9b92e1040f95730993cc4742fabf747b7 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 20 May 2023 09:55:10 +0400 Subject: [PATCH 10/13] =?UTF-8?q?=D0=95=D1=89=D1=91=20=D0=BD=D0=B5=D0=BC?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/js/case/case-create.js | 5 +++++ .../wwwroot/js/case/case-update.js | 5 +++++ .../wwwroot/js/hearing/hearing-create.js | 5 +++++ .../wwwroot/js/hearing/hearing-update.js | 11 ++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-create.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-create.js index 761e275..dff80e6 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-create.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-create.js @@ -57,6 +57,11 @@ const validate = function () { errorP.innerHTML = "Заполните поле 'Примечание'"; return false; } + if (specializationSelect.value === '') { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Выберите 'Специализацию'"; + return false; + } return true; }; diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js index c731be4..bf48191 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/case/case-update.js @@ -78,6 +78,11 @@ const validate = function () { errorP.innerHTML = "Заполните поле 'Примечание'"; return false; } + if (specializationSelect.value === '') { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Выберите 'Специализацию'"; + return false; + } return true; }; diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-create.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-create.js index d318c01..6744802 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-create.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-create.js @@ -39,6 +39,11 @@ const validate = function () { errorP.innerHTML = "Заполните поле 'Информация по слушанию'"; return false; } + if (caseSelect.value === '') { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Выберите 'Дело'"; + return false; + } return true; }; diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js index 1bf6d5f..9d776b4 100644 --- a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js +++ b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/hearing/hearing-update.js @@ -51,7 +51,16 @@ const correctData = function () { }; const validate = function () { - + if (informationInput.value === "") { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Заполните поле 'Информация по слушанию'"; + return false; + } + if (caseSelect.value === '') { + errorDivShell.style.gridTemplateRows = "1fr"; + errorP.innerHTML = "Выберите 'Дело'"; + return false; + } return true; }; From 33d22bbb246cf6f5f419b23837fe6821ec94a49a Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 20 May 2023 11:00:13 +0400 Subject: [PATCH 11/13] fix update lawyer --- .../Controllers/Lawyers.cs | 7 +++++ .../wwwroot/js/Lawyers/lawyer-update.js | 26 +++++++++++-------- .../wwwroot/js/Report/reportlist.js | 2 +- .../Models/Lawyer.cs | 7 +++++ .../Views/Shared/_Layout.cshtml | 2 +- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs index 1f0e19c..ba8c8bd 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs +++ b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs @@ -61,6 +61,13 @@ namespace CaseAccountingCustomerView.Controllers dict.Add(element.Id, _case); } lawyerModel.Cases = dict; + var dictContr = new Dictionary(); + foreach (var element in lawyerModel.ContractViewModels) + { + var contract = APIUser.GetRequest($"api/contract/get?id={element.Id}"); + dictContr.Add(element.Id, contract); + } + lawyerModel.Contracts = dictContr; APIUser.PostRequest("api/lawyer/update", lawyerModel); Response.Redirect("/Home/Lawyers"); } diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js index 1c3a921..a0c0cc2 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js @@ -1,7 +1,9 @@ const createBtn = document.getElementById("create-button"); const tbody = document.getElementById("scrollable-table__tbody"); -const serviceInput = document.getElementById("service-input"); -const coastInput = document.getElementById("coast-input"); +const nameInput = document.getElementById("name-input") +const surnameInput = document.getElementById("surname-input") +const patronymicInput = document.getElementById("patronymic-input") +const experienceInput = document.getElementById("experience-input") const currentLawyerId = document.getElementById("lawyer-id").dataset.id; var contracts = []; var dataArray = []; @@ -17,7 +19,7 @@ window.addEventListener('load', async () => { }); console.log(currentLawyerId) await $.ajax({ - url: "/lawyers/get?id=${currentLawyerId}", + url: `/lawyers/get?id=${currentLawyerId}`, type: "GET", contentType: "json" }).done((result) => { @@ -36,23 +38,25 @@ window.addEventListener('load', async () => { cell.textContent = value; }); console.log(currentLawyer); - if (currentLawyer.ContractViewModels.find(x => parseInt(x.id) === parseInt(contract.id))) { + /*if (currentLawyer.сontractViewModels.find(x => parseInt(x.id) === parseInt(contract.id))) { row.classList.add("bg-success"); dataArray.push(contract); - } + }*/ row.addEventListener('click', () => addAndRemoveFromList(row)); }); }) createBtn.addEventListener('click', () => { + console.log(dataArray); var lawyerCasesUpdate = { - "Id": currentLawyer.id, - "Service": serviceInput.value, - "Coast": coastInput.value, - "Date": currentLawyer.date, - "ContractViewModels": dataArray, - "LawyerCases": currentLawyer.lawyerCases, + "Id": currentLawyerId, + "Name": nameInput.value, + "Surname": surnameInput.value, + "Patronymic": patronymicInput.value, + "Experience": parseInt(experienceInput.value), + "SpecializationId": parseInt(currentLawyer.specializationId), + "ContractViewModels": dataArray } $.ajax({ url: "/lawyers/update", diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js index fe47bc2..b775f3a 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js @@ -66,7 +66,7 @@ const createRowForLawyersTable = (lawyer) => { const row = tbody.insertRow(); row.setAttribute("data-id", id); - const cells = [name, surname, patronymic, experience, specialization]; + const cells = [name, surname, patronymic, experience, specialization ]; cells.forEach((value) => { const cell = row.insertCell(); cell.textContent = value; diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs index fd7359f..a19305c 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs @@ -114,6 +114,13 @@ namespace CaseAccountingDataBaseImplement.Models Case = context.Cases.First(y => y.Id == x.Key) }).ToList(); } + if (model.Contracts.Count > 0) + { + LawyerContracts = model.Contracts.Select(x => new LawyerContract + { + Contract = context.Contracts.First(y => y.Id == x.Key) + }).ToList(); + } } public void UpdateContracts(CaseAccountingDatabase context, LawyerBindingModel model) diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml index e3fdc9e..f759a54 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml @@ -12,7 +12,7 @@