diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomDataTable.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomDataTable.cs index 477bb22..0169e86 100644 --- a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomDataTable.cs +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomDataTable.cs @@ -41,7 +41,7 @@ namespace Cop.Borovkov.Var3.Components column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; } - outDataGridView.Columns.Add(column); + _ = outDataGridView.Columns.Add(column); } } @@ -108,10 +108,10 @@ namespace Cop.Borovkov.Var3.Components Type type = typeof(TType); - for (int i = 0; i < insertValues.Count(); ++i) + for (int i = 0; i < insertValues.Count; ++i) { var row = insertValues[i]; - outDataGridView.Rows.Add(); + _ = outDataGridView.Rows.Add(); for (int j = 0; j < outDataGridView.ColumnCount; ++j) { diff --git a/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs index f623e96..3aeb93a 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs @@ -14,7 +14,7 @@ namespace Lab3.Database.Extensions this IServiceCollection services, IConfiguration configuration) { - services.AddDbContextPool( + _ = services.AddDbContextPool( dbContextOptions => { AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs index 03cbaa6..5481f1d 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs @@ -19,7 +19,7 @@ namespace Lab3.Forms var values = (await _repository.Get()).ToList(); for (int i = 0; i < values.Count; i++) { - Catalog.Rows.Add(); + _ = Catalog.Rows.Add(); Catalog.Rows[i].Cells[0].Value = values[i]; } } @@ -40,7 +40,7 @@ namespace Lab3.Forms string? val = (string?)Catalog.Rows[i].Cells[0].Value; if (string.IsNullOrEmpty(val)) { - MessageBox.Show( + _ = MessageBox.Show( "Неверные данные", "Ошибка", MessageBoxButtons.OK, @@ -54,7 +54,7 @@ namespace Lab3.Forms } catch (Exception ex) { - MessageBox.Show( + _ = MessageBox.Show( ex.Message, "Ошибка", MessageBoxButtons.OK, @@ -66,7 +66,7 @@ namespace Lab3.Forms { if (e.KeyCode == Keys.Insert) { - Catalog.Rows.Add(); + _ = Catalog.Rows.Add(); } if (e.KeyCode == Keys.Delete && Catalog.SelectedRows.Count == 1) @@ -84,7 +84,7 @@ namespace Lab3.Forms } catch (Exception ex) { - MessageBox.Show( + _ = MessageBox.Show( ex.Message, "Ошибка", MessageBoxButtons.OK, diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs index 1929461..c7b6c4b 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs @@ -37,7 +37,7 @@ namespace Lab3.Forms } var student = await _studentRepository.GetAsync(_updatedStudentGuid.Value); - NameTextBox.Text = student.Name; + NameTextBox.Text = student!.Name; StartEducationDataPicker.Value = student.StartEducation; FormSelector.ComboBoxSelectedValue = student.EducationForm; @@ -101,11 +101,11 @@ namespace Lab3.Forms if (_updatedStudentGuid != null) { - await _studentRepository.UpdateAsync(student); + _ = await _studentRepository.UpdateAsync(student); } else { - await _studentRepository.CreateAsync(student); + _ = await _studentRepository.CreateAsync(student); } Close(); } diff --git a/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs b/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs new file mode 100644 index 0000000..373b463 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab4/Implementations/PluginsConvention.cs @@ -0,0 +1,233 @@ +using Cop.Borovkov.Var3.Components; +using Lab4.Interfaces; +using Lab4.Models; +using Lab3.Database.Repository.Interfaces; +using ComponentsLibrary.entities; +using ComponentsLibrary; +using ComponentsLibrary.entities.enums; +using Lab3.Database.DTO; +using CustomComponentsVar2; +using Lab3.Forms; +using Lab3.Models; +using AutoMapper; + +namespace Lab4.Implementations +{ + public class PluginsConvention : IPluginsConvention + { + private readonly IMapper _mapper; + private readonly IStudentRepository _studentRepository; + private readonly IEducationFormRepository _educationFormRepository; + + private readonly CustomListBox _control; + private readonly CustomPdfTable _simpleDocumentCreator; + private readonly CustomExcelTable _tableCreator; + private readonly ComponentDiagram _chartCreator; + + public PluginsConvention( + IMapper mapper, + IStudentRepository studentRepository, + IEducationFormRepository educationFormRepository) + { + _mapper = mapper; + _studentRepository = studentRepository; + _educationFormRepository = educationFormRepository; + + _control = new(); + _chartCreator = new(); + _tableCreator = new(); + _simpleDocumentCreator = new(); + } + + public string PluginName => throw new NotImplementedException(); + + public UserControl GetControl => _control; + + public PluginsConventionElement GetElement { + get + { + var filds = _control.Selected.Split(); + + Guid id = Guid.Parse(filds[0]); + + return new() + { + Id = id, + }; + } + } + + public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument) + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return false; + } + + var data = _studentRepository.GetAsync().Result + .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(); + + _chartCreator.AddDiagram( + new( + saveFileDialog.FileName, + "Поступления", + "Диаграмма", + + EnumAreaLegend.Bottom, + data + ) + ); + + return true; + } + catch + { + return false; + } + } + + public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument) + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "pdf|*.pdf" + }; + + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return false; + } + + var values = (_studentRepository.GetAsync()).Result + .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]; + } + } + + _simpleDocumentCreator.SaveToPdf(new() + { + FilePath = saveFileDialog.FileName, + Title = "Сессии", + Tables = [tables] + }); + + return true; + } + catch + { + return false; + } + } + + public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument) + { + try + { + using var saveFileDialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (saveFileDialog.ShowDialog() != DialogResult.OK) + { + return false; + } + + _tableCreator.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 = _studentRepository.GetAsync().Result + }); + + return true; + } + catch + { + return false; + } + } + + public bool DeleteElement(PluginsConventionElement element) + { + try + { + _studentRepository + .DeleteAsync(element.Id).Wait(); + + return true; + } + catch + { + return false; + } + } + + public Form GetForm(PluginsConventionElement? element = null) + => new CreateForm(_studentRepository, _educationFormRepository, element?.Id); + + public Form GetThesaurus() + => new CatalogForm(_educationFormRepository); + + public void ReloadData() + { + try + { + var students = _mapper.Map>(_studentRepository.GetAsync().Result); + + _control.FillValues( + students.Select(s => string.Join(" ", + [ + s.Id, + s.Name, + s.EducationForm, + s.StartEducation.ToLongDateString(), + s.SessionMarks, + ] + )) + ); + } + catch + { + + } + } + } +} diff --git a/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs b/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs index 52dda70..43b757b 100644 --- a/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs +++ b/Cop.Borovkov.Var3/Lab4/Interfaces/IPluginsConvention.cs @@ -12,7 +12,7 @@ namespace Lab4.Interfaces /// /// Получение контрола для вывода набора данных /// - UserControl GetControl { get; } + UserControl GetControl { get; } /// /// Получение элемента, выбранного в контроле diff --git a/Cop.Borovkov.Var3/Lab4/Lab4.csproj b/Cop.Borovkov.Var3/Lab4/Lab4.csproj index 663fdb8..3b383bd 100644 --- a/Cop.Borovkov.Var3/Lab4/Lab4.csproj +++ b/Cop.Borovkov.Var3/Lab4/Lab4.csproj @@ -8,4 +8,8 @@ enable + + + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab4/Program.cs b/Cop.Borovkov.Var3/Lab4/Program.cs index 6270a9b..17d2a90 100644 --- a/Cop.Borovkov.Var3/Lab4/Program.cs +++ b/Cop.Borovkov.Var3/Lab4/Program.cs @@ -1,3 +1,5 @@ +using Lab4.Forms; + namespace Lab4 { internal static class Program @@ -11,7 +13,7 @@ namespace Lab4 // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormMain()); } } } \ No newline at end of file