Лабораторная работа 2
This commit is contained in:
parent
7ad5c24644
commit
2fc3adecc4
@ -1,31 +0,0 @@
|
|||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Entities;
|
|
||||||
|
|
||||||
public class AddMark
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
public int StudentId { get; private set; }
|
|
||||||
public int GroupId { get; private set; }
|
|
||||||
public int DisciplineId { get; private set; }
|
|
||||||
public Mark? Mark { get; private set; } // Оставляем тип Mark
|
|
||||||
public DateTime Date { get; private set; }
|
|
||||||
|
|
||||||
public static AddMark CreateOperation(int id, int studentId, int groupId, int disciplineId, Mark mark)
|
|
||||||
{
|
|
||||||
return new AddMark
|
|
||||||
{
|
|
||||||
Id = id,
|
|
||||||
StudentId = studentId,
|
|
||||||
GroupId = groupId,
|
|
||||||
DisciplineId = disciplineId,
|
|
||||||
Mark = mark, // Если `Mark` имеет значение по умолчанию, его можно обработать
|
|
||||||
Date = DateTime.Now
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,4 @@
|
|||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
using SessionResults_Kudyaeva.Entities.Enums;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Entities;
|
namespace SessionResults_Kudyaeva.Entities;
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ namespace SessionResults_Kudyaeva.Entities.Enums;
|
|||||||
[Flags]
|
[Flags]
|
||||||
public enum Course
|
public enum Course
|
||||||
{
|
{
|
||||||
None = 0,
|
None,
|
||||||
First = 1, // 1 курс
|
First = 1, // 1 курс
|
||||||
Second = 2, // 2 курс
|
Second = 2, // 2 курс
|
||||||
Third = 4, // 3 курс
|
Third = 4, // 3 курс
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace SessionResults_Kudyaeva.Entities.Enums;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Entities.Enums;
|
|
||||||
|
|
||||||
public enum GroupType
|
public enum GroupType
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,6 @@ namespace SessionResults_Kudyaeva.Entities.Enums;
|
|||||||
|
|
||||||
public enum Mark
|
public enum Mark
|
||||||
{
|
{
|
||||||
None,
|
|
||||||
One = 1,
|
One = 1,
|
||||||
Two = 2,
|
Two = 2,
|
||||||
Three = 3,
|
Three = 3,
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
namespace SessionResults_Kudyaeva.Entities;
|
||||||
|
|
||||||
|
public class Statement
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public int TeacherId { get; private set; }
|
||||||
|
public int DisciplineId { get; private set; }
|
||||||
|
public DateTime Date { get; private set; }
|
||||||
|
public IEnumerable<StatementStudent> StatementStudents { get; private set; } = [];
|
||||||
|
|
||||||
|
public static Statement CreateOperation(int id, int teacherId, int disciplineId, IEnumerable<StatementStudent> statementStudents)
|
||||||
|
{
|
||||||
|
return new Statement
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
TeacherId = teacherId,
|
||||||
|
DisciplineId = disciplineId,
|
||||||
|
Date = DateTime.Now,
|
||||||
|
StatementStudents = statementStudents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
using SessionResults_Kudyaeva.Entities.Enums;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SessionResults_Kudyaeva.Entities;
|
||||||
|
|
||||||
|
public class StatementStudent
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public int StudentId { get; private set; }
|
||||||
|
public Mark Mark { get; private set; }
|
||||||
|
|
||||||
|
public static StatementStudent CreateOperation(int id, int studentId, Mark mark)
|
||||||
|
{
|
||||||
|
return new StatementStudent
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
StudentId = studentId,
|
||||||
|
Mark = mark
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Entities;
|
namespace SessionResults_Kudyaeva.Entities;
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ public class Student
|
|||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
public string MiddleName { get; private set; } = string.Empty;
|
public string MiddleName { get; private set; } = string.Empty;
|
||||||
public int GroupID { get; private set; }
|
public int GroupID { get; private set; }
|
||||||
|
public string DisplayName => $"{Surname} {Name[0]}. {MiddleName[0]}.";
|
||||||
|
|
||||||
public static Student Create(int id, string surname, string name, string middleName, int groupID)
|
public static Student Create(int id, string surname, string name, string middleName, int groupID)
|
||||||
{
|
{
|
||||||
|
@ -12,17 +12,16 @@ public class Teacher
|
|||||||
public string Surname { get; private set; } = string.Empty;
|
public string Surname { get; private set; } = string.Empty;
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
public string MiddleName { get; private set; } = string.Empty;
|
public string MiddleName { get; private set; } = string.Empty;
|
||||||
public int DisciplineID { get; private set; }
|
public string DisplayName => $"{Surname} {Name[0]}. {MiddleName[0]}.";
|
||||||
|
|
||||||
public static Teacher Create(int id, string surname, string name, string middleName, int disciplineID)
|
public static Teacher Create(int id, string surname, string name, string middleName)
|
||||||
{
|
{
|
||||||
return new Teacher
|
return new Teacher
|
||||||
{
|
{
|
||||||
ID = id,
|
ID = id,
|
||||||
Surname = surname,
|
Surname = surname,
|
||||||
Name = name,
|
Name = name,
|
||||||
MiddleName = middleName,
|
MiddleName = middleName
|
||||||
DisciplineID = disciplineID
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,28 +59,28 @@
|
|||||||
// StudentsToolStripMenuItem
|
// StudentsToolStripMenuItem
|
||||||
//
|
//
|
||||||
StudentsToolStripMenuItem.Name = "StudentsToolStripMenuItem";
|
StudentsToolStripMenuItem.Name = "StudentsToolStripMenuItem";
|
||||||
StudentsToolStripMenuItem.Size = new Size(159, 22);
|
StudentsToolStripMenuItem.Size = new Size(180, 22);
|
||||||
StudentsToolStripMenuItem.Text = "Студенты";
|
StudentsToolStripMenuItem.Text = "Студенты";
|
||||||
StudentsToolStripMenuItem.Click += StudentsToolStripMenuItem_Click;
|
StudentsToolStripMenuItem.Click += StudentsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// GroupsToolStripMenuItem
|
// GroupsToolStripMenuItem
|
||||||
//
|
//
|
||||||
GroupsToolStripMenuItem.Name = "GroupsToolStripMenuItem";
|
GroupsToolStripMenuItem.Name = "GroupsToolStripMenuItem";
|
||||||
GroupsToolStripMenuItem.Size = new Size(159, 22);
|
GroupsToolStripMenuItem.Size = new Size(180, 22);
|
||||||
GroupsToolStripMenuItem.Text = "Группы";
|
GroupsToolStripMenuItem.Text = "Группы";
|
||||||
GroupsToolStripMenuItem.Click += GroupsToolStripMenuItem_Click;
|
GroupsToolStripMenuItem.Click += GroupsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// TeachersToolStripMenuItem
|
// TeachersToolStripMenuItem
|
||||||
//
|
//
|
||||||
TeachersToolStripMenuItem.Name = "TeachersToolStripMenuItem";
|
TeachersToolStripMenuItem.Name = "TeachersToolStripMenuItem";
|
||||||
TeachersToolStripMenuItem.Size = new Size(159, 22);
|
TeachersToolStripMenuItem.Size = new Size(180, 22);
|
||||||
TeachersToolStripMenuItem.Text = "Преподаватели";
|
TeachersToolStripMenuItem.Text = "Преподаватели";
|
||||||
TeachersToolStripMenuItem.Click += TeachersToolStripMenuItem_Click;
|
TeachersToolStripMenuItem.Click += TeachersToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// DisciplinesToolStripMenuItem
|
// DisciplinesToolStripMenuItem
|
||||||
//
|
//
|
||||||
DisciplinesToolStripMenuItem.Name = "DisciplinesToolStripMenuItem";
|
DisciplinesToolStripMenuItem.Name = "DisciplinesToolStripMenuItem";
|
||||||
DisciplinesToolStripMenuItem.Size = new Size(159, 22);
|
DisciplinesToolStripMenuItem.Size = new Size(180, 22);
|
||||||
DisciplinesToolStripMenuItem.Text = "Дисциплины";
|
DisciplinesToolStripMenuItem.Text = "Дисциплины";
|
||||||
DisciplinesToolStripMenuItem.Click += DisciplinesToolStripMenuItem_Click;
|
DisciplinesToolStripMenuItem.Click += DisciplinesToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
@ -94,8 +94,8 @@
|
|||||||
// AddMarksToolStripMenuItem
|
// AddMarksToolStripMenuItem
|
||||||
//
|
//
|
||||||
AddMarksToolStripMenuItem.Name = "AddMarksToolStripMenuItem";
|
AddMarksToolStripMenuItem.Name = "AddMarksToolStripMenuItem";
|
||||||
AddMarksToolStripMenuItem.Size = new Size(184, 22);
|
AddMarksToolStripMenuItem.Size = new Size(236, 22);
|
||||||
AddMarksToolStripMenuItem.Text = "Добавление оценки";
|
AddMarksToolStripMenuItem.Text = "Создание результатов сессии";
|
||||||
AddMarksToolStripMenuItem.Click += AddMarksToolStripMenuItem_Click;
|
AddMarksToolStripMenuItem.Click += AddMarksToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// отчетыToolStripMenuItem
|
// отчетыToolStripMenuItem
|
||||||
|
@ -74,7 +74,7 @@ public partial class FormSessionResults : Form
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_container.Resolve<AddMarkListForm>().ShowDialog();
|
_container.Resolve<StatementListForm>().ShowDialog();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -1,218 +0,0 @@
|
|||||||
namespace SessionResults_Kudyaeva.Forms
|
|
||||||
{
|
|
||||||
partial class AddMarkForm
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
label1 = new Label();
|
|
||||||
label2 = new Label();
|
|
||||||
label3 = new Label();
|
|
||||||
label4 = new Label();
|
|
||||||
label5 = new Label();
|
|
||||||
label6 = new Label();
|
|
||||||
ButtonSave = new Button();
|
|
||||||
ButtonCancel = new Button();
|
|
||||||
comboBoxDiscipline = new ComboBox();
|
|
||||||
comboBoxTeacher = new ComboBox();
|
|
||||||
comboBoxStudent = new ComboBox();
|
|
||||||
comboBoxGroup = new ComboBox();
|
|
||||||
comboBoxMark = new ComboBox();
|
|
||||||
dateTimePickerDate = new DateTimePicker();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// label1
|
|
||||||
//
|
|
||||||
label1.AutoSize = true;
|
|
||||||
label1.Location = new Point(40, 42);
|
|
||||||
label1.Name = "label1";
|
|
||||||
label1.Size = new Size(55, 15);
|
|
||||||
label1.TabIndex = 0;
|
|
||||||
label1.Text = "Предмет";
|
|
||||||
//
|
|
||||||
// label2
|
|
||||||
//
|
|
||||||
label2.AutoSize = true;
|
|
||||||
label2.Location = new Point(40, 73);
|
|
||||||
label2.Name = "label2";
|
|
||||||
label2.Size = new Size(91, 15);
|
|
||||||
label2.TabIndex = 1;
|
|
||||||
label2.Text = "Преподаватель";
|
|
||||||
//
|
|
||||||
// label3
|
|
||||||
//
|
|
||||||
label3.AutoSize = true;
|
|
||||||
label3.Location = new Point(40, 105);
|
|
||||||
label3.Name = "label3";
|
|
||||||
label3.Size = new Size(50, 15);
|
|
||||||
label3.TabIndex = 2;
|
|
||||||
label3.Text = "Студент";
|
|
||||||
//
|
|
||||||
// label4
|
|
||||||
//
|
|
||||||
label4.AutoSize = true;
|
|
||||||
label4.Location = new Point(40, 137);
|
|
||||||
label4.Name = "label4";
|
|
||||||
label4.Size = new Size(46, 15);
|
|
||||||
label4.TabIndex = 3;
|
|
||||||
label4.Text = "Группа";
|
|
||||||
//
|
|
||||||
// label5
|
|
||||||
//
|
|
||||||
label5.AutoSize = true;
|
|
||||||
label5.Location = new Point(40, 195);
|
|
||||||
label5.Name = "label5";
|
|
||||||
label5.Size = new Size(48, 15);
|
|
||||||
label5.TabIndex = 4;
|
|
||||||
label5.Text = "Оценка";
|
|
||||||
//
|
|
||||||
// label6
|
|
||||||
//
|
|
||||||
label6.AutoSize = true;
|
|
||||||
label6.Location = new Point(40, 233);
|
|
||||||
label6.Name = "label6";
|
|
||||||
label6.Size = new Size(32, 15);
|
|
||||||
label6.TabIndex = 5;
|
|
||||||
label6.Text = "Дата";
|
|
||||||
//
|
|
||||||
// ButtonSave
|
|
||||||
//
|
|
||||||
ButtonSave.Location = new Point(61, 284);
|
|
||||||
ButtonSave.Name = "ButtonSave";
|
|
||||||
ButtonSave.Size = new Size(96, 23);
|
|
||||||
ButtonSave.TabIndex = 10;
|
|
||||||
ButtonSave.Text = "Сохранить";
|
|
||||||
ButtonSave.UseVisualStyleBackColor = true;
|
|
||||||
ButtonSave.Click += ButtonSave_Click;
|
|
||||||
//
|
|
||||||
// ButtonCancel
|
|
||||||
//
|
|
||||||
ButtonCancel.Location = new Point(234, 284);
|
|
||||||
ButtonCancel.Name = "ButtonCancel";
|
|
||||||
ButtonCancel.Size = new Size(96, 23);
|
|
||||||
ButtonCancel.TabIndex = 11;
|
|
||||||
ButtonCancel.Text = "Отменить";
|
|
||||||
ButtonCancel.UseVisualStyleBackColor = true;
|
|
||||||
ButtonCancel.Click += ButtonCancel_Click;
|
|
||||||
//
|
|
||||||
// comboBoxDiscipline
|
|
||||||
//
|
|
||||||
comboBoxDiscipline.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxDiscipline.FormattingEnabled = true;
|
|
||||||
comboBoxDiscipline.Location = new Point(186, 39);
|
|
||||||
comboBoxDiscipline.Name = "comboBoxDiscipline";
|
|
||||||
comboBoxDiscipline.Size = new Size(175, 23);
|
|
||||||
comboBoxDiscipline.TabIndex = 12;
|
|
||||||
//
|
|
||||||
// comboBoxTeacher
|
|
||||||
//
|
|
||||||
comboBoxTeacher.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxTeacher.FormattingEnabled = true;
|
|
||||||
comboBoxTeacher.Location = new Point(186, 70);
|
|
||||||
comboBoxTeacher.Name = "comboBoxTeacher";
|
|
||||||
comboBoxTeacher.Size = new Size(175, 23);
|
|
||||||
comboBoxTeacher.TabIndex = 13;
|
|
||||||
//
|
|
||||||
// comboBoxStudent
|
|
||||||
//
|
|
||||||
comboBoxStudent.BackColor = Color.White;
|
|
||||||
comboBoxStudent.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxStudent.FormattingEnabled = true;
|
|
||||||
comboBoxStudent.Location = new Point(186, 102);
|
|
||||||
comboBoxStudent.Name = "comboBoxStudent";
|
|
||||||
comboBoxStudent.Size = new Size(175, 23);
|
|
||||||
comboBoxStudent.TabIndex = 14;
|
|
||||||
//
|
|
||||||
// comboBoxGroup
|
|
||||||
//
|
|
||||||
comboBoxGroup.BackColor = Color.White;
|
|
||||||
comboBoxGroup.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxGroup.FormattingEnabled = true;
|
|
||||||
comboBoxGroup.Location = new Point(186, 134);
|
|
||||||
comboBoxGroup.Name = "comboBoxGroup";
|
|
||||||
comboBoxGroup.Size = new Size(175, 23);
|
|
||||||
comboBoxGroup.TabIndex = 15;
|
|
||||||
//
|
|
||||||
// comboBoxMark
|
|
||||||
//
|
|
||||||
comboBoxMark.BackColor = Color.White;
|
|
||||||
comboBoxMark.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxMark.FormattingEnabled = true;
|
|
||||||
comboBoxMark.Location = new Point(186, 192);
|
|
||||||
comboBoxMark.Name = "comboBoxMark";
|
|
||||||
comboBoxMark.Size = new Size(175, 23);
|
|
||||||
comboBoxMark.TabIndex = 16;
|
|
||||||
//
|
|
||||||
// dateTimePickerDate
|
|
||||||
//
|
|
||||||
dateTimePickerDate.Location = new Point(186, 227);
|
|
||||||
dateTimePickerDate.Name = "dateTimePickerDate";
|
|
||||||
dateTimePickerDate.Size = new Size(175, 23);
|
|
||||||
dateTimePickerDate.TabIndex = 17;
|
|
||||||
//
|
|
||||||
// AddMarkForm
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(407, 342);
|
|
||||||
Controls.Add(dateTimePickerDate);
|
|
||||||
Controls.Add(comboBoxMark);
|
|
||||||
Controls.Add(comboBoxGroup);
|
|
||||||
Controls.Add(comboBoxStudent);
|
|
||||||
Controls.Add(comboBoxTeacher);
|
|
||||||
Controls.Add(comboBoxDiscipline);
|
|
||||||
Controls.Add(ButtonCancel);
|
|
||||||
Controls.Add(ButtonSave);
|
|
||||||
Controls.Add(label6);
|
|
||||||
Controls.Add(label5);
|
|
||||||
Controls.Add(label4);
|
|
||||||
Controls.Add(label3);
|
|
||||||
Controls.Add(label2);
|
|
||||||
Controls.Add(label1);
|
|
||||||
Name = "AddMarkForm";
|
|
||||||
Text = "Добавить оценку";
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private Label label1;
|
|
||||||
private Label label2;
|
|
||||||
private Label label3;
|
|
||||||
private Label label4;
|
|
||||||
private Label label5;
|
|
||||||
private Label label6;
|
|
||||||
private Button ButtonSave;
|
|
||||||
private Button ButtonCancel;
|
|
||||||
private ComboBox comboBoxDiscipline;
|
|
||||||
private ComboBox comboBoxTeacher;
|
|
||||||
private ComboBox comboBoxStudent;
|
|
||||||
private ComboBox comboBoxGroup;
|
|
||||||
private ComboBox comboBoxMark;
|
|
||||||
private DateTimePicker dateTimePickerDate;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
using SessionResults_Kudyaeva.Entities;
|
|
||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
|
||||||
using SessionResults_Kudyaeva.Repositories;
|
|
||||||
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 SessionResults_Kudyaeva.Forms;
|
|
||||||
|
|
||||||
|
|
||||||
public partial class AddMarkForm : Form
|
|
||||||
{
|
|
||||||
private readonly IAddMarkRepository _addMarkRepository;
|
|
||||||
private readonly IStudentRepository _studentRepository;
|
|
||||||
private readonly IGroupRepository _groupRepository;
|
|
||||||
private readonly ITeacherRepository _teacherRepository;
|
|
||||||
private readonly IDisciplineRepository _disciplineRepository;
|
|
||||||
|
|
||||||
public AddMarkForm(IAddMarkRepository addMarkRepository, IStudentRepository studentRepository, IGroupRepository groupRepository, ITeacherRepository teacherRepository, IDisciplineRepository disciplineRepository)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
|
|
||||||
_addMarkRepository = addMarkRepository ?? throw new ArgumentNullException(nameof(addMarkRepository));
|
|
||||||
_studentRepository = studentRepository ?? throw new ArgumentNullException(nameof(studentRepository));
|
|
||||||
_groupRepository = groupRepository ?? throw new ArgumentNullException(nameof(groupRepository));
|
|
||||||
_teacherRepository = teacherRepository ?? throw new ArgumentNullException(nameof(teacherRepository));
|
|
||||||
_disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository));
|
|
||||||
|
|
||||||
|
|
||||||
comboBoxStudent.DataSource = _studentRepository.GetAllStudents();
|
|
||||||
comboBoxStudent.DisplayMember = "Name";
|
|
||||||
comboBoxStudent.ValueMember = "Id";
|
|
||||||
|
|
||||||
comboBoxGroup.DataSource = _groupRepository.GetAllGroups();
|
|
||||||
comboBoxGroup.DisplayMember = "Name";
|
|
||||||
comboBoxGroup.ValueMember = "Id";
|
|
||||||
|
|
||||||
comboBoxTeacher.DataSource = _teacherRepository.GetAllTeachers();
|
|
||||||
comboBoxTeacher.DisplayMember = "Name";
|
|
||||||
comboBoxTeacher.ValueMember = "Id";
|
|
||||||
|
|
||||||
comboBoxDiscipline.DataSource = _disciplineRepository.GetAllDisciplines();
|
|
||||||
comboBoxDiscipline.DisplayMember = "Name";
|
|
||||||
comboBoxDiscipline.ValueMember = "Id";
|
|
||||||
|
|
||||||
comboBoxMark.DataSource = Enum.GetValues(typeof(Mark));
|
|
||||||
|
|
||||||
|
|
||||||
dateTimePickerDate.Enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonSave_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (comboBoxStudent.SelectedIndex < 0 ||
|
|
||||||
comboBoxGroup.SelectedIndex < 0 ||
|
|
||||||
comboBoxTeacher.SelectedIndex < 0 ||
|
|
||||||
comboBoxDiscipline.SelectedIndex < 0 ||
|
|
||||||
comboBoxMark.SelectedIndex < 0)
|
|
||||||
{
|
|
||||||
throw new Exception("Имеются незаполненные поля");
|
|
||||||
}
|
|
||||||
|
|
||||||
_addMarkRepository.CreateMark(AddMark.CreateOperation(0,
|
|
||||||
(int)comboBoxStudent.SelectedValue!,
|
|
||||||
(int)comboBoxGroup.SelectedValue!,
|
|
||||||
(int)comboBoxDiscipline.SelectedValue!,
|
|
||||||
(Mark)comboBoxMark.SelectedItem!));
|
|
||||||
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
|
||||||
}
|
|
@ -90,7 +90,7 @@
|
|||||||
//
|
//
|
||||||
// ButtonSave
|
// ButtonSave
|
||||||
//
|
//
|
||||||
ButtonSave.Location = new Point(54, 298);
|
ButtonSave.Location = new Point(41, 349);
|
||||||
ButtonSave.Name = "ButtonSave";
|
ButtonSave.Name = "ButtonSave";
|
||||||
ButtonSave.Size = new Size(96, 23);
|
ButtonSave.Size = new Size(96, 23);
|
||||||
ButtonSave.TabIndex = 10;
|
ButtonSave.TabIndex = 10;
|
||||||
@ -100,7 +100,7 @@
|
|||||||
//
|
//
|
||||||
// ButtonCancel
|
// ButtonCancel
|
||||||
//
|
//
|
||||||
ButtonCancel.Location = new Point(210, 298);
|
ButtonCancel.Location = new Point(235, 349);
|
||||||
ButtonCancel.Name = "ButtonCancel";
|
ButtonCancel.Name = "ButtonCancel";
|
||||||
ButtonCancel.Size = new Size(96, 23);
|
ButtonCancel.Size = new Size(96, 23);
|
||||||
ButtonCancel.TabIndex = 11;
|
ButtonCancel.TabIndex = 11;
|
||||||
@ -112,7 +112,7 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(372, 347);
|
ClientSize = new Size(372, 384);
|
||||||
Controls.Add(ButtonCancel);
|
Controls.Add(ButtonCancel);
|
||||||
Controls.Add(ButtonSave);
|
Controls.Add(ButtonSave);
|
||||||
Controls.Add(checkedListBoxCourse);
|
Controls.Add(checkedListBoxCourse);
|
||||||
|
@ -39,6 +39,7 @@ public partial class DisciplineForm : Form
|
|||||||
textBoxName.Text = discipline.Name;
|
textBoxName.Text = discipline.Name;
|
||||||
textBoxDescription.Text = discipline.Description;
|
textBoxDescription.Text = discipline.Description;
|
||||||
_disciplineId = value;
|
_disciplineId = value;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -58,6 +59,8 @@ public partial class DisciplineForm : Form
|
|||||||
{
|
{
|
||||||
checkedListBoxCourse.Items.Add(elem);
|
checkedListBoxCourse.Items.Add(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonSave_Click(object sender, EventArgs e)
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
172
SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/StatementForm.Designer.cs
generated
Normal file
172
SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/StatementForm.Designer.cs
generated
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
namespace SessionResults_Kudyaeva.Forms
|
||||||
|
{
|
||||||
|
partial class StatementForm
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
label1 = new Label();
|
||||||
|
label2 = new Label();
|
||||||
|
ButtonSave = new Button();
|
||||||
|
ButtonCancel = new Button();
|
||||||
|
comboBoxDiscipline = new ComboBox();
|
||||||
|
comboBoxTeacher = new ComboBox();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
groupBox1 = new GroupBox();
|
||||||
|
ColumnStudent = new DataGridViewComboBoxColumn();
|
||||||
|
ColumnMark = new DataGridViewTextBoxColumn();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
groupBox1.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(53, 19);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(55, 15);
|
||||||
|
label1.TabIndex = 0;
|
||||||
|
label1.Text = "Предмет";
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(17, 57);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(91, 15);
|
||||||
|
label2.TabIndex = 1;
|
||||||
|
label2.Text = "Преподаватель";
|
||||||
|
//
|
||||||
|
// ButtonSave
|
||||||
|
//
|
||||||
|
ButtonSave.Location = new Point(12, 307);
|
||||||
|
ButtonSave.Name = "ButtonSave";
|
||||||
|
ButtonSave.Size = new Size(96, 23);
|
||||||
|
ButtonSave.TabIndex = 10;
|
||||||
|
ButtonSave.Text = "Сохранить";
|
||||||
|
ButtonSave.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSave.Click += ButtonSave_Click;
|
||||||
|
//
|
||||||
|
// ButtonCancel
|
||||||
|
//
|
||||||
|
ButtonCancel.Location = new Point(217, 307);
|
||||||
|
ButtonCancel.Name = "ButtonCancel";
|
||||||
|
ButtonCancel.Size = new Size(96, 23);
|
||||||
|
ButtonCancel.TabIndex = 11;
|
||||||
|
ButtonCancel.Text = "Отменить";
|
||||||
|
ButtonCancel.UseVisualStyleBackColor = true;
|
||||||
|
ButtonCancel.Click += ButtonCancel_Click;
|
||||||
|
//
|
||||||
|
// comboBoxDiscipline
|
||||||
|
//
|
||||||
|
comboBoxDiscipline.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxDiscipline.FormattingEnabled = true;
|
||||||
|
comboBoxDiscipline.Location = new Point(114, 16);
|
||||||
|
comboBoxDiscipline.Name = "comboBoxDiscipline";
|
||||||
|
comboBoxDiscipline.Size = new Size(196, 23);
|
||||||
|
comboBoxDiscipline.TabIndex = 12;
|
||||||
|
//
|
||||||
|
// comboBoxTeacher
|
||||||
|
//
|
||||||
|
comboBoxTeacher.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxTeacher.FormattingEnabled = true;
|
||||||
|
comboBoxTeacher.Location = new Point(114, 54);
|
||||||
|
comboBoxTeacher.Name = "comboBoxTeacher";
|
||||||
|
comboBoxTeacher.Size = new Size(196, 23);
|
||||||
|
comboBoxTeacher.TabIndex = 13;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.AllowUserToResizeColumns = false;
|
||||||
|
dataGridView.AllowUserToResizeRows = false;
|
||||||
|
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnStudent, ColumnMark });
|
||||||
|
dataGridView.Dock = DockStyle.Fill;
|
||||||
|
dataGridView.Location = new Point(3, 19);
|
||||||
|
dataGridView.MultiSelect = false;
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.RowHeadersVisible = false;
|
||||||
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
dataGridView.Size = new Size(295, 157);
|
||||||
|
dataGridView.TabIndex = 14;
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
groupBox1.Controls.Add(dataGridView);
|
||||||
|
groupBox1.Location = new Point(12, 99);
|
||||||
|
groupBox1.Name = "groupBox1";
|
||||||
|
groupBox1.Size = new Size(301, 179);
|
||||||
|
groupBox1.TabIndex = 15;
|
||||||
|
groupBox1.TabStop = false;
|
||||||
|
groupBox1.Text = "Студенты";
|
||||||
|
//
|
||||||
|
// ColumnStudent
|
||||||
|
//
|
||||||
|
ColumnStudent.HeaderText = "Студенты";
|
||||||
|
ColumnStudent.Name = "ColumnStudent";
|
||||||
|
//
|
||||||
|
// ColumnMark
|
||||||
|
//
|
||||||
|
ColumnMark.HeaderText = "Оценки";
|
||||||
|
ColumnMark.Name = "ColumnMark";
|
||||||
|
ColumnMark.Resizable = DataGridViewTriState.True;
|
||||||
|
ColumnMark.SortMode = DataGridViewColumnSortMode.NotSortable;
|
||||||
|
//
|
||||||
|
// StatementForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(324, 342);
|
||||||
|
Controls.Add(groupBox1);
|
||||||
|
Controls.Add(comboBoxTeacher);
|
||||||
|
Controls.Add(comboBoxDiscipline);
|
||||||
|
Controls.Add(ButtonCancel);
|
||||||
|
Controls.Add(ButtonSave);
|
||||||
|
Controls.Add(label2);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Name = "StatementForm";
|
||||||
|
Text = "Результат сессии";
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
groupBox1.ResumeLayout(false);
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label label1;
|
||||||
|
private Label label2;
|
||||||
|
private Button ButtonSave;
|
||||||
|
private Button ButtonCancel;
|
||||||
|
private ComboBox comboBoxDiscipline;
|
||||||
|
private ComboBox comboBoxTeacher;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private DataGridViewComboBoxColumn ColumnStudent;
|
||||||
|
private DataGridViewTextBoxColumn ColumnMark;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
using SessionResults_Kudyaeva.Entities;
|
||||||
|
using SessionResults_Kudyaeva.Entities.Enums;
|
||||||
|
using SessionResults_Kudyaeva.Repositories;
|
||||||
|
|
||||||
|
namespace SessionResults_Kudyaeva.Forms;
|
||||||
|
|
||||||
|
|
||||||
|
public partial class StatementForm : Form
|
||||||
|
{
|
||||||
|
private readonly IStatementRepository _statementRepository;
|
||||||
|
private readonly ITeacherRepository _teacherRepository;
|
||||||
|
private readonly IDisciplineRepository _disciplineRepository;
|
||||||
|
|
||||||
|
public StatementForm(IStatementRepository statementRepository, ITeacherRepository teacherRepository, IDisciplineRepository disciplineRepository, IStudentRepository studentRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_statementRepository = statementRepository ?? throw new ArgumentNullException(nameof(statementRepository));
|
||||||
|
_teacherRepository = teacherRepository ?? throw new ArgumentNullException(nameof(teacherRepository));
|
||||||
|
_disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository));
|
||||||
|
|
||||||
|
comboBoxTeacher.DataSource = _teacherRepository.GetAllTeachers();
|
||||||
|
comboBoxTeacher.DisplayMember = "Name";
|
||||||
|
comboBoxTeacher.ValueMember = "Id";
|
||||||
|
|
||||||
|
comboBoxDiscipline.DataSource = _disciplineRepository.GetAllDisciplines();
|
||||||
|
comboBoxDiscipline.DisplayMember = "Name";
|
||||||
|
comboBoxDiscipline.ValueMember = "Id";
|
||||||
|
|
||||||
|
ColumnStudent.DataSource = studentRepository.GetAllStudents();
|
||||||
|
ColumnStudent.DisplayMember = "DisplayName";
|
||||||
|
ColumnStudent.ValueMember = "Id";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (comboBoxTeacher.SelectedIndex < 0 || comboBoxDiscipline.SelectedIndex < 0 || dataGridView.RowCount < 1)
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
|
||||||
|
_statementRepository.CreateStatement(Statement.CreateOperation(0,
|
||||||
|
(int)comboBoxTeacher.SelectedValue!,
|
||||||
|
(int)comboBoxDiscipline.SelectedValue!,
|
||||||
|
CreateListStatementStudentFromDataGrid()));
|
||||||
|
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
|
private List<StatementStudent> CreateListStatementStudentFromDataGrid()
|
||||||
|
{
|
||||||
|
var list = new List<StatementStudent>();
|
||||||
|
foreach (DataGridViewRow row in dataGridView.Rows)
|
||||||
|
{
|
||||||
|
if (row.Cells["ColumnStudent"].Value == null ||
|
||||||
|
row.Cells["ColumnMark"].Value == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
list.Add(StatementStudent.CreateOperation(0,
|
||||||
|
Convert.ToInt32(row.Cells["ColumnStudent"].Value),
|
||||||
|
(Mark)Convert.ToInt32(row.Cells["ColumnMark"].Value)));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
@ -117,4 +117,10 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<metadata name="ColumnStudent.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="ColumnMark.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
@ -1,6 +1,6 @@
|
|||||||
namespace SessionResults_Kudyaeva.Forms
|
namespace SessionResults_Kudyaeva.Forms
|
||||||
{
|
{
|
||||||
partial class AddMarkListForm
|
partial class StatementListForm
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@ -48,7 +48,7 @@
|
|||||||
//
|
//
|
||||||
ButtonAdd.BackgroundImage = Properties.Resources.Add;
|
ButtonAdd.BackgroundImage = Properties.Resources.Add;
|
||||||
ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
ButtonAdd.Location = new Point(6, 43);
|
ButtonAdd.Location = new Point(6, 12);
|
||||||
ButtonAdd.Name = "ButtonAdd";
|
ButtonAdd.Name = "ButtonAdd";
|
||||||
ButtonAdd.Size = new Size(100, 100);
|
ButtonAdd.Size = new Size(100, 100);
|
||||||
ButtonAdd.TabIndex = 3;
|
ButtonAdd.TabIndex = 3;
|
||||||
@ -73,15 +73,15 @@
|
|||||||
dataGridViewData.Size = new Size(845, 449);
|
dataGridViewData.Size = new Size(845, 449);
|
||||||
dataGridViewData.TabIndex = 4;
|
dataGridViewData.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// AddMarkListForm
|
// StatementListForm
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(959, 449);
|
ClientSize = new Size(959, 449);
|
||||||
Controls.Add(dataGridViewData);
|
Controls.Add(dataGridViewData);
|
||||||
Controls.Add(panel1);
|
Controls.Add(panel1);
|
||||||
Name = "AddMarkListForm";
|
Name = "StatementListForm";
|
||||||
Text = "Добавление оценок";
|
Text = "Создание результатов сессии";
|
||||||
Load += AddMarkListForm_Load;
|
Load += AddMarkListForm_Load;
|
||||||
panel1.ResumeLayout(false);
|
panel1.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
@ -3,16 +3,16 @@ using Unity;
|
|||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Forms;
|
namespace SessionResults_Kudyaeva.Forms;
|
||||||
|
|
||||||
public partial class AddMarkListForm : Form
|
public partial class StatementListForm : Form
|
||||||
{
|
{
|
||||||
private readonly IUnityContainer _container;
|
private readonly IUnityContainer _container;
|
||||||
private readonly IAddMarkRepository _addMarkRepository;
|
private readonly IStatementRepository _statementRepository;
|
||||||
|
|
||||||
public AddMarkListForm(IUnityContainer container, IAddMarkRepository addMarkRepository)
|
public StatementListForm(IUnityContainer container, IStatementRepository statementRepository)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
_addMarkRepository = addMarkRepository ?? throw new ArgumentNullException(nameof(addMarkRepository));
|
_statementRepository = statementRepository ?? throw new ArgumentNullException(nameof(statementRepository));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddMarkListForm_Load(object sender, EventArgs e)
|
private void AddMarkListForm_Load(object sender, EventArgs e)
|
||||||
@ -31,7 +31,7 @@ public partial class AddMarkListForm : Form
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_container.Resolve<AddMarkForm>().ShowDialog();
|
_container.Resolve<StatementForm>().ShowDialog();
|
||||||
LoadList();
|
LoadList();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -40,6 +40,6 @@ public partial class AddMarkListForm : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _addMarkRepository.GetAllMarks();
|
private void LoadList() => dataGridViewData.DataSource = _statementRepository.GetAllStatements();
|
||||||
|
|
||||||
}
|
}
|
@ -15,6 +15,7 @@ namespace SessionResults_Kudyaeva.Forms;
|
|||||||
public partial class StudentForm : Form
|
public partial class StudentForm : Form
|
||||||
{
|
{
|
||||||
private readonly IStudentRepository _studentRepository;
|
private readonly IStudentRepository _studentRepository;
|
||||||
|
private readonly IGroupRepository _groupRepository;
|
||||||
private int? _studentId;
|
private int? _studentId;
|
||||||
|
|
||||||
public int Id
|
public int Id
|
||||||
@ -42,11 +43,17 @@ public partial class StudentForm : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public StudentForm(IStudentRepository studentRepository)
|
public StudentForm(IStudentRepository studentRepository, IGroupRepository groupRepository)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
comboBoxGroup.DataSource = groupRepository.GetAllGroups();
|
||||||
|
comboBoxGroup.DisplayMember = "Name";
|
||||||
|
comboBoxGroup.ValueMember = "Id";
|
||||||
_studentRepository = studentRepository ??
|
_studentRepository = studentRepository ??
|
||||||
throw new ArgumentNullException(nameof(studentRepository));
|
throw new ArgumentNullException(nameof(studentRepository));
|
||||||
|
_groupRepository = groupRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(groupRepository));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonSave_Click(object sender, EventArgs e)
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
@ -33,11 +33,9 @@
|
|||||||
labelSurname = new Label();
|
labelSurname = new Label();
|
||||||
label2 = new Label();
|
label2 = new Label();
|
||||||
label3 = new Label();
|
label3 = new Label();
|
||||||
label4 = new Label();
|
|
||||||
textBoxSurname = new TextBox();
|
textBoxSurname = new TextBox();
|
||||||
textBoxName = new TextBox();
|
textBoxName = new TextBox();
|
||||||
textBoxMiddleName = new TextBox();
|
textBoxMiddleName = new TextBox();
|
||||||
comboBoxDiscipline = new ComboBox();
|
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// ButtonSave
|
// ButtonSave
|
||||||
@ -48,6 +46,7 @@
|
|||||||
ButtonSave.TabIndex = 9;
|
ButtonSave.TabIndex = 9;
|
||||||
ButtonSave.Text = "Сохранить";
|
ButtonSave.Text = "Сохранить";
|
||||||
ButtonSave.UseVisualStyleBackColor = true;
|
ButtonSave.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSave.Click += ButtonSave_Click;
|
||||||
//
|
//
|
||||||
// ButtonCancel
|
// ButtonCancel
|
||||||
//
|
//
|
||||||
@ -85,15 +84,6 @@
|
|||||||
label3.TabIndex = 13;
|
label3.TabIndex = 13;
|
||||||
label3.Text = "Отчество";
|
label3.Text = "Отчество";
|
||||||
//
|
//
|
||||||
// label4
|
|
||||||
//
|
|
||||||
label4.AutoSize = true;
|
|
||||||
label4.Location = new Point(56, 144);
|
|
||||||
label4.Name = "label4";
|
|
||||||
label4.Size = new Size(76, 15);
|
|
||||||
label4.TabIndex = 14;
|
|
||||||
label4.Text = "Дисциплина";
|
|
||||||
//
|
|
||||||
// textBoxSurname
|
// textBoxSurname
|
||||||
//
|
//
|
||||||
textBoxSurname.Location = new Point(200, 52);
|
textBoxSurname.Location = new Point(200, 52);
|
||||||
@ -115,25 +105,14 @@
|
|||||||
textBoxMiddleName.Size = new Size(145, 23);
|
textBoxMiddleName.Size = new Size(145, 23);
|
||||||
textBoxMiddleName.TabIndex = 17;
|
textBoxMiddleName.TabIndex = 17;
|
||||||
//
|
//
|
||||||
// comboBoxDiscipline
|
|
||||||
//
|
|
||||||
comboBoxDiscipline.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxDiscipline.FormattingEnabled = true;
|
|
||||||
comboBoxDiscipline.Location = new Point(200, 141);
|
|
||||||
comboBoxDiscipline.Name = "comboBoxDiscipline";
|
|
||||||
comboBoxDiscipline.Size = new Size(145, 23);
|
|
||||||
comboBoxDiscipline.TabIndex = 18;
|
|
||||||
//
|
|
||||||
// TeacherForm
|
// TeacherForm
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(388, 249);
|
ClientSize = new Size(388, 249);
|
||||||
Controls.Add(comboBoxDiscipline);
|
|
||||||
Controls.Add(textBoxMiddleName);
|
Controls.Add(textBoxMiddleName);
|
||||||
Controls.Add(textBoxName);
|
Controls.Add(textBoxName);
|
||||||
Controls.Add(textBoxSurname);
|
Controls.Add(textBoxSurname);
|
||||||
Controls.Add(label4);
|
|
||||||
Controls.Add(label3);
|
Controls.Add(label3);
|
||||||
Controls.Add(label2);
|
Controls.Add(label2);
|
||||||
Controls.Add(labelSurname);
|
Controls.Add(labelSurname);
|
||||||
@ -152,10 +131,8 @@
|
|||||||
private Label labelSurname;
|
private Label labelSurname;
|
||||||
private Label label2;
|
private Label label2;
|
||||||
private Label label3;
|
private Label label3;
|
||||||
private Label label4;
|
|
||||||
private TextBox textBoxSurname;
|
private TextBox textBoxSurname;
|
||||||
private TextBox textBoxName;
|
private TextBox textBoxName;
|
||||||
private TextBox textBoxMiddleName;
|
private TextBox textBoxMiddleName;
|
||||||
private ComboBox comboBoxDiscipline;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,7 +32,6 @@ public partial class TeacherForm : Form
|
|||||||
textBoxSurname.Text = teacher.Surname;
|
textBoxSurname.Text = teacher.Surname;
|
||||||
textBoxName.Text = teacher.Name;
|
textBoxName.Text = teacher.Name;
|
||||||
textBoxMiddleName.Text = teacher.MiddleName;
|
textBoxMiddleName.Text = teacher.MiddleName;
|
||||||
comboBoxDiscipline.SelectedValue = teacher.DisciplineID;
|
|
||||||
_teacherId = value;
|
_teacherId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -83,6 +82,5 @@ public partial class TeacherForm : Form
|
|||||||
id,
|
id,
|
||||||
textBoxSurname.Text,
|
textBoxSurname.Text,
|
||||||
textBoxName.Text,
|
textBoxName.Text,
|
||||||
textBoxMiddleName.Text,
|
textBoxMiddleName.Text);
|
||||||
(int)comboBoxDiscipline.SelectedValue!);
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,12 @@ using SessionResults_Kudyaeva.Repositories.Implementations;
|
|||||||
using SessionResults_Kudyaeva.Repositories;
|
using SessionResults_Kudyaeva.Repositories;
|
||||||
using Unity.Lifetime;
|
using Unity.Lifetime;
|
||||||
using Unity;
|
using Unity;
|
||||||
using System.ComponentModel;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
using Unity.Microsoft.Logging;
|
||||||
|
using ProjectGasStation.Repositories.Implementations;
|
||||||
|
using ProjectGasStation.Repositories;
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva
|
namespace SessionResults_Kudyaeva
|
||||||
{
|
{
|
||||||
@ -24,14 +29,29 @@ namespace SessionResults_Kudyaeva
|
|||||||
{
|
{
|
||||||
var container = new UnityContainer();
|
var container = new UnityContainer();
|
||||||
|
|
||||||
|
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||||
// Ðåãèñòðàöèÿ ðåïîçèòîðèåâ
|
// Ðåãèñòðàöèÿ ðåïîçèòîðèåâ
|
||||||
container.RegisterType<IStudentRepository, StudentRepository>(new TransientLifetimeManager());
|
container.RegisterType<IStudentRepository, StudentRepository>(new TransientLifetimeManager());
|
||||||
container.RegisterType<IGroupRepository, GroupRepository>(new TransientLifetimeManager());
|
container.RegisterType<IGroupRepository, GroupRepository>(new TransientLifetimeManager());
|
||||||
container.RegisterType<ITeacherRepository, TeacherRepository>(new TransientLifetimeManager());
|
container.RegisterType<ITeacherRepository, TeacherRepository>(new TransientLifetimeManager());
|
||||||
container.RegisterType<IDisciplineRepository, DisciplineRepository>(new TransientLifetimeManager());
|
container.RegisterType<IDisciplineRepository, DisciplineRepository>(new TransientLifetimeManager());
|
||||||
container.RegisterType<IAddMarkRepository, AddMarkRepository>(new TransientLifetimeManager());
|
container.RegisterType<IStatementRepository, StatementRepository>(new TransientLifetimeManager());
|
||||||
|
|
||||||
|
container.RegisterType<IConnectionString, ConnectionString>();
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static LoggerFactory CreateLoggerFactory()
|
||||||
|
{
|
||||||
|
var loggerFactory = new LoggerFactory();
|
||||||
|
loggerFactory.AddSerilog(new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json")
|
||||||
|
.Build())
|
||||||
|
.CreateLogger());
|
||||||
|
return loggerFactory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,17 +0,0 @@
|
|||||||
using SessionResults_Kudyaeva.Entities;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Repositories;
|
|
||||||
|
|
||||||
public interface IAddMarkRepository
|
|
||||||
{
|
|
||||||
void CreateMark(AddMark addMark);
|
|
||||||
void UpdateMark(AddMark addMark);
|
|
||||||
void DeleteMark(int id);
|
|
||||||
AddMark GetMarkById(int id);
|
|
||||||
IEnumerable<AddMark> GetAllMarks();
|
|
||||||
}
|
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectGasStation.Repositories;
|
||||||
|
|
||||||
|
public interface IConnectionString
|
||||||
|
{
|
||||||
|
public string ConnectionString { get; }
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using SessionResults_Kudyaeva.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SessionResults_Kudyaeva.Repositories;
|
||||||
|
|
||||||
|
public interface IStatementRepository
|
||||||
|
{
|
||||||
|
void CreateStatement(Statement statement);
|
||||||
|
IEnumerable<Statement> GetAllStatements();
|
||||||
|
}
|
@ -1,39 +0,0 @@
|
|||||||
using SessionResults_Kudyaeva.Entities;
|
|
||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
|
||||||
|
|
||||||
public class AddMarkRepository : IAddMarkRepository
|
|
||||||
{
|
|
||||||
public void CreateMark(AddMark addMark)
|
|
||||||
{
|
|
||||||
// Заглушка
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateMark(AddMark addMark)
|
|
||||||
{
|
|
||||||
// Заглушка
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeleteMark(int id)
|
|
||||||
{
|
|
||||||
// Заглушка
|
|
||||||
}
|
|
||||||
|
|
||||||
public AddMark GetMarkById(int id)
|
|
||||||
{
|
|
||||||
// Возвращаем объект с фиктивными данными, убедившись, что Mark.One существует
|
|
||||||
return AddMark.CreateOperation(0, 0, 0, 0, Mark.One); // Убедитесь, что Mark.One определен
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<AddMark> GetAllMarks()
|
|
||||||
{
|
|
||||||
// Заглушка
|
|
||||||
return new List<AddMark>();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace ProjectGasStation.Repositories.Implementations;
|
||||||
|
|
||||||
|
public class ConnectionString : IConnectionString
|
||||||
|
{
|
||||||
|
string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Username=student;Password=030405;Database=OTP3";
|
||||||
|
}
|
@ -1,38 +1,125 @@
|
|||||||
using System;
|
using Dapper;
|
||||||
using System.Collections.Generic;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Linq;
|
using Newtonsoft.Json;
|
||||||
using System.Text;
|
using Npgsql;
|
||||||
using System.Threading.Tasks;
|
using ProjectGasStation.Repositories;
|
||||||
using SessionResults_Kudyaeva.Entities;
|
using SessionResults_Kudyaeva.Entities;
|
||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
||||||
|
|
||||||
|
|
||||||
public class DisciplineRepository : IDisciplineRepository
|
public class DisciplineRepository : IDisciplineRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<DisciplineRepository> _logger;
|
||||||
|
|
||||||
|
public DisciplineRepository(IConnectionString connectionString, ILogger<DisciplineRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void AddDiscipline(Discipline discipline)
|
public void AddDiscipline(Discipline discipline)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(discipline));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Discipline (Name, Description, Courses)
|
||||||
|
VALUES (@Name, @Description, @Courses)";
|
||||||
|
connection.Execute(queryInsert, discipline);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteDiscipline(int id)
|
public void DeleteDiscipline(int id)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM Discipline
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Discipline> GetAllDisciplines()
|
public IEnumerable<Discipline> GetAllDisciplines()
|
||||||
{
|
{
|
||||||
return new List<Discipline>();
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Discipline";
|
||||||
|
var disciplines = connection.Query<Discipline>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(disciplines));
|
||||||
|
return disciplines;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Discipline GetDisciplineById(int id)
|
public Discipline GetDisciplineById(int id)
|
||||||
{
|
{
|
||||||
return Discipline.Create(0, string.Empty, string.Empty, Course.None);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Discipline
|
||||||
|
WHERE Id=@id";
|
||||||
|
var discipline = connection.QueryFirst<Discipline>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(discipline));
|
||||||
|
return discipline;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateDiscipline(Discipline discipline)
|
public void UpdateDiscipline(Discipline discipline)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(discipline));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE Discipline
|
||||||
|
SET
|
||||||
|
Name=@Name,
|
||||||
|
Description=@Description,
|
||||||
|
Courses=@Courses
|
||||||
|
WHERE Id=@Id";
|
||||||
|
connection.Execute(queryUpdate, discipline);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,124 @@
|
|||||||
using System;
|
using Dapper;
|
||||||
using System.Collections.Generic;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Linq;
|
using Newtonsoft.Json;
|
||||||
using System.Text;
|
using Npgsql;
|
||||||
using System.Threading.Tasks;
|
using ProjectGasStation.Repositories;
|
||||||
using SessionResults_Kudyaeva.Entities;
|
using SessionResults_Kudyaeva.Entities;
|
||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
||||||
|
|
||||||
|
|
||||||
public class GroupRepository : IGroupRepository
|
public class GroupRepository : IGroupRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<GroupRepository> _logger;
|
||||||
|
|
||||||
|
public GroupRepository(IConnectionString connectionString, ILogger<GroupRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void AddGroup(Group group)
|
public void AddGroup(Group group)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(group));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO ""Group"" (Name, Type)
|
||||||
|
VALUES (@Name, @Type)";
|
||||||
|
connection.Execute(queryInsert, group);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteGroup(int id)
|
public void DeleteGroup(int id)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM ""Group""
|
||||||
|
WHERE ID = @id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Group> GetAllGroups()
|
public IEnumerable<Group> GetAllGroups()
|
||||||
{
|
{
|
||||||
return new List<Group>();
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM \"Group\"";
|
||||||
|
var groups = connection.Query<Group>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(groups));
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group GetGroupById(int id)
|
public Group GetGroupById(int id)
|
||||||
{
|
{
|
||||||
return Group.Create(0, string.Empty, GroupType.Daytime);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM ""Group""
|
||||||
|
WHERE Id=@id";
|
||||||
|
var group = connection.QueryFirst<Group>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(group));
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateGroup(Group group)
|
public void UpdateGroup(Group group)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(group));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE ""Group""
|
||||||
|
SET
|
||||||
|
Name=@Name,
|
||||||
|
Type=@Type
|
||||||
|
WHERE Id=@Id";
|
||||||
|
connection.Execute(queryUpdate, group);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectGasStation.Repositories;
|
||||||
|
using SessionResults_Kudyaeva.Entities;
|
||||||
|
|
||||||
|
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
||||||
|
|
||||||
|
public class StatementRepository : IStatementRepository
|
||||||
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<StatementRepository> _logger;
|
||||||
|
|
||||||
|
public StatementRepository(IConnectionString connectionString, ILogger<StatementRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
public void CreateStatement(Statement statement)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(statement));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new
|
||||||
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Statement (TeacherId, DisciplineId, Date)
|
||||||
|
VALUES (@TeacherId, @DisciplineId, @Date);
|
||||||
|
SELECT MAX(Id) FROM Statement";
|
||||||
|
var statementId =
|
||||||
|
connection.QueryFirst<int>(queryInsert, statement, transaction);
|
||||||
|
var querySubInsert = @"
|
||||||
|
INSERT INTO StatementStudent (StatementId, StudentId, Mark)
|
||||||
|
VALUES (@StatementId, @StudentId, @Mark)";
|
||||||
|
foreach (var elem in statement.StatementStudents)
|
||||||
|
{
|
||||||
|
connection.Execute(querySubInsert, new
|
||||||
|
{
|
||||||
|
statementId,
|
||||||
|
elem.StudentId,
|
||||||
|
elem.Mark
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Statement> GetAllStatements()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Statement";
|
||||||
|
var statements = connection.Query<Statement>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(statements));
|
||||||
|
return statements;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,39 +1,125 @@
|
|||||||
using SessionResults_Kudyaeva.Entities;
|
using SessionResults_Kudyaeva.Entities;
|
||||||
using System;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Generic;
|
using ProjectGasStation.Repositories;
|
||||||
using System.Linq;
|
using Newtonsoft.Json;
|
||||||
using System.Text;
|
using Npgsql;
|
||||||
using System.Threading.Tasks;
|
using Dapper;
|
||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
public class StudentRepository : IStudentRepository
|
public class StudentRepository : IStudentRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<StudentRepository> _logger;
|
||||||
|
|
||||||
|
public StudentRepository(IConnectionString connectionString, ILogger<StudentRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void AddStudent(Student student)
|
public void AddStudent(Student student)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(student));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Student (Surname, Name, MiddleName, GroupID)
|
||||||
|
VALUES (@Surname, @Name, @MiddleName, @GroupID)";
|
||||||
|
connection.Execute(queryInsert, student);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteStudent(int id)
|
public void DeleteStudent(int id)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM Student
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Student> GetAllStudents()
|
public IEnumerable<Student> GetAllStudents()
|
||||||
{
|
{
|
||||||
return new List<Student>();
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Student";
|
||||||
|
var students = connection.Query<Student>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(students));
|
||||||
|
return students;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Student GetStudentById(int id)
|
public Student GetStudentById(int id)
|
||||||
{
|
{
|
||||||
return Student.Create(0, string.Empty, string.Empty, string.Empty, 0);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Student
|
||||||
|
WHERE Id=@id";
|
||||||
|
var student = connection.QueryFirst<Student>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(student));
|
||||||
|
return student;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateStudent(Student student)
|
public void UpdateStudent(Student student)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(student));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE Student
|
||||||
|
SET
|
||||||
|
Surname=@Surname,
|
||||||
|
Name=@Name,
|
||||||
|
MiddleName=@MiddleName,
|
||||||
|
GroupID=@GroupID
|
||||||
|
WHERE Id=@Id";
|
||||||
|
connection.Execute(queryUpdate, student);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,40 +1,123 @@
|
|||||||
using System;
|
using SessionResults_Kudyaeva.Entities;
|
||||||
using System.Collections.Generic;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Linq;
|
using ProjectGasStation.Repositories;
|
||||||
using System.Text;
|
using Newtonsoft.Json;
|
||||||
using System.Threading.Tasks;
|
using Npgsql;
|
||||||
using SessionResults_Kudyaeva.Entities;
|
using Dapper;
|
||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
||||||
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
public class TeacherRepository : ITeacherRepository
|
public class TeacherRepository : ITeacherRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<TeacherRepository> _logger;
|
||||||
|
|
||||||
|
public TeacherRepository(IConnectionString connectionString, ILogger<TeacherRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void AddTeacher(Teacher teacher)
|
public void AddTeacher(Teacher teacher)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(teacher));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Teacher (Surname, Name, MiddleName)
|
||||||
|
VALUES (@Surname, @Name, @MiddleName)";
|
||||||
|
connection.Execute(queryInsert, teacher);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteTeacher(int id)
|
public void DeleteTeacher(int id)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM Teacher
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Teacher> GetAllTeachers()
|
public IEnumerable<Teacher> GetAllTeachers()
|
||||||
{
|
{
|
||||||
return new List<Teacher>();
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Teacher";
|
||||||
|
var teachers = connection.Query<Teacher>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(teachers));
|
||||||
|
return teachers;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Teacher GetTeacherById(int id)
|
public Teacher GetTeacherById(int id)
|
||||||
{
|
{
|
||||||
return Teacher.Create(0, string.Empty, string.Empty, string.Empty, 0);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Teacher
|
||||||
|
WHERE Id=@id";
|
||||||
|
var teacher = connection.QueryFirst<Teacher>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(teacher));
|
||||||
|
return teacher;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateTeacher(Teacher teacher)
|
public void UpdateTeacher(Teacher teacher)
|
||||||
{
|
{
|
||||||
// Заглушка
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(teacher));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE Teacher
|
||||||
|
SET
|
||||||
|
Surname=@Surname,
|
||||||
|
Name=@Name,
|
||||||
|
MiddleName=@MiddleName
|
||||||
|
WHERE Id=@Id";
|
||||||
|
connection.Execute(queryUpdate, teacher);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,18 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Npgsql" Version="9.0.1" />
|
||||||
|
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||||
<PackageReference Include="Unity" Version="5.11.10" />
|
<PackageReference Include="Unity" Version="5.11.10" />
|
||||||
|
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "Logs/gas_log.txt",
|
||||||
|
"rollingInterval": "Day"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user