📄 guanliyuan.cs
字号:
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label10
//
this.label10.Location = new System.Drawing.Point(16, 32);
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;
//
// label11
//
this.label11.Location = new System.Drawing.Point(16, 88);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(24, 23);
this.label11.TabIndex = 35;
this.label11.Text = "D";
this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label12
//
this.label12.Location = new System.Drawing.Point(16, 56);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(24, 23);
this.label12.TabIndex = 34;
this.label12.Text = "C";
this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// butoutput
//
this.butoutput.BackColor = System.Drawing.Color.Transparent;
this.butoutput.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.butoutput.ForeColor = System.Drawing.Color.Yellow;
this.butoutput.Location = new System.Drawing.Point(480, 91);
this.butoutput.Name = "butoutput";
this.butoutput.Size = new System.Drawing.Size(80, 26);
this.butoutput.TabIndex = 39;
this.butoutput.Text = "显示题目";
this.butoutput.Click += new System.EventHandler(this.butoutput_Click);
//
// butdelete
//
this.butdelete.BackColor = System.Drawing.Color.Transparent;
this.butdelete.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.butdelete.ForeColor = System.Drawing.Color.Yellow;
this.butdelete.Location = new System.Drawing.Point(480, 259);
this.butdelete.Name = "butdelete";
this.butdelete.Size = new System.Drawing.Size(80, 26);
this.butdelete.TabIndex = 38;
this.butdelete.Text = "删除题目";
this.butdelete.Click += new System.EventHandler(this.butdelete_Click);
//
// butinsert
//
this.butinsert.BackColor = System.Drawing.Color.Transparent;
this.butinsert.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.butinsert.ForeColor = System.Drawing.Color.Yellow;
this.butinsert.Location = new System.Drawing.Point(480, 203);
this.butinsert.Name = "butinsert";
this.butinsert.Size = new System.Drawing.Size(80, 26);
this.butinsert.TabIndex = 37;
this.butinsert.Text = "插入题目";
this.butinsert.Click += new System.EventHandler(this.butinsert_Click);
//
// butuptade
//
this.butuptade.BackColor = System.Drawing.Color.Transparent;
this.butuptade.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.butuptade.ForeColor = System.Drawing.Color.Yellow;
this.butuptade.Location = new System.Drawing.Point(480, 147);
this.butuptade.Name = "butuptade";
this.butuptade.Size = new System.Drawing.Size(80, 26);
this.butuptade.TabIndex = 36;
this.butuptade.Text = "更新题目";
this.butuptade.Click += new System.EventHandler(this.butuptade_Click);
//
// guanliyuan
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.Control;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(576, 374);
this.Controls.Add(this.txtda);
this.Controls.Add(this.label6);
this.Controls.Add(this.label7);
this.Controls.Add(this.label2);
this.Controls.Add(this.txttihao);
this.Controls.Add(this.label1);
this.Controls.Add(this.butexit);
this.Controls.Add(this.butend);
this.Controls.Add(this.butnext);
this.Controls.Add(this.butup);
this.Controls.Add(this.butfirst);
this.Controls.Add(this.txtD);
this.Controls.Add(this.txtC);
this.Controls.Add(this.txtB);
this.Controls.Add(this.txtA);
this.Controls.Add(this.txttimu);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.butoutput);
this.Controls.Add(this.butdelete);
this.Controls.Add(this.butinsert);
this.Controls.Add(this.butuptade);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "guanliyuan";
this.Text = "试题管理系统";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//显示代码
private void loandata()//方法
{
int tihao=Int32.Parse(txttihao.Text);//强自变换为等效的32位数
this.conn=new OleDbConnection();//是否是打开的
conn.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ";//连接表
string sqlstring="Select * From 题目表 where 题号="+tihao+"";//SQL语句来约束题号
this.comm=new OleDbCommand(sqlstring,conn);//数据库识别器
conn.Open();//打开数据库联接
OleDbDataReader dr=comm.ExecuteReader();//提供从数据源读取
dr.Read();//一条一条往下读
txttimu.Text="";//清空
txtA.Text="";//清空
txtB.Text="";//清空
txtC.Text="";//清空
txtD.Text="";//清空
txtda.Text="";//清空
txttimu.AppendText(dr["题目"].ToString());//显示在txttimu文本中
txtA.AppendText(dr["A"].ToString());//显示在txtA文本中
txtB.AppendText(dr["B"].ToString());//显示在txtB文本中
txtC.AppendText(dr["C"].ToString());//显示在txtC文本中
txtD.AppendText(dr["D"].ToString());//显示在txtD文本中
txtda.AppendText(dr["答案"].ToString());//显示在txtda文本中
conn.Close();
}
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+"";//SQL语句来约束题号
this.comm=new OleDbCommand(sqlstring,conn);//数据库识别器
conn.Open();//打开数据库联接
OleDbDataReader dr=comm.ExecuteReader();//提供从数据源读取
dr.Read();//一条一条往下读
txttimu.Text="";//清空
txtA.Text="";//清空
txtB.Text="";//清空
txtC.Text="";//清空
txtD.Text="";//清空
txtda.Text="";//清空
txttimu.AppendText(dr["题目"].ToString());//显示在txttimu文本中
txtA.AppendText(dr["A"].ToString());//显示在txtA文本中
txtB.AppendText(dr["B"].ToString());//显示在txtB文本中
txtC.AppendText(dr["C"].ToString());//显示在txtC文本中
txtD.AppendText(dr["D"].ToString());//显示在txtD文本中
txtda.AppendText(dr["答案"].ToString());//显示在txtta文本中
conn.Close();//关闭
}
private void butoutput_Click(object sender, System.EventArgs e)
{
loandata();//重载方法
}
//更新代码
private void butuptade_Click(object sender, System.EventArgs e)
{
int tihao=Int32.Parse(txttihao.Text);//强自变换为等效的32位数
string timu=txttimu.Text;//将它们一一对应
string A=txtA.Text;//显示对应在txtA文本中
string B=txtB.Text;//显示对应在txtB文本中
string C=txtC.Text;//显示对应在txtC文本中
string D=txtD.Text;//显示对应在txtD文本中
string da=txtda.Text;//显示对应在txtda文本中
string sqlstring =@"update [题目表] set 题目='"+timu+"',A='"+A+"',B='"+B+"',C='"+C+"',D='"+D+"',答案='"+da+"' where 题号="+tihao+"";//用SQL语句更新控自数据
this.conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ");//表示数据库联接的表
this.comm=new OleDbCommand(sqlstring,conn);//数据库识别器
conn.Open();//打开数据库联接
try
{
comm.ExecuteNonQuery();//执行SQL语句返回受影响的行数
MessageBox.Show("恭喜你,题目更新成功!");
}
catch(Exception ex)//执行程序时发生的错误
{
MessageBox.Show("更新时,出错的原因:\n"+ex.Message+"\n");
}
conn.Close();//关闭窗体
}
//插入代码
private void butinsert_Click(object sender, System.EventArgs e)
{
int tihao=0;//题号
string timu=txttimu.Text;//显示对应在txttimu文本中
string A=txtA.Text;//显示对应在txtA文本中
string B=txtB.Text;//显示对应在txtB文本中
string C=txtC.Text;//显示对应在txtC文本中
string D=txtD.Text;//显示对应在txtD文本中
string da=txtda.Text;//显示对应在txtda文本中
try
{//异常
tihao=int.Parse(txttihao.Text);
}
catch(System.FormatException)
{
MessageBox.Show("对不起,您输入的不是数字!");
return;//返回
}
string sqlstring =@"Insert into [题目表](题号,题目,A,B,C,D,答案) values(";
sqlstring +=""+tihao+",'"+timu+"','"+A+"','"+B+"','"+C+"','"+D+"','"+da+"')";//插入记录将它一一对应
this.conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ");//联接数据库的表
this.comm=new OleDbCommand(sqlstring,conn);//数据库识别器
conn.Open();//打开
try
{//异常处理
comm.ExecuteNonQuery();//执行SQL语句返回受影响的行数
MessageBox.Show("恭喜你,你的题目插入成功!");
}
catch(Exception ex)//执行程序时发生的错误
{
MessageBox.Show("插入出错!错误的原因:\n"+ex.Message+"\n");
}
conn.Close();//关闭
}
//删除代码
private void butdelete_Click(object sender, System.EventArgs e)
{
int tihao=Int32.Parse(txttihao.Text);//强自变换为等效的32位数
string sqlstring =@"delete from [题目表] where 题号="+tihao+"";//删除以题号
this.conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ");//联接数据库的表
this.comm=new OleDbCommand(sqlstring,conn);//数据库识别器
conn.Open();//打开
try
{//异常处理
comm.ExecuteNonQuery();//执行SQL语句返回受影响的行数
MessageBox.Show("恭喜你,删除成功!");
}
catch(Exception ex)//执行程序时发生的错误
{
MessageBox.Show("删除时,出错的原因:\n"+ex.Message+"\n");
}
conn.Close();//关闭
}
private void butfirst_Click(object sender, System.EventArgs e)
{
int tihao=1;
this.conn=new OleDbConnection();
conn.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ";
string sqlstring="Select * From 题目表 where 题号=1";
this.comm=new OleDbCommand(sqlstring,conn);
conn.Open();
OleDbDataReader dr=comm.ExecuteReader();
dr.Read();
txttimu.Text="";
txtA.Text="";
txtB.Text="";
txtC.Text="";
txtD.Text="";
txtda.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());
txtda.AppendText(dr["答案"].ToString());
txttihao.Text=tihao.ToString();
conn.Close();
}
private void butup_Click(object sender, System.EventArgs e)
{
int tihao=Int32.Parse(txttihao.Text);
if(tihao!=1)
{
tihao--;
loandata(tihao);
txttihao.Text=tihao.ToString();
}
else
{
MessageBox.Show("这已是第一题!");
}
}
private void butnext_Click(object sender, System.EventArgs e)
{
int tihao=Int32.Parse(txttihao.Text);
if(tihao!=399+tihao)
{
try
{
tihao++;
loandata(tihao);
txttihao.Text=tihao.ToString();
}
catch(Exception ex)
{
MessageBox.Show("错误的原因:\n"+ex.Message+"\n");
}
}
}
private void butend_Click(object sender, System.EventArgs e)
{
this.conn=new OleDbConnection();
conn.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ";
string sqlstring="Select count(*) as totalnum From 题目表" ;
this.comm=new OleDbCommand(sqlstring,conn);
conn.Open();
OleDbDataReader dr=comm.ExecuteReader();
dr.Read();
txttimu.Text="";
txtA.Text="";
txtB.Text="";
txtC.Text="";
txtD.Text="";
txtda.Text="";
int tihao=(int)(dr["totalnum"]);
conn.Close();
loandata(tihao);
txttihao.Text=tihao.ToString();
}
private void butexit_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -