178 lines
7.0 KiB
C#
178 lines
7.0 KiB
C#
|
using COP.Info;
|
|||
|
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
|
|||
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|||
|
using Microsoft.Extensions.Logging;
|
|||
|
using System.Windows.Forms;
|
|||
|
using UniversityBusinessLogic.BusinessLogics;
|
|||
|
using UniversityContracts.BindingModels;
|
|||
|
using UniversityContracts.BusinessLogicsContracts;
|
|||
|
using WinFormsControlLibrary;
|
|||
|
using static COP.ExcelComponent;
|
|||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
|||
|
|
|||
|
namespace UniversityView
|
|||
|
{
|
|||
|
public partial class FormMain : Form
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IStudentLogic _studentLogic;
|
|||
|
private readonly IDirectionLogic _directionLogic;
|
|||
|
public FormMain(ILogger<FormMain> logger, IStudentLogic studentLogic, IDirectionLogic directionLogic)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_logger = logger;
|
|||
|
_studentLogic = studentLogic;
|
|||
|
_directionLogic = directionLogic;
|
|||
|
Configure();
|
|||
|
; }
|
|||
|
|
|||
|
private void LoadData()
|
|||
|
{
|
|||
|
_logger.LogInformation("Загрузка студентов");
|
|||
|
try
|
|||
|
{
|
|||
|
tableOfValues.ClearRows();
|
|||
|
var list = _studentLogic.ReadList(null);
|
|||
|
if (list != null)
|
|||
|
{
|
|||
|
tableOfValues.SetCellValueFromList(list);
|
|||
|
}
|
|||
|
_logger.LogInformation("Загрузка студентов");
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка загрузки студентов");
|
|||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void FormMain_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
|
|||
|
private void СоздатьToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var service = Program.ServiceProvider?.GetService(typeof(FormStudent));
|
|||
|
if (service is FormStudent form)
|
|||
|
{
|
|||
|
form.ShowDialog();
|
|||
|
}
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
|
|||
|
private void Configure()
|
|||
|
{
|
|||
|
var columnConfigs = new List<GridColumnConfig>
|
|||
|
{
|
|||
|
new GridColumnConfig { HeaderText = "ФИО", Width = 100, Visible = true, PropertyName = "FIO" },
|
|||
|
new GridColumnConfig { HeaderText = "Направление", Width = 80, Visible = true, PropertyName = "DirectionName" },
|
|||
|
new GridColumnConfig { HeaderText = "Электронная почта", Width = 80, Visible = true, PropertyName = "Email" },
|
|||
|
};
|
|||
|
|
|||
|
tableOfValues.ConfigureColumns(columnConfigs);
|
|||
|
}
|
|||
|
|
|||
|
private void ИзменитьToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private void УдалитьToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
DialogResult dialogResult = MessageBox.Show("Удалить выбранный элемент?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|||
|
if (dialogResult == DialogResult.Yes)
|
|||
|
_studentLogic.Delete(new StudentBindingModel { Id = tableOfValues.SelectedRowIndex });
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
|
|||
|
private void СоздатьПростойДокументToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var list = _studentLogic.ReadList(null);
|
|||
|
List<ImageInfo> images = new();
|
|||
|
using var dialog = new SaveFileDialog
|
|||
|
{
|
|||
|
Filter = "xlsx|*.xlsx"
|
|||
|
};
|
|||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (list != null)
|
|||
|
{
|
|||
|
foreach (var item in list)
|
|||
|
{
|
|||
|
images.Add(new ImageInfo() { FilePath = item.PhotoFilePath });
|
|||
|
}
|
|||
|
}
|
|||
|
ExcelImageInfo info = new(dialog.FileName, "Документ с фотографиями студентов", images);
|
|||
|
excelComponent.GenerateExcelWithImages(info);
|
|||
|
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "Ошибка",
|
|||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void СоздатьДокументСТаблицейToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void СоздатьДокументСДиаграммойToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var listStudents = _studentLogic.ReadList(null);
|
|||
|
var listDirections = _directionLogic.ReadList(null);
|
|||
|
List<(string, int)> data = new();
|
|||
|
List<HistogramData> gistData = new();
|
|||
|
using var dialog = new SaveFileDialog
|
|||
|
{
|
|||
|
Filter = "pdf|*.pdf"
|
|||
|
};
|
|||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
for (int i = 0; i < listDirections.Count; i++)
|
|||
|
{
|
|||
|
int count = 0;
|
|||
|
for (int j = 0; j < listStudents.Count; j++)
|
|||
|
{
|
|||
|
if (listStudents[j].DirectionName == listDirections[i].Name) count++;
|
|||
|
}
|
|||
|
data.Add((listDirections[i].Name, count));
|
|||
|
}
|
|||
|
if (data != null) {
|
|||
|
foreach (var item in data)
|
|||
|
{
|
|||
|
gistData.Add(new HistogramData
|
|||
|
{
|
|||
|
SeriesName = item.Item1,
|
|||
|
Data = new double[] { item.Item2 }
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
gistogramPdfComponent.GenerateHistogramDocument(dialog.FileName, "Histogram", "Students-Directions", LegendPosition.TopRight, gistData);
|
|||
|
MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "Ошибка",
|
|||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void СправочникиToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var service = Program.ServiceProvider?.GetService(typeof(FormHandbooks));
|
|||
|
if (service is FormHandbooks form)
|
|||
|
{
|
|||
|
form.ShowDialog();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|