protected void Image_Ques_PreRender(object sender, EventArgs e) { string studentID = ""; string TestID = ""; SqlConnection AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 SqlCommand cmd; SqlDataReader DataBase_Reader; //AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 createView(); int Qnow = Convert.ToInt32(Session["CCMATHReplynum"]); Response.Write(this.Panel_button.Controls.Count); HttpCookie mycookie = Request.Cookies["CCMATHTEST"]; /*if (mycookie != null) * {*/ TestID = Label_CTID.Text.Trim(); studentID = Label_CSID.Text.Trim(); /* }*/ string DataBase_Language = "Select * from FloatData where StudentID = '" + studentID + "'AND TestID='" + TestID + "'"; //資料庫語法 AllData_Connection.Open(); //開啟AllData資料庫 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); while (DataBase_Reader.Read()) { int numberQ = (int)DataBase_Reader["NumberQ"]; string reply = (string)DataBase_Reader["Reply"]; foreach (Button control in this.Panel_button.Controls) { if (control.ID == ("I" + numberQ).ToString().Trim()) { if (reply.Trim() != "X") { control.ForeColor = System.Drawing.Color.Black; control.BackColor = System.Drawing.Color.YellowGreen; } else { control.ForeColor = System.Drawing.Color.Black; control.BackColor = System.Drawing.Color.White; } } } } AllData_Connection.Close();//關閉AllData資料庫 foreach (Button control in this.Panel_button.Controls) { if (control.ID == ("I" + Qnow).ToString().Trim()) { control.ForeColor = System.Drawing.Color.White; control.BackColor = System.Drawing.Color.Black; } } }
protected void Button1_Click(object sender, EventArgs e) { int DataNum = 0; try { SqlConnection AllData_Connection = null; SqlDataReader DataBase_Reader; //資料庫讀取 AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 DataBase_Language = "Select COUNT(ID) from ExerciseData where DoneTimes >0"; //資料庫語法 SqlCommand cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); String s = ""; while (DataBase_Reader.Read()) { DataNum = (int)DataBase_Reader[0]; } AllData_Connection.Close(); } catch { Console.Write("資料庫連接無法連線,請從新輸入" + "\n"); } String [,] DataCatch = new String[DataNum, 8]; try { SqlConnection AllData_Connection = null; SqlDataReader DataBase_Reader; //資料庫讀取 AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 DataBase_Language = "Select ID,Difficulty,User1,User2,User3,User1Total,User2Total,User3Total from ExerciseData where DoneTimes >0"; //資料庫語法 SqlCommand cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); int i = 0; while (DataBase_Reader.Read()) { DataCatch[i, 0] = (string)DataBase_Reader["ID"]; DataCatch[i, 1] = "" + (int)DataBase_Reader["Difficulty"]; DataCatch[i, 2] = "" + (int)DataBase_Reader["User1"]; DataCatch[i, 3] = "" + (int)DataBase_Reader["User2"]; DataCatch[i, 4] = "" + (int)DataBase_Reader["User3"]; DataCatch[i, 5] = "" + (int)DataBase_Reader["User1Total"]; DataCatch[i, 6] = "" + (int)DataBase_Reader["User2Total"]; DataCatch[i, 7] = "" + (int)DataBase_Reader["User3Total"]; i++; } AllData_Connection.Close(); //Label1.Text = DataCatch[0, 0] + DataCatch[0, 1] + DataCatch[0, 2] + DataCatch[0, 3] + DataCatch[0, 4] + DataCatch[0, 5] + DataCatch[0, 6] + DataCatch[0,7]; //Label1.Text = "" + int.Parse(DataCatch[0, 6]); AnswersAbnormalRate(DataCatch, DataNum); } catch { Console.Write("資料庫連接無法連線,請從新輸入" + "\n"); } }
protected void Page_Load(object sender, EventArgs e) { SqlCommand cmd; SqlConnection AllData_Connection = null; SqlDataReader DataBase_Reader;//資料庫讀取 #region Use是否上線 AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 string DataBase_Language = "Select * from PersonalInformation Where Account=@Account and Passsword=@Passsword"; //資料庫語法 string MD5_A = ""; string MD5_P = ""; string Group = ""; try { MD5_A = Server.HtmlEncode(Request.Cookies["CCMATH"]["UserID"].ToString()); MD5_P = Server.HtmlEncode(Request.Cookies["CCMATH"]["Password"].ToString()); } catch { Server.Transfer("~/Account/Login.aspx"); } // Session["CCMATHUserID"] = MD5_A; // Session["CCMATHPassword"] = MD5_P; cmd = new SqlCommand(DataBase_Language, AllData_Connection);//使用SQL cmd.Parameters.Add("Account", SqlDbType.Char).Value = MD5_A; cmd.Parameters.Add("Passsword", SqlDbType.Char).Value = MD5_P; DataBase_Reader = cmd.ExecuteReader(); Boolean check = false; while (DataBase_Reader.Read()) { check = true; studentID = (string)DataBase_Reader["StudentID"]; Group = (string)DataBase_Reader["Groups"]; } AllData_Connection.Close();//開啟AllData資料庫 if (!check) { Server.Transfer("~/Account/Login.aspx"); } #endregion Label_group.Text = Group.Trim(); }
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; }
protected void Page_Load(object sender, EventArgs e) { //初始化 if (!IsPostBack) { string TestID = ""; string studentID = ""; int QuestionSet = 0; HttpCookie mycookie = Request.Cookies["CCMATHTEST"]; if (mycookie != null) { Label_ID.Text = mycookie.Values["SID"]; studentID = mycookie.Values["SID"]; Label_class.Text = HttpUtility.UrlDecode(mycookie.Values["Name"]); Label_textId.Text = mycookie.Values["textID"]; TestID = HttpUtility.UrlDecode(mycookie.Values["textID"]); Label_context.Text = HttpUtility.UrlDecode(mycookie.Values["Context"]); //Label_Qnum.Text = mycookie.Values["totalNumber"]; // QuestionSet = Convert.ToInt16(Label_Qnum.Text.Trim()); } else { Server.Transfer("~/WebPage/TestQuestion.aspx"); } //------------------------------------ #region 題目設定 if (TestID != string.Empty) { SqlConnection AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 SqlCommand cmd; SqlDataReader DataBase_Reader; AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 #region 刪除 /*刪除*/ DataBase_Language = string.Format("DELETE FROM FloatData WHERE StudentID = '{0}' AND TestID='{1}'", studentID, TestID); cmd = new SqlCommand(DataBase_Language, AllData_Connection);//使用SQL cmd.Connection = AllData_Connection; cmd.ExecuteNonQuery(); #endregion /*---*/ #region 找題目 /*找題目*/ Response.Write("ID:" + TestID); // TestID = TestID.Trim(); DataBase_Language = "Select * from SelectedData where TextID = '" + TestID.Trim() + "'"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); List <string> TestData = new List <string>(); List <string> RandData = new List <string>(); //初始化 TestData.Clear(); RandData.Clear(); while (DataBase_Reader.Read()) { int Way = (int)DataBase_Reader["Way"]; string doNumber = (string)DataBase_Reader["doNumber"]; switch (Way) { case 1: //必出題目 TestData.Add(doNumber); break; case 2: //隨機選擇 RandData.Add(doNumber); break; } } DataBase_Reader.Close(); #endregion int index = 0; string temp = ""; int RandCount = 0; int TotalCount = 0; try { //隨機打亂 for (int i = 0; i < RandData.Count; i++) { index = rand.Next(0, RandData.Count - 1); if (index != i) { temp = RandData[i]; RandData[i] = RandData[index]; RandData[index] = temp; } } DataBase_Language = "Select * from TestTimeData where TestID= '" + TestID.Trim() + "'"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); while (DataBase_Reader.Read()) { RandCount = (int)DataBase_Reader["RandCount"]; TotalCount = (int)DataBase_Reader["TotalCount"]; QuestionSet = TotalCount; } DataBase_Reader.Close(); //加入隨機選題目 for (int tempRandCount = 0; tempRandCount < RandCount; tempRandCount++) { if (TestData.Count < QuestionSet) { TestData.Add(RandData[tempRandCount].Trim()); } } //一一把題目匯入 string[] option_set = { "C", "B", "D", "A" }; // 選項 string OptionSet = ""; //打亂後存入選項 int diff = 0; //困難度 string TestDataNumber = ""; int SKill = 0; //每一題設定 for (int Ques = 1; Ques <= TestData.Count; Ques++) { //選項打亂 for (int t = 0; t < option_set.Length; t++) { int A = t; int B = rand.Next(option_set.Length); string temp_S = option_set[A]; option_set[A] = option_set[B]; option_set[B] = temp_S; } OptionSet = option_set[0] + option_set[1] + option_set[2] + option_set[3]; TestDataNumber = TestData[Ques - 1]; //實際作答題號 DataBase_Language = "Select * from ExerciseData where ID = '" + TestDataNumber + "'"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); string Chapter = ""; while (DataBase_Reader.Read()) { SKill = (int)DataBase_Reader["SkillsUnit"]; Chapter = (string)DataBase_Reader["Chapter"]; diff = (int)DataBase_Reader["Difficulty"]; } DataBase_Reader.Close(); //停用上一個CMD用法 // //載入到浮動資料 char Reply = 'X'; string AddNew = string.Format("INSERT INTO FloatData(StudentID, QuestionID,SaveOption,NumberQ,TestType,Chapter,TestID,SkillsUnit,Difficulty,Reply) VALUES('{0}','{1}','{2}',{3},{4},'{5}','{6}','{7}','{8}','{9}')", studentID, TestDataNumber, OptionSet, Ques, 1, Chapter, TestID, SKill, diff, 'X'); //要改 cmd = new SqlCommand(AddNew, AllData_Connection); //使用SQL cmd.Connection = AllData_Connection; cmd.ExecuteNonQuery(); DataBase_Reader.Close(); } //cookie 更新. HttpCookie CCcookie = new HttpCookie("CCMATHTESTTN"); CCcookie.Values.Add("TN", TestData.Count.ToString()); CCcookie.Expires = DateTime.Now.AddDays(5); // Response.Cookies["CCMATHTESTTN"].Domain = ""; Response.Cookies.Add(CCcookie); Response.AppendCookie(CCcookie); // Response.Redirect("~/WebPage/Exam_Page.aspx"); // Response.Cookies["CCMATHTEST"].Values["totalNumber"] = TestData.Count.ToString(); // mycookie.Values[]= TestData.Count.ToString(); Label_Qnum.Text = CCcookie.Values["TN"]; } catch { } AllData_Connection.Close();//開啟AllData資料庫 } else { Server.Transfer("~/WebPage/AdaptiveOption.aspx"); } #endregion } }
//string[] option_set = { "D", "A", "C", "B" };//選項暫存 protected void Page_Load(object sender, EventArgs e) { Button_Finish.Attributes.Add("onclick", "return confirm('確定要離開考試嗎?');"); if (!IsPostBack) { Session["CCMATHReplynum"] = 1; setQuestion(); // createButton(); // ChangeView(); HttpCookie mycookie = Request.Cookies["CCMATHTEST"]; if (mycookie != null && mycookie.Values["textID"] != string.Empty) { Label_CSID.Text = mycookie.Values["SID"]; Label_CTID.Text = mycookie.Values["textID"]; //Label_Count.Text= mycookie.Values["totalNumber"]; } else { if (mycookie.Values["SID"] == string.Empty) { Response.Write("問題:讀不到學號"); Response.Redirect("~/WebPage/TextOption_Page.aspx"); } if (mycookie.Values["textID"] == string.Empty) { Response.Write("問題:讀不到考試內容"); Response.Redirect("~/WebPage/TextOption_Page.aspx"); } else { Response.Redirect("~/WebPage/TextOption_Page.aspx"); } } HttpCookie TNcookie = Request.Cookies["CCMATHTESTTN"]; if (TNcookie != null) { Label_Count.Text = TNcookie.Values["TN"]; } else { Label_Count.Text = "15"; SqlConnection AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 SqlCommand cmd; SqlDataReader DataBase_Reader; AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 string DataBase_Language = "Select * from TestTimeData where TestID='" + Label_CTID.Text.Trim() + "'"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); int TotalCount = 0; while (DataBase_Reader.Read()) { TotalCount = (int)DataBase_Reader["TotalCount"]; } AllData_Connection.Close();//關閉AllData資料庫 Label_Count.Text = TotalCount.ToString(); } } createButton(); // setQuestion(); // createButton(); }
public void setQuestion() //設定題目 { SqlConnection AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 SqlCommand cmd; SqlDataReader DataBase_Reader; AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 int NQ = Convert.ToInt32(Session["CCMATHReplynum"]); string studentID = ""; string TestID = ""; string OptionSet = ""; //存下選項 string TestDataNumber = ""; string Reply = "X"; //存下選項 string SaveOption = "CABD"; HttpCookie mycookie = Request.Cookies["CCMATHTEST"]; if (mycookie != null && mycookie.Values["textID"] != string.Empty) { studentID = HttpUtility.UrlDecode(mycookie.Values["SID"]); TestID = mycookie.Values["textID"]; } else { TestID = Label_CTID.Text; studentID = Label_CSID.Text; } //string update = string.Format("UPDATE FloatData set Reply='{0}' where StudentID='{1}' AND NumberQ ='{2}' AND TestType='{3}' ", OptionSet, studentID, PersonReply, 1); string DataBase_Language = "Select * from FloatData where NumberQ = '" + NQ + "' AND StudentID = '" + studentID.Trim() + "'AND TestID='" + TestID.Trim() + "'"; //資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection); //使用SQL DataBase_Reader = cmd.ExecuteReader(); while (DataBase_Reader.Read()) { OptionSet = (string)DataBase_Reader["SaveOption"]; TestDataNumber = (string)DataBase_Reader["QuestionID"]; Reply = (string)DataBase_Reader["Reply"]; SaveOption = (string)DataBase_Reader["SaveOption"]; } AllData_Connection.Close(); //11/9還沒取題目.選項設定好 //string TestDataNumber = ""; string[] option_set = { "D", "A", "C", "B" }; char[] charArr = OptionSet.ToCharArray(); for (int U = 0; U < 4; U++) //選項 { option_set[U] = charArr[U].ToString(); } ViewState["CCMathsaveOptionA"] = option_set[0]; ViewState["CCMathsaveOptionB"] = option_set[1]; ViewState["CCMathsaveOptionC"] = option_set[2]; ViewState["CCMathsaveOptionD"] = option_set[3]; RadioButton_Option1.Checked = false; RadioButton_Option2.Checked = false; RadioButton_Option3.Checked = false; RadioButton_Option4.Checked = false; Reply = Reply.Trim(); if (Reply == option_set[0]) { RadioButton_Option1.Checked = true; } else if (Reply == option_set[1]) { RadioButton_Option2.Checked = true; } else if (Reply == option_set[2]) { RadioButton_Option3.Checked = true; } else if (Reply == option_set[3]) { RadioButton_Option4.Checked = true; } System.Drawing.Image image_set = System.Drawing.Image.FromFile(Server.MapPath("~/Images/Adaptive/" + TestDataNumber.Trim() + "Q.png")); Image_Ques.ImageUrl = "~/Images/Adaptive/" + TestDataNumber.Trim() + "Q.png"; Image_Ques.Width = image_set.Width; Image_Ques.Height = image_set.Height; Image_Option1.ImageUrl = "~/Images/Adaptive/" + TestDataNumber.Trim() + option_set[0].Trim() + ".png"; Image_Option2.ImageUrl = "~/Images/Adaptive/" + TestDataNumber.Trim() + option_set[1].Trim() + ".png"; Image_Option3.ImageUrl = "~/Images/Adaptive/" + TestDataNumber.Trim() + option_set[2].Trim() + ".png"; Image_Option4.ImageUrl = "~/Images/Adaptive/" + TestDataNumber.Trim() + option_set[3].Trim() + ".png"; }
protected void Button1_Click(object sender, EventArgs e) { Boolean error; error = true; Label_ERROR.Text = ""; /* * string MD5_P = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5").ToLower(); */ SqlCommand cmd; SqlConnection AllData_Connection = null; SqlDataReader DataBase_Reader;//資料庫讀取 #region Use是否上線 AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 string DataBase_Language = "Select * from PersonalInformation Where Account=@Account "; //資料庫語法 string MD5_A = ""; string MD5_P = ""; try { MD5_A = Server.HtmlEncode(Request.Cookies["CCMATH"]["UserID"].ToString()); MD5_P = Server.HtmlEncode(Request.Cookies["CCMATH"]["Password"].ToString()); } catch { // Server.Transfer("~/Account/Login.aspx"); } // Session["CCMATHUserID"] = MD5_A; // Session["CCMATHPassword"] = MD5_P; cmd = new SqlCommand(DataBase_Language, AllData_Connection);//使用SQL cmd.Parameters.Add("Account", SqlDbType.Char).Value = MD5_A; //cmd.Parameters.Add("Passsword", SqlDbType.Char).Value = MD5_P; DataBase_Reader = cmd.ExecuteReader(); Boolean check = false; while (DataBase_Reader.Read()) { check = true; string password = (string)DataBase_Reader["Passsword"]; string check_old = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox_old.Text.Trim(), "MD5").ToLower(); if (password.Trim() != check_old.Trim()) { error = false; Label_ERROR.Text += "舊密碼錯誤\n"; } // Purview = (string)DataBase_Reader["Purview"]; } AllData_Connection.Close();//開啟AllData資料庫 if (TextBox_new1.Text.Trim() != TextBox_new2.Text.Trim()) { error = false; Label_ERROR.Text += "新密碼不一致\n"; } if (check && error) { string passwordMD5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox_new1.Text.Trim(), "MD5").ToLower(); AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結 AllData_Connection.Open(); //開啟AllData資料庫 DataBase_Language = "UPDATE PersonalInformation set Passsword=@Passsword Where Account=@Account"; //DataBase_Language = "update * from ExerciseData s where Chapter = '" + chapterSelect + "'";//資料庫語法 cmd = new SqlCommand(DataBase_Language, AllData_Connection);//使用SQL cmd.Parameters.Add("Account", SqlDbType.Char).Value = MD5_A; cmd.Parameters.Add("Passsword", SqlDbType.Char).Value = passwordMD5; cmd.ExecuteNonQuery(); AllData_Connection.Close(); Session["CCMATHUserID"] = MD5_A; Session["CCMATHPassword"] = passwordMD5; } #endregion }