private void Add_Button_Click(object sender, EventArgs e) { //For addings risks //Make sure every entry is filled before adding if (Risk_Name_Textbox.Text != "" && Risk_Description_TextBox.Text != "" && !string.IsNullOrEmpty(Risk_Status_ComboBox.Text)) { Risk NewRisk = new Risk(Risk_Name_Textbox.Text, Risk_Description_TextBox.Text, Risk_Status_ComboBox.SelectedItem.ToString()); RiskList.Add(NewRisk); Risks_ListBox.Items.Add(Risk_Name_Textbox.Text); TempProj.setProjRisk(RiskList); //update the list Risk_Name_Textbox.Text = ""; Risk_Description_TextBox.Text = ""; Risk_Status_ComboBox.Text = ""; RisksListbox_PictureBox.Visible = false; } //For adding requirements //Make sure every entry is filled before adding if (Requirements_Name_TextBox.Text != "" && Requirements_Description_TextBox.Text != "" && Functional_RadioButton.Checked || NonFunctional_RadioButton.Checked) { bool ReqType = false; if (Functional_RadioButton.Checked == true) { ReqType = true; } else if (NonFunctional_RadioButton.Checked == true) { ReqType = false; } Requirement NewRequirement = new Requirement(Requirements_Name_TextBox.Text, Requirements_Description_TextBox.Text, ReqType); RequirementList.Add(NewRequirement); Requirements_ListBox.Items.Add(Requirements_Name_TextBox.Text); TempProj.setProjReq(RequirementList); Requirements_Name_TextBox.Text = ""; Requirements_Description_TextBox.Text = ""; Functional_RadioButton.Checked = false; NonFunctional_RadioButton.Checked = false; RequirementsListBox_PictureBox.Visible = false; } }
private void Modify_Button_Click(object sender, EventArgs e) { //if both listboxes are empty or neither of them have an item selected then dont run the code below if (Risks_ListBox.Items.Count == 0 && Requirements_ListBox.Items.Count == 0 || Risks_ListBox.SelectedIndex == -1 && Requirements_ListBox.SelectedIndex == -1) { return; } if (Modify_Button.Text == "Modify Selected Item") { Modify_Button.Text = "Update Selected Item"; Add_Button.Enabled = false; Delete_Button.Enabled = false; //For modifying risks if (Risks_ListBox.SelectedIndex > -1) { //Load into fields the selected risk int x = Risks_ListBox.SelectedIndex; Risk_Name_Textbox.Text = RiskList[x].Name; Risk_Description_TextBox.Text = RiskList[x].Description; Risk_Status_ComboBox.Text = RiskList[x].RiskStatus; Risks_ListBox.Enabled = false; Requirements_ListBox.Enabled = false; } //For modifying requirements if (Requirements_ListBox.SelectedIndex > -1) { //Load into fields the selected requirement int y = Requirements_ListBox.SelectedIndex; Requirements_Name_TextBox.Text = RequirementList[y].Name; Requirements_Description_TextBox.Text = RequirementList[y].Description; bool ReqStatus = RequirementList[y].Functional; if (ReqStatus == true) { Functional_RadioButton.Checked = true; } else { NonFunctional_RadioButton.Checked = true; } Requirements_ListBox.Enabled = false; Risks_ListBox.Enabled = false; } } else if (Modify_Button.Text == "Update Selected Item") { Modify_Button.Text = "Modify Selected Item"; Add_Button.Enabled = true; Delete_Button.Enabled = true; //Rewrites the risk if (Risks_ListBox.SelectedIndex > -1) { Risk UpdatedRisk = new Risk(Risk_Name_Textbox.Text, Risk_Description_TextBox.Text, Risk_Status_ComboBox.SelectedItem.ToString()); RiskList[Risks_ListBox.SelectedIndex] = UpdatedRisk; Risks_ListBox.Items[Risks_ListBox.SelectedIndex] = Risk_Name_Textbox.Text; Risks_ListBox.ClearSelected(); Risk_Name_Textbox.Text = ""; Risk_Description_TextBox.Text = ""; Risk_Status_ComboBox.Text = ""; Risks_ListBox.Enabled = true; Requirements_ListBox.Enabled = true; TempProj.setProjRisk(RiskList); //update list of risks } //Rewrites the requirement if (Requirements_ListBox.SelectedIndex > -1) { bool RequireType = false; if (Functional_RadioButton.Checked == true) { RequireType = true; } else if (NonFunctional_RadioButton.Checked == true) { RequireType = false; } Requirement UpdatedRequirement = new Requirement(Requirements_Name_TextBox.Text, Requirements_Description_TextBox.Text, RequireType); RequirementList[Requirements_ListBox.SelectedIndex] = UpdatedRequirement; Requirements_ListBox.Items[Requirements_ListBox.SelectedIndex] = Requirements_Name_TextBox.Text; Requirements_ListBox.ClearSelected(); Requirements_Name_TextBox.Text = ""; Requirements_Description_TextBox.Text = ""; Functional_RadioButton.Checked = false; NonFunctional_RadioButton.Checked = false; Requirements_ListBox.Enabled = true; Risks_ListBox.Enabled = true; TempProj.setProjReq(RequirementList); //updates list of requirements } } }