Fixed a bug when deleting non ad special rows the ad special index flag wouldn't get updated.
This commit is contained in:
@@ -280,15 +280,22 @@ namespace AdvertsingProfitControl
|
||||
private void UpdateUsedAdItemCollectionOnRowRemoving(object sender, CancelEventArgs e)
|
||||
{
|
||||
//Create an object that represents the DataGridView that fired the event.
|
||||
var dataGridView = ((DataGridView)sender);
|
||||
var dataGridView = (DataGridView)sender;
|
||||
if (dataGridView.CurrentRow == null) return;
|
||||
var currentRowIndex = dataGridView.CurrentRow.Index;
|
||||
//Remove the ad item from the gUsedAdItem collection, if it exists.
|
||||
if (_adSpecialIndex == -1 || currentRowIndex < _adSpecialIndex)
|
||||
if (_adSpecialIndex == -1)
|
||||
{
|
||||
//If the ad item entered in the first cell is in the gUsedAdItems collection, then remove it from there.
|
||||
_usedAdItems[0].Remove(dataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString());
|
||||
}
|
||||
else if (currentRowIndex < _adSpecialIndex)
|
||||
{
|
||||
//If the ad item entered in the first cell is in the gUsedAdItems collection, then remove it from there.
|
||||
_usedAdItems[0].Remove(dataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString());
|
||||
//Also decrement the _adSpecialIndex so that it points to the correct row.
|
||||
_adSpecialIndex--;
|
||||
}
|
||||
else if (currentRowIndex > _adSpecialIndex)
|
||||
{
|
||||
//If the ad item entered in the first cell is in the gUsedAdItems collection, then remove it from there.
|
||||
@@ -1552,8 +1559,6 @@ namespace AdvertsingProfitControl
|
||||
|
||||
private void getCellValueDebugMainMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
var dataGridView = (DataGridView)mainTabControl.TabPages[0].Controls[0];
|
||||
MessageBox.Show(dataGridView.CurrentRow.DefaultCellStyle.BackColor.Name);
|
||||
}
|
||||
|
||||
private void AddRecordsButtonClick(object sender, EventArgs e)
|
||||
@@ -1647,7 +1652,9 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
//Run the row parsing engine on all the APC tables.
|
||||
//Create the cleaned table objects that will be sent to the database.
|
||||
//var trimmedProjectionsTable = ConstructCleanedProjectionsTable(dateId);
|
||||
var trimmed = new DataTable();
|
||||
var update = new DataTable();
|
||||
var trimmedProjectionsTable = ConstructCleanedProjectionsTable(dateId, out trimmed, out update);
|
||||
//var trimmedInventoryTable = ConstructCleanedInventoryTable(dateId);
|
||||
//var trimmedActualSalesTable = ConstructCleanedActualSalesTable(dateId);
|
||||
//Create the transaction scope.
|
||||
@@ -1703,8 +1710,6 @@ namespace AdvertsingProfitControl
|
||||
var databaseReader = new DatabaseReader();
|
||||
var databaseWriter = new DatabaseWriter(databaseTracker.DatabaseConnectionString);
|
||||
var adSpecialId = 0; //Entries in the database are not allowed to be zero (unique ID wise that is).
|
||||
//Dictionary<AdItemID, TableID> The table ID is zero (0) for the new table and one (1) for the update table.
|
||||
var usedAdItems = new Dictionary<int, string>(); //Contains ad items that are used in section one, used for checking for repeats.
|
||||
//Grab the ad special ID, assuming there is one.
|
||||
if (_adSpecialIndex != -1)
|
||||
{
|
||||
@@ -1727,11 +1732,6 @@ namespace AdvertsingProfitControl
|
||||
//Check to see if the row is dirty.
|
||||
if (!(bool)row.Cells[(int)SalesTableColumns.IsDirty].Value)
|
||||
{
|
||||
//Log ad items from section one (1), recording their row index as the key.
|
||||
//If the ad special isn't set then ignore this operation entirely as its not necessary.
|
||||
if (_adSpecialIndex != -1 && row.Index < _adSpecialIndex)
|
||||
{
|
||||
}
|
||||
//If it is not then continue on to the next row.
|
||||
continue;
|
||||
}
|
||||
@@ -1746,53 +1746,62 @@ namespace AdvertsingProfitControl
|
||||
adItemId = databaseWriter.InsertNewAdItem(row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString());
|
||||
if (adItemId == 0)
|
||||
{
|
||||
errorLabel.Text = @"Failed to insert new ad item.";
|
||||
//TODO: Throw an exception, this can not be allowed.
|
||||
//AdItemInsertionFailedException
|
||||
trimmedTables[0].Rows.Clear(); //Work around for now
|
||||
trimmedTables[1].Rows.Clear();
|
||||
//throw new InvalidOperationException("Failed to add ad item.");
|
||||
//break;
|
||||
return TrimmingOperationResult.FailedToTrim;
|
||||
}
|
||||
}
|
||||
var tableIndex = 0;
|
||||
string spma;
|
||||
//Check for repeated ad items in the ad special section
|
||||
if (usedAdItems.TryGetValue(adItemId, out spma))
|
||||
if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex)
|
||||
{
|
||||
//If the ad item is being used in section one then locate it and update it in the trimmed table.
|
||||
var foundRow = trimmedTables[tableIndex].Select("AdItemID = '" + adItemId + "'");
|
||||
if (foundRow.Length == 1)
|
||||
//Attempt to grab the index of an ad item, if it is not found then the return value is -1.
|
||||
var repeatedItemIndex =
|
||||
_usedAdItems[0].FindIndex(x => x == row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString());
|
||||
//Check if a repeat was found.
|
||||
if (repeatedItemIndex != -1)
|
||||
{
|
||||
LogConsole.WriteToLog(FrmLogConsole.Level.Info,
|
||||
"Ad item '" + row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue +
|
||||
"' found in the trimmed table.");
|
||||
LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Repeated ad item '" + row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue + "' found.");
|
||||
LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Its row index is " + repeatedItemIndex + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO: Throw an exception, this can not be allowed.
|
||||
//InvalidTrimmedRowCountException
|
||||
trimmedTables[0].Rows.Clear(); //Work around for now
|
||||
trimmedTables[1].Rows.Clear();
|
||||
break;
|
||||
}
|
||||
//Begin spinning through all the rows to find the one selected above.
|
||||
for (var i = 0; i < trimmedTables[tableIndex].Rows.Count; i++)
|
||||
{
|
||||
//Check to see if the selected row is equal.
|
||||
if (foundRow[0] != trimmedTables[tableIndex].Rows[i]) continue;
|
||||
//If so then update that row index with the group ID number.
|
||||
if (tableIndex == 0)
|
||||
{
|
||||
trimmedTables[0].Rows[i][8] = adSpecialId;
|
||||
}
|
||||
else
|
||||
{
|
||||
trimmedTables[1].Rows[i][9] = adSpecialId;
|
||||
}
|
||||
}
|
||||
//Once ad special ID has been updated jump to the next row.
|
||||
continue;
|
||||
//if (_usedAdItems[0].Contains(row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString()))
|
||||
//{
|
||||
// //If the ad item is being used in section one then locate it and update it in the trimmed table.
|
||||
// var foundRow = trimmedTables[tableIndex].Select("AdItemID = '" + adItemId + "'");
|
||||
// if (foundRow.Length == 1)
|
||||
// {
|
||||
// LogConsole.WriteToLog(FrmLogConsole.Level.Info,
|
||||
// "Ad item '" + row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue +
|
||||
// "' found in the trimmed table.");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //TODO: Throw an exception, this can not be allowed.
|
||||
// //InvalidTrimmedRowCountException
|
||||
// trimmedTables[0].Rows.Clear(); //Work around for now
|
||||
// trimmedTables[1].Rows.Clear();
|
||||
// return TrimmingOperationResult.FailedToTrim;
|
||||
// }
|
||||
// //Begin spinning through all the rows to find the one selected above.
|
||||
// for (var i = 0; i < trimmedTables[tableIndex].Rows.Count; i++)
|
||||
// {
|
||||
// //Check to see if the selected row is equal.
|
||||
// if (foundRow[0] != trimmedTables[tableIndex].Rows[i]) continue;
|
||||
// //If so then update that row index with the group ID number.
|
||||
// if (tableIndex == 0)
|
||||
// {
|
||||
// trimmedTables[0].Rows[i][8] = adSpecialId;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// trimmedTables[1].Rows[i][9] = adSpecialId;
|
||||
// }
|
||||
// }
|
||||
// //Once ad special ID has been updated jump to the next row.
|
||||
// continue;
|
||||
//}
|
||||
}
|
||||
//Determine the row's attribute.
|
||||
var rowAttribute = 0; //Zero (0) means no grouping, its not a header nor a member.
|
||||
@@ -1807,7 +1816,7 @@ namespace AdvertsingProfitControl
|
||||
//Since we've made it this far, add the ad item into the dictionary if we're not in the ad special group.
|
||||
if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex)
|
||||
{
|
||||
usedAdItems.Add(row.Index, "s");
|
||||
//usedAdItems.Add(row.Index, "s");
|
||||
}
|
||||
//Add the values to their respective data table.
|
||||
if (rowIdNumber == 0)
|
||||
@@ -1834,7 +1843,7 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
newRow[10] = dateId;
|
||||
trimmedTables[0].Rows.Add(newRow);
|
||||
usedAdItems.Add(adItemId, "0");
|
||||
//usedAdItems.Add(adItemId, "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1861,7 +1870,7 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
newRow[11] = dateId;
|
||||
trimmedTables[1].Rows.Add(newRow);
|
||||
usedAdItems.Add(adItemId, "1");
|
||||
//usedAdItems.Add(adItemId, "1");
|
||||
}
|
||||
//LogConsole.WriteToLog(FrmLogConsole.Level.Verbose, "Row Dump for row number " + (row.Index + 1) + ".");
|
||||
//LogConsole.WriteToLog(FrmLogConsole.Level.Verbose, "ID : " + rowIdNumber + " Sold: " + row.Cells[(int)SalesTableColumns.Sold].EditedFormattedValue);
|
||||
|
||||
Reference in New Issue
Block a user