Added a tool to remove an entire date and all records associated with it. Updated row deletion code to handle unbalanced tables or missing row IDs.
This commit is contained in:
@@ -46,10 +46,9 @@ namespace AdvertsingProfitControl
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
weekEndingCalendar.BoldedDates = databaseReader.RetrieveDates(databaseTracker.DatabaseConnectionString).ToArray();
|
||||
weekEndingCalendar.SelectionStart = date;
|
||||
weekEndingCalendar.DateChanged += ValidateDateChanged;
|
||||
_currentActiveDate = date;
|
||||
Text = @"Modify Record (Current Record: " + date.ToString("d") + @")";
|
||||
weekEndingCalendar.SelectionStart = date;
|
||||
_currentActiveDate = date;
|
||||
weekEndingCalendar.DateChanged += ValidateDateChanged;
|
||||
//next pull all the ad items into memory.
|
||||
_adItemCollection = databaseReader.GetAdItemsSuggestionList(databaseTracker.DatabaseConnectionString);
|
||||
//Now pull all the suppliers and the ad special list into memory.
|
||||
@@ -159,6 +158,7 @@ namespace AdvertsingProfitControl
|
||||
//
|
||||
_debugTabPage = mainTabControl.TabPages[4];
|
||||
mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]);
|
||||
Text = @"Modify Record (Current Record: " + date.ToString("d") + @")";
|
||||
LoadDate(date);
|
||||
}
|
||||
|
||||
@@ -573,9 +573,13 @@ namespace AdvertsingProfitControl
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
//Attempt to delete the row from the database by its ID number.
|
||||
var projectionsRowId = int.Parse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
var inventoryRowId = int.Parse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
var actualSalesRowId = int.Parse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
int projectionsRowId;
|
||||
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);
|
||||
if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
{
|
||||
informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database.";
|
||||
@@ -602,9 +606,13 @@ namespace AdvertsingProfitControl
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
//Attempt to delete the row from the database by its ID number.
|
||||
var projectionsRowId = int.Parse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
var inventoryRowId = int.Parse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
var actualSalesRowId = int.Parse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
int projectionsRowId;
|
||||
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);
|
||||
if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
{
|
||||
informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database.";
|
||||
@@ -678,12 +686,16 @@ namespace AdvertsingProfitControl
|
||||
if (dataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString() != string.Empty)
|
||||
{
|
||||
//Attempt to delete the row from the database by its ID number.
|
||||
var projectionsRowId = int.Parse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
var inventoryRowId = int.Parse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
var actualSalesRowId = int.Parse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
int projectionsRowId;
|
||||
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);
|
||||
if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
{
|
||||
informationLabel.Text += @"Successfully removed row " + (currentRowIndex + 1) + @" from the database." + Environment.NewLine;
|
||||
informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database.";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3331,11 +3343,32 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
errorLabel.Text += @"Failed to process actual sales." + Environment.NewLine;
|
||||
}
|
||||
if (!SaveInvoices(dateId, displayInformation)) return false;
|
||||
if (!SaveComments(dateId, displayInformation)) return false;
|
||||
if (!SaveWeeklySales(dateId, displayInformation)) return false;
|
||||
if (!SaveTaxable(dateId, displayInformation)) return false;
|
||||
return SaveCostAnalysis(dateId, displayInformation) && success;
|
||||
if (SaveInvoices(dateId, displayInformation))
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
if (!SaveComments(dateId, displayInformation))
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
if (!SaveWeeklySales(dateId, displayInformation))
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
if (!SaveTaxable(dateId, displayInformation))
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
if (!SaveCostAnalysis(dateId, displayInformation))
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
//If everything went through properly then set the form as not dirty since all changes are saved.
|
||||
if (success)
|
||||
{
|
||||
_isFormDirty = false;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -3896,6 +3929,25 @@ namespace AdvertsingProfitControl
|
||||
SaveRecords();
|
||||
}
|
||||
|
||||
private void NewModifyRecord_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (!_isFormDirty) return;
|
||||
var result = MessageBox.Show(@"Would you like to save the changes you have made?", @"Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
SaveRecords(false);
|
||||
}
|
||||
else if(result == DialogResult.Cancel)
|
||||
{
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void NewModifyRecord_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//private void NormalizeApcTables(DataTable projections, DataTable inventory, DataTable actualSales, string dateId)
|
||||
//{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user