private void button6_Click(object sender, EventArgs e)
 {
     //switch ()
     if (checkedListBox1.SelectedItems.Count == 0 || textBox1.Text == "" || textBox3.Text == "" || textBox2.Text == "")
     {
         MessageBox.Show("Not all necessary fields have been filled in!");
     }
     else
     {
         foreach (Case c in testCases)
         {
             if (c.selected)
             {
                 param p = new param();
                 p.isActive = true;
                 p.file     = textBox3.Text;
                 p.value    = textBox1.Text;
                 p.name     = textBox2.Text;
                 p.type     = checkedListBox1.GetItemText(checkedListBox1.CheckedItems[0]);
                 c.parameters.Add(p);
                 showListboxItems();
                 //listBox1.Items.Add("\t Step: " + s.name);
             }
         }
     }
 }
        private int forceFields(param par)
        {
            int returnValue = 0;

            switch (par.type)
            {
            case "xPath": returnValue = 0; break;

            case "C#": returnValue = 1;  break;

            case "SQL": returnValue = 2;  break;
            }
            return(returnValue);
        }
        private void GenerateFromFile()
        {
            string filePath = TextBoxFilePath.Text;

            BL.FunctionClass  fc       = new BL.FunctionClass();
            XPathNavigator    nav      = fc.XpathNavigator(filePath);
            XPathExpression   expr     = nav.Compile("//cases/case");
            XPathNodeIterator iterator = nav.Select(expr);

            testCases.Clear();
            while (iterator.MoveNext())
            {
                Case c = new Case
                {
                    name       = iterator.Current.SelectSingleNode("@name").Value,
                    selected   = false,
                    parameters = new List <param>(),
                    steps      = new List <TempStep>()
                };
                XPathExpression   paramExpr = iterator.Current.Compile("//case[@name='" + c.name + "']/param");
                XPathNodeIterator paramIt   = iterator.Current.Select(paramExpr);

                int k = 0;
                while (paramIt.MoveNext())
                {
                    param p = new param
                    {
                        name     = paramIt.Current.SelectSingleNode("@name").Value,
                        isActive = false,
                        type     = paramIt.Current.SelectSingleNode("@type").Value,
                        value    = paramIt.Current.SelectSingleNode("@value").Value
                    };
                    if (p.type == "xPath")
                    {
                        p.file = paramIt.Current.SelectSingleNode("@file").Value;
                    }
                    c.parameters.Add(p);
                    k++;
                }

                XPathExpression   stepExpr = iterator.Current.Compile("//case[@name='" + c.name + "']/step");
                XPathNodeIterator stepIt   = iterator.Current.Select(stepExpr);

                k = 0;
                while (stepIt.MoveNext())
                {
                    TempStep s = new TempStep()
                    {
                        isActive  = false,
                        extension = stepIt.Current.SelectSingleNode("@extension").Value,
                        value     = "",
                        element   = ""
                    };
                    s.name = s.extension;

                    if (s.extension != "Navigate")
                    {
                        s.element = stepIt.Current.SelectSingleNode("@element").Value;
                        s.action  = stepIt.Current.SelectSingleNode("@action").Value;

                        s.name += (" | " + s.element + " | " + s.action);
                        if (s.action == "SendKeys")
                        {
                            s.value = stepIt.Current.SelectSingleNode("@value").Value;
                        }
                    }
                    else
                    {
                        s.value = stepIt.Current.SelectSingleNode("@value").Value;
                        s.name += (" | " + s.value);
                    }

                    k++;
                    c.steps.Add(s);
                }
                testCases.Add(c);
            }
            showListboxItems();
        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.GetItemText(listBox1.SelectedItem).Contains("Case:"))
            {
                NewStepPanel.Visible = false;
                ParamPanel.Visible   = false;
                TextBoxCaseName.Text = testCases.Find(t => t.name.Trim() == (listBox1.GetItemText(listBox1.SelectedItem).Split(':').LastOrDefault().Trim())).name;
            }
            else if (listBox1.GetItemText(listBox1.SelectedItem).Contains("Param:"))
            {
                NewStepPanel.Visible = false;
                ParamPanel.Visible   = true;
                Case  c = new Case();
                param p = new param();

                foreach (Case y in testCases)
                {
                    foreach (param o in y.parameters)
                    {
                        if (o.name.Trim() == listBox1.GetItemText(listBox1.SelectedItem).Split(':').LastOrDefault().Trim())
                        {
                            o.isActive = true;
                            p          = o;
                            c          = y;
                        }
                    }
                }
                TextBoxCaseName.Text = c.name;
                textBox2.Text        = p.name;
                textBox3.Text        = p.file;
                textBox1.Text        = p.value;
                checkedListBox1.SetItemChecked(checkedListBox1.Items.IndexOf(p.type), true);
            }
            else if (listBox1.GetItemText(listBox1.SelectedItem).Contains("Step:"))
            {
                NewStepPanel.Visible = true;
                ParamPanel.Visible   = false;
                Case     c = new Case();
                TempStep s = new TempStep();
                foreach (Case y in testCases)
                {
                    if (y.selected == true)
                    {
                        //y.selected = false;
                        foreach (TempStep o in y.steps)
                        {
                            int commaIn = listBox1.GetItemText(listBox1.SelectedItem).IndexOf(':');
                            o.isActive = false;
                            if (o.name.Trim() == listBox1.GetItemText(listBox1.SelectedItem).Substring(commaIn + 1).Trim())
                            {
                                //y.selected = true;
                                o.isActive = true;
                                s          = o;
                                c          = y;
                            }
                        }
                    }
                }

                ListBoxExtension.SetItemChecked(ListBoxExtension.Items.IndexOf(s.extension), true);
                TextBoxCaseName.Text = c.name;
                TextBoxValue.Text    = "";
                TextBoxElement.Text  = "";
                switch (forceFields(s))
                {
                case 0: TextBoxValue.Text = s.value;
                    fieldManager(2, 10);
                    break;

                case 1:
                case 2: TextBoxElement.Text = s.element;
                    TextBoxElement.Text     = s.element;
                    ListBoxAction.SetItemChecked(ListBoxAction.Items.IndexOf(s.action), true);
                    if (ListBoxAction.Items.IndexOf(s.action) != 0)
                    {
                        fieldManager(1, 1);
                        TextBoxValue.Text = s.value;
                    }
                    else
                    {
                        fieldManager(1);
                    }
                    break;

                case 10:
                    TextBoxElement.Text = s.element;
                    fieldManager(0, 2);
                    if (s.action != "")
                    {
                        ListBoxAction.SetItemChecked(ListBoxAction.Items.IndexOf(s.action), true);
                    }
                    ;
                    break;

                default:
                    TextBoxElement.Text = s.element;
                    fieldManager(1, 1);
                    ListBoxAction.SetItemChecked(ListBoxAction.Items.IndexOf(s.action), true);
                    //TextBoxValue.Text = s.value;
                    break;
                }
            }
        }