diff --git a/AdvertsingProfitControl/App.config b/AdvertsingProfitControl/App.config
index 9e830f2..1dd3bd0 100644
--- a/AdvertsingProfitControl/App.config
+++ b/AdvertsingProfitControl/App.config
@@ -15,7 +15,6 @@
-
\ No newline at end of file
diff --git a/AdvertsingProfitControl/FrmMain.Designer.cs b/AdvertsingProfitControl/FrmMain.Designer.cs
index 07fffd5..ee0d23a 100644
--- a/AdvertsingProfitControl/FrmMain.Designer.cs
+++ b/AdvertsingProfitControl/FrmMain.Designer.cs
@@ -40,7 +40,7 @@
this.toolsMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.clearRecordToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.clearCurrentRecordSelectedDateToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem();
- this.selectRangeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.clearCurrentActiveYearTools = new System.Windows.Forms.ToolStripMenuItem();
this.manageItemsToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.manageSuppliersToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.adSpecialKeyWordsToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem();
@@ -220,7 +220,7 @@
//
this.clearRecordToolsMainMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.clearCurrentRecordSelectedDateToolsMainMenu,
- this.selectRangeToolStripMenuItem});
+ this.clearCurrentActiveYearTools});
this.clearRecordToolsMainMenu.Name = "clearRecordToolsMainMenu";
this.clearRecordToolsMainMenu.Size = new System.Drawing.Size(282, 34);
this.clearRecordToolsMainMenu.Text = "&Clear Record(s)";
@@ -228,16 +228,16 @@
// clearCurrentRecordSelectedDateToolsMainMenu
//
this.clearCurrentRecordSelectedDateToolsMainMenu.Name = "clearCurrentRecordSelectedDateToolsMainMenu";
- this.clearCurrentRecordSelectedDateToolsMainMenu.Size = new System.Drawing.Size(244, 34);
+ this.clearCurrentRecordSelectedDateToolsMainMenu.Size = new System.Drawing.Size(272, 34);
this.clearCurrentRecordSelectedDateToolsMainMenu.Text = "C&urrent Record";
this.clearCurrentRecordSelectedDateToolsMainMenu.Click += new System.EventHandler(this.ClearCurrentRecord);
//
- // selectRangeToolStripMenuItem
+ // clearCurrentActiveYearTools
//
- this.selectRangeToolStripMenuItem.Name = "selectRangeToolStripMenuItem";
- this.selectRangeToolStripMenuItem.Size = new System.Drawing.Size(244, 34);
- this.selectRangeToolStripMenuItem.Text = "Select Ran&ge...";
- this.selectRangeToolStripMenuItem.Click += new System.EventHandler(this.DisplayRecordDeletionRangeForm);
+ this.clearCurrentActiveYearTools.Name = "clearCurrentActiveYearTools";
+ this.clearCurrentActiveYearTools.Size = new System.Drawing.Size(272, 34);
+ this.clearCurrentActiveYearTools.Text = "Clear Current &Year";
+ this.clearCurrentActiveYearTools.Click += new System.EventHandler(this.ClearActiveDateYearRecords);
//
// manageItemsToolsMainMenu
//
@@ -249,7 +249,7 @@
// manageSuppliersToolsMainMenu
//
this.manageSuppliersToolsMainMenu.Name = "manageSuppliersToolsMainMenu";
- this.manageSuppliersToolsMainMenu.Size = new System.Drawing.Size(286, 34);
+ this.manageSuppliersToolsMainMenu.Size = new System.Drawing.Size(282, 34);
this.manageSuppliersToolsMainMenu.Text = "Manage &Suppliers";
this.manageSuppliersToolsMainMenu.Click += new System.EventHandler(this.manageSuppliersToolsMainMenu_Click);
//
@@ -1105,7 +1105,7 @@
private System.Windows.Forms.ToolStripMenuItem reportsMainMenu;
private System.Windows.Forms.ToolStripMenuItem manageSuppliersToolsMainMenu;
private System.Windows.Forms.ToolStripMenuItem clearCurrentRecordSelectedDateToolsMainMenu;
- private System.Windows.Forms.ToolStripMenuItem selectRangeToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem clearCurrentActiveYearTools;
}
}
diff --git a/AdvertsingProfitControl/FrmMain.cs b/AdvertsingProfitControl/FrmMain.cs
index b65b953..0c3a8d7 100644
--- a/AdvertsingProfitControl/FrmMain.cs
+++ b/AdvertsingProfitControl/FrmMain.cs
@@ -1,4 +1,5 @@
using System;
+using System.Data.Entity.Core;
using System.Data.Entity.Infrastructure;
using System.Drawing;
using System.Drawing.Printing;
@@ -231,11 +232,6 @@ namespace AdvertsingProfitControl
}
}
- private void DisplayRecordDeletionRangeForm(object sender, EventArgs e)
- {
- //TODO: Create a form to allow the user to delete a range of dates.
- }
-
private void DisplayAdItemManager(object sender, EventArgs e)
{
var adItemManager = new FrmManageAdItems();
@@ -884,6 +880,8 @@ namespace AdvertsingProfitControl
modifyRecordMainMenu.ToolTipText = string.Empty;
clearCurrentRecordSelectedDateToolsMainMenu.Enabled = true;
clearCurrentRecordSelectedDateToolsMainMenu.ToolTipText = string.Empty;
+ clearCurrentActiveYearTools.Enabled = true;
+ clearCurrentActiveYearTools.ToolTipText = string.Empty;
}
else
{
@@ -892,6 +890,8 @@ namespace AdvertsingProfitControl
modifyRecordMainMenu.ToolTipText = @"There are no records to modify.";
clearCurrentRecordSelectedDateToolsMainMenu.Enabled = false;
clearCurrentRecordSelectedDateToolsMainMenu.ToolTipText = @"There is no date to clear.";
+ clearCurrentActiveYearTools.Enabled = false;
+ clearCurrentActiveYearTools.ToolTipText = @"There are no records to clear.";
}
}
@@ -927,6 +927,171 @@ namespace AdvertsingProfitControl
}
- #endregion
+ #endregion
+
+ private void ClearActiveDateYearRecords(object sender, EventArgs e)
+ {
+ 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 distinctYears = db.WeekEndingDates.Select(x => x.EndingDate.Year).Distinct().ToArray();
+ if (distinctYears.Length == 1)
+ {
+ result = MessageBox.Show(_currentActiveDate.Year + @" appears to be the only year, clearing it will wipe all data in the database. Are you sure you wish to continue?", @"Clear " + _currentActiveDate.Year + @"'s Records", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
+ if (result != DialogResult.Yes) return;
+ }
+ if (ClearSelectedDate(_currentActiveDate.Year))
+ {
+ RefreshDateListing();
+ }
+ else
+ {
+ MessageBox.Show(@"Failed to clear the records for " + _currentActiveDate.Year + @".", @"Update Error",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ #region Writing Operations
+
+ private bool ClearSelectedDate(int year)
+ {
+ var db = new AdvertisingProfitControlModel();
+ var status = true;
+
+ using (var scope = new TransactionScope())
+ {
+ try
+ {
+ var dateRecords = db.WeekEndingDates.Select(x => x).Where(x => x.EndingDate.Year == year).ToArray();
+ foreach (var dateRecord in dateRecords)
+ {
+ ClearProjectionRecords(dateRecord);
+ ClearInventoyRecords(dateRecord);
+ ClearActualSalesRecords(dateRecord);
+ ClearInvoices(dateRecord);
+ ClearWeeklySales(dateRecord);
+ ClearTaxableRecords(dateRecord);
+ ClearCostAnalysisRecords(dateRecord);
+ ClearCommentsRecords(dateRecord);
+ db.WeekEndingDates.Remove(dateRecord);
+ }
+ db.SaveChanges();
+ scope.Complete();
+ }
+ catch (DbUpdateException e)
+ {
+ _console.WriteToLog(FrmLogConsole.Level.Error, e.Message);
+ status = false;
+ }
+ }
+
+ return status;
+ }
+
+ private void ClearProjectionRecords(WeekEndingDate dateRecord)
+ {
+ var db = new AdvertisingProfitControlModel();
+
+ using (var scope = new TransactionScope())
+ {
+ var projections = db.Projections.Select(x => x).Where(x => x.FkDateId == dateRecord.Id);
+ db.Projections.RemoveRange(projections);
+ db.SaveChanges();
+ scope.Complete();
+ }
+ }
+
+ private void ClearInventoyRecords(WeekEndingDate dateRecord)
+ {
+ var db = new AdvertisingProfitControlModel();
+
+ using (var scope = new TransactionScope())
+ {
+ var inventories = db.Inventories.Select(x => x).Where(x => x.FkDateId == dateRecord.Id);
+ db.Inventories.RemoveRange(inventories);
+ db.SaveChanges();
+ scope.Complete();
+ }
+ }
+
+ private void ClearActualSalesRecords(WeekEndingDate dateRecord)
+ {
+ var db = new AdvertisingProfitControlModel();
+
+ using (var scope = new TransactionScope())
+ {
+ var actualSales = db.ActualSales.Select(x => x).Where(x => x.FkDateId == dateRecord.Id);
+ db.ActualSales.RemoveRange(actualSales);
+ db.SaveChanges();
+ scope.Complete();
+ }
+ }
+
+ private void ClearInvoices(WeekEndingDate dateRecord)
+ {
+ var db = new AdvertisingProfitControlModel();
+
+ using (var scope = new TransactionScope())
+ {
+ var invoices = db.Invoices.Select(x => x).Where(x => x.FkDateId == dateRecord.Id);
+ db.Invoices.RemoveRange(invoices);
+ db.SaveChanges();
+ scope.Complete();
+ }
+ }
+
+ private void ClearWeeklySales(WeekEndingDate dateRecord)
+ {
+ var db = new AdvertisingProfitControlModel();
+
+ using (var scope = new TransactionScope())
+ {
+ var weeklySales = db.WeeklySales.Select(x => x).Where(x => x.FkDateId == dateRecord.Id);
+ db.WeeklySales.RemoveRange(weeklySales);
+ db.SaveChanges();
+ scope.Complete();
+ }
+ }
+
+ private void ClearTaxableRecords(WeekEndingDate dateRecord)
+ {
+ var db = new AdvertisingProfitControlModel();
+
+ using (var scope = new TransactionScope())
+ {
+ var taxables = db.Taxables.Select(x => x).Where(x => x.FkDateId == dateRecord.Id);
+ db.Taxables.RemoveRange(taxables);
+ db.SaveChanges();
+ scope.Complete();
+ }
+ }
+
+ private void ClearCostAnalysisRecords(WeekEndingDate dateRecord)
+ {
+ var db = new AdvertisingProfitControlModel();
+
+ using (var scope = new TransactionScope())
+ {
+ var costAnalysis = db.CostAnalysis.Select(x => x).Where(x => x.FkDateId == dateRecord.Id);
+ db.CostAnalysis.RemoveRange(costAnalysis);
+ db.SaveChanges();
+ scope.Complete();
+ }
+ }
+
+ private void ClearCommentsRecords(WeekEndingDate dateRecord)
+ {
+ var db = new AdvertisingProfitControlModel();
+
+ using (var scope = new TransactionScope())
+ {
+ var comments = db.Notes.Select(x => x).Where(x => x.FkDateId == dateRecord.Id);
+ db.Notes.RemoveRange(comments);
+ db.SaveChanges();
+ scope.Complete();
+ }
+ }
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/AdvertsingProfitControl/FrmManageAdItems.Designer.cs b/AdvertsingProfitControl/FrmManageAdItems.Designer.cs
index 3065929..ac150cd 100644
--- a/AdvertsingProfitControl/FrmManageAdItems.Designer.cs
+++ b/AdvertsingProfitControl/FrmManageAdItems.Designer.cs
@@ -44,6 +44,7 @@
// adItemsListView
//
this.adItemsListView.Location = new System.Drawing.Point(258, 12);
+ this.adItemsListView.MultiSelect = false;
this.adItemsListView.Name = "adItemsListView";
this.adItemsListView.Size = new System.Drawing.Size(452, 431);
this.adItemsListView.TabIndex = 3;
diff --git a/AdvertsingProfitControl/FrmManageAdItems.cs b/AdvertsingProfitControl/FrmManageAdItems.cs
index 10cc835..2b5e093 100644
--- a/AdvertsingProfitControl/FrmManageAdItems.cs
+++ b/AdvertsingProfitControl/FrmManageAdItems.cs
@@ -139,6 +139,7 @@ namespace AdvertsingProfitControl
else
{
adItemsListView.Columns[0].Text = @"No Ad Items to Display.";
+ filterComboBox.Enabled = false;
filterComboBox.SelectedIndex = 0;
}
removeAdItemButton.Enabled = false;
diff --git a/AdvertsingProfitControl/FrmManageSuppliers.Designer.cs b/AdvertsingProfitControl/FrmManageSuppliers.Designer.cs
index e7b18e3..cd32da4 100644
--- a/AdvertsingProfitControl/FrmManageSuppliers.Designer.cs
+++ b/AdvertsingProfitControl/FrmManageSuppliers.Designer.cs
@@ -43,6 +43,7 @@
//
this.suppliersListBox.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.suppliersListBox.Location = new System.Drawing.Point(257, 12);
+ this.suppliersListBox.MultiSelect = false;
this.suppliersListBox.Name = "suppliersListBox";
this.suppliersListBox.Size = new System.Drawing.Size(423, 412);
this.suppliersListBox.TabIndex = 16;
diff --git a/AdvertsingProfitControl/FrmRegisterAdSpecial.Designer.cs b/AdvertsingProfitControl/FrmRegisterAdSpecial.Designer.cs
index 337fa0f..5408e30 100644
--- a/AdvertsingProfitControl/FrmRegisterAdSpecial.Designer.cs
+++ b/AdvertsingProfitControl/FrmRegisterAdSpecial.Designer.cs
@@ -107,6 +107,7 @@
//
this.adSpecialsListBox.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.adSpecialsListBox.Location = new System.Drawing.Point(260, 21);
+ this.adSpecialsListBox.MultiSelect = false;
this.adSpecialsListBox.Name = "adSpecialsListBox";
this.adSpecialsListBox.Size = new System.Drawing.Size(420, 401);
this.adSpecialsListBox.TabIndex = 8;
diff --git a/SetupProject/Product.wxs b/SetupProject/Product.wxs
index 890bc23..287625d 100644
--- a/SetupProject/Product.wxs
+++ b/SetupProject/Product.wxs
@@ -1,7 +1,7 @@
-
+
@@ -12,6 +12,7 @@
+
@@ -19,8 +20,8 @@
-
-
+
+