diff --git a/Cop.Borovkov.Var3/Lab3.Database/Context/Configurations/StartEducationConfiguration.cs b/Cop.Borovkov.Var3/Lab3.Database/Context/Configurations/StartEducationConfiguration.cs deleted file mode 100644 index c3b3f33..0000000 --- a/Cop.Borovkov.Var3/Lab3.Database/Context/Configurations/StartEducationConfiguration.cs +++ /dev/null @@ -1,31 +0,0 @@ -// This file has been auto generated by EF Core Power Tools. -using Lab3.Database.Context; -using Lab3.Database.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using System; -using System.Collections.Generic; - -namespace Lab3.Database.Context.Configurations -{ - public partial class StartEducationConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder entity) - { - entity.HasKey(e => e.Id).HasName("StartEducation_pkey"); - - entity.ToTable("StartEducation"); - - entity.Property(e => e.Id).ValueGeneratedNever(); - entity.Property(e => e.DateTime).HasColumnType("timestamp without time zone"); - - entity.HasOne(d => d.Student).WithMany(p => p.StartEducations) - .HasForeignKey(d => d.StudentId) - .HasConstraintName("StartEducation_StudentId_fkey"); - - OnConfigurePartial(entity); - } - - partial void OnConfigurePartial(EntityTypeBuilder entity); - } -} diff --git a/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs index 291cb2d..d749c36 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Extensions/DIExtension.cs @@ -1,5 +1,7 @@ using Lab3.Database.Context; using Lab3.Database.MappingProfiles; +using Lab3.Database.Repository.Implementations; +using Lab3.Database.Repository.Interfaces; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -34,5 +36,13 @@ namespace Lab3.Database.Extensions return services; } + + public static IServiceCollection AddRepositories( + this IServiceCollection services) + { + services.AddScoped(); + + return services; + } } } diff --git a/Cop.Borovkov.Var3/Lab3.Database/Lab3.Database.csproj b/Cop.Borovkov.Var3/Lab3.Database/Lab3.Database.csproj index 29b0575..6ac96a7 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Lab3.Database.csproj +++ b/Cop.Borovkov.Var3/Lab3.Database/Lab3.Database.csproj @@ -11,8 +11,4 @@ - - - - diff --git a/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs b/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs index 251c789..31b547a 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/MappingProfiles/SessionMappingProfile.cs @@ -6,7 +6,7 @@ namespace Lab3.Database.MappingProfiles { public class SessionMappingProfile : Profile { - SessionMappingProfile() + public SessionMappingProfile() { _ = CreateMap(); _ = CreateMap(); diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs new file mode 100644 index 0000000..1db612e --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs @@ -0,0 +1,35 @@ +using AutoMapper; +using Lab3.Database.Context; +using Lab3.Database.DTO; +using Lab3.Database.Repository.Interfaces; +using Microsoft.EntityFrameworkCore; + +namespace Lab3.Database.Repository.Implementations +{ + public class StudentRepository : IStudentRepository + { + private readonly IMapper _mapper; + + private readonly COPContext _context; + + public StudentRepository(IMapper mapper, COPContext context) + { + _mapper = mapper; + _context = context; + } + + public Task> Create(StudentDTO studentDTO) => throw new NotImplementedException(); + public Task Delete(Guid id) => throw new NotImplementedException(); + + public async Task> Get(int limit = 10000, int offset = 0) + => _mapper.Map>( + await _context.Students + .Include(s => s.StudentSessions) + .Skip(offset) + .Take(limit) + .ToListAsync()); + + public Task Get(Guid id) => throw new NotImplementedException(); + public Task Update(StudentDTO studentDTO) => throw new NotImplementedException(); + } +} diff --git a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs index 8d3ade7..5962a2f 100644 --- a/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs +++ b/Cop.Borovkov.Var3/Lab3/Extensions/DIExtension.cs @@ -1,4 +1,6 @@ using Lab3.Database.Extensions; +using Lab3.Forms; +using Lab3.MappingProfiles; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -12,6 +14,23 @@ namespace Lab3.Extensions { services.AddDatabase(configuration); services.AddDbMapping(); + services.AddRepositories(); + + return services; + } + + public static IServiceCollection AddForms( + this IServiceCollection services) + { + services.AddScoped(); + + return services; + } + + public static IServiceCollection AddMapping( + this IServiceCollection services) + { + services.AddAutoMapper(typeof(StudentViewMappingProfile)); return services; } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs new file mode 100644 index 0000000..be38e3e --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.Designer.cs @@ -0,0 +1,291 @@ +namespace Lab3.Forms +{ + partial class CreateForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + customDateTimePicker1 = new CustomsComponentsVar2.CustomDateTimePicker(); + visualSelectionComponent1 = new ComponentsLab.VisualSelectionComponent(); + label1 = new Label(); + label2 = new Label(); + textBox1 = new TextBox(); + label3 = new Label(); + numericUpDown1 = new NumericUpDown(); + label4 = new Label(); + label5 = new Label(); + label6 = new Label(); + numericUpDown2 = new NumericUpDown(); + label7 = new Label(); + numericUpDown3 = new NumericUpDown(); + label8 = new Label(); + numericUpDown4 = new NumericUpDown(); + label9 = new Label(); + numericUpDown5 = new NumericUpDown(); + label10 = new Label(); + numericUpDown6 = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown3).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown4).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown5).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown6).BeginInit(); + SuspendLayout(); + // + // customDateTimePicker1 + // + customDateTimePicker1.Location = new Point(430, 32); + customDateTimePicker1.Name = "customDateTimePicker1"; + customDateTimePicker1.Size = new Size(456, 55); + customDateTimePicker1.TabIndex = 0; + customDateTimePicker1.Value = new DateTime(2024, 11, 6, 22, 54, 54, 353); + // + // visualSelectionComponent1 + // + visualSelectionComponent1.BorderStyle = BorderStyle.FixedSingle; + visualSelectionComponent1.comboBoxSelectedValue = ""; + visualSelectionComponent1.Location = new Point(430, 114); + visualSelectionComponent1.Margin = new Padding(3, 4, 3, 4); + visualSelectionComponent1.Name = "visualSelectionComponent1"; + visualSelectionComponent1.Size = new Size(211, 109); + visualSelectionComponent1.TabIndex = 1; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(430, 9); + label1.Name = "label1"; + label1.Size = new Size(134, 20); + label1.TabIndex = 2; + label1.Text = "Дата поступления"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(436, 90); + label2.Name = "label2"; + label2.Size = new Size(128, 20); + label2.TabIndex = 3; + label2.Text = "Форма обучения"; + // + // textBox1 + // + textBox1.Location = new Point(12, 60); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(315, 27); + textBox1.TabIndex = 4; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 18); + label3.Name = "label3"; + label3.Size = new Size(42, 20); + label3.TabIndex = 5; + label3.Text = "ФИО"; + // + // numericUpDown1 + // + numericUpDown1.DecimalPlaces = 2; + numericUpDown1.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown1.Location = new Point(12, 156); + numericUpDown1.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown1.Name = "numericUpDown1"; + numericUpDown1.Size = new Size(150, 27); + numericUpDown1.TabIndex = 6; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(12, 101); + label4.Name = "label4"; + label4.Size = new Size(107, 20); + label4.TabIndex = 7; + label4.Text = "Успеваемость"; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(12, 133); + label5.Name = "label5"; + label5.Size = new Size(65, 20); + label5.TabIndex = 8; + label5.Text = "Сессия1"; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new Point(12, 188); + label6.Name = "label6"; + label6.Size = new Size(65, 20); + label6.TabIndex = 10; + label6.Text = "Сессия2"; + // + // numericUpDown2 + // + numericUpDown2.DecimalPlaces = 2; + numericUpDown2.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown2.Location = new Point(12, 211); + numericUpDown2.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown2.Name = "numericUpDown2"; + numericUpDown2.Size = new Size(150, 27); + numericUpDown2.TabIndex = 9; + // + // label7 + // + label7.AutoSize = true; + label7.Location = new Point(12, 247); + label7.Name = "label7"; + label7.Size = new Size(65, 20); + label7.TabIndex = 12; + label7.Text = "Сессия3"; + // + // numericUpDown3 + // + numericUpDown3.DecimalPlaces = 2; + numericUpDown3.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown3.Location = new Point(12, 270); + numericUpDown3.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown3.Name = "numericUpDown3"; + numericUpDown3.Size = new Size(150, 27); + numericUpDown3.TabIndex = 11; + // + // label8 + // + label8.AutoSize = true; + label8.Location = new Point(177, 247); + label8.Name = "label8"; + label8.Size = new Size(65, 20); + label8.TabIndex = 18; + label8.Text = "Сессия6"; + // + // numericUpDown4 + // + numericUpDown4.DecimalPlaces = 2; + numericUpDown4.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown4.Location = new Point(177, 270); + numericUpDown4.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown4.Name = "numericUpDown4"; + numericUpDown4.Size = new Size(150, 27); + numericUpDown4.TabIndex = 17; + // + // label9 + // + label9.AutoSize = true; + label9.Location = new Point(177, 188); + label9.Name = "label9"; + label9.Size = new Size(65, 20); + label9.TabIndex = 16; + label9.Text = "Сессия5"; + // + // numericUpDown5 + // + numericUpDown5.DecimalPlaces = 2; + numericUpDown5.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown5.Location = new Point(177, 211); + numericUpDown5.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown5.Name = "numericUpDown5"; + numericUpDown5.Size = new Size(150, 27); + numericUpDown5.TabIndex = 15; + // + // label10 + // + label10.AutoSize = true; + label10.Location = new Point(177, 133); + label10.Name = "label10"; + label10.Size = new Size(65, 20); + label10.TabIndex = 14; + label10.Text = "Сессия4"; + // + // numericUpDown6 + // + numericUpDown6.DecimalPlaces = 2; + numericUpDown6.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown6.Location = new Point(177, 156); + numericUpDown6.Maximum = new decimal(new int[] { 5, 0, 0, 0 }); + numericUpDown6.Name = "numericUpDown6"; + numericUpDown6.Size = new Size(150, 27); + numericUpDown6.TabIndex = 13; + // + // CreateForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 309); + Controls.Add(label8); + Controls.Add(numericUpDown4); + Controls.Add(label9); + Controls.Add(numericUpDown5); + Controls.Add(label10); + Controls.Add(numericUpDown6); + Controls.Add(label7); + Controls.Add(numericUpDown3); + Controls.Add(label6); + Controls.Add(numericUpDown2); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(numericUpDown1); + Controls.Add(label3); + Controls.Add(textBox1); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(customDateTimePicker1); + Controls.Add(visualSelectionComponent1); + Name = "CreateForm"; + Text = "Сессия1"; + ((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown3).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown4).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown5).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown6).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CustomsComponentsVar2.CustomDateTimePicker customDateTimePicker1; + private ComponentsLab.VisualSelectionComponent visualSelectionComponent1; + private Label label1; + private Label label2; + private TextBox textBox1; + private Label label3; + private NumericUpDown numericUpDown1; + private Label label4; + private Label label5; + private Label label6; + private NumericUpDown numericUpDown2; + private Label label7; + private NumericUpDown numericUpDown3; + private Label label8; + private NumericUpDown numericUpDown4; + private Label label9; + private NumericUpDown numericUpDown5; + private Label label10; + private NumericUpDown numericUpDown6; + } +} \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs new file mode 100644 index 0000000..c1d3860 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Lab3.Forms +{ + public partial class CreateForm : Form + { + public CreateForm() + { + InitializeComponent(); + } + } +} diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.resx b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs index 1675ede..0e30590 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.Designer.cs @@ -28,12 +28,33 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "MainForm"; + StudentsListBox = new ComponentsLibrary.ListBoxValues(); + SuspendLayout(); + // + // StudentsListBox + // + StudentsListBox.Dock = DockStyle.Fill; + StudentsListBox.Location = new Point(0, 0); + StudentsListBox.Margin = new Padding(3, 4, 3, 4); + StudentsListBox.Name = "StudentsListBox"; + StudentsListBox.SelectedIndex = -1; + StudentsListBox.Size = new Size(800, 450); + StudentsListBox.TabIndex = 0; + // + // MainForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(StudentsListBox); + Name = "MainForm"; + Text = "MainForm"; + Load += MainForm_LoadAsync; + ResumeLayout(false); } #endregion + + private ComponentsLibrary.ListBoxValues StudentsListBox; } } \ 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 7f63187..5bdb12e 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.cs @@ -1,20 +1,27 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using AutoMapper; +using Lab3.Database.Repository.Interfaces; +using Lab3.Models; namespace Lab3.Forms { public partial class MainForm : Form { - public MainForm() + private readonly IStudentRepository _studentRepository; + private readonly IMapper _mapper; + + public MainForm( + IStudentRepository repository, + IMapper mapper) { + _studentRepository = repository; + _mapper = mapper; InitializeComponent(); } + + private async void MainForm_LoadAsync(object sender, EventArgs e) + { + var students = _mapper.Map>(await _studentRepository.Get()); + StudentsListBox.FillListBox(students); + } } } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx index 1af7de1..8b2ff64 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx +++ b/Cop.Borovkov.Var3/Lab3/Forms/MainForm.resx @@ -1,17 +1,17 @@  - diff --git a/Cop.Borovkov.Var3/Lab3/Lab3.csproj b/Cop.Borovkov.Var3/Lab3/Lab3.csproj index c1f50c7..db1aab1 100644 --- a/Cop.Borovkov.Var3/Lab3/Lab3.csproj +++ b/Cop.Borovkov.Var3/Lab3/Lab3.csproj @@ -12,8 +12,22 @@ + + + + + + + + + + + Always + + + \ No newline at end of file diff --git a/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs b/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs index 1df0214..7be214c 100644 --- a/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs +++ b/Cop.Borovkov.Var3/Lab3/MappingProfiles/StudentViewMappingProfile.cs @@ -8,7 +8,7 @@ namespace Lab3.MappingProfiles { public StudentViewMappingProfile() { - _ = CreateMap()\ + _ = CreateMap() ; } } diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs index f7a9a87..2ac9d73 100644 --- a/Cop.Borovkov.Var3/Lab3/Program.cs +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -1,3 +1,10 @@ +using Lab3.Database.Extensions; +using Lab3.Extensions; +using Lab3.Forms; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + namespace Lab3 { internal static class Program @@ -11,7 +18,25 @@ namespace Lab3 // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + + var app = CreateHostBuilder().Build(); + + Application.Run(app.Services.GetRequiredService()); + } + + static IHostBuilder CreateHostBuilder() + { + return Host.CreateDefaultBuilder() + .ConfigureAppConfiguration(c + => c.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)) + .ConfigureServices((context, services) => { + + services.ConfigureDAL(context.Configuration); + + services.AddMapping(); + + services.AddForms(); + }); } } } \ No newline at end of file