Added a check for if the user changes an ad item to an ad special item. Fixed a bug that caused a crash when deleting a row in the APC tables (finally!).
This commit is contained in:
@@ -599,7 +599,7 @@ namespace AdvertsingProfitControl
|
||||
var parser = new RowParsing();
|
||||
if (parser.GetRowAttribute(dataGridView.Rows[e.RowIndex]) == RowAttribute.AdSpecialRow)
|
||||
{
|
||||
_adSpecialIndex = e.RowIndex;
|
||||
_adSpecialIndex = e.RowIndex;
|
||||
return;
|
||||
}
|
||||
//Section one (1) detected.
|
||||
@@ -717,6 +717,7 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
//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());
|
||||
FlagRowsAsDirty(dataGridView, currentRowIndex);
|
||||
}
|
||||
else if (currentRowIndex < _adSpecialIndex)
|
||||
{
|
||||
@@ -750,6 +751,8 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
//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());
|
||||
//Mark the rows as dirty before decrementing the _adSpecialIndex since this wouldn't account for the fact that the current row hasn't been cleared yet.
|
||||
FlagRowsAsDirty(dataGridView, currentRowIndex, _adSpecialIndex);
|
||||
//Also decrement the _adSpecialIndex so that it points to the correct row.
|
||||
_adSpecialIndex--;
|
||||
}
|
||||
@@ -781,6 +784,7 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
//If the ad item entered in the first cell is in the gUsedAdItems collection, then remove it from there.
|
||||
_usedAdItems[1].Remove(dataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString());
|
||||
FlagRowsAsDirty(dataGridView, currentRowIndex);
|
||||
}
|
||||
else if (currentRowIndex == _adSpecialIndex)
|
||||
{
|
||||
@@ -860,11 +864,31 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
e.Cancel = true;
|
||||
}
|
||||
//Mark all rows under the row that just got deleted as dirty.
|
||||
}
|
||||
|
||||
private void FlagRowsAsDirty(DataGridView dataGridView, int currentRowIndex, int adSpecialIndex = -1)
|
||||
{
|
||||
//Check to see if the user started to add a row but then decided against it, does not mark the form dirty.
|
||||
if (dataGridView.Rows.Count != inventoryDataGridView.Rows.Count ||
|
||||
dataGridView.Rows.Count != actualSalesDataGridView.Rows.Count) return;
|
||||
for (var index = currentRowIndex; currentRowIndex < dataGridView.Rows.Count; index++)
|
||||
//Mark all rows under the row that just got deleted as dirty.
|
||||
_isFormDirty = true;
|
||||
for (var index = currentRowIndex; index < dataGridView.Rows.Count; index++)
|
||||
{
|
||||
//Do not color code the NewRow just break, we're done.
|
||||
if (dataGridView.Rows[index].IsNewRow) break;
|
||||
//Do not color code the Ad Special Row, just for preference.
|
||||
if (index == adSpecialIndex)
|
||||
{
|
||||
//Clear it's row color coding just in-case the user clears more than one row.
|
||||
projectionsDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = false;
|
||||
projectionsDataGridView.Rows[index].HeaderCell.Style.BackColor = DefaultBackColor;
|
||||
inventoryDataGridView.Rows[index].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
|
||||
inventoryDataGridView.Rows[index].HeaderCell.Style.BackColor = DefaultBackColor;
|
||||
actualSalesDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = false;
|
||||
actualSalesDataGridView.Rows[index].HeaderCell.Style.BackColor = DefaultBackColor;
|
||||
continue;
|
||||
}
|
||||
projectionsDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = true;
|
||||
projectionsDataGridView.Rows[index].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
|
||||
inventoryDataGridView.Rows[index].Cells[(int)InventoryTableColumns.IsDirty].Value = true;
|
||||
@@ -1016,9 +1040,80 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
else
|
||||
{
|
||||
_adSpecialIndex = e.RowIndex;
|
||||
//Since this is the ad special row don't give it any color coding.
|
||||
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = DefaultBackColor;
|
||||
//Check to see if the ad special index has changed.
|
||||
if (_adSpecialIndex == -1)
|
||||
{
|
||||
//Check to see if there is an ID in the row and warn the user about the row deletion.
|
||||
if (
|
||||
dataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.Id].EditedFormattedValue
|
||||
.ToString() != string.Empty)
|
||||
{
|
||||
var result =
|
||||
MessageBox.Show(
|
||||
@"Performing this operation will clear '" + _beginningCellValue +
|
||||
@"' from the database. Do you wish to continue?",
|
||||
@"Delete " + _beginningCellValue + @" Permanently", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Information);
|
||||
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
if (!dbW.DeleteApcRow(
|
||||
int.Parse(
|
||||
projectionsDataGridView.Rows[e.RowIndex].Cells[
|
||||
(int) SalesTableColumns.Id].EditedFormattedValue.ToString()),
|
||||
int.Parse(
|
||||
inventoryDataGridView.Rows[e.RowIndex].Cells[
|
||||
(int) InventoryTableColumns.Id].EditedFormattedValue.ToString()),
|
||||
int.Parse(
|
||||
actualSalesDataGridView.Rows[e.RowIndex].Cells[
|
||||
(int) SalesTableColumns.Id].EditedFormattedValue.ToString())))
|
||||
{
|
||||
//Error out, it failed to be cleared.
|
||||
MessageBox.Show(
|
||||
@"Failed to delete '" + _beginningCellValue +
|
||||
@"' from the database, cannot replace ad item with " + userInput + @"'.",
|
||||
@"Failed to Delete Row", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//Flag the rows under the changed row as dirty.
|
||||
FlagRowsAsDirty(dataGridView, e.RowIndex + 1);
|
||||
//_beginningCellValue has the ad item that was destroyed.
|
||||
_usedAdItems[0].Remove(_beginningCellValue);
|
||||
//Now update the UsedAdItemCollection
|
||||
for (var i = e.RowIndex + 1; i < _usedAdItems[0].Count; i++)
|
||||
{
|
||||
//Wow this seems to work... well one shot baby!
|
||||
_usedAdItems[1].Add(_usedAdItems[0][i]);
|
||||
_usedAdItems[0].RemoveAt(e.RowIndex + 1);
|
||||
}
|
||||
//Mark row as Ad Special.
|
||||
projectionsDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor =
|
||||
ApplicationColors.AdSpecial;
|
||||
projectionsDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value =
|
||||
false;
|
||||
inventoryDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor =
|
||||
ApplicationColors.AdSpecial;
|
||||
inventoryDataGridView.Rows[e.RowIndex].Cells[(int) InventoryTableColumns.IsDirty].Value
|
||||
= false;
|
||||
actualSalesDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor =
|
||||
ApplicationColors.AdSpecial;
|
||||
actualSalesDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value =
|
||||
false;
|
||||
ClearRow(e.RowIndex);
|
||||
_adSpecialIndex = e.RowIndex;
|
||||
//Since this is the ad special row don't give it any color coding.
|
||||
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = DefaultBackColor;
|
||||
}
|
||||
}
|
||||
//Force a refresh so the cell's text updates and displays for the user.
|
||||
dataGridView.RefreshEdit();
|
||||
@@ -1463,9 +1558,64 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
else
|
||||
{
|
||||
_adSpecialIndex = e.RowIndex;
|
||||
//Since this is the ad special row don't give it any color coding.
|
||||
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = DefaultBackColor;
|
||||
//Check to see if the ad special index has changed.
|
||||
if (e.RowIndex != _adSpecialIndex && _adSpecialIndex == -1)
|
||||
{
|
||||
//Check to see if there is an ID in the row and warn the user about the row deletion.
|
||||
if (dataGridView.Rows[e.RowIndex].Cells[(int)InventoryTableColumns.Id].EditedFormattedValue.ToString() != string.Empty)
|
||||
{
|
||||
var result = MessageBox.Show(@"Performing this operation will clear '" + _beginningCellValue + @"' from the database. Do you wish to continue?", @"Delete " + _beginningCellValue + @" Permanently", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
||||
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
if (!dbW.DeleteApcRow(
|
||||
int.Parse(
|
||||
projectionsDataGridView.Rows[e.RowIndex].Cells[
|
||||
(int)SalesTableColumns.Id].EditedFormattedValue.ToString()),
|
||||
int.Parse(
|
||||
inventoryDataGridView.Rows[e.RowIndex].Cells[
|
||||
(int)InventoryTableColumns.Id].EditedFormattedValue.ToString()),
|
||||
int.Parse(
|
||||
actualSalesDataGridView.Rows[e.RowIndex].Cells[
|
||||
(int)SalesTableColumns.Id].EditedFormattedValue.ToString())))
|
||||
{
|
||||
//Error out, it failed to be cleared.
|
||||
MessageBox.Show(@"Failed to delete '" + _beginningCellValue + @"' from the database, cannot replace ad item with " + userInput + @"'.", @"Failed to Delete Row", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//Flag the rows under the changed row as dirty.
|
||||
FlagRowsAsDirty(dataGridView, e.RowIndex + 1);
|
||||
//_beginningCellValue has the ad item that was destroyed.
|
||||
_usedAdItems[0].Remove(_beginningCellValue);
|
||||
//Now update the UsedAdItemCollection
|
||||
for (var i = e.RowIndex + 1; i < _usedAdItems[0].Count; i++)
|
||||
{
|
||||
//Wow this seems to work... well one shot baby!
|
||||
_usedAdItems[1].Add(_usedAdItems[0][i]);
|
||||
_usedAdItems[0].RemoveAt(e.RowIndex + 1);
|
||||
}
|
||||
//Mark row as Ad Special.
|
||||
projectionsDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
|
||||
projectionsDataGridView.Rows[e.RowIndex].Cells[(int)SalesTableColumns.IsDirty].Value = false;
|
||||
inventoryDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
|
||||
inventoryDataGridView.Rows[e.RowIndex].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
|
||||
actualSalesDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial;
|
||||
actualSalesDataGridView.Rows[e.RowIndex].Cells[(int)SalesTableColumns.IsDirty].Value = false;
|
||||
ClearRow(e.RowIndex);
|
||||
_adSpecialIndex = e.RowIndex;
|
||||
//Since this is the ad special row don't give it any color coding.
|
||||
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = DefaultBackColor;
|
||||
}
|
||||
}
|
||||
//Force a refresh so the cell's text updates and displays for the user.
|
||||
dataGridView.RefreshEdit();
|
||||
@@ -4279,5 +4429,37 @@ namespace AdvertsingProfitControl
|
||||
actualSalesDataGridView.RowValidating += ValidateActualSalesRow;
|
||||
//END ENABLE EVENTS
|
||||
}
|
||||
|
||||
private void ClearRow(int rowIndex)
|
||||
{
|
||||
foreach (DataGridViewCell cell in projectionsDataGridView.Rows[rowIndex].Cells)
|
||||
{
|
||||
if (cell.ColumnIndex == (int) SalesTableColumns.AdItem) continue;
|
||||
var actualSalesCell = actualSalesDataGridView.Rows[rowIndex].Cells[cell.ColumnIndex];
|
||||
if (cell.ColumnIndex < (int) SalesTableColumns.IsHeaderRow)
|
||||
{
|
||||
cell.Value = string.Empty;
|
||||
actualSalesCell.Value = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.Value = false;
|
||||
actualSalesCell.Value = false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (DataGridViewCell cell in inventoryDataGridView.Rows[rowIndex].Cells)
|
||||
{
|
||||
if (cell.ColumnIndex == (int)InventoryTableColumns.AdItem) continue;
|
||||
if (cell.ColumnIndex < (int)InventoryTableColumns.IsHeaderRow)
|
||||
{
|
||||
cell.Value = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.Value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>qslhA++lVLBctd11zuiyGxsc1HQGD2NdhJMAlbYkvSA=</dsig:DigestValue>
|
||||
<dsig:DigestValue>ffANB5BH9jvoyfR09JBLV4mTjMowgtoLxga6w/HpWLU=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
@@ -43,14 +43,14 @@
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3652096">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3655168">
|
||||
<assemblyIdentity name="AdvertsingProfitControl" version="1.9.2.0" language="neutral" processorArchitecture="amd64" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>hvMMYVQ3UshVHNWRVBHGms+WBonEb7cFKwhPKPfr7zw=</dsig:DigestValue>
|
||||
<dsig:DigestValue>X7+5y23vASKIWqD7axQzZHiWBiU+8VPagqUiqgXGMTw=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
Reference in New Issue
Block a user