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,
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>
</Content>
<Content Include="APCDatabase Template Script.sql" />
<Content Include="APCTemplate.accdb">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Stretched Logo Collection.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+35 -29
View File
@@ -14,10 +14,10 @@ namespace AdvertsingProfitControl
{
public partial class FrmMain : Form
{
private double _salesProducedByAdItems;
private double _totalProfitReturnFromAdItems;
private double _totalInvoicePurchases; //Total Purchases
private double _departmentSales; //weekly sales total
private decimal _salesProducedByAdItems;
private decimal _totalProfitReturnFromAdItems;
private decimal _totalInvoicePurchases; //Total Purchases
private decimal _departmentSales; //weekly sales total
private DateTime _currentActiveDate;
private readonly FrmLogConsole _console = FrmLogConsole.GetStaticInstance;
private int _LazyPageCounter;
@@ -39,7 +39,7 @@ namespace AdvertsingProfitControl
monthCalendar.BoldedDates = db.WeekEndingDates.Select(zdate => zdate.EndingDate).ToArray();
ConstructApcDataGridViews();
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.
var recentDate = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault();
if (recentDate != null)
@@ -51,14 +51,10 @@ namespace AdvertsingProfitControl
//projectionsDataGridView.KeyDown += FrmMain_KeyDown;
//var margin = new Margins(50, 50, 0, 0);
//_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)
{
@@ -73,12 +69,12 @@ namespace AdvertsingProfitControl
var incompleteData = false;
//First grab the total sales and the total profit return generated by the actual sales of product.
if (
double.TryParse(
decimal.TryParse(
actualSalesDataGridView.Rows[actualSalesDataGridView.Rows.Count - 1].Cells[3].EditedFormattedValue
.ToString(), out _salesProducedByAdItems))
{
//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
.ToString(), out _totalProfitReturnFromAdItems))
{
@@ -112,7 +108,7 @@ namespace AdvertsingProfitControl
//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");
//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");
var totalProfitReturn = _totalProfitReturnFromAdItems + totalProfitReturnFromRemainingSales;
@@ -242,12 +238,12 @@ namespace AdvertsingProfitControl
var dateId =
databaseReader.RetrieveDateIdByDateString(monthCalendar.SelectionStart.ToShortDateString(),
databaseTracker.DatabaseConnectionString);
double remaingingSales = _departmentSales - _salesProducedByAdItems;
double totalProfitReturnFromReminaingSales = remaingingSales*.3;
double totalProfitReturn = _totalProfitReturnFromAdItems + totalProfitReturnFromReminaingSales;
test.BuildFormFrontCompressedLayout(dateId, _departmentSales, _salesProducedByAdItems, remaingingSales,
_totalProfitReturnFromAdItems, totalProfitReturnFromReminaingSales, totalProfitReturn,
commentsTextBox.Text);
var remaingingSales = _departmentSales - _salesProducedByAdItems;
var totalProfitReturnFromReminaingSales = remaingingSales * .3m;
var totalProfitReturn = _totalProfitReturnFromAdItems + totalProfitReturnFromReminaingSales;
//test.BuildFormFrontCompressedLayout(dateId, _departmentSales, _salesProducedByAdItems, remaingingSales,
//_totalProfitReturnFromAdItems, totalProfitReturnFromReminaingSales, totalProfitReturn,
//commentsTextBox.Text);
test.RenderHtmlToImage();
backPageTest.GenerateWeeklyInventoryControlPage(dateId);
backPageTest.RenderHtmlToImage();
@@ -371,8 +367,11 @@ namespace AdvertsingProfitControl
LoadInventoryTable(dateRecord);
LoadActualSalesTable(dateRecord);
LoadInvoices(dateRecord);
var note = db.Notes.Single(x => x.FkDateId == dateRecord.Id);
commentsTextBox.Text = note.Remark;
if (db.Notes.Any(x => x.FkDateId == dateRecord.Id))
{
var note = db.Notes.Single(x => x.FkDateId == dateRecord.Id);
commentsTextBox.Text = note.Remark;
}
LoadWeeklySales(dateRecord);
LoadTaxable(dateRecord);
LoadCostAnalysis(dateRecord);
@@ -423,6 +422,7 @@ namespace AdvertsingProfitControl
}
}
//Now add the totals row.
if (projectionsDataGridView.RowCount == 0) return;
var totalsRow = new DataGridViewRow();
projectionsDataGridView.Rows.Add(totalsRow);
projectionsDataGridView.Rows[projectionsDataGridView.Rows.Count - 1].Cells[0].Value = "Total";
@@ -517,6 +517,7 @@ namespace AdvertsingProfitControl
}
}
//Now add the totals row.
if (actualSalesDataGridView.RowCount == 0) return;
var totalsRow = new DataGridViewRow();
actualSalesDataGridView.Rows.Add(totalsRow);
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[3].Value = $@"{invoice.InvoiceNetAmountAtCost: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;
}
//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);
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}";
if (sale.Monday != null) _departmentSales += (double)sale.Monday;
if (sale.Monday != null) _departmentSales += (decimal) sale.Monday;
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}";
if (sale.Wednesday != null) _departmentSales += (double)sale.Wednesday;
if (sale.Wednesday != null) _departmentSales += (decimal) sale.Wednesday;
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}";
if (sale.Friday != null) _departmentSales += (double)sale.Friday;
if (sale.Friday != null) _departmentSales += (decimal) sale.Friday;
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}";
totalWeeklySalesLabel.Text = @"Total Sales: " + $@"{sale.TotalSales:c}";
}
@@ -608,6 +609,11 @@ namespace AdvertsingProfitControl
saturdayTaxableLabel.Text = @"Saturday: " + $@"{taxable.Saturday: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)
File diff suppressed because it is too large Load Diff