diff --git a/AdvertsingProfitControl/DatabaseWriter.cs b/AdvertsingProfitControl/DatabaseWriter.cs index 51832a1..289f6fb 100644 --- a/AdvertsingProfitControl/DatabaseWriter.cs +++ b/AdvertsingProfitControl/DatabaseWriter.cs @@ -359,7 +359,7 @@ namespace AdvertsingProfitControl oleDbTransaction.Commit(); foreach (DataRow row in table.Rows) { - var rowId = RetrieveRowId(table.TableName, int.Parse(row[4].ToString()), int.Parse(row[8].ToString()), int.Parse(table.Rows[7].ToString())); + var rowId = RetrieveRowId(table.TableName, int.Parse(row[4].ToString()), int.Parse(row[8].ToString()), int.Parse(row[7].ToString())); if (int.Parse(row[7].ToString()) != 0) { //Account for the ad special row. @@ -421,6 +421,7 @@ namespace AdvertsingProfitControl OleDbTransaction oleDbTransaction = null; try { + var dirtyRowsProcessed = 0; oleDbConnection.Open(); oleDbTransaction = oleDbConnection.BeginTransaction(); oleDbCommand.Transaction = oleDbTransaction; @@ -432,6 +433,7 @@ namespace AdvertsingProfitControl lastRowProcessed = i + 1; continue; } + dirtyRowsProcessed++; //Grab the supplier ID number before moving forward. var supplierId = RetrieveSupplierId( table.Rows[i].Cells[(int) InvoiceTableColumns.Supplier].EditedFormattedValue.ToString()); @@ -439,6 +441,7 @@ namespace AdvertsingProfitControl { status.SetErrorMessage("Failed to obtain supplier ID number for " + table.Rows[i].Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue + "."); status.SetStatus(WritingOperationStatus.Failed); + oleDbTransaction.Rollback(); return status; } //Check whether or not the row is already in the database by seeing if anything is in the ID number cell. @@ -480,23 +483,32 @@ namespace AdvertsingProfitControl oleDbTransaction.Commit(); foreach (DataGridViewRow row in table.Rows) { - if (rowsAdded.Contains(row.Index)) - { - var supplierId = RetrieveSupplierId(row.Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue.ToString()); - var invoiceIdNumber = - RetrieveInvoiceId( - row.Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue - .ToString(), - long.Parse( - row.Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue - .ToString()), supplierId, dateId); - row.Cells[(int)InvoiceTableColumns.Id].Value = invoiceIdNumber; - } + if(row.IsNewRow) continue; + if (!rowsAdded.Contains(row.Index)) continue; + var supplierId = RetrieveSupplierId(row.Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue.ToString()); + var invoiceIdNumber = + RetrieveInvoiceId( + row.Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue + .ToString(), + long.Parse( + row.Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue + .ToString()), supplierId, dateId); + row.Cells[(int)InvoiceTableColumns.Id].Value = invoiceIdNumber; row.Cells[(int)InvoiceTableColumns.IsDirty].Value = false; + row.HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } table.RefreshEdit(); //Set the status. status.SetStatus(WritingOperationStatus.InsertionSuccessful); + //Set the message to be used on the calling form since we don't have access to the form's information label. + if (dirtyRowsProcessed == 0) + { + status.SetErrorMessage("No changes to the Invoices table detected."); + } + else + { + status.SetErrorMessage("Invoices processed successfully."); + } } catch (OleDbException e) { @@ -765,6 +777,40 @@ namespace AdvertsingProfitControl return status; } + /// + /// Deletes the contents for the specified table where the date IDs + /// match the one sent to this method. + /// + /// The name of the table in the database to be trimmed. + /// The ID number for the date that is to be dropped. + /// The connection info for the database. + public void DeleteApcDataEntriesByDate(string tableName, int dateId, string connectionString) + { + var oleDbConnection = new OleDbConnection(connectionString); + var oleDbCommand = new OleDbCommand + { + Connection = oleDbConnection, + CommandText = "DELETE * FROM " + tableName + " WHERE FK_DateID = ?" + + }; + oleDbCommand.Parameters.AddWithValue("DateID", dateId); + try + { + oleDbConnection.Open(); + oleDbCommand.ExecuteNonQuery(); + } + catch (OleDbException e) + { + _logConsole.WriteToLog(FrmLogConsole.Level.Error, + "Failed to delete the entries in " + tableName + " with the date ID of " + dateId + "."); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message); + } + finally + { + oleDbConnection.Close(); + } + } + /// /// Inserts a new ad item into the database and returns the new item's ID number. /// Supports rolling back as to not corrupt the database. diff --git a/AdvertsingProfitControl/NewAddRecord.Designer.cs b/AdvertsingProfitControl/NewAddRecord.Designer.cs index 16b853b..7752292 100644 --- a/AdvertsingProfitControl/NewAddRecord.Designer.cs +++ b/AdvertsingProfitControl/NewAddRecord.Designer.cs @@ -51,6 +51,7 @@ this.isTaxableDirtyCheckBox = new System.Windows.Forms.CheckBox(); this.isWeeklySalesDirtyCheckBox = new System.Windows.Forms.CheckBox(); this.isCommentDirtyCheckBox = new System.Windows.Forms.CheckBox(); + this.informationLabel = new System.Windows.Forms.Label(); this.mainMenuStrip = new System.Windows.Forms.MenuStrip(); this.FileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.clearFormFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); @@ -101,14 +102,10 @@ this.tuesdayTaxableLabel = new System.Windows.Forms.Label(); this.saturdayTaxableTextBox = new System.Windows.Forms.TextBox(); this.dateGroupBox = new System.Windows.Forms.GroupBox(); - this.monthCalendarInstructionsLabel = new System.Windows.Forms.Label(); - this.weekEndingMonthCalendar = new System.Windows.Forms.MonthCalendar(); + this.weekEndingCalendar = new System.Windows.Forms.MonthCalendar(); this.dateTimeMaskedTextBoxPanel = new System.Windows.Forms.Panel(); - this.errorLabel = new System.Windows.Forms.Label(); - this.weekEndingMaskedTextBox = new System.Windows.Forms.MaskedTextBox(); - this.weekEndingMaskedTextBoxInstructionLabel = new System.Windows.Forms.Label(); this.informationPanel = new System.Windows.Forms.Panel(); - this.informationLabel = new System.Windows.Forms.Label(); + this.errorLabel = new System.Windows.Forms.Label(); this.addRecordButton = new System.Windows.Forms.Button(); this.commentsGroupBox.SuspendLayout(); this.mainTabControl.SuspendLayout(); @@ -142,7 +139,7 @@ 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(461, 223); + this.commentsGroupBox.Size = new System.Drawing.Size(461, 177); this.commentsGroupBox.TabIndex = 2; this.commentsGroupBox.TabStop = false; this.commentsGroupBox.Text = "Comments"; @@ -154,7 +151,8 @@ this.commentsTextBox.MaxLength = 256; this.commentsTextBox.Multiline = true; this.commentsTextBox.Name = "commentsTextBox"; - this.commentsTextBox.Size = new System.Drawing.Size(453, 193); + this.commentsTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.commentsTextBox.Size = new System.Drawing.Size(453, 147); this.commentsTextBox.TabIndex = 4; // // mainTabControl @@ -303,7 +301,6 @@ // // debugPanel // - this.debugPanel.Controls.Add(this.informationLabel); this.debugPanel.Controls.Add(this.generateCostAnalysisIdButton); this.debugPanel.Controls.Add(this.generateTaxableIdButton); this.debugPanel.Controls.Add(this.generateWeeklySalesIdButton); @@ -408,6 +405,14 @@ this.isCommentDirtyCheckBox.Text = "IsCommentDirty"; this.isCommentDirtyCheckBox.UseVisualStyleBackColor = true; // + // informationLabel + // + this.informationLabel.AutoSize = true; + this.informationLabel.Location = new System.Drawing.Point(0, 7); + this.informationLabel.Name = "informationLabel"; + this.informationLabel.Size = new System.Drawing.Size(0, 25); + this.informationLabel.TabIndex = 27; + // // mainMenuStrip // this.mainLayoutPanel.SetColumnSpan(this.mainMenuStrip, 4); @@ -464,8 +469,8 @@ this.mainLayoutPanel.RowCount = 4; this.mainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 35F)); 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.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.mainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)); this.mainLayoutPanel.Size = new System.Drawing.Size(1876, 961); this.mainLayoutPanel.TabIndex = 0; // @@ -482,28 +487,28 @@ this.costAnalysisGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; this.costAnalysisGroupBox.Location = new System.Drawing.Point(1410, 593); this.costAnalysisGroupBox.Name = "costAnalysisGroupBox"; - this.costAnalysisGroupBox.Size = new System.Drawing.Size(463, 225); + this.costAnalysisGroupBox.Size = new System.Drawing.Size(463, 179); this.costAnalysisGroupBox.TabIndex = 6; this.costAnalysisGroupBox.TabStop = false; this.costAnalysisGroupBox.Text = "Cost Analysis"; // // suppliesTextBox // - this.suppliesTextBox.Location = new System.Drawing.Point(205, 185); + this.suppliesTextBox.Location = new System.Drawing.Point(203, 139); this.suppliesTextBox.Name = "suppliesTextBox"; this.suppliesTextBox.Size = new System.Drawing.Size(199, 29); this.suppliesTextBox.TabIndex = 25; // // salaryPercentageTextBox // - this.salaryPercentageTextBox.Location = new System.Drawing.Point(205, 87); + this.salaryPercentageTextBox.Location = new System.Drawing.Point(203, 69); this.salaryPercentageTextBox.Name = "salaryPercentageTextBox"; this.salaryPercentageTextBox.Size = new System.Drawing.Size(199, 29); this.salaryPercentageTextBox.TabIndex = 23; // // salaryDollarsTextBox // - this.salaryDollarsTextBox.Location = new System.Drawing.Point(205, 136); + this.salaryDollarsTextBox.Location = new System.Drawing.Point(203, 104); this.salaryDollarsTextBox.Name = "salaryDollarsTextBox"; this.salaryDollarsTextBox.Size = new System.Drawing.Size(199, 29); this.salaryDollarsTextBox.TabIndex = 24; @@ -511,7 +516,7 @@ // salesPerManHourLabel // this.salesPerManHourLabel.AutoSize = true; - this.salesPerManHourLabel.Location = new System.Drawing.Point(5, 38); + this.salesPerManHourLabel.Location = new System.Drawing.Point(3, 34); this.salesPerManHourLabel.Name = "salesPerManHourLabel"; this.salesPerManHourLabel.Size = new System.Drawing.Size(194, 25); this.salesPerManHourLabel.TabIndex = 0; @@ -520,7 +525,7 @@ // salaryPercentageLabel // this.salaryPercentageLabel.AutoSize = true; - this.salaryPercentageLabel.Location = new System.Drawing.Point(20, 87); + this.salaryPercentageLabel.Location = new System.Drawing.Point(18, 69); this.salaryPercentageLabel.Name = "salaryPercentageLabel"; this.salaryPercentageLabel.Size = new System.Drawing.Size(179, 25); this.salaryPercentageLabel.TabIndex = 1; @@ -528,7 +533,7 @@ // // salesPerManHourTextBox // - this.salesPerManHourTextBox.Location = new System.Drawing.Point(205, 38); + this.salesPerManHourTextBox.Location = new System.Drawing.Point(203, 34); this.salesPerManHourTextBox.Name = "salesPerManHourTextBox"; this.salesPerManHourTextBox.Size = new System.Drawing.Size(199, 29); this.salesPerManHourTextBox.TabIndex = 22; @@ -536,7 +541,7 @@ // salaryDollarsLabel // this.salaryDollarsLabel.AutoSize = true; - this.salaryDollarsLabel.Location = new System.Drawing.Point(60, 136); + this.salaryDollarsLabel.Location = new System.Drawing.Point(58, 104); this.salaryDollarsLabel.Name = "salaryDollarsLabel"; this.salaryDollarsLabel.Size = new System.Drawing.Size(139, 25); this.salaryDollarsLabel.TabIndex = 2; @@ -545,7 +550,7 @@ // suppliesLabel // this.suppliesLabel.AutoSize = true; - this.suppliesLabel.Location = new System.Drawing.Point(105, 185); + this.suppliesLabel.Location = new System.Drawing.Point(103, 139); this.suppliesLabel.Name = "suppliesLabel"; this.suppliesLabel.Size = new System.Drawing.Size(94, 25); this.suppliesLabel.TabIndex = 3; @@ -876,8 +881,7 @@ // // dateGroupBox // - this.dateGroupBox.Controls.Add(this.monthCalendarInstructionsLabel); - this.dateGroupBox.Controls.Add(this.weekEndingMonthCalendar); + this.dateGroupBox.Controls.Add(this.weekEndingCalendar); this.dateGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; this.dateGroupBox.Location = new System.Drawing.Point(3, 593); this.dateGroupBox.Name = "dateGroupBox"; @@ -887,91 +891,49 @@ this.dateGroupBox.TabStop = false; this.dateGroupBox.Text = "Week Ending Date"; // - // monthCalendarInstructionsLabel + // weekEndingCalendar // - this.monthCalendarInstructionsLabel.AutoSize = true; - this.monthCalendarInstructionsLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.142858F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.monthCalendarInstructionsLabel.Location = new System.Drawing.Point(57, 30); - this.monthCalendarInstructionsLabel.Name = "monthCalendarInstructionsLabel"; - this.monthCalendarInstructionsLabel.Size = new System.Drawing.Size(296, 25); - this.monthCalendarInstructionsLabel.TabIndex = 2; - this.monthCalendarInstructionsLabel.Text = "Select a date from the calendar..."; - // - // weekEndingMonthCalendar - // - this.weekEndingMonthCalendar.BackColor = System.Drawing.SystemColors.ControlLight; - this.weekEndingMonthCalendar.FirstDayOfWeek = System.Windows.Forms.Day.Sunday; - this.weekEndingMonthCalendar.Location = new System.Drawing.Point(49, 61); - this.weekEndingMonthCalendar.MaxSelectionCount = 1; - this.weekEndingMonthCalendar.Name = "weekEndingMonthCalendar"; - this.weekEndingMonthCalendar.ShowTodayCircle = false; - this.weekEndingMonthCalendar.TabIndex = 2; - this.weekEndingMonthCalendar.TabStop = false; - this.weekEndingMonthCalendar.DateChanged += new System.Windows.Forms.DateRangeEventHandler(this.UpdateWeekEndingMaskedTextBox); + this.weekEndingCalendar.BackColor = System.Drawing.SystemColors.ControlLight; + this.weekEndingCalendar.FirstDayOfWeek = System.Windows.Forms.Day.Sunday; + this.weekEndingCalendar.Location = new System.Drawing.Point(48, 34); + this.weekEndingCalendar.MaxSelectionCount = 1; + this.weekEndingCalendar.Name = "weekEndingCalendar"; + this.weekEndingCalendar.ShowTodayCircle = false; + this.weekEndingCalendar.TabIndex = 2; + this.weekEndingCalendar.TabStop = false; // // dateTimeMaskedTextBoxPanel // - this.dateTimeMaskedTextBoxPanel.Controls.Add(this.errorLabel); - this.dateTimeMaskedTextBoxPanel.Controls.Add(this.weekEndingMaskedTextBox); - this.dateTimeMaskedTextBoxPanel.Controls.Add(this.weekEndingMaskedTextBoxInstructionLabel); + this.dateTimeMaskedTextBoxPanel.Controls.Add(this.informationLabel); this.dateTimeMaskedTextBoxPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.dateTimeMaskedTextBoxPanel.Location = new System.Drawing.Point(472, 824); + this.dateTimeMaskedTextBoxPanel.Location = new System.Drawing.Point(472, 778); this.dateTimeMaskedTextBoxPanel.Name = "dateTimeMaskedTextBoxPanel"; - this.dateTimeMaskedTextBoxPanel.Size = new System.Drawing.Size(463, 134); + this.dateTimeMaskedTextBoxPanel.Size = new System.Drawing.Size(463, 180); this.dateTimeMaskedTextBoxPanel.TabIndex = 1; // + // informationPanel + // + this.informationPanel.Controls.Add(this.errorLabel); + this.informationPanel.Controls.Add(this.addRecordButton); + this.informationPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.informationPanel.Location = new System.Drawing.Point(1410, 778); + this.informationPanel.Name = "informationPanel"; + this.informationPanel.Size = new System.Drawing.Size(463, 180); + this.informationPanel.TabIndex = 25; + // // errorLabel // this.errorLabel.AutoSize = true; this.errorLabel.ForeColor = System.Drawing.Color.Maroon; - this.errorLabel.Location = new System.Drawing.Point(3, 31); + this.errorLabel.Location = new System.Drawing.Point(-1, 7); this.errorLabel.Name = "errorLabel"; - this.errorLabel.Size = new System.Drawing.Size(108, 25); + this.errorLabel.Size = new System.Drawing.Size(0, 25); this.errorLabel.TabIndex = 28; - this.errorLabel.Text = "Errors here"; - // - // weekEndingMaskedTextBox - // - this.weekEndingMaskedTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.weekEndingMaskedTextBox.Location = new System.Drawing.Point(277, 3); - this.weekEndingMaskedTextBox.Mask = "00/00/0000"; - this.weekEndingMaskedTextBox.Name = "weekEndingMaskedTextBox"; - this.weekEndingMaskedTextBox.Size = new System.Drawing.Size(115, 31); - this.weekEndingMaskedTextBox.TabIndex = 3; - this.weekEndingMaskedTextBox.ValidatingType = typeof(System.DateTime); - // - // weekEndingMaskedTextBoxInstructionLabel - // - this.weekEndingMaskedTextBoxInstructionLabel.AutoSize = true; - this.weekEndingMaskedTextBoxInstructionLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.142858F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.weekEndingMaskedTextBoxInstructionLabel.Location = new System.Drawing.Point(16, 6); - this.weekEndingMaskedTextBoxInstructionLabel.Name = "weekEndingMaskedTextBoxInstructionLabel"; - this.weekEndingMaskedTextBoxInstructionLabel.Size = new System.Drawing.Size(245, 25); - this.weekEndingMaskedTextBoxInstructionLabel.TabIndex = 0; - this.weekEndingMaskedTextBoxInstructionLabel.Text = "... or manually enter it here:\r\n"; - // - // informationPanel - // - this.informationPanel.Controls.Add(this.addRecordButton); - this.informationPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.informationPanel.Location = new System.Drawing.Point(1410, 824); - this.informationPanel.Name = "informationPanel"; - this.informationPanel.Size = new System.Drawing.Size(463, 134); - this.informationPanel.TabIndex = 25; - // - // informationLabel - // - this.informationLabel.AutoSize = true; - this.informationLabel.Location = new System.Drawing.Point(1014, 26); - this.informationLabel.Name = "informationLabel"; - this.informationLabel.Size = new System.Drawing.Size(152, 25); - this.informationLabel.TabIndex = 27; - this.informationLabel.Text = "Information here"; // // 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(287, 84); + this.addRecordButton.Location = new System.Drawing.Point(287, 130); this.addRecordButton.Name = "addRecordButton"; this.addRecordButton.Size = new System.Drawing.Size(167, 41); this.addRecordButton.TabIndex = 26; @@ -1017,10 +979,10 @@ this.taxableTabPage.ResumeLayout(false); this.taxableTabPage.PerformLayout(); this.dateGroupBox.ResumeLayout(false); - this.dateGroupBox.PerformLayout(); this.dateTimeMaskedTextBoxPanel.ResumeLayout(false); this.dateTimeMaskedTextBoxPanel.PerformLayout(); this.informationPanel.ResumeLayout(false); + this.informationPanel.PerformLayout(); this.ResumeLayout(false); } @@ -1088,11 +1050,8 @@ private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage weeklySalesTabPage; private System.Windows.Forms.TabPage taxableTabPage; - private System.Windows.Forms.Label monthCalendarInstructionsLabel; - private System.Windows.Forms.MonthCalendar weekEndingMonthCalendar; + private System.Windows.Forms.MonthCalendar weekEndingCalendar; private System.Windows.Forms.Panel dateTimeMaskedTextBoxPanel; - private System.Windows.Forms.MaskedTextBox weekEndingMaskedTextBox; - private System.Windows.Forms.Label weekEndingMaskedTextBoxInstructionLabel; private System.Windows.Forms.TabPage debugTabPage; private System.Windows.Forms.Panel informationPanel; private System.Windows.Forms.Label errorLabel; diff --git a/AdvertsingProfitControl/NewAddRecord.cs b/AdvertsingProfitControl/NewAddRecord.cs index 9b284ad..05ddc16 100644 --- a/AdvertsingProfitControl/NewAddRecord.cs +++ b/AdvertsingProfitControl/NewAddRecord.cs @@ -50,8 +50,6 @@ namespace AdvertsingProfitControl //Assign the events for the comments text box and display the remaining character count for the user. commentsTextBox.TextChanged += DisplayRemainingCommentCharacterCount; commentsGroupBox.Text = @"Comments (Characters Remaining: " + commentsTextBox.MaxLength + @")"; - //Set up the event for when the masked text box looses focus. - weekEndingMaskedTextBox.LostFocus += UpdateCalendarOnFocusLost; //Setup the events for that the Projected and Actual Sales DataGridViews will share. //Events are assigned with regard to which event gets triggered first and so on.. //Hook the row add event so we can paint a row number in the header cell of the row. @@ -881,8 +879,13 @@ namespace AdvertsingProfitControl case (int)SalesTableColumns.IsDirty: rowContents[i] = true; break; + case (int)SalesTableColumns.IsHeaderRow: + rowContents[i] = false; + break; + case (int)SalesTableColumns.IsMemberRow: + rowContents[i] = false; + break; default: - if(i >= (int)SalesTableColumns.IsHeaderRow) continue; rowContents[i] = ""; break; } @@ -903,14 +906,18 @@ namespace AdvertsingProfitControl inventoryNewRow[(int)InventoryTableColumns.AdItem] = projectionsDataGridView.Rows[e.RowIndex].Cells[i].EditedFormattedValue.ToString(); break; - case (int)SalesTableColumns.IsDirty: + case (int)InventoryTableColumns.IsDirty: inventoryNewRow[(int)InventoryTableColumns.IsDirty] = true; break; + case (int)InventoryTableColumns.IsHeaderRow: + inventoryNewRow[(int)InventoryTableColumns.IsHeaderRow] = false; + break; + case (int)InventoryTableColumns.IsMemberRow: + inventoryNewRow[(int)InventoryTableColumns.IsMemberRow] = false; + break; default: - if (i < (int) InventoryTableColumns.IsHeaderRow) - { - inventoryNewRow[i] = ""; - } + if(i > (int)InventoryTableColumns.IsHeaderRow) continue; + inventoryNewRow[i] = ""; break; } } @@ -1185,11 +1192,13 @@ namespace AdvertsingProfitControl case (int)SalesTableColumns.IsDirty: rowContents[i] = true; break; + case (int)SalesTableColumns.IsHeaderRow: + rowContents[i] = false; + break; + case (int)SalesTableColumns.IsMemberRow: + rowContents[i] = false; + break; default: - if (i >= (int) InventoryTableColumns.IsHeaderRow) - { - continue; - } rowContents[i] = ""; break; } @@ -1337,8 +1346,13 @@ namespace AdvertsingProfitControl case (int)SalesTableColumns.IsDirty: rowContents[i] = true; break; + case (int)SalesTableColumns.IsHeaderRow: + rowContents[i] = false; + break; + case (int)SalesTableColumns.IsMemberRow: + rowContents[i] = false; + break; default: - if (i >= (int)SalesTableColumns.IsHeaderRow) continue; rowContents[i] = ""; break; } @@ -1359,11 +1373,15 @@ namespace AdvertsingProfitControl case (int)SalesTableColumns.IsDirty: inventoryNewRow[(int)InventoryTableColumns.IsDirty] = true; break; + case (int)InventoryTableColumns.IsHeaderRow: + inventoryNewRow[(int)InventoryTableColumns.IsHeaderRow] = false; + break; + case (int)InventoryTableColumns.IsMemberRow: + inventoryNewRow[(int)InventoryTableColumns.IsMemberRow] = false; + break; default: - if (i > (int)InventoryTableColumns.AdItem && i < (int)InventoryTableColumns.IsHeaderRow || i == (int)InventoryTableColumns.Id) - { - inventoryNewRow[i] = ""; - } + if (i > (int)InventoryTableColumns.IsHeaderRow) continue; + inventoryNewRow[i] = ""; break; } } @@ -1844,114 +1862,29 @@ namespace AdvertsingProfitControl #endregion #region DateTime Events - /// - /// Updates the week ending masked text box with the selected date - /// using the format (MM/DD/YYYY). - /// - /// - /// - private void UpdateWeekEndingMaskedTextBox(object sender, DateRangeEventArgs e) - { - var selectedDate = weekEndingMonthCalendar.SelectionStart; - if (!selectedDate.ToString("D").StartsWith("Saturday")) - { - weekEndingMaskedTextBox.ForeColor = Color.Maroon; - weekEndingMaskedTextBoxInstructionLabel.Text = @"... or manually enter it here: *"; - errorLabel.Text = @"* The date you selected does not appear to be a week ending date."; - } - else - { - weekEndingMaskedTextBox.ForeColor = Color.Black; - weekEndingMaskedTextBoxInstructionLabel.Text = @"... or manually enter it here:"; - errorLabel.Text = ""; - } - - weekEndingMaskedTextBox.Text = selectedDate.ToString("MM-dd-yyyy"); - } - /// - /// Event Used: LostFocus - /// Attempts to set the selected date of the calendar to the date that - /// has been entered into the masked text box. - /// - /// - /// - private void UpdateCalendarOnFocusLost(object sender, EventArgs e) - { - //Replace any white space with zeros to pad out the mask. - weekEndingMaskedTextBox.Text = weekEndingMaskedTextBox.Text.Replace("/", ""); - DateTime date; - //Try parsing the contents of the masked text box to see if the date is valid. - if (DateTime.TryParse(weekEndingMaskedTextBox.Text, out date)) - { - //Update the text box's text with a nicely formatted date. - weekEndingMaskedTextBox.Text = date.ToString("MM/dd/yyyy"); - //If it is update the calendar with the manually entered date. - weekEndingMonthCalendar.SelectionStart = date; - } - else - { - //Otherwise throw an error to day that the date isn't valid and clear the text box. - MessageBox.Show(@"The date entered appears to be invalid.", @"Invalid Date", MessageBoxButtons.OK, MessageBoxIcon.Error); - weekEndingMaskedTextBox.Text = ""; - } - } #endregion private void AddRecordsButtonClick(object sender, EventArgs e) { - //Make sure the mask in the text box is completed. - if (!weekEndingMaskedTextBox.MaskCompleted) - { - MessageBox.Show(@"A valid date must be specified.", @"Invalid Date", MessageBoxButtons.OK, - MessageBoxIcon.Error); - return; - } - //Create the database interaction objects. var dbT = new DatabaseTracker(); var dbW = new DatabaseWriter(dbT.DatabaseConnectionString); var dbR = new DatabaseReader(); - DateTime dateTime; - //Attempt to parse the date entered to verify it's integrity. - if (DateTime.TryParseExact(weekEndingMaskedTextBox.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture, - DateTimeStyles.None, out dateTime)) - { - //Check to see if the date is before the store was even founded, though I think a date range starting at 2014 would work but eh. - if (dateTime.Year < 1958) - { - var result = - MessageBox.Show( - @"Fairly certain Allen's wasn't even founded at this time... Maybe try another date or year at least?", - @"Let Alone Used Computers This Fast", MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (result == DialogResult.Yes) - { - weekEndingMaskedTextBox.Focus(); - return; - } - MessageBox.Show(@"Alright if you insist since technically this date is valid.", - @"Technically Correct Is The Best Correct", MessageBoxButtons.OK); - } - } - else - { - MessageBox.Show(@"The date " + weekEndingMaskedTextBox.Text + @" is an invalid date.", @"Invalid Date", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } //Obtain the date ID. int dateId; if ( - int.TryParse(dbR.RetrieveDateIdByDateString(dateTime.ToString("MM/dd/yyyy"), + int.TryParse(dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), dbT.DatabaseConnectionString), out dateId)) { //If the ID is zero (0) that means the date isn't in the database so simply insert it. if (dateId == 0) { //Try inserting the date string. - if (dbW.InsertIntoWeekEnding(dateTime.ToString("MM/dd/yyyy"))) + if (dbW.InsertIntoWeekEnding(weekEndingCalendar.SelectionStart.ToString("d"))) { if ( int.TryParse( - dbR.RetrieveDateIdByDateString(dateTime.ToString("MM/dd/yyyy"), + dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), dbT.DatabaseConnectionString), out dateId)) { //Now if its still zero (0) then that means something went really wrong and failed to insert. @@ -1974,24 +1907,17 @@ namespace AdvertsingProfitControl else { //The above method reports that it failed to insert the date into the database. - MessageBox.Show(@"Failed insert the date " + weekEndingMaskedTextBox.Text + @" into the database.", @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(@"Failed to insert the date '" + weekEndingCalendar.SelectionStart.ToString("d") + @"' into the database.", @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } - else - { - //Seriously don't think this will happen, but eh might as well. - MessageBox.Show( - @"You really should not be able to see this message. If you are well that means something really weird happened converting text into a number, that is hard-coded to not fail on conversion. Either way I couldn't get the date ID due to some error, check the logs if you're curious.", - @"Well This Is Awkward...", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } + informationLabel.Text = ""; //Run the row parsing engine on all the APC tables. + //Create the cleaned table objects that will be sent to the database. DataTable trimmedTable; DataTable updateTable; - informationLabel.Text = @"Compressing data tables..." + Environment.NewLine; errorLabel.Text = ""; var operationStatus = ConstructCleanedSalesTable("Projections", dateId, out trimmedTable, out updateTable); if (operationStatus == TrimmingOperationResult.FailedToTrim) @@ -1999,45 +1925,75 @@ namespace AdvertsingProfitControl errorLabel.Text = @"Failed to trim the Projections table."; return; } - if (!ProcessTrimmingStatusResult(projectionsDataGridView, "Projections", operationStatus, trimmedTable, updateTable)) return; - trimmedTable.Rows.Clear(); - updateTable.Rows.Clear(); - operationStatus = ConstructCleanedInventoryTable(dateId, out trimmedTable, out updateTable); - if (operationStatus == TrimmingOperationResult.FailedToTrim) + if (ProcessTrimmingStatusResult(projectionsDataGridView, "Projections", operationStatus, trimmedTable, updateTable)) { - errorLabel.Text = @"Failed to trim the Inventory table."; - return; + trimmedTable.Rows.Clear(); + updateTable.Rows.Clear(); + operationStatus = ConstructCleanedInventoryTable(dateId, out trimmedTable, out updateTable); + if (operationStatus == TrimmingOperationResult.FailedToTrim) + { + errorLabel.Text = @"Failed to trim the Inventory table."; + //Delete the Projections table. + dbW.DeleteApcDataEntriesByDate("Projections", dateId, dbT.DatabaseConnectionString); + } + else + { + //Add the Inventory table to the database. + if (ProcessTrimmingStatusForInventory(operationStatus, trimmedTable, updateTable)) + { + trimmedTable.Rows.Clear(); + updateTable.Rows.Clear(); + operationStatus = ConstructCleanedSalesTable("ActualSales", dateId, out trimmedTable, + out updateTable); + if (operationStatus == TrimmingOperationResult.FailedToTrim) + { + errorLabel.Text = @"Failed to trim the Actual Sales table."; + //Delete the Projections table and the Inventory table. + dbW.DeleteApcDataEntriesByDate("Projections", dateId, dbT.DatabaseConnectionString); + dbW.DeleteApcDataEntriesByDate("Inventory", dateId, dbT.DatabaseConnectionString); + } + else + { + if (!ProcessTrimmingStatusResult(actualSalesDataGridView, "ActualSales", operationStatus, trimmedTable, updateTable)) + { + //Delete the Projections and Inventory table. + dbW.DeleteApcDataEntriesByDate("Projections", dateId, dbT.DatabaseConnectionString); + dbW.DeleteApcDataEntriesByDate("Inventory", dateId, dbT.DatabaseConnectionString); + } + } + } + else + { + //Delete the Projections table. + dbW.DeleteApcDataEntriesByDate("Projections", dateId, dbT.DatabaseConnectionString); + } + } } - if (!ProcessTrimmingStatusForInventory(operationStatus, trimmedTable, updateTable)) return; - trimmedTable.Rows.Clear(); - updateTable.Rows.Clear(); - operationStatus = ConstructCleanedSalesTable("ActualSales", dateId, out trimmedTable, out updateTable); - if (operationStatus == TrimmingOperationResult.FailedToTrim) - { - errorLabel.Text = @"Failed to trim the Actual Sales table."; - return; - } - if (!ProcessTrimmingStatusResult(actualSalesDataGridView, "ActualSales", operationStatus, trimmedTable, updateTable)) return; //Commit the Invoice table to the database. var writerStatus = dbW.ProccessInvoiceTable(invoicesDataGridView, dateId, dbT.DatabaseConnectionString); if (writerStatus.GetWritingOperationStatus() == WritingOperationStatus.Failed) { + informationLabel.Text += @"Failed to add Invoices to the database."; errorLabel.Text = writerStatus.GetErrorMessage(); } + else + { + informationLabel.Text += writerStatus.GetErrorMessage() + Environment.NewLine; + } //TODO: If the comments are null but there is a comment ID, delete the comments from the database. if (isCommentDirtyCheckBox.Checked) - { + { if (isCommentDirtyCheckBox.Tag == null) { - informationLabel.Text += @"Inserting Comment(s)."; var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString); if (status.Status == WritingOperationStatus.Failed) { + informationLabel.Text += @"Failed to add Comments to the database." + Environment.NewLine; errorLabel.Text = status.ErrorMessage; } else { - informationLabel.Text += @"Comment(s) processed successfully."; + informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine; var id = status.Id; isCommentDirtyCheckBox.Tag = id; isCommentDirtyCheckBox.Text = @"IsCommentDirty (" + id + @")"; @@ -2048,19 +2004,24 @@ namespace AdvertsingProfitControl { //Check for a null comment box and delete the comment ID from the database. //Then if all is successful clear the Tag in the isCommentsDirty check box. - informationLabel.Text += @"Updating Comment(s)."; - var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString, int.Parse(isCommentDirtyCheckBox.Tag.ToString())); + var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString, + int.Parse(isCommentDirtyCheckBox.Tag.ToString())); if (status.Status == WritingOperationStatus.Failed) { + informationLabel.Text += @"Failed to add Comments to the database." + Environment.NewLine; errorLabel.Text = status.ErrorMessage; } else { isCommentDirtyCheckBox.Checked = false; - informationLabel.Text += @"Comment(s) processed successfully."; + informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine; } } } + else + { + informationLabel.Text += @"No changes detected for the comment(s)" + Environment.NewLine; + } //Begin checking the Weekly Sales. if (isWeeklySalesDirtyCheckBox.Checked) { @@ -2070,23 +2031,27 @@ namespace AdvertsingProfitControl weeklySales[1] = mondayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(mondayWeeklySalesTextBox.Text); weeklySales[2] = tuesdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(tuesdayWeeklySalesTextBox.Text); weeklySales[3] = wednesdayTaxableTextBox.Text == "" ? 0 : double.Parse(wednesdayWeeklySalesTextBox.Text); - weeklySales[4] = thursdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(thursdayWeeklySalesTextBox.Text); + weeklySales[4] = thursdayWeeklySalesTextBox.Text == "" + ? 0 + : double.Parse(thursdayWeeklySalesTextBox.Text); weeklySales[5] = fridayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(fridayWeeklySalesTextBox.Text); - weeklySales[6] = saturdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(saturdayWeeklySalesTextBox.Text); + weeklySales[6] = saturdayWeeklySalesTextBox.Text == "" + ? 0 + : double.Parse(saturdayWeeklySalesTextBox.Text); weeklySales[7] = totalWeeklySalesTextBox.Text == "" ? 0 : double.Parse(totalWeeklySalesTextBox.Text); if (isWeeklySalesDirtyCheckBox.Tag == null) { //Weekly sales is not in the database. - informationLabel.Text += @"Inserting weekly sales..."; var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString); if (status.Status == WritingOperationStatus.Failed) { + informationLabel.Text += @"Failed to add Weekly Sales to the database." + Environment.NewLine; errorLabel.Text = status.ErrorMessage; } else { - informationLabel.Text += @"Weekly Sales processed successfully."; + informationLabel.Text += @"Weekly Sales processed successfully." + Environment.NewLine; isWeeklySalesDirtyCheckBox.Tag = status.Id; isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty (" + status.Id + @")"; isWeeklySalesDirtyCheckBox.Checked = false; @@ -2094,19 +2059,24 @@ namespace AdvertsingProfitControl } else { - informationLabel.Text += @"Updating Weekly Sales."; - var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString, int.Parse(isWeeklySalesDirtyCheckBox.Tag.ToString())); + var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString, + int.Parse(isWeeklySalesDirtyCheckBox.Tag.ToString())); if (status.Status == WritingOperationStatus.Failed) { + informationLabel.Text += @"Failed to add Weekly Sales to the database." + Environment.NewLine; errorLabel.Text = status.ErrorMessage; } else { isWeeklySalesDirtyCheckBox.Checked = false; - informationLabel.Text += @"Weekly Sales updated successfully."; + informationLabel.Text += @"Weekly Sales updated successfully." + Environment.NewLine; } } } + else + { + informationLabel.Text += @"No changes detected for Weekly Sales." + Environment.NewLine; + } //Begin checking the Taxable. if (isTaxableDirtyCheckBox.Checked) { @@ -2124,15 +2094,15 @@ namespace AdvertsingProfitControl if (isTaxableDirtyCheckBox.Tag == null) { //Weekly sales is not in the database. - informationLabel.Text += @"Inserting Taxable..."; var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString); if (status.Status == WritingOperationStatus.Failed) { + informationLabel.Text += @"Failed to add Taxable to the database." + Environment.NewLine; errorLabel.Text = status.ErrorMessage; } else { - informationLabel.Text += @"Taxable processed successfully."; + informationLabel.Text += @"Taxable processed successfully." + Environment.NewLine; isTaxableDirtyCheckBox.Tag = status.Id; isTaxableDirtyCheckBox.Text = @"IsTaxableDirty (" + status.Id + @")"; isTaxableDirtyCheckBox.Checked = false; @@ -2140,19 +2110,24 @@ namespace AdvertsingProfitControl } else { - informationLabel.Text += @"Updating Taxable."; - var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString, int.Parse(isTaxableDirtyCheckBox.Tag.ToString())); + var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString, + int.Parse(isTaxableDirtyCheckBox.Tag.ToString())); if (status.Status == WritingOperationStatus.Failed) { + informationLabel.Text += @"Failed to add Taxable to the database." + Environment.NewLine; errorLabel.Text = status.ErrorMessage; } else { isTaxableDirtyCheckBox.Checked = false; - informationLabel.Text += @"Taxable updated successfully."; + informationLabel.Text += @"Taxable updated successfully." + Environment.NewLine; } } } + else + { + informationLabel.Text += @"No changes detected for Taxable." + Environment.NewLine; + } //Begin checking cost analysis. if (isCostAnalysisDirtyCheckBox.Checked) { @@ -2166,15 +2141,15 @@ namespace AdvertsingProfitControl if (isCostAnalysisDirtyCheckBox.Tag == null) { //Weekly sales is not in the database. - informationLabel.Text += @"Inserting Cost Analysis..."; var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString); if (status.Status == WritingOperationStatus.Failed) { + informationLabel.Text += @"Failed to add Cost Analysis to the database."; errorLabel.Text = status.ErrorMessage; } else { - informationLabel.Text += @"Costs analysis processed successfully."; + informationLabel.Text += @"Costs Analysis processed successfully."; isCostAnalysisDirtyCheckBox.Tag = status.Id; isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty (" + status.Id + @")"; isCostAnalysisDirtyCheckBox.Checked = false; @@ -2182,19 +2157,24 @@ namespace AdvertsingProfitControl } else { - informationLabel.Text += @"Updating cost analysis."; - var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString, int.Parse(isCostAnalysisDirtyCheckBox.Tag.ToString())); + var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString, + int.Parse(isCostAnalysisDirtyCheckBox.Tag.ToString())); if (status.Status == WritingOperationStatus.Failed) { + informationLabel.Text += @"Failed to add Cost Analysis to the database."; errorLabel.Text = status.ErrorMessage; } else { isCostAnalysisDirtyCheckBox.Checked = false; - informationLabel.Text += @"Cost analysis updated successfully."; + informationLabel.Text += @"Cost Analysis updated successfully."; } } } + else + { + informationLabel.Text += @"No changes made to Cost Analysis."; + } //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. @@ -2672,11 +2652,10 @@ namespace AdvertsingProfitControl switch (operationStatus) { case TrimmingOperationResult.NoChangesRequired: - informationLabel.Text += Environment.NewLine + @"No changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table detected."; + informationLabel.Text += @"No changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table detected." + Environment.NewLine; successful = true; break; case TrimmingOperationResult.CreatedNewInsertionTable: - informationLabel.Text += Environment.NewLine + @"Inserting new changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table."; dbWriterStatus = dbW.InsertIntoSalesTable(trimmedTable, dbT.DatabaseConnectionString); if (dbWriterStatus.GetErrorMessage() == string.Empty) { @@ -2685,17 +2664,17 @@ namespace AdvertsingProfitControl { dataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.Id].Value = rowIndex.Value; dataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value = false; + dataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } - informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database."; + informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database." + Environment.NewLine; successful = true; } else { - errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database."; + errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database." + Environment.NewLine; } break; case TrimmingOperationResult.CreatedUpdateTable: - informationLabel.Text += Environment.NewLine + @"Updating changes made to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table."; dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString); if (dbWriterStatus.GetErrorMessage() == string.Empty) { @@ -2704,35 +2683,36 @@ namespace AdvertsingProfitControl { //Only reset the IsDirty value to false since the updates when through. dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false; + dataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } - informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated."; + informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated." + Environment.NewLine; successful = true; } else { - errorLabel.Text = @"Failed to update the " + trimmedTable + @" table."; + errorLabel.Text = @"Failed to update the " + trimmedTable + @" table." + Environment.NewLine; } break; case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables: //Insert the new values... - informationLabel.Text += Environment.NewLine + @"Inserting new changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table."; dbWriterStatus = dbW.InsertIntoSalesTable(trimmedTable, dbT.DatabaseConnectionString); if (dbWriterStatus.GetErrorMessage() == string.Empty) { //Spin through the collection and update the affected rows. foreach (var rowIndex in dbWriterStatus.GetRowCollection()) { + //Add the ID numbers to the first column since these are new additions to the database. dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.Id].Value = rowIndex.Value; dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false; + dataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } - informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database."; + informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database." + Environment.NewLine; } else { - errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database."; + errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database." + Environment.NewLine; } //... and update the existing values. - informationLabel.Text += Environment.NewLine + @"Updating changes made to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table."; dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString); if (dbWriterStatus.GetErrorMessage() == string.Empty) { @@ -2741,13 +2721,14 @@ namespace AdvertsingProfitControl { //Only reset the IsDirty value to false since the updates when through. dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false; + dataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } - informationLabel.Text += Environment.NewLine + TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated."; + informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated." + Environment.NewLine; successful = true; } else { - errorLabel.Text = @"Failed to update the " + trimmedTable + @" table."; + errorLabel.Text = @"Failed to update the " + trimmedTable + @" table." + Environment.NewLine; } break; } @@ -2765,11 +2746,10 @@ namespace AdvertsingProfitControl switch (operationStatus) { case TrimmingOperationResult.NoChangesRequired: - informationLabel.Text += Environment.NewLine + @"No changes to the Inventory table detected."; + informationLabel.Text += @"No changes to the Inventory table detected." + Environment.NewLine; successful = true; break; case TrimmingOperationResult.CreatedNewInsertionTable: - informationLabel.Text += Environment.NewLine + @"Inserting new changes to the Inventory table."; dbWriterStatus = dbW.InsertIntoInventoryTable(trimmedTable, dbT.DatabaseConnectionString); if (dbWriterStatus.GetErrorMessage() == string.Empty) { @@ -2778,17 +2758,17 @@ namespace AdvertsingProfitControl { inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.Id].Value = rowIndex.Value; inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false; + inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } - informationLabel.Text += Environment.NewLine + @"Inventory table successfully added to the database."; + informationLabel.Text += @"Inventory table successfully added to the database." + Environment.NewLine; successful = true; } else { - errorLabel.Text = @"Failed to insert Inventory table into the database."; + errorLabel.Text = @"Failed to insert Inventory table into the database." + Environment.NewLine; } break; case TrimmingOperationResult.CreatedUpdateTable: - informationLabel.Text += Environment.NewLine + @"Updating changes made to the Inventory table."; dbWriterStatus = dbW.UpdateInventoryTable(updateTable, dbT.DatabaseConnectionString); if (dbWriterStatus.GetErrorMessage() == string.Empty) { @@ -2797,33 +2777,35 @@ namespace AdvertsingProfitControl { //Only reset the IsDirty value to false since the updates when through. inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false; + inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } - informationLabel.Text += Environment.NewLine + @"Inventory table successfully updated."; + informationLabel.Text += @"Inventory table successfully updated." + Environment.NewLine; successful = true; } else { - errorLabel.Text = @"Failed to update the changes in the Inventory table."; + errorLabel.Text = @"Failed to update the changes in the Inventory table." + Environment.NewLine; } break; case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables: //Insert the new values... - informationLabel.Text += Environment.NewLine + @"Inserting new changes to the Inventory table."; dbWriterStatus = dbW.InsertIntoInventoryTable(trimmedTable, dbT.DatabaseConnectionString); if (dbWriterStatus.GetErrorMessage() == string.Empty) { //Spin through the collection and update the affected rows. foreach (var rowIndex in dbWriterStatus.GetRowCollection()) { + //Add the ID numbers to the first column since these are new additions to the database. inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.Id].Value = rowIndex.Value; inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false; + inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } - informationLabel.Text += Environment.NewLine + @"Inventory table successfully added to the database."; + informationLabel.Text += @"Inventory table successfully added to the database." + Environment.NewLine; successful = true; } else { - errorLabel.Text = @"Failed to insert Inventory table into the database."; + errorLabel.Text = @"Failed to insert Inventory table into the database." + Environment.NewLine; } dbWriterStatus = dbW.UpdateInventoryTable(updateTable, dbT.DatabaseConnectionString); if (dbWriterStatus.GetErrorMessage() == string.Empty) @@ -2832,15 +2814,15 @@ namespace AdvertsingProfitControl foreach (var rowIndex in dbWriterStatus.GetRowCollection()) { //Only reset the IsDirty value to false since the updates when through. - inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int) InventoryTableColumns.IsDirty] - .Value = false; + inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int) InventoryTableColumns.IsDirty].Value = false; + inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } - informationLabel.Text += Environment.NewLine + @"Inventory table successfully updated."; + informationLabel.Text += @"Inventory table successfully updated." + Environment.NewLine; successful = true; } else { - errorLabel.Text = @"Failed to update the changes in the Inventory table."; + errorLabel.Text = @"Failed to update the changes in the Inventory table." + Environment.NewLine; } break; } diff --git a/AdvertsingProfitControl/NewAddRecord.resx b/AdvertsingProfitControl/NewAddRecord.resx index ed00b2b..ad2c550 100644 --- a/AdvertsingProfitControl/NewAddRecord.resx +++ b/AdvertsingProfitControl/NewAddRecord.resx @@ -120,9 +120,6 @@ 17, 17 - - 17, 17 - diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application index c456705..3e737ce 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application @@ -14,7 +14,7 @@ - 0ciZORzVO0teig7ltOqRbCAT8SY4vWnHXeZQzuXDQso= + awuF53zQVe9V3zUNL3d5T6YCMzmHhsse6PclfUp46TM= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest index 7b7887d..b99ead8 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest @@ -43,14 +43,14 @@ - + - J37ovQ2w2uLSWexQjta/p83ZtKKy+IC5/Dlnu814/qs= + UU8qwZxBBKymnYncKNbRY9vyIqD6hwiqMecESA476/8= @@ -84,7 +84,7 @@ - OTOg6k+3pem3uA+Xpy/Nu0Ifwo+hXeYq3hn83njXnT4= + vIWbpHhaPK+/SPRL5GUWOfjJsfzpB/rCMLUdLPlUB+s=