Updated the main form with a slightly new look. Finished all the code for the main for to pull in all the data from the database and perform calculations on it. Currently can only load the most recent date. Added detection for holidays in the weekly and taxable lists.
This commit is contained in:
@@ -347,16 +347,16 @@ namespace AdvertsingProfitControl
|
||||
|
||||
//Re factor later....
|
||||
#region DataGridView Filling Methods
|
||||
private void FillDataGridViews(string dateId = "")
|
||||
private void FillDataGridViews(int dateId = 0)
|
||||
{
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
|
||||
BuildDataGridViewEvents(false);
|
||||
|
||||
if (dateId == "")
|
||||
if (dateId == 0)
|
||||
{
|
||||
dateId = databaseReader.RetrieveMostRecentDateId(databaseTracker.DatabaseConnectionString);
|
||||
//dateId = databaseReader.RetrieveMostRecentDateId(databaseTracker.DatabaseConnectionString);
|
||||
}
|
||||
//Clear the DataGridViews and the last used ad item.
|
||||
projectionsDataGridView.DataSource = null;
|
||||
@@ -423,7 +423,7 @@ namespace AdvertsingProfitControl
|
||||
weeklySalesDataGridView.Rows.Add(row.ItemArray);
|
||||
}
|
||||
|
||||
commentsTextBox.Text = databaseReader.RetrieveComments(dateId, databaseTracker.DatabaseConnectionString);
|
||||
commentsTextBox.Text = databaseReader.RetrieveComments(dateId, databaseTracker.DatabaseConnectionString)[1];
|
||||
|
||||
BuildDataGridViewEvents();
|
||||
}
|
||||
@@ -640,7 +640,7 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
FillDataGridViews(databaseReader.RetrieveDateIdByDateString(monthComboBox.SelectedItem + "/" + dayComboBox.SelectedItem + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString).ToString());
|
||||
FillDataGridViews(databaseReader.RetrieveDateIdByDateString(monthComboBox.SelectedItem + "/" + dayComboBox.SelectedItem + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString));
|
||||
}
|
||||
|
||||
private void FillDateSuggestionComboBoxes()
|
||||
@@ -666,7 +666,6 @@ namespace AdvertsingProfitControl
|
||||
yearComboBox.Items.Clear();
|
||||
monthComboBox.SelectedIndexChanged -= UpdateDaysOfMonth;
|
||||
dayComboBox.SelectedIndexChanged -= UpdateDataGridViewInformation;
|
||||
yearComboBox.SelectedIndexChanged -= UpdateDaysOfMonthByYear;
|
||||
//Now spin through the oneYearDatesTable and fill the class wide object with all the dates for the most recent year.
|
||||
for (var i = 0; i < datesList.Count; i++)
|
||||
{
|
||||
@@ -727,7 +726,6 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
monthComboBox.SelectedIndexChanged += UpdateDaysOfMonth;
|
||||
dayComboBox.SelectedIndexChanged += UpdateDataGridViewInformation;
|
||||
yearComboBox.SelectedIndexChanged += UpdateDaysOfMonthByYear;
|
||||
DrawingControl.ResumeDrawing(dateSelectorGroupBox);
|
||||
}
|
||||
|
||||
@@ -754,71 +752,6 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires when the Year combo box's index changes.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void UpdateDaysOfMonthByYear(object sender, EventArgs e)
|
||||
{
|
||||
//Obligatory database retrieval call...
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
//First, grab the year and the month from their respective combo boxes.
|
||||
var year = yearComboBox.SelectedItem.ToString();
|
||||
//Since we can more or less be certain that nothing is null, clear the current date collection.
|
||||
_dateStringCollection.Clear();
|
||||
var months = databaseReader.RetrieveUniqueMonthsList(year, databaseTracker.DatabaseConnectionString);
|
||||
var mostRecentMonth = months.Max();
|
||||
if (mostRecentMonth.Length == 1)
|
||||
{
|
||||
mostRecentMonth = "0" + mostRecentMonth;
|
||||
}
|
||||
var datesList = databaseReader.RetrieveDateListByYear(year, databaseTracker.DatabaseConnectionString);
|
||||
|
||||
for (var i = 0; i < datesList.Count; i++)
|
||||
{
|
||||
_dateStringCollection.Add(datesList[i].ToString("MM/dd/yyyy"));
|
||||
}
|
||||
|
||||
//Clear the month and day combo boxes and unregister their event handlers.
|
||||
dayComboBox.Items.Clear();
|
||||
monthComboBox.Items.Clear();
|
||||
monthComboBox.SelectedIndexChanged -= UpdateDaysOfMonth;
|
||||
dayComboBox.SelectedIndexChanged -= UpdateDataGridViewInformation;
|
||||
for (var i = 0; i < _dateStringCollection.Count; i++)
|
||||
{
|
||||
var dateArray = _dateStringCollection[i].Split('/');
|
||||
var month = dateArray[0];
|
||||
//Declare the patterns to look for when enumerating the combo boxes.
|
||||
var dayBasedOnMonthAndYeaRegex = new Regex(@"^(" + mostRecentMonth + @"\/\d{2}\/" + year + ")"); //Only allows days that are actually part of the month and year.
|
||||
var day = dateArray[1];
|
||||
|
||||
if (dayBasedOnMonthAndYeaRegex.IsMatch( _dateStringCollection[i]))
|
||||
{
|
||||
dayComboBox.Items.Add(day);
|
||||
}
|
||||
|
||||
if (!monthComboBox.Items.Contains(month))
|
||||
{
|
||||
monthComboBox.Items.Add(month);
|
||||
}
|
||||
}
|
||||
|
||||
if (dayComboBox.Items.Count > 0)
|
||||
{
|
||||
dayComboBox.SelectedIndex = dayComboBox.Items.Count - 1;
|
||||
}
|
||||
if (monthComboBox.Items.Count > 0)
|
||||
{
|
||||
monthComboBox.SelectedIndex = monthComboBox.Items.Count - 1;
|
||||
}
|
||||
|
||||
//Now re-register the event handlers
|
||||
monthComboBox.SelectedIndexChanged += UpdateDaysOfMonth;
|
||||
dayComboBox.SelectedIndexChanged += UpdateDataGridViewInformation;
|
||||
FillDataGridViews(databaseReader.RetrieveDateIdByDateString(monthComboBox.SelectedItem + "/" + dayComboBox.SelectedItem + "/" + year, databaseTracker.DatabaseConnectionString).ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Third Party Code
|
||||
|
||||
Reference in New Issue
Block a user