Fixed a bug on the modify record form where updating an existing row's ad item wouldn't mark the other APC tables as dirty.

This commit is contained in:
2017-01-17 14:15:21 -06:00
parent c9d8186d75
commit 2b3c234aaa
7 changed files with 237 additions and 26 deletions
+211 -14
View File
@@ -1027,7 +1027,11 @@ namespace AdvertsingProfitControl
{
var adItemText = projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString();
actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText;
actualSalesDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value = true;
actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText;
inventoryDataGridView.Rows[e.RowIndex].Cells[(int) InventoryTableColumns.IsDirty].Value = true;
inventoryDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
projectionsDataGridView.RefreshEdit();
//Remove the last ad item from the UsedAdItem array, the new one will be added in the OnRowLeave event handler.
if (_adSpecialIndex == -1 || e.RowIndex < _adSpecialIndex)
@@ -1385,7 +1389,11 @@ namespace AdvertsingProfitControl
{
var adItemText = inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString();
projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText;
projectionsDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value = true;
projectionsDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText;
actualSalesDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value = true;
actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
//inventoryDataGridView.RefreshEdit();
//Remove the last ad item from the UsedAdItem array, the new one will be added in the OnRowLeave event handler.
if (_adSpecialIndex == -1 || e.RowIndex < _adSpecialIndex)
@@ -1542,7 +1550,11 @@ namespace AdvertsingProfitControl
{
var adItemText = actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString();
projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText;
projectionsDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value = true;
projectionsDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Value = adItemText;
inventoryDataGridView.Rows[e.RowIndex].Cells[(int) InventoryTableColumns.IsDirty].Value = true;
inventoryDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
//projectionsDataGridView.RefreshEdit();
//Remove the last ad item from the UsedAdItem array, the new one will be added in the OnRowLeave event handler.
if (_adSpecialIndex == -1 || e.RowIndex < _adSpecialIndex)
@@ -2127,15 +2139,27 @@ namespace AdvertsingProfitControl
var projections = databaseReader.ReturnProjectionsTable(dateId, databaseTracker.DatabaseConnectionString);
var inventory = databaseReader.ReturnInventoryTable(dateId, databaseTracker.DatabaseConnectionString);
var actualSales = databaseReader.ReturnActualSales(dateId, databaseTracker.DatabaseConnectionString);
LoadApcTables(projections, inventory, actualSales);
LoadProjectionsTable(projections);
LoadInventory(inventory);
LoadActualSales(actualSales);
var invoices = databaseReader.ReturnInvoiceTable(dateId, databaseTracker.DatabaseConnectionString);
//Re-enable the events
projectionsDataGridView.CellEnter += StoreBeginningCellValue;
projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
projectionsDataGridView.CellValidating += ValidateSalesDataGridViewCellContents;
projectionsDataGridView.RowValidating += ValidateProjectedRow;
inventoryDataGridView.CellEnter += StoreBeginningCellValue;
inventoryDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
inventoryDataGridView.CellValidating += ValidateInventoryCellContents;
inventoryDataGridView.RowValidating += ValidateInventoryRow;
actualSalesDataGridView.CellEnter += StoreBeginningCellValue;
actualSalesDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
actualSalesDataGridView.CellValidating += ValidateSalesDataGridViewCellContents;
actualSalesDataGridView.RowValidating += ValidateActualSalesRow;
}
private void LoadApcTables(DataTable projections, DataTable inventory, DataTable actualSales)
private void LoadProjectionsTable(DataTable projections)
{
//Assuming all the tables are correctly aligned.
//Disable the relevant events in the DataGridViews
@@ -2144,17 +2168,17 @@ namespace AdvertsingProfitControl
projectionsDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents;
projectionsDataGridView.RowValidating -= ValidateProjectedRow;
for(var i = 0; i < projections.Rows.Count; i++)
for(var rowIndex = 0; rowIndex < projections.Rows.Count; rowIndex++)
{
var newRow = new DataGridViewRow();
for (var cellIndex = 0; cellIndex < projections.Rows[i].ItemArray.Length; cellIndex++)
for (var cellIndex = 0; cellIndex < projections.Rows[rowIndex].ItemArray.Length; cellIndex++)
{
//ID and Ad Item.
if (cellIndex <= 1)
{
var cell = new DataGridViewTextBoxCell
{
Value = projections.Rows[i].ItemArray[cellIndex].ToString()
Value = projections.Rows[rowIndex].ItemArray[cellIndex].ToString()
};
newRow.Cells.Add(cell);
continue;
@@ -2162,14 +2186,14 @@ namespace AdvertsingProfitControl
//Everything in between the ad item cell and the row attribute cells.
if (cellIndex > 1 && cellIndex <= 7)
{
if (projections.Rows[i].ItemArray[cellIndex].ToString() == "0")
if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
{
var cell = new DataGridViewTextBoxCell {Value = ""};
newRow.Cells.Add(cell);
}
else
{
var cell = new DataGridViewTextBoxCell { Value = projections.Rows[i].ItemArray[cellIndex].ToString() };
var cell = new DataGridViewTextBoxCell { Value = projections.Rows[rowIndex].ItemArray[cellIndex].ToString() };
newRow.Cells.Add(cell);
}
continue;
@@ -2179,7 +2203,7 @@ namespace AdvertsingProfitControl
{
var isHeaderCell = new DataGridViewCheckBoxCell(false);
var isMemberCell = new DataGridViewCheckBoxCell(false);
var rowAttribute = int.Parse(projections.Rows[i].ItemArray[cellIndex].ToString());
var rowAttribute = int.Parse(projections.Rows[rowIndex].ItemArray[cellIndex].ToString());
switch (rowAttribute)
{
case 1:
@@ -2200,25 +2224,198 @@ namespace AdvertsingProfitControl
//Check the group it is part of if any.
if (cellIndex == 9)
{
if (projections.Rows[i].ItemArray[cellIndex].ToString() != "0" && _adSpecialIndex == -1)
if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() != "0" && _adSpecialIndex == -1)
{
var databaseTracker = new DatabaseTracker();
var databaseReader = new DatabaseReader();
var groupName =
databaseReader.ReturnGroupNameFromGroupId(
projections.Rows[i].ItemArray[cellIndex].ToString(),
projections.Rows[rowIndex].ItemArray[cellIndex].ToString(),
databaseTracker.DatabaseConnectionString);
var adSpecialRow = new DataGridViewRow();
projectionsDataGridView.Rows.Add(adSpecialRow);
projectionsDataGridView.Rows[i].Cells[1].Value = groupName;
projectionsDataGridView.Rows[i].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
_adSpecialIndex = i;
projectionsDataGridView.Rows[rowIndex].Cells[1].Value = groupName;
projectionsDataGridView.Rows[rowIndex].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
_adSpecialIndex = rowIndex;
}
}
}
projectionsDataGridView.Rows.Add(newRow);
}
//Re-enable the events
}
private void LoadInventory(DataTable inventoryTable)
{
//Assuming all the tables are correctly aligned.
//Disable the relevant events in the DataGridViews
inventoryDataGridView.CellEnter -= StoreBeginningCellValue;
inventoryDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave;
inventoryDataGridView.CellValidating -= ValidateInventoryCellContents;
inventoryDataGridView.RowValidating -= ValidateInventoryRow;
//Create a local ad special index since Projections should have filled the ad special index in for the class.
var adSpecialIndex = -1;
for (var rowIndex = 0; rowIndex < inventoryTable.Rows.Count; rowIndex++)
{
var newRow = new DataGridViewRow();
for (var cellIndex = 0; cellIndex < inventoryTable.Rows[rowIndex].ItemArray.Length; cellIndex++)
{
//ID and Ad Item.
if (cellIndex <= 1)
{
var cell = new DataGridViewTextBoxCell
{
Value = inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString()
};
newRow.Cells.Add(cell);
continue;
}
//Everything in between the ad item cell and the row attribute cells.
if (cellIndex > 1 && cellIndex <= 5)
{
if (inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
{
var cell = new DataGridViewTextBoxCell { Value = "" };
newRow.Cells.Add(cell);
}
else
{
var cell = new DataGridViewTextBoxCell { Value = inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() };
newRow.Cells.Add(cell);
}
continue;
}
//Check the attribute cell.
if (cellIndex == 6)
{
var isHeaderCell = new DataGridViewCheckBoxCell(false);
var isMemberCell = new DataGridViewCheckBoxCell(false);
var rowAttribute = int.Parse(inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString());
switch (rowAttribute)
{
case 1:
//Header row
isHeaderCell.Value = true;
newRow.DefaultCellStyle.BackColor = ApplicationColors.HeaderRow;
break;
case 2:
//Member Row
isMemberCell.Value = true;
newRow.DefaultCellStyle.BackColor = ApplicationColors.MemberRow;
break;
}
newRow.Cells.Add(isHeaderCell);
newRow.Cells.Add(isMemberCell);
continue;
}
//Check the group it is part of if any.
if (cellIndex == 7)
{
if (inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() != "0" && adSpecialIndex == -1)
{
var databaseTracker = new DatabaseTracker();
var databaseReader = new DatabaseReader();
var groupName =
databaseReader.ReturnGroupNameFromGroupId(
inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString(),
databaseTracker.DatabaseConnectionString);
var adSpecialRow = new DataGridViewRow();
inventoryDataGridView.Rows.Add(adSpecialRow);
inventoryDataGridView.Rows[rowIndex].Cells[1].Value = groupName;
inventoryDataGridView.Rows[rowIndex].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
adSpecialIndex = rowIndex;
}
}
}
inventoryDataGridView.Rows.Add(newRow);
}
}
public void LoadActualSales(DataTable actualSales)
{
//Assuming all the tables are correctly aligned.
//Disable the relevant events in the DataGridViews
actualSalesDataGridView.CellEnter -= StoreBeginningCellValue;
actualSalesDataGridView.RowLeave -= UpdateUsedAdItemCollectionOnRowLeave;
actualSalesDataGridView.CellValidating -= ValidateSalesDataGridViewCellContents;
actualSalesDataGridView.RowValidating -= ValidateActualSalesRow;
//Create a local ad special index since Projections should have filled the ad special index in for the class.
var adSpecialIndex = -1;
for (var rowIndex = 0; rowIndex < actualSales.Rows.Count; rowIndex++)
{
var newRow = new DataGridViewRow();
for (var cellIndex = 0; cellIndex < actualSales.Rows[rowIndex].ItemArray.Length; cellIndex++)
{
//ID and Ad Item.
if (cellIndex <= 1)
{
var cell = new DataGridViewTextBoxCell
{
Value = actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString()
};
newRow.Cells.Add(cell);
continue;
}
//Everything in between the ad item cell and the row attribute cells.
if (cellIndex > 1 && cellIndex <= 7)
{
if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
{
var cell = new DataGridViewTextBoxCell { Value = "" };
newRow.Cells.Add(cell);
}
else
{
var cell = new DataGridViewTextBoxCell { Value = actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() };
newRow.Cells.Add(cell);
}
continue;
}
//Check the attribute cell.
if (cellIndex == 8)
{
var isHeaderCell = new DataGridViewCheckBoxCell(false);
var isMemberCell = new DataGridViewCheckBoxCell(false);
var rowAttribute = int.Parse(actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString());
switch (rowAttribute)
{
case 1:
//Header row
isHeaderCell.Value = true;
newRow.DefaultCellStyle.BackColor = ApplicationColors.HeaderRow;
break;
case 2:
//Member Row
isMemberCell.Value = true;
newRow.DefaultCellStyle.BackColor = ApplicationColors.MemberRow;
break;
}
newRow.Cells.Add(isHeaderCell);
newRow.Cells.Add(isMemberCell);
continue;
}
//Check the group it is part of if any.
if (cellIndex == 9)
{
if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() != "0" && adSpecialIndex == -1)
{
var databaseTracker = new DatabaseTracker();
var databaseReader = new DatabaseReader();
var groupName =
databaseReader.ReturnGroupNameFromGroupId(
actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString(),
databaseTracker.DatabaseConnectionString);
var adSpecialRow = new DataGridViewRow();
actualSalesDataGridView.Rows.Add(adSpecialRow);
actualSalesDataGridView.Rows[rowIndex].Cells[1].Value = groupName;
actualSalesDataGridView.Rows[rowIndex].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
adSpecialIndex = rowIndex;
}
}
}
actualSalesDataGridView.Rows.Add(newRow);
}
}
private void NormalizeApcTables(DataTable projetions, DataTable inventory, DataTable actualSales, string dateId)