diff --git a/AdvertsingProfitControl/APCDatabase.accdb b/AdvertsingProfitControl/APCDatabase.accdb
index c7a14ac..3d53bc0 100644
Binary files a/AdvertsingProfitControl/APCDatabase.accdb and b/AdvertsingProfitControl/APCDatabase.accdb differ
diff --git a/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs b/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs
index 43fc6b4..c49b7a8 100644
--- a/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs
+++ b/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs
@@ -63,7 +63,7 @@ namespace AdvertsingProfitControl
//The start by checking the previous row's status.
rowStatus = parser.GetRowAttribute(dataGridView.Rows[i - 1]);
//IF the previous row is a header row AND has color coding saying it is a group header, then clear the previous row's color and apply it to this row (i).
- if (rowStatus == RowAttribute.HeaderRow && (bool)dataGridView.Rows[i - 1].Cells[isHeaderColumn].Value)
+ if (rowStatus == RowAttribute.HeaderRow && (bool)dataGridView.Rows[i - 1].Cells[isHeaderColumn].EditedFormattedValue)
{
//Clear the previous row of its attributes.
dataGridView.Rows[i - 1].Cells[isHeaderColumn].Value = false;
@@ -72,6 +72,16 @@ namespace AdvertsingProfitControl
dataGridView.Rows[i - 1].Cells[isDirtyColumn].Value = true;
dataGridView.Rows[i - 1].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
dataGridView.Rows[i - 1].DefaultCellStyle.BackColor = Color.White;
+ //Check the next row to see if its a member row before declaring the current row a header row.
+ rowStatus = parser.GetRowAttribute(dataGridView.Rows[i + 1]);
+ if (rowStatus != RowAttribute.MemberRow)
+ {
+ //Clear the coloring from the current row.
+ dataGridView.Rows[i].Cells[isHeaderColumn].Value = true;
+ dataGridView.Rows[i].Cells[isMemberColumn].Value = false;
+ dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
+ return;
+ }
//Set the current row as a header row.
dataGridView.Rows[i].Cells[isHeaderColumn].Value = true;
dataGridView.Rows[i].Cells[isMemberColumn].Value = false;
@@ -122,15 +132,26 @@ namespace AdvertsingProfitControl
dataGridView.Rows[i - 1].Cells[isHeaderColumn].Value = false;
dataGridView.Rows[i - 1].Cells[isMemberColumn].Value = false;
dataGridView.Rows[i - 1].DefaultCellStyle.BackColor = Color.White;
- //Clear the current row of its attributes.
+ //Check for changes in the current row.
+ if ((bool) dataGridView.Rows[i].Cells[isMemberColumn].EditedFormattedValue)
+ {
+ dataGridView.Rows[i].Cells[isDirtyColumn].Value = true;
+ dataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ }
+ //Clear the current row of its attributes.
dataGridView.Rows[i].Cells[isHeaderColumn].Value = false;
dataGridView.Rows[i].Cells[isMemberColumn].Value = false;
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
- return;
}
//IF the previous row is a member row AND it also has color coding suggesting that it is a member of a group, then add the current row (i) as well.
- if (rowStatus == RowAttribute.MemberRow && (bool)dataGridView.Rows[i - 1].Cells[isMemberColumn].Value)
+ else if (rowStatus == RowAttribute.MemberRow && (bool)dataGridView.Rows[i - 1].Cells[isMemberColumn].EditedFormattedValue)
{
+ //Check for changes in the current row.
+ if (!(bool)dataGridView.Rows[i].Cells[isMemberColumn].EditedFormattedValue)
+ {
+ dataGridView.Rows[i].Cells[isDirtyColumn].Value = true;
+ dataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ }
//Set the current row as a member row.
dataGridView.Rows[i].Cells[isHeaderColumn].Value = false;
dataGridView.Rows[i].Cells[isMemberColumn].Value = true;
@@ -139,14 +160,19 @@ namespace AdvertsingProfitControl
//IF the previous row is simply a member row with no coloring at all, then remove the coloring from the current row (i).
else if (rowStatus == RowAttribute.MemberRow || rowStatus == RowAttribute.AdSpecialRow)
{
+ //Check for changes in the current row.
+ if ((bool)dataGridView.Rows[i].Cells[isMemberColumn].EditedFormattedValue)
+ {
+ dataGridView.Rows[i].Cells[isDirtyColumn].Value = true;
+ dataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ }
//Clear the current row of its attributes.
dataGridView.Rows[i].Cells[isHeaderColumn].Value = false;
dataGridView.Rows[i].Cells[isMemberColumn].Value = false;
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
- return;
}
//IF the previous row is a header row, then color it as a group header and color the current row as a member of said group.
- else if (rowStatus == RowAttribute.HeaderRow && !(bool)dataGridView.Rows[i - 1].Cells[isHeaderColumn].Value)
+ else if (rowStatus == RowAttribute.HeaderRow && !(bool)dataGridView.Rows[i - 1].Cells[isHeaderColumn].EditedFormattedValue)
{
//Set the previous row as a header row.
dataGridView.Rows[i - 1].Cells[isHeaderColumn].Value = true;
@@ -155,6 +181,25 @@ namespace AdvertsingProfitControl
//This condition means the user created a group so the newly made header row will need to be updated in the database as well.
dataGridView.Rows[i - 1].Cells[isDirtyColumn].Value = true;
dataGridView.Rows[i - 1].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ //Check for changes in the current row.
+ if ((bool)dataGridView.Rows[i].Cells[isMemberColumn].EditedFormattedValue)
+ {
+ dataGridView.Rows[i].Cells[isDirtyColumn].Value = true;
+ dataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ }
+ //Set the current row as a member row.
+ dataGridView.Rows[i].Cells[isHeaderColumn].Value = false;
+ dataGridView.Rows[i].Cells[isMemberColumn].Value = true;
+ dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.LightBlue;
+ }
+ else if (rowStatus == RowAttribute.HeaderRow)
+ {
+ //Check for changes in the current row.
+ if (!(bool)dataGridView.Rows[i].Cells[isMemberColumn].EditedFormattedValue)
+ {
+ dataGridView.Rows[i].Cells[isDirtyColumn].Value = true;
+ dataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ }
//Set the current row as a member row.
dataGridView.Rows[i].Cells[isHeaderColumn].Value = false;
dataGridView.Rows[i].Cells[isMemberColumn].Value = true;
diff --git a/AdvertsingProfitControl/DatabaseWriter.cs b/AdvertsingProfitControl/DatabaseWriter.cs
index c39dabd..bc5d8fe 100644
--- a/AdvertsingProfitControl/DatabaseWriter.cs
+++ b/AdvertsingProfitControl/DatabaseWriter.cs
@@ -360,7 +360,7 @@ namespace AdvertsingProfitControl
oleDbTransaction.Commit();
foreach (DataRow row in table.Rows)
{
- var rowId = RetrieveRowId(table.TableName, int.Parse(row[4].ToString()), int.Parse(row[8].ToString()), int.Parse(row[7].ToString()));
+ var rowId = int.Parse(row[0].ToString());
if (int.Parse(row[7].ToString()) != 0)
{
//Account for the ad special row.
@@ -408,7 +408,6 @@ namespace AdvertsingProfitControl
return status;
}
-
public DbTableWriterStatus ProccessInvoiceTable(DataGridView table, int dateId, string connectionString)
{
var status = new DbTableWriterStatus();
diff --git a/AdvertsingProfitControl/NewAddRecord.cs b/AdvertsingProfitControl/NewAddRecord.cs
index ed05896..45f389c 100644
--- a/AdvertsingProfitControl/NewAddRecord.cs
+++ b/AdvertsingProfitControl/NewAddRecord.cs
@@ -683,12 +683,23 @@ namespace AdvertsingProfitControl
//Reset the gAdSpecialIndex to -1.
_adSpecialIndex = -1;
e.Cancel = true; //Prevent the new row from being removed.
+ return;
}
else
{
e.Cancel = true;
}
}
+ //Mark all rows under the row that just got deleted as dirty.
+ for (var index = currentRowIndex; currentRowIndex < dataGridView.Rows.Count; index++)
+ {
+ 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;
+ inventoryDataGridView.Rows[index].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ actualSalesDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = true;
+ actualSalesDataGridView.Rows[index].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ }
}
private void ChangeAutoCompleteListOnKeyCombo(object sender, KeyEventArgs e)
diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs
index 50d0c2d..6a02fd8 100644
--- a/AdvertsingProfitControl/NewModifyRecord.cs
+++ b/AdvertsingProfitControl/NewModifyRecord.cs
@@ -719,12 +719,25 @@ namespace AdvertsingProfitControl
//Reset the gAdSpecialIndex to -1.
_adSpecialIndex = -1;
e.Cancel = true; //Prevent the new row from being removed.
+ return;
}
else
{
e.Cancel = true;
}
}
+ //Mark all rows under the row that just got deleted as dirty.
+ for (var index = currentRowIndex; index < dataGridView.Rows.Count; index++)
+ {
+ if (index == _adSpecialIndex + 1) continue;
+ if (projectionsDataGridView.Rows[index].IsNewRow) 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;
+ inventoryDataGridView.Rows[index].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ actualSalesDataGridView.Rows[index].Cells[(int) SalesTableColumns.IsDirty].Value = true;
+ actualSalesDataGridView.Rows[index].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ }
}
private void ChangeAutoCompleteListOnKeyCombo(object sender, KeyEventArgs e)
@@ -2583,8 +2596,8 @@ namespace AdvertsingProfitControl
//Check the attribute cell.
if (cellIndex == 6)
{
- var isHeaderCell = new DataGridViewCheckBoxCell(false);
- var isMemberCell = new DataGridViewCheckBoxCell(false);
+ var isHeaderCell = new DataGridViewCheckBoxCell();
+ var isMemberCell = new DataGridViewCheckBoxCell();
var rowAttribute = int.Parse(inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString());
switch (rowAttribute)
{
@@ -2598,6 +2611,10 @@ namespace AdvertsingProfitControl
isMemberCell.Value = true;
newRow.DefaultCellStyle.BackColor = ApplicationColors.MemberRow;
break;
+ default:
+ isHeaderCell.Value = false;
+ isMemberCell.Value = false;
+ break;
}
newRow.Cells.Add(isHeaderCell);
newRow.Cells.Add(isMemberCell);
@@ -2683,8 +2700,8 @@ namespace AdvertsingProfitControl
//Check the attribute cell.
if (cellIndex == 8)
{
- var isHeaderCell = new DataGridViewCheckBoxCell(false);
- var isMemberCell = new DataGridViewCheckBoxCell(false);
+ var isHeaderCell = new DataGridViewCheckBoxCell();
+ var isMemberCell = new DataGridViewCheckBoxCell();
var rowAttribute = int.Parse(actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString());
switch (rowAttribute)
{
@@ -2698,6 +2715,10 @@ namespace AdvertsingProfitControl
isMemberCell.Value = true;
newRow.DefaultCellStyle.BackColor = ApplicationColors.MemberRow;
break;
+ default:
+ isHeaderCell.Value = false;
+ isMemberCell.Value = false;
+ break;
}
newRow.Cells.Add(isHeaderCell);
newRow.Cells.Add(isMemberCell);
@@ -3103,6 +3124,7 @@ namespace AdvertsingProfitControl
MessageBox.Show(@"Failed to get the date ID number.", @"Invalid ID Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
+ if (displayInformation) informationLabel.Text = "";
//Create the database interaction objects.
var dbT = new DatabaseTracker();
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
@@ -3151,6 +3173,80 @@ namespace AdvertsingProfitControl
{
errorLabel.Text += @"Failed to process projections." + Environment.NewLine;
}
+ DataTable inventoryNewTable;
+ DataTable inventoryUpdateTable;
+ var inventoryTrimmingStatus = ConstructCleanedInventoryTable(dateId, out inventoryNewTable, out inventoryUpdateTable);
+ if (inventoryTrimmingStatus != TrimmingOperationResult.NoChangesRequired && inventoryTrimmingStatus != TrimmingOperationResult.FailedToTrim)
+ {
+ if (inventoryNewTable.Rows.Count > 0)
+ {
+ var writerResult = dbW.InsertIntoInventoryTable(inventoryNewTable, dbT.DatabaseConnectionString);
+ if (writerResult.GetWritingOperationStatus() != WritingOperationStatus.Failed)
+ {
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in writerResult.GetRowCollection())
+ {
+ //Only reset the IsDirty value to false since the updates when through.
+ inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.Id].Value = rowIndex.Value;
+ inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
+ inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
+ }
+ }
+ }
+ //Next check to see if the update table has anything.
+ if (inventoryUpdateTable.Rows.Count > 0)
+ {
+ var writerResult = dbW.UpdateInventoryTable(inventoryUpdateTable, dbT.DatabaseConnectionString);
+ if (writerResult.GetWritingOperationStatus() != WritingOperationStatus.Failed)
+ {
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in writerResult.GetRowCollection())
+ {
+ //Only reset the IsDirty value to false since the updates when through.
+ inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
+ inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
+ }
+ }
+ }
+ if (displayInformation) informationLabel.Text += @"Successfully saved inventory." + Environment.NewLine;
+ }
+ DataTable actualSalesNewTable;
+ DataTable actualSalesUpdateTable;
+ var actualSalesTrimmingStatus = ConstructCleanedSalesTable("ActualSales", dateId, out actualSalesNewTable, out actualSalesUpdateTable);
+ if (actualSalesTrimmingStatus != TrimmingOperationResult.NoChangesRequired && actualSalesTrimmingStatus != TrimmingOperationResult.FailedToTrim)
+ {
+ //Check to see if the insert table has any items.
+ if (actualSalesNewTable.Rows.Count > 0)
+ {
+ var writerResult = dbW.InsertIntoSalesTable(actualSalesNewTable, dbT.DatabaseConnectionString);
+ if (writerResult.GetWritingOperationStatus() != WritingOperationStatus.Failed)
+ {
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in writerResult.GetRowCollection())
+ {
+ actualSalesDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.Id].Value = rowIndex.Value;
+ actualSalesDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
+ actualSalesDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
+ }
+ }
+ }
+ //Next check to see if the update table has anything.
+ if (actualSalesUpdateTable.Rows.Count > 0)
+ {
+ var writerResult = dbW.UpdateSalesTable(actualSalesUpdateTable, dbT.DatabaseConnectionString);
+ if (writerResult.GetWritingOperationStatus() != WritingOperationStatus.Failed)
+ {
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in writerResult.GetRowCollection())
+ {
+ //Only reset the IsDirty value to false since the updates when through.
+ actualSalesDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
+ actualSalesDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
+ }
+ }
+ }
+ if (displayInformation) informationLabel.Text += @"Successfully saved actual sales." + Environment.NewLine;
+ }
return success;
}
@@ -3242,7 +3338,7 @@ namespace AdvertsingProfitControl
continue;
}
//Check to see if the row is dirty.
- if (!(bool)row.Cells[(int)SalesTableColumns.IsDirty].Value)
+ if (!(bool)row.Cells[(int)SalesTableColumns.IsDirty].EditedFormattedValue)
{
//If it is not then continue on to the next row.
continue;
@@ -3268,11 +3364,11 @@ namespace AdvertsingProfitControl
}
//Determine the row's attribute.
var rowAttribute = 0; //Zero (0) means no grouping, its not a header nor a member.
- if ((bool)row.Cells[(int)SalesTableColumns.IsHeaderRow].Value && !(bool)row.Cells[(int)SalesTableColumns.IsMemberRow].Value)
+ if ((bool)row.Cells[(int)SalesTableColumns.IsHeaderRow].EditedFormattedValue && !(bool)row.Cells[(int)SalesTableColumns.IsMemberRow].EditedFormattedValue)
{
rowAttribute = 1;
}
- else if ((bool)row.Cells[(int)SalesTableColumns.IsMemberRow].Value && !(bool)row.Cells[(int)SalesTableColumns.IsHeaderRow].Value)
+ else if ((bool)row.Cells[(int)SalesTableColumns.IsMemberRow].EditedFormattedValue && !(bool)row.Cells[(int)SalesTableColumns.IsHeaderRow].EditedFormattedValue)
{
rowAttribute = 2;
}
@@ -3399,7 +3495,7 @@ namespace AdvertsingProfitControl
continue;
}
//Check to see if the row is dirty.
- if (!(bool)row.Cells[(int)InventoryTableColumns.IsDirty].Value)
+ if (!(bool)row.Cells[(int)InventoryTableColumns.IsDirty].EditedFormattedValue)
{
//If it is not then continue on to the next row.
continue;
@@ -3424,11 +3520,11 @@ namespace AdvertsingProfitControl
}
//Determine the row's attribute.
var rowAttribute = 0; //Zero (0) means no grouping, its not a header nor a member.
- if ((bool)row.Cells[(int)InventoryTableColumns.IsHeaderRow].Value && !(bool)row.Cells[(int)InventoryTableColumns.IsMemberRow].Value)
+ if ((bool)row.Cells[(int)InventoryTableColumns.IsHeaderRow].EditedFormattedValue && !(bool)row.Cells[(int)InventoryTableColumns.IsMemberRow].EditedFormattedValue)
{
rowAttribute = 1;
}
- else if ((bool)row.Cells[(int)InventoryTableColumns.IsMemberRow].Value && !(bool)row.Cells[(int)InventoryTableColumns.IsHeaderRow].Value)
+ else if ((bool)row.Cells[(int)InventoryTableColumns.IsMemberRow].EditedFormattedValue && !(bool)row.Cells[(int)InventoryTableColumns.IsHeaderRow].EditedFormattedValue)
{
rowAttribute = 2;
}
diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application
index 57deb74..78e560f 100644
--- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application
+++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application
@@ -14,7 +14,7 @@
- b7XWNTKdLoveai+Ezig6qhdfRQNnqDFOegZLHdvzxx0=
+ opU00zIbvKlwE9ETDbcBw3wn43DC9oTiG2Ds1yBbqBA=
diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest
index 4690085..c203a09 100644
--- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest
+++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest
@@ -43,14 +43,14 @@
-
+
- JdsSdLXGV6xF3G52D7+6tloy6VbDDJnLshBRhBOm3iQ=
+ T8dp3gOWrMgWFpeIbwYfpgMQxCEBFP64iXUiGpV4wto=