From b580e48c261696475893402d8b5478aaa40fe47c Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Fri, 17 Feb 2017 04:51:25 -0600 Subject: [PATCH] Updated how the record manipulation form behaves when adding new records, allowing the user to select a new date freely. May be the final update before the Entity Update. --- AdvertsingProfitControl/NewModifyRecord.cs | 108 ++++++++++++++---- .../Properties/AssemblyInfo.cs | 4 +- ...AdvertsingProfitControl.vshost.application | 2 +- ...dvertsingProfitControl.vshost.exe.manifest | 8 +- 4 files changed, 90 insertions(+), 32 deletions(-) diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs index 9208fd6..50d3e70 100644 --- a/AdvertsingProfitControl/NewModifyRecord.cs +++ b/AdvertsingProfitControl/NewModifyRecord.cs @@ -37,7 +37,8 @@ namespace AdvertsingProfitControl private DateTime _currentActiveDate; // private bool _isFormDirty; - + // + private FormRoll _formRoll; public NewModifyRecord(DateTime date) { InitializeComponent(); @@ -158,6 +159,7 @@ namespace AdvertsingProfitControl //_debugTabPage = mainTabControl.TabPages[4]; //mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]); Text = @"Modify Record (Current Record: " + date.ToShortDateString() + @")"; + _formRoll = FormRoll.ModifyRecord; LoadDate(date); } @@ -168,7 +170,7 @@ namespace AdvertsingProfitControl var databaseTracker = new DatabaseTracker(); var databaseReader = new DatabaseReader(); weekEndingCalendar.BoldedDates = databaseReader.RetrieveDates(databaseTracker.DatabaseConnectionString).ToArray(); - SetNewRecordDate(databaseReader.RetrieveMostRecentDate(databaseTracker.DatabaseConnectionString), 2); + SetNewRecordDate(databaseReader.RetrieveMostRecentDate(databaseTracker.DatabaseConnectionString), 1); _currentActiveDate = weekEndingCalendar.SelectionStart; //next pull all the ad items into memory. _adItemCollection = databaseReader.GetAdItemsSuggestionList(databaseTracker.DatabaseConnectionString); @@ -280,6 +282,7 @@ namespace AdvertsingProfitControl //_debugTabPage = mainTabControl.TabPages[4]; //mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]); Text = @"Add New Record (Current Record: " + _currentActiveDate.ToShortDateString() + @")"; + _formRoll = FormRoll.AddRecord; addRecordButton.Text = @"Add Record"; } @@ -2552,38 +2555,79 @@ namespace AdvertsingProfitControl private void ValidateDateChanged(object sender, DateRangeEventArgs e) { - if (e.Start == _currentActiveDate || !weekEndingCalendar.BoldedDates.Contains(e.Start)) return; - //If the form is dirty then prompt the user to save changes. - if (_isFormDirty) + if (e.Start == _currentActiveDate) return; + if (!weekEndingCalendar.BoldedDates.Contains(e.Start)) { - var result = MessageBox.Show(@"Would you like to save the changes you have made to this record?", @"Changes Detected", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (result == DialogResult.Yes) + if (_formRoll == FormRoll.AddRecord) { - //Save the changes made to the database then clear and load the date picked by the user. - if (SaveRecords(false)) + //If the form is dirty then prompt the user to save changes. + if (_isFormDirty) { - informationLabel.Text = @"Saved all changes successfully." + Environment.NewLine; + var result = MessageBox.Show( + @"Would you like to save the changes you have made to this record?", @"Changes Detected", + MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + if (result == DialogResult.Yes) + { + //Save the changes made to the database then clear and load the date picked by the user. + if (SaveRecords(false)) + { + informationLabel.Text = @"Saved all changes successfully." + Environment.NewLine; + } + else + { + errorLabel.Text = @"Failed to save all changes." + Environment.NewLine; + } + } + else if (result == DialogResult.Cancel) + { + //Cancel this method, select the active current date and return. + weekEndingCalendar.SelectionStart = _currentActiveDate; + } + //The "No" button doesn't need to be processed since it just means continue on with the method. } else { - errorLabel.Text = @"Failed to save all changes." + Environment.NewLine; + //Change the active date of the form. + _currentActiveDate = e.Start; + Text = Text = @"Add New Record (Current Record: " + e.Start.ToString("d") + @")"; } } - else if (result == DialogResult.Cancel) - { - //Cancel this method, select the active current date and return. - weekEndingCalendar.SelectionStart = _currentActiveDate; - return; - } - //The "No" button doesn't need to be processed since it just means continue on with the method. } - _currentActiveDate = e.Start; - Text = @"Modify Record (Current Record: " + e.Start.ToString("d") + @")"; - addRecordButton.Text = @"Update Record"; - //Clear the form state. - ClearFormState(); - //Load the specified date from the database. - LoadDate(e.Start); + else + { + //If the form is dirty then prompt the user to save changes. + if (_isFormDirty) + { + var result = MessageBox.Show(@"Would you like to save the changes you have made to this record?", @"Changes Detected", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + if (result == DialogResult.Yes) + { + //Save the changes made to the database then clear and load the date picked by the user. + if (SaveRecords(false)) + { + informationLabel.Text = @"Saved all changes successfully." + Environment.NewLine; + } + else + { + errorLabel.Text = @"Failed to save all changes." + Environment.NewLine; + return; + } + } + else if (result == DialogResult.Cancel) + { + //Cancel this method, select the active current date and return. + weekEndingCalendar.SelectionStart = _currentActiveDate; + return; + } + //The "No" button doesn't need to be processed since it just means continue on with the method. + } + _currentActiveDate = e.Start; + Text = @"Modify Record (Current Record: " + e.Start.ToString("d") + @")"; + addRecordButton.Text = @"Update Record"; + //Clear the form state. + ClearFormState(); + //Load the specified date from the database. + LoadDate(e.Start); + } } private void SetNewRecordDate(DateTime date, int weeksAhead = 0) @@ -2865,6 +2909,7 @@ namespace AdvertsingProfitControl { informationLabel.Text += @"No cost analysis data to display." + Environment.NewLine; } + _formRoll = FormRoll.ModifyRecord; } private void LoadProjectionsTable(DataTable projections) @@ -3573,6 +3618,11 @@ namespace AdvertsingProfitControl { var success = true; //Get the date ID for the current active date. + if (_currentActiveDate.DayOfWeek != DayOfWeek.Saturday) + { + SetNewRecordDate(_currentActiveDate); + _currentActiveDate = weekEndingCalendar.SelectionStart; + } var dateId = GetDateId(_currentActiveDate.ToString("d")); if (dateId == 0) { @@ -3769,6 +3819,7 @@ namespace AdvertsingProfitControl addRecordButton.Text = @"Update Record"; Text = @"Modify Record (Current Record: " + _currentActiveDate.ToShortDateString() + @")"; } + _formRoll = FormRoll.ModifyRecord; weekEndingCalendar.AddBoldedDate(_currentActiveDate); weekEndingCalendar.Invalidate(); return success; @@ -4359,6 +4410,7 @@ namespace AdvertsingProfitControl Text = @"Add New Record (Current Date: " + _currentActiveDate.ToShortDateString() + @")"; informationLabel.Text = string.Empty; errorLabel.Text = string.Empty; + _formRoll = FormRoll.AddRecord; } private void NormalizeApcTables() @@ -4543,5 +4595,11 @@ namespace AdvertsingProfitControl } } } + + private enum FormRoll + { + AddRecord = 0, + ModifyRecord = 1 + } } } diff --git a/AdvertsingProfitControl/Properties/AssemblyInfo.cs b/AdvertsingProfitControl/Properties/AssemblyInfo.cs index 43ab7aa..4423fec 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.2.0")] -[assembly: AssemblyFileVersion("1.9.2.0")] +[assembly: AssemblyVersion("1.9.3.0")] +[assembly: AssemblyFileVersion("1.9.3.0")] diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application index e32867c..e879498 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application @@ -14,7 +14,7 @@ - Cu5j9/buzIqFXwUVaREpWMereptetrOpSA4RfZP4zPs= + wZKyz33oBaTu7LlzGeOCxkM7UGOPV8kZeC+ZUmNCdwY= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest index 5bc0a8d..826e10a 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest @@ -43,14 +43,14 @@ - + - IfKNnpS3AvxJQzSAD+uL9oD6uCKebOR0f5N0pEztZ20= + Go6lCPrcJgk3GBchewQqB1BCxQhEtIFVMBBGG72lMB8= @@ -78,13 +78,13 @@ - + - e48EkTyChGHXYJETENSLw7RKQ1LZ5ZDUghEtiv5DmqY= + hrCGS0Sn5+IzPQDdJqcLf/Le8W/IzTyGRSduCe/L7Yo=