Создание списка тсудентов

This commit is contained in:
kotcheshir73 2022-12-19 22:12:03 +04:00
parent 72cb1f1e63
commit 6840a8966f
10 changed files with 555 additions and 30 deletions

View File

@ -381,10 +381,6 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic
SaveLog("Не удалось распознать список приказов по студенту");
return;
}
if (student.LastName == "Костенко" || student.LastName == "Киселева")
{
int c = 10;
}
foreach (var syncOrder in syncOrders.StudentOrders)
{
if (syncOrder.orderTypeName == "Утверждение тем курсовых работ" ||

View File

@ -2,8 +2,19 @@
using DepartmentContract.Logics.IGenericEntityLogic;
using DepartmentContract.Services.IGenericEntityService;
using DepartmentContract.ViewModels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using ToolsModule.ManagmentDependency;
using ToolsModule.ManagmentEntity;
using ToolsModule.ManagmentExtension;
using ToolsModule.ManagmentSecurity;
using ToolsOffice.Interfaces;
using ToolsOffice.Interfaces.Word;
using ToolsOffice.Interfaces.Word.Models;
using ToolsOffice.Interfaces.Word.Models.Cases;
namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic
{
@ -13,5 +24,172 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic
public class StudentGroupBusinessLogic : GenericBusinessLogic<StudentGroupGetBindingModel, StudentGroupSetBindingModel, StudentGroupListViewModel, StudentGroupViewModel>, IStudentGroupLogic
{
public StudentGroupBusinessLogic(IStudentGroupService service) : base(service, "Учебные Группы", AccessOperation.УчебныеГруппы) { }
public async Task<bool> SaveToWord(StudentGroupSaveToWordBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (model.FileName.IsEmpty())
{
throw new ArgumentNullException("Имя файла", nameof(model.FileName));
}
var builderWordDocument = DependencyManager.Instance.Resolve<BuilderWordDocument>();
if (builderWordDocument == null)
{
throw new ArgumentNullException("Сервис генерации документов", nameof(builderWordDocument));
}
var studentLogic = DependencyManager.Instance.Resolve<IStudentLogic>();
if (studentLogic == null)
{
throw new ArgumentNullException("Сервис студентов", nameof(studentLogic));
}
var studetns = studentLogic.GetList(new StudentGetBindingModel { StudentGroupId = model.StudentGroupId });
if (studetns == null)
{
throw new InvalidOperationException(string.Join(Environment.NewLine, studentLogic.Errors.Select(x => x.Message)));
}
var studentGroup = GetElement(new StudentGroupGetBindingModel { Id = model.StudentGroupId });
if (studentGroup == null)
{
throw new InvalidOperationException(string.Join(Environment.NewLine, Errors.Select(x => x.Message)));
}
var table = new ModelWordTable()
{
RowsHeight = new Dictionary<int, double>(),
BorderType = TypeWordTableBorder.Single,
BorderWidth = 4,
Headers = new List<(int ColumnIndex, int RowIndex, string Header)>(),
ColumnWidths = new Dictionary<int, double>(),
Data = new List<string[]>(),
LookFirstRow = true,
LookFirstColumn = true
};
int columnIndex = 0;
table.Headers.Add((columnIndex, 0, "№"));
table.ColumnWidths.Add(columnIndex, 1);
columnIndex++;
if (model.ShowNumberOfBook)
{
table.Headers.Add((columnIndex, 0, "Номер зачетной книжки"));
table.ColumnWidths.Add(columnIndex, 2.5);
columnIndex++;
}
if (model.UnionFIO)
{
table.Headers.Add((columnIndex, 0, "ФИО"));
table.ColumnWidths.Add(columnIndex, 5);
columnIndex++;
}
else
{
table.Headers.Add((columnIndex, 0, "Фамилия"));
table.ColumnWidths.Add(columnIndex, 5);
columnIndex++;
table.Headers.Add((columnIndex, 0, "Имя"));
table.ColumnWidths.Add(columnIndex, 5);
columnIndex++;
table.Headers.Add((columnIndex, 0, "Отчество"));
table.ColumnWidths.Add(columnIndex, 5);
columnIndex++;
}
if (model.ShowStatus)
{
table.Headers.Add((columnIndex, 0, "Статус"));
table.ColumnWidths.Add(columnIndex, 2.5);
columnIndex++;
}
if (model.ShowInfo)
{
table.Headers.Add((columnIndex, 0, "Информация"));
table.ColumnWidths.Add(columnIndex, 15);
columnIndex++;
}
table.RowsHeight.Add(0, 1.5);
int rowIndex = 0;
foreach(var student in studetns.List)
{
var listOfData = new List<string>() { (rowIndex + 1).ToString() };
if (model.ShowNumberOfBook)
{
listOfData.Add(student.NumberOfBook);
}
if (model.UnionFIO)
{
if (model.UseInitials)
{
listOfData.Add($"{student.LastName}{(student.FirstName.Length > 0 ? $" {student.FirstName[0]}." : "")}{(student.Patronymic.Length > 0 ? $" {student.Patronymic[0]}." : "")}");
}
else
{
listOfData.Add($"{student.LastName} {student.FirstName} {student.Patronymic}");
}
}
else
{
listOfData.Add(student.LastName);
listOfData.Add(student.FirstName);
listOfData.Add(student.Patronymic);
}
if (model.ShowStatus)
{
listOfData.Add(student.StudentStateTitle);
}
if (model.ShowInfo)
{
listOfData.Add(student.Description);
}
table.Data.Add(listOfData.ToArray());
table.RowsHeight.Add(rowIndex + 1, 1);
rowIndex++;
}
var pageSize = new PageSizes("А4");
var docModel = new ModelWordDocumentWithHeaderAndTable
{
Document = new ModelWordDocument
{
WordPageOrientation = TypeWordPageOrientation.Landscape,
PageSizeHeight = pageSize.PageSizeWidth,
PageSizeWidth = pageSize.PageSizeHeight,
PageMarginBottom = pageSize.PageMarginBottom,
PageMarginTop = pageSize.PageMarginTop,
PageMarginLeft = pageSize.PageMarginLeft,
PageMarginRight = pageSize.PageMarginRight,
PageMarginGutter = pageSize.PageMarginGutter,
PageHeader = pageSize.PageHeader,
PageFooter = pageSize.PageFooter
},
Header = new ModelWordParagraph
{
FontName = FontNames.TimesNewRoman,
FontSize = 16,
IsBold = true,
JustificationType = TypeWordJustification.Center,
Text = studentGroup.ToString(),
SpacingBetweenLinesAfter = 10
},
Table = table
};
var stream = builderWordDocument.CreateDocumentWithTable(docModel);
if (stream == null)
{
throw new InvalidOperationException("Не удалось получить поток с документом");
}
stream.Position = 0;
using (var saveStream = new FileStream(model.FileName, FileMode.OpenOrCreate))
{
await stream.CopyToAsync(saveStream);
}
stream.Close();
return true;
}
}
}

View File

@ -2,9 +2,11 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\ToolsOffice\ToolsOffice.csproj" />
<ProjectReference Include="..\..\Security\SecurityContract\SecurityContract.csproj" />
<ProjectReference Include="..\DepartmentContract\DepartmentContract.csproj" />
</ItemGroup>

View File

@ -1,6 +1,8 @@
using DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic;
using DepartmentContract.Logics.IGenericEntityLogic;
using ToolsModule.ManagmentDependency;
using ToolsOffice.Implements.WordOpenXML;
using ToolsOffice.Interfaces.Word;
namespace DepartmentBusinessLogic
{
@ -42,6 +44,10 @@ namespace DepartmentBusinessLogic
DependencyManager.Instance.RegisterType<IOrderSyncHistoryRecordLogic, OrderSyncHistoryRecordBusinessLogic>();
DependencyManager.Instance.RegisterType<IBasicDepartmentLogic, BasicDepartmentBusinessLogic>();
DependencyManager.Instance.RegisterType<BuilderWordDocument, BuilderWordDocumentOpenXML>();
}
}
}

View File

@ -0,0 +1,21 @@
using System;
namespace DepartmentContract.BindingModels
{
public class StudentGroupSaveToWordBindingModel
{
public string FileName { get; set; }
public Guid StudentGroupId { get; set; }
public bool ShowNumberOfBook { get; set; } = false;
public bool UnionFIO { get; set; } = false;
public bool UseInitials { get; set; } = false;
public bool ShowStatus { get; set; } = false;
public bool ShowInfo { get; set; } = false;
}
}

View File

@ -1,5 +1,6 @@
using DepartmentContract.BindingModels;
using DepartmentContract.ViewModels;
using System.Threading.Tasks;
using ToolsModule.ManagmentEntity;
namespace DepartmentContract.Logics.IGenericEntityLogic
@ -7,5 +8,8 @@ namespace DepartmentContract.Logics.IGenericEntityLogic
/// <summary>
/// Логика работы с учебными группами
/// </summary>
public interface IStudentGroupLogic : IGenericEntityLogic<StudentGroupGetBindingModel, StudentGroupSetBindingModel, StudentGroupListViewModel, StudentGroupViewModel> { }
public interface IStudentGroupLogic : IGenericEntityLogic<StudentGroupGetBindingModel, StudentGroupSetBindingModel, StudentGroupListViewModel, StudentGroupViewModel>
{
Task<bool> SaveToWord(StudentGroupSaveToWordBindingModel model);
}
}

View File

@ -1,10 +1,14 @@
using DepartmentContract.BindingModels;
using DepartmentContract.Logics.IGenericEntityLogic;
using DepartmentContract.ViewModels;
using DepartmentWindowsDesktop.EntityControls.StudentGroup;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using ToolsDesktop.Controls;
using ToolsDesktop.Enums;
using ToolsDesktop.Helpers;
using ToolsDesktop.Interfaces;
using ToolsDesktop.Models;
using ToolsModule.ManagmentSecurity;
@ -36,7 +40,46 @@ namespace DepartmentWindowsDesktop.EntityControls
HideToolStripButton = new List<ToolStripButtonListNames>
{
ToolStripButtonListNames.toolStripButtonSearch
},
ControlOnMoveElem = new()
{
{ "ToolStripMenuItemSaveStudentGroup", ("Сохранить список студентов", async (object sender, EventArgs e) => { await SaveToFile(); }) }
}
};
/// <summary>
/// Сохранение в файл
/// </summary>
/// <returns></returns>
private async Task SaveToFile()
{
var guids = GetSelectedIds();
if (guids == null || guids.Count != 1)
{
DialogHelper.MessageException("Должна быть выбрана одна группа", "Ошибки при создании документа");
return;
}
var form = new FormSaveToFile();
if (form.ShowDialog() != DialogResult.OK)
{
return;
}
var model = form.Model;
if (model == null)
{
DialogHelper.MessageException("Данные для сохранения не получены", "Ошибки при создании документа");
return;
}
model.StudentGroupId = guids[0];
var flag = await _businessLogic.SaveToWord(model);
if (!flag)
{
DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при создании документа");
}
else
{
DialogHelper.MessageInformation("Завершено успешно", "Сохранение списка группы");
}
}
}
}

View File

@ -0,0 +1,165 @@

namespace DepartmentWindowsDesktop.EntityControls.StudentGroup
{
partial class FormSaveToFile
{
/// <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()
{
this.labelFileName = new System.Windows.Forms.Label();
this.textBoxFileName = new System.Windows.Forms.TextBox();
this.buttonSelect = new System.Windows.Forms.Button();
this.checkBoxShowNumberOfBook = new System.Windows.Forms.CheckBox();
this.checkBoxUnionFIO = new System.Windows.Forms.CheckBox();
this.checkBoxUseInitials = new System.Windows.Forms.CheckBox();
this.checkBoxShowStatus = new System.Windows.Forms.CheckBox();
this.checkBoxShowInfo = new System.Windows.Forms.CheckBox();
this.buttonSave = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelFileName
//
this.labelFileName.AutoSize = true;
this.labelFileName.Location = new System.Drawing.Point(22, 24);
this.labelFileName.Name = "labelFileName";
this.labelFileName.Size = new System.Drawing.Size(90, 15);
this.labelFileName.TabIndex = 0;
this.labelFileName.Text = "Путь до файла:";
//
// textBoxFileName
//
this.textBoxFileName.Location = new System.Drawing.Point(118, 21);
this.textBoxFileName.Name = "textBoxFileName";
this.textBoxFileName.Size = new System.Drawing.Size(300, 23);
this.textBoxFileName.TabIndex = 1;
//
// buttonSelect
//
this.buttonSelect.Location = new System.Drawing.Point(338, 50);
this.buttonSelect.Name = "buttonSelect";
this.buttonSelect.Size = new System.Drawing.Size(80, 23);
this.buttonSelect.TabIndex = 2;
this.buttonSelect.Text = "Выбрать";
this.buttonSelect.UseVisualStyleBackColor = true;
this.buttonSelect.Click += new System.EventHandler(this.ButtonSelect_Click);
//
// checkBoxShowNumberOfBook
//
this.checkBoxShowNumberOfBook.AutoSize = true;
this.checkBoxShowNumberOfBook.Location = new System.Drawing.Point(29, 73);
this.checkBoxShowNumberOfBook.Name = "checkBoxShowNumberOfBook";
this.checkBoxShowNumberOfBook.Size = new System.Drawing.Size(216, 19);
this.checkBoxShowNumberOfBook.TabIndex = 3;
this.checkBoxShowNumberOfBook.Text = "Выводить номер зачетной книжки";
this.checkBoxShowNumberOfBook.UseVisualStyleBackColor = true;
//
// checkBoxUnionFIO
//
this.checkBoxUnionFIO.AutoSize = true;
this.checkBoxUnionFIO.Location = new System.Drawing.Point(29, 112);
this.checkBoxUnionFIO.Name = "checkBoxUnionFIO";
this.checkBoxUnionFIO.Size = new System.Drawing.Size(204, 19);
this.checkBoxUnionFIO.TabIndex = 4;
this.checkBoxUnionFIO.Text = "Выводить ФИО в одной колонке";
this.checkBoxUnionFIO.UseVisualStyleBackColor = true;
this.checkBoxUnionFIO.CheckedChanged += new System.EventHandler(this.CheckBoxUnionFIO_CheckedChanged);
//
// checkBoxUseInitials
//
this.checkBoxUseInitials.AutoSize = true;
this.checkBoxUseInitials.Enabled = false;
this.checkBoxUseInitials.Location = new System.Drawing.Point(73, 148);
this.checkBoxUseInitials.Name = "checkBoxUseInitials";
this.checkBoxUseInitials.Size = new System.Drawing.Size(184, 19);
this.checkBoxUseInitials.TabIndex = 5;
this.checkBoxUseInitials.Text = "Выводить ФИО с иницалами";
this.checkBoxUseInitials.UseVisualStyleBackColor = true;
//
// checkBoxShowStatus
//
this.checkBoxShowStatus.AutoSize = true;
this.checkBoxShowStatus.Location = new System.Drawing.Point(29, 184);
this.checkBoxShowStatus.Name = "checkBoxShowStatus";
this.checkBoxShowStatus.Size = new System.Drawing.Size(116, 19);
this.checkBoxShowStatus.TabIndex = 6;
this.checkBoxShowStatus.Text = "Выводить статус";
this.checkBoxShowStatus.UseVisualStyleBackColor = true;
//
// checkBoxShowInfo
//
this.checkBoxShowInfo.AutoSize = true;
this.checkBoxShowInfo.Location = new System.Drawing.Point(29, 224);
this.checkBoxShowInfo.Name = "checkBoxShowInfo";
this.checkBoxShowInfo.Size = new System.Drawing.Size(135, 19);
this.checkBoxShowInfo.TabIndex = 7;
this.checkBoxShowInfo.Text = "Выводить описание";
this.checkBoxShowInfo.UseVisualStyleBackColor = true;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(286, 196);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(101, 33);
this.buttonSave.TabIndex = 8;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// FormSaveToFile
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(438, 269);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.checkBoxShowInfo);
this.Controls.Add(this.checkBoxShowStatus);
this.Controls.Add(this.checkBoxUseInitials);
this.Controls.Add(this.checkBoxUnionFIO);
this.Controls.Add(this.checkBoxShowNumberOfBook);
this.Controls.Add(this.buttonSelect);
this.Controls.Add(this.textBoxFileName);
this.Controls.Add(this.labelFileName);
this.Name = "FormSaveToFile";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Сохранение в файл";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label labelFileName;
private System.Windows.Forms.TextBox textBoxFileName;
private System.Windows.Forms.Button buttonSelect;
private System.Windows.Forms.CheckBox checkBoxShowNumberOfBook;
private System.Windows.Forms.CheckBox checkBoxUnionFIO;
private System.Windows.Forms.CheckBox checkBoxUseInitials;
private System.Windows.Forms.CheckBox checkBoxShowStatus;
private System.Windows.Forms.CheckBox checkBoxShowInfo;
private System.Windows.Forms.Button buttonSave;
}
}

View File

@ -0,0 +1,50 @@
using DepartmentContract.BindingModels;
using System;
using System.Windows.Forms;
using ToolsModule.ManagmentExtension;
namespace DepartmentWindowsDesktop.EntityControls.StudentGroup
{
public partial class FormSaveToFile : Form
{
public StudentGroupSaveToWordBindingModel Model { get; private set; }
public FormSaveToFile()
{
InitializeComponent();
}
private void ButtonSelect_Click(object sender, EventArgs e)
{
var dialog = new SaveFileDialog { Filter = "doc file | *.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
textBoxFileName.Text = dialog.FileName;
}
}
private void CheckBoxUnionFIO_CheckedChanged(object sender, EventArgs e)
{
checkBoxUseInitials.Enabled = checkBoxUnionFIO.Checked;
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (textBoxFileName.Text.IsEmpty())
{
DialogResult = DialogResult.Cancel;
return;
}
Model = new StudentGroupSaveToWordBindingModel
{
FileName = textBoxFileName.Text,
ShowInfo = checkBoxShowInfo.Checked,
ShowNumberOfBook = checkBoxShowNumberOfBook.Checked,
ShowStatus = checkBoxShowStatus.Checked,
UnionFIO = checkBoxUnionFIO.Checked,
UseInitials = checkBoxUnionFIO.Checked && checkBoxUseInitials.Checked
};
DialogResult = DialogResult.OK;
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>