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
+24 -24
View File
@@ -61,7 +61,7 @@ namespace AdvertsingProfitControl
public NewModifyRecord()
{
InitializeComponent();
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
//Check to see if there are dates in the database.
if (db.WeekEndingDates.Any())
{
@@ -85,7 +85,7 @@ namespace AdvertsingProfitControl
public void InitializeForm()
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
weekEndingCalendar.BoldedDates = db.WeekEndingDates.Select(zdate => zdate.EndingDate).ToArray();
weekEndingCalendar.DateChanged += ValidateDateChanged;
//next pull all the ad items into memory.
@@ -2737,7 +2737,7 @@ namespace AdvertsingProfitControl
private void LoadDate(DateTime date)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var dateRecord = db.WeekEndingDates.SingleOrDefault(x => x.EndingDate == date);
if (dateRecord == null)
{
@@ -2765,7 +2765,7 @@ namespace AdvertsingProfitControl
projectionsDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents;
projectionsDataGridView.RowValidating -= ValidateProjectedRow;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var adSpecialIndex = -1;
var projections = db.Projections.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x).OrderBy(x => x.RowPosition);
var index = 0;
@@ -2831,7 +2831,7 @@ namespace AdvertsingProfitControl
inventoryDataGridView.CellValidating -= ValidateInventoryCellContents;
inventoryDataGridView.RowValidating -= ValidateInventoryRow;
//Create a local ad special index since Projections should have filled the ad special index in for the class.
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);
var index = 0;
@@ -2893,7 +2893,7 @@ namespace AdvertsingProfitControl
actualSalesDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents;
actualSalesDataGridView.RowValidating -= ValidateActualSalesRow;
//Create a local ad special index since Projections should have filled the ad special index in for the class.
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var adSpecialIndex = -1;
var actualSales = db.ActualSales.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x).OrderBy(x => x.RowPosition);
var index = 0;
@@ -2950,7 +2950,7 @@ namespace AdvertsingProfitControl
private void LoadInvoices(WeekEndingDate dateRecord)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var invoices = db.Invoices.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x);
var index = 0;
foreach (var invoice in invoices)
@@ -2973,7 +2973,7 @@ namespace AdvertsingProfitControl
commentsTextBox.Enter -= StoreBeginningTextBoxValue;
commentsTextBox.KeyDown -= CheckForKeyCommand;
commentsTextBox.Leave -= CheckForTextChangeOnLeave;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var comments = db.Notes.SingleOrDefault(x => x.FkDateId == dateRecord.Id);
if (comments != null)
{
@@ -3011,7 +3011,7 @@ namespace AdvertsingProfitControl
totalWeeklySalesTextBox.Enter -= StoreBeginningTextBoxValue;
totalWeeklySalesTextBox.Validating -= ValidateWeeklySales;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var weeklySale = db.WeeklySales.SingleOrDefault(x => x.FkDateId == dateRecord.Id);
if (weeklySale == null)
{
@@ -3068,7 +3068,7 @@ namespace AdvertsingProfitControl
saturdayTaxableTextBox.Validating -= ValidateTaxableFields;
totalTaxableTextBox.Enter -= StoreBeginningTextBoxValue;
totalTaxableTextBox.Validating -= ValidateTaxableFields;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var taxable = db.Taxables.SingleOrDefault(x => x.FkDateId == dateRecord.Id);
if (taxable == null)
{
@@ -3117,7 +3117,7 @@ namespace AdvertsingProfitControl
suppliesTextBox.Enter -= StoreBeginningTextBoxValue;
suppliesTextBox.Validating -= ValidateCostAnalysisValues;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var costAnalysis = db.CostAnalysis.SingleOrDefault(x => x.FkDateId == dateRecord.Id);
if (costAnalysis == null)
{
@@ -3154,7 +3154,7 @@ namespace AdvertsingProfitControl
private bool SaveRecords()
{
var success = true;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
//Get the date ID for the current active date.
if (_currentActiveDate.DayOfWeek != DayOfWeek.Saturday)
{
@@ -3303,7 +3303,7 @@ namespace AdvertsingProfitControl
private void SaveProjections(WeekEndingDate date)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var lastRow = -1;
using (var scope = new TransactionScope())
{
@@ -3482,7 +3482,7 @@ namespace AdvertsingProfitControl
private void SaveInventory(WeekEndingDate date)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var lastRow = -1;
using (var scope = new TransactionScope())
{
@@ -3623,7 +3623,7 @@ namespace AdvertsingProfitControl
private void SaveActualSales(WeekEndingDate date)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var lastRow = -1;
using (var scope = new TransactionScope())
{
@@ -3804,7 +3804,7 @@ namespace AdvertsingProfitControl
private void SaveInvoices(WeekEndingDate date)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var lastRow = -1;
using (var scope = new TransactionScope())
{
@@ -3936,7 +3936,7 @@ namespace AdvertsingProfitControl
informationLabel.Text += @"No changes detected to Weekly Sales." + Environment.NewLine;
return;
}
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
try
@@ -4011,7 +4011,7 @@ namespace AdvertsingProfitControl
informationLabel.Text += @"No changes detected to Taxable." + Environment.NewLine;
return;
}
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
try
@@ -4086,7 +4086,7 @@ namespace AdvertsingProfitControl
informationLabel.Text += @"No changes detected to Cost Analysis." + Environment.NewLine;
return;
}
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
try
@@ -4153,7 +4153,7 @@ namespace AdvertsingProfitControl
informationLabel.Text += @"No changes detected for Comments." + Environment.NewLine;
return;
}
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
try
@@ -4209,7 +4209,7 @@ namespace AdvertsingProfitControl
private static AdSpecial GetAdSpecial(string adSpecialText)
{
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var adSpecial = new AdSpecial();
//An ad special does exist so grab its ID from the database.
if (db.AdSpecials.Any(x => x.Name == adSpecialText))
@@ -4227,7 +4227,7 @@ namespace AdvertsingProfitControl
private static bool DeleteApcRow(int projectionId, int inventoryId, int actualSalesId)
{
var result = true;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
try
@@ -4263,7 +4263,7 @@ namespace AdvertsingProfitControl
private static bool DeleteInvoiceRow(int invoiceId)
{
var result = true;
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
using (var scope = new TransactionScope())
{
try
@@ -4325,7 +4325,7 @@ namespace AdvertsingProfitControl
ClearFormState();
addRecordButton.Text = @"Add Record";
var db = new AdvertisingProfitControlModel();
var db = new AdvertisingProfitControlDbContext();
var recentDate = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault(x => x.EndingDate.Year == _currentActiveDate.Year);
if (recentDate == null)
{