Exemplo n.º 1
0
/*
 *              public string[] getRandomQIDArray(string strPaperID , int intQuestionNum)
 *              {
 *                      ///亂數取得某一個問題組別中的問題
 *
 *                      //傳回的陣列
 *                      string[] arrayQID = new String[intQuestionNum];
 *                      int intArrayIndex = 0;//代表arrayQID的指標
 *
 *                      //取得Paper_Grouping的資料
 *                      string strSQL = "SELECT * FROM Paper_GroupingQuestion WHERE cPaperID = '"+strPaperID+"' ";
 *                      DataSet dsGroup = sqldb.getDataSet(strSQL);
 *                      if(dsGroup.Tables[0].Rows.Count > 0)
 *                      {
 *                              for(int i=0 ; i<dsGroup.Tables[0].Rows.Count ; i++)
 *                              {
 *                                      //針對每一個組別找出屬於此分組的題目
 *
 *                                      //QuestionGroupID
 *                                      string strGroupID = "";
 *                                      try
 *                                      {
 *                                              strGroupID = dsGroup.Tables[0].Rows[i]["cGroupID"].ToString();
 *                                      }
 *                                      catch
 *                                      {
 *                                      }
 *
 *                                      //Question number
 *                                      int intGroupQuestionNum = 0;
 *                                      try
 *                                      {
 *                                              intGroupQuestionNum = Convert.ToInt32(dsGroup.Tables[0].Rows[i]["sQuestionNum"]);
 *                                      }
 *                                      catch
 *                                      {
 *                                      }
 *
 *                                      //GroupDivision
 *                                      string strDivisionID = "";
 *                                      try
 *                                      {
 *                                              strDivisionID =	dsGroup.Tables[0].Rows[i]["cDivisionID"].ToString();
 *                                      }
 *                                      catch
 *                                      {
 *                                      }
 *
 *                                      //取得屬於該組別並且尚未被引用的問題集合
 *                                      strSQL = mySQL.getGroupQuestionLevel1NotSelect(strGroupID , strPaperID);
 *                                      DataSet dsQuestionList = sqldb.getDataSet(strSQL);
 *
 *                                      //亂數選取問題後存入Array中
 *                                      //檢查intQuestionNum是否大於QuestionList中的題目數量
 *                                      if(intGroupQuestionNum <= dsQuestionList.Tables[0].Rows.Count)
 *                                      {
 *                                              for(int j=0 ; j<intGroupQuestionNum ; j++)
 *                                              {
 *                                                      //亂數取得一個介於0~RowCount之間的數字
 *                                                      int intRandom = 0;
 *                                                      string strQID = "";
 *                                                      do
 *                                                      {
 *                                                              intRandom = myRandom.Next(0,dsQuestionList.Tables[0].Rows.Count);
 *                                                              strQID = dsQuestionList.Tables[0].Rows[intRandom]["cQID"].ToString();
 *                                                      }
 *                                                      while(checkArray(strQID , arrayQID));
 *
 *                                                      //將此QID存入Array中
 *                                                      arrayQID[intArrayIndex] = strQID;
 *                                                      intArrayIndex += 1;
 *                                              }
 *                                      }
 *                                      else
 *                                      {
 *                                              //把所有的題目都挑選進Array來
 *                                              for(int j=0 ; j<dsQuestionList.Tables[0].Rows.Count ; j++)
 *                                              {
 *                                                      arrayQID[j] = dsQuestionList.Tables[0].Rows[j]["cQID"].ToString();
 *                                              }
 *                                      }
 *                                      dsQuestionList.Dispose();
 *                              }
 *                      }
 *                      dsGroup.Dispose();
 *
 *                      return arrayQID;
 *              }
 */
        public string[] getRandomQIDArray(string strPaperID)
        {
            ///亂數取得某一個問題組別中的問題

            //取得此問卷所有需要亂數取得的問題總數
            int intQuestionSum = 0;

            intQuestionSum = myReceiver.getTotalQuestionNumFromRandomQuestion(strPaperID);

            //傳回的陣列
            string[] arrayQID      = new String[intQuestionSum];
            int      intArrayIndex = 0;       //代表arrayQID的指標

            //取得Paper_RandomQuestionNum的資料
            string  strSQL     = mySQL.getPaper_RandomQuestionNum(strPaperID);
            DataSet dsGroupNum = sqldb.getDataSet(strSQL);

            if (dsGroupNum.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsGroupNum.Tables[0].Rows.Count; i++)
                {
                    //get GroupID
                    string strGroupID = "";
                    try
                    {
                        strGroupID = dsGroupNum.Tables[0].Rows[i]["cQuestionGroupID"].ToString();
                    }
                    catch
                    {
                    }

                    //get Question number
                    int intQuestionNum = 0;
                    try
                    {
                        intQuestionNum = Convert.ToInt32(dsGroupNum.Tables[0].Rows[i]["sQuestionNum"]);
                    }
                    catch
                    {
                    }

                    //取得此問題組別的所有Level 1問題
                    if (strGroupID == "Specific")
                    {
                        strSQL = mySQL.getSpecificSelectionQuestion(strPaperID);
                    }
                    else
                    {
                        strSQL = mySQL.getGroupSelectionQuestion(strGroupID);
                    }

                    DataSet dsQuestionList = sqldb.getDataSet(strSQL);
                    if (dsQuestionList.Tables[0].Rows.Count > 0)
                    {
                        //檢查intQuestionNum是否大於QuestionList中的題目數量
                        if (intQuestionNum <= dsQuestionList.Tables[0].Rows.Count)
                        {
                            //亂數選取問題後存入Array中
                            for (int j = 0; j < intQuestionNum; j++)
                            {
                                //亂數取得一個介於0~RowCount之間的數字
                                int    intRandom = 0;
                                string strQID    = "";
                                do
                                {
                                    intRandom = myRandom.Next(0, dsQuestionList.Tables[0].Rows.Count);
                                    strQID    = dsQuestionList.Tables[0].Rows[intRandom]["cQID"].ToString();
                                }while(checkArray(strQID, arrayQID));
                                //將此QID存入Array中
                                arrayQID[intArrayIndex] = strQID;
                                intArrayIndex          += 1;
                            }
                        }
                        else
                        {
                            //把所有的題目都挑選進Array來
                            for (int j = 0; j < dsQuestionList.Tables[0].Rows.Count; j++)
                            {
                                arrayQID[j] = dsQuestionList.Tables[0].Rows[j]["cQID"].ToString();
                            }
                        }
                    }
                    else
                    {
                        //找不到此問題組別的資料
                    }
                    dsQuestionList.Dispose();
                }
            }
            else
            {
                //在Paper_RandomQuestion找不到資料
            }
            dsGroupNum.Dispose();

            return(arrayQID);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 傳回Paper_RandomNum的組別問題數目表格(不做動作)
        /// </summary>
        private Table setupQuestionNumTable(string strPaperID)
        {
            Table table = new Table();

            table.Attributes.Add("Class", "TableName");
            table.Style.Add("WIDTH", "100%");
            table.CellSpacing = 0;
            table.CellPadding = 2;
            table.BorderWidth = Unit.Pixel(1);
            table.BorderStyle = BorderStyle.Solid;
            table.BorderColor = System.Drawing.Color.Black;

            SQLString    mySQL      = new SQLString();
            DataReceiver myReceiver = new DataReceiver();

            //從Paper_RandomQuestionNum取出此問卷的資料

            SqlDB   sqldb         = new SqlDB(System.Configuration.ConfigurationSettings.AppSettings["connstr"]);
            string  strSQL        = mySQL.getPaper_RandomQuestionNum(strPaperID);
            DataSet dsQuestionNum = sqldb.getDataSet(strSQL);

            if (dsQuestionNum.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsQuestionNum.Tables[0].Rows.Count; i++)
                {
                    //設定Table的Style
                    string strStyle = "header1_tr_odd_row";
                    if ((i % 2) != 0)
                    {
                        strStyle = "header1_tr_odd_row";
                    }
                    else
                    {
                        strStyle = "header1_tr_even_row";
                    }

                    TableRow tr = new TableRow();
                    tr.CssClass = strStyle;
                    table.Rows.Add(tr);

                    //get GroupID
                    string strGroupID = "";
                    try
                    {
                        strGroupID = dsQuestionNum.Tables[0].Rows[i]["cQuestionGroupID"].ToString();
                    }
                    catch
                    {
                    }

                    //get Question number
                    int intQuestionNum = 0;
                    try
                    {
                        intQuestionNum = Convert.ToInt32(dsQuestionNum.Tables[0].Rows[i]["sQuestionNum"]);
                    }
                    catch
                    {
                    }

                    //get 此組別全部的問題數目
                    int intQuestionCount = 0;
                    if (strGroupID == "Specific")
                    {
                        strSQL = mySQL.getSpecificSelectionQuestion(strPaperID);
                    }
                    else
                    {
                        strSQL = mySQL.getGroupSelectionQuestion(strGroupID);
                    }

                    DataSet dsQuestionCount = sqldb.getDataSet(strSQL);
                    try
                    {
                        intQuestionCount = dsQuestionCount.Tables[0].Rows.Count;
                    }
                    catch
                    {
                    }
                    dsQuestionCount.Dispose();

                    //組別名稱
                    TableCell tcGroupName = new TableCell();
                    tr.Cells.Add(tcGroupName);

                    string strGroupName = "";
                    if (strGroupID == "Specific")
                    {
                        strGroupName = "Specific questions";
                    }
                    else
                    {
                        strGroupName = mySQL.getQuestionGroupName(strGroupID);
                    }
                    tcGroupName.Text = strGroupName;

                    //問題個數
                    TableCell tcQuestionNum = new TableCell();
                    tr.Cells.Add(tcQuestionNum);

                    TextBox txtQuestionNum = new TextBox();
                    tcQuestionNum.Controls.Add(txtQuestionNum);
                    txtQuestionNum.ID   = "txt" + strGroupID;
                    txtQuestionNum.Text = intQuestionNum.ToString();

                    //此組別的問題總數
                    TableCell tcQuestionCount = new TableCell();
                    tr.Cells.Add(tcQuestionCount);

                    tcQuestionCount.Text = intQuestionCount.ToString();
                    tcQuestionCount.Attributes.Add("Align", "Center");

                    //建立Title的TextArea
                    TableRow trQuestionTitle = new TableRow();
                    table.Rows.Add(trQuestionTitle);

                    TableCell tcTitle = new TableCell();
                    trQuestionTitle.Cells.Add(tcTitle);
                    tcTitle.Attributes.Add("align", "right");
                    tcTitle.ColumnSpan = 3;

                    //建立Question title的TextArea
                    HtmlTextArea txtTitle = new HtmlTextArea();
                    tcTitle.Controls.Add(txtTitle);
                    txtTitle.ID = "txtTitle" + strGroupID;
                    txtTitle.Style.Add("WIDTH", "100%");
                    txtTitle.Rows = 5;
                    txtTitle.Style.Add("DISPLAY", "none");

                    //取出此QuestionTitle的內容
                    txtTitle.InnerText = myReceiver.getQuestionTitle(strPaperID, strGroupID);

                    //建立Question title button
                    HtmlInputButton btnTitle = new HtmlInputButton("button");
                    tcTitle.Controls.Add(btnTitle);
                    btnTitle.ID    = "btnTitle" + strGroupID;
                    btnTitle.Value = "Add a question title";
                    btnTitle.Attributes.Add("onclick", "showQuestionTitle('" + strGroupID + "')");

                    //建立間隔
                    Label lblCell0 = new Label();
                    lblCell0.Style.Add("WIDTH", "20px");
                    tcTitle.Controls.Add(lblCell0);

                    //建立Empty row
                    if (i < dsQuestionNum.Tables[0].Rows.Count - 1)
                    {
                        TableRow trEmpty = new TableRow();
                        table.Rows.Add(trEmpty);
                        trEmpty.BackColor = System.Drawing.Color.White;

                        TableCell tcEmpty1 = new TableCell();
                        trEmpty.Cells.Add(tcEmpty1);
                        tcEmpty1.Style.Add("Height", "10px");
                        tcEmpty1.ColumnSpan = 3;
                    }
                }

                //加入Table的Title
                TableRow trTitle = new TableRow();
                table.Rows.AddAt(0, trTitle);
                trTitle.Attributes.Add("Class", "header1_table_first_row");

                TableCell tcGroupTitle = new TableCell();
                trTitle.Cells.Add(tcGroupTitle);
                tcGroupTitle.Text = "Question topic";

                TableCell tcQuestionTitle = new TableCell();
                trTitle.Cells.Add(tcQuestionTitle);
                tcQuestionTitle.Text = "Selected questions number";

                TableCell tcQuestionCountTitle = new TableCell();
                trTitle.Cells.Add(tcQuestionCountTitle);
                tcQuestionCountTitle.Text = "Maximum questions count";
            }
            else
            {
                //沒有資料
            }
            dsQuestionNum.Dispose();

            return(table);
        }