Implemented database backups and restores into the AdvertisingProfitControlData DLL and added a form, DatabaseRecovery, to manage the backups and restores. Updated the installer to include the data DLL file into the install bundle.

This commit is contained in:
2017-06-23 03:12:51 -05:00
parent 308b60bd84
commit 12a6b36370
20 changed files with 5378 additions and 80 deletions
+36 -24
View File
@@ -27,7 +27,7 @@ namespace AdvertsingProfitControl
private void frmMain_Load(object sender, EventArgs e)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
RefreshDateListing();
ConstructApcDataGridViews();
ConstructInvoicesDataGridView();
@@ -136,7 +136,7 @@ namespace AdvertsingProfitControl
private void DisplayNewRecordForm(object sender, EventArgs e)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var form = new NewModifyRecord();
form.ShowDialog();
//One the user has closed the add record form, check to see if there is a newer date
@@ -157,6 +157,19 @@ namespace AdvertsingProfitControl
LoadDate(_currentActiveDate);
}
private void DisplayDatabaseRecoveryFormOnBackupRestoreClick(object sender, EventArgs e)
{
var form = new DatabaseRecovery();
form.ShowDialog();
if (!form.RestoredDatabase) return;
//If a database restore operation occurred then load the most recent date.
var db = new AdvertisingProfitControlDbContext();
var recentDate = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault();
if (recentDate == null) return;
_currentActiveDate = recentDate.EndingDate;
LoadDate(recentDate.EndingDate);
}
private void ClearCurrentRecord(object sender, EventArgs e)
{
var result = MessageBox.Show(@"Are you sure you want to delete all records for the date " + _currentActiveDate.ToShortDateString() + @"?", @"Clear Date", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
@@ -165,7 +178,7 @@ namespace AdvertsingProfitControl
return;
}
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var dateRecord = db.WeekEndingDates.Single(x => x.EndingDate == _currentActiveDate);
var projections = db.Projections.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
var inventories = db.Inventories.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
@@ -242,7 +255,6 @@ namespace AdvertsingProfitControl
adItemManager.ShowDialog();
}
private void manageSuppliersToolsMainMenu_Click(object sender, EventArgs e)
{
var form = new FrmManageSuppliers();
@@ -447,7 +459,7 @@ namespace AdvertsingProfitControl
private void LoadDate(DateTime date)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
//Check to see if that date record can be found before clearing the form.
var dateRecord = db.WeekEndingDates.SingleOrDefault(x => x.EndingDate == date);
if (dateRecord == null)
@@ -478,7 +490,7 @@ namespace AdvertsingProfitControl
private void LoadProjectionsTable(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var adSpecialIndex = -1;
decimal totalSales = 0;
decimal totalProfitReturn = 0;
@@ -538,7 +550,7 @@ namespace AdvertsingProfitControl
private void LoadInventoryTable(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var adSpecialIndex = -1;
var inventories = db.Inventories.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x).OrderBy(x => x.RowPosition);
@@ -570,7 +582,7 @@ namespace AdvertsingProfitControl
private void LoadActualSalesTable(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var adSpecialIndex = -1;
decimal totalSales = 0;
decimal totalProfitReturn = 0;
@@ -630,7 +642,7 @@ namespace AdvertsingProfitControl
private void LoadInvoices(WeekEndingDate dateRecord)
{
_totalInvoicePurchases = 0;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var invoices = db.Invoices.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x);
foreach (var invoice in invoices)
@@ -660,7 +672,7 @@ namespace AdvertsingProfitControl
{
//Clear the department sales and prepare to add up a total.
_departmentSales = 0;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var weeklySales = db.WeeklySales.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x);
foreach (var sale in weeklySales)
{
@@ -719,7 +731,7 @@ namespace AdvertsingProfitControl
private void LoadTaxable(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var taxables = db.Taxables.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x);
foreach (var taxable in taxables)
{
@@ -750,7 +762,7 @@ namespace AdvertsingProfitControl
private void LoadCostAnalysis(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var analysis = db.CostAnalysis.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x);
foreach (var a in analysis)
{
@@ -870,7 +882,7 @@ namespace AdvertsingProfitControl
private void RefreshDateListing()
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
monthCalendar.BoldedDates = db.WeekEndingDates.Select(zdate => zdate.EndingDate).ToArray();
if (monthCalendar.BoldedDates.Length > 0)
{
@@ -931,7 +943,7 @@ namespace AdvertsingProfitControl
{
var result = MessageBox.Show(@"Are you sure you want to remove all records for the year of " + _currentActiveDate.Year + @"? This cannot be undone!", @"Clear " + _currentActiveDate.Year + @"'s Records", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (result != DialogResult.Yes) return;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var distinctYears = db.WeekEndingDates.Select(x => x.EndingDate.Year).Distinct().ToArray();
if (distinctYears.Length == 1)
{
@@ -953,7 +965,7 @@ namespace AdvertsingProfitControl
private bool ClearSelectedDate(int year)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var status = true;
using (var scope = new TransactionScope())
@@ -988,7 +1000,7 @@ namespace AdvertsingProfitControl
private void ClearProjectionRecords(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
@@ -1001,7 +1013,7 @@ namespace AdvertsingProfitControl
private void ClearInventoyRecords(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
@@ -1014,7 +1026,7 @@ namespace AdvertsingProfitControl
private void ClearActualSalesRecords(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
@@ -1027,7 +1039,7 @@ namespace AdvertsingProfitControl
private void ClearInvoices(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
@@ -1040,7 +1052,7 @@ namespace AdvertsingProfitControl
private void ClearWeeklySales(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
@@ -1053,7 +1065,7 @@ namespace AdvertsingProfitControl
private void ClearTaxableRecords(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
@@ -1066,7 +1078,7 @@ namespace AdvertsingProfitControl
private void ClearCostAnalysisRecords(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
@@ -1079,7 +1091,7 @@ namespace AdvertsingProfitControl
private void ClearCommentsRecords(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
@@ -1109,7 +1121,7 @@ namespace AdvertsingProfitControl
private void testToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show(@"Nothing to debug here!", @"Debug Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}