public Embed GetEmbed(Color color) { var embed = new EmbedBuilder { Title = Title, Url = $"\nhttp://myanimelist.net/manga/{Id}", }; ////embed.AddField(f => f.WithName("Title").WithValue(title)); if (EnglishTitle != null) { embed.AddField(f => f.WithName("English Title").WithValue(EnglishTitle)); } if (Synonyms != null) { embed.AddField(f => f.WithName("Synonyms").WithValue(Synonyms)); } embed.AddField(f => f.WithName("Type").WithValue(Type).WithIsInline(true)); embed.AddField(f => f.WithName("Status").WithValue(Status).WithIsInline(true)); embed.AddField(f => f.WithName("Score (max. 10)").WithValue(Score.ToString()).WithIsInline(true)); if (ChapterCount.HasValue) { embed.AddField(f => f.WithName("Chapters").WithValue(ChapterCount.ToString()).WithIsInline(true)); } else { embed.AddField(f => f.WithName("Chapters").WithValue("?").WithIsInline(true)); } if (VolumeCount.HasValue) { embed.AddField(f => f.WithName("Volumes").WithValue(VolumeCount.ToString()).WithIsInline(true)); } else { embed.AddField(f => f.WithName("Volumes").WithValue("?").WithIsInline(true)); } embed.AddField(f => f.WithName("Published").WithValue(DateString).WithIsInline(true)); ////embed.AddField(f => f.WithName("MyAnimeList Page").WithValue($"\nhttp://myanimelist.net/manga/{id}")); embed.ThumbnailUrl = ThumbnailUrl; embed.AddField(f => f.WithName("Synopsis").WithValue(Synopsis)); embed.WithFooter(f => f.WithText("Source: MyAnimeList")); embed.WithColor(color); return(embed.Build()); }
protected void Button_text_Click(object sender, EventArgs e) { List <Questdata> Qdata = new List <Questdata>(); TestID = DropDownList1.SelectedValue; SqlCommand cmd; SqlConnection AllData_Connection = null; SqlDataReader DataBase_Reader; //資料庫讀取 AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 #region 取得ID AllData_Connection.Open(); //開啟AllData資料庫 DataBase_Language = "Select * from SelectedData where TextID= '" + TestID.Trim() + "'"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); while (DataBase_Reader.Read()) { string doNumber = (string)DataBase_Reader["doNumber"]; int way = (int)DataBase_Reader["Way"]; Qdata.Add(new Questdata(doNumber, 0, 0, 0, 0, way)); } DataBase_Reader.Close(); AllData_Connection.Close();//close AllData資料庫 #endregion #region 取得答題狀況 AllData_Connection.Open(); //開啟AllData資料庫 DataBase_Language = "Select * from FloatData where TestID= '" + TestID.Trim() + "'"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); while (DataBase_Reader.Read()) { string Reply; string doNumber = (string)DataBase_Reader["QuestionID"]; if (DataBase_Reader["Reply"] == DBNull.Value) { Reply = "X"; } else { Reply = (string)DataBase_Reader["Reply"]; } // Reply = (string)DataBase_Reader["Reply"]==DBNull.Value? "X" : (string)DataBase_Reader["Reply"]; for (int u = 0; u < Qdata.Count; u++) { if (doNumber.Trim() == Qdata[u].testid.Trim()) { if (Reply == "A") { Qdata[u].optiontotal[0]++; } if (Reply == "B") { Qdata[u].optiontotal[1]++; } if (Reply == "C") { Qdata[u].optiontotal[2]++; } if (Reply == "D") { Qdata[u].optiontotal[3]++; } } } } DataBase_Reader.Close(); AllData_Connection.Close();//close AllData資料庫 #endregion for (int u = 0; u < Qdata.Count; u++) { int total = Qdata[u].optiontotal[0] + Qdata[u].optiontotal[1] + Qdata[u].optiontotal[2] + Qdata[u].optiontotal[3]; if (total != 0) { #region 畫圖 if (Qdata[u].way == 1) { Panel_onImage.Controls.Add(new Label() { Text = "第" + (u + 1) + "題" + Qdata[u].testid.Trim() + "(必選)" }); } else { Panel_onImage.Controls.Add(new Label() { Text = "第" + (u + 1) + "題" + Qdata[u].testid.Trim() + "(隨機)" }); } Panel_onImage.Controls.Add(new Label() { Text = "<br>" }); Panel_onImage.Controls.Add(new System.Web.UI.WebControls.Image() { ImageUrl = "~/Images/Adaptive/" + Qdata[u].testid.Trim() + "Q.png", Width = 500 }); Panel_onImage.Controls.Add(new Label() { Text = "<br><HR color=#E6E8EA size=1 >" }); Label label = new Label(); label.Text = "正確解答<br>"; label.BackColor = System.Drawing.Color.GreenYellow; label.Font.Size = 16; Panel_onImage.Controls.Add(label); Panel_onImage.Controls.Add(new System.Web.UI.WebControls.Image() { ImageUrl = "~/Images/Adaptive/" + Qdata[u].testid.Trim() + "A.png", Width = 200 }); Panel_onImage.Controls.Add(new Label() { Text = "<br>選正解人數:" + Qdata[u].optiontotal[0] + "人(" + (Qdata[u].optiontotal[0] * 100 / total) + "%)<HR color=#E6E8EA size=1 >" }); Label label2 = new Label(); label2.Text = "<br>其他選項<br>"; label2.BackColor = System.Drawing.Color.MediumVioletRed; label2.Font.Size = 14; Panel_onImage.Controls.Add(label2); Panel_onImage.Controls.Add(new System.Web.UI.WebControls.Image() { ImageUrl = "~/Images/Adaptive/" + Qdata[u].testid.Trim() + "B.png", Width = 200 }); Panel_onImage.Controls.Add(new Label() { Text = "<br>人數:" + Qdata[u].optiontotal[1] + "人(" + (Qdata[u].optiontotal[1] * 100 / total) + "%)<br><HR color=#E6E8EA size=1 >" }); Panel_onImage.Controls.Add(new System.Web.UI.WebControls.Image() { ImageUrl = "~/Images/Adaptive/" + Qdata[u].testid.Trim() + "C.png", Width = 200 }); Panel_onImage.Controls.Add(new Label() { Text = "<br>人數:" + Qdata[u].optiontotal[2] + "人(" + (Qdata[u].optiontotal[2] * 100 / total) + "%)<br><HR color=#E6E8EA size=1 >" }); Panel_onImage.Controls.Add(new System.Web.UI.WebControls.Image() { ImageUrl = "~/Images/Adaptive/" + Qdata[u].testid.Trim() + "D.png", Width = 200 }); Panel_onImage.Controls.Add(new Label() { Text = "<br>人數:" + Qdata[u].optiontotal[3] + "人(" + (Qdata[u].optiontotal[3] * 100 / total) + "%)<br><HR color=#E6E8EA size=1 >" }); Panel_onImage.Controls.Add(new Button() { Text = "查看答題情況" }); Panel_onImage.Controls.Add(new Label() { Text = "<HR color=#00FF00 size=10 >" }); #endregion 畫圖 } else { #region 畫圖 if (Qdata[u].way == 1) { Panel_onImage.Controls.Add(new Label() { Text = "第" + (u + 1) + "題(必選)(無人作答)" }); } else { Panel_onImage.Controls.Add(new Label() { Text = "第" + (u + 1) + "題(隨機)(無人作答)" }); } //Panel_onImage.Controls.Add(new Label() { Text = "第" + (u + 1) + "題(無人作答)"}); Panel_onImage.Controls.Add(new Label() { Text = "<br>" }); Panel_onImage.Controls.Add(new System.Web.UI.WebControls.Image() { ImageUrl = "~/Images/Adaptive/" + Qdata[u].testid.Trim() + "Q.png", Width = 500 }); Panel_onImage.Controls.Add(new Label() { Text = "<br>" }); Panel_onImage.Controls.Add(new Label() { Text = "正確解答<br>" }); Panel_onImage.Controls.Add(new System.Web.UI.WebControls.Image() { ImageUrl = "~/Images/Adaptive/" + Qdata[u].testid.Trim() + "A.png", Width = 200 }); Panel_onImage.Controls.Add(new Label() { Text = "<br>其他選項<br>" }); Panel_onImage.Controls.Add(new System.Web.UI.WebControls.Image() { ImageUrl = "~/Images/Adaptive/" + Qdata[u].testid.Trim() + "B.png", Width = 200 }); Panel_onImage.Controls.Add(new Label() { Text = "<br>" }); Panel_onImage.Controls.Add(new System.Web.UI.WebControls.Image() { ImageUrl = "~/Images/Adaptive/" + Qdata[u].testid.Trim() + "C.png", Width = 200 }); Panel_onImage.Controls.Add(new Label() { Text = "<br>" }); Panel_onImage.Controls.Add(new System.Web.UI.WebControls.Image() { ImageUrl = "~/Images/Adaptive/" + Qdata[u].testid.Trim() + "D.png", Width = 200 }); Panel_onImage.Controls.Add(new Label() { Text = "<br>" }); Panel_onImage.Controls.Add(new Button() { Text = "查看答題情況" }); Panel_onImage.Controls.Add(new Label() { Text = "<br>--------------------------------------------------------------------------------------------------------------------------------<br>" }); #endregion 畫圖 } } //----------------------------------------------------------------------- List <ChapterCount> chapterlist = new List <ChapterCount>(); AllData_Connection.Open(); //開啟AllData資料庫 DataBase_Language = "Select * from FloatData where TestID ='" + TestID + "'"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); Boolean getCH = false; #region 曲線取值 while (DataBase_Reader.Read()) { try { getCH = true; string tempChapter = (string)DataBase_Reader["Chapter"]; int skills = (int)DataBase_Reader["SkillsUnit"]; string Reply = "X"; if (!DataBase_Reader.IsDBNull(DataBase_Reader.GetOrdinal("Reply"))) { Reply = (string)DataBase_Reader["Reply"]; } for (int tc = 0; tc < chapterlist.Count; tc++) { if (tempChapter.Trim() == chapterlist[tc].chapter) { getCH = false; while (skills != 0) { int ab = skills % 10; if (Reply.Trim() == "A")//2 { chapterlist[tc].abilityYes[ab - 1]++; } chapterlist[tc].abilityTotal[ab - 1]++; skills = skills / 10; } } } //-------------沒有章節情況下 if (getCH == true) { ChapterCount tempCC = new ChapterCount(tempChapter.Trim()); while (skills != 0) { int ab = skills % 10; if (Reply.Trim() == "A")//2 { tempCC.abilityYes[ab - 1]++; } tempCC.abilityTotal[ab - 1]++; skills = skills / 10; } chapterlist.Add(tempCC); } } catch { } } AllData_Connection.Close();//開啟AllData資料庫 #endregion // Label2.Text = tempSelected; #region 資料讀取-屬性能力名稱 for (int tc = 0; tc < chapterlist.Count; tc++) { AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 DataBase_Language = " Select * from Ability"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); int tempIndex = 0; while (DataBase_Reader.Read()) { try { string TestDataNumber = (string)DataBase_Reader[chapterlist[tc].chapter.Trim()]; chapterlist[tc].abilityName[tempIndex] = TestDataNumber; tempIndex++; } catch { } } AllData_Connection.Close();//開啟AllData資料庫 } #endregion #region 畫圖 for (int tc = 0; tc < chapterlist.Count; tc++) { Chart Chart1 = new Chart(); Chart1.Width = 500; Chart1.Height = 300; Chart1.Series.Add("Series1"); Chart1.ChartAreas.Add("ChartArea1"); Chart1.Series["Series1"].ChartType = SeriesChartType.Bar; //橫條圖 Chart1.Series["Series1"].IsValueShownAsLabel = true; //---------- Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; //3D效果 Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = true; //並排顯示 Chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 40; //垂直角度 Chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 50; //水平角度 Chart1.ChartAreas["ChartArea1"].Area3DStyle.PointDepth = 30; //數據條深度 Chart1.ChartAreas["ChartArea1"].Area3DStyle.WallWidth = 0; //外牆寬度 Chart1.ChartAreas["ChartArea1"].Area3DStyle.LightStyle = LightStyle.Realistic; //光源 Chart1.ChartAreas["ChartArea1"].BackColor = Color.FromArgb(240, 240, 240); //背景色 Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.FromArgb(150, 150, 150); //X 軸線顏色 Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.FromArgb(150, 150, 150); //Y 軸線顏色 Chart1.Series["Series1"].MarkerSize = 16; Chart1.ChartAreas["ChartArea1"].AxisX.Title = "答題率(%)"; Chart1.ChartAreas["ChartArea1"].AxisY.Title = "屬性"; Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; //------ Title title = new Title(); title.Text = "[" + chapterlist[tc].chapter + "] 能力答題率"; title.Font = new System.Drawing.Font("Trebuchet MS", 14F, FontStyle.Bold); Chart1.Titles.Add(title); for (int U = 0; U < chapterlist[tc].abilityTotal.Length; U++) { if (chapterlist[tc].abilityTotal[U] != 0) { Chart1.Series["Series1"].Points.AddXY(U + 1, chapterlist[tc].abilityYes[U] * 100 / chapterlist[tc].abilityTotal[U]); } } //Chart1.Series["Series1"].IsValueShownAsLabel = true; for (int i = 0; i < Chart1.Series["Series1"].Points.Count; i++) { Chart1.Series["Series1"].Points[i].Label = "#VALX." + chapterlist[tc].abilityName[Convert.ToInt16(Chart1.Series["Series1"].Points[i].XValue) - 1] + "(#VALY %," + chapterlist[tc].abilityYes[Convert.ToInt16(Chart1.Series["Series1"].Points[i].XValue) - 1] + "/" + chapterlist[tc].abilityTotal[Convert.ToInt16(Chart1.Series["Series1"].Points[i].XValue) - 1] + ")"; if (Chart1.Series["Series1"].Points[i].YValues[0] > 60) { Chart1.Series["Series1"].Points[i].Color = Color.Green; } else { Chart1.Series["Series1"].Points[i].Color = Color.Red; } ; } // Chart1.DataBind(); //Chart1.Series["Series1"]["BarLabelStyle"]="Top"; Panel_chart.Controls.Add(Chart1); } #endregion int[] Score = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int nottest = 0; int totaltest = 0; AllData_Connection.Open(); //開啟AllData資料庫 DataBase_Language = "Select * from ExamsList where TestID= '" + TestID.Trim() + "'"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); while (DataBase_Reader.Read()) { totaltest++; int Sc = (int)DataBase_Reader["Score"]; if (Sc >= 0) { Score[(Sc / 10)]++; } else { nottest++; } } DataBase_Reader.Close(); AllData_Connection.Close();//close AllData資料庫 for (int U = 0; U < Score.Length; U++) { string name = ""; if (U == 0) { name = "10以下"; } else if (U == (Score.Length - 1)) { name = "滿分"; } else { name = (U * 10) + "~" + ((U + 1) * 10 - 1); } Chart_Score.Series["Series1"].Points.AddXY(name, Score[U]); } Chart_Score.Series["Series1"].Points.AddXY("未考", nottest); #region 畫圖成績 Chart_Score.Series["Series1"].ChartType = SeriesChartType.Bar; //橫條圖 Chart_Score.ChartAreas["ChartArea1"].AxisX.Title = "分數"; Chart_Score.ChartAreas["ChartArea1"].AxisY.Title = "人數"; Chart_Score.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; //3D效果 Chart_Score.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = true; //並排顯示 Chart_Score.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 40; //垂直角度 Chart_Score.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 50; //水平角度 Chart_Score.ChartAreas["ChartArea1"].Area3DStyle.PointDepth = 30; //數據條深度 Chart_Score.ChartAreas["ChartArea1"].Area3DStyle.WallWidth = 0; //外牆寬度 Chart_Score.Series["Series1"].IsValueShownAsLabel = true; Chart_Score.ChartAreas["ChartArea1"].BackColor = Color.FromArgb(240, 240, 240); //背景色 Chart_Score.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.FromArgb(150, 150, 150); //X 軸線顏色 Chart_Score.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.FromArgb(150, 150, 150); //Y 軸線顏色 Chart_Score.Series["Series1"].MarkerSize = 16; Title title1 = new Title(); title1.Text = "成績分布圖"; title1.Font = new System.Drawing.Font("Trebuchet MS", 18F, FontStyle.Bold); Chart_Score.Titles.Add(title1); for (int i = 0; i < Chart_Score.Series["Series1"].Points.Count; i++) { Chart_Score.Series["Series1"].Points[i].Label = "#VALX(#VALY人," + (Chart_Score.Series["Series1"].Points[i].YValues[0] * 100 / totaltest).ToString("0.00") + "%)"; } #endregion // this.GridView_Test.Columns[3].Visible = false; }
/// <summary> /// 生成试卷的具体题目 /// </summary> /// <returns>返回生成试卷的难度系数,-1表示生成失败</returns> private decimal Generate() { #region 定义辅助变量 ChapterCount SR = new ChapterCount(paper.sr_chapterrange, paper.sr_countofeachchatper); ChapterCount CB = new ChapterCount(paper.cb_chapterrange, paper.cb_countofeachchapter); ChapterCount JD = new ChapterCount(paper.jd_chapterrange, paper.jd_countofeachchapter); ChapterCount BF = new ChapterCount(paper.bf_chapterrange, paper.bf_countofeachchapter); ChapterCount SA = new ChapterCount(paper.sa_chapterrange, paper.sa_countofeachchapter); //定义可用的题目数量 int count = 0; //定义可用的难度系数集合 List <decimal> diffArray = null; //定义实际难度系数 decimal realDifficulty; //定义要求的难度系数 decimal demandDifficulty; //定义难度系数总和 decimal allDifficulty = 0; //定义已经出了的总题目数 Int32 allCount = 0; //定义暂时题目库 Dictionary <Int32, QuestionSimple> dictionary = null; //定义满足某个难度系数的题目库 List <Int32> smallDictionary = null; //定义随机产生的难度系数 decimal randomDifficulty = 0; //定义各个类型题目的难度系数数组 decimal[] diffSumArray = new decimal[] { 0, 0, 0, 0, 0 }; //定义从smallDictionary取出题目所要用到的随机数 Int32 randomSmall = -1; //定义取出的主键ID值 Int32 id = 0; #endregion #region 单选题抽取 //获得实际要求的难度系数 demandDifficulty = (decimal)paper.sr_diff; //实际难度系数,-1表示没有题目 realDifficulty = -1; //重新初始化数据 allCount = 0; allDifficulty = 0; //判断是否设置章节详细数目 if (SR.Chapter.Count != 0 && SR.Count.Count != 0) { //已设置章节详细数目 //============================循环各章节 for (int i = 0; i < SR.Chapter.Count && allCount < paper.sr_count; i++) { //获取第i个章节的可用题目数 count = GetCountOfChapter("tbSingle", SR.Chapter[i]); //判断第i个章节的可用题目数是否足够 if (count >= SR.Count[i]) { //清空dictionary,防止内存溢出 if (dictionary != null) { dictionary.Clear(); } //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } //获得第i个章节的题目库 dictionary = GetQuesOfChapter("tbSingle", SR.Chapter[i]); //获取第i个章节的可用难度系数 diffArray = GetDiffOfChapter("tbSingle", SR.Chapter[i]); //=====================循环第i个章节的各个题目 for (int j = 0; j < SR.Count[i]; j++) { randomDifficulty = GetRandomDiff(diffArray, realDifficulty, demandDifficulty, allCount); //从dictionary筛选出难度系数为randomDifficulty的子题目库 smallDictionary = GetSmallQuestion(dictionary, randomDifficulty); //产生另一个随机数 if (smallDictionary.Count != 0) { randomSmall = random.Next(0, smallDictionary.Count); //取出smallDictionary中的一个Key id = (Int32)smallDictionary[randomSmall]; } //取出题目 SR.TempQuestion.Add(dictionary[id]); SR.TempID.Add(id); //删除dictionary中的题目,防止重复 dictionary.Remove(id); //判断该难度系数是否还存在 if (smallDictionary.Count == 1) { //从diffArray中删除该难度系数 diffArray.Remove(randomDifficulty); } //总题目数加1 allCount++; //算出难度系数总和 allDifficulty += randomDifficulty; //算出现在的难度系数 realDifficulty = (decimal)allDifficulty / allCount; //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } } } else { //题目不足 return(-1); } } } else { //没有设置章节详细数目 //获取该科目的可用题目数 count = GetCountOfSubject("tbSingle", paper.subjectid); //判断该科目的可用题目数是否足够 if (count >= paper.sr_count) { //足够 //清空dictionary,防止内存溢出 if (dictionary != null) { dictionary.Clear(); } //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } //获得该科目的题目库 dictionary = GetQuesOfSubject("tbSingle", paper.subjectid); //获取该科目的可用难度系数 diffArray = GetDiffOfSubject("tbSingle", paper.subjectid); //================循环抽出各个题目 for (int i = 0; i < paper.sr_count; i++) { //产生随机难度系数 randomDifficulty = GetRandomDiff(diffArray, realDifficulty, demandDifficulty, allCount); //从dictionary筛选出难度系数为randomDifficulty的子题目库 smallDictionary = GetSmallQuestion(dictionary, randomDifficulty); //产生另一个随机数 if (smallDictionary.Count != 0) { randomSmall = random.Next(0, smallDictionary.Count); //取出smallDictionary中的一个Key id = (Int32)smallDictionary[randomSmall]; } //取出题目 SR.TempQuestion.Add(dictionary[id]); SR.TempID.Add(id); //删除dictionary中的题目,防止重复 dictionary.Remove(id); //判断该难度系数是否还存在 if (smallDictionary.Count == 1) { //从diffArray中删除该难度系数 diffArray.Remove(randomDifficulty); } //总题目数加1 allCount++; //算出难度系数总和 allDifficulty += randomDifficulty; //算出现在的难度系数 realDifficulty = (decimal)allDifficulty / allCount; //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } } } else { //题目不足 return(-1); } } //保存难度系数 diffSumArray[0] = allDifficulty; #endregion #region 多选题抽取 //获得实际要求的难度系数 demandDifficulty = (decimal)paper.cb_diff; //实际难度系数,-1表示没有题目 realDifficulty = -1; //重新初始化数据 allCount = 0; allDifficulty = 0; //判断是否设置章节详细数目 if (CB.Chapter.Count != 0 && CB.Count.Count != 0) { //已设置章节详细数目 //============================循环各章节 for (int i = 0; i < CB.Chapter.Count && allCount < paper.cb_count; i++) { //获取第i个章节的可用题目数 count = GetCountOfChapter("tbCheck", CB.Chapter[i]); //判断第i个章节的可用题目数是否足够 if (count >= CB.Count[i]) { //清空dictionary,防止内存溢出 if (dictionary != null) { dictionary.Clear(); } //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } //获得第i个章节的题目库 dictionary = GetQuesOfChapter("tbCheck", CB.Chapter[i]); //获取第i个章节的可用难度系数 diffArray = GetDiffOfChapter("tbCheck", CB.Chapter[i]); //=====================循环第i个章节的各个题目 for (int j = 0; j < CB.Count[i]; j++) { randomDifficulty = GetRandomDiff(diffArray, realDifficulty, demandDifficulty, allCount); //从dictionary筛选出难度系数为randomDifficulty的子题目库 smallDictionary = GetSmallQuestion(dictionary, randomDifficulty); //产生另一个随机数 if (smallDictionary.Count != 0) { randomSmall = random.Next(0, smallDictionary.Count); //取出smallDictionary中的一个Key id = (Int32)smallDictionary[randomSmall]; } //取出题目 CB.TempQuestion.Add(dictionary[id]); CB.TempID.Add(id); //删除dictionary中的题目,防止重复 dictionary.Remove(id); //判断该难度系数是否还存在 if (smallDictionary.Count == 1) { //从diffArray中删除该难度系数 diffArray.Remove(randomDifficulty); } //总题目数加1 allCount++; //算出难度系数总和 allDifficulty += randomDifficulty; //算出现在的难度系数 realDifficulty = (decimal)allDifficulty / allCount; //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } } } else { //题目不足 return(-1); } } } else { //没有设置章节详细数目 //获取该科目的可用题目数 count = GetCountOfSubject("tbCheck", paper.subjectid); //判断该科目的可用题目数是否足够 if (count >= paper.cb_count) { //足够 //清空dictionary,防止内存溢出 if (dictionary != null) { dictionary.Clear(); } //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } //获得该科目的题目库 dictionary = GetQuesOfSubject("tbCheck", paper.subjectid); //获取该科目的可用难度系数 diffArray = GetDiffOfSubject("tbCheck", paper.subjectid); //================循环抽出各个题目 for (int i = 0; i < paper.cb_count; i++) { //产生随机难度系数 randomDifficulty = GetRandomDiff(diffArray, realDifficulty, demandDifficulty, allCount); //从dictionary筛选出难度系数为randomDifficulty的子题目库 smallDictionary = GetSmallQuestion(dictionary, randomDifficulty); //产生另一个随机数 if (smallDictionary.Count != 0) { randomSmall = random.Next(0, smallDictionary.Count); //取出smallDictionary中的一个Key id = (Int32)smallDictionary[randomSmall]; } //取出题目 CB.TempQuestion.Add(dictionary[id]); CB.TempID.Add(id); //删除dictionary中的题目,防止重复 dictionary.Remove(id); //判断该难度系数是否还存在 if (smallDictionary.Count == 1) { //从diffArray中删除该难度系数 diffArray.Remove(randomDifficulty); } //总题目数加1 allCount++; //算出难度系数总和 allDifficulty += randomDifficulty; //算出现在的难度系数 realDifficulty = (decimal)allDifficulty / allCount; //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } } } else { //题目不足 return(-1); } } //保存难度系数 diffSumArray[1] = allDifficulty; #endregion #region 判断题抽取 //获得实际要求的难度系数 demandDifficulty = (decimal)paper.jd_diff; //实际难度系数,-1表示没有题目 realDifficulty = -1; //重新初始化数据 allCount = 0; allDifficulty = 0; //判断是否设置章节详细数目 if (JD.Chapter.Count != 0 && JD.Count.Count != 0) { //已设置章节详细数目 //============================循环各章节 for (int i = 0; i < JD.Chapter.Count && allCount < paper.jd_count; i++) { //获取第i个章节的可用题目数 count = GetCountOfChapter("tbJudge", JD.Chapter[i]); //判断第i个章节的可用题目数是否足够 if (count >= JD.Count[i]) { //清空dictionary,防止内存溢出 if (dictionary != null) { dictionary.Clear(); } //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } //获得第i个章节的题目库 dictionary = GetQuesOfChapter("tbJudge", JD.Chapter[i]); //获取第i个章节的可用难度系数 diffArray = GetDiffOfChapter("tbJudge", JD.Chapter[i]); //=====================循环第i个章节的各个题目 for (int j = 0; j < JD.Count[i]; j++) { randomDifficulty = GetRandomDiff(diffArray, realDifficulty, demandDifficulty, allCount); //从dictionary筛选出难度系数为randomDifficulty的子题目库 smallDictionary = GetSmallQuestion(dictionary, randomDifficulty); //产生另一个随机数 if (smallDictionary.Count != 0) { randomSmall = random.Next(0, smallDictionary.Count); //取出smallDictionary中的一个Key id = (Int32)smallDictionary[randomSmall]; } //取出题目 JD.TempQuestion.Add(dictionary[id]); JD.TempID.Add(id); //删除dictionary中的题目,防止重复 dictionary.Remove(id); //判断该难度系数是否还存在 if (smallDictionary.Count == 1) { //从diffArray中删除该难度系数 diffArray.Remove(randomDifficulty); } //总题目数加1 allCount++; //算出难度系数总和 allDifficulty += randomDifficulty; //算出现在的难度系数 realDifficulty = (decimal)allDifficulty / allCount; //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } } } else { //题目不足 return(-1); } } } else { //没有设置章节详细数目 //获取该科目的可用题目数 count = GetCountOfSubject("tbJudge", paper.subjectid); //判断该科目的可用题目数是否足够 if (count >= paper.jd_count) { //足够 //清空dictionary,防止内存溢出 if (dictionary != null) { dictionary.Clear(); } //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } //获得该科目的题目库 dictionary = GetQuesOfSubject("tbJudge", paper.subjectid); //获取该科目的可用难度系数 diffArray = GetDiffOfSubject("tbJudge", paper.subjectid); //================循环抽出各个题目 for (int i = 0; i < paper.jd_count; i++) { //产生随机难度系数 randomDifficulty = GetRandomDiff(diffArray, realDifficulty, demandDifficulty, allCount); //从dictionary筛选出难度系数为randomDifficulty的子题目库 smallDictionary = GetSmallQuestion(dictionary, randomDifficulty); //产生另一个随机数 if (smallDictionary.Count != 0) { randomSmall = random.Next(0, smallDictionary.Count); //取出smallDictionary中的一个Key id = (Int32)smallDictionary[randomSmall]; } //取出题目 JD.TempQuestion.Add(dictionary[id]); JD.TempID.Add(id); //删除dictionary中的题目,防止重复 dictionary.Remove(id); //判断该难度系数是否还存在 if (smallDictionary.Count == 1) { //从diffArray中删除该难度系数 diffArray.Remove(randomDifficulty); } //总题目数加1 allCount++; //算出难度系数总和 allDifficulty += randomDifficulty; //算出现在的难度系数 realDifficulty = (decimal)allDifficulty / allCount; //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } } } else { //题目不足 return(-1); } } //保存难度系数 diffSumArray[2] = allDifficulty; #endregion #region 填空题抽取 //获得实际要求的难度系数 demandDifficulty = (decimal)paper.bf_diff; //实际难度系数,-1表示没有题目 realDifficulty = -1; //重新初始化数据 allCount = 0; allDifficulty = 0; //判断是否设置章节详细数目 if (BF.Chapter.Count != 0 && BF.Count.Count != 0) { //已设置章节详细数目 //============================循环各章节 for (int i = 0; i < BF.Chapter.Count && allCount < paper.bf_count; i++) { //获取第i个章节的可用题目数 count = GetCountOfChapter("tbBlank", BF.Chapter[i]); //判断第i个章节的可用题目数是否足够 if (count >= BF.Count[i]) { //清空dictionary,防止内存溢出 if (dictionary != null) { dictionary.Clear(); } //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } //获得第i个章节的题目库 dictionary = GetQuesOfChapter("tbBlank", BF.Chapter[i]); //获取第i个章节的可用难度系数 diffArray = GetDiffOfChapter("tbBlank", BF.Chapter[i]); //=====================循环第i个章节的各个题目 for (int j = 0; j < BF.Count[i]; j++) { randomDifficulty = GetRandomDiff(diffArray, realDifficulty, demandDifficulty, allCount); //从dictionary筛选出难度系数为randomDifficulty的子题目库 smallDictionary = GetSmallQuestion(dictionary, randomDifficulty); //产生另一个随机数 if (smallDictionary.Count != 0) { randomSmall = random.Next(0, smallDictionary.Count); //取出smallDictionary中的一个Key id = (Int32)smallDictionary[randomSmall]; } //取出题目 BF.TempQuestion.Add(dictionary[id]); BF.TempID.Add(id); //删除dictionary中的题目,防止重复 dictionary.Remove(id); //判断该难度系数是否还存在 if (smallDictionary.Count == 1) { //从diffArray中删除该难度系数 diffArray.Remove(randomDifficulty); } //总题目数加1 allCount++; //算出难度系数总和 allDifficulty += randomDifficulty; //算出现在的难度系数 realDifficulty = (decimal)allDifficulty / allCount; //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } } } else { //题目不足 return(-1); } } } else { //没有设置章节详细数目 //获取该科目的可用题目数 count = GetCountOfSubject("tbBlank", paper.subjectid); //判断该科目的可用题目数是否足够 if (count >= paper.bf_count) { //足够 //清空dictionary,防止内存溢出 if (dictionary != null) { dictionary.Clear(); } //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } //获得该科目的题目库 dictionary = GetQuesOfSubject("tbBlank", paper.subjectid); //获取该科目的可用难度系数 diffArray = GetDiffOfSubject("tbBlank", paper.subjectid); //================循环抽出各个题目 for (int i = 0; i < paper.bf_count; i++) { //产生随机难度系数 randomDifficulty = GetRandomDiff(diffArray, realDifficulty, demandDifficulty, allCount); //从dictionary筛选出难度系数为randomDifficulty的子题目库 smallDictionary = GetSmallQuestion(dictionary, randomDifficulty); //产生另一个随机数 if (smallDictionary.Count != 0) { randomSmall = random.Next(0, smallDictionary.Count); //取出smallDictionary中的一个Key id = (Int32)smallDictionary[randomSmall]; } //取出题目 BF.TempQuestion.Add(dictionary[id]); BF.TempID.Add(id); //删除dictionary中的题目,防止重复 dictionary.Remove(id); //判断该难度系数是否还存在 if (smallDictionary.Count == 1) { //从diffArray中删除该难度系数 diffArray.Remove(randomDifficulty); } //总题目数加1 allCount++; //算出难度系数总和 allDifficulty += randomDifficulty; //算出现在的难度系数 realDifficulty = (decimal)allDifficulty / allCount; //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } } } else { //题目不足 return(-1); } } //保存难度系数 diffSumArray[3] = allDifficulty; #endregion #region 简答题抽取 //获得实际要求的难度系数 demandDifficulty = (decimal)paper.sa_diff; //实际难度系数,-1表示没有题目 realDifficulty = -1; //重新初始化数据 allCount = 0; allDifficulty = 0; //判断是否设置章节详细数目 if (SA.Chapter.Count != 0 && SA.Count.Count != 0) { //已设置章节详细数目 //============================循环各章节 for (int i = 0; i < SA.Chapter.Count && allCount < paper.sa_count; i++) { //获取第i个章节的可用题目数 count = GetCountOfChapter("tbAnswer", SA.Chapter[i]); //判断第i个章节的可用题目数是否足够 if (count >= SA.Count[i]) { //清空dictionary,防止内存溢出 if (dictionary != null) { dictionary.Clear(); } //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } //获得第i个章节的题目库 dictionary = GetQuesOfChapter("tbAnswer", SA.Chapter[i]); //获取第i个章节的可用难度系数 diffArray = GetDiffOfChapter("tbAnswer", SA.Chapter[i]); //=====================循环第i个章节的各个题目 for (int j = 0; j < SA.Count[i]; j++) { randomDifficulty = GetRandomDiff(diffArray, realDifficulty, demandDifficulty, allCount); //从dictionary筛选出难度系数为randomDifficulty的子题目库 smallDictionary = GetSmallQuestion(dictionary, randomDifficulty); //产生另一个随机数 if (smallDictionary.Count != 0) { randomSmall = random.Next(0, smallDictionary.Count); //取出smallDictionary中的一个Key id = (Int32)smallDictionary[randomSmall]; } //取出题目 SA.TempQuestion.Add(dictionary[id]); SA.TempID.Add(id); //删除dictionary中的题目,防止重复 dictionary.Remove(id); //判断该难度系数是否还存在 if (smallDictionary.Count == 1) { //从diffArray中删除该难度系数 diffArray.Remove(randomDifficulty); } //总题目数加1 allCount++; //算出难度系数总和 allDifficulty += randomDifficulty; //算出现在的难度系数 realDifficulty = (decimal)allDifficulty / allCount; //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } } } else { //题目不足 return(-1); } } } else { //没有设置章节详细数目 //获取该科目的可用题目数 count = GetCountOfSubject("tbAnswer", paper.subjectid); //判断该科目的可用题目数是否足够 if (count >= paper.sa_count) { //足够 //清空dictionary,防止内存溢出 if (dictionary != null) { dictionary.Clear(); } //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } //获得该科目的题目库 dictionary = GetQuesOfSubject("tbAnswer", paper.subjectid); //获取该科目的可用难度系数 diffArray = GetDiffOfSubject("tbAnswer", paper.subjectid); //================循环抽出各个题目 for (int i = 0; i < paper.sa_count; i++) { //产生随机难度系数 randomDifficulty = GetRandomDiff(diffArray, realDifficulty, demandDifficulty, allCount); //从dictionary筛选出难度系数为randomDifficulty的子题目库 smallDictionary = GetSmallQuestion(dictionary, randomDifficulty); //产生另一个随机数 if (smallDictionary.Count != 0) { randomSmall = random.Next(0, smallDictionary.Count); //取出smallDictionary中的一个Key id = (Int32)smallDictionary[randomSmall]; } //取出题目 SA.TempQuestion.Add(dictionary[id]); SA.TempID.Add(id); //删除dictionary中的题目,防止重复 dictionary.Remove(id); //判断该难度系数是否还存在 if (smallDictionary.Count == 1) { //从diffArray中删除该难度系数 diffArray.Remove(randomDifficulty); } //总题目数加1 allCount++; //算出难度系数总和 allDifficulty += randomDifficulty; //算出现在的难度系数 realDifficulty = (decimal)allDifficulty / allCount; //清空smallDictionary,防止内存溢出 if (smallDictionary != null) { smallDictionary.Clear(); } } } else { //题目不足 return(-1); } } //保存难度系数 diffSumArray[4] = allDifficulty; #endregion SetPaperContent(SR.TempID, CB.TempID, JD.TempID, BF.TempID, SA.TempID); //计算出总的难度系数 realDifficulty = ComputeDiff(diffSumArray); return(realDifficulty); }
protected void GridView_Test_SelectedIndexChanged(object sender, EventArgs e) { //string tempSelected = ((HiddenField)GridView_Test.SelectedRow.Cells[0].FindControl("HiddenField1")).Value; Label field = (Label)GridView_Test.Rows[GridView_Test.SelectedIndex].Cells[0].FindControl("Label3"); string tempSelected = GridView_Test.Rows[GridView_Test.SelectedIndex].Cells[3].Text; List <ChapterCount> chapterlist = new List <ChapterCount>(); AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 DataBase_Language = "Select * from FloatData where StudentID = '" + StudentID + "' AND TestID ='" + tempSelected + "'"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); Boolean getCH = false; #region 曲線取值 while (DataBase_Reader.Read()) { getCH = true; string tempChapter = (string)DataBase_Reader["Chapter"]; int skills = (int)DataBase_Reader["SkillsUnit"]; string Reply = "X"; if (!DataBase_Reader.IsDBNull(DataBase_Reader.GetOrdinal("Reply"))) { Reply = (string)DataBase_Reader["Reply"]; } for (int tc = 0; tc < chapterlist.Count; tc++) { if (tempChapter.Trim() == chapterlist[tc].chapter) { getCH = false; while (skills != 0) { int ab = skills % 10; if (Reply.Trim() == "A")//2 { chapterlist[tc].abilityYes[ab - 1]++; } chapterlist[tc].abilityTotal[ab - 1]++; skills = skills / 10; } } } //-------------沒有章節情況下 if (getCH == true) { ChapterCount tempCC = new ChapterCount(tempChapter.Trim()); while (skills != 0) { int ab = skills % 10; if (Reply.Trim() == "A")//2 { tempCC.abilityYes[ab - 1]++; } tempCC.abilityTotal[ab - 1]++; skills = skills / 10; } chapterlist.Add(tempCC); } } AllData_Connection.Close();//開啟AllData資料庫 #endregion // Label2.Text = tempSelected; #region 資料讀取-屬性能力名稱 for (int tc = 0; tc < chapterlist.Count; tc++) { AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 DataBase_Language = " Select * from Ability"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); int tempIndex = 0; while (DataBase_Reader.Read()) { try { string TestDataNumber = (string)DataBase_Reader[chapterlist[tc].chapter.Trim()]; chapterlist[tc].abilityName[tempIndex] = TestDataNumber; tempIndex++; } catch { } } AllData_Connection.Close();//開啟AllData資料庫 } #endregion #region 畫圖 for (int tc = 0; tc < chapterlist.Count; tc++) { Chart Chart1 = new Chart(); Chart1.Width = 500; Chart1.Height = 300; Chart1.Series.Add("Series1"); Chart1.ChartAreas.Add("ChartArea1"); Chart1.Series["Series1"].ChartType = SeriesChartType.Bar; //橫條圖 Chart1.Series["Series1"].IsValueShownAsLabel = true; //---------- Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; //3D效果 Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = true; //並排顯示 Chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 40; //垂直角度 Chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 50; //水平角度 Chart1.ChartAreas["ChartArea1"].Area3DStyle.PointDepth = 30; //數據條深度 Chart1.ChartAreas["ChartArea1"].Area3DStyle.WallWidth = 0; //外牆寬度 Chart1.ChartAreas["ChartArea1"].Area3DStyle.LightStyle = LightStyle.Realistic; //光源 Chart1.ChartAreas["ChartArea1"].BackColor = Color.FromArgb(240, 240, 240); //背景色 Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.FromArgb(150, 150, 150); //X 軸線顏色 Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.FromArgb(150, 150, 150); //Y 軸線顏色 Chart1.Series["Series1"].MarkerSize = 16; Chart1.ChartAreas["ChartArea1"].AxisX.Title = "答題率(%)"; Chart1.ChartAreas["ChartArea1"].AxisY.Title = "屬性"; Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; //------ Title title = new Title(); title.Text = "[" + chapterlist[tc].chapter + "] 能力答題率"; title.Font = new System.Drawing.Font("Trebuchet MS", 14F, FontStyle.Bold); Chart1.Titles.Add(title); for (int U = 0; U < chapterlist[tc].abilityTotal.Length; U++) { if (chapterlist[tc].abilityTotal[U] != 0) { Chart1.Series["Series1"].Points.AddXY(U + 1, chapterlist[tc].abilityYes[U] * 100 / chapterlist[tc].abilityTotal[U]); } } //Chart1.Series["Series1"].IsValueShownAsLabel = true; for (int i = 0; i < Chart1.Series["Series1"].Points.Count; i++) { Chart1.Series["Series1"].Points[i].Label = "#VALX." + chapterlist[tc].abilityName[Convert.ToInt16(Chart1.Series["Series1"].Points[i].XValue) - 1] + "(#VALY %," + chapterlist[tc].abilityYes[Convert.ToInt16(Chart1.Series["Series1"].Points[i].XValue) - 1] + "/" + chapterlist[tc].abilityTotal[Convert.ToInt16(Chart1.Series["Series1"].Points[i].XValue) - 1] + ")"; if (Chart1.Series["Series1"].Points[i].YValues[0] > 60) { Chart1.Series["Series1"].Points[i].Color = Color.Green; } else { Chart1.Series["Series1"].Points[i].Color = Color.Red; } ; } // Chart1.DataBind(); //Chart1.Series["Series1"]["BarLabelStyle"]="Top"; Panel_chart.Controls.Add(Chart1); } #endregion // this.GridView_Test.Columns[3].Visible = false; }