Compare commits

...

3 Commits

17 changed files with 285 additions and 39 deletions

View File

@ -0,0 +1,88 @@
using Contracts.BusinessLogicsContracts;
using Contracts.StoragesContracts;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.BusinessLogic
{
public class GuarantorReportLogic : IGuarantorReportLogic
{
private readonly IWorkerStorage _workerStorage;
private readonly IMachineStorage _machineStorage;
private readonly IWorkshopStorage _workshopStorage;
private readonly IProductStorage _productStorage;
public GuarantorReportLogic(IWorkerStorage workerStorage, IMachineStorage machineStorage, IWorkshopStorage workshopStorage, IProductStorage productStorage)
{
_workerStorage = workerStorage;
_machineStorage = machineStorage;
_workshopStorage = workshopStorage;
_productStorage = productStorage;
}
public List<WorkerMachineCountChartViewModel>? GetWorkerMachineChart(int UserId)
{
var machines = _machineStorage.GetFilteredList(new() { UserId = UserId });
List<WorkerMachineCountChartViewModel> workerChart = new();
foreach (var mach in machines)
{
WorkerMachineCountChartViewModel worker = new WorkerMachineCountChartViewModel();
worker.MachineName = mach.Title;
var count = _workerStorage.GetFilteredList(new() { MachineId = mach.Id, UserId = UserId }).Count;
worker.WorkerCount = count;
workerChart.Add(worker);
}
return workerChart;
}
public List<WorkerWorkshopCountChartViewModel>? GetWorkerWorkshopChart(int UserId)
{
var workshops = _workshopStorage.GetFilteredList(new() { UserId = UserId });
List<WorkerWorkshopCountChartViewModel> workerChart = new();
foreach (var work in workshops)
{
WorkerWorkshopCountChartViewModel worker = new WorkerWorkshopCountChartViewModel();
worker.WorkshopName = work.Title;
var count = _workerStorage.GetFilteredList(new() { WorkshopId = work.Id, UserId = UserId }).Count;
worker.WorkerCount = count;
workerChart.Add(worker);
}
return workerChart;
}
public List<MachineWorkshopTimeReport>? GetMachineWorkshopTimeReport(DateTime startDate, DateTime endDate, int UserId)
{
var workshops = _workshopStorage.GetFilteredList(new() { DateFrom = startDate, DateTo = endDate, UserId = UserId });
if (workshops == null)
return new();
List<MachineWorkshopTimeReport> machineWorkshopTimeReports = new List<MachineWorkshopTimeReport>();
foreach (var workshop in workshops)
{
var report = new MachineWorkshopTimeReport();
report.WorkshopName = workshop.Title;
var machines = _machineStorage.GetFilteredList(new() { WorkshopId = workshop.Id, UserId = UserId });
if (machines != null)
report.Machines = machines.Select(p => p.Title).ToList();
machineWorkshopTimeReports.Add(report);
}
return machineWorkshopTimeReports;
}
public List<WorkerProductReportViewModel>? GetWorkerProductReport(List<int> ids)
{
List<WorkerProductReportViewModel> reports = new();
foreach (int i in ids)
{
WorkerProductReportViewModel report = new();
var worker = _workerStorage.GetElement(new() { Id = i });
report.WorkerName = worker!.Name;
var products = _productStorage.GetFilteredList(new() { WorkerId = i });
if (products != null)
report.Products = products.Select(x => x.Name).ToList();
reports.Add(report);
}
return reports;
}
}
}

View File

@ -0,0 +1,17 @@
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BusinessLogicsContracts
{
public interface IGuarantorReportLogic
{
List<WorkerProductReportViewModel>? GetWorkerProductReport(List<int> ids);
List<MachineWorkshopTimeReport>? GetMachineWorkshopTimeReport(DateTime start, DateTime end, int UserId);
List<WorkerMachineCountChartViewModel>? GetWorkerMachineChart(int UserId);
List<WorkerWorkshopCountChartViewModel>? GetWorkerWorkshopChart(int UserId);
}
}

View File

@ -5,5 +5,7 @@
public int? Id { get; set; }
public string? Name { get; set; }
public int? UserId { get; set; }
public int MachineId { get; set; }
public int WorkshopId { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class WorkerMachineCountChartViewModel
{
public string MachineName { get; set; } = string.Empty;
public int WorkerCount { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class WorkerWorkshopCountChartViewModel
{
public string WorkshopName { get; set; } = string.Empty;
public int WorkerCount { get; set; }
}
}

View File

@ -537,12 +537,47 @@ namespace GuarantorAPP.Controllers
var workshop = _data.GetWorkshop(workshopId);
if (workshop == null)
return RedirectToAction("Index");
WorkshopBindingModel workshopBinding = new() { Id = workshopId, Title = workshop.Title, Address = workshop.Address, Director = workshop.Director, UserId = workshop.UserId, ProductionId = workshop.ProductionId, WorkshopWorker = workshop.WorkerWorkshops };
WorkshopBindingModel workshopBinding = new() { Id = workshopId, Title = workshop.Title, Address = workshop.Address, Director = workshop.Director, UserId = workshop.UserId, ProductionId = productionId, WorkshopWorker = workshop.WorkerWorkshops };
_data.UpdateWorkshop(workshopBinding);
}
catch (Exception) { }
return RedirectToAction("IndexWorkshop");
}
[HttpGet]
public IActionResult MachineHistogram()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
var chart = _data.GetMachineChart(UserId);
return View(chart);
} catch
{
return RedirectToAction("IndexNonReg");
}
}
public IActionResult Menu()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
return View();
}
[HttpGet]
public IActionResult WorkshopHistogram()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
var chart = _data.GetWorkshopChart(UserId);
return View(chart);
}
catch
{
return RedirectToAction("IndexNonReg");
}
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error(string ex)
{

View File

@ -18,12 +18,13 @@ namespace GuarantorAPP
private readonly IWorkshopLogic _workshopLogic;
private readonly IProductionLogic _productionLogic;
private readonly IProductLogic _productLogic;
private readonly IGuarantorReportLogic _reportLogic;
private readonly AbstractSaveToExcelGuarantor _excel;
private readonly AbstractSaveToWordGuarantor _word;
private readonly AbstractSaveToPdfGuarantor _pdf;
private readonly AbstractMailWorker _mail;
public GuarantorData(ILogger<GuarantorData> logger, IGuarantorLogic guarantorLogic, IWorkerLogic workerLogic, IMachineLogic machineLogic, IWorkshopLogic workshopLogic, IProductionLogic productionLogic, IProductLogic productLogic, AbstractSaveToExcelGuarantor excel, AbstractSaveToPdfGuarantor pdf, AbstractSaveToWordGuarantor word, AbstractMailWorker mail)
public GuarantorData(ILogger<GuarantorData> logger, IGuarantorLogic guarantorLogic, IWorkerLogic workerLogic, IMachineLogic machineLogic, IWorkshopLogic workshopLogic, IProductionLogic productionLogic, IProductLogic productLogic, IGuarantorReportLogic reportLogic, AbstractSaveToExcelGuarantor excel, AbstractSaveToPdfGuarantor pdf, AbstractSaveToWordGuarantor word, AbstractMailWorker mail)
{
_logger = logger;
_guarantorLogic = guarantorLogic;
@ -32,6 +33,7 @@ namespace GuarantorAPP
_workshopLogic = workshopLogic;
_productionLogic = productionLogic;
_productLogic = productLogic;
_reportLogic = reportLogic;
_excel = excel;
_pdf = pdf;
_mail = mail;
@ -138,37 +140,13 @@ namespace GuarantorAPP
{
return _productionLogic.ReadList(null);
}
public List<MachineWorkshopTimeReport> GetTimeReport(DateTime? startDate, DateTime? endDate, int UserId)
public List<MachineWorkshopTimeReport>? GetTimeReport(DateTime? startDate, DateTime? endDate, int UserId)
{
var workshops = _workshopLogic.ReadList(new() { DateFrom = startDate, DateTo = endDate, UserId = UserId });
if (workshops == null)
return new();
List<MachineWorkshopTimeReport> machineWorkshopTimeReports = new List<MachineWorkshopTimeReport>();
foreach (var workshop in workshops)
{
var report = new MachineWorkshopTimeReport();
report.WorkshopName = workshop.Title;
var machines = _machineLogic.ReadList(new() { WorkshopId = workshop.Id, UserId = UserId });
if (machines != null)
report.Machines = machines.Select(p => p.Title).ToList();
machineWorkshopTimeReports.Add(report);
}
return machineWorkshopTimeReports;
return _reportLogic.GetMachineWorkshopTimeReport(startDate!.Value, endDate!.Value, UserId);
}
public List<WorkerProductReportViewModel>? GetProductReports(List<int> workers)
{
List<WorkerProductReportViewModel> reports = new();
foreach (int i in workers)
{
WorkerProductReportViewModel report = new();
var worker = _workerLogic.ReadElement(new() { Id = i });
report.WorkerName = worker!.Name;
var products = _productLogic.ReadList(new() { WorkerId = i });
if (products != null)
report.Products = products.Select(x => x.Name).ToList();
reports.Add(report);
}
return reports;
return _reportLogic.GetWorkerProductReport(workers);
}
public void SaveReportExcel(List<int> workers, MemoryStream stream)
{
@ -225,5 +203,13 @@ namespace GuarantorAPP
MailAddress = UserGuarantor.user!.Email, Subject = "Отчет", FileName = "PdfReport.pdf", Pdf = report
});
}
public List<WorkerMachineCountChartViewModel>? GetMachineChart(int UserId)
{
return _reportLogic.GetWorkerMachineChart(UserId);
}
public List<WorkerWorkshopCountChartViewModel>? GetWorkshopChart(int UserId)
{
return _reportLogic.GetWorkerWorkshopChart(UserId);
}
}
}

View File

@ -26,6 +26,7 @@ builder.Services.AddTransient<IWorkshopLogic, WorkshopLogic>();
builder.Services.AddTransient<IMachineLogic, MachineLogic>();
builder.Services.AddTransient<IProductionLogic, ProductionLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>();
builder.Services.AddTransient<IGuarantorReportLogic, GuarantorReportLogic>();
builder.Services.AddTransient<AbstractSaveToExcelGuarantor, SaveToExcelGuarantor>();
builder.Services.AddTransient<AbstractSaveToWordGuarantor, SaveToWordGuarantor>();
builder.Services.AddTransient<AbstractSaveToPdfGuarantor, SaveToPdfGuarantor>();

View File

@ -4,7 +4,7 @@
}
@model WorkerViewModel;
<div class="text-center">
<h2 class="display-4">работник</h2>
<h2 class="display-4">Работник</h2>
</div>
<form id="workerForm" method="post">
<input type="text" name="id" id="id" value="@Model.Id" hidden="hidden" />

View File

@ -10,6 +10,7 @@
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexWorkshop">Цеха</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ReportsMenu">Меню отчетов</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Menu">Графики</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Logout">Выйти</a>
</div>
</div>

View File

@ -7,7 +7,7 @@
}
<div class="text-center">
<h1 class="display-4">Детали</h1>
<h1 class="display-4">Станки</h1>
</div>

View File

@ -0,0 +1,42 @@
@using Contracts.ViewModels;
@model List<WorkerMachineCountChartViewModel>;
<!DOCTYPE html>
<html>
<head>
<title>Histogram Example</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<div>
<canvas id="myChart" width="400" height="150"></canvas>
</div>
<script>
var ctx = document.getElementById('myChart').getContext('2d');
var data = {
labels: @Html.Raw(Json.Serialize(Model.Select(m => m.MachineName))),
datasets: [{
label: 'Category Data',
data: @Html.Raw(Json.Serialize(Model.Select(m => m.WorkerCount))),
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
};
var myChart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
</script>
</body>
</html>

View File

@ -0,0 +1,11 @@
@{
ViewData["Title"] = "Меню графиков";
}
<div class="text-center">
<h1 class="display-4">Главное меню</h1>
<div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-action="MachineHistogram">Количество работников на каждом станке</a>
<a class="nav-link text-dark" asp-area="" asp-action="WorkshopHistogram">Количество работников в каждом цеху</a>
</div>
</div>

View File

@ -5,7 +5,7 @@
ViewData["Title"] = "Выбор работников для отчета";
}
<h2>Выберите рвботников для отчета</h2>
<h2>Выберите работников для отчета</h2>
<form asp-controller="Home" asp-action="WorkerProductChoose" method="post" onsubmit="return validateForm()">
<table class="table">

View File

@ -9,13 +9,6 @@
<h1 class="display-4">Список работников с отображением изделий</h1>
</div>
<form asp-controller="Report" method="post">
<button type="submit" class="btn btn-primary">Сгенерировать отчет в Word</button>
</form>
<form asp-controller="Report" method="post">
<button type="submit" class="btn btn-primary">Сгенерировать отчет в Excel</button>
</form>
<table class="table">
<thead>
<tr>

View File

@ -0,0 +1,42 @@
@using Contracts.ViewModels;
@model List<WorkerWorkshopCountChartViewModel>;
<!DOCTYPE html>
<html>
<head>
<title>Histogram Example</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<div>
<canvas id="myChart" width="400" height="150"></canvas>
</div>
<script>
var ctx = document.getElementById('myChart').getContext('2d');
var data = {
labels: @Html.Raw(Json.Serialize(Model.Select(m => m.WorkshopName))),
datasets: [{
label: 'Category Data',
data: @Html.Raw(Json.Serialize(Model.Select(m => m.WorkerCount))),
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
};
var myChart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB