Author Topic: Delete step in scenario  (Read 6927 times)

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Delete step in scenario
« on: April 24, 2014, 11:07:33 pm »
Hello everybody,
I'm trying to delete a certain step from a scenario in c#

But nothing happens...

Here's the code

Code: [Select]
foreach (Scenario del in a.Scenarios)
                                          {
                                              if (del.Name == form.Text)
                                             {
                                                 EA.Collection delsteps = del.Steps;
                                                  foreach (ScenarioStep aaa in delsteps)
                                                  {
                                                      for (short index = 0; index < delsteps.Count; index++)
                                                      {
                                                          if (aaa.Name == test)
                                                          {

                                                              MessageBox.Show(index.ToString());
                                                              delsteps.Delete(index);
                                                          }
                                                      }
                                                      aaa.Update();
                                                      delsteps.Refresh();
                                                      del.Update();
                                                      a.Refresh();

What's wrong with it ?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Delete step in scenario
« Reply #1 on: April 25, 2014, 12:00:33 am »
I think "aaa.Update()" will restore the step right after you deleted it.

Geert

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Delete step in scenario
« Reply #2 on: April 25, 2014, 12:28:05 am »
Hello Geert, thanks for replying

I modified the code, but it still cannot delete the step...

Code: [Select]
foreach (object itemChecked in form.checkedListBox1.CheckedItems)
                                      {

                                         //MessageBox.Show(form.Text);
                                          string test = itemChecked.ToString();
                                          //MessageBox.Show(test);
                                         foreach (Scenario del in a.Scenarios)
                                          {
                                              if (del.Name == form.Text)
                                             {
                                                 short ind = 0;
                                                  /*
                                                  foreach (ScenarioStep aaa in del.Steps)
                                                  {
                                                      for (short index = 0; index < del.Steps.Count; index++)
                                                      {
//if (aaa.Name == test)
                                                          //{
                                                              ind = index;
                                                              //break;
                                                        //  }
                                                      }
                                                  }
                                                   * */
                                                      try
                                                      {
                                                          del.Steps.DeleteAt(ind, true);
                                                      }
                                                      catch (Exception e)
                                                      {
                                                          MessageBox.Show(e.Message);
                                                      }
                                                      del.Steps.Refresh();
                                                      MessageBox.Show(del.Steps.Count.ToString());  
                                                      del.Update();
                                                      a.Scenarios.Refresh();

solenn

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: Delete step in scenario
« Reply #3 on: April 25, 2014, 01:19:11 am »
Hello,

In fact, you must write :

for (short index = del.Steps.Count -1; index >=0; index--)
{

}

because you are deleting steps in the list  so your list become smaller.

Solenn

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Delete step in scenario
« Reply #4 on: April 25, 2014, 03:20:48 pm »
And you don't need the refresh() and update() calls.
EA.Collection.DeleteAt() will delete immediately in the database.
You only need a refresh call if you want to do something with the Collection later on and you need it to reflect the deleted elements.

Geert

PiotrS

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
    • View Profile
Re: Delete step in scenario
« Reply #5 on: May 30, 2014, 09:20:25 pm »
I have these same problem with deleting steps from scenario...

I want delete empty steps of scenario from element, but its not working, this "deleted" steps exists in this scenario.
Where is mistake in my code?  :-/

foreach (EA.IDualScenario es in element.Scenarios)
{ foreach (EA.IDualScenarioStep ess in es.Steps)
  {
    if (ess.Name.Trim().Length == 0 &&
      ess.Uses.Trim().Length == 0 &&
      ess.Results.Trim().Length == 0)
    {
      es.Steps.Delete((short)ess.Pos);
      es.Steps.Refresh();
      es.Update();
      element.Scenarios.Refresh();
    }
  }
}

Do you have any ideas? :)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Delete step in scenario
« Reply #6 on: May 31, 2014, 12:32:37 am »
Move the Refresh out of the loop

q.

PiotrS

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
    • View Profile
Re: Delete step in scenario
« Reply #7 on: June 03, 2014, 12:17:59 am »
Thank you for the quick response, I tried to changed my code as You suggest, but I still need help. These empty rows are not deleted, there are only moved on the end of the steps collection. I tried delate, update and refresh in different sections but still was uncorrect. Could You help me?

Code: [Select]
                 short esCnt = element.Scenarios.Count;
                    for (short esIdx = (short)(esCnt - 1); esIdx >= 0; --esIdx)
                    {
                        EA.IDualScenario es = element.Scenarios.GetAt(esIdx);
                        short essCnt = es.Steps.Count;
                        for (short essIdx = (short)(essCnt - 1); essIdx >= 0; --essIdx)
                        {
                            EA.IDualScenarioStep ess = es.Steps.GetAt(essIdx);
                            if (ess.Name.Trim().Length == 0 &&
                                ess.Uses.Trim().Length == 0 &&
                                ess.Results.Trim().Length == 0)
                            {
                                //1. section
                                es.Steps.DeleteAt(essIdx, true);

                                //ess.Update();
                                //es.Update();
                                //element.Update();
                                //es.Steps.Refresh();
                                //element.Scenarios.Refresh();
                            }
                        }
                        //2. section
                        //es.Update();
                        //es.Steps.Refresh();
                        //es.Update();
                    }
                    //3. section
                    //element.Update();
                    element.Scenarios.Refresh();
« Last Edit: June 03, 2014, 12:21:51 am by PiotrS »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Delete step in scenario
« Reply #8 on: June 03, 2014, 03:48:27 am »
Hmm. Looks like an issue. I'm also not able to delete any step although the docu tells to use Delete(idx). I'll have some more investigation.

q.

P.S. As a possible work around you can delete the whole scenario and recreate it with the valid scenario steps. Deleting the scenario worked as desired.

P.P.S. Definitely deletion does not work for single steps. So you should a) report a bug (link bottom right) and b) use the work around above.
« Last Edit: June 03, 2014, 03:55:24 am by qwerty »

PiotrS

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
    • View Profile
Re: Delete step in scenario
« Reply #9 on: June 03, 2014, 05:04:02 pm »
Thank you for your interest in my problem, I'm waiting for the results of your tests 8-)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Delete step in scenario
« Reply #10 on: June 03, 2014, 06:01:20 pm »
Did you see the P.S. in my post above?

q.

PiotrS

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
    • View Profile
Re: Delete step in scenario
« Reply #11 on: June 03, 2014, 06:14:05 pm »
Yes, I saw. Thank you, I'm doing as you wrote.
I was thinking that You will make other tests (?).

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Delete step in scenario
« Reply #12 on: June 03, 2014, 06:55:22 pm »
Nope. I'm almost 100% sure that this is a bug. There's always the chance that one is doing something stupidly wrong. But if two people come to the same conclusion. There's a good chance that you're the first to manipulate scenario steps. Most people were just after creating steps, not modifying or deleting them. I have also tested with 9.3 and the issue is the same there.

I'd ask you to send the bug report. I once stopped sending bug reports since I had so many open issues and no corrections (or at least very few).

q.
« Last Edit: June 03, 2014, 06:56:56 pm by qwerty »

PiotrS

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
    • View Profile
Re: Delete step in scenario
« Reply #13 on: June 03, 2014, 08:03:12 pm »
I sent the bug report. If I get an answer, I'll pass it on the forum.
Thank You for help.