Updated the UI of the add record form. Added support to clear the APC tables if even one fails to be added to the database. Fixed a crash bug with the trimming operations where Header and Member Booleans would be null.
This commit is contained in:
@@ -50,8 +50,6 @@ namespace AdvertsingProfitControl
|
||||
//Assign the events for the comments text box and display the remaining character count for the user.
|
||||
commentsTextBox.TextChanged += DisplayRemainingCommentCharacterCount;
|
||||
commentsGroupBox.Text = @"Comments (Characters Remaining: " + commentsTextBox.MaxLength + @")";
|
||||
//Set up the event for when the masked text box looses focus.
|
||||
weekEndingMaskedTextBox.LostFocus += UpdateCalendarOnFocusLost;
|
||||
//Setup the events for that the Projected and Actual Sales DataGridViews will share.
|
||||
//Events are assigned with regard to which event gets triggered first and so on..
|
||||
//Hook the row add event so we can paint a row number in the header cell of the row.
|
||||
@@ -881,8 +879,13 @@ namespace AdvertsingProfitControl
|
||||
case (int)SalesTableColumns.IsDirty:
|
||||
rowContents[i] = true;
|
||||
break;
|
||||
case (int)SalesTableColumns.IsHeaderRow:
|
||||
rowContents[i] = false;
|
||||
break;
|
||||
case (int)SalesTableColumns.IsMemberRow:
|
||||
rowContents[i] = false;
|
||||
break;
|
||||
default:
|
||||
if(i >= (int)SalesTableColumns.IsHeaderRow) continue;
|
||||
rowContents[i] = "";
|
||||
break;
|
||||
}
|
||||
@@ -903,14 +906,18 @@ namespace AdvertsingProfitControl
|
||||
inventoryNewRow[(int)InventoryTableColumns.AdItem] =
|
||||
projectionsDataGridView.Rows[e.RowIndex].Cells[i].EditedFormattedValue.ToString();
|
||||
break;
|
||||
case (int)SalesTableColumns.IsDirty:
|
||||
case (int)InventoryTableColumns.IsDirty:
|
||||
inventoryNewRow[(int)InventoryTableColumns.IsDirty] = true;
|
||||
break;
|
||||
case (int)InventoryTableColumns.IsHeaderRow:
|
||||
inventoryNewRow[(int)InventoryTableColumns.IsHeaderRow] = false;
|
||||
break;
|
||||
case (int)InventoryTableColumns.IsMemberRow:
|
||||
inventoryNewRow[(int)InventoryTableColumns.IsMemberRow] = false;
|
||||
break;
|
||||
default:
|
||||
if (i < (int) InventoryTableColumns.IsHeaderRow)
|
||||
{
|
||||
inventoryNewRow[i] = "";
|
||||
}
|
||||
if(i > (int)InventoryTableColumns.IsHeaderRow) continue;
|
||||
inventoryNewRow[i] = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1185,11 +1192,13 @@ namespace AdvertsingProfitControl
|
||||
case (int)SalesTableColumns.IsDirty:
|
||||
rowContents[i] = true;
|
||||
break;
|
||||
case (int)SalesTableColumns.IsHeaderRow:
|
||||
rowContents[i] = false;
|
||||
break;
|
||||
case (int)SalesTableColumns.IsMemberRow:
|
||||
rowContents[i] = false;
|
||||
break;
|
||||
default:
|
||||
if (i >= (int) InventoryTableColumns.IsHeaderRow)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
rowContents[i] = "";
|
||||
break;
|
||||
}
|
||||
@@ -1337,8 +1346,13 @@ namespace AdvertsingProfitControl
|
||||
case (int)SalesTableColumns.IsDirty:
|
||||
rowContents[i] = true;
|
||||
break;
|
||||
case (int)SalesTableColumns.IsHeaderRow:
|
||||
rowContents[i] = false;
|
||||
break;
|
||||
case (int)SalesTableColumns.IsMemberRow:
|
||||
rowContents[i] = false;
|
||||
break;
|
||||
default:
|
||||
if (i >= (int)SalesTableColumns.IsHeaderRow) continue;
|
||||
rowContents[i] = "";
|
||||
break;
|
||||
}
|
||||
@@ -1359,11 +1373,15 @@ namespace AdvertsingProfitControl
|
||||
case (int)SalesTableColumns.IsDirty:
|
||||
inventoryNewRow[(int)InventoryTableColumns.IsDirty] = true;
|
||||
break;
|
||||
case (int)InventoryTableColumns.IsHeaderRow:
|
||||
inventoryNewRow[(int)InventoryTableColumns.IsHeaderRow] = false;
|
||||
break;
|
||||
case (int)InventoryTableColumns.IsMemberRow:
|
||||
inventoryNewRow[(int)InventoryTableColumns.IsMemberRow] = false;
|
||||
break;
|
||||
default:
|
||||
if (i > (int)InventoryTableColumns.AdItem && i < (int)InventoryTableColumns.IsHeaderRow || i == (int)InventoryTableColumns.Id)
|
||||
{
|
||||
inventoryNewRow[i] = "";
|
||||
}
|
||||
if (i > (int)InventoryTableColumns.IsHeaderRow) continue;
|
||||
inventoryNewRow[i] = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1844,114 +1862,29 @@ namespace AdvertsingProfitControl
|
||||
#endregion
|
||||
|
||||
#region DateTime Events
|
||||
/// <summary>
|
||||
/// Updates the week ending masked text box with the selected date
|
||||
/// using the format (MM/DD/YYYY).
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void UpdateWeekEndingMaskedTextBox(object sender, DateRangeEventArgs e)
|
||||
{
|
||||
var selectedDate = weekEndingMonthCalendar.SelectionStart;
|
||||
if (!selectedDate.ToString("D").StartsWith("Saturday"))
|
||||
{
|
||||
weekEndingMaskedTextBox.ForeColor = Color.Maroon;
|
||||
weekEndingMaskedTextBoxInstructionLabel.Text = @"... or manually enter it here: *";
|
||||
errorLabel.Text = @"* The date you selected does not appear to be a week ending date.";
|
||||
}
|
||||
else
|
||||
{
|
||||
weekEndingMaskedTextBox.ForeColor = Color.Black;
|
||||
weekEndingMaskedTextBoxInstructionLabel.Text = @"... or manually enter it here:";
|
||||
errorLabel.Text = "";
|
||||
}
|
||||
|
||||
weekEndingMaskedTextBox.Text = selectedDate.ToString("MM-dd-yyyy");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event Used: LostFocus
|
||||
/// Attempts to set the selected date of the calendar to the date that
|
||||
/// has been entered into the masked text box.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void UpdateCalendarOnFocusLost(object sender, EventArgs e)
|
||||
{
|
||||
//Replace any white space with zeros to pad out the mask.
|
||||
weekEndingMaskedTextBox.Text = weekEndingMaskedTextBox.Text.Replace("/", "");
|
||||
DateTime date;
|
||||
//Try parsing the contents of the masked text box to see if the date is valid.
|
||||
if (DateTime.TryParse(weekEndingMaskedTextBox.Text, out date))
|
||||
{
|
||||
//Update the text box's text with a nicely formatted date.
|
||||
weekEndingMaskedTextBox.Text = date.ToString("MM/dd/yyyy");
|
||||
//If it is update the calendar with the manually entered date.
|
||||
weekEndingMonthCalendar.SelectionStart = date;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Otherwise throw an error to day that the date isn't valid and clear the text box.
|
||||
MessageBox.Show(@"The date entered appears to be invalid.", @"Invalid Date", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
weekEndingMaskedTextBox.Text = "";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void AddRecordsButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
//Make sure the mask in the text box is completed.
|
||||
if (!weekEndingMaskedTextBox.MaskCompleted)
|
||||
{
|
||||
MessageBox.Show(@"A valid date must be specified.", @"Invalid Date", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
//Create the database interaction objects.
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
var dbR = new DatabaseReader();
|
||||
DateTime dateTime;
|
||||
//Attempt to parse the date entered to verify it's integrity.
|
||||
if (DateTime.TryParseExact(weekEndingMaskedTextBox.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None, out dateTime))
|
||||
{
|
||||
//Check to see if the date is before the store was even founded, though I think a date range starting at 2014 would work but eh.
|
||||
if (dateTime.Year < 1958)
|
||||
{
|
||||
var result =
|
||||
MessageBox.Show(
|
||||
@"Fairly certain Allen's wasn't even founded at this time... Maybe try another date or year at least?",
|
||||
@"Let Alone Used Computers This Fast", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
weekEndingMaskedTextBox.Focus();
|
||||
return;
|
||||
}
|
||||
MessageBox.Show(@"Alright if you insist since technically this date is valid.",
|
||||
@"Technically Correct Is The Best Correct", MessageBoxButtons.OK);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show(@"The date " + weekEndingMaskedTextBox.Text + @" is an invalid date.", @"Invalid Date", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
//Obtain the date ID.
|
||||
int dateId;
|
||||
if (
|
||||
int.TryParse(dbR.RetrieveDateIdByDateString(dateTime.ToString("MM/dd/yyyy"),
|
||||
int.TryParse(dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"),
|
||||
dbT.DatabaseConnectionString), out dateId))
|
||||
{
|
||||
//If the ID is zero (0) that means the date isn't in the database so simply insert it.
|
||||
if (dateId == 0)
|
||||
{
|
||||
//Try inserting the date string.
|
||||
if (dbW.InsertIntoWeekEnding(dateTime.ToString("MM/dd/yyyy")))
|
||||
if (dbW.InsertIntoWeekEnding(weekEndingCalendar.SelectionStart.ToString("d")))
|
||||
{
|
||||
if (
|
||||
int.TryParse(
|
||||
dbR.RetrieveDateIdByDateString(dateTime.ToString("MM/dd/yyyy"),
|
||||
dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"),
|
||||
dbT.DatabaseConnectionString), out dateId))
|
||||
{
|
||||
//Now if its still zero (0) then that means something went really wrong and failed to insert.
|
||||
@@ -1974,24 +1907,17 @@ namespace AdvertsingProfitControl
|
||||
else
|
||||
{
|
||||
//The above method reports that it failed to insert the date into the database.
|
||||
MessageBox.Show(@"Failed insert the date " + weekEndingMaskedTextBox.Text + @" into the database.", @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show(@"Failed to insert the date '" + weekEndingCalendar.SelectionStart.ToString("d") + @"' into the database.", @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Seriously don't think this will happen, but eh might as well.
|
||||
MessageBox.Show(
|
||||
@"You really should not be able to see this message. If you are well that means something really weird happened converting text into a number, that is hard-coded to not fail on conversion. Either way I couldn't get the date ID due to some error, check the logs if you're curious.",
|
||||
@"Well This Is Awkward...", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
informationLabel.Text = "";
|
||||
//Run the row parsing engine on all the APC tables.
|
||||
|
||||
//Create the cleaned table objects that will be sent to the database.
|
||||
DataTable trimmedTable;
|
||||
DataTable updateTable;
|
||||
informationLabel.Text = @"Compressing data tables..." + Environment.NewLine;
|
||||
errorLabel.Text = "";
|
||||
var operationStatus = ConstructCleanedSalesTable("Projections", dateId, out trimmedTable, out updateTable);
|
||||
if (operationStatus == TrimmingOperationResult.FailedToTrim)
|
||||
@@ -1999,45 +1925,75 @@ namespace AdvertsingProfitControl
|
||||
errorLabel.Text = @"Failed to trim the Projections table.";
|
||||
return;
|
||||
}
|
||||
if (!ProcessTrimmingStatusResult(projectionsDataGridView, "Projections", operationStatus, trimmedTable, updateTable)) return;
|
||||
trimmedTable.Rows.Clear();
|
||||
updateTable.Rows.Clear();
|
||||
operationStatus = ConstructCleanedInventoryTable(dateId, out trimmedTable, out updateTable);
|
||||
if (operationStatus == TrimmingOperationResult.FailedToTrim)
|
||||
if (ProcessTrimmingStatusResult(projectionsDataGridView, "Projections", operationStatus, trimmedTable, updateTable))
|
||||
{
|
||||
errorLabel.Text = @"Failed to trim the Inventory table.";
|
||||
return;
|
||||
trimmedTable.Rows.Clear();
|
||||
updateTable.Rows.Clear();
|
||||
operationStatus = ConstructCleanedInventoryTable(dateId, out trimmedTable, out updateTable);
|
||||
if (operationStatus == TrimmingOperationResult.FailedToTrim)
|
||||
{
|
||||
errorLabel.Text = @"Failed to trim the Inventory table.";
|
||||
//Delete the Projections table.
|
||||
dbW.DeleteApcDataEntriesByDate("Projections", dateId, dbT.DatabaseConnectionString);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Add the Inventory table to the database.
|
||||
if (ProcessTrimmingStatusForInventory(operationStatus, trimmedTable, updateTable))
|
||||
{
|
||||
trimmedTable.Rows.Clear();
|
||||
updateTable.Rows.Clear();
|
||||
operationStatus = ConstructCleanedSalesTable("ActualSales", dateId, out trimmedTable,
|
||||
out updateTable);
|
||||
if (operationStatus == TrimmingOperationResult.FailedToTrim)
|
||||
{
|
||||
errorLabel.Text = @"Failed to trim the Actual Sales table.";
|
||||
//Delete the Projections table and the Inventory table.
|
||||
dbW.DeleteApcDataEntriesByDate("Projections", dateId, dbT.DatabaseConnectionString);
|
||||
dbW.DeleteApcDataEntriesByDate("Inventory", dateId, dbT.DatabaseConnectionString);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ProcessTrimmingStatusResult(actualSalesDataGridView, "ActualSales", operationStatus, trimmedTable, updateTable))
|
||||
{
|
||||
//Delete the Projections and Inventory table.
|
||||
dbW.DeleteApcDataEntriesByDate("Projections", dateId, dbT.DatabaseConnectionString);
|
||||
dbW.DeleteApcDataEntriesByDate("Inventory", dateId, dbT.DatabaseConnectionString);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Delete the Projections table.
|
||||
dbW.DeleteApcDataEntriesByDate("Projections", dateId, dbT.DatabaseConnectionString);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ProcessTrimmingStatusForInventory(operationStatus, trimmedTable, updateTable)) return;
|
||||
trimmedTable.Rows.Clear();
|
||||
updateTable.Rows.Clear();
|
||||
operationStatus = ConstructCleanedSalesTable("ActualSales", dateId, out trimmedTable, out updateTable);
|
||||
if (operationStatus == TrimmingOperationResult.FailedToTrim)
|
||||
{
|
||||
errorLabel.Text = @"Failed to trim the Actual Sales table.";
|
||||
return;
|
||||
}
|
||||
if (!ProcessTrimmingStatusResult(actualSalesDataGridView, "ActualSales", operationStatus, trimmedTable, updateTable)) return;
|
||||
//Commit the Invoice table to the database.
|
||||
var writerStatus = dbW.ProccessInvoiceTable(invoicesDataGridView, dateId, dbT.DatabaseConnectionString);
|
||||
if (writerStatus.GetWritingOperationStatus() == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Invoices to the database.";
|
||||
errorLabel.Text = writerStatus.GetErrorMessage();
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += writerStatus.GetErrorMessage() + Environment.NewLine;
|
||||
}
|
||||
//TODO: If the comments are null but there is a comment ID, delete the comments from the database.
|
||||
if (isCommentDirtyCheckBox.Checked)
|
||||
{
|
||||
{
|
||||
if (isCommentDirtyCheckBox.Tag == null)
|
||||
{
|
||||
informationLabel.Text += @"Inserting Comment(s).";
|
||||
var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString);
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Comments to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Comment(s) processed successfully.";
|
||||
informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine;
|
||||
var id = status.Id;
|
||||
isCommentDirtyCheckBox.Tag = id;
|
||||
isCommentDirtyCheckBox.Text = @"IsCommentDirty (" + id + @")";
|
||||
@@ -2048,19 +2004,24 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
//Check for a null comment box and delete the comment ID from the database.
|
||||
//Then if all is successful clear the Tag in the isCommentsDirty check box.
|
||||
informationLabel.Text += @"Updating Comment(s).";
|
||||
var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString, int.Parse(isCommentDirtyCheckBox.Tag.ToString()));
|
||||
var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString,
|
||||
int.Parse(isCommentDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Comments to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
isCommentDirtyCheckBox.Checked = false;
|
||||
informationLabel.Text += @"Comment(s) processed successfully.";
|
||||
informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No changes detected for the comment(s)" + Environment.NewLine;
|
||||
}
|
||||
//Begin checking the Weekly Sales.
|
||||
if (isWeeklySalesDirtyCheckBox.Checked)
|
||||
{
|
||||
@@ -2070,23 +2031,27 @@ namespace AdvertsingProfitControl
|
||||
weeklySales[1] = mondayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(mondayWeeklySalesTextBox.Text);
|
||||
weeklySales[2] = tuesdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(tuesdayWeeklySalesTextBox.Text);
|
||||
weeklySales[3] = wednesdayTaxableTextBox.Text == "" ? 0 : double.Parse(wednesdayWeeklySalesTextBox.Text);
|
||||
weeklySales[4] = thursdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(thursdayWeeklySalesTextBox.Text);
|
||||
weeklySales[4] = thursdayWeeklySalesTextBox.Text == ""
|
||||
? 0
|
||||
: double.Parse(thursdayWeeklySalesTextBox.Text);
|
||||
weeklySales[5] = fridayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(fridayWeeklySalesTextBox.Text);
|
||||
weeklySales[6] = saturdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(saturdayWeeklySalesTextBox.Text);
|
||||
weeklySales[6] = saturdayWeeklySalesTextBox.Text == ""
|
||||
? 0
|
||||
: double.Parse(saturdayWeeklySalesTextBox.Text);
|
||||
weeklySales[7] = totalWeeklySalesTextBox.Text == "" ? 0 : double.Parse(totalWeeklySalesTextBox.Text);
|
||||
|
||||
if (isWeeklySalesDirtyCheckBox.Tag == null)
|
||||
{
|
||||
//Weekly sales is not in the database.
|
||||
informationLabel.Text += @"Inserting weekly sales...";
|
||||
var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString);
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Weekly Sales to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Weekly Sales processed successfully.";
|
||||
informationLabel.Text += @"Weekly Sales processed successfully." + Environment.NewLine;
|
||||
isWeeklySalesDirtyCheckBox.Tag = status.Id;
|
||||
isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty (" + status.Id + @")";
|
||||
isWeeklySalesDirtyCheckBox.Checked = false;
|
||||
@@ -2094,19 +2059,24 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Updating Weekly Sales.";
|
||||
var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString, int.Parse(isWeeklySalesDirtyCheckBox.Tag.ToString()));
|
||||
var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString,
|
||||
int.Parse(isWeeklySalesDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Weekly Sales to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
isWeeklySalesDirtyCheckBox.Checked = false;
|
||||
informationLabel.Text += @"Weekly Sales updated successfully.";
|
||||
informationLabel.Text += @"Weekly Sales updated successfully." + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No changes detected for Weekly Sales." + Environment.NewLine;
|
||||
}
|
||||
//Begin checking the Taxable.
|
||||
if (isTaxableDirtyCheckBox.Checked)
|
||||
{
|
||||
@@ -2124,15 +2094,15 @@ namespace AdvertsingProfitControl
|
||||
if (isTaxableDirtyCheckBox.Tag == null)
|
||||
{
|
||||
//Weekly sales is not in the database.
|
||||
informationLabel.Text += @"Inserting Taxable...";
|
||||
var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString);
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Taxable to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Taxable processed successfully.";
|
||||
informationLabel.Text += @"Taxable processed successfully." + Environment.NewLine;
|
||||
isTaxableDirtyCheckBox.Tag = status.Id;
|
||||
isTaxableDirtyCheckBox.Text = @"IsTaxableDirty (" + status.Id + @")";
|
||||
isTaxableDirtyCheckBox.Checked = false;
|
||||
@@ -2140,19 +2110,24 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Updating Taxable.";
|
||||
var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString, int.Parse(isTaxableDirtyCheckBox.Tag.ToString()));
|
||||
var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString,
|
||||
int.Parse(isTaxableDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Taxable to the database." + Environment.NewLine;
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
isTaxableDirtyCheckBox.Checked = false;
|
||||
informationLabel.Text += @"Taxable updated successfully.";
|
||||
informationLabel.Text += @"Taxable updated successfully." + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No changes detected for Taxable." + Environment.NewLine;
|
||||
}
|
||||
//Begin checking cost analysis.
|
||||
if (isCostAnalysisDirtyCheckBox.Checked)
|
||||
{
|
||||
@@ -2166,15 +2141,15 @@ namespace AdvertsingProfitControl
|
||||
if (isCostAnalysisDirtyCheckBox.Tag == null)
|
||||
{
|
||||
//Weekly sales is not in the database.
|
||||
informationLabel.Text += @"Inserting Cost Analysis...";
|
||||
var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString);
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Cost Analysis to the database.";
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Costs analysis processed successfully.";
|
||||
informationLabel.Text += @"Costs Analysis processed successfully.";
|
||||
isCostAnalysisDirtyCheckBox.Tag = status.Id;
|
||||
isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty (" + status.Id + @")";
|
||||
isCostAnalysisDirtyCheckBox.Checked = false;
|
||||
@@ -2182,19 +2157,24 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Updating cost analysis.";
|
||||
var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString, int.Parse(isCostAnalysisDirtyCheckBox.Tag.ToString()));
|
||||
var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString,
|
||||
int.Parse(isCostAnalysisDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
informationLabel.Text += @"Failed to add Cost Analysis to the database.";
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
isCostAnalysisDirtyCheckBox.Checked = false;
|
||||
informationLabel.Text += @"Cost analysis updated successfully.";
|
||||
informationLabel.Text += @"Cost Analysis updated successfully.";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No changes made to Cost Analysis.";
|
||||
}
|
||||
//Create the transaction scope.
|
||||
//By default the TransactionScopeOption is "Required", so if an ambient transaction does not
|
||||
//exist then the new transaction that is made (in the first method) becomes the root transaction.
|
||||
@@ -2672,11 +2652,10 @@ namespace AdvertsingProfitControl
|
||||
switch (operationStatus)
|
||||
{
|
||||
case TrimmingOperationResult.NoChangesRequired:
|
||||
informationLabel.Text += Environment.NewLine + @"No changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table detected.";
|
||||
informationLabel.Text += @"No changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table detected." + Environment.NewLine;
|
||||
successful = true;
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedNewInsertionTable:
|
||||
informationLabel.Text += Environment.NewLine + @"Inserting new changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table.";
|
||||
dbWriterStatus = dbW.InsertIntoSalesTable(trimmedTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
@@ -2685,17 +2664,17 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
dataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.Id].Value = rowIndex.Value;
|
||||
dataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value = false;
|
||||
dataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database.";
|
||||
informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database." + Environment.NewLine;
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database.";
|
||||
errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database." + Environment.NewLine;
|
||||
}
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedUpdateTable:
|
||||
informationLabel.Text += Environment.NewLine + @"Updating changes made to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table.";
|
||||
dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
@@ -2704,35 +2683,36 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
//Only reset the IsDirty value to false since the updates when through.
|
||||
dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
|
||||
dataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated.";
|
||||
informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated." + Environment.NewLine;
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to update the " + trimmedTable + @" table.";
|
||||
errorLabel.Text = @"Failed to update the " + trimmedTable + @" table." + Environment.NewLine;
|
||||
}
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables:
|
||||
//Insert the new values...
|
||||
informationLabel.Text += Environment.NewLine + @"Inserting new changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table.";
|
||||
dbWriterStatus = dbW.InsertIntoSalesTable(trimmedTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
//Spin through the collection and update the affected rows.
|
||||
foreach (var rowIndex in dbWriterStatus.GetRowCollection())
|
||||
{
|
||||
//Add the ID numbers to the first column since these are new additions to the database.
|
||||
dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.Id].Value = rowIndex.Value;
|
||||
dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
|
||||
dataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database.";
|
||||
informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database." + Environment.NewLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database.";
|
||||
errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database." + Environment.NewLine;
|
||||
}
|
||||
//... and update the existing values.
|
||||
informationLabel.Text += Environment.NewLine + @"Updating changes made to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table.";
|
||||
dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
@@ -2741,13 +2721,14 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
//Only reset the IsDirty value to false since the updates when through.
|
||||
dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
|
||||
dataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated.";
|
||||
informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated." + Environment.NewLine;
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to update the " + trimmedTable + @" table.";
|
||||
errorLabel.Text = @"Failed to update the " + trimmedTable + @" table." + Environment.NewLine;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2765,11 +2746,10 @@ namespace AdvertsingProfitControl
|
||||
switch (operationStatus)
|
||||
{
|
||||
case TrimmingOperationResult.NoChangesRequired:
|
||||
informationLabel.Text += Environment.NewLine + @"No changes to the Inventory table detected.";
|
||||
informationLabel.Text += @"No changes to the Inventory table detected." + Environment.NewLine;
|
||||
successful = true;
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedNewInsertionTable:
|
||||
informationLabel.Text += Environment.NewLine + @"Inserting new changes to the Inventory table.";
|
||||
dbWriterStatus = dbW.InsertIntoInventoryTable(trimmedTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
@@ -2778,17 +2758,17 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
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;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + @"Inventory table successfully added to the database.";
|
||||
informationLabel.Text += @"Inventory table successfully added to the database." + Environment.NewLine;
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to insert Inventory table into the database.";
|
||||
errorLabel.Text = @"Failed to insert Inventory table into the database." + Environment.NewLine;
|
||||
}
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedUpdateTable:
|
||||
informationLabel.Text += Environment.NewLine + @"Updating changes made to the Inventory table.";
|
||||
dbWriterStatus = dbW.UpdateInventoryTable(updateTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
@@ -2797,33 +2777,35 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
//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;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + @"Inventory table successfully updated.";
|
||||
informationLabel.Text += @"Inventory table successfully updated." + Environment.NewLine;
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to update the changes in the Inventory table.";
|
||||
errorLabel.Text = @"Failed to update the changes in the Inventory table." + Environment.NewLine;
|
||||
}
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables:
|
||||
//Insert the new values...
|
||||
informationLabel.Text += Environment.NewLine + @"Inserting new changes to the Inventory table.";
|
||||
dbWriterStatus = dbW.InsertIntoInventoryTable(trimmedTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
//Spin through the collection and update the affected rows.
|
||||
foreach (var rowIndex in dbWriterStatus.GetRowCollection())
|
||||
{
|
||||
//Add the ID numbers to the first column since these are new additions to the database.
|
||||
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;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + @"Inventory table successfully added to the database.";
|
||||
informationLabel.Text += @"Inventory table successfully added to the database." + Environment.NewLine;
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to insert Inventory table into the database.";
|
||||
errorLabel.Text = @"Failed to insert Inventory table into the database." + Environment.NewLine;
|
||||
}
|
||||
dbWriterStatus = dbW.UpdateInventoryTable(updateTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
@@ -2832,15 +2814,15 @@ namespace AdvertsingProfitControl
|
||||
foreach (var rowIndex in dbWriterStatus.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].Cells[(int) InventoryTableColumns.IsDirty].Value = false;
|
||||
inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + @"Inventory table successfully updated.";
|
||||
informationLabel.Text += @"Inventory table successfully updated." + Environment.NewLine;
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to update the changes in the Inventory table.";
|
||||
errorLabel.Text = @"Failed to update the changes in the Inventory table." + Environment.NewLine;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user