Removed the Invoice Net Amount Extended Retail column from the Invoice table DataGridViews. Fixed a crash bug on the main form caused by an empty department sales variable. Small refactoring on the main form's calculation methods.

This commit is contained in:
2017-04-17 02:01:31 -05:00
parent 61f369f7fe
commit c72fbf88cf
8 changed files with 81 additions and 47 deletions
+20 -18
View File
@@ -49,8 +49,8 @@ namespace AdvertsingProfitControl
if (actualSalesDataGridView.Rows.Count == 0)
{
salesProducedLabel.Text = @"Sales Produced By Ad Items (A): No Data";
totalProfitFromAdItemsLabel.Text = @"Total Profit Return " + Environment.NewLine + @" From Ad Items (B): No Data";
if (Math.Abs(_departmentSales) < 1)
totalProfitFromAdItemsLabel.Text = @"Total Profit Return " + Environment.NewLine + @"From Ad Items (B): No Data";
if (_departmentSales == 0)
{
departmentSalesLabel.Text = @"Department Sales: No Data";
}
@@ -71,17 +71,17 @@ namespace AdvertsingProfitControl
}
}
if (Math.Abs(_salesProducedByAdItems) < 1)
if (_salesProducedByAdItems == 0)
{
salesProducedLabel.Text = @"Sales Produced By Ad Items (A): No Data";
incompleteData = true;
}
if (Math.Abs(_totalProfitReturnFromAdItems) < 1)
if (_totalProfitReturnFromAdItems == 0)
{
totalProfitFromAdItemsLabel.Text = @"Total Profit Return " + Environment.NewLine + @"From Ad Items (B): No Data";
incompleteData = true;
}
if (Math.Abs(_departmentSales) < 1)
if (_departmentSales == 0)
{
departmentSalesLabel.Text = @"Department Sales: No Data";
incompleteData = true;
@@ -107,16 +107,21 @@ namespace AdvertsingProfitControl
private void CalculateGrossProfit()
{
if (Math.Abs(_totalInvoicePurchases) < 1)
if (_totalInvoicePurchases == 0)
{
//IF Cost of Sales hasn't been calculated, then clear labels and return.
if (Math.Abs(_departmentSales) < 1)
{
grossProfitTotalSales.Text = @"Total Sales: No Data";
}
grossProfitTotalSales.Text = _departmentSales == 0
? @"Total Sales: No Data"
: @"Total Sales: " + _departmentSales.ToString("C");
grossProfitLessCostOfSales.Text = @"Less Cost of Sales: No Data";
return;
}
//IF Cost of Sales hasn't been calculated, then clear labels and return.
if (_departmentSales == 0)
{
grossProfitTotalSales.Text = @"Total Sales: No Data";
grossProfitLessCostOfSales.Text = @"Less Cost of Sales: " + _totalInvoicePurchases.ToString("C");
return;
}
grossProfitTotalSales.Text = @"Total Sales: " + _departmentSales.ToString("C");
grossProfitLessCostOfSales.Text = @"Less Cost of Sales: " + _totalInvoicePurchases.ToString("C");
var dollarGrossProfit = _departmentSales - _totalInvoicePurchases;
@@ -432,8 +437,7 @@ namespace AdvertsingProfitControl
{
string[] invoicesColumnNames =
{
"InvoiceDate", "Supplier", "InvoiceNumber", "InvoiceNetAmountAtCost",
"InvoiceNetAmountExtendedRetail", "InvoiceNote"
"InvoiceDate", "Supplier", "InvoiceNumber", "InvoiceNetAmountAtCost", "InvoiceNote"
};
foreach (var name in invoicesColumnNames)
@@ -444,7 +448,6 @@ namespace AdvertsingProfitControl
HeaderText = TextFormat.AddSpacesToSentence(name, false),
ValueType = typeof(string),
SortMode = DataGridViewColumnSortMode.NotSortable,
MaxInputLength = 20
};
invoicesDataGridView.Columns.Add(column);
}
@@ -651,9 +654,8 @@ namespace AdvertsingProfitControl
invoicesDataGridView.Rows[index].Cells[2].Value = invoice.InvoiceNumber;
invoicesDataGridView.Rows[index].Cells[3].Value = $@"{invoice.InvoiceNetAmountAtCost:N2}";
//Net Amount Extended Retail is not the required field.
if (invoice.InvoiceNetAmountAtCost != null) _totalInvoicePurchases += (decimal)invoice.InvoiceNetAmountAtCost;
invoicesDataGridView.Rows[index].Cells[4].Value = $@"{invoice.InvoiceNetAmount:N2}";
invoicesDataGridView.Rows[index].Cells[5].Value = invoice.InvoiceNote;
if (invoice.InvoiceNetAmountAtCost != null) _totalInvoicePurchases += (decimal)invoice.InvoiceNetAmountAtCost;
invoicesDataGridView.Rows[index].Cells[4].Value = invoice.InvoiceNote;
}
//Add the total purchases row to the invoice table.
if(invoicesDataGridView.RowCount == 0) return;
@@ -662,7 +664,7 @@ namespace AdvertsingProfitControl
invoicesDataGridView.Rows[invoicesDataGridView.Rows.Count - 1].Cells[0].Value = @"Total Purchases";
if (Math.Abs(_totalInvoicePurchases) > 0)
{
invoicesDataGridView.Rows[invoicesDataGridView.Rows.Count - 1].Cells[4].Value = _totalInvoicePurchases.ToString("N2");
invoicesDataGridView.Rows[invoicesDataGridView.Rows.Count - 1].Cells[3].Value = _totalInvoicePurchases.ToString("N2");
}
}