private void btn_AddStep_Click(object sender, EventArgs e) { this.procedure.setName(txtBx_Title.Text); this.procedure.setDescription(txtBx_Description.Text); //steps[steps.Count - 1] is the previous step of the one which is about to be created. //The last step is previous of the one to create now. Etape prevStep; if (this.procedure.steps != null && this.procedure.steps.Count > 0) { prevStep = this.procedure.steps[this.procedure.steps.Count - 1]; } else { prevStep = null; } frm_AddStep frm = new frm_AddStep(prevStep, null, this.procedure, Operation.AddNew); frm.ShowDialog(); //Add the created step to the steps list of the procedure. if (frm.Tag != null) { Etape step = (Etape)frm.Tag; this.procedure.addEtape(step); //Fill the list view with the step's data. ListViewItem item = new ListViewItem(new string[] { step.getId().ToString(), step.getName(), step.getDescription() }); lstVew_Steps.Items.Add(item); } }
private void btn_ModifySetp_Click(object sender, EventArgs e) { if (lstVew_Steps.SelectedIndices.Count > 0) { //Set the procedure data if its not already set. this.procedure.setName(txtBx_Title.Text); this.procedure.setDescription(txtBx_Description.Text); //Get the selected item (step) from the list. int selected = lstVew_Steps.SelectedIndices[0]; ListViewItem item = lstVew_Steps.Items[selected]; //Etape step = new Etape(Convert.ToInt32(item.SubItems[0].Text), item.SubItems[1].Text, item.SubItems[2].Text, this.procedure); Etape step = null; //Gets the id of the selected Step. int id = Convert.ToInt32(item.SubItems[0].Text); //MessageBox.Show("SelectedStepId: " + id, "frm_AddProcedure.btn_ModifyStep"); //In the list of the procedure steps we look for the step with the previous Id. foreach (Etape stp in this.procedure.steps) { if (stp.getId() == id) { step = stp; break; } } //We send the slected step to the update form. frm_AddStep frm = new frm_AddStep(null, step, this.procedure, Operation.Update); frm.ShowDialog(); //Add the created step to the steps list of the procedure. if (frm.Tag != null) { step = (Etape)frm.Tag; //Remove the old version of step. this.procedure.steps.RemoveAt(selected); //Insert the new version at the same place. this.procedure.steps.Insert(selected, step); //Fill the list view with the step's data. item = new ListViewItem(new string[] { step.getId().ToString(), step.getName(), step.getDescription() }); //Remove the old version of step. lstVew_Steps.Items.RemoveAt(selected); //Insert the new version at the same place. lstVew_Steps.Items.Insert(selected, item); } } else { MessageBox.Show(this, "Sélectionner une étape SVP.", "Message d'erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } }