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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user