|
|
|
@@ -37,7 +37,6 @@ namespace AdvertsingProfitControl
|
|
|
|
|
private DateTime _currentActiveDate;
|
|
|
|
|
//
|
|
|
|
|
private bool _isFormDirty;
|
|
|
|
|
private TabPage _debugTabPage;
|
|
|
|
|
|
|
|
|
|
public NewModifyRecord(DateTime date)
|
|
|
|
|
{
|
|
|
|
@@ -156,12 +155,134 @@ namespace AdvertsingProfitControl
|
|
|
|
|
suppliesTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
suppliesTextBox.Validating += ValidateCostAnalysisValues;
|
|
|
|
|
//
|
|
|
|
|
_debugTabPage = mainTabControl.TabPages[4];
|
|
|
|
|
mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]);
|
|
|
|
|
Text = @"Modify Record (Current Record: " + date.ToString("d") + @")";
|
|
|
|
|
//_debugTabPage = mainTabControl.TabPages[4];
|
|
|
|
|
//mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]);
|
|
|
|
|
Text = @"Modify Record (Current Record: " + date.ToShortDateString() + @")";
|
|
|
|
|
LoadDate(date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NewModifyRecord()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
//Start by grabbing all the AdItems and putting them into memory.
|
|
|
|
|
var databaseTracker = new DatabaseTracker();
|
|
|
|
|
var databaseReader = new DatabaseReader();
|
|
|
|
|
weekEndingCalendar.BoldedDates = databaseReader.RetrieveDates(databaseTracker.DatabaseConnectionString).ToArray();
|
|
|
|
|
SetNewRecordDate(databaseReader.RetrieveMostRecentDate(databaseTracker.DatabaseConnectionString), 2);
|
|
|
|
|
_currentActiveDate = weekEndingCalendar.SelectionStart;
|
|
|
|
|
//next pull all the ad items into memory.
|
|
|
|
|
_adItemCollection = databaseReader.GetAdItemsSuggestionList(databaseTracker.DatabaseConnectionString);
|
|
|
|
|
//Now pull all the suppliers and the ad special list into memory.
|
|
|
|
|
_supplierCollection = databaseReader.GetSupplierSuggestionList(databaseTracker.DatabaseConnectionString);
|
|
|
|
|
_adSpecialList = databaseReader.RetrieveAdSpecialList(databaseTracker.DatabaseConnectionString);
|
|
|
|
|
//Initialize the used ad item collection.
|
|
|
|
|
_usedAdItems[0] = new List<string>();
|
|
|
|
|
_usedAdItems[1] = new List<string>();
|
|
|
|
|
//Assign the events for the comments text box and display the remaining character count for the user.
|
|
|
|
|
commentsTextBox.TextChanged += DisplayRemainingCommentCharacterCount;
|
|
|
|
|
commentsGroupBox.Text = @"Comments (Characters Remaining: " + commentsTextBox.MaxLength + @")";
|
|
|
|
|
//Setup the events for that the Projected and Actual Sales DataGridViews will share.
|
|
|
|
|
//Events are assigned with regard to which event gets triggered first and so on..
|
|
|
|
|
//Hook the row add event so we can paint a row number in the header cell of the row.
|
|
|
|
|
projectionsDataGridView.RowsAdded += DisplayRowNumbers;
|
|
|
|
|
inventoryDataGridView.RowsAdded += DisplayRowNumbers;
|
|
|
|
|
actualSalesDataGridView.RowsAdded += DisplayRowNumbers;
|
|
|
|
|
//Assign all the tables to store the cell's contents on enter so changes (if any) can be detected and flagged (marked as dirty).
|
|
|
|
|
projectionsDataGridView.CellEnter += StoreBeginningCellValue;
|
|
|
|
|
inventoryDataGridView.CellEnter += StoreBeginningCellValue;
|
|
|
|
|
actualSalesDataGridView.CellEnter += StoreBeginningCellValue;
|
|
|
|
|
//Update the contents of the used as item list on row leave.
|
|
|
|
|
projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
|
|
|
|
|
inventoryDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
|
|
|
|
|
actualSalesDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
|
|
|
|
|
//Validate, clean and format the contents of the cell that fires the cell validating event.
|
|
|
|
|
projectionsDataGridView.CellValidating += ValidateSalesDataGridViewCellContents;
|
|
|
|
|
inventoryDataGridView.CellValidating += ValidateInventoryCellContents;
|
|
|
|
|
actualSalesDataGridView.CellValidating += ValidateSalesDataGridViewCellContents;
|
|
|
|
|
//Validate that the row the user is trying to leave is legal (has at least an ad item entered) and prevent the user from leaving the row is its not.
|
|
|
|
|
projectionsDataGridView.RowValidating += ValidateProjectedRow;
|
|
|
|
|
inventoryDataGridView.RowValidating += ValidateInventoryRow;
|
|
|
|
|
actualSalesDataGridView.RowValidating += ValidateActualSalesRow;
|
|
|
|
|
//Update the used ad item collection by removing the contents of the ad item column when a row is deleted.
|
|
|
|
|
projectionsDataGridView.UserDeletingRow += UpdateUsedAdItemCollectionOnRowRemoving;
|
|
|
|
|
inventoryDataGridView.UserDeletingRow += UpdateUsedAdItemCollectionOnRowRemoving;
|
|
|
|
|
actualSalesDataGridView.UserDeletingRow += UpdateUsedAdItemCollectionOnRowRemoving;
|
|
|
|
|
//Once a row has been removed update the other tables keep them uniform.
|
|
|
|
|
projectionsDataGridView.RowsRemoved += ProjectionRowRemoved;
|
|
|
|
|
inventoryDataGridView.RowsRemoved += InventoryRowRemoved;
|
|
|
|
|
actualSalesDataGridView.RowsRemoved += ActualSalesRowRemoved;
|
|
|
|
|
//Grab the underlying text box object in the ad item cell, and build an auto complete list for the user.
|
|
|
|
|
projectionsDataGridView.EditingControlShowing += DisplayAutoCompleteOnEditingControlShowing;
|
|
|
|
|
inventoryDataGridView.EditingControlShowing += DisplayAutoCompleteOnEditingControlShowing;
|
|
|
|
|
actualSalesDataGridView.EditingControlShowing += DisplayAutoCompleteOnEditingControlShowing;
|
|
|
|
|
//After all events have been set, construct the DataGridVeiws for use.
|
|
|
|
|
ConstructApcDataGridViews();
|
|
|
|
|
//Set-up events for the Invoice table.
|
|
|
|
|
invoicesDataGridView.CellEnter += StoreBeginningCellValue;
|
|
|
|
|
//Validate that the row the user is trying to leave is legal (has at least an ad item entered) and prevent the user from leaving the row is its not.
|
|
|
|
|
invoicesDataGridView.RowValidating += ValidateInvoiceRow;
|
|
|
|
|
//Validate, clean and format the contents of the cell that fires the cell validating event.
|
|
|
|
|
invoicesDataGridView.CellValidating += ValidateInvoicesCellContents;
|
|
|
|
|
//Grab the underlying text box object in the ad item cell, and build an auto complete list for the user.
|
|
|
|
|
invoicesDataGridView.EditingControlShowing += DisplaySupplierAutoComleteOnEditingShadowControl;
|
|
|
|
|
//Subscribe the method to allow the user to delete saved rows from the Invoices table.
|
|
|
|
|
invoicesDataGridView.UserDeletingRow += UpdateInvoicesOnRowDeleting;
|
|
|
|
|
//Finally build the last DataGridView for the form.
|
|
|
|
|
ConstructInvoicesDataGridView();//No weekly sales table is nice.
|
|
|
|
|
//Subscribe the comments text box to check if changes have been made on leave.
|
|
|
|
|
commentsTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
commentsTextBox.KeyDown += CheckForKeyCommand;
|
|
|
|
|
commentsTextBox.Leave += CheckForTextChangeOnLeave;
|
|
|
|
|
//Subscribe the weekly sales text boxes to validation, update required checks and auto-complete methods.
|
|
|
|
|
sundayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
sundayWeeklySalesTextBox.Validating += ValidateWeeklySales;
|
|
|
|
|
mondayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
mondayWeeklySalesTextBox.Validating += ValidateWeeklySales;
|
|
|
|
|
tuesdayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
tuesdayWeeklySalesTextBox.Validating += ValidateWeeklySales;
|
|
|
|
|
wednesdayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
wednesdayWeeklySalesTextBox.Validating += ValidateWeeklySales;
|
|
|
|
|
thursdayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
thursdayWeeklySalesTextBox.Validating += ValidateWeeklySales;
|
|
|
|
|
fridayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
fridayWeeklySalesTextBox.Validating += ValidateWeeklySales;
|
|
|
|
|
saturdayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
saturdayWeeklySalesTextBox.Validating += ValidateWeeklySales;
|
|
|
|
|
totalWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
totalWeeklySalesTextBox.Validating += ValidateWeeklySales;
|
|
|
|
|
//Subscribe the taxable text boxes to validation and update events.
|
|
|
|
|
sundayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
sundayTaxableTextBox.Validating += ValidateTaxableFields;
|
|
|
|
|
mondayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
mondayTaxableTextBox.Validating += ValidateTaxableFields;
|
|
|
|
|
tuesdayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
tuesdayTaxableTextBox.Validating += ValidateTaxableFields;
|
|
|
|
|
wednesdayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
wednesdayTaxableTextBox.Validating += ValidateTaxableFields;
|
|
|
|
|
thursdayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
thursdayTaxableTextBox.Validating += ValidateTaxableFields;
|
|
|
|
|
fridayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
fridayTaxableTextBox.Validating += ValidateTaxableFields;
|
|
|
|
|
saturdayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
saturdayTaxableTextBox.Validating += ValidateTaxableFields;
|
|
|
|
|
totalTaxableTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
totalTaxableTextBox.Validating += ValidateTaxableFields;
|
|
|
|
|
//Subscribe the Cost Analysis text boxes to the validation and update events.
|
|
|
|
|
salesPerManHourTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
salesPerManHourTextBox.Validating += ValidateCostAnalysisValues;
|
|
|
|
|
salaryPercentageTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
salaryPercentageTextBox.Validating += ValidateCostAnalysisValues;
|
|
|
|
|
salaryDollarsTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
salaryDollarsTextBox.Validating += ValidateCostAnalysisValues;
|
|
|
|
|
suppliesTextBox.Enter += StoreBeginningTextBoxValue;
|
|
|
|
|
suppliesTextBox.Validating += ValidateCostAnalysisValues;
|
|
|
|
|
//
|
|
|
|
|
//_debugTabPage = mainTabControl.TabPages[4];
|
|
|
|
|
//mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]);
|
|
|
|
|
Text = @"Add New Record (Current Record: " + _currentActiveDate.ToShortDateString() + @")";
|
|
|
|
|
addRecordButton.Text = @"Add Record";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed override string Text
|
|
|
|
|
{
|
|
|
|
|
get { return base.Text; }
|
|
|
|
@@ -425,7 +546,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void DisplayRowNumbers(object sender, DataGridViewRowsAddedEventArgs e)
|
|
|
|
|
private static void DisplayRowNumbers(object sender, DataGridViewRowsAddedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var table = ((DataGridView)sender);
|
|
|
|
|
table.Rows[e.RowIndex].HeaderCell.Value = (e.RowIndex + 1).ToString();
|
|
|
|
@@ -1041,11 +1162,20 @@ namespace AdvertsingProfitControl
|
|
|
|
|
projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true;
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
|
|
|
|
//Check to see if the other tables have more then one additional row. If the tables have two or more rows than the Projections table then that means
|
|
|
|
|
//the tables have become unbalanced and need to be repaired. If the difference is only one row than that means the user is simply adding this row as
|
|
|
|
|
//a new entry to the Projections table.
|
|
|
|
|
if (projectionsDataGridView.RowCount - actualSalesDataGridView.RowCount > 1 || projectionsDataGridView.RowCount - inventoryDataGridView.RowCount > 1)
|
|
|
|
|
{
|
|
|
|
|
NormalizeApcTables();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//Check to see if the user left a row that already exists and doesn't require being copied over.
|
|
|
|
|
if (projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() == actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_isFormDirty = true;
|
|
|
|
|
//Next check to see if the user changed the ad item is the corresponding row.
|
|
|
|
|
if (projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString())
|
|
|
|
|
{
|
|
|
|
@@ -1197,6 +1327,8 @@ namespace AdvertsingProfitControl
|
|
|
|
|
LogConsole.WriteToLog(FrmLogConsole.Level.Error, "Inventory Row Count: " + inventoryDataGridView.RowCount);
|
|
|
|
|
LogConsole.WriteToLog(FrmLogConsole.Level.Error, "Actual Sales Row Count: " + actualSalesDataGridView.RowCount);
|
|
|
|
|
errorLabel.Text = @"Error removing rows from Actual Sales and Inventory.";
|
|
|
|
|
NormalizeApcTables();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//... After all the row removal has been finished re-enable the row removal events.
|
|
|
|
|
inventoryDataGridView.UserDeletingRow += UpdateUsedAdItemCollectionOnRowRemoving;
|
|
|
|
@@ -1413,11 +1545,20 @@ namespace AdvertsingProfitControl
|
|
|
|
|
inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true;
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
|
|
|
|
//Check to see if the other tables have more then one additional row. If the tables have two or more rows than the Inventory table then that means
|
|
|
|
|
//the tables have become unbalanced and need to be repaired. If the difference is only one row than that means the user is simply adding this row as
|
|
|
|
|
//a new entry to the Inventory table.
|
|
|
|
|
if (inventoryDataGridView.RowCount - projectionsDataGridView.RowCount > 1 || inventoryDataGridView.RowCount - actualSalesDataGridView.RowCount > 1)
|
|
|
|
|
{
|
|
|
|
|
NormalizeApcTables();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//Check to see if the user left a row that already exists and doesn't require being copied over.
|
|
|
|
|
if (inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() == actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_isFormDirty = true;
|
|
|
|
|
//Next check to see if the user changed the ad item is the corresponding row.
|
|
|
|
|
if (inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString())
|
|
|
|
|
{
|
|
|
|
@@ -1530,6 +1671,8 @@ namespace AdvertsingProfitControl
|
|
|
|
|
LogConsole.WriteToLog(FrmLogConsole.Level.Error, "Inventory Row Count: " + inventoryDataGridView.RowCount);
|
|
|
|
|
LogConsole.WriteToLog(FrmLogConsole.Level.Error, "Actual Sales Row Count: " + actualSalesDataGridView.RowCount);
|
|
|
|
|
errorLabel.Text = @"Error removing rows from Actual Sales and Inventory.";
|
|
|
|
|
NormalizeApcTables();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//... After all the row removal has been finished re-enable the row removal events.
|
|
|
|
|
projectionsDataGridView.UserDeletingRow += UpdateUsedAdItemCollectionOnRowRemoving;
|
|
|
|
@@ -1581,11 +1724,20 @@ namespace AdvertsingProfitControl
|
|
|
|
|
actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true;
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
|
|
|
|
//Check to see if the other tables have more then one additional row. If the tables have two or more rows than the Actual Sales table then that means
|
|
|
|
|
//the tables have become unbalanced and need to be repaired. If the difference is only one row than that means the user is simply adding this row as
|
|
|
|
|
//a new entry to the Actual Sales table.
|
|
|
|
|
if (actualSalesDataGridView.RowCount - projectionsDataGridView.RowCount > 1 || actualSalesDataGridView.RowCount - inventoryDataGridView.RowCount > 1)
|
|
|
|
|
{
|
|
|
|
|
NormalizeApcTables();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//Check to see if the user left a row that already exists and doesn't require being copied over.
|
|
|
|
|
if (actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() == projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_isFormDirty = true;
|
|
|
|
|
//Next check to see if the user changed the ad item is the corresponding row.
|
|
|
|
|
if (actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString())
|
|
|
|
|
{
|
|
|
|
@@ -1735,6 +1887,8 @@ namespace AdvertsingProfitControl
|
|
|
|
|
LogConsole.WriteToLog(FrmLogConsole.Level.Error, "Inventory Row Count: " + inventoryDataGridView.RowCount);
|
|
|
|
|
LogConsole.WriteToLog(FrmLogConsole.Level.Error, "Actual Sales Row Count: " + actualSalesDataGridView.RowCount);
|
|
|
|
|
errorLabel.Text = @"Error removing rows from Actual Sales and Inventory.";
|
|
|
|
|
NormalizeApcTables();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//... After all the row removal has been finished re-enable the row removal events.
|
|
|
|
|
projectionsDataGridView.UserDeletingRow += UpdateUsedAdItemCollectionOnRowRemoving;
|
|
|
|
@@ -2202,6 +2356,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
private void ValidateDateChanged(object sender, DateRangeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Start == _currentActiveDate || !weekEndingCalendar.BoldedDates.Contains(e.Start)) return;
|
|
|
|
|
//If the form is dirty then prompt the user to save changes.
|
|
|
|
|
if (_isFormDirty)
|
|
|
|
|
{
|
|
|
|
|
var result = MessageBox.Show(@"Would you like to save the changes you have made to this record?", @"Changes Detected", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
|
|
|
@@ -2227,12 +2382,45 @@ namespace AdvertsingProfitControl
|
|
|
|
|
}
|
|
|
|
|
_currentActiveDate = e.Start;
|
|
|
|
|
Text = @"Modify Record (Current Record: " + e.Start.ToString("d") + @")";
|
|
|
|
|
addRecordButton.Text = @"Update Record";
|
|
|
|
|
//Clear the form state.
|
|
|
|
|
ClearFormState();
|
|
|
|
|
//Load the specified date from the database.
|
|
|
|
|
LoadDate(e.Start);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetNewRecordDate(DateTime date, int weeksAhead = 0)
|
|
|
|
|
{
|
|
|
|
|
weekEndingCalendar.DateChanged -= ValidateDateChanged;
|
|
|
|
|
switch (date.DayOfWeek)
|
|
|
|
|
{
|
|
|
|
|
case DayOfWeek.Sunday:
|
|
|
|
|
weekEndingCalendar.SelectionStart = date.AddDays(6 + (weeksAhead * 7));
|
|
|
|
|
break;
|
|
|
|
|
case DayOfWeek.Monday:
|
|
|
|
|
weekEndingCalendar.SelectionStart = date.AddDays(5 + (weeksAhead * 7));
|
|
|
|
|
break;
|
|
|
|
|
case DayOfWeek.Tuesday:
|
|
|
|
|
weekEndingCalendar.SelectionStart = date.AddDays(4 + (weeksAhead * 7));
|
|
|
|
|
break;
|
|
|
|
|
case DayOfWeek.Wednesday:
|
|
|
|
|
weekEndingCalendar.SelectionStart = date.AddDays(3 + (weeksAhead * 7));
|
|
|
|
|
break;
|
|
|
|
|
case DayOfWeek.Thursday:
|
|
|
|
|
weekEndingCalendar.SelectionStart = date.AddDays(2 + (weeksAhead * 7));
|
|
|
|
|
break;
|
|
|
|
|
case DayOfWeek.Friday:
|
|
|
|
|
weekEndingCalendar.SelectionStart = date.AddDays(1 + (weeksAhead * 7));
|
|
|
|
|
break;
|
|
|
|
|
case DayOfWeek.Saturday:
|
|
|
|
|
weekEndingCalendar.SelectionStart = date.AddDays((weeksAhead * 7));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
weekEndingCalendar.DateChanged += ValidateDateChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void ClearFormState()
|
|
|
|
@@ -2311,8 +2499,8 @@ namespace AdvertsingProfitControl
|
|
|
|
|
//Reset the form's dirty flag
|
|
|
|
|
_isFormDirty = false;
|
|
|
|
|
//Clear the used ad items
|
|
|
|
|
_usedAdItems[0].Clear(); //regular ad items (section 1)
|
|
|
|
|
_usedAdItems[1].Clear(); //ad special items (section 2)
|
|
|
|
|
_usedAdItems[0].Clear(); //regular ad items (section 1)
|
|
|
|
|
_usedAdItems[1].Clear(); //ad special items (section 2)
|
|
|
|
|
//Clear invoices
|
|
|
|
|
invoicesDataGridView.Rows.Clear();
|
|
|
|
|
//Clear comments
|
|
|
|
@@ -2451,8 +2639,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
informationLabel.Text += @"No comments to display." + Environment.NewLine;
|
|
|
|
|
}
|
|
|
|
|
var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId,
|
|
|
|
|
databaseTracker.DatabaseConnectionString);
|
|
|
|
|
var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId, databaseTracker.DatabaseConnectionString);
|
|
|
|
|
if (weeklySales.Rows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
LoadWeeklySales(weeklySales);
|
|
|
|
@@ -2472,8 +2659,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
informationLabel.Text += @"No taxable data to display." + Environment.NewLine;
|
|
|
|
|
}
|
|
|
|
|
LoadInvoices(invoices);
|
|
|
|
|
var costAnalysis = databaseReader.ReturnCostAnalysis(dateId,
|
|
|
|
|
databaseTracker.DatabaseConnectionString);
|
|
|
|
|
var costAnalysis = databaseReader.ReturnCostAnalysis(dateId, databaseTracker.DatabaseConnectionString);
|
|
|
|
|
if (costAnalysis.Rows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
LoadCostAnalysis(costAnalysis);
|
|
|
|
@@ -2493,7 +2679,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
projectionsDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents;
|
|
|
|
|
projectionsDataGridView.RowValidating -= ValidateProjectedRow;
|
|
|
|
|
|
|
|
|
|
for(var rowIndex = 0; rowIndex < projections.Rows.Count; rowIndex++)
|
|
|
|
|
for (var rowIndex = 0; rowIndex < projections.Rows.Count; rowIndex++)
|
|
|
|
|
{
|
|
|
|
|
var newRow = new DataGridViewRow();
|
|
|
|
|
for (var cellIndex = 0; cellIndex < projections.Rows[rowIndex].ItemArray.Length; cellIndex++)
|
|
|
|
@@ -2518,7 +2704,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var cell = new DataGridViewTextBoxCell { Value = projections.Rows[rowIndex].ItemArray[cellIndex].ToString() };
|
|
|
|
|
var cell = new DataGridViewTextBoxCell {Value = projections.Rows[rowIndex].ItemArray[cellIndex].ToString()};
|
|
|
|
|
newRow.Cells.Add(cell);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
@@ -2563,18 +2749,13 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
var databaseTracker = new DatabaseTracker();
|
|
|
|
|
var databaseReader = new DatabaseReader();
|
|
|
|
|
var groupName =
|
|
|
|
|
databaseReader.ReturnGroupNameFromGroupId(
|
|
|
|
|
projections.Rows[rowIndex].ItemArray[cellIndex].ToString(),
|
|
|
|
|
databaseTracker.DatabaseConnectionString);
|
|
|
|
|
var groupName = databaseReader.ReturnGroupNameFromGroupId(projections.Rows[rowIndex].ItemArray[cellIndex].ToString(), databaseTracker.DatabaseConnectionString);
|
|
|
|
|
var adSpecialRow = new DataGridViewRow();
|
|
|
|
|
projectionsDataGridView.Rows.Add(adSpecialRow);
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex].Cells[1].Value = groupName;
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex].DefaultCellStyle.BackColor =
|
|
|
|
|
ApplicationColors.AdSpecial;
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
|
|
|
|
|
_adSpecialIndex = rowIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@@ -2631,12 +2812,12 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
if (inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
|
|
|
|
|
{
|
|
|
|
|
var cell = new DataGridViewTextBoxCell { Value = string.Empty };
|
|
|
|
|
var cell = new DataGridViewTextBoxCell {Value = string.Empty};
|
|
|
|
|
newRow.Cells.Add(cell);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var cell = new DataGridViewTextBoxCell { Value = inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() };
|
|
|
|
|
var cell = new DataGridViewTextBoxCell {Value = inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString()};
|
|
|
|
|
newRow.Cells.Add(cell);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
@@ -2675,10 +2856,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
var databaseTracker = new DatabaseTracker();
|
|
|
|
|
var databaseReader = new DatabaseReader();
|
|
|
|
|
var groupName =
|
|
|
|
|
databaseReader.ReturnGroupNameFromGroupId(
|
|
|
|
|
inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString(),
|
|
|
|
|
databaseTracker.DatabaseConnectionString);
|
|
|
|
|
var groupName = databaseReader.ReturnGroupNameFromGroupId(inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString(), databaseTracker.DatabaseConnectionString);
|
|
|
|
|
var adSpecialRow = new DataGridViewRow();
|
|
|
|
|
inventoryDataGridView.Rows.Add(adSpecialRow);
|
|
|
|
|
inventoryDataGridView.Rows[rowIndex].Cells[1].Value = groupName;
|
|
|
|
@@ -2735,12 +2913,12 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0.0000")
|
|
|
|
|
{
|
|
|
|
|
var cell = new DataGridViewTextBoxCell { Value = string.Empty };
|
|
|
|
|
var cell = new DataGridViewTextBoxCell {Value = string.Empty};
|
|
|
|
|
newRow.Cells.Add(cell);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var cell = new DataGridViewTextBoxCell { Value = actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() };
|
|
|
|
|
var cell = new DataGridViewTextBoxCell {Value = actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString()};
|
|
|
|
|
newRow.Cells.Add(cell);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
@@ -2779,10 +2957,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
var databaseTracker = new DatabaseTracker();
|
|
|
|
|
var databaseReader = new DatabaseReader();
|
|
|
|
|
var groupName =
|
|
|
|
|
databaseReader.ReturnGroupNameFromGroupId(
|
|
|
|
|
actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString(),
|
|
|
|
|
databaseTracker.DatabaseConnectionString);
|
|
|
|
|
var groupName = databaseReader.ReturnGroupNameFromGroupId(actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString(), databaseTracker.DatabaseConnectionString);
|
|
|
|
|
var adSpecialRow = new DataGridViewRow();
|
|
|
|
|
actualSalesDataGridView.Rows.Add(adSpecialRow);
|
|
|
|
|
actualSalesDataGridView.Rows[rowIndex].Cells[1].Value = groupName;
|
|
|
|
@@ -3190,12 +3365,9 @@ namespace AdvertsingProfitControl
|
|
|
|
|
//Spin through the collection and update the affected rows.
|
|
|
|
|
foreach (var rowIndex in writerResult.GetRowCollection())
|
|
|
|
|
{
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.Id].Value =
|
|
|
|
|
rowIndex.Value;
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value
|
|
|
|
|
= false;
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor =
|
|
|
|
|
ApplicationColors.EditingSaved;
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.Id].Value = rowIndex.Value;
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value = false;
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@@ -3213,10 +3385,8 @@ namespace AdvertsingProfitControl
|
|
|
|
|
foreach (var rowIndex in writerResult.GetRowCollection())
|
|
|
|
|
{
|
|
|
|
|
//Only reset the IsDirty value to false since the updates when through.
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value
|
|
|
|
|
= false;
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor =
|
|
|
|
|
ApplicationColors.EditingSaved;
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value = false;
|
|
|
|
|
projectionsDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@@ -3248,12 +3418,9 @@ namespace AdvertsingProfitControl
|
|
|
|
|
foreach (var rowIndex in writerResult.GetRowCollection())
|
|
|
|
|
{
|
|
|
|
|
//Only reset the IsDirty value to false since the updates when through.
|
|
|
|
|
inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int) InventoryTableColumns.Id].Value =
|
|
|
|
|
rowIndex.Value;
|
|
|
|
|
inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int) InventoryTableColumns.IsDirty]
|
|
|
|
|
.Value = false;
|
|
|
|
|
inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor =
|
|
|
|
|
ApplicationColors.EditingSaved;
|
|
|
|
|
inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int) InventoryTableColumns.Id].Value = rowIndex.Value;
|
|
|
|
|
inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int) InventoryTableColumns.IsDirty].Value = false;
|
|
|
|
|
inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@@ -3271,7 +3438,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
foreach (var rowIndex in writerResult.GetRowCollection())
|
|
|
|
|
{
|
|
|
|
|
//Only reset the IsDirty value to false since the updates when through.
|
|
|
|
|
inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
|
|
|
|
|
inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int) InventoryTableColumns.IsDirty].Value = false;
|
|
|
|
|
inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -3304,8 +3471,8 @@ namespace AdvertsingProfitControl
|
|
|
|
|
//Spin through the collection and update the affected rows.
|
|
|
|
|
foreach (var rowIndex in writerResult.GetRowCollection())
|
|
|
|
|
{
|
|
|
|
|
actualSalesDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.Id].Value = rowIndex.Value;
|
|
|
|
|
actualSalesDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
|
|
|
|
|
actualSalesDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.Id].Value = rowIndex.Value;
|
|
|
|
|
actualSalesDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value = false;
|
|
|
|
|
actualSalesDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -3324,7 +3491,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
foreach (var rowIndex in writerResult.GetRowCollection())
|
|
|
|
|
{
|
|
|
|
|
//Only reset the IsDirty value to false since the updates when through.
|
|
|
|
|
actualSalesDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
|
|
|
|
|
actualSalesDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value = false;
|
|
|
|
|
actualSalesDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -3343,7 +3510,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
errorLabel.Text += @"Failed to process actual sales." + Environment.NewLine;
|
|
|
|
|
}
|
|
|
|
|
if (SaveInvoices(dateId, displayInformation))
|
|
|
|
|
if (!SaveInvoices(dateId, displayInformation))
|
|
|
|
|
{
|
|
|
|
|
success = false;
|
|
|
|
|
}
|
|
|
|
@@ -3367,7 +3534,11 @@ namespace AdvertsingProfitControl
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
_isFormDirty = false;
|
|
|
|
|
addRecordButton.Text = @"Update Record";
|
|
|
|
|
Text = @"Modify Record (Current Record: " + _currentActiveDate.ToShortDateString() + @")";
|
|
|
|
|
}
|
|
|
|
|
weekEndingCalendar.AddBoldedDate(_currentActiveDate);
|
|
|
|
|
weekEndingCalendar.Invalidate();
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -3409,7 +3580,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
errorLabel.Text = writerStatus.GetErrorMessage();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(displayInformation) informationLabel.Text += writerStatus.GetErrorMessage() + Environment.NewLine;
|
|
|
|
|
if (displayInformation) informationLabel.Text += writerStatus.GetErrorMessage() + Environment.NewLine;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -3428,7 +3599,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
errorLabel.Text = status.ErrorMessage;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(displayInformation) 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 + @")";
|
|
|
|
@@ -3439,8 +3610,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
//Check for a null comment box and delete the comment ID from the database.
|
|
|
|
|
//Then if all is successful clear the Tag in the isCommentsDirty check box.
|
|
|
|
|
var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString,
|
|
|
|
|
int.Parse(isCommentDirtyCheckBox.Tag.ToString()));
|
|
|
|
|
var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString, int.Parse(isCommentDirtyCheckBox.Tag.ToString()));
|
|
|
|
|
if (status.Status == WritingOperationStatus.Failed)
|
|
|
|
|
{
|
|
|
|
|
errorLabel.Text = status.ErrorMessage;
|
|
|
|
@@ -3468,13 +3638,9 @@ namespace AdvertsingProfitControl
|
|
|
|
|
weeklySales[1] = mondayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(mondayWeeklySalesTextBox.Text);
|
|
|
|
|
weeklySales[2] = tuesdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(tuesdayWeeklySalesTextBox.Text);
|
|
|
|
|
weeklySales[3] = wednesdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(wednesdayWeeklySalesTextBox.Text);
|
|
|
|
|
weeklySales[4] = thursdayWeeklySalesTextBox.Text == ""
|
|
|
|
|
? 0
|
|
|
|
|
: double.Parse(thursdayWeeklySalesTextBox.Text);
|
|
|
|
|
weeklySales[4] = thursdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(thursdayWeeklySalesTextBox.Text);
|
|
|
|
|
weeklySales[5] = fridayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(fridayWeeklySalesTextBox.Text);
|
|
|
|
|
weeklySales[6] = saturdayWeeklySalesTextBox.Text == ""
|
|
|
|
|
? 0
|
|
|
|
|
: double.Parse(saturdayWeeklySalesTextBox.Text);
|
|
|
|
|
weeklySales[6] = saturdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(saturdayWeeklySalesTextBox.Text);
|
|
|
|
|
weeklySales[7] = totalWeeklySalesTextBox.Text == "" ? 0 : double.Parse(totalWeeklySalesTextBox.Text);
|
|
|
|
|
|
|
|
|
|
if (isWeeklySalesDirtyCheckBox.Tag == null)
|
|
|
|
@@ -3494,8 +3660,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString,
|
|
|
|
|
int.Parse(isWeeklySalesDirtyCheckBox.Tag.ToString()));
|
|
|
|
|
var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString, int.Parse(isWeeklySalesDirtyCheckBox.Tag.ToString()));
|
|
|
|
|
if (status.Status == WritingOperationStatus.Failed)
|
|
|
|
|
{
|
|
|
|
|
errorLabel.Text = status.ErrorMessage;
|
|
|
|
@@ -3544,8 +3709,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString,
|
|
|
|
|
int.Parse(isTaxableDirtyCheckBox.Tag.ToString()));
|
|
|
|
|
var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString, int.Parse(isTaxableDirtyCheckBox.Tag.ToString()));
|
|
|
|
|
if (status.Status == WritingOperationStatus.Failed)
|
|
|
|
|
{
|
|
|
|
|
errorLabel.Text = status.ErrorMessage;
|
|
|
|
@@ -3591,8 +3755,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString,
|
|
|
|
|
int.Parse(isCostAnalysisDirtyCheckBox.Tag.ToString()));
|
|
|
|
|
var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString, int.Parse(isCostAnalysisDirtyCheckBox.Tag.ToString()));
|
|
|
|
|
if (status.Status == WritingOperationStatus.Failed)
|
|
|
|
|
{
|
|
|
|
|
errorLabel.Text = status.ErrorMessage;
|
|
|
|
@@ -3606,6 +3769,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
if (displayInformation) informationLabel.Text += @"No changes made to Cost Analysis." + Environment.NewLine;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Table Trimming Operations
|
|
|
|
@@ -3629,8 +3793,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
//Construct a list of column names for the projections/actual sales DataGridViews and the inventory DataGirdView.
|
|
|
|
|
string[] saleColumnNames =
|
|
|
|
|
{
|
|
|
|
|
"ID", "Sold", "SalePrice", "TotalSales", "Cost", "ProfitReturn",
|
|
|
|
|
"TotalProfitReturn", "AdItemID", "RowAttribute", "AdSpecialID", "RowPosition", "DateID"
|
|
|
|
|
"ID", "Sold", "SalePrice", "TotalSales", "Cost", "ProfitReturn", "TotalProfitReturn", "AdItemID", "RowAttribute", "AdSpecialID", "RowPosition", "DateID"
|
|
|
|
|
};
|
|
|
|
|
foreach (var columnName in saleColumnNames)
|
|
|
|
|
{
|
|
|
|
@@ -3652,9 +3815,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
if (_adSpecialIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
//An ad special does exist so grab its ID from the database.
|
|
|
|
|
int.TryParse(databaseReader.RetrieveGroupIdByString(
|
|
|
|
|
dataGridView.Rows[_adSpecialIndex].Cells[(int)SalesTableColumns.AdItem]
|
|
|
|
|
.EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString), out adSpecialId);
|
|
|
|
|
int.TryParse(databaseReader.RetrieveGroupIdByString(dataGridView.Rows[_adSpecialIndex].Cells[(int) SalesTableColumns.AdItem].EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString), out adSpecialId);
|
|
|
|
|
}
|
|
|
|
|
//Begin spinning through all the rows in the projections table.
|
|
|
|
|
foreach (DataGridViewRow row in dataGridView.Rows)
|
|
|
|
@@ -3667,20 +3828,20 @@ namespace AdvertsingProfitControl
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//Check to see if the row is dirty.
|
|
|
|
|
if (!(bool)row.Cells[(int)SalesTableColumns.IsDirty].EditedFormattedValue)
|
|
|
|
|
if (!(bool) row.Cells[(int) SalesTableColumns.IsDirty].EditedFormattedValue)
|
|
|
|
|
{
|
|
|
|
|
//If it is not then continue on to the next row.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//Try grabbing the row's ID number (the number that it is in the database).
|
|
|
|
|
var rowIdNumber = row.Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString() == "" ? 0 : int.Parse(row.Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
|
|
|
|
var rowIdNumber = row.Cells[(int) SalesTableColumns.Id].EditedFormattedValue.ToString() == "" ? 0 : int.Parse(row.Cells[(int) SalesTableColumns.Id].EditedFormattedValue.ToString());
|
|
|
|
|
//Grab the ad item ID.
|
|
|
|
|
var adItemId = int.Parse(databaseReader.RetrieveAdItemId(row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString));
|
|
|
|
|
var adItemId = int.Parse(databaseReader.RetrieveAdItemId(row.Cells[(int) SalesTableColumns.AdItem].EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString));
|
|
|
|
|
//If the return value is zero (0) then the ad item is not in the database so try to add it.
|
|
|
|
|
if (adItemId == 0)
|
|
|
|
|
{
|
|
|
|
|
//Add the item to the database.
|
|
|
|
|
adItemId = databaseWriter.InsertNewAdItem(row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString());
|
|
|
|
|
adItemId = databaseWriter.InsertNewAdItem(row.Cells[(int) SalesTableColumns.AdItem].EditedFormattedValue.ToString());
|
|
|
|
|
if (adItemId == 0)
|
|
|
|
|
{
|
|
|
|
|
//TODO: Throw an exception, this can not be allowed.
|
|
|
|
@@ -3693,11 +3854,11 @@ namespace AdvertsingProfitControl
|
|
|
|
|
}
|
|
|
|
|
//Determine the row's attribute.
|
|
|
|
|
var rowAttribute = 0; //Zero (0) means no grouping, its not a header nor a member.
|
|
|
|
|
if ((bool)row.Cells[(int)SalesTableColumns.IsHeaderRow].EditedFormattedValue && !(bool)row.Cells[(int)SalesTableColumns.IsMemberRow].EditedFormattedValue)
|
|
|
|
|
if ((bool) row.Cells[(int) SalesTableColumns.IsHeaderRow].EditedFormattedValue && !(bool) row.Cells[(int) SalesTableColumns.IsMemberRow].EditedFormattedValue)
|
|
|
|
|
{
|
|
|
|
|
rowAttribute = 1;
|
|
|
|
|
}
|
|
|
|
|
else if ((bool)row.Cells[(int)SalesTableColumns.IsMemberRow].EditedFormattedValue && !(bool)row.Cells[(int)SalesTableColumns.IsHeaderRow].EditedFormattedValue)
|
|
|
|
|
else if ((bool) row.Cells[(int) SalesTableColumns.IsMemberRow].EditedFormattedValue && !(bool) row.Cells[(int) SalesTableColumns.IsHeaderRow].EditedFormattedValue)
|
|
|
|
|
{
|
|
|
|
|
rowAttribute = 2;
|
|
|
|
|
}
|
|
|
|
@@ -3706,12 +3867,12 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
//This table is full of data not in the database so the ID column isn't needed.
|
|
|
|
|
var newRow = new object[11];
|
|
|
|
|
newRow[0] = row.Cells[(int)SalesTableColumns.Sold].EditedFormattedValue.ToString();//Sold, is string
|
|
|
|
|
newRow[1] = row.Cells[(int)SalesTableColumns.SalePrice].EditedFormattedValue.ToString();//SalePrice, is string
|
|
|
|
|
newRow[2] = row.Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString());//TotalSales, must be a number
|
|
|
|
|
newRow[3] = row.Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString());//Cost, must be a number
|
|
|
|
|
newRow[4] = row.Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString());//ProfitReturn, must be a number
|
|
|
|
|
newRow[5] = row.Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString());//TotalProfitReturn, must be a number
|
|
|
|
|
newRow[0] = row.Cells[(int) SalesTableColumns.Sold].EditedFormattedValue.ToString(); //Sold, is string
|
|
|
|
|
newRow[1] = row.Cells[(int) SalesTableColumns.SalePrice].EditedFormattedValue.ToString(); //SalePrice, is string
|
|
|
|
|
newRow[2] = row.Cells[(int) SalesTableColumns.TotalSales].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int) SalesTableColumns.TotalSales].EditedFormattedValue.ToString()); //TotalSales, must be a number
|
|
|
|
|
newRow[3] = row.Cells[(int) SalesTableColumns.Cost].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int) SalesTableColumns.Cost].EditedFormattedValue.ToString()); //Cost, must be a number
|
|
|
|
|
newRow[4] = row.Cells[(int) SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int) SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString()); //ProfitReturn, must be a number
|
|
|
|
|
newRow[5] = row.Cells[(int) SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int) SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString()); //TotalProfitReturn, must be a number
|
|
|
|
|
newRow[6] = adItemId;
|
|
|
|
|
newRow[7] = rowAttribute;
|
|
|
|
|
if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex)
|
|
|
|
@@ -3732,12 +3893,12 @@ namespace AdvertsingProfitControl
|
|
|
|
|
//This table is full of data that is already in the database.
|
|
|
|
|
var newRow = new object[12];
|
|
|
|
|
newRow[0] = rowIdNumber;
|
|
|
|
|
newRow[1] = row.Cells[(int)SalesTableColumns.Sold].EditedFormattedValue.ToString();//Sold, is string
|
|
|
|
|
newRow[2] = row.Cells[(int)SalesTableColumns.SalePrice].EditedFormattedValue.ToString();//SalePrice, is string
|
|
|
|
|
newRow[3] = row.Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString());//TotalSales, must be a number
|
|
|
|
|
newRow[4] = row.Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString());//Cost, must be a number
|
|
|
|
|
newRow[5] = row.Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString());//ProfitReturn, must be a number
|
|
|
|
|
newRow[6] = row.Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString());//TotalProfitReturn, must be a number
|
|
|
|
|
newRow[1] = row.Cells[(int) SalesTableColumns.Sold].EditedFormattedValue.ToString(); //Sold, is string
|
|
|
|
|
newRow[2] = row.Cells[(int) SalesTableColumns.SalePrice].EditedFormattedValue.ToString(); //SalePrice, is string
|
|
|
|
|
newRow[3] = row.Cells[(int) SalesTableColumns.TotalSales].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int) SalesTableColumns.TotalSales].EditedFormattedValue.ToString()); //TotalSales, must be a number
|
|
|
|
|
newRow[4] = row.Cells[(int) SalesTableColumns.Cost].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int) SalesTableColumns.Cost].EditedFormattedValue.ToString()); //Cost, must be a number
|
|
|
|
|
newRow[5] = row.Cells[(int) SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int) SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString()); //ProfitReturn, must be a number
|
|
|
|
|
newRow[6] = row.Cells[(int) SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int) SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString()); //TotalProfitReturn, must be a number
|
|
|
|
|
newRow[7] = adItemId;
|
|
|
|
|
newRow[8] = rowAttribute;
|
|
|
|
|
if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex)
|
|
|
|
@@ -3785,8 +3946,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
//Construct a list of column names for the projections/actual sales DataGridViews and the inventory DataGirdView.
|
|
|
|
|
string[] saleColumnNames =
|
|
|
|
|
{
|
|
|
|
|
"ID", "Sold", "SalePrice", "TotalSales", "Cost", "ProfitReturn",
|
|
|
|
|
"TotalProfitReturn", "AdItemID", "RowAttribute", "AdSpecialID", "RowPosition", "DateID"
|
|
|
|
|
"ID", "Sold", "SalePrice", "TotalSales", "Cost", "ProfitReturn", "TotalProfitReturn", "AdItemID", "RowAttribute", "AdSpecialID", "RowPosition", "DateID"
|
|
|
|
|
};
|
|
|
|
|
foreach (var columnName in saleColumnNames)
|
|
|
|
|
{
|
|
|
|
@@ -3808,9 +3968,7 @@ namespace AdvertsingProfitControl
|
|
|
|
|
if (_adSpecialIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
//An ad special does exist so grab its ID from the database.
|
|
|
|
|
int.TryParse(databaseReader.RetrieveGroupIdByString(
|
|
|
|
|
inventoryDataGridView.Rows[_adSpecialIndex].Cells[(int)InventoryTableColumns.AdItem]
|
|
|
|
|
.EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString), out adSpecialId);
|
|
|
|
|
int.TryParse(databaseReader.RetrieveGroupIdByString(inventoryDataGridView.Rows[_adSpecialIndex].Cells[(int) InventoryTableColumns.AdItem].EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString), out adSpecialId);
|
|
|
|
|
}
|
|
|
|
|
//Begin spinning through all the rows in the projections table.
|
|
|
|
|
foreach (DataGridViewRow row in inventoryDataGridView.Rows)
|
|
|
|
@@ -3824,20 +3982,20 @@ namespace AdvertsingProfitControl
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//Check to see if the row is dirty.
|
|
|
|
|
if (!(bool)row.Cells[(int)InventoryTableColumns.IsDirty].EditedFormattedValue)
|
|
|
|
|
if (!(bool) row.Cells[(int) InventoryTableColumns.IsDirty].EditedFormattedValue)
|
|
|
|
|
{
|
|
|
|
|
//If it is not then continue on to the next row.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//Try grabbing the row's ID number (the number that it is in the database).
|
|
|
|
|
var rowIdNumber = row.Cells[(int)InventoryTableColumns.Id].EditedFormattedValue.ToString() == "" ? 0 : int.Parse(row.Cells[(int)InventoryTableColumns.Id].EditedFormattedValue.ToString());
|
|
|
|
|
var rowIdNumber = row.Cells[(int) InventoryTableColumns.Id].EditedFormattedValue.ToString() == "" ? 0 : int.Parse(row.Cells[(int) InventoryTableColumns.Id].EditedFormattedValue.ToString());
|
|
|
|
|
//Grab the ad item ID.
|
|
|
|
|
var adItemId = int.Parse(databaseReader.RetrieveAdItemId(row.Cells[(int)InventoryTableColumns.AdItem].EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString));
|
|
|
|
|
var adItemId = int.Parse(databaseReader.RetrieveAdItemId(row.Cells[(int) InventoryTableColumns.AdItem].EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString));
|
|
|
|
|
//If the return value is zero (0) then the ad item is not in the database so try to add it.
|
|
|
|
|
if (adItemId == 0)
|
|
|
|
|
{
|
|
|
|
|
//Add the item to the database.
|
|
|
|
|
adItemId = databaseWriter.InsertNewAdItem(row.Cells[(int)InventoryTableColumns.AdItem].EditedFormattedValue.ToString());
|
|
|
|
|
adItemId = databaseWriter.InsertNewAdItem(row.Cells[(int) InventoryTableColumns.AdItem].EditedFormattedValue.ToString());
|
|
|
|
|
if (adItemId == 0)
|
|
|
|
|
{
|
|
|
|
|
//TODO: Throw an exception, this can not be allowed.
|
|
|
|
@@ -3849,11 +4007,11 @@ namespace AdvertsingProfitControl
|
|
|
|
|
}
|
|
|
|
|
//Determine the row's attribute.
|
|
|
|
|
var rowAttribute = 0; //Zero (0) means no grouping, its not a header nor a member.
|
|
|
|
|
if ((bool)row.Cells[(int)InventoryTableColumns.IsHeaderRow].EditedFormattedValue && !(bool)row.Cells[(int)InventoryTableColumns.IsMemberRow].EditedFormattedValue)
|
|
|
|
|
if ((bool) row.Cells[(int) InventoryTableColumns.IsHeaderRow].EditedFormattedValue && !(bool) row.Cells[(int) InventoryTableColumns.IsMemberRow].EditedFormattedValue)
|
|
|
|
|
{
|
|
|
|
|
rowAttribute = 1;
|
|
|
|
|
}
|
|
|
|
|
else if ((bool)row.Cells[(int)InventoryTableColumns.IsMemberRow].EditedFormattedValue && !(bool)row.Cells[(int)InventoryTableColumns.IsHeaderRow].EditedFormattedValue)
|
|
|
|
|
else if ((bool) row.Cells[(int) InventoryTableColumns.IsMemberRow].EditedFormattedValue && !(bool) row.Cells[(int) InventoryTableColumns.IsHeaderRow].EditedFormattedValue)
|
|
|
|
|
{
|
|
|
|
|
rowAttribute = 2;
|
|
|
|
|
}
|
|
|
|
@@ -3862,10 +4020,10 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
//This table is full of data not in the database so the ID column isn't needed.
|
|
|
|
|
var newRow = new object[9];
|
|
|
|
|
newRow[0] = row.Cells[(int)InventoryTableColumns.BeginningInventory].EditedFormattedValue.ToString();//Beginning inventory, is string
|
|
|
|
|
newRow[1] = row.Cells[(int)InventoryTableColumns.Recieved].EditedFormattedValue.ToString();//Received, is string
|
|
|
|
|
newRow[2] = row.Cells[(int)InventoryTableColumns.Total].EditedFormattedValue.ToString();//Total inventory. is string
|
|
|
|
|
newRow[3] = row.Cells[(int)InventoryTableColumns.EndingInventory].EditedFormattedValue.ToString(); //Ending inventory, is string
|
|
|
|
|
newRow[0] = row.Cells[(int) InventoryTableColumns.BeginningInventory].EditedFormattedValue.ToString(); //Beginning inventory, is string
|
|
|
|
|
newRow[1] = row.Cells[(int) InventoryTableColumns.Recieved].EditedFormattedValue.ToString(); //Received, is string
|
|
|
|
|
newRow[2] = row.Cells[(int) InventoryTableColumns.Total].EditedFormattedValue.ToString(); //Total inventory. is string
|
|
|
|
|
newRow[3] = row.Cells[(int) InventoryTableColumns.EndingInventory].EditedFormattedValue.ToString(); //Ending inventory, is string
|
|
|
|
|
newRow[4] = adItemId;
|
|
|
|
|
newRow[5] = rowAttribute;
|
|
|
|
|
if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex)
|
|
|
|
@@ -3886,10 +4044,10 @@ namespace AdvertsingProfitControl
|
|
|
|
|
//This table is full of data that is already in the database.
|
|
|
|
|
var newRow = new object[10];
|
|
|
|
|
newRow[0] = rowIdNumber;
|
|
|
|
|
newRow[1] = row.Cells[(int)InventoryTableColumns.BeginningInventory].EditedFormattedValue.ToString();//Beginning inventory, is string
|
|
|
|
|
newRow[2] = row.Cells[(int)InventoryTableColumns.Recieved].EditedFormattedValue.ToString();//Received, is string
|
|
|
|
|
newRow[3] = row.Cells[(int)InventoryTableColumns.Total].EditedFormattedValue.ToString();//Total inventory. is string
|
|
|
|
|
newRow[4] = row.Cells[(int)InventoryTableColumns.EndingInventory].EditedFormattedValue.ToString(); //Ending inventory, is string
|
|
|
|
|
newRow[1] = row.Cells[(int) InventoryTableColumns.BeginningInventory].EditedFormattedValue.ToString(); //Beginning inventory, is string
|
|
|
|
|
newRow[2] = row.Cells[(int) InventoryTableColumns.Recieved].EditedFormattedValue.ToString(); //Received, is string
|
|
|
|
|
newRow[3] = row.Cells[(int) InventoryTableColumns.Total].EditedFormattedValue.ToString(); //Total inventory. is string
|
|
|
|
|
newRow[4] = row.Cells[(int) InventoryTableColumns.EndingInventory].EditedFormattedValue.ToString(); //Ending inventory, is string
|
|
|
|
|
newRow[5] = adItemId;
|
|
|
|
|
newRow[6] = rowAttribute;
|
|
|
|
|
if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex)
|
|
|
|
@@ -3933,24 +4091,193 @@ namespace AdvertsingProfitControl
|
|
|
|
|
{
|
|
|
|
|
if (!_isFormDirty) return;
|
|
|
|
|
var result = MessageBox.Show(@"Would you like to save the changes you have made?", @"Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
|
|
|
|
if (result == DialogResult.Yes)
|
|
|
|
|
switch (result)
|
|
|
|
|
{
|
|
|
|
|
SaveRecords(false);
|
|
|
|
|
}
|
|
|
|
|
else if(result == DialogResult.Cancel)
|
|
|
|
|
{
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
case DialogResult.Yes:
|
|
|
|
|
SaveRecords(false);
|
|
|
|
|
break;
|
|
|
|
|
case DialogResult.Cancel:
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NewModifyRecord_Load(object sender, EventArgs e)
|
|
|
|
|
private void createNewRecordEditMainMenu_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_isFormDirty)
|
|
|
|
|
{
|
|
|
|
|
var result = MessageBox.Show(@"Do you wish to save the changes you have made before creating a new record?", @"Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
SaveRecords();
|
|
|
|
|
}
|
|
|
|
|
else if (result == DialogResult.Cancel)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClearFormState();
|
|
|
|
|
addRecordButton.Text = @"Add Record";
|
|
|
|
|
var databaseTracker = new DatabaseTracker();
|
|
|
|
|
var databaseReader = new DatabaseReader();
|
|
|
|
|
_currentActiveDate = databaseReader.RetrieveMostRecentDate(databaseTracker.DatabaseConnectionString).AddDays(7);
|
|
|
|
|
weekEndingCalendar.SelectionStart = _currentActiveDate;
|
|
|
|
|
Text = @"Add New Record (Current Date: " + _currentActiveDate.ToShortDateString() + @")";
|
|
|
|
|
informationLabel.Text = string.Empty;
|
|
|
|
|
errorLabel.Text = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//private void NormalizeApcTables(DataTable projections, DataTable inventory, DataTable actualSales, string dateId)
|
|
|
|
|
//{
|
|
|
|
|
private void NormalizeApcTables()
|
|
|
|
|
{
|
|
|
|
|
//Disable validation events in the APC tables.
|
|
|
|
|
projectionsDataGridView.CellEnter -= StoreBeginningCellValue;
|
|
|
|
|
inventoryDataGridView.CellEnter -= StoreBeginningCellValue;
|
|
|
|
|
actualSalesDataGridView.CellEnter -= StoreBeginningCellValue;
|
|
|
|
|
projectionsDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave;
|
|
|
|
|
inventoryDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave;
|
|
|
|
|
actualSalesDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave;
|
|
|
|
|
projectionsDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents;
|
|
|
|
|
inventoryDataGridView.CellValidating -= ValidateInventoryCellContents;
|
|
|
|
|
actualSalesDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents;
|
|
|
|
|
projectionsDataGridView.RowValidating -= ValidateProjectedRow;
|
|
|
|
|
inventoryDataGridView.RowValidating -= ValidateInventoryRow;
|
|
|
|
|
actualSalesDataGridView.RowValidating -= ValidateActualSalesRow;
|
|
|
|
|
//END DISABLE EVENTS
|
|
|
|
|
informationLabel.Text = string.Empty;
|
|
|
|
|
errorLabel.Text = @"Tables unbalanced, attempting repairs.";
|
|
|
|
|
var dataGridView = projectionsDataGridView.RowCount > inventoryDataGridView.RowCount
|
|
|
|
|
? projectionsDataGridView
|
|
|
|
|
: inventoryDataGridView;
|
|
|
|
|
dataGridView = dataGridView.RowCount > actualSalesDataGridView.RowCount
|
|
|
|
|
? dataGridView
|
|
|
|
|
: actualSalesDataGridView;
|
|
|
|
|
var maxRowCount = dataGridView.RowCount;
|
|
|
|
|
//MessageBox.Show(dataGridView.Name);
|
|
|
|
|
var rowParser = new RowParsing();
|
|
|
|
|
for (var i = 0; i < maxRowCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if (rowParser.GetRowAttribute(dataGridView.Rows[i]) == RowAttribute.AdSpecialRow)
|
|
|
|
|
{
|
|
|
|
|
_adSpecialIndex = i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
if (maxRowCount != projectionsDataGridView.RowCount)
|
|
|
|
|
{
|
|
|
|
|
if (i < projectionsDataGridView.RowCount)
|
|
|
|
|
{
|
|
|
|
|
//Force update the existing row with whatever the fuller table has.
|
|
|
|
|
if (
|
|
|
|
|
projectionsDataGridView.Rows[i].Cells[(int) SalesTableColumns.AdItem].EditedFormattedValue !=
|
|
|
|
|
dataGridView.Rows[i].Cells[(int) SalesTableColumns.AdItem].EditedFormattedValue)
|
|
|
|
|
{
|
|
|
|
|
//Force the creation of the NewRow in the DataGridView.
|
|
|
|
|
projectionsDataGridView.Rows.Add();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Add the new row to the projections DataGridView
|
|
|
|
|
projectionsDataGridView.Rows.Insert(i - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
projectionsDataGridView.Rows[i].Cells[(int)SalesTableColumns.AdItem].Value = dataGridView.Rows[i].Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue;
|
|
|
|
|
projectionsDataGridView.Rows[i].Cells[(int)SalesTableColumns.IsDirty].Value = true;
|
|
|
|
|
if (i != _adSpecialIndex)
|
|
|
|
|
{
|
|
|
|
|
projectionsDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dataGridView == actualSalesDataGridView)
|
|
|
|
|
{
|
|
|
|
|
projectionsDataGridView.Rows[i].Cells[(int) SalesTableColumns.SalePrice].Value =
|
|
|
|
|
dataGridView.Rows[i].Cells[(int) SalesTableColumns.SalePrice].EditedFormattedValue;
|
|
|
|
|
projectionsDataGridView.Rows[i].Cells[(int)SalesTableColumns.Cost].Value = dataGridView.Rows[i].Cells[(int)SalesTableColumns.Cost].EditedFormattedValue;
|
|
|
|
|
projectionsDataGridView.Rows[i].Cells[(int)SalesTableColumns.ProfitReturn].Value = dataGridView.Rows[i].Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (maxRowCount != inventoryDataGridView.RowCount)
|
|
|
|
|
{
|
|
|
|
|
if (i < inventoryDataGridView.RowCount)
|
|
|
|
|
{
|
|
|
|
|
//Force update the existing row with whatever the fuller table has.
|
|
|
|
|
if (
|
|
|
|
|
inventoryDataGridView.Rows[i].Cells[(int)InventoryTableColumns.AdItem].EditedFormattedValue !=
|
|
|
|
|
dataGridView.Rows[i].Cells[(int)InventoryTableColumns.AdItem].EditedFormattedValue)
|
|
|
|
|
{
|
|
|
|
|
inventoryDataGridView.Rows.Add();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Add the new row to the projections DataGridView
|
|
|
|
|
inventoryDataGridView.Rows.Insert(i - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inventoryDataGridView.Rows[i].Cells[(int)InventoryTableColumns.AdItem].Value = dataGridView.Rows[i].Cells[(int)InventoryTableColumns.AdItem].EditedFormattedValue;
|
|
|
|
|
inventoryDataGridView.Rows[i].Cells[(int)InventoryTableColumns.IsDirty].Value = true;
|
|
|
|
|
if (i != _adSpecialIndex)
|
|
|
|
|
{
|
|
|
|
|
inventoryDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (maxRowCount != actualSalesDataGridView.RowCount)
|
|
|
|
|
{
|
|
|
|
|
if (i < actualSalesDataGridView.RowCount)
|
|
|
|
|
{
|
|
|
|
|
//Force update the existing row with whatever the fuller table has.
|
|
|
|
|
if (
|
|
|
|
|
actualSalesDataGridView.Rows[i].Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue !=
|
|
|
|
|
dataGridView.Rows[i].Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue)
|
|
|
|
|
{
|
|
|
|
|
//Force the creation of the NewRow in the DataGridView.
|
|
|
|
|
actualSalesDataGridView.Rows.Add();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Add the new row to the projections DataGridView
|
|
|
|
|
actualSalesDataGridView.Rows.Insert(i - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
actualSalesDataGridView.Rows[i].Cells[(int)SalesTableColumns.AdItem].Value = dataGridView.Rows[i].Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue;
|
|
|
|
|
actualSalesDataGridView.Rows[i].Cells[(int)SalesTableColumns.IsDirty].Value = true;
|
|
|
|
|
if (i != _adSpecialIndex)
|
|
|
|
|
{
|
|
|
|
|
actualSalesDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dataGridView == projectionsDataGridView)
|
|
|
|
|
{
|
|
|
|
|
actualSalesDataGridView.Rows[i].Cells[(int)SalesTableColumns.SalePrice].Value =
|
|
|
|
|
dataGridView.Rows[i].Cells[(int)SalesTableColumns.SalePrice].EditedFormattedValue;
|
|
|
|
|
actualSalesDataGridView.Rows[i].Cells[(int)SalesTableColumns.Cost].Value = dataGridView.Rows[i].Cells[(int)SalesTableColumns.Cost].EditedFormattedValue;
|
|
|
|
|
actualSalesDataGridView.Rows[i].Cells[(int)SalesTableColumns.ProfitReturn].Value = dataGridView.Rows[i].Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
informationLabel.Text = @"Tables balanced.";
|
|
|
|
|
//Update the NewRow's header cell text.
|
|
|
|
|
projectionsDataGridView.Rows[projectionsDataGridView.RowCount - 1].HeaderCell.Value = projectionsDataGridView.RowCount.ToString();
|
|
|
|
|
inventoryDataGridView.Rows[inventoryDataGridView.RowCount - 1].HeaderCell.Value = inventoryDataGridView.RowCount.ToString();
|
|
|
|
|
actualSalesDataGridView.Rows[actualSalesDataGridView.RowCount - 1].HeaderCell.Value = actualSalesDataGridView.RowCount.ToString();
|
|
|
|
|
//Enable validation events in the APC tables.
|
|
|
|
|
projectionsDataGridView.CellEnter += StoreBeginningCellValue;
|
|
|
|
|
inventoryDataGridView.CellEnter += StoreBeginningCellValue;
|
|
|
|
|
actualSalesDataGridView.CellEnter += StoreBeginningCellValue;
|
|
|
|
|
projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
|
|
|
|
|
inventoryDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
|
|
|
|
|
actualSalesDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
|
|
|
|
|
projectionsDataGridView.CellValidating += ValidateSalesDataGridViewCellContents;
|
|
|
|
|
inventoryDataGridView.CellValidating += ValidateInventoryCellContents;
|
|
|
|
|
actualSalesDataGridView.CellValidating += ValidateSalesDataGridViewCellContents;
|
|
|
|
|
projectionsDataGridView.RowValidating += ValidateProjectedRow;
|
|
|
|
|
inventoryDataGridView.RowValidating += ValidateInventoryRow;
|
|
|
|
|
actualSalesDataGridView.RowValidating += ValidateActualSalesRow;
|
|
|
|
|
//END ENABLE EVENTS
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|