Updated the modify record form to calculate the total profit return for projections and actual sales. Removed the Access database as it is no longer supported or needed.

This commit is contained in:
2017-10-20 23:24:49 -05:00
parent 650014076a
commit 4e807e03b9
5 changed files with 82 additions and 63 deletions
Binary file not shown.
@@ -288,7 +288,6 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="APCDatabase.accdb" />
<Content Include="APCDatabase Template Script.sql" />
<Content Include="libeay32.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
+80 -11
View File
@@ -5,6 +5,7 @@ using System.Data.Entity.Infrastructure;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Transactions;
using System.Windows.Forms;
@@ -900,7 +901,7 @@ namespace AdvertsingProfitControl
{
return;
}
//Cell validating gets to handle updating the used ad item list since it handles cells on by one, instead by a whole row.
//Cell validating gets to handle updating the used ad item list since it handles cells one by one, instead of by a whole row.
if (userInput != _beginningCellValue && e.ColumnIndex == (int)TableGroupParser.SalesTableColumns.AdItem)
{
//The user is trying to change the ad special text to something else.
@@ -1091,13 +1092,11 @@ namespace AdvertsingProfitControl
//Otherwise, show an error.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "This column can't be blank!";
break;
case (int)TableGroupParser.SalesTableColumns.Sold: //Sold
//This Reg-ex pattern will match any number followed by the word bin(s), to allow specifying the number of bins of product were ordered.
case (int)TableGroupParser.SalesTableColumns.Sold:
//IF a match has been found, then make sure the word 'bin(s)' is capitalized to keep things looking pretty.
if (TextFormat.TryParseBinCount(
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString(),
out double binCount, out string binText))
out double _, out string binText))
{
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = binText;
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = TableColors.PendingEdit;
@@ -1162,7 +1161,28 @@ namespace AdvertsingProfitControl
{
return;
}
MessageBox.Show(@"Column " + (e.ColumnIndex + 1) + @" only allows numbers or prices in the format like '1/$10'.", @"Invalid Characters Detected");
MessageBox.Show(@"Column " + (e.ColumnIndex + 1) + @" only allows decimal numbers or prices in the format like '1/$10'.", @"Invalid Characters Detected");
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty;
dataGridView.RefreshEdit();
e.Cancel = true;
return;
}
break;
case (int)TableGroupParser.SalesTableColumns.ProfitReturn:
if (double.TryParse(userInput, out parsedNumber))
{
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Math.Round(parsedNumber, 2).ToString("N");
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = TableColors.PendingEdit;
CalculateTotalPofitReturn(dataGridView.Rows[e.RowIndex]);
_isFormDirty = true;
}
else
{
if (userInput == string.Empty)
{
return;
}
MessageBox.Show(@"Non numeric characters are not allowed in the Profit Return column.", @"Invalid Characters Detected");
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty;
dataGridView.RefreshEdit();
e.Cancel = true;
@@ -1624,7 +1644,7 @@ namespace AdvertsingProfitControl
}
double parsedNumber;
//Try parsing the text entered as a number and if that fails then break out and clear the value entered.
if (userInput != string.Empty && double.TryParse(userInput, out parsedNumber))
if (double.TryParse(userInput, out parsedNumber))
{
//Add the value to the cell.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = userInput;
@@ -1651,9 +1671,12 @@ namespace AdvertsingProfitControl
.ToString(), out totalInventory))
{
actualSalesDataGridView.Rows[e.RowIndex].Cells[(int) TableGroupParser.SalesTableColumns.Sold].Value = totalInventory - parsedNumber;
//Calculate the total profit return.
actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = TableColors.PendingEdit;
actualSalesDataGridView.Rows[e.RowIndex].Cells[
(int) TableGroupParser.SalesTableColumns.IsDirty].Value = true;
CalculateTotalPofitReturn(actualSalesDataGridView.Rows[e.RowIndex]);
}
}
_isFormDirty = true;
@@ -1674,7 +1697,7 @@ namespace AdvertsingProfitControl
if (e.ColumnIndex == (int)TableGroupParser.InventoryTableColumns.Recieved)
{
if (TextFormat.TryParseBinCount(inventoryDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex - 1].EditedFormattedValue.ToString(),
out double beginningBinCount, out string newBinText))
out double beginningBinCount, out string _))
{
var finalBinCount = binCount + beginningBinCount;
if (finalBinCount <= 0 || finalBinCount > 1)
@@ -1691,12 +1714,12 @@ out double beginningBinCount, out string newBinText))
else if (e.ColumnIndex == (int)TableGroupParser.InventoryTableColumns.EndingInventory)
{
if (TextFormat.TryParseBinCount(inventoryDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex - 1].EditedFormattedValue
.ToString(), out double totalBinCount, out string newBinText))
.ToString(), out double totalBinCount, out string _))
{
var finalBinCount = totalBinCount - binCount;
if (finalBinCount < 1|| finalBinCount > 1)
if (finalBinCount < 1 || finalBinCount > 1)
{
actualSalesDataGridView.Rows[e.RowIndex].Cells[(int)TableGroupParser.SalesTableColumns.Sold].Value = totalBinCount - binCount + " Bins";
actualSalesDataGridView.Rows[e.RowIndex].Cells[(int)TableGroupParser.SalesTableColumns.Sold].Value = finalBinCount + " Bins";
}
else
{
@@ -1705,6 +1728,7 @@ out double beginningBinCount, out string newBinText))
actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = TableColors.PendingEdit;
actualSalesDataGridView.Rows[e.RowIndex].Cells[
(int)TableGroupParser.SalesTableColumns.IsDirty].Value = true;
CalculateTotalPofitReturn(actualSalesDataGridView.Rows[e.RowIndex]);
}
}
dataGridView.RefreshEdit();
@@ -4391,6 +4415,51 @@ out double beginningBinCount, out string newBinText))
#endregion
private static void CalculateTotalPofitReturn(DataGridViewRow salesTableRow)
{
var sold = salesTableRow.Cells[(int) TableGroupParser.SalesTableColumns.Sold].EditedFormattedValue.ToString();
double profitReturn = 0;
//Check to see if the profit return cell has any values.
if (
!string.IsNullOrWhiteSpace(salesTableRow.Cells[(int) TableGroupParser.SalesTableColumns.ProfitReturn].EditedFormattedValue.ToString
()))
{
//All validation on the contents of the cell should have been taken care of, so just parse.
profitReturn =
double.Parse(
salesTableRow.Cells[(int) TableGroupParser.SalesTableColumns.ProfitReturn].EditedFormattedValue
.ToString());
}
if (double.TryParse(sold, out double soldCount))
{
salesTableRow.Cells[(int) TableGroupParser.SalesTableColumns.TotalProfitReturn].Value = (soldCount * profitReturn).ToString("N");
}
else if (sold.Contains("in"))
{
//If the sold string contains the text "in" which would imply the word Bin or Bins is present.
//So extract the numbers from the text and calculate the total profit return.
var soldCountText = new StringBuilder();
foreach (var c in sold)
{
if (char.IsNumber(c))
{
soldCountText.Append(c);
}
else
{
//If the character isn't a number then break out of the loop, there will be no more numbers
//to worry about since the text is in the # Bin(s) format.
break;
}
}
soldCount = double.Parse(soldCountText.ToString());
salesTableRow.Cells[(int)TableGroupParser.SalesTableColumns.TotalProfitReturn].Value = (soldCount * profitReturn).ToString("N");
}
}
private void addRecordButton_Click(object sender, EventArgs e)
{
SaveRecords();
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.4.0.0")]
[assembly: AssemblyFileVersion("3.4.0.0")]
[assembly: AssemblyVersion("3.4.1.0")]
[assembly: AssemblyFileVersion("3.4.1.0")]
@@ -1,49 +0,0 @@
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\APCDatabase.accdb
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\libeay32.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\libgcc_s_dw2-1.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\mingwm10.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\ssleay32.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\wkhtmltox0.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\AdvertsingProfitControl.exe.config
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\AdvertsingProfitControl.exe
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\AdvertsingProfitControl.pdb
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\AdvertisingProfitControlData.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Common.Logging.Core.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Common.Logging.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\DataTableParsingEngine.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\EntityFramework.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\EntityFramework.SqlServer.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Pechkin.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Spire.License.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Spire.Pdf.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Microsoft.mshtml.dll
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\AdvertisingProfitControlData.pdb
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\AdvertisingProfitControlData.dll.config
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\DataTableParsingEngine.pdb
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\DataTableParsingEngine.dll.config
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Common.Logging.pdb
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Common.Logging.xml
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Common.Logging.Core.pdb
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Common.Logging.Core.xml
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\EntityFramework.xml
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\EntityFramework.SqlServer.xml
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Spire.License.xml
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\Spire.Pdf.xml
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.csprojResolveAssemblyReference.cache
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.AboutBox.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.DatabaseRecovery.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmAddRecord.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmChangeShrink.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmLogFileViewer.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmLoginForm.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmMain.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmLogConsole.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmManageAdItems.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmManageSuppliers.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmRegisterAdSpecial.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmReportSettings.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.NewModifyRecord.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.Properties.Resources.resources
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.csproj.GenerateResource.Cache
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.exe
C:\Users\Crypto\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.pdb