Updated the APC table builder so zeros won't show in some columns. Changed the ad special index setting to the cell validation event, and stabilized the user changing an ad item to an ad special keyword. Fixed a bug where saying no to deleting a row wouldn't work.
This commit is contained in:
@@ -550,7 +550,6 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
var table = ((DataGridView)sender);
|
||||
table.Rows[e.RowIndex].HeaderCell.Value = (e.RowIndex + 1).ToString();
|
||||
LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Added row at Index " + e.RowIndex + " in " + table.Name + ".");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -596,12 +595,6 @@ namespace AdvertsingProfitControl
|
||||
//Add in used Ad Items to the list.
|
||||
if (userInput == string.Empty) return;
|
||||
//Clear the old ad item out of the used ad item collection.
|
||||
var parser = new RowParsing();
|
||||
if (parser.GetRowAttribute(dataGridView.Rows[e.RowIndex]) == RowAttribute.AdSpecialRow)
|
||||
{
|
||||
_adSpecialIndex = e.RowIndex;
|
||||
return;
|
||||
}
|
||||
//Section one (1) detected.
|
||||
if (_adSpecialIndex == -1 || e.RowIndex < _adSpecialIndex)
|
||||
{
|
||||
@@ -609,7 +602,7 @@ namespace AdvertsingProfitControl
|
||||
_usedAdItems[0].Add(userInput);
|
||||
}
|
||||
//Section two (2) detected.
|
||||
else
|
||||
else if(e.RowIndex > _adSpecialIndex)
|
||||
{
|
||||
if (_usedAdItems[1].Contains(userInput)) return;
|
||||
_usedAdItems[1].Add(userInput);
|
||||
@@ -698,22 +691,35 @@ namespace AdvertsingProfitControl
|
||||
int inventoryRowId;
|
||||
int actualSalesRowId;
|
||||
//Attempt to delete the row from the database by its ID number.
|
||||
int.TryParse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out projectionsRowId);
|
||||
int.TryParse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out inventoryRowId);
|
||||
int.TryParse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out actualSalesRowId);
|
||||
int.TryParse(
|
||||
projectionsDataGridView.Rows[currentRowIndex].Cells[(int) SalesTableColumns.Id]
|
||||
.EditedFormattedValue.ToString(), out projectionsRowId);
|
||||
int.TryParse(
|
||||
inventoryDataGridView.Rows[currentRowIndex].Cells[(int) SalesTableColumns.Id]
|
||||
.EditedFormattedValue.ToString(), out inventoryRowId);
|
||||
int.TryParse(
|
||||
actualSalesDataGridView.Rows[currentRowIndex].Cells[(int) SalesTableColumns.Id]
|
||||
.EditedFormattedValue.ToString(), out actualSalesRowId);
|
||||
if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
{
|
||||
informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database.";
|
||||
informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) +
|
||||
@" from the database.";
|
||||
}
|
||||
else
|
||||
{
|
||||
//If the removing failed cancel the row deletion in the DataGridView.
|
||||
e.Cancel = true;
|
||||
MessageBox.Show(@"Failed to delete " + dataGridView.Rows[currentRowIndex].Cells[1].EditedFormattedValue +
|
||||
MessageBox.Show(
|
||||
@"Failed to delete " + dataGridView.Rows[currentRowIndex].Cells[1].EditedFormattedValue +
|
||||
@" from the database.", @"Failed to Update Database");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//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());
|
||||
@@ -748,6 +754,11 @@ namespace AdvertsingProfitControl
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//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());
|
||||
@@ -781,6 +792,11 @@ namespace AdvertsingProfitControl
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//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());
|
||||
@@ -1031,7 +1047,8 @@ namespace AdvertsingProfitControl
|
||||
//Clear the error text since there is in fact an item entered.
|
||||
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = string.Empty;
|
||||
//Send the ad item text through the formatting engine and assign the new value to the cell.
|
||||
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = TextFormat.FormatAdItemText(userInput);
|
||||
userInput = TextFormat.FormatAdItemText(userInput);
|
||||
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = userInput;
|
||||
var parser = new RowParsing();
|
||||
if (parser.CheckForGroupKeyWord(userInput) == "NoGroupFound")
|
||||
{
|
||||
@@ -1078,9 +1095,24 @@ namespace AdvertsingProfitControl
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
//Update the color coding of the other tables.
|
||||
var helperClass = new AdvertisingProfitControlTableHelper();
|
||||
helperClass.PaintRowGroupsFromIndex(e.RowIndex - 1, projectionsDataGridView);
|
||||
if (inventoryDataGridView.RowCount > e.RowIndex)
|
||||
{
|
||||
inventoryDataGridView.Rows[e.RowIndex].Cells[(int) InventoryTableColumns.AdItem].Value = userInput;
|
||||
}
|
||||
helperClass.PaintRowGroupsFromIndex(e.RowIndex - 1, inventoryDataGridView);
|
||||
if (actualSalesDataGridView.RowCount > e.RowIndex)
|
||||
{
|
||||
actualSalesDataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.AdItem].Value = userInput;
|
||||
}
|
||||
helperClass.PaintRowGroupsFromIndex(e.RowIndex - 1, actualSalesDataGridView);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = _beginningCellValue;
|
||||
dataGridView.RefreshEdit();
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
@@ -1559,7 +1591,7 @@ namespace AdvertsingProfitControl
|
||||
else
|
||||
{
|
||||
//Check to see if the ad special index has changed.
|
||||
if (e.RowIndex != _adSpecialIndex && _adSpecialIndex == -1)
|
||||
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)InventoryTableColumns.Id].EditedFormattedValue.ToString() != string.Empty)
|
||||
@@ -1586,9 +1618,24 @@ namespace AdvertsingProfitControl
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
//Update the color coding of the other tables.
|
||||
var helperClass = new AdvertisingProfitControlTableHelper();
|
||||
helperClass.PaintRowGroupsFromIndex(e.RowIndex - 1, projectionsDataGridView);
|
||||
if (inventoryDataGridView.RowCount > e.RowIndex)
|
||||
{
|
||||
inventoryDataGridView.Rows[e.RowIndex].Cells[(int)InventoryTableColumns.AdItem].Value = userInput;
|
||||
}
|
||||
helperClass.PaintRowGroupsFromIndex(e.RowIndex - 1, inventoryDataGridView);
|
||||
if (actualSalesDataGridView.RowCount > e.RowIndex)
|
||||
{
|
||||
actualSalesDataGridView.Rows[e.RowIndex].Cells[(int)SalesTableColumns.AdItem].Value = userInput;
|
||||
}
|
||||
helperClass.PaintRowGroupsFromIndex(e.RowIndex - 1, actualSalesDataGridView);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = _beginningCellValue;
|
||||
dataGridView.RefreshEdit();
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
@@ -2832,6 +2879,7 @@ namespace AdvertsingProfitControl
|
||||
for (var rowIndex = 0; rowIndex < projections.Rows.Count; rowIndex++)
|
||||
{
|
||||
var newRow = new DataGridViewRow();
|
||||
var isMemberRow = false;
|
||||
for (var cellIndex = 0; cellIndex < projections.Rows[rowIndex].ItemArray.Length; cellIndex++)
|
||||
{
|
||||
//ID and Ad Item.
|
||||
@@ -2847,7 +2895,13 @@ namespace AdvertsingProfitControl
|
||||
//Everything in between the ad item cell and the row attribute cells.
|
||||
if (cellIndex > 1 && cellIndex <= 7)
|
||||
{
|
||||
if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0.0000")
|
||||
//Only allow zeros in the Sold columns otherwise just leave them blank.
|
||||
if (cellIndex == (int) SalesTableColumns.Sold)
|
||||
{
|
||||
var cell = new DataGridViewTextBoxCell { Value = projections.Rows[rowIndex].ItemArray[cellIndex].ToString() };
|
||||
newRow.Cells.Add(cell);
|
||||
}
|
||||
else if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0.0000" || projections.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
|
||||
{
|
||||
var cell = new DataGridViewTextBoxCell {Value = string.Empty};
|
||||
newRow.Cells.Add(cell);
|
||||
@@ -2875,6 +2929,7 @@ namespace AdvertsingProfitControl
|
||||
case 2:
|
||||
//Member Row
|
||||
isMemberCell.Value = true;
|
||||
isMemberRow = true;
|
||||
newRow.DefaultCellStyle.BackColor = ApplicationColors.MemberRow;
|
||||
break;
|
||||
default:
|
||||
@@ -2913,6 +2968,15 @@ namespace AdvertsingProfitControl
|
||||
_usedAdItems[0].Add(projections.Rows[rowIndex].ItemArray[1].ToString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!isMemberRow) continue;
|
||||
//Clear all values from the member row, they are not needed.
|
||||
newRow.Cells[2].Value = string.Empty;
|
||||
newRow.Cells[3].Value = string.Empty;
|
||||
newRow.Cells[4].Value = string.Empty;
|
||||
newRow.Cells[5].Value = string.Empty;
|
||||
newRow.Cells[6].Value = string.Empty;
|
||||
newRow.Cells[7].Value = string.Empty;
|
||||
}
|
||||
//Set the is dirty cell to false.
|
||||
var isDirtyCell = new DataGridViewCheckBoxCell
|
||||
@@ -2945,6 +3009,7 @@ namespace AdvertsingProfitControl
|
||||
for (var rowIndex = 0; rowIndex < inventoryTable.Rows.Count; rowIndex++)
|
||||
{
|
||||
var newRow = new DataGridViewRow();
|
||||
var isMemberRow = false;
|
||||
for (var cellIndex = 0; cellIndex < inventoryTable.Rows[rowIndex].ItemArray.Length; cellIndex++)
|
||||
{
|
||||
//ID and Ad Item.
|
||||
@@ -2960,16 +3025,8 @@ namespace AdvertsingProfitControl
|
||||
//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 = string.Empty};
|
||||
newRow.Cells.Add(cell);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cell = new DataGridViewTextBoxCell {Value = inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString()};
|
||||
newRow.Cells.Add(cell);
|
||||
}
|
||||
var cell = new DataGridViewTextBoxCell {Value = inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString()};
|
||||
newRow.Cells.Add(cell);
|
||||
continue;
|
||||
}
|
||||
//Check the attribute cell.
|
||||
@@ -2988,6 +3045,7 @@ namespace AdvertsingProfitControl
|
||||
case 2:
|
||||
//Member Row
|
||||
isMemberCell.Value = true;
|
||||
isMemberRow = true;
|
||||
newRow.DefaultCellStyle.BackColor = ApplicationColors.MemberRow;
|
||||
break;
|
||||
default:
|
||||
@@ -3003,7 +3061,7 @@ namespace AdvertsingProfitControl
|
||||
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);
|
||||
@@ -3014,6 +3072,13 @@ namespace AdvertsingProfitControl
|
||||
adSpecialIndex = rowIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isMemberRow) continue;
|
||||
//Clear all values from the member row, they are not needed.
|
||||
newRow.Cells[2].Value = string.Empty;
|
||||
newRow.Cells[3].Value = string.Empty;
|
||||
newRow.Cells[4].Value = string.Empty;
|
||||
newRow.Cells[5].Value = string.Empty;
|
||||
}
|
||||
//Set the is dirty cell to false.
|
||||
var isDirtyCell = new DataGridViewCheckBoxCell
|
||||
@@ -3046,6 +3111,7 @@ namespace AdvertsingProfitControl
|
||||
for (var rowIndex = 0; rowIndex < actualSales.Rows.Count; rowIndex++)
|
||||
{
|
||||
var newRow = new DataGridViewRow();
|
||||
var isMemberRow = false;
|
||||
for (var cellIndex = 0; cellIndex < actualSales.Rows[rowIndex].ItemArray.Length; cellIndex++)
|
||||
{
|
||||
//ID and Ad Item.
|
||||
@@ -3061,9 +3127,15 @@ namespace AdvertsingProfitControl
|
||||
//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.0000")
|
||||
//Only allow zeros in the Sold columns otherwise just leave them blank.
|
||||
if (cellIndex == (int)SalesTableColumns.Sold)
|
||||
{
|
||||
var cell = new DataGridViewTextBoxCell {Value = string.Empty};
|
||||
var cell = new DataGridViewTextBoxCell { Value = actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() };
|
||||
newRow.Cells.Add(cell);
|
||||
}
|
||||
else if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0.0000" || actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
|
||||
{
|
||||
var cell = new DataGridViewTextBoxCell { Value = string.Empty };
|
||||
newRow.Cells.Add(cell);
|
||||
}
|
||||
else
|
||||
@@ -3089,6 +3161,7 @@ namespace AdvertsingProfitControl
|
||||
case 2:
|
||||
//Member Row
|
||||
isMemberCell.Value = true;
|
||||
isMemberRow = true;
|
||||
newRow.DefaultCellStyle.BackColor = ApplicationColors.MemberRow;
|
||||
break;
|
||||
default:
|
||||
@@ -3115,6 +3188,15 @@ namespace AdvertsingProfitControl
|
||||
adSpecialIndex = rowIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isMemberRow) continue;
|
||||
//Clear all values from the member row, they are not needed.
|
||||
newRow.Cells[2].Value = string.Empty;
|
||||
newRow.Cells[3].Value = string.Empty;
|
||||
newRow.Cells[4].Value = string.Empty;
|
||||
newRow.Cells[5].Value = string.Empty;
|
||||
newRow.Cells[6].Value = string.Empty;
|
||||
newRow.Cells[7].Value = string.Empty;
|
||||
}
|
||||
//Set the is dirty cell to false.
|
||||
var isDirtyCell = new DataGridViewCheckBoxCell
|
||||
|
||||
Reference in New Issue
Block a user