сохранение и загрузка контролов
This commit is contained in:
parent
e17b723899
commit
680823a981
@ -40,6 +40,8 @@ namespace DesktopTools.Controls
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private event Action<bool> CloseSelectEvent;
|
private event Action<bool> CloseSelectEvent;
|
||||||
|
|
||||||
|
private readonly object _lockObject = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Объект бизнес-логики для получения данных
|
/// Объект бизнес-логики для получения данных
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -90,7 +92,10 @@ namespace DesktopTools.Controls
|
|||||||
DialogHelper.MessageException(ex.Message, "Ошибка при конфигурации");
|
DialogHelper.MessageException(ex.Message, "Ошибка при конфигурации");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await LoadListAsync();
|
if (!model.LazyLoading)
|
||||||
|
{
|
||||||
|
await LoadListAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IControl GetInstanceControl() => _genericControlViewEntityList?.GetInstanceGenericControl();
|
public IControl GetInstanceControl() => _genericControlViewEntityList?.GetInstanceGenericControl();
|
||||||
@ -110,9 +115,9 @@ namespace DesktopTools.Controls
|
|||||||
new XElement("Value", ((toolStripComboBoxPageNames.SelectedItem as PageNamesForPaginationModel)?.Value ?? "-"))),
|
new XElement("Value", ((toolStripComboBoxPageNames.SelectedItem as PageNamesForPaginationModel)?.Value ?? "-"))),
|
||||||
new XElement("ParentId", ParentId?.ToString() ?? "-"))).ToString();
|
new XElement("ParentId", ParentId?.ToString() ?? "-"))).ToString();
|
||||||
|
|
||||||
public void LoadControlFromXml(string xml)
|
public async void LoadControlFromXml(string xml)
|
||||||
{
|
{
|
||||||
var control = XElement.Parse(xml).Element("Control");
|
var control = XElement.Parse(xml);
|
||||||
ControlId = new Guid(control.Attribute("ControlId").Value.ToString());
|
ControlId = new Guid(control.Attribute("ControlId").Value.ToString());
|
||||||
Title = control.Attribute("Title").Value.ToString();
|
Title = control.Attribute("Title").Value.ToString();
|
||||||
AccessOperation = (AccessOperation)Enum.Parse(typeof(AccessOperation), control.Attribute("AccessOperation").Value.ToString());
|
AccessOperation = (AccessOperation)Enum.Parse(typeof(AccessOperation), control.Attribute("AccessOperation").Value.ToString());
|
||||||
@ -126,12 +131,19 @@ namespace DesktopTools.Controls
|
|||||||
Key = config.Element("PageName").Element("Key").Value.ToString(),
|
Key = config.Element("PageName").Element("Key").Value.ToString(),
|
||||||
Value = config.Element("PageName").Element("Value").Value.ToString()
|
Value = config.Element("PageName").Element("Value").Value.ToString()
|
||||||
};
|
};
|
||||||
toolStripComboBoxPageNames.SelectedItem = pageName;
|
var elem = toolStripComboBoxPageNames.Items.Cast<PageNamesForPaginationModel>().FirstOrDefault(x => x.Key == pageName.Key);
|
||||||
|
if (elem != null)
|
||||||
|
{
|
||||||
|
toolStripComboBoxPageNames.SelectedIndexChanged -= ToolStripComboBoxPageNamesSelectedIndexChanged;
|
||||||
|
toolStripComboBoxPageNames.SelectedItem = elem;
|
||||||
|
toolStripComboBoxPageNames.SelectedIndexChanged += ToolStripComboBoxPageNamesSelectedIndexChanged;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (config.Element("ParentId").Value.ToString() != "-")
|
if (config.Element("ParentId").Value.ToString() != "-")
|
||||||
{
|
{
|
||||||
ParentId = new Guid(config.Element("ParentId").Value.ToString());
|
ParentId = new Guid(config.Element("ParentId").Value.ToString());
|
||||||
}
|
}
|
||||||
|
await LoadListAsync();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -233,7 +245,9 @@ namespace DesktopTools.Controls
|
|||||||
toolStripLabelCountRecords.Visible = toolStripTextBoxCountRecords.Visible = toolStripButtonNext.Visible = false;
|
toolStripLabelCountRecords.Visible = toolStripTextBoxCountRecords.Visible = toolStripButtonNext.Visible = false;
|
||||||
|
|
||||||
toolStripComboBoxPageNames.Items.AddRange(config.PageNamesForPagination.ToArray());
|
toolStripComboBoxPageNames.Items.AddRange(config.PageNamesForPagination.ToArray());
|
||||||
|
toolStripComboBoxPageNames.SelectedIndexChanged -= ToolStripComboBoxPageNamesSelectedIndexChanged;
|
||||||
toolStripComboBoxPageNames.SelectedIndex = 0;
|
toolStripComboBoxPageNames.SelectedIndex = 0;
|
||||||
|
toolStripComboBoxPageNames.SelectedIndexChanged += ToolStripComboBoxPageNamesSelectedIndexChanged;
|
||||||
toolStripComboBoxPageNames.Tag = config.ParentPropertyName;
|
toolStripComboBoxPageNames.Tag = config.ParentPropertyName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -332,9 +346,16 @@ namespace DesktopTools.Controls
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
toolStripComboBoxPageNames.SelectedIndexChanged += async (object sender, EventArgs e) => { await LoadListAsync(); };
|
toolStripComboBoxPageNames.SelectedIndexChanged += ToolStripComboBoxPageNamesSelectedIndexChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Событие смены выбрарнного элемента выпдающего спика (вынесено отдельно, чтобы при настройки конфигурации не вызывать прогрузку)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private async void ToolStripComboBoxPageNamesSelectedIndexChanged(object sender, EventArgs e) => await LoadListAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вызов события загрузки данных на datagrid
|
/// Вызов события загрузки данных на datagrid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -13,6 +13,11 @@ namespace DesktopTools.Models
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ControlOpenMode OpenMode { get; set; }
|
public ControlOpenMode OpenMode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Не загружать данные
|
||||||
|
/// </summary>
|
||||||
|
public bool LazyLoading { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Событипе на закрытие контрола списка, если открыт как список
|
/// Событипе на закрытие контрола списка, если открыт как список
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -128,6 +128,7 @@ namespace DepartmentPortalDesctop
|
|||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "Кафедральный портал";
|
this.Text = "Кафедральный портал";
|
||||||
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
|
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
|
||||||
|
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormMain_FormClosing);
|
||||||
this.panelControls.ResumeLayout(false);
|
this.panelControls.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridViewControls)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridViewControls)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
using DesktopTools.BusinessLogics;
|
using DesktopTools.BusinessLogics;
|
||||||
using DesktopTools.Controls;
|
|
||||||
using DesktopTools.Enums;
|
using DesktopTools.Enums;
|
||||||
using DesktopTools.Interfaces;
|
using DesktopTools.Interfaces;
|
||||||
using DesktopTools.Models;
|
using DesktopTools.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace DepartmentPortalDesctop
|
namespace DepartmentPortalDesctop
|
||||||
{
|
{
|
||||||
@ -16,6 +17,8 @@ namespace DepartmentPortalDesctop
|
|||||||
|
|
||||||
private readonly Dictionary<Guid, IControl> _controls;
|
private readonly Dictionary<Guid, IControl> _controls;
|
||||||
|
|
||||||
|
private readonly string _fileForXmlConfig = "ControlsConfig.xml";
|
||||||
|
|
||||||
public FormMain()
|
public FormMain()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -51,6 +54,33 @@ namespace DepartmentPortalDesctop
|
|||||||
menuMain.Items.Add(menu);
|
menuMain.Items.Add(menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(File.Exists(_fileForXmlConfig))
|
||||||
|
{
|
||||||
|
var xml = XDocument.Load(_fileForXmlConfig).Element("Controls");
|
||||||
|
Guid? id = null;
|
||||||
|
if (xml != null)
|
||||||
|
{
|
||||||
|
foreach(XElement node in xml.Elements("Control"))
|
||||||
|
{
|
||||||
|
var type = node.Attribute("Type").Value.ToString();
|
||||||
|
var control = _baseControls.Values.FirstOrDefault(x => x.GetType().FullName == type);
|
||||||
|
if (control != null)
|
||||||
|
{
|
||||||
|
var ctrl = control.GetInstance();
|
||||||
|
ctrl.Open(new ControlOpenModel { OpenMode = ControlOpenMode.List, LazyLoading = true, CloseList = CloseControl });
|
||||||
|
ctrl.LoadFromXml(node.ToString());
|
||||||
|
_controls.Add(ctrl.ControlId, ctrl);
|
||||||
|
dataGridViewControls.Rows.Insert(0, new object[] { ctrl.ControlId, ctrl.Title });
|
||||||
|
id = ctrl.ControlId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (id.HasValue)
|
||||||
|
{
|
||||||
|
ShowControl(id.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -143,5 +173,19 @@ namespace DepartmentPortalDesctop
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void DataGridViewControls_CellClick(object sender, DataGridViewCellEventArgs e) => ShowControl(new Guid(dataGridViewControls.Rows[e.RowIndex].Cells[0].Value.ToString()));
|
private void DataGridViewControls_CellClick(object sender, DataGridViewCellEventArgs e) => ShowControl(new Guid(dataGridViewControls.Rows[e.RowIndex].Cells[0].Value.ToString()));
|
||||||
|
|
||||||
|
private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
var xml = new XElement("Controls");
|
||||||
|
foreach(var cntrl in _controls)
|
||||||
|
{
|
||||||
|
xml.AddFirst(XElement.Parse(cntrl.Value.SaveToXml()));
|
||||||
|
}
|
||||||
|
if (File.Exists(_fileForXmlConfig))
|
||||||
|
{
|
||||||
|
File.Delete(_fileForXmlConfig);
|
||||||
|
}
|
||||||
|
xml.Save(_fileForXmlConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user