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:
Binary file not shown.
@@ -37,6 +37,7 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
|
||||
#region Date Functions
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the most recent date's ID from the database.
|
||||
/// </summary>
|
||||
@@ -44,11 +45,12 @@ namespace AdvertsingProfitControl
|
||||
/// <returns>The ID number as a string.</returns>
|
||||
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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>wZKyz33oBaTu7LlzGeOCxkM7UGOPV8kZeC+ZUmNCdwY=</dsig:DigestValue>
|
||||
<dsig:DigestValue>3ChUsEqNUMAjVaBGqxbdYDY0WFTlgEm8k8f2eCP9a18=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<description asmv2:iconFile="Stretched Logo Collection.ico" xmlns="urn:schemas-microsoft-com:asm.v1" />
|
||||
<application />
|
||||
<entryPoint>
|
||||
<assemblyIdentity name="AdvertsingProfitControl" version="1.9.2.0" language="neutral" processorArchitecture="amd64" />
|
||||
<assemblyIdentity name="AdvertsingProfitControl" version="1.9.3.0" language="neutral" processorArchitecture="amd64" />
|
||||
<commandLine file="AdvertsingProfitControl.exe" parameters="" />
|
||||
</entryPoint>
|
||||
<trustInfo>
|
||||
@@ -43,14 +43,14 @@
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="2434048">
|
||||
<assemblyIdentity name="AdvertsingProfitControl" version="1.9.2.0" language="neutral" processorArchitecture="amd64" />
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="2435072">
|
||||
<assemblyIdentity name="AdvertsingProfitControl" version="1.9.3.0" language="neutral" processorArchitecture="amd64" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>Go6lCPrcJgk3GBchewQqB1BCxQhEtIFVMBBGG72lMB8=</dsig:DigestValue>
|
||||
<dsig:DigestValue>mupCCLiyPu/EYkKY9Sc0jm2Z0deNl6wThi2EYMz/tAI=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
@@ -93,7 +93,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>bPUdW2UkdkedvUlfZHuxhxUjqrn/LMCowSfDLWqF+4Y=</dsig:DigestValue>
|
||||
<dsig:DigestValue>u8KjFRismEEKveuk50umuN3UTCd1w3Uh6n8Nk4q8yoo=</dsig:DigestValue>
|
||||
</hash>
|
||||
</file>
|
||||
<file name="APCTemplate.accdb" size="819200">
|
||||
|
||||
Reference in New Issue
Block a user