diff --git a/AdvertsingProfitControl/AdvertsingProfitControl.csproj b/AdvertsingProfitControl/AdvertsingProfitControl.csproj index 1e3db06..dbf4cb2 100644 --- a/AdvertsingProfitControl/AdvertsingProfitControl.csproj +++ b/AdvertsingProfitControl/AdvertsingProfitControl.csproj @@ -107,6 +107,7 @@ + diff --git a/AdvertsingProfitControl/DatabaseWriter.cs b/AdvertsingProfitControl/DatabaseWriter.cs index fd405c7..2302614 100644 --- a/AdvertsingProfitControl/DatabaseWriter.cs +++ b/AdvertsingProfitControl/DatabaseWriter.cs @@ -23,10 +23,10 @@ namespace AdvertsingProfitControl /// The data table that contains the data to be inserted. /// A string pointing to the database. /// A DbWriterStatus object that contains a status, rows added and an error message if necessary. - 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 /// The data table that contains the data to be inserted. /// A string pointing to the database. /// A DbWriterStatus object that contains a status, rows added and an error message if necessary. - 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 /// The data table that contains the data to be inserted. /// A string pointing to the database. /// A DbWriterStatus object that contains a status, rows added and an error message if necessary. - 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 /// The table with the changes to be made. /// A string pointing to the database. /// A DbWriterStatus object that contains a status, rows added and an error message if necessary. - 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(); 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 { diff --git a/AdvertsingProfitControl/DbTableWriterStatus.cs b/AdvertsingProfitControl/DbTableWriterStatus.cs new file mode 100644 index 0000000..a7f53f2 --- /dev/null +++ b/AdvertsingProfitControl/DbTableWriterStatus.cs @@ -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 _rowIds; + private string _errorMessage; + + public DbTableWriterStatus() + { + _rowIds = new Dictionary(); + } + + public void SetStatus(WritingOperationStatus status) + { + _status = status; + } + /// + /// Gets the status from the operation. + /// + /// A status indicating whether or not it was successful, default is failed. + public WritingOperationStatus GetWritingOperationStatus() + { + return _status; + } + /// + /// Adds a row to the Rows Dictionary that keeps track of what rows have been + /// added to the database including their IDs. + /// + /// The index of the row that was added to the database. + /// The ID number of the row as represented in the database. + public void AddRowId(int rowIndex, int rowIdNumber) + { + _rowIds.Add(rowIndex, rowIdNumber); + } + /// + /// Removes a row from the Rows collection. + /// + /// The row's index that is to be deleted. + public void DeleteRow(int key) + { + _rowIds.Remove(key); + } + + public void ClearRowCollection() + { + _rowIds.Clear(); + } + /// + /// 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. + /// + /// The rows that have been added to the database. + public Dictionary GetRowCollection() + { + return _rowIds; + } + /// + /// Sets an error message. + /// + /// The error message to be set. + public void SetErrorMessage(string message) + { + _errorMessage = message; + } + /// + /// Gets any error message set by the Insertion/Update operation function. + /// If none are set returns an empty string. + /// + /// The error message. + public string GetErrorMessage() + { + //If the error message is null then return string.Empty. + //Otherwise return the error message. + return _errorMessage ?? string.Empty; + } + } + + /// + /// Operation status emus to keep things consistent. + /// + public enum WritingOperationStatus + { + Failed = 0, + InsertionSuccessful = 1, + UpdateSuccessful = 2 + } +} diff --git a/AdvertsingProfitControl/DbWriterStatus.cs b/AdvertsingProfitControl/DbWriterStatus.cs index 8af4ede..0b637d0 100644 --- a/AdvertsingProfitControl/DbWriterStatus.cs +++ b/AdvertsingProfitControl/DbWriterStatus.cs @@ -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 _rowIds; - private string _errorMessage; - - public DbWriterStatus() - { - _rowIds = new Dictionary(); - } - - public void SetStatus(WritingOperationStatus status) - { - _status = status; - } - /// - /// Gets the status from the operation. - /// - /// A status indicating whether or not it was successful, default is failed. - public WritingOperationStatus GetWritingOperationStatus() - { - return _status; - } - /// - /// Adds a row to the Rows Dictionary that keeps track of what rows have been - /// added to the database including their IDs. - /// - /// The index of the row that was added to the database. - /// The ID number of the row as represented in the database. - public void AddRowId(int rowIndex, int rowIdNumber) - { - _rowIds.Add(rowIndex, rowIdNumber); - } - /// - /// Removes a row from the Rows collection. - /// - /// The row's index that is to be deleted. - public void DeleteRow(int key) - { - _rowIds.Remove(key); - } - - public void ClearRowCollection() - { - _rowIds.Clear(); - } - /// - /// 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. - /// - /// The rows that have been added to the database. - public Dictionary GetRowCollection() - { - return _rowIds; - } - /// - /// Sets an error message. - /// - /// The error message to be set. - public void SetErrorMessage(string message) - { - _errorMessage = message; - } - /// - /// Gets any error message set by the Insertion/Update operation function. - /// If none are set returns an empty string. - /// - /// The error message. - public string GetErrorMessage() - { - //If the error message is null then return string.Empty. - //Otherwise return the error message. - return _errorMessage ?? string.Empty; - } - } - - /// - /// Operation status emus to keep things consistent. - /// - public enum WritingOperationStatus - { - Failed = 0, - InsertionSuccessful = 1, - UpdateSuccessful = 2 + public string ErrorMessage; + public int Id; + public WritingOperationStatus Status; } } diff --git a/AdvertsingProfitControl/FrmMain.cs b/AdvertsingProfitControl/FrmMain.cs index a764d9b..a4a1e57 100644 --- a/AdvertsingProfitControl/FrmMain.cs +++ b/AdvertsingProfitControl/FrmMain.cs @@ -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(); diff --git a/AdvertsingProfitControl/NewAddRecord.Designer.cs b/AdvertsingProfitControl/NewAddRecord.Designer.cs index c143974..f924d85 100644 --- a/AdvertsingProfitControl/NewAddRecord.Designer.cs +++ b/AdvertsingProfitControl/NewAddRecord.Designer.cs @@ -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); } diff --git a/AdvertsingProfitControl/NewAddRecord.cs b/AdvertsingProfitControl/NewAddRecord.cs index 3e84263..a6f7e58 100644 --- a/AdvertsingProfitControl/NewAddRecord.cs +++ b/AdvertsingProfitControl/NewAddRecord.cs @@ -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) { diff --git a/AdvertsingProfitControl/NewAddRecord.resx b/AdvertsingProfitControl/NewAddRecord.resx index ad2c550..ed00b2b 100644 --- a/AdvertsingProfitControl/NewAddRecord.resx +++ b/AdvertsingProfitControl/NewAddRecord.resx @@ -120,6 +120,9 @@ 17, 17 + + 17, 17 + diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application index 1019250..b8f543b 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application @@ -14,7 +14,7 @@ - OlX6CvX02QUSDXImEM6f2HKdWzzRripa5ZZRa0lenPo= + xZQf4lyG78NuQ0APSprGJE7TfHmXY3q7EniNsorWnAI= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest index d1b8c33..f1270d4 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest @@ -43,14 +43,14 @@ - + - 4TfzARAAxdb/PYNmotwSF5x29OfcgoIH9QiACmt25T0= + pwX2HuLuQjN0X0mlI91r2H59iOeuMyMgp+zObWw85r0=