Updated the main form to allow the user to be able to select dates from the database. Updated information displaying on the main form.

This commit is contained in:
2017-01-21 19:15:26 -06:00
parent 96e61546c3
commit db200e31b2
4 changed files with 88 additions and 36 deletions
+76 -10
View File
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace AdvertsingProfitControl
@@ -17,8 +15,9 @@ namespace AdvertsingProfitControl
private double _totalProfitReturnFromAdItems;
private double _totalInvoicePurchases; //Total Purchases
private double _departmentSales; //weekly sales total
private DateTime _currentActiveDate;
readonly FrmLogConsole _console = FrmLogConsole.GetStaticInstance;
private int _LazyPageCounter = 0;
private int _LazyPageCounter;
public FrmMain()
{
@@ -29,14 +28,15 @@ namespace AdvertsingProfitControl
{
var databaseTracker = new DatabaseTracker();
var databaseReader = new DatabaseReader();
monthCalendar.BoldedDates = databaseReader.RetrieveDates(databaseTracker.DatabaseConnectionString).ToArray();
RowParsing.AdSpecialGroups.AddRange(databaseReader.ReturnGroupNameList(databaseTracker.DatabaseConnectionString));
ConstructApcDataGridViews();
ConstructInvoicesDataGridView();
var date = databaseReader.RetrieveMostRecentDate(databaseTracker.DatabaseConnectionString);
monthCalendar.SelectionStart = date;
_currentActiveDate = date;
LoadDate(date);
CalculateProfitAnalysis();
CalculateGrossProfit();
monthCalendar.DateChanged += ValidateDateChanged;
//projectionsDataGridView.KeyDown += FrmMain_KeyDown;
//var margin = new Margins(50, 50, 0, 0);
//_printDoc.DefaultPageSettings.Margins = margin;
@@ -44,6 +44,16 @@ namespace AdvertsingProfitControl
private void CalculateProfitAnalysis(double shrink = 0.30)
{
if (actualSalesDataGridView.Rows.Count == 0)
{
salesProducedLabel.Text = @"Sales Produced By Ad Items (A): No Data";
totalProfitFromAdItemsLabel.Text = @"Total Profit Return From Ad Items (B): No Data";
if (Math.Abs(_departmentSales) < 1)
{
departmentSalesLabel.Text = @"Department Sales: No Data";
}
return;
}
var incompleteData = false;
//First grab the total sales and the total profit return generated by the actual sales of product.
if (
@@ -357,7 +367,7 @@ namespace AdvertsingProfitControl
errorLabel.Text = @"Failed to get the date ID number, aborting load operation." + Environment.NewLine;
return;
}
informationLabel.Text = @"Loading data for " + date.ToString("d") + "." + Environment.NewLine;
ClearForm();
var projections = databaseReader.ReturnProjectionsTable(dateId, databaseTracker.DatabaseConnectionString);
var inventory = databaseReader.ReturnInventoryTable(dateId, databaseTracker.DatabaseConnectionString);
var actualSales = databaseReader.ReturnActualSales(dateId, databaseTracker.DatabaseConnectionString);
@@ -374,7 +384,7 @@ namespace AdvertsingProfitControl
}
else
{
informationLabel.Text += @"No comments to display." + Environment.NewLine;
commentMainGroupBox.Text = @"Comments (None to Display)";
}
var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId,
databaseTracker.DatabaseConnectionString);
@@ -384,7 +394,7 @@ namespace AdvertsingProfitControl
}
else
{
informationLabel.Text += @"No sales to display." + Environment.NewLine;
weeklySalesGroupBox.Text = @"Weekly Sales (Nothing to Display)";
}
var taxable = databaseReader.ReturnTaxableFromDateId(dateId, databaseTracker.DatabaseConnectionString);
@@ -394,7 +404,7 @@ namespace AdvertsingProfitControl
}
else
{
informationLabel.Text += @"No taxable data to display." + Environment.NewLine;
taxableGroupBox.Text = @"Taxable (Nothing to Display)";
}
var costAnalysis = databaseReader.ReturnCostAnalysis(dateId,
databaseTracker.DatabaseConnectionString);
@@ -404,8 +414,11 @@ namespace AdvertsingProfitControl
}
else
{
informationLabel.Text += @"No cost analysis data to display." + Environment.NewLine;
costAnalysisGroupBox.Text = @"Cost Analysis (Nothing to Display)";
}
CalculateProfitAnalysis();
CalculateGrossProfit();
dateTimeGroupBox.Text = @"Loaded " + date.ToString("d");
}
private void LoadProjectionsTable(DataTable projections)
@@ -1148,6 +1161,59 @@ namespace AdvertsingProfitControl
}
return holidayText;
}
private void ValidateDateChanged(object sender, DateRangeEventArgs e)
{
if (e.Start == _currentActiveDate || !monthCalendar.BoldedDates.Contains(e.Start)) return;
_currentActiveDate = e.Start;
//Load the specified date from the database.
LoadDate(e.Start);
}
private void ClearForm()
{
projectionsDataGridView.Rows.Clear();
inventoryDataGridView.Rows.Clear();
actualSalesDataGridView.Rows.Clear();
invoicesDataGridView.Rows.Clear();
commentsTextBox.Text = string.Empty;
commentMainGroupBox.Text = @"Comments";
dateTimeGroupBox.Text = string.Empty;
salesPerManHourLabel.Text = @"Sales Per Man Hour:";
salaryPercentageLabel.Text = @"Salary Percentage:";
salaryDollarsLabel.Text = @"Salary Dollars:";
suppliesLabel.Text = @"Supplies:";
costAnalysisGroupBox.Text = @"Cost Analysis";
sundayWeeklySalesLabel.Text = @"Sunday: ";
mondayWeeklySalesLabel.Text = @"Monday: ";
tuesadayWeeklySalesLabel.Text = @"Tuesday: ";
wednesdayWeeklySalesLabel.Text = @"Wednesday: ";
thursdayWeeklySalesLabel.Text = @"Wednesday: ";
fridayWeeklySalesLabel.Text = @"Friday: ";
saturdayWeeklySalesLabel.Text = @"Saturday: ";
totalWeeklySalesLabel.Text = @"Total Sales: ";
weeklySalesGroupBox.Text = @"Weekly Sales";
sundayTaxableLabel.Text = @"Sunday: ";
mondayTaxableLabel.Text = @"Monday: ";
tuesdayTaxableLabel.Text = @"Tuesday: ";
wednesdayTaxableLabel.Text = @"Wednesday: ";
thursdayTaxableLabel.Text = @"Wednesday: ";
fridayTaxableLabel.Text = @"Friday: ";
saturdayTaxableLabel.Text = @"Saturday: ";
totalTaxableLabel.Text = @"Total: ";
taxableGroupBox.Text = @"Taxable";
departmentSalesLabel.Text = @"Department Sales: ";
salesProducedLabel.Text = @"Sales Produced By Ad Items (A):";
remainingSalesLabel.Text = @"Remaining Sales:";
totalProfitFromAdItemsLabel.Text = @"Total Profit Return From Ad Items (B): ";
totalProfitReturnFromRemaingLabel.Text = @"Total Profit Return From Remaining Sales: ";
totalProfitReturnLabel.Text = @"Total Profit Return: ";
grossProfitTotalSales.Text = @"Total Sales:";
grossProfitLessCostOfSales.Text = @"Less Cost of Sales: ";
grossProfitDollarGrossProfitLabel.Text = @"Dollar Gross Profit: ";
perfectGrossProfitLabel.Text = @"Percent Gross Profit: ";
grossProfitEstimatedWeeklyDeptmartmentExpenseLabel.Text = @"Estimated Weekly Department Expense: ";
}
}
}
//http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children