Почти работает
This commit is contained in:
parent
a474bd8bbb
commit
e66e721e98
@ -21,7 +21,7 @@ namespace Lab3.Extensions
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddForms(
|
public static IServiceCollection AddLab3Forms(
|
||||||
this IServiceCollection services)
|
this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddScoped<MainForm>();
|
services.AddScoped<MainForm>();
|
||||||
|
@ -9,7 +9,7 @@ namespace Lab3
|
|||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
@ -34,7 +34,7 @@ namespace Lab3
|
|||||||
|
|
||||||
services.AddMapping();
|
services.AddMapping();
|
||||||
|
|
||||||
services.AddForms();
|
services.AddLab3Forms();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs
Normal file
29
Cop.Borovkov.Var3/Lab4/Extensions/DiExtensions.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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>();
|
||||||
|
|
||||||
|
services.AddScoped<PluginsConvention>();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddScopes(
|
||||||
|
this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddScoped<Func<Type, IPluginsConvention>>(sp
|
||||||
|
=> (type) => (sp.GetRequiredService(type) as IPluginsConvention)!);
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,13 +8,13 @@ namespace Lab4.Forms
|
|||||||
private readonly Dictionary<string, IPluginsConvention> _plugins;
|
private readonly Dictionary<string, IPluginsConvention> _plugins;
|
||||||
private string _selectedPlugin;
|
private string _selectedPlugin;
|
||||||
|
|
||||||
private readonly Func<string, IPluginsConvention> _pluginsConventionFunc;
|
private readonly Func<Type, IPluginsConvention> _getPluginObjectFunc;
|
||||||
|
|
||||||
public FormMain(Func<string, IPluginsConvention> pluginsConventionFunc)
|
public FormMain(Func<Type, IPluginsConvention> getPluginObjectFunc)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
_pluginsConventionFunc = pluginsConventionFunc;
|
_getPluginObjectFunc = getPluginObjectFunc;
|
||||||
|
|
||||||
_plugins = LoadPlugins();
|
_plugins = LoadPlugins();
|
||||||
_selectedPlugin = string.Empty;
|
_selectedPlugin = string.Empty;
|
||||||
@ -24,20 +24,30 @@ namespace Lab4.Forms
|
|||||||
{
|
{
|
||||||
Dictionary<string, IPluginsConvention> result = [];
|
Dictionary<string, IPluginsConvention> result = [];
|
||||||
|
|
||||||
List<string> keys = ["Успеваемость"];
|
var plurinType = typeof(IPluginsConvention);
|
||||||
result = keys.Select(k => KeyValuePair.Create(k, _pluginsConventionFunc(k))).ToDictionary();
|
|
||||||
foreach (string key in keys)
|
|
||||||
{
|
|
||||||
var item = new ToolStripMenuItem(key);
|
|
||||||
item.Click += (s, e) => _selectedPlugin = key;
|
|
||||||
|
|
||||||
ControlsStripMenuItem.Container!.Add(item);
|
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();
|
||||||
|
panelControl.Controls.Add(_plugins[key].GetControl);
|
||||||
|
};
|
||||||
|
ControlsStripMenuItem.DropDownItems!.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO При выборе пункта меню получать UserControl и заполнять элемент panelControl этим контролом на всю площадь
|
return result;
|
||||||
// Пример: panelControl.Controls.Clear();
|
|
||||||
// panelControl.Controls.Add(ctrl);
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormMain_KeyDown(object sender, KeyEventArgs e)
|
private void FormMain_KeyDown(object sender, KeyEventArgs e)
|
||||||
@ -136,8 +146,19 @@ namespace Lab4.Forms
|
|||||||
|
|
||||||
private void CreateSimpleDoc()
|
private void CreateSimpleDoc()
|
||||||
{
|
{
|
||||||
// TODO узнать где сохранять
|
using var saveFileDialog = new SaveFileDialog
|
||||||
if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument()))
|
{
|
||||||
|
Filter = "pdf|*.pdf"
|
||||||
|
};
|
||||||
|
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument()
|
||||||
|
{
|
||||||
|
FileName = saveFileDialog.FileName,
|
||||||
|
}))
|
||||||
{
|
{
|
||||||
_ = MessageBox.Show("Документ сохранен",
|
_ = MessageBox.Show("Документ сохранен",
|
||||||
"Создание документа",
|
"Создание документа",
|
||||||
@ -151,9 +172,21 @@ namespace Lab4.Forms
|
|||||||
}
|
}
|
||||||
private void CreateTableDoc()
|
private void CreateTableDoc()
|
||||||
{
|
{
|
||||||
// TODO узнать где сохранять
|
using var saveFileDialog = new SaveFileDialog
|
||||||
|
{
|
||||||
|
Filter = "xlsx|*.xlsx"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_plugins[_selectedPlugin].CreateTableDocument(new
|
if (_plugins[_selectedPlugin].CreateTableDocument(new
|
||||||
PluginsConventionSaveDocument()))
|
PluginsConventionSaveDocument()
|
||||||
|
{
|
||||||
|
FileName = saveFileDialog.FileName,
|
||||||
|
}))
|
||||||
{
|
{
|
||||||
_ = MessageBox.Show("Документ сохранен",
|
_ = MessageBox.Show("Документ сохранен",
|
||||||
"Создание документа",
|
"Создание документа",
|
||||||
@ -167,8 +200,20 @@ namespace Lab4.Forms
|
|||||||
}
|
}
|
||||||
private void CreateChartDoc()
|
private void CreateChartDoc()
|
||||||
{
|
{
|
||||||
// TODO узнать где сохранять
|
using var saveFileDialog = new SaveFileDialog
|
||||||
if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument()))
|
{
|
||||||
|
Filter = "docx|*.docx"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument()
|
||||||
|
{
|
||||||
|
FileName= saveFileDialog.FileName,
|
||||||
|
}))
|
||||||
{
|
{
|
||||||
_ = MessageBox.Show("Документ сохранен",
|
_ = MessageBox.Show("Документ сохранен",
|
||||||
"Создание документа",
|
"Создание документа",
|
||||||
@ -180,7 +225,6 @@ namespace Lab4.Forms
|
|||||||
_ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
_ = MessageBox.Show("Ошибка при создании документа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus();
|
private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus();
|
||||||
|
|
||||||
private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement();
|
private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement();
|
||||||
|
@ -39,7 +39,7 @@ namespace Lab4.Implementations
|
|||||||
_simpleDocumentCreator = new();
|
_simpleDocumentCreator = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string PluginName => throw new NotImplementedException();
|
public string PluginName => "Успеваемость";
|
||||||
|
|
||||||
public UserControl GetControl => _control;
|
public UserControl GetControl => _control;
|
||||||
|
|
||||||
@ -61,16 +61,6 @@ namespace Lab4.Implementations
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var saveFileDialog = new SaveFileDialog
|
|
||||||
{
|
|
||||||
Filter = "docx|*.docx"
|
|
||||||
};
|
|
||||||
|
|
||||||
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var data = _studentRepository.GetAsync().Result
|
var data = _studentRepository.GetAsync().Result
|
||||||
.GroupBy(s => s.EducationForm)
|
.GroupBy(s => s.EducationForm)
|
||||||
.Select(s => new DataLine(
|
.Select(s => new DataLine(
|
||||||
@ -82,7 +72,7 @@ namespace Lab4.Implementations
|
|||||||
|
|
||||||
_chartCreator.AddDiagram(
|
_chartCreator.AddDiagram(
|
||||||
new(
|
new(
|
||||||
saveFileDialog.FileName,
|
saveDocument.FileName,
|
||||||
"Поступления",
|
"Поступления",
|
||||||
"Диаграмма",
|
"Диаграмма",
|
||||||
|
|
||||||
@ -103,16 +93,6 @@ namespace Lab4.Implementations
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var saveFileDialog = new SaveFileDialog
|
|
||||||
{
|
|
||||||
Filter = "pdf|*.pdf"
|
|
||||||
};
|
|
||||||
|
|
||||||
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var values = (_studentRepository.GetAsync()).Result
|
var values = (_studentRepository.GetAsync()).Result
|
||||||
.Select(s => s.StudentSessions
|
.Select(s => s.StudentSessions
|
||||||
.OrderBy(x => x.Number)
|
.OrderBy(x => x.Number)
|
||||||
@ -132,7 +112,7 @@ namespace Lab4.Implementations
|
|||||||
|
|
||||||
_simpleDocumentCreator.SaveToPdf(new()
|
_simpleDocumentCreator.SaveToPdf(new()
|
||||||
{
|
{
|
||||||
FilePath = saveFileDialog.FileName,
|
FilePath = saveDocument.FileName,
|
||||||
Title = "Сессии",
|
Title = "Сессии",
|
||||||
Tables = [tables]
|
Tables = [tables]
|
||||||
});
|
});
|
||||||
@ -149,18 +129,9 @@ namespace Lab4.Implementations
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var saveFileDialog = new SaveFileDialog
|
|
||||||
{
|
|
||||||
Filter = "xlsx|*.xlsx"
|
|
||||||
};
|
|
||||||
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tableCreator.SaveToExcel<StudentDTO>(new()
|
_tableCreator.SaveToExcel<StudentDTO>(new()
|
||||||
{
|
{
|
||||||
FilePath = saveFileDialog.FileName,
|
FilePath = saveDocument.FileName,
|
||||||
Title = "Студенты",
|
Title = "Студенты",
|
||||||
Headers =
|
Headers =
|
||||||
[
|
[
|
||||||
|
@ -12,4 +12,10 @@
|
|||||||
<ProjectReference Include="..\Lab3\Lab3.csproj" />
|
<ProjectReference Include="..\Lab3\Lab3.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -1,11 +1,17 @@
|
|||||||
|
using Lab3.Extensions;
|
||||||
|
using Lab3.Forms;
|
||||||
|
using Lab4.Extensions;
|
||||||
using Lab4.Forms;
|
using Lab4.Forms;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace Lab4
|
namespace Lab4
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
@ -13,7 +19,28 @@ namespace Lab4
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormMain());
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
5
Cop.Borovkov.Var3/Lab4/appsettings.json
Normal file
5
Cop.Borovkov.Var3/Lab4/appsettings.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"COPDataBase": "Host=localhost;Username=postgres;Password=postgres;Database=COP"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user