Compare commits

..

No commits in common. "d9dea309c59bc97611e3ef242e9d60ea9ee45ea4" and "2513ebcc8e3cd9fffabe6d77ec70687a9d1eceeb" have entirely different histories.

13 changed files with 33 additions and 377 deletions

View File

@ -41,7 +41,7 @@ namespace Cop.Borovkov.Var3.Components
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
}
_ = outDataGridView.Columns.Add(column);
outDataGridView.Columns.Add(column);
}
}
@ -108,10 +108,10 @@ namespace Cop.Borovkov.Var3.Components
Type type = typeof(TType);
for (int i = 0; i < insertValues.Count; ++i)
for (int i = 0; i < insertValues.Count(); ++i)
{
var row = insertValues[i];
_ = outDataGridView.Rows.Add();
outDataGridView.Rows.Add();
for (int j = 0; j < outDataGridView.ColumnCount; ++j)
{

View File

@ -14,7 +14,7 @@ namespace Lab3.Database.Extensions
this IServiceCollection services,
IConfiguration configuration)
{
_ = services.AddDbContextPool<COPContext>(
services.AddDbContextPool<COPContext>(
dbContextOptions =>
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);

View File

@ -21,7 +21,7 @@ namespace Lab3.Extensions
return services;
}
public static IServiceCollection AddLab3Forms(
public static IServiceCollection AddForms(
this IServiceCollection services)
{
services.AddScoped<MainForm>();

View File

@ -19,7 +19,7 @@ namespace Lab3.Forms
var values = (await _repository.Get()).ToList();
for (int i = 0; i < values.Count; i++)
{
_ = Catalog.Rows.Add();
Catalog.Rows.Add();
Catalog.Rows[i].Cells[0].Value = values[i];
}
}
@ -40,7 +40,7 @@ namespace Lab3.Forms
string? val = (string?)Catalog.Rows[i].Cells[0].Value;
if (string.IsNullOrEmpty(val))
{
_ = MessageBox.Show(
MessageBox.Show(
"Неверные данные",
"Ошибка",
MessageBoxButtons.OK,
@ -54,7 +54,7 @@ namespace Lab3.Forms
}
catch (Exception ex)
{
_ = MessageBox.Show(
MessageBox.Show(
ex.Message,
"Ошибка",
MessageBoxButtons.OK,
@ -66,7 +66,7 @@ namespace Lab3.Forms
{
if (e.KeyCode == Keys.Insert)
{
_ = Catalog.Rows.Add();
Catalog.Rows.Add();
}
if (e.KeyCode == Keys.Delete && Catalog.SelectedRows.Count == 1)
@ -84,7 +84,7 @@ namespace Lab3.Forms
}
catch (Exception ex)
{
_ = MessageBox.Show(
MessageBox.Show(
ex.Message,
"Ошибка",
MessageBoxButtons.OK,

View File

@ -37,7 +37,7 @@ namespace Lab3.Forms
}
var student = await _studentRepository.GetAsync(_updatedStudentGuid.Value);
NameTextBox.Text = student!.Name;
NameTextBox.Text = student.Name;
StartEducationDataPicker.Value = student.StartEducation;
FormSelector.ComboBoxSelectedValue = student.EducationForm;
@ -101,11 +101,11 @@ namespace Lab3.Forms
if (_updatedStudentGuid != null)
{
_ = await _studentRepository.UpdateAsync(student);
await _studentRepository.UpdateAsync(student);
}
else
{
_ = await _studentRepository.CreateAsync(student);
await _studentRepository.CreateAsync(student);
}
Close();
}

View File

@ -9,7 +9,7 @@ namespace Lab3
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
@ -34,7 +34,7 @@ namespace Lab3
services.AddMapping();
services.AddLab3Forms();
services.AddForms();
});
}
}

View File

@ -1,29 +0,0 @@
using Lab4.Forms;
using Lab4.Implementations;
using Lab4.Interfaces;
using Microsoft.Extensions.DependencyInjection;
namespace Lab4.Extensions
{
public static class DiExtensions
{
public static IServiceCollection AddLab4Forms(
this IServiceCollection services)
{
services.AddScoped<FormMain>();
return services;
}
public static IServiceCollection AddScopes(
this IServiceCollection services)
{
services.AddScoped<PluginsConvention>();
services.AddScoped<Func<Type, IPluginsConvention>>(sp
=> (type) => (sp.GetRequiredService(type) as IPluginsConvention)!);
return services;
}
}
}

View File

@ -8,52 +8,23 @@ namespace Lab4.Forms
private readonly Dictionary<string, IPluginsConvention> _plugins;
private string _selectedPlugin;
private readonly Func<Type, IPluginsConvention> _getPluginObjectFunc;
public FormMain(Func<Type, IPluginsConvention> getPluginObjectFunc)
public FormMain()
{
InitializeComponent();
_getPluginObjectFunc = getPluginObjectFunc;
_plugins = LoadPlugins();
_selectedPlugin = string.Empty;
}
private Dictionary<string, IPluginsConvention> LoadPlugins()
{
Dictionary<string, IPluginsConvention> result = [];
var plurinType = typeof(IPluginsConvention);
foreach (var type in AppDomain.CurrentDomain
.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(x => plurinType.IsAssignableFrom(x) && x != plurinType))
{
var plugin = _getPluginObjectFunc(type);
string key = plugin.PluginName;
result[key] = plugin;
var item = new ToolStripMenuItem(key);
item.Click += (s, e) =>
{
_selectedPlugin = key;
panelControl.Controls.Clear();
_plugins[_selectedPlugin].ReloadData();
var control = _plugins[key].GetControl;
control.Parent = panelControl;
control.Dock = DockStyle.Fill;
panelControl.Controls.Add(control);
};
ControlsStripMenuItem.DropDownItems!.Add(item);
}
return result;
// TODO Заполнить IPluginsConvention
// TODO Заполнить пункт меню "Компоненты" на основе IPluginsConvention.PluginName
// TODO Например, создавать ToolStripMenuItem, привязывать к ним обработку событий и добавлять в menuStrip
// TODO При выборе пункта меню получать UserControl и заполнять элемент panelControl этим контролом на всю площадь
// Пример: panelControl.Controls.Clear();
// panelControl.Controls.Add(ctrl);
return [];
}
private void FormMain_KeyDown(object sender, KeyEventArgs e)
@ -127,7 +98,6 @@ namespace Lab4.Forms
_plugins[_selectedPlugin].ReloadData();
}
}
private void DeleteElement()
{
if (MessageBox.Show("Удалить выбранный элемент", "Удаление",
@ -153,19 +123,8 @@ namespace Lab4.Forms
private void CreateSimpleDoc()
{
using var saveFileDialog = new SaveFileDialog
{
Filter = "pdf|*.pdf"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK)
{
return;
}
if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument()
{
FileName = saveFileDialog.FileName,
}))
// TODO узнать где сохранять
if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument()))
{
_ = MessageBox.Show("Документ сохранен",
"Создание документа",
@ -177,24 +136,11 @@ namespace Lab4.Forms
_ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CreateTableDoc()
{
using var saveFileDialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK)
{
return;
}
// TODO узнать где сохранять
if (_plugins[_selectedPlugin].CreateTableDocument(new
PluginsConventionSaveDocument()
{
FileName = saveFileDialog.FileName,
}))
PluginsConventionSaveDocument()))
{
_ = MessageBox.Show("Документ сохранен",
"Создание документа",
@ -206,23 +152,10 @@ namespace Lab4.Forms
_ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CreateChartDoc()
{
using var saveFileDialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK)
{
return;
}
if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument()
{
FileName= saveFileDialog.FileName,
}))
// TODO узнать где сохранять
if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument()))
{
_ = MessageBox.Show("Документ сохранен",
"Создание документа",
@ -234,7 +167,7 @@ namespace Lab4.Forms
_ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus();
private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement();

View File

@ -1,204 +0,0 @@
using Cop.Borovkov.Var3.Components;
using Lab4.Interfaces;
using Lab4.Models;
using Lab3.Database.Repository.Interfaces;
using ComponentsLibrary.entities;
using ComponentsLibrary;
using ComponentsLibrary.entities.enums;
using Lab3.Database.DTO;
using CustomComponentsVar2;
using Lab3.Forms;
using Lab3.Models;
using AutoMapper;
namespace Lab4.Implementations
{
public class PluginsConvention : IPluginsConvention
{
private readonly IMapper _mapper;
private readonly IStudentRepository _studentRepository;
private readonly IEducationFormRepository _educationFormRepository;
private readonly CustomListBox _control;
private readonly CustomPdfTable _simpleDocumentCreator;
private readonly CustomExcelTable _tableCreator;
private readonly ComponentDiagram _chartCreator;
public PluginsConvention(
IMapper mapper,
IStudentRepository studentRepository,
IEducationFormRepository educationFormRepository)
{
_mapper = mapper;
_studentRepository = studentRepository;
_educationFormRepository = educationFormRepository;
_control = new();
_chartCreator = new();
_tableCreator = new();
_simpleDocumentCreator = new();
}
public string PluginName => "Успеваемость";
public UserControl GetControl => _control;
public PluginsConventionElement GetElement {
get
{
var filds = _control.Selected.Split();
Guid id = Guid.Parse(filds[0]);
return new()
{
Id = id,
};
}
}
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
var data = _studentRepository.GetAsync().Result
.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();
_chartCreator.AddDiagram(
new(
saveDocument.FileName,
"Поступления",
"Диаграмма",
EnumAreaLegend.Bottom,
data
)
);
return true;
}
catch
{
return false;
}
}
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
var values = (_studentRepository.GetAsync()).Result
.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];
}
}
_simpleDocumentCreator.SaveToPdf(new()
{
FilePath = saveDocument.FileName,
Title = "Сессии",
Tables = [tables]
});
return true;
}
catch
{
return false;
}
}
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
{
try
{
_tableCreator.SaveToExcel<StudentDTO>(new()
{
FilePath = saveDocument.FileName,
Title = "Студенты",
Headers =
[
("Id", nameof(StudentDTO.Id)),
("ФИО", nameof(StudentDTO.Name)),
("Форма обучения", nameof(StudentDTO.EducationForm)),
("Дата поступления", nameof(StudentDTO.StartEducation)),
],
HeaderGroups = [new() {
GroupHeader = "Образование",
FirstHeader = 2,
LastHeader = 3,
}],
Values = _studentRepository.GetAsync().Result
});
return true;
}
catch
{
return false;
}
}
public bool DeleteElement(PluginsConventionElement element)
{
try
{
_studentRepository
.DeleteAsync(element.Id).Wait();
return true;
}
catch
{
return false;
}
}
public Form GetForm(PluginsConventionElement? element = null)
=> new CreateForm(_studentRepository, _educationFormRepository, element?.Id);
public Form GetThesaurus()
=> new CatalogForm(_educationFormRepository);
public async void ReloadData()
{
try
{
var students = _mapper.Map<List<StudentViewModel>>(await _studentRepository.GetAsync());
_control.FillValues(
students.Select(s => string.Join(" ",
[
s.Id,
s.Name,
s.EducationForm,
s.StartEducation.ToLongDateString(),
s.SessionMarks,
]
))
);
}
catch
{
}
}
}
}

View File

@ -12,7 +12,7 @@ namespace Lab4.Interfaces
/// <summary>
/// Получение контрола для вывода набора данных
/// </summary>
UserControl GetControl { get; }
UserControl GetControl { get; }
/// <summary>
/// Получение элемента, выбранного в контроле

View File

@ -8,14 +8,4 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Lab3\Lab3.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -1,17 +1,9 @@
using Lab3.Extensions;
using Lab3.Forms;
using Lab4.Extensions;
using Lab4.Forms;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Lab4
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
@ -19,28 +11,7 @@ namespace Lab4
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
var app = CreateHostBuilder().Build();
Application.Run(app.Services.GetRequiredService<FormMain>());
}
static IHostBuilder CreateHostBuilder()
{
return Host.CreateDefaultBuilder()
.ConfigureAppConfiguration(c
=> c.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true))
.ConfigureServices((context, services) => {
services.ConfigureDAL(context.Configuration);
services.AddMapping();
services.AddLab3Forms();
services.AddLab4Forms();
services.AddScopes();
});
Application.Run(new Form1());
}
}
}

View File

@ -1,5 +0,0 @@
{
"ConnectionStrings": {
"COPDataBase": "Host=localhost;Username=postgres;Password=postgres;Database=COP"
}
}