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

176 lines
5.1 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 DesktopTools.Helpers;
using DesktopTools.Interfaces;
using DesktopTools.Models;
using ModuleTools.BusinessLogics;
using ModuleTools.Enums;
using SecurityBusinessLogic.BindingModels;
using SecurityBusinessLogic.BusinessLogics;
using System;
using System.Windows.Forms;
using System.Xml.Linq;
namespace SecurityWindowsDesktop.SpecialControls
{
/// <summary>
/// Контрол для работы с бекапом
/// </summary>
public partial class BackupControl : UserControl, IControl
{
/// <summary>
/// Класс с бизнес-лоникой работы с бекапом
/// </summary>
private readonly BackupBusinessLogic _businessLogic;
/// <summary>
/// Событие, вызываемое при закрытии контрола
/// </summary>
private event Action<Guid> CloseEvent;
/// <summary>
/// Контрол для работы с бекапом
/// </summary>
public BackupControl()
{
InitializeComponent();
_businessLogic = DependencyManager.Instance.Resolve<BackupBusinessLogic>();
Title = "Работа с бекапом";
ControlId = new Guid("cc9844e6-5d92-4c89-b817-4c17ec382bc1");
AccessOperation = AccessOperation.РаботасБекапом;
}
#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 ToolStripHeader_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
CloseEvent?.Invoke(ControlId);
Dispose();
}
/// <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;
}
}
}