Completely removed all the old database interaction code, save the database converter form. Updated the formatting in the weekly and taxable areas on the modify record form. Re-enabled holiday checking on the main form.
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Entity;
|
||||
using System.Diagnostics;
|
||||
using System.Data.Entity.Infrastructure;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Printing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Transactions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
@@ -20,7 +18,7 @@ namespace AdvertsingProfitControl
|
||||
private decimal _departmentSales; //weekly sales total
|
||||
private DateTime _currentActiveDate;
|
||||
private readonly FrmLogConsole _console = FrmLogConsole.GetStaticInstance;
|
||||
private int _LazyPageCounter;
|
||||
private int _lazyPageCounter;
|
||||
private bool isDebug;
|
||||
|
||||
public FrmMain(bool isDebug)
|
||||
@@ -28,9 +26,8 @@ namespace AdvertsingProfitControl
|
||||
InitializeComponent();
|
||||
this.isDebug = isDebug;
|
||||
isDebug = true;
|
||||
debugToolStripMenuItem.Visible = isDebug;
|
||||
debugMainMenu.Visible = isDebug;
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
db.Versions.Count();
|
||||
}
|
||||
|
||||
private void frmMain_Load(object sender, EventArgs e)
|
||||
@@ -137,15 +134,15 @@ namespace AdvertsingProfitControl
|
||||
|
||||
private void addRecordToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var form = new NewModifyRecord();
|
||||
form.ShowDialog();
|
||||
//One the user has closed the add record form, check to see if there is a newer date
|
||||
//available. If so, reload the form.
|
||||
var date = databaseReader.RetrieveMostRecentDate(databaseTracker.DatabaseConnectionString);
|
||||
if (date == _currentActiveDate) return;
|
||||
LoadDate(date);
|
||||
var date = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault();
|
||||
if (date == null) return;
|
||||
if (date.EndingDate == _currentActiveDate) return;
|
||||
LoadDate(date.EndingDate);
|
||||
}
|
||||
|
||||
private void showHideConsoleHelpMainMenu_Click(object sender, EventArgs e)
|
||||
@@ -165,31 +162,34 @@ namespace AdvertsingProfitControl
|
||||
var form = new NewModifyRecord(_currentActiveDate);
|
||||
form.ShowDialog();
|
||||
//On return reload the date that was just modified by the modify record form.
|
||||
LoadDate(monthCalendar.SelectionStart);
|
||||
LoadDate(_currentActiveDate);
|
||||
}
|
||||
|
||||
private void manageItemsToolsMainMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
var adItemManager = new FrmManageAdItems();
|
||||
adItemManager.ShowDialog();
|
||||
//TODO: Bring back Manage Ad Items form and managing AdSpecials.
|
||||
//var adItemManager = new FrmManageAdItems();
|
||||
//adItemManager.ShowDialog();
|
||||
}
|
||||
|
||||
private void dbVersionHelpMainMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
var version = databaseReader.GetDatabaseVersion(databaseTracker.DatabaseConnectionString);
|
||||
|
||||
if (version != "0.0.0.0")
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var version = db.Versions.FirstOrDefault(x => x.Id == 1);
|
||||
if (version == null)
|
||||
{
|
||||
MessageBox.Show(@"The current database's version is " + version + @".", @"Database Version Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
MessageBox.Show(@"Failed to retrieve the version number of the SQL database", @"Database Version Number",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
MessageBox.Show(@"The current database's version is " + version + @".", @"Database Version Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
}
|
||||
|
||||
private void PrintPage(object sender, PrintPageEventArgs e)
|
||||
{
|
||||
Bitmap bitMap;
|
||||
if (_LazyPageCounter == 0)
|
||||
if (_lazyPageCounter == 0)
|
||||
{
|
||||
bitMap = new Bitmap(Application.StartupPath + "\\FrontPage.png");
|
||||
}
|
||||
@@ -210,16 +210,16 @@ namespace AdvertsingProfitControl
|
||||
rect.Width = (int) ((double) bitMap.Width/(double) bitMap.Height*(double) rect.Height);
|
||||
}
|
||||
|
||||
if (_LazyPageCounter == 0)
|
||||
if (_lazyPageCounter == 0)
|
||||
{
|
||||
e.Graphics.DrawImage(bitMap, new Rectangle(0, 25, 850, 1050));
|
||||
_LazyPageCounter++;
|
||||
_lazyPageCounter++;
|
||||
e.HasMorePages = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Graphics.DrawImage(bitMap, new Rectangle(0, 0, 850, 1100));
|
||||
_LazyPageCounter = 0;
|
||||
_lazyPageCounter = 0;
|
||||
e.HasMorePages = false;
|
||||
}
|
||||
}
|
||||
@@ -233,20 +233,20 @@ namespace AdvertsingProfitControl
|
||||
var printDialog = new PrintPreviewDialog();
|
||||
if (!usePreRenderedFilesCheckbox.Checked)
|
||||
{
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
var dateId =
|
||||
databaseReader.RetrieveDateIdByDateString(monthCalendar.SelectionStart.ToShortDateString(),
|
||||
databaseTracker.DatabaseConnectionString);
|
||||
var remaingingSales = _departmentSales - _salesProducedByAdItems;
|
||||
var totalProfitReturnFromReminaingSales = remaingingSales * .3m;
|
||||
var totalProfitReturn = _totalProfitReturnFromAdItems + totalProfitReturnFromReminaingSales;
|
||||
//test.BuildFormFrontCompressedLayout(dateId, _departmentSales, _salesProducedByAdItems, remaingingSales,
|
||||
//_totalProfitReturnFromAdItems, totalProfitReturnFromReminaingSales, totalProfitReturn,
|
||||
//commentsTextBox.Text);
|
||||
test.RenderHtmlToImage();
|
||||
backPageTest.GenerateWeeklyInventoryControlPage(dateId);
|
||||
backPageTest.RenderHtmlToImage();
|
||||
//var databaseTracker = new DatabaseTracker();
|
||||
//var databaseReader = new DatabaseReader();
|
||||
//var dateId =
|
||||
// databaseReader.RetrieveDateIdByDateString(monthCalendar.SelectionStart.ToShortDateString(),
|
||||
// databaseTracker.DatabaseConnectionString);
|
||||
//var remaingingSales = _departmentSales - _salesProducedByAdItems;
|
||||
//var totalProfitReturnFromReminaingSales = remaingingSales * .3m;
|
||||
//var totalProfitReturn = _totalProfitReturnFromAdItems + totalProfitReturnFromReminaingSales;
|
||||
////test.BuildFormFrontCompressedLayout(dateId, _departmentSales, _salesProducedByAdItems, remaingingSales,
|
||||
// //_totalProfitReturnFromAdItems, totalProfitReturnFromReminaingSales, totalProfitReturn,
|
||||
// //commentsTextBox.Text);
|
||||
//test.RenderHtmlToImage();
|
||||
//backPageTest.GenerateWeeklyInventoryControlPage(dateId);
|
||||
//backPageTest.RenderHtmlToImage();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -361,7 +361,12 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
modifyRecordMainMenu.Enabled = true;
|
||||
modifyRecordMainMenu.ToolTipText = @"";
|
||||
var dateRecord = db.WeekEndingDates.Single(x => x.EndingDate == date);
|
||||
var dateRecord = db.WeekEndingDates.SingleOrDefault(x => x.EndingDate == date);
|
||||
if (dateRecord == null)
|
||||
{
|
||||
dateTimeGroupBox.Text = @"Failed to retrieve " + date.ToString("d") + @".";
|
||||
return;
|
||||
}
|
||||
ClearForm();
|
||||
LoadProjectionsTable(dateRecord);
|
||||
LoadInventoryTable(dateRecord);
|
||||
@@ -575,45 +580,88 @@ namespace AdvertsingProfitControl
|
||||
var weeklySales = db.WeeklySales.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x);
|
||||
foreach (var sale in weeklySales)
|
||||
{
|
||||
if (sale.Sunday != null) _departmentSales += (decimal) sale.Sunday;
|
||||
sundayWeeklySalesLabel.Text = @"Sunday: " + $@"{sale.Sunday:c}";
|
||||
if (sale.Monday != null) _departmentSales += (decimal) sale.Monday;
|
||||
mondayWeeklySalesLabel.Text = @"Monday: " + $@"{sale.Monday:c}";
|
||||
if (sale.Tuesday != null) _departmentSales += (decimal) sale.Tuesday;
|
||||
tuesadayWeeklySalesLabel.Text = @"Tuesday: " + $@"{sale.Tuesday:c}";
|
||||
if (sale.Wednesday != null) _departmentSales += (decimal) sale.Wednesday;
|
||||
wednesdayWeeklySalesLabel.Text = @"Wednesday: " + $@"{sale.Wednesday:c}";
|
||||
if (sale.Thursday != null) _departmentSales += (decimal)sale.Thursday;
|
||||
thursdayWeeklySalesLabel.Text = @"Thursday: " + $@"{sale.Thursday:c}";
|
||||
if (sale.Friday != null) _departmentSales += (decimal) sale.Friday;
|
||||
fridayWeeklySalesLabel.Text = @"Friday: " + $@"{sale.Friday:c}";
|
||||
if (sale.Saturday != null) _departmentSales += (decimal) sale.Saturday;
|
||||
saturdayWeeklySalesLabel.Text = @"Saturday: " + $@"{sale.Saturday:c}";
|
||||
if (sale.Sunday != null)
|
||||
{
|
||||
sundayWeeklySalesLabel.Text = sale.Sunday != 0
|
||||
? @"Sunday: " + $@"{sale.Sunday:c}"
|
||||
: @"Sunday: " + CheckForHoliday(DayOfWeek.Sunday);
|
||||
_departmentSales += (decimal) sale.Sunday;
|
||||
}
|
||||
if (sale.Monday != null)
|
||||
{
|
||||
mondayWeeklySalesLabel.Text = sale.Monday != 0
|
||||
? @"Monday: " + $@"{sale.Monday:c}"
|
||||
: @"Monday: " + CheckForHoliday(DayOfWeek.Monday);
|
||||
_departmentSales += (decimal) sale.Monday;
|
||||
}
|
||||
if (sale.Tuesday != null)
|
||||
{
|
||||
tuesadayWeeklySalesLabel.Text = sale.Tuesday != 0
|
||||
? @"Tuesday: " + $@"{sale.Tuesday:c}"
|
||||
: @"Tuesday: " + CheckForHoliday(DayOfWeek.Tuesday);
|
||||
_departmentSales += (decimal) sale.Tuesday;
|
||||
}
|
||||
if (sale.Wednesday != null)
|
||||
{
|
||||
wednesdayWeeklySalesLabel.Text = sale.Wednesday != 0
|
||||
? @"Wednesday: " + $@"{sale.Wednesday:c}"
|
||||
: @"Wednesday: " + CheckForHoliday(DayOfWeek.Wednesday);
|
||||
_departmentSales += (decimal) sale.Wednesday;
|
||||
}
|
||||
if (sale.Thursday != null)
|
||||
{
|
||||
thursdayWeeklySalesLabel.Text = sale.Thursday != 0
|
||||
? @"Thursday: " + $@"{sale.Thursday:c}"
|
||||
: @"Thursday: " + CheckForHoliday(DayOfWeek.Thursday);
|
||||
_departmentSales += (decimal)sale.Thursday;
|
||||
}
|
||||
if (sale.Friday != null)
|
||||
{
|
||||
fridayWeeklySalesLabel.Text = sale.Friday != 0
|
||||
? @"Friday: " + $@"{sale.Friday:c}"
|
||||
: @"Friday: " + CheckForHoliday(DayOfWeek.Friday);
|
||||
_departmentSales += (decimal) sale.Friday;
|
||||
}
|
||||
if (sale.Saturday != null)
|
||||
{
|
||||
saturdayWeeklySalesLabel.Text = sale.Saturday != 0
|
||||
? @"Saturday: " + $@"{sale.Saturday:c}"
|
||||
: @"Saturday: " + CheckForHoliday(DayOfWeek.Saturday);
|
||||
_departmentSales += (decimal) sale.Saturday;
|
||||
}
|
||||
totalWeeklySalesLabel.Text = @"Total Sales: " + $@"{sale.TotalSales:c}";
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadTaxable(WeekEndingDate dateRecord)
|
||||
{
|
||||
//TODO: Check for holidays
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var taxables = db.Taxables.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x);
|
||||
foreach (var taxable in taxables)
|
||||
{
|
||||
sundayTaxableLabel.Text = @"Sunday: " + $@"{taxable.Sunday:c}";
|
||||
mondayTaxableLabel.Text = @"Monday: " + $@"{taxable.Monday:c}";
|
||||
tuesdayTaxableLabel.Text = @"Tuesday: " + $@"{taxable.Tuesday:c}";
|
||||
wednesdayTaxableLabel.Text = @"Wednesday: " + $@"{taxable.Wednesday:c}";
|
||||
thursdayTaxableLabel.Text = @"Thursday: " + $@"{taxable.Thursday:c}";
|
||||
fridayTaxableLabel.Text = @"Friday: " + $@"{taxable.Friday:c}";
|
||||
saturdayTaxableLabel.Text = @"Saturday: " + $@"{taxable.Saturday:c}";
|
||||
sundayTaxableLabel.Text = taxable.Sunday != 0
|
||||
? @"Sunday: " + $@"{taxable.Sunday:c}"
|
||||
: @"Sunday: " + CheckForHoliday(DayOfWeek.Sunday);
|
||||
mondayTaxableLabel.Text = taxable.Monday != 0
|
||||
? @"Monday: " + $@"{taxable.Monday:c}"
|
||||
: @"Monday: " + CheckForHoliday(DayOfWeek.Monday);
|
||||
tuesdayTaxableLabel.Text = taxable.Tuesday != 0
|
||||
? @"Tuesday: " + $@"{taxable.Tuesday:c}"
|
||||
: @"Tuesday: " + CheckForHoliday(DayOfWeek.Tuesday);
|
||||
wednesdayTaxableLabel.Text = taxable.Wednesday != 0
|
||||
? @"Wednesday: " + $@"{taxable.Wednesday:c}"
|
||||
: @"Wednesday: " + CheckForHoliday(DayOfWeek.Wednesday);
|
||||
thursdayTaxableLabel.Text = taxable.Thursday != 0
|
||||
? @"Thursday: " + $@"{taxable.Thursday:c}"
|
||||
: @"Thursday: " + CheckForHoliday(DayOfWeek.Thursday);
|
||||
fridayTaxableLabel.Text = taxable.Friday != 0
|
||||
? @"Friday: " + $@"{taxable.Friday:c}"
|
||||
: @"Friday: " + CheckForHoliday(DayOfWeek.Friday);
|
||||
saturdayTaxableLabel.Text = taxable.Saturday != 0
|
||||
? @"Saturday: " + $@"{taxable.Saturday:c}"
|
||||
: @"Saturday: " + CheckForHoliday(DayOfWeek.Saturday);
|
||||
totalTaxableLabel.Text = @"Total: " + $@"{taxable.Total:c}";
|
||||
}
|
||||
////See if there are any items and see if any of them are holidays (have a value of zero).
|
||||
//if (taxables.ToList().Count == 1)
|
||||
//{
|
||||
// var Spam = taxables.Select(x => x.)
|
||||
//}
|
||||
}
|
||||
|
||||
private void LoadCostAnalysis(WeekEndingDate dateRecord)
|
||||
@@ -665,8 +713,8 @@ namespace AdvertsingProfitControl
|
||||
switch (holiday)
|
||||
{
|
||||
case Holidays.Thanksgiving:
|
||||
case Holidays.Christmas:
|
||||
case Holidays.NewYearsDay:
|
||||
case Holidays.Christmas:
|
||||
case Holidays.NewYearsDay:
|
||||
holidayText = @"Closed for " + TextFormat.AddSpacesToSentence(holiday.ToString(), false);
|
||||
break;
|
||||
}
|
||||
@@ -735,15 +783,8 @@ namespace AdvertsingProfitControl
|
||||
|
||||
private void RefreshDateListing()
|
||||
{
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
monthCalendar.BoldedDates = databaseReader.RetrieveDates(databaseTracker.DatabaseConnectionString).ToArray();
|
||||
}
|
||||
|
||||
public enum FormDefaultRoll
|
||||
{
|
||||
AddNewRecord = 0,
|
||||
ModifyExistingRecord = 1
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
monthCalendar.BoldedDates = db.WeekEndingDates.Select(zdate => zdate.EndingDate).ToArray();
|
||||
}
|
||||
|
||||
private void clearSelectedDateToolsMainMenu_Click(object sender, EventArgs e)
|
||||
@@ -753,27 +794,82 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
return;
|
||||
}
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
var dbR = new DatabaseReader();
|
||||
var dateId = dbR.RetrieveDateIdByDateString(_currentActiveDate.ToShortDateString(), dbT.DatabaseConnectionString);
|
||||
if (dateId != 0)
|
||||
|
||||
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())
|
||||
{
|
||||
if (dbW.ClearDateById(dateId))
|
||||
try
|
||||
{
|
||||
RefreshDateListing();
|
||||
var date = dbR.RetrieveMostRecentDate(dbT.DatabaseConnectionString);
|
||||
LoadDate(date);
|
||||
//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();
|
||||
}
|
||||
else
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
errorLabel.Text = @"Failed to clear the selected date.";
|
||||
MessageBox.Show(@"Failed to clear selected date.", @"Error");
|
||||
_console.WriteToLog(FrmLogConsole.Level.Error, ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to get the date ID number.";
|
||||
}
|
||||
|
||||
RefreshDateListing();
|
||||
LoadDate(db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault().EndingDate);
|
||||
}
|
||||
|
||||
private void addRecordToolStripMenuItem_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
var form = new FrmAddRecord();
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void rawViewDebugMainMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user