This commit is contained in:
ker73rus 2023-06-22 00:20:17 +04:00
parent 71de67e722
commit d71a022960
20 changed files with 676 additions and 85 deletions

View File

@ -1,17 +1,13 @@
/*using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityContracts.BindingModels;
using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.ViewModels;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityBusinessLogic.OfficePackage;
using System.Reflection;
using System.Net;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using DocumentFormat.OpenXml.InkML;
using DocumentFormat.OpenXml.Wordprocessing;
using UniversityBusinessLogic.BusinessLogic.OfficePackage;
namespace UniversityBusinessLogic.BusinessLogics
{
@ -23,9 +19,10 @@ namespace UniversityBusinessLogic.BusinessLogics
private readonly IEducationGroupStorage _educationGroupStorage;
private readonly IDisciplineStorage _disciplineStorage;
private readonly IStreamStorage _streamStorage;
private readonly AbstractSaveToExcelProvider _saveToExcel;
private readonly AbstractSaveToWordProvider _saveToWord;
private readonly AbstractSaveToPdfProvider _saveToPdf;
private readonly WordBuilderCustomer _wordBuilder;
private readonly ExcelBuilderCustomer _excelBuilder;
private readonly PdfBuilderProvider _pdfBuilder;
private readonly MailSender _mailSender;
public ReportCustomerLogic(IDocumentStorage documentStorage,
IStudentStorage studentStorage,
@ -33,9 +30,10 @@ namespace UniversityBusinessLogic.BusinessLogics
IEducationGroupStorage educationGroupStorage,
IDisciplineStorage disciplineStorage,
IStreamStorage streamStorage,
AbstractSaveToExcelProvider saveToExcel,
AbstractSaveToWordProvider saveToWord,
AbstractSaveToPdfProvider saveToPdf)
WordBuilderCustomer wordBuilder,
ExcelBuilderCustomer excelBuilder,
PdfBuilderProvider pdfBuilder,
MailSender mailSender)
{
_documentStorage = documentStorage;
_studentStorage = studentStorage;
@ -43,69 +41,88 @@ namespace UniversityBusinessLogic.BusinessLogics
_educationGroupStorage = educationGroupStorage;
_disciplineStorage = disciplineStorage;
_streamStorage = streamStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
_wordBuilder = wordBuilder;
_excelBuilder = excelBuilder;
_pdfBuilder = pdfBuilder;
_mailSender = mailSender;
}
public List<ReportDisciplineViewModel> GetDiscipline(ReportBindingModel model)
public List<ReportStudentsDisciplineViewModel> GetStudentsDiscipline(List<StudentViewModel> students)
{
var result = _streamStorage.GetFilteredList(new StreamSearchModel { Id = _disciplineStorage.GetElement(new DisciplineSearchModel { Name = model.DisciplineName })?.StreamId })
.Select(stream => new ReportDisciplineViewModel
var reportRecords = new List<ReportStudentsDisciplineViewModel>();
foreach (var student in students)
{
var disciplines = _studentStorage.GetStudentStreams(new() { Id = student.Id })
.SelectMany(stream => _streamStorage.GetStreamDisciplines(new() { Id = stream.Id }))
.Select(discipline => discipline.Name)
.ToList();
ReportStudentsDisciplineViewModel reportRecord = new()
{
DisciplineName = model.DisciplineName,
StudentEdStatus = stream.StudentStream
.Where(student => _documentStorage.GetFilteredList(new DocumentSearchModel
{
UserId = model.UserId,
DateFrom = model.DateFrom,
DateTo = model.DateTo,
})
.Any(document => document.DocumentStudents.Contains(student.Value)))//Выбираем студентов, которые есть в приказах за выбранный промежуток времени
.Join(_documentStorage.GetFullList(),
t1 => t1.Value.Id,
t2 => t2.UserId,
(t1, t2) => new { student = t1, document = t2 })
.Select(res => (
StudentFIO: $"{res.student.Value.Name} {res.student.Value.Surname}",
Document: $"{res.document.Date}",
EdStatus: _educationStatusStorage.GetElement(new EducationStatusSearchModel { Id = res.student.Value.EducationStatusId })?.Name ?? "не удалось получить"))
.ToList()
})
.ToList();
return result;
Student = student.Name + " " + student.Surname + ", " + student.StudentCard,
Disciplines = disciplines
};
reportRecords.Add(reportRecord);
}
return reportRecords;
}
public List<ReportStreamEducationStatusViewModel> StreamEducationStatus(List<StreamViewModel> streams)
public byte[] SaveListFile(StreamStudentBindingModel model)
{
var result = streams
.Select(stream => new ReportStreamEducationStatusViewModel
{
StreamName = stream.Name,
StudentEdStatus = stream.StudentStream
.Select(student => (
StudentFIO: $"{student.Value.Name} {student.Value.Surname}",
EdStatus: _educationStatusStorage.GetElement(new EducationStatusSearchModel { Id = student.Value.EducationStatusId })?.Name ?? "не удалось получить"))
.ToList()
})
.ToList();
return result;
byte[] file = Array.Empty<byte>();
string title = "Список студентов по потоку " + model.StreamName;
if (model.FileType == "docx")
{
_wordBuilder.CreateDocument();
_wordBuilder.CreateTitle(title);
_wordBuilder.CreateStudentsStatusTable(model.Students);
file = _wordBuilder.GetFile();
}
else if (model.FileType == "xlsx")
{
_excelBuilder.CreateDocument();
_excelBuilder.CreateTitle(title);
_excelBuilder.CreateStudentsDisciplineTable(model.Students);
file = _excelBuilder.GetFile();
}
return file;
}
public void SendByMailStatusReport(ReportBindingModel reportModel)
{
/*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
});*/
}
public void SaveBlanksToWordFile(ReportBindingModel model)
List<ReportDisciplineViewModel> IReportCustomerLogic.GetDiscipline(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveDocumentBlankToExcelFile(ReportBindingModel model)
List<ReportStreamEducationStatusViewModel> IReportCustomerLogic.StreamEducationStatus(List<StreamViewModel> streams)
{
throw new NotImplementedException();
}
public void SaveOrdersToPdfFile(ReportBindingModel model)
void IReportCustomerLogic.SendByMailStatusReport(ReportBindingModel reportModel)
{
throw new NotImplementedException();
}
}
}
*/

View File

@ -112,5 +112,10 @@ namespace UniversityBusinessLogic.BusinessLogics
throw new InvalidOperationException("Студент с таким номером студенческого билета уже есть");
}
}
public List<StudentViewModel> GetStudentsFromStream(int streamId)
{
return _studentStorage.GetStudentsFromStream(streamId);
}
}
}

View File

@ -0,0 +1,344 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityBusinessLogic.OfficePackage.Models;
using UniversityContracts.ViewModels;
namespace UniversityBusinessLogic.OfficePackage
{
public class ExcelBuilderCustomer
{
private readonly string tempFileName = "temp.xlsx";
private SpreadsheetDocument? spreadsheetDocument;
private SharedStringTablePart? shareStringPart;
private Worksheet? worksheet;
private void CreateStyles(WorkbookPart workbookpart)
{
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
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<SharedStringTablePart>()
.Any()
? spreadsheetDocument.WorkbookPart
.GetPartsOfType<SharedStringTablePart>()
.First()
: spreadsheetDocument.WorkbookPart
.AddNewPart<SharedStringTablePart>();
if (shareStringPart.SharedStringTable == null)
{
shareStringPart.SharedStringTable = new SharedStringTable();
}
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
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<SheetData>();
if (sheetData == null)
{
return;
}
Row? row = sheetData.Elements<Row>()
.Where(r => r.RowIndex! == cellData.RowIndex)
.FirstOrDefault();
if (row == null)
{
row = new Row() { RowIndex = cellData.RowIndex };
sheetData.Append(row);
}
Cell? cell = row.Elements<Cell>()
.Where(c => c.CellReference!.Value == cellData.CellReference)
.FirstOrDefault();
if (cell == null)
{
Cell? refCell = null;
foreach (Cell rowCell in row.Elements<Cell>())
{
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<SharedStringItem>().Count() - 1).ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.StyleIndex = cellData.StyleIndex;
}
private void MergeCells(ExcelMergeParameters excelParams)
{
if (worksheet == null)
{
return;
}
MergeCells mergeCells;
if (worksheet.Elements<MergeCells>().Any())
{
mergeCells = worksheet.Elements<MergeCells>().First();
}
else
{
mergeCells = new MergeCells();
if (worksheet.Elements<CustomSheetView>().Any())
{
worksheet.InsertAfter(mergeCells, worksheet.Elements<CustomSheetView>().First());
}
else
{
worksheet.InsertAfter(mergeCells, worksheet.Elements<SheetData>().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<StudentViewModel> students)
{
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 (StudentViewModel student in students)
{
InsertCellInWorksheet(new ExcelCellData
{
ColumnName = "A",
RowIndex = currentRow,
Text = student.Name + " " + student.Surname,
StyleIndex = 1
});
InsertCellInWorksheet(new ExcelCellData
{
ColumnName = "B",
RowIndex = currentRow,
Text = student.EducationStatusName,
StyleIndex = 1
});
currentRow++;
}
}
}
}

View File

@ -164,7 +164,7 @@ namespace UniversityBusinessLogic.BusinessLogic.OfficePackage
if (k < studentsAndStatus.Count)
{
cellsData[1] = studentsAndStatus[k].StudentName;
cellsData[2] = studentsAndStatus[k].DateOfAddmission.ToString("yyyy-MM-dd");
//cellsData[2] = studentsAndStatus[k].DateOfAddmission.ToString("yyyy-MM-dd");
cellsData[3] = studentsAndStatus[k].EducationStatus;
}
CreateRow(new PdfRowParameters

View File

@ -0,0 +1,171 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityBusinessLogic.OfficePackage.Models;
using UniversityContracts.ViewModels;
namespace UniversityBusinessLogic.OfficePackage
{
public class WordBuilderCustomer
{
private readonly string tempFileName = "temp.docx";
private WordprocessingDocument? wordDocument;
private Body? documentBody;
public void CreateDocument()
{
wordDocument = WordprocessingDocument.Create(tempFileName,
WordprocessingDocumentType.Document);
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
documentBody = mainPart.Document.AppendChild(new Body());
}
public void CreateParagraph(string text)
{
if (documentBody == null)
{
return;
}
Paragraph paragraph = new();
Run run = new();
run.AppendChild(new Text
{
Text = text
});
paragraph.AppendChild(run);
documentBody.AppendChild(paragraph);
}
public void CreateTitle(string text)
{
if (documentBody == null)
{
return;
}
Paragraph paragraph = new();
Run run = new();
RunProperties properties = new();
properties.AppendChild(new Bold());
run.AppendChild(properties);
run.AppendChild(new Text
{
Text = text
});
paragraph.AppendChild(run);
documentBody.AppendChild(paragraph);
}
private TableCell CreateTableCell(string text, bool inHead = false, int? cellWidth = null)
{
Run run = new();
TableCell tableCell = new();
TableCellProperties cellProperties = new()
{
TableCellWidth = new()
{
Width = cellWidth.ToString()
},
TableCellMargin = new()
{
LeftMargin = new()
{
Width = "100"
}
}
};
if (inHead)
{
Shading shading = new()
{
Color = "auto",
Fill = "e0e8ff",
Val = ShadingPatternValues.Clear
};
cellProperties.Append(shading);
RunProperties properties = new();
properties.AppendChild(new Bold());
run.AppendChild(properties);
}
run.AppendChild(new Text
{
Text = text
});
Paragraph paragraph = new(run);
tableCell.AppendChild(paragraph);
tableCell.Append(cellProperties);
return tableCell;
}
protected void CreateTable(WordTableData tableData)
{
if (documentBody == null || tableData == null)
{
return;
}
var table = new Table();
TableProperties tableProperties = new(
new TableBorders(
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 },
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 },
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 },
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 },
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 },
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(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 CreateStudentsStatusTable(List<StudentViewModel> students)
{
List<List<string>> rows = new();
foreach(StudentViewModel student in students) {
List<string> studentCells = new() { student.Name + " " + student.Surname, student.EducationStatusName };
rows.Add(studentCells);
}
WordTableData wordTable = new()
{
Columns = new List<(string, int)>()
{
("Студент", 3000),
("Cтатус", 3000)
},
Rows = rows
};
CreateTable(wordTable);
}
}
}

View File

@ -10,6 +10,7 @@ namespace UniversityContracts.BindingModels
public class StreamStudentBindingModel
{
public string FileType { get; set; } = string.Empty;
public string StreamName { get; set; }
public List<StudentViewModel> Students { get; set; } = new();
}
}

View File

@ -17,5 +17,6 @@ namespace UniversityContracts.BusinessLogicContracts
List<StudentViewModel>? ReadList(StudentSearchModel? model);
StudentViewModel? ReadElement(StudentSearchModel model);
int GetNumberOfPages(int userId, int pageSize = 10);
}
List<StudentViewModel> GetStudentsFromStream(int streamId);
}
}

View File

@ -18,6 +18,7 @@ namespace UniversityContracts.StoragesContracts
StudentViewModel? Update(StudentBindingModel model);
StudentViewModel? Delete(StudentBindingModel model);
List<StreamViewModel> GetStudentStreams(StudentSearchModel model);
List<StudentViewModel> GetStudentsFromStream(int streamId);
int GetNumberOfPages(int userId, int pageSize);
}
}

View File

@ -9,7 +9,7 @@ namespace UniversityContracts.ViewModels
public class StudentStatusViewModel
{
public string StudentName { get; set; } = string.Empty;
public DateTime DateOfAddmission { get; set; }
public DateTime? DateOfAddmission { get; set; }
public string EducationStatus { get; set; } = string.Empty;
}
}

View File

@ -80,8 +80,12 @@ namespace UniversityProvider.Controllers
($"api/stream/getnumberofpages?userId={APIClient.User.Id}");
return View();
}
public IActionResult EducationGroups(int page)
public List<EducationStatusViewModel> Status()
{
return APIClient.GetRequest<List<EducationStatusViewModel>>
($"api/educationstatus/getall");
}
public IActionResult EducationGroups(int page)
{
if (APIClient.User == null)
{

View File

@ -16,6 +16,7 @@ namespace UniversityRestAPI.Controllers
this.reportLogic = reportLogic;
}
[HttpPost]
public byte[] StreamStudentList(StreamStudentBindingModel listModel)
{

View File

@ -30,22 +30,5 @@
</button>
</div>
<div class="mt-4">
<div class="scrollable-table">
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th>Имя</th>
<th>Фамилия</th>
<th>Дата рождения</th>
<th>Номер студ. билета</th>
<th>Статус обучения</th>
</tr>
</thead>
<tbody id="scrollable-table__tbody">
</tbody>
</table>
</div>
</div>
<script src="~/js/report/reportlist.js" asp-append-version="true"></script>

View File

@ -34,12 +34,27 @@ createBtn.addEventListener('click', async () => {
type: "GET",
contentType: "json"
});
console.log(st);
const edst = await $.ajax({
url: `status`,
type: "GET",
contentType: "json"
});
console.log(edst);
console.log(select[select.selectedIndex].innerHTML);
students = st.studentStream;
students.forEach((student) => {
createRowForStudentsTable(student);
})
edst.forEach((status) => {
if (student.educationStatusId = status.id) {
student.educationStatusName = status.name
}
});
});
let listModel = {
"Students": Array.from(dataArray),
"StreamName": select[select.selectedIndex].innerHTML,
"Students": Array.from(students),
"FileType": fileType.value
};
$.ajax({
@ -48,6 +63,7 @@ createBtn.addEventListener('click', async () => {
contentType: "application/json",
data: JSON.stringify(listModel)
}).done((file) => {
console.log(file);
let byteArray = new Uint8Array(file);
saveFile(byteArray, fileType);
});

View File

@ -10,7 +10,7 @@ namespace UniversityDataBaseImplemet
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=UniversityCourseWork;Username=postgres;Password=4757");
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=UniversityCourseWork;Username=postgres;Password=0000");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -31,6 +31,11 @@ namespace UniversityDataBaseImplemet.Implements
|| record.Name.Equals(model.Name))
?.GetViewModel;
}
public List<StreamViewModel> GetFilteredList(StreamSearchModel model)
{
using var context = new Database();

View File

@ -100,6 +100,19 @@ namespace UniversityDataBaseImplemet.Implements
.Select(record => record.GetViewModel)
.ToList();
}
public List<StudentViewModel> GetStudentsFromStream(int streamId)
{
using var context = new Database();
return context.StudentStreams
.Include(x => x.Student)
.Where(x => x.StreamId == streamId)
.Select(x => x.Student.GetViewModel)
.ToList();
}
public StudentViewModel? Insert(StudentBindingModel model)
{
var newStudent = Student.Create(model);

View File

@ -29,6 +29,19 @@ namespace UniversityRestAPI.Controllers
throw;
}
}
[HttpGet]
public List<EducationStatusViewModel>? GetAll()
{
try
{
return _educationStatusLogic.ReadList(null);
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
public List<EducationStatusViewModel>? GetAllByUser(int userId)

View File

@ -19,6 +19,7 @@ namespace UniversityRestAPI.Controllers
[HttpPost]
public byte[] StreamStudentList(StreamStudentBindingModel listModel)
{
Console.BackgroundColor = ConsoleColor.Green;
byte[] file = reportLogic.SaveListFile(listModel);
return file;
}

View File

@ -146,5 +146,17 @@ namespace UniversityRestAPI.Controllers
throw;
}
}
[HttpGet]
public List<StudentViewModel> GetStudentsFromStream(int streamId ) {
try
{
return _studentLogic.GetStudentsFromStream(streamId);
}
catch (Exception ex)
{
throw;
}
}
}
}

View File

@ -27,9 +27,12 @@ builder.Services.AddTransient<IEducationGroupLogic, EducationGroupLogic>();
builder.Services.AddTransient<IDisciplineLogic, DisciplineLogic>();
builder.Services.AddTransient<IStreamLogic, StreamLogic>();
builder.Services.AddTransient<IReportProviderLogic, ReportProviderLogic>();
builder.Services.AddTransient<IReportCustomerLogic, ReportCustomerLogic>();
builder.Services.AddTransient<WordBuilderProvider>();
builder.Services.AddTransient<WordBuilderCustomer>();
builder.Services.AddTransient<ExcelBuilderProvider>();
builder.Services.AddTransient<ExcelBuilderCustomer>();
builder.Services.AddTransient<PdfBuilderProvider>();
builder.Services.AddSingleton<MailSender>();