public ArrayList getAllThisLayerNeedSolvedCrowTaskInDecomposeResult(string workflow_id,string mainTaskId)
    {
       // int result = 0;
        SqlCommand com = null;
        ArrayList al = new ArrayList();
        try
        {
            conn.Open();
            string sql = string.Format("select *  from decomposeResult where simples='{0}' and workflow_id='{1}' and mainTaskId='{2}'", "yes",workflow_id,mainTaskId);

            com = new SqlCommand(sql, conn);
            SqlDataReader dr = com.ExecuteReader();
            while (dr.Read())
            {
                    //输出数据
                    DecomposeResult decomposeResult = new DecomposeResult();
                    decomposeResult.taskName = dr["taskName"].ToString();
                    decomposeResult.taskDescription = dr["taskDescription"].ToString();
                    decomposeResult.taskOrder = dr["taskOrder"].ToString();
                    decomposeResult.workflow_id = dr["workflow_id"].ToString();
                    decomposeResult.parent_workflow_id = dr["parent_workflow_id"].ToString();

                    decomposeResult.vote = dr["vote"].ToString();
                    decomposeResult.simple = dr["simples"].ToString();
                    decomposeResult.mainTaskId = dr["mainTaskId"].ToString();
                    al.Add(decomposeResult);
            }

        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            if (com != null)
            {
                com.Dispose();
            }
            if (conn != null)
            {
                conn.Close();
            }

        }
        return al;
    }
    public Dictionary<string, ArrayList> getAllNeedSolvedCrowTaskInDecomposeResult(string mainTaskId)
    {
      //  int result = 0;
        SqlCommand com = null;
        Dictionary<string, ArrayList> dic = new Dictionary<string, ArrayList>();
        try
        {
            conn.Open();
            string sql = string.Format("select wrokflow_id  from decomposeResult where simples='{0}' and mainTaskId='{1}' group by workflow_id", "yes",mainTaskId);
            com = new SqlCommand(sql, conn);
            SqlDataReader dr = com.ExecuteReader();
            while (dr.Read())
            {
                ArrayList al = new ArrayList();
                string sql2 = string.Format("select *  from decomposeResult where simples='{0}' and workflow_id='{1}' and mainTaskId='{2}'", "yes",dr["workflow_id"].ToString(),mainTaskId);
                SqlConnection sqlconnection = DbHelper.getSqlConnection();
                SqlCommand sc = new SqlCommand(sql2,sqlconnection);
                SqlDataReader dr1 = sc.ExecuteReader();
                while (dr1.Read())
                {
                    DecomposeResult decomposeResult = new DecomposeResult();
                    decomposeResult.taskName = dr["taskName"].ToString();
                    decomposeResult.taskDescription = dr["taskDescription"].ToString();
                    decomposeResult.taskOrder = dr["taskOrder"].ToString();
                    decomposeResult.workflow_id = dr["workflow_id"].ToString();
                    decomposeResult.parent_workflow_id = dr["parent_workflow_id"].ToString();
                    decomposeResult.vote = dr["vote"].ToString();
                    decomposeResult.simple = dr["simples"].ToString();
                    decomposeResult.mainTaskId = dr["mainTaskId"].ToString();
                    al.Add(decomposeResult);
                }
                dic.Add(dr["workflow_id"].ToString(),al);
            }

        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            if (com != null)
            {
                com.Dispose();
            }
            if (conn != null)
            {
                conn.Close();
            }

        }
        return dic;
    
    }
 public ArrayList findDecomposeResultByWorkflowId(string workflow_id,string mainTaskId)
 {
     ArrayList arrayList = new ArrayList();
     SqlCommand com = null;
     try
     {
         conn.Open();
         string sql = string.Format("select * from decomposeResult where workflow_id='{0}' and mainTaskId='{1}'", workflow_id,mainTaskId);
         com = new SqlCommand(sql, conn);
         SqlDataReader dr = com.ExecuteReader();
         while (dr.Read())
         {
             DecomposeResult decomposeResult = new DecomposeResult();
             decomposeResult.taskName = dr["taskName"].ToString();
             decomposeResult.taskDescription = dr["taskDescription"].ToString();
             decomposeResult.taskOrder = dr["taskOrder"].ToString();
             decomposeResult.workflow_id = dr["workflow_id"].ToString();
             decomposeResult.parent_workflow_id = dr["parent_workflow_id"].ToString();
             decomposeResult.vote = dr["vote"].ToString();
             decomposeResult.simple = dr["simples"].ToString();
             decomposeResult.mainTaskId=dr["mainTaskId"].ToString();
             arrayList.Add(decomposeResult);
         }
         com = new SqlCommand(sql, conn);
     }
     catch (Exception e)
     {
         throw e;
     }
     finally
     {
         if (com != null)
         {
             com.Dispose();
         }
         if (conn != null)
         {
             conn.Close();
         }
     }
     return arrayList;
 }
    public Dictionary<string,ArrayList> findAllDecomposeResultByParentWorkflowId(string parent_workflow_id,string mainTaskId)
    {
        Dictionary<string, ArrayList> dic = new Dictionary<string, ArrayList>();
        SqlCommand com = null;
        try
        {
            conn.Open();
            string sql = string.Format("select * from decomposeResult where parent_workflow_id='{0}' and mainTaskId='{1}'", parent_workflow_id,mainTaskId);
            com = new SqlCommand(sql, conn);
            SqlDataReader dr = com.ExecuteReader();
            ArrayList arrayList = new ArrayList();
            while (dr.Read())
            {
                DecomposeResult decomposeResult = new DecomposeResult();
                decomposeResult.taskName = dr["taskName"].ToString();
                decomposeResult.taskDescription = dr["taskDescription"].ToString();
                decomposeResult.taskOrder = dr["taskOrder"].ToString();
                decomposeResult.workflow_id = dr["workflow_id"].ToString();
                decomposeResult.parent_workflow_id = dr["parent_workflow_id"].ToString();
                decomposeResult.simple = dr["simples"].ToString();
                decomposeResult.mainTaskId = dr["mainTaskId"].ToString();
                arrayList.Add(decomposeResult);
            }
            ArrayList list = new ArrayList();
            for (int i=0;i<arrayList.Count-1;i++)
            {
                DecomposeResult dr1 = arrayList[i] as DecomposeResult;
                DecomposeResult dr2 = arrayList[i+1] as DecomposeResult;

                if (dr1.workflow_id == dr2.workflow_id)
                {
                    list.Add(dr1);
                    list.Add(dr2);
                }

            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            if (com != null)
            {
                com.Dispose();
            }
            if (conn != null)
            {
                conn.Close();
            }
        }
        return dic;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ArrayList arrayList = new ArrayList();
        string steps = tb_step.Text;
        int number = Convert.ToInt32(steps);
        CrowdTask[] crowdTasks = new CrowdTask[number];
        DecomposeResult[] decomposeResults = new DecomposeResult[number];


        for (int i = 0; i < number; i++)
        {
            CrowdTask ct = new CrowdTask();
            crowdTasks[i] = ct;
            DecomposeResult dr = new DecomposeResult();
            decomposeResults[i] = dr;
        }  
        switch(steps){
            case "2":
               
                /*
                    crowdTasks[0].taskName = taskName_1.Text;
                    crowdTasks[0].taskDescription = taskDescription_1.Text;
                    crowdTasks[1].taskName = taskName_2.Text;
                    crowdTasks[1].taskDescription = taskDescription_2.Text;
                */
               
                    decomposeResults[0].taskName = taskName_1.Text;
                    decomposeResults[0].taskDescription = taskDescription_1.Text;
                    decomposeResults[0].taskOrder = "第一步";
                    decomposeResults[0].workflow_id = taskWorkflowId;
                    decomposeResults[0].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[0].mainTaskId = currentCrowdTask.mainTaskId;

                    decomposeResults[1].taskName = taskName_2.Text;
                    decomposeResults[1].taskDescription = taskDescription_2.Text;
                    decomposeResults[1].taskOrder = "第二步";
                    decomposeResults[1].workflow_id = taskWorkflowId;
                    decomposeResults[1].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[1].mainTaskId = currentCrowdTask.mainTaskId;

                    for (int i = 0; i < number; i++)
                    {
                        arrayList.Add(decomposeResults[i]);
                    } 
                break;
            case "3":
                 
                /*
                    crowdTasks[0].taskName = taskName_1.Text;
                    crowdTasks[0].taskDescription = taskDescription_1.Text;
                    crowdTasks[1].taskName = taskName_2.Text;
                    crowdTasks[1].taskDescription = taskDescription_2.Text;     
                    crowdTasks[2].taskName = taskName_3.Text;
                    crowdTasks[2].taskDescription = taskDescription_3.Text;  
                */

                   decomposeResults[0].taskName = taskName_1.Text;
                    decomposeResults[0].taskDescription = taskDescription_1.Text;
                    decomposeResults[0].taskOrder = "第一步";
                    decomposeResults[0].workflow_id = taskWorkflowId;
                    decomposeResults[0].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[0].mainTaskId = currentCrowdTask.mainTaskId;

                    decomposeResults[1].taskName = taskName_2.Text;
                    decomposeResults[1].taskDescription = taskDescription_2.Text;
                    decomposeResults[1].taskOrder = "第二步";
                    decomposeResults[1].workflow_id = taskWorkflowId;
                    decomposeResults[1].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[1].mainTaskId = currentCrowdTask.mainTaskId;

                    decomposeResults[2].taskName = taskName_3.Text;
                    decomposeResults[2].taskDescription = taskDescription_3.Text;
                    decomposeResults[2].taskOrder = "第三步";
                    decomposeResults[2].workflow_id = taskWorkflowId;
                    decomposeResults[2].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[2].mainTaskId = currentCrowdTask.mainTaskId;
                    for (int i = 0; i < number; i++)
                    {
                        arrayList.Add(decomposeResults[i]);
                    } 
                break;
            case "4":
                /*
                  crowdTasks[0].taskName = taskName_1.Text;
                    crowdTasks[0].taskDescription = taskDescription_1.Text;
                    crowdTasks[1].taskName = taskName_2.Text;
                    crowdTasks[1].taskDescription = taskDescription_2.Text;     
                 crowdTasks[2].taskName = taskName_3.Text;
                    crowdTasks[2].taskDescription = taskDescription_3.Text;  
                    crowdTasks[3].taskName = taskName_4.Text;
                    crowdTasks[3].taskDescription = taskDescription_4.Text;  
                */
                      decomposeResults[0].taskName = taskName_1.Text;
                    decomposeResults[0].taskDescription = taskDescription_1.Text;
                    decomposeResults[0].taskOrder = "第一步";
                    decomposeResults[0].workflow_id = taskWorkflowId;
                    decomposeResults[0].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[0].mainTaskId = currentCrowdTask.mainTaskId;

                    decomposeResults[1].taskName = taskName_2.Text;
                    decomposeResults[1].taskDescription = taskDescription_2.Text;
                    decomposeResults[1].taskOrder = "第二步";
                    decomposeResults[1].workflow_id = taskWorkflowId;
                    decomposeResults[1].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[1].mainTaskId = currentCrowdTask.mainTaskId;

                    decomposeResults[2].taskName = taskName_3.Text;
                    decomposeResults[2].taskDescription = taskDescription_3.Text;
                    decomposeResults[2].taskOrder = "第三步";
                    decomposeResults[2].workflow_id = taskWorkflowId;
                    decomposeResults[2].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[2].mainTaskId = currentCrowdTask.mainTaskId;

                    decomposeResults[3].taskName = taskName_4.Text;
                    decomposeResults[3].taskDescription = taskDescription_4.Text;
                    decomposeResults[3].taskOrder = "第四步";
                    decomposeResults[3].workflow_id = taskWorkflowId;
                    decomposeResults[3].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[3].mainTaskId = currentCrowdTask.mainTaskId;
                    for (int i = 0; i < number; i++)
                    {
                        arrayList.Add(decomposeResults[i]);
                    } 
                break;
            case "5":
                /*
                  crowdTasks[0].taskName = taskName_1.Text;
                    crowdTasks[0].taskDescription = taskDescription_1.Text;
                    crowdTasks[1].taskName = taskName_2.Text;
                    crowdTasks[1].taskDescription = taskDescription_2.Text;     
                 crowdTasks[2].taskName = taskName_3.Text;
                    crowdTasks[2].taskDescription = taskDescription_3.Text;  
                    crowdTasks[3].taskName = taskName_4.Text;
                    crowdTasks[3].taskDescription = taskDescription_4.Text;   
                    crowdTasks[4].taskName = taskName_5.Text;
                    crowdTasks[4].taskDescription = taskDescription_5.Text; 
                */

                
                  
                      decomposeResults[0].taskName = taskName_1.Text;
                    decomposeResults[0].taskDescription = taskDescription_1.Text;
                    decomposeResults[0].taskOrder = "第一步";
                    decomposeResults[0].workflow_id = taskWorkflowId;
                    decomposeResults[0].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[0].mainTaskId = currentCrowdTask.mainTaskId;

                    decomposeResults[1].taskName = taskName_2.Text;
                    decomposeResults[1].taskDescription = taskDescription_2.Text;
                    decomposeResults[1].taskOrder = "第二步";
                    decomposeResults[1].workflow_id = taskWorkflowId;
                    decomposeResults[1].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[1].mainTaskId = currentCrowdTask.mainTaskId;

                    decomposeResults[2].taskName = taskName_3.Text;
                    decomposeResults[2].taskDescription = taskDescription_3.Text;
                    decomposeResults[2].taskOrder = "第三步";
                    decomposeResults[2].workflow_id = taskWorkflowId;
                    decomposeResults[2].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[2].mainTaskId = currentCrowdTask.mainTaskId;

                    decomposeResults[3].taskName = taskName_4.Text;
                    decomposeResults[3].taskDescription = taskDescription_4.Text;
                    decomposeResults[3].taskOrder = "第四步";
                    decomposeResults[3].workflow_id = taskWorkflowId;
                    decomposeResults[3].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[3].mainTaskId = currentCrowdTask.mainTaskId;

                    decomposeResults[4].taskName = taskName_5.Text;
                    decomposeResults[4].taskDescription = taskDescription_5.Text;
                    decomposeResults[4].taskOrder = "第五步";
                    decomposeResults[4].workflow_id = taskWorkflowId;
                    decomposeResults[4].parent_workflow_id = currentCrowdTask.taskParentWorkflowId;
                    decomposeResults[4].mainTaskId = currentCrowdTask.mainTaskId;


                    for (int i = 0; i < number; i++)
                    {
                        arrayList.Add(decomposeResults[i]);
                    } 

                break;
        }

        WorkflowApplication instance = MyWorkflowInstance.getDecomposeWorkflowApplication(taskWorkflowId);

        instance.ResumeBookmark(BookmarkName.Decomposing, arrayList);

        //跳转到分解完成页面
        Server.Transfer("decomposeCompeleted.aspx");


        
    }