?? testfullex.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_GeneralEx_TestFullEx : System.Web.UI.Page
{
public String[] strAnswer = new String[70];//答案
public int TestNumber = 1;//題量,完型1道
public int QuesNumber = 20;//每題的問題數量
public static String strHard;//難度
string Sname = "";
public static readonly string ConnectionString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERSTYLE"] == "STUDENT")
{
}
else
{
Dialog("對不起,你沒有權限訪問這個頁面!");
Response.Redirect("~/SystemManage/Login.aspx");
}
Sname = Request.QueryString["Sname"];
if (Sname != null)
{
strHard = Request.QueryString["strHard"];
if (strHard == null) strHard = "4";//=
String[] MainKey = getMainKey("TAB_TESTFULL", "TFGRADE", strHard);
if (MainKey.Length < TestNumber)
{
Dialog(MainKey[0]);//題庫題量不夠
}
txtFullBindData(MainKey);
RdBindData(MainKey);
}
else
{
Dialog("對不起,你沒有權限訪問這個頁面!");
Response.Redirect("~/SystemManage/Login.aspx");
}
}
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[] getMainKey(String TableName, String ColumnName, String Str)
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
String conString = "SELECT * FROM " + TableName + " where " + ColumnName + "='" + Str + "'";
String[] strMainKey = new String[TestNumber];
try
{
SqlDataAdapter myAdapter = new SqlDataAdapter(conString, myConnection);
DataSet myDateSet = new DataSet();
myAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
myAdapter.Fill(myDateSet, "getTestRead");
DataTable Table = myDateSet.Tables[0];
int i = Table.Rows.Count;
if (i < TestNumber)
{
TestNumber = i;//題庫題目太少,出不了一張完整的試卷!
}
int[] a;//聲明一個數組用來接收返回的隨機數
a = getRandomNum(TestNumber, 0, i+1);//從0-(i-1)中產生4個不一樣的數裝入數組a中
for (int j = 0; j < TestNumber; j++)
{
strMainKey[j] = (String)Table.Rows[a[j]-1].ItemArray[0];
}
}
finally
{
myConnection.Close();
}
return strMainKey;
}
//產生真正的隨機數
public int getNum(int[] arrNum, int tmp, int minValue, int maxValue, Random ra)
{
bool IsRan = false;
while (!IsRan)
{
int n;
for (n = 0; n <= arrNum.Length - 1; n++)
{
if (arrNum[n] == tmp)
{
tmp = ra.Next(minValue, maxValue);
break;
//getNum(arrNum, tmp, minValue, maxValue, ra);
}
}
if(n == arrNum.Length )
IsRan = true;
}
return tmp;
}
//產生一組隨機數
public int[] getRandomNum(int num, int minValue, int maxValue)
{
Random ra = new Random(unchecked((int)DateTime.Now.Ticks));
int[] arrNum = new int[num];
int tmp = 0;
for (int i = 0; i <= num - 1; i++)
{
tmp = ra.Next(minValue, maxValue);
arrNum[i] = getNum(arrNum, tmp, minValue, maxValue, ra);
}
return arrNum;
}
public void txtFullBindData(String[] Str)
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
try
{
String TableName = "TAB_TESTFULL";
String ColumnName1 = "TFCONTENT";
String ColumnName2 = "TFNO";
String conString = "SELECT " + ColumnName1 + " FROM " + TableName + " where " + ColumnName2 + "='" + Str[0] + "'";
SqlDataAdapter da = new SqlDataAdapter(conString, myConnection);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable Table = ds.Tables[0];
if (Table.Rows.Count == 0)
return;
String strTmp = (String)Table.Rows[0].ItemArray[0];
TxtFull.Text =readData(strTmp);
}
finally
{
myConnection.Close();
}
}
public void RdBindData(String[] Str)
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
try
{
String TableName = "TAB_TESTFULLKEY";
String ColumnName1 = "A";
String ColumnName2 = "B";
String ColumnName3 = "C";
String ColumnName4 = "D";
String ColumnName5 = "TFNO";
String ColumnName6 = "ANO";
String ColumnName7 = "TFKEY";
String[] strOption ={ "A.", "B.", "C.", "D." };
String[] strQno={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"};
RadioButtonList[] Rd ={ Rd1, Rd2, Rd3, Rd4, Rd5, Rd6, Rd7, Rd8, Rd9, Rd10, Rd11, Rd12, Rd13, Rd14, Rd15, Rd16, Rd17, Rd18, Rd19, Rd20 };
for (int i = 0; i < QuesNumber; i++)
{
String conString = "SELECT " + ColumnName1 + "," + ColumnName2 + "," + ColumnName3 + "," + ColumnName4 +","+ColumnName7+ " FROM " + TableName + " where " + ColumnName5 + "='" + Str[0] + "'and " + ColumnName6 + "='" + strQno[i] + "'";
SqlDataAdapter da = new SqlDataAdapter(conString, myConnection);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable Table = ds.Tables[0];
if (Table.Rows.Count == 0)
{
strAnswer[50 + i] = "題為空";
continue;
}
for (int k = 0; k < 4; k++)
{
Rd[i].Items[k].Value = strOption[k] + (String)Table.Rows[0].ItemArray[k];
}
strAnswer[50 + i] = (String)Table.Rows[0].ItemArray[4];
}
}
finally
{
myConnection.Close();
}
}
protected void BltNext_Click(object sender, EventArgs e)
{
String[] strOption ={ "A", "B", "C", "D" };
RadioButtonList[] Rd ={ Rd1, Rd2, Rd3, Rd4, Rd5, Rd6, Rd7, Rd8, Rd9, Rd10, Rd11, Rd12, Rd13, Rd14, Rd15, Rd16, Rd17, Rd18, Rd19, Rd20 };
for (int i = 0; i < 20; i++)
{
int j;
for (j = 0; j < 4; j++)
{
if (Rd[i].Items[j].Selected)
{
strAnswer[50 + i] +="&"+ strOption[j];
break;
}
}
if (j == 4)
strAnswer[50 + i] += "&" + "未選";
}
String[] strAn ={ "test51", "test52", "test53", "test54", "test55", "test56", "test57", "test58", "test59", "test60", "test61", "test62", "test63", "test64", "test65", "test66", "test67", "test68", "test69", "test70" };//索引答案
//Session.Clear();
for (int i = 0; i < 20; i++)
{
Session[strAn[i]] = strAnswer[50+i];
}
String sParam = "?strHard=" + strHard;
sParam += "&Sname=" + Sname;
Response.Redirect("~/Student/GeneralEx/Evaluate.aspx" + sParam);
}
public String readData(String FileName)
{
String ss = "";
String A = Server.MapPath("TestFullEx.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;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -