Compare commits

..

No commits in common. "2bb8b42453731bedfeb1528fcf860f5da34d95c1" and "e825cc46c2fccde685e278ed34939f98f17d858d" have entirely different histories.

33 changed files with 77 additions and 297 deletions

View File

@ -7,9 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cop.Borovkov.Var3", "Cop.Bo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestCustomComponents", "TestCustomComponents\TestCustomComponents.csproj", "{E2C46D08-ACCE-4547-922B-E92AD76D99C8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3", "Lab3\Lab3.csproj", "{1E630CC7-090F-471C-ADA1-74107CF3DC2A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PIHelperSh.PdfCreator", "PIHelperSh.PdfCreater\PIHelperSh.PdfCreator.csproj", "{572BD835-A500-43C9-A66F-648540F4A1C8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3.Database", "Lab3.Database\Lab3.Database.csproj", "{698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab3", "Lab3\Lab3.csproj", "{1E630CC7-090F-471C-ADA1-74107CF3DC2A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab3.Database", "Lab3.Database\Lab3.Database.csproj", "{698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -25,6 +27,10 @@ Global
{E2C46D08-ACCE-4547-922B-E92AD76D99C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2C46D08-ACCE-4547-922B-E92AD76D99C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2C46D08-ACCE-4547-922B-E92AD76D99C8}.Release|Any CPU.Build.0 = Release|Any CPU
{572BD835-A500-43C9-A66F-648540F4A1C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{572BD835-A500-43C9-A66F-648540F4A1C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{572BD835-A500-43C9-A66F-648540F4A1C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{572BD835-A500-43C9-A66F-648540F4A1C8}.Release|Any CPU.Build.0 = Release|Any CPU
{1E630CC7-090F-471C-ADA1-74107CF3DC2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E630CC7-090F-471C-ADA1-74107CF3DC2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E630CC7-090F-471C-ADA1-74107CF3DC2A}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@ -7,26 +7,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>$(AssemblyName)</PackageId>
<Version>$(VersionPrefix)8.0.2</Version>
<Version>$(VersionPrefix)8.0.1</Version>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\LICENSE" Link="PdfCreator\LICENSE">
<PackagePath>\</PackagePath>
<Pack>True</Pack>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="PIHelperSh.Core" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="PdfCreator\README.md">
<PackagePath>\</PackagePath>
<Pack>True</Pack>
</None>
<ProjectReference Include="..\PIHelperSh.PdfCreater\PIHelperSh.PdfCreator.csproj" />
</ItemGroup>
</Project>

View File

@ -29,20 +29,7 @@ namespace Lab3.Database.Repository.Implementations
return _mapper.Map<StudentDTO>(result.Entity);
}
public async Task<StudentDTO?> DeleteAsync(Guid id)
{
var student = await _context.Students.FindAsync(id);
if (student == null)
{
return null;
}
var result = _context.Students.Remove(student);
await _context.SaveChangesAsync();
return _mapper.Map<StudentDTO>(result.Entity);
}
public Task<StudentDTO> DeleteAsync(Guid id) => throw new NotImplementedException();
public async Task<List<StudentDTO>> GetAsync(int limit = 10000, int offset = 0)
=> _mapper.Map<List<StudentDTO>>(
@ -57,7 +44,7 @@ namespace Lab3.Database.Repository.Implementations
return _mapper.Map<StudentDTO>(
await _context.Students
.Include(s => s.StudentSessions)
.FirstOrDefaultAsync(s =>s.Id == id));
.FirstOrDefaultAsync());
}
public async Task<StudentDTO?> UpdateAsync(StudentDTO studentDTO)

View File

@ -10,7 +10,7 @@ namespace Lab3.Database.Repository.Interfaces
Task<StudentDTO?> UpdateAsync(StudentDTO studentDTO);
Task<StudentDTO?> DeleteAsync(Guid id);
Task<StudentDTO> DeleteAsync(Guid id);
Task<StudentDTO> CreateAsync(StudentDTO studentDTO);
}

View File

@ -57,22 +57,20 @@ namespace Lab3.Forms
private async void ButtonSave_ClickAsync(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(NameTextBox.Text)
if (string.IsNullOrEmpty(NameTextBox.Text)
|| string.IsNullOrEmpty(FormSelector.ComboBoxSelectedValue))
{
throw new Exception();
}
{
throw new Exception();
}
StudentDTO student = new()
{
Id = _updatedStudentGuid ?? Guid.NewGuid(),
Name = NameTextBox.Text,
StartEducation = StartEducationDataPicker.Value,
EducationForm = FormSelector.ComboBoxSelectedValue,
StudentSessions = [
new(){
StudentDTO student = new()
{
Id = _updatedStudentGuid ?? Guid.NewGuid(),
Name = NameTextBox.Text,
StartEducation = StartEducationDataPicker.Value,
EducationForm = FormSelector.ComboBoxSelectedValue,
StudentSessions = [
new(){
Score = session1Score.Value,
Number = 1,
},
@ -97,21 +95,15 @@ namespace Lab3.Forms
Number = 6,
},
],
};
};
if (_updatedStudentGuid != null)
{
await _studentRepository.UpdateAsync(student);
}
else
{
await _studentRepository.CreateAsync(student);
}
Close();
}
catch (Exception ex)
if (_updatedStudentGuid != null)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
await _studentRepository.UpdateAsync(student);
}
else
{
await _studentRepository.CreateAsync(student);
}
}
}

View File

@ -28,11 +28,7 @@
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
StudentsListBox = new Cop.Borovkov.Var3.Components.CustomListBox();
SimpleTableCreator = new Cop.Borovkov.Var3.Components.CustomPdfTable(components);
ExcelTableCreator = new CustomComponentsVar2.CustomExcelTable(components);
WordDiogramCreator = new ComponentsLibrary.ComponentDiagram(components);
SuspendLayout();
//
// StudentsListBox
@ -53,14 +49,12 @@
Name = "MainForm";
Text = "MainForm";
Load += MainForm_LoadAsync;
KeyDown += MainForm_KeyDown;
ResumeLayout(false);
}
#endregion
private Cop.Borovkov.Var3.Components.CustomListBox StudentsListBox;
private Cop.Borovkov.Var3.Components.CustomPdfTable SimpleTableCreator;
private CustomComponentsVar2.CustomExcelTable ExcelTableCreator;
private ComponentsLibrary.ComponentDiagram WordDiogramCreator;
}
}

View File

@ -1,7 +1,4 @@
using AutoMapper;
using ComponentsLibrary.entities;
using ComponentsLibrary.entities.enums;
using Lab3.Database.DTO;
using Lab3.Database.Repository.Interfaces;
using Lab3.Models;
@ -12,239 +9,56 @@ namespace Lab3.Forms
private readonly IStudentRepository _studentRepository;
private readonly IMapper _mapper;
private readonly Func<Guid?, CreateForm> _getCreateOrUpdateForm;
private readonly CatalogForm _catalogForm;
private bool _cont = false;
public MainForm(
IStudentRepository repository,
IMapper mapper,
Func<Guid?, CreateForm> getCreateOrUpdateForm,
CatalogForm catalogForm)
Func<Guid?, CreateForm> getCreateOrUpdateForm)
{
_studentRepository = repository;
_mapper = mapper;
_getCreateOrUpdateForm = getCreateOrUpdateForm;
_catalogForm = catalogForm;
InitializeComponent();
}
private void MainForm_LoadAsync(object sender, EventArgs e)
private async void MainForm_LoadAsync(object sender, EventArgs e)
{
LoadAsync();
}
private async void LoadAsync()
{
try
{
var students = _mapper.Map<List<StudentViewModel>>(await _studentRepository.GetAsync());
StudentsListBox.FillValues(
students.Select(s => string.Join(" ",
[
s.Id,
var students = _mapper.Map<List<StudentViewModel>>(await _studentRepository.GetAsync());
StudentsListBox.FillValues(
students.Select(s => string.Join(" ",
[
s.Id,
s.Name,
s.EducationForm,
s.StartEducation.ToLongDateString(),
s.SessionMarks,
]
))
);
}
catch (Exception ex)
{
MessageBox.Show(
ex.Message,
"Ошибка",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
]
))
);
}
private async void RemoveStudentAsync()
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if (e.Modifiers != Keys.Control)
{
try
{
await _studentRepository
.DeleteAsync(Guid.Parse(StudentsListBox.Selected.Split()[0]));
LoadAsync();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return;
}
}
private async void CreateSimpleDocAsync()
{
try
switch (e.KeyCode)
{
using var saveFileDialog = new SaveFileDialog
{
Filter = "pdf|*.pdf"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK)
{
case Keys.A:
_getCreateOrUpdateForm(null).Show(this);
break;
case Keys.U:
_getCreateOrUpdateForm(
Guid.Parse(StudentsListBox.Selected.Split()[0])
).Show(this);
break;
default:
return;
}
var values = (await _studentRepository.GetAsync())
.Select(s => s.StudentSessions
.OrderBy(x => x.Number)
.Select(x => x.Score.ToString())
.ToArray())
.ToArray();
var tables = new string[values.Length, 6];
for (int i = 0; i < values.Length; ++i)
{
for (int j = 0; j < 6; ++j)
{
tables[i, j] = values[i][j];
}
}
SimpleTableCreator.SaveToPdf(new()
{
FilePath = saveFileDialog.FileName,
Title = "Сессии",
Tables = [tables]
});
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private async void CreateTableAsync()
{
try
{
using var saveFileDialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK)
{
return;
}
ExcelTableCreator.SaveToExcel<StudentDTO>(new()
{
FilePath = saveFileDialog.FileName,
Title = "Студенты",
Headers =
[
("Id", nameof(StudentDTO.Id)),
("ФИО", nameof(StudentDTO.Name)),
("Форма обучения", nameof(StudentDTO.EducationForm)),
("Дата поступления", nameof(StudentDTO.StartEducation)),
],
HeaderGroups = [new() {
GroupHeader = "Образование",
FirstHeader = 2,
LastHeader = 3,
}],
Values = await _studentRepository.GetAsync()
});
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private async void CreateWordDocAsync()
{
try
{
using var saveFileDialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK)
{
return;
}
var data = (await _studentRepository.GetAsync())
.GroupBy(s => s.EducationForm)
.Select(s => new DataLine(
s.Key,
s.GroupBy(x => x.StartEducation.Year)
.Select(x => (year: x.Key.ToString(), count: (double)x.Count()))
.ToArray()))
.ToList();
WordDiogramCreator.AddDiagram(
new(
saveFileDialog.FileName,
"Поступления",
"Диограмма",
EnumAreaLegend.Bottom,
data
)
);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.ControlKey | Keys.Control)) _cont = true;
if (_cont && keyData == Keys.A)
{
_getCreateOrUpdateForm(null).ShowDialog(this);
LoadAsync();
}
else if (_cont && keyData == Keys.U)
{
var elem = StudentsListBox.Selected;
_getCreateOrUpdateForm(
Guid.Parse(elem.Split()[0])
).ShowDialog(this);
LoadAsync();
}
else if (_cont && keyData == Keys.D)
{
RemoveStudentAsync();
}
else if (_cont && keyData == Keys.S)
{
CreateSimpleDocAsync();
}
else if (_cont && keyData == Keys.T)
{
CreateTableAsync();
}
else if (_cont && keyData == Keys.C)
{
CreateWordDocAsync();
}
else if (_cont && keyData == Keys.G)
{
_catalogForm.ShowDialog(this);
}
if (keyData == Keys.A ||
keyData == Keys.U ||
keyData == Keys.D ||
keyData == Keys.S ||
keyData == Keys.T ||
keyData == Keys.C ||
keyData == Keys.G) _cont = false;
return true;
}
}
}

View File

@ -117,13 +117,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="SimpleTableCreator.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="ExcelTableCreator.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>203, 17</value>
</metadata>
<metadata name="WordDiogramCreator.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>377, 17</value>
</metadata>
</root>

View File

@ -15,7 +15,7 @@
<ItemGroup>
<PackageReference Include="ComponentsLibraryLab1" Version="8.0.2" />
<PackageReference Include="ComponentsLibraryLab2" Version="8.0.1" />
<PackageReference Include="Cop.Borovkov.Var3" Version="8.0.2" />
<PackageReference Include="Cop.Borovkov.Var3" Version="8.0.1" />
<PackageReference Include="CustomComponentsVar2" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
</ItemGroup>

View File

@ -20,7 +20,7 @@ namespace Lab3
var app = CreateHostBuilder().Build();
Application.Run(app.Services.GetRequiredService<MainForm>());
Application.Run(app.Services.GetRequiredService<CatalogForm>());
}
static IHostBuilder CreateHostBuilder()

View File

@ -16,9 +16,23 @@
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="PIHelperSh.Core" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
</Project>

View File

@ -1,6 +1,8 @@
using MigraDoc.DocumentObjectModel;
using System.Text;
using MigraDoc.Rendering;
using MigraDoc.DocumentObjectModel.Tables;
using System.Reflection;
using MigraDoc.DocumentObjectModel.Shapes.Charts;
using PIHelperSh.Core.Extensions;
using PIHelperSh.PdfCreator.Enums;
@ -9,11 +11,6 @@ using PIHelperSh.PdfCreator.Models.TextModels;
using PIHelperSh.PdfCreator.Models.ImageModels;
using PIHelperSh.PdfCreator.Models.PieChartModel;
using PIHelperSh.PdfCreator.Interfaces;
using System.Text;
using TabAlignment = MigraDoc.DocumentObjectModel.TabAlignment;
using System.Reflection;
using HorizontalAlignment = MigraDoc.DocumentObjectModel.Shapes.Charts.HorizontalAlignment;
using Color = MigraDoc.DocumentObjectModel.Color;
namespace PIHelperSh.PdfCreator
{
@ -416,7 +413,7 @@ namespace PIHelperSh.PdfCreator
if (rowHeaded)
{
_section!.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
_section!.PageSetup.Orientation = Orientation.Landscape;
_section.PageSetup.LeftMargin = 10;
MakeTableWithHederInRow(_document.LastSection.AddTable(), header);
return;
@ -459,7 +456,7 @@ namespace PIHelperSh.PdfCreator
if (tableData.ChangePageOrientation)
{
_section!.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
_section!.PageSetup.Orientation = Orientation.Landscape;
_section.PageSetup.LeftMargin = 10;
_section.PageSetup.BottomMargin = 5;
}
@ -538,7 +535,7 @@ namespace PIHelperSh.PdfCreator
if (item.Color.HasValue)
{
series.FillFormat.Color = new MigraDoc.DocumentObjectModel.Color((uint)item.Color.Value.ToArgb());
series.FillFormat.Color = new Color((uint)item.Color.Value.ToArgb());
}
}