コード例 #1
0
        public string[] getGroupRandomQIDArrayNotSelectLevel1(string strGroupID, int intQuestionNum, string strPaperID)
        {
            //傳回的陣列
            string[] arrayQID      = new String[intQuestionNum];
            int      intArrayIndex = 0;       //代表arrayQID的指標

            //到QuestionIndex找出符合條件的問題
            //string strSQL = "SELECT * FROM QuestionIndex I , QuestionMode M WHERE M.cQuestionGroupID = '"+strGroupID+"' AND I.cQID = M.cQID ";
            string  strSQL         = mySQL.getGroupQuestionLevel1NotSelect(strGroupID, strPaperID);
            DataSet dsQuestionList = sqldb.getDataSet(strSQL);

            //亂數選取問題後存入Array中
            //檢查intQuestionNum是否大於QuestionList中的題目數量
            if (intQuestionNum <= dsQuestionList.Tables[0].Rows.Count)
            {
                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[arrayQID.Length] = dsQuestionList.Tables[0].Rows[j]["cQID"].ToString();
                }
            }
            dsQuestionList.Dispose();

            return(arrayQID);
        }