подправил отчеты, убрал кнопку добавления машин к неисрпавностям, допилил логкику, отсалось ТО

This commit is contained in:
Максим Яковлев 2024-05-29 03:02:47 +04:00
parent e80ba13485
commit 4c12ecf513
18 changed files with 144 additions and 188 deletions

View File

@ -100,12 +100,10 @@ namespace ServiceStationBusinessLogic.BusinessLogics
_logger.LogInformation("AddCarToDefect find. Id:{Id}", element.Id);
element.DefectCars.Clear();
foreach(int car in cars)
{
if (!element.DefectCars.Keys.Contains(car))
{
element.DefectCars.Add(car, new CarViewModel() { Id = car });
}
element.DefectCars.Add(car, new CarViewModel() { Id = car });
}
_defectStorage.Update(new DefectBindingModel()

View File

@ -88,7 +88,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
}
return allList;
}
public List<ReportCarsViewModel> GetCars(ReportExecutorBindingModel model)
public List<ReportCarsViewModel> GetCars(PdfReportBindingModel model)
{
List<ReportCarsViewModel> allList = new List<ReportCarsViewModel>();
@ -122,7 +122,8 @@ namespace ServiceStationBusinessLogic.BusinessLogics
int contains = 0;
foreach (var defectt in defects)
{
if (defectt.Item2 == car.Id && defect.DefectType == defectt.Item1.DefectType)
var carr = _carStorage.GetElement(new CarSearchModel { Id = defectt.Item2 });
if (defectt.Item2 == car.Id && defectt.Item1.DefectType == defect.DefectType)
{
contains++;
}
@ -161,13 +162,13 @@ namespace ServiceStationBusinessLogic.BusinessLogics
{
_saveToWord.CreateDoc(new WordInfoExecutor
{
FileName = model.FileName,
FileStream = model.FileStream,
Title = "Список работ",
WorksByCar = GetWorks(model.Ids!)
});
}
public void SaveTechWorkAndRepairsByCarsToPdfFile(ReportExecutorBindingModel model)
public void SaveTechWorkAndRepairsByCarsToPdfFile(PdfReportBindingModel model)
{
if(model.DateFrom == null)
{
@ -192,7 +193,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
{
_saveToExcel.CreateReport(new ExcelInfoExecutor
{
FileName = model.FileName,
FileStream = model.FileStream,
Title = "Список работ",
WorksByCar = GetWorks(model.Ids!)
});

View File

@ -10,6 +10,7 @@ namespace ServiceStationBusinessLogic.OfficePackage.HelperModels
public class ExcelInfoExecutor
{
public string FileName { get; set; } = string.Empty;
public Stream FileStream { get; set; } = new MemoryStream();
public string Title { get; set; } = string.Empty;
public List<ReportWorksViewModel> WorksByCar { get; set; } = new();
}

View File

@ -10,6 +10,7 @@ namespace ServiceStationBusinessLogic.OfficePackage.HelperModels
public class WordInfoExecutor
{
public string FileName { get; set; } = string.Empty;
public Stream FileStream { get; set; } = new MemoryStream();
public string Title { get; set; } = string.Empty;
public List<ReportWorksViewModel> WorksByCar { get; set; } = new();
}

View File

@ -198,7 +198,7 @@ namespace ServiceStationBusinessLogic.OfficePackage.Implements
protected override void CreateExcel(ExcelInfoExecutor info)
{
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileStream, SpreadsheetDocumentType.Workbook);
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();

View File

@ -74,7 +74,7 @@ namespace ServiceStationBusinessLogic.OfficePackage.Implements
protected override void CreateWord(WordInfoExecutor info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
_wordDocument = WordprocessingDocument.Create(info.FileStream, WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServiceStationContracts.BindingModels
{
public class PdfReportBindingModel
{
public string FileName { get; set; } = string.Empty;
public int ExecutorId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public List<int>? Ids { get; set; }
}
}

View File

@ -2,13 +2,14 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace ServiceStationContracts.BindingModels
{
public class ReportExecutorBindingModel
{
public string FileName { get; set; } = string.Empty;
public Stream FileStream { get; set; } = new MemoryStream();
public int ExecutorId { get; set; }

View File

@ -11,12 +11,12 @@ namespace ServiceStationContracts.BusinessLogicsContracts
public interface IExecutorReportLogic
{
List<ReportWorksViewModel> GetWorks(List<int> Ids);
List<ReportCarsViewModel> GetCars(ReportExecutorBindingModel model);
List<ReportCarsViewModel> GetCars(PdfReportBindingModel model);
void SaveWorkByCarsWordFile(ReportExecutorBindingModel model);
void SaveWorkByCarsToExcelFile(ReportExecutorBindingModel model);
void SaveTechWorkAndRepairsByCarsToPdfFile(ReportExecutorBindingModel model);
void SaveTechWorkAndRepairsByCarsToPdfFile(PdfReportBindingModel model);
}
}

View File

@ -18,15 +18,15 @@ namespace ServiceStationDatabaseImplement.Implements
public List<DefectViewModel> GetFullList()
{
using var context = new ServiceStationDatabase();
return context.Defects
var defects = context.Defects
.Include(x => x.Cars)
.ThenInclude(x => x.Car)
.ThenInclude(x => x.CarTechnicalWorks)
.ThenInclude(x => x.TechnicalWork)
.Include(x => x.Repair)
.Include(x => x.Executor)
.Select(x => x.GetViewModel)
.ToList();
return defects;
}
public List<DefectViewModel> GetFilteredList(DefectSearchModel model)

View File

@ -81,7 +81,8 @@ namespace ServiceStationDatabaseImplement.Models
DefectType = DefectType,
DefectPrice = DefectPrice,
ExecutorId = ExecutorId,
DefectCars = DefectCars
DefectCars = DefectCars,
RepairId = RepairId
};
public void UpdateCars(ServiceStationDatabase context, DefectBindingModel model)

View File

@ -1,8 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.AspNetCore.Mvc;
using ServiceStationContracts.BindingModels;
using ServiceStationContracts.BusinessLogicsContracts;
using ServiceStationContracts.SearchModels;
using ServiceStationContracts.ViewModels;
using ServiceStationDatabaseImplement.Models;
using ServiceStationExecutorApp.Models;
using System.Collections.Generic;
using System.Diagnostics;
@ -128,7 +130,7 @@ namespace ServiceStationExecutorApp.Controllers
var result = APIExecutor.GetRequest<Tuple<DefectViewModel, List<Tuple<string, string>>>>($"api/main/getdefect?defectId={defectId}");
if (result == null) return default;
string table = "";
for(int i = 0; i < result.Item2.Count; i++)
for (int i = 0; i < result.Item2.Count; i++)
{
var carNumber = result.Item2[i].Item1;
var carBrand = result.Item2[i].Item2;
@ -137,6 +139,7 @@ namespace ServiceStationExecutorApp.Controllers
table += $"<td>{carBrand}</td>";
table += "</tr>";
}
return Tuple.Create(result.Item1, table);
}
[HttpGet]
@ -260,10 +263,10 @@ namespace ServiceStationExecutorApp.Controllers
return RedirectToAction("Enter");
}
ViewBag.Defects = APIExecutor.GetRequest<List<DefectViewModel>>($"api/main/getdefectlist?executorId={APIExecutor.Executor.Id}");
return View();
return View(APIExecutor.GetRequest<List<CarViewModel>>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"));
}
[HttpPost]
public void UpdateDefect(int defect, string DefectType, double DefectPrice)
public void UpdateDefect(int defect, string DefectType, double DefectPrice, int[] car)
{
if (APIExecutor.Executor == null)
{
@ -284,6 +287,10 @@ namespace ServiceStationExecutorApp.Controllers
DefectType = DefectType,
DefectPrice = DefectPrice
});
APIExecutor.PostRequest("api/main/addcartodefect", Tuple.Create(
new DefectSearchModel() { Id = defect },
car
));
Response.Redirect("ListDefects");
}
public IActionResult UpdateTechnicalWork()
@ -348,10 +355,10 @@ namespace ServiceStationExecutorApp.Controllers
{
return RedirectToAction("Enter");
}
return View();
return View(APIExecutor.GetRequest<List<CarViewModel>>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"));
}
[HttpPost]
public void CreateDefect(string defectType, double defectPrice)
public void CreateDefect(string defectType, double defectPrice, int[] car)
{
if (APIExecutor.Executor == null)
{
@ -363,6 +370,10 @@ namespace ServiceStationExecutorApp.Controllers
DefectType = defectType,
DefectPrice = defectPrice
});
APIExecutor.PostRequest("api/main/addcartodefect", Tuple.Create(
new DefectSearchModel() { DefectType = defectType },
car
));
Response.Redirect("ListDefects");
}
public IActionResult CreateTechnicalWork()
@ -389,50 +400,6 @@ namespace ServiceStationExecutorApp.Controllers
});
Response.Redirect("ListTechnicalWorks");
}
public IActionResult AddCarToDefect()
{
if (APIExecutor.Executor == null)
{
return RedirectToAction("Enter");
}
return View(Tuple.Create(APIExecutor.GetRequest<List<DefectViewModel>>($"api/main/getdefectlist?executorId={APIExecutor.Executor.Id}"),
APIExecutor.GetRequest<List<CarViewModel>>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}")));
}
[HttpPost]
public void AddCarToDefect(int defect, int[] car)
{
if(APIExecutor.Executor == null)
{
throw new Exception("Авторизироваться не забыли?");
}
APIExecutor.PostRequest("api/main/addcartodefect", Tuple.Create(
new DefectSearchModel() { Id = defect },
car
));
Response.Redirect("ListDefects");
}
public IActionResult AddCarToTechnicalWork()
{
if (APIExecutor.Executor == null)
{
return RedirectToAction("Enter");
}
return View(Tuple.Create(APIExecutor.GetRequest<List<TechnicalWorkViewModel>>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"),
APIExecutor.GetRequest<List<CarViewModel>>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}")));
}
[HttpPost]
public void AddCarToTechnicalWork(int technicalWork, int[] car)
{
if (APIExecutor.Executor == null)
{
throw new Exception("Авторизироваться не забыли?");
}
APIExecutor.PostRequest("api/main/addcartotechnicalwork", Tuple.Create(
new TechnicalWorkSearchModel() { Id = technicalWork },
car
));
Response.Redirect("ListTechnicalWorks");
}
public IActionResult BindingTechnicalWorkToWork()
{
if (APIExecutor.Executor == null)
@ -464,60 +431,57 @@ namespace ServiceStationExecutorApp.Controllers
}
return View(APIExecutor.GetRequest<List<CarViewModel>>($"api/main/getcarlist?executorId={APIExecutor.Executor.Id}"));
}
[HttpPost]
public void ListWorkToFile(int[] Ids, string type)
public IActionResult ListWorkToFile(int[] Ids, string type)
{
if (APIExecutor.Executor == null)
{
throw new Exception("Авторизироваться не забыли?");
}
if(Ids.Length <= 0)
if (Ids.Length <= 0)
{
throw new Exception("Кол-во меньше нуля");
}
if(string.IsNullOrEmpty(type))
if (string.IsNullOrEmpty(type))
{
throw new Exception("Неопознанный тип");
}
List<int> res = new List<int>();
foreach(var id in Ids)
foreach (var id in Ids)
{
res.Add(id);
}
if(type == "docx")
if (type == "docx")
{
APIExecutor.PostRequest("api/report/createexecutorreporttoword", new ReportExecutorBindingModel
using (var stream = new MemoryStream())
{
Ids = res,
FileName = Directory.GetCurrentDirectory() + "\\Reports\\wordfile.docx"
});
Response.Redirect("GetWordFile");
_report.SaveWorkByCarsWordFile(new ReportExecutorBindingModel
{
FileStream = stream,
Ids = res
});
stream.Seek(0, SeekOrigin.Begin);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "wordfile.docx");
}
}
else
{
APIExecutor.PostRequest("api/report/createexecutorreporttoexcel", new ReportExecutorBindingModel
using (var stream = new MemoryStream())
{
Ids = res,
FileName = Directory.GetCurrentDirectory() + "\\Reports\\excelfile.xlsx"
});
Response.Redirect("GetExcelFile");
_report.SaveWorkByCarsToExcelFile(new ReportExecutorBindingModel
{
FileStream = stream,
Ids = res
});
stream.Seek(0, SeekOrigin.Begin);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "excelfile.xlsx");
}
}
}
public IActionResult GetWordFile()
{
return new PhysicalFileResult(Directory.GetCurrentDirectory() + "\\Reports\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
}
public IActionResult GetExcelFile()
{
return new PhysicalFileResult(Directory.GetCurrentDirectory() + "\\Reports\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
//public IActionResult GetPdfFile()
//{
// return new PhysicalFileResult(Directory.GetCurrentDirectory() + "\\Reports\\pdffile.pdf", "application/pdf");
//}
public IActionResult ListCarsToPdf()
{
if (APIExecutor.Executor == null)
@ -537,13 +501,13 @@ namespace ServiceStationExecutorApp.Controllers
{
throw new Exception("Email пуст");
}
APIExecutor.PostRequest("api/report/createexecutorreporttopdf", new ReportExecutorBindingModel
APIExecutor.PostRequest("api/report/createexecutorreporttopdf", new PdfReportBindingModel
{
FileName = Directory.GetCurrentDirectory() + "\\Reports\\pdffile.pdf",
DateFrom = dateFrom,
DateTo = dateTo,
ExecutorId = APIExecutor.Executor.Id,
});
}) ;
APIExecutor.PostRequest("api/report/sendpdftomail", new MailSendInfoBindingModel
{
MailAddress = executorEmail,
@ -563,7 +527,7 @@ namespace ServiceStationExecutorApp.Controllers
List<ReportCarsViewModel> cars;
try
{
cars = _report.GetCars(new ReportExecutorBindingModel
cars = _report.GetCars(new PdfReportBindingModel
{
ExecutorId = APIExecutor.Executor.Id,
DateFrom = dateFrom,

View File

@ -1,53 +0,0 @@
@using ServiceStationContracts.ViewModels;
@using ServiceStationDataModels.Models;
@{
ViewData["Title"] = "AddCarToDefect";
}
@model Tuple<List<DefectViewModel>, List<CarViewModel>>
<div class="container">
<h2>Добавление машин к неисправностям:</h2>
<form method="post">
<div class="form-group">
<label for="defect">Выберите неисправность</label>
<select id="defect" name="defect" class="form-control">
@foreach (var defect in Model.Item1)
{
<option value="@defect.Id">@Html.DisplayFor(modelItem => defect.DefectType)</option>
}
</select>
</div>
<div class="form-group">
<label for="car">Выберите машины</label>
<table class="table mb-0">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Номер</th>
<th scope="col">Марка</th>
</tr>
</thead>
<tbody>
@foreach (var car in Model.Item2)
{
<tr>
<td class="align-middle">
<div class="form-check">
<input type="checkbox" class="form-check-input" name="car[]" value="@car.Id" id="@car.Id">
</div>
</td>
<td class="align-middle">@Html.DisplayFor(modelItem => car.CarNumber)</td>
<td class="align-middle">@Html.DisplayFor(modelItem => car.CarBrand)</td>
</tr>
}
</tbody>
</table>
</div>
<br>
<div>
<input type="submit" value="Добавить" class="btn btn-secondary" />
</div>
</form>
</div>

View File

@ -1,9 +1,11 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@using ServiceStationContracts.ViewModels
@{
ViewData["Title"] = "CreateDefect";
}
@model List<CarViewModel>
<form method="post">
<div class="w-25 container justify-content-center align-items-center">
<div class="form-group py-2">
@ -14,6 +16,29 @@
<label>Цена неисправности</label>
<input type="number" min="100" step="100" id="defectPrice" placeholder="Введите цену" name="defectPrice" class="form-control" />
</div>
<table class="table">
<thead>
<tr>
<th scope="col">№</th>
<th scope="col">Номер машины</th>
<th scope="col">Марка машины</th>
</tr>
</thead>
<tbody>
@foreach (var car in Model)
{
<tr>
<td class="align-middle">
<div class="form-check">
<input type="checkbox" class="form-check-input" name="car[]" value="@car.Id" id="@car.Id">
</div>
</td>
<td class="align-middle">@Html.DisplayFor(modelItem => car.CarNumber)</td>
<td class="align-middle">@Html.DisplayFor(modelItem => car.CarBrand)</td>
</tr>
}
</tbody>
</table>
<br>
<div>
<input type="submit" value="Сохранить" class="btn btn-secondary text-center" />

View File

@ -42,8 +42,6 @@
&nbsp;
<a asp-controller="Home" asp-action="UpdateDefect" class="btn btn-secondary text-center col-2">Изменить</a>
&nbsp;
<a asp-controller="Home" asp-action="AddCarToDefect" class="btn btn-secondary text-center col-2">Добавить машину</a>
&nbsp;
<a asp-controller="Home" asp-action="DeleteDefect" class="btn btn-secondary text-center col-2">Удалить</a>
</div>
</section>

View File

@ -1,6 +1,6 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@using ServiceStationContracts.ViewModels
@model List<CarViewModel>
@{
ViewData["Title"] = "UpdateDefect";
}
@ -19,6 +19,7 @@
<label>Цена починки</label>
<input type="number" min="100" step="100" id="DefectPrice" placeholder="Введите цену" name="DefectPrice" class="form-control" />
</div>
<h5>Уже привязанные машины</h5>
<table class="table">
<thead>
<tr>
@ -30,6 +31,30 @@
@* полученные машины *@
</tbody>
</table>
<h5>Изменить машины</h5>
<table class="table">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Номер машины</th>
<th scope="col">Марка машины</th>
</tr>
</thead>
<tbody>
@foreach (var car in Model)
{
<tr>
<td class="align-middle">
<div class="form-check">
<input type="checkbox" class="form-check-input" name="car[]" value="@car.Id" id="@car.Id">
</div>
</td>
<td class="align-middle">@Html.DisplayFor(modelItem => car.CarNumber)</td>
<td class="align-middle">@Html.DisplayFor(modelItem => car.CarBrand)</td>
</tr>
}
</tbody>
</table>
<br>
<div>
<input type="submit" value="Сохранить" class="btn btn-secondary text-center" />
@ -49,7 +74,6 @@
url: "/Home/GetDefect",
data: { defectId: defect },
success: function (result) {
$('#defectType').val(result.item1.defectType);
$('#table-elements').html(result.item2);
}
});

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using ServiceStationContracts.BindingModels;
using ServiceStationContracts.BusinessLogicsContracts;
using ServiceStationContracts.SearchModels;

View File

@ -21,39 +21,12 @@ namespace ServiceStationRestApi.Controllers
_mailWorker = abstractMailWorker;
_guarantorReportLogic = guarantorReportLogic;
}
[HttpPost]
public void CreateExecutorReportToWord(ReportExecutorBindingModel model)
public void CreateExecutorReportToPdf(PdfReportBindingModel model)
{
try
{
_executorReportLogic.SaveWorkByCarsWordFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
[HttpPost]
public void CreateExecutorReportToExcel(ReportExecutorBindingModel model)
{
try
{
_executorReportLogic.SaveWorkByCarsToExcelFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
[HttpPost]
public void CreateExecutorReportToPdf(ReportExecutorBindingModel model)
{
try
{
_executorReportLogic.SaveTechWorkAndRepairsByCarsToPdfFile(new ReportExecutorBindingModel
_executorReportLogic.SaveTechWorkAndRepairsByCarsToPdfFile(new PdfReportBindingModel
{
FileName = model.FileName,
DateFrom = model.DateFrom,