Marked as 'AdvertsingProfitControl' but located in a 'projects' folder. Added a new 'Add Record' form with a completely neww interface. This is the start of the final look of the the form that'd allow the user to add, update and remove records.

This commit is contained in:
2021-01-28 20:00:16 -06:00
parent 75061c9d51
commit 21eaae4d67
21 changed files with 1613 additions and 9813 deletions
+37 -31
View File
@@ -35,6 +35,9 @@ namespace AdvertsingProfitControl
public FrmAddRecord()
{
InitializeComponent();
//Set the maximum and minimum sizes for the form.
MaximumSize = new Size(1200, 650);
MinimumSize = new Size(1000, 550);
}
private void frmAddRecord_Load(object sender, EventArgs e)
@@ -82,14 +85,15 @@ namespace AdvertsingProfitControl
//Begin DataGridView event handlers
/// <summary>
/// Event Used: Leave
///
/// Attempts to parse the date entered when the user leaves the DateMaskedTextbox.
/// Clears the date if it is invalid, otherwise formats it and places it in the textbox.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnWeekEndingDateMaskedTextBoxLeave(object sender, EventArgs e)
{
string input = weekEndingDateMaskedTextBox.Text;
input = input.Replace(" ", "");
input = input.Replace(" ", ""); //The forwardslashes "/" in the masked textbox are sent programmically as spaces.
DateTime processedDate;
if (!DateTime.TryParse(input, out processedDate))
{
@@ -104,7 +108,7 @@ namespace AdvertsingProfitControl
/// <summary>
/// Event Used: CellValidating
///
/// Performs formatting and validation based on what column the cell is in.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
@@ -148,7 +152,7 @@ namespace AdvertsingProfitControl
}
}
//Make an ugly check for the Inventory / Actual Sales table, and perform logic on the inventory columns to allow 'Bin(s) [0-9]'.
if (dataGridView.Name == "inventoryActualSalesDataGridView" && e.ColumnIndex > 0 && e.ColumnIndex < 6)
if (dataGridView.Name == "inventoryActualSalesDataGridView" && e.ColumnIndex > 0 && e.ColumnIndex < 6 || dataGridView.Name == "projectionsDataGridView" && e.ColumnIndex == 1)
{
var invenotryStringCheck = new Regex(@"^[0-9] \bbin(s){0,1}\b", RegexOptions.IgnoreCase);
@@ -165,7 +169,7 @@ namespace AdvertsingProfitControl
}
//Check to see if whether or not the current cell is not in the first column and not empty.
if (e.ColumnIndex != 0 && !String.IsNullOrEmpty(dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString()))
if (e.ColumnIndex != 0 && !string.IsNullOrEmpty(dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString()))
{
//IF so, try to parse the contents to a Double and apply number formatting to the contents.
//Check for the cost column to see if there are any strings formatted like such:
@@ -639,7 +643,7 @@ namespace AdvertsingProfitControl
}
_gLastAdItemEntered = projectionsDataGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString();
//IF the current row is either a MemberRow OR an AdSpecialRow then only add the item in the first cell, place holder values are not needed.
if (parser.GetRowAttribute(projectionsDataGridView.Rows[e.RowIndex]) == "MemberRow" || parser.GetRowAttribute(projectionsDataGridView.Rows[e.RowIndex]) == "AdSpecialRow")
if (parser.GetRowAttribute(projectionsDataGridView.Rows[e.RowIndex]) == RowAttribute.MemberRow || parser.GetRowAttribute(projectionsDataGridView.Rows[e.RowIndex]) == RowAttribute.AdSpecialRow)
{
rowContents[0] = projectionsDataGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString();
actualSalesDataGridView.Rows.Add(rowContents);
@@ -742,7 +746,7 @@ namespace AdvertsingProfitControl
}
_gLastAdItemEntered = actualSalesDataGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString();
//IF the current row is either a MemberRow OR an AdSpecialRow then only ad the item in the first cell, place holder values are not needed.
if (parser.GetRowAttribute(actualSalesDataGridView.Rows[e.RowIndex]) == "MemberRow" || parser.GetRowAttribute(actualSalesDataGridView.Rows[e.RowIndex]) == "AdSpecialRow")
if (parser.GetRowAttribute(actualSalesDataGridView.Rows[e.RowIndex]) == RowAttribute.MemberRow || parser.GetRowAttribute(actualSalesDataGridView.Rows[e.RowIndex]) == RowAttribute.AdSpecialRow)
{
rowContents[0] = actualSalesDataGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString();
projectionsDataGridView.Rows.Add(rowContents);
@@ -923,13 +927,13 @@ namespace AdvertsingProfitControl
//Get the status of the current row.
var rowStatus = parser.GetRowAttribute(dataGridView.Rows[i]);
//IF the current row is a header row...
if (rowStatus == "HeaderRow")
if (rowStatus == RowAttribute.HeaderRow)
{
_gLastRowHeaderIndex = i;
//Then check to see if the next row is a row header.
rowStatus = parser.GetRowAttribute(dataGridView.Rows[i + 1]);
//IF so, color code this row as White, since it is not a true group header.
if (rowStatus != "HeaderRow")
if (rowStatus != RowAttribute.HeaderRow)
{
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
@@ -939,53 +943,53 @@ namespace AdvertsingProfitControl
//The start by checking the previous row's status.
rowStatus = parser.GetRowAttribute(dataGridView.Rows[i - 1]);
//IF the previous row is a header row OR if the previous row is index zero AND a member row, clear its coloring.
if (rowStatus == "HeaderRow" || rowStatus == "MemberRow" && (i - 1) == 0)
if (rowStatus == RowAttribute.HeaderRow || rowStatus == RowAttribute.MemberRow && (i - 1) == 0)
{
dataGridView.Rows[i - 1].DefaultCellStyle.BackColor = Color.White;
}
//IF the previous row is a header row AND has color coding saying it is a group header, then clear its color and apply it to this row (i).
else if (rowStatus == "HeaderRow" && dataGridView.Rows[i - 1].DefaultCellStyle.BackColor == Color.LightGray)
else if (rowStatus == RowAttribute.HeaderRow && dataGridView.Rows[i - 1].DefaultCellStyle.BackColor == Color.LightGray)
{
dataGridView.Rows[i - 1].DefaultCellStyle.BackColor = Color.White;
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.LightGray;
}
//IF previous row is Incomplete, then call the stable PaintRowGroups function.
else if (rowStatus == "IncompleteRow")
else if (rowStatus == RowAttribute.IncompleteRow)
{
PaintRowGroups(dataGridView);
}
}
}
else if (rowStatus == "MemberRow")
else if (rowStatus == RowAttribute.MemberRow)
{
if (i > 0)
{
//Check the previous row.
rowStatus = parser.GetRowAttribute(dataGridView.Rows[i - 1]);
//IF the previous row is a member row AND is the first row in the data grid, then remove the coloring for it and the current row (i).
if (rowStatus == "MemberRow" && (i - 1) == 0)
if (rowStatus == RowAttribute.MemberRow && (i - 1) == 0)
{
dataGridView.Rows[i - 1].DefaultCellStyle.BackColor = Color.White;
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
//IF the previous row is a member row AND it also has color coding suggesting that it is a member of a group, then add the current row (i) as well.
else if (rowStatus == "MemberRow" && dataGridView.Rows[i - 1].DefaultCellStyle.BackColor == Color.LightBlue)
else if (rowStatus == RowAttribute.MemberRow && dataGridView.Rows[i - 1].DefaultCellStyle.BackColor == Color.LightBlue)
{
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.LightBlue;
}
//IF the previous row is simply a member row with no coloring at all, then remove the coloring from the current row (i).
else if (rowStatus == "MemberRow" || rowStatus == "AdSpecialRow")
else if (rowStatus == RowAttribute.MemberRow || rowStatus == RowAttribute.AdSpecialRow)
{
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
//IF the previous row is a header row, then color it as a group header and color the current row as a member of said group.
else if (rowStatus == "HeaderRow")
else if (rowStatus == RowAttribute.HeaderRow)
{
dataGridView.Rows[i - 1].DefaultCellStyle.BackColor = Color.LightGray;
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.LightBlue;
}
//IF the previous row is incomplete, then call the stable PaintRowGroups function.
else if (rowStatus == "IncompleteRow")
else if (rowStatus == RowAttribute.IncompleteRow)
{
PaintRowGroups(dataGridView);
}
@@ -1013,7 +1017,7 @@ namespace AdvertsingProfitControl
//Get the current row's status.
var rowType = parser.GetRowAttribute(row);
//If the current row is not a group header, the first row in the grid, or a new row and in fact a member row...
if (i != 0 && rowType == "MemberRow" && !row.IsNewRow && rowType != "IncompleteRow")
if (i != 0 && rowType == RowAttribute.MemberRow && !row.IsNewRow && rowType != RowAttribute.IncompleteRow)
{
//Remove all coloring on the current row.
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
@@ -1023,13 +1027,14 @@ namespace AdvertsingProfitControl
{
//Check to see if the previous row is a header row by subtracting the number of rows that are (incomplete + 1) from the total number of rows (i).
//Adding one (1) to the incomplete count allows for checking the row right before the first incomplete row found so far to see if it's a header row.
if (parser.GetRowAttribute(dataGridView.Rows[i - (1 + incompleteRowsFound)]) == "HeaderRow")
if (parser.GetRowAttribute(dataGridView.Rows[i - (1 + incompleteRowsFound)]) == RowAttribute.HeaderRow)
{
row.DefaultCellStyle.BackColor = Color.LightBlue; //Group member
dataGridView.Rows[lastHeaderIndex].DefaultCellStyle.BackColor = Color.LightGray; //Group header
groupCount++;
statusReport += string.Format("\nGroup {0} created with the header row {1} and the following row members: {2} ", groupCount, (i - incompleteRowsFound).ToString(), (i + 1).ToString());
statusReport +=
$"\nGroup {groupCount} created with the header row {(i - incompleteRowsFound)} and the following row members: {(i + 1)} ";
}
//Else if a header row was not found from the previous operation but a header row is set, then its safe to assume that this row can be a member.
else if (lastHeaderIndex >= 0)
@@ -1045,21 +1050,22 @@ namespace AdvertsingProfitControl
}
}
//If the current row is a potential group header AND the next row is as well remove the coloring from the current row, no need for checks.
else if (rowType == "HeaderRow" && parser.GetRowAttribute(dataGridView.Rows[i + 1]) == "HeaderRow")
else if (rowType == RowAttribute.HeaderRow && parser.GetRowAttribute(dataGridView.Rows[i + 1]) == RowAttribute.HeaderRow)
{
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
//Check to see if this row is the first row, a header index row, AND the next row is a MemberRow.
else if (rowType == "HeaderRow" && parser.GetRowAttribute(dataGridView.Rows[i + 1]) == "MemberRow" && i == 0)
else if (rowType == RowAttribute.HeaderRow && parser.GetRowAttribute(dataGridView.Rows[i + 1]) == RowAttribute.MemberRow && i == 0)
{
//IF so, set the last header index, and color code of this row along with the next row which is a MemberRow.
lastHeaderIndex = 0;
dataGridView.Rows[0].DefaultCellStyle.BackColor = Color.LightGray;
dataGridView.Rows[i + 1].DefaultCellStyle.BackColor = Color.LightBlue;
statusReport += string.Format("Group {0} created with the header row 1 and the following row member(s): {1}", groupCount, (i + 2).ToString());
statusReport +=
$"Group {groupCount} created with the header row 1 and the following row member(s): {(i + 2)}";
}
//Check to see if this row is a group header.
else if (rowType == "HeaderRow")
else if (rowType == RowAttribute.HeaderRow)
{
//If so, reset the incomplete rows found count, set the lastHeaderIndex to this row's index (i) and change it's color to white.
incompleteRowsFound = 0;
@@ -1067,12 +1073,12 @@ namespace AdvertsingProfitControl
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
//If the current row is the first row in the grid AND is not a group header then remove all color from it, since its not allowed to be a header or a member.
else if (i == 0 && rowType == "MemberRow")
else if (i == 0 && rowType == RowAttribute.MemberRow)
{
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
//Mark an incomplete row to determine whether or not we found one and remove any coloring it may have, incomplete rows are not allowed to be members or headers.
if (rowType == "IncompleteRow")
if (rowType == RowAttribute.IncompleteRow)
{
incompleteRowsFound++;
dataGridView.Rows[i].DefaultCellStyle.BackColor = Color.White;
@@ -1266,7 +1272,7 @@ namespace AdvertsingProfitControl
//Get the current row's attribute.
var currentRowAttribute = parser.GetRowAttribute(row);
//IF the current row is invalid then skip it.
if (currentRowAttribute == "IncompleteRow" || currentRowAttribute == "MemberRow" && rowIndexNumber == 0)
if (currentRowAttribute == RowAttribute.IncompleteRow || currentRowAttribute == RowAttribute.MemberRow && rowIndexNumber == 0)
{
continue;
}
@@ -1286,12 +1292,12 @@ namespace AdvertsingProfitControl
//BEGIN row attribute check.
//Do an in-depth check to determine if the row should be marked with a "Header Row" group tag.
//Only rows that have members will be explicitly marked as such.
if (currentRowAttribute == "HeaderRow")
if (currentRowAttribute == RowAttribute.HeaderRow)
{
if ((rowIndexNumber + 1) <= projectionsDataGridView.Rows.Count)
{
//Check to see if the next row is a Member Row.
if ((parser.GetRowAttribute(projectionsDataGridView.Rows[rowIndexNumber + 1])) == "MemberRow")
if ((parser.GetRowAttribute(projectionsDataGridView.Rows[rowIndexNumber + 1])) == RowAttribute.MemberRow)
{
//Set the current row's attribute to HeaderRow in the database.
parameters[16] = "1";
@@ -1306,7 +1312,7 @@ namespace AdvertsingProfitControl
}
}
}
else if (currentRowAttribute == "MemberRow" && lastHeaderRowNumber != -1)
else if (currentRowAttribute == RowAttribute.MemberRow && lastHeaderRowNumber != -1)
{
//ELSE IF this row is a member, then mark it as such.
parameters[16] = "2";