diff --git a/AdvertsingProfitControl/NewModifyRecord.Designer.cs b/AdvertsingProfitControl/NewModifyRecord.Designer.cs index b626ea9..5a7b3d7 100644 --- a/AdvertsingProfitControl/NewModifyRecord.Designer.cs +++ b/AdvertsingProfitControl/NewModifyRecord.Designer.cs @@ -111,6 +111,7 @@ this.informationPanel = new System.Windows.Forms.Panel(); this.errorLabel = new System.Windows.Forms.Label(); this.addRecordButton = new System.Windows.Forms.Button(); + this.insertAdSepecialRowButton = new System.Windows.Forms.Button(); this.mainLayoutPanel.SuspendLayout(); this.mainMenuStrip.SuspendLayout(); this.mainTabControl.SuspendLayout(); @@ -187,7 +188,7 @@ // exitFileMainMenu // this.exitFileMainMenu.Name = "exitFileMainMenu"; - this.exitFileMainMenu.Size = new System.Drawing.Size(240, 34); + this.exitFileMainMenu.Size = new System.Drawing.Size(137, 34); this.exitFileMainMenu.Text = "E&xit"; // // editMainMenu @@ -201,7 +202,7 @@ // createNewRecordEditMainMenu // this.createNewRecordEditMainMenu.Name = "createNewRecordEditMainMenu"; - this.createNewRecordEditMainMenu.Size = new System.Drawing.Size(283, 34); + this.createNewRecordEditMainMenu.Size = new System.Drawing.Size(282, 34); this.createNewRecordEditMainMenu.Text = "&Create New Record"; this.createNewRecordEditMainMenu.Click += new System.EventHandler(this.CreateNewRecordEditMainMenuOnClick); // @@ -217,14 +218,14 @@ // showConsoleHelpMainMenu // this.showConsoleHelpMainMenu.Name = "showConsoleHelpMainMenu"; - this.showConsoleHelpMainMenu.Size = new System.Drawing.Size(286, 34); + this.showConsoleHelpMainMenu.Size = new System.Drawing.Size(285, 34); this.showConsoleHelpMainMenu.Text = "Sh&ow/Hide Console"; this.showConsoleHelpMainMenu.Click += new System.EventHandler(this.DisplayLogConsole); // // examineLogsHelpMainMenu // this.examineLogsHelpMainMenu.Name = "examineLogsHelpMainMenu"; - this.examineLogsHelpMainMenu.Size = new System.Drawing.Size(286, 34); + this.examineLogsHelpMainMenu.Size = new System.Drawing.Size(285, 34); this.examineLogsHelpMainMenu.Text = "Examine &Logs"; this.examineLogsHelpMainMenu.Click += new System.EventHandler(this.ViewLogFiles); // @@ -946,6 +947,7 @@ // // informationPanel // + this.informationPanel.Controls.Add(this.insertAdSepecialRowButton); this.informationPanel.Controls.Add(this.errorLabel); this.informationPanel.Controls.Add(this.addRecordButton); this.informationPanel.Dock = System.Windows.Forms.DockStyle.Fill; @@ -974,6 +976,17 @@ this.addRecordButton.UseVisualStyleBackColor = true; this.addRecordButton.Click += new System.EventHandler(this.SaveRecordOnAddRecordButtonClick); // + // insertAdSepecialRowButton + // + this.insertAdSepecialRowButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.insertAdSepecialRowButton.Location = new System.Drawing.Point(8, 133); + this.insertAdSepecialRowButton.Name = "insertAdSepecialRowButton"; + this.insertAdSepecialRowButton.Size = new System.Drawing.Size(167, 41); + this.insertAdSepecialRowButton.TabIndex = 29; + this.insertAdSepecialRowButton.Text = "Insert Ad Row"; + this.insertAdSepecialRowButton.UseVisualStyleBackColor = true; + this.insertAdSepecialRowButton.Visible = false; + // // NewModifyRecord // this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F); @@ -1104,5 +1117,6 @@ private System.Windows.Forms.ToolStripMenuItem helpMainMenu; private System.Windows.Forms.ToolStripMenuItem examineLogsHelpMainMenu; private System.Windows.Forms.ToolStripMenuItem showConsoleHelpMainMenu; + private System.Windows.Forms.Button insertAdSepecialRowButton; } } \ No newline at end of file diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs index a710828..19c21cc 100644 --- a/AdvertsingProfitControl/NewModifyRecord.cs +++ b/AdvertsingProfitControl/NewModifyRecord.cs @@ -19,6 +19,10 @@ namespace AdvertsingProfitControl //TODO: Re-enable drag and drop on the modify record form. //http://stackoverflow.com/questions/6219454/efficient-way-to-remove-all-whitespace-from-string private static readonly FrmLogConsole LogConsole = FrmLogConsole.GetStaticInstance; + //Variables used to allow drag and drop functionality. + private Rectangle _dragBoxFromMouseDown; + private int _rowIndexFromMouseDown; + private int _rowIndexOfItemUnderMouseToDrop; //Create an array that contains all the ad items from the database. private List _adItemCollection; //This object contains all the unused ad items. @@ -335,6 +339,26 @@ namespace AdvertsingProfitControl } } + private void ToggleInvoicesEvents(bool enable = true) + { + if (enable) + { + invoicesDataGridView.CellEnter += StoreBeginningCellValue; + invoicesDataGridView.RowValidating += ValidateInvoiceRow; + invoicesDataGridView.CellValidating += ValidateInvoicesCellContents; + invoicesDataGridView.EditingControlShowing += DisplaySupplierAutoComleteOnEditingShadowControl; + invoicesDataGridView.UserDeletingRow += UpdateInvoicesOnRowDeleting; + } + else + { + invoicesDataGridView.CellEnter -= StoreBeginningCellValue; + invoicesDataGridView.RowValidating -= ValidateInvoiceRow; + invoicesDataGridView.CellValidating -= ValidateInvoicesCellContents; + invoicesDataGridView.EditingControlShowing -= DisplaySupplierAutoComleteOnEditingShadowControl; + invoicesDataGridView.UserDeletingRow -= UpdateInvoicesOnRowDeleting; + } + } + #endregion #region APC DataGridView Events @@ -400,23 +424,7 @@ namespace AdvertsingProfitControl adItemIndex = (int)TableGroupParser.InventoryTableColumns.AdItem; break; } - var userInput = dataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString().Trim(); - //Paint the rows to identify what group they belong to. - if (dataGridView != inventoryDataGridView) - { - //Paint the groups and check if the form should be marked as dirty. - if (TableGroupParser.PaintRowGroups(dataGridView, e.RowIndex)) - { - _isFormDirty = true; - } - } - else - { - if (TableGroupParser.PaintIneventory(inventoryDataGridView, projectionsDataGridView, e.RowIndex)) - { - _isFormDirty = true; - } - } + var userInput = dataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString().Trim(); //Add in used Ad Items to the list. if (userInput == string.Empty) return; //Clear the old ad item out of the used ad item collection. @@ -780,7 +788,7 @@ namespace AdvertsingProfitControl return; } //Check to make sure we're not in the boolean fields or the ID field. - if (e.ColumnIndex >= (int)TableGroupParser.SalesTableColumns.IsHeaderRow || e.ColumnIndex == (int)TableGroupParser.SalesTableColumns.Id) + if (e.ColumnIndex >= (int)TableGroupParser.SalesTableColumns.IsDirty || e.ColumnIndex == (int)TableGroupParser.SalesTableColumns.Id) { return; } @@ -904,31 +912,14 @@ namespace AdvertsingProfitControl e.Cancel = true; return; } - //Update the color coding of the other tables. - //Paint the groups and check if the form should be marked as dirty. - if (TableGroupParser.PaintRowGroups(projectionsDataGridView, e.RowIndex, true)) - { - _isFormDirty = true; - } if (inventoryDataGridView.RowCount > e.RowIndex) { inventoryDataGridView.Rows[e.RowIndex].Cells[(int) TableGroupParser.InventoryTableColumns.AdItem].Value = userInput; } - if (TableGroupParser.PaintIneventory(inventoryDataGridView, - projectionsDataGridView, - e.RowIndex - 1)) - { - _isFormDirty = true; - } if (actualSalesDataGridView.RowCount > e.RowIndex) { actualSalesDataGridView.Rows[e.RowIndex].Cells[(int) TableGroupParser.SalesTableColumns.AdItem].Value = userInput; } - //Paint the groups and check if the form should be marked as dirty. - if (TableGroupParser.PaintRowGroups(actualSalesDataGridView, e.RowIndex, true)) - { - _isFormDirty = true; - } } else { @@ -1074,7 +1065,7 @@ namespace AdvertsingProfitControl break; default: //Purely here for protection against parsing the Boolean columns by mistake. - if (e.ColumnIndex == (int)TableGroupParser.SalesTableColumns.Id || e.ColumnIndex >= (int)TableGroupParser.SalesTableColumns.IsHeaderRow) { return; } + if (e.ColumnIndex == (int)TableGroupParser.SalesTableColumns.Id || e.ColumnIndex >= (int)TableGroupParser.SalesTableColumns.IsDirty) { return; } //If the column is any other then check to see if the entered value can be parsed to a double (is a number), if not then throw an error to the user. if (double.TryParse(userInput, out parsedNumber)) { @@ -1197,12 +1188,6 @@ namespace AdvertsingProfitControl case (int)TableGroupParser.SalesTableColumns.IsDirty: rowContents[i] = true; break; - case (int)TableGroupParser.SalesTableColumns.IsHeaderRow: - rowContents[i] = false; - break; - case (int)TableGroupParser.SalesTableColumns.IsMemberRow: - rowContents[i] = false; - break; default: rowContents[i] = string.Empty; break; @@ -1228,14 +1213,8 @@ namespace AdvertsingProfitControl case (int)TableGroupParser.InventoryTableColumns.IsDirty: inventoryNewRow[(int)TableGroupParser.InventoryTableColumns.IsDirty] = true; break; - case (int)TableGroupParser.InventoryTableColumns.IsHeaderRow: - inventoryNewRow[(int)TableGroupParser.InventoryTableColumns.IsHeaderRow] = false; - break; - case (int)TableGroupParser.InventoryTableColumns.IsMemberRow: - inventoryNewRow[(int)TableGroupParser.InventoryTableColumns.IsMemberRow] = false; - break; default: - if (i > (int)TableGroupParser.InventoryTableColumns.IsHeaderRow) continue; + if (i >= (int)TableGroupParser.InventoryTableColumns.IsDirty) continue; inventoryNewRow[i] = string.Empty; break; } @@ -1315,7 +1294,43 @@ namespace AdvertsingProfitControl projectionsDataGridView.RefreshEdit(); inventoryDataGridView.RefreshEdit(); actualSalesDataGridView.RefreshEdit(); - TableGroupParser.PaintRowGroups(dataGridView, 0); + } + + private void ToggleProjectionTableEvents(bool enable = true) + { + if (enable) + { + projectionsDataGridView.RowsAdded += DisplayRowNumbers; + projectionsDataGridView.CellEnter += StoreBeginningCellValue; + projectionsDataGridView.RowEnter += UpdateSelectedRowIndexOnEnter; + projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; + projectionsDataGridView.CellValidating += ValidateSalesDataGridViewCellContents; + projectionsDataGridView.RowValidating += ValidateProjectedRow; + projectionsDataGridView.UserDeletingRow += UpdateUsedAdItemCollectionOnRowRemoving; + projectionsDataGridView.RowsRemoved += ProjectionRowRemoved; + projectionsDataGridView.EditingControlShowing += DisplayAutoCompleteOnEditingControlShowing; + //projectionsDataGridView.MouseMove += dataGridView1_MouseMove; + //projectionsDataGridView.MouseDown += dataGridView1_MouseDown; + //projectionsDataGridView.DragOver += dataGridView1_DragOver; + //projectionsDataGridView.DragDrop += dataGridView1_DragDrop; + } + else + { + projectionsDataGridView.RowsAdded -= DisplayRowNumbers; + projectionsDataGridView.CellEnter -= StoreBeginningCellValue; + projectionsDataGridView.RowEnter -= UpdateSelectedRowIndexOnEnter; + projectionsDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave; + projectionsDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents; + projectionsDataGridView.RowValidating -= ValidateProjectedRow; + projectionsDataGridView.UserDeletingRow -= UpdateUsedAdItemCollectionOnRowRemoving; + projectionsDataGridView.RowsRemoved -= ProjectionRowRemoved; + projectionsDataGridView.EditingControlShowing -= DisplayAutoCompleteOnEditingControlShowing; + //projectionsDataGridView.MouseMove -= dataGridView1_MouseMove; + //projectionsDataGridView.MouseDown -= dataGridView1_MouseDown; + //projectionsDataGridView.DragOver -= dataGridView1_DragOver; + //projectionsDataGridView.DragDrop -= dataGridView1_DragDrop; + } + } #endregion @@ -1345,7 +1360,7 @@ namespace AdvertsingProfitControl return; } //Check to make sure we're not in the boolean fields or the ID field. - if (e.ColumnIndex >= (int)TableGroupParser.InventoryTableColumns.IsHeaderRow || e.ColumnIndex == (int)TableGroupParser.InventoryTableColumns.Id) + if (e.ColumnIndex >= (int)TableGroupParser.InventoryTableColumns.IsDirty || e.ColumnIndex == (int)TableGroupParser.InventoryTableColumns.Id) { return; } @@ -1454,31 +1469,14 @@ namespace AdvertsingProfitControl e.Cancel = true; return; } - //Update the color coding of the other tables. - //Paint the groups and check if the form should be marked as dirty. - if (TableGroupParser.PaintRowGroups(projectionsDataGridView, e.RowIndex, true)) - { - _isFormDirty = true; - } if (inventoryDataGridView.RowCount > e.RowIndex) { inventoryDataGridView.Rows[e.RowIndex].Cells[(int)TableGroupParser.InventoryTableColumns.AdItem].Value = userInput; } - if (TableGroupParser.PaintIneventory(inventoryDataGridView, - projectionsDataGridView, - e.RowIndex - 1)) - { - _isFormDirty = true; - } if (actualSalesDataGridView.RowCount > e.RowIndex) { actualSalesDataGridView.Rows[e.RowIndex].Cells[(int)TableGroupParser.SalesTableColumns.AdItem].Value = userInput; } - //Paint the groups and check if the form should be marked as dirty. - if (TableGroupParser.PaintRowGroups(actualSalesDataGridView, e.RowIndex, true)) - { - _isFormDirty = true; - } } else { @@ -1714,12 +1712,6 @@ out double beginningBinCount, out string _)) case (int)TableGroupParser.SalesTableColumns.IsDirty: rowContents[i] = true; break; - case (int)TableGroupParser.SalesTableColumns.IsHeaderRow: - rowContents[i] = false; - break; - case (int)TableGroupParser.SalesTableColumns.IsMemberRow: - rowContents[i] = false; - break; default: rowContents[i] = string.Empty; break; @@ -1803,9 +1795,33 @@ out double beginningBinCount, out string _)) projectionsDataGridView.RefreshEdit(); inventoryDataGridView.RefreshEdit(); actualSalesDataGridView.RefreshEdit(); - if (TableGroupParser.PaintIneventory(inventoryDataGridView, projectionsDataGridView, 0)) + } + + private void ToggleInventoryEvents(bool enable = true) + { + if (enable) { - _isFormDirty = true; + inventoryDataGridView.RowsAdded += DisplayRowNumbers; + inventoryDataGridView.CellEnter += StoreBeginningCellValue; + inventoryDataGridView.RowEnter += UpdateSelectedRowIndexOnEnter; + inventoryDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; + inventoryDataGridView.CellValidating += ValidateInventoryCellContents; + inventoryDataGridView.RowValidating += ValidateInventoryRow; + inventoryDataGridView.UserDeletingRow += UpdateUsedAdItemCollectionOnRowRemoving; + inventoryDataGridView.RowsRemoved += InventoryRowRemoved; + inventoryDataGridView.EditingControlShowing += DisplayAutoCompleteOnEditingControlShowing; + } + else + { + inventoryDataGridView.RowsAdded -= DisplayRowNumbers; + inventoryDataGridView.CellEnter -= StoreBeginningCellValue; + inventoryDataGridView.RowEnter -= UpdateSelectedRowIndexOnEnter; + inventoryDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave; + inventoryDataGridView.CellValidating -= ValidateInventoryCellContents; + inventoryDataGridView.RowValidating -= ValidateInventoryRow; + inventoryDataGridView.UserDeletingRow -= UpdateUsedAdItemCollectionOnRowRemoving; + inventoryDataGridView.RowsRemoved -= InventoryRowRemoved; + inventoryDataGridView.EditingControlShowing -= DisplayAutoCompleteOnEditingControlShowing; } } @@ -1906,12 +1922,6 @@ out double beginningBinCount, out string _)) case (int)TableGroupParser.SalesTableColumns.IsDirty: rowContents[i] = true; break; - case (int)TableGroupParser.SalesTableColumns.IsHeaderRow: - rowContents[i] = false; - break; - case (int)TableGroupParser.SalesTableColumns.IsMemberRow: - rowContents[i] = false; - break; default: rowContents[i] = string.Empty; break; @@ -1934,14 +1944,8 @@ out double beginningBinCount, out string _)) case (int)TableGroupParser.SalesTableColumns.IsDirty: inventoryNewRow[(int)TableGroupParser.InventoryTableColumns.IsDirty] = true; break; - case (int)TableGroupParser.InventoryTableColumns.IsHeaderRow: - inventoryNewRow[(int)TableGroupParser.InventoryTableColumns.IsHeaderRow] = false; - break; - case (int)TableGroupParser.InventoryTableColumns.IsMemberRow: - inventoryNewRow[(int)TableGroupParser.InventoryTableColumns.IsMemberRow] = false; - break; default: - if (i > (int)TableGroupParser.InventoryTableColumns.IsHeaderRow) continue; + if (i >= (int)TableGroupParser.InventoryTableColumns.IsDirty) continue; inventoryNewRow[i] = string.Empty; break; } @@ -2022,7 +2026,34 @@ out double beginningBinCount, out string _)) projectionsDataGridView.RefreshEdit(); inventoryDataGridView.RefreshEdit(); actualSalesDataGridView.RefreshEdit(); - TableGroupParser.PaintRowGroups(dataGridView, 0); + } + + private void ToggleActualSalesEvents(bool enable = true) + { + if (enable) + { + actualSalesDataGridView.RowsAdded += DisplayRowNumbers; + actualSalesDataGridView.CellEnter += StoreBeginningCellValue; + actualSalesDataGridView.RowEnter += UpdateSelectedRowIndexOnEnter; + actualSalesDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; + actualSalesDataGridView.CellValidating += ValidateSalesDataGridViewCellContents; + actualSalesDataGridView.RowValidating += ValidateActualSalesRow; + actualSalesDataGridView.UserDeletingRow += UpdateUsedAdItemCollectionOnRowRemoving; + actualSalesDataGridView.RowsRemoved += ActualSalesRowRemoved; + actualSalesDataGridView.EditingControlShowing += DisplayAutoCompleteOnEditingControlShowing; + } + else + { + actualSalesDataGridView.RowsAdded -= DisplayRowNumbers; + actualSalesDataGridView.CellEnter -= StoreBeginningCellValue; + actualSalesDataGridView.RowEnter -= UpdateSelectedRowIndexOnEnter; + actualSalesDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave; + actualSalesDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents; + actualSalesDataGridView.RowValidating -= ValidateActualSalesRow; + actualSalesDataGridView.UserDeletingRow -= UpdateUsedAdItemCollectionOnRowRemoving; + actualSalesDataGridView.RowsRemoved -= ActualSalesRowRemoved; + actualSalesDataGridView.EditingControlShowing -= DisplayAutoCompleteOnEditingControlShowing; + } } #endregion @@ -2249,6 +2280,23 @@ out double beginningBinCount, out string _)) } } + private void ToggleCommentsEvents(bool enable = true) + { + if (enable) + { + commentsTextBox.Enter += StoreBeginningTextBoxValue; + commentsTextBox.KeyDown += CheckForKeyCommand; + commentsTextBox.Leave += CheckForTextChangeOnLeave; + + } + else + { + commentsTextBox.Enter -= StoreBeginningTextBoxValue; + commentsTextBox.KeyDown -= CheckForKeyCommand; + commentsTextBox.Leave -= CheckForTextChangeOnLeave; + } + } + #endregion #region Weekly Sales Events @@ -2320,6 +2368,48 @@ out double beginningBinCount, out string _)) } } + private void ToggleWeeklySalesEvents(bool enable = true) + { + if (enable) + { + 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; + } + else + { + 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; + } + } + #endregion #region Taxable Events @@ -2390,6 +2480,49 @@ out double beginningBinCount, out string _)) } } + private void ToggleTaxableEvents(bool enable = true) + { + if (enable) + { + 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; + + } + else + { + 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; + } + } + #endregion #region Cost Analysis Events @@ -2463,6 +2596,32 @@ out double beginningBinCount, out string _)) } } + private void ToggleCostAnalysisEvents(bool enable = true) + { + if (enable) + { + salesPerManHourTextBox.Enter += StoreBeginningTextBoxValue; + salesPerManHourTextBox.Validating += ValidateCostAnalysisValues; + salaryPercentageTextBox.Enter += StoreBeginningTextBoxValue; + salaryPercentageTextBox.Validating += ValidateCostAnalysisValues; + salaryDollarsTextBox.Enter += StoreBeginningTextBoxValue; + salaryDollarsTextBox.Validating += ValidateCostAnalysisValues; + suppliesTextBox.Enter += StoreBeginningTextBoxValue; + suppliesTextBox.Validating += ValidateCostAnalysisValues; + } + else + { + salesPerManHourTextBox.Enter -= StoreBeginningTextBoxValue; + salesPerManHourTextBox.Validating -= ValidateCostAnalysisValues; + salaryPercentageTextBox.Enter -= StoreBeginningTextBoxValue; + salaryPercentageTextBox.Validating -= ValidateCostAnalysisValues; + salaryDollarsTextBox.Enter -= StoreBeginningTextBoxValue; + salaryDollarsTextBox.Validating -= ValidateCostAnalysisValues; + suppliesTextBox.Enter -= StoreBeginningTextBoxValue; + suppliesTextBox.Validating -= ValidateCostAnalysisValues; + } + } + #endregion #region Date Time Events @@ -2567,176 +2726,50 @@ out double beginningBinCount, out 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 + @")"; + //Set the text for the button that will allow the user to insert an ad special row using + //a list of ad special keywords pulled from the database. This will be easier to use then ALT + S I feel. + //https://stackoverflow.com/questions/10803184/windows-forms-button-with-drop-down-menu + insertAdSepecialRowButton.Text = @"Insert Ad Row ▼"; //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; + ToggleProjectionTableEvents(); + ToggleInventoryEvents(); + ToggleActualSalesEvents(); //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; + ToggleInvoicesEvents(); //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; + ToggleCommentsEvents(); //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; + ToggleWeeklySalesEvents(); //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; + ToggleTaxableEvents(); //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; + ToggleCostAnalysisEvents(); } private void ClearFormState() { - projectionsDataGridView.CellEnter -= StoreBeginningCellValue; - projectionsDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave; - projectionsDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents; - projectionsDataGridView.RowValidating -= ValidateProjectedRow; - projectionsDataGridView.RowsRemoved -= ProjectionRowRemoved; - inventoryDataGridView.CellEnter -= StoreBeginningCellValue; - inventoryDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave; - inventoryDataGridView.CellValidating -= ValidateInventoryCellContents; - inventoryDataGridView.RowValidating -= ValidateInventoryRow; - inventoryDataGridView.RowsRemoved -= InventoryRowRemoved; - actualSalesDataGridView.CellEnter -= StoreBeginningCellValue; - actualSalesDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave; - actualSalesDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents; - actualSalesDataGridView.RowValidating -= ValidateActualSalesRow; - actualSalesDataGridView.RowsRemoved -= ActualSalesRowRemoved; - invoicesDataGridView.CellEnter -= StoreBeginningCellValue; - invoicesDataGridView.RowValidating -= ValidateInvoiceRow; - invoicesDataGridView.CellValidating -= ValidateInvoicesCellContents; - commentsTextBox.Enter -= StoreBeginningTextBoxValue; - commentsTextBox.KeyDown -= CheckForKeyCommand; - commentsTextBox.Leave -= CheckForTextChangeOnLeave; - 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; - 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; - salesPerManHourTextBox.Enter -= StoreBeginningTextBoxValue; - salesPerManHourTextBox.Validating -= ValidateCostAnalysisValues; - salaryPercentageTextBox.Enter -= StoreBeginningTextBoxValue; - salaryPercentageTextBox.Validating -= ValidateCostAnalysisValues; - salaryDollarsTextBox.Enter -= StoreBeginningTextBoxValue; - salaryDollarsTextBox.Validating -= ValidateCostAnalysisValues; - suppliesTextBox.Enter -= StoreBeginningTextBoxValue; - suppliesTextBox.Validating -= ValidateCostAnalysisValues; + ToggleProjectionTableEvents(false); + ToggleInventoryEvents(false); + ToggleActualSalesEvents(false); + ToggleInvoicesEvents(false); + ToggleCommentsEvents(false); + ToggleWeeklySalesEvents(false); + ToggleTaxableEvents(false); + ToggleCostAnalysisEvents(false); //Clear projections projectionsDataGridView.Rows.Clear(); + projectionsDataGridView.Rows[0].HeaderCell.Value = "1"; //Clear inventory inventoryDataGridView.Rows.Clear(); + inventoryDataGridView.Rows[0].HeaderCell.Value = "1"; //Clear actual sales actualSalesDataGridView.Rows.Clear(); + actualSalesDataGridView.Rows[0].HeaderCell.Value = "1"; //Reset the ad special index. _adSpecialIndex = -1; //Clear the beginning cell value variable. @@ -2790,72 +2823,14 @@ out double beginningBinCount, out string _)) salaryDollarsTextBox.Text = string.Empty; suppliesTextBox.Text = string.Empty; //Re-enable the events for all the controls. - projectionsDataGridView.CellEnter += StoreBeginningCellValue; - projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; - projectionsDataGridView.CellValidating += ValidateSalesDataGridViewCellContents; - projectionsDataGridView.RowValidating += ValidateProjectedRow; - projectionsDataGridView.RowsRemoved += ProjectionRowRemoved; - inventoryDataGridView.CellEnter += StoreBeginningCellValue; - inventoryDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; - inventoryDataGridView.CellValidating += ValidateInventoryCellContents; - inventoryDataGridView.RowValidating += ValidateInventoryRow; - inventoryDataGridView.RowsRemoved += InventoryRowRemoved; - actualSalesDataGridView.CellEnter += StoreBeginningCellValue; - actualSalesDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; - actualSalesDataGridView.CellValidating += ValidateSalesDataGridViewCellContents; - actualSalesDataGridView.RowValidating += ValidateActualSalesRow; - actualSalesDataGridView.RowsRemoved += ActualSalesRowRemoved; - - invoicesDataGridView.CellEnter += StoreBeginningCellValue; - invoicesDataGridView.RowValidating += ValidateInvoiceRow; - invoicesDataGridView.CellValidating += ValidateInvoicesCellContents; - - commentsTextBox.Enter += StoreBeginningTextBoxValue; - commentsTextBox.KeyDown += CheckForKeyCommand; - commentsTextBox.Leave += CheckForTextChangeOnLeave; - - 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; - - 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; - - salesPerManHourTextBox.Enter += StoreBeginningTextBoxValue; - salesPerManHourTextBox.Validating += ValidateCostAnalysisValues; - salaryPercentageTextBox.Enter += StoreBeginningTextBoxValue; - salaryPercentageTextBox.Validating += ValidateCostAnalysisValues; - salaryDollarsTextBox.Enter += StoreBeginningTextBoxValue; - salaryDollarsTextBox.Validating += ValidateCostAnalysisValues; - suppliesTextBox.Enter += StoreBeginningTextBoxValue; - suppliesTextBox.Validating += ValidateCostAnalysisValues; + ToggleProjectionTableEvents(); + ToggleInventoryEvents(); + ToggleActualSalesEvents(); + ToggleInvoicesEvents(); + ToggleCommentsEvents(); + ToggleWeeklySalesEvents(); + ToggleTaxableEvents(); + ToggleCostAnalysisEvents(); } private void ClearRow(int rowIndex) @@ -2864,7 +2839,7 @@ out double beginningBinCount, out string _)) { if (cell.ColumnIndex == (int)TableGroupParser.SalesTableColumns.AdItem) continue; var actualSalesCell = actualSalesDataGridView.Rows[rowIndex].Cells[cell.ColumnIndex]; - if (cell.ColumnIndex < (int)TableGroupParser.SalesTableColumns.IsHeaderRow) + if (cell.ColumnIndex < (int)TableGroupParser.SalesTableColumns.IsDirty) { cell.Value = string.Empty; actualSalesCell.Value = string.Empty; @@ -2879,7 +2854,7 @@ out double beginningBinCount, out string _)) foreach (DataGridViewCell cell in inventoryDataGridView.Rows[rowIndex].Cells) { if (cell.ColumnIndex == (int)TableGroupParser.InventoryTableColumns.AdItem) continue; - if (cell.ColumnIndex < (int)TableGroupParser.InventoryTableColumns.IsHeaderRow) + if (cell.ColumnIndex < (int)TableGroupParser.InventoryTableColumns.IsDirty) { cell.Value = string.Empty; } @@ -3103,24 +3078,7 @@ out double beginningBinCount, out string _)) projectionsDataGridView.Rows[index].Cells[6].Value = projection.ProfitReturn == 0 ? "" : projection.SalePrice; projectionsDataGridView.Rows[index].Cells[7].Value = projection.TotalProfitReturn == 0 ? "" : projection.SalePrice; projectionsDataGridView.Rows[index].Cells[(int) TableGroupParser.SalesTableColumns.IsDirty].Value = false; - - switch (projection.RowAttribute) - { - case 1: - projectionsDataGridView.Rows[index].DefaultCellStyle.BackColor = TableColors.HeaderRow; - projectionsDataGridView.Rows[index].Cells[(int) TableGroupParser.SalesTableColumns.IsHeaderRow].Value = true; - projectionsDataGridView.Rows[index].Cells[(int)TableGroupParser.SalesTableColumns.IsMemberRow].Value = false; - break; - case 2: - projectionsDataGridView.Rows[index].DefaultCellStyle.BackColor = TableColors.MemberRow; - projectionsDataGridView.Rows[index].Cells[(int) TableGroupParser.SalesTableColumns.IsHeaderRow].Value = false; - projectionsDataGridView.Rows[index].Cells[(int) TableGroupParser.SalesTableColumns.IsMemberRow].Value = true; - break; - default: - projectionsDataGridView.Rows[index].Cells[(int)TableGroupParser.SalesTableColumns.IsHeaderRow].Value = false; - projectionsDataGridView.Rows[index].Cells[(int)TableGroupParser.SalesTableColumns.IsMemberRow].Value = false; - break; - } + index++; } //Manually write the row number to the new row. @@ -3166,23 +3124,6 @@ out double beginningBinCount, out string _)) inventoryDataGridView.Rows[index].Cells[5].Value = inventory.EndingInventory; inventoryDataGridView.Rows[index].Cells[(int)TableGroupParser.InventoryTableColumns.IsDirty].Value = false; - switch (inventory.RowAttribute) - { - case 1: - inventoryDataGridView.Rows[index].DefaultCellStyle.BackColor = TableColors.HeaderRow; - inventoryDataGridView.Rows[index].Cells[(int)TableGroupParser.InventoryTableColumns.IsHeaderRow].Value = true; - inventoryDataGridView.Rows[index].Cells[(int)TableGroupParser.InventoryTableColumns.IsMemberRow].Value = false; - break; - case 2: - inventoryDataGridView.Rows[index].DefaultCellStyle.BackColor = TableColors.MemberRow; - inventoryDataGridView.Rows[index].Cells[(int)TableGroupParser.InventoryTableColumns.IsHeaderRow].Value = false; - inventoryDataGridView.Rows[index].Cells[(int)TableGroupParser.InventoryTableColumns.IsMemberRow].Value = true; - break; - default: - inventoryDataGridView.Rows[index].Cells[(int)TableGroupParser.InventoryTableColumns.IsHeaderRow].Value = false; - inventoryDataGridView.Rows[index].Cells[(int)TableGroupParser.InventoryTableColumns.IsMemberRow].Value = false; - break; - } index++; } //Manually write the row number to the new row. @@ -3230,23 +3171,6 @@ out double beginningBinCount, out string _)) actualSalesDataGridView.Rows[index].Cells[7].Value = actualSale.TotalProfitReturn == 0 ? "" : actualSale.SalePrice; actualSalesDataGridView.Rows[index].Cells[(int)TableGroupParser.SalesTableColumns.IsDirty].Value = false; - switch (actualSale.RowAttribute) - { - case 1: - actualSalesDataGridView.Rows[index].DefaultCellStyle.BackColor = TableColors.HeaderRow; - actualSalesDataGridView.Rows[index].Cells[(int)TableGroupParser.SalesTableColumns.IsHeaderRow].Value = true; - actualSalesDataGridView.Rows[index].Cells[(int)TableGroupParser.SalesTableColumns.IsMemberRow].Value = false; - break; - case 2: - actualSalesDataGridView.Rows[index].DefaultCellStyle.BackColor = TableColors.MemberRow; - actualSalesDataGridView.Rows[index].Cells[(int)TableGroupParser.SalesTableColumns.IsHeaderRow].Value = false; - actualSalesDataGridView.Rows[index].Cells[(int)TableGroupParser.SalesTableColumns.IsMemberRow].Value = true; - break; - default: - actualSalesDataGridView.Rows[index].Cells[(int)TableGroupParser.SalesTableColumns.IsHeaderRow].Value = false; - actualSalesDataGridView.Rows[index].Cells[(int)TableGroupParser.SalesTableColumns.IsMemberRow].Value = false; - break; - } index++; } //Manually write the row number to the new row. @@ -3304,22 +3228,7 @@ out double beginningBinCount, out string _)) private void LoadWeeklySales(WeekEndingDate dateRecord) { - 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; + ToggleWeeklySalesEvents(false); var db = new AdvertisingProfitControlDbContext(); var weeklySale = db.WeeklySales.SingleOrDefault(x => x.FkDateId == dateRecord.Id); @@ -3342,42 +3251,12 @@ out double beginningBinCount, out string _)) isWeeklySalesDirtyCheckBox.Tag = weeklySale.Id; } //Re-enable the events - 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; + ToggleWeeklySalesEvents(); } private void LoadTaxable(WeekEndingDate dateRecord) { - 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; + ToggleTaxableEvents(false); var db = new AdvertisingProfitControlDbContext(); var taxable = db.Taxables.SingleOrDefault(x => x.FkDateId == dateRecord.Id); if (taxable == null) @@ -3398,34 +3277,12 @@ out double beginningBinCount, out string _)) isTaxableDirtyCheckBox.Text = @"IsTaxableDirty (" + taxable.Id + @")"; isTaxableDirtyCheckBox.Tag = taxable.Id; } - 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; + ToggleTaxableEvents(); } private void LoadCostAnalysis(WeekEndingDate dateRecord) { - salesPerManHourTextBox.Enter -= StoreBeginningTextBoxValue; - salesPerManHourTextBox.Validating -= ValidateCostAnalysisValues; - salaryPercentageTextBox.Enter -= StoreBeginningTextBoxValue; - salaryPercentageTextBox.Validating -= ValidateCostAnalysisValues; - salaryDollarsTextBox.Enter -= StoreBeginningTextBoxValue; - salaryDollarsTextBox.Validating -= ValidateCostAnalysisValues; - suppliesTextBox.Enter -= StoreBeginningTextBoxValue; - suppliesTextBox.Validating -= ValidateCostAnalysisValues; + ToggleCostAnalysisEvents(false); var db = new AdvertisingProfitControlDbContext(); var costAnalysis = db.CostAnalysis.SingleOrDefault(x => x.FkDateId == dateRecord.Id); @@ -3443,14 +3300,7 @@ out double beginningBinCount, out string _)) isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty (" + costAnalysis.Id + @")"; isCostAnalysisDirtyCheckBox.Tag = costAnalysis.Id; } - salesPerManHourTextBox.Enter += StoreBeginningTextBoxValue; - salesPerManHourTextBox.Validating += ValidateCostAnalysisValues; - salaryPercentageTextBox.Enter += StoreBeginningTextBoxValue; - salaryPercentageTextBox.Validating += ValidateCostAnalysisValues; - salaryDollarsTextBox.Enter += StoreBeginningTextBoxValue; - salaryDollarsTextBox.Validating += ValidateCostAnalysisValues; - suppliesTextBox.Enter += StoreBeginningTextBoxValue; - suppliesTextBox.Validating += ValidateCostAnalysisValues; + ToggleCostAnalysisEvents(); } #endregion @@ -3528,11 +3378,6 @@ out double beginningBinCount, out string _)) try { - //Force update all the data tables. - //Paint the groups and check if the form should be marked as dirty. - TableGroupParser.PaintRowGroups(projectionsDataGridView, 0, true); - TableGroupParser.PaintIneventory(inventoryDataGridView, actualSalesDataGridView, 0, true); - TableGroupParser.PaintRowGroups(actualSalesDataGridView, 0, true); using (var scope = new TransactionScope()) { SaveProjections(date); @@ -3666,16 +3511,6 @@ out double beginningBinCount, out string _)) db.AdItems.Add(adItem); db.SaveChanges(); } - //Grab the row's attribute if there is one. - var rowAttribute = 0; - if ((bool) row.Cells[(int) TableGroupParser.SalesTableColumns.IsHeaderRow].EditedFormattedValue) - { - rowAttribute = 1; - } - else if ((bool) row.Cells[(int) TableGroupParser.SalesTableColumns.IsMemberRow].EditedFormattedValue) - { - rowAttribute = 2; - } var projection = new Projection(); //Apply ad special status if there is one. if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex) @@ -3721,7 +3556,6 @@ out double beginningBinCount, out string _)) row.Cells[(int) TableGroupParser.SalesTableColumns.TotalProfitReturn].EditedFormattedValue .ToString()); projection.FkAdItemId = adItem.Id; - projection.RowAttribute = rowAttribute; projection.RowPosition = row.Index + 1; projection.FkDateId = date.Id; db.Projections.Add(projection); @@ -3758,7 +3592,9 @@ out double beginningBinCount, out string _)) .ToString()); projection.FkAdSpecialId = adSpecial.Id == 0 ? (int?) null : adSpecial.Id; projection.FkAdItemId = adItem.Id; - projection.RowAttribute = rowAttribute; + //Hard coded value to prevent legacy values from interfering. + //TODO: Remove this un-needed line. + projection.RowAttribute = 0; projection.RowPosition = row.Index + 1; } //Update the last row that was done before jumping to the next loop. @@ -3845,16 +3681,6 @@ out double beginningBinCount, out string _)) db.AdItems.Add(adItem); db.SaveChanges(); } - //Grab the row's attribute if there is one. - var rowAttribute = 0; - if ((bool)row.Cells[(int)TableGroupParser.InventoryTableColumns.IsHeaderRow].EditedFormattedValue) - { - rowAttribute = 1; - } - else if ((bool)row.Cells[(int)TableGroupParser.InventoryTableColumns.IsMemberRow].EditedFormattedValue) - { - rowAttribute = 2; - } var inventory = new Inventory(); //Apply ad special status if there is one. if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex) @@ -3878,7 +3704,6 @@ out double beginningBinCount, out string _)) inventory.EndingInventory = row.Cells[(int) TableGroupParser.InventoryTableColumns.EndingInventory].EditedFormattedValue.ToString(); inventory.FkAdItemId = adItem.Id; - inventory.RowAttribute = rowAttribute; inventory.RowPosition = row.Index + 1; inventory.FkDateId = date.Id; db.Inventories.Add(inventory); @@ -3899,7 +3724,9 @@ out double beginningBinCount, out string _)) row.Cells[(int)TableGroupParser.InventoryTableColumns.EndingInventory].EditedFormattedValue.ToString(); inventory.FkAdSpecialId = adSpecial.Id == 0 ? (int?)null : adSpecial.Id; inventory.FkAdItemId = adItem.Id; - inventory.RowAttribute = rowAttribute; + //Hard coded value to prevent legacy values from interfering. + //TODO: Remove this un-needed line. + inventory.RowAttribute = 0; inventory.RowPosition = row.Index + 1; } //Update the last row that was done before jumping to the next loop. @@ -3986,16 +3813,6 @@ out double beginningBinCount, out string _)) db.AdItems.Add(adItem); db.SaveChanges(); } - //Grab the row's attribute if there is one. - var rowAttribute = 0; - if ((bool)row.Cells[(int)TableGroupParser.SalesTableColumns.IsHeaderRow].EditedFormattedValue) - { - rowAttribute = 1; - } - else if ((bool)row.Cells[(int)TableGroupParser.SalesTableColumns.IsMemberRow].EditedFormattedValue) - { - rowAttribute = 2; - } var actualSale = new ActualSale(); //Apply ad special status if there is one. if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex) @@ -4041,7 +3858,9 @@ out double beginningBinCount, out string _)) row.Cells[(int)TableGroupParser.SalesTableColumns.TotalProfitReturn].EditedFormattedValue .ToString()); actualSale.FkAdItemId = adItem.Id; - actualSale.RowAttribute = rowAttribute; + //Hard coded value to prevent legacy values from interfering. + //TODO: Remove this un-needed line. + actualSale.RowAttribute = 0; actualSale.RowPosition = row.Index + 1; actualSale.FkDateId = date.Id; db.ActualSales.Add(actualSale); @@ -4078,7 +3897,6 @@ out double beginningBinCount, out string _)) .ToString()); actualSale.FkAdSpecialId = adSpecial.Id == 0 ? (int?)null : adSpecial.Id; actualSale.FkAdItemId = adItem.Id; - actualSale.RowAttribute = rowAttribute; actualSale.RowPosition = row.Index + 1; } //Update the last row that was done before jumping to the next loop. @@ -4725,5 +4543,239 @@ out double beginningBinCount, out string _)) } #endregion + + #region Drag and Drop Methods + //Drag and drop functionality shamelessly ripped from StackOverflow. + //Reordering rows: http://stackoverflow.com/questions/1620947/how-could-i-drag-and-drop-datagridview-rows-under-each-other/1623968#1623968 + + private void dataGridView1_MouseMove(object sender, MouseEventArgs e) + { + var dataGridView = (DataGridView) sender; + if ((e.Button & MouseButtons.Left) == MouseButtons.Left) + { + // If the mouse moves outside the rectangle, start the drag. + if (_dragBoxFromMouseDown != Rectangle.Empty && + !_dragBoxFromMouseDown.Contains(e.X, e.Y)) + { + // Proceed with the drag and drop, passing in the list item. + dataGridView.DoDragDrop( + dataGridView.Rows[_rowIndexFromMouseDown], + DragDropEffects.Move); + } + } + } + + private void dataGridView1_MouseDown(object sender, MouseEventArgs e) + { + var dataGridView = (DataGridView)sender; + // Get the index of the item the mouse is below. + _rowIndexFromMouseDown = dataGridView.HitTest(e.X, e.Y).RowIndex; + if (_rowIndexFromMouseDown != -1) + { + // Remember the point where the mouse down occurred. + // The DragSize indicates the size that the mouse can move + // before a drag event should be started. + var dragSize = SystemInformation.DragSize; + + // Create a rectangle using the DragSize, with the mouse position being + // at the center of the rectangle. + _dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2), + e.Y - (dragSize.Height / 2)), + dragSize); + } + else + // Reset the rectangle if the mouse is not over an item in the ListBox. + _dragBoxFromMouseDown = Rectangle.Empty; + } + + private void dataGridView1_DragOver(object sender, DragEventArgs e) + { + e.Effect = DragDropEffects.Move; + } + + private void dataGridView1_DragDrop(object sender, DragEventArgs e) + { + //Check if the item being dropped is actually a row object. + if (sender.GetType() != typeof(DataGridView)) return; + var dataGridView = (DataGridView)sender; + // The mouse locations are relative to the screen, so they must be + // converted to client coordinates. + var clientPoint = dataGridView.PointToClient(new Point(e.X, e.Y)); + // Get the row index of the item the mouse is below. + _rowIndexOfItemUnderMouseToDrop = + dataGridView.HitTest(clientPoint.X, clientPoint.Y).RowIndex; + // If the drag operation was a move then remove and insert the row. + if (e.Effect != DragDropEffects.Move) return; + var rowToMove = e.Data.GetData( + typeof(DataGridViewRow)) as DataGridViewRow; + //Check to make sure that the row to move isn't null for whatever reason. + if (rowToMove == null) return; + //Also check to make sure that the new row isn't being moved. + if (rowToMove.IsNewRow) return; + //Make sure the target and destination aren't the same. + if (rowToMove.Index == _rowIndexOfItemUnderMouseToDrop) return; + //Finally check to make sure the row isn't out of bounds. + if (_rowIndexOfItemUnderMouseToDrop < 0) return; + //Check to see if the target row is the NewRow, if so subtract one to prevent + //the NewRow from being manipulated, effectively putting the row to move before the very last row. + if (_rowIndexOfItemUnderMouseToDrop == dataGridView.RowCount - 1) + { + _rowIndexOfItemUnderMouseToDrop--; + } + //Basic verification completed, now un-subscribe from the row add events. + projectionsDataGridView.RowsAdded -= DisplayRowNumbers; + inventoryDataGridView.RowsAdded -= DisplayRowNumbers; + actualSalesDataGridView.RowsAdded -= DisplayRowNumbers; + //And disable the row removed event, can't risk anything here. + projectionsDataGridView.RowsRemoved -= ProjectionRowRemoved; + inventoryDataGridView.RowsRemoved -= InventoryRowRemoved; + actualSalesDataGridView.RowsRemoved -= ActualSalesRowRemoved; + //Now check to see if the row is a header, member or ad special row. + //dataGridView.Rows.RemoveAt(_rowIndexFromMouseDown); + //dataGridView.Rows.Insert(_rowIndexOfItemUnderMouseToDrop, rowToMove); + DragNonAttributedRow(); + } + + private void DragNonAttributedRow() + { + //Target Rows + var projectionsTargetRow = projectionsDataGridView.Rows[_rowIndexOfItemUnderMouseToDrop]; + var inventoryTargetRow = inventoryDataGridView.Rows[_rowIndexOfItemUnderMouseToDrop]; + var actualSalesTargetRow = actualSalesDataGridView.Rows[_rowIndexOfItemUnderMouseToDrop]; + //Rows to be moved + var projectionRowToMove = projectionsDataGridView.Rows[_rowIndexFromMouseDown]; + var inventoryRowToMove = inventoryDataGridView.Rows[_rowIndexFromMouseDown]; + var actualSalesRowToMove = actualSalesDataGridView.Rows[_rowIndexFromMouseDown]; + //Assume that the row to move is a regular row with now attributes. + //Begin by checking the attributes of the target row. (R -> R || A) + //Note: this if case will capture the ad special row as well. + //Check to see where the row is being dropped. This only needs to be considered + //if one row is greater then or less then the ad special index (assuming its set) + //and the target row is the opposite of the row being moved. + if (_adSpecialIndex != -1) + { + if (_rowIndexFromMouseDown < _adSpecialIndex && _rowIndexOfItemUnderMouseToDrop > _adSpecialIndex) + { + //Moving the row to move into the Ad Special group. + _adSpecialIndex--; + _usedAdItems[0].Remove( + projectionRowToMove.Cells[(int) TableGroupParser.SalesTableColumns.AdItem] + .EditedFormattedValue.ToString()); + _usedAdItems[1].Add( + projectionRowToMove.Cells[(int)TableGroupParser.SalesTableColumns.AdItem] + .EditedFormattedValue.ToString()); + } + else if (_rowIndexFromMouseDown > _adSpecialIndex && _rowIndexOfItemUnderMouseToDrop < _adSpecialIndex) + { + //Moving the row to move OUT of the Ad Special group. + _adSpecialIndex++; + _usedAdItems[1].Remove( + projectionRowToMove.Cells[(int)TableGroupParser.SalesTableColumns.AdItem] + .EditedFormattedValue.ToString()); + _usedAdItems[0].Add( + projectionRowToMove.Cells[(int)TableGroupParser.SalesTableColumns.AdItem] + .EditedFormattedValue.ToString()); + } + else if (_rowIndexOfItemUnderMouseToDrop == _adSpecialIndex) + { + //Move the ad special row up by one row if the user tries dropping a row on it. + _adSpecialIndex--; + _usedAdItems[0].Remove( + projectionRowToMove.Cells[(int)TableGroupParser.SalesTableColumns.AdItem] + .EditedFormattedValue.ToString()); + _usedAdItems[1].Add( + projectionRowToMove.Cells[(int)TableGroupParser.SalesTableColumns.AdItem] + .EditedFormattedValue.ToString()); + } + } + //This row is simply a regular row, so simply drop the row to move into place. + projectionsDataGridView.Rows.RemoveAt(_rowIndexFromMouseDown); + projectionsDataGridView.Rows.Insert(_rowIndexOfItemUnderMouseToDrop, projectionRowToMove); + inventoryDataGridView.Rows.RemoveAt(_rowIndexFromMouseDown); + inventoryDataGridView.Rows.Insert(_rowIndexOfItemUnderMouseToDrop, inventoryRowToMove); + actualSalesDataGridView.Rows.RemoveAt(_rowIndexFromMouseDown); + actualSalesDataGridView.Rows.Insert(_rowIndexOfItemUnderMouseToDrop, actualSalesRowToMove); + } + + private void DragRow() + { + //var targetRow = dataGridView.Rows[_rowIndexOfItemUnderMouseToDrop]; + //var targetIndex = targetRow.Index; //We need this as one the target row gets moved in the datagridview its index will change. + var projectionRowToMove = projectionsDataGridView.Rows[_rowIndexFromMouseDown]; + var inventoryRowToMove = inventoryDataGridView.Rows[_rowIndexFromMouseDown]; + var actualSalesRowToMove = actualSalesDataGridView.Rows[_rowIndexFromMouseDown]; + //Assume that the row to move is a regular row with now attributes. + //Begin by checking the attributes of the target row. (R -> R || A) + //Note: this if case will capture the ad special row as well. + + //If the target row is a header row, check to see where the row is being dropped. This only needs to be considered + //if one row is greater then or less then the ad special index (assuming its set) + //and the target row is the opposite of the row being moved. + if (_adSpecialIndex != -1) + { + if (_rowIndexFromMouseDown < _adSpecialIndex && _rowIndexOfItemUnderMouseToDrop > _adSpecialIndex) + { + //Moving the row to move into the Ad Special group. + _adSpecialIndex--; + } + else if (_rowIndexFromMouseDown > _adSpecialIndex && _rowIndexOfItemUnderMouseToDrop < _adSpecialIndex) + { + //Moving the row to move OUT of the Ad Special group. + _adSpecialIndex++; + } + else if (_rowIndexOfItemUnderMouseToDrop == _adSpecialIndex) + { + //Move the ad special row up by one row if the user tries dropping a row on it. + _adSpecialIndex--; + } + } + //This particular situation is similar to the non attributed row being dropped on a like row. + //Except that the target row has to have its "Header Row" attribute cleared, and color cleared. + //Then the row to move needs to be given that attribute. + ////TODO: may not be necessary + //projectionsDataGridView.Rows[targetRow.Index].DefaultCellStyle.BackColor = default(Color); + //inventoryDataGridView.Rows[targetRow.Index].DefaultCellStyle.BackColor = default(Color); + //actualSalesDataGridView.Rows[targetRow.Index].DefaultCellStyle.BackColor = default(Color); + //Now move the rows around. + projectionsDataGridView.Rows.RemoveAt(_rowIndexFromMouseDown); + projectionsDataGridView.Rows.Insert(_rowIndexOfItemUnderMouseToDrop, projectionRowToMove); + inventoryDataGridView.Rows.RemoveAt(_rowIndexFromMouseDown); + inventoryDataGridView.Rows.Insert(_rowIndexOfItemUnderMouseToDrop, inventoryRowToMove); + actualSalesDataGridView.Rows.RemoveAt(_rowIndexFromMouseDown); + actualSalesDataGridView.Rows.Insert(_rowIndexOfItemUnderMouseToDrop, actualSalesRowToMove); + + //And mark the affected rows as dirty so their positions will be updated on save. + // MarkRowRangeForEditing(_rowIndexFromMouseDown, targetIndex); + } + + private void MarkRowRangeForEditing(int startingIndex, int endingIndex) + { + var parser = new RowParser(); + //Mark the changed rows as dirty. + for (var i = startingIndex; i <= endingIndex; i++) + { + projectionsDataGridView.Rows[i].HeaderCell.Value = (i + 1).ToString(); + inventoryDataGridView.Rows[i].HeaderCell.Value = (i + 1).ToString(); + actualSalesDataGridView.Rows[i].HeaderCell.Value = (i + 1).ToString(); + if (parser.GetRowAttribute(projectionsDataGridView.Rows[i]) == RowParser.RowAttribute.AdSpecialRow || projectionsDataGridView.Rows[i].IsNewRow) + { + continue; + } + //Mark as dirty and update the numbers in the header cell. + projectionsDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.IsDirty].Value = true; + projectionsDataGridView.Rows[i].HeaderCell.Style.BackColor = TableColors.PendingEdit; + inventoryDataGridView.Rows[i].Cells[(int)TableGroupParser.InventoryTableColumns.IsDirty].Value = true; + inventoryDataGridView.Rows[i].HeaderCell.Style.BackColor = TableColors.PendingEdit; + actualSalesDataGridView.Rows[i].Cells[(int)TableGroupParser.SalesTableColumns.IsDirty].Value = true; + actualSalesDataGridView.Rows[i].HeaderCell.Style.BackColor = TableColors.PendingEdit; + } + projectionsDataGridView.Refresh(); + inventoryDataGridView.Refresh(); + actualSalesDataGridView.Refresh(); + //Mark the form as dirty. + _isFormDirty = true; + } + + #endregion } } diff --git a/DataTableParsingEngine/RowParser.cs b/DataTableParsingEngine/RowParser.cs index 5ab40f2..2ca5c2b 100644 --- a/DataTableParsingEngine/RowParser.cs +++ b/DataTableParsingEngine/RowParser.cs @@ -58,7 +58,7 @@ namespace DataTableParsingEngine return RowAttribute.NewRow; } //Determine the range to use during the looping process. - var headerCellIndex = row.Cells.Count == Enum.GetNames(typeof(TableGroupParser.SalesTableColumns)).Length ? (int)TableGroupParser.SalesTableColumns.IsHeaderRow : (int)TableGroupParser.InventoryTableColumns.IsHeaderRow; + var headerCellIndex = row.Cells.Count == Enum.GetNames(typeof(TableGroupParser.SalesTableColumns)).Length ? (int)TableGroupParser.SalesTableColumns.IsDirty : (int)TableGroupParser.InventoryTableColumns.IsDirty; var rowContents = new List(); var rowAttribute = RowAttribute.MemberRow; //Get the contents of the row that's being examined and add then to a List array. diff --git a/DataTableParsingEngine/TableGroupParser.cs b/DataTableParsingEngine/TableGroupParser.cs index c7110d5..a010cf5 100644 --- a/DataTableParsingEngine/TableGroupParser.cs +++ b/DataTableParsingEngine/TableGroupParser.cs @@ -15,17 +15,17 @@ namespace DataTableParsingEngine /// The DataGridView to parse. /// The starting index (the row that fired the RowLeave event) /// True to force a full scan of all rows beginning at the starting index. - public static bool PaintRowGroups(DataGridView table, int startingIndex, bool fullScan = false) + public static bool PaintRowGroupss(DataGridView table, int startingIndex, bool fullScan = false) { var parser = new RowParser(); - var isHeaderColumn = (int) SalesTableColumns.IsHeaderRow; - var isMemberColumn = (int) SalesTableColumns.IsMemberRow; + var isHeaderColumn = 1;//(int) SalesTableColumns.IsHeaderRow; + var isMemberColumn = 2;//(int) SalesTableColumns.IsMemberRow; var isDirtyColumn = (int) SalesTableColumns.IsDirty; var updatesOccured = false; if (table.ColumnCount < Enum.GetNames(typeof(SalesTableColumns)).Length) { - isHeaderColumn = (int) InventoryTableColumns.IsHeaderRow; - isMemberColumn = (int) InventoryTableColumns.IsMemberRow; + isHeaderColumn = 2;//(int) InventoryTableColumns.IsHeaderRow; + isMemberColumn = 5;//(int) InventoryTableColumns.IsMemberRow; isDirtyColumn = (int) InventoryTableColumns.IsDirty; } //Spin through the dataGridView rows starting at the row that fired the event. @@ -233,13 +233,13 @@ namespace DataTableParsingEngine return updatesOccured; } - public static bool PaintIneventory(DataGridView inventoryDataGridView, DataGridView masterGridView, + public static bool PaintIneventorys(DataGridView inventoryDataGridView, DataGridView masterGridView, int startingIndex, bool fullScan = false) { var parser = new RowParser(); var updatesOccured = false; - const int isHeaderColumn = (int)InventoryTableColumns.IsHeaderRow; - const int isMemberColumn = (int)InventoryTableColumns.IsMemberRow; + const int isHeaderColumn = 2; + const int isMemberColumn = 1; const int isDirtyColumn = (int)InventoryTableColumns.IsDirty; //Spin through the dataGridView rows starting at the row that fired the event. for (var i = startingIndex; i < (inventoryDataGridView.RowCount - 1); i++) @@ -453,9 +453,7 @@ namespace DataTableParsingEngine Cost = 5, ProfitReturn = 6, TotalProfitReturn = 7, - IsHeaderRow = 8, - IsMemberRow = 9, - IsDirty = 10 + IsDirty = 8 } public enum InventoryTableColumns @@ -466,9 +464,7 @@ namespace DataTableParsingEngine Recieved = 3, Total = 4, EndingInventory = 5, - IsHeaderRow = 6, - IsMemberRow = 7, - IsDirty = 8 + IsDirty = 6 } public enum InvoiceTableColumns