BacupFunctionality

This commit is contained in:
2021-03-17 08:33:02 +01:00
parent 0d8f884544
commit 154f8cc07a
21 changed files with 674 additions and 9 deletions

View File

@ -1,4 +1,6 @@
using Autofac;
using SqliteBackups;
using SqliteBackups.Interfaces;
using StockBL;
using StockBL.Interface;
using StockDal;
@ -32,6 +34,8 @@ namespace StockInfo
Container.Resolve<IPersonRepository>(),
Container.Resolve<IAddressRepository>(),
Container.Resolve<IStockPersonConnect>(),
Container.Resolve<IBackupRepository>(),
Container.Resolve<IBackupRoutines>(),
Container.Resolve<IPersonStockFacade>()
));
}
@ -44,6 +48,8 @@ namespace StockInfo
builder.RegisterType<PersonRepository>().As<IPersonRepository>();
builder.RegisterType<AddressRepository>().As<IAddressRepository>();
builder.RegisterType<StockPersonConnect>().As<IStockPersonConnect>();
builder.RegisterType<BackupRepository>().As<IBackupRepository>();
builder.RegisterType<BackupRoutines>().As<IBackupRoutines>();
builder.RegisterType<PersonStockFacade>().As<IPersonStockFacade>();
builder.RegisterType<frmInitial>();
return builder.Build();

View File

@ -26,6 +26,7 @@
<ItemGroup>
<ProjectReference Include="..\DataDomain\DataDomain.csproj" />
<ProjectReference Include="..\Helpers\Helpers.csproj" />
<ProjectReference Include="..\SqliteBackups\SqliteBackups.csproj" />
<ProjectReference Include="..\StockBL.Interface\StockBL.Interface.csproj" />
<ProjectReference Include="..\StockBL\StockBL.csproj" />
<ProjectReference Include="..\StockDal.Interface\StockDAL.Interface.csproj" />
@ -52,7 +53,14 @@
<ItemGroup>
<None Update="Stocks.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="bin\Debug\net5.0-windows\Stocks.db">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
</ItemGroup>

Binary file not shown.

Binary file not shown.

127
StockInfo/frmBackup.Designer.cs generated Normal file
View File

@ -0,0 +1,127 @@

namespace StockInfo
{
partial class frmBackup
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.sfdChoosePlaceAndFile = new System.Windows.Forms.SaveFileDialog();
this.btnChooseBackupDest = new System.Windows.Forms.Button();
this.txtBackupPath = new System.Windows.Forms.TextBox();
this.txtBackupFile = new System.Windows.Forms.TextBox();
this.lstBackups = new System.Windows.Forms.ListBox();
this.btnClose = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(226, 15);
this.label1.TabIndex = 0;
this.label1.Text = "Backup Local database to where you wish";
//
// sfdChoosePlaceAndFile
//
this.sfdChoosePlaceAndFile.Title = "Choose path and filename";
//
// btnChooseBackupDest
//
this.btnChooseBackupDest.Location = new System.Drawing.Point(13, 31);
this.btnChooseBackupDest.Name = "btnChooseBackupDest";
this.btnChooseBackupDest.Size = new System.Drawing.Size(152, 23);
this.btnChooseBackupDest.TabIndex = 1;
this.btnChooseBackupDest.Text = "Choose BU destination";
this.btnChooseBackupDest.UseVisualStyleBackColor = true;
this.btnChooseBackupDest.Click += new System.EventHandler(this.btnChooseBackupDest_Click);
//
// txtBackupPath
//
this.txtBackupPath.Location = new System.Drawing.Point(171, 32);
this.txtBackupPath.Name = "txtBackupPath";
this.txtBackupPath.ReadOnly = true;
this.txtBackupPath.Size = new System.Drawing.Size(148, 23);
this.txtBackupPath.TabIndex = 2;
//
// txtBackupFile
//
this.txtBackupFile.Location = new System.Drawing.Point(325, 31);
this.txtBackupFile.Name = "txtBackupFile";
this.txtBackupFile.ReadOnly = true;
this.txtBackupFile.Size = new System.Drawing.Size(100, 23);
this.txtBackupFile.TabIndex = 3;
//
// lstBackups
//
this.lstBackups.FormattingEnabled = true;
this.lstBackups.ItemHeight = 15;
this.lstBackups.Location = new System.Drawing.Point(13, 70);
this.lstBackups.Name = "lstBackups";
this.lstBackups.Size = new System.Drawing.Size(214, 184);
this.lstBackups.TabIndex = 4;
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(350, 259);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 5;
this.btnClose.Text = "Close";
this.btnClose.UseVisualStyleBackColor = true;
//
// frmBackup
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(438, 294);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.lstBackups);
this.Controls.Add(this.txtBackupFile);
this.Controls.Add(this.txtBackupPath);
this.Controls.Add(this.btnChooseBackupDest);
this.Controls.Add(this.label1);
this.Name = "frmBackup";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "frmBackup";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.SaveFileDialog sfdChoosePlaceAndFile;
private System.Windows.Forms.Button btnChooseBackupDest;
private System.Windows.Forms.TextBox txtBackupPath;
private System.Windows.Forms.TextBox txtBackupFile;
private System.Windows.Forms.ListBox lstBackups;
private System.Windows.Forms.Button btnClose;
}
}

54
StockInfo/frmBackup.cs Normal file
View File

@ -0,0 +1,54 @@
using DataDomain;
using Helpers;
using SqliteBackups.Interfaces;
using StockDAL.Interface;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace StockInfo
{
public partial class frmBackup : Form
{
private readonly IBackupRepository _backupRepository;
private readonly IBackupRoutines _backupRoutines;
public frmBackup(IBackupRepository backupRepository,IBackupRoutines backupRoutines)
{
InitializeComponent();
_backupRepository = backupRepository;
_backupRoutines = backupRoutines;
}
private void btnChooseBackupDest_Click(object sender, EventArgs e)
{
sfdChoosePlaceAndFile.Filter = "Database files (*.db)|*.db|All files (*.*)|*.*";
if (sfdChoosePlaceAndFile.ShowDialog() == DialogResult.OK)
{
var wholeFile = sfdChoosePlaceAndFile.FileName;
var lastBackslash = wholeFile.LastIndexOf('\\') + 1;
var dir = wholeFile.Substring(0, lastBackslash);
var file = wholeFile.Substring(lastBackslash, wholeFile.Length - lastBackslash);
//Debug.WriteLine($"Chosen file:{wholeFile}");
//Debug.WriteLine($"Path: {dir} , File {file}");
BackupRegister reg = new();
reg.BackupDbName = file;
reg.BackupPath = dir;
reg = _backupRepository.SaveBackupReging(reg);
_backupRoutines.BackupSqliteDb(reg.DbName, Path.Combine(dir, file));
var cmbItem = new ComboboxItem(wholeFile, reg.Id);
lstBackups.Items.Add(cmbItem);
};
}
}
}

60
StockInfo/frmBackup.resx Normal file
View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -32,6 +32,8 @@ namespace StockInfo
this.dataGridView = new System.Windows.Forms.DataGridView();
this.lblTotalRecords = new System.Windows.Forms.Label();
this.gB1 = new System.Windows.Forms.GroupBox();
this.btnRestoreAll = new System.Windows.Forms.Button();
this.btnBackupAll = new System.Windows.Forms.Button();
this.chkEnableBackRes = new System.Windows.Forms.CheckBox();
this.btnRestoreShares = new System.Windows.Forms.Button();
this.btnBackupShares = new System.Windows.Forms.Button();
@ -65,7 +67,7 @@ namespace StockInfo
this.dataGridView.Location = new System.Drawing.Point(12, 16);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(829, 360);
this.dataGridView.Size = new System.Drawing.Size(871, 360);
this.dataGridView.TabIndex = 0;
//
// lblTotalRecords
@ -81,17 +83,38 @@ namespace StockInfo
// gB1
//
this.gB1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.gB1.Controls.Add(this.btnRestoreAll);
this.gB1.Controls.Add(this.btnBackupAll);
this.gB1.Controls.Add(this.chkEnableBackRes);
this.gB1.Controls.Add(this.btnRestoreShares);
this.gB1.Controls.Add(this.btnBackupShares);
this.gB1.Controls.Add(this.btnReload);
this.gB1.Location = new System.Drawing.Point(157, 385);
this.gB1.Name = "gB1";
this.gB1.Size = new System.Drawing.Size(203, 144);
this.gB1.Size = new System.Drawing.Size(245, 144);
this.gB1.TabIndex = 3;
this.gB1.TabStop = false;
this.gB1.Text = "Sharelist";
//
// btnRestoreAll
//
this.btnRestoreAll.Location = new System.Drawing.Point(130, 111);
this.btnRestoreAll.Name = "btnRestoreAll";
this.btnRestoreAll.Size = new System.Drawing.Size(105, 23);
this.btnRestoreAll.TabIndex = 7;
this.btnRestoreAll.Text = "Restore All";
this.btnRestoreAll.UseVisualStyleBackColor = true;
//
// btnBackupAll
//
this.btnBackupAll.Location = new System.Drawing.Point(130, 82);
this.btnBackupAll.Name = "btnBackupAll";
this.btnBackupAll.Size = new System.Drawing.Size(105, 23);
this.btnBackupAll.TabIndex = 6;
this.btnBackupAll.Text = "Backup All";
this.btnBackupAll.UseVisualStyleBackColor = true;
this.btnBackupAll.Click += new System.EventHandler(this.btnBackupAll_Click);
//
// chkEnableBackRes
//
this.chkEnableBackRes.AutoSize = true;
@ -174,7 +197,7 @@ namespace StockInfo
this.gbStockMgmnt.Controls.Add(this.btnStockSale);
this.gbStockMgmnt.Controls.Add(this.btnValueView);
this.gbStockMgmnt.Controls.Add(this.btnStockReg);
this.gbStockMgmnt.Location = new System.Drawing.Point(366, 385);
this.gbStockMgmnt.Location = new System.Drawing.Point(408, 385);
this.gbStockMgmnt.Name = "gbStockMgmnt";
this.gbStockMgmnt.Size = new System.Drawing.Size(216, 144);
this.gbStockMgmnt.TabIndex = 8;
@ -232,7 +255,7 @@ namespace StockInfo
this.gpOwners.Controls.Add(this.btnConnShares);
this.gpOwners.Controls.Add(this.btnEditPerson);
this.gpOwners.Controls.Add(this.cmbOwners);
this.gpOwners.Location = new System.Drawing.Point(589, 385);
this.gpOwners.Location = new System.Drawing.Point(630, 385);
this.gpOwners.Name = "gpOwners";
this.gpOwners.Size = new System.Drawing.Size(252, 141);
this.gpOwners.TabIndex = 10;
@ -274,7 +297,7 @@ namespace StockInfo
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(853, 538);
this.ClientSize = new System.Drawing.Size(895, 538);
this.Controls.Add(this.gpOwners);
this.Controls.Add(this.lblStockRows);
this.Controls.Add(this.gbStockMgmnt);
@ -324,6 +347,8 @@ namespace StockInfo
private System.Windows.Forms.Button btnConnShares;
private System.Windows.Forms.Button btnEditPerson;
private System.Windows.Forms.ComboBox cmbOwners;
private System.Windows.Forms.Button btnRestoreAll;
private System.Windows.Forms.Button btnBackupAll;
}
}

View File

@ -14,6 +14,7 @@ using System.Text.Json;
using System.IO;
using Helpers;
using StockBL.Interface;
using SqliteBackups.Interfaces;
namespace StockInfo
{
@ -24,12 +25,15 @@ namespace StockInfo
private readonly IPersonRepository _personRepository;
private readonly IAddressRepository _addressRepository;
private readonly IStockPersonConnect _stockPersonConnect;
private readonly IBackupRepository _backupRepository;
private readonly IBackupRoutines _backupRoutines;
private readonly IPersonStockFacade _personStockFacade;
private frmRegisterStock regWindow;
private frmMyStocks stockWindow;
private frmSelling sellWindow;
private frmPerson personWindow;
private frmPersonShareConnect personShareConnect;
private frmBackup backupWindow;
public int SelectedPersonId { get; set; } = 0;
public frmInitial(
@ -38,7 +42,9 @@ namespace StockInfo
IPersonRepository personRepository,
IAddressRepository addressRepository,
IStockPersonConnect stockPersonConnect,
IPersonStockFacade personStockFacade)
IBackupRepository backupRepository,
IBackupRoutines backupRoutines,
IPersonStockFacade personStockFacade)
{
InitializeComponent();
_stockRepository = stockMemberRepository;
@ -46,6 +52,8 @@ namespace StockInfo
_personRepository = personRepository;
_addressRepository = addressRepository;
_stockPersonConnect = stockPersonConnect;
_backupRepository = backupRepository;
_backupRoutines = backupRoutines;
_personStockFacade = personStockFacade;
}
@ -55,6 +63,8 @@ namespace StockInfo
btnRestoreShares.Enabled = false;
btnBackupShares.Enabled = false;
btnReloadShares.Enabled = false;
btnRestoreAll.Enabled = false;
btnBackupAll.Enabled = false;
}
private void ReloadData()
@ -135,11 +145,15 @@ namespace StockInfo
{
btnRestoreShares.Enabled = true;
btnBackupShares.Enabled = true;
btnBackupAll.Enabled = true;
btnRestoreAll.Enabled = true;
}
else
{
btnRestoreShares.Enabled = false;
btnBackupShares.Enabled = false;
btnBackupAll.Enabled = false;
btnRestoreAll.Enabled = false;
}
}
@ -235,5 +249,11 @@ namespace StockInfo
{
SelectedPersonId = ((ComboboxItem)cmbOwners.SelectedItem).HiddenValue;
}
private void btnBackupAll_Click(object sender, EventArgs e)
{
backupWindow = new frmBackup(_backupRepository,_backupRoutines);
backupWindow.ShowDialog();
}
}
}