Updated the table class files to allow a nullable ad special ID and changed the enum in the new modify record form to a boolean. Added a form to manage ad special keywords, still needs to handle removing them properly.

This commit is contained in:
2017-04-10 16:42:21 -05:00
parent d4d0a62eba
commit 09508aa16c
17 changed files with 594 additions and 86 deletions
+49 -27
View File
@@ -40,7 +40,7 @@ namespace AdvertsingProfitControl
//
private bool _isFormDirty;
//
private FormRoll _formRoll;
private bool _isModifyingRecord;
public NewModifyRecord(DateTime date)
{
InitializeComponent();
@@ -50,7 +50,7 @@ namespace AdvertsingProfitControl
InitializeForm();
mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]);
Text = @"Modify Record (Current Record: " + date.ToShortDateString() + @")";
_formRoll = FormRoll.ModifyRecord;
_isModifyingRecord = true;
LoadDate(date);
}
@@ -75,7 +75,7 @@ namespace AdvertsingProfitControl
//_debugTabPage = mainTabControl.TabPages[4];
mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]);
Text = @"Add New Record (Current Record: " + _currentActiveDate.ToShortDateString() + @")";
_formRoll = FormRoll.AddRecord;
_isModifyingRecord = false;
addRecordButton.Text = @"Add Record";
}
@@ -2450,7 +2450,7 @@ namespace AdvertsingProfitControl
if (e.Start == _currentActiveDate) return;
if (!weekEndingCalendar.BoldedDates.Contains(e.Start))
{
if (_formRoll == FormRoll.AddRecord)
if (_isModifyingRecord == false)
{
_currentActiveDate = e.Start;
Text = @"Add New Record (Current Record: " + e.Start.ToString("d") + @")";
@@ -2605,6 +2605,9 @@ namespace AdvertsingProfitControl
//Clear the used ad items
_usedAdItems[0].Clear(); //regular ad items (section 1)
_usedAdItems[1].Clear(); //ad special items (section 2)
//Reset the error label
errorLabel.Text = string.Empty;
errorLabel.ForeColor = Color.Red;
//Clear invoices
invoicesDataGridView.Rows.Clear();
//Clear comments
@@ -2734,7 +2737,7 @@ namespace AdvertsingProfitControl
LoadWeeklySales(dateRecord);
LoadTaxable(dateRecord);
LoadCostAnalysis(dateRecord);
_formRoll = FormRoll.ModifyRecord;
_isModifyingRecord = true;
}
private void LoadProjectionsTable(WeekEndingDate dateRecord)
@@ -2752,7 +2755,7 @@ namespace AdvertsingProfitControl
var index = 0;
foreach (var projection in projections)
{
if (projection.FkAdSpecialId != 0 && adSpecialIndex == -1)
if (projection.FkAdSpecialId != null && adSpecialIndex == -1)
{
adSpecialIndex = index;
projectionsDataGridView.Rows.Insert(index, 1);
@@ -2816,7 +2819,7 @@ namespace AdvertsingProfitControl
var index = 0;
foreach (var inventory in inventories)
{
if (inventory.FkAdSpecialId != 0 && adSpecialIndex == -1)
if (inventory.FkAdSpecialId != null && adSpecialIndex == -1)
{
adSpecialIndex = index;
inventoryDataGridView.Rows.Insert(index, 1);
@@ -2878,7 +2881,7 @@ namespace AdvertsingProfitControl
var index = 0;
foreach (var actualSale in actualSales)
{
if (actualSale.FkAdSpecialId != 0 && adSpecialIndex == -1)
if (actualSale.FkAdSpecialId != null && adSpecialIndex == -1)
{
adSpecialIndex = index;
actualSalesDataGridView.Rows.Insert(index, 1);
@@ -3211,20 +3214,20 @@ namespace AdvertsingProfitControl
//Prevent the ad special row from being marked in any way.
if (i == _adSpecialIndex) continue;
//Prevent rows pulled from that the database, that haven't been touched, from being marked as well.
if ((bool) projectionsDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].EditedFormattedValue)
if ((bool) projectionsDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].EditedFormattedValue && projectionsDataGridView.Rows[i].Cells[(int) SalesTableColumns.Id].EditedFormattedValue.ToString() != string.Empty)
{
projectionsDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].Value = false;
projectionsDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
}
//Prevent rows pulled from that the database, that haven't been touched, from being marked as well.
if ((bool) inventoryDataGridView.Rows[i].Cells[(int)InventoryTableColumns.IsDirty].EditedFormattedValue)
if ((bool) inventoryDataGridView.Rows[i].Cells[(int)InventoryTableColumns.IsDirty].EditedFormattedValue && inventoryDataGridView.Rows[i].Cells[(int)InventoryTableColumns.Id].EditedFormattedValue.ToString() != string.Empty)
{
inventoryDataGridView.Rows[i].Cells[(int) InventoryTableColumns.IsDirty].Value = false;
inventoryDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
}
//Prevent rows pulled from that the database, that haven't been touched, from being marked as well.
if (!(bool)
actualSalesDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].EditedFormattedValue)
actualSalesDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].EditedFormattedValue && actualSalesDataGridView.Rows[i].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString() != string.Empty)
continue;
actualSalesDataGridView.Rows[i].Cells[(int) SalesTableColumns.IsDirty].Value = false;
actualSalesDataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
@@ -3275,7 +3278,7 @@ namespace AdvertsingProfitControl
_isFormDirty = false;
addRecordButton.Text = @"Update Record";
Text = @"Modify Record (Current Record: " + _currentActiveDate.ToShortDateString() + @")";
_formRoll = FormRoll.ModifyRecord;
_isModifyingRecord = true;
weekEndingCalendar.AddBoldedDate(_currentActiveDate);
weekEndingCalendar.Invalidate();
return success;
@@ -3307,6 +3310,15 @@ namespace AdvertsingProfitControl
if (row.Index == _adSpecialIndex)
{
adSpecial = GetAdSpecial(adItemName);
//Check to see if the ad special return value exists.
if (adSpecial.Id == 0)
{
//Warn the user about the error and break out of the loop.
//We can simply ignore the ad special group and write the rest to the database.
errorLabel.Text = @"Warning: ad special group '" + adItemName + @"' failed to" + Environment.NewLine + @"write to the database." + Environment.NewLine + @"All rows starting from " + (_adSpecialIndex + 1) + @" to " + (projectionsDataGridView.RowCount - 1) + @" will not be saved.";
errorLabel.ForeColor = Color.Orange;
break;
}
continue;
}
//Check to see if the ad item is in the database and if so grab the object for it, otherwise add it.
@@ -3340,7 +3352,7 @@ namespace AdvertsingProfitControl
}
else
{
projection.FkAdSpecialId = 0;
projection.FkAdSpecialId = null;
}
//Check for an ID number
if (row.Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString() == string.Empty)
@@ -3375,7 +3387,7 @@ namespace AdvertsingProfitControl
? 0
: decimal.Parse(
row.Cells[(int) SalesTableColumns.TotalProfitReturn].EditedFormattedValue
.ToString());
.ToString());
projection.FkAdItemId = adItem.Id;
projection.RowAttribute = rowAttribute;
projection.RowPosition = row.Index + 1;
@@ -3470,6 +3482,15 @@ namespace AdvertsingProfitControl
if (row.Index == _adSpecialIndex)
{
adSpecial = GetAdSpecial(adItemName);
//Check to see if the ad special return value exists.
if (adSpecial.Id == 0)
{
//Warn the user about the error and break out of the loop.
//We can simply ignore the ad special group and write the rest to the database.
errorLabel.Text = @"Warning: ad special group '" + adItemName + @"' failed to" + Environment.NewLine + @"write to the database." + Environment.NewLine + @"All rows starting from " + (_adSpecialIndex + 1) + @" to " + (projectionsDataGridView.RowCount - 1) + @" will not be saved.";
errorLabel.ForeColor = Color.Orange;
break;
}
continue;
}
//Check to see if the ad item is in the database and if so grab the object for it, otherwise add it.
@@ -3503,7 +3524,7 @@ namespace AdvertsingProfitControl
}
else
{
inventory.FkAdSpecialId = 0;
inventory.FkAdSpecialId = null;
}
//Check for an ID number
if (row.Cells[(int)InventoryTableColumns.Id].EditedFormattedValue.ToString() == string.Empty)
@@ -3595,6 +3616,15 @@ namespace AdvertsingProfitControl
if (row.Index == _adSpecialIndex)
{
adSpecial = GetAdSpecial(adItemName);
//Check to see if the ad special return value exists.
if (adSpecial.Id == 0)
{
//Warn the user about the error and break out of the loop.
//We can simply ignore the ad special group and write the rest to the database.
errorLabel.Text = @"Warning: ad special group '" + adItemName + @"' failed to" + Environment.NewLine + @"write to the database." + Environment.NewLine + @"All rows starting from " + (_adSpecialIndex + 1) + @" to " + (projectionsDataGridView.RowCount - 1) + @" will not be saved.";
errorLabel.ForeColor = Color.Orange;
break;
}
continue;
}
//Check to see if the ad item is in the database and if so grab the object for it, otherwise add it.
@@ -3628,7 +3658,7 @@ namespace AdvertsingProfitControl
}
else
{
actualSale.FkAdSpecialId = 0;
actualSale.FkAdSpecialId = null;
}
//Check for an ID number
if (row.Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString() == string.Empty)
@@ -3772,7 +3802,7 @@ namespace AdvertsingProfitControl
{
//If there isn't one then create a new record and add it to the database.
invoice.InvoiceDate = DateTime.Parse(row.Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString());
invoice.InvoiceNumber = int.Parse(row.Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue.ToString());
invoice.InvoiceNumber = row.Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue.ToString();
invoice.InvoiceNetAmountAtCost =
string.IsNullOrWhiteSpace(
row.Cells[(int)InvoiceTableColumns.InvoiceNetAmountAtCost].EditedFormattedValue.ToString())
@@ -3800,10 +3830,7 @@ namespace AdvertsingProfitControl
invoice.InvoiceDate =
DateTime.Parse(
row.Cells[(int) InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString());
invoice.InvoiceNumber =
int.Parse(
row.Cells[(int) InvoiceTableColumns.InvoiceNumber].EditedFormattedValue.ToString
());
invoice.InvoiceNumber = row.Cells[(int) InvoiceTableColumns.InvoiceNumber].EditedFormattedValue.ToString();
invoice.InvoiceNetAmountAtCost =
string.IsNullOrWhiteSpace(
row.Cells[(int) InvoiceTableColumns.InvoiceNetAmountAtCost].EditedFormattedValue
@@ -4250,7 +4277,7 @@ namespace AdvertsingProfitControl
Text = @"Add New Record (Current Date: " + _currentActiveDate.ToShortDateString() + @")";
informationLabel.Text = string.Empty;
errorLabel.Text = string.Empty;
_formRoll = FormRoll.AddRecord;
_isModifyingRecord = false;
}
private void NormalizeApcTables()
@@ -4436,10 +4463,5 @@ namespace AdvertsingProfitControl
}
}
private enum FormRoll
{
AddRecord = 0,
ModifyRecord = 1
}
}
}