📄 createexaminepaper.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Caching;
using System.Data.SqlClient;
namespace ExamineSystem
{
/// <summary>
/// Summary description for CreateExaminePaper.
/// </summary>
public class CreateExaminePaper : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image RegisterImage;
protected System.Web.UI.WebControls.Label InfoLabel;
protected System.Web.UI.HtmlControls.HtmlGenericControl title;
private void Page_Load(object sender, System.EventArgs e)
{
ArrayList tempKindList = new ArrayList();
QuestionKinds kind = new QuestionKinds();
kind.KindID = 1;
kind.KindNum = 5;
tempKindList.Add(kind);
QuestionKinds kind2 = new QuestionKinds();
kind2.KindID = 2;
kind2.KindNum = 0;
tempKindList.Add(kind2);
QuestionKinds kind3 = new QuestionKinds();
kind3.KindID = 3;
kind3.KindNum = 5;
tempKindList.Add(kind3);
ArrayList QuestionData = new ArrayList();
QuestionData = CreateIntegerExaminePaper(100,3,6,tempKindList);
// ArrayList tempPaperList = GetRolePaper(Int32.Parse(Session["RoleID"].ToString()));
// if(tempPaperList.Count <= 0)
// {
// return;
// }
// QuestionData = CreateIntegerExaminePaper(Int32.Parse(tempPaperList[1].ToString()),
// Int32.Parse(tempPaperList[2].ToString()),Int32.Parse(tempPaperList[3].ToString()),
// (ArrayList)tempPaperList[4]);
Session[Session.SessionID + Session["UserName"].ToString()] = QuestionData;
}
private ArrayList GetRolePaper(int nRoleID)
{
int nPaperCount = 0;
ArrayList PaperList = new ArrayList();
PaperDB paper = new PaperDB();
SqlDataReader recpcount = paper.GetPaperCountByRole(nRoleID);
while(recpcount.Read())
{
nPaperCount = Int32.Parse(recpcount["PaperCount"].ToString());
}
recpcount.Close();
int index = GetRandomInt(nPaperCount);
int i = 0;
SqlDataReader recpc = paper.GetPaperByRole(nRoleID);
while(recpc.Read())
{
if(i == index)
{
PaperList.Add(recpc["PaperID"].ToString());
PaperList.Add(recpc["TotalMark"].ToString());
PaperList.Add(recpc["MinDefficult"].ToString());
PaperList.Add(recpc["MaxDefficult"].ToString());
break;
}
i++;
}
recpc.Close();
SqlDataReader recpk = paper.GetPaperKinds(Int32.Parse(PaperList[0].ToString()));
ArrayList KindList = new ArrayList();
if(recpk.Read())
{
QuestionKinds kind = new QuestionKinds();
kind.KindID = Int32.Parse(recpk["KindID"].ToString());
kind.KindNum = Int32.Parse(recpk["KindNum"].ToString());
KindList.Add(kind);
}
recpk.Close();
PaperList.Add(KindList);
return(PaperList);
}
private ArrayList CreateIntegerExaminePaper(int nTotalMark,int minDefficult,int maxDefficult,ArrayList KindList)
{
if(KindList.Count <= 0)
{
return((ArrayList)null);
}
int allMark = 0;
Decimal defficultParm = 0;
ArrayList QuestionIDList = new ArrayList();
int whilecount = 0;
while(true)
{
whilecount++;
if(whilecount > 10)
{
break;
}
for(int i = 0; i < KindList.Count; i++)
{
ArrayList tempList = CreateSpecialKindQuestion(((QuestionKinds)KindList[i]).KindNum,((QuestionKinds)KindList[i]).KindID);
for(int j = 0; j < tempList.Count; j++)
{
QuestionIDList.Add(tempList[j]);
}
}
for(int k = 0; k < QuestionIDList.Count; k++)
{
allMark += ((QuestionDetails)QuestionIDList[k]).Mark;
defficultParm += ((QuestionDetails)QuestionIDList[k]).Mark * ((QuestionDetails)QuestionIDList[k]).Defficult;
}
if(allMark == nTotalMark && defficultParm >= 100 * minDefficult * QuestionIDList.Count
&& defficultParm <= 100 * maxDefficult * QuestionIDList.Count)
{
break;
}
else
{
QuestionIDList = CreateIntegerExaminePaper(nTotalMark,minDefficult,maxDefficult,KindList);
}
}
return(QuestionIDList);
}
private ArrayList CreateSpecialKindQuestion(int nKindNum,int kind)
{
int index = 0;
ArrayList IndexList = new ArrayList();
IndexList.Capacity = nKindNum;
ArrayList QuestionIDList = new ArrayList();
QuestionIDList.Capacity = nKindNum;
while(IndexList.Count != nKindNum)
{
index = GetRandomInt(nKindNum);
if(IsExistIndex(IndexList,index) == false)
{
IndexList.Add(index.ToString());
}
}
QuestionDB question = new QuestionDB();
DataSet ds = new DataSet();
ds = (DataSet)Cache["QuestionIDList"];
if(ds == null)
{
ds = question.GetAllQuestionID();
Cache.Add("QuestionIDList",ds,null,DateTime.Now.AddMinutes(20),TimeSpan.Zero,
CacheItemPriority.High,null);
}
int startIndex = 0;
foreach(DataRow row in ds.Tables[0].Rows)
{
startIndex++;
if(row["KindID"].ToString() == kind.ToString())
{
break;
}
}
if(startIndex <= 0)
{
startIndex++;
}
if(startIndex >= ds.Tables[0].Rows.Count)
{
return(QuestionIDList);
}
for(int i = 0; i < IndexList.Count; i++)
{
QuestionDetails questionDetail = new QuestionDetails();
questionDetail.QuestionID = Int32.Parse(ds.Tables[0].Rows[i + startIndex -1].ItemArray[0].ToString());
questionDetail.Index = i + 1;
questionDetail.Mark = Int32.Parse(ds.Tables[0].Rows[i + startIndex -1].ItemArray[2].ToString());
questionDetail.Defficult = Int32.Parse(ds.Tables[0].Rows[i + startIndex -1].ItemArray[3].ToString());
QuestionIDList.Add(questionDetail);
}
///返回问题的ID集合
return(QuestionIDList);
}
private bool IsExistIndex(ArrayList IndexList,int index)
{
bool isExist = false;
for(int j = 0; j < IndexList.Count; j++)
{
if(index.ToString() == IndexList[j].ToString())
{
isExist = true;
break;
}
}
return(isExist);
}
private int GetRandomInt(int nKindNum)
{
Random random = new Random();
return(random.Next(nKindNum));
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -