diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln b/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln index 2f42979..1c8d7d9 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3.sln @@ -7,11 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cop.Borovkov.Var3", "Cop.Bo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestCustomComponents", "TestCustomComponents\TestCustomComponents.csproj", "{E2C46D08-ACCE-4547-922B-E92AD76D99C8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PIHelperSh.PdfCreator", "PIHelperSh.PdfCreater\PIHelperSh.PdfCreator.csproj", "{572BD835-A500-43C9-A66F-648540F4A1C8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3", "Lab3\Lab3.csproj", "{1E630CC7-090F-471C-ADA1-74107CF3DC2A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab3", "Lab3\Lab3.csproj", "{1E630CC7-090F-471C-ADA1-74107CF3DC2A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab3.Database", "Lab3.Database\Lab3.Database.csproj", "{698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3.Database", "Lab3.Database\Lab3.Database.csproj", "{698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,10 +25,6 @@ Global {E2C46D08-ACCE-4547-922B-E92AD76D99C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {E2C46D08-ACCE-4547-922B-E92AD76D99C8}.Release|Any CPU.ActiveCfg = Release|Any CPU {E2C46D08-ACCE-4547-922B-E92AD76D99C8}.Release|Any CPU.Build.0 = Release|Any CPU - {572BD835-A500-43C9-A66F-648540F4A1C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {572BD835-A500-43C9-A66F-648540F4A1C8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {572BD835-A500-43C9-A66F-648540F4A1C8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {572BD835-A500-43C9-A66F-648540F4A1C8}.Release|Any CPU.Build.0 = Release|Any CPU {1E630CC7-090F-471C-ADA1-74107CF3DC2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1E630CC7-090F-471C-ADA1-74107CF3DC2A}.Debug|Any CPU.Build.0 = Debug|Any CPU {1E630CC7-090F-471C-ADA1-74107CF3DC2A}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Cop.Borovkov.Var3.csproj b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Cop.Borovkov.Var3.csproj index e32cffc..7fd5f42 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Cop.Borovkov.Var3.csproj +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Cop.Borovkov.Var3.csproj @@ -7,11 +7,26 @@ enable True $(AssemblyName) - $(VersionPrefix)8.0.1 + $(VersionPrefix)8.0.2 - + + \ + True + + + + + + + + + + + \ + True + diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfAlignmentType.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfAlignmentType.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfAlignmentType.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfAlignmentType.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfLegendPosition.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfLegendPosition.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfLegendPosition.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfLegendPosition.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfMargin.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfMargin.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfMargin.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfMargin.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfStyleType.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfStyleType.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Enums/PdfStyleType.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Enums/PdfStyleType.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfColumnItem.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfColumnItem.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfColumnItem.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfColumnItem.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfCreator.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfCreator.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfCreator.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfCreator.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfElement.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfElement.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Interfaces/IPdfElement.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Interfaces/IPdfElement.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/ImageModels/MiraDocImage.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/MiraDocImage.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/ImageModels/MiraDocImage.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/MiraDocImage.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/ImageModels/PdfImage.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/PdfImage.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/ImageModels/PdfImage.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/ImageModels/PdfImage.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramData.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramData.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramData.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramData.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramModel.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramModel.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfHistogramModel.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfHistogramModel.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfPieChartData.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartData.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfPieChartData.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartData.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfPieChartModel.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartModel.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/PieChartModel/PdfPieChartModel.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/PieChartModel/PdfPieChartModel.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PDFSimpleTable.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTable.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PDFSimpleTable.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTable.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PDFSimpleTableRow.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTableRow.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PDFSimpleTableRow.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PDFSimpleTableRow.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTable.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTable.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTable.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTable.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTableColumn.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTableColumn.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTableColumn.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTableColumn.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTableColumnGroup.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTableColumnGroup.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TableModels/PdfTableColumnGroup.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TableModels/PdfTableColumnGroup.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TextModels/PdfList.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfList.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TextModels/PdfList.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfList.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TextModels/PdfParagraph.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfParagraph.cs similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/Models/TextModels/PdfParagraph.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/Models/TextModels/PdfParagraph.cs diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/PdfCreator.cs similarity index 97% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/PdfCreator.cs index e5dfad9..3fecdf0 100644 --- a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PdfCreator.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/PdfCreator.cs @@ -1,8 +1,6 @@ using MigraDoc.DocumentObjectModel; -using System.Text; using MigraDoc.Rendering; using MigraDoc.DocumentObjectModel.Tables; -using System.Reflection; using MigraDoc.DocumentObjectModel.Shapes.Charts; using PIHelperSh.Core.Extensions; using PIHelperSh.PdfCreator.Enums; @@ -11,6 +9,11 @@ using PIHelperSh.PdfCreator.Models.TextModels; using PIHelperSh.PdfCreator.Models.ImageModels; using PIHelperSh.PdfCreator.Models.PieChartModel; using PIHelperSh.PdfCreator.Interfaces; +using System.Text; +using TabAlignment = MigraDoc.DocumentObjectModel.TabAlignment; +using System.Reflection; +using HorizontalAlignment = MigraDoc.DocumentObjectModel.Shapes.Charts.HorizontalAlignment; +using Color = MigraDoc.DocumentObjectModel.Color; namespace PIHelperSh.PdfCreator { @@ -413,7 +416,7 @@ namespace PIHelperSh.PdfCreator if (rowHeaded) { - _section!.PageSetup.Orientation = Orientation.Landscape; + _section!.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape; _section.PageSetup.LeftMargin = 10; MakeTableWithHederInRow(_document.LastSection.AddTable(), header); return; @@ -456,7 +459,7 @@ namespace PIHelperSh.PdfCreator if (tableData.ChangePageOrientation) { - _section!.PageSetup.Orientation = Orientation.Landscape; + _section!.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape; _section.PageSetup.LeftMargin = 10; _section.PageSetup.BottomMargin = 5; } @@ -535,7 +538,7 @@ namespace PIHelperSh.PdfCreator if (item.Color.HasValue) { - series.FillFormat.Color = new Color((uint)item.Color.Value.ToArgb()); + series.FillFormat.Color = new MigraDoc.DocumentObjectModel.Color((uint)item.Color.Value.ToArgb()); } } diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/README.md b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/README.md similarity index 100% rename from Cop.Borovkov.Var3/PIHelperSh.PdfCreater/README.md rename to Cop.Borovkov.Var3/Cop.Borovkov.Var3/PdfCreator/README.md diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs index 0b13144..108f8cf 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs @@ -29,7 +29,20 @@ namespace Lab3.Database.Repository.Implementations return _mapper.Map(result.Entity); } - public Task DeleteAsync(Guid id) => throw new NotImplementedException(); + public async Task DeleteAsync(Guid id) + { + var student = await _context.Students.FindAsync(id); + + if (student == null) + { + return null; + } + + var result = _context.Students.Remove(student); + await _context.SaveChangesAsync(); + + return _mapper.Map(result.Entity); + } public async Task> GetAsync(int limit = 10000, int offset = 0) => _mapper.Map>( diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs index 4b1873f..e653df3 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs @@ -10,7 +10,7 @@ namespace Lab3.Database.Repository.Interfaces Task UpdateAsync(StudentDTO studentDTO); - Task DeleteAsync(Guid id); + Task DeleteAsync(Guid id); Task CreateAsync(StudentDTO studentDTO); } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs index 9a6cb6f..1929461 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs @@ -57,20 +57,22 @@ namespace Lab3.Forms private async void ButtonSave_ClickAsync(object sender, EventArgs e) { - if (string.IsNullOrEmpty(NameTextBox.Text) + try + { + if (string.IsNullOrEmpty(NameTextBox.Text) || string.IsNullOrEmpty(FormSelector.ComboBoxSelectedValue)) - { - throw new Exception(); - } + { + throw new Exception(); + } - StudentDTO student = new() - { - Id = _updatedStudentGuid ?? Guid.NewGuid(), - Name = NameTextBox.Text, - StartEducation = StartEducationDataPicker.Value, - EducationForm = FormSelector.ComboBoxSelectedValue, - StudentSessions = [ - new(){ + StudentDTO student = new() + { + Id = _updatedStudentGuid ?? Guid.NewGuid(), + Name = NameTextBox.Text, + StartEducation = StartEducationDataPicker.Value, + EducationForm = FormSelector.ComboBoxSelectedValue, + StudentSessions = [ + new(){ Score = session1Score.Value, Number = 1, }, @@ -95,15 +97,21 @@ namespace Lab3.Forms Number = 6, }, ], - }; + }; - if (_updatedStudentGuid != null) - { - await _studentRepository.UpdateAsync(student); + if (_updatedStudentGuid != null) + { + await _studentRepository.UpdateAsync(student); + } + else + { + await _studentRepository.CreateAsync(student); + } + Close(); } - else + catch (Exception ex) { - await _studentRepository.CreateAsync(student); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs index 383fc4f..c90e979 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs @@ -28,7 +28,11 @@ /// private void InitializeComponent() { + components = new System.ComponentModel.Container(); StudentsListBox = new Cop.Borovkov.Var3.Components.CustomListBox(); + SimpleTableCreator = new Cop.Borovkov.Var3.Components.CustomPdfTable(components); + ExcelTableCreator = new CustomComponentsVar2.CustomExcelTable(components); + WordDiogramCreator = new ComponentsLibrary.ComponentDiagram(components); SuspendLayout(); // // StudentsListBox @@ -49,12 +53,14 @@ Name = "MainForm"; Text = "MainForm"; Load += MainForm_LoadAsync; - KeyDown += MainForm_KeyDown; ResumeLayout(false); } #endregion private Cop.Borovkov.Var3.Components.CustomListBox StudentsListBox; + private Cop.Borovkov.Var3.Components.CustomPdfTable SimpleTableCreator; + private CustomComponentsVar2.CustomExcelTable ExcelTableCreator; + private ComponentsLibrary.ComponentDiagram WordDiogramCreator; } } \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs index d6754c4..ba949f3 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs @@ -1,6 +1,13 @@ using AutoMapper; +using ComponentsLibrary.entities; +using ComponentsLibrary.entities.enums; +using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Drawing; +using DocumentFormat.OpenXml.Spreadsheet; +using Lab3.Database.DTO; using Lab3.Database.Repository.Interfaces; using Lab3.Models; +using NPOI.OpenXml4Net.OPC.Internal; namespace Lab3.Forms { @@ -10,6 +17,8 @@ namespace Lab3.Forms private readonly IMapper _mapper; private readonly Func _getCreateOrUpdateForm; + private bool _cont = false; + public MainForm( IStudentRepository repository, IMapper mapper, @@ -23,42 +32,216 @@ namespace Lab3.Forms InitializeComponent(); } - private async void MainForm_LoadAsync(object sender, EventArgs e) + private void MainForm_LoadAsync(object sender, EventArgs e) { - var students = _mapper.Map>(await _studentRepository.GetAsync()); - StudentsListBox.FillValues( - students.Select(s => string.Join(" ", - [ - s.Id, + LoadAsync(); + } + + private async void LoadAsync() + { + try + { + var students = _mapper.Map>(await _studentRepository.GetAsync()); + StudentsListBox.FillValues( + students.Select(s => string.Join(" ", + [ + s.Id, s.Name, s.EducationForm, s.StartEducation.ToLongDateString(), s.SessionMarks, - ] - )) - ); + ] + )) + ); + } + catch (Exception ex) + { + MessageBox.Show( + ex.Message, + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + } } - private void MainForm_KeyDown(object sender, KeyEventArgs e) + private async void RemoveStudentAsync() { - if (e.Modifiers != Keys.Control) + if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - return; + try + { + await _studentRepository + .DeleteAsync(Guid.Parse(StudentsListBox.Selected.Split()[0])); + LoadAsync(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private async void CreateSimpleDocAsync() + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "pdf|*.pdf" + }; + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + + var values = (await _studentRepository.GetAsync()) + .Select(s => s.StudentSessions + .OrderBy(x => x.Number) + .Select(x => x.Score.ToString()) + .ToArray()) + .ToArray(); + var tables = new string[values.Length, 6]; + + for (int i = 0; i < values.Length; ++i) + { + for (int j = 0; j < 6; ++j) + { + tables[i, j] = values[i][j]; + } + } + + SimpleTableCreator.SaveToPdf(new() + { + FilePath = saveFileDialog.FileName, + Title = "Сессии", + Tables = [tables] + }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private async void CreateTableAsync() + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + ExcelTableCreator.SaveToExcel(new() + { + FilePath = saveFileDialog.FileName, + Title = "Студенты", + Headers = + [ + ("Id", nameof(StudentDTO.Id)), + ("ФИО", nameof(StudentDTO.Name)), + ("Форма обучения", nameof(StudentDTO.EducationForm)), + ("Дата поступления", nameof(StudentDTO.StartEducation)), + ], + HeaderGroups = [new() { + GroupHeader = "Образование", + FirstHeader = 2, + LastHeader = 3, + }], + Values = await _studentRepository.GetAsync() + }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private async void CreateWordDocAsync() + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + + var data = (await _studentRepository.GetAsync()) + .GroupBy(s => s.EducationForm) + .Select(s => new DataLine( + s.Key, + s.GroupBy(x => x.StartEducation.Year) + .Select(x => (year: x.Key.ToString(), count: (double)x.Count())) + .ToArray())) + .ToList(); + + WordDiogramCreator.AddDiagram( + new( + saveFileDialog.FileName, + "Поступления", + "Диограмма", + + EnumAreaLegend.Bottom, + data + ) + ); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) + { + if (keyData == (Keys.ControlKey | Keys.Control)) _cont = true; + + if (_cont && keyData == Keys.A) + { + _getCreateOrUpdateForm(null).ShowDialog(this); + LoadAsync(); + } + else if (_cont && keyData == Keys.U) + { + var elem = StudentsListBox.Selected; + _getCreateOrUpdateForm( + Guid.Parse(elem.Split()[0]) + ).ShowDialog(this); + LoadAsync(); + } + else if (_cont && keyData == Keys.D) + { + RemoveStudentAsync(); + } + else if (_cont && keyData == Keys.S) + { + CreateSimpleDocAsync(); + } + else if (_cont && keyData == Keys.T) + { + CreateTableAsync(); + } + else if (_cont && keyData == Keys.C) + { + CreateWordDocAsync(); } - switch (e.KeyCode) - { - case Keys.A: - _getCreateOrUpdateForm(null).Show(this); - break; - case Keys.U: - _getCreateOrUpdateForm( - Guid.Parse(StudentsListBox.Selected.Split()[0]) - ).Show(this); - break; - default: - return; - } + if (keyData == Keys.A || + keyData == Keys.U || + keyData == Keys.D || + keyData == Keys.S || + keyData == Keys.T || + keyData == Keys.C) _cont = false; + //if (keyData != Keys.None && keyData != (System.Windows.Forms.Keys.ControlKey | System.Windows.Forms.Keys.Control)) cont = false; + return true; + return base.ProcessCmdKey(ref msg, keyData); } } } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx index 8b2ff64..8579cb7 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 203, 17 + + + 377, 17 + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Lab3.csproj b/Cop.Borovkov.Var3/Lab3/Lab3.csproj index 19346e9..8a7a992 100644 --- a/Cop.Borovkov.Var3/Lab3/Lab3.csproj +++ b/Cop.Borovkov.Var3/Lab3/Lab3.csproj @@ -15,7 +15,7 @@ - + diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs index ff96b66..8cbc6aa 100644 --- a/Cop.Borovkov.Var3/Lab3/Program.cs +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -20,7 +20,7 @@ namespace Lab3 var app = CreateHostBuilder().Build(); - Application.Run(app.Services.GetRequiredService()); + Application.Run(app.Services.GetRequiredService()); } static IHostBuilder CreateHostBuilder() diff --git a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PIHelperSh.PdfCreator.csproj b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PIHelperSh.PdfCreator.csproj index ebb8d93..99f55df 100644 --- a/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PIHelperSh.PdfCreator.csproj +++ b/Cop.Borovkov.Var3/PIHelperSh.PdfCreater/PIHelperSh.PdfCreator.csproj @@ -16,23 +16,9 @@ True - - - True - \ - - - - - - True - \ - - -