Added support for color coding the DataGridViews' header cells based on row state (saved, pending edit, row error) and finished writing the last database writer function for cost analysis.

This commit is contained in:
2016-12-04 01:27:25 -06:00
parent 6813bbb341
commit d8c753f788
11 changed files with 770 additions and 562 deletions
Binary file not shown.
@@ -289,6 +289,7 @@ namespace AdvertsingProfitControl
InvoiceNote = 6, InvoiceNote = 6,
IsDirty = 7 IsDirty = 7
} }
/// <summary> /// <summary>
/// TODO: Push into a stand alone object. /// TODO: Push into a stand alone object.
/// </summary> /// </summary>
@@ -106,6 +106,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="AdItemCollectionModel.cs" /> <Compile Include="AdItemCollectionModel.cs" />
<Compile Include="AdvertisingProfitControlTableHelper.cs" /> <Compile Include="AdvertisingProfitControlTableHelper.cs" />
<Compile Include="ApplicationColors.cs" />
<Compile Include="DbWriterStatus.cs" /> <Compile Include="DbWriterStatus.cs" />
<Compile Include="TextFormat.cs" /> <Compile Include="TextFormat.cs" />
<Compile Include="APCDatabaseWriter.cs" /> <Compile Include="APCDatabaseWriter.cs" />
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdvertsingProfitControl
{
/// <summary>
/// Defines the colors to be used for the rows on the DataGridViews based on their state.
/// </summary>
public static class ApplicationColors
{
public static Color EditingSaved = Color.ForestGreen;
public static Color PendingEdit = Color.Yellow;
public static Color RowError = Color.Red;
public static Color HeaderRow = Color.LightGray;
public static Color MemberRow = Color.LightBlue;
}
}
+120 -17
View File
@@ -532,21 +532,15 @@ namespace AdvertsingProfitControl
{ {
Connection = oleDbConnection Connection = oleDbConnection
}; };
OleDbTransaction oleDbTransaction = null;
try try
{ {
oleDbConnection.Open(); oleDbConnection.Open();
oleDbTransaction = oleDbConnection.BeginTransaction();
oleDbCommand.Transaction = oleDbTransaction;
if (id == 0) if (id == 0)
{ {
oleDbCommand.CommandText = "INSERT INTO Comment (Comment, FK_DateID) VALUES (?, ?)"; oleDbCommand.CommandText = "INSERT INTO Comment (Comment, FK_DateID) VALUES (?, ?)";
oleDbCommand.Parameters.AddWithValue("Comment", comments); oleDbCommand.Parameters.AddWithValue("Comment", comments);
oleDbCommand.Parameters.AddWithValue("DateID", dateId); oleDbCommand.Parameters.AddWithValue("DateID", dateId);
oleDbCommand.ExecuteNonQuery(); oleDbCommand.ExecuteNonQuery();
//If the execute non query didn't throw an exception then we're good to go.
oleDbTransaction.Commit();
//Now grab the ID number of the comment that was just added. //Now grab the ID number of the comment that was just added.
oleDbCommand.CommandText = "SELECT ID FROM Comment WHERE FK_DateID = ?"; oleDbCommand.CommandText = "SELECT ID FROM Comment WHERE FK_DateID = ?";
oleDbCommand.Parameters.Clear(); oleDbCommand.Parameters.Clear();
@@ -564,8 +558,6 @@ namespace AdvertsingProfitControl
oleDbCommand.Parameters.AddWithValue("Comment", comments); oleDbCommand.Parameters.AddWithValue("Comment", comments);
oleDbCommand.Parameters.AddWithValue("ID", id); oleDbCommand.Parameters.AddWithValue("ID", id);
oleDbCommand.ExecuteNonQuery(); oleDbCommand.ExecuteNonQuery();
//If the execute non query didn't throw an exception then we're good to go.
oleDbTransaction.Commit();
} }
} }
catch (OleDbException e) catch (OleDbException e)
@@ -573,7 +565,6 @@ namespace AdvertsingProfitControl
status.SetStatus(WritingOperationStatus.Failed); status.SetStatus(WritingOperationStatus.Failed);
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the comment(s): " + e.Message); _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.SetErrorMessage("Failed to update or insert comments into the database.");
oleDbTransaction?.Rollback();
} }
finally finally
{ {
@@ -590,12 +581,9 @@ namespace AdvertsingProfitControl
{ {
Connection = oleDbConnection Connection = oleDbConnection
}; };
OleDbTransaction oleDbTransaction = null;
try try
{ {
oleDbConnection.Open(); oleDbConnection.Open();
oleDbTransaction = oleDbConnection.BeginTransaction();
oleDbCommand.Transaction = oleDbTransaction;
if (id == 0) if (id == 0)
{ {
@@ -610,8 +598,6 @@ namespace AdvertsingProfitControl
oleDbCommand.Parameters.AddWithValue("TotalSales", weeklySales[7]); oleDbCommand.Parameters.AddWithValue("TotalSales", weeklySales[7]);
oleDbCommand.Parameters.AddWithValue("DateID", dateId); oleDbCommand.Parameters.AddWithValue("DateID", dateId);
oleDbCommand.ExecuteNonQuery(); oleDbCommand.ExecuteNonQuery();
//If the execute non query didn't throw an exception then we're good to go.
oleDbTransaction.Commit();
//Now grab the ID number of the comment that was just added. //Now grab the ID number of the comment that was just added.
oleDbCommand.CommandText = "SELECT ID FROM WeeklySales WHERE FK_DateID = ?"; oleDbCommand.CommandText = "SELECT ID FROM WeeklySales WHERE FK_DateID = ?";
oleDbCommand.Parameters.Clear(); oleDbCommand.Parameters.Clear();
@@ -636,8 +622,6 @@ namespace AdvertsingProfitControl
oleDbCommand.Parameters.AddWithValue("TotalSales", weeklySales[7]); oleDbCommand.Parameters.AddWithValue("TotalSales", weeklySales[7]);
oleDbCommand.Parameters.AddWithValue("ID", id); oleDbCommand.Parameters.AddWithValue("ID", id);
oleDbCommand.ExecuteNonQuery(); oleDbCommand.ExecuteNonQuery();
//If the execute non query didn't throw an exception then we're good to go.
oleDbTransaction.Commit();
} }
} }
catch (OleDbException e) catch (OleDbException e)
@@ -645,7 +629,126 @@ namespace AdvertsingProfitControl
status.SetStatus(WritingOperationStatus.Failed); status.SetStatus(WritingOperationStatus.Failed);
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the weekly sales: " + e.Message); _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.SetErrorMessage("Failed to update or insert weekly sales into the database.");
oleDbTransaction?.Rollback(); }
finally
{
oleDbConnection.Close();
}
return status;
}
public DbWriterStatus ProcessTaxable(double[] taxable, int dateId, string connectionString, int id = 0)
{
var status = new DbWriterStatus();
var oleDbConnection = new OleDbConnection(connectionString);
var oleDbCommand = new OleDbCommand
{
Connection = oleDbConnection
};
try
{
oleDbConnection.Open();
if (id == 0)
{
oleDbCommand.CommandText = "INSERT INTO Taxable (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Total, FK_DateID) VALUES (?,?,?,?,?,?,?,?,?)";
oleDbCommand.Parameters.AddWithValue("Sunday", taxable[0]);
oleDbCommand.Parameters.AddWithValue("Monday", taxable[1]);
oleDbCommand.Parameters.AddWithValue("Tuesday", taxable[2]);
oleDbCommand.Parameters.AddWithValue("Wednesday", taxable[3]);
oleDbCommand.Parameters.AddWithValue("Thursday", taxable[4]);
oleDbCommand.Parameters.AddWithValue("Friday", taxable[5]);
oleDbCommand.Parameters.AddWithValue("Saturday", taxable[6]);
oleDbCommand.Parameters.AddWithValue("TotalSales", taxable[7]);
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.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()));
}
}
else
{
oleDbCommand.CommandText = "UPDATE Taxable SET Sunday = ?, Monday = ?, Tuesday = ?, Wednesday = ?, Thursday = ?, Friday = ?, Saturday = ?, Total = ? WHERE ID = ?";
oleDbCommand.Parameters.AddWithValue("Sunday", taxable[0]);
oleDbCommand.Parameters.AddWithValue("Monday", taxable[1]);
oleDbCommand.Parameters.AddWithValue("Tuesday", taxable[2]);
oleDbCommand.Parameters.AddWithValue("Wednesday", taxable[3]);
oleDbCommand.Parameters.AddWithValue("Thursday", taxable[4]);
oleDbCommand.Parameters.AddWithValue("Friday", taxable[5]);
oleDbCommand.Parameters.AddWithValue("Saturday", taxable[6]);
oleDbCommand.Parameters.AddWithValue("TotalSales", taxable[7]);
oleDbCommand.Parameters.AddWithValue("ID", id);
oleDbCommand.ExecuteNonQuery();
}
}
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.");
}
finally
{
oleDbConnection.Close();
}
return status;
}
public DbWriterStatus ProcessCostAnalysis(double[] costAnalysis, int dateId, string connectionString, int id = 0)
{
var status = new DbWriterStatus();
var oleDbConnection = new OleDbConnection(connectionString);
var oleDbCommand = new OleDbCommand
{
Connection = oleDbConnection
};
try
{
oleDbConnection.Open();
if (id == 0)
{
oleDbCommand.CommandText = "INSERT INTO CostOfSalesAnalysis (SalesPerManHour, SalaryPercentage, SalaryDollars, Supplies, FK_dateID) VALUES (?,?,?,?,?)";
oleDbCommand.Parameters.AddWithValue("SalesPerManHour", costAnalysis[0]);
oleDbCommand.Parameters.AddWithValue("SalaryPercentage", costAnalysis[1]);
oleDbCommand.Parameters.AddWithValue("SalaryDollars", costAnalysis[2]);
oleDbCommand.Parameters.AddWithValue("Supplies", costAnalysis[3]);
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.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()));
}
}
else
{
oleDbCommand.CommandText = "UPDATE CostOfSalesAnalysis SET SalesPerManHour = ?, SalaryPercentage = ?, SalaryDollars = ?, Supplies = ? WHERE ID = ?";
oleDbCommand.Parameters.AddWithValue("SalesPerManHour", costAnalysis[0]);
oleDbCommand.Parameters.AddWithValue("SalaryPercentage", costAnalysis[1]);
oleDbCommand.Parameters.AddWithValue("SalaryDollars", costAnalysis[2]);
oleDbCommand.Parameters.AddWithValue("Supplies", costAnalysis[3]);
oleDbCommand.Parameters.AddWithValue("ID", id);
oleDbCommand.ExecuteNonQuery();
}
}
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.");
} }
finally finally
{ {
+3 -3
View File
@@ -30,11 +30,11 @@ namespace AdvertsingProfitControl
/// Adds a row to the Rows Dictionary that keeps track of what rows have been /// Adds a row to the Rows Dictionary that keeps track of what rows have been
/// added to the database including their IDs. /// added to the database including their IDs.
/// </summary> /// </summary>
/// <param name="key">The index of the row that was added to the database.</param> /// <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> /// <param name="rowIdNumber">The ID number of the row as represented in the database.</param>
public void AddRowId(int key, int rowIdNumber) public void AddRowId(int rowIndex, int rowIdNumber)
{ {
_rowIds.Add(key, rowIdNumber); _rowIds.Add(rowIndex, rowIdNumber);
} }
/// <summary> /// <summary>
/// Removes a row from the Rows collection. /// Removes a row from the Rows collection.
+136 -127
View File
@@ -41,8 +41,19 @@
this.invoicesTabPage = new System.Windows.Forms.TabPage(); this.invoicesTabPage = new System.Windows.Forms.TabPage();
this.invoicesDataGridView = new System.Windows.Forms.DataGridView(); this.invoicesDataGridView = new System.Windows.Forms.DataGridView();
this.debugTabPage = new System.Windows.Forms.TabPage(); this.debugTabPage = new System.Windows.Forms.TabPage();
this.debugPanel = new System.Windows.Forms.Panel();
this.generateCostAnalysisIdButton = new System.Windows.Forms.Button();
this.generateTaxableIdButton = new System.Windows.Forms.Button();
this.generateWeeklySalesIdButton = new System.Windows.Forms.Button();
this.reminderLabel = new System.Windows.Forms.Label();
this.generateCommentIdButton = new System.Windows.Forms.Button();
this.isCostAnalysisDirtyCheckBox = new System.Windows.Forms.CheckBox();
this.isTaxableDirtyCheckBox = new System.Windows.Forms.CheckBox();
this.isWeeklySalesDirtyCheckBox = new System.Windows.Forms.CheckBox();
this.isCommentDirtyCheckBox = new System.Windows.Forms.CheckBox();
this.mainMenuStrip = new System.Windows.Forms.MenuStrip(); this.mainMenuStrip = new System.Windows.Forms.MenuStrip();
this.FileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.FileMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.clearFormFileMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.exitFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.exitFileMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.mainLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.mainLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.costAnalysisGroupBox = new System.Windows.Forms.GroupBox(); this.costAnalysisGroupBox = new System.Windows.Forms.GroupBox();
@@ -99,17 +110,6 @@
this.informationPanel = new System.Windows.Forms.Panel(); this.informationPanel = new System.Windows.Forms.Panel();
this.informationLabel = new System.Windows.Forms.Label(); this.informationLabel = new System.Windows.Forms.Label();
this.addRecordButton = new System.Windows.Forms.Button(); this.addRecordButton = new System.Windows.Forms.Button();
this.debugPanel = new System.Windows.Forms.Panel();
this.isCommentDirtyCheckBox = new System.Windows.Forms.CheckBox();
this.isWeeklySalesDirtyCheckBox = new System.Windows.Forms.CheckBox();
this.isTaxableDirtyCheckBox = new System.Windows.Forms.CheckBox();
this.isCostAnalysisDirtyCheckBox = new System.Windows.Forms.CheckBox();
this.clearFormFileMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.generateCommentIdButton = new System.Windows.Forms.Button();
this.reminderLabel = new System.Windows.Forms.Label();
this.generateWeeklySalesIdButton = new System.Windows.Forms.Button();
this.generateTaxableIdButton = new System.Windows.Forms.Button();
this.generateCostAnalysisIdButton = new System.Windows.Forms.Button();
this.commentsGroupBox.SuspendLayout(); this.commentsGroupBox.SuspendLayout();
this.mainTabControl.SuspendLayout(); this.mainTabControl.SuspendLayout();
this.projectionTabPage.SuspendLayout(); this.projectionTabPage.SuspendLayout();
@@ -121,6 +121,7 @@
this.invoicesTabPage.SuspendLayout(); this.invoicesTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.invoicesDataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.invoicesDataGridView)).BeginInit();
this.debugTabPage.SuspendLayout(); this.debugTabPage.SuspendLayout();
this.debugPanel.SuspendLayout();
this.mainMenuStrip.SuspendLayout(); this.mainMenuStrip.SuspendLayout();
this.mainLayoutPanel.SuspendLayout(); this.mainLayoutPanel.SuspendLayout();
this.costAnalysisGroupBox.SuspendLayout(); this.costAnalysisGroupBox.SuspendLayout();
@@ -130,11 +131,11 @@
this.dateGroupBox.SuspendLayout(); this.dateGroupBox.SuspendLayout();
this.dateTimeMaskedTextBoxPanel.SuspendLayout(); this.dateTimeMaskedTextBoxPanel.SuspendLayout();
this.informationPanel.SuspendLayout(); this.informationPanel.SuspendLayout();
this.debugPanel.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// commentsGroupBox // commentsGroupBox
// //
this.commentsGroupBox.BackColor = System.Drawing.SystemColors.Control;
this.commentsGroupBox.Controls.Add(this.commentsTextBox); this.commentsGroupBox.Controls.Add(this.commentsTextBox);
this.commentsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; this.commentsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.commentsGroupBox.Location = new System.Drawing.Point(473, 594); this.commentsGroupBox.Location = new System.Drawing.Point(473, 594);
@@ -192,10 +193,12 @@
this.projectionsDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; this.projectionsDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
this.projectionsDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.projectionsDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.projectionsDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.projectionsDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
this.projectionsDataGridView.EnableHeadersVisualStyles = false;
this.projectionsDataGridView.Location = new System.Drawing.Point(0, 0); this.projectionsDataGridView.Location = new System.Drawing.Point(0, 0);
this.projectionsDataGridView.Margin = new System.Windows.Forms.Padding(4); this.projectionsDataGridView.Margin = new System.Windows.Forms.Padding(4);
this.projectionsDataGridView.MultiSelect = false; this.projectionsDataGridView.MultiSelect = false;
this.projectionsDataGridView.Name = "projectionsDataGridView"; this.projectionsDataGridView.Name = "projectionsDataGridView";
this.projectionsDataGridView.RowHeadersWidth = 70;
this.projectionsDataGridView.RowTemplate.Height = 28; this.projectionsDataGridView.RowTemplate.Height = 28;
this.projectionsDataGridView.Size = new System.Drawing.Size(1860, 510); this.projectionsDataGridView.Size = new System.Drawing.Size(1860, 510);
this.projectionsDataGridView.TabIndex = 2; this.projectionsDataGridView.TabIndex = 2;
@@ -219,10 +222,12 @@
this.inventoryDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; this.inventoryDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
this.inventoryDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.inventoryDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.inventoryDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.inventoryDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
this.inventoryDataGridView.EnableHeadersVisualStyles = false;
this.inventoryDataGridView.Location = new System.Drawing.Point(0, 0); this.inventoryDataGridView.Location = new System.Drawing.Point(0, 0);
this.inventoryDataGridView.Margin = new System.Windows.Forms.Padding(4); this.inventoryDataGridView.Margin = new System.Windows.Forms.Padding(4);
this.inventoryDataGridView.MultiSelect = false; this.inventoryDataGridView.MultiSelect = false;
this.inventoryDataGridView.Name = "inventoryDataGridView"; this.inventoryDataGridView.Name = "inventoryDataGridView";
this.inventoryDataGridView.RowHeadersWidth = 70;
this.inventoryDataGridView.RowTemplate.Height = 28; this.inventoryDataGridView.RowTemplate.Height = 28;
this.inventoryDataGridView.Size = new System.Drawing.Size(1860, 510); this.inventoryDataGridView.Size = new System.Drawing.Size(1860, 510);
this.inventoryDataGridView.TabIndex = 1; this.inventoryDataGridView.TabIndex = 1;
@@ -246,10 +251,12 @@
this.actualSalesDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; this.actualSalesDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
this.actualSalesDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.actualSalesDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.actualSalesDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.actualSalesDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
this.actualSalesDataGridView.EnableHeadersVisualStyles = false;
this.actualSalesDataGridView.Location = new System.Drawing.Point(0, 0); this.actualSalesDataGridView.Location = new System.Drawing.Point(0, 0);
this.actualSalesDataGridView.Margin = new System.Windows.Forms.Padding(4); this.actualSalesDataGridView.Margin = new System.Windows.Forms.Padding(4);
this.actualSalesDataGridView.MultiSelect = false; this.actualSalesDataGridView.MultiSelect = false;
this.actualSalesDataGridView.Name = "actualSalesDataGridView"; this.actualSalesDataGridView.Name = "actualSalesDataGridView";
this.actualSalesDataGridView.RowHeadersWidth = 70;
this.actualSalesDataGridView.RowTemplate.Height = 28; this.actualSalesDataGridView.RowTemplate.Height = 28;
this.actualSalesDataGridView.Size = new System.Drawing.Size(1860, 510); this.actualSalesDataGridView.Size = new System.Drawing.Size(1860, 510);
this.actualSalesDataGridView.TabIndex = 1; this.actualSalesDataGridView.TabIndex = 1;
@@ -273,10 +280,12 @@
this.invoicesDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; this.invoicesDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
this.invoicesDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.invoicesDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.invoicesDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.invoicesDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
this.invoicesDataGridView.EnableHeadersVisualStyles = false;
this.invoicesDataGridView.Location = new System.Drawing.Point(0, 0); this.invoicesDataGridView.Location = new System.Drawing.Point(0, 0);
this.invoicesDataGridView.Margin = new System.Windows.Forms.Padding(4); this.invoicesDataGridView.Margin = new System.Windows.Forms.Padding(4);
this.invoicesDataGridView.MultiSelect = false; this.invoicesDataGridView.MultiSelect = false;
this.invoicesDataGridView.Name = "invoicesDataGridView"; this.invoicesDataGridView.Name = "invoicesDataGridView";
this.invoicesDataGridView.RowHeadersWidth = 70;
this.invoicesDataGridView.RowTemplate.Height = 28; this.invoicesDataGridView.RowTemplate.Height = 28;
this.invoicesDataGridView.Size = new System.Drawing.Size(1860, 510); this.invoicesDataGridView.Size = new System.Drawing.Size(1860, 510);
this.invoicesDataGridView.TabIndex = 1; this.invoicesDataGridView.TabIndex = 1;
@@ -292,6 +301,112 @@
this.debugTabPage.Text = "DEBUG"; this.debugTabPage.Text = "DEBUG";
this.debugTabPage.UseVisualStyleBackColor = true; this.debugTabPage.UseVisualStyleBackColor = true;
// //
// debugPanel
//
this.debugPanel.Controls.Add(this.generateCostAnalysisIdButton);
this.debugPanel.Controls.Add(this.generateTaxableIdButton);
this.debugPanel.Controls.Add(this.generateWeeklySalesIdButton);
this.debugPanel.Controls.Add(this.reminderLabel);
this.debugPanel.Controls.Add(this.generateCommentIdButton);
this.debugPanel.Controls.Add(this.isCostAnalysisDirtyCheckBox);
this.debugPanel.Controls.Add(this.isTaxableDirtyCheckBox);
this.debugPanel.Controls.Add(this.isWeeklySalesDirtyCheckBox);
this.debugPanel.Controls.Add(this.isCommentDirtyCheckBox);
this.debugPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.debugPanel.Location = new System.Drawing.Point(3, 3);
this.debugPanel.Name = "debugPanel";
this.debugPanel.Size = new System.Drawing.Size(1854, 504);
this.debugPanel.TabIndex = 0;
//
// generateCostAnalysisIdButton
//
this.generateCostAnalysisIdButton.Location = new System.Drawing.Point(931, 283);
this.generateCostAnalysisIdButton.Name = "generateCostAnalysisIdButton";
this.generateCostAnalysisIdButton.Size = new System.Drawing.Size(299, 62);
this.generateCostAnalysisIdButton.TabIndex = 8;
this.generateCostAnalysisIdButton.Text = "Create / Clear Cost Analysis ID";
this.generateCostAnalysisIdButton.UseVisualStyleBackColor = true;
this.generateCostAnalysisIdButton.Click += new System.EventHandler(this.generateCostAnalysisIdButton_Click);
//
// generateTaxableIdButton
//
this.generateTaxableIdButton.Location = new System.Drawing.Point(638, 283);
this.generateTaxableIdButton.Name = "generateTaxableIdButton";
this.generateTaxableIdButton.Size = new System.Drawing.Size(286, 62);
this.generateTaxableIdButton.TabIndex = 7;
this.generateTaxableIdButton.Text = "Create / Clear Taxable ID";
this.generateTaxableIdButton.UseVisualStyleBackColor = true;
this.generateTaxableIdButton.Click += new System.EventHandler(this.generateTaxableIdButton_Click);
//
// generateWeeklySalesIdButton
//
this.generateWeeklySalesIdButton.Location = new System.Drawing.Point(346, 283);
this.generateWeeklySalesIdButton.Name = "generateWeeklySalesIdButton";
this.generateWeeklySalesIdButton.Size = new System.Drawing.Size(286, 62);
this.generateWeeklySalesIdButton.TabIndex = 6;
this.generateWeeklySalesIdButton.Text = "Create / Clear Weekly Sales ID";
this.generateWeeklySalesIdButton.UseVisualStyleBackColor = true;
this.generateWeeklySalesIdButton.Click += new System.EventHandler(this.generateWeeklySalesIdButton_Click);
//
// reminderLabel
//
this.reminderLabel.AutoSize = true;
this.reminderLabel.Location = new System.Drawing.Point(82, 94);
this.reminderLabel.Name = "reminderLabel";
this.reminderLabel.Size = new System.Drawing.Size(659, 25);
this.reminderLabel.TabIndex = 5;
this.reminderLabel.Text = "These checkboxes Tag properties hold the ID for their respective elements.";
//
// generateCommentIdButton
//
this.generateCommentIdButton.Location = new System.Drawing.Point(54, 283);
this.generateCommentIdButton.Name = "generateCommentIdButton";
this.generateCommentIdButton.Size = new System.Drawing.Size(286, 62);
this.generateCommentIdButton.TabIndex = 4;
this.generateCommentIdButton.Text = "Create / Clear Comments ID";
this.generateCommentIdButton.UseVisualStyleBackColor = true;
this.generateCommentIdButton.Click += new System.EventHandler(this.idButton_Click);
//
// isCostAnalysisDirtyCheckBox
//
this.isCostAnalysisDirtyCheckBox.AutoSize = true;
this.isCostAnalysisDirtyCheckBox.Location = new System.Drawing.Point(87, 227);
this.isCostAnalysisDirtyCheckBox.Name = "isCostAnalysisDirtyCheckBox";
this.isCostAnalysisDirtyCheckBox.Size = new System.Drawing.Size(207, 29);
this.isCostAnalysisDirtyCheckBox.TabIndex = 3;
this.isCostAnalysisDirtyCheckBox.Text = "IsCostAnalysisDirty";
this.isCostAnalysisDirtyCheckBox.UseVisualStyleBackColor = true;
//
// isTaxableDirtyCheckBox
//
this.isTaxableDirtyCheckBox.AutoSize = true;
this.isTaxableDirtyCheckBox.Location = new System.Drawing.Point(87, 192);
this.isTaxableDirtyCheckBox.Name = "isTaxableDirtyCheckBox";
this.isTaxableDirtyCheckBox.Size = new System.Drawing.Size(163, 29);
this.isTaxableDirtyCheckBox.TabIndex = 2;
this.isTaxableDirtyCheckBox.Text = "IsTaxableDirty";
this.isTaxableDirtyCheckBox.UseVisualStyleBackColor = true;
//
// isWeeklySalesDirtyCheckBox
//
this.isWeeklySalesDirtyCheckBox.AutoSize = true;
this.isWeeklySalesDirtyCheckBox.Location = new System.Drawing.Point(87, 157);
this.isWeeklySalesDirtyCheckBox.Name = "isWeeklySalesDirtyCheckBox";
this.isWeeklySalesDirtyCheckBox.Size = new System.Drawing.Size(208, 29);
this.isWeeklySalesDirtyCheckBox.TabIndex = 1;
this.isWeeklySalesDirtyCheckBox.Text = "IsWeeklySalesDirty";
this.isWeeklySalesDirtyCheckBox.UseVisualStyleBackColor = true;
//
// isCommentDirtyCheckBox
//
this.isCommentDirtyCheckBox.AutoSize = true;
this.isCommentDirtyCheckBox.Location = new System.Drawing.Point(87, 122);
this.isCommentDirtyCheckBox.Name = "isCommentDirtyCheckBox";
this.isCommentDirtyCheckBox.Size = new System.Drawing.Size(177, 29);
this.isCommentDirtyCheckBox.TabIndex = 0;
this.isCommentDirtyCheckBox.Text = "IsCommentDirty";
this.isCommentDirtyCheckBox.UseVisualStyleBackColor = true;
//
// mainMenuStrip // mainMenuStrip
// //
this.mainLayoutPanel.SetColumnSpan(this.mainMenuStrip, 4); this.mainLayoutPanel.SetColumnSpan(this.mainMenuStrip, 4);
@@ -314,10 +429,16 @@
this.FileMainMenu.Size = new System.Drawing.Size(56, 31); this.FileMainMenu.Size = new System.Drawing.Size(56, 31);
this.FileMainMenu.Text = "&File"; this.FileMainMenu.Text = "&File";
// //
// clearFormFileMainMenu
//
this.clearFormFileMainMenu.Name = "clearFormFileMainMenu";
this.clearFormFileMainMenu.Size = new System.Drawing.Size(205, 34);
this.clearFormFileMainMenu.Text = "&Clear Form";
//
// exitFileMainMenu // exitFileMainMenu
// //
this.exitFileMainMenu.Name = "exitFileMainMenu"; this.exitFileMainMenu.Name = "exitFileMainMenu";
this.exitFileMainMenu.Size = new System.Drawing.Size(240, 34); this.exitFileMainMenu.Size = new System.Drawing.Size(205, 34);
this.exitFileMainMenu.Text = "E&xit"; this.exitFileMainMenu.Text = "E&xit";
// //
// mainLayoutPanel // mainLayoutPanel
@@ -858,118 +979,6 @@
this.addRecordButton.UseVisualStyleBackColor = true; this.addRecordButton.UseVisualStyleBackColor = true;
this.addRecordButton.Click += new System.EventHandler(this.AddRecordsButtonClick); this.addRecordButton.Click += new System.EventHandler(this.AddRecordsButtonClick);
// //
// debugPanel
//
this.debugPanel.Controls.Add(this.generateCostAnalysisIdButton);
this.debugPanel.Controls.Add(this.generateTaxableIdButton);
this.debugPanel.Controls.Add(this.generateWeeklySalesIdButton);
this.debugPanel.Controls.Add(this.reminderLabel);
this.debugPanel.Controls.Add(this.generateCommentIdButton);
this.debugPanel.Controls.Add(this.isCostAnalysisDirtyCheckBox);
this.debugPanel.Controls.Add(this.isTaxableDirtyCheckBox);
this.debugPanel.Controls.Add(this.isWeeklySalesDirtyCheckBox);
this.debugPanel.Controls.Add(this.isCommentDirtyCheckBox);
this.debugPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.debugPanel.Location = new System.Drawing.Point(3, 3);
this.debugPanel.Name = "debugPanel";
this.debugPanel.Size = new System.Drawing.Size(1854, 504);
this.debugPanel.TabIndex = 0;
//
// isCommentDirtyCheckBox
//
this.isCommentDirtyCheckBox.AutoSize = true;
this.isCommentDirtyCheckBox.Location = new System.Drawing.Point(87, 122);
this.isCommentDirtyCheckBox.Name = "isCommentDirtyCheckBox";
this.isCommentDirtyCheckBox.Size = new System.Drawing.Size(177, 29);
this.isCommentDirtyCheckBox.TabIndex = 0;
this.isCommentDirtyCheckBox.Text = "IsCommentDirty";
this.isCommentDirtyCheckBox.UseVisualStyleBackColor = true;
//
// isWeeklySalesDirtyCheckBox
//
this.isWeeklySalesDirtyCheckBox.AutoSize = true;
this.isWeeklySalesDirtyCheckBox.Location = new System.Drawing.Point(87, 157);
this.isWeeklySalesDirtyCheckBox.Name = "isWeeklySalesDirtyCheckBox";
this.isWeeklySalesDirtyCheckBox.Size = new System.Drawing.Size(208, 29);
this.isWeeklySalesDirtyCheckBox.TabIndex = 1;
this.isWeeklySalesDirtyCheckBox.Text = "IsWeeklySalesDirty";
this.isWeeklySalesDirtyCheckBox.UseVisualStyleBackColor = true;
//
// isTaxableDirtyCheckBox
//
this.isTaxableDirtyCheckBox.AutoSize = true;
this.isTaxableDirtyCheckBox.Location = new System.Drawing.Point(87, 192);
this.isTaxableDirtyCheckBox.Name = "isTaxableDirtyCheckBox";
this.isTaxableDirtyCheckBox.Size = new System.Drawing.Size(163, 29);
this.isTaxableDirtyCheckBox.TabIndex = 2;
this.isTaxableDirtyCheckBox.Text = "IsTaxableDirty";
this.isTaxableDirtyCheckBox.UseVisualStyleBackColor = true;
//
// isCostAnalysisDirtyCheckBox
//
this.isCostAnalysisDirtyCheckBox.AutoSize = true;
this.isCostAnalysisDirtyCheckBox.Location = new System.Drawing.Point(87, 227);
this.isCostAnalysisDirtyCheckBox.Name = "isCostAnalysisDirtyCheckBox";
this.isCostAnalysisDirtyCheckBox.Size = new System.Drawing.Size(207, 29);
this.isCostAnalysisDirtyCheckBox.TabIndex = 3;
this.isCostAnalysisDirtyCheckBox.Text = "IsCostAnalysisDirty";
this.isCostAnalysisDirtyCheckBox.UseVisualStyleBackColor = true;
//
// clearFormFileMainMenu
//
this.clearFormFileMainMenu.Name = "clearFormFileMainMenu";
this.clearFormFileMainMenu.Size = new System.Drawing.Size(240, 34);
this.clearFormFileMainMenu.Text = "&Clear Form";
//
// generateCommentIdButton
//
this.generateCommentIdButton.Location = new System.Drawing.Point(54, 283);
this.generateCommentIdButton.Name = "generateCommentIdButton";
this.generateCommentIdButton.Size = new System.Drawing.Size(286, 62);
this.generateCommentIdButton.TabIndex = 4;
this.generateCommentIdButton.Text = "Create / Clear Comments ID";
this.generateCommentIdButton.UseVisualStyleBackColor = true;
this.generateCommentIdButton.Click += new System.EventHandler(this.idButton_Click);
//
// reminderLabel
//
this.reminderLabel.AutoSize = true;
this.reminderLabel.Location = new System.Drawing.Point(82, 94);
this.reminderLabel.Name = "reminderLabel";
this.reminderLabel.Size = new System.Drawing.Size(659, 25);
this.reminderLabel.TabIndex = 5;
this.reminderLabel.Text = "These checkboxes Tag properties hold the ID for their respective elements.";
//
// generateWeeklySalesIdButton
//
this.generateWeeklySalesIdButton.Location = new System.Drawing.Point(346, 283);
this.generateWeeklySalesIdButton.Name = "generateWeeklySalesIdButton";
this.generateWeeklySalesIdButton.Size = new System.Drawing.Size(286, 62);
this.generateWeeklySalesIdButton.TabIndex = 6;
this.generateWeeklySalesIdButton.Text = "Create / Clear Weekly Sales ID";
this.generateWeeklySalesIdButton.UseVisualStyleBackColor = true;
this.generateWeeklySalesIdButton.Click += new System.EventHandler(this.generateWeeklySalesIdButton_Click);
//
// generateTaxableIdButton
//
this.generateTaxableIdButton.Location = new System.Drawing.Point(638, 283);
this.generateTaxableIdButton.Name = "generateTaxableIdButton";
this.generateTaxableIdButton.Size = new System.Drawing.Size(286, 62);
this.generateTaxableIdButton.TabIndex = 7;
this.generateTaxableIdButton.Text = "Create / Clear Taxable ID";
this.generateTaxableIdButton.UseVisualStyleBackColor = true;
this.generateTaxableIdButton.Click += new System.EventHandler(this.generateTaxableIdButton_Click);
//
// generateCostAnalysisIdButton
//
this.generateCostAnalysisIdButton.Location = new System.Drawing.Point(931, 283);
this.generateCostAnalysisIdButton.Name = "generateCostAnalysisIdButton";
this.generateCostAnalysisIdButton.Size = new System.Drawing.Size(299, 62);
this.generateCostAnalysisIdButton.TabIndex = 8;
this.generateCostAnalysisIdButton.Text = "Create / Clear Cost Analysis ID";
this.generateCostAnalysisIdButton.UseVisualStyleBackColor = true;
this.generateCostAnalysisIdButton.Click += new System.EventHandler(this.generateCostAnalysisIdButton_Click);
//
// NewAddRecord // NewAddRecord
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F);
@@ -995,6 +1004,8 @@
this.invoicesTabPage.ResumeLayout(false); this.invoicesTabPage.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.invoicesDataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.invoicesDataGridView)).EndInit();
this.debugTabPage.ResumeLayout(false); this.debugTabPage.ResumeLayout(false);
this.debugPanel.ResumeLayout(false);
this.debugPanel.PerformLayout();
this.mainMenuStrip.ResumeLayout(false); this.mainMenuStrip.ResumeLayout(false);
this.mainMenuStrip.PerformLayout(); this.mainMenuStrip.PerformLayout();
this.mainLayoutPanel.ResumeLayout(false); this.mainLayoutPanel.ResumeLayout(false);
@@ -1012,8 +1023,6 @@
this.dateTimeMaskedTextBoxPanel.PerformLayout(); this.dateTimeMaskedTextBoxPanel.PerformLayout();
this.informationPanel.ResumeLayout(false); this.informationPanel.ResumeLayout(false);
this.informationPanel.PerformLayout(); this.informationPanel.PerformLayout();
this.debugPanel.ResumeLayout(false);
this.debugPanel.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
+300 -224
View File
@@ -100,6 +100,7 @@ namespace AdvertsingProfitControl
ConstructInvoicesDataGridView();//No weekly sales table is nice. ConstructInvoicesDataGridView();//No weekly sales table is nice.
//Subscribe the comments text box to check if changes have been made on leave. //Subscribe the comments text box to check if changes have been made on leave.
commentsTextBox.Enter += StoreBeginningTextBoxValue; commentsTextBox.Enter += StoreBeginningTextBoxValue;
commentsTextBox.KeyDown += CheckForKeyCommand;
commentsTextBox.Leave += CheckForTextChangeOnLeave; commentsTextBox.Leave += CheckForTextChangeOnLeave;
//Subscribe the weekly sales text boxes to validation, update required checks and auto-complete methods. //Subscribe the weekly sales text boxes to validation, update required checks and auto-complete methods.
sundayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue; sundayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
@@ -146,182 +147,6 @@ namespace AdvertsingProfitControl
suppliesTextBox.Validating += ValidateCostAnalysisValues; suppliesTextBox.Validating += ValidateCostAnalysisValues;
} }
private void ValidateCostAnalysisValues(object sender, CancelEventArgs e)
{
var textBox = (TextBox) sender;
if (_beginningCellValue == textBox.Text) return;
//There was a change to the starting value of the text box if we've made it this far.
if (textBox.Text != "")
{
double value;
if (double.TryParse(textBox.Text.Trim(), out value))
{
//Input is valid so mark the section as dirty.
isCostAnalysisDirtyCheckBox.Checked = true;
//And apply formatting.
textBox.Text = Math.Round(value, 2).ToString("N", new CultureInfo("en-US"));
//Check to see if the number is equal to zero (0) i.e. "0.00".
if (textBox.Text == @"0.00") textBox.Text = "";
}
else
{
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = "";
}
}
else
{
//Since the text box that fired this event is empty check to see if this group has been committed to the database.
if (isCostAnalysisDirtyCheckBox.Tag == null)
{
//Since it hasn't check to see if the other text boxes are empty.
var isDirty = salesPerManHourTextBox.Text.Trim() == "";
if (isDirty)
{
isCostAnalysisDirtyCheckBox.Checked = false;
return;
}
isDirty = salaryPercentageTextBox.Text.Trim() == "";
if (isDirty)
{
isCostAnalysisDirtyCheckBox.Checked = false;
return;
}
isDirty = salaryDollarsTextBox.Text.Trim() == "";
if (isDirty)
{
isCostAnalysisDirtyCheckBox.Checked = false;
return;
}
isDirty = suppliesTextBox.Text.Trim() == "";
if (isDirty)
{
isCostAnalysisDirtyCheckBox.Checked = false;
}
}
else if (isCostAnalysisDirtyCheckBox.Tag != null && textBox.Text == "")
{
//If the user has already added the fields to the database but has removed a value
//update that accordingly.
isCostAnalysisDirtyCheckBox.Checked = true;
}
}
}
private void ValidateTaxableFields(object sender, CancelEventArgs e)
{
var textBox = (TextBox)sender;
if (_beginningCellValue == textBox.Text) return;
//There was a change to the starting value of the text box if we've made it this far.
if (textBox.Text != "")
{
double dollarValue;
if (double.TryParse(textBox.Text.Trim(), out dollarValue))
{
//Input is valid so mark the section as dirty.
isTaxableDirtyCheckBox.Checked = true;
//And apply formatting.
textBox.Text = Math.Round(dollarValue, 2).ToString("N", new CultureInfo("en-US"));
//Check to see if the number is equal to zero (0) i.e. "0.00".
if (textBox.Text == @"0.00") textBox.Text = "";
}
else
{
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = "";
}
}
//Update the total sales text box before returning.
var totalTaxable = 0.00;
if (sundayTaxableTextBox.Text != "") totalTaxable += double.Parse(sundayTaxableTextBox.Text);
if (mondayTaxableTextBox.Text != "") totalTaxable += double.Parse(mondayTaxableTextBox.Text);
if (tuesdayTaxableTextBox.Text != "") totalTaxable += double.Parse(tuesdayTaxableTextBox.Text);
if (wednesdayTaxableTextBox.Text != "") totalTaxable += double.Parse(wednesdayTaxableTextBox.Text);
if (thursdayTaxableTextBox.Text != "") totalTaxable += double.Parse(thursdayTaxableTextBox.Text);
if (fridayTaxableTextBox.Text != "") totalTaxable += double.Parse(fridayTaxableTextBox.Text);
if (saturdayTaxableTextBox.Text != "") totalTaxable += double.Parse(saturdayTaxableTextBox.Text);
if (Math.Abs(totalTaxable) > 0)
{
totalTaxableTextBox.Text = totalTaxable.ToString("N", new CultureInfo("en-US"));
}
else
{
//Check to see if the weekly sales have been added to the database.
if (isTaxableDirtyCheckBox.Tag == null)
{
//If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag.
isTaxableDirtyCheckBox.Checked = false;
}
else if (isTaxableDirtyCheckBox.Tag != null && textBox.Text == "")
{
//If the user has already added the fields to the database but has removed a value
//update that accordingly.
isTaxableDirtyCheckBox.Checked = true;
}
totalTaxableTextBox.Text = "";
}
}
private void StoreBeginningTextBoxValue(object sender, EventArgs e)
{
var textBox = (TextBox) sender;
_beginningCellValue = textBox.Text;
}
private void ValidateWeeklySales(object sender, CancelEventArgs e)
{
var textBox = (TextBox) sender;
if (_beginningCellValue == textBox.Text) return;
//There was a change to the starting value of the text box if we've made it this far.
if (textBox.Text != "")
{
double dollarValue;
if (double.TryParse(textBox.Text.Trim(), out dollarValue))
{
//Input is valid so mark the section as dirty.
isWeeklySalesDirtyCheckBox.Checked = true;
//And apply formatting.
textBox.Text = Math.Round(dollarValue, 2).ToString("N", new CultureInfo("en-US"));
//Check to see if the number is equal to zero (0) i.e. "0.00".
if (textBox.Text == @"0.00") textBox.Text = "";
}
else
{
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = "";
}
}
//Update the total sales text box before returning.
var totalWeeklySales = 0.00;
if (sundayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(sundayWeeklySalesTextBox.Text);
if (mondayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(mondayWeeklySalesTextBox.Text);
if (tuesdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(tuesdayWeeklySalesTextBox.Text);
if (wednesdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(wednesdayWeeklySalesTextBox.Text);
if (thursdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(thursdayWeeklySalesTextBox.Text);
if (fridayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(fridayWeeklySalesTextBox.Text);
if (saturdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(saturdayWeeklySalesTextBox.Text);
if (Math.Abs(totalWeeklySales) > 0)
{
totalWeeklySalesTextBox.Text = totalWeeklySales.ToString("N", new CultureInfo("en-US"));
}
else
{
//Check to see if the weekly sales have been added to the database.
if (isWeeklySalesDirtyCheckBox.Tag == null)
{
//If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag.
isWeeklySalesDirtyCheckBox.Checked = false;
}
else if(isWeeklySalesDirtyCheckBox.Tag != null && textBox.Text == "")
{
//If the user has already added the fields to the database but has removed a value
//update that accordingly.
isWeeklySalesDirtyCheckBox.Checked = true;
}
totalWeeklySalesTextBox.Text = "";
}
}
#region Invoice Table Events #region Invoice Table Events
/// <summary> /// <summary>
@@ -330,7 +155,7 @@ namespace AdvertsingProfitControl
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ValidateInvoiceRow(object sender, DataGridViewCellCancelEventArgs e) private static void ValidateInvoiceRow(object sender, DataGridViewCellCancelEventArgs e)
{ {
var dataGridView = (DataGridView) sender; var dataGridView = (DataGridView) sender;
if (dataGridView.Rows[e.RowIndex].IsNewRow) return; if (dataGridView.Rows[e.RowIndex].IsNewRow) return;
@@ -338,6 +163,7 @@ namespace AdvertsingProfitControl
//Check to make sure the Invoice Date, Invoice Number and the Supplier values are set. //Check to make sure the Invoice Date, Invoice Number and the Supplier values are set.
if (dataGridView.Rows[e.RowIndex].Cells[(int) InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString() == "" || !DateTime.TryParse(dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString(), out dateTime)) if (dataGridView.Rows[e.RowIndex].Cells[(int) InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString() == "" || !DateTime.TryParse(dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString(), out dateTime))
{ {
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"An invoice date must be specified.", @"Invalid Invoice Date", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(@"An invoice date must be specified.", @"Invalid Invoice Date", MessageBoxButtons.OK, MessageBoxIcon.Error);
e.Cancel = true; e.Cancel = true;
dataGridView.CurrentCell = dataGridView.Rows[e.RowIndex].Cells[(int) InvoiceTableColumns.InvoiceDate]; dataGridView.CurrentCell = dataGridView.Rows[e.RowIndex].Cells[(int) InvoiceTableColumns.InvoiceDate];
@@ -346,15 +172,20 @@ namespace AdvertsingProfitControl
if (dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue.ToString() == "") if (dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue.ToString() == "")
{ {
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"A supplier must be specified.", @"Invalid Supplier", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(@"A supplier must be specified.", @"Invalid Supplier", MessageBoxButtons.OK, MessageBoxIcon.Error);
e.Cancel = true; e.Cancel = true;
dataGridView.CurrentCell = dataGridView.Rows[e.RowIndex].Cells[(int) InvoiceTableColumns.Supplier]; dataGridView.CurrentCell = dataGridView.Rows[e.RowIndex].Cells[(int) InvoiceTableColumns.Supplier];
return; return;
} }
if (dataGridView.Rows[e.RowIndex].Cells[(int) InvoiceTableColumns.InvoiceNumber].EditedFormattedValue.ToString() == "") if (
dataGridView.Rows[e.RowIndex].Cells[(int) InvoiceTableColumns.InvoiceNumber].EditedFormattedValue
.ToString() == "")
{ {
MessageBox.Show(@"An invoice number must be specified.", @"Invalid Invoice Number", MessageBoxButtons.OK, MessageBoxIcon.Error); dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"An invoice number must be specified.", @"Invalid Invoice Number", MessageBoxButtons.OK,
MessageBoxIcon.Error);
dataGridView.CurrentCell = dataGridView.Rows[e.RowIndex].Cells[(int) InvoiceTableColumns.InvoiceNumber]; dataGridView.CurrentCell = dataGridView.Rows[e.RowIndex].Cells[(int) InvoiceTableColumns.InvoiceNumber];
e.Cancel = true; e.Cancel = true;
} }
@@ -399,6 +230,7 @@ namespace AdvertsingProfitControl
if (DateTime.TryParse(userInput, out date)) if (DateTime.TryParse(userInput, out date))
{ {
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = date.ToString("MM/dd/yyyy"); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = date.ToString("MM/dd/yyyy");
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
} }
else else
{ {
@@ -422,6 +254,7 @@ namespace AdvertsingProfitControl
if (long.TryParse(userInput, out parsedNumber)) if (long.TryParse(userInput, out parsedNumber))
{ {
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = parsedNumber; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = parsedNumber;
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
} }
else else
{ {
@@ -444,6 +277,7 @@ namespace AdvertsingProfitControl
//TODO: Create a custom engine to do this. //TODO: Create a custom engine to do this.
//Pretty up the entered text since there is something here. //Pretty up the entered text since there is something here.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = textInfo.ToTitleCase(userInput); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = textInfo.ToTitleCase(userInput);
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
} }
else else
{ {
@@ -453,6 +287,7 @@ namespace AdvertsingProfitControl
break; break;
case (int)InvoiceTableColumns.InvoiceNote: case (int)InvoiceTableColumns.InvoiceNote:
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = userInput; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = userInput;
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
break; break;
default: default:
//Should only process the InvoiceNetAmountAtCost and InvoiceNetAmount columns. //Should only process the InvoiceNetAmountAtCost and InvoiceNetAmount columns.
@@ -469,7 +304,7 @@ namespace AdvertsingProfitControl
{ {
//Since the input is a number format it to show the cents and display it. //Since the input is a number format it to show the cents and display it.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US")); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US"));
//dataGridView.RefreshEdit(); dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
} }
else else
{ {
@@ -824,6 +659,8 @@ namespace AdvertsingProfitControl
else if (userInput != _beginningCellValue) else if (userInput != _beginningCellValue)
{ {
dataGridView.Rows[e.RowIndex].Cells[(int)SalesTableColumns.IsDirty].Value = true; dataGridView.Rows[e.RowIndex].Cells[(int)SalesTableColumns.IsDirty].Value = true;
//Set the coloring for the header cell.
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
} }
double parsedNumber; double parsedNumber;
//Check to see if the current column is the ad item column. //Check to see if the current column is the ad item column.
@@ -842,6 +679,7 @@ namespace AdvertsingProfitControl
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "";
//Send the ad item text through the formatting engine and assign the new value to the cell. //Send the ad item text through the formatting engine and assign the new value to the cell.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = TextFormat.FormatAdItemText(userInput); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = TextFormat.FormatAdItemText(userInput);
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
//Force a refresh so the cell's text updates and displays for the user. //Force a refresh so the cell's text updates and displays for the user.
dataGridView.RefreshEdit(); dataGridView.RefreshEdit();
return; return;
@@ -859,6 +697,7 @@ namespace AdvertsingProfitControl
{ {
//IF a match has been found, then make sure the word 'bin(s)' is capitalized to keep things looking pretty. //IF a match has been found, then make sure the word 'bin(s)' is capitalized to keep things looking pretty.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = textInfo.ToTitleCase(userInput); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = textInfo.ToTitleCase(userInput);
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
dataGridView.RefreshEdit(); dataGridView.RefreshEdit();
return; return;
} }
@@ -867,6 +706,7 @@ namespace AdvertsingProfitControl
{ {
//Add the formatted value to the cell. //Add the formatted value to the cell.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US")); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US"));
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
} }
else else
{ {
@@ -875,9 +715,9 @@ namespace AdvertsingProfitControl
return; return;
} }
MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected"); MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected");
e.Cancel = true;
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "";
dataGridView.RefreshEdit(); dataGridView.RefreshEdit();
e.Cancel = true;
return; return;
} }
break; break;
@@ -897,6 +737,7 @@ namespace AdvertsingProfitControl
//Format the last number as Currency, and round it up if necessary. //Format the last number as Currency, and round it up if necessary.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value =
$@"{stringArray[0]}/{Math.Round(decimal.Parse(stringArray[1]), 2):C}"; $@"{stringArray[0]}/{Math.Round(decimal.Parse(stringArray[1]), 2):C}";
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
//Always refresh edit so the new value shows up to the user. //Always refresh edit so the new value shows up to the user.
dataGridView.RefreshEdit(); dataGridView.RefreshEdit();
return; //And return, there is no need to go further. return; //And return, there is no need to go further.
@@ -905,6 +746,7 @@ namespace AdvertsingProfitControl
if (double.TryParse(userInput, out parsedNumber)) if (double.TryParse(userInput, out parsedNumber))
{ {
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US")); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US"));
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
} }
else else
{ {
@@ -913,9 +755,9 @@ namespace AdvertsingProfitControl
return; return;
} }
MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected"); MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected");
e.Cancel = true;
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "";
dataGridView.RefreshEdit(); dataGridView.RefreshEdit();
e.Cancel = true;
return; return;
} }
break; break;
@@ -926,6 +768,7 @@ namespace AdvertsingProfitControl
if (double.TryParse(userInput, out parsedNumber)) if (double.TryParse(userInput, out parsedNumber))
{ {
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US")); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US"));
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
} }
else else
{ {
@@ -934,9 +777,9 @@ namespace AdvertsingProfitControl
return; return;
} }
MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected"); MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected");
e.Cancel = true;
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "";
dataGridView.RefreshEdit(); dataGridView.RefreshEdit();
e.Cancel = true;
return; return;
} }
break; break;
@@ -969,6 +812,7 @@ namespace AdvertsingProfitControl
//Clear all whitespace and check for a null value in the ad item column. //Clear all whitespace and check for a null value in the ad item column.
if (Regex.Replace(projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", "") == "") if (Regex.Replace(projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", "") == "")
{ {
projectionsDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified"); MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified");
projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true; projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true;
e.Cancel = true; e.Cancel = true;
@@ -978,9 +822,6 @@ namespace AdvertsingProfitControl
{ {
return; return;
} }
//Now check to make sure there is an ad item present, otherwise throw an error and block the user from leaving the current row.
if (projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != "")
{
//Next check to see if the user changed the ad item is the corresponding row. //Next check to see if the user changed the ad item is the corresponding row.
if (projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString()) if (projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString())
{ {
@@ -1074,13 +915,9 @@ namespace AdvertsingProfitControl
} }
} }
inventoryDataGridView.Rows.Add(inventoryNewRow); inventoryDataGridView.Rows.Add(inventoryNewRow);
} //Set the row headers of the other tables to show up as pending; this row is valid without a doubt.
else inventoryDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
{ actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
MessageBox.Show(@"An Ad Item is required.", @"Invalid Ad Item");
projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true;
e.Cancel = true;
}
} }
private void ProjectionRowRemoved(object sender, DataGridViewRowsRemovedEventArgs e) private void ProjectionRowRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
@@ -1236,6 +1073,7 @@ namespace AdvertsingProfitControl
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "";
//Send the ad item text through the formatting engine and assign the new value to the cell. //Send the ad item text through the formatting engine and assign the new value to the cell.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = TextFormat.FormatAdItemText(userInput); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = TextFormat.FormatAdItemText(userInput);
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
//Force a refresh so the cell's text updates and displays for the user. //Force a refresh so the cell's text updates and displays for the user.
dataGridView.RefreshEdit(); dataGridView.RefreshEdit();
return; return;
@@ -1255,23 +1093,27 @@ namespace AdvertsingProfitControl
{ {
//IF a match has been found, then make sure the word 'bin(s)' is capitalized to keep things looking pretty. //IF a match has been found, then make sure the word 'bin(s)' is capitalized to keep things looking pretty.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = textInfo.ToTitleCase(userInput); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = textInfo.ToTitleCase(userInput);
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
dataGridView.RefreshEdit(); dataGridView.RefreshEdit();
return; return;
} }
double parsedNumber; double parsedNumber;
//Try parsing the text entered as a number and if that fails then break out and clear the value entered. //Try parsing the text entered as a number and if that fails then break out and clear the value entered.
if (userInput != "" && !double.TryParse(userInput, out parsedNumber)) if (userInput != "" && double.TryParse(userInput, out parsedNumber))
{ {
MessageBox.Show(
@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.",
@"Invalid Characters Detected");
e.Cancel = true;
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "";
dataGridView.RefreshEdit();
return;
}
//Add the value to the cell. //Add the value to the cell.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = userInput; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = userInput;
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
return;
}
//Prevent the user from being bombarded by message boxes. All validation has been completed at this point so there's nothing to worry about.
if (userInput != "")
{
MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected");
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "";
dataGridView.RefreshEdit();
e.Cancel = true;
}
break; break;
} }
//Always refresh edit so the new value shows up to the user. //Always refresh edit so the new value shows up to the user.
@@ -1298,6 +1140,7 @@ namespace AdvertsingProfitControl
//Clear all whitespace and check for a null value in the ad item column. //Clear all whitespace and check for a null value in the ad item column.
if (Regex.Replace(inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", "") == "") if (Regex.Replace(inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", "") == "")
{ {
inventoryDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified"); MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified");
inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true; inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true;
e.Cancel = true; e.Cancel = true;
@@ -1307,9 +1150,6 @@ namespace AdvertsingProfitControl
{ {
return; return;
} }
//Now check to make sure there is an ad item present, otherwise throw an error and block the user from leaving the current row.
if (inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != "")
{
//Next check to see if the user changed the ad item is the corresponding row. //Next check to see if the user changed the ad item is the corresponding row.
if (inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString()) if (inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString())
{ {
@@ -1356,13 +1196,9 @@ namespace AdvertsingProfitControl
} }
projectionsDataGridView.Rows.Add(rowContents); projectionsDataGridView.Rows.Add(rowContents);
actualSalesDataGridView.Rows.Add(rowContents); actualSalesDataGridView.Rows.Add(rowContents);
} //Apply color coding to the respective row headers on the other tables.
else projectionsDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
{ actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
MessageBox.Show(@"An Ad Item is required.", @"Invalid Ad Item");
inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true;
e.Cancel = true;
}
} }
private void InventoryRowRemoved(object sender, DataGridViewRowsRemovedEventArgs e) private void InventoryRowRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
@@ -1450,6 +1286,7 @@ namespace AdvertsingProfitControl
//Clear all whitespace and check for a null value in the ad item column. //Clear all whitespace and check for a null value in the ad item column.
if (Regex.Replace(actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", "") == "") if (Regex.Replace(actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", "") == "")
{ {
actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified"); MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified");
actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true; actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true;
e.Cancel = true; e.Cancel = true;
@@ -1459,9 +1296,6 @@ namespace AdvertsingProfitControl
{ {
return; return;
} }
//Now check to make sure there is an ad item present, otherwise throw an error and block the user from leaving the current row.
if (actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != "")
{
//Next check to see if the user changed the ad item is the corresponding row. //Next check to see if the user changed the ad item is the corresponding row.
if (actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString()) if (actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString() != projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString())
{ {
@@ -1534,13 +1368,9 @@ namespace AdvertsingProfitControl
} }
} }
inventoryDataGridView.Rows.Add(inventoryNewRow); inventoryDataGridView.Rows.Add(inventoryNewRow);
} //Apply color coding to the respective row headers on the other tables.
else projectionsDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
{ inventoryDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
MessageBox.Show(@"An Ad Item is required.", @"Invalid Ad Item");
actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].Selected = true;
e.Cancel = true;
}
} }
private void ActualSalesRowRemoved(object sender, DataGridViewRowsRemovedEventArgs e) private void ActualSalesRowRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
@@ -1755,7 +1585,32 @@ namespace AdvertsingProfitControl
#endregion #endregion
/// <summary>
/// Stores the beginning value in a text box into the _beginningCellValue field.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StoreBeginningTextBoxValue(object sender, EventArgs e)
{
var textBox = (TextBox) sender;
_beginningCellValue = textBox.Text;
}
#region Comments TextBox Events #region Comments TextBox Events
/// <summary>
/// Allows the user to select all the text in the comments text box.
/// TODO: Fix error chime when using CNTRL+A.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckForKeyCommand(object sender, KeyEventArgs e)
{
if (!e.Control || e.KeyCode != Keys.A) return;
commentsTextBox.SelectionStart = 0;
commentsTextBox.SelectionLength = commentsTextBox.Text.Length;
}
/// <summary> /// <summary>
/// Event Used: TextChanged /// Event Used: TextChanged
/// Calculates and displays the remaining number of characters available for the user to enter /// Calculates and displays the remaining number of characters available for the user to enter
@@ -1792,16 +1647,199 @@ namespace AdvertsingProfitControl
#region Weekly Sales Events #region Weekly Sales Events
/// <summary>
/// Validates the contents of the weekly sales text boxes and adds up the total.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ValidateWeeklySales(object sender, CancelEventArgs e)
{
var textBox = (TextBox)sender;
if (_beginningCellValue == textBox.Text) return;
//There was a change to the starting value of the text box if we've made it this far.
if (textBox.Text != "")
{
double dollarValue;
if (double.TryParse(textBox.Text.Trim(), out dollarValue))
{
//Input is valid so mark the section as dirty.
isWeeklySalesDirtyCheckBox.Checked = true;
//And apply formatting.
textBox.Text = Math.Round(dollarValue, 2).ToString("N", new CultureInfo("en-US"));
//Check to see if the number is equal to zero (0) i.e. "0.00".
if (textBox.Text == @"0.00") textBox.Text = "";
}
else
{
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = "";
}
}
//Update the total sales text box before returning.
var totalWeeklySales = 0.00;
if (sundayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(sundayWeeklySalesTextBox.Text);
if (mondayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(mondayWeeklySalesTextBox.Text);
if (tuesdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(tuesdayWeeklySalesTextBox.Text);
if (wednesdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(wednesdayWeeklySalesTextBox.Text);
if (thursdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(thursdayWeeklySalesTextBox.Text);
if (fridayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(fridayWeeklySalesTextBox.Text);
if (saturdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(saturdayWeeklySalesTextBox.Text);
if (Math.Abs(totalWeeklySales) > 0)
{
totalWeeklySalesTextBox.Text = totalWeeklySales.ToString("N", new CultureInfo("en-US"));
}
else
{
//Check to see if the weekly sales have been added to the database.
if (isWeeklySalesDirtyCheckBox.Tag == null)
{
//If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag.
isWeeklySalesDirtyCheckBox.Checked = false;
}
else if (isWeeklySalesDirtyCheckBox.Tag != null && textBox.Text == "")
{
//If the user has already added the fields to the database but has removed a value
//update that accordingly.
isWeeklySalesDirtyCheckBox.Checked = true;
}
totalWeeklySalesTextBox.Text = "";
}
}
#endregion #endregion
#region Taxable Events #region Taxable Events
/// <summary>
/// Validates the contents of the Taxable text boxes and adds up the total.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ValidateTaxableFields(object sender, CancelEventArgs e)
{
var textBox = (TextBox)sender;
if (_beginningCellValue == textBox.Text) return;
//There was a change to the starting value of the text box if we've made it this far.
if (textBox.Text != "")
{
double dollarValue;
if (double.TryParse(textBox.Text.Trim(), out dollarValue))
{
//Input is valid so mark the section as dirty.
isTaxableDirtyCheckBox.Checked = true;
//And apply formatting.
textBox.Text = Math.Round(dollarValue, 2).ToString("N", new CultureInfo("en-US"));
//Check to see if the number is equal to zero (0) i.e. "0.00".
if (textBox.Text == @"0.00") textBox.Text = "";
}
else
{
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = "";
}
}
//Update the total sales text box before returning.
var totalTaxable = 0.00;
if (sundayTaxableTextBox.Text != "") totalTaxable += double.Parse(sundayTaxableTextBox.Text);
if (mondayTaxableTextBox.Text != "") totalTaxable += double.Parse(mondayTaxableTextBox.Text);
if (tuesdayTaxableTextBox.Text != "") totalTaxable += double.Parse(tuesdayTaxableTextBox.Text);
if (wednesdayTaxableTextBox.Text != "") totalTaxable += double.Parse(wednesdayTaxableTextBox.Text);
if (thursdayTaxableTextBox.Text != "") totalTaxable += double.Parse(thursdayTaxableTextBox.Text);
if (fridayTaxableTextBox.Text != "") totalTaxable += double.Parse(fridayTaxableTextBox.Text);
if (saturdayTaxableTextBox.Text != "") totalTaxable += double.Parse(saturdayTaxableTextBox.Text);
if (Math.Abs(totalTaxable) > 0)
{
totalTaxableTextBox.Text = totalTaxable.ToString("N", new CultureInfo("en-US"));
}
else
{
//Check to see if the weekly sales have been added to the database.
if (isTaxableDirtyCheckBox.Tag == null)
{
//If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag.
isTaxableDirtyCheckBox.Checked = false;
}
else if (isTaxableDirtyCheckBox.Tag != null && textBox.Text == "")
{
//If the user has already added the fields to the database but has removed a value
//update that accordingly.
isTaxableDirtyCheckBox.Checked = true;
}
totalTaxableTextBox.Text = "";
}
}
#endregion #endregion
#region Cost Analysis Events #region Cost Analysis Events
/// <summary>
/// Validates the cost analysis text boxes.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ValidateCostAnalysisValues(object sender, CancelEventArgs e)
{
var textBox = (TextBox)sender;
if (_beginningCellValue == textBox.Text) return;
//There was a change to the starting value of the text box if we've made it this far.
if (textBox.Text != "")
{
double value;
if (double.TryParse(textBox.Text.Trim(), out value))
{
//Input is valid so mark the section as dirty.
isCostAnalysisDirtyCheckBox.Checked = true;
//And apply formatting.
textBox.Text = Math.Round(value, 2).ToString("N", new CultureInfo("en-US"));
//Check to see if the number is equal to zero (0) i.e. "0.00".
if (textBox.Text == @"0.00") textBox.Text = "";
}
else
{
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = "";
}
}
else
{
//Since the text box that fired this event is empty check to see if this group has been committed to the database.
if (isCostAnalysisDirtyCheckBox.Tag == null)
{
//Since it hasn't check to see if the other text boxes are empty.
var isDirty = salesPerManHourTextBox.Text.Trim() == "";
if (isDirty)
{
isCostAnalysisDirtyCheckBox.Checked = false;
return;
}
isDirty = salaryPercentageTextBox.Text.Trim() == "";
if (isDirty)
{
isCostAnalysisDirtyCheckBox.Checked = false;
return;
}
isDirty = salaryDollarsTextBox.Text.Trim() == "";
if (isDirty)
{
isCostAnalysisDirtyCheckBox.Checked = false;
return;
}
isDirty = suppliesTextBox.Text.Trim() == "";
if (isDirty)
{
isCostAnalysisDirtyCheckBox.Checked = false;
}
}
else if (isCostAnalysisDirtyCheckBox.Tag != null && textBox.Text == "")
{
//If the user has already added the fields to the database but has removed a value
//update that accordingly.
isCostAnalysisDirtyCheckBox.Checked = true;
}
}
}
#endregion #endregion
@@ -1982,11 +2020,44 @@ namespace AdvertsingProfitControl
if (!ProcessTrimmingStatusResult(actualSalesDataGridView, "ActualSales", operationStatus, trimmedTable, updateTable)) return; if (!ProcessTrimmingStatusResult(actualSalesDataGridView, "ActualSales", operationStatus, trimmedTable, updateTable)) return;
//Commit the Invoice table to the database. //Commit the Invoice table to the database.
var writerStatus = dbW.ProccessInvoiceTable(invoicesDataGridView, dateId, dbT.DatabaseConnectionString); var writerStatus = dbW.ProccessInvoiceTable(invoicesDataGridView, dateId, dbT.DatabaseConnectionString);
if (writerStatus.GetWritingOperationStatus() != WritingOperationStatus.Failed) if (writerStatus.GetWritingOperationStatus() == WritingOperationStatus.Failed)
{ {
errorLabel.Text = writerStatus.GetErrorMessage(); errorLabel.Text = writerStatus.GetErrorMessage();
} }
informationLabel.Text = @"All operations completed successfully.";
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)
{
errorLabel.Text = writerStatus.GetErrorMessage();
}
else
{
informationLabel.Text += @"Comment(s) processed successfully.";
var id = writerStatus.GetRowCollection();
}
}
else
{
informationLabel.Text += @"Updating Comment(s).";
writerStatus = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString, int.Parse(isCommentDirtyCheckBox.Tag.ToString()));
}
if (writerStatus.GetWritingOperationStatus() == WritingOperationStatus.Failed)
{
errorLabel.Text = writerStatus.GetErrorMessage();
}
else
{
informationLabel.Text += @"Comment(s) processed successfully.";
}
}
informationLabel.Text += @"All operations completed successfully.";
//Create the transaction scope. //Create the transaction scope.
//By default the TransactionScopeOption is "Required", so if an ambient transaction does not //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. //exist then the new transaction that is made (in the first method) becomes the root transaction.
@@ -2642,6 +2713,9 @@ namespace AdvertsingProfitControl
#endregion #endregion
#region Debug Operations
private void idButton_Click(object sender, EventArgs e) private void idButton_Click(object sender, EventArgs e)
{ {
if (isCommentDirtyCheckBox.Tag == null) if (isCommentDirtyCheckBox.Tag == null)
@@ -2701,5 +2775,7 @@ namespace AdvertsingProfitControl
MessageBox.Show(@"ID cleared from Cost Analysis.", @"Clear ID Debug"); MessageBox.Show(@"ID cleared from Cost Analysis.", @"Clear ID Debug");
} }
} }
#endregion
} }
} }
@@ -120,9 +120,6 @@
<metadata name="mainMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="mainMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </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" /> <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"> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
@@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms> </dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>sJa3N/qFPRThckha4aReaPFLpwQDio7tNBSSDURtnBk=</dsig:DigestValue> <dsig:DigestValue>OlX6CvX02QUSDXImEM6f2HKdWzzRripa5ZZRa0lenPo=</dsig:DigestValue>
</hash> </hash>
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
@@ -43,14 +43,14 @@
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
<dependency> <dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3538944"> <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3543552">
<assemblyIdentity name="AdvertsingProfitControl" version="0.9.5.2" language="neutral" processorArchitecture="amd64" /> <assemblyIdentity name="AdvertsingProfitControl" version="0.9.5.2" language="neutral" processorArchitecture="amd64" />
<hash> <hash>
<dsig:Transforms> <dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms> </dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>KJrIBRsbaX/71nFWLgdvuorK6BWoYWZ05mGNqVbM0Y0=</dsig:DigestValue> <dsig:DigestValue>4TfzARAAxdb/PYNmotwSF5x29OfcgoIH9QiACmt25T0=</dsig:DigestValue>
</hash> </hash>
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
@@ -84,7 +84,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms> </dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>dX2Dundhh4161Q3VUoRkM0RkUhpDPmRvgqyLNfiU3Nk=</dsig:DigestValue> <dsig:DigestValue>OTOg6k+3pem3uA+Xpy/Nu0Ifwo+hXeYq3hn83njXnT4=</dsig:DigestValue>
</hash> </hash>
</file> </file>
<file name="Stretched Logo Collection.ico" size="370070"> <file name="Stretched Logo Collection.ico" size="370070">