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

180 lines
5.2 KiB
C#
Raw Permalink Normal View History

2021-04-02 15:53:15 +04:00
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;
2021-04-02 15:53:15 +04:00
namespace SecurityWindowsDesktop.SpecialControls
{
/// <summary>
/// Контрол для работы с бекапом
/// </summary>
2021-04-02 15:53:15 +04:00
public partial class BackupControl : UserControl, IControl
{
/// <summary>
/// Класс с бизнес-логикой работы с бекапом
/// </summary>
2021-04-02 15:53:15 +04:00
private readonly BackupBusinessLogic _businessLogic;
/// <summary>
/// Событие, вызываемое при закрытии контрола
/// </summary>
private event Action<Guid> CloseEvent;
/// <summary>
/// Контрол для работы с бекапом
/// </summary>
2021-04-02 15:53:15 +04:00
public BackupControl()
{
InitializeComponent();
_businessLogic = DependencyManager.Instance.Resolve<BackupBusinessLogic>();
Title = "Работа с бекапом";
ControlId = new Guid("cc9844e6-5d92-4c89-b817-4c17ec382bc1");
AccessOperation = AccessOperation.РаботасБекапом;
toolStripButtonClose.Click += (object sender, EventArgs e) =>
{
CloseEvent?.Invoke(ControlId);
Dispose();
};
2021-04-02 15:53:15 +04:00
}
#region IControl
2021-04-02 15:53:15 +04:00
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)
2021-04-02 15:53:15 +04:00
{
var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
textBoxSaveFolderName.Text = fbd.SelectedPath;
2021-04-02 15:53:15 +04:00
}
}
/// <summary>
/// Создание бекапа
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2021-04-02 15:53:15 +04:00
private void ButtonCreateBackup_Click(object sender, EventArgs e)
{
var cursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
2021-04-02 15:53:15 +04:00
if (_businessLogic.CreateBackUp(new BackupBindingModel
{
FolderName = textBoxSaveFolderName.Text,
2021-04-02 15:53:15 +04:00
FullData = checkBoxFullLoad.Checked,
CreateArchive = checkBoxCreateArchive.Checked
}))
{
DialogHelper.MessageInformation("Сохранение прошло успешно", "Результат");
}
else
{
DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при сохранении");
}
Cursor.Current = cursor;
2021-04-02 15:53:15 +04:00
}
/// <summary>
/// Выбор пути для папки восстановления бекапа
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonLoadSelectFolder_Click(object sender, EventArgs e)
2021-04-02 15:53:15 +04:00
{
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;
2021-04-02 15:53:15 +04:00
}
private void textBoxSaveFolderName_TextChanged(object sender, EventArgs e)
{
}
private void labelSaveFolderName_Click(object sender, EventArgs e)
{
}
}
2021-04-02 15:53:15 +04:00
}