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:
@@ -107,6 +107,7 @@
|
||||
<Compile Include="AdItemCollectionModel.cs" />
|
||||
<Compile Include="AdvertisingProfitControlTableHelper.cs" />
|
||||
<Compile Include="ApplicationColors.cs" />
|
||||
<Compile Include="DbTableWriterStatus.cs" />
|
||||
<Compile Include="DbWriterStatus.cs" />
|
||||
<Compile Include="TextFormat.cs" />
|
||||
<Compile Include="APCDatabaseWriter.cs" />
|
||||
|
||||
@@ -23,10 +23,10 @@ namespace AdvertsingProfitControl
|
||||
/// <param name="salesTable">The data table that contains the data to be inserted.</param>
|
||||
/// <param name="connectionString">A string pointing to the database.</param>
|
||||
/// <returns>A DbWriterStatus object that contains a status, rows added and an error message if necessary.</returns>
|
||||
public DbWriterStatus InsertIntoSalesTable(DataTable salesTable, string connectionString)
|
||||
public DbTableWriterStatus InsertIntoSalesTable(DataTable salesTable, string connectionString)
|
||||
{
|
||||
var lastRowProcessed = 0;
|
||||
var writerStatus = new DbWriterStatus();
|
||||
var writerStatus = new DbTableWriterStatus();
|
||||
var oleDbConnection = new OleDbConnection(connectionString);
|
||||
var oleDbCommand = new OleDbCommand
|
||||
{
|
||||
@@ -126,9 +126,9 @@ namespace AdvertsingProfitControl
|
||||
/// <param name="salesTable">The data table that contains the data to be inserted.</param>
|
||||
/// <param name="connectionString">A string pointing to the database.</param>
|
||||
/// <returns>A DbWriterStatus object that contains a status, rows added and an error message if necessary.</returns>
|
||||
public DbWriterStatus UpdateSalesTable(DataTable salesTable, string connectionString)
|
||||
public DbTableWriterStatus UpdateSalesTable(DataTable salesTable, string connectionString)
|
||||
{
|
||||
var updateStatus = new DbWriterStatus();
|
||||
var updateStatus = new DbTableWriterStatus();
|
||||
var lastRowProccessed = 0;
|
||||
var oleDbConnection = new OleDbConnection(connectionString);
|
||||
var oleDbCommand = new OleDbCommand
|
||||
@@ -228,9 +228,9 @@ namespace AdvertsingProfitControl
|
||||
/// <param name="table">The data table that contains the data to be inserted.</param>
|
||||
/// <param name="connectionString">A string pointing to the database.</param>
|
||||
/// <returns>A DbWriterStatus object that contains a status, rows added and an error message if necessary.</returns>
|
||||
public DbWriterStatus InsertIntoInventoryTable(DataTable table, string connectionString)
|
||||
public DbTableWriterStatus InsertIntoInventoryTable(DataTable table, string connectionString)
|
||||
{
|
||||
var status = new DbWriterStatus();
|
||||
var status = new DbTableWriterStatus();
|
||||
var lastRowProcessed = 0;
|
||||
var oleDbConnection = new OleDbConnection(connectionString);
|
||||
var oleDbCommand = new OleDbCommand
|
||||
@@ -321,9 +321,9 @@ namespace AdvertsingProfitControl
|
||||
/// <param name="table">The table with the changes to be made.</param>
|
||||
/// <param name="connectionString">A string pointing to the database.</param>
|
||||
/// <returns>A DbWriterStatus object that contains a status, rows added and an error message if necessary.</returns>
|
||||
public DbWriterStatus UpdateInventoryTable(DataTable table, string connectionString)
|
||||
public DbTableWriterStatus UpdateInventoryTable(DataTable table, string connectionString)
|
||||
{
|
||||
var status = new DbWriterStatus();
|
||||
var status = new DbTableWriterStatus();
|
||||
var lastRowProcessed = 0;
|
||||
var oleDbConnection = new OleDbConnection(connectionString);
|
||||
var oleDbCommand = new OleDbCommand
|
||||
@@ -408,9 +408,9 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
|
||||
|
||||
public DbWriterStatus ProccessInvoiceTable(DataGridView table, int dateId, string connectionString)
|
||||
public DbTableWriterStatus ProccessInvoiceTable(DataGridView table, int dateId, string connectionString)
|
||||
{
|
||||
var status = new DbWriterStatus();
|
||||
var status = new DbTableWriterStatus();
|
||||
var lastRowProcessed = 0;
|
||||
var rowsAdded = new List<int>();
|
||||
var oleDbConnection = new OleDbConnection(connectionString);
|
||||
@@ -549,22 +549,24 @@ namespace AdvertsingProfitControl
|
||||
var reader = oleDbCommand.ExecuteReader();
|
||||
while (reader != null && reader.Read())
|
||||
{
|
||||
status.AddRowId(0, int.Parse(reader[0].ToString()));
|
||||
status.Id = int.Parse(reader[0].ToString());
|
||||
}
|
||||
status.Status = status.Id > 0 ? WritingOperationStatus.InsertionSuccessful : WritingOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
oleDbCommand.CommandText = "UPDATE Comment SET Comment = ? WHERE ID = ?";
|
||||
oleDbCommand.Parameters.AddWithValue("Comment", comments);
|
||||
oleDbCommand.Parameters.AddWithValue("ID", id);
|
||||
oleDbCommand.ExecuteNonQuery();
|
||||
var rowsEffected = oleDbCommand.ExecuteNonQuery();
|
||||
status.Status = rowsEffected == 1 ? WritingOperationStatus.UpdateSuccessful : WritingOperationStatus.Failed;
|
||||
}
|
||||
}
|
||||
catch (OleDbException e)
|
||||
{
|
||||
status.SetStatus(WritingOperationStatus.Failed);
|
||||
status.Status = WritingOperationStatus.Failed;
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the comment(s): " + e.Message);
|
||||
status.SetErrorMessage("Failed to update or insert comments into the database.");
|
||||
status.ErrorMessage = "Failed to update or insert comments into the database.";
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -606,8 +608,9 @@ namespace AdvertsingProfitControl
|
||||
var reader = oleDbCommand.ExecuteReader();
|
||||
while (reader != null && reader.Read())
|
||||
{
|
||||
status.AddRowId(0, int.Parse(reader[0].ToString()));
|
||||
status.Id = int.Parse(reader[0].ToString());
|
||||
}
|
||||
status.Status = status.Id > 0 ? WritingOperationStatus.InsertionSuccessful : WritingOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -621,14 +624,15 @@ namespace AdvertsingProfitControl
|
||||
oleDbCommand.Parameters.AddWithValue("Saturday", weeklySales[6]);
|
||||
oleDbCommand.Parameters.AddWithValue("TotalSales", weeklySales[7]);
|
||||
oleDbCommand.Parameters.AddWithValue("ID", id);
|
||||
oleDbCommand.ExecuteNonQuery();
|
||||
var rowsEffected = oleDbCommand.ExecuteNonQuery();
|
||||
status.Status = rowsEffected == 1 ? WritingOperationStatus.UpdateSuccessful : WritingOperationStatus.Failed;
|
||||
}
|
||||
}
|
||||
catch (OleDbException e)
|
||||
{
|
||||
status.SetStatus(WritingOperationStatus.Failed);
|
||||
status.Status = WritingOperationStatus.Failed;
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the weekly sales: " + e.Message);
|
||||
status.SetErrorMessage("Failed to update or insert weekly sales into the database.");
|
||||
status.ErrorMessage = "Failed to update or insert weekly sales into the database.";
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -670,8 +674,9 @@ namespace AdvertsingProfitControl
|
||||
var reader = oleDbCommand.ExecuteReader();
|
||||
while (reader != null && reader.Read())
|
||||
{
|
||||
status.AddRowId(0, int.Parse(reader[0].ToString()));
|
||||
status.Id = int.Parse(reader[0].ToString());
|
||||
}
|
||||
status.Status = status.Id > 0 ? WritingOperationStatus.InsertionSuccessful : WritingOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -685,14 +690,15 @@ namespace AdvertsingProfitControl
|
||||
oleDbCommand.Parameters.AddWithValue("Saturday", taxable[6]);
|
||||
oleDbCommand.Parameters.AddWithValue("TotalSales", taxable[7]);
|
||||
oleDbCommand.Parameters.AddWithValue("ID", id);
|
||||
oleDbCommand.ExecuteNonQuery();
|
||||
var rowsEffected = oleDbCommand.ExecuteNonQuery();
|
||||
status.Status = rowsEffected == 1 ? WritingOperationStatus.UpdateSuccessful : WritingOperationStatus.Failed;
|
||||
}
|
||||
}
|
||||
catch (OleDbException e)
|
||||
{
|
||||
status.SetStatus(WritingOperationStatus.Failed);
|
||||
status.Status = WritingOperationStatus.Failed;
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the taxable: " + e.Message);
|
||||
status.SetErrorMessage("Failed to update or insert taxable into the database.");
|
||||
status.ErrorMessage = "Failed to update or insert taxable into the database.";
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -723,15 +729,16 @@ namespace AdvertsingProfitControl
|
||||
oleDbCommand.Parameters.AddWithValue("DateID", dateId);
|
||||
oleDbCommand.ExecuteNonQuery();
|
||||
//Now grab the ID number of the comment that was just added.
|
||||
oleDbCommand.CommandText = "SELECT ID FROM Taxable WHERE FK_DateID = ?";
|
||||
oleDbCommand.CommandText = "SELECT ID FROM CostOfSalesAnalysis WHERE FK_DateID = ?";
|
||||
oleDbCommand.Parameters.Clear();
|
||||
oleDbCommand.Parameters.AddWithValue("DateID", dateId);
|
||||
//Now read the ID number and add it to the collection with a default key.
|
||||
var reader = oleDbCommand.ExecuteReader();
|
||||
while (reader != null && reader.Read())
|
||||
{
|
||||
status.AddRowId(0, int.Parse(reader[0].ToString()));
|
||||
status.Id = int.Parse(reader[0].ToString());
|
||||
}
|
||||
status.Status = status.Id > 0 ? WritingOperationStatus.InsertionSuccessful : WritingOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -741,14 +748,15 @@ namespace AdvertsingProfitControl
|
||||
oleDbCommand.Parameters.AddWithValue("SalaryDollars", costAnalysis[2]);
|
||||
oleDbCommand.Parameters.AddWithValue("Supplies", costAnalysis[3]);
|
||||
oleDbCommand.Parameters.AddWithValue("ID", id);
|
||||
oleDbCommand.ExecuteNonQuery();
|
||||
var rowsEffected = oleDbCommand.ExecuteNonQuery();
|
||||
status.Status = rowsEffected == 1 ? WritingOperationStatus.UpdateSuccessful : WritingOperationStatus.Failed;
|
||||
}
|
||||
}
|
||||
catch (OleDbException e)
|
||||
{
|
||||
status.SetStatus(WritingOperationStatus.Failed);
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the taxable: " + e.Message);
|
||||
status.SetErrorMessage("Failed to update or insert taxable into the database.");
|
||||
status.Status = WritingOperationStatus.Failed;
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the cost analysis: " + e.Message);
|
||||
status.ErrorMessage = "Failed to update or insert costs analysis.";
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
internal class DbTableWriterStatus
|
||||
{
|
||||
//Initialize the _status to failed just to have it not be null.
|
||||
private WritingOperationStatus _status = WritingOperationStatus.Failed;
|
||||
private readonly Dictionary<int, int> _rowIds;
|
||||
private string _errorMessage;
|
||||
|
||||
public DbTableWriterStatus()
|
||||
{
|
||||
_rowIds = new Dictionary<int, int>();
|
||||
}
|
||||
|
||||
public void SetStatus(WritingOperationStatus status)
|
||||
{
|
||||
_status = status;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the status from the operation.
|
||||
/// </summary>
|
||||
/// <returns>A status indicating whether or not it was successful, default is failed.</returns>
|
||||
public WritingOperationStatus GetWritingOperationStatus()
|
||||
{
|
||||
return _status;
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds a row to the Rows Dictionary that keeps track of what rows have been
|
||||
/// added to the database including their IDs.
|
||||
/// </summary>
|
||||
/// <param name="rowIndex">The index of the row that was added to the database.</param>
|
||||
/// <param name="rowIdNumber">The ID number of the row as represented in the database.</param>
|
||||
public void AddRowId(int rowIndex, int rowIdNumber)
|
||||
{
|
||||
_rowIds.Add(rowIndex, rowIdNumber);
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes a row from the Rows collection.
|
||||
/// </summary>
|
||||
/// <param name="key">The row's index that is to be deleted.</param>
|
||||
public void DeleteRow(int key)
|
||||
{
|
||||
_rowIds.Remove(key);
|
||||
}
|
||||
|
||||
public void ClearRowCollection()
|
||||
{
|
||||
_rowIds.Clear();
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the Dictionary containing rows that have been added to the database.
|
||||
/// The keys are the row's index and the value is the row's ID as represented
|
||||
/// in the database.
|
||||
/// Returns an empty Dictionary if no rows have been added.
|
||||
/// </summary>
|
||||
/// <returns>The rows that have been added to the database.</returns>
|
||||
public Dictionary<int, int> GetRowCollection()
|
||||
{
|
||||
return _rowIds;
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets an error message.
|
||||
/// </summary>
|
||||
/// <param name="message">The error message to be set.</param>
|
||||
public void SetErrorMessage(string message)
|
||||
{
|
||||
_errorMessage = message;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets any error message set by the Insertion/Update operation function.
|
||||
/// If none are set returns an empty string.
|
||||
/// </summary>
|
||||
/// <returns>The error message.</returns>
|
||||
public string GetErrorMessage()
|
||||
{
|
||||
//If the error message is null then return string.Empty.
|
||||
//Otherwise return the error message.
|
||||
return _errorMessage ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Operation status emus to keep things consistent.
|
||||
/// </summary>
|
||||
public enum WritingOperationStatus
|
||||
{
|
||||
Failed = 0,
|
||||
InsertionSuccessful = 1,
|
||||
UpdateSuccessful = 2
|
||||
}
|
||||
}
|
||||
@@ -1,93 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
internal class DbWriterStatus
|
||||
{
|
||||
//Initialize the _status to failed just to have it not be null.
|
||||
private WritingOperationStatus _status = WritingOperationStatus.Failed;
|
||||
private readonly Dictionary<int, int> _rowIds;
|
||||
private string _errorMessage;
|
||||
|
||||
public DbWriterStatus()
|
||||
{
|
||||
_rowIds = new Dictionary<int, int>();
|
||||
}
|
||||
|
||||
public void SetStatus(WritingOperationStatus status)
|
||||
{
|
||||
_status = status;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the status from the operation.
|
||||
/// </summary>
|
||||
/// <returns>A status indicating whether or not it was successful, default is failed.</returns>
|
||||
public WritingOperationStatus GetWritingOperationStatus()
|
||||
{
|
||||
return _status;
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds a row to the Rows Dictionary that keeps track of what rows have been
|
||||
/// added to the database including their IDs.
|
||||
/// </summary>
|
||||
/// <param name="rowIndex">The index of the row that was added to the database.</param>
|
||||
/// <param name="rowIdNumber">The ID number of the row as represented in the database.</param>
|
||||
public void AddRowId(int rowIndex, int rowIdNumber)
|
||||
{
|
||||
_rowIds.Add(rowIndex, rowIdNumber);
|
||||
}
|
||||
/// <summary>
|
||||
/// Removes a row from the Rows collection.
|
||||
/// </summary>
|
||||
/// <param name="key">The row's index that is to be deleted.</param>
|
||||
public void DeleteRow(int key)
|
||||
{
|
||||
_rowIds.Remove(key);
|
||||
}
|
||||
|
||||
public void ClearRowCollection()
|
||||
{
|
||||
_rowIds.Clear();
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the Dictionary containing rows that have been added to the database.
|
||||
/// The keys are the row's index and the value is the row's ID as represented
|
||||
/// in the database.
|
||||
/// Returns an empty Dictionary if no rows have been added.
|
||||
/// </summary>
|
||||
/// <returns>The rows that have been added to the database.</returns>
|
||||
public Dictionary<int, int> GetRowCollection()
|
||||
{
|
||||
return _rowIds;
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets an error message.
|
||||
/// </summary>
|
||||
/// <param name="message">The error message to be set.</param>
|
||||
public void SetErrorMessage(string message)
|
||||
{
|
||||
_errorMessage = message;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets any error message set by the Insertion/Update operation function.
|
||||
/// If none are set returns an empty string.
|
||||
/// </summary>
|
||||
/// <returns>The error message.</returns>
|
||||
public string GetErrorMessage()
|
||||
{
|
||||
//If the error message is null then return string.Empty.
|
||||
//Otherwise return the error message.
|
||||
return _errorMessage ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Operation status emus to keep things consistent.
|
||||
/// </summary>
|
||||
public enum WritingOperationStatus
|
||||
{
|
||||
Failed = 0,
|
||||
InsertionSuccessful = 1,
|
||||
UpdateSuccessful = 2
|
||||
public string ErrorMessage;
|
||||
public int Id;
|
||||
public WritingOperationStatus Status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,17 +30,6 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
var versionControl = new DatabaseVersionControl();
|
||||
var version = versionControl.GetDatabaseVerionNumber(databaseTracker.DatabaseConnectionString);
|
||||
if(version == "0.3.0.0")
|
||||
{
|
||||
MessageBox.Show("An older version of the APC database has been detected.\nAdvertising Profit Control " + Application.ProductVersion + " will now attempt to update it.", "Outdated Database Detected");
|
||||
string versionNumber = "";
|
||||
if (versionControl.UpdateVersionPointFive(databaseTracker.DatabaseConnectionString, out versionNumber))
|
||||
{
|
||||
MessageBox.Show("The database has been successfully upgraded to version " + versionNumber + ".\nA back up of the old database has been made called APCDatabase.bak in the same location as the current database.", "Half Baked Code For The Win");
|
||||
}
|
||||
}
|
||||
RowParsing.AdSpecialGroups.AddRange(databaseReader.ReturnGroupNameList(databaseTracker.DatabaseConnectionString));
|
||||
FillDateSuggestionComboBoxes();
|
||||
BuildAndFillDataGridTables();
|
||||
|
||||
+2
-4
@@ -303,6 +303,7 @@
|
||||
//
|
||||
// debugPanel
|
||||
//
|
||||
this.debugPanel.Controls.Add(this.informationLabel);
|
||||
this.debugPanel.Controls.Add(this.generateCostAnalysisIdButton);
|
||||
this.debugPanel.Controls.Add(this.generateTaxableIdButton);
|
||||
this.debugPanel.Controls.Add(this.generateWeeklySalesIdButton);
|
||||
@@ -951,7 +952,6 @@
|
||||
//
|
||||
// informationPanel
|
||||
//
|
||||
this.informationPanel.Controls.Add(this.informationLabel);
|
||||
this.informationPanel.Controls.Add(this.addRecordButton);
|
||||
this.informationPanel.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.informationPanel.Location = new System.Drawing.Point(1410, 824);
|
||||
@@ -962,7 +962,7 @@
|
||||
// informationLabel
|
||||
//
|
||||
this.informationLabel.AutoSize = true;
|
||||
this.informationLabel.Location = new System.Drawing.Point(0, 0);
|
||||
this.informationLabel.Location = new System.Drawing.Point(3, 18);
|
||||
this.informationLabel.Name = "informationLabel";
|
||||
this.informationLabel.Size = new System.Drawing.Size(152, 25);
|
||||
this.informationLabel.TabIndex = 27;
|
||||
@@ -988,7 +988,6 @@
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MainMenuStrip = this.mainMenuStrip;
|
||||
this.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.MaximumSize = new System.Drawing.Size(1900, 1025);
|
||||
this.MinimumSize = new System.Drawing.Size(1000, 1000);
|
||||
this.Name = "NewAddRecord";
|
||||
this.Text = "Add New Record";
|
||||
@@ -1022,7 +1021,6 @@
|
||||
this.dateTimeMaskedTextBoxPanel.ResumeLayout(false);
|
||||
this.dateTimeMaskedTextBoxPanel.PerformLayout();
|
||||
this.informationPanel.ResumeLayout(false);
|
||||
this.informationPanel.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
if (writerStatus.GetWritingOperationStatus() == WritingOperationStatus.Failed)
|
||||
var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString, int.Parse(isCommentDirtyCheckBox.Tag.ToString()));
|
||||
if (status.Status == WritingOperationStatus.Failed)
|
||||
{
|
||||
errorLabel.Text = writerStatus.GetErrorMessage();
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Comment(s) processed successfully.";
|
||||
}
|
||||
}
|
||||
}
|
||||
//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);
|
||||
|
||||
informationLabel.Text += @"All operations completed successfully.";
|
||||
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)
|
||||
{
|
||||
errorLabel.Text = status.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"Weekly Sales processed successfully.";
|
||||
isWeeklySalesDirtyCheckBox.Tag = status.Id;
|
||||
isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty (" + status.Id + @")";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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.";
|
||||
}
|
||||
}
|
||||
}
|
||||
//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)
|
||||
{
|
||||
|
||||
@@ -120,6 +120,9 @@
|
||||
<metadata name="mainMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="mainMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>OlX6CvX02QUSDXImEM6f2HKdWzzRripa5ZZRa0lenPo=</dsig:DigestValue>
|
||||
<dsig:DigestValue>xZQf4lyG78NuQ0APSprGJE7TfHmXY3q7EniNsorWnAI=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
@@ -43,14 +43,14 @@
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3543552">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3546624">
|
||||
<assemblyIdentity name="AdvertsingProfitControl" version="0.9.5.2" language="neutral" processorArchitecture="amd64" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>4TfzARAAxdb/PYNmotwSF5x29OfcgoIH9QiACmt25T0=</dsig:DigestValue>
|
||||
<dsig:DigestValue>pwX2HuLuQjN0X0mlI91r2H59iOeuMyMgp+zObWw85r0=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
Reference in New Issue
Block a user