📄 frmstart.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using ExamSystem.Common.Objects;
using ExamSystem.Common;
using ExamSystem.BusinessFacade.TopicsFacade;
using System.Threading;
namespace StudentsClient
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class FrmStart : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Panel panel6;
private System.Windows.Forms.Button btnEnd;
private System.Windows.Forms.Panel panel7;
private System.Windows.Forms.Label lblTopic;
private System.Windows.Forms.Panel panel8;
private System.Windows.Forms.Label lblAnswer;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Panel panel5;
private System.ComponentModel.IContainer components;
private Exam curExam;
private ExamSystem.Common.DataListView dlvTitles;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Button btnNext;
private System.Windows.Forms.Button btnBack;
private System.Windows.Forms.CheckedListBox clbAnwser;
private System.Windows.Forms.RichTextBox rtbTitle;
private DataSet dsTitle;
private System.Windows.Forms.Timer timerExam;
private System.Windows.Forms.Label labTime;//题目的数据集
private ExamTime examTime;
public FrmStart(Exam exam)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.curExam=exam;
}
private void setAnswer(string answers)
{
if(answers.Trim().Length<=0)
{
return;
}
string[] titAnswers=answers.Split(new char[]{','});
clbAnwser.ClearSelected();
for(int i=0;i<titAnswers.Length;i++)
{
char ans=titAnswers[i][0];
int selIndex=(int)(ans-'A');
clbAnwser.SetItemCheckState(selIndex,CheckState.Checked);
}
}
private void fillTitleInfo(int index)
{
DataRow dr=dsTitle.Tables[0].Rows[index];
this.rtbTitle.Text=dr["TopicDetil"].ToString();
int answers=(int)dr["Anwsers"];
clbAnwser.Items.Clear();
for(int i=0;i<answers;i++)
{
clbAnwser.Items.Add((char)('A'+i));
}
setAnswer(dr["myAnswer"].ToString());
}
private DataSet getTopicID()
{
DataSet ds=new DataSet();
TopicsFac topic=new TopicsFac();
if(curExam.ExamCate>0)
{
ds=topic.selectTopicID(curExam.ExamID,"",-1,-1,"",SearchBooleans.NULL);
}
else
{
ds=topic.selectTopicID(curExam.ExamClass,"",-1);
}
return ds;
}
/// <summary>
/// 把筛选出来的题目填进ArrayList里
/// </summary>
/// <param name="dv">筛选的DataView</param>
/// <param name="level">难度</param>
/// <param name="count">题目数量</param>
/// <param name="titIDList">要填进的ArrayList</param>
private void filter(DataView dv,int level,int count,ArrayList titIDList)
{
dv.RowFilter="TopicLevel="+level.ToString();
Random rnd=new Random(DateTime.Now.Hour*100+DateTime.Now.Second*10+DateTime.Now.Millisecond);
for(int i=0;i<count;i++)
{
int index=rnd.Next(0,dv.Count);
titIDList.Add(dv[index]["TopicID"]);
dv.Delete(index);
if(dv.Count<=0)
{
break;
}
}
}
private ArrayList filterTopicID()
{
DataView dvTopic=getTopicID().Tables[0].DefaultView;
string[] tits=curExam.ExamTitles.Split(new char[]{','});
int[] tit=new int[tits.Length];
ArrayList titIDList=new ArrayList();
for(int i=0;i<tits.Length;i++)
{
tit[i]=Convert.ToInt32(tits[i]);
filter(dvTopic,i+1,tit[i],titIDList);
}
return titIDList;
}
private void fillList()
{
DataTable dt=dsTitle.Tables[0].Copy();
dt.Columns.RemoveAt(5);
dt.Columns.RemoveAt(4);
dt.Columns.RemoveAt(3);
dt.Columns.RemoveAt(2);
dt.Columns.RemoveAt(0);
dlvTitles.BindTable=dt;
dlvTitles.Columns[1].Text="题目";
dlvTitles.Columns[2].Text="答案";
dlvTitles.AutoColumnsWidth=true;
}
private ArrayList getAnswer()
{
ArrayList list=new ArrayList();
for(int i=0;i<clbAnwser.CheckedItems.Count;i++)
{
list.Add(clbAnwser.CheckedItems[i].ToString());
}
return list;
}
private bool insertInfo()
{
if(curExam.ExamID<=0)
{
return true;
}
ResultFac resFac=new ResultFac();
return resFac.insertResult(CommVal.CurrentStu.StuID,this.curExam.ExamID,-1,"");
//resFac.insertResult
}
private void updateResult(string res,double sorce)
{
ResultFac resFac=new ResultFac();
DataSet ds=resFac.getResult(-1,CommVal.CurrentStu.StuID,this.curExam.ExamID,-1,"");
int id=(int)ds.Tables[0].Rows[0]["ResultID"];
if(id>=0)
{
resFac.updateResult(id,-1,-1,sorce,res);
}
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.panel3 = new System.Windows.Forms.Panel();
this.btnNext = new System.Windows.Forms.Button();
this.btnBack = new System.Windows.Forms.Button();
this.panel6 = new System.Windows.Forms.Panel();
this.btnEnd = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.dlvTitles = new ExamSystem.Common.DataListView();
this.panel2 = new System.Windows.Forms.Panel();
this.panel7 = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
this.rtbTitle = new System.Windows.Forms.RichTextBox();
this.panel5 = new System.Windows.Forms.Panel();
this.labTime = new System.Windows.Forms.Label();
this.lblTopic = new System.Windows.Forms.Label();
this.panel8 = new System.Windows.Forms.Panel();
this.clbAnwser = new System.Windows.Forms.CheckedListBox();
this.lblAnswer = new System.Windows.Forms.Label();
this.timerExam = new System.Windows.Forms.Timer(this.components);
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel3.SuspendLayout();
this.panel6.SuspendLayout();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.panel7.SuspendLayout();
this.panel4.SuspendLayout();
this.panel5.SuspendLayout();
this.panel8.SuspendLayout();
this.SuspendLayout();
//
// panel3
//
this.panel3.Controls.Add(this.btnNext);
this.panel3.Controls.Add(this.btnBack);
this.panel3.Controls.Add(this.panel6);
this.panel3.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel3.Location = new System.Drawing.Point(0, 325);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(600, 48);
this.panel3.TabIndex = 20;
//
// btnNext
//
this.btnNext.Location = new System.Drawing.Point(106, 14);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(80, 24);
this.btnNext.TabIndex = 31;
this.btnNext.Text = "下一题>>";
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
//
// btnBack
//
this.btnBack.Location = new System.Drawing.Point(14, 14);
this.btnBack.Name = "btnBack";
this.btnBack.Size = new System.Drawing.Size(80, 24);
this.btnBack.TabIndex = 30;
this.btnBack.Text = "<<上一题";
this.btnBack.Click += new System.EventHandler(this.btnBack_Click);
//
// panel6
//
this.panel6.Controls.Add(this.btnEnd);
this.panel6.Dock = System.Windows.Forms.DockStyle.Right;
this.panel6.Location = new System.Drawing.Point(488, 0);
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(112, 48);
this.panel6.TabIndex = 1;
//
// btnEnd
//
this.btnEnd.Location = new System.Drawing.Point(26, 14);
this.btnEnd.Name = "btnEnd";
this.btnEnd.Size = new System.Drawing.Size(64, 24);
this.btnEnd.TabIndex = 2;
this.btnEnd.Text = "交卷";
this.btnEnd.Click += new System.EventHandler(this.btnEnd_Click);
//
// panel1
//
this.panel1.Controls.Add(this.dlvTitles);
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(138, 325);
this.panel1.TabIndex = 21;
//
// dlvTitles
//
this.dlvTitles.AutoColumnsWidth = false;
this.dlvTitles.BindTable = null;
this.dlvTitles.ColumnsWidth = 100;
this.dlvTitles.Dock = System.Windows.Forms.DockStyle.Fill;
this.dlvTitles.FullRowSelect = true;
this.dlvTitles.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.dlvTitles.LineNumWidth = 30;
this.dlvTitles.Location = new System.Drawing.Point(0, 0);
this.dlvTitles.MultiSelect = false;
this.dlvTitles.Name = "dlvTitles";
this.dlvTitles.SelectedColor = System.Drawing.Color.MediumBlue;
this.dlvTitles.Size = new System.Drawing.Size(138, 325);
this.dlvTitles.TabIndex = 0;
this.dlvTitles.View = System.Windows.Forms.View.Details;
this.dlvTitles.SelectedIndexChanged += new System.EventHandler(this.dlvTitles_SelectedIndexChanged);
//
// panel2
//
this.panel2.Controls.Add(this.panel7);
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(138, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(462, 325);
this.panel2.TabIndex = 22;
//
// panel7
//
this.panel7.Controls.Add(this.panel4);
this.panel7.Controls.Add(this.panel5);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -