guanliyuan.cs

来自「我做的题库管理系统。大家看看吧」· CS 代码 · 共 647 行 · 第 1/2 页

CS
647
字号
			// 
			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.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.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.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.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(568, 366);
			this.Controls.Add(this.txtda);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label7);
			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);
			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="";
			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());
			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+"";
			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());
			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);
			string timu=txttimu.Text;
			string A=txtA.Text;
			string B=txtB.Text;
			string C=txtC.Text;
			string D=txtD.Text;
			string da=txtda.Text;
			string sqlstring =@"update [题目表] set 题目='"+timu+"',A='"+A+"',B='"+B+"',C='"+C+"',D='"+D+"',答案='"+da+"' 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();
				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;
			string A=txtA.Text;
			string B=txtB.Text;
			string C=txtC.Text;
			string D=txtD.Text;
			string da=txtda.Text;
			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();
				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);
			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();
				MessageBox.Show("恭喜你,删除成功!");


			}
			catch(Exception ex)
			{
				MessageBox.Show("删除时,出错的原因:\n"+ex.Message+"\n");
			}
			conn.Close();
		}

		private void butfirst_Click(object sender, System.EventArgs e)
		{
			this.conn=new OleDbConnection();//连接数据库
			conn.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb ";//连接数据库score表
			string sqlstring="Select *  From 题目表 where 题号=1";//显示题号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());
			conn.Close(); //关闭数据库
		}

		private void butup_Click(object sender, System.EventArgs e)
		{
			int tihao=Int32.Parse(txttihao.Text); //题号
		
			if(tihao!=1)// 判断题号是否为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("这是最后一题"+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 ";//连接数据库score表
			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);//调用loandata的方法
		}

		private void butexit_Click(object sender, System.EventArgs e)
		{
			this.Close();//关闭窗体
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?