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:
2017-02-18 02:33:57 -06:00
parent b580e48c26
commit 02fbc253d6
6 changed files with 48 additions and 15 deletions
+9 -2
View File
@@ -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;