diff --git a/AdvertsingProfitControl/APCDatabase.accdb b/AdvertsingProfitControl/APCDatabase.accdb index c2715fb..caa1630 100644 Binary files a/AdvertsingProfitControl/APCDatabase.accdb and b/AdvertsingProfitControl/APCDatabase.accdb differ diff --git a/AdvertsingProfitControl/DatabaseReader.cs b/AdvertsingProfitControl/DatabaseReader.cs index 38c39b9..926d927 100644 --- a/AdvertsingProfitControl/DatabaseReader.cs +++ b/AdvertsingProfitControl/DatabaseReader.cs @@ -37,6 +37,7 @@ namespace AdvertsingProfitControl } #region Date Functions + /// /// 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=