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
@@ -414,8 +414,7 @@ namespace AdvertsingProfitControl
Supplier = 2, Supplier = 2,
InvoiceNumber = 3, InvoiceNumber = 3,
InvoiceNetAmountAtCost = 4, InvoiceNetAmountAtCost = 4,
InvoiceNetAmount = 5, InvoiceNote = 5,
InvoiceNote = 6, IsDirty = 6
IsDirty = 7
} }
} }
@@ -102,6 +102,7 @@
<Reference Include="System.ComponentModel.DataAnnotations" /> <Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Deployment" /> <Reference Include="System.Deployment" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" /> <Reference Include="System.Runtime.Serialization" />
+32 -6
View File
@@ -33,31 +33,33 @@
this.moveOverButton = new System.Windows.Forms.Button(); this.moveOverButton = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.convertButton = new System.Windows.Forms.Button(); this.convertButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// existingDatesListBox // existingDatesListBox
// //
this.existingDatesListBox.FormattingEnabled = true; this.existingDatesListBox.FormattingEnabled = true;
this.existingDatesListBox.ItemHeight = 24; this.existingDatesListBox.ItemHeight = 24;
this.existingDatesListBox.Location = new System.Drawing.Point(59, 84); this.existingDatesListBox.Location = new System.Drawing.Point(23, 12);
this.existingDatesListBox.Name = "existingDatesListBox"; this.existingDatesListBox.Name = "existingDatesListBox";
this.existingDatesListBox.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; this.existingDatesListBox.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.existingDatesListBox.Size = new System.Drawing.Size(254, 316); this.existingDatesListBox.Size = new System.Drawing.Size(353, 364);
this.existingDatesListBox.TabIndex = 0; this.existingDatesListBox.TabIndex = 0;
// //
// datesToConvertListBox // datesToConvertListBox
// //
this.datesToConvertListBox.FormattingEnabled = true; this.datesToConvertListBox.FormattingEnabled = true;
this.datesToConvertListBox.ItemHeight = 24; this.datesToConvertListBox.ItemHeight = 24;
this.datesToConvertListBox.Location = new System.Drawing.Point(373, 84); this.datesToConvertListBox.Location = new System.Drawing.Point(556, 29);
this.datesToConvertListBox.Name = "datesToConvertListBox"; this.datesToConvertListBox.Name = "datesToConvertListBox";
this.datesToConvertListBox.Size = new System.Drawing.Size(254, 316); this.datesToConvertListBox.Size = new System.Drawing.Size(97, 52);
this.datesToConvertListBox.TabIndex = 1; this.datesToConvertListBox.TabIndex = 1;
// //
// moveOverButton // moveOverButton
// //
this.moveOverButton.Enabled = false; this.moveOverButton.Enabled = false;
this.moveOverButton.Location = new System.Drawing.Point(59, 446); this.moveOverButton.Location = new System.Drawing.Point(381, 417);
this.moveOverButton.Name = "moveOverButton"; this.moveOverButton.Name = "moveOverButton";
this.moveOverButton.Size = new System.Drawing.Size(160, 56); this.moveOverButton.Size = new System.Drawing.Size(160, 56);
this.moveOverButton.TabIndex = 2; this.moveOverButton.TabIndex = 2;
@@ -71,7 +73,7 @@
// //
// convertButton // convertButton
// //
this.convertButton.Location = new System.Drawing.Point(373, 452); this.convertButton.Location = new System.Drawing.Point(556, 530);
this.convertButton.Name = "convertButton"; this.convertButton.Name = "convertButton";
this.convertButton.Size = new System.Drawing.Size(133, 50); this.convertButton.Size = new System.Drawing.Size(133, 50);
this.convertButton.TabIndex = 3; this.convertButton.TabIndex = 3;
@@ -79,11 +81,32 @@
this.convertButton.UseVisualStyleBackColor = true; this.convertButton.UseVisualStyleBackColor = true;
this.convertButton.Click += new System.EventHandler(this.convertButton_Click); this.convertButton.Click += new System.EventHandler(this.convertButton_Click);
// //
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 515);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 25);
this.label1.TabIndex = 4;
this.label1.Text = "label1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(400, 530);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(141, 58);
this.button1.TabIndex = 5;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// DebugDatabaseConverter // DebugDatabaseConverter
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F); this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(701, 592); this.ClientSize = new System.Drawing.Size(701, 592);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.convertButton); this.Controls.Add(this.convertButton);
this.Controls.Add(this.moveOverButton); this.Controls.Add(this.moveOverButton);
this.Controls.Add(this.datesToConvertListBox); this.Controls.Add(this.datesToConvertListBox);
@@ -92,6 +115,7 @@
this.Text = "DebugDatabaseConverter"; this.Text = "DebugDatabaseConverter";
this.Load += new System.EventHandler(this.DebugDatabaseConverter_Load); this.Load += new System.EventHandler(this.DebugDatabaseConverter_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
@@ -102,5 +126,7 @@
private System.Windows.Forms.Button moveOverButton; private System.Windows.Forms.Button moveOverButton;
private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.Button convertButton; private System.Windows.Forms.Button convertButton;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
} }
} }
@@ -69,6 +69,7 @@ namespace AdvertsingProfitControl
} }
} }
} }
} }
private void MoveOverButton_Click(object sender, EventArgs e) private void MoveOverButton_Click(object sender, EventArgs e)
@@ -776,5 +777,23 @@ namespace AdvertsingProfitControl
return dataTable; return dataTable;
} }
private void button1_Click(object sender, EventArgs e)
{
var db = new AdvertisingProfitControlModel();
using (var scope = new TransactionScope())
{
var invoices = db.Invoices.Select(x => x);
foreach (var invoice in invoices)
{
invoice.InvoiceNetAmountAtCost = invoice.InvoiceNetAmount;
invoice.InvoiceNetAmount = null;
}
db.SaveChanges();
scope.Complete();
}
}
} }
} }
+19 -17
View File
@@ -49,8 +49,8 @@ namespace AdvertsingProfitControl
if (actualSalesDataGridView.Rows.Count == 0) if (actualSalesDataGridView.Rows.Count == 0)
{ {
salesProducedLabel.Text = @"Sales Produced By Ad Items (A): No Data"; salesProducedLabel.Text = @"Sales Produced By Ad Items (A): No Data";
totalProfitFromAdItemsLabel.Text = @"Total Profit Return " + Environment.NewLine + @" From Ad Items (B): No Data"; totalProfitFromAdItemsLabel.Text = @"Total Profit Return " + Environment.NewLine + @"From Ad Items (B): No Data";
if (Math.Abs(_departmentSales) < 1) if (_departmentSales == 0)
{ {
departmentSalesLabel.Text = @"Department Sales: No Data"; 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"; salesProducedLabel.Text = @"Sales Produced By Ad Items (A): No Data";
incompleteData = true; incompleteData = true;
} }
if (Math.Abs(_totalProfitReturnFromAdItems) < 1) if (_totalProfitReturnFromAdItems == 0)
{ {
totalProfitFromAdItemsLabel.Text = @"Total Profit Return " + Environment.NewLine + @"From Ad Items (B): No Data"; totalProfitFromAdItemsLabel.Text = @"Total Profit Return " + Environment.NewLine + @"From Ad Items (B): No Data";
incompleteData = true; incompleteData = true;
} }
if (Math.Abs(_departmentSales) < 1) if (_departmentSales == 0)
{ {
departmentSalesLabel.Text = @"Department Sales: No Data"; departmentSalesLabel.Text = @"Department Sales: No Data";
incompleteData = true; incompleteData = true;
@@ -107,16 +107,21 @@ namespace AdvertsingProfitControl
private void CalculateGrossProfit() private void CalculateGrossProfit()
{ {
if (Math.Abs(_totalInvoicePurchases) < 1) if (_totalInvoicePurchases == 0)
{ {
//IF Cost of Sales hasn't been calculated, then clear labels and return. grossProfitTotalSales.Text = _departmentSales == 0
if (Math.Abs(_departmentSales) < 1) ? @"Total Sales: No Data"
{ : @"Total Sales: " + _departmentSales.ToString("C");
grossProfitTotalSales.Text = @"Total Sales: No Data";
}
grossProfitLessCostOfSales.Text = @"Less Cost of Sales: No Data"; grossProfitLessCostOfSales.Text = @"Less Cost of Sales: No Data";
return; 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"); grossProfitTotalSales.Text = @"Total Sales: " + _departmentSales.ToString("C");
grossProfitLessCostOfSales.Text = @"Less Cost of Sales: " + _totalInvoicePurchases.ToString("C"); grossProfitLessCostOfSales.Text = @"Less Cost of Sales: " + _totalInvoicePurchases.ToString("C");
var dollarGrossProfit = _departmentSales - _totalInvoicePurchases; var dollarGrossProfit = _departmentSales - _totalInvoicePurchases;
@@ -432,8 +437,7 @@ namespace AdvertsingProfitControl
{ {
string[] invoicesColumnNames = string[] invoicesColumnNames =
{ {
"InvoiceDate", "Supplier", "InvoiceNumber", "InvoiceNetAmountAtCost", "InvoiceDate", "Supplier", "InvoiceNumber", "InvoiceNetAmountAtCost", "InvoiceNote"
"InvoiceNetAmountExtendedRetail", "InvoiceNote"
}; };
foreach (var name in invoicesColumnNames) foreach (var name in invoicesColumnNames)
@@ -444,7 +448,6 @@ namespace AdvertsingProfitControl
HeaderText = TextFormat.AddSpacesToSentence(name, false), HeaderText = TextFormat.AddSpacesToSentence(name, false),
ValueType = typeof(string), ValueType = typeof(string),
SortMode = DataGridViewColumnSortMode.NotSortable, SortMode = DataGridViewColumnSortMode.NotSortable,
MaxInputLength = 20
}; };
invoicesDataGridView.Columns.Add(column); invoicesDataGridView.Columns.Add(column);
} }
@@ -652,8 +655,7 @@ namespace AdvertsingProfitControl
invoicesDataGridView.Rows[index].Cells[3].Value = $@"{invoice.InvoiceNetAmountAtCost:N2}"; invoicesDataGridView.Rows[index].Cells[3].Value = $@"{invoice.InvoiceNetAmountAtCost:N2}";
//Net Amount Extended Retail is not the required field. //Net Amount Extended Retail is not the required field.
if (invoice.InvoiceNetAmountAtCost != null) _totalInvoicePurchases += (decimal)invoice.InvoiceNetAmountAtCost; if (invoice.InvoiceNetAmountAtCost != null) _totalInvoicePurchases += (decimal)invoice.InvoiceNetAmountAtCost;
invoicesDataGridView.Rows[index].Cells[4].Value = $@"{invoice.InvoiceNetAmount:N2}"; invoicesDataGridView.Rows[index].Cells[4].Value = invoice.InvoiceNote;
invoicesDataGridView.Rows[index].Cells[5].Value = invoice.InvoiceNote;
} }
//Add the total purchases row to the invoice table. //Add the total purchases row to the invoice table.
if(invoicesDataGridView.RowCount == 0) return; if(invoicesDataGridView.RowCount == 0) return;
@@ -662,7 +664,7 @@ namespace AdvertsingProfitControl
invoicesDataGridView.Rows[invoicesDataGridView.Rows.Count - 1].Cells[0].Value = @"Total Purchases"; invoicesDataGridView.Rows[invoicesDataGridView.Rows.Count - 1].Cells[0].Value = @"Total Purchases";
if (Math.Abs(_totalInvoicePurchases) > 0) 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");
} }
} }
+4 -17
View File
@@ -2153,7 +2153,7 @@ namespace AdvertsingProfitControl
/// </summary> /// </summary>
private void ConstructInvoicesDataGridView() private void ConstructInvoicesDataGridView()
{ {
string[] invoicesColumnNames = { "ID", "InvoiceDate", "Supplier", "InvoiceNumber", "InvoiceNetAmountAtCost", "InvoiceNetAmountExtendedRetail", "InvoiceNote", "IsDirty" }; string[] invoicesColumnNames = { "ID", "InvoiceDate", "Supplier", "InvoiceNumber", "InvoiceNetAmountAtCost", "InvoiceNote", "IsDirty" };
foreach (var name in invoicesColumnNames) foreach (var name in invoicesColumnNames)
{ {
@@ -2960,8 +2960,7 @@ namespace AdvertsingProfitControl
invoicesDataGridView.Rows[index].Cells[1].Value = invoice.InvoiceDate.ToString("d"); invoicesDataGridView.Rows[index].Cells[1].Value = invoice.InvoiceDate.ToString("d");
invoicesDataGridView.Rows[index].Cells[3].Value = invoice.InvoiceNumber; invoicesDataGridView.Rows[index].Cells[3].Value = invoice.InvoiceNumber;
invoicesDataGridView.Rows[index].Cells[4].Value = invoice.InvoiceNetAmountAtCost == 0 ? "" : invoice.InvoiceNetAmountAtCost.ToString(); invoicesDataGridView.Rows[index].Cells[4].Value = invoice.InvoiceNetAmountAtCost == 0 ? "" : invoice.InvoiceNetAmountAtCost.ToString();
invoicesDataGridView.Rows[index].Cells[5].Value = invoice.InvoiceNetAmount == 0 ? "" : invoice.InvoiceNetAmount.ToString(); invoicesDataGridView.Rows[index].Cells[5].Value = invoice.InvoiceNote;
invoicesDataGridView.Rows[index].Cells[6].Value = invoice.InvoiceNote;
invoicesDataGridView.Rows[index].Cells[(int)InvoiceTableColumns.IsDirty].Value = false; invoicesDataGridView.Rows[index].Cells[(int)InvoiceTableColumns.IsDirty].Value = false;
index++; index++;
} }
@@ -3829,12 +3828,6 @@ namespace AdvertsingProfitControl
? 0 ? 0
: decimal.Parse( : decimal.Parse(
row.Cells[(int)InvoiceTableColumns.InvoiceNetAmountAtCost].EditedFormattedValue.ToString()); row.Cells[(int)InvoiceTableColumns.InvoiceNetAmountAtCost].EditedFormattedValue.ToString());
invoice.InvoiceNetAmount =
string.IsNullOrWhiteSpace(
row.Cells[(int)InvoiceTableColumns.InvoiceNetAmount].EditedFormattedValue.ToString())
? 0
: decimal.Parse(
row.Cells[(int)InvoiceTableColumns.InvoiceNetAmount].EditedFormattedValue.ToString());
invoice.InvoiceNote = row.Cells[(int)InvoiceTableColumns.InvoiceNote].EditedFormattedValue.ToString(); invoice.InvoiceNote = row.Cells[(int)InvoiceTableColumns.InvoiceNote].EditedFormattedValue.ToString();
invoice.FkSupplierId = supplier.Id; invoice.FkSupplierId = supplier.Id;
invoice.FkDateId = date.Id; invoice.FkDateId = date.Id;
@@ -3859,17 +3852,10 @@ namespace AdvertsingProfitControl
: decimal.Parse( : decimal.Parse(
row.Cells[(int) InvoiceTableColumns.InvoiceNetAmountAtCost] row.Cells[(int) InvoiceTableColumns.InvoiceNetAmountAtCost]
.EditedFormattedValue.ToString()); .EditedFormattedValue.ToString());
invoice.InvoiceNetAmount =
string.IsNullOrWhiteSpace(
row.Cells[(int) InvoiceTableColumns.InvoiceNetAmount].EditedFormattedValue
.ToString())
? 0
: decimal.Parse(
row.Cells[(int) InvoiceTableColumns.InvoiceNetAmount].EditedFormattedValue
.ToString());
invoice.InvoiceNote = invoice.InvoiceNote =
row.Cells[(int) InvoiceTableColumns.InvoiceNote].EditedFormattedValue.ToString(); row.Cells[(int) InvoiceTableColumns.InvoiceNote].EditedFormattedValue.ToString();
invoice.FkSupplierId = supplier.Id; invoice.FkSupplierId = supplier.Id;
idNumbers.Add(row.Index, invoice);
} }
else else
{ {
@@ -3889,6 +3875,7 @@ namespace AdvertsingProfitControl
invoicesDataGridView.Rows[index.Key].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; invoicesDataGridView.Rows[index.Key].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
invoicesDataGridView.Rows[index.Key].Cells[(int)InvoiceTableColumns.IsDirty].Value = false; invoicesDataGridView.Rows[index.Key].Cells[(int)InvoiceTableColumns.IsDirty].Value = false;
} }
informationLabel.Text += @"Updated the Invoices table." + Environment.NewLine; informationLabel.Text += @"Updated the Invoices table." + Environment.NewLine;
} }
else else
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.1.16")] [assembly: AssemblyVersion("2.0.2.16")]
[assembly: AssemblyFileVersion("2.0.1.16")] [assembly: AssemblyFileVersion("2.0.2.16")]
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Advertising Profit Control" Language="1033" Version="2.0.1.16" Manufacturer="Garritt McCune" UpgradeCode="a416a558-d7c0-4f24-8b1e-2d01761ad15f"> <Product Id="*" Name="Advertising Profit Control" Language="1033" Version="2.0.2.16" Manufacturer="Garritt McCune" UpgradeCode="a416a558-d7c0-4f24-8b1e-2d01761ad15f">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Description="Custom Profit Control Recording Software" Comments="Profit Control Recording Software"/> <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Description="Custom Profit Control Recording Software" Comments="Profit Control Recording Software"/>
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /> <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<!--Not set by default, EmbedCab="yes" embeds the cabinet file into the installer--> <!--Not set by default, EmbedCab="yes" embeds the cabinet file into the installer-->