Updated the Main Form to read from the SQL database exclusively. Modify record form now writes exclusively to the SQL database, and reads the main APC tables from SQL. New bug with row validation, but only on records with ad specials.

This commit is contained in:
2017-04-04 15:36:04 -05:00
parent 9da9540969
commit 89b45d34ab
6 changed files with 1136 additions and 1212 deletions
Binary file not shown.
Binary file not shown.
@@ -418,16 +418,4 @@ namespace AdvertsingProfitControl
InvoiceNote = 6, InvoiceNote = 6,
IsDirty = 7 IsDirty = 7
} }
/// <summary>
/// TODO: Push into a stand alone object.
/// </summary>
public enum TrimmingOperationResult
{
FailedToTrim = 0,
CreatedNewInsertionTable = 1,
CreatedUpdateTable = 2,
CreatedNewInsertionAndUpdateTables = 3,
NoChangesRequired = 4
}
} }
@@ -254,9 +254,6 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="APCDatabase Template Script.sql" /> <Content Include="APCDatabase Template Script.sql" />
<Content Include="APCTemplate.accdb">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Stretched Logo Collection.ico" /> <Content Include="Stretched Logo Collection.ico" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+33 -27
View File
@@ -14,10 +14,10 @@ namespace AdvertsingProfitControl
{ {
public partial class FrmMain : Form public partial class FrmMain : Form
{ {
private double _salesProducedByAdItems; private decimal _salesProducedByAdItems;
private double _totalProfitReturnFromAdItems; private decimal _totalProfitReturnFromAdItems;
private double _totalInvoicePurchases; //Total Purchases private decimal _totalInvoicePurchases; //Total Purchases
private double _departmentSales; //weekly sales total private decimal _departmentSales; //weekly sales total
private DateTime _currentActiveDate; private DateTime _currentActiveDate;
private readonly FrmLogConsole _console = FrmLogConsole.GetStaticInstance; private readonly FrmLogConsole _console = FrmLogConsole.GetStaticInstance;
private int _LazyPageCounter; private int _LazyPageCounter;
@@ -39,7 +39,7 @@ namespace AdvertsingProfitControl
monthCalendar.BoldedDates = db.WeekEndingDates.Select(zdate => zdate.EndingDate).ToArray(); monthCalendar.BoldedDates = db.WeekEndingDates.Select(zdate => zdate.EndingDate).ToArray();
ConstructApcDataGridViews(); ConstructApcDataGridViews();
ConstructInvoicesDataGridView(); ConstructInvoicesDataGridView();
//RowParsing.AdSpecialGroups.AddRange(databaseReader.ReturnGroupNameList(databaseTracker.DatabaseConnectionString)); RowParsing.AdSpecialGroups.AddRange(db.AdSpecials.Select(x => x.Name));
//Select the most recent date from the database. //Select the most recent date from the database.
var recentDate = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault(); var recentDate = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault();
if (recentDate != null) if (recentDate != null)
@@ -51,14 +51,10 @@ namespace AdvertsingProfitControl
//projectionsDataGridView.KeyDown += FrmMain_KeyDown; //projectionsDataGridView.KeyDown += FrmMain_KeyDown;
//var margin = new Margins(50, 50, 0, 0); //var margin = new Margins(50, 50, 0, 0);
//_printDoc.DefaultPageSettings.Margins = margin; //_printDoc.DefaultPageSettings.Margins = margin;
//var adItem = new AdItem {Name = "Celery"};
//var db = new AdvertisingProfitControlContext();
//db.AdItems.Add(adItem);
//db.SaveChanges();
} }
private void CalculateProfitAnalysis(double shrink = 0.30) private void CalculateProfitAnalysis(decimal shrink = 0.30m)
{ {
if (actualSalesDataGridView.Rows.Count == 0) if (actualSalesDataGridView.Rows.Count == 0)
{ {
@@ -73,12 +69,12 @@ namespace AdvertsingProfitControl
var incompleteData = false; var incompleteData = false;
//First grab the total sales and the total profit return generated by the actual sales of product. //First grab the total sales and the total profit return generated by the actual sales of product.
if ( if (
double.TryParse( decimal.TryParse(
actualSalesDataGridView.Rows[actualSalesDataGridView.Rows.Count - 1].Cells[3].EditedFormattedValue actualSalesDataGridView.Rows[actualSalesDataGridView.Rows.Count - 1].Cells[3].EditedFormattedValue
.ToString(), out _salesProducedByAdItems)) .ToString(), out _salesProducedByAdItems))
{ {
//The sales parsed properly so there is data in the cell. Next try to grab the total profit return. //The sales parsed properly so there is data in the cell. Next try to grab the total profit return.
if (double.TryParse( if (decimal.TryParse(
actualSalesDataGridView.Rows[actualSalesDataGridView.Rows.Count - 1].Cells[6].EditedFormattedValue actualSalesDataGridView.Rows[actualSalesDataGridView.Rows.Count - 1].Cells[6].EditedFormattedValue
.ToString(), out _totalProfitReturnFromAdItems)) .ToString(), out _totalProfitReturnFromAdItems))
{ {
@@ -112,7 +108,7 @@ namespace AdvertsingProfitControl
//Again assume the total profit return is larger then zero (0). //Again assume the total profit return is larger then zero (0).
totalProfitFromAdItemsLabel.Text = @"Total Profit Return" + Environment.NewLine + @" From Ad Items (B): " + _totalProfitReturnFromAdItems.ToString("C"); totalProfitFromAdItemsLabel.Text = @"Total Profit Return" + Environment.NewLine + @" From Ad Items (B): " + _totalProfitReturnFromAdItems.ToString("C");
//Shrink is being used as a place holder for Cross Profit % which is obtained by dividing the total profit return from the department weekly retail sales. //Shrink is being used as a place holder for Cross Profit % which is obtained by dividing the total profit return from the department weekly retail sales.
var totalProfitReturnFromRemainingSales = shrink*remainingSales; var totalProfitReturnFromRemainingSales = shrink * remainingSales;
// //
totalProfitReturnFromRemaingLabel.Text = @"Total Profit Return" + Environment.NewLine + @" From Remaining Sales: " + totalProfitReturnFromRemainingSales.ToString("C"); totalProfitReturnFromRemaingLabel.Text = @"Total Profit Return" + Environment.NewLine + @" From Remaining Sales: " + totalProfitReturnFromRemainingSales.ToString("C");
var totalProfitReturn = _totalProfitReturnFromAdItems + totalProfitReturnFromRemainingSales; var totalProfitReturn = _totalProfitReturnFromAdItems + totalProfitReturnFromRemainingSales;
@@ -242,12 +238,12 @@ namespace AdvertsingProfitControl
var dateId = var dateId =
databaseReader.RetrieveDateIdByDateString(monthCalendar.SelectionStart.ToShortDateString(), databaseReader.RetrieveDateIdByDateString(monthCalendar.SelectionStart.ToShortDateString(),
databaseTracker.DatabaseConnectionString); databaseTracker.DatabaseConnectionString);
double remaingingSales = _departmentSales - _salesProducedByAdItems; var remaingingSales = _departmentSales - _salesProducedByAdItems;
double totalProfitReturnFromReminaingSales = remaingingSales*.3; var totalProfitReturnFromReminaingSales = remaingingSales * .3m;
double totalProfitReturn = _totalProfitReturnFromAdItems + totalProfitReturnFromReminaingSales; var totalProfitReturn = _totalProfitReturnFromAdItems + totalProfitReturnFromReminaingSales;
test.BuildFormFrontCompressedLayout(dateId, _departmentSales, _salesProducedByAdItems, remaingingSales, //test.BuildFormFrontCompressedLayout(dateId, _departmentSales, _salesProducedByAdItems, remaingingSales,
_totalProfitReturnFromAdItems, totalProfitReturnFromReminaingSales, totalProfitReturn, //_totalProfitReturnFromAdItems, totalProfitReturnFromReminaingSales, totalProfitReturn,
commentsTextBox.Text); //commentsTextBox.Text);
test.RenderHtmlToImage(); test.RenderHtmlToImage();
backPageTest.GenerateWeeklyInventoryControlPage(dateId); backPageTest.GenerateWeeklyInventoryControlPage(dateId);
backPageTest.RenderHtmlToImage(); backPageTest.RenderHtmlToImage();
@@ -371,8 +367,11 @@ namespace AdvertsingProfitControl
LoadInventoryTable(dateRecord); LoadInventoryTable(dateRecord);
LoadActualSalesTable(dateRecord); LoadActualSalesTable(dateRecord);
LoadInvoices(dateRecord); LoadInvoices(dateRecord);
if (db.Notes.Any(x => x.FkDateId == dateRecord.Id))
{
var note = db.Notes.Single(x => x.FkDateId == dateRecord.Id); var note = db.Notes.Single(x => x.FkDateId == dateRecord.Id);
commentsTextBox.Text = note.Remark; commentsTextBox.Text = note.Remark;
}
LoadWeeklySales(dateRecord); LoadWeeklySales(dateRecord);
LoadTaxable(dateRecord); LoadTaxable(dateRecord);
LoadCostAnalysis(dateRecord); LoadCostAnalysis(dateRecord);
@@ -423,6 +422,7 @@ namespace AdvertsingProfitControl
} }
} }
//Now add the totals row. //Now add the totals row.
if (projectionsDataGridView.RowCount == 0) return;
var totalsRow = new DataGridViewRow(); var totalsRow = new DataGridViewRow();
projectionsDataGridView.Rows.Add(totalsRow); projectionsDataGridView.Rows.Add(totalsRow);
projectionsDataGridView.Rows[projectionsDataGridView.Rows.Count - 1].Cells[0].Value = "Total"; projectionsDataGridView.Rows[projectionsDataGridView.Rows.Count - 1].Cells[0].Value = "Total";
@@ -517,6 +517,7 @@ namespace AdvertsingProfitControl
} }
} }
//Now add the totals row. //Now add the totals row.
if (actualSalesDataGridView.RowCount == 0) return;
var totalsRow = new DataGridViewRow(); var totalsRow = new DataGridViewRow();
actualSalesDataGridView.Rows.Add(totalsRow); actualSalesDataGridView.Rows.Add(totalsRow);
actualSalesDataGridView.Rows[actualSalesDataGridView.Rows.Count - 1].Cells[0].Value = "Total"; actualSalesDataGridView.Rows[actualSalesDataGridView.Rows.Count - 1].Cells[0].Value = "Total";
@@ -553,7 +554,7 @@ namespace AdvertsingProfitControl
invoicesDataGridView.Rows[index].Cells[2].Value = invoice.InvoiceNumber; invoicesDataGridView.Rows[index].Cells[2].Value = invoice.InvoiceNumber;
invoicesDataGridView.Rows[index].Cells[3].Value = $@"{invoice.InvoiceNetAmountAtCost:N2}"; invoicesDataGridView.Rows[index].Cells[3].Value = $@"{invoice.InvoiceNetAmountAtCost:N2}";
invoicesDataGridView.Rows[index].Cells[4].Value = $@"{invoice.InvoiceNetAmount:N2}"; invoicesDataGridView.Rows[index].Cells[4].Value = $@"{invoice.InvoiceNetAmount:N2}";
if (invoice.InvoiceNetAmount != null) _totalInvoicePurchases += (double)invoice.InvoiceNetAmount; if (invoice.InvoiceNetAmount != null) _totalInvoicePurchases += (decimal) invoice.InvoiceNetAmount;
invoicesDataGridView.Rows[index].Cells[5].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.
@@ -574,19 +575,19 @@ namespace AdvertsingProfitControl
var weeklySales = db.WeeklySales.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x); var weeklySales = db.WeeklySales.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x);
foreach (var sale in weeklySales) foreach (var sale in weeklySales)
{ {
if (sale.Sunday != null) _departmentSales += (double)sale.Sunday; if (sale.Sunday != null) _departmentSales += (decimal) sale.Sunday;
sundayWeeklySalesLabel.Text = @"Sunday: " + $@"{sale.Sunday:c}"; sundayWeeklySalesLabel.Text = @"Sunday: " + $@"{sale.Sunday:c}";
if (sale.Monday != null) _departmentSales += (double)sale.Monday; if (sale.Monday != null) _departmentSales += (decimal) sale.Monday;
mondayWeeklySalesLabel.Text = @"Monday: " + $@"{sale.Monday:c}"; mondayWeeklySalesLabel.Text = @"Monday: " + $@"{sale.Monday:c}";
if (sale.Tuesday != null) _departmentSales += (double)sale.Tuesday; if (sale.Tuesday != null) _departmentSales += (decimal) sale.Tuesday;
tuesadayWeeklySalesLabel.Text = @"Tuesday: " + $@"{sale.Tuesday:c}"; tuesadayWeeklySalesLabel.Text = @"Tuesday: " + $@"{sale.Tuesday:c}";
if (sale.Wednesday != null) _departmentSales += (double)sale.Wednesday; if (sale.Wednesday != null) _departmentSales += (decimal) sale.Wednesday;
wednesdayWeeklySalesLabel.Text = @"Wednesday: " + $@"{sale.Wednesday:c}"; wednesdayWeeklySalesLabel.Text = @"Wednesday: " + $@"{sale.Wednesday:c}";
if (sale.Thursday != null) _departmentSales += (double)sale.Thursday; if (sale.Thursday != null) _departmentSales += (decimal)sale.Thursday;
thursdayWeeklySalesLabel.Text = @"Thursday: " + $@"{sale.Thursday:c}"; thursdayWeeklySalesLabel.Text = @"Thursday: " + $@"{sale.Thursday:c}";
if (sale.Friday != null) _departmentSales += (double)sale.Friday; if (sale.Friday != null) _departmentSales += (decimal) sale.Friday;
fridayWeeklySalesLabel.Text = @"Friday: " + $@"{sale.Friday:c}"; fridayWeeklySalesLabel.Text = @"Friday: " + $@"{sale.Friday:c}";
if (sale.Saturday != null) _departmentSales += (double)sale.Saturday; if (sale.Saturday != null) _departmentSales += (decimal) sale.Saturday;
saturdayWeeklySalesLabel.Text = @"Saturday: " + $@"{sale.Saturday:c}"; saturdayWeeklySalesLabel.Text = @"Saturday: " + $@"{sale.Saturday:c}";
totalWeeklySalesLabel.Text = @"Total Sales: " + $@"{sale.TotalSales:c}"; totalWeeklySalesLabel.Text = @"Total Sales: " + $@"{sale.TotalSales:c}";
} }
@@ -608,6 +609,11 @@ namespace AdvertsingProfitControl
saturdayTaxableLabel.Text = @"Saturday: " + $@"{taxable.Saturday:c}"; saturdayTaxableLabel.Text = @"Saturday: " + $@"{taxable.Saturday:c}";
totalTaxableLabel.Text = @"Total: " + $@"{taxable.Total:c}"; totalTaxableLabel.Text = @"Total: " + $@"{taxable.Total:c}";
} }
////See if there are any items and see if any of them are holidays (have a value of zero).
//if (taxables.ToList().Count == 1)
//{
// var Spam = taxables.Select(x => x.)
//}
} }
private void LoadCostAnalysis(WeekEndingDate dateRecord) private void LoadCostAnalysis(WeekEndingDate dateRecord)
File diff suppressed because it is too large Load Diff