diff --git a/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs b/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs index c49b7a8..4f9c652 100644 --- a/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs +++ b/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs @@ -96,6 +96,29 @@ namespace AdvertsingProfitControl dataGridView.Rows[i - 1].Cells[isMemberColumn].Value = false; dataGridView.Rows[i - 1].DefaultCellStyle.BackColor = Color.White; } + //Then check to see if the next row is a member row + rowStatus = parser.GetRowAttribute(dataGridView.Rows[i + 1]); + if (rowStatus == RowAttribute.MemberRow) + { + //Set the current row and check for changes. + if (!(bool)dataGridView.Rows[i].Cells[isHeaderColumn].EditedFormattedValue) + { + dataGridView.Rows[i].Cells[isDirtyColumn].Value = true; + dataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit; + } + dataGridView.Rows[i].Cells[isHeaderColumn].Value = true; + dataGridView.Rows[i].Cells[isMemberColumn].Value = false; + dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.LightGray; + //Set the next row as a member row. + if (!(bool)dataGridView.Rows[i + 1].Cells[isMemberColumn].EditedFormattedValue) + { + dataGridView.Rows[i + 1].Cells[isDirtyColumn].Value = true; + dataGridView.Rows[i + 1].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit; + } + dataGridView.Rows[i + 1].Cells[isHeaderColumn].Value = false; + dataGridView.Rows[i + 1].Cells[isMemberColumn].Value = true; + dataGridView.Rows[i + 1].DefaultCellStyle.BackColor = Color.LightBlue; + } //IF previous row is Incomplete, then call the stable PaintRowGroups function. else if (rowStatus == RowAttribute.IncompleteRow) { @@ -108,11 +131,21 @@ namespace AdvertsingProfitControl rowStatus = parser.GetRowAttribute(dataGridView.Rows[i + 1]); if (rowStatus == RowAttribute.MemberRow) { - //Set the previous row as a header row. + //Set the current row and check for changes. + if (!(bool)dataGridView.Rows[i].Cells[isHeaderColumn].EditedFormattedValue) + { + dataGridView.Rows[i].Cells[isDirtyColumn].Value = true; + dataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit; + } dataGridView.Rows[i].Cells[isHeaderColumn].Value = true; dataGridView.Rows[i].Cells[isMemberColumn].Value = false; dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.LightGray; //Set the next row as a member row. + if (!(bool)dataGridView.Rows[i + 1].Cells[isMemberColumn].EditedFormattedValue) + { + dataGridView.Rows[i + 1].Cells[isDirtyColumn].Value = true; + dataGridView.Rows[i + 1].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit; + } dataGridView.Rows[i + 1].Cells[isHeaderColumn].Value = false; dataGridView.Rows[i + 1].Cells[isMemberColumn].Value = true; dataGridView.Rows[i + 1].DefaultCellStyle.BackColor = Color.LightBlue; diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs index 6a02fd8..af3ea9c 100644 --- a/AdvertsingProfitControl/NewModifyRecord.cs +++ b/AdvertsingProfitControl/NewModifyRecord.cs @@ -465,7 +465,7 @@ namespace AdvertsingProfitControl adItemIndex = (int)InventoryTableColumns.AdItem; break; } - var userInput = dataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(); + var userInput = dataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString().Trim(); //Paint the rows to identify what group they belong to. _tableHelperFunctions.PaintRowGroupsFromIndex(e.RowIndex, dataGridView); //Add in used Ad Items to the list. @@ -3116,7 +3116,7 @@ namespace AdvertsingProfitControl /// True on success otherwise, false. private bool SaveRecords(bool displayInformation = true) { - var success = false; + var success = true; //Get the date ID for the current active date. var dateId = GetDateId(_currentActiveDate.ToString("d")); if (dateId == 0) @@ -3142,11 +3142,18 @@ namespace AdvertsingProfitControl //Spin through the collection and update the affected rows. foreach (var rowIndex in writerResult.GetRowCollection()) { - projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.Id].Value = rowIndex.Value; - projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false; - projectionsDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.Id].Value = + rowIndex.Value; + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value + = false; + projectionsDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = + ApplicationColors.EditingSaved; } } + else + { + success = false; + } } //Next check to see if the update table has anything. if (updateProjectionsTable.Rows.Count > 0) @@ -3158,10 +3165,16 @@ namespace AdvertsingProfitControl foreach (var rowIndex in writerResult.GetRowCollection()) { //Only reset the IsDirty value to false since the updates when through. - projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false; - projectionsDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value + = false; + projectionsDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = + ApplicationColors.EditingSaved; } } + else + { + success = false; + } } if (displayInformation) informationLabel.Text += @"Successfully saved projections." + Environment.NewLine; } @@ -3187,10 +3200,17 @@ namespace AdvertsingProfitControl foreach (var rowIndex in writerResult.GetRowCollection()) { //Only reset the IsDirty value to false since the updates when through. - inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.Id].Value = rowIndex.Value; - inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false; - inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - } + inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int) InventoryTableColumns.Id].Value = + rowIndex.Value; + inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int) InventoryTableColumns.IsDirty] + .Value = false; + inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = + ApplicationColors.EditingSaved; + } + } + else + { + success = false; } } //Next check to see if the update table has anything. @@ -3207,9 +3227,21 @@ namespace AdvertsingProfitControl inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } } + else + { + success = false; + } } if (displayInformation) informationLabel.Text += @"Successfully saved inventory." + Environment.NewLine; } + else if (projectionsTrimmingStatus == TrimmingOperationResult.NoChangesRequired) + { + if (displayInformation) informationLabel.Text += @"No changes to inventory detected." + Environment.NewLine; + } + else + { + errorLabel.Text += @"Failed to process inventory." + Environment.NewLine; + } DataTable actualSalesNewTable; DataTable actualSalesUpdateTable; var actualSalesTrimmingStatus = ConstructCleanedSalesTable("ActualSales", dateId, out actualSalesNewTable, out actualSalesUpdateTable); @@ -3229,6 +3261,10 @@ namespace AdvertsingProfitControl actualSalesDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } } + else + { + success = false; + } } //Next check to see if the update table has anything. if (actualSalesUpdateTable.Rows.Count > 0) @@ -3244,9 +3280,21 @@ namespace AdvertsingProfitControl actualSalesDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } } + else + { + success = false; + } } if (displayInformation) informationLabel.Text += @"Successfully saved actual sales." + Environment.NewLine; } + else if (projectionsTrimmingStatus == TrimmingOperationResult.NoChangesRequired) + { + if (displayInformation) informationLabel.Text += @"No changes to actual sales detected." + Environment.NewLine; + } + else + { + errorLabel.Text += @"Failed to process actual sales." + Environment.NewLine; + } return success; } diff --git a/AdvertsingProfitControl/RowParsing.cs b/AdvertsingProfitControl/RowParsing.cs index 2099aaf..ec32762 100644 --- a/AdvertsingProfitControl/RowParsing.cs +++ b/AdvertsingProfitControl/RowParsing.cs @@ -44,14 +44,15 @@ namespace AdvertsingProfitControl { return RowAttribute.NewRow; } - + //Determine the range to use during the looping process. + var headerCellIndex = row.Cells.Count == Enum.GetNames(typeof(SalesTableColumns)).Length ? (int)SalesTableColumns.IsHeaderRow : (int)InventoryTableColumns.IsHeaderRow; 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. var i = 0; foreach (DataGridViewCell cell in row.Cells) { - if (cell.ColumnIndex >= (int) SalesTableColumns.IsHeaderRow || cell.ColumnIndex == 0) { i++; continue;} + if (cell.ColumnIndex >= headerCellIndex || cell.ColumnIndex == 0) { i++; continue;} //Strip all whitespace characters from the cell, this includes vertical tabs, newlines, and any number of spaces. var cellContentsStripped = new string(cell.EditedFormattedValue.ToString().Where(c => !char.IsWhiteSpace(c)).ToArray()); //Now remove all zeros, including any decimal points as these values are meaningless. diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application index 78e560f..1315bc1 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application @@ -14,7 +14,7 @@ - opU00zIbvKlwE9ETDbcBw3wn43DC9oTiG2Ds1yBbqBA= + Btzwp78H3RT2AmoucaHpeRFbGzPf83asDL/GO1dGVPA= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest index c203a09..da40c12 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest @@ -43,14 +43,14 @@ - + - T8dp3gOWrMgWFpeIbwYfpgMQxCEBFP64iXUiGpV4wto= + xkEtzq+MLDnIJnChEMusRcJt0LD8/sPMW87LQ9g7ulE= @@ -93,7 +93,7 @@ - oAigmBR/53icZZvL5j6Qt5ZBgYe6Mu1htzSdYejMGRo= + yZCLj+jy8vUBAeTKpwbwGxsDAc4IOfwKM+XGhtNBq5M=