From ec4ffdfdf059281712a3268034dbc571decac553 Mon Sep 17 00:00:00 2001 From: Kirill <39030726+Kirill3455@users.noreply.github.com> Date: Mon, 23 Dec 2024 00:55:51 +0400 Subject: [PATCH] 3 --- Project/Project/Entities/Statement.cs | 16 +- .../Project/Entities/TempStatementStudent.cs | 18 + Project/Project/FormMain.Designer.cs | 34 +- Project/Project/FormMain.cs | 36 ++ .../Project/Forms/FormDocReport.Designer.cs | 99 ++++++ Project/Project/Forms/FormDocReport.cs | 62 ++++ Project/Project/Forms/FormDocReport.resx | 120 +++++++ .../Forms/FormStatementReport.Designer.cs | 107 ++++++ Project/Project/Forms/FormStatementReport.cs | 60 ++++ .../Project/Forms/FormStatementReport.resx | 120 +++++++ .../Forms/FormStudentInfoReport.Designer.cs | 162 +++++++++ .../Project/Forms/FormStudentInfoReport.cs | 72 ++++ .../Project/Forms/FormStudentInfoReport.resx | 120 +++++++ .../Project/Forms/StatementForm.Designer.cs | 61 ++-- Project/Project/Forms/StatementForm.cs | 28 +- Project/Project/Forms/StatementForm.resx | 7 +- .../Forms/StatementListForm.Designer.cs | 2 +- Project/Project/Forms/StudentForm.cs | 2 +- Project/Project/Project.csproj | 2 + Project/Project/Reports/ChartReport.cs | 61 ++++ Project/Project/Reports/DocReport.cs | 77 +++++ Project/Project/Reports/ExcelBuilder.cs | 311 ++++++++++++++++++ Project/Project/Reports/PdfBuilder.cs | 76 +++++ Project/Project/Reports/TableReport.cs | 98 ++++++ Project/Project/Reports/WordBuilder.cs | 130 ++++++++ .../Implementations/StatementRepository.cs | 9 +- 26 files changed, 1819 insertions(+), 71 deletions(-) create mode 100644 Project/Project/Entities/TempStatementStudent.cs create mode 100644 Project/Project/Forms/FormDocReport.Designer.cs create mode 100644 Project/Project/Forms/FormDocReport.cs create mode 100644 Project/Project/Forms/FormDocReport.resx create mode 100644 Project/Project/Forms/FormStatementReport.Designer.cs create mode 100644 Project/Project/Forms/FormStatementReport.cs create mode 100644 Project/Project/Forms/FormStatementReport.resx create mode 100644 Project/Project/Forms/FormStudentInfoReport.Designer.cs create mode 100644 Project/Project/Forms/FormStudentInfoReport.cs create mode 100644 Project/Project/Forms/FormStudentInfoReport.resx create mode 100644 Project/Project/Reports/ChartReport.cs create mode 100644 Project/Project/Reports/DocReport.cs create mode 100644 Project/Project/Reports/ExcelBuilder.cs create mode 100644 Project/Project/Reports/PdfBuilder.cs create mode 100644 Project/Project/Reports/TableReport.cs create mode 100644 Project/Project/Reports/WordBuilder.cs diff --git a/Project/Project/Entities/Statement.cs b/Project/Project/Entities/Statement.cs index ce9a73a..864a78d 100644 --- a/Project/Project/Entities/Statement.cs +++ b/Project/Project/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 subjectId, IEnumerable statementStudents) + public static Statement CreateOperation(int id, int teacherId, int subjectId, DateTime date, IEnumerable statementStudents) { return new Statement { Id = id, TeacherId = teacherId, SubjectId = subjectId, - Date = DateTime.Now, + Date = date, + StatementStudents = statementStudents + }; + } + + public static Statement CreateOperation(TempStatementStudent tempStatementStudent, IEnumerable statementStudents) + { + return new Statement + { + Id = tempStatementStudent.Id, + TeacherId = tempStatementStudent.TeacherId, + SubjectId = tempStatementStudent.SubjectId, + Date = tempStatementStudent.Date, StatementStudents = statementStudents }; } diff --git a/Project/Project/Entities/TempStatementStudent.cs b/Project/Project/Entities/TempStatementStudent.cs new file mode 100644 index 0000000..63e185d --- /dev/null +++ b/Project/Project/Entities/TempStatementStudent.cs @@ -0,0 +1,18 @@ +using Project.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Project.Entities; + +public class TempStatementStudent +{ + public int Id { get; private set; } + public int TeacherId { get; private set; } + public int SubjectId { get; private set; } + public DateTime Date { get; private set; } + public int StudentId { get; private set; } + public Mark Mark { get; private set; } +} diff --git a/Project/Project/FormMain.Designer.cs b/Project/Project/FormMain.Designer.cs index a66fb45..a055ba6 100644 --- a/Project/Project/FormMain.Designer.cs +++ b/Project/Project/FormMain.Designer.cs @@ -38,6 +38,9 @@ toolStripMenuItemStatements = new ToolStripMenuItem(); toolStripMenuItemDecrees = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); + toolStripMenuItemDocReport = new ToolStripMenuItem(); + toolStripMenuItemStudentInfoReport = new ToolStripMenuItem(); + toolStripMenuItemMarksReport = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); SuspendLayout(); // @@ -60,21 +63,21 @@ // toolStripMenuItemStudents // toolStripMenuItemStudents.Name = "toolStripMenuItemStudents"; - toolStripMenuItemStudents.Size = new Size(180, 22); + toolStripMenuItemStudents.Size = new Size(159, 22); toolStripMenuItemStudents.Text = "Студенты"; toolStripMenuItemStudents.Click += toolStripMenuItemStudents_Click; // // toolStripMenuItemTeachers // toolStripMenuItemTeachers.Name = "toolStripMenuItemTeachers"; - toolStripMenuItemTeachers.Size = new Size(180, 22); + toolStripMenuItemTeachers.Size = new Size(159, 22); toolStripMenuItemTeachers.Text = "Преподаватели"; toolStripMenuItemTeachers.Click += toolStripMenuItemTeachers_Click; // // toolStripMenuItemSubjects // toolStripMenuItemSubjects.Name = "toolStripMenuItemSubjects"; - toolStripMenuItemSubjects.Size = new Size(180, 22); + toolStripMenuItemSubjects.Size = new Size(159, 22); toolStripMenuItemSubjects.Text = "Предметы"; toolStripMenuItemSubjects.Click += toolStripMenuItemSubjects_Click; // @@ -101,10 +104,32 @@ // // отчетыToolStripMenuItem // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemDocReport, toolStripMenuItemStudentInfoReport, toolStripMenuItemMarksReport }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; отчетыToolStripMenuItem.Size = new Size(60, 20); отчетыToolStripMenuItem.Text = "Отчеты"; // + // toolStripMenuItemDocReport + // + toolStripMenuItemDocReport.Name = "toolStripMenuItemDocReport"; + toolStripMenuItemDocReport.Size = new Size(207, 22); + toolStripMenuItemDocReport.Text = "Отчет по справочникам"; + toolStripMenuItemDocReport.Click += toolStripMenuItemDocReport_Click; + // + // toolStripMenuItemStudentInfoReport + // + toolStripMenuItemStudentInfoReport.Name = "toolStripMenuItemStudentInfoReport"; + toolStripMenuItemStudentInfoReport.Size = new Size(207, 22); + toolStripMenuItemStudentInfoReport.Text = "Отчет по студенту"; + toolStripMenuItemStudentInfoReport.Click += toolStripMenuItemStudentInfoReport_Click; + // + // toolStripMenuItemMarksReport + // + toolStripMenuItemMarksReport.Name = "toolStripMenuItemMarksReport"; + toolStripMenuItemMarksReport.Size = new Size(207, 22); + toolStripMenuItemMarksReport.Text = "Отчет по оценкам"; + toolStripMenuItemMarksReport.Click += toolStripMenuItemMarksReport_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); @@ -133,5 +158,8 @@ private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem toolStripMenuItemStatements; private ToolStripMenuItem toolStripMenuItemDecrees; + private ToolStripMenuItem toolStripMenuItemDocReport; + private ToolStripMenuItem toolStripMenuItemStudentInfoReport; + private ToolStripMenuItem toolStripMenuItemMarksReport; } } diff --git a/Project/Project/FormMain.cs b/Project/Project/FormMain.cs index 1e79714..500737b 100644 --- a/Project/Project/FormMain.cs +++ b/Project/Project/FormMain.cs @@ -71,5 +71,41 @@ namespace Project 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 toolStripMenuItemMarksReport_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void toolStripMenuItemStudentInfoReport_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/Project/Project/Forms/FormDocReport.Designer.cs b/Project/Project/Forms/FormDocReport.Designer.cs new file mode 100644 index 0000000..3a2f9f3 --- /dev/null +++ b/Project/Project/Forms/FormDocReport.Designer.cs @@ -0,0 +1,99 @@ +namespace Project.Forms +{ + partial class FormDocReport + { + /// + /// 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() + { + checkBoxStudents = new CheckBox(); + checkBoxSubjects = new CheckBox(); + checkBoxTeachers = new CheckBox(); + buttonBuild = new Button(); + SuspendLayout(); + // + // checkBoxStudents + // + checkBoxStudents.AutoSize = true; + checkBoxStudents.Location = new Point(12, 12); + checkBoxStudents.Name = "checkBoxStudents"; + checkBoxStudents.Size = new Size(78, 19); + checkBoxStudents.TabIndex = 0; + checkBoxStudents.Text = "Студенты"; + checkBoxStudents.UseVisualStyleBackColor = true; + // + // checkBoxSubjects + // + checkBoxSubjects.AutoSize = true; + checkBoxSubjects.Location = new Point(12, 46); + checkBoxSubjects.Name = "checkBoxSubjects"; + checkBoxSubjects.Size = new Size(83, 19); + checkBoxSubjects.TabIndex = 1; + checkBoxSubjects.Text = "Предметы"; + checkBoxSubjects.UseVisualStyleBackColor = true; + // + // checkBoxTeachers + // + checkBoxTeachers.AutoSize = true; + checkBoxTeachers.Location = new Point(12, 80); + checkBoxTeachers.Name = "checkBoxTeachers"; + checkBoxTeachers.Size = new Size(111, 19); + checkBoxTeachers.TabIndex = 2; + checkBoxTeachers.Text = "Преподаватели"; + checkBoxTeachers.UseVisualStyleBackColor = true; + // + // buttonBuild + // + buttonBuild.Location = new Point(12, 119); + buttonBuild.Name = "buttonBuild"; + buttonBuild.Size = new Size(146, 23); + buttonBuild.TabIndex = 3; + buttonBuild.Text = "Сформировать"; + buttonBuild.UseVisualStyleBackColor = true; + buttonBuild.Click += buttonBuild_Click; + // + // FormDocReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(170, 153); + Controls.Add(buttonBuild); + Controls.Add(checkBoxTeachers); + Controls.Add(checkBoxSubjects); + Controls.Add(checkBoxStudents); + Name = "FormDocReport"; + Text = "Отчет по справочникам"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox checkBoxStudents; + private CheckBox checkBoxSubjects; + private CheckBox checkBoxTeachers; + private Button buttonBuild; + } +} \ No newline at end of file diff --git a/Project/Project/Forms/FormDocReport.cs b/Project/Project/Forms/FormDocReport.cs new file mode 100644 index 0000000..c60d536 --- /dev/null +++ b/Project/Project/Forms/FormDocReport.cs @@ -0,0 +1,62 @@ +using Project.Reports; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace Project.Forms +{ + public partial class FormDocReport : Form + { + private readonly IUnityContainer _container; + + public FormDocReport(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void buttonBuild_Click(object sender, EventArgs e) + { + try + { + if (!checkBoxStudents.Checked && !checkBoxSubjects.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, checkBoxStudents.Checked, checkBoxSubjects.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/Project/Project/Forms/FormDocReport.resx b/Project/Project/Forms/FormDocReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Project/Project/Forms/FormDocReport.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/Project/Project/Forms/FormStatementReport.Designer.cs b/Project/Project/Forms/FormStatementReport.Designer.cs new file mode 100644 index 0000000..cdc578a --- /dev/null +++ b/Project/Project/Forms/FormStatementReport.Designer.cs @@ -0,0 +1,107 @@ +namespace Project.Forms +{ + partial class FormStatementReport + { + /// + /// 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(); + label3 = new Label(); + labelFilePath = new Label(); + buttonFile = new Button(); + buttonBuild = new Button(); + SuspendLayout(); + // + // dateTimePicker + // + dateTimePicker.Location = new Point(57, 41); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(167, 23); + dateTimePicker.TabIndex = 13; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(13, 46); + label3.Name = "label3"; + label3.Size = new Size(35, 15); + label3.TabIndex = 12; + label3.Text = "Дата:"; + // + // labelFilePath + // + labelFilePath.AutoSize = true; + labelFilePath.Location = new Point(175, 16); + labelFilePath.Name = "labelFilePath"; + labelFilePath.Size = new Size(36, 15); + labelFilePath.TabIndex = 11; + labelFilePath.Text = "Файл"; + // + // buttonFile + // + buttonFile.Location = new Point(13, 12); + buttonFile.Name = "buttonFile"; + buttonFile.Size = new Size(156, 23); + buttonFile.TabIndex = 10; + buttonFile.Text = "Выбрать"; + buttonFile.UseVisualStyleBackColor = true; + buttonFile.Click += buttonFile_Click; + // + // buttonBuild + // + buttonBuild.Location = new Point(12, 79); + buttonBuild.Name = "buttonBuild"; + buttonBuild.Size = new Size(212, 23); + buttonBuild.TabIndex = 9; + buttonBuild.Text = "Сформировать"; + buttonBuild.UseVisualStyleBackColor = true; + buttonBuild.Click += buttonBuild_Click; + // + // FormStatementReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(245, 124); + Controls.Add(dateTimePicker); + Controls.Add(label3); + Controls.Add(labelFilePath); + Controls.Add(buttonFile); + Controls.Add(buttonBuild); + Name = "FormStatementReport"; + Text = "Отчет по оценкам"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker dateTimePicker; + private Label label3; + private Label labelFilePath; + private Button buttonFile; + private Button buttonBuild; + } +} \ No newline at end of file diff --git a/Project/Project/Forms/FormStatementReport.cs b/Project/Project/Forms/FormStatementReport.cs new file mode 100644 index 0000000..5f62808 --- /dev/null +++ b/Project/Project/Forms/FormStatementReport.cs @@ -0,0 +1,60 @@ +using Project.Reports; +using Unity; + +namespace Project.Forms +{ + public partial class FormStatementReport : Form + { + private string _fileName = string.Empty; + private readonly IUnityContainer _container; + + public FormStatementReport(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void buttonFile_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Pdf Files | *.pdf" + }; + if (sfd.ShowDialog() == DialogResult.OK) + { + _fileName = sfd.FileName; + labelFilePath.Text = Path.GetFileName(_fileName); + } + } + + 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); + } + } + } +} diff --git a/Project/Project/Forms/FormStatementReport.resx b/Project/Project/Forms/FormStatementReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Project/Project/Forms/FormStatementReport.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/Project/Project/Forms/FormStudentInfoReport.Designer.cs b/Project/Project/Forms/FormStudentInfoReport.Designer.cs new file mode 100644 index 0000000..659c9c9 --- /dev/null +++ b/Project/Project/Forms/FormStudentInfoReport.Designer.cs @@ -0,0 +1,162 @@ +namespace Project.Forms +{ + partial class FormStudentInfoReport + { + /// + /// 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() + { + buttonBuild = new Button(); + buttonFile = new Button(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + dateTimePickerEnd = new DateTimePicker(); + dateTimePickerStart = new DateTimePicker(); + comboBoxStudent = new ComboBox(); + textBoxFilePath = new TextBox(); + SuspendLayout(); + // + // buttonBuild + // + buttonBuild.Location = new Point(12, 179); + buttonBuild.Name = "buttonBuild"; + buttonBuild.Size = new Size(262, 23); + buttonBuild.TabIndex = 1; + buttonBuild.Text = "Сформировать"; + buttonBuild.UseVisualStyleBackColor = true; + buttonBuild.Click += buttonBuild_Click; + // + // buttonFile + // + buttonFile.Location = new Point(243, 12); + buttonFile.Name = "buttonFile"; + buttonFile.Size = new Size(31, 23); + buttonFile.TabIndex = 2; + buttonFile.Text = "..."; + buttonFile.UseVisualStyleBackColor = true; + buttonFile.Click += buttonFile_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(11, 16); + label1.Name = "label1"; + label1.Size = new Size(90, 15); + label1.TabIndex = 3; + label1.Text = "Путь до файла:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(11, 57); + label2.Name = "label2"; + label2.Size = new Size(53, 15); + label2.TabIndex = 4; + label2.Text = "Студент:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(11, 98); + label3.Name = "label3"; + label3.Size = new Size(77, 15); + label3.TabIndex = 5; + label3.Text = "Дата начала:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(11, 138); + label4.Name = "label4"; + label4.Size = new Size(71, 15); + label4.TabIndex = 6; + label4.Text = "Дата конца:"; + // + // dateTimePickerEnd + // + dateTimePickerEnd.Location = new Point(107, 132); + dateTimePickerEnd.Name = "dateTimePickerEnd"; + dateTimePickerEnd.Size = new Size(167, 23); + dateTimePickerEnd.TabIndex = 7; + // + // dateTimePickerStart + // + dateTimePickerStart.Location = new Point(107, 92); + dateTimePickerStart.Name = "dateTimePickerStart"; + dateTimePickerStart.Size = new Size(167, 23); + dateTimePickerStart.TabIndex = 8; + // + // comboBoxStudent + // + comboBoxStudent.FormattingEnabled = true; + comboBoxStudent.Location = new Point(107, 54); + comboBoxStudent.Name = "comboBoxStudent"; + comboBoxStudent.Size = new Size(167, 23); + comboBoxStudent.TabIndex = 9; + // + // textBoxFilePath + // + textBoxFilePath.Location = new Point(107, 12); + textBoxFilePath.Name = "textBoxFilePath"; + textBoxFilePath.Size = new Size(130, 23); + textBoxFilePath.TabIndex = 10; + // + // FormStudentInfoReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(294, 213); + Controls.Add(textBoxFilePath); + Controls.Add(comboBoxStudent); + Controls.Add(dateTimePickerStart); + Controls.Add(dateTimePickerEnd); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonFile); + Controls.Add(buttonBuild); + Name = "FormStudentInfoReport"; + Text = "FormStudentInfoReport"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonBuild; + private Button buttonFile; + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private DateTimePicker dateTimePickerEnd; + private DateTimePicker dateTimePickerStart; + private ComboBox comboBoxStudent; + private TextBox textBoxFilePath; + } +} \ No newline at end of file diff --git a/Project/Project/Forms/FormStudentInfoReport.cs b/Project/Project/Forms/FormStudentInfoReport.cs new file mode 100644 index 0000000..4495c03 --- /dev/null +++ b/Project/Project/Forms/FormStudentInfoReport.cs @@ -0,0 +1,72 @@ +using Project.Reports; +using Project.Repositories; +using Unity; + +namespace Project.Forms +{ + public partial class FormStudentInfoReport : Form + { + private readonly IUnityContainer _container; + + public FormStudentInfoReport(IUnityContainer container, IStudentRepository studentRepository) + { + InitializeComponent(); + + _container = container ?? throw new ArgumentNullException(nameof(container)); + + comboBoxStudent.DataSource = studentRepository.GetAllStudents(); + comboBoxStudent.DisplayMember = "LastName"; + comboBoxStudent.ValueMember = "Id"; + } + + 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); + } + } + + 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; + } + } +} diff --git a/Project/Project/Forms/FormStudentInfoReport.resx b/Project/Project/Forms/FormStudentInfoReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Project/Project/Forms/FormStudentInfoReport.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/Project/Project/Forms/StatementForm.Designer.cs b/Project/Project/Forms/StatementForm.Designer.cs index 47bb625..4e26779 100644 --- a/Project/Project/Forms/StatementForm.Designer.cs +++ b/Project/Project/Forms/StatementForm.Designer.cs @@ -1,6 +1,4 @@ -using Project.Entities.Enums; - -namespace Project.Forms +namespace Project.Forms { partial class StatementForm { @@ -36,12 +34,11 @@ namespace Project.Forms ButtonCancel = new Button(); comboBoxSubject = new ComboBox(); comboBoxTeacher = new ComboBox(); - groupBox1 = new GroupBox(); dataGridView = new DataGridView(); + groupBox1 = new GroupBox(); ColumnStudent = new DataGridViewComboBoxColumn(); - ColumnMark = new DataGridViewComboBoxColumn(); - groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + groupBox1.SuspendLayout(); SuspendLayout(); // // label1 @@ -100,6 +97,22 @@ namespace Project.Forms 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 }); + 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); @@ -110,42 +123,11 @@ namespace Project.Forms groupBox1.TabStop = false; groupBox1.Text = "Студенты"; // - // 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; - // // ColumnStudent // ColumnStudent.HeaderText = "Студенты"; ColumnStudent.Name = "ColumnStudent"; // - // ColumnMark - // - ColumnMark.DataPropertyName = "Enum.GetNames(typeof(Mark));"; - ColumnMark.DataSource = new Mark[] - { - Mark.One, - Mark.Two, - Mark.Three, - Mark.Four, - Mark.Five - }; - ColumnMark.HeaderText = "Оценки"; - ColumnMark.Name = "ColumnMark"; - ColumnMark.Resizable = DataGridViewTriState.True; - // // StatementForm // AutoScaleDimensions = new SizeF(7F, 15F); @@ -160,8 +142,8 @@ namespace Project.Forms Controls.Add(label1); Name = "StatementForm"; Text = "Результат сессии"; - groupBox1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + groupBox1.ResumeLayout(false); ResumeLayout(false); PerformLayout(); } @@ -174,9 +156,8 @@ namespace Project.Forms private Button ButtonCancel; private ComboBox comboBoxSubject; private ComboBox comboBoxTeacher; - private GroupBox groupBox1; private DataGridView dataGridView; + private GroupBox groupBox1; private DataGridViewComboBoxColumn ColumnStudent; - private DataGridViewComboBoxColumn ColumnMark; } } \ No newline at end of file diff --git a/Project/Project/Forms/StatementForm.cs b/Project/Project/Forms/StatementForm.cs index 2d3ca4f..e2f0dd6 100644 --- a/Project/Project/Forms/StatementForm.cs +++ b/Project/Project/Forms/StatementForm.cs @@ -30,7 +30,15 @@ public partial class StatementForm : Form ColumnStudent.DisplayMember = "DisplayName"; ColumnStudent.ValueMember = "Id"; - ColumnMark.DataSource = Enum.GetNames(typeof(Mark)); + var columnMark = new DataGridViewComboBoxColumn + { + Name = "ColumnMark", + HeaderText = "Оценка", + DataSource = Enum.GetValues(typeof(Mark)), + ValueType = typeof(Mark), + DataPropertyName = "Mark" + }; + dataGridView.Columns.Add(columnMark); } private void ButtonSave_Click(object sender, EventArgs e) @@ -45,6 +53,7 @@ public partial class StatementForm : Form _statementRepository.CreateStatement(Statement.CreateOperation(0, (int)comboBoxTeacher.SelectedValue!, (int)comboBoxSubject.SelectedValue!, + DateTime.Now, CreateListStatementStudentFromDataGrid())); Close(); @@ -67,20 +76,9 @@ public partial class StatementForm : Form { continue; } - if (Enum.TryParse(row.Cells["ColumnMark"].Value.ToString(), out var mark)) - { - list.Add(StatementStudent.CreateOperation( - 0, - Convert.ToInt32(row.Cells["ColumnStudent"].Value), - mark)); - } - else - { - MessageBox.Show($"Недопустимое значение оценки: {row.Cells["ColumnMark"].Value}", - "Ошибка", - MessageBoxButtons.OK, - MessageBoxIcon.Warning); - } + list.Add(StatementStudent.CreateOperation(0, + Convert.ToInt32(row.Cells["ColumnStudent"].Value), + (Mark)row.Cells["ColumnMark"].Value)); } return list; } diff --git a/Project/Project/Forms/StatementForm.resx b/Project/Project/Forms/StatementForm.resx index 81039cf..afacd50 100644 --- a/Project/Project/Forms/StatementForm.resx +++ b/Project/Project/Forms/StatementForm.resx @@ -1,7 +1,7 @@