diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Entities/Retake.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Entities/Retake.cs new file mode 100644 index 0000000..fb14eb0 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Entities/Retake.cs @@ -0,0 +1,36 @@ +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 Retake +{ + public int Id { get; private set; } + + public int StudentId { get; private set; } + + public int TeacherId { get; private set; } + + public int DisciplineId { get; private set; } + + public Mark Mark { get; private set; } + + public DateTime Date { get; private set; } + + public static Retake CreateOperation(int id, int studentId, int teacherId, int disciplineId, Mark mark, DateTime date) + { + return new Retake + { + Id = id, + StudentId = studentId, + TeacherId = teacherId, + DisciplineId = disciplineId, + Mark = mark, + Date = date + }; + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Entities/Statement.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Entities/Statement.cs index 80ec2ee..2a1047b 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Entities/Statement.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Entities/Statement.cs @@ -8,14 +8,26 @@ public class Statement public DateTime Date { get; private set; } public IEnumerable StatementStudents { get; private set; } = []; - public static Statement CreateOperation(int id, int teacherId, int disciplineId, IEnumerable statementStudents) + public static Statement CreateOperation(int id, int teacherId, int disciplineId, DateTime date, IEnumerable statementStudents) { return new Statement { Id = id, TeacherId = teacherId, DisciplineId = disciplineId, - Date = DateTime.Now, + Date = date, + StatementStudents = statementStudents + }; + } + + public static Statement CreateOperation(TempStatementStudent tempStatementStudent, IEnumerable statementStudents) + { + return new Statement + { + Id = tempStatementStudent.Id, + TeacherId = tempStatementStudent.TeacherId, + DisciplineId = tempStatementStudent.DisciplineId, + Date = tempStatementStudent.Date, StatementStudents = statementStudents }; } diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Entities/TempStatementStudent.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Entities/TempStatementStudent.cs new file mode 100644 index 0000000..81a5400 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Entities/TempStatementStudent.cs @@ -0,0 +1,18 @@ +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 TempStatementStudent +{ + 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 int StudentId { get; private set; } + public Mark Mark { get; private set; } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/FormSessionResults.Designer.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/FormSessionResults.Designer.cs index 95c4f20..a17f5e6 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/FormSessionResults.Designer.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/FormSessionResults.Designer.cs @@ -36,7 +36,11 @@ DisciplinesToolStripMenuItem = new ToolStripMenuItem(); опереToolStripMenuItem = new ToolStripMenuItem(); AddMarksToolStripMenuItem = new ToolStripMenuItem(); + toolStripMenuItemRetake = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); + toolStripMenuItemDocReport = new ToolStripMenuItem(); + toolStripMenuItemStudentReport = new ToolStripMenuItem(); + toolStripMenuItemMarksDistribution = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); SuspendLayout(); // @@ -59,34 +63,34 @@ // StudentsToolStripMenuItem // StudentsToolStripMenuItem.Name = "StudentsToolStripMenuItem"; - StudentsToolStripMenuItem.Size = new Size(180, 22); + StudentsToolStripMenuItem.Size = new Size(159, 22); StudentsToolStripMenuItem.Text = "Студенты"; StudentsToolStripMenuItem.Click += StudentsToolStripMenuItem_Click; // // GroupsToolStripMenuItem // GroupsToolStripMenuItem.Name = "GroupsToolStripMenuItem"; - GroupsToolStripMenuItem.Size = new Size(180, 22); + GroupsToolStripMenuItem.Size = new Size(159, 22); GroupsToolStripMenuItem.Text = "Группы"; GroupsToolStripMenuItem.Click += GroupsToolStripMenuItem_Click; // // TeachersToolStripMenuItem // TeachersToolStripMenuItem.Name = "TeachersToolStripMenuItem"; - TeachersToolStripMenuItem.Size = new Size(180, 22); + TeachersToolStripMenuItem.Size = new Size(159, 22); TeachersToolStripMenuItem.Text = "Преподаватели"; TeachersToolStripMenuItem.Click += TeachersToolStripMenuItem_Click; // // DisciplinesToolStripMenuItem // DisciplinesToolStripMenuItem.Name = "DisciplinesToolStripMenuItem"; - DisciplinesToolStripMenuItem.Size = new Size(180, 22); + DisciplinesToolStripMenuItem.Size = new Size(159, 22); DisciplinesToolStripMenuItem.Text = "Дисциплины"; DisciplinesToolStripMenuItem.Click += DisciplinesToolStripMenuItem_Click; // // опереToolStripMenuItem // - опереToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AddMarksToolStripMenuItem }); + опереToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AddMarksToolStripMenuItem, toolStripMenuItemRetake }); опереToolStripMenuItem.Name = "опереToolStripMenuItem"; опереToolStripMenuItem.Size = new Size(75, 20); опереToolStripMenuItem.Text = "Операции"; @@ -98,12 +102,41 @@ AddMarksToolStripMenuItem.Text = "Создание результатов сессии"; AddMarksToolStripMenuItem.Click += AddMarksToolStripMenuItem_Click; // + // toolStripMenuItemRetake + // + toolStripMenuItemRetake.Name = "toolStripMenuItemRetake"; + toolStripMenuItemRetake.Size = new Size(236, 22); + toolStripMenuItemRetake.Text = "Создание пересдачи"; + toolStripMenuItemRetake.Click += toolStripMenuItemRetake_Click; + // // отчетыToolStripMenuItem // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemDocReport, toolStripMenuItemStudentReport, toolStripMenuItemMarksDistribution }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; отчетыToolStripMenuItem.Size = new Size(60, 20); отчетыToolStripMenuItem.Text = "Отчеты"; // + // toolStripMenuItemDocReport + // + toolStripMenuItemDocReport.Name = "toolStripMenuItemDocReport"; + toolStripMenuItemDocReport.Size = new Size(235, 22); + toolStripMenuItemDocReport.Text = "Документ со справочниками"; + toolStripMenuItemDocReport.Click += toolStripMenuItemDocReport_Click; + // + // toolStripMenuItemStudentReport + // + toolStripMenuItemStudentReport.Name = "toolStripMenuItemStudentReport"; + toolStripMenuItemStudentReport.Size = new Size(235, 22); + toolStripMenuItemStudentReport.Text = "Успеваемость студента"; + toolStripMenuItemStudentReport.Click += toolStripMenuItemStudentReport_Click; + // + // toolStripMenuItemMarksDistribution + // + toolStripMenuItemMarksDistribution.Name = "toolStripMenuItemMarksDistribution"; + toolStripMenuItemMarksDistribution.Size = new Size(235, 22); + toolStripMenuItemMarksDistribution.Text = "Выставленные оценки"; + toolStripMenuItemMarksDistribution.Click += toolStripMenuItemMarksDistribution_Click; + // // FormSessionResults // AutoScaleDimensions = new SizeF(7F, 15F); @@ -133,5 +166,9 @@ private ToolStripMenuItem опереToolStripMenuItem; private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem AddMarksToolStripMenuItem; + private ToolStripMenuItem toolStripMenuItemRetake; + private ToolStripMenuItem toolStripMenuItemDocReport; + private ToolStripMenuItem toolStripMenuItemStudentReport; + private ToolStripMenuItem toolStripMenuItemMarksDistribution; } } \ No newline at end of file diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/FormSessionResults.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/FormSessionResults.cs index b9dc61c..de3f485 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/FormSessionResults.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/FormSessionResults.cs @@ -81,4 +81,52 @@ public partial class FormSessionResults : Form MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void toolStripMenuItemRetake_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void toolStripMenuItemDocReport_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void toolStripMenuItemStudentReport_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void toolStripMenuItemMarksDistribution_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormDirectoryReport.Designer.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormDirectoryReport.Designer.cs new file mode 100644 index 0000000..1a72402 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormDirectoryReport.Designer.cs @@ -0,0 +1,112 @@ +namespace SessionResults_Kudyaeva.Forms +{ + partial class FormDirectoryReport + { + /// + /// 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() + { + checkBoxDisciplines = new CheckBox(); + checkBoxGroups = new CheckBox(); + checkBoxStudents = new CheckBox(); + checkBoxTeachers = new CheckBox(); + buttonBuild = new Button(); + SuspendLayout(); + // + // checkBoxDisciplines + // + checkBoxDisciplines.AutoSize = true; + checkBoxDisciplines.Location = new Point(12, 12); + checkBoxDisciplines.Name = "checkBoxDisciplines"; + checkBoxDisciplines.Size = new Size(83, 19); + checkBoxDisciplines.TabIndex = 0; + checkBoxDisciplines.Text = "Предметы"; + checkBoxDisciplines.UseVisualStyleBackColor = true; + // + // checkBoxGroups + // + checkBoxGroups.AutoSize = true; + checkBoxGroups.Location = new Point(12, 46); + checkBoxGroups.Name = "checkBoxGroups"; + checkBoxGroups.Size = new Size(68, 19); + checkBoxGroups.TabIndex = 1; + checkBoxGroups.Text = "Группы"; + checkBoxGroups.UseVisualStyleBackColor = true; + // + // checkBoxStudents + // + checkBoxStudents.AutoSize = true; + checkBoxStudents.Location = new Point(12, 82); + checkBoxStudents.Name = "checkBoxStudents"; + checkBoxStudents.Size = new Size(78, 19); + checkBoxStudents.TabIndex = 2; + checkBoxStudents.Text = "Студенты"; + checkBoxStudents.UseVisualStyleBackColor = true; + // + // checkBoxTeachers + // + checkBoxTeachers.AutoSize = true; + checkBoxTeachers.Location = new Point(12, 118); + checkBoxTeachers.Name = "checkBoxTeachers"; + checkBoxTeachers.Size = new Size(111, 19); + checkBoxTeachers.TabIndex = 3; + checkBoxTeachers.Text = "Преподаватели"; + checkBoxTeachers.UseVisualStyleBackColor = true; + // + // buttonBuild + // + buttonBuild.Location = new Point(12, 159); + buttonBuild.Name = "buttonBuild"; + buttonBuild.Size = new Size(139, 23); + buttonBuild.TabIndex = 4; + buttonBuild.Text = "Сформировать"; + buttonBuild.UseVisualStyleBackColor = true; + buttonBuild.Click += buttonBuild_Click; + // + // FormDirectoryReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(167, 197); + Controls.Add(buttonBuild); + Controls.Add(checkBoxTeachers); + Controls.Add(checkBoxStudents); + Controls.Add(checkBoxGroups); + Controls.Add(checkBoxDisciplines); + Name = "FormDirectoryReport"; + Text = "FormDirectoryReport"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox checkBoxDisciplines; + private CheckBox checkBoxGroups; + private CheckBox checkBoxStudents; + private CheckBox checkBoxTeachers; + private Button buttonBuild; + } +} \ No newline at end of file diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormDirectoryReport.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormDirectoryReport.cs new file mode 100644 index 0000000..efa1b82 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormDirectoryReport.cs @@ -0,0 +1,52 @@ +using SessionResults_Kudyaeva.Reports; +using Unity; + +namespace SessionResults_Kudyaeva.Forms; + +public partial class FormDirectoryReport : Form +{ + private readonly IUnityContainer _container; + public FormDirectoryReport(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void buttonBuild_Click(object sender, EventArgs e) + { + try + { + if (!checkBoxDisciplines.Checked && !checkBoxGroups.Checked && !checkBoxStudents.Checked && !checkBoxTeachers.Checked) + { + throw new Exception("Не выбран ни один справочник для выгрузки"); + } + var sfd = new SaveFileDialog() + { + Filter = "Docx Files | *.docx" + }; + if (sfd.ShowDialog() != DialogResult.OK) + { + throw new Exception("Не выбран файла для отчета"); + } + if + (_container.Resolve().CreateDoc(sfd.FileName, checkBoxDisciplines.Checked, checkBoxGroups.Checked, checkBoxStudents.Checked, checkBoxTeachers.Checked)) + { + MessageBox.Show("Документ сформирован", + "Формирование документа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", + "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormDirectoryReport.resx b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormDirectoryReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormDirectoryReport.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/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormMarksDistributionReport.Designer.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormMarksDistributionReport.Designer.cs new file mode 100644 index 0000000..4aba1c2 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormMarksDistributionReport.Designer.cs @@ -0,0 +1,107 @@ +namespace SessionResults_Kudyaeva.Forms +{ + partial class FormMarksDistributionReport + { + /// + /// 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() + { + dateTimePicker = new DateTimePicker(); + label1 = new Label(); + labelFileName = new Label(); + buttonFile = new Button(); + buttonBuild = new Button(); + SuspendLayout(); + // + // dateTimePicker + // + dateTimePicker.Location = new Point(70, 44); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(200, 23); + dateTimePicker.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(29, 50); + label1.Name = "label1"; + label1.Size = new Size(35, 15); + label1.TabIndex = 1; + label1.Text = "Дата:"; + // + // labelFileName + // + labelFileName.AutoSize = true; + labelFileName.Location = new Point(111, 16); + labelFileName.Name = "labelFileName"; + labelFileName.Size = new Size(36, 15); + labelFileName.TabIndex = 2; + labelFileName.Text = "Файл"; + // + // buttonFile + // + buttonFile.Location = new Point(29, 12); + buttonFile.Name = "buttonFile"; + buttonFile.Size = new Size(75, 23); + buttonFile.TabIndex = 3; + buttonFile.Text = "Выбрать"; + buttonFile.UseVisualStyleBackColor = true; + buttonFile.Click += buttonFile_Click; + // + // buttonBuild + // + buttonBuild.Location = new Point(29, 85); + buttonBuild.Name = "buttonBuild"; + buttonBuild.Size = new Size(241, 23); + buttonBuild.TabIndex = 4; + buttonBuild.Text = "Сформировать"; + buttonBuild.UseVisualStyleBackColor = true; + buttonBuild.Click += buttonBuild_Click; + // + // FormContractorFuelDistributionReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(291, 137); + Controls.Add(buttonBuild); + Controls.Add(buttonFile); + Controls.Add(labelFileName); + Controls.Add(label1); + Controls.Add(dateTimePicker); + Name = "FormContractorFuelDistributionReport"; + Text = "FormContractorFuelDistributionReport"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker dateTimePicker; + private Label label1; + private Label labelFileName; + private Button buttonFile; + private Button buttonBuild; + } +} \ No newline at end of file diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormMarksDistributionReport.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormMarksDistributionReport.cs new file mode 100644 index 0000000..4439e31 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormMarksDistributionReport.cs @@ -0,0 +1,60 @@ +using SessionResults_Kudyaeva.Reports; +using Unity; + +namespace SessionResults_Kudyaeva.Forms +{ + public partial class FormMarksDistributionReport : Form + { + private string _fileName = string.Empty; + private readonly IUnityContainer _container; + public FormMarksDistributionReport(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void buttonBuild_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(_fileName)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + if + (_container.Resolve().CreateChart(_fileName, dateTimePicker.Value)) + { + MessageBox.Show("Документ сформирован", + "Формирование документа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", + "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании очета", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void buttonFile_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Pdf Files | *.pdf" + }; + if (sfd.ShowDialog() == DialogResult.OK) + { + _fileName = sfd.FileName; + labelFileName.Text = Path.GetFileName(_fileName); + } + } + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormMarksDistributionReport.resx b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormMarksDistributionReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormMarksDistributionReport.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/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormStudentReport.Designer.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormStudentReport.Designer.cs new file mode 100644 index 0000000..0a0a135 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormStudentReport.Designer.cs @@ -0,0 +1,162 @@ +namespace SessionResults_Kudyaeva.Forms +{ + partial class FormStudentReport + { + /// + /// 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() + { + dateTimePickerEnd = new DateTimePicker(); + dateTimePickerStart = new DateTimePicker(); + comboBoxStudent = new ComboBox(); + textBoxFilePath = new TextBox(); + buttonFile = new Button(); + buttonBuild = new Button(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + SuspendLayout(); + // + // dateTimePickerEnd + // + dateTimePickerEnd.Location = new Point(118, 137); + dateTimePickerEnd.Name = "dateTimePickerEnd"; + dateTimePickerEnd.Size = new Size(200, 23); + dateTimePickerEnd.TabIndex = 0; + // + // dateTimePickerStart + // + dateTimePickerStart.Location = new Point(118, 99); + dateTimePickerStart.Name = "dateTimePickerStart"; + dateTimePickerStart.Size = new Size(200, 23); + dateTimePickerStart.TabIndex = 1; + // + // comboBoxStudent + // + comboBoxStudent.FormattingEnabled = true; + comboBoxStudent.Location = new Point(118, 59); + comboBoxStudent.Name = "comboBoxStudent"; + comboBoxStudent.Size = new Size(198, 23); + comboBoxStudent.TabIndex = 2; + // + // textBoxFilePath + // + textBoxFilePath.Location = new Point(118, 20); + textBoxFilePath.Name = "textBoxFilePath"; + textBoxFilePath.Size = new Size(166, 23); + textBoxFilePath.TabIndex = 3; + // + // buttonFile + // + buttonFile.Location = new Point(290, 20); + buttonFile.Name = "buttonFile"; + buttonFile.Size = new Size(26, 23); + buttonFile.TabIndex = 4; + buttonFile.Text = "..."; + buttonFile.UseVisualStyleBackColor = true; + buttonFile.Click += buttonFile_Click; + // + // buttonBuild + // + buttonBuild.Location = new Point(22, 181); + buttonBuild.Name = "buttonBuild"; + buttonBuild.Size = new Size(296, 23); + buttonBuild.TabIndex = 5; + buttonBuild.Text = "Сформировать"; + buttonBuild.UseVisualStyleBackColor = true; + buttonBuild.Click += buttonBuild_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(22, 23); + label1.Name = "label1"; + label1.Size = new Size(90, 15); + label1.TabIndex = 6; + label1.Text = "Путь до файла:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(22, 62); + label2.Name = "label2"; + label2.Size = new Size(53, 15); + label2.TabIndex = 7; + label2.Text = "Студент:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(22, 105); + label3.Name = "label3"; + label3.Size = new Size(77, 15); + label3.TabIndex = 8; + label3.Text = "Дата начала:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(22, 143); + label4.Name = "label4"; + label4.Size = new Size(71, 15); + label4.TabIndex = 9; + label4.Text = "Дата конца:"; + // + // FormStudentReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(345, 227); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonBuild); + Controls.Add(buttonFile); + Controls.Add(textBoxFilePath); + Controls.Add(comboBoxStudent); + Controls.Add(dateTimePickerStart); + Controls.Add(dateTimePickerEnd); + Name = "FormStudentReport"; + Text = "Отчет по студенту"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker dateTimePickerEnd; + private DateTimePicker dateTimePickerStart; + private ComboBox comboBoxStudent; + private TextBox textBoxFilePath; + private Button buttonFile; + private Button buttonBuild; + private Label label1; + private Label label2; + private Label label3; + private Label label4; + } +} \ No newline at end of file diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormStudentReport.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormStudentReport.cs new file mode 100644 index 0000000..2546257 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormStudentReport.cs @@ -0,0 +1,72 @@ +using SessionResults_Kudyaeva.Reports; +using SessionResults_Kudyaeva.Repositories; +using Unity; + +namespace SessionResults_Kudyaeva.Forms +{ + public partial class FormStudentReport : Form + { + private readonly IUnityContainer _container; + + public FormStudentReport(IUnityContainer container, IStudentRepository studentRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + + comboBoxStudent.DataSource = studentRepository.GetAllStudents(); + comboBoxStudent.DisplayMember = "DisplayName"; + comboBoxStudent.ValueMember = "Id"; + } + + private void buttonFile_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Excel Files | *.xlsx" + }; + if (sfd.ShowDialog() != DialogResult.OK) + { + return; + } + textBoxFilePath.Text = sfd.FileName; + } + + private void buttonBuild_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFilePath.Text)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + if (comboBoxStudent.SelectedIndex < 0) + { + throw new Exception("Не выбран студент"); + } + if (dateTimePickerEnd.Value <= dateTimePickerStart.Value) + { + throw new Exception("Дата начала должна быть раньше даты окончания"); + } + if (_container.Resolve().CreateTable(textBoxFilePath.Text,(int)comboBoxStudent.SelectedValue!, dateTimePickerStart.Value, dateTimePickerEnd.Value)) + { + MessageBox.Show("Документ сформирован", + "Формирование документа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", + "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании очета", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormStudentReport.resx b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormStudentReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/FormStudentReport.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/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeForm.Designer.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeForm.Designer.cs new file mode 100644 index 0000000..0de7f48 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeForm.Designer.cs @@ -0,0 +1,172 @@ +namespace SessionResults_Kudyaeva.Forms +{ + partial class RetakeForm + { + /// + /// 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() + { + lblSurname = new Label(); + lblName = new Label(); + lblMiddleName = new Label(); + lblGroup = new Label(); + ButtonSave = new Button(); + ButtonCancel = new Button(); + comboBoxStudent = new ComboBox(); + comboBoxTeacher = new ComboBox(); + comboBoxDiscipline = new ComboBox(); + comboBoxMark = new ComboBox(); + SuspendLayout(); + // + // lblSurname + // + lblSurname.AutoSize = true; + lblSurname.Location = new Point(38, 39); + lblSurname.Name = "lblSurname"; + lblSurname.Size = new Size(50, 15); + lblSurname.TabIndex = 0; + lblSurname.Text = "Студент"; + // + // lblName + // + lblName.AutoSize = true; + lblName.Location = new Point(38, 69); + lblName.Name = "lblName"; + lblName.Size = new Size(91, 15); + lblName.TabIndex = 1; + lblName.Text = "Преподаватель"; + // + // lblMiddleName + // + lblMiddleName.AutoSize = true; + lblMiddleName.Location = new Point(38, 101); + lblMiddleName.Name = "lblMiddleName"; + lblMiddleName.Size = new Size(55, 15); + lblMiddleName.TabIndex = 2; + lblMiddleName.Text = "Предмет"; + // + // lblGroup + // + lblGroup.AutoSize = true; + lblGroup.Location = new Point(38, 130); + lblGroup.Name = "lblGroup"; + lblGroup.Size = new Size(48, 15); + lblGroup.TabIndex = 3; + lblGroup.Text = "Оценка"; + // + // ButtonSave + // + ButtonSave.Location = new Point(38, 176); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(96, 23); + ButtonSave.TabIndex = 8; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(183, 176); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(96, 23); + ButtonCancel.TabIndex = 9; + ButtonCancel.Text = "Отменить"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // comboBoxStudent + // + comboBoxStudent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStudent.FormattingEnabled = true; + comboBoxStudent.Location = new Point(138, 36); + comboBoxStudent.Name = "comboBoxStudent"; + comboBoxStudent.Size = new Size(141, 23); + comboBoxStudent.TabIndex = 10; + // + // comboBoxTeacher + // + comboBoxTeacher.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxTeacher.FormattingEnabled = true; + comboBoxTeacher.Location = new Point(138, 66); + comboBoxTeacher.Name = "comboBoxTeacher"; + comboBoxTeacher.Size = new Size(141, 23); + comboBoxTeacher.TabIndex = 11; + // + // comboBoxDiscipline + // + comboBoxDiscipline.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxDiscipline.FormattingEnabled = true; + comboBoxDiscipline.Location = new Point(138, 98); + comboBoxDiscipline.Name = "comboBoxDiscipline"; + comboBoxDiscipline.Size = new Size(141, 23); + comboBoxDiscipline.TabIndex = 12; + // + // comboBoxMark + // + comboBoxMark.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxMark.FormattingEnabled = true; + comboBoxMark.Location = new Point(138, 127); + comboBoxMark.Name = "comboBoxMark"; + comboBoxMark.Size = new Size(141, 23); + comboBoxMark.TabIndex = 13; + // + // RetakeForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(331, 224); + Controls.Add(comboBoxMark); + Controls.Add(comboBoxDiscipline); + Controls.Add(comboBoxTeacher); + Controls.Add(comboBoxStudent); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(lblGroup); + Controls.Add(lblMiddleName); + Controls.Add(lblName); + Controls.Add(lblSurname); + Name = "RetakeForm"; + Text = "Пересдача"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label lblSurname; + private Label lblName; + private Label lblMiddleName; + private Label lblGroup; + private TextBox textBoxSurname; + private TextBox textBoxName; + private TextBox textBoxMiddleName; + private Button ButtonSave; + private Button ButtonCancel; + private ComboBox comboBoxStudent; + private ComboBox comboBoxTeacher; + private ComboBox comboBoxDiscipline; + private ComboBox comboBoxMark; + } +} \ No newline at end of file diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeForm.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeForm.cs new file mode 100644 index 0000000..387cc6a --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeForm.cs @@ -0,0 +1,54 @@ +using SessionResults_Kudyaeva.Entities; +using SessionResults_Kudyaeva.Entities.Enums; +using SessionResults_Kudyaeva.Repositories; + +namespace SessionResults_Kudyaeva.Forms; + +public partial class RetakeForm : Form +{ + private readonly IRetakeRepository _retakeRepository; + + public RetakeForm(IRetakeRepository retakeRepository, IStudentRepository studentRepository, ITeacherRepository teacherRepository, IDisciplineRepository disciplineRepository) + { + InitializeComponent(); + comboBoxStudent.DataSource = studentRepository.GetAllStudents(); + comboBoxStudent.DisplayMember = "DisplayName"; + comboBoxStudent.ValueMember = "Id"; + + comboBoxTeacher.DataSource = teacherRepository.GetAllTeachers(); + comboBoxTeacher.DisplayMember = "DisplayName"; + comboBoxTeacher.ValueMember = "Id"; + + comboBoxDiscipline.DataSource = disciplineRepository.GetAllDisciplines(); + comboBoxDiscipline.DisplayMember = "Name"; + comboBoxDiscipline.ValueMember = "Id"; + + comboBoxMark.DataSource = Enum.GetValues(typeof(Mark)).Cast().ToList(); + + _retakeRepository = retakeRepository ?? + throw new ArgumentNullException(nameof(retakeRepository)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxDiscipline.SelectedItem == null || + comboBoxTeacher.SelectedItem == null || + comboBoxStudent.SelectedItem == null) + { + throw new Exception("Имеются незаполненные поля"); + } + + _retakeRepository.CreateRetake(Retake.CreateOperation(0, (int)comboBoxStudent.SelectedValue!, (int)comboBoxTeacher.SelectedValue!, (int)comboBoxDiscipline.SelectedValue!, (Mark)comboBoxMark.SelectedValue!, DateTime.Now )); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeForm.resx b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeForm.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/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeListForm.Designer.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeListForm.Designer.cs new file mode 100644 index 0000000..c456b79 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeListForm.Designer.cs @@ -0,0 +1,97 @@ +namespace SessionResults_Kudyaeva.Forms +{ + partial class RetakeListForm + { + /// + /// 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() + { + panel1 = new Panel(); + ButtonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(ButtonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(845, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(114, 449); + panel1.TabIndex = 0; + // + // ButtonAdd + // + ButtonAdd.BackgroundImage = Properties.Resources.Add; + ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonAdd.Location = new Point(6, 12); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(100, 100); + ButtonAdd.TabIndex = 3; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(845, 449); + dataGridViewData.TabIndex = 4; + // + // RetakeListForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(959, 449); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "RetakeListForm"; + Text = "Создание пересдачи"; + Load += RetakeListForm_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button ButtonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeListForm.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeListForm.cs new file mode 100644 index 0000000..f8765ca --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeListForm.cs @@ -0,0 +1,44 @@ +using SessionResults_Kudyaeva.Repositories; +using Unity; + +namespace SessionResults_Kudyaeva.Forms; + +public partial class RetakeListForm : Form +{ + private readonly IUnityContainer _container; + private readonly IRetakeRepository _retakeRepository; + + public RetakeListForm(IUnityContainer container, IRetakeRepository retakeRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _retakeRepository = retakeRepository ?? throw new ArgumentNullException(nameof(retakeRepository)); + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _retakeRepository.GetAllRetakes(); + + private void RetakeListForm_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeListForm.resx b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeListForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/RetakeListForm.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/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/StatementForm.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/StatementForm.cs index e5716f5..3cfef7c 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/StatementForm.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/StatementForm.cs @@ -44,6 +44,7 @@ public partial class StatementForm : Form _statementRepository.CreateStatement(Statement.CreateOperation(0, (int)comboBoxTeacher.SelectedValue!, (int)comboBoxDiscipline.SelectedValue!, + DateTime.Now, CreateListStatementStudentFromDataGrid())); Close(); diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/StudentForm.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/StudentForm.cs index 9f46365..7a5d4d8 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/StudentForm.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Forms/StudentForm.cs @@ -1,21 +1,11 @@ using SessionResults_Kudyaeva.Entities; 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 StudentForm : Form { private readonly IStudentRepository _studentRepository; - private readonly IGroupRepository _groupRepository; private int? _studentId; public int Id @@ -51,9 +41,6 @@ public partial class StudentForm : Form comboBoxGroup.ValueMember = "Id"; _studentRepository = studentRepository ?? throw new ArgumentNullException(nameof(studentRepository)); - _groupRepository = groupRepository ?? - throw new ArgumentNullException(nameof(groupRepository)); - } private void ButtonSave_Click(object sender, EventArgs e) diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Program.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Program.cs index 49c9180..9f58290 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Program.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Program.cs @@ -6,8 +6,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Serilog; using Unity.Microsoft.Logging; -using ProjectGasStation.Repositories.Implementations; -using ProjectGasStation.Repositories; namespace SessionResults_Kudyaeva { @@ -36,6 +34,7 @@ namespace SessionResults_Kudyaeva container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); container.RegisterType(); diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/ChartReport.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/ChartReport.cs new file mode 100644 index 0000000..68dec3a --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/ChartReport.cs @@ -0,0 +1,45 @@ +using Microsoft.Extensions.Logging; +using SessionResults_Kudyaeva.Repositories; + +namespace SessionResults_Kudyaeva.Reports; + +internal class ChartReport +{ + private readonly IStatementRepository _statementRepository; + private readonly ILogger _logger; + + public ChartReport(IStatementRepository statementRepository, ILogger logger) + { + _statementRepository = statementRepository ?? throw new ArgumentNullException(nameof(statementRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateChart(string filePath, DateTime dateTime) + { + try + { + new PdfBuilder(filePath) + .AddHeader("Выставленные оценки по предметам") + .AddPieChart("Предметы", GetData(dateTime)) + .Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + private List<(string Caption, double Value)> GetData(DateTime dateTime) + { + return _statementRepository + .GetAllStatements() + .Where(x => x.Date.Date == dateTime.Date) + .GroupBy(x => x.DisciplineId, (key, group) => new { + Id = key, + Count = group.Sum(statement => statement.StatementStudents.Count()) + }) + .Select(x => (x.Id.ToString(), (double)x.Count)) + .ToList(); + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/DocReport.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/DocReport.cs new file mode 100644 index 0000000..8299607 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/DocReport.cs @@ -0,0 +1,93 @@ +using Microsoft.Extensions.Logging; +using SessionResults_Kudyaeva.Repositories; + +namespace SessionResults_Kudyaeva.Reports; + +public class DocReport +{ + private readonly IDisciplineRepository _disciplineRepository; + private readonly IGroupRepository _groupRepository; + private readonly IStudentRepository _studentRepository; + private readonly ITeacherRepository _teacherRepository; + private readonly ILogger _logger; + + public DocReport(IDisciplineRepository disciplineRepository, IGroupRepository groupRepository, IStudentRepository studentRepository, ITeacherRepository teacherRepository, ILogger logger) + { + _disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository)); + _groupRepository = groupRepository ?? throw new ArgumentNullException(nameof(groupRepository)); + _studentRepository = studentRepository ?? throw new ArgumentNullException(nameof(studentRepository)); + _teacherRepository = teacherRepository ?? throw new ArgumentNullException(nameof(teacherRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateDoc(string filePath, bool includeDisciplines, bool includeGroups, bool includeStudents, bool includeTeachers) + { + try + { + var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками"); + if (includeDisciplines) + { + builder.AddParagraph("Предметы").AddTable([2400, 2400, 2400], GetDisciplines()); + } + if (includeGroups) + { + builder.AddParagraph("Группы").AddTable([2400, 2400], GetGroups()); + } + if (includeStudents) + { + builder.AddParagraph("Студенты").AddTable([2400, 2400, 2400], GetStudents()); + } + if (includeTeachers) + { + builder.AddParagraph("Преподаватели").AddTable([2400, 2400, 2400], GetTeachers()); + } + builder.Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List GetDisciplines() + { + return [ + ["Название", "Описание", "На каких курсах"], + .. _disciplineRepository + .GetAllDisciplines() + .Select(x => new string[] { x.Name, x.Description, x.Courses.ToString() }), + ]; + } + + private List GetGroups() + { + return [ + ["Название", "Тип"], + .. _groupRepository + .GetAllGroups() + .Select(x => new string[] { x.Name, x.Type.ToString() }), + ]; + } + + private List GetStudents() + { + return [ + ["Фамилия", "Имя", "Отчество"], + .. _studentRepository + .GetAllStudents() + .Select(x => new string[] { x.Surname, x.Name, x.MiddleName }), + ]; + } + + private List GetTeachers() + { + return [ + ["Фамилия", "Имя", "Отчество"], + .. _teacherRepository + .GetAllTeachers() + .Select(x => new string[] { x.Surname, x.Name, x.MiddleName }), + ]; + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/ExcelBuilder.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/ExcelBuilder.cs new file mode 100644 index 0000000..49e89a5 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/ExcelBuilder.cs @@ -0,0 +1,311 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml; + +namespace SessionResults_Kudyaeva.Reports; + +internal class ExcelBuilder +{ + private readonly string _filePath; + private readonly SheetData _sheetData; + private readonly MergeCells _mergeCells; + private readonly Columns _columns; + private uint _rowIndex = 0; + + public ExcelBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _sheetData = new SheetData(); + _mergeCells = new MergeCells(); + _columns = new Columns(); + _rowIndex = 1; + } + + public ExcelBuilder AddHeader(string header, int startIndex, int count) + { + CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithoutBorder); + for (int i = startIndex + 1; i < startIndex + count; ++i) + { + CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder); + } + _mergeCells.Append(new MergeCell() + { + Reference = new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}") + }); + _rowIndex++; + return this; + } + + public ExcelBuilder AddParagraph(string text, int columnIndex) + { + CreateCell(columnIndex, _rowIndex++, text, StyleIndex.SimpleTextWithoutBorder); + return this; + } + + public ExcelBuilder AddTable(int[] columnsWidths, List data) + { + if (columnsWidths == null || columnsWidths.Length == 0) + { + throw new ArgumentNullException(nameof(columnsWidths)); + } + if (data == null || data.Count == 0) + { + throw new ArgumentNullException(nameof(data)); + } + if (data.Any(x => x.Length != columnsWidths.Length)) + { + throw new InvalidOperationException("widths.Length != data.Length"); + } + + uint counter = 1; + int coef = 2; + _columns.Append(columnsWidths.Select(x => new Column + { + Min = counter, + Max = counter++, + Width = x * coef, + CustomWidth = true + })); + for (var j = 0; j < data.First().Length; ++j) + { + CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder); + } + _rowIndex++; + + for (var i = 1; i < data.Count - 1; ++i) + { + for (var j = 0; j < data[i].Length; ++j) + { + CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder); + } + _rowIndex++; + } + for (var j = 0; j < data.Last().Length; ++j) + { + CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder); + } + _rowIndex++; + return this; + } + + public void Build() + { + using var spreadsheetDocument = SpreadsheetDocument.Create(_filePath, SpreadsheetDocumentType.Workbook); + var workbookpart = spreadsheetDocument.AddWorkbookPart(); + GenerateStyle(workbookpart); + workbookpart.Workbook = new Workbook(); + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(); + + if (_columns.HasChildren) + { + worksheetPart.Worksheet.Append(_columns); + } + + worksheetPart.Worksheet.Append(_sheetData); + var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист 1" + }; + sheets.Append(sheet); + if (_mergeCells.HasChildren) + { + worksheetPart.Worksheet.InsertAfter(_mergeCells, + worksheetPart.Worksheet.Elements().First()); + } + } + + private static void GenerateStyle(WorkbookPart workbookPart) + { + var workbookStylesPart = workbookPart.AddNewPart(); + workbookStylesPart.Stylesheet = new Stylesheet(); + + var fonts = new Fonts() + { + Count = 2, + KnownFonts = BooleanValue.FromBoolean(true) + }; + fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font + { + FontSize = new FontSize() { Val = 11 }, + FontName = new FontName() { Val = "Calibri" }, + FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }, + FontScheme = new FontScheme() + { + Val = new EnumValue(FontSchemeValues.Minor) + } + }); + fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font + { + FontSize = new FontSize() { Val = 11 }, + FontName = new FontName() { Val = "Calibri" }, + FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }, + FontScheme = new FontScheme() + { + Val = new EnumValue(FontSchemeValues.Minor) + }, + Bold = new Bold() { Val = true } + }); + workbookStylesPart.Stylesheet.Append(fonts); + + // Default Fill + var fills = new Fills() { Count = 1 }; + fills.Append(new Fill + { + PatternFill = new PatternFill() + { + PatternType = new EnumValue(PatternValues.None) + } + }); + workbookStylesPart.Stylesheet.Append(fills); + + // Default Border + var borders = new Borders() { Count = 2 }; + borders.Append(new Border + { + LeftBorder = new LeftBorder(), + RightBorder = new RightBorder(), + TopBorder = new TopBorder(), + BottomBorder = new BottomBorder(), + DiagonalBorder = new DiagonalBorder() + }); + borders.Append(new Border + { + LeftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }, + RightBorder = new RightBorder() { Style = BorderStyleValues.Thin }, + TopBorder = new TopBorder() { Style = BorderStyleValues.Thin }, + BottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }, + DiagonalBorder = new DiagonalBorder() + }); + workbookStylesPart.Stylesheet.Append(borders); + + // Default cell format and a date cell format + var cellFormats = new CellFormats() { Count = 4 }; + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 0, + BorderId = 0, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Left, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 0, + BorderId = 1, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Right, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 1, + BorderId = 0, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Center, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 1, + BorderId = 1, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Center, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + workbookStylesPart.Stylesheet.Append(cellFormats); + } + + private enum StyleIndex + { + SimpleTextWithoutBorder = 0, + SimpleTextWithBorder = 1, + BoldTextWithoutBorder = 2, + BoldTextWithBorder = 3, + } + + private void CreateCell(int columnIndex, uint rowIndex, string text, StyleIndex styleIndex) + { + var columnName = GetExcelColumnName(columnIndex); + var cellReference = columnName + rowIndex; + var row = _sheetData.Elements().FirstOrDefault(r => r.RowIndex! == rowIndex); + if (row == null) + { + row = new Row() { RowIndex = rowIndex }; + _sheetData.Append(row); + } + var newCell = row.Elements().FirstOrDefault(c => c.CellReference != null && + c.CellReference.Value == columnName + rowIndex); + if (newCell == null) + { + Cell? refCell = null; + foreach (Cell cell in row.Elements()) + { + if (cell.CellReference?.Value != null && + cell.CellReference.Value.Length == cellReference.Length) + { + if (string.Compare(cell.CellReference.Value, cellReference, true) > 0) + { + refCell = cell; + break; + } + } + } + newCell = new Cell() { CellReference = cellReference }; + row.InsertBefore(newCell, refCell); + } + newCell.CellValue = new CellValue(text); + newCell.DataType = CellValues.String; + newCell.StyleIndex = (uint)styleIndex; + } + + private static string GetExcelColumnName(int columnNumber) + { + columnNumber += 1; + int dividend = columnNumber; + string columnName = string.Empty; + int modulo; + while (dividend > 0) + { + modulo = (dividend - 1) % 26; + columnName = Convert.ToChar(65 + modulo).ToString() + columnName; + dividend = (dividend - modulo) / 26; + } + return columnName; + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/PdfBuilder.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/PdfBuilder.cs new file mode 100644 index 0000000..a8e03b8 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/PdfBuilder.cs @@ -0,0 +1,76 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Shapes.Charts; +using MigraDoc.Rendering; +using System.Text; + +namespace SessionResults_Kudyaeva.Reports; + +internal class PdfBuilder +{ + private readonly string _filePath; + private readonly Document _document; + + public PdfBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _document = new Document(); + DefineStyles(); + } + + public PdfBuilder AddHeader(string header) + { + _document.AddSection().AddParagraph(header, "NormalBold"); + return this; + } + + public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data) + { + if (data == null || data.Count == 0) + { + return this; + } + var chart = new Chart(ChartType.Pie2D); + var series = chart.SeriesCollection.AddSeries(); + series.Add(data.Select(x => x.Value).ToArray()); + var xseries = chart.XValues.AddXSeries(); + xseries.Add(data.Select(x => x.Caption).ToArray()); + chart.DataLabel.Type = DataLabelType.Percent; + chart.DataLabel.Position = DataLabelPosition.OutsideEnd; + chart.Width = Unit.FromCentimeter(16); + chart.Height = Unit.FromCentimeter(12); + chart.TopArea.AddParagraph(title); + chart.XAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.HasMajorGridlines = true; + chart.PlotArea.LineFormat.Width = 1; + chart.PlotArea.LineFormat.Visible = true; + chart.TopArea.AddLegend(); + _document.LastSection.Add(chart); + return this; + } + + public void Build() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(_filePath); + } + private void DefineStyles() + { + var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal"); + headerStyle.Font.Bold = true; + headerStyle.Font.Size = 14; + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/TableReport.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/TableReport.cs new file mode 100644 index 0000000..af1bd5e --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/TableReport.cs @@ -0,0 +1,97 @@ +using Microsoft.Extensions.Logging; +using SessionResults_Kudyaeva.Entities.Enums; +using SessionResults_Kudyaeva.Repositories; + +namespace SessionResults_Kudyaeva.Reports; + +internal class TableReport +{ + private readonly IStatementRepository _statementRepository; + private readonly IRetakeRepository _retakeRepository; + private readonly ILogger _logger; + internal static readonly string[] item = ["Предмет", "Дата", "Оценка", "Пересдача"]; + + public TableReport(IStatementRepository statementRepository, IRetakeRepository retakeRepository, ILogger logger) + { + _statementRepository = statementRepository ?? throw new ArgumentNullException(nameof(statementRepository)); + _retakeRepository = retakeRepository ?? throw new ArgumentNullException(nameof(retakeRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateTable(string filePath, int studentId, DateTime startDate, DateTime endDate) + { + try + { + new ExcelBuilder(filePath) + .AddHeader("Сводка по оценкам студента", 0, 3) + .AddParagraph("за период", 0) + .AddTable([10, 15, 15, 15], GetData(studentId, startDate, endDate)) + .Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List GetData(int studentId, DateTime startDate, DateTime endDate) + { + var statements = _statementRepository + .GetAllStatements() + .Where(x => x.Date >= startDate && x.Date <= endDate && x.StatementStudents.Any(y => y.StudentId == studentId)) + .Select(x => new { + Discipline = x.DisciplineId.ToString(), + x.Date, + Mark = x.StatementStudents.FirstOrDefault(y => y.StudentId == studentId)?.Mark, + RetakeMark = (int?)null + }); + + var retakes = _retakeRepository + .GetAllRetakes() + .Where(x => x.Date >= startDate && x.Date <= endDate && x.StudentId == studentId) + .Select(x => new { + Discipline = x.DisciplineId.ToString(), + x.Date, + Mark = (Mark?)null, + RetakeMark = (int?)x.Mark + }); + + var data = statements + .Union(retakes) + .OrderBy(x => x.Date) + .Select(x => new string[] { + x.Discipline, + x.Date.ToString("dd.MM.yyyy"), + x.Mark.HasValue ? ((int)x.Mark.Value).ToString() : string.Empty, + x.RetakeMark.HasValue ? x.RetakeMark.Value.ToString() : string.Empty + }) + .ToList(); + + data.Insert(0, item); + + var averageMark = data.Skip(1) + .Select(row => double.TryParse(row[2], out var mark) ? mark : (double?)null) + .Where(mark => mark != null) + .Average(mark => mark.Value); + + var averageRetakeMark = data.Skip(1) + .Select(row => double.TryParse(row[3], out var retakeMark) ? retakeMark : (double?)null) + .Where(retakeMark => retakeMark != null) + .Average(retakeMark => retakeMark.Value); + + var averageRow = new string[] + { + "Среднее", + string.Empty, + ((double)averageMark) > 0 ? ((double)averageMark).ToString("F2") : string.Empty, + ((double)averageRetakeMark) > 0 ? ((double)averageRetakeMark).ToString("F2") : string.Empty + }; + + data.Add(averageRow); + + return data; + } + +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/WordBuilder.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/WordBuilder.cs new file mode 100644 index 0000000..e4c26f7 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Reports/WordBuilder.cs @@ -0,0 +1,129 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml.Packaging; + +namespace SessionResults_Kudyaeva.Reports; + +public class WordBuilder +{ + private readonly string _filePath; + private readonly Document _document; + private readonly Body _body; + + public WordBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _document = new Document(); + _body = _document.AppendChild(new Body()); + } + + public WordBuilder AddHeader(string header) + { + var paragraph = _body.AppendChild(new Paragraph()); + var run = paragraph.AppendChild(new Run()); + var runProperties = run.AppendChild(new RunProperties()); + runProperties.AppendChild(new Bold()); + run.AppendChild(new Text(header)); + return this; + } + + public WordBuilder AddParagraph(string text) + { + var paragraph = _body.AppendChild(new Paragraph()); + var run = paragraph.AppendChild(new Run()); + run.AppendChild(new Text(text)); + return this; + } + + public WordBuilder AddTable(int[] widths, List data) + { + if (widths == null || widths.Length == 0) + { + throw new ArgumentNullException(nameof(widths)); + } + if (data == null || data.Count == 0) + { + throw new ArgumentNullException(nameof(data)); + } + if (data.Any(x => x.Length != widths.Length)) + { + throw new InvalidOperationException("widths.Length != data.Length"); + } + var table = new Table(); + table.AppendChild(new TableProperties( + new TableBorders( + new TopBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder() + { + Val = new + EnumValue(BorderValues.Single), + Size = 12 + } + ) + )); + + var tr = new TableRow(); + for (var j = 0; j < widths.Length; ++j) + { + tr.Append(new TableCell( + new TableCellProperties(new TableCellWidth() + { + Width = + widths[j].ToString() + }), + new Paragraph(new Run(new RunProperties(new Bold()), new + Text(data.First()[j]))))); + } + table.Append(tr); + + table.Append(data.Skip(1).Select(x => + new TableRow(x.Select(y => new TableCell(new Paragraph(new Run(new Text(y)))))))); + _body.Append(table); + return this; + } + + public void Build() + { + using var wordDocument = WordprocessingDocument.Create(_filePath, +WordprocessingDocumentType.Document); + var mainPart = wordDocument.AddMainDocumentPart(); + mainPart.Document = _document; + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/IConnectionString.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/IConnectionString.cs index 781a4f9..428e335 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/IConnectionString.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/IConnectionString.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectGasStation.Repositories; +namespace SessionResults_Kudyaeva.Repositories; public interface IConnectionString { diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/IRetakeRepository.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/IRetakeRepository.cs new file mode 100644 index 0000000..cf40eab --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/IRetakeRepository.cs @@ -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 IRetakeRepository +{ + void CreateRetake(Retake retake); + IEnumerable GetAllRetakes(); +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/ConnectionString.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/ConnectionString.cs index 21513a5..1597e9a 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/ConnectionString.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/ConnectionString.cs @@ -1,4 +1,4 @@ -namespace ProjectGasStation.Repositories.Implementations; +namespace SessionResults_Kudyaeva.Repositories.Implementations; public class ConnectionString : IConnectionString { diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/DisciplineRepository.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/DisciplineRepository.cs index 35e3f6b..96e6343 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/DisciplineRepository.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/DisciplineRepository.cs @@ -2,12 +2,10 @@ using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Npgsql; -using ProjectGasStation.Repositories; using SessionResults_Kudyaeva.Entities; namespace SessionResults_Kudyaeva.Repositories.Implementations; - public class DisciplineRepository : IDisciplineRepository { private readonly IConnectionString _connectionString; diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/GroupRepository.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/GroupRepository.cs index 9bf0bfb..00392aa 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/GroupRepository.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/GroupRepository.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Npgsql; -using ProjectGasStation.Repositories; using SessionResults_Kudyaeva.Entities; namespace SessionResults_Kudyaeva.Repositories.Implementations; diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/RetakeRepository.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/RetakeRepository.cs new file mode 100644 index 0000000..9782f20 --- /dev/null +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/RetakeRepository.cs @@ -0,0 +1,58 @@ +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using SessionResults_Kudyaeva.Entities; + +namespace SessionResults_Kudyaeva.Repositories.Implementations; + +public class RetakeRepository : IRetakeRepository +{ + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public RetakeRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + + public void CreateRetake(Retake retake) + { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(retake)); + + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" + INSERT INTO Retake (StudentId, TeacherId, DisciplineId, Mark, Date) + VALUES (@StudentId, @TeacherId, @DisciplineId, @Mark, @Date)"; + connection.Execute(queryInsert, retake); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } + + public IEnumerable GetAllRetakes() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Retake"; + var retakes = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(retakes)); + return retakes; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } +} diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/StatementRepository.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/StatementRepository.cs index af83715..0e73d72 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/StatementRepository.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/StatementRepository.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Npgsql; -using ProjectGasStation.Repositories; using SessionResults_Kudyaeva.Entities; namespace SessionResults_Kudyaeva.Repositories.Implementations; @@ -61,11 +60,12 @@ public class StatementRepository : IStatementRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM Statement"; - var statements = connection.Query(querySelect); + var querySelect = @"SELECT s.*, ss.StudentId, ss.Mark FROM Statement s + INNER JOIN StatementStudent ss on ss.StatementId = s.Id"; + var statements = connection.Query(querySelect); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(statements)); - return statements; + return statements.GroupBy(x => x.Id, y => y, (key, value) => Statement.CreateOperation(value.First(), value.Select(z => StatementStudent.CreateOperation(0, z.StudentId, z.Mark)))).ToList(); } catch (Exception ex) { diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/StudentRepository.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/StudentRepository.cs index 640460a..0149b35 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/StudentRepository.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/StudentRepository.cs @@ -1,6 +1,5 @@ using SessionResults_Kudyaeva.Entities; using Microsoft.Extensions.Logging; -using ProjectGasStation.Repositories; using Newtonsoft.Json; using Npgsql; using Dapper; diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/TeacherRepository.cs b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/TeacherRepository.cs index 0ecaf7a..8c8ff13 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/TeacherRepository.cs +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/Repositories/Implementations/TeacherRepository.cs @@ -1,6 +1,5 @@ using SessionResults_Kudyaeva.Entities; using Microsoft.Extensions.Logging; -using ProjectGasStation.Repositories; using Newtonsoft.Json; using Npgsql; using Dapper; diff --git a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/SessionResults_Kudyaeva.csproj b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/SessionResults_Kudyaeva.csproj index 09359df..725a97f 100644 --- a/SessionResults_Kudyaeva/SessionResults_Kudyaeva/SessionResults_Kudyaeva.csproj +++ b/SessionResults_Kudyaeva/SessionResults_Kudyaeva/SessionResults_Kudyaeva.csproj @@ -10,11 +10,13 @@ + + @@ -24,6 +26,12 @@ + + Form + + + Form + True True