Первый отчет
This commit is contained in:
parent
0fc8f3fd47
commit
7e70458d08
@ -1,10 +1,4 @@
|
||||
using ProjectShedule.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace ProjectShedule.Entities;
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectShedule.Entities;
|
||||
namespace ProjectShedule.Entities;
|
||||
|
||||
public class Curriculum
|
||||
{
|
||||
|
@ -1,9 +1,4 @@
|
||||
using ProjectShedule.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectShedule.Entities;
|
||||
|
||||
@ -24,5 +19,4 @@ public class CurriculumSubject
|
||||
SubjectSubject = subjectSubjects
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,4 @@
|
||||
using ProjectShedule.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectShedule.Entities;
|
||||
|
||||
|
@ -1,9 +1,4 @@
|
||||
using ProjectShedule.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectShedule.Entities;
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectShedule.Entities;
|
||||
namespace ProjectShedule.Entities;
|
||||
|
||||
public class Subject
|
||||
{
|
||||
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace ProjectShedule.Entities;
|
||||
|
||||
public class SubjectSubject
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectShedule.Entities;
|
||||
namespace ProjectShedule.Entities;
|
||||
|
||||
public class Teacher
|
||||
{
|
||||
|
@ -39,6 +39,7 @@
|
||||
createSheduleToolStripMenuItem = new ToolStripMenuItem();
|
||||
createCurriculumToolStripMenuItem = new ToolStripMenuItem();
|
||||
отчетыToolStripMenuItem = new ToolStripMenuItem();
|
||||
directoryReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
menuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -62,35 +63,35 @@
|
||||
// classroomToolStripMenuItem
|
||||
//
|
||||
classroomToolStripMenuItem.Name = "classroomToolStripMenuItem";
|
||||
classroomToolStripMenuItem.Size = new Size(224, 26);
|
||||
classroomToolStripMenuItem.Size = new Size(216, 26);
|
||||
classroomToolStripMenuItem.Text = "Аудитории";
|
||||
classroomToolStripMenuItem.Click += classroomToolStripMenuItem_Click;
|
||||
//
|
||||
// teacherToolStripMenuItem
|
||||
//
|
||||
teacherToolStripMenuItem.Name = "teacherToolStripMenuItem";
|
||||
teacherToolStripMenuItem.Size = new Size(224, 26);
|
||||
teacherToolStripMenuItem.Size = new Size(216, 26);
|
||||
teacherToolStripMenuItem.Text = "Преподаватели";
|
||||
teacherToolStripMenuItem.Click += teacherToolStripMenuItem_Click;
|
||||
//
|
||||
// subjectsToolStripMenuItem
|
||||
//
|
||||
subjectsToolStripMenuItem.Name = "subjectsToolStripMenuItem";
|
||||
subjectsToolStripMenuItem.Size = new Size(224, 26);
|
||||
subjectsToolStripMenuItem.Size = new Size(216, 26);
|
||||
subjectsToolStripMenuItem.Text = "Дисциплины";
|
||||
subjectsToolStripMenuItem.Click += subjectsToolStripMenuItem_Click;
|
||||
//
|
||||
// curriculumsToolStripMenuItem
|
||||
//
|
||||
curriculumsToolStripMenuItem.Name = "curriculumsToolStripMenuItem";
|
||||
curriculumsToolStripMenuItem.Size = new Size(224, 26);
|
||||
curriculumsToolStripMenuItem.Size = new Size(216, 26);
|
||||
curriculumsToolStripMenuItem.Text = "Направлении";
|
||||
curriculumsToolStripMenuItem.Click += curriculumsToolStripMenuItem_Click;
|
||||
//
|
||||
// studentGroupsToolStripMenuItem
|
||||
//
|
||||
studentGroupsToolStripMenuItem.Name = "studentGroupsToolStripMenuItem";
|
||||
studentGroupsToolStripMenuItem.Size = new Size(224, 26);
|
||||
studentGroupsToolStripMenuItem.Size = new Size(216, 26);
|
||||
studentGroupsToolStripMenuItem.Text = "Группы студентов";
|
||||
studentGroupsToolStripMenuItem.Click += studentGroupsToolStripMenuItem_Click;
|
||||
//
|
||||
@ -117,10 +118,19 @@
|
||||
//
|
||||
// отчетыToolStripMenuItem
|
||||
//
|
||||
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { directoryReportToolStripMenuItem });
|
||||
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
|
||||
отчетыToolStripMenuItem.Size = new Size(73, 24);
|
||||
отчетыToolStripMenuItem.Text = "Отчеты";
|
||||
//
|
||||
// directoryReportToolStripMenuItem
|
||||
//
|
||||
directoryReportToolStripMenuItem.Name = "directoryReportToolStripMenuItem";
|
||||
directoryReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W;
|
||||
directoryReportToolStripMenuItem.Size = new Size(354, 26);
|
||||
directoryReportToolStripMenuItem.Text = "Документ со справочниками ";
|
||||
directoryReportToolStripMenuItem.Click += directoryReportToolStripMenuItem_Click;
|
||||
//
|
||||
// FormSchedulingBureau
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
@ -152,5 +162,6 @@
|
||||
private ToolStripMenuItem createSheduleToolStripMenuItem;
|
||||
private ToolStripMenuItem отчетыToolStripMenuItem;
|
||||
private ToolStripMenuItem createCurriculumToolStripMenuItem;
|
||||
private ToolStripMenuItem directoryReportToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using ProjectGasStation.Forms;
|
||||
using ProjectShedule.Forms;
|
||||
using System.ComponentModel;
|
||||
using Unity;
|
||||
@ -104,5 +105,18 @@ namespace ProjectShedule
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void directoryReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormDirectoryReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
132
ProjectShedule/ProjectShedule/Forms/FormDirectoryReport.Designer.cs
generated
Normal file
132
ProjectShedule/ProjectShedule/Forms/FormDirectoryReport.Designer.cs
generated
Normal file
@ -0,0 +1,132 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormDirectoryReport
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
checkBoxClassrooms = new CheckBox();
|
||||
checkBoxTeachers = new CheckBox();
|
||||
checkBoxSubjects = new CheckBox();
|
||||
checkBoxCurriculums = new CheckBox();
|
||||
buttonBuild = new Button();
|
||||
checkBoxGroups = new CheckBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// checkBoxClassrooms
|
||||
//
|
||||
checkBoxClassrooms.AutoSize = true;
|
||||
checkBoxClassrooms.Location = new Point(14, 16);
|
||||
checkBoxClassrooms.Margin = new Padding(3, 4, 3, 4);
|
||||
checkBoxClassrooms.Name = "checkBoxClassrooms";
|
||||
checkBoxClassrooms.Size = new Size(107, 24);
|
||||
checkBoxClassrooms.TabIndex = 0;
|
||||
checkBoxClassrooms.Text = "Аудитории";
|
||||
checkBoxClassrooms.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxTeachers
|
||||
//
|
||||
checkBoxTeachers.AutoSize = true;
|
||||
checkBoxTeachers.Location = new Point(14, 61);
|
||||
checkBoxTeachers.Margin = new Padding(3, 4, 3, 4);
|
||||
checkBoxTeachers.Name = "checkBoxTeachers";
|
||||
checkBoxTeachers.Size = new Size(140, 24);
|
||||
checkBoxTeachers.TabIndex = 1;
|
||||
checkBoxTeachers.Text = "Преподаватели";
|
||||
checkBoxTeachers.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxSubjects
|
||||
//
|
||||
checkBoxSubjects.AutoSize = true;
|
||||
checkBoxSubjects.Location = new Point(14, 109);
|
||||
checkBoxSubjects.Margin = new Padding(3, 4, 3, 4);
|
||||
checkBoxSubjects.Name = "checkBoxSubjects";
|
||||
checkBoxSubjects.Size = new Size(121, 24);
|
||||
checkBoxSubjects.TabIndex = 2;
|
||||
checkBoxSubjects.Text = "Дисциплины";
|
||||
checkBoxSubjects.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxCurriculums
|
||||
//
|
||||
checkBoxCurriculums.AutoSize = true;
|
||||
checkBoxCurriculums.Location = new Point(14, 157);
|
||||
checkBoxCurriculums.Margin = new Padding(3, 4, 3, 4);
|
||||
checkBoxCurriculums.Name = "checkBoxCurriculums";
|
||||
checkBoxCurriculums.Size = new Size(127, 24);
|
||||
checkBoxCurriculums.TabIndex = 3;
|
||||
checkBoxCurriculums.Text = "Направлении";
|
||||
checkBoxCurriculums.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonBuild
|
||||
//
|
||||
buttonBuild.Location = new Point(12, 257);
|
||||
buttonBuild.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonBuild.Name = "buttonBuild";
|
||||
buttonBuild.Size = new Size(159, 31);
|
||||
buttonBuild.TabIndex = 4;
|
||||
buttonBuild.Text = "Сформировать";
|
||||
buttonBuild.UseVisualStyleBackColor = true;
|
||||
buttonBuild.Click += buttonBuild_Click;
|
||||
//
|
||||
// checkBoxGroups
|
||||
//
|
||||
checkBoxGroups.AutoSize = true;
|
||||
checkBoxGroups.Location = new Point(14, 206);
|
||||
checkBoxGroups.Margin = new Padding(3, 4, 3, 4);
|
||||
checkBoxGroups.Name = "checkBoxGroups";
|
||||
checkBoxGroups.Size = new Size(83, 24);
|
||||
checkBoxGroups.TabIndex = 5;
|
||||
checkBoxGroups.Text = "Группы";
|
||||
checkBoxGroups.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormDirectoryReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(191, 317);
|
||||
Controls.Add(checkBoxGroups);
|
||||
Controls.Add(buttonBuild);
|
||||
Controls.Add(checkBoxCurriculums);
|
||||
Controls.Add(checkBoxSubjects);
|
||||
Controls.Add(checkBoxTeachers);
|
||||
Controls.Add(checkBoxClassrooms);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormDirectoryReport";
|
||||
Text = "FormDirectoryReport";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CheckBox checkBoxClassrooms;
|
||||
private CheckBox checkBoxTeachers;
|
||||
private CheckBox checkBoxSubjects;
|
||||
private CheckBox checkBoxCurriculums;
|
||||
private Button buttonBuild;
|
||||
private CheckBox checkBoxGroups;
|
||||
}
|
||||
}
|
52
ProjectShedule/ProjectShedule/Forms/FormDirectoryReport.cs
Normal file
52
ProjectShedule/ProjectShedule/Forms/FormDirectoryReport.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using ProjectShedule.Reports;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectGasStation.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 (!checkBoxClassrooms.Checked && !checkBoxTeachers.Checked && !checkBoxSubjects.Checked && !checkBoxCurriculums.Checked && !checkBoxGroups.Checked)
|
||||
{
|
||||
throw new Exception("Не выбран ни один справочник для выгрузки");
|
||||
}
|
||||
var sfd = new SaveFileDialog()
|
||||
{
|
||||
Filter = "Docx Files | *.docx"
|
||||
};
|
||||
if (sfd.ShowDialog() != DialogResult.OK)
|
||||
{
|
||||
throw new Exception("Не выбран файла для отчета");
|
||||
}
|
||||
if
|
||||
(_container.Resolve<DocReport>().CreateDoc(sfd.FileName, checkBoxClassrooms.Checked, checkBoxTeachers.Checked, checkBoxSubjects.Checked, checkBoxCurriculums.Checked, checkBoxGroups.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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
120
ProjectShedule/ProjectShedule/Forms/FormDirectoryReport.resx
Normal file
120
ProjectShedule/ProjectShedule/Forms/FormDirectoryReport.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -10,6 +10,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
|
125
ProjectShedule/ProjectShedule/Reports/DocReport.cs
Normal file
125
ProjectShedule/ProjectShedule/Reports/DocReport.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectShedule.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectShedule.Reports;
|
||||
internal class DocReport
|
||||
{
|
||||
private readonly IClassroomRepository _classroomRepository;
|
||||
private readonly ITeacherRepository _teacherRepository;
|
||||
private readonly ISubjectRepository _subjectRepository;
|
||||
private readonly ICurriculumRepository _curriculumRepository;
|
||||
private readonly IGroupRepository _groupRepository;
|
||||
private readonly ILogger<DocReport> _logger;
|
||||
public DocReport(IClassroomRepository classroomRepository,
|
||||
ITeacherRepository teacherRepository,
|
||||
ISubjectRepository subjectRepository,
|
||||
ICurriculumRepository curriculumRepository,
|
||||
IGroupRepository groupRepository,
|
||||
ILogger<DocReport> logger)
|
||||
{
|
||||
_classroomRepository = classroomRepository ??
|
||||
throw new ArgumentNullException(nameof(classroomRepository));
|
||||
_teacherRepository = teacherRepository ??
|
||||
throw new ArgumentNullException(nameof(teacherRepository));
|
||||
_subjectRepository = subjectRepository ??
|
||||
throw new ArgumentNullException(nameof(subjectRepository));
|
||||
_curriculumRepository = curriculumRepository ??
|
||||
throw new ArgumentNullException(nameof(curriculumRepository));
|
||||
_groupRepository = groupRepository ??
|
||||
throw new ArgumentNullException(nameof(groupRepository));
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
}
|
||||
public bool CreateDoc(string filePath, bool includeClassrooms,
|
||||
bool includeTeachers, bool includeSubjects,
|
||||
bool includeCurriculums, bool includeGroups)
|
||||
{
|
||||
try
|
||||
{
|
||||
var builder = new WordBuilder(filePath)
|
||||
.AddHeader("Документ со справочниками");
|
||||
if (includeClassrooms)
|
||||
{
|
||||
builder.AddParagraph("Аудитории")
|
||||
.AddTable([2400, 1200, 2400],
|
||||
GetClassrooms());
|
||||
}
|
||||
if (includeTeachers)
|
||||
{
|
||||
builder.AddParagraph("Преподаватели")
|
||||
.AddTable([2400, 2400],
|
||||
GetTeachers());
|
||||
}
|
||||
if (includeSubjects)
|
||||
{
|
||||
builder.AddParagraph("Дисциплины")
|
||||
.AddTable([2400],
|
||||
GetSubjects());
|
||||
}
|
||||
if (includeCurriculums)
|
||||
{
|
||||
builder.AddParagraph("Направлении")
|
||||
.AddTable([2400],
|
||||
GetCurriculums());
|
||||
}
|
||||
if (includeGroups)
|
||||
{
|
||||
builder.AddParagraph("Группы студентов")
|
||||
.AddTable([2400, 2400, 1200, 2400],
|
||||
GetGroups());
|
||||
}
|
||||
builder.Build();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private List<string[]> GetClassrooms()
|
||||
{
|
||||
return [
|
||||
["Размер", "Номер аудитории", "Тип"],
|
||||
.. _classroomRepository.ReadClassroom().Select(x => new string[]
|
||||
{ x.Size.ToString(), x.Name, x.ClassType.ToString() }),
|
||||
];
|
||||
}
|
||||
private List<string[]> GetTeachers()
|
||||
{
|
||||
return [
|
||||
["Имя", "Фамилия"],
|
||||
.. _teacherRepository.ReadTeacher().Select(x => new string[] { x.FirstName, x.LastName }),
|
||||
];
|
||||
}
|
||||
private List<string[]> GetSubjects()
|
||||
{
|
||||
return [
|
||||
["Название предмета"],
|
||||
.. _subjectRepository.ReadSubject().Select(x => new string[]
|
||||
{ x.Name }),
|
||||
];
|
||||
}
|
||||
private List<string[]> GetCurriculums()
|
||||
{
|
||||
return [
|
||||
["Направление"],
|
||||
.. _curriculumRepository.ReadCurriculum().Select(x => new string[]
|
||||
{ x.Direction }),
|
||||
];
|
||||
}
|
||||
private List<string[]> GetGroups()
|
||||
{
|
||||
return [
|
||||
["Количество студентов", "Номер группы", "Курс", "Направление"],
|
||||
.. _groupRepository.ReadGroup().Select(x => new string[]
|
||||
{ x.StudentsCount.ToString(),x.GroupNumber.ToString(), x.Course.ToString(), x.CurriculumId.ToString()}),
|
||||
];
|
||||
}
|
||||
}
|
125
ProjectShedule/ProjectShedule/Reports/WordBuilder.cs
Normal file
125
ProjectShedule/ProjectShedule/Reports/WordBuilder.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using DocumentFormat.OpenXml;
|
||||
|
||||
namespace ProjectShedule.Reports;
|
||||
|
||||
internal 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<string[]> 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>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new BottomBorder()
|
||||
{
|
||||
Val = new
|
||||
EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new LeftBorder()
|
||||
{
|
||||
Val = new
|
||||
EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new RightBorder()
|
||||
{
|
||||
Val = new
|
||||
EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new InsideHorizontalBorder()
|
||||
{
|
||||
Val = new
|
||||
EnumValue<BorderValues>(BorderValues.Single),
|
||||
Size = 12
|
||||
},
|
||||
new InsideVerticalBorder()
|
||||
{
|
||||
Val = new
|
||||
EnumValue<BorderValues>(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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user