private void bGenTestcase_Click(object sender, EventArgs e)
        {
            bGenTestcase.Enabled = false;

            if (!initTestcaseBox())
            {
                bGenTestcase.Enabled = true;
                return;
            }

            Excel.Worksheet sheet = app.ActiveWorkbook.ActiveSheet as Excel.Worksheet;

            Excel.Range selection = app.Application.Selection as Excel.Range;

            DefaultTC itc = (DefaultTC)this.cbScriptType.SelectedItem;

            if (selection.Count != 1 || !itc.InitialTestcase(sheet, selection.Row))
            {
                this.AppendLine("请选择1行用例,并且测试步骤字段不能为空");
                bGenTestcase.Enabled = true;
                return;
            }
            itc.insertCases(sheet, selection.Row, int.Parse(cbDeep.Items[cbDeep.SelectedIndex].ToString()));

            bGenTestcase.Enabled = true;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (!initTestcaseBox())
            {
                return;
            }

            Excel.Worksheet sheet = app.ActiveWorkbook.ActiveSheet as Excel.Worksheet;

            Excel.Range selection = app.Application.Selection as Excel.Range;
            DefaultTC   itc       = (DefaultTC)this.cbScriptType.SelectedItem;

            if (selection.Count != 1 || !itc.InitialTestcase(sheet, selection.Row))
            {
                this.AppendLine("请选择1行用例,并且测试步骤字段不能为空");
                return;
            }

            int           row = selection.Row;
            List <string> tmp = itc.getSteps();
            string        s   = "";

            for (int i = 0; i < tmp.Count; i++)
            {
                s += (i + 1) + "," + tmp[i] + "\n";
            }

            sheet.Cells[row, (int)DefaultTC.colName.STEP] = s.Trim();

            tmp = itc.getExpRsts();
            s   = "";
            for (int i = 0; i < tmp.Count; i++)
            {
                s += (i + 1) + "," + tmp[i] + "\n";
            }

            sheet.Cells[row, (int)DefaultTC.colName.EXP_RESULT] = s.Trim();
        }
        public int addTestcases(Excel.Worksheet sheet,DefaultTC itc, int row)
        {
            itc.InitialTestcase(sheet, row);
               // testsuite ts=addItems(4,itc.GetCell(DefaultTC.colName.FEATUREID),itc.GetCell(DefaultTC.colName.FEATURE_DESC));

            string detail = itc.GetCell(DefaultTC.colName.FEATUREID)+":"+itc.GetCell(DefaultTC.colName.CASE_DESC);

            testsuite ts = addItems(4, itc.GetCell(DefaultTC.colName.FEATURE_DESC), detail);

            string preset = itc.GetCell(DefaultTC.colName.PRESET);
            List<string> steps = itc.getSteps();
            List<string> exp = itc.getExpRsts();
            string req = itc.GetCell(DefaultTC.colName.DS_ID);
            bool can_auto = itc.GetCell(DefaultTC.colName.CAN_AUTO).ToLower().Equals("true");
            string importance = itc.GetCell(DefaultTC.colName.PRIORITY).ToLower();
            string testtype=itc.GetCell(DefaultTC.colName.TYPE);

            uint order = 0;
            while (true)
            {
                row++;
                string c0 = itc.GetSubCase(row, DefaultTC.subColName.ID0);
                string c1 = itc.GetSubCase(row,DefaultTC.subColName.ID);

                if (c0.Length != 0||c1.Length==0)
                {
                    row--;
                    return row;
                }

                string c2 = itc.GetSubCase(row,DefaultTC.subColName.SAMPLES);
                testcase tc = new testcase();
                tc.name = c1;
                tc.externalid = externalid++;
                tc.internalid = externalid+"";
                tc.node_order = order++;
                tc.version = 1;
                tc.summary = c2;
                tc.preconditions = preset;
                tc.execution_type = (uint)(can_auto ? 2 : 1);
                if (importance.Length>5)
                    tc.importance = Convert.ToUInt32(importance.Substring(5,1));
                else tc.importance = 1;
                custom_field test_type=new custom_field();
                test_type.name="test_type";
                test_type.value=testtype;
                tc.custom_fields.Add(test_type);

                //todo 需求没有处理
                //string reqs= itc.GetSubCase(row,DefaultTC.subColName.REQ);
                //requirement rq=new requirement();

                //tc.requirements.Add

                for (int i = 0; i < steps.Count; i++) {
                    step s = new step();
                    s.actions = steps[i];
                    s.expectedresults=exp[i];
                    s.step_number=(uint)(i+1);
                    s.execution_type = tc.execution_type;
                    tc.steps.Add(s);
                }

                ts.Items.Add(tc);
            }
        }
        private void bCheckStyle_Click(object sender, EventArgs e)
        {
            if (!initTestcaseBox())
            {
                return;
            }

            Excel.Worksheet sheet = app.ActiveWorkbook.ActiveSheet as Excel.Worksheet;
            try
            {
                int  rows      = sheet.UsedRange.Rows.Count;
                int  curr_flag = 0;
                bool isok      = true;
                for (int i = 3; i < rows; i++)
                {
                    Excel.Range tmprange = sheet.Range["A" + i, Type.Missing].EntireRow;
                    Array       values   = (Array)tmprange.Cells.Value2;
                    Object      c1       = values.GetValue(1, 1);
                    Object      c2       = values.GetValue(1, 2);
                    if (c1 == null)
                    {
                        if (c2 == null)
                        {
                            this.AppendLine("Warning:空白行,row " + i);
                            isok = false;
                            continue;
                        }
                        else
                        {
                            curr_flag = c2.ToString().Split(new string[] { "_" }, StringSplitOptions.None).Length;
                        }
                    }
                    if (c1 == null)
                    {
                        continue;
                    }

                    int flag = c1.ToString().Split(new string[] { "_" }, StringSplitOptions.None).Length;

                    if (flag > 5)
                    {
                        this.AppendLine("Warning:层级大过5,row " + i);
                        isok = false;

                        continue;
                    }

                    if (curr_flag <= 0)
                    {
                        curr_flag = flag;
                        continue;
                    }

                    if ((flag - curr_flag) > 1)
                    {
                        this.AppendLine("Warning:缺少中间模块,row " + i);
                        isok = false;
                    }

                    if (flag == 5)
                    {
                        if (curr_flag == 5)
                        {
                            this.AppendLine("Warning:没有生产用例 row " + (i - 1));
                            isok = false;
                        }
                        DefaultTC itc = (DefaultTC)this.cbScriptType.SelectedItem;
                        if (!itc.InitialTestcase(sheet, i))
                        {
                            isok = false;
                        }
                        else if (itc.getSteps().Count != itc.getExpRsts().Count)
                        {
                            this.AppendLine("Warning:步骤和预期结果长度不一致 row " + i);
                            isok = false;
                        }
                    }
                    curr_flag = flag;
                }
                if (isok)
                {
                    this.AppendLine("End!");
                }
            }
            catch (Exception ex)
            {
                this.AppendLine(ex.StackTrace);
            }
        }
        private void bGen_Click(object sender, EventArgs e)
        {
            bGen.Enabled = false;

            if (!initTestcaseBox() || !createDir(textBox1.Text))
            {
                bGen.Enabled = true;
                return;
            }

            Excel.Worksheet sheet = app.ActiveWorkbook.ActiveSheet as Excel.Worksheet;

            Excel.Range selection = app.Application.Selection as Excel.Range;

            DefaultTC itc = (DefaultTC)this.cbScriptType.SelectedItem;
            int       cnt = 0;

            for (int i = 0; i < selection.Count; i++)
            {
                int row = selection.Row + i;
                if (!itc.InitialTestcase(sheet, row))
                {
                    this.AppendLine("Line" + row + "不是用例");
                    continue;
                }
                if (!itc.CanAuto() && DialogResult.OK != MessageBox.Show(
                        "Line" + row + "用例不能自动化,是否继续?",
                        "注意!",
                        MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Asterisk))
                {
                    this.AppendLine("Line" + row + "不能自动化!");
                    continue;
                }

                String   fname = System.IO.Path.Combine(textBox1.Text, itc.GetScriptName());
                FileInfo fi    = new FileInfo(fname);

                if (fi.Exists)
                {
                    DialogResult rst = MessageBox.Show(
                        "文件" + fi.FullName + "已经存在,是否覆盖?",
                        "注意!",
                        MessageBoxButtons.YesNoCancel,
                        MessageBoxIcon.Asterisk);
                    if (DialogResult.Yes == rst)
                    {
                        fi.Delete();
                    }
                    else if (DialogResult.No == rst)
                    {
                        continue;
                    }
                    else if (DialogResult.Cancel == rst)
                    {
                        bGen.Enabled = true;
                        return;
                    }
                }
                UTF8Encoding utf8 = new UTF8Encoding(false, false);
                itc.walkSubItemTestCase(sheet, selection.Row);
                StreamWriter w = new StreamWriter(fi.Create(), Encoding.GetEncoding("GBK"));
                w.WriteLine(itc.ToScript());
                w.Flush();
                w.Close();
                this.AppendLine("生成脚本:" + itc.GetScriptName());
                cnt++;
            }
            saveConfig("save_path", textBox1.Text);
            if (cnt == 0)
            {
                MessageBox.Show("请选择用例先!");
            }
            bGen.Enabled = true;
        }
        public int addTestcases(Excel.Worksheet sheet, DefaultTC itc, int row)
        {
            itc.InitialTestcase(sheet, row);
            // testsuite ts=addItems(4,itc.GetCell(DefaultTC.colName.FEATUREID),itc.GetCell(DefaultTC.colName.FEATURE_DESC));

            string detail = itc.GetCell(DefaultTC.colName.FEATUREID) + ":" + itc.GetCell(DefaultTC.colName.CASE_DESC);

            testsuite ts = addItems(4, itc.GetCell(DefaultTC.colName.FEATURE_DESC), detail);

            string        preset     = itc.GetCell(DefaultTC.colName.PRESET);
            List <string> steps      = itc.getSteps();
            List <string> exp        = itc.getExpRsts();
            string        req        = itc.GetCell(DefaultTC.colName.DS_ID);
            bool          can_auto   = itc.GetCell(DefaultTC.colName.CAN_AUTO).ToLower().Equals("true");
            string        importance = itc.GetCell(DefaultTC.colName.PRIORITY).ToLower();
            string        testtype   = itc.GetCell(DefaultTC.colName.TYPE);

            uint order = 0;

            while (true)
            {
                row++;
                string c0 = itc.GetSubCase(row, DefaultTC.subColName.ID0);
                string c1 = itc.GetSubCase(row, DefaultTC.subColName.ID);

                if (c0.Length != 0 || c1.Length == 0)
                {
                    row--;
                    return(row);
                }

                string   c2 = itc.GetSubCase(row, DefaultTC.subColName.SAMPLES);
                testcase tc = new testcase();
                tc.name           = c1;
                tc.externalid     = externalid++;
                tc.internalid     = externalid + "";
                tc.node_order     = order++;
                tc.version        = 1;
                tc.summary        = c2;
                tc.preconditions  = preset;
                tc.execution_type = (uint)(can_auto ? 2 : 1);
                if (importance.Length > 5)
                {
                    tc.importance = Convert.ToUInt32(importance.Substring(5, 1));
                }
                else
                {
                    tc.importance = 1;
                }
                custom_field test_type = new custom_field();
                test_type.name  = "test_type";
                test_type.value = testtype;
                tc.custom_fields.Add(test_type);

                //todo 需求没有处理
                //string reqs= itc.GetSubCase(row,DefaultTC.subColName.REQ);
                //requirement rq=new requirement();

                //tc.requirements.Add

                for (int i = 0; i < steps.Count; i++)
                {
                    step s = new step();
                    s.actions         = steps[i];
                    s.expectedresults = exp[i];
                    s.step_number     = (uint)(i + 1);
                    s.execution_type  = tc.execution_type;
                    tc.steps.Add(s);
                }

                ts.Items.Add(tc);
            }
        }