protected enum_PageMode GetCurrentPageMode() { enum_PageMode tempMode = enum_PageMode.WordDesc; if (Session["CurrentPageMode"] == null) { tempMode = enum_PageMode.WordDesc; Session["CurrentPageMode"] = 0; } else if (Convert.ToInt32(Session["CurrentPageMode"]) == 0) { tempMode = enum_PageMode.WordDesc; } else if (Convert.ToInt32(Session["CurrentPageMode"]) == 1) { tempMode = enum_PageMode.CompleteSentence; } else if (Convert.ToInt32(Session["CurrentPageMode"]) == 2) { tempMode = enum_PageMode.Synonyms; } return(tempMode); }
protected string[] GetOptions(enum_PageMode pageMode, int rowId) { //返回的数组中,前4个为选项 //第5个为正确答案索引 string[] straryOptions = new string[5]; //bool blRowIdFound = false; //int intRowIdIndex = 0; int PerUnitWordsAmount = Convert.ToInt32(ConfigurationManager.AppSettings["PerUnitWordsAmount"]); int[] array1 = UseDoubleArrayToNonRepeatedRandom(PerUnitWordsAmount); int seed = Guid.NewGuid().GetHashCode(); Random rnd = new Random(seed); int currentWordOptionKey = rnd.Next(4); for (int i = 0; i < array1.Length; i++) { if (array1[i] == rowId) //说明i对应的词中是待测的词 { int temp = array1[currentWordOptionKey]; array1[currentWordOptionKey] = array1[i]; array1[i] = temp; } } /* * for (int i = 0; i <= 3; i++) * { * if (array1[i] == rowId) //说明随机选的4个词中正好有待测的词, * { * blRowIdFound = true; * intRowIdIndex = i; * } * } * * if (!blRowIdFound) * { * * //随机指定一个索引,替换成答案id * Random rnd = new Random(); * int rndKey = rnd.Next(4); * array1[rndKey] = rowId; * intRowIdIndex = rndKey; * }*/ int findIndexStart = currentWordOptionKey; for (int i = 0; i <= 3; i++) { if (pageMode == enum_PageMode.WordDesc) { straryOptions[i] = GetWordRdnDesc(array1[i]); //GetWordAllDesc(array1[i]); } else if (pageMode == enum_PageMode.CompleteSentence) { straryOptions[i] = GetWordBody(array1[i]); } else if (pageMode == enum_PageMode.Synonyms) { string synonymsFound = string.Empty; if (i != currentWordOptionKey) { while (synonymsFound == string.Empty && findIndexStart < array1.Length - 1) { findIndexStart++; string wordId = GetWordId(array1[findIndexStart]); synonymsFound = GetWordSynonyms(wordId); } } else { string wordId = GetWordId(array1[i]); synonymsFound = GetWordSynonyms(wordId); } if (synonymsFound == string.Empty) { synonymsFound = "NO Synonyms found"; } straryOptions[i] = synonymsFound; } } straryOptions[4] = currentWordOptionKey.ToString(); return(straryOptions); }