using DepartmentBusinessLogic.BindingModels;
using DepartmentBusinessLogic.BusinessLogics;
using DepartmentBusinessLogic.ViewModels;
using DesktopTools.Controls;
using DesktopTools.Enums;
using DesktopTools.Helpers;
using DesktopTools.Interfaces;
using DesktopTools.Models;
using ToolsModule.Enums;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace DepartmentWindowsDesktop.EntityControls
{
///
/// Реализация контрола для списка учебных планов
///
public partial class ControlAcademicPlanList :
GenericControlEntityList,
IGenericControlEntityList
{
public ControlAcademicPlanList()
{
InitializeComponent();
Title = "Учебные планы";
ControlId = new Guid("144d098c-ff55-4786-ae63-3105a92990cd");
AccessOperation = AccessOperation.УчебныеПланы;
ControlViewEntityElement = new ControlAcademicPlanElement();
_genericControlViewEntityList = this;
}
public IControl GetInstanceGenericControl() => new ControlAcademicPlanList() { ControlId = Guid.NewGuid() };
public ControlViewEntityListConfiguration GetConfigControl() => new()
{
PaginationOn = false,
HideToolStripButton = new List
{
ToolStripButtonListNames.toolStripButtonSearch
},
ControlOnMoveElem = new Dictionary
{
{ "ToolStripMenuItemLoadPlx", ("Загрузить план", (object sender, EventArgs e) => { LoadPlx(); }) }
}
};
///
/// Загрузка учебного плана
///
private void LoadPlx()
{
var ids = GetSelectedIds();
if (ids.Count != 1)
{
DialogHelper.MessageException("Должна быть выбрана одна запись", $"Ошибка");
return;
}
var dialog = new OpenFileDialog
{
Filter = "plx|*.plx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
var result = _businessLogic.LoadPlx(new AcademicPlanLoadPlxModel
{
AcademicPlanId = ids[0],
FileName = dialog.FileName
});
if (result)
{
DialogHelper.MessageInformation("Загрузка прошла успешно", "Результат");
}
else
{
DialogHelper.MessageException(_businessLogic.Errors, $"Ошибки при загрузке плана");
}
}
}
}
}