Updated the main form with a slightly new look. Finished all the code for the main for to pull in all the data from the database and perform calculations on it. Currently can only load the most recent date. Added detection for holidays in the weekly and taxable lists.
This commit is contained in:
@@ -2171,6 +2171,14 @@ namespace AdvertsingProfitControl
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
//Save the changes made to the database then clear and load the date picked by the user.
|
||||
if (SaveRecords(false))
|
||||
{
|
||||
informationLabel.Text = @"Saved all changes successfully." + Environment.NewLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to save all changes." + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
else if (result == DialogResult.Cancel)
|
||||
{
|
||||
@@ -2253,9 +2261,6 @@ namespace AdvertsingProfitControl
|
||||
salaryDollarsTextBox.Validating -= ValidateCostAnalysisValues;
|
||||
suppliesTextBox.Enter -= StoreBeginningTextBoxValue;
|
||||
suppliesTextBox.Validating -= ValidateCostAnalysisValues;
|
||||
//Clear errors and information.
|
||||
informationLabel.Text = string.Empty;
|
||||
errorLabel.Text = string.Empty;
|
||||
//Clear projections
|
||||
projectionsDataGridView.Rows.Clear();
|
||||
//Clear inventory
|
||||
@@ -2387,13 +2392,19 @@ namespace AdvertsingProfitControl
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
var dateId = databaseReader.RetrieveDateIdByDateString(date.ToString("d"), databaseTracker.DatabaseConnectionString);
|
||||
var projections = databaseReader.ReturnProjectionsTable(dateId.ToString(), databaseTracker.DatabaseConnectionString);
|
||||
var inventory = databaseReader.ReturnInventoryTable(dateId.ToString(), databaseTracker.DatabaseConnectionString);
|
||||
var actualSales = databaseReader.ReturnActualSales(dateId.ToString(), databaseTracker.DatabaseConnectionString);
|
||||
if (dateId == 0)
|
||||
{
|
||||
errorLabel.Text = @"Failed to get the date ID number, aborting load operation." + Environment.NewLine;
|
||||
return;
|
||||
}
|
||||
informationLabel.Text = @"Loading data for " + _currentActiveDate.ToString("d") + "." + Environment.NewLine;
|
||||
var projections = databaseReader.ReturnProjectionsTable(dateId, databaseTracker.DatabaseConnectionString);
|
||||
var inventory = databaseReader.ReturnInventoryTable(dateId, databaseTracker.DatabaseConnectionString);
|
||||
var actualSales = databaseReader.ReturnActualSales(dateId, databaseTracker.DatabaseConnectionString);
|
||||
LoadProjectionsTable(projections);
|
||||
LoadInventory(inventory);
|
||||
LoadActualSales(actualSales);
|
||||
var invoices = databaseReader.ReturnInvoiceTable(dateId.ToString(), databaseTracker.DatabaseConnectionString);
|
||||
var invoices = databaseReader.ReturnInvoiceTable(dateId, databaseTracker.DatabaseConnectionString);
|
||||
var comments = databaseReader.RetrieveComments(int.Parse(dateId.ToString()), databaseTracker.DatabaseConnectionString);
|
||||
if (comments.Count == 2)
|
||||
{
|
||||
@@ -2403,7 +2414,7 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
informationLabel.Text += @"No comments to display." + Environment.NewLine;
|
||||
}
|
||||
var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId.ToString(),
|
||||
var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId,
|
||||
databaseTracker.DatabaseConnectionString);
|
||||
if (weeklySales.Rows.Count == 1)
|
||||
{
|
||||
@@ -2414,7 +2425,7 @@ namespace AdvertsingProfitControl
|
||||
informationLabel.Text += @"No sales to display." + Environment.NewLine;
|
||||
}
|
||||
|
||||
var taxable = databaseReader.ReturnTaxableFromDateId(dateId.ToString(), databaseTracker.DatabaseConnectionString);
|
||||
var taxable = databaseReader.ReturnTaxableFromDateId(dateId, databaseTracker.DatabaseConnectionString);
|
||||
if (taxable.Rows.Count == 1)
|
||||
{
|
||||
LoadTaxable(taxable);
|
||||
@@ -2463,7 +2474,7 @@ namespace AdvertsingProfitControl
|
||||
//Everything in between the ad item cell and the row attribute cells.
|
||||
if (cellIndex > 1 && cellIndex <= 7)
|
||||
{
|
||||
if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
|
||||
if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0.0000")
|
||||
{
|
||||
var cell = new DataGridViewTextBoxCell {Value = string.Empty};
|
||||
newRow.Cells.Add(cell);
|
||||
@@ -2656,7 +2667,7 @@ namespace AdvertsingProfitControl
|
||||
inventoryDataGridView.RowValidating += ValidateInventoryRow;
|
||||
}
|
||||
|
||||
public void LoadActualSales(DataTable actualSales)
|
||||
private void LoadActualSales(DataTable actualSales)
|
||||
{
|
||||
//Assuming all the tables are correctly aligned.
|
||||
//Disable the relevant events in the DataGridViews
|
||||
@@ -2685,7 +2696,7 @@ namespace AdvertsingProfitControl
|
||||
//Everything in between the ad item cell and the row attribute cells.
|
||||
if (cellIndex > 1 && cellIndex <= 7)
|
||||
{
|
||||
if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
|
||||
if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0.0000")
|
||||
{
|
||||
var cell = new DataGridViewTextBoxCell { Value = string.Empty };
|
||||
newRow.Cells.Add(cell);
|
||||
@@ -3295,11 +3306,11 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
errorLabel.Text += @"Failed to process actual sales." + Environment.NewLine;
|
||||
}
|
||||
if (!SaveInvoices(dateId)) return false;
|
||||
if (!SaveComments(dateId)) return false;
|
||||
if (!SaveWeeklySales(dateId)) return false;
|
||||
if (!SaveTaxable(dateId)) return false;
|
||||
return SaveCostAnalysis(dateId) && success;
|
||||
if (!SaveInvoices(dateId, displayInformation)) return false;
|
||||
if (!SaveComments(dateId, displayInformation)) return false;
|
||||
if (!SaveWeeklySales(dateId, displayInformation)) return false;
|
||||
if (!SaveTaxable(dateId, displayInformation)) return false;
|
||||
return SaveCostAnalysis(dateId, displayInformation) && success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -3329,7 +3340,7 @@ namespace AdvertsingProfitControl
|
||||
return dateId;
|
||||
}
|
||||
|
||||
private bool SaveInvoices(int dateId)
|
||||
private bool SaveInvoices(int dateId, bool displayInformation = true)
|
||||
{
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
@@ -3340,11 +3351,11 @@ namespace AdvertsingProfitControl
|
||||
errorLabel.Text = writerStatus.GetErrorMessage();
|
||||
return false;
|
||||
}
|
||||
informationLabel.Text += writerStatus.GetErrorMessage() + Environment.NewLine;
|
||||
if(displayInformation) informationLabel.Text += writerStatus.GetErrorMessage() + Environment.NewLine;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool SaveComments(int dateId)
|
||||
private bool SaveComments(int dateId, bool displayInformation = true)
|
||||
{
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
@@ -3356,11 +3367,10 @@ namespace AdvertsingProfitControl
|
||||
var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString);
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Comments to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
return false;
|
||||
}
|
||||
informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine;
|
||||
if(displayInformation) informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine;
|
||||
var id = status.Id;
|
||||
isCommentDirtyCheckBox.Tag = id;
|
||||
isCommentDirtyCheckBox.Text = @"IsCommentDirty (" + id + @")";
|
||||
@@ -3375,20 +3385,19 @@ namespace AdvertsingProfitControl
|
||||
int.Parse(isCommentDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Comments to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
return false;
|
||||
}
|
||||
isCommentDirtyCheckBox.Checked = false;
|
||||
informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
informationLabel.Text += @"No changes detected for the comment(s)" + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"No changes detected for the comment(s)" + Environment.NewLine;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool SaveWeeklySales(int dateId)
|
||||
private bool SaveWeeklySales(int dateId, bool displayInformation = true)
|
||||
{
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
@@ -3416,11 +3425,10 @@ namespace AdvertsingProfitControl
|
||||
var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString);
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Weekly Sales to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
return false;
|
||||
}
|
||||
informationLabel.Text += @"Weekly Sales processed successfully." + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"Weekly Sales processed successfully." + Environment.NewLine;
|
||||
isWeeklySalesDirtyCheckBox.Tag = status.Id;
|
||||
isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty (" + status.Id + @")";
|
||||
isWeeklySalesDirtyCheckBox.Checked = false;
|
||||
@@ -3432,20 +3440,19 @@ namespace AdvertsingProfitControl
|
||||
int.Parse(isWeeklySalesDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Weekly Sales to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
return false;
|
||||
}
|
||||
isWeeklySalesDirtyCheckBox.Checked = false;
|
||||
informationLabel.Text += @"Weekly Sales updated successfully." + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"Weekly Sales updated successfully." + Environment.NewLine;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
informationLabel.Text += @"No changes detected for Weekly Sales." + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"No changes detected for Weekly Sales." + Environment.NewLine;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool SaveTaxable(int dateId)
|
||||
private bool SaveTaxable(int dateId, bool displayInformation = true)
|
||||
{
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
@@ -3469,11 +3476,10 @@ namespace AdvertsingProfitControl
|
||||
var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString);
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Taxable to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
return false;
|
||||
}
|
||||
informationLabel.Text += @"Taxable processed successfully." + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"Taxable processed successfully." + Environment.NewLine;
|
||||
isTaxableDirtyCheckBox.Tag = status.Id;
|
||||
isTaxableDirtyCheckBox.Text = @"IsTaxableDirty (" + status.Id + @")";
|
||||
return true;
|
||||
@@ -3484,20 +3490,19 @@ namespace AdvertsingProfitControl
|
||||
int.Parse(isTaxableDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Taxable to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
return false;
|
||||
}
|
||||
isTaxableDirtyCheckBox.Checked = false;
|
||||
informationLabel.Text += @"Taxable updated successfully." + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"Taxable updated successfully." + Environment.NewLine;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
informationLabel.Text += @"No changes detected for Taxable." + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"No changes detected for Taxable." + Environment.NewLine;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool SaveCostAnalysis(int dateId)
|
||||
private bool SaveCostAnalysis(int dateId, bool displayInformation = true)
|
||||
{
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
@@ -3517,11 +3522,10 @@ namespace AdvertsingProfitControl
|
||||
var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString);
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Cost Analysis to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
return false;
|
||||
}
|
||||
informationLabel.Text += @"Costs Analysis processed successfully." + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"Costs Analysis processed successfully." + Environment.NewLine;
|
||||
isCostAnalysisDirtyCheckBox.Tag = status.Id;
|
||||
isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty (" + status.Id + @")";
|
||||
isCostAnalysisDirtyCheckBox.Checked = false;
|
||||
@@ -3533,16 +3537,15 @@ namespace AdvertsingProfitControl
|
||||
int.Parse(isCostAnalysisDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Cost Analysis to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
return false;
|
||||
}
|
||||
isCostAnalysisDirtyCheckBox.Checked = false;
|
||||
informationLabel.Text += @"Cost Analysis updated successfully." + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"Cost Analysis updated successfully." + Environment.NewLine;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
informationLabel.Text += @"No changes made to Cost Analysis." + Environment.NewLine;
|
||||
if (displayInformation) informationLabel.Text += @"No changes made to Cost Analysis." + Environment.NewLine;
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user