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
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestCustomComponents", "TestCustomComponents\TestCustomComponents.csproj", "{E2C46D08-ACCE-4547-922B-E92AD76D99C8}"
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
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}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3.Database", "Lab3.Database\Lab3.Database.csproj", "{698DE9E8-7885-4F98-AFE3-9A9C6CD2FCF5}"
EndProject
Global
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}.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,11 +7,26 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>$(AssemblyName)</PackageId>
<Version>$(VersionPrefix)8.0.1</Version>
<Version>$(VersionPrefix)8.0.2</Version>
</PropertyGroup>
<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>
</Project>

View File

@ -1,8 +1,6 @@
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;
@ -11,6 +9,11 @@ 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
{
@ -413,7 +416,7 @@ namespace PIHelperSh.PdfCreator
if (rowHeaded)
{
_section!.PageSetup.Orientation = Orientation.Landscape;
_section!.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
_section.PageSetup.LeftMargin = 10;
MakeTableWithHederInRow(_document.LastSection.AddTable(), header);
return;
@ -456,7 +459,7 @@ namespace PIHelperSh.PdfCreator
if (tableData.ChangePageOrientation)
{
_section!.PageSetup.Orientation = Orientation.Landscape;
_section!.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
_section.PageSetup.LeftMargin = 10;
_section.PageSetup.BottomMargin = 5;
}
@ -535,7 +538,7 @@ namespace PIHelperSh.PdfCreator
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);
}
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)
=> _mapper.Map<List<StudentDTO>>(
@ -44,7 +57,7 @@ namespace Lab3.Database.Repository.Implementations
return _mapper.Map<StudentDTO>(
await _context.Students
.Include(s => s.StudentSessions)
.FirstOrDefaultAsync());
.FirstOrDefaultAsync(s =>s.Id == id));
}
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

@ -56,6 +56,8 @@ namespace Lab3.Forms
}
private async void ButtonSave_ClickAsync(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(NameTextBox.Text)
|| string.IsNullOrEmpty(FormSelector.ComboBoxSelectedValue))
@ -105,6 +107,12 @@ namespace Lab3.Forms
{
await _studentRepository.CreateAsync(student);
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -28,7 +28,11 @@
/// </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
@ -49,12 +53,14 @@
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,4 +1,7 @@
using AutoMapper;
using ComponentsLibrary.entities;
using ComponentsLibrary.entities.enums;
using Lab3.Database.DTO;
using Lab3.Database.Repository.Interfaces;
using Lab3.Models;
@ -9,21 +12,33 @@ 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)
Func<Guid?, CreateForm> getCreateOrUpdateForm,
CatalogForm catalogForm)
{
_studentRepository = repository;
_mapper = mapper;
_getCreateOrUpdateForm = getCreateOrUpdateForm;
_catalogForm = catalogForm;
InitializeComponent();
}
private async void MainForm_LoadAsync(object sender, EventArgs e)
private void MainForm_LoadAsync(object sender, EventArgs e)
{
LoadAsync();
}
private async void LoadAsync()
{
try
{
var students = _mapper.Map<List<StudentViewModel>>(await _studentRepository.GetAsync());
StudentsListBox.FillValues(
@ -38,27 +53,198 @@ namespace Lab3.Forms
))
);
}
private void MainForm_KeyDown(object sender, KeyEventArgs e)
catch (Exception ex)
{
if (e.Modifiers != Keys.Control)
MessageBox.Show(
ex.Message,
"Ошибка",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private async void RemoveStudentAsync()
{
if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
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;
}
switch (e.KeyCode)
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)
{
case Keys.A:
_getCreateOrUpdateForm(null).Show(this);
break;
case Keys.U:
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(StudentsListBox.Selected.Split()[0])
).Show(this);
break;
default:
return;
}
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,4 +117,13 @@
<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.1" />
<PackageReference Include="Cop.Borovkov.Var3" Version="8.0.2" />
<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<CatalogForm>());
Application.Run(app.Services.GetRequiredService<MainForm>());
}
static IHostBuilder CreateHostBuilder()

View File

@ -16,23 +16,9 @@
<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>