170 lines
4.9 KiB
C#
170 lines
4.9 KiB
C#
using SecurityContract.BindingModels;
|
||
using SecurityContract.Logics;
|
||
using System;
|
||
using System.Windows.Forms;
|
||
using System.Xml.Linq;
|
||
using ToolsDesktop.Helpers;
|
||
using ToolsDesktop.Interfaces;
|
||
using ToolsDesktop.Models;
|
||
using ToolsModule.BusinessLogics;
|
||
using ToolsModule.Enums;
|
||
|
||
namespace SecurityWindowsDesktop.SpecialControls
|
||
{
|
||
/// <summary>
|
||
/// Контрол для работы с бекапом
|
||
/// </summary>
|
||
public partial class BackupControl : UserControl, IControl
|
||
{
|
||
/// <summary>
|
||
/// Класс с бизнес-логикой работы с бекапом
|
||
/// </summary>
|
||
private readonly IBackupLogic _businessLogic;
|
||
|
||
/// <summary>
|
||
/// Событие, вызываемое при закрытии контрола
|
||
/// </summary>
|
||
private event Action<Guid> CloseEvent;
|
||
|
||
/// <summary>
|
||
/// Контрол для работы с бекапом
|
||
/// </summary>
|
||
public BackupControl()
|
||
{
|
||
InitializeComponent();
|
||
_businessLogic = DependencyManager.Instance.Resolve<IBackupLogic>();
|
||
Title = "Работа с бекапом";
|
||
ControlId = new Guid("cc9844e6-5d92-4c89-b817-4c17ec382bc1");
|
||
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 BackupControl() { 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 ButtonSaveSelectFolder_Click(object sender, EventArgs e)
|
||
{
|
||
var fbd = new FolderBrowserDialog();
|
||
if (fbd.ShowDialog() == DialogResult.OK)
|
||
{
|
||
textBoxSaveFolderName.Text = fbd.SelectedPath;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Создание бекапа
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonCreateBackup_Click(object sender, EventArgs e)
|
||
{
|
||
var cursor = Cursor.Current;
|
||
Cursor.Current = Cursors.WaitCursor;
|
||
if (_businessLogic.CreateBackUp(new BackupBindingModel
|
||
{
|
||
FolderName = textBoxSaveFolderName.Text,
|
||
FullData = checkBoxFullLoad.Checked,
|
||
CreateArchive = checkBoxCreateArchive.Checked
|
||
}))
|
||
{
|
||
DialogHelper.MessageInformation("Сохранение прошло успешно", "Результат");
|
||
}
|
||
else
|
||
{
|
||
DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при сохранении");
|
||
}
|
||
Cursor.Current = cursor;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Выбор пути для папки восстановления бекапа
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonLoadSelectFolder_Click(object sender, EventArgs e)
|
||
{
|
||
var fbd = new FolderBrowserDialog();
|
||
if (fbd.ShowDialog() == DialogResult.OK)
|
||
{
|
||
textBoxLoadFolderName.Text = fbd.SelectedPath;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Выбор пути для файла-архива с бекапом
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonLoadArchiveSelect_Click(object sender, EventArgs e)
|
||
{
|
||
var ofd = new OpenFileDialog();
|
||
if (ofd.ShowDialog() == DialogResult.OK)
|
||
{
|
||
textBoxLoadArchiveName.Text = ofd.FileName;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Восстановление
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonRestoreBackup_Click(object sender, EventArgs e)
|
||
{
|
||
var cursor = Cursor.Current;
|
||
Cursor.Current = Cursors.WaitCursor;
|
||
if (_businessLogic.RestoreBackUp(new BackupBindingModel
|
||
{
|
||
FolderName = textBoxLoadFolderName.Text,
|
||
ArchiveFileName = textBoxLoadArchiveName.Text
|
||
}))
|
||
{
|
||
DialogHelper.MessageInformation("Сохранение прошло успешно", "Результат");
|
||
}
|
||
else
|
||
{
|
||
DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при сохранении");
|
||
}
|
||
Cursor.Current = cursor;
|
||
}
|
||
}
|
||
} |