Compare commits

...

2 Commits

Author SHA1 Message Date
bekodeg
2bb8b42453 фиксы небольших моментов 2024-11-24 13:20:49 +04:00
bekodeg
7ca62ddb1d Почти работает 2024-11-07 17:36:09 +04:00
33 changed files with 299 additions and 79 deletions

View File

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

View File

@ -7,11 +7,26 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>$(AssemblyName)</PackageId> <PackageId>$(AssemblyName)</PackageId>
<Version>$(VersionPrefix)8.0.1</Version> <Version>$(VersionPrefix)8.0.2</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\PIHelperSh.PdfCreater\PIHelperSh.PdfCreator.csproj" /> <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>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

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

View File

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

View File

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

View File

@ -28,7 +28,11 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
components = new System.ComponentModel.Container();
StudentsListBox = new Cop.Borovkov.Var3.Components.CustomListBox(); 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(); SuspendLayout();
// //
// StudentsListBox // StudentsListBox
@ -49,12 +53,14 @@
Name = "MainForm"; Name = "MainForm";
Text = "MainForm"; Text = "MainForm";
Load += MainForm_LoadAsync; Load += MainForm_LoadAsync;
KeyDown += MainForm_KeyDown;
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private Cop.Borovkov.Var3.Components.CustomListBox StudentsListBox; 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,4 +1,7 @@
using AutoMapper; using AutoMapper;
using ComponentsLibrary.entities;
using ComponentsLibrary.entities.enums;
using Lab3.Database.DTO;
using Lab3.Database.Repository.Interfaces; using Lab3.Database.Repository.Interfaces;
using Lab3.Models; using Lab3.Models;
@ -9,56 +12,239 @@ namespace Lab3.Forms
private readonly IStudentRepository _studentRepository; private readonly IStudentRepository _studentRepository;
private readonly IMapper _mapper; private readonly IMapper _mapper;
private readonly Func<Guid?, CreateForm> _getCreateOrUpdateForm; private readonly Func<Guid?, CreateForm> _getCreateOrUpdateForm;
private readonly CatalogForm _catalogForm;
private bool _cont = false;
public MainForm( public MainForm(
IStudentRepository repository, IStudentRepository repository,
IMapper mapper, IMapper mapper,
Func<Guid?, CreateForm> getCreateOrUpdateForm) Func<Guid?, CreateForm> getCreateOrUpdateForm,
CatalogForm catalogForm)
{ {
_studentRepository = repository; _studentRepository = repository;
_mapper = mapper; _mapper = mapper;
_getCreateOrUpdateForm = getCreateOrUpdateForm; _getCreateOrUpdateForm = getCreateOrUpdateForm;
_catalogForm = catalogForm;
InitializeComponent(); InitializeComponent();
} }
private async void MainForm_LoadAsync(object sender, EventArgs e) private void MainForm_LoadAsync(object sender, EventArgs e)
{ {
var students = _mapper.Map<List<StudentViewModel>>(await _studentRepository.GetAsync()); LoadAsync();
StudentsListBox.FillValues( }
students.Select(s => string.Join(" ",
[ private async void LoadAsync()
s.Id, {
try
{
var students = _mapper.Map<List<StudentViewModel>>(await _studentRepository.GetAsync());
StudentsListBox.FillValues(
students.Select(s => string.Join(" ",
[
s.Id,
s.Name, s.Name,
s.EducationForm, s.EducationForm,
s.StartEducation.ToLongDateString(), s.StartEducation.ToLongDateString(),
s.SessionMarks, s.SessionMarks,
] ]
)) ))
); );
}
catch (Exception ex)
{
MessageBox.Show(
ex.Message,
"Ошибка",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
} }
private void MainForm_KeyDown(object sender, KeyEventArgs e) private async void RemoveStudentAsync()
{ {
if (e.Modifiers != Keys.Control) if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
return; try
{
await _studentRepository
.DeleteAsync(Guid.Parse(StudentsListBox.Selected.Split()[0]));
LoadAsync();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private async void CreateSimpleDocAsync()
{
try
{
using var saveFileDialog = new SaveFileDialog
{
Filter = "pdf|*.pdf"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK)
{
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);
} }
switch (e.KeyCode) if (keyData == Keys.A ||
{ keyData == Keys.U ||
case Keys.A: keyData == Keys.D ||
_getCreateOrUpdateForm(null).Show(this); keyData == Keys.S ||
break; keyData == Keys.T ||
case Keys.U: keyData == Keys.C ||
_getCreateOrUpdateForm( keyData == Keys.G) _cont = false;
Guid.Parse(StudentsListBox.Selected.Split()[0])
).Show(this); return true;
break;
default:
return;
}
} }
} }
} }

View File

@ -117,4 +117,13 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </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> </root>

View File

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

View File

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

View File

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