From a33e89a0dde886a89d5ba8e27eb72dc4c6a488fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Tue, 9 May 2023 12:39:23 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81?= =?UTF-8?q?=20=D0=B1=D1=8D=D0=BA=D0=B0=D0=BF=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.Designer.cs | 24 ++++++++++----- .../BlacksmithWorkshop/FormMain.cs | 14 ++++++++- .../BusinessLogics/BackupLogic.cs | 3 +- .../BackupInfo.cs | 29 +++++++++++++++++++ .../Implements/BackupInfo.cs | 5 ---- 5 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BackupInfo.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index cd4bbac..e3c7874 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -39,11 +39,12 @@ this.reportManufactureComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reportOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.doWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.mailsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); - this.mailsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.backupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -54,7 +55,8 @@ this.refbooksToolStripMenuItem, this.reportsToolStripMenuItem, this.doWorkToolStripMenuItem, - this.mailsToolStripMenuItem}); + this.mailsToolStripMenuItem, + this.backupToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1795, 24); @@ -138,6 +140,13 @@ this.doWorkToolStripMenuItem.Text = "Запуск работ"; this.doWorkToolStripMenuItem.Click += new System.EventHandler(this.DoWorkToolStripMenuItem_Click); // + // mailsToolStripMenuItem + // + this.mailsToolStripMenuItem.Name = "mailsToolStripMenuItem"; + this.mailsToolStripMenuItem.Size = new System.Drawing.Size(62, 20); + this.mailsToolStripMenuItem.Text = "Письма"; + this.mailsToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; @@ -181,12 +190,12 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // - // mailsToolStripMenuItem + // backupToolStripMenuItem // - this.mailsToolStripMenuItem.Name = "mailsToolStripMenuItem"; - this.mailsToolStripMenuItem.Size = new System.Drawing.Size(62, 20); - this.mailsToolStripMenuItem.Text = "Письма"; - this.mailsToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click); + this.backupToolStripMenuItem.Name = "backupToolStripMenuItem"; + this.backupToolStripMenuItem.Size = new System.Drawing.Size(51, 20); + this.backupToolStripMenuItem.Text = "Бэкап"; + this.backupToolStripMenuItem.Click += new System.EventHandler(this.BackupToolStripMenuItem_Click); // // FormMain // @@ -228,5 +237,6 @@ private ToolStripMenuItem implementersToolStripMenuItem; private ToolStripMenuItem doWorkToolStripMenuItem; private ToolStripMenuItem mailsToolStripMenuItem; + private ToolStripMenuItem backupToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 73d3172..418b6ca 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -14,7 +14,8 @@ namespace BlacksmithWorkshopView private readonly IReportLogic _reportLogic; private readonly IImplementerLogic _implementerLogic; private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IImplementerLogic implementerLogic, IMessageInfoLogic messageInfoLogic) + private readonly IBackupLogic _backupLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IImplementerLogic implementerLogic, IMessageInfoLogic messageInfoLogic, IBackupLogic backupLogic) { InitializeComponent(); _logger = logger; @@ -22,6 +23,7 @@ namespace BlacksmithWorkshopView _reportLogic = reportLogic; _workProcess = workProcess; _implementerLogic = implementerLogic; + _backupLogic = backupLogic; } private void FormMain_Load(object sender, EventArgs e) { @@ -191,5 +193,15 @@ namespace BlacksmithWorkshopView form.ShowDialog(); LoadData(); } + + private void BackupToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new FolderBrowserDialog(); + if (dialog.ShowDialog() == DialogResult.OK) + { + _backupLogic.CreateBackup(new() { FolderName = dialog.SelectedPath}); + MessageBox.Show("Бэкап сохранен", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackupLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackupLogic.cs index e807736..342ef23 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackupLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/BackupLogic.cs @@ -48,8 +48,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics var assembly = typeIId.Assembly; if (assembly == null) { - throw new ArgumentNullException("Сборка не найдена", - nameof(assembly)); + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); } var types = assembly.GetTypes(); var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BackupInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BackupInfo.cs new file mode 100644 index 0000000..9a25a11 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BackupInfo.cs @@ -0,0 +1,29 @@ +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopDatabaseImplement.Implements; + +namespace BlacksmithWorkshopDatabaseImplement +{ + public class BackupInfo : IBackupInfo + { + public List? GetList() where T : class, new() + { + using var context = new BlacksmithWorkshopDatabase(); + return context.Set().ToList(); + } + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackupInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && + type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackupInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackupInfo.cs index da2cd71..da9d37e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackupInfo.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/BackupInfo.cs @@ -1,9 +1,4 @@ using BlacksmithWorkshopContracts.StoragesContracts; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BlacksmithWorkshopListImplement.Implements {