2021-03-28 19:30:56 +04:00
|
|
|
|
using DesktopTools.BusinessLogics;
|
|
|
|
|
using DesktopTools.Controls;
|
2021-04-01 21:30:29 +04:00
|
|
|
|
using DesktopTools.Enums;
|
|
|
|
|
using DesktopTools.Interfaces;
|
|
|
|
|
using DesktopTools.Models;
|
2021-03-27 23:50:29 +04:00
|
|
|
|
using System;
|
2021-03-26 20:09:52 +04:00
|
|
|
|
using System.Collections.Generic;
|
2021-03-27 23:50:29 +04:00
|
|
|
|
using System.Linq;
|
2021-03-26 20:09:52 +04:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace DepartmentPortalDesctop
|
|
|
|
|
{
|
|
|
|
|
public partial class FormMain : Form
|
|
|
|
|
{
|
2021-04-01 21:30:29 +04:00
|
|
|
|
private readonly Dictionary<Guid, IControl> _baseControls;
|
2021-03-27 23:50:29 +04:00
|
|
|
|
|
2021-04-01 21:30:29 +04:00
|
|
|
|
private readonly Dictionary<Guid, IControl> _controls;
|
2021-03-27 23:50:29 +04:00
|
|
|
|
|
2021-03-26 20:09:52 +04:00
|
|
|
|
public FormMain()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2021-04-01 21:30:29 +04:00
|
|
|
|
_baseControls = new Dictionary<Guid, IControl>();
|
|
|
|
|
_controls = new Dictionary<Guid, IControl>();
|
2021-03-27 23:50:29 +04:00
|
|
|
|
|
2021-03-28 19:30:56 +04:00
|
|
|
|
var extensions = DesktopLoader.GetWindowDesktopExtensions();
|
2021-03-27 23:50:29 +04:00
|
|
|
|
foreach (var extens in extensions)
|
|
|
|
|
{
|
2021-04-01 21:30:29 +04:00
|
|
|
|
var list = extens?.GetListControlEntityList()?.ToList();
|
2021-03-27 23:50:29 +04:00
|
|
|
|
if (list != null && list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var menu = new ToolStripMenuItem { Text = list[0].Title };
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
2021-04-01 21:30:29 +04:00
|
|
|
|
if (list[i].Control is IControl control)
|
2021-03-27 23:50:29 +04:00
|
|
|
|
{
|
|
|
|
|
if (_baseControls.ContainsKey(list[i].Id))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_baseControls.Add(list[i].Id, control);
|
|
|
|
|
var submenu = new ToolStripMenuItem { Text = list[i].Title, Tag = list[i].Id };
|
|
|
|
|
submenu.Click += (object sender, EventArgs e) =>
|
|
|
|
|
{
|
|
|
|
|
OpenControl(new Guid((sender as ToolStripMenuItem).Tag.ToString()));
|
|
|
|
|
};
|
|
|
|
|
menu.DropDownItems.Add(submenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menuMain.Items.Add(menu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление нового контрола
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
private void OpenControl(Guid id)
|
|
|
|
|
{
|
|
|
|
|
if (!_baseControls.ContainsKey(id))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (_baseControls[id] == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 21:30:29 +04:00
|
|
|
|
var ctrl = _baseControls[id].GetInstance();
|
2021-03-29 23:16:11 +04:00
|
|
|
|
if (!_controls.ContainsKey(ctrl.ControlId))
|
2021-03-27 23:50:29 +04:00
|
|
|
|
{
|
2021-04-01 21:30:29 +04:00
|
|
|
|
ctrl.Open(new ControlOpenModel { OpenMode = ControlOpenMode.List, CloseList = CloseControl });
|
2021-03-29 23:16:11 +04:00
|
|
|
|
_controls.Add(ctrl.ControlId, ctrl);
|
2021-03-27 23:50:29 +04:00
|
|
|
|
|
|
|
|
|
splitContainerMain.Panel1.Controls.Clear();
|
2021-04-01 21:30:29 +04:00
|
|
|
|
splitContainerMain.Panel1.Controls.Add(ctrl as UserControl);
|
2021-03-29 23:16:11 +04:00
|
|
|
|
dataGridViewControls.Rows.Add(new object[] { ctrl.ControlId, ctrl.Title });
|
2021-03-28 20:46:27 +04:00
|
|
|
|
dataGridViewControls.Rows[^1].Selected = true;
|
2021-03-27 23:50:29 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Закрытие контрола
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
private void CloseControl(Guid id)
|
|
|
|
|
{
|
|
|
|
|
if (!_controls.ContainsKey(id))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var ctrl = _controls[id];
|
|
|
|
|
if (ctrl == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < dataGridViewControls.Rows.Count; ++i)
|
|
|
|
|
{
|
2021-03-29 23:16:11 +04:00
|
|
|
|
if (dataGridViewControls.Rows[i].Cells[0].Value.ToString() == ctrl.ControlId.ToString())
|
2021-03-27 23:50:29 +04:00
|
|
|
|
{
|
|
|
|
|
dataGridViewControls.Rows.RemoveAt(i);
|
|
|
|
|
if (i < dataGridViewControls.Rows.Count - 1)
|
|
|
|
|
{
|
|
|
|
|
dataGridViewControls.Rows[i].Selected = true;
|
|
|
|
|
ShowControl(new Guid(dataGridViewControls.Rows[i].Cells[0].Value.ToString()));
|
|
|
|
|
}
|
|
|
|
|
else if (i > 0)
|
|
|
|
|
{
|
|
|
|
|
dataGridViewControls.Rows[i - 1].Selected = true;
|
|
|
|
|
ShowControl(new Guid(dataGridViewControls.Rows[i - 1].Cells[0].Value.ToString()));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-29 23:16:11 +04:00
|
|
|
|
_controls.Remove(ctrl.ControlId);
|
2021-03-27 23:50:29 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Отображение контрола
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
private void ShowControl(Guid id)
|
|
|
|
|
{
|
|
|
|
|
if (!_controls.ContainsKey(id))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var ctrl = _controls[id];
|
|
|
|
|
if (ctrl == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
splitContainerMain.Panel1.Controls.Clear();
|
2021-04-01 21:30:29 +04:00
|
|
|
|
splitContainerMain.Panel1.Controls.Add(ctrl as UserControl);
|
2021-03-26 20:09:52 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonShowHideControlList_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ButtonShowHideControlList.Text = panelControls.Visible ? ">" : "<";
|
|
|
|
|
panelControls.Visible = !panelControls.Visible;
|
|
|
|
|
}
|
2021-03-27 23:50:29 +04:00
|
|
|
|
|
|
|
|
|
private void DataGridViewControls_CellClick(object sender, DataGridViewCellEventArgs e) => ShowControl(new Guid(dataGridViewControls.Rows[e.RowIndex].Cells[0].Value.ToString()));
|
2021-03-26 20:09:52 +04:00
|
|
|
|
}
|
|
|
|
|
}
|