diff --git a/AdvertsingProfitControl/APCDatabase.accdb b/AdvertsingProfitControl/APCDatabase.accdb index 7a2529d..cc80a4f 100644 Binary files a/AdvertsingProfitControl/APCDatabase.accdb and b/AdvertsingProfitControl/APCDatabase.accdb differ diff --git a/AdvertsingProfitControl/DatabaseWriter.cs b/AdvertsingProfitControl/DatabaseWriter.cs index 4509b31..37d84d9 100644 --- a/AdvertsingProfitControl/DatabaseWriter.cs +++ b/AdvertsingProfitControl/DatabaseWriter.cs @@ -15,13 +15,6 @@ namespace AdvertsingProfitControl #region New Code - public OleDbCommand GetOleDbCommand(string connectionString) - { - var oleDbCommand = new OleDbCommand(); - - return oleDbCommand; - } - /// /// Inserts new records into the specified sales table. /// Supports rolling back the database to prevent corruption. @@ -31,7 +24,7 @@ namespace AdvertsingProfitControl /// A DbWriterStatus object that contains a status, rows added and an error message if necessary. public DbWriterStatus InsertIntoSalesTable(DataTable salesTable, string connectionString) { - var rowIndex = 0; + var lastRowProcessed = 0; var writerStatus = new DbWriterStatus(); var oleDbConnection = new OleDbConnection(connectionString); var oleDbCommand = new OleDbCommand @@ -65,7 +58,8 @@ namespace AdvertsingProfitControl oleDbCommand.Parameters.AddWithValue("dateID", salesTable.Rows[i][10]); oleDbCommand.ExecuteNonQuery(); oleDbCommand.Parameters.Clear(); - rowIndex++; + //Row index is only used to keep track of what row failed to update. + lastRowProcessed = int.Parse(salesTable.Rows[i][9].ToString()) - 1; } oleDbTransaction.Commit(); foreach (DataRow row in salesTable.Rows) @@ -92,7 +86,7 @@ namespace AdvertsingProfitControl { writerStatus.SetStatus(WritingOperationStatus.Failed); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to write to database: " + ex.Message); - if (rowIndex <= 0) + if (lastRowProcessed <= 0) { _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to begin parsing data rows, var dump of erroneous row unavailable."); @@ -101,25 +95,25 @@ namespace AdvertsingProfitControl else { _logConsole.WriteToLog(FrmLogConsole.Level.Error, - "Failed on row " + (rowIndex + 1) + " due to the above error. Dumping contents of row " + (rowIndex + 1) + " from " + salesTable.TableName + "."); + "Failed on row " + (lastRowProcessed + 1) + " due to the above error. Dumping contents of row " + (lastRowProcessed + 1) + " from " + salesTable.TableName + "."); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Ad Item ID: \"" + - salesTable.Rows[rowIndex][6] + "\" Sold: \"" + salesTable.Rows[rowIndex][0] + "\""); + salesTable.Rows[lastRowProcessed][6] + "\" Sold: \"" + salesTable.Rows[lastRowProcessed][0] + "\""); _logConsole.WriteToLog(FrmLogConsole.Level.Error, - "Sale Price: \"" + salesTable.Rows[rowIndex][1] + "\" Total Sales: \"" + salesTable.Rows[rowIndex][2] + "\""); + "Sale Price: \"" + salesTable.Rows[lastRowProcessed][1] + "\" Total Sales: \"" + salesTable.Rows[lastRowProcessed][2] + "\""); _logConsole.WriteToLog(FrmLogConsole.Level.Error, - "Cost: \"" + salesTable.Rows[rowIndex][3] + "\" Profit Return: \"" + salesTable.Rows[rowIndex][4] + "\""); + "Cost: \"" + salesTable.Rows[lastRowProcessed][3] + "\" Profit Return: \"" + salesTable.Rows[lastRowProcessed][4] + "\""); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Total Profit Return: \"" + - salesTable.Rows[rowIndex][5] + "\" Ad Special Group: \"" + salesTable.Rows[rowIndex][8] + "\""); - writerStatus.SetErrorMessage("Failed to write to the database on row " + (rowIndex + 1) + "."); + salesTable.Rows[lastRowProcessed][5] + "\" Ad Special Group: \"" + salesTable.Rows[lastRowProcessed][8] + "\""); + writerStatus.SetErrorMessage("Failed to write to the database on row " + (lastRowProcessed + 1) + "."); } oleDbTransaction?.Rollback(); _logConsole.WriteToLog(FrmLogConsole.Level.Critical, "Rollback completed successfully, " + salesTable.TableName+ " table failed on insertion."); } finally { - _oleDbConnection.Close(); + oleDbConnection.Close(); } return writerStatus; } @@ -134,7 +128,7 @@ namespace AdvertsingProfitControl public DbWriterStatus UpdateSalesTable(DataTable salesTable, string connectionString) { var updateStatus = new DbWriterStatus(); - var rowIndex = 0; + var lastRowProccessed = 0; var oleDbConnection = new OleDbConnection(connectionString); var oleDbCommand = new OleDbCommand { @@ -142,9 +136,9 @@ namespace AdvertsingProfitControl }; OleDbTransaction oleDbTransaction = null; try - { + { + oleDbConnection.Open(); oleDbTransaction = oleDbConnection.BeginTransaction(); - _oleDbConnection.Open(); oleDbCommand.Transaction = oleDbTransaction; for (var i = 0; i < salesTable.Rows.Count; i++) { @@ -168,16 +162,33 @@ namespace AdvertsingProfitControl oleDbCommand.ExecuteNonQuery(); oleDbCommand.Parameters.Clear(); //Row index is only used to keep track of what row failed to update. - rowIndex++; + lastRowProccessed = int.Parse(salesTable.Rows[i][10].ToString()) - 1; } oleDbTransaction.Commit(); + foreach (DataRow row in salesTable.Rows) + { + if (int.Parse(row[9].ToString()) != 0) + { + //Account for the ad special row. + //Index 10 of the row indicates that this row is an ad special member row + //so we must add one to the row position to offset the fact that a row + //is "missing" from this DataTable. + //Row[10] is its row position, which is not zero index based. + updateStatus.AddRowId(int.Parse(row[10].ToString()) + 1, int.Parse(row[0].ToString())); + } + else + { + //The ad special row doesn't exist so no need to offset it. + updateStatus.AddRowId(int.Parse(row[10].ToString()), int.Parse(row[0].ToString())); + } + } updateStatus.SetStatus(WritingOperationStatus.UpdateSuccessful); } catch (OleDbException ex) { updateStatus.SetStatus(WritingOperationStatus.Failed); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to update the database for " + salesTable.TableName + ": " + ex.Message); - if (rowIndex <= 0) + if (lastRowProccessed <= 0) { _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to begin parsing data rows, var dump of erroneous row unavailable."); @@ -186,25 +197,25 @@ namespace AdvertsingProfitControl else { _logConsole.WriteToLog(FrmLogConsole.Level.Error, - "Failed on row " + (rowIndex + 1) + " due to the above error. Dumping contents of row " + (rowIndex + 1) + " from " + salesTable.TableName + "."); + "Failed on row " + (lastRowProccessed + 1) + " due to the above error. Dumping contents of row " + (lastRowProccessed + 1) + " from " + salesTable.TableName + "."); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Ad Item ID: \"" + - salesTable.Rows[rowIndex][7] + "\" Sold: \"" + salesTable.Rows[rowIndex][1] + "\""); + salesTable.Rows[lastRowProccessed][7] + "\" Sold: \"" + salesTable.Rows[lastRowProccessed][1] + "\""); _logConsole.WriteToLog(FrmLogConsole.Level.Error, - "Sale Price: \"" + salesTable.Rows[rowIndex][2] + "\" Total Sales: \"" + salesTable.Rows[rowIndex][3] + "\""); + "Sale Price: \"" + salesTable.Rows[lastRowProccessed][2] + "\" Total Sales: \"" + salesTable.Rows[lastRowProccessed][3] + "\""); _logConsole.WriteToLog(FrmLogConsole.Level.Error, - "Cost: \"" + salesTable.Rows[rowIndex][4] + "\" Profit Return: \"" + salesTable.Rows[rowIndex][5] + "\""); + "Cost: \"" + salesTable.Rows[lastRowProccessed][4] + "\" Profit Return: \"" + salesTable.Rows[lastRowProccessed][5] + "\""); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Total Profit Return: \"" + - salesTable.Rows[rowIndex][6] + "\" Ad Special Group: \"" + salesTable.Rows[rowIndex][9] + "\""); - updateStatus.SetErrorMessage("Failed to write to the database on row " + (rowIndex + 1) + "."); + salesTable.Rows[lastRowProccessed][6] + "\" Ad Special Group: \"" + salesTable.Rows[lastRowProccessed][9] + "\""); + updateStatus.SetErrorMessage("Failed to write to the database on row " + (lastRowProccessed + 1) + "."); } oleDbTransaction?.Rollback(); _logConsole.WriteToLog(FrmLogConsole.Level.Critical, "Rollback completed successfully, " + salesTable.TableName + " table failed on update."); } finally { - _oleDbConnection.Close(); + oleDbConnection.Close(); } return updateStatus; @@ -219,7 +230,7 @@ namespace AdvertsingProfitControl public DbWriterStatus InsertIntoInventoryTable(DataTable table, string connectionString) { var status = new DbWriterStatus(); - var rowIndex = 0; + var lastRowProcessed = 0; var oleDbConnection = new OleDbConnection(connectionString); var oleDbCommand = new OleDbCommand { @@ -228,8 +239,8 @@ namespace AdvertsingProfitControl OleDbTransaction oleDbTransaction = null; try { + oleDbConnection.Open(); oleDbTransaction = oleDbConnection.BeginTransaction(); - _oleDbConnection.Open(); oleDbCommand.Transaction = oleDbTransaction; for (var i = 0; i < table.Rows.Count; i++) { @@ -250,7 +261,7 @@ namespace AdvertsingProfitControl oleDbCommand.ExecuteNonQuery(); oleDbCommand.Parameters.Clear(); //Row index is only used to keep track of what row failed to update. - rowIndex++; + lastRowProcessed = int.Parse(table.Rows[i][7].ToString()) - 1; } oleDbTransaction.Commit(); foreach (DataRow row in table.Rows) @@ -277,7 +288,7 @@ namespace AdvertsingProfitControl { status.SetStatus(WritingOperationStatus.Failed); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to update the database for " + table.TableName + ": " + e.Message); - if (rowIndex <= 0) + if (lastRowProcessed <= 0) { _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to begin parsing data rows, var dump of erroneous row unavailable."); @@ -285,19 +296,19 @@ namespace AdvertsingProfitControl } else { - _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed on row " + (rowIndex + 1) + " due to the above error. Dumping contents of row " + (rowIndex + 1) + " from " + table.TableName + "."); - _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Ad Item ID: \"" + table.Rows[rowIndex][4] + "\" Beginning Inventory: \"" + table.Rows[rowIndex][0]); - _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Received: \"" + table.Rows[rowIndex][1] + "\" Total Inventory: \"" + table.Rows[rowIndex][2] + "\" Ending Inventory: \"" + table.Rows[rowIndex][3] + "\""); - _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Row Attribute: \"" + table.Rows[rowIndex][5] + "\" Ad Special ID: \"" + table.Rows[rowIndex][7] + "\""); - _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Date ID: \"" + table.Rows[rowIndex][8] + "\""); - status.SetErrorMessage("Failed to write to the database on row " + (rowIndex + 1) + "."); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed on row " + (lastRowProcessed + 1) + " due to the above error. Dumping contents of row " + (lastRowProcessed + 1) + " from " + table.TableName + "."); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Ad Item ID: \"" + table.Rows[lastRowProcessed][4] + "\" Beginning Inventory: \"" + table.Rows[lastRowProcessed][0]); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Received: \"" + table.Rows[lastRowProcessed][1] + "\" Total Inventory: \"" + table.Rows[lastRowProcessed][2] + "\" Ending Inventory: \"" + table.Rows[lastRowProcessed][3] + "\""); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Row Attribute: \"" + table.Rows[lastRowProcessed][5] + "\" Ad Special ID: \"" + table.Rows[lastRowProcessed][7] + "\""); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Date ID: \"" + table.Rows[lastRowProcessed][8] + "\""); + status.SetErrorMessage("Failed to write to the database on row " + (lastRowProcessed + 1) + "."); } oleDbTransaction?.Rollback(); _logConsole.WriteToLog(FrmLogConsole.Level.Critical, "Rollback completed successfully, " + table.TableName + " table failed on update."); } finally { - _oleDbConnection.Close(); + oleDbConnection.Close(); } return status; @@ -312,7 +323,7 @@ namespace AdvertsingProfitControl public DbWriterStatus UpdateInventoryTable(DataTable table, string connectionString) { var status = new DbWriterStatus(); - var rowIndex = 0; + var lastRowProcessed = 0; var oleDbConnection = new OleDbConnection(connectionString); var oleDbCommand = new OleDbCommand { @@ -321,8 +332,8 @@ namespace AdvertsingProfitControl OleDbTransaction oleDbTransaction = null; try { + oleDbConnection.Open(); oleDbTransaction = oleDbConnection.BeginTransaction(); - _oleDbConnection.Open(); oleDbCommand.Transaction = oleDbTransaction; for (var i = 0; i < table.Rows.Count; i++) { @@ -342,16 +353,34 @@ namespace AdvertsingProfitControl oleDbCommand.ExecuteNonQuery(); oleDbCommand.Parameters.Clear(); //Row index is only used to keep track of what row failed to update. - rowIndex++; + lastRowProcessed = int.Parse(table.Rows[i][8].ToString()) - 1; } oleDbTransaction.Commit(); + foreach (DataRow row in table.Rows) + { + var rowId = RetrieveRowId(table.TableName, int.Parse(row[4].ToString()), int.Parse(row[8].ToString())); + if (int.Parse(row[7].ToString()) != 0) + { + //Account for the ad special row. + //Index 8 of the row indicates that this row is an ad special member row + //so we must add one to the row position to offset the fact that a row + //is "missing" from this DataTable. + //Row[8] is its row position, which is not zero index based. + status.AddRowId(int.Parse(row[8].ToString()) + 1, rowId); + } + else + { + //The ad special row doesn't exist so no need to offset it. + status.AddRowId(int.Parse(row[8].ToString()), rowId); + } + } status.SetStatus(WritingOperationStatus.InsertionSuccessful); } catch (OleDbException e) { status.SetStatus(WritingOperationStatus.Failed); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to update the database for " + table.TableName + ": " + e.Message); - if (rowIndex <= 0) + if (lastRowProcessed <= 0) { _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to begin parsing data rows, var dump of erroneous row unavailable."); @@ -359,19 +388,19 @@ namespace AdvertsingProfitControl } else { - _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed on row " + (rowIndex + 1) + " due to the above error. Dumping contents of row " + (rowIndex + 1) + " from " + table.TableName + "."); - _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Ad Item ID: \"" + table.Rows[rowIndex][4] + "\" Beginning Inventory: \"" + table.Rows[rowIndex][0]); - _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Received: \"" + table.Rows[rowIndex][1] + "\" Total Inventory: \"" + table.Rows[rowIndex][2] + "\" Ending Inventory: \"" + table.Rows[rowIndex][3] + "\""); - _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Row Attribute: \"" + table.Rows[rowIndex][5] + "\" Ad Special ID: \"" + table.Rows[rowIndex][7] + "\""); - _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Date ID: \"" + table.Rows[rowIndex][8] + "\""); - status.SetErrorMessage("Failed to write to the database on row " + (rowIndex + 1) + "."); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed on row " + (lastRowProcessed + 1) + " due to the above error. Dumping contents of row " + (lastRowProcessed + 1) + " from " + table.TableName + "."); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Ad Item ID: \"" + table.Rows[lastRowProcessed][4] + "\" Beginning Inventory: \"" + table.Rows[lastRowProcessed][0]); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Received: \"" + table.Rows[lastRowProcessed][1] + "\" Total Inventory: \"" + table.Rows[lastRowProcessed][2] + "\" Ending Inventory: \"" + table.Rows[lastRowProcessed][3] + "\""); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Row Attribute: \"" + table.Rows[lastRowProcessed][5] + "\" Ad Special ID: \"" + table.Rows[lastRowProcessed][7] + "\""); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Date ID: \"" + table.Rows[lastRowProcessed][8] + "\""); + status.SetErrorMessage("Failed to write to the database on row " + (lastRowProcessed + 1) + "."); } oleDbTransaction?.Rollback(); _logConsole.WriteToLog(FrmLogConsole.Level.Critical, "Rollback completed successfully, " + table.TableName + " table failed on update."); } finally { - _oleDbConnection.Close(); + oleDbConnection.Close(); } return status; diff --git a/AdvertsingProfitControl/DbWriterStatus.cs b/AdvertsingProfitControl/DbWriterStatus.cs index 0801a04..0471b88 100644 --- a/AdvertsingProfitControl/DbWriterStatus.cs +++ b/AdvertsingProfitControl/DbWriterStatus.cs @@ -58,7 +58,7 @@ namespace AdvertsingProfitControl /// The rows that have been added to the database. public Dictionary GetRowCollection() { - return _rowIds ?? new Dictionary(); + return _rowIds; } /// /// Sets an error message. diff --git a/AdvertsingProfitControl/NewAddRecord.Designer.cs b/AdvertsingProfitControl/NewAddRecord.Designer.cs index a0129d3..0bfd119 100644 --- a/AdvertsingProfitControl/NewAddRecord.Designer.cs +++ b/AdvertsingProfitControl/NewAddRecord.Designer.cs @@ -126,11 +126,11 @@ // this.commentsGroupBox.Controls.Add(this.commentsTextBox); this.commentsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.commentsGroupBox.Location = new System.Drawing.Point(423, 594); + this.commentsGroupBox.Location = new System.Drawing.Point(473, 594); this.commentsGroupBox.Margin = new System.Windows.Forms.Padding(4); this.commentsGroupBox.Name = "commentsGroupBox"; this.commentsGroupBox.Padding = new System.Windows.Forms.Padding(4); - this.commentsGroupBox.Size = new System.Drawing.Size(411, 223); + this.commentsGroupBox.Size = new System.Drawing.Size(461, 223); this.commentsGroupBox.TabIndex = 2; this.commentsGroupBox.TabStop = false; this.commentsGroupBox.Text = "Comments"; @@ -142,7 +142,7 @@ this.commentsTextBox.MaxLength = 256; this.commentsTextBox.Multiline = true; this.commentsTextBox.Name = "commentsTextBox"; - this.commentsTextBox.Size = new System.Drawing.Size(403, 193); + this.commentsTextBox.Size = new System.Drawing.Size(453, 193); this.commentsTextBox.TabIndex = 4; // // mainTabControl @@ -158,7 +158,7 @@ this.mainTabControl.Margin = new System.Windows.Forms.Padding(4); this.mainTabControl.Name = "mainTabControl"; this.mainTabControl.SelectedIndex = 0; - this.mainTabControl.Size = new System.Drawing.Size(1668, 547); + this.mainTabControl.Size = new System.Drawing.Size(1868, 547); this.mainTabControl.TabIndex = 1; this.mainTabControl.TabStop = false; // @@ -168,7 +168,7 @@ this.projectionTabPage.Location = new System.Drawing.Point(4, 33); this.projectionTabPage.Margin = new System.Windows.Forms.Padding(4); this.projectionTabPage.Name = "projectionTabPage"; - this.projectionTabPage.Size = new System.Drawing.Size(1660, 510); + this.projectionTabPage.Size = new System.Drawing.Size(1860, 510); this.projectionTabPage.TabIndex = 0; this.projectionTabPage.Text = "Projected Sales"; this.projectionTabPage.UseVisualStyleBackColor = true; @@ -186,7 +186,7 @@ this.projectionsDataGridView.MultiSelect = false; this.projectionsDataGridView.Name = "projectionsDataGridView"; this.projectionsDataGridView.RowTemplate.Height = 28; - this.projectionsDataGridView.Size = new System.Drawing.Size(1660, 510); + this.projectionsDataGridView.Size = new System.Drawing.Size(1860, 510); this.projectionsDataGridView.TabIndex = 2; // // inventoryTabPage @@ -195,7 +195,7 @@ this.inventoryTabPage.Location = new System.Drawing.Point(4, 33); this.inventoryTabPage.Margin = new System.Windows.Forms.Padding(4); this.inventoryTabPage.Name = "inventoryTabPage"; - this.inventoryTabPage.Size = new System.Drawing.Size(1660, 510); + this.inventoryTabPage.Size = new System.Drawing.Size(1860, 510); this.inventoryTabPage.TabIndex = 1; this.inventoryTabPage.Text = "Inventory"; this.inventoryTabPage.UseVisualStyleBackColor = true; @@ -213,7 +213,7 @@ this.inventoryDataGridView.MultiSelect = false; this.inventoryDataGridView.Name = "inventoryDataGridView"; this.inventoryDataGridView.RowTemplate.Height = 28; - this.inventoryDataGridView.Size = new System.Drawing.Size(1660, 510); + this.inventoryDataGridView.Size = new System.Drawing.Size(1860, 510); this.inventoryDataGridView.TabIndex = 1; // // actualSalesTabPage @@ -222,7 +222,7 @@ this.actualSalesTabPage.Location = new System.Drawing.Point(4, 33); this.actualSalesTabPage.Margin = new System.Windows.Forms.Padding(4); this.actualSalesTabPage.Name = "actualSalesTabPage"; - this.actualSalesTabPage.Size = new System.Drawing.Size(1660, 510); + this.actualSalesTabPage.Size = new System.Drawing.Size(1860, 510); this.actualSalesTabPage.TabIndex = 2; this.actualSalesTabPage.Text = "Actual Sales"; this.actualSalesTabPage.UseVisualStyleBackColor = true; @@ -240,7 +240,7 @@ this.actualSalesDataGridView.MultiSelect = false; this.actualSalesDataGridView.Name = "actualSalesDataGridView"; this.actualSalesDataGridView.RowTemplate.Height = 28; - this.actualSalesDataGridView.Size = new System.Drawing.Size(1660, 510); + this.actualSalesDataGridView.Size = new System.Drawing.Size(1860, 510); this.actualSalesDataGridView.TabIndex = 1; // // invoicesTabPage @@ -249,7 +249,7 @@ this.invoicesTabPage.Location = new System.Drawing.Point(4, 33); this.invoicesTabPage.Margin = new System.Windows.Forms.Padding(4); this.invoicesTabPage.Name = "invoicesTabPage"; - this.invoicesTabPage.Size = new System.Drawing.Size(1660, 510); + this.invoicesTabPage.Size = new System.Drawing.Size(1860, 510); this.invoicesTabPage.TabIndex = 3; this.invoicesTabPage.Text = "Invoices"; this.invoicesTabPage.UseVisualStyleBackColor = true; @@ -267,7 +267,7 @@ this.invoicesDataGridView.MultiSelect = false; this.invoicesDataGridView.Name = "invoicesDataGridView"; this.invoicesDataGridView.RowTemplate.Height = 28; - this.invoicesDataGridView.Size = new System.Drawing.Size(1660, 510); + this.invoicesDataGridView.Size = new System.Drawing.Size(1860, 510); this.invoicesDataGridView.TabIndex = 1; // // debugTabPage @@ -275,7 +275,7 @@ this.debugTabPage.Location = new System.Drawing.Point(4, 33); this.debugTabPage.Name = "debugTabPage"; this.debugTabPage.Padding = new System.Windows.Forms.Padding(3); - this.debugTabPage.Size = new System.Drawing.Size(1660, 510); + this.debugTabPage.Size = new System.Drawing.Size(1860, 510); this.debugTabPage.TabIndex = 4; this.debugTabPage.Text = "DEBUG"; this.debugTabPage.UseVisualStyleBackColor = true; @@ -290,7 +290,7 @@ this.mainMenuStrip.Location = new System.Drawing.Point(0, 0); this.mainMenuStrip.Name = "mainMenuStrip"; this.mainMenuStrip.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2); - this.mainMenuStrip.Size = new System.Drawing.Size(1676, 35); + this.mainMenuStrip.Size = new System.Drawing.Size(1876, 35); this.mainMenuStrip.TabIndex = 0; this.mainMenuStrip.Text = "menuStrip1"; // @@ -347,7 +347,7 @@ this.mainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 60F)); this.mainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); this.mainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 15F)); - this.mainLayoutPanel.Size = new System.Drawing.Size(1676, 961); + this.mainLayoutPanel.Size = new System.Drawing.Size(1876, 961); this.mainLayoutPanel.TabIndex = 0; // // costAnalysisGroupBox @@ -361,9 +361,9 @@ this.costAnalysisGroupBox.Controls.Add(this.salaryDollarsLabel); this.costAnalysisGroupBox.Controls.Add(this.suppliesLabel); this.costAnalysisGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.costAnalysisGroupBox.Location = new System.Drawing.Point(1260, 593); + this.costAnalysisGroupBox.Location = new System.Drawing.Point(1410, 593); this.costAnalysisGroupBox.Name = "costAnalysisGroupBox"; - this.costAnalysisGroupBox.Size = new System.Drawing.Size(413, 225); + this.costAnalysisGroupBox.Size = new System.Drawing.Size(463, 225); this.costAnalysisGroupBox.TabIndex = 6; this.costAnalysisGroupBox.TabStop = false; this.costAnalysisGroupBox.Text = "Cost Analysis"; @@ -437,14 +437,14 @@ this.tabControl1.Controls.Add(this.weeklySalesTabPage); this.tabControl1.Controls.Add(this.taxableTabPage); this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; - this.tabControl1.Location = new System.Drawing.Point(838, 590); + this.tabControl1.Location = new System.Drawing.Point(938, 590); this.tabControl1.Margin = new System.Windows.Forms.Padding(0); this.tabControl1.Multiline = true; this.tabControl1.Name = "tabControl1"; this.tabControl1.Padding = new System.Drawing.Point(0, 0); this.mainLayoutPanel.SetRowSpan(this.tabControl1, 2); this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(419, 371); + this.tabControl1.Size = new System.Drawing.Size(469, 371); this.tabControl1.TabIndex = 5; // // weeklySalesTabPage @@ -469,7 +469,7 @@ this.weeklySalesTabPage.Location = new System.Drawing.Point(4, 33); this.weeklySalesTabPage.Name = "weeklySalesTabPage"; this.weeklySalesTabPage.Padding = new System.Windows.Forms.Padding(3); - this.weeklySalesTabPage.Size = new System.Drawing.Size(411, 334); + this.weeklySalesTabPage.Size = new System.Drawing.Size(461, 334); this.weeklySalesTabPage.TabIndex = 0; this.weeklySalesTabPage.Text = "Weekly Sales"; // @@ -623,7 +623,7 @@ this.taxableTabPage.Location = new System.Drawing.Point(4, 33); this.taxableTabPage.Name = "taxableTabPage"; this.taxableTabPage.Padding = new System.Windows.Forms.Padding(3); - this.taxableTabPage.Size = new System.Drawing.Size(411, 334); + this.taxableTabPage.Size = new System.Drawing.Size(461, 334); this.taxableTabPage.TabIndex = 1; this.taxableTabPage.Text = "Taxable"; // @@ -763,10 +763,10 @@ this.dateGroupBox.Location = new System.Drawing.Point(3, 593); this.dateGroupBox.Name = "dateGroupBox"; this.mainLayoutPanel.SetRowSpan(this.dateGroupBox, 2); - this.dateGroupBox.Size = new System.Drawing.Size(413, 365); + this.dateGroupBox.Size = new System.Drawing.Size(463, 365); this.dateGroupBox.TabIndex = 24; this.dateGroupBox.TabStop = false; - this.dateGroupBox.Text = "Week Ending Date (MM/DD/YYYY)"; + this.dateGroupBox.Text = "Week Ending Date"; // // monthCalendarInstructionsLabel // @@ -796,9 +796,9 @@ this.dateTimeMaskedTextBoxPanel.Controls.Add(this.weekEndingMaskedTextBox); this.dateTimeMaskedTextBoxPanel.Controls.Add(this.weekEndingMaskedTextBoxInstructionLabel); this.dateTimeMaskedTextBoxPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.dateTimeMaskedTextBoxPanel.Location = new System.Drawing.Point(422, 824); + this.dateTimeMaskedTextBoxPanel.Location = new System.Drawing.Point(472, 824); this.dateTimeMaskedTextBoxPanel.Name = "dateTimeMaskedTextBoxPanel"; - this.dateTimeMaskedTextBoxPanel.Size = new System.Drawing.Size(413, 134); + this.dateTimeMaskedTextBoxPanel.Size = new System.Drawing.Size(463, 134); this.dateTimeMaskedTextBoxPanel.TabIndex = 1; // // errorLabel @@ -836,9 +836,9 @@ 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(1260, 824); + this.informationPanel.Location = new System.Drawing.Point(1410, 824); this.informationPanel.Name = "informationPanel"; - this.informationPanel.Size = new System.Drawing.Size(413, 134); + this.informationPanel.Size = new System.Drawing.Size(463, 134); this.informationPanel.TabIndex = 25; // // informationLabel @@ -853,7 +853,7 @@ // addRecordButton // this.addRecordButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.addRecordButton.Location = new System.Drawing.Point(237, 84); + this.addRecordButton.Location = new System.Drawing.Point(287, 84); this.addRecordButton.Name = "addRecordButton"; this.addRecordButton.Size = new System.Drawing.Size(167, 41); this.addRecordButton.TabIndex = 26; @@ -863,17 +863,14 @@ // // NewAddRecord // - this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.ClientSize = new System.Drawing.Size(1676, 961); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.ClientSize = new System.Drawing.Size(1876, 961); this.Controls.Add(this.mainLayoutPanel); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MainMenuStrip = this.mainMenuStrip; this.Margin = new System.Windows.Forms.Padding(4); - this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(1900, 1025); - this.MinimumSize = new System.Drawing.Size(1700, 1025); + this.MinimumSize = new System.Drawing.Size(1000, 1000); this.Name = "NewAddRecord"; this.Text = "Add New Record"; this.commentsGroupBox.ResumeLayout(false); diff --git a/AdvertsingProfitControl/NewAddRecord.cs b/AdvertsingProfitControl/NewAddRecord.cs index d6ea3bf..9285bd9 100644 --- a/AdvertsingProfitControl/NewAddRecord.cs +++ b/AdvertsingProfitControl/NewAddRecord.cs @@ -615,21 +615,34 @@ namespace AdvertsingProfitControl //Add overflow protection if (index < projectionsDataGridView.RowCount) { - projectionsDataGridView.Rows[index].Cells[(int) SalesTableColumns.IsDirty].Value = true; + if (!projectionsDataGridView.Rows[index].IsNewRow) + { + projectionsDataGridView.Rows[index].Cells[(int) SalesTableColumns.IsDirty].Value = true; + } } if (index < actualSalesDataGridView.RowCount) { - actualSalesDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = true; + if (!actualSalesDataGridView.Rows[index].IsNewRow) + { + actualSalesDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = true; + } } if (index < inventoryDataGridView.RowCount) { - inventoryDataGridView.Rows[index].Cells[(int)InventoryTableColumns.IsDirty].Value = true; + if (!inventoryDataGridView.Rows[index].IsNewRow) + { + inventoryDataGridView.Rows[index].Cells[(int)InventoryTableColumns.IsDirty].Value = true; + } } } } _usedAdItems[_adSpecialIndex == -1 || e.RowIndex < _adSpecialIndex ? 0 : 1].Remove(_beginningCellValue); dataGridView.Rows[e.RowIndex].Cells[(int) SalesTableColumns.IsDirty].Value = true; } + else if (userInput != _beginningCellValue) + { + dataGridView.Rows[e.RowIndex].Cells[(int)SalesTableColumns.IsDirty].Value = true; + } double parsedNumber; //Check to see if the current column is the ad item column. switch (e.ColumnIndex) @@ -1041,21 +1054,27 @@ namespace AdvertsingProfitControl dataGridView.RefreshEdit(); return; } - else + //Mark all ad special members as dirty since the user changed the ad special. + for (var index = _adSpecialIndex + 1; index < dataGridView.RowCount; index++) { - //Mark all ad special members as dirty since the user changed the ad special. - for (var index = _adSpecialIndex + 1; index < dataGridView.RowCount; index++) + //Add overflow protection + if (index < projectionsDataGridView.RowCount) { - //Add overflow protection - if (index < projectionsDataGridView.RowCount) + if (!projectionsDataGridView.Rows[index].IsNewRow) { projectionsDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = true; } - if (index < actualSalesDataGridView.RowCount) + } + if (index < actualSalesDataGridView.RowCount) + { + if (!actualSalesDataGridView.Rows[index].IsNewRow) { actualSalesDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = true; } - if (index < inventoryDataGridView.RowCount) + } + if (index < inventoryDataGridView.RowCount) + { + if (!inventoryDataGridView.Rows[index].IsNewRow) { inventoryDataGridView.Rows[index].Cells[(int)InventoryTableColumns.IsDirty].Value = true; } @@ -1065,6 +1084,10 @@ namespace AdvertsingProfitControl _usedAdItems[_adSpecialIndex == -1 || e.RowIndex < _adSpecialIndex ? 0 : 1].Remove(_beginningCellValue); dataGridView.Rows[e.RowIndex].Cells[(int) InventoryTableColumns.IsDirty].Value = true; } + else if (userInput != _beginningCellValue) + { + dataGridView.Rows[e.RowIndex].Cells[(int)InventoryTableColumns.IsDirty].Value = true; + } //Check to see if the current column is the ad item column. switch (e.ColumnIndex) { @@ -1838,27 +1861,70 @@ namespace AdvertsingProfitControl } //Run the row parsing engine on all the APC tables. //Create the cleaned table objects that will be sent to the database. - var trimmedTable = new DataTable(); - var updateTable = new DataTable(); - //var operationStatus = ConstructCleanedProjectionsTable(dateId, out trimmed, out update); - //operationStatus = ConstructCleanedInventoryTable(dateId); - //operationgStatus = ConstructCleanedActualSalesTable(dateId); + DataTable trimmedTable; + DataTable updateTable; + DbWriterStatus dbWriterStatus; + informationLabel.Text = @"Preparing data tables..."; + var operationStatus = ConstructCleanedSalesTable("Projections", dateId, out trimmedTable, out updateTable); + switch (operationStatus) + { + case TrimmingOperationResult.NoChangesRequired: + informationLabel.Text += Environment.NewLine + @"No changes for the Projections table detected."; + break; + case TrimmingOperationResult.CreatedNewInsertionTable: + informationLabel.Text += Environment.NewLine + @"New table created."; + dbWriterStatus = dbW.InsertIntoSalesTable(trimmedTable, dbT.DatabaseConnectionString); + //Spin through the collection and update the affected rows. + foreach (var rowIndex in dbWriterStatus.GetRowCollection()) + { + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.Id].Value = rowIndex.Value; + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false; + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsInDatabase].Value = true; + } + break; + case TrimmingOperationResult.CreatedUpdateTable: + informationLabel.Text += Environment.NewLine + @"Updates required."; + dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString); + //Spin through the collection and update the affected rows. + foreach (var rowIndex in dbWriterStatus.GetRowCollection()) + { + //Only reset the IsDirty value to false since the updates when through. + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false; + } + break; + case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables: + //Insert the new values... + dbWriterStatus = dbW.InsertIntoSalesTable(trimmedTable, dbT.DatabaseConnectionString); + //Spin through the collection and update the affected rows. + foreach (var rowIndex in dbWriterStatus.GetRowCollection()) + { + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.Id].Value = rowIndex.Value; + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false; + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsInDatabase].Value = true; + } + //... and update the existing values. + dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString); + //Spin through the collection and update the affected rows. + foreach (var rowIndex in dbWriterStatus.GetRowCollection()) + { + //Only reset the IsDirty value to false since the updates when through. + projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false; + } + break; + case TrimmingOperationResult.FailedToTrim: + errorLabel.Text = @"Failed to trim."; + informationLabel.Text = ""; + return; + } //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. //Transaction Scope: https://msdn.microsoft.com/en-us/library/ms172152.aspx - //var projectionsAdditions = dbW.InsertIntoSalesTable(trimmedTable, dbT.DatabaseConnectionString); - //foreach (var rowIndex in projectionsAdditions) - //{ - // projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.Id].Value = rowIndex.Value; - // projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false; - // projectionsDataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsInDatabase].Value = true; - //} } #region APC Table Trimming - private TrimmingOperationResult ConstructCleanedProjectionsTable(int dateId, out DataTable insertNewTable, out DataTable updateExistingTable) + private TrimmingOperationResult ConstructCleanedSalesTable(string tableName, int dateId, out DataTable insertNewTable, out DataTable updateExistingTable) { //Create two DataTables one for the new items to be added to the database //and one for items that have to be updated. @@ -1866,12 +1932,14 @@ namespace AdvertsingProfitControl //0:Sold 1:SalePrice 2:TotalSales 3:cost 4:ProfitReturn 5:TotalProfitReturn //6:FK_AdItemID 7:RowAttribute 8:FK_AdSpecialGroupName (ID) 9:RowPosition (not index based) //10:FK_DateID - insertNewTable = new DataTable("Projections"); + insertNewTable = new DataTable(tableName); //Update Sales Table Layout (Based on the Database's Physical Layout) //0:ID 1:Sold 2:SalePrice 3:TotalSales 4:cost 5:ProfitReturn 6:TotalProfitReturn //7:FK_AdItemID 8:RowAttribute 9:FK_AdSpecialGroupName (ID) 10:RowPosition (not index based) //11:FK_DateID - updateExistingTable = new DataTable("Projections"); + updateExistingTable = new DataTable(tableName); + //Create a reference to the DataGridView that will be used (either Projections or Actual Sales). + var dataGridView = tableName == "Projections" ? projectionsDataGridView : actualSalesDataGridView; //Construct a list of column names for the projections/actual sales DataGridViews and the inventory DataGirdView. string[] saleColumnNames = { @@ -1899,11 +1967,11 @@ namespace AdvertsingProfitControl { //An ad special does exist so grab its ID from the database. int.TryParse(databaseReader.RetrieveGroupIdByString( - projectionsDataGridView.Rows[_adSpecialIndex].Cells[(int)SalesTableColumns.AdItem] + dataGridView.Rows[_adSpecialIndex].Cells[(int)SalesTableColumns.AdItem] .EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString), out adSpecialId); } //Begin spinning through all the rows in the projections table. - foreach (DataGridViewRow row in projectionsDataGridView.Rows) + foreach (DataGridViewRow row in dataGridView.Rows) { //Always check for new row. if (row.IsNewRow) break; @@ -1934,6 +2002,7 @@ namespace AdvertsingProfitControl //AdItemInsertionFailedException insertNewTable.Rows.Clear(); //Work around for now updateExistingTable.Rows.Clear(); + errorLabel.Text = @"Failed to ad item to database."; return TrimmingOperationResult.FailedToTrim; } } @@ -1941,116 +2010,70 @@ namespace AdvertsingProfitControl if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex) { //Attempt to grab the index of an ad item, if it is not found then the return value is -1. - var repeatedItemIndex = - _usedAdItems[0].FindIndex(x => x == row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString()); - //Check if a repeat was found. + var repeatedItemIndex = _usedAdItems[0].FindIndex(x => x == row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString()); + //Skip checking this row if an index is found, and use the values in the row at the previous index found. if (repeatedItemIndex != -1) { - //A row index has been found so check to see if the row in question has already been added to any of the trimmed tables. - if ((bool)projectionsDataGridView.Rows[repeatedItemIndex].Cells[(int) SalesTableColumns.IsDirty].Value) + //Add the values to their respective data table. + if (rowIdNumber == 0) { - //If the row is dirty then its going to be found in either... - if (!(bool)projectionsDataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.IsInDatabase].Value) + //This table is full of data not in the database so the ID column isn't needed. + var newRow = new object[11]; + newRow[0] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.Sold].EditedFormattedValue.ToString();//Sold, is string + newRow[1] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.SalePrice].EditedFormattedValue.ToString();//SalePrice, is string + newRow[2] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString());//TotalSales, must be a number + newRow[3] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString());//Cost, must be a number + newRow[4] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString());//ProfitReturn, must be a number + newRow[5] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString());//TotalProfitReturn, must be a number + newRow[6] = adItemId; + if ((bool)dataGridView.Rows[repeatedItemIndex].Cells[(int) SalesTableColumns.IsHeaderRow].Value) { - //... or the add new items table. - //If the ad item is being used in section one then locate it and update it in the trimmed table. - var foundRow = insertNewTable.Select("AdItemID = '" + adItemId + "'"); - if (foundRow.Length == 1) - { - LogConsole.WriteToLog(FrmLogConsole.Level.Info, - "Ad item '" + row.Cells[(int) SalesTableColumns.AdItem].EditedFormattedValue + - "' found in the trimmed new table."); - } - //Else error condition? - else - { - insertNewTable.Rows.Clear(); - updateExistingTable.Rows.Clear(); - return TrimmingOperationResult.FailedToTrim; - } - //With the row found obtain the row's index and modify it in the table to - //include the ad special ID number. No other modifications are required so we can return. - //Begin spinning through all the rows to find the one selected above. - for (var i = 0; i < insertNewTable.Rows.Count; i++) - { - //Check to see if the selected row is equal. - if (foundRow[0] != insertNewTable.Rows[i]) continue; - //If so then update that row index with the group ID number. - insertNewTable.Rows[i][8] = adSpecialId; - } - //Once ad special ID has been updated jump to the next row. - continue; + newRow[7] = 1; + } + else if ((bool)dataGridView.Rows[repeatedItemIndex].Cells[(int) SalesTableColumns.IsMemberRow].Value) + { + newRow[7] = 2; } else { - //... the update existing items table - //If the ad item is being used in section two then locate it and update it in the trimmed table. - var foundRow = updateExistingTable.Select("AdItemID = '" + adItemId + "'"); - if (foundRow.Length == 1) - { - LogConsole.WriteToLog(FrmLogConsole.Level.Info, - "Ad item '" + row.Cells[(int) SalesTableColumns.AdItem].EditedFormattedValue + - "' found in the trimmed update table."); - } - //Else error condition? - else - { - insertNewTable.Rows.Clear(); - updateExistingTable.Rows.Clear(); - return TrimmingOperationResult.FailedToTrim; - } - //With the row found obtain the row's index and modify it in the table to - //include the ad special ID number. No other modifications are required so we can return. - //Begin spinning through all the rows to find the one selected above. - for (var i = 0; i < updateExistingTable.Rows.Count; i++) - { - //Check to see if the selected row is equal. - if (foundRow[0] != updateExistingTable.Rows[i]) continue; - //If so then update that row index with the group ID number. - updateExistingTable.Rows[i][8] = adSpecialId; - } - //Once ad special ID has been updated jump to the next row. - continue; + newRow[7] = 0; } + newRow[8] = adSpecialId; + newRow[9] = row.Index; //"Subtract" one since we don't need to acknowledge the Ad Special Row's existence. + newRow[10] = dateId; + insertNewTable.Rows.Add(newRow); + continue; } - //If the row is not dirty then it would not be included in any trimmed table just yet. - if ((bool)projectionsDataGridView.Rows[repeatedItemIndex].Cells[(int) SalesTableColumns.IsInDatabase].Value) + else { - //If its in the database already then add the row to the update table, including the ad special ID number. - //If the ad item is being used in section two then locate it and update it in the trimmed table. - var foundRow = updateExistingTable.Select("AdItemID = '" + adItemId + "'"); - if (foundRow.Length == 1) + //This table is full of data that is already in the database. + var newRow = new object[11]; + newRow[0] = rowIdNumber; + newRow[1] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.Sold].EditedFormattedValue.ToString();//Sold, is string + newRow[2] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.SalePrice].EditedFormattedValue.ToString();//SalePrice, is string + newRow[3] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString());//TotalSales, must be a number + newRow[4] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString());//Cost, must be a number + newRow[5] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString());//ProfitReturn, must be a number + newRow[6] = dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString());//TotalProfitReturn, must be a number + newRow[7] = adItemId; + if ((bool)dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.IsHeaderRow].Value) { - LogConsole.WriteToLog(FrmLogConsole.Level.Info, - "Ad item '" + row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue + - "' found in the trimmed update table."); + newRow[8] = 1; } - //Else error condition? - else + else if ((bool)dataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.IsMemberRow].Value) { - insertNewTable.Rows.Clear(); - updateExistingTable.Rows.Clear(); - return TrimmingOperationResult.FailedToTrim; + newRow[8] = 2; } - //With the row found obtain the row's index and modify it in the table to - //include the ad special ID number. No other modifications are required so we can return. - //Begin spinning through all the rows to find the one selected above. - for (var i = 0; i < updateExistingTable.Rows.Count; i++) + else { - //Check to see if the selected row is equal. - if (foundRow[0] != updateExistingTable.Rows[i]) continue; - //If so then update that row index with the group ID number. - updateExistingTable.Rows[i][8] = adSpecialId; + newRow[8] = 0; } - //Once ad special ID has been updated jump to the next row. + newRow[9] = adSpecialId; + newRow[10] = row.Index; //"Subtract" one since we don't need to acknowledge the Ad Special Row's existence. + newRow[11] = dateId; + insertNewTable.Rows.Add(newRow); continue; } - //else - //{ - // //Otherwise add it to the add new item trimmed table (should never happen). - //} - LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Repeated ad item '" + row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue + "' found."); - LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Its row index is " + repeatedItemIndex + "."); } } //Determine the row's attribute. @@ -2146,11 +2169,11 @@ namespace AdvertsingProfitControl //New inventory Table Layout (Based on the Database's Physical Layout) //0:Beginning Inventory 1:Received 2:Total Inventory 3:Ending Inventory //4:AdItemID 5:RowAttribute 6:GroupID 7:RowPosition 8:DateID - insertNewTable = new DataTable("Projections"); + insertNewTable = new DataTable("Inventory"); //Update Sales Table Layout (Based on the Database's Physical Layout) //0:ID 1:BeginningInventory 2:Received 3:TotalInventory 4:EndingInventory //5:AdItemID 6:RowAttribute 7:GroupID 8:RowPosition 9:DateID - updateExistingTable = new DataTable("Projections"); + updateExistingTable = new DataTable("Inventory"); //Construct a list of column names for the projections/actual sales DataGridViews and the inventory DataGirdView. string[] saleColumnNames = { @@ -2222,114 +2245,68 @@ namespace AdvertsingProfitControl //Attempt to grab the index of an ad item, if it is not found then the return value is -1. var repeatedItemIndex = _usedAdItems[0].FindIndex(x => x == row.Cells[(int)InventoryTableColumns.AdItem].EditedFormattedValue.ToString()); - //Check if a repeat was found. + //Skip checking this row if an index is found, and use the values in the row at the previous index found. if (repeatedItemIndex != -1) { - //A row index has been found so check to see if the row in question has already been added to any of the trimmed tables. - if ((bool)inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.IsDirty].Value) + //Add the values to their respective data table. + if (rowIdNumber == 0) { - //If the row is dirty then its going to be found in either... - if (!(bool)inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.IsInDatabase].Value) + //This table is full of data not in the database so the ID column isn't needed. + //0:Beginning Inventory 1:Received 2:Total Inventory 3:Ending Inventory + //4:AdItemID 5:RowAttribute 6:GroupID 7:RowPosition 8:DateID + var newRow = new object[9]; + newRow[0] = inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.BeginningInventory].EditedFormattedValue.ToString();//Sold, is string + newRow[1] = inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.Recieved].EditedFormattedValue.ToString();//SalePrice, is string + newRow[2] = inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int) InventoryTableColumns.Total].EditedFormattedValue.ToString(); //Total Inventory is string + newRow[3] = inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.EndingInventory].EditedFormattedValue.ToString();//Ending Inventory, is string + newRow[4] = adItemId; + if ((bool)inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.IsHeaderRow].Value) { - //... or the add new items table. - //If the ad item is being used in section one then locate it and update it in the trimmed table. - var foundRow = insertNewTable.Select("AdItemID = '" + adItemId + "'"); - if (foundRow.Length == 1) - { - LogConsole.WriteToLog(FrmLogConsole.Level.Info, - "Ad item '" + row.Cells[(int)InventoryTableColumns.AdItem].EditedFormattedValue + - "' found in the trimmed new table."); - } - //Else error condition? - else - { - insertNewTable.Rows.Clear(); - updateExistingTable.Rows.Clear(); - return TrimmingOperationResult.FailedToTrim; - } - //With the row found obtain the row's index and modify it in the table to - //include the ad special ID number. No other modifications are required so we can return. - //Begin spinning through all the rows to find the one selected above. - for (var i = 0; i < insertNewTable.Rows.Count; i++) - { - //Check to see if the selected row is equal. - if (foundRow[0] != insertNewTable.Rows[i]) continue; - //If so then update that row index with the group ID number. - insertNewTable.Rows[i][8] = adSpecialId; - } - //Once ad special ID has been updated jump to the next row. - continue; + newRow[5] = 1; + } + else if ((bool)inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.IsMemberRow].Value) + { + newRow[5] = 2; } else { - //... the update existing items table - //If the ad item is being used in section two then locate it and update it in the trimmed table. - var foundRow = updateExistingTable.Select("AdItemID = '" + adItemId + "'"); - if (foundRow.Length == 1) - { - LogConsole.WriteToLog(FrmLogConsole.Level.Info, - "Ad item '" + row.Cells[(int)InventoryTableColumns.AdItem].EditedFormattedValue + - "' found in the trimmed update table."); - } - //Else error condition? - else - { - insertNewTable.Rows.Clear(); - updateExistingTable.Rows.Clear(); - return TrimmingOperationResult.FailedToTrim; - } - //With the row found obtain the row's index and modify it in the table to - //include the ad special ID number. No other modifications are required so we can return. - //Begin spinning through all the rows to find the one selected above. - for (var i = 0; i < updateExistingTable.Rows.Count; i++) - { - //Check to see if the selected row is equal. - if (foundRow[0] != updateExistingTable.Rows[i]) continue; - //If so then update that row index with the group ID number. - updateExistingTable.Rows[i][8] = adSpecialId; - } - //Once ad special ID has been updated jump to the next row. - continue; + newRow[5] = 0; } + newRow[6] = adSpecialId; + newRow[7] = row.Index; //"Subtract" one since we don't need to acknowledge the Ad Special Row's existence. + newRow[8] = dateId; + insertNewTable.Rows.Add(newRow); + continue; } - //If the row is not dirty then it would not be included in any trimmed table just yet. - if ((bool)inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.IsInDatabase].Value) + else { - //If its in the database already then add the row to the update table, including the ad special ID number. - //If the ad item is being used in section two then locate it and update it in the trimmed table. - var foundRow = updateExistingTable.Select("AdItemID = '" + adItemId + "'"); - if (foundRow.Length == 1) + //This table is full of data that is already in the database. + //0:ID 1:BeginningInventory 2:Received 3:TotalInventory 4:EndingInventory + //5:AdItemID 6:RowAttribute 7:GroupID 8:RowPosition 9:DateID + var newRow = new object[10]; + newRow[0] = rowIdNumber; + newRow[1] = inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.BeginningInventory].EditedFormattedValue.ToString();//Sold, is string + newRow[2] = inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.Recieved].EditedFormattedValue.ToString();//SalePrice, is string + newRow[3] = inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.Total].EditedFormattedValue.ToString(); //Total Inventory is string + newRow[4] = inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.EndingInventory].EditedFormattedValue.ToString();//Ending Inventory, is string + newRow[5] = adItemId; + if ((bool)inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.IsHeaderRow].Value) { - LogConsole.WriteToLog(FrmLogConsole.Level.Info, - "Ad item '" + row.Cells[(int)InventoryTableColumns.AdItem].EditedFormattedValue + - "' found in the trimmed update table."); + newRow[6] = 1; } - //Else error condition? - else + else if ((bool)inventoryDataGridView.Rows[repeatedItemIndex].Cells[(int)InventoryTableColumns.IsMemberRow].Value) { - insertNewTable.Rows.Clear(); - updateExistingTable.Rows.Clear(); - return TrimmingOperationResult.FailedToTrim; + newRow[6] = 2; } - //With the row found obtain the row's index and modify it in the table to - //include the ad special ID number. No other modifications are required so we can return. - //Begin spinning through all the rows to find the one selected above. - for (var i = 0; i < updateExistingTable.Rows.Count; i++) + else { - //Check to see if the selected row is equal. - if (foundRow[0] != updateExistingTable.Rows[i]) continue; - //If so then update that row index with the group ID number. - updateExistingTable.Rows[i][8] = adSpecialId; + newRow[6] = 0; } - //Once ad special ID has been updated jump to the next row. + newRow[7] = adSpecialId; + newRow[8] = row.Index; //"Subtract" one since we don't need to acknowledge the Ad Special Row's existence. + newRow[9] = dateId; continue; } - //else - //{ - // //Otherwise add it to the add new item trimmed table (should never happen). - //} - LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Repeated ad item '" + row.Cells[(int)InventoryTableColumns.AdItem].EditedFormattedValue + "' found."); - LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Its row index is " + repeatedItemIndex + "."); } } //Determine the row's attribute. @@ -2406,281 +2383,6 @@ namespace AdvertsingProfitControl } return TrimmingOperationResult.CreatedNewInsertionAndUpdateTables; } - - private TrimmingOperationResult ConstructCleanedActualSalesTable(int dateId, out DataTable insertNewTable, out DataTable updateExistingTable) - { - //Create two DataTables one for the new items to be added to the database - //and one for items that have to be updated. - //New Sales Table Layout (Based on the Database's Physical Layout) - //0:Sold 1:SalePrice 2:TotalSales 3:cost 4:ProfitReturn 5:TotalProfitReturn - //6:FK_AdItemID 7:RowAttribute 8:FK_AdSpecialGroupName (ID) 9:RowPosition (not index based) - //10:FK_DateID - insertNewTable = new DataTable("Projections"); - //Update Sales Table Layout (Based on the Database's Physical Layout) - //0:ID 1:Sold 2:SalePrice 3:TotalSales 4:cost 5:ProfitReturn 6:TotalProfitReturn - //7:FK_AdItemID 8:RowAttribute 9:FK_AdSpecialGroupName (ID) 10:RowPosition (not index based) - //11:FK_DateID - updateExistingTable = new DataTable("Projections"); - //Construct a list of column names for the projections/actual sales DataGridViews and the inventory DataGirdView. - string[] saleColumnNames = - { - "ID", "Sold", "SalePrice", "TotalSales", "Cost", "ProfitReturn", - "TotalProfitReturn", "AdItemID", "RowAttribute", "AdSpecialID", "RowPosition", "DateID" - }; - foreach (var columnName in saleColumnNames) - { - if (columnName == "ID") continue; - var column = new DataColumn(columnName); - insertNewTable.Columns.Add(column); - } - foreach (var columnName in saleColumnNames) - { - var column = new DataColumn(columnName); - updateExistingTable.Columns.Add(column); - } - //Create the database interaction objects. - var databaseTracker = new DatabaseTracker(); - var databaseReader = new DatabaseReader(); - var databaseWriter = new DatabaseWriter(databaseTracker.DatabaseConnectionString); - var adSpecialId = 0; //Entries in the database are not allowed to be zero (unique ID wise that is). - //Grab the ad special ID, assuming there is one. - if (_adSpecialIndex != -1) - { - //An ad special does exist so grab its ID from the database. - int.TryParse(databaseReader.RetrieveGroupIdByString( - actualSalesDataGridView.Rows[_adSpecialIndex].Cells[(int)SalesTableColumns.AdItem] - .EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString), out adSpecialId); - } - //Begin spinning through all the rows in the projections table. - foreach (DataGridViewRow row in actualSalesDataGridView.Rows) - { - //Always check for new row. - if (row.IsNewRow) break; - //Check to see if the current row is the ad special row. - if (row.Index == _adSpecialIndex) - { - //LogConsole.WriteToLog(FrmLogConsole.Level.Verbose, "Ad Special Row found at index " + row.Index + "."); - continue; - } - //Check to see if the row is dirty. - if (!(bool)row.Cells[(int)SalesTableColumns.IsDirty].Value) - { - //If it is not then continue on to the next row. - continue; - } - //Try grabbing the row's ID number (the number that it is in the database). - var rowIdNumber = row.Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString() == "" ? 0 : int.Parse(row.Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - //Grab the ad item ID. - var adItemId = int.Parse(databaseReader.RetrieveAdItemId(row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString(), databaseTracker.DatabaseConnectionString)); - //If the return value is zero (0) then the ad item is not in the database so try to add it. - if (adItemId == 0) - { - //Add the item to the database. - adItemId = databaseWriter.InsertNewAdItem(row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString()); - if (adItemId == 0) - { - //TODO: Throw an exception, this can not be allowed. - //AdItemInsertionFailedException - insertNewTable.Rows.Clear(); //Work around for now - updateExistingTable.Rows.Clear(); - return TrimmingOperationResult.FailedToTrim; - } - } - //Check for repeated ad items in the ad special section - if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex) - { - //Attempt to grab the index of an ad item, if it is not found then the return value is -1. - var repeatedItemIndex = - _usedAdItems[0].FindIndex(x => x == row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue.ToString()); - //Check if a repeat was found. - if (repeatedItemIndex != -1) - { - //A row index has been found so check to see if the row in question has already been added to any of the trimmed tables. - if ((bool)actualSalesDataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.IsDirty].Value) - { - //If the row is dirty then its going to be found in either... - if (!(bool)actualSalesDataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.IsInDatabase].Value) - { - //... or the add new items table. - //If the ad item is being used in section one then locate it and update it in the trimmed table. - var foundRow = insertNewTable.Select("AdItemID = '" + adItemId + "'"); - if (foundRow.Length == 1) - { - LogConsole.WriteToLog(FrmLogConsole.Level.Info, - "Ad item '" + row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue + - "' found in the trimmed new table."); - } - //Else error condition? - else - { - insertNewTable.Rows.Clear(); - updateExistingTable.Rows.Clear(); - return TrimmingOperationResult.FailedToTrim; - } - //With the row found obtain the row's index and modify it in the table to - //include the ad special ID number. No other modifications are required so we can return. - //Begin spinning through all the rows to find the one selected above. - for (var i = 0; i < insertNewTable.Rows.Count; i++) - { - //Check to see if the selected row is equal. - if (foundRow[0] != insertNewTable.Rows[i]) continue; - //If so then update that row index with the group ID number. - insertNewTable.Rows[i][8] = adSpecialId; - } - //Once ad special ID has been updated jump to the next row. - continue; - } - else - { - //... the update existing items table - //If the ad item is being used in section two then locate it and update it in the trimmed table. - var foundRow = updateExistingTable.Select("AdItemID = '" + adItemId + "'"); - if (foundRow.Length == 1) - { - LogConsole.WriteToLog(FrmLogConsole.Level.Info, - "Ad item '" + row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue + - "' found in the trimmed update table."); - } - //Else error condition? - else - { - insertNewTable.Rows.Clear(); - updateExistingTable.Rows.Clear(); - return TrimmingOperationResult.FailedToTrim; - } - //With the row found obtain the row's index and modify it in the table to - //include the ad special ID number. No other modifications are required so we can return. - //Begin spinning through all the rows to find the one selected above. - for (var i = 0; i < updateExistingTable.Rows.Count; i++) - { - //Check to see if the selected row is equal. - if (foundRow[0] != updateExistingTable.Rows[i]) continue; - //If so then update that row index with the group ID number. - updateExistingTable.Rows[i][8] = adSpecialId; - } - //Once ad special ID has been updated jump to the next row. - continue; - } - } - //If the row is not dirty then it would not be included in any trimmed table just yet. - if ((bool)actualSalesDataGridView.Rows[repeatedItemIndex].Cells[(int)SalesTableColumns.IsInDatabase].Value) - { - //If its in the database already then add the row to the update table, including the ad special ID number. - //If the ad item is being used in section two then locate it and update it in the trimmed table. - var foundRow = updateExistingTable.Select("AdItemID = '" + adItemId + "'"); - if (foundRow.Length == 1) - { - LogConsole.WriteToLog(FrmLogConsole.Level.Info, - "Ad item '" + row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue + - "' found in the trimmed update table."); - } - //Else error condition? - else - { - insertNewTable.Rows.Clear(); - updateExistingTable.Rows.Clear(); - return TrimmingOperationResult.FailedToTrim; - } - //With the row found obtain the row's index and modify it in the table to - //include the ad special ID number. No other modifications are required so we can return. - //Begin spinning through all the rows to find the one selected above. - for (var i = 0; i < updateExistingTable.Rows.Count; i++) - { - //Check to see if the selected row is equal. - if (foundRow[0] != updateExistingTable.Rows[i]) continue; - //If so then update that row index with the group ID number. - updateExistingTable.Rows[i][8] = adSpecialId; - } - //Once ad special ID has been updated jump to the next row. - continue; - } - //else - //{ - // //Otherwise add it to the add new item trimmed table (should never happen). - //} - LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Repeated ad item '" + row.Cells[(int)SalesTableColumns.AdItem].EditedFormattedValue + "' found."); - LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Its row index is " + repeatedItemIndex + "."); - } - } - //Determine the row's attribute. - var rowAttribute = 0; //Zero (0) means no grouping, its not a header nor a member. - if ((bool)row.Cells[(int)SalesTableColumns.IsHeaderRow].Value && !(bool)row.Cells[(int)SalesTableColumns.IsMemberRow].Value) - { - rowAttribute = 1; - } - else if ((bool)row.Cells[(int)SalesTableColumns.IsMemberRow].Value && !(bool)row.Cells[(int)SalesTableColumns.IsHeaderRow].Value) - { - rowAttribute = 2; - } - //Add the values to their respective data table. - if (rowIdNumber == 0) - { - //This table is full of data not in the database so the ID column isn't needed. - var newRow = new object[11]; - newRow[0] = row.Cells[(int)SalesTableColumns.Sold].EditedFormattedValue.ToString();//Sold, is string - newRow[1] = row.Cells[(int)SalesTableColumns.SalePrice].EditedFormattedValue.ToString();//SalePrice, is string - newRow[2] = row.Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString());//TotalSales, must be a number - newRow[3] = row.Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString());//Cost, must be a number - newRow[4] = row.Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString());//ProfitReturn, must be a number - newRow[5] = row.Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString());//TotalProfitReturn, must be a number - newRow[6] = adItemId; - newRow[7] = rowAttribute; - if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex) - { - newRow[8] = adSpecialId; - newRow[9] = row.Index; //"Subtract" one since we don't need to acknowledge the Ad Special Row's existence. - } - else - { - newRow[8] = 0; - newRow[9] = row.Index + 1; - } - newRow[10] = dateId; - insertNewTable.Rows.Add(newRow); - } - else - { - //This table is full of data that is already in the database. - var newRow = new object[12]; - newRow[0] = rowIdNumber; - newRow[1] = row.Cells[(int)SalesTableColumns.Sold].EditedFormattedValue.ToString();//Sold, is string - newRow[2] = row.Cells[(int)SalesTableColumns.SalePrice].EditedFormattedValue.ToString();//SalePrice, is string - newRow[3] = row.Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.TotalSales].EditedFormattedValue.ToString());//TotalSales, must be a number - newRow[4] = row.Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.Cost].EditedFormattedValue.ToString());//Cost, must be a number - newRow[5] = row.Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString());//ProfitReturn, must be a number - newRow[6] = row.Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(row.Cells[(int)SalesTableColumns.TotalProfitReturn].EditedFormattedValue.ToString());//TotalProfitReturn, must be a number - newRow[7] = adItemId; - newRow[8] = rowAttribute; - if (_adSpecialIndex != -1 && row.Index > _adSpecialIndex) - { - newRow[9] = adSpecialId; - newRow[10] = row.Index; //"Subtract" one since we don't need to acknowledge the Ad Special Row's existence. - } - else - { - newRow[9] = 0; - newRow[10] = row.Index + 1; - } - newRow[11] = dateId; - updateExistingTable.Rows.Add(newRow); - } - } - - if (insertNewTable.Rows.Count == 0 && updateExistingTable.Rows.Count == 0) - { - return TrimmingOperationResult.NoChangesRequired; - } - if (insertNewTable.Rows.Count > 0 && updateExistingTable.Rows.Count == 0) - { - return TrimmingOperationResult.CreatedNewInsertionTable; - } - if (insertNewTable.Rows.Count == 0 && updateExistingTable.Rows.Count > 0) - { - return TrimmingOperationResult.CreatedUpdateTable; - } - return TrimmingOperationResult.CreatedNewInsertionAndUpdateTables; - } - #endregion } } diff --git a/AdvertsingProfitControl/bin/Debug/APCDatabase.accdb b/AdvertsingProfitControl/bin/Debug/APCDatabase.accdb index 661ffc5..67a9e7b 100644 Binary files a/AdvertsingProfitControl/bin/Debug/APCDatabase.accdb and b/AdvertsingProfitControl/bin/Debug/APCDatabase.accdb differ diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.application index 786f289..0e9f4b4 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.application @@ -14,7 +14,7 @@ - ZL5dwalV8JqCCLJbc11enpP7V0Ttl3QSWzyKFXpqQeA= + +ssiBRxAIMo1rYBk1za3itR7/whCFhhY9pJz/fEqrC4= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.exe.manifest index efcc546..30ea602 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.exe.manifest @@ -43,14 +43,14 @@ - + - Jb2/XD/xmkjSGdpdtKCMoj9SdjztlACxydkOCDCOUcU= + Yu2YbMJIbDdI4qvbL4hRtraLKoPxP0wq2Mbn7/XyWug= @@ -84,7 +84,7 @@ - jHrcUaYXYq1n7JCrmyieXoxYIayP5Xf8FNLYAJKW198= + nDAH4e73CtUOempeqgnfoRyypkOO191kktA8yxaiU3g= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application index 786f289..0e9f4b4 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application @@ -14,7 +14,7 @@ - ZL5dwalV8JqCCLJbc11enpP7V0Ttl3QSWzyKFXpqQeA= + +ssiBRxAIMo1rYBk1za3itR7/whCFhhY9pJz/fEqrC4= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest index efcc546..30ea602 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest @@ -43,14 +43,14 @@ - + - Jb2/XD/xmkjSGdpdtKCMoj9SdjztlACxydkOCDCOUcU= + Yu2YbMJIbDdI4qvbL4hRtraLKoPxP0wq2Mbn7/XyWug= @@ -84,7 +84,7 @@ - jHrcUaYXYq1n7JCrmyieXoxYIayP5Xf8FNLYAJKW198= + nDAH4e73CtUOempeqgnfoRyypkOO191kktA8yxaiU3g= diff --git a/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.application b/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.application index 786f289..0e9f4b4 100644 --- a/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.application +++ b/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.application @@ -14,7 +14,7 @@ - ZL5dwalV8JqCCLJbc11enpP7V0Ttl3QSWzyKFXpqQeA= + +ssiBRxAIMo1rYBk1za3itR7/whCFhhY9pJz/fEqrC4= diff --git a/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.exe.manifest b/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.exe.manifest index efcc546..30ea602 100644 --- a/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.exe.manifest +++ b/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.exe.manifest @@ -43,14 +43,14 @@ - + - Jb2/XD/xmkjSGdpdtKCMoj9SdjztlACxydkOCDCOUcU= + Yu2YbMJIbDdI4qvbL4hRtraLKoPxP0wq2Mbn7/XyWug= @@ -84,7 +84,7 @@ - jHrcUaYXYq1n7JCrmyieXoxYIayP5Xf8FNLYAJKW198= + nDAH4e73CtUOempeqgnfoRyypkOO191kktA8yxaiU3g= diff --git a/StringInputParseTester/obj/Debug/StringInputParseTester.csproj.FileListAbsolute.txt b/StringInputParseTester/obj/Debug/StringInputParseTester.csproj.FileListAbsolute.txt index c2eaf04..186de09 100644 --- a/StringInputParseTester/obj/Debug/StringInputParseTester.csproj.FileListAbsolute.txt +++ b/StringInputParseTester/obj/Debug/StringInputParseTester.csproj.FileListAbsolute.txt @@ -16,3 +16,12 @@ C:\Users\Crypto\Documents\Visual Studio 2015\Projects\AdvertsingProfitControl\St C:\Users\Crypto\Documents\Visual Studio 2015\Projects\AdvertsingProfitControl\StringInputParseTester\obj\Debug\StringInputParseTester.csproj.GenerateResource.Cache C:\Users\Crypto\Documents\Visual Studio 2015\Projects\AdvertsingProfitControl\StringInputParseTester\obj\Debug\StringInputParseTester.exe C:\Users\Crypto\Documents\Visual Studio 2015\Projects\AdvertsingProfitControl\StringInputParseTester\obj\Debug\StringInputParseTester.pdb +C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\StringInputParseTester\bin\Debug\StringInputParseTester.exe.config +C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\StringInputParseTester\bin\Debug\StringInputParseTester.exe +C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\StringInputParseTester\bin\Debug\StringInputParseTester.pdb +C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\StringInputParseTester\obj\Debug\StringInputParseTester.csprojResolveAssemblyReference.cache +C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\StringInputParseTester\obj\Debug\StringInputParseTester.Form1.resources +C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\StringInputParseTester\obj\Debug\StringInputParseTester.Properties.Resources.resources +C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\StringInputParseTester\obj\Debug\StringInputParseTester.csproj.GenerateResource.Cache +C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\StringInputParseTester\obj\Debug\StringInputParseTester.exe +C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\StringInputParseTester\obj\Debug\StringInputParseTester.pdb