Skip to content

Commit

Permalink
PreFlight ChecklistEditor Form Update: sub add button functionality u…
Browse files Browse the repository at this point in the history
…pdated to work more effieciently and fix bugs
  • Loading branch information
Matthew-Alti authored and meee1 committed May 16, 2024
1 parent 28abe2e commit 5cedb78
Showing 1 changed file with 91 additions and 53 deletions.
144 changes: 91 additions & 53 deletions Controls/PreFlight/CheckListEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,17 @@ public void AddNewCheck()
{
//Variable for the last item in the checklist items list.
var lastItem = _parent.CheckListItems.LastOrDefault();
//Set the Y for the checklist item as the bottom of the previous input.
y = panel1.Controls[panel1.Controls.Count - 1].Bottom;
//Check if there is only one item left in the controls list.
if (_parent.CheckListItems.Count > 1)
{
//Set the Y for the checklist item as the bottom of the previous input.
y = panel1.Controls[panel1.Controls.Count - 1].Bottom;
}
else if (_parent.CheckListItems.Count <= 1)
{
//Set the y value to 0 if there is only 1 item in the list of controls.
y = 0;
}
//Set the input using the lastItem variable.
wrnctl = addwarningcontrol(5, y, lastItem);
//set the newItemAdded bool to false
Expand All @@ -78,14 +87,15 @@ public void AddNewCheck()
MessageBox.Show(ex.Message);
}
}
CheckListInput addNewChecklistInput(int a, int x, int y, CheckListItem checklistItem, CheckListInput checklistInput)
CheckListInput AddNewSubChecklistInput(int a, int x, int y, CheckListItem checklistItem, CheckListInput checklistInput)
{
wrnctl = new CheckListInput(_parent, checklistItem);
wrnctl.ReloadList += wrnctl_ChildAdd;
wrnctl.TXT_text.Visible = false;
wrnctl.TXT_desc.Visible = false;
wrnctl.CMB_colour1.Visible = false;
wrnctl.CMB_colour2.Visible = false;
//Set the correct location for the checklist input
wrnctl.Location = new Point(x + 5, y);

//Add the new control to the panel1 controls
Expand All @@ -97,16 +107,18 @@ CheckListInput addNewChecklistInput(int a, int x, int y, CheckListItem checklist
return wrnctl;
}

private void AddedSelectedItem(int a, int b, Control _ChecklistControl, CheckListInput _ChecklistInputItem, CheckListItem _ChecklistItemSelected)
private void AddedSelectedSubItem(int a, int b, Control _ChecklistControl, CheckListInput _ChecklistInputItem, CheckListItem _ChecklistItemSelected)
{
//Set the added bool to true
added = true;
try
{
//Set the Y for the checklist item as the bottom of the previous input.
int y = panel1.Controls[a].Bottom;
//Set the X location as the location X at control a
int x = panel1.Controls[a].Location.X;
//Add the new Chcklist Item Input to the panel1 cotrols in the correct location
wrnctl = addNewChecklistInput(a, x, y, _ChecklistItemSelected.Child, _ChecklistInputItem);
//Add the new sub checklist item input to panel1 at the correct location.
wrnctl = AddNewSubChecklistInput(a, x, y, _ChecklistItemSelected.Child, _ChecklistInputItem);
wrnctl.Refresh();
//Make the wrnctl checklistInput visible
wrnctl.Visible = true;
Expand Down Expand Up @@ -173,15 +185,15 @@ CheckListInput addwarningcontrol(int x, int y, CheckListItem item, bool hideforc
//set the text for the textboxes accordingly.
wrnctl.TXT_desc.Text = "add description";
wrnctl.TXT_text.Text = "add value";
//Set the itm's child to null if the Add button has been clicked
//Set the item's child to null if the Add button has been clicked
item.Child = null;
}
y = wrnctl.Bottom;

//used for when there is a secondary + button click
if (item.Child != null)
{
//make the "+" button invisible
//make the "+" button invisible on the control
wrnctl.Controls[4].Visible = false;
wrnctl = addwarningcontrol(x += 5, y, item.Child, true);
}
Expand All @@ -192,7 +204,7 @@ CheckListInput addwarningcontrol(int x, int y, CheckListItem item, bool hideforc
return wrnctl;
}

//remove selected item
//Remove selected item
private void RemoveSelectedItem(int i, int k, Control _ChecklistControl, CheckListInput _ChecklistInputItem, CheckListItem _ChecklistItemSelected)
{
//Remove Control that is clicked on
Expand Down Expand Up @@ -232,6 +244,10 @@ private void RemoveSelectedItem(int i, int k, Control _ChecklistControl, CheckLi
EditorChecklistInputList.RemoveAt(j);
//Remove the Control at position 'j'.
panel1.Controls.RemoveAt(j);
//Remove the item from the list of desc textboxes.
wrnctlDescList.RemoveAt(j);
//Remove the item from the list of text textboxes.
wrnctlTextList.RemoveAt(j);
//Make the selected ChecklistItem's Child null
_ChecklistItemSelected.Child = null;
//Make 'j' j-1 to be used in the loop again for the removed item from the list
Expand Down Expand Up @@ -289,6 +305,11 @@ private void RemoveSelectedItem(int i, int k, Control _ChecklistControl, CheckLi
_ChecklistItemSelected.Child = null;
//Make 'p' p-1 to be used in the loop again for the removed item from the list.
p -= 1;
//if the amount of controls is greater than 0 and the control at p has the "+" button control's visibility set to false
if (panel1.Controls.Count>0 && panel1.Controls[p].Controls[4].Visible == false)
{
panel1.Controls[p].Controls[4].Visible = true;
}
}
//If the Selected Item textbox is visible or the item is the last in the list of items, then Set the _Parent ChecklistItem's relevant child to null, so that it is no longer visible in the Items list.
if (TheItemSelected.TXT_desc.Visible == true || (p == panel1.Controls.Count - 1))
Expand All @@ -312,8 +333,18 @@ private void RemoveSelectedItem(int i, int k, Control _ChecklistControl, CheckLi
parentChecklistItemNeededCount = p - countPreviousChildrenItems;

//Loop through the Children Items of the Parent Item
//Set the currentChildItem variable for the Children Items that willl be looped through in the for loop 's'.
currentChildItem = _parent.CheckListItems[parentChecklistItemNeededCount - 1].Child;
//if not the first item in the list
if (_parent.CheckListItems.Count > 1 && _parent.CheckListItems[parentChecklistItemNeededCount].Child != null)
{
//Set the currentChildItem variable for the Children Items that willl be looped through in the for loop 's'.
currentChildItem = _parent.CheckListItems[parentChecklistItemNeededCount -1].Child;
}
else
{
//Set the currentChildItem variable for the Children Items that willl be looped through in the for loop 's'.
currentChildItem = _parent.CheckListItems[parentChecklistItemNeededCount].Child;
}

for (int s = parentChecklistItemNeededCount - 1; s <= p; s++)
{
//If the currentChildItem is equal to the Selected ChecklistItem
Expand Down Expand Up @@ -344,15 +375,16 @@ private void RemoveSelectedItem(int i, int k, Control _ChecklistControl, CheckLi
}
}
//If the last Item is being looped
//, then make the currentChild Item, the selected checklist Item and the previousItemBefore_ChecklistItemNeeded.Child set to null
//varaible for the item above the selected item
var checklistInputItemAtp = EditorChecklistInputList[p - 1];
//, then make the currentChild Item, the selected checklist Item and the previousItemBefore_ChecklistItemNeeded.Child set to null
//if p is not the first item in the list, nor the last
if (p > 0 && p < panel1.Controls.Count - 1)
{
//varaible for the item above the selected item, updated: moved variable into if statement
var checklistInputItemAtp = EditorChecklistInputList[p - 1];
//make the + button visible for the item at position p-1
checklistInputItemAtp.Controls[4].Visible = true;
}
//if the item at p is the last item in the list
else if (p == (panel1.Controls.Count - 1))
{
currentChildItem = null;
Expand Down Expand Up @@ -406,6 +438,7 @@ void wrnctl_ChildAdd(object sender, EventArgs e)
int i = 0;
int a = 0;
int b = 0;
//variable for the y location
int y = 0;
if (ChecklistInputText == "-" || (secondaryAddButton == true && ChecklistInputText == "-"))
{
Expand All @@ -420,8 +453,8 @@ void wrnctl_ChildAdd(object sender, EventArgs e)
{
//Set k equal to i - used for setting locations of the Controls below the removed item/s.
k = i;
//If k == 0, then move the next first item to position 0,5
if (k == 0)
//If k == 0, then move the next first item to position 0,5 -> updated: checks to see if there are any controls on the panel
if (k == 0 && panel1.Controls.Count > 0)
{
panel1.Controls[i].Location = new Point(0, 5);
k = 1;
Expand Down Expand Up @@ -450,54 +483,59 @@ void wrnctl_ChildAdd(object sender, EventArgs e)
else if (ChecklistInputText == "+")
{
//When the + button is clicked, the secondary Addbutton bool is set to true - used for removal function above.
secondaryAddButton = true;
//The original reload method is used for the secondary Add Button.

//For the controls on the Panel One Controls list
secondaryAddButton = true;
//For the controls on Panel1
for (a = 0; a <= panel1.Controls.Count - 1; a++)
{
try
{
//If the control at position a is the same as the selected control
if (panel1.Controls[a] == ChecklistControl)
{
//Set variable b to equal a
b = a;
//Make the Add button invisible for the item that was selected
//Make the "+" button invisible for the item that was selected
panel1.Controls[a].Controls[4].Visible = false;
//EditorChecklistInputList[a].Controls[4].Visible = false;
//Add all that are after into a new list
//Add all items that are after selected item into a new list
for (b = a + 1; b <= panel1.Controls.Count; b++)
{
//add the items into a new list
//Add the items into a new list
if (b < panel1.Controls.Count)
{
//Add the items after the selected item into a new list
AfterSelectedItemList.Add(panel1.Controls[b]);
//Remove the item at position b
//Remove the item at position b from panel1
panel1.Controls.RemoveAt(b);

//Add the description at position b into a new list
AfterSelectedItemDescList.Add(wrnctlDescList[b]);
//Remove the description at position b from the wrnctlDescList list
wrnctlDescList.RemoveAt(b);

//Add the text at position b into a new list
AfterSelectedItemTextList.Add(wrnctlTextList[b]);
//Remove the text at position b from the wrnctlTextList list
wrnctlTextList.RemoveAt(b);
}
//else if b is the last item in the list of panel1.controls
//Else if b is the last item in the list of panel1 controls
else if (b == panel1.Controls.Count)
{
break;
}
//Change the value of b to 1 less than it was
b -= 1;
}
AddedSelectedItem(a, b, ChecklistControl, ChecklistInputItem, ChecklistItemSelected);
//Method to add a in a sub item
AddedSelectedSubItem(a, b, ChecklistControl, ChecklistInputItem, ChecklistItemSelected);
//Refresh panel1
panel1.Refresh();

int yWrnctl = wrnctl.Bottom;
for (int c = 0; c < (AfterSelectedItemList.Count); c++)
{
//for the items in the after selected list, change the location based on the wrnctl item recently added
//for the items in the after selected item list, change the location based on the wrnctl item recently added
AfterSelectedItemList[c].Location = new Point(AfterSelectedItemList[c].Location.X, yWrnctl);
//Set the y for the next item to the value of the current item's bottom value
yWrnctl = AfterSelectedItemList[c].Bottom;

//Add the control at position c from the AfterSelectedItemList list to panel1.
panel1.Controls.Add(AfterSelectedItemList[c]);
}
panel1.Refresh();
Expand All @@ -512,12 +550,12 @@ void wrnctl_ChildAdd(object sender, EventArgs e)
}
foreach (var afterSelectedDescItem in AfterSelectedItemDescList)
{
//add the text to the new text list
//Add the text to the new text list
wrnctlDescList.Add(afterSelectedDescItem);
}
foreach (var afterSelectedTextItem in AfterSelectedItemTextList)
{
//add the text to the new text list
//Add the text to the new text list
wrnctlTextList.Add(afterSelectedTextItem);
}
//Function that clears the lists necessary
Expand Down Expand Up @@ -565,22 +603,22 @@ private void BUT_Add_Click(object sender, EventArgs e)
private void TXT_desc_Enter(object sender, EventArgs e)
{
//string for the Textbox's Text (The clicked on textbox)
string itemClickedText = (sender as TextBox).Text;
string itemClickedText = (sender as TextBox).Text;
//Check if the string equals the text of a new desc Textbox. If the same, make its value an empty string.
if (itemClickedText == "add description")
{
itemClickedText = string.Empty;
}
//loop until the textbox which was clicked on is reached.
for (int i = wrnctlDescList.Count-1; i > 0; i--)
{
if ((sender as TextBox) == wrnctlDescList[i])
//loop until the textbox which was clicked on is reached. Update: starts from the last item in the list to loop through
for (int i = wrnctlDescList.Count-1; i >= 0; i--)
{
//change the text of the textbox to the itemClickedText string value(Empty string).
wrnctlDescList[i].Text = itemClickedText;
return;
if ((sender as TextBox) == wrnctlDescList[i])
{
//change the text of the textbox to the itemClickedText string value(Empty string).
wrnctlDescList[i].Text = itemClickedText;
break;
}
}
}
}
}
private void TXT_text_Enter(object sender, EventArgs e)
{
Expand All @@ -590,18 +628,18 @@ private void TXT_text_Enter(object sender, EventArgs e)
if (itemClickedText == "add value")
{
itemClickedText = string.Empty;
}
//loop until the textbox which was clicked on is reached.
//Updated: loops through the wrnctlTextList List
for (int i = wrnctlTextList.Count - 1; i > 0; i--)
{
if ((sender as TextBox) == wrnctlTextList[i])
//loop until the textbox which was clicked on is reached.
//Update: loops through the wrnctlTextList List, starts from the last item in the list to loop through
for (int i = wrnctlTextList.Count - 1; i >= 0; i--)
{
//change the text of the textbox to the itemClickedText string value(Empty string).
wrnctlTextList[i].Text = itemClickedText;
return;
if ((sender as TextBox) == wrnctlTextList[i])
{
//change the text of the textbox to the itemClickedText string value(Empty string).
wrnctlTextList[i].Text = itemClickedText;
return;
}
}
}
}
}

private void ClearPlaceHolderText()
Expand Down

0 comments on commit 5cedb78

Please sign in to comment.