Moved the text formatting class to the data table parsing class. Slightly organized the code in the NewModifyRecord form.
This commit is contained in:
@@ -188,7 +188,6 @@
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ReportGenerator.cs" />
|
||||
<Compile Include="TextFormat.cs" />
|
||||
<Compile Include="BackPageGenerator.cs" />
|
||||
<Compile Include="FrmAddRecord.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
this.shrinkAcceptButton.TabIndex = 1;
|
||||
this.shrinkAcceptButton.Text = "Accept";
|
||||
this.shrinkAcceptButton.UseVisualStyleBackColor = true;
|
||||
this.shrinkAcceptButton.Click += new System.EventHandler(this.shrinkAcceptButton_Click);
|
||||
//
|
||||
// FrmChangeShrink
|
||||
//
|
||||
|
||||
@@ -18,11 +18,5 @@ namespace AdvertsingProfitControl
|
||||
shrinkNumericUpDown.Value = shrink;
|
||||
Shrink = shrink;
|
||||
}
|
||||
|
||||
private void shrinkAcceptButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
Shrink = int.Parse(shrinkNumericUpDown.Text);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Transactions;
|
||||
using System.Windows.Forms;
|
||||
using AdvertisingProfitControlData;
|
||||
using DataTableParsingEngine;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
|
||||
+3
-3
@@ -203,7 +203,7 @@
|
||||
this.createNewRecordEditMainMenu.Name = "createNewRecordEditMainMenu";
|
||||
this.createNewRecordEditMainMenu.Size = new System.Drawing.Size(283, 34);
|
||||
this.createNewRecordEditMainMenu.Text = "&Create New Record";
|
||||
this.createNewRecordEditMainMenu.Click += new System.EventHandler(this.createNewRecordEditMainMenu_Click);
|
||||
this.createNewRecordEditMainMenu.Click += new System.EventHandler(this.CreateNewRecordEditMainMenuOnClick);
|
||||
//
|
||||
// helpMainMenu
|
||||
//
|
||||
@@ -972,7 +972,7 @@
|
||||
this.addRecordButton.TabIndex = 26;
|
||||
this.addRecordButton.Text = "Update Record";
|
||||
this.addRecordButton.UseVisualStyleBackColor = true;
|
||||
this.addRecordButton.Click += new System.EventHandler(this.addRecordButton_Click);
|
||||
this.addRecordButton.Click += new System.EventHandler(this.SaveRecordOnAddRecordButtonClick);
|
||||
//
|
||||
// NewModifyRecord
|
||||
//
|
||||
@@ -985,7 +985,7 @@
|
||||
this.Name = "NewModifyRecord";
|
||||
this.Text = "Modify Record";
|
||||
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.NewModifyRecord_FormClosing);
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CheckFormStateOnClosing);
|
||||
this.mainLayoutPanel.ResumeLayout(false);
|
||||
this.mainLayoutPanel.PerformLayout();
|
||||
this.mainMenuStrip.ResumeLayout(false);
|
||||
|
||||
@@ -46,19 +46,6 @@ namespace AdvertsingProfitControl
|
||||
|
||||
private int _selectedRowIndex = -1;
|
||||
|
||||
public NewModifyRecord(DateTime date)
|
||||
{
|
||||
InitializeComponent();
|
||||
//
|
||||
weekEndingCalendar.SelectionStart = date;
|
||||
_currentActiveDate = date;
|
||||
InitializeForm();
|
||||
mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]);
|
||||
Text = @"Modify Record (Current Record: " + date.ToShortDateString() + @")";
|
||||
_isModifyingRecord = true;
|
||||
LoadDate(date);
|
||||
}
|
||||
|
||||
public NewModifyRecord()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -84,121 +71,17 @@ namespace AdvertsingProfitControl
|
||||
addRecordButton.Text = @"Add Record";
|
||||
}
|
||||
|
||||
public void InitializeForm()
|
||||
public NewModifyRecord(DateTime date)
|
||||
{
|
||||
var db = new AdvertisingProfitControlDbContext();
|
||||
weekEndingCalendar.BoldedDates = db.WeekEndingDates.Select(zdate => zdate.EndingDate).ToArray();
|
||||
weekEndingCalendar.DateChanged += ValidateDateChanged;
|
||||
//next pull all the ad items into memory.
|
||||
_adItemCollection = db.AdItems.Select(x => x.Name).ToList();
|
||||
//Now pull all the suppliers and the ad special list into memory.
|
||||
_supplierCollection.AddRange(db.Suppliers.Select(x => x.Name).ToArray());
|
||||
_adSpecialList.AddRange(db.AdSpecials.Select(x => x.Name).ToArray());
|
||||
//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 selected row index field.
|
||||
projectionsDataGridView.RowEnter += UpdateSelectedRowIndexOnEnter;
|
||||
inventoryDataGridView.RowEnter += UpdateSelectedRowIndexOnEnter;
|
||||
actualSalesDataGridView.RowEnter += UpdateSelectedRowIndexOnEnter;
|
||||
//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;
|
||||
InitializeComponent();
|
||||
//
|
||||
weekEndingCalendar.SelectionStart = date;
|
||||
_currentActiveDate = date;
|
||||
InitializeForm();
|
||||
mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]);
|
||||
Text = @"Modify Record (Current Record: " + date.ToShortDateString() + @")";
|
||||
_isModifyingRecord = true;
|
||||
LoadDate(date);
|
||||
}
|
||||
|
||||
public sealed override string Text
|
||||
@@ -2666,6 +2549,125 @@ out double beginningBinCount, out string _))
|
||||
|
||||
#endregion
|
||||
|
||||
#region Form State Methods
|
||||
|
||||
public void InitializeForm()
|
||||
{
|
||||
var db = new AdvertisingProfitControlDbContext();
|
||||
weekEndingCalendar.BoldedDates = db.WeekEndingDates.Select(zdate => zdate.EndingDate).ToArray();
|
||||
weekEndingCalendar.DateChanged += ValidateDateChanged;
|
||||
//next pull all the ad items into memory.
|
||||
_adItemCollection = db.AdItems.Select(x => x.Name).ToList();
|
||||
//Now pull all the suppliers and the ad special list into memory.
|
||||
_supplierCollection.AddRange(db.Suppliers.Select(x => x.Name).ToArray());
|
||||
_adSpecialList.AddRange(db.AdSpecials.Select(x => x.Name).ToArray());
|
||||
//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 selected row index field.
|
||||
projectionsDataGridView.RowEnter += UpdateSelectedRowIndexOnEnter;
|
||||
inventoryDataGridView.RowEnter += UpdateSelectedRowIndexOnEnter;
|
||||
actualSalesDataGridView.RowEnter += UpdateSelectedRowIndexOnEnter;
|
||||
//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;
|
||||
}
|
||||
|
||||
private void ClearFormState()
|
||||
{
|
||||
projectionsDataGridView.CellEnter -= StoreBeginningCellValue;
|
||||
@@ -2856,6 +2858,191 @@ out double beginningBinCount, out string _))
|
||||
suppliesTextBox.Validating += ValidateCostAnalysisValues;
|
||||
}
|
||||
|
||||
private void ClearRow(int rowIndex)
|
||||
{
|
||||
foreach (DataGridViewCell cell in projectionsDataGridView.Rows[rowIndex].Cells)
|
||||
{
|
||||
if (cell.ColumnIndex == (int)TableGroupParser.SalesTableColumns.AdItem) continue;
|
||||
var actualSalesCell = actualSalesDataGridView.Rows[rowIndex].Cells[cell.ColumnIndex];
|
||||
if (cell.ColumnIndex < (int)TableGroupParser.SalesTableColumns.IsHeaderRow)
|
||||
{
|
||||
cell.Value = string.Empty;
|
||||
actualSalesCell.Value = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.Value = false;
|
||||
actualSalesCell.Value = false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (DataGridViewCell cell in inventoryDataGridView.Rows[rowIndex].Cells)
|
||||
{
|
||||
if (cell.ColumnIndex == (int)TableGroupParser.InventoryTableColumns.AdItem) continue;
|
||||
if (cell.ColumnIndex < (int)TableGroupParser.InventoryTableColumns.IsHeaderRow)
|
||||
{
|
||||
cell.Value = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.Value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 RowParser();
|
||||
for (var i = 0; i < maxRowCount; i++)
|
||||
{
|
||||
if (rowParser.GetRowAttribute(dataGridView.Rows[i]) == RowParser.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)TableGroupParser.SalesTableColumns.AdItem].EditedFormattedValue !=
|
||||
dataGridView.Rows[i].Cells[(int)TableGroupParser.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)TableGroupParser.SalesTableColumns.AdItem].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.AdItem].EditedFormattedValue;
|
||||
projectionsDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.IsDirty].Value = true;
|
||||
if (i != _adSpecialIndex)
|
||||
{
|
||||
projectionsDataGridView.Rows[i].HeaderCell.Style.BackColor = TableColors.PendingEdit;
|
||||
}
|
||||
|
||||
if (dataGridView == actualSalesDataGridView)
|
||||
{
|
||||
projectionsDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.SalePrice].Value =
|
||||
dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.SalePrice].EditedFormattedValue;
|
||||
projectionsDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.Cost].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.Cost].EditedFormattedValue;
|
||||
projectionsDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.ProfitReturn].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.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)TableGroupParser.InventoryTableColumns.AdItem].EditedFormattedValue !=
|
||||
dataGridView.Rows[i].Cells[(int)TableGroupParser.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)TableGroupParser.InventoryTableColumns.AdItem].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.InventoryTableColumns.AdItem].EditedFormattedValue;
|
||||
inventoryDataGridView.Rows[i].Cells[(int)TableGroupParser.InventoryTableColumns.IsDirty].Value = true;
|
||||
if (i != _adSpecialIndex)
|
||||
{
|
||||
inventoryDataGridView.Rows[i].HeaderCell.Style.BackColor = TableColors.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)TableGroupParser.SalesTableColumns.AdItem].EditedFormattedValue !=
|
||||
dataGridView.Rows[i].Cells[(int)TableGroupParser.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)TableGroupParser.SalesTableColumns.AdItem].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.AdItem].EditedFormattedValue;
|
||||
actualSalesDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.IsDirty].Value = true;
|
||||
if (i != _adSpecialIndex)
|
||||
{
|
||||
actualSalesDataGridView.Rows[i].HeaderCell.Style.BackColor = TableColors.PendingEdit;
|
||||
}
|
||||
|
||||
if (dataGridView == projectionsDataGridView)
|
||||
{
|
||||
actualSalesDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.SalePrice].Value =
|
||||
dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.SalePrice].EditedFormattedValue;
|
||||
actualSalesDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.Cost].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.Cost].EditedFormattedValue;
|
||||
actualSalesDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.ProfitReturn].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.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
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Data Loading Methods
|
||||
|
||||
private void LoadDate(DateTime date)
|
||||
@@ -4415,6 +4602,8 @@ out double beginningBinCount, out string _))
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sales Table Calculation Methods
|
||||
|
||||
private static void CalculateTotalPofitReturn(DataGridViewRow salesTableRow)
|
||||
{
|
||||
var sold = salesTableRow.Cells[(int) TableGroupParser.SalesTableColumns.Sold].EditedFormattedValue.ToString();
|
||||
@@ -4460,12 +4649,16 @@ out double beginningBinCount, out string _))
|
||||
}
|
||||
}
|
||||
|
||||
private void addRecordButton_Click(object sender, EventArgs e)
|
||||
#endregion
|
||||
|
||||
private void SaveRecordOnAddRecordButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
SaveRecords();
|
||||
}
|
||||
|
||||
private void NewModifyRecord_FormClosing(object sender, FormClosingEventArgs e)
|
||||
#region Menu Item Click Events
|
||||
|
||||
private void CheckFormStateOnClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (!_isFormDirty) return;
|
||||
var result = MessageBox.Show(@"Would you like to save the changes you have made?", @"Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
||||
@@ -4480,7 +4673,7 @@ out double beginningBinCount, out string _))
|
||||
}
|
||||
}
|
||||
|
||||
private void createNewRecordEditMainMenu_Click(object sender, EventArgs e)
|
||||
private void CreateNewRecordEditMainMenuOnClick(object sender, EventArgs e)
|
||||
{
|
||||
if (_isFormDirty)
|
||||
{
|
||||
@@ -4513,189 +4706,6 @@ out double beginningBinCount, out string _))
|
||||
_isModifyingRecord = false;
|
||||
}
|
||||
|
||||
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 RowParser();
|
||||
for (var i = 0; i < maxRowCount; i++)
|
||||
{
|
||||
if (rowParser.GetRowAttribute(dataGridView.Rows[i]) == RowParser.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) TableGroupParser.SalesTableColumns.AdItem].EditedFormattedValue !=
|
||||
dataGridView.Rows[i].Cells[(int) TableGroupParser.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)TableGroupParser.SalesTableColumns.AdItem].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.AdItem].EditedFormattedValue;
|
||||
projectionsDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.IsDirty].Value = true;
|
||||
if (i != _adSpecialIndex)
|
||||
{
|
||||
projectionsDataGridView.Rows[i].HeaderCell.Style.BackColor = TableColors.PendingEdit;
|
||||
}
|
||||
|
||||
if (dataGridView == actualSalesDataGridView)
|
||||
{
|
||||
projectionsDataGridView.Rows[i].Cells[(int) TableGroupParser.SalesTableColumns.SalePrice].Value =
|
||||
dataGridView.Rows[i].Cells[(int) TableGroupParser.SalesTableColumns.SalePrice].EditedFormattedValue;
|
||||
projectionsDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.Cost].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.Cost].EditedFormattedValue;
|
||||
projectionsDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.ProfitReturn].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.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)TableGroupParser.InventoryTableColumns.AdItem].EditedFormattedValue !=
|
||||
dataGridView.Rows[i].Cells[(int)TableGroupParser.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)TableGroupParser.InventoryTableColumns.AdItem].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.InventoryTableColumns.AdItem].EditedFormattedValue;
|
||||
inventoryDataGridView.Rows[i].Cells[(int)TableGroupParser.InventoryTableColumns.IsDirty].Value = true;
|
||||
if (i != _adSpecialIndex)
|
||||
{
|
||||
inventoryDataGridView.Rows[i].HeaderCell.Style.BackColor = TableColors.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)TableGroupParser.SalesTableColumns.AdItem].EditedFormattedValue !=
|
||||
dataGridView.Rows[i].Cells[(int)TableGroupParser.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)TableGroupParser.SalesTableColumns.AdItem].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.AdItem].EditedFormattedValue;
|
||||
actualSalesDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.IsDirty].Value = true;
|
||||
if (i != _adSpecialIndex)
|
||||
{
|
||||
actualSalesDataGridView.Rows[i].HeaderCell.Style.BackColor = TableColors.PendingEdit;
|
||||
}
|
||||
|
||||
if (dataGridView == projectionsDataGridView)
|
||||
{
|
||||
actualSalesDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.SalePrice].Value =
|
||||
dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.SalePrice].EditedFormattedValue;
|
||||
actualSalesDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.Cost].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.Cost].EditedFormattedValue;
|
||||
actualSalesDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.ProfitReturn].Value = dataGridView.Rows[i].Cells[(int)TableGroupParser.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
|
||||
}
|
||||
|
||||
private void ClearRow(int rowIndex)
|
||||
{
|
||||
foreach (DataGridViewCell cell in projectionsDataGridView.Rows[rowIndex].Cells)
|
||||
{
|
||||
if (cell.ColumnIndex == (int) TableGroupParser.SalesTableColumns.AdItem) continue;
|
||||
var actualSalesCell = actualSalesDataGridView.Rows[rowIndex].Cells[cell.ColumnIndex];
|
||||
if (cell.ColumnIndex < (int) TableGroupParser.SalesTableColumns.IsHeaderRow)
|
||||
{
|
||||
cell.Value = string.Empty;
|
||||
actualSalesCell.Value = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.Value = false;
|
||||
actualSalesCell.Value = false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (DataGridViewCell cell in inventoryDataGridView.Rows[rowIndex].Cells)
|
||||
{
|
||||
if (cell.ColumnIndex == (int)TableGroupParser.InventoryTableColumns.AdItem) continue;
|
||||
if (cell.ColumnIndex < (int)TableGroupParser.InventoryTableColumns.IsHeaderRow)
|
||||
{
|
||||
cell.Value = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.Value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ViewLogFiles(object sender, EventArgs e)
|
||||
{
|
||||
var form = new FrmLogFileViewer();
|
||||
@@ -4713,5 +4723,7 @@ out double beginningBinCount, out string _))
|
||||
LogConsole.Show();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("3.4.1.0")]
|
||||
[assembly: AssemblyFileVersion("3.4.1.0")]
|
||||
[assembly: AssemblyVersion("3.5.1.0")]
|
||||
[assembly: AssemblyFileVersion("3.5.1.0")]
|
||||
|
||||
@@ -1,437 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains methods that assist with managing ad item names.
|
||||
/// </summary>
|
||||
internal static class TextFormat
|
||||
{
|
||||
//private static readonly FrmLogConsole LogConsole = FrmLogConsole.GetStaticInstance;
|
||||
|
||||
/// <summary>
|
||||
/// Formats an ad item's name / text into a standard format so as to help reduce redundancy in the database.
|
||||
/// </summary>
|
||||
/// <param name="adItemText">The ad item's name to be formatted.</param>
|
||||
/// <param name="preserveAcronyms">Whether or not to preserve case on abbreviations.</param>
|
||||
/// <returns>A cleaned up and formatted version of the ad item text.</returns>
|
||||
public static string FormatAdItemText(string adItemText, bool preserveAcronyms = false)
|
||||
{
|
||||
//Trim all beginning and trailing whitespace characters to start.
|
||||
adItemText = adItemText.Trim();
|
||||
var abbreviations = new List<string>();
|
||||
var words = new List<string>();
|
||||
var isInsideBrackets = false;
|
||||
//This just makes the code a bit more readable rather then doing "adItemText[currentCharacter - 1]" to access the previous character.
|
||||
var isPreviousCharWhiteSpace = false;
|
||||
var cleanedInputString = "";
|
||||
var lastnumberStartingIndex = -1;
|
||||
//Create an array of brackets to test for, and either balance out or simply ignore the extras.
|
||||
char[] openBrackets = { '(', '<', '{', '[' };
|
||||
char[] closedBrackets = { ')', '>', '}', ']' };
|
||||
for (var currentCharacter = 0; currentCharacter < adItemText.Length; currentCharacter++)
|
||||
{
|
||||
//Capitalize the first character in the string and move to the next character.
|
||||
if (currentCharacter == 0)
|
||||
{
|
||||
cleanedInputString += char.ToUpperInvariant(adItemText[0]);
|
||||
continue;
|
||||
}
|
||||
//IF the current character is a whitespace character, mark it as such, add to the temporary string, and move on to the next.
|
||||
if (char.IsWhiteSpace(adItemText[currentCharacter]))
|
||||
{
|
||||
//Check for more then one space in a row.
|
||||
if (isPreviousCharWhiteSpace)
|
||||
{
|
||||
//If more then one space is found to be in a row, then ignore it and move onto the next character.
|
||||
continue;
|
||||
}
|
||||
//IF the current character is whitespace, then mark it and move onto the next loop.
|
||||
isPreviousCharWhiteSpace = true;
|
||||
lastnumberStartingIndex = -1; //reset
|
||||
cleanedInputString += adItemText[currentCharacter];
|
||||
continue;
|
||||
}
|
||||
//IF the current character is an open bracket then mark it so we're inside brackets and move to the next character.
|
||||
if (openBrackets.Contains(adItemText[currentCharacter]))
|
||||
{
|
||||
if (isInsideBrackets)
|
||||
{
|
||||
//If we are already inside of brackets then don't add anymore to the string just continue.
|
||||
continue;
|
||||
}
|
||||
isInsideBrackets = true;
|
||||
//Just gonna force parenthesis for now.
|
||||
cleanedInputString += '(';
|
||||
continue;
|
||||
}
|
||||
//IF the current character is a closing bracket then mark it as such and move to the next character (if any).
|
||||
if (closedBrackets.Contains(adItemText[currentCharacter]))
|
||||
{
|
||||
//IF we're not inside brackets then there is an imbalance so discard this parenthesis.
|
||||
if (!isInsideBrackets)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//Just gonna force parenthesis for now.
|
||||
cleanedInputString += ')';
|
||||
lastnumberStartingIndex = -1; //reset
|
||||
//Clear the current working word.
|
||||
isInsideBrackets = false;
|
||||
continue;
|
||||
}
|
||||
//IF the current character is not a number and the previous character is a white space character
|
||||
//then capitalize the current character and add it to the string.
|
||||
if (!char.IsNumber(adItemText[currentCharacter]) && isPreviousCharWhiteSpace)
|
||||
{
|
||||
//Check to see the length of the string and determine if the word with the number needs to be capitalized.
|
||||
if (char.IsNumber(cleanedInputString[cleanedInputString.Length - 2]))
|
||||
{
|
||||
BuildAbbreviationsAndWordsLists(adItemText, currentCharacter, out abbreviations, out words);
|
||||
//Remove the last space if there are any abbreviations or words found.
|
||||
if (abbreviations.Count > 0 || words.Count > 0)
|
||||
{
|
||||
cleanedInputString = cleanedInputString.Remove(cleanedInputString.Length - 1, 1);
|
||||
}
|
||||
//Begin checking to see how to place these items back into the final string.
|
||||
if (abbreviations.Count >= 1 && words.Count == 0)
|
||||
{
|
||||
if (!isInsideBrackets)
|
||||
{
|
||||
cleanedInputString += abbreviations[0] + ")";
|
||||
if (lastnumberStartingIndex != -1)
|
||||
{
|
||||
cleanedInputString = cleanedInputString.Insert(lastnumberStartingIndex, "(");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cleanedInputString += abbreviations[0] + ")";
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (abbreviations.Count >= 1 && words.Count == 1)
|
||||
{
|
||||
cleanedInputString += abbreviations[0] + " " + words[0];
|
||||
//Clear all braces since this format doesn't allow for braces in this set up.
|
||||
cleanedInputString = cleanedInputString.Replace("(", "");
|
||||
break;
|
||||
}
|
||||
if (abbreviations.Count >= 0 && words.Count >= 1)
|
||||
{
|
||||
if (abbreviations.Count != 0)
|
||||
{
|
||||
cleanedInputString += abbreviations[0];
|
||||
}
|
||||
cleanedInputString = words.Aggregate(cleanedInputString, (current, word) => current + (" " + word));
|
||||
//Clear all braces since this format doesn't allow for braces in this set up.
|
||||
cleanedInputString = cleanedInputString.Replace("(", "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
//If all else fails simply assume this is the beginning of a new word and capitalize it.
|
||||
cleanedInputString += char.ToUpperInvariant(adItemText[currentCharacter]);
|
||||
}
|
||||
//However, if the current character is not a number but the previous character is NOT a white space character
|
||||
//then run a few checks before adding it to the string.
|
||||
else if (!char.IsNumber(adItemText[currentCharacter]) && char.IsLetter(adItemText[currentCharacter]))
|
||||
{
|
||||
//IF the previous character is a number...
|
||||
if (char.IsNumber(cleanedInputString[cleanedInputString.Length - 1]))
|
||||
{
|
||||
//Check to see the length of the string and determine if the word with the number needs to be capitalized.
|
||||
BuildAbbreviationsAndWordsLists(adItemText, currentCharacter, out abbreviations, out words);
|
||||
//Check to see if braces are necessary for the format we're going for.
|
||||
if (abbreviations.Count >= 1 && words.Count == 0)
|
||||
{
|
||||
if (!isInsideBrackets)
|
||||
{
|
||||
cleanedInputString += abbreviations[0] + ")";
|
||||
if (lastnumberStartingIndex != -1)
|
||||
{
|
||||
cleanedInputString = cleanedInputString.Insert(lastnumberStartingIndex, "(");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cleanedInputString += abbreviations[0] + ")";
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (abbreviations.Count >= 1 && words.Count == 1)
|
||||
{
|
||||
cleanedInputString += abbreviations[0] + " " + words[0];
|
||||
//Clear all braces since this format doesn't allow for braces in this set up.
|
||||
cleanedInputString = cleanedInputString.Replace("(", "");
|
||||
break;
|
||||
}
|
||||
if (abbreviations.Count >= 0 && words.Count >= 1)
|
||||
{
|
||||
if (abbreviations.Count != 0)
|
||||
{
|
||||
cleanedInputString += abbreviations[0];
|
||||
}
|
||||
cleanedInputString = words.Aggregate(cleanedInputString, (current, word) => current + (" " + word));
|
||||
//Clear all braces since this format doesn't allow for braces in this set up.
|
||||
cleanedInputString = cleanedInputString.Replace("(", "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (char.IsLetter(adItemText[currentCharacter - 1]) || adItemText[currentCharacter - 1] == '\'')
|
||||
{
|
||||
cleanedInputString += char.ToLowerInvariant(adItemText[currentCharacter]);
|
||||
}
|
||||
}
|
||||
//IF a number is found, and we're not inside brackets, check to see if there is an opening parenthesis and if there aren't create one.
|
||||
if (char.IsNumber(adItemText[currentCharacter]))
|
||||
{
|
||||
cleanedInputString += adItemText[currentCharacter];
|
||||
if (lastnumberStartingIndex == -1)
|
||||
{
|
||||
lastnumberStartingIndex = cleanedInputString.Length - 1; //Non-index based system, minus one for the index
|
||||
}
|
||||
}
|
||||
//Check for any allowed punctuation.
|
||||
if (adItemText[currentCharacter] == '\'')
|
||||
{
|
||||
cleanedInputString += adItemText[currentCharacter];
|
||||
}
|
||||
//Check if the previous character is an "'".
|
||||
else if (cleanedInputString[cleanedInputString.Length - 1] == '\'')
|
||||
{
|
||||
cleanedInputString += adItemText[currentCharacter];
|
||||
}
|
||||
//Since whitespace booleans are handled above, set the boolean for white spaces false.
|
||||
//IF we've made it this far that means the current character is not a white space character.
|
||||
isPreviousCharWhiteSpace = false;
|
||||
//IF we're at the end of the string and we're inside brackets then balance out the open bracket.
|
||||
if ((currentCharacter + 1) == adItemText.Length && isInsideBrackets)
|
||||
{
|
||||
cleanedInputString += ')';
|
||||
}
|
||||
//removedCharacterOffset++;
|
||||
}
|
||||
|
||||
//#if DEBUG
|
||||
// if (abbreviations.Count > 0)
|
||||
// {
|
||||
// LogConsole.WriteToLog(FrmLogConsole.Level.Debug, "Detected abbreviation(s) in input string \"" + adItemText + "\":");
|
||||
// foreach (var abbreviation in abbreviations)
|
||||
// {
|
||||
// LogConsole.WriteToLog(FrmLogConsole.Level.Debug, abbreviation);
|
||||
// }
|
||||
// }
|
||||
// else if (words.Count > 0)
|
||||
// {
|
||||
// LogConsole.WriteToLog(FrmLogConsole.Level.Debug, "Detected words(s) in input string \"" + adItemText + "\":");
|
||||
// foreach (var word in words)
|
||||
// {
|
||||
// LogConsole.WriteToLog(FrmLogConsole.Level.Debug, word);
|
||||
// }
|
||||
// }
|
||||
//#endif
|
||||
|
||||
return cleanedInputString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Infrastructure for the TextFormat class, not to be used with external code.
|
||||
/// Parses the full ad item text, starting at the specified index, for abbreviations and words.
|
||||
/// Once either of these objects have been found they are added to their respective Lists
|
||||
/// and returned as outed variables to the calling code. Preserving acronyms is off by default
|
||||
/// but if turned on keeps the cases of abbreviations as they are.
|
||||
/// </summary>
|
||||
/// <param name="adItemText">The full text to be parsed.</param>
|
||||
/// <param name="startingIndex">Where to start looping through the characters in the text.</param>
|
||||
/// <param name="abbreviations">A list of abbreviations that were found in the text.</param>
|
||||
/// <param name="words">A list of words found in the text.</param>
|
||||
/// <param name="preserveAcronyms">Whether or not to force normal casing rules on abbreviations.</param>
|
||||
private static void BuildAbbreviationsAndWordsLists(string adItemText, int startingIndex, out List<string> abbreviations, out List<string> words, bool preserveAcronyms = false)
|
||||
{
|
||||
abbreviations = new List<string>();
|
||||
words = new List<string>();
|
||||
var currentWorkingString = "";
|
||||
//Starting at the next character, spin through and find all words or abbreviations that are separated by white space.
|
||||
for (var i = startingIndex; i < adItemText.Length; i++)
|
||||
{
|
||||
//If the current character is a letter and if so add it to the current working string.
|
||||
if (char.IsLetter(adItemText[i]))
|
||||
{
|
||||
currentWorkingString += adItemText[i];
|
||||
}
|
||||
//Check for the current character being a white space, showing the end of a word or abbreviation.
|
||||
else if (char.IsWhiteSpace(adItemText[i]))
|
||||
{
|
||||
//Block against null values from messing things up.
|
||||
if (string.IsNullOrEmpty(currentWorkingString)) continue;
|
||||
//The end of what ever word we were on has been reached, so check to see what the string is.
|
||||
if (IsWord(currentWorkingString))
|
||||
{
|
||||
words.Add(currentWorkingString);
|
||||
}
|
||||
else
|
||||
{
|
||||
abbreviations.Add(currentWorkingString);
|
||||
}
|
||||
//Clear the current working string to start on the next.
|
||||
currentWorkingString = "";
|
||||
}
|
||||
//Run a check to see if this is the last character in the string.
|
||||
if ((i + 1) != adItemText.Length) continue;
|
||||
//The end of whatever word we were on has been reached, so check to see what the string is.
|
||||
if (IsWord(currentWorkingString))
|
||||
{
|
||||
words.Add(currentWorkingString);
|
||||
}
|
||||
else
|
||||
{
|
||||
abbreviations.Add(currentWorkingString);
|
||||
}
|
||||
}
|
||||
//Clean the cases of the abbreviations and words.
|
||||
for (var i = 0; i < abbreviations.Count; i++)
|
||||
{
|
||||
//If preserve acronyms is set to true then just leave the cases of the abbreviations alone.
|
||||
if (!preserveAcronyms)
|
||||
{
|
||||
abbreviations[i] = abbreviations[i].ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < words.Count; i++)
|
||||
{
|
||||
words[i] = words[i].ToLowerInvariant();
|
||||
words[i] = CapitalizeFirstLetter(words[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether or not a string is an abbreviation or a word.
|
||||
/// A word is defined as being at least three (3) characters long and having
|
||||
/// at least one (1) vowel. Where as an abbreviation is defined as less then
|
||||
/// three (3) characters long but has at least one (1) character, whether or not
|
||||
/// the string that is two (2) or one (1) characters long has a vowel is meaningless
|
||||
/// or being exactly three characters long but having zero (0) vowels.
|
||||
/// </summary>
|
||||
/// <param name="text">The text to determine whether or not its a word.</param>
|
||||
/// <returns>A boolean indicating whether or not the text is a word.</returns>
|
||||
public static bool IsWord(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return false;
|
||||
var isWord = true;
|
||||
//Most abbreviations do not have vowels in them so check to see if the "abbreviation"
|
||||
//isn't just a short word like "Box", as opposed to "lbs".
|
||||
char[] vowels = { 'a', 'e', 'i', 'o', 'u', 'y' };
|
||||
//Count the number of vowels the word has.
|
||||
var vowelCount = text.Count(x => vowels.Contains(x));
|
||||
//IF the string is exactly three (3) characters long and has more then zero (0) vowels then it is considered a word.
|
||||
if (text.Length == 3 && vowelCount == 0)
|
||||
{
|
||||
isWord = false;
|
||||
}
|
||||
else if (text.Length < 3)
|
||||
{
|
||||
isWord = false;
|
||||
}
|
||||
//Return the verdict.
|
||||
return isWord;
|
||||
}
|
||||
|
||||
public static bool TryParseBinCount(string inputText, out double binCount, out string binCountString)
|
||||
{
|
||||
if (inputText.Length == 0)
|
||||
{
|
||||
binCountString = string.Empty;
|
||||
binCount = 0;
|
||||
return false;
|
||||
}
|
||||
var success = false;
|
||||
binCountString = string.Empty;
|
||||
var number = new StringBuilder();
|
||||
var binString = new StringBuilder(); //
|
||||
var characterReached = false;
|
||||
|
||||
for (var i = 0; i < inputText.Length; i++)
|
||||
{
|
||||
if (char.IsNumber(inputText[i]) && !characterReached)
|
||||
{
|
||||
number.Append(inputText[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inputText[i] == '-' || inputText[i] == '.')
|
||||
{
|
||||
number.Append(inputText[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!char.IsLetter(inputText[i])) continue;
|
||||
binString.Append(inputText[i]);
|
||||
characterReached = true;
|
||||
}
|
||||
|
||||
if (number.ToString() == string.Empty)
|
||||
{
|
||||
binCount = 0;
|
||||
return false;
|
||||
}
|
||||
if (double.TryParse(number.ToString(), out binCount))
|
||||
{
|
||||
if (binString.ToString().Equals("bin", StringComparison.InvariantCultureIgnoreCase) ||
|
||||
binString.ToString().Equals("bins", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
if (binCount < 1 || binCount > 1)
|
||||
{
|
||||
binCountString = binCount + " Bins";
|
||||
}
|
||||
else
|
||||
{
|
||||
binCountString = "1 Bin";
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Capitalizes the first letter of the text sent to this method.
|
||||
/// </summary>
|
||||
/// <param name="text">The text to be capitalized.</param>
|
||||
/// <returns>The input text that has the first letter capitalized.</returns>
|
||||
public static string CapitalizeFirstLetter(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return string.Empty;
|
||||
return text.First().ToString().ToUpperInvariant() + string.Join("", text.Skip(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add spaces between all words that have capital letters.
|
||||
/// </summary>
|
||||
/// <param name="text">The column header text to be made presentable.</param>
|
||||
/// <param name="preserveAcronyms">Whether or not to do anything with text that's in all caps.</param>
|
||||
/// <returns>The text with spaces.</returns>
|
||||
public static string AddSpacesToSentence(string text, bool preserveAcronyms)
|
||||
{
|
||||
//http://stackoverflow.com/questions/272633/add-spaces-before-capital-letters
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
return string.Empty;
|
||||
var newText = new StringBuilder(text.Length * 2);
|
||||
newText.Append(text[0]);
|
||||
for (var i = 1; i < text.Length; i++)
|
||||
{
|
||||
if (char.IsUpper(text[i]))
|
||||
if ((text[i - 1] != ' ' && !char.IsUpper(text[i - 1])) ||
|
||||
(preserveAcronyms && char.IsUpper(text[i - 1]) &&
|
||||
i < text.Length - 1 && !char.IsUpper(text[i + 1])))
|
||||
newText.Append(' ');
|
||||
newText.Append(text[i]);
|
||||
}
|
||||
return newText.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user