Finished and tested database writing code for non table entities. Improved information reporting to the user, and created a new DbWriter object for table operations only.
This commit is contained in:
@@ -1857,7 +1857,7 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
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.";
|
||||
errorLabel.Text = @"* The date you selected does not appear to be a week ending date.";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1991,7 +1991,7 @@ namespace AdvertsingProfitControl
|
||||
//Create the cleaned table objects that will be sent to the database.
|
||||
DataTable trimmedTable;
|
||||
DataTable updateTable;
|
||||
informationLabel.Text = @"Compressing data tables...";
|
||||
informationLabel.Text = @"Compressing data tables..." + Environment.NewLine;
|
||||
errorLabel.Text = "";
|
||||
var operationStatus = ConstructCleanedSalesTable("Projections", dateId, out trimmedTable, out updateTable);
|
||||
if (operationStatus == TrimmingOperationResult.FailedToTrim)
|
||||
@@ -2024,40 +2024,169 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
errorLabel.Text = writerStatus.GetErrorMessage();
|
||||
}
|
||||
|
||||
//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).";
|
||||
writerStatus = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString);
|
||||
if (writerStatus.GetWritingOperationStatus() == WritingOperationStatus.Failed)
|
||||
var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString);
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
errorLabel.Text = writerStatus.GetErrorMessage();
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Comment(s) processed successfully.";
|
||||
var id = writerStatus.GetRowCollection();
|
||||
|
||||
var id = status.Id;
|
||||
isCommentDirtyCheckBox.Tag = id;
|
||||
isCommentDirtyCheckBox.Text = @"IsCommentDirty (" + id + @")";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//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).";
|
||||
writerStatus = 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)
|
||||
{
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Comment(s) processed successfully.";
|
||||
}
|
||||
}
|
||||
if (writerStatus.GetWritingOperationStatus() == WritingOperationStatus.Failed)
|
||||
}
|
||||
//Begin checking the Weekly Sales.
|
||||
if (isWeeklySalesDirtyCheckBox.Checked)
|
||||
{
|
||||
//Parse out all the text boxes' values in the weekly sales group.
|
||||
var weeklySales = new double[8];
|
||||
weeklySales[0] = sundayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(sundayWeeklySalesTextBox.Text);
|
||||
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[5] = fridayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(fridayWeeklySalesTextBox.Text);
|
||||
weeklySales[6] = saturdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(saturdayWeeklySalesTextBox.Text);
|
||||
weeklySales[7] = totalWeeklySalesTextBox.Text == "" ? 0 : double.Parse(totalWeeklySalesTextBox.Text);
|
||||
|
||||
if (isWeeklySalesDirtyCheckBox.Tag == null)
|
||||
{
|
||||
errorLabel.Text = writerStatus.GetErrorMessage();
|
||||
//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)
|
||||
{
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Weekly Sales processed successfully.";
|
||||
isWeeklySalesDirtyCheckBox.Tag = status.Id;
|
||||
isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty (" + status.Id + @")";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Comment(s) processed successfully.";
|
||||
informationLabel.Text += @"Updating Weekly Sales.";
|
||||
var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString, int.Parse(isWeeklySalesDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Weekly Sales updated successfully.";
|
||||
}
|
||||
}
|
||||
}
|
||||
//Begin checking the Taxable.
|
||||
if (isTaxableDirtyCheckBox.Checked)
|
||||
{
|
||||
//Parse out all the text boxes' values in the taxable group.
|
||||
var taxable = new double[8];
|
||||
taxable[0] = sundayTaxableTextBox.Text == "" ? 0 : double.Parse(sundayTaxableTextBox.Text);
|
||||
taxable[1] = mondayTaxableTextBox.Text == "" ? 0 : double.Parse(mondayTaxableTextBox.Text);
|
||||
taxable[2] = tuesdayTaxableTextBox.Text == "" ? 0 : double.Parse(tuesdayTaxableTextBox.Text);
|
||||
taxable[3] = wednesdayTaxableTextBox.Text == "" ? 0 : double.Parse(wednesdayTaxableTextBox.Text);
|
||||
taxable[4] = thursdayTaxableTextBox.Text == "" ? 0 : double.Parse(thursdayTaxableTextBox.Text);
|
||||
taxable[5] = fridayTaxableTextBox.Text == "" ? 0 : double.Parse(fridayTaxableTextBox.Text);
|
||||
taxable[6] = saturdayTaxableTextBox.Text == "" ? 0 : double.Parse(saturdayTaxableTextBox.Text);
|
||||
taxable[7] = totalTaxableTextBox.Text == "" ? 0 : double.Parse(totalTaxableTextBox.Text);
|
||||
|
||||
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)
|
||||
{
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Taxable processed successfully.";
|
||||
isTaxableDirtyCheckBox.Tag = status.Id;
|
||||
isTaxableDirtyCheckBox.Text = @"IsTaxableDirty (" + status.Id + @")";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Updating Taxable.";
|
||||
var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString, int.Parse(isTaxableDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Taxable updated successfully.";
|
||||
}
|
||||
}
|
||||
}
|
||||
//Begin checking cost analysis.
|
||||
if (isCostAnalysisDirtyCheckBox.Checked)
|
||||
{
|
||||
//Parse out the cost analysis group values.
|
||||
var costAnalysis = new double[4];
|
||||
costAnalysis[0] = salesPerManHourTextBox.Text == "" ? 0 : double.Parse(salesPerManHourTextBox.Text);
|
||||
costAnalysis[1] = salaryPercentageTextBox.Text == "" ? 0 : double.Parse(salaryPercentageTextBox.Text);
|
||||
costAnalysis[2] = salaryDollarsTextBox.Text == "" ? 0 : double.Parse(salaryDollarsTextBox.Text);
|
||||
costAnalysis[3] = suppliesTextBox.Text == "" ? 0 : double.Parse(suppliesTextBox.Text);
|
||||
|
||||
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)
|
||||
{
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Costs analysis processed successfully.";
|
||||
isCostAnalysisDirtyCheckBox.Tag = status.Id;
|
||||
isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty (" + status.Id + @")";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Updating cost analysis.";
|
||||
var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString, int.Parse(isCostAnalysisDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Cost analysis updated successfully.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
informationLabel.Text += @"All operations completed successfully.";
|
||||
//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.
|
||||
@@ -2530,16 +2659,16 @@ namespace AdvertsingProfitControl
|
||||
//Create the database interaction objects.
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
DbWriterStatus dbWriterStatus;
|
||||
DbTableWriterStatus dbWriterStatus;
|
||||
var successful = false;
|
||||
switch (operationStatus)
|
||||
{
|
||||
case TrimmingOperationResult.NoChangesRequired:
|
||||
informationLabel.Text += Environment.NewLine + @"No changes for the " + tableName + @" table detected.";
|
||||
informationLabel.Text += Environment.NewLine + @"No changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table detected.";
|
||||
successful = true;
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedNewInsertionTable:
|
||||
informationLabel.Text += Environment.NewLine + @"Inserting new changes to the " + tableName + @" table.";
|
||||
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)
|
||||
{
|
||||
@@ -2549,7 +2678,7 @@ 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;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + tableName + @" table successfully added to the database.";
|
||||
informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database.";
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
@@ -2558,7 +2687,7 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedUpdateTable:
|
||||
informationLabel.Text += Environment.NewLine + @"Updating changes made to the " + tableName + @" table.";
|
||||
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)
|
||||
{
|
||||
@@ -2568,7 +2697,7 @@ 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;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + tableName + @" table successfully updated.";
|
||||
informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated.";
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
@@ -2578,7 +2707,7 @@ namespace AdvertsingProfitControl
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables:
|
||||
//Insert the new values...
|
||||
informationLabel.Text += Environment.NewLine + @"Inserting new changes to the " + tableName + @" table.";
|
||||
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)
|
||||
{
|
||||
@@ -2588,14 +2717,14 @@ 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;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + tableName + @" table successfully added to the database.";
|
||||
informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database.";
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database.";
|
||||
}
|
||||
//... and update the existing values.
|
||||
informationLabel.Text += Environment.NewLine + @"Updating changes made to the " + tableName + @" table.";
|
||||
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)
|
||||
{
|
||||
@@ -2605,7 +2734,7 @@ 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;
|
||||
}
|
||||
informationLabel.Text += Environment.NewLine + tableName + @" table successfully updated.";
|
||||
informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated.";
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
@@ -2623,7 +2752,7 @@ namespace AdvertsingProfitControl
|
||||
//Create the database interaction objects.
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
DbWriterStatus dbWriterStatus;
|
||||
DbTableWriterStatus dbWriterStatus;
|
||||
var successful = false;
|
||||
switch (operationStatus)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user