DepartmentProject/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/SynchronizationControl.cs

98 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SecurityContract.Logics;
using System;
using System.Windows.Forms;
using System.Xml.Linq;
using ToolsDesktop.Helpers;
using ToolsDesktop.Interfaces;
using ToolsDesktop.Models;
using ToolsModule.ManagmentDependency;
using ToolsModule.ManagmentSecurity;
namespace SecurityWindowsDesktop.SpecialControls
{
/// <summary>
/// Контрол для работы с синхронизацией
/// </summary>
public partial class SynchronizationControl : UserControl, IControl
{
/// <summary>
/// Класс с бизнес-логикой работы с синхронизацией
/// </summary>
private readonly ISynchronizationLogic _businessLogic;
/// <summary>
/// Событие, вызываемое при закрытии контрола
/// </summary>
private event Action<Guid> CloseEvent;
/// <summary>
/// Контрол для работы с синхронизацией
/// </summary>
public SynchronizationControl()
{
InitializeComponent();
_businessLogic = DependencyManager.Instance.Resolve<ISynchronizationLogic>();
Title = "Синхронизация";
ControlId = new Guid("c392818b-9036-4c4b-8a57-8ff935115e6a");
AccessOperation = AccessOperation.Синхронизация;
toolStripButtonClose.Click += (object sender, EventArgs e) =>
{
CloseEvent?.Invoke(ControlId);
Dispose();
};
}
#region IControl
public Guid ControlId { get; private set; }
public string Title { get; private set; }
public AccessOperation AccessOperation { get; private set; }
public IControl GetInstance() => new SynchronizationControl() { ControlId = Guid.NewGuid() };
public void Open(ControlOpenModel model)
{
if (model.CloseList != null)
{
CloseEvent += model.CloseList;
}
Dock = DockStyle.Fill;
}
public string SaveToXml() => new XElement("Control",
new XAttribute("Type", GetType().FullName),
new XAttribute("ControlId", ControlId),
new XAttribute("Title", Title),
new XAttribute("AccessOperation", AccessOperation)).ToString();
public void LoadFromXml(string xml)
{
var control = XElement.Parse(xml);
ControlId = new Guid(control.Attribute("ControlId").Value.ToString());
Title = control.Attribute("Title").Value.ToString();
AccessOperation = (AccessOperation)Enum.Parse(typeof(AccessOperation), control.Attribute("AccessOperation").Value.ToString());
}
#endregion
/// <summary>
/// Запуск синхронизации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRunSynchronization_Click(object sender, EventArgs e)
{
var cursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
if (_businessLogic.RunSynchronization())
{
DialogHelper.MessageInformation("Синхронизация прошла успешно", "Результат");
}
else
{
DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при синхронизации");
}
Cursor.Current = cursor;
}
}
}