From 02fbc253d64938fa275350b9d20095f55aa79b05 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Sat, 18 Feb 2017 02:33:57 -0600 Subject: [PATCH] Updated the SaveRecord method to detect if a date is already in the database. It now selects the next available week after prompting the user. Changed the behavior of the create new record menu item to select the week after the most recent date based on the year that is being worked on. --- AdvertsingProfitControl/APCDatabase.accdb | Bin 864256 -> 864256 bytes AdvertsingProfitControl/DatabaseReader.cs | 11 +++++- AdvertsingProfitControl/NewModifyRecord.cs | 36 +++++++++++++++--- .../Properties/AssemblyInfo.cs | 4 +- ...AdvertsingProfitControl.vshost.application | 2 +- ...dvertsingProfitControl.vshost.exe.manifest | 10 ++--- 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/AdvertsingProfitControl/APCDatabase.accdb b/AdvertsingProfitControl/APCDatabase.accdb index c2715fbcacafc722eb3ba7a3224fce9c3a6c92d3..caa1630745042c7e379a58dbab35f379604e4a1a 100644 GIT binary patch delta 141 zcmZp8VAAlwWCIf)^DY+E&4PUI87C|7@iYl+6JR{S$F}QJgAenQ>F4AaB^XQEpUW|} zKbK=_e=f(|{#=fw{ka_L_UCeJHv<@X+7ITlwI9r9Z$FsN(S9(Wv;AN`SNp+y?(GNj xc^n&fE^_&VIr=a#Fff!dOc(gTb8Wi92OgpA&pz<*Fi*G4;1b&|@rCDwH2{u`G_n8y delta 139 zcmZp8VAAlwWCIf)^E?*S&4PUI87C|7@iYl+6JR{S#};GxF)`}#^mB5I5{x /// Retrieves the most recent date's ID from the database. /// @@ -44,11 +45,12 @@ namespace AdvertsingProfitControl /// The ID number as a string. public int RetrieveMostRecentDateId(string connectionString) { - int dateId = 0; + var dateId = 0; var oleDbCommand = new OleDbCommand { CommandText = "SELECT WeekEnding.ID FROM WeekEnding WHERE WeekEnding.EndOfWeekDate = (SELECT MAX(WeekEnding.EndOfWeekDate) FROM WeekEnding)" }; + var connection = new OleDbConnection(connectionString); oleDbCommand.Connection = connection; @@ -70,13 +72,18 @@ namespace AdvertsingProfitControl return dateId; } - public DateTime RetrieveMostRecentDate(string connectionString) + public DateTime RetrieveMostRecentDate(string connectionString, int year = 0) { var date = new DateTime(); var oleDbCommand = new OleDbCommand { CommandText = "SELECT WeekEnding.EndOfWeekDate FROM WeekEnding WHERE WeekEnding.EndOfWeekDate = (SELECT MAX(WeekEnding.EndOfWeekDate) FROM WeekEnding)" }; + if (year != 0) + { + oleDbCommand.CommandText = "SELECT WeekEnding.EndOfWeekDate FROM WeekEnding WHERE WeekEnding.EndOfWeekDate = (SELECT MAX(WeekEnding.EndOfWeekDate) FROM WeekEnding WHERE YEAR(WeekEnding.EndOfWeekDate) = ?)"; + oleDbCommand.Parameters.AddWithValue("Year", year); + } var connection = new OleDbConnection(connectionString); oleDbCommand.Connection = connection; diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs index 50d3e70..e3d3cba 100644 --- a/AdvertsingProfitControl/NewModifyRecord.cs +++ b/AdvertsingProfitControl/NewModifyRecord.cs @@ -156,8 +156,7 @@ namespace AdvertsingProfitControl suppliesTextBox.Enter += StoreBeginningTextBoxValue; suppliesTextBox.Validating += ValidateCostAnalysisValues; // - //_debugTabPage = mainTabControl.TabPages[4]; - //mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]); + mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]); Text = @"Modify Record (Current Record: " + date.ToShortDateString() + @")"; _formRoll = FormRoll.ModifyRecord; LoadDate(date); @@ -280,7 +279,7 @@ namespace AdvertsingProfitControl suppliesTextBox.Validating += ValidateCostAnalysisValues; // //_debugTabPage = mainTabControl.TabPages[4]; - //mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]); + mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]); Text = @"Add New Record (Current Record: " + _currentActiveDate.ToShortDateString() + @")"; _formRoll = FormRoll.AddRecord; addRecordButton.Text = @"Add Record"; @@ -3622,6 +3621,33 @@ namespace AdvertsingProfitControl { SetNewRecordDate(_currentActiveDate); _currentActiveDate = weekEndingCalendar.SelectionStart; + //See if the date is in the database already. + if (weekEndingCalendar.BoldedDates.Contains(_currentActiveDate)) + { + //Loop till we hit a date not in the system. + var weekAhead = 1; + while (weekEndingCalendar.BoldedDates.Contains(_currentActiveDate.AddDays(7 * weekAhead))) + { + + weekAhead++; + } + var result = MessageBox.Show(@"The date " + _currentActiveDate.ToShortDateString() + @" is already in the database. Did you mean to select " + _currentActiveDate.AddDays(7 * weekAhead).ToShortDateString() + @" instead?", @"", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + if (result == DialogResult.Yes) + { + _currentActiveDate = _currentActiveDate.AddDays(7 * weekAhead); + weekEndingCalendar.SelectionStart = _currentActiveDate; + } + else if (result == DialogResult.No) + { + errorLabel.Text = _currentActiveDate.ToShortDateString() + + @" must be loaded before modifications can be made to it."; + return false; + } + else + { + return false; + } + } } var dateId = GetDateId(_currentActiveDate.ToString("d")); if (dateId == 0) @@ -4363,7 +4389,7 @@ namespace AdvertsingProfitControl return TrimmingOperationResult.CreatedNewInsertionAndUpdateTables; } - #endregion + #endregion private void addRecordButton_Click(object sender, EventArgs e) { @@ -4405,7 +4431,7 @@ namespace AdvertsingProfitControl addRecordButton.Text = @"Add Record"; var databaseTracker = new DatabaseTracker(); var databaseReader = new DatabaseReader(); - _currentActiveDate = databaseReader.RetrieveMostRecentDate(databaseTracker.DatabaseConnectionString).AddDays(7); + _currentActiveDate = databaseReader.RetrieveMostRecentDate(databaseTracker.DatabaseConnectionString, _currentActiveDate.Year).AddDays(7); weekEndingCalendar.SelectionStart = _currentActiveDate; Text = @"Add New Record (Current Date: " + _currentActiveDate.ToShortDateString() + @")"; informationLabel.Text = string.Empty; diff --git a/AdvertsingProfitControl/Properties/AssemblyInfo.cs b/AdvertsingProfitControl/Properties/AssemblyInfo.cs index 4423fec..4f627a1 100644 --- a/AdvertsingProfitControl/Properties/AssemblyInfo.cs +++ b/AdvertsingProfitControl/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.3.0")] -[assembly: AssemblyFileVersion("1.9.3.0")] +[assembly: AssemblyVersion("1.10.0.0")] +[assembly: AssemblyFileVersion("1.10.0.0")] diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application index e879498..1589a0c 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application @@ -14,7 +14,7 @@ - wZKyz33oBaTu7LlzGeOCxkM7UGOPV8kZeC+ZUmNCdwY= + 3ChUsEqNUMAjVaBGqxbdYDY0WFTlgEm8k8f2eCP9a18= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest index 826e10a..2e81436 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest @@ -4,7 +4,7 @@ - + @@ -43,14 +43,14 @@ - - + + - Go6lCPrcJgk3GBchewQqB1BCxQhEtIFVMBBGG72lMB8= + mupCCLiyPu/EYkKY9Sc0jm2Z0deNl6wThi2EYMz/tAI= @@ -93,7 +93,7 @@ - bPUdW2UkdkedvUlfZHuxhxUjqrn/LMCowSfDLWqF+4Y= + u8KjFRismEEKveuk50umuN3UTCd1w3Uh6n8Nk4q8yoo=