Created forms to allow the management of ad items, suppliers and ad special keywords. Updated the database migration tool to include the ad special table. Cleaned up the main form's code and did a slight touch up of the interface.
This commit is contained in:
+186
-158
@@ -4,7 +4,6 @@ using System.Drawing;
|
||||
using System.Drawing.Printing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Transactions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@@ -41,12 +40,10 @@ namespace AdvertsingProfitControl
|
||||
LoadDate(recentDate.EndingDate);
|
||||
}
|
||||
monthCalendar.DateChanged += ValidateDateChanged;
|
||||
//projectionsDataGridView.KeyDown += FrmMain_KeyDown;
|
||||
//var margin = new Margins(50, 50, 0, 0);
|
||||
//_printDoc.DefaultPageSettings.Margins = margin;
|
||||
|
||||
}
|
||||
|
||||
#region Calculate Analysis Methods
|
||||
|
||||
private void CalculateProfitAnalysis(decimal shrink = 0.30m)
|
||||
{
|
||||
if (actualSalesDataGridView.Rows.Count == 0)
|
||||
@@ -128,7 +125,11 @@ namespace AdvertsingProfitControl
|
||||
perfectGrossProfitLabel.Text = @"Percent Gross Profit: " + grossProfitPercent.ToString("P");
|
||||
}
|
||||
|
||||
private void addRecordToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
#endregion
|
||||
|
||||
#region Main Menu Click Handlers
|
||||
|
||||
private void DisplayNewRecordForm(object sender, EventArgs e)
|
||||
{
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var form = new NewModifyRecord();
|
||||
@@ -142,7 +143,119 @@ namespace AdvertsingProfitControl
|
||||
LoadDate(date.EndingDate);
|
||||
}
|
||||
|
||||
private void showHideConsoleHelpMainMenu_Click(object sender, EventArgs e)
|
||||
private void DisplayModifyRecordForm(object sender, EventArgs e)
|
||||
{
|
||||
var form = new NewModifyRecord(_currentActiveDate);
|
||||
form.ShowDialog();
|
||||
RefreshDateListing();
|
||||
//On return reload the date that was just modified by the modify record form.
|
||||
LoadDate(_currentActiveDate);
|
||||
}
|
||||
|
||||
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);
|
||||
if (result == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
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);
|
||||
var actualSales = db.ActualSales.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
var invoices = db.Invoices.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
var weeklySale = db.WeeklySales.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
var taxable = db.Taxables.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
var costAnalysis = db.CostAnalysis.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
var comment = db.Notes.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
|
||||
using (var scope = new TransactionScope())
|
||||
{
|
||||
try
|
||||
{
|
||||
//Clear projections
|
||||
foreach (var projection in projections)
|
||||
{
|
||||
db.Projections.Remove(projection);
|
||||
}
|
||||
//Clear inventory
|
||||
foreach (var inventory in inventories)
|
||||
{
|
||||
db.Inventories.Remove(inventory);
|
||||
}
|
||||
//Clear actual sales
|
||||
foreach (var sale in actualSales)
|
||||
{
|
||||
db.ActualSales.Remove(sale);
|
||||
}
|
||||
//Clear invoices
|
||||
foreach (var invoice in invoices)
|
||||
{
|
||||
db.Invoices.Remove(invoice);
|
||||
}
|
||||
if (weeklySale != null)
|
||||
{
|
||||
db.WeeklySales.Remove(weeklySale);
|
||||
}
|
||||
if (taxable != null)
|
||||
{
|
||||
db.Taxables.Remove(taxable);
|
||||
}
|
||||
if (costAnalysis != null)
|
||||
{
|
||||
db.CostAnalysis.Remove(costAnalysis);
|
||||
}
|
||||
if (comment != null)
|
||||
{
|
||||
db.Notes.Remove(comment);
|
||||
}
|
||||
db.WeekEndingDates.Remove(dateRecord);
|
||||
db.SaveChanges();
|
||||
scope.Complete();
|
||||
ClearForm();
|
||||
}
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
MessageBox.Show(@"Failed to clear selected date.", @"Error");
|
||||
_console.WriteToLog(FrmLogConsole.Level.Error, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
RefreshDateListing();
|
||||
var mostRecentDate = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault();
|
||||
if (mostRecentDate != null)
|
||||
{
|
||||
LoadDate(mostRecentDate.EndingDate);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
adItemManager.ShowDialog();
|
||||
}
|
||||
|
||||
|
||||
private void manageSuppliersToolsMainMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
var form = new FrmManageSuppliers();
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void DisplayRegisterAdSpecial(object sender, EventArgs e)
|
||||
{
|
||||
var form = new FrmRegisterAdSpecial();
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void ShowHideLogConsole(object sender, EventArgs e)
|
||||
{
|
||||
if (_console.IsVisable)
|
||||
{
|
||||
@@ -154,23 +267,7 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
}
|
||||
|
||||
private void modifyRecordMainMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
var form = new NewModifyRecord(_currentActiveDate);
|
||||
form.ShowDialog();
|
||||
RefreshDateListing();
|
||||
//On return reload the date that was just modified by the modify record form.
|
||||
LoadDate(_currentActiveDate);
|
||||
}
|
||||
|
||||
private void manageItemsToolsMainMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
//TODO: Bring back Manage Ad Items form and managing AdSpecials.
|
||||
//var adItemManager = new FrmManageAdItems();
|
||||
//adItemManager.ShowDialog();
|
||||
}
|
||||
|
||||
private void dbVersionHelpMainMenu_Click(object sender, EventArgs e)
|
||||
private void DisplayDatabaseVersionNumber(object sender, EventArgs e)
|
||||
{
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var version = db.Versions.FirstOrDefault(x => x.Id == 1);
|
||||
@@ -183,6 +280,9 @@ namespace AdvertsingProfitControl
|
||||
MessageBox.Show(@"The current database's version is " + version.VersionNumber + @".", @"Database Version Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Print Handler Methods
|
||||
|
||||
private void PrintPage(object sender, PrintPageEventArgs e)
|
||||
{
|
||||
@@ -264,9 +364,12 @@ namespace AdvertsingProfitControl
|
||||
printDialog.Document = new PrintDocument();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DataGridView Constructor Methods
|
||||
|
||||
/// <summary>
|
||||
/// Fills the APC DataGridViews with the appropriate columns and starting row for the user to start
|
||||
/// entering data.
|
||||
/// Builds the appropriate columns in the APC DataGridViews so they can be filled.
|
||||
/// </summary>
|
||||
private void ConstructApcDataGridViews()
|
||||
{
|
||||
@@ -346,9 +449,14 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Date Loading Methods
|
||||
|
||||
private void LoadDate(DateTime date)
|
||||
{
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
//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)
|
||||
{
|
||||
@@ -356,6 +464,7 @@ namespace AdvertsingProfitControl
|
||||
return;
|
||||
}
|
||||
ClearForm();
|
||||
//Load all the data attached to the date record.
|
||||
LoadProjectionsTable(dateRecord);
|
||||
LoadInventoryTable(dateRecord);
|
||||
LoadActualSalesTable(dateRecord);
|
||||
@@ -405,14 +514,12 @@ namespace AdvertsingProfitControl
|
||||
projectionsDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.MemberRow;
|
||||
}
|
||||
|
||||
if (p.FkAdSpecialId != null && adSpecialIndex == -1)
|
||||
{
|
||||
//TODO: Fix null reference when no object is found.
|
||||
adSpecialIndex = index;
|
||||
projectionsDataGridView.Rows.Insert(index, 1);
|
||||
projectionsDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
|
||||
projectionsDataGridView.Rows[index].Cells[3].Value = db.AdSpecials.Single(x => x.Id == p.FkAdSpecialId).Name;
|
||||
}
|
||||
if (p.FkAdSpecialId == null || adSpecialIndex != -1) continue;
|
||||
//TODO: Fix null reference when no object is found.
|
||||
adSpecialIndex = index;
|
||||
projectionsDataGridView.Rows.Insert(index, 1);
|
||||
projectionsDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
|
||||
projectionsDataGridView.Rows[index].Cells[3].Value = db.AdSpecials.Single(x => x.Id == p.FkAdSpecialId).Name;
|
||||
}
|
||||
//Now add the totals row.
|
||||
if (projectionsDataGridView.RowCount == 0) return;
|
||||
@@ -461,13 +568,11 @@ namespace AdvertsingProfitControl
|
||||
inventoryDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.MemberRow;
|
||||
}
|
||||
|
||||
if (i.FkAdSpecialId != null && adSpecialIndex == -1)
|
||||
{
|
||||
adSpecialIndex = index;
|
||||
inventoryDataGridView.Rows.Insert(index, 1);
|
||||
inventoryDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
|
||||
inventoryDataGridView.Rows[index].Cells[2].Value = db.AdSpecials.Single(x => x.Id == i.FkAdSpecialId).Name;
|
||||
}
|
||||
if (i.FkAdSpecialId == null || adSpecialIndex != -1) continue;
|
||||
adSpecialIndex = index;
|
||||
inventoryDataGridView.Rows.Insert(index, 1);
|
||||
inventoryDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
|
||||
inventoryDataGridView.Rows[index].Cells[2].Value = db.AdSpecials.Single(x => x.Id == i.FkAdSpecialId).Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,13 +606,11 @@ namespace AdvertsingProfitControl
|
||||
actualSalesDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.MemberRow;
|
||||
}
|
||||
|
||||
if (a.FkAdSpecialId != null && adSpecialIndex == -1)
|
||||
{
|
||||
adSpecialIndex = index;
|
||||
actualSalesDataGridView.Rows.Insert(index, 1);
|
||||
actualSalesDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
|
||||
actualSalesDataGridView.Rows[index].Cells[3].Value = db.AdSpecials.Single(x => x.Id == a.FkAdSpecialId).Name;
|
||||
}
|
||||
if (a.FkAdSpecialId == null || adSpecialIndex != -1) continue;
|
||||
adSpecialIndex = index;
|
||||
actualSalesDataGridView.Rows.Insert(index, 1);
|
||||
actualSalesDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
|
||||
actualSalesDataGridView.Rows[index].Cells[3].Value = db.AdSpecials.Single(x => x.Id == a.FkAdSpecialId).Name;
|
||||
}
|
||||
//Now add the totals row.
|
||||
if (actualSalesDataGridView.RowCount == 0) return;
|
||||
@@ -665,6 +768,8 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string CheckForHoliday(DayOfWeek day)
|
||||
{
|
||||
var holidayText = string.Empty;
|
||||
@@ -709,6 +814,13 @@ namespace AdvertsingProfitControl
|
||||
return holidayText;
|
||||
}
|
||||
|
||||
#region Form Reset And Data Loading Methods
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if the newly selected date is one that should be loaded.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ValidateDateChanged(object sender, DateRangeEventArgs e)
|
||||
{
|
||||
if (e.Start == _currentActiveDate || !monthCalendar.BoldedDates.Contains(e.Start)) return;
|
||||
@@ -762,13 +874,6 @@ namespace AdvertsingProfitControl
|
||||
grossProfitEstimatedWeeklyDeptmartmentExpenseLabel.Text = @"Estimated Weekly" + Environment.NewLine + @"Department Expense: ";
|
||||
}
|
||||
|
||||
private void debugToolStripMenuItem1_Click(object sender, EventArgs e)
|
||||
{
|
||||
var form = new DebugDatabaseConverter();
|
||||
form.ShowDialog();
|
||||
RefreshDateListing();
|
||||
}
|
||||
|
||||
private void RefreshDateListing()
|
||||
{
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
@@ -776,129 +881,52 @@ namespace AdvertsingProfitControl
|
||||
if (monthCalendar.BoldedDates.Length > 0)
|
||||
{
|
||||
modifyRecordMainMenu.Enabled = true;
|
||||
modifyRecordMainMenu.ToolTipText = @"";
|
||||
modifyRecordMainMenu.ToolTipText = string.Empty;
|
||||
clearCurrentRecordSelectedDateToolsMainMenu.Enabled = true;
|
||||
clearCurrentRecordSelectedDateToolsMainMenu.ToolTipText = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
dateTimeGroupBox.Text = @"No records found in the database.";
|
||||
modifyRecordMainMenu.Enabled = false;
|
||||
modifyRecordMainMenu.ToolTipText = @"There are no records to modify.";
|
||||
clearCurrentRecordSelectedDateToolsMainMenu.Enabled = false;
|
||||
clearCurrentRecordSelectedDateToolsMainMenu.ToolTipText = @"There is no date to clear.";
|
||||
}
|
||||
}
|
||||
|
||||
private void clearSelectedDateToolsMainMenu_Click(object sender, EventArgs e)
|
||||
#endregion
|
||||
|
||||
#region Debug Tool Menu Items
|
||||
|
||||
private void DisplayDebugTool(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);
|
||||
if (result == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
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);
|
||||
var actualSales = db.ActualSales.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
var invoices = db.Invoices.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
var weeklySale = db.WeeklySales.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
var taxable = db.Taxables.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
var costAnalysis = db.CostAnalysis.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
var comment = db.Notes.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate);
|
||||
|
||||
using (var scope = new TransactionScope())
|
||||
{
|
||||
try
|
||||
{
|
||||
//Clear projections
|
||||
foreach (var projection in projections)
|
||||
{
|
||||
db.Projections.Remove(projection);
|
||||
}
|
||||
//Clear inventory
|
||||
foreach (var inventory in inventories)
|
||||
{
|
||||
db.Inventories.Remove(inventory);
|
||||
}
|
||||
//Clear actual sales
|
||||
foreach (var sale in actualSales)
|
||||
{
|
||||
db.ActualSales.Remove(sale);
|
||||
}
|
||||
//Clear invoices
|
||||
foreach (var invoice in invoices)
|
||||
{
|
||||
db.Invoices.Remove(invoice);
|
||||
}
|
||||
if (weeklySale != null)
|
||||
{
|
||||
db.WeeklySales.Remove(weeklySale);
|
||||
}
|
||||
if (taxable != null)
|
||||
{
|
||||
db.Taxables.Remove(taxable);
|
||||
}
|
||||
if (costAnalysis != null)
|
||||
{
|
||||
db.CostAnalysis.Remove(costAnalysis);
|
||||
}
|
||||
if (comment != null)
|
||||
{
|
||||
db.Notes.Remove(comment);
|
||||
}
|
||||
db.WeekEndingDates.Remove(dateRecord);
|
||||
db.SaveChanges();
|
||||
scope.Complete();
|
||||
ClearForm();
|
||||
}
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
MessageBox.Show(@"Failed to clear selected date.", @"Error");
|
||||
_console.WriteToLog(FrmLogConsole.Level.Error, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
var form = new DebugDatabaseConverter();
|
||||
form.ShowDialog();
|
||||
RefreshDateListing();
|
||||
var mostRecentDate = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault();
|
||||
if (mostRecentDate != null)
|
||||
{
|
||||
LoadDate(mostRecentDate.EndingDate);
|
||||
}
|
||||
}
|
||||
|
||||
private void addRecordToolStripMenuItem_Click_1(object sender, EventArgs e)
|
||||
/// <summary>
|
||||
/// Displays the legacy Add Record form. Completely for looks.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void DisplayLegacyAddRecord(object sender, EventArgs e)
|
||||
{
|
||||
var form = new FrmAddRecord();
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void rawViewDebugMainMenu_Click(object sender, EventArgs e)
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void DisplayRawDatabaseView(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void adSpecialKeyWordsToolsMainMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
var form = new FrmRegisterAdSpecial();
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
//http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children
|
||||
internal class DrawingControl
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
|
||||
|
||||
private const int WmSetredraw = 11;
|
||||
|
||||
public static void SuspendDrawing(Control parent)
|
||||
{
|
||||
SendMessage(parent.Handle, WmSetredraw, false, 0);
|
||||
}
|
||||
|
||||
public static void ResumeDrawing(Control parent)
|
||||
{
|
||||
SendMessage(parent.Handle, WmSetredraw, true, 0);
|
||||
parent.Refresh();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user