Organized the code a bit, and fixed a bug where selecting a new date wouldn't update the modify record form. Prettied up the formatting for the invoices table.
This commit is contained in:
@@ -163,7 +163,7 @@ namespace AdvertsingProfitControl
|
||||
set { base.Text = value; }
|
||||
}
|
||||
|
||||
#region Global Event Handlers
|
||||
#region Global Text Box Events
|
||||
|
||||
/// <summary>
|
||||
/// Stores the beginning value in a text box into the _beginningCellValue field.
|
||||
@@ -2110,6 +2110,8 @@ namespace AdvertsingProfitControl
|
||||
|
||||
#endregion
|
||||
|
||||
#region Date Time Events
|
||||
|
||||
private void ValidateDateChanged(object sender, DateRangeEventArgs e)
|
||||
{
|
||||
if (e.Start == _currentActiveDate || !weekEndingCalendar.BoldedDates.Contains(e.Start)) return;
|
||||
@@ -2118,7 +2120,8 @@ namespace AdvertsingProfitControl
|
||||
var result = MessageBox.Show(@"Would you like to save the changes you have made to this record?", @"Changes Detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
_currentActiveDate = e.Start;
|
||||
//_currentActiveDate = e.Start;
|
||||
//Save the changes made to the database then clear and load the date picked by the user.
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2126,6 +2129,7 @@ namespace AdvertsingProfitControl
|
||||
return;
|
||||
}
|
||||
}
|
||||
_currentActiveDate = e.Start;
|
||||
Text = @"Modify Record (Current Record: " + e.Start.ToString("d") + @")";
|
||||
//Clear the form state.
|
||||
ClearFormState();
|
||||
@@ -2133,60 +2137,7 @@ namespace AdvertsingProfitControl
|
||||
LoadDate(e.Start);
|
||||
}
|
||||
|
||||
private void LoadDate(DateTime date)
|
||||
{
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
var dateId = databaseReader.RetrieveDateIdByDateString(date.ToString("d"), databaseTracker.DatabaseConnectionString);
|
||||
var projections = databaseReader.ReturnProjectionsTable(dateId, databaseTracker.DatabaseConnectionString);
|
||||
var inventory = databaseReader.ReturnInventoryTable(dateId, databaseTracker.DatabaseConnectionString);
|
||||
var actualSales = databaseReader.ReturnActualSales(dateId, databaseTracker.DatabaseConnectionString);
|
||||
LoadProjectionsTable(projections);
|
||||
LoadInventory(inventory);
|
||||
LoadActualSales(actualSales);
|
||||
var invoices = databaseReader.ReturnInvoiceTable(dateId, databaseTracker.DatabaseConnectionString);
|
||||
var comments = databaseReader.RetrieveComments(int.Parse(dateId), databaseTracker.DatabaseConnectionString);
|
||||
if (comments.Count == 2)
|
||||
{
|
||||
LoadComments(int.Parse(comments[0]), comments[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogConsole.WriteToLog(FrmLogConsole.Level.Info, "No comments to display for the date of " + _currentActiveDate.ToString("d") + ".");
|
||||
informationLabel.Text += @"No comments to display." + Environment.NewLine;
|
||||
}
|
||||
var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId,
|
||||
databaseTracker.DatabaseConnectionString);
|
||||
if (weeklySales.Rows.Count == 1)
|
||||
{
|
||||
LoadWeeklySales(weeklySales);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No weekly sales to display." + Environment.NewLine;
|
||||
}
|
||||
|
||||
var taxable = databaseReader.ReturnTaxableFromDateId(dateId, databaseTracker.DatabaseConnectionString);
|
||||
if (taxable.Rows.Count == 1)
|
||||
{
|
||||
LoadTaxable(taxable);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No taxable data to display." + Environment.NewLine;
|
||||
}
|
||||
LoadInvoices(invoices);
|
||||
var costAnalysis = databaseReader.ReturnCostAnalysis(int.Parse(dateId),
|
||||
databaseTracker.DatabaseConnectionString);
|
||||
if (costAnalysis.Rows.Count == 1)
|
||||
{
|
||||
LoadCostAnalysis(costAnalysis);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No cost analysis data to display." + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void ClearFormState()
|
||||
{
|
||||
@@ -2377,6 +2328,60 @@ namespace AdvertsingProfitControl
|
||||
|
||||
#region Data Loading Methods
|
||||
|
||||
private void LoadDate(DateTime date)
|
||||
{
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
var dateId = databaseReader.RetrieveDateIdByDateString(date.ToString("d"), databaseTracker.DatabaseConnectionString);
|
||||
var projections = databaseReader.ReturnProjectionsTable(dateId, databaseTracker.DatabaseConnectionString);
|
||||
var inventory = databaseReader.ReturnInventoryTable(dateId, databaseTracker.DatabaseConnectionString);
|
||||
var actualSales = databaseReader.ReturnActualSales(dateId, databaseTracker.DatabaseConnectionString);
|
||||
LoadProjectionsTable(projections);
|
||||
LoadInventory(inventory);
|
||||
LoadActualSales(actualSales);
|
||||
var invoices = databaseReader.ReturnInvoiceTable(dateId, databaseTracker.DatabaseConnectionString);
|
||||
var comments = databaseReader.RetrieveComments(int.Parse(dateId), databaseTracker.DatabaseConnectionString);
|
||||
if (comments.Count == 2)
|
||||
{
|
||||
LoadComments(int.Parse(comments[0]), comments[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No comments to display." + Environment.NewLine;
|
||||
}
|
||||
var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId,
|
||||
databaseTracker.DatabaseConnectionString);
|
||||
if (weeklySales.Rows.Count == 1)
|
||||
{
|
||||
LoadWeeklySales(weeklySales);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No sales to display." + Environment.NewLine;
|
||||
}
|
||||
|
||||
var taxable = databaseReader.ReturnTaxableFromDateId(dateId, databaseTracker.DatabaseConnectionString);
|
||||
if (taxable.Rows.Count == 1)
|
||||
{
|
||||
LoadTaxable(taxable);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No taxable data to display." + Environment.NewLine;
|
||||
}
|
||||
LoadInvoices(invoices);
|
||||
var costAnalysis = databaseReader.ReturnCostAnalysis(int.Parse(dateId),
|
||||
databaseTracker.DatabaseConnectionString);
|
||||
if (costAnalysis.Rows.Count == 1)
|
||||
{
|
||||
LoadCostAnalysis(costAnalysis);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No cost analysis data to display." + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadProjectionsTable(DataTable projections)
|
||||
{
|
||||
//Assuming all the tables are correctly aligned.
|
||||
@@ -2658,34 +2663,29 @@ namespace AdvertsingProfitControl
|
||||
var row = new DataGridViewRow();
|
||||
for (var cellIndex = 0; cellIndex < invoices.Rows[rowIndex].ItemArray.Length; cellIndex++)
|
||||
{
|
||||
//Get the
|
||||
var cell = new DataGridViewTextBoxCell();
|
||||
//Format the invoice date.
|
||||
if (cellIndex == 1)
|
||||
{
|
||||
var date = DateTime.Parse(invoices.Rows[rowIndex].ItemArray[cellIndex].ToString());
|
||||
var cell = new DataGridViewTextBoxCell
|
||||
{
|
||||
Value = date.ToString("d")
|
||||
};
|
||||
cell.Value = date.ToString("d");
|
||||
row.Cells.Add(cell);
|
||||
continue;
|
||||
}
|
||||
if (invoices.Rows[rowIndex].ItemArray[cellIndex].ToString() != "0")
|
||||
//Apply formatting to the only cells that will have currency values in them.
|
||||
if (cellIndex == 4 || cellIndex == 5)
|
||||
{
|
||||
var cell = new DataGridViewTextBoxCell
|
||||
var formattedNumber = Math.Round(double.Parse(invoices.Rows[rowIndex].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
Value = invoices.Rows[rowIndex].ItemArray[cellIndex].ToString()
|
||||
};
|
||||
cell.Value = formattedNumber;
|
||||
}
|
||||
row.Cells.Add(cell);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cell = new DataGridViewTextBoxCell
|
||||
{
|
||||
Value = ""
|
||||
};
|
||||
row.Cells.Add(cell);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
//No special formatting rules here so just put the value in and move on.
|
||||
cell.Value = invoices.Rows[rowIndex].ItemArray[cellIndex].ToString();
|
||||
row.Cells.Add(cell);
|
||||
}
|
||||
invoicesDataGridView.Rows.Add(row);
|
||||
}
|
||||
@@ -2995,11 +2995,17 @@ namespace AdvertsingProfitControl
|
||||
suppliesTextBox.Validating += ValidateCostAnalysisValues;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Database Update/Insertion Methods
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
//private void NormalizeApcTables(DataTable projections, DataTable inventory, DataTable actualSales, string dateId)
|
||||
//{
|
||||
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user