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