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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user