?? showfullexercise.aspx.cs.svn-base
字號:
?using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.IO;
public partial class Student_UnitEx_ShowFullExercise : System.Web.UI.Page
{
String tp;
string[] str ={ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" };
string ConnectionString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection myConnection = null;
SqlDataAdapter myAdapter = null;
DataSet myDateSet = null;
String info;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERSTYLE"] == "STUDENT")
{
}
else
{
Dialog("對不起,你沒有權(quán)限訪問這個頁面!");
Response.Redirect("~/SystemManage/Login.aspx");
}
tp = Request.QueryString["deep"];
info = CheckInfo("TAB_TESTFULL", "TFCONTENT", "TFGRADE", tp);
txt_full.Text = readData(info);
}
private void Dialog(String Str)
{
Response.Write(@"<script type='text/JavaScript'>");
Response.Write(@"alert('" + Str + "');");
//Response.Write(@"window.location='./list_logingroup.aspx';");
Response.Write(@"</script>");
}
public String readData(String FileName)
{
String ss = "";
String A = Server.MapPath("Exercise.asps");
String delimStr = "Wed";
string[] sArray = Regex.Split(A, delimStr, RegexOptions.None);
int j = 0;
String[] str = new string[2];
foreach (string filePath in sArray)
{
str[j] = filePath.ToString(); j++;
}
try
{
FileStream fs = new FileStream(str[0] + "\\Wed\\SubjectManage\\Full\\" + FileName, FileMode.Open);
StreamReader sr = new StreamReader(fs);
ss = sr.ReadToEnd();
sr.Close();
}
catch (Exception ex)
{
Console.Write(ex);
}
return ss;
}
public string CheckInfo(String TableName, String ColumnName1,String ColumnName2, String Str)
{
myConnection = new SqlConnection(ConnectionString);
try
{
string ColumnName; ;
String conString = "SELECT " + ColumnName1 +","+"TFNO"+ " FROM " + TableName + " where " + ColumnName2 + "='" + Str + "'";
myAdapter = new SqlDataAdapter(conString, myConnection);
myDateSet = new DataSet();
myAdapter.Fill(myDateSet);
myAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataTable Table = myDateSet.Tables[0];
if (Table.Rows.Count != 0)
{
int i;
String f_info;
Random ra = new Random(unchecked((int)DateTime.Now.Ticks));
i = ra.Next(0, Table.Rows.Count-1);
f_info = (string)Table.Rows[i].ItemArray[0];
ColumnName=(string)Table.Rows[i].ItemArray[1];
LinkInfo(ColumnName,"A","B","C","D","TFNO");
return f_info;
}
else
{
return "";
}
}
catch (SqlException E)
{
return E.Message;
}
}
public void LinkInfo(String TN, String ColumnName1, String ColumnName2, string ColumnName3, string ColumnName4, string ColumnName5)
{
int j;
String tr = "ANO";
RadioButtonList[] rdols ={ RadioButtonList1, RadioButtonList2, RadioButtonList3, RadioButtonList4, RadioButtonList5, RadioButtonList6, RadioButtonList7, RadioButtonList8, RadioButtonList9, RadioButtonList10,
RadioButtonList11,RadioButtonList12,RadioButtonList13,RadioButtonList14,RadioButtonList15,RadioButtonList16,RadioButtonList17,RadioButtonList18,RadioButtonList19,RadioButtonList20};
//循環(huán)取數(shù)據(jù)庫的選項
for (j = 0; j < 20; j++)
{
myConnection = new SqlConnection(ConnectionString);
String conString = "SELECT " + ColumnName1 + "," + ColumnName2 + "," + ColumnName3 + "," + ColumnName4 +" FROM " + "TAB_TESTFULLKEY" + " where " + ColumnName5 + "='" +TN+ "'and " + tr + "='" + str[j]+"'";
myAdapter = new SqlDataAdapter(conString, myConnection);
myDateSet = new DataSet();
myAdapter.Fill(myDateSet, "user_info");
myAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataTable Table = myDateSet.Tables[0];
if (Table.Rows.Count == 0)
continue;
rdols[j].Items[0].Value= "A. " + (string)Table.Rows[0].ItemArray[0] ;
rdols[j].Items[1].Value = "B. " + (string)Table.Rows[0].ItemArray[1];
rdols[j].Items[2].Value = "C. " + (string)Table.Rows[0].ItemArray[2];
rdols[j].Items[3].Value = "D. " + (string)Table.Rows[0].ItemArray[3];
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void txt1_TextChanged(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
String[] answer ={"A","B","C","D" };
String[] answer1 = new string[20];
int i;
double f;
int k = 0;
string[] select=new string[20];
RadioButtonList[] rdols ={ RadioButtonList1, RadioButtonList2, RadioButtonList3, RadioButtonList4, RadioButtonList5, RadioButtonList6, RadioButtonList7, RadioButtonList8, RadioButtonList9, RadioButtonList10,
RadioButtonList11,RadioButtonList12,RadioButtonList13,RadioButtonList14,RadioButtonList15,RadioButtonList16,RadioButtonList17,RadioButtonList18,RadioButtonList19,RadioButtonList20};
//選出完型填空題編碼
string P_TFNO;
myConnection = new SqlConnection(ConnectionString);
String conString = "SELECT " + "TFNO" + " FROM " + "TAB_TESTFULL" + " where " + "TFGRADE" + "='" + tp + "'and"+" TFCONTENT"+"='"+info+"'";
myAdapter = new SqlDataAdapter(conString, myConnection);
myDateSet = new DataSet();
myAdapter.Fill(myDateSet, "user_info");
myAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataTable Table = myDateSet.Tables[0];
P_TFNO = (string)Table.Rows[0].ItemArray[0];
for (i = 0; i < 19;i++)
{
for(int j=0;j<4;j++){
if (rdols[i].Items[j].Selected)
select[i] = answer[j];
}
}
TextBox7.Text += "答案分析如下:" + "\n";
for (i = 0; i < 20; i++)
{
String conString1 = "SELECT " + "TFKEY" + " FROM " + " TAB_TESTFULLKEY" + " where " + "TFNO" + "='" + P_TFNO + "'and" + " ANO" + "='" + str[i] + "'";
myAdapter = new SqlDataAdapter(conString1, myConnection);
myDateSet = new DataSet();
myAdapter.Fill(myDateSet, "user_info");
myAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataTable Table1 = myDateSet.Tables[0];
if (Table1.Rows.Count == 0)
continue;
answer1[i]= (string)Table1.Rows[0].ItemArray[0];
if (answer1[i] == select[i])
{
k++;
TextBox7.Text += "\r\n"+"你選的答案" + answer1[i] + "正確";
}
else
TextBox7.Text += "\r\n"+"你選的答案" + select[i] + "錯誤" ;
}
TextBox3.Text += "正確的答案是:" + "\r\n\n";
for(i=0;i<20;i++)
TextBox3.Text += answer1[i] + "\r\n";
TextBox1.Text +="你選擇的答案是:"+ "\r\n\n";
for (i = 0; i < 20; i++)
TextBox1.Text += select[i] + "\r\n";
f = (float)k * 0.5;
TextBox5.Text =f.ToString();
f = (float)k / (float)20;
TextBox4.Text = f.ToString();
TextBox6.Text = tp;
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>window.close();</script>");
}
protected void BtnReturn_Click(object sender, EventArgs e)
{
Response.Redirect("~/SystemManage/Main.aspx");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -