Completely removed all the old database interaction code, save the database converter form. Updated the formatting in the weekly and taxable areas on the modify record form. Re-enabled holiday checking on the main form.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.Entity.Infrastructure;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
@@ -14,6 +13,7 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
public partial class NewModifyRecord : Form
|
||||
{
|
||||
//TODO: Re-enable drag and drop on the modify record form.
|
||||
//http://stackoverflow.com/questions/6219454/efficient-way-to-remove-all-whitespace-from-string
|
||||
private static readonly FrmLogConsole LogConsole = FrmLogConsole.GetStaticInstance;
|
||||
//Create an array that contains all the ad items from the database.
|
||||
@@ -422,13 +422,11 @@ namespace AdvertsingProfitControl
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
//If so create the database interaction objects.
|
||||
var dbTracker = new DatabaseTracker();
|
||||
var dbWriter = new DatabaseWriter(dbTracker.DatabaseConnectionString);
|
||||
var id =
|
||||
int.Parse(
|
||||
invoicesDataGridView.Rows[rowIndex].Cells[(int)InvoiceTableColumns.Id].EditedFormattedValue
|
||||
.ToString());
|
||||
if (dbWriter.DeleteInvoiceRow(id))
|
||||
if (DeleteInvoiceRow(id))
|
||||
{
|
||||
informationLabel.Text = @"Successfully removed row " + (rowIndex + 1) + @" from the database.";
|
||||
}
|
||||
@@ -583,8 +581,6 @@ namespace AdvertsingProfitControl
|
||||
var dataGridView = (DataGridView)sender;
|
||||
if (dataGridView.CurrentRow == null) return;
|
||||
//Create the database writer object so rows that are in the database can be deleted.
|
||||
var dbTracker = new DatabaseTracker();
|
||||
var dbWriter = new DatabaseWriter(dbTracker.DatabaseConnectionString);
|
||||
var currentRowIndex = dataGridView.CurrentRow.Index;
|
||||
//Remove the ad item from the gUsedAdItem collection, if it exists.
|
||||
if (_adSpecialIndex == -1)
|
||||
@@ -596,20 +592,17 @@ namespace AdvertsingProfitControl
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
//Attempt to delete the row from the database by its ID number.
|
||||
int projectionsRowId;
|
||||
int inventoryRowId;
|
||||
int actualSalesRowId;
|
||||
//Attempt to delete the row from the database by its ID number.
|
||||
int.TryParse(
|
||||
projectionsDataGridView.Rows[currentRowIndex].Cells[(int) SalesTableColumns.Id]
|
||||
.EditedFormattedValue.ToString(), out projectionsRowId);
|
||||
projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id]
|
||||
.EditedFormattedValue.ToString(), out int projectionsRowId);
|
||||
int.TryParse(
|
||||
inventoryDataGridView.Rows[currentRowIndex].Cells[(int) SalesTableColumns.Id]
|
||||
.EditedFormattedValue.ToString(), out inventoryRowId);
|
||||
.EditedFormattedValue.ToString(), out int inventoryRowId);
|
||||
int.TryParse(
|
||||
actualSalesDataGridView.Rows[currentRowIndex].Cells[(int) SalesTableColumns.Id]
|
||||
.EditedFormattedValue.ToString(), out actualSalesRowId);
|
||||
if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
.EditedFormattedValue.ToString(), out int actualSalesRowId);
|
||||
if (DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
{
|
||||
informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) +
|
||||
@" from the database.";
|
||||
@@ -643,14 +636,11 @@ namespace AdvertsingProfitControl
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
//Attempt to delete the row from the database by its ID number.
|
||||
int projectionsRowId;
|
||||
int inventoryRowId;
|
||||
int actualSalesRowId;
|
||||
//Attempt to delete the row from the database by its ID number.
|
||||
int.TryParse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out projectionsRowId);
|
||||
int.TryParse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out inventoryRowId);
|
||||
int.TryParse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out actualSalesRowId);
|
||||
if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
int.TryParse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out int projectionsRowId);
|
||||
int.TryParse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out int inventoryRowId);
|
||||
int.TryParse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out int actualSalesRowId);
|
||||
if (DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
{
|
||||
informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database.";
|
||||
}
|
||||
@@ -688,7 +678,7 @@ namespace AdvertsingProfitControl
|
||||
var projectionsRowId = int.Parse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
var inventoryRowId = int.Parse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
var actualSalesRowId = int.Parse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString());
|
||||
if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
if (DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
{
|
||||
informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database.";
|
||||
}
|
||||
@@ -743,7 +733,7 @@ namespace AdvertsingProfitControl
|
||||
int.TryParse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out projectionsRowId);
|
||||
int.TryParse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out inventoryRowId);
|
||||
int.TryParse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out actualSalesRowId);
|
||||
if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
if (DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId))
|
||||
{
|
||||
informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database.";
|
||||
}
|
||||
@@ -983,9 +973,7 @@ namespace AdvertsingProfitControl
|
||||
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
if (!dbW.DeleteApcRow(
|
||||
if (!DeleteApcRow(
|
||||
int.Parse(
|
||||
projectionsDataGridView.Rows[e.RowIndex].Cells[
|
||||
(int) SalesTableColumns.Id].EditedFormattedValue.ToString()),
|
||||
@@ -1509,9 +1497,7 @@ namespace AdvertsingProfitControl
|
||||
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
var dbT = new DatabaseTracker();
|
||||
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
|
||||
if (!dbW.DeleteApcRow(
|
||||
if (DeleteApcRow(
|
||||
int.Parse(
|
||||
projectionsDataGridView.Rows[e.RowIndex].Cells[
|
||||
(int)SalesTableColumns.Id].EditedFormattedValue.ToString()),
|
||||
@@ -2732,12 +2718,9 @@ namespace AdvertsingProfitControl
|
||||
|
||||
private void LoadDate(DateTime date)
|
||||
{
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var dateRecord = db.WeekEndingDates.Single(x => x.EndingDate == date);
|
||||
var dateId = databaseReader.RetrieveDateIdByDateString(date.ToString("d"), databaseTracker.DatabaseConnectionString);
|
||||
if (dateId == 0)
|
||||
var dateRecord = db.WeekEndingDates.SingleOrDefault(x => x.EndingDate == date);
|
||||
if (dateRecord == null)
|
||||
{
|
||||
errorLabel.Text = @"Failed to get the date ID number, aborting load operation." + Environment.NewLine;
|
||||
return;
|
||||
@@ -2746,45 +2729,11 @@ namespace AdvertsingProfitControl
|
||||
LoadProjectionsTable(dateRecord);
|
||||
LoadInventory(dateRecord);
|
||||
LoadActualSales(dateRecord);
|
||||
var invoices = databaseReader.ReturnInvoiceTable(dateId, databaseTracker.DatabaseConnectionString);
|
||||
var comments = databaseReader.RetrieveComments(int.Parse(dateId.ToString()), databaseTracker.DatabaseConnectionString);
|
||||
if (comments.Count == 2)
|
||||
{
|
||||
LoadComments(int.Parse(comments[0]), comments[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No comments to display." + Environment.NewLine;
|
||||
}
|
||||
var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId, databaseTracker.DatabaseConnectionString);
|
||||
if (weeklySales.Rows.Count == 1)
|
||||
{
|
||||
LoadWeeklySales(weeklySales);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No sales to display." + Environment.NewLine;
|
||||
}
|
||||
|
||||
var taxable = databaseReader.ReturnTaxableFromDateId(dateId, databaseTracker.DatabaseConnectionString);
|
||||
if (taxable.Rows.Count == 1)
|
||||
{
|
||||
LoadTaxable(taxable);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No taxable data to display." + Environment.NewLine;
|
||||
}
|
||||
LoadInvoices(invoices);
|
||||
var costAnalysis = databaseReader.ReturnCostAnalysis(dateId, databaseTracker.DatabaseConnectionString);
|
||||
if (costAnalysis.Rows.Count == 1)
|
||||
{
|
||||
LoadCostAnalysis(costAnalysis);
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No cost analysis data to display." + Environment.NewLine;
|
||||
}
|
||||
LoadInvoices(dateRecord);
|
||||
LoadComments(dateRecord);
|
||||
LoadWeeklySales(dateRecord);
|
||||
LoadTaxable(dateRecord);
|
||||
LoadCostAnalysis(dateRecord);
|
||||
_formRoll = FormRoll.ModifyRecord;
|
||||
}
|
||||
|
||||
@@ -2978,59 +2927,44 @@ namespace AdvertsingProfitControl
|
||||
actualSalesDataGridView.RowValidating += ValidateActualSalesRow;
|
||||
}
|
||||
|
||||
private void LoadInvoices(DataTable invoices)
|
||||
private void LoadInvoices(WeekEndingDate dateRecord)
|
||||
{
|
||||
for (var rowIndex = 0; rowIndex < invoices.Rows.Count; rowIndex++)
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var invoices = db.Invoices.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x);
|
||||
var index = 0;
|
||||
foreach (var invoice in invoices)
|
||||
{
|
||||
var row = new DataGridViewRow();
|
||||
for (var cellIndex = 0; cellIndex < invoices.Rows[rowIndex].ItemArray.Length; cellIndex++)
|
||||
{
|
||||
var cell = new DataGridViewTextBoxCell();
|
||||
//Format the invoice date.
|
||||
if (cellIndex == 1)
|
||||
{
|
||||
var date = DateTime.Parse(invoices.Rows[rowIndex].ItemArray[cellIndex].ToString());
|
||||
cell.Value = date.ToString("d");
|
||||
row.Cells.Add(cell);
|
||||
continue;
|
||||
}
|
||||
//Apply formatting to the only cells that will have currency values in them.
|
||||
if (cellIndex == 4 || cellIndex == 5)
|
||||
{
|
||||
var formattedNumber = Math.Round(double.Parse(invoices.Rows[rowIndex].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
cell.Value = formattedNumber;
|
||||
}
|
||||
row.Cells.Add(cell);
|
||||
continue;
|
||||
}
|
||||
//No special formatting rules here so just put the value in and move on.
|
||||
cell.Value = invoices.Rows[rowIndex].ItemArray[cellIndex].ToString();
|
||||
row.Cells.Add(cell);
|
||||
}
|
||||
//Set the is dirty cell to false.
|
||||
var isDirtyCell = new DataGridViewCheckBoxCell
|
||||
{
|
||||
Value = false
|
||||
};
|
||||
row.Cells.Add(isDirtyCell);
|
||||
invoicesDataGridView.Rows.Add(row);
|
||||
invoicesDataGridView.Rows.Add();
|
||||
invoicesDataGridView.Rows[index].Cells[0].Value = invoice.Id;
|
||||
invoicesDataGridView.Rows[index].Cells[2].Value = invoice.Supplier.Name;
|
||||
invoicesDataGridView.Rows[index].Cells[1].Value = invoice.InvoiceDate.ToString("d");
|
||||
invoicesDataGridView.Rows[index].Cells[3].Value = invoice.InvoiceNumber;
|
||||
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[6].Value = invoice.InvoiceNote;
|
||||
invoicesDataGridView.Rows[index].Cells[(int)InvoiceTableColumns.IsDirty].Value = false;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadComments(int id, string comments)
|
||||
private void LoadComments(WeekEndingDate dateRecord)
|
||||
{
|
||||
//commentsTextBox.TextChanged -= DisplayRemainingCommentCharacterCount;
|
||||
commentsTextBox.Enter -= StoreBeginningTextBoxValue;
|
||||
commentsTextBox.KeyDown -= CheckForKeyCommand;
|
||||
commentsTextBox.Leave -= CheckForTextChangeOnLeave;
|
||||
|
||||
isCommentDirtyCheckBox.Text = @"isCommentsDirty (" + id + @")";
|
||||
isCommentDirtyCheckBox.Tag = id;
|
||||
|
||||
commentsTextBox.Text = comments;
|
||||
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var comments = db.Notes.SingleOrDefault(x => x.FkDateId == dateRecord.Id);
|
||||
if (comments != null)
|
||||
{
|
||||
isCommentDirtyCheckBox.Tag = comments.Id;
|
||||
isCommentDirtyCheckBox.Text = @"IsCommentsDirty (" + comments.Id + @")";
|
||||
commentsTextBox.Text = comments.Remark;
|
||||
}
|
||||
else
|
||||
{
|
||||
informationLabel.Text += @"No comments to display." + Environment.NewLine;
|
||||
}
|
||||
//commentsGroupBox.Text = @"Comments (Characters Remaining: " + commentsTextBox.MaxLength + @")";
|
||||
//commentsTextBox.TextChanged += DisplayRemainingCommentCharacterCount;
|
||||
commentsTextBox.Enter += StoreBeginningTextBoxValue;
|
||||
@@ -3038,7 +2972,7 @@ namespace AdvertsingProfitControl
|
||||
commentsTextBox.Leave += CheckForTextChangeOnLeave;
|
||||
}
|
||||
|
||||
private void LoadWeeklySales(DataTable weeklySales)
|
||||
private void LoadWeeklySales(WeekEndingDate dateRecord)
|
||||
{
|
||||
sundayWeeklySalesTextBox.Enter -= StoreBeginningTextBoxValue;
|
||||
sundayWeeklySalesTextBox.Validating -= ValidateWeeklySales;
|
||||
@@ -3057,80 +2991,27 @@ namespace AdvertsingProfitControl
|
||||
totalWeeklySalesTextBox.Enter -= StoreBeginningTextBoxValue;
|
||||
totalWeeklySalesTextBox.Validating -= ValidateWeeklySales;
|
||||
|
||||
//Spin through the only row in the weekly sales table. Item in item
|
||||
//array index zero (0) is the ID number of the weekly sales.
|
||||
for (var cellIndex = 0; cellIndex < weeklySales.Rows[0].ItemArray.Length; cellIndex++)
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var weeklySale = db.WeeklySales.SingleOrDefault(x => x.FkDateId == dateRecord.Id);
|
||||
if (weeklySale == null)
|
||||
{
|
||||
if (cellIndex == 0)
|
||||
{
|
||||
//ID number
|
||||
var id = int.Parse(weeklySales.Rows[0].ItemArray[cellIndex].ToString());
|
||||
isWeeklySalesDirtyCheckBox.Tag = id;
|
||||
isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty (" + id + @")";
|
||||
continue;
|
||||
}
|
||||
string formattedNumber;
|
||||
switch (cellIndex)
|
||||
{
|
||||
case 1: //Sunday
|
||||
formattedNumber = Math.Round(double.Parse(weeklySales.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
sundayWeeklySalesTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 2: //Monday
|
||||
formattedNumber = Math.Round(double.Parse(weeklySales.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
mondayWeeklySalesTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 3: //Tuesday
|
||||
formattedNumber = Math.Round(double.Parse(weeklySales.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
tuesdayWeeklySalesTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 4: //Wednesday
|
||||
formattedNumber = Math.Round(double.Parse(weeklySales.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
wednesdayWeeklySalesTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 5: //Thursday
|
||||
formattedNumber = Math.Round(double.Parse(weeklySales.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
thursdayWeeklySalesTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 6: //Friday
|
||||
formattedNumber = Math.Round(double.Parse(weeklySales.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
fridayWeeklySalesTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 7: //Saturday
|
||||
formattedNumber = Math.Round(double.Parse(weeklySales.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
saturdayWeeklySalesTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 8: //Total Sales
|
||||
formattedNumber = Math.Round(double.Parse(weeklySales.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
totalWeeklySalesTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
}
|
||||
informationLabel.Text += @"No weekly sales to display." + Environment.NewLine;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
sundayWeeklySalesTextBox.Text = weeklySale.Sunday == 0 ? string.Empty : $"{weeklySale.Sunday:N2}";
|
||||
mondayWeeklySalesTextBox.Text = weeklySale.Monday == 0 ? string.Empty : $"{weeklySale.Monday:N2}";
|
||||
tuesdayWeeklySalesTextBox.Text = weeklySale.Tuesday == 0 ? string.Empty : $"{weeklySale.Tuesday:N2}";
|
||||
wednesdayWeeklySalesTextBox.Text = weeklySale.Wednesday == 0 ? string.Empty : $"{weeklySale.Wednesday:N2}";
|
||||
thursdayWeeklySalesTextBox.Text = weeklySale.Thursday == 0 ? string.Empty : $"{weeklySale.Thursday:N2}";
|
||||
fridayWeeklySalesTextBox.Text = weeklySale.Friday == 0 ? string.Empty : $"{weeklySale.Friday:N2}";
|
||||
saturdayWeeklySalesTextBox.Text = weeklySale.Saturday == 0 ? string.Empty : $"{weeklySale.Saturday:N2}";
|
||||
totalWeeklySalesTextBox.Text = weeklySale.TotalSales == 0 ? string.Empty : $"{weeklySale.TotalSales:N2}";
|
||||
//Set the internal state
|
||||
isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty (" + weeklySale.Id + @")";
|
||||
isWeeklySalesDirtyCheckBox.Tag = weeklySale.Id;
|
||||
}
|
||||
//Re-enable the events
|
||||
sundayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
|
||||
sundayWeeklySalesTextBox.Validating += ValidateWeeklySales;
|
||||
mondayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
|
||||
@@ -3149,7 +3030,7 @@ namespace AdvertsingProfitControl
|
||||
totalWeeklySalesTextBox.Validating += ValidateWeeklySales;
|
||||
}
|
||||
|
||||
private void LoadTaxable(DataTable taxable)
|
||||
private void LoadTaxable(WeekEndingDate dateRecord)
|
||||
{
|
||||
sundayTaxableTextBox.Enter -= StoreBeginningTextBoxValue;
|
||||
sundayTaxableTextBox.Validating -= ValidateTaxableFields;
|
||||
@@ -3167,78 +3048,25 @@ namespace AdvertsingProfitControl
|
||||
saturdayTaxableTextBox.Validating -= ValidateTaxableFields;
|
||||
totalTaxableTextBox.Enter -= StoreBeginningTextBoxValue;
|
||||
totalTaxableTextBox.Validating -= ValidateTaxableFields;
|
||||
//Spin through the only row in the taxable table. Item in item
|
||||
//array index zero (0) is the ID number of the weekly sales.
|
||||
for (var cellIndex = 0; cellIndex < taxable.Rows[0].ItemArray.Length; cellIndex++)
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var taxable = db.Taxables.SingleOrDefault(x => x.FkDateId == dateRecord.Id);
|
||||
if (taxable == null)
|
||||
{
|
||||
if (cellIndex == 0)
|
||||
{
|
||||
//ID number
|
||||
var id = int.Parse(taxable.Rows[0].ItemArray[cellIndex].ToString());
|
||||
isTaxableDirtyCheckBox.Tag = id;
|
||||
isTaxableDirtyCheckBox.Text = @"IsTaxableDirty (" + id + @")";
|
||||
continue;
|
||||
}
|
||||
string formattedNumber;
|
||||
switch (cellIndex)
|
||||
{
|
||||
case 1: //Sunday
|
||||
formattedNumber = Math.Round(double.Parse(taxable.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
sundayTaxableTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 2: //Monday
|
||||
formattedNumber = Math.Round(double.Parse(taxable.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
mondayTaxableTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 3: //Tuesday
|
||||
formattedNumber = Math.Round(double.Parse(taxable.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
tuesdayTaxableTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 4: //Wednesday
|
||||
formattedNumber = Math.Round(double.Parse(taxable.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
wednesdayTaxableTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 5: //Thursday
|
||||
formattedNumber = Math.Round(double.Parse(taxable.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
thursdayTaxableTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 6: //Friday
|
||||
formattedNumber = Math.Round(double.Parse(taxable.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
fridayTaxableTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 7: //Saturday
|
||||
formattedNumber = Math.Round(double.Parse(taxable.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
saturdayTaxableTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 8: //Total Taxable
|
||||
formattedNumber = Math.Round(double.Parse(taxable.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
totalTaxableTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
}
|
||||
informationLabel.Text += @"No taxables to display." + Environment.NewLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
sundayTaxableTextBox.Text = taxable.Sunday == 0 ? string.Empty : $"{taxable.Sunday:N2}";
|
||||
mondayTaxableTextBox.Text = taxable.Monday == 0 ? string.Empty : $"{taxable.Monday:N2}";
|
||||
tuesdayTaxableTextBox.Text = taxable.Tuesday == 0 ? string.Empty : $"{taxable.Tuesday:N2}";
|
||||
wednesdayTaxableTextBox.Text = taxable.Wednesday == 0 ? string.Empty : $"{taxable.Wednesday:N2}";
|
||||
thursdayTaxableTextBox.Text = taxable.Thursday == 0 ? string.Empty : $"{taxable.Thursday:N2}";
|
||||
fridayTaxableTextBox.Text = taxable.Friday == 0 ? string.Empty : $"{taxable.Friday:N2}";
|
||||
saturdayTaxableTextBox.Text = taxable.Saturday == 0 ? string.Empty : $"{taxable.Saturday:N2}";
|
||||
totalTaxableTextBox.Text = taxable.Total == 0 ? string.Empty : $"{taxable.Total:N2}";
|
||||
//Set the internal state
|
||||
isTaxableDirtyCheckBox.Text = @"IsTaxableDirty (" + taxable.Id + @")";
|
||||
isTaxableDirtyCheckBox.Tag = taxable.Id;
|
||||
}
|
||||
sundayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
|
||||
sundayTaxableTextBox.Validating += ValidateTaxableFields;
|
||||
@@ -3258,7 +3086,7 @@ namespace AdvertsingProfitControl
|
||||
totalTaxableTextBox.Validating += ValidateTaxableFields;
|
||||
}
|
||||
|
||||
private void LoadCostAnalysis(DataTable costAnalysis)
|
||||
private void LoadCostAnalysis(WeekEndingDate dateRecord)
|
||||
{
|
||||
salesPerManHourTextBox.Enter -= StoreBeginningTextBoxValue;
|
||||
salesPerManHourTextBox.Validating -= ValidateCostAnalysisValues;
|
||||
@@ -3268,50 +3096,22 @@ namespace AdvertsingProfitControl
|
||||
salaryDollarsTextBox.Validating -= ValidateCostAnalysisValues;
|
||||
suppliesTextBox.Enter -= StoreBeginningTextBoxValue;
|
||||
suppliesTextBox.Validating -= ValidateCostAnalysisValues;
|
||||
//Spin through the only row in the taxable table. Item in item
|
||||
//array index zero (0) is the ID number of the weekly sales.
|
||||
for (var cellIndex = 0; cellIndex < costAnalysis.Rows[0].ItemArray.Length; cellIndex++)
|
||||
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var costAnalysis = db.CostAnalysis.SingleOrDefault(x => x.FkDateId == dateRecord.Id);
|
||||
if (costAnalysis == null)
|
||||
{
|
||||
if (cellIndex == 0)
|
||||
{
|
||||
//ID number
|
||||
var id = int.Parse(costAnalysis.Rows[0].ItemArray[cellIndex].ToString());
|
||||
isCostAnalysisDirtyCheckBox.Tag = id;
|
||||
isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty (" + id + @")";
|
||||
continue;
|
||||
}
|
||||
string formattedNumber;
|
||||
switch (cellIndex)
|
||||
{
|
||||
case 1: //Sales per man hour
|
||||
formattedNumber = Math.Round(double.Parse(costAnalysis.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
salesPerManHourTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 2: //Salary Percentage
|
||||
formattedNumber = Math.Round(double.Parse(costAnalysis.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
salaryPercentageTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 3: //Salary Dollars
|
||||
formattedNumber = Math.Round(double.Parse(costAnalysis.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
salaryDollarsTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
case 4: //Supplies
|
||||
formattedNumber = Math.Round(double.Parse(costAnalysis.Rows[0].ItemArray[cellIndex].ToString()), 2).ToString("N", new CultureInfo("en-US"));
|
||||
if (formattedNumber != "0.00")
|
||||
{
|
||||
suppliesTextBox.Text = formattedNumber;
|
||||
}
|
||||
break;
|
||||
}
|
||||
informationLabel.Text += @"No cost analysis to display." + Environment.NewLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
salaryDollarsTextBox.Text = costAnalysis.SalaryDollar == 0 ? string.Empty : costAnalysis.SalaryDollar.ToString();
|
||||
salesPerManHourTextBox.Text = costAnalysis.SalesPerManHour == 0 ? string.Empty : costAnalysis.SalesPerManHour.ToString();
|
||||
salaryPercentageTextBox.Text = costAnalysis.SalaryPercentage == 0 ? string.Empty : costAnalysis.SalaryPercentage.ToString();
|
||||
suppliesTextBox.Text = costAnalysis.Supplies == 0 ? string.Empty : costAnalysis.Supplies.ToString();
|
||||
//Set the internal state
|
||||
isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty (" + costAnalysis.Id + @")";
|
||||
isCostAnalysisDirtyCheckBox.Tag = costAnalysis.Id;
|
||||
}
|
||||
salesPerManHourTextBox.Enter += StoreBeginningTextBoxValue;
|
||||
salesPerManHourTextBox.Validating += ValidateCostAnalysisValues;
|
||||
@@ -4337,6 +4137,67 @@ namespace AdvertsingProfitControl
|
||||
return adSpecial;
|
||||
}
|
||||
|
||||
private static bool DeleteApcRow(int projectionId, int inventoryId, int actualSalesId)
|
||||
{
|
||||
var result = true;
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
using (var scope = new TransactionScope())
|
||||
{
|
||||
try
|
||||
{
|
||||
var projection = db.Projections.SingleOrDefault(x => x.Id == projectionId);
|
||||
if (projection != null)
|
||||
{
|
||||
db.Projections.Remove(projection);
|
||||
}
|
||||
var inventory = db.Inventories.SingleOrDefault(x => x.Id == inventoryId);
|
||||
if (inventory != null)
|
||||
{
|
||||
db.Inventories.Remove(inventory);
|
||||
}
|
||||
var actualSale = db.ActualSales.SingleOrDefault(x => x.Id == actualSalesId);
|
||||
if (actualSale != null)
|
||||
{
|
||||
db.ActualSales.Remove(actualSale);
|
||||
}
|
||||
db.SaveChanges();
|
||||
scope.Complete();
|
||||
}
|
||||
catch (DbUpdateException e)
|
||||
{
|
||||
LogConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static bool DeleteInvoiceRow(int invoiceId)
|
||||
{
|
||||
var result = true;
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
using (var scope = new TransactionScope())
|
||||
{
|
||||
try
|
||||
{
|
||||
var invoice = db.Invoices.SingleOrDefault(x => x.Id == invoiceId);
|
||||
if (invoice != null)
|
||||
{
|
||||
db.Invoices.Remove(invoice);
|
||||
}
|
||||
db.SaveChanges();
|
||||
scope.Complete();
|
||||
}
|
||||
catch (DbUpdateException e)
|
||||
{
|
||||
LogConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void addRecordButton_Click(object sender, EventArgs e)
|
||||
@@ -4377,9 +4238,14 @@ namespace AdvertsingProfitControl
|
||||
|
||||
ClearFormState();
|
||||
addRecordButton.Text = @"Add Record";
|
||||
var databaseTracker = new DatabaseTracker();
|
||||
var databaseReader = new DatabaseReader();
|
||||
_currentActiveDate = databaseReader.RetrieveMostRecentDate(databaseTracker.DatabaseConnectionString, _currentActiveDate.Year).AddDays(7);
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var recentDate = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault(x => x.EndingDate.Year == _currentActiveDate.Year);
|
||||
if (recentDate == null)
|
||||
{
|
||||
errorLabel.Text = @"Bad things...";
|
||||
return;
|
||||
}
|
||||
_currentActiveDate = recentDate.EndingDate.AddDays(7);
|
||||
weekEndingCalendar.SelectionStart = _currentActiveDate;
|
||||
Text = @"Add New Record (Current Date: " + _currentActiveDate.ToShortDateString() + @")";
|
||||
informationLabel.Text = string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user