Fixed a bug with the invoice table failing to save an invoice number longer then 9 characters.

This commit is contained in:
2017-01-21 04:17:09 -06:00
parent f9968942ea
commit d429f2b931
5 changed files with 231 additions and 197 deletions
+222 -189
View File
@@ -3295,7 +3295,11 @@ namespace AdvertsingProfitControl
{
errorLabel.Text += @"Failed to process actual sales." + Environment.NewLine;
}
return success;
if (!SaveInvoices(dateId)) return false;
if (!SaveComments(dateId)) return false;
if (!SaveWeeklySales(dateId)) return false;
if (!SaveTaxable(dateId)) return false;
return SaveCostAnalysis(dateId) && success;
}
/// <summary>
@@ -3325,6 +3329,222 @@ namespace AdvertsingProfitControl
return dateId;
}
private bool SaveInvoices(int dateId)
{
var dbT = new DatabaseTracker();
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
//Commit the Invoice table to the database.
var writerStatus = dbW.ProccessInvoiceTable(invoicesDataGridView, dateId, dbT.DatabaseConnectionString);
if (writerStatus.GetWritingOperationStatus() == WritingOperationStatus.Failed)
{
errorLabel.Text = writerStatus.GetErrorMessage();
return false;
}
informationLabel.Text += writerStatus.GetErrorMessage() + Environment.NewLine;
return true;
}
private bool SaveComments(int dateId)
{
var dbT = new DatabaseTracker();
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
//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)
{
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;
return false;
}
informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine;
var id = status.Id;
isCommentDirtyCheckBox.Tag = id;
isCommentDirtyCheckBox.Text = @"IsCommentDirty (" + id + @")";
isCommentDirtyCheckBox.Checked = false;
return true;
}
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.
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;
return false;
}
isCommentDirtyCheckBox.Checked = false;
informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine;
return true;
}
}
informationLabel.Text += @"No changes detected for the comment(s)" + Environment.NewLine;
return true;
}
private bool SaveWeeklySales(int dateId)
{
var dbT = new DatabaseTracker();
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
//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] = wednesdayWeeklySalesTextBox.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)
{
//Weekly sales is not in the database.
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;
return false;
}
informationLabel.Text += @"Weekly Sales processed successfully." + Environment.NewLine;
isWeeklySalesDirtyCheckBox.Tag = status.Id;
isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty (" + status.Id + @")";
isWeeklySalesDirtyCheckBox.Checked = false;
return true;
}
else
{
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;
return false;
}
isWeeklySalesDirtyCheckBox.Checked = false;
informationLabel.Text += @"Weekly Sales updated successfully." + Environment.NewLine;
return true;
}
}
informationLabel.Text += @"No changes detected for Weekly Sales." + Environment.NewLine;
return true;
}
private bool SaveTaxable(int dateId)
{
var dbT = new DatabaseTracker();
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
//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)
{
//Taxable is not in the database.
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;
return false;
}
informationLabel.Text += @"Taxable processed successfully." + Environment.NewLine;
isTaxableDirtyCheckBox.Tag = status.Id;
isTaxableDirtyCheckBox.Text = @"IsTaxableDirty (" + status.Id + @")";
return true;
}
else
{
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;
return false;
}
isTaxableDirtyCheckBox.Checked = false;
informationLabel.Text += @"Taxable updated successfully." + Environment.NewLine;
return true;
}
}
informationLabel.Text += @"No changes detected for Taxable." + Environment.NewLine;
return true;
}
private bool SaveCostAnalysis(int dateId)
{
var dbT = new DatabaseTracker();
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
//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.
var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString);
if (status.Status == WritingOperationStatus.Failed)
{
informationLabel.Text += @"Failed to add Cost Analysis to the database." + Environment.NewLine;
errorLabel.Text = status.ErrorMessage;
return false;
}
informationLabel.Text += @"Costs Analysis processed successfully." + Environment.NewLine;
isCostAnalysisDirtyCheckBox.Tag = status.Id;
isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty (" + status.Id + @")";
isCostAnalysisDirtyCheckBox.Checked = false;
return true;
}
else
{
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." + Environment.NewLine;
errorLabel.Text = status.ErrorMessage;
return false;
}
isCostAnalysisDirtyCheckBox.Checked = false;
informationLabel.Text += @"Cost Analysis updated successfully." + Environment.NewLine;
return true;
}
}
informationLabel.Text += @"No changes made to Cost Analysis." + Environment.NewLine;
return true;
}
#endregion
#region Table Trimming Operations
@@ -3641,200 +3861,13 @@ namespace AdvertsingProfitControl
return TrimmingOperationResult.CreatedNewInsertionAndUpdateTables;
}
private bool ProcessTrimmingStatusResult(DataGridView dataGridView, string tableName, TrimmingOperationResult operationStatus, DataTable trimmedTable, DataTable updateTable)
{
//Create the database interaction objects.
var dbT = new DatabaseTracker();
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
DbTableWriterStatus dbWriterStatus;
var successful = false;
switch (operationStatus)
{
case TrimmingOperationResult.NoChangesRequired:
informationLabel.Text += @"No changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table detected." + Environment.NewLine;
successful = true;
break;
case TrimmingOperationResult.CreatedNewInsertionTable:
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())
{
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 += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database." + Environment.NewLine;
successful = true;
}
else
{
errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database." + Environment.NewLine;
}
break;
case TrimmingOperationResult.CreatedUpdateTable:
dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString);
if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
//Spin through the collection and update the affected rows.
foreach (var rowIndex in dbWriterStatus.GetRowCollection())
{
//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 += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated." + Environment.NewLine;
successful = true;
}
else
{
errorLabel.Text = @"Failed to update the " + trimmedTable + @" table." + Environment.NewLine;
}
break;
case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables:
//Insert the new values...
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 += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database." + Environment.NewLine;
}
else
{
errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database." + Environment.NewLine;
}
//... and update the existing values.
dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString);
if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
//Spin through the collection and update the affected rows.
foreach (var rowIndex in dbWriterStatus.GetRowCollection())
{
//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 += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated." + Environment.NewLine;
successful = true;
}
else
{
errorLabel.Text = @"Failed to update the " + trimmedTable + @" table." + Environment.NewLine;
}
break;
}
return successful;
}
private bool ProcessTrimmingStatusForInventory(TrimmingOperationResult operationStatus, DataTable trimmedTable, DataTable updateTable)
{
//Create the database interaction objects.
var dbT = new DatabaseTracker();
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
DbTableWriterStatus dbWriterStatus;
var successful = false;
switch (operationStatus)
{
case TrimmingOperationResult.NoChangesRequired:
informationLabel.Text += @"No changes to the Inventory table detected." + Environment.NewLine;
successful = true;
break;
case TrimmingOperationResult.CreatedNewInsertionTable:
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())
{
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 += @"Inventory table successfully added to the database." + Environment.NewLine;
successful = true;
}
else
{
errorLabel.Text = @"Failed to insert Inventory table into the database." + Environment.NewLine;
}
break;
case TrimmingOperationResult.CreatedUpdateTable:
dbWriterStatus = dbW.UpdateInventoryTable(updateTable, dbT.DatabaseConnectionString);
if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
//Spin through the collection and update the affected rows.
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].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
}
informationLabel.Text += @"Inventory table successfully updated." + Environment.NewLine;
successful = true;
}
else
{
errorLabel.Text = @"Failed to update the changes in the Inventory table." + Environment.NewLine;
}
break;
case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables:
//Insert the new values...
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 += @"Inventory table successfully added to the database." + Environment.NewLine;
successful = true;
}
else
{
errorLabel.Text = @"Failed to insert Inventory table into the database." + Environment.NewLine;
}
dbWriterStatus = dbW.UpdateInventoryTable(updateTable, dbT.DatabaseConnectionString);
if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
//Spin through the collection and update the affected rows.
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].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
}
informationLabel.Text += @"Inventory table successfully updated." + Environment.NewLine;
successful = true;
}
else
{
errorLabel.Text = @"Failed to update the changes in the Inventory table." + Environment.NewLine;
}
break;
}
inventoryDataGridView.RefreshEdit();
return successful;
}
#endregion
private void addRecordButton_Click(object sender, EventArgs e)
{
SaveRecords();
}
#endregion
//private void NormalizeApcTables(DataTable projections, DataTable inventory, DataTable actualSales, string dateId)
//{