From e5fa0a82387f22d1904e3b00074e9dff56f984e1 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Tue, 4 Apr 2017 19:33:25 -0500 Subject: [PATCH] Fixed a crash bug in the modify records form. Fixed behavioral issue with marking all rows in the DataGridViews as saved after updating regardless of whether or not the row was untouched from the database. --- AdvertsingProfitControl/NewModifyRecord.cs | 85 +++++++++++++--------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs index a561561..4eb3435 100644 --- a/AdvertsingProfitControl/NewModifyRecord.cs +++ b/AdvertsingProfitControl/NewModifyRecord.cs @@ -2803,6 +2803,16 @@ namespace AdvertsingProfitControl var index = 0; foreach (var projection in projections) { + if (projection.FkAdSpecialId != 0 && adSpecialIndex == -1) + { + adSpecialIndex = index; + projectionsDataGridView.Rows.Insert(index, 1); + //Apply the ad special text. + projectionsDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; + var adSpecial = db.AdSpecials.Single(x => x.Id == projection.FkAdSpecialId); + projectionsDataGridView.Rows[index].Cells[1].Value = adSpecial.Name; + index++; + } projectionsDataGridView.Rows.Add(); projectionsDataGridView.Rows[index].Cells[0].Value = projection.Id; projectionsDataGridView.Rows[index].Cells[1].Value = projection.AdItem.Name; @@ -2831,15 +2841,6 @@ namespace AdvertsingProfitControl projectionsDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsMemberRow].Value = false; break; } - if (projection.FkAdSpecialId != 0 && adSpecialIndex == -1) - { - adSpecialIndex = index; - projectionsDataGridView.Rows.Insert(index, 1); - //Apply the ad special text. - projectionsDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; - var adSpecial = db.AdSpecials.Single(x => x.Id == projection.FkAdSpecialId); - projectionsDataGridView.Rows[index].Cells[1].Value = adSpecial.Name; - } index++; } //Manually write the row number to the new row. @@ -2866,6 +2867,16 @@ namespace AdvertsingProfitControl var index = 0; foreach (var inventory in inventories) { + if (inventory.FkAdSpecialId != 0 && adSpecialIndex == -1) + { + adSpecialIndex = index; + inventoryDataGridView.Rows.Insert(index, 1); + //Apply the ad special text. + inventoryDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; + var adSpecial = db.AdSpecials.Single(x => x.Id == inventory.FkAdSpecialId); + inventoryDataGridView.Rows[index].Cells[1].Value = adSpecial.Name; + index++; + } inventoryDataGridView.Rows.Add(); inventoryDataGridView.Rows[index].Cells[0].Value = inventory.Id; inventoryDataGridView.Rows[index].Cells[1].Value = inventory.AdItem.Name; @@ -2892,15 +2903,6 @@ namespace AdvertsingProfitControl inventoryDataGridView.Rows[index].Cells[(int)InventoryTableColumns.IsMemberRow].Value = false; break; } - if (inventory.FkAdSpecialId != 0 && adSpecialIndex == -1) - { - adSpecialIndex = index; - inventoryDataGridView.Rows.Insert(index, 1); - //Apply the ad special text. - inventoryDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; - var adSpecial = db.AdSpecials.Single(x => x.Id == inventory.FkAdSpecialId); - inventoryDataGridView.Rows[index].Cells[1].Value = adSpecial.Name; - } index++; } //Manually write the row number to the new row. @@ -2927,6 +2929,16 @@ namespace AdvertsingProfitControl var index = 0; foreach (var actualSale in actualSales) { + if (actualSale.FkAdSpecialId != 0 && adSpecialIndex == -1) + { + adSpecialIndex = index; + actualSalesDataGridView.Rows.Insert(index, 1); + //Apply the ad special text. + actualSalesDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; + var adSpecial = db.AdSpecials.Single(x => x.Id == actualSale.FkAdSpecialId); + actualSalesDataGridView.Rows[index].Cells[1].Value = adSpecial.Name; + index++; + } actualSalesDataGridView.Rows.Add(); actualSalesDataGridView.Rows[index].Cells[0].Value = actualSale.Id; actualSalesDataGridView.Rows[index].Cells[1].Value = actualSale.AdItem.Name; @@ -2955,15 +2967,6 @@ namespace AdvertsingProfitControl actualSalesDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsMemberRow].Value = false; break; } - if (actualSale.FkAdSpecialId != 0 && adSpecialIndex == -1) - { - adSpecialIndex = index; - actualSalesDataGridView.Rows.Insert(index, 1); - //Apply the ad special text. - actualSalesDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; - var adSpecial = db.AdSpecials.Single(x => x.Id == actualSale.FkAdSpecialId); - actualSalesDataGridView.Rows[index].Cells[1].Value = adSpecial.Name; - } index++; } //Manually write the row number to the new row. @@ -3403,14 +3406,27 @@ namespace AdvertsingProfitControl scope.Complete(); } //All completed without error so mark all the APC table rows as committed. - //TODO: Find a better way so this doesn't fire every time this method executes. for (var i = 0; i < projectionsDataGridView.RowCount - 1; i++) { - projectionsDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].Value = false; - projectionsDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - inventoryDataGridView.Rows[i].Cells[(int)InventoryTableColumns.IsDirty].Value = false; - inventoryDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - actualSalesDataGridView.Rows[i].Cells[(int)SalesTableColumns.IsDirty].Value = false; + //Prevent the ad special row from being marked in any way. + if (i == _adSpecialIndex) continue; + //Prevent rows pulled from that the database, that haven't been touched, from being marked as well. + if ((bool) projectionsDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].EditedFormattedValue) + { + projectionsDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].Value = false; + projectionsDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; + } + //Prevent rows pulled from that the database, that haven't been touched, from being marked as well. + if ((bool) inventoryDataGridView.Rows[i].Cells[(int)InventoryTableColumns.IsDirty].EditedFormattedValue) + { + inventoryDataGridView.Rows[i].Cells[(int) InventoryTableColumns.IsDirty].Value = false; + inventoryDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; + } + //Prevent rows pulled from that the database, that haven't been touched, from being marked as well. + if (!(bool) + actualSalesDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].EditedFormattedValue) + continue; + actualSalesDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].Value = false; actualSalesDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } } @@ -3420,7 +3436,6 @@ namespace AdvertsingProfitControl informationLabel.Text = e.Message; success = false; //Spin through all the rows and check to see if their IDs are in the database. - //TODO: WRITE CODE BLOCK for (var i = 0; i < projectionsDataGridView.RowCount - 1; i++) { if (projectionsDataGridView.Rows[i].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString() != string.Empty) @@ -3885,7 +3900,7 @@ namespace AdvertsingProfitControl : decimal.Parse( row.Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue .ToString()); - actualSale.FkAdItemId = -1;//adItem.Id; + actualSale.FkAdItemId = adItem.Id; actualSale.RowAttribute = rowAttribute; actualSale.RowPosition = row.Index + 1; }