📄 xuesheng.cs
字号:
this.label8.Text = "D";
this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label10
//
this.label10.BackColor = System.Drawing.Color.Transparent;
this.label10.Location = new System.Drawing.Point(16, 40);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(24, 23);
this.label10.TabIndex = 33;
this.label10.Text = "B";
this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txttihao
//
this.txttihao.BackColor = System.Drawing.Color.WhiteSmoke;
this.txttihao.Location = new System.Drawing.Point(8, 41);
this.txttihao.Name = "txttihao";
this.txttihao.ReadOnly = true;
this.txttihao.Size = new System.Drawing.Size(56, 21);
this.txttihao.TabIndex = 68;
this.txttihao.Text = "1";
//
// txttimu
//
this.txttimu.BackColor = System.Drawing.Color.WhiteSmoke;
this.txttimu.Location = new System.Drawing.Point(8, 67);
this.txttimu.Multiline = true;
this.txttimu.Name = "txttimu";
this.txttimu.ReadOnly = true;
this.txttimu.Size = new System.Drawing.Size(500, 80);
this.txttimu.TabIndex = 56;
this.txttimu.Text = "";
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Font = new System.Drawing.Font("楷体_GB2312", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(16, 11);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(492, 40);
this.label1.TabIndex = 67;
this.label1.Text = "安徽机电职业技术学院计算机一级模拟试题";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// butexit
//
this.butexit.BackColor = System.Drawing.Color.Transparent;
this.butexit.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.butexit.Location = new System.Drawing.Point(328, 320);
this.butexit.Name = "butexit";
this.butexit.Size = new System.Drawing.Size(72, 25);
this.butexit.TabIndex = 72;
this.butexit.Text = "提交试卷";
this.butexit.Click += new System.EventHandler(this.butexit_Click);
//
// buttimu
//
this.buttimu.BackColor = System.Drawing.Color.Transparent;
this.buttimu.Location = new System.Drawing.Point(16, 320);
this.buttimu.Name = "buttimu";
this.buttimu.TabIndex = 73;
this.buttimu.Text = "开始考试";
this.buttimu.Click += new System.EventHandler(this.buttimu_Click);
//
// xuesheng
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(520, 358);
this.Controls.Add(this.buttimu);
this.Controls.Add(this.butexit);
this.Controls.Add(this.butnext);
this.Controls.Add(this.butup);
this.Controls.Add(this.txtD);
this.Controls.Add(this.txtB);
this.Controls.Add(this.txtA);
this.Controls.Add(this.txtC);
this.Controls.Add(this.txtda);
this.Controls.Add(this.label6);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.txttihao);
this.Controls.Add(this.txttimu);
this.Controls.Add(this.label1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "xuesheng";
this.Text = "学生考试系统";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void loandata(int tihao)
{
this.conn=new OleDbConnection();
conn.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ";
string sqlstring="Select * From 题目表 where 题号="+tihao+"";
this.comm=new OleDbCommand(sqlstring,conn);
conn.Open();
OleDbDataReader dr=comm.ExecuteReader();
dr.Read();
txttimu.Text="";
txtA.Text="";
txtB.Text="";
txtC.Text="";
txtD.Text="";
txttimu.AppendText(dr["题目"].ToString());
txtA.AppendText(dr["A"].ToString());
txtB.AppendText(dr["B"].ToString());
txtC.AppendText(dr["C"].ToString());
txtD.AppendText(dr["D"].ToString());
conn.Close();
}
private void buttimu_Click(object sender, System.EventArgs e)
{
int tihao=Int32.Parse(txttihao.Text);
this.conn=new OleDbConnection();
conn.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ";
string sqlstring="Select * From 题目表 where 题号="+tihao+"";
this.comm=new OleDbCommand(sqlstring,conn);
conn.Open();
OleDbDataReader dr=comm.ExecuteReader();
dr.Read();
txttimu.Text="";
txtA.Text="";
txtB.Text="";
txtC.Text="";
txtD.Text="";
txttimu.AppendText(dr["题目"].ToString());
txtA.AppendText(dr["A"].ToString());
txtB.AppendText(dr["B"].ToString());
txtC.AppendText(dr["C"].ToString());
txtD.AppendText(dr["D"].ToString());
conn.Close();
}
private void butnext_Click(object sender, System.EventArgs e)
{
int tihao=Int32.Parse(txttihao.Text);
if(tihao!=20)
{
tihao++;
loandata(tihao);
txttihao.Text=tihao.ToString();
}
txtda.Text="";
}
private void butup_Click(object sender, System.EventArgs e)
{
int tihao=Int32.Parse(txttihao.Text);
if(tihao!=1)
{
tihao=tihao-1;
loandata(tihao);
txttihao.Text=tihao.ToString();
}
else
{
MessageBox.Show("这已是第一题!");
}
txtda.Text="";
}
private void butexit_Click(object sender, System.EventArgs e)
{
DialogResult result=MessageBox.Show("你真的要交试卷吗?","提交试卷",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
if(result==DialogResult.Yes)
{
DialogResult re=MessageBox.Show("恭喜你!这次考试的得分是:"+chengji.ToString(),"考试结果",MessageBoxButtons.YesNo);
if(re==DialogResult.Yes)
{
this.Close();
}
}
}
private void txtda_TextChanged(object sender, System.EventArgs e)
{
string xueshengda=txtda.Text;//学生答案
int tihao=Int32.Parse(txttihao.Text);//题号
string sqlstring =@"update [题目表] set 学生答案='"+xueshengda+"' where 题号="+tihao+"";//更新学生答案字段里面的内容
this.conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ");//连接数据库score表
sqlstring="Select * From 题目表 where 题号="+tihao+"";// 根据题号显示字段
this.comm=new OleDbCommand(sqlstring,conn);//数据识别器
conn.Open();//打开数据源
OleDbDataReader dr=comm.ExecuteReader();//重载数据源
dr.Read();//读出数据源的下一条记录
if(dr["学生答案"]==null)//判断表里面的学生答案字段是否为空
{
if(xueshengda==dr["答案"].ToString())//判断文本框里面的答案是否等于表里面答案字段
{//如果是加5分
chengji=chengji+5;
}
}
else
{//如果不是,就判断表里面的学生答案与答案不相等并且文本框里面的答案等于字段答案
if(dr["学生答案"].ToString()!=dr["答案"].ToString()&&xueshengda==dr["答案"].ToString())
{//如果是加5分
chengji=chengji+5;
}
else
{//如果不是减5分
chengji=chengji;
}
}
conn.Close(); //关闭数据源
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -