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