【年少的风】C#小学生算式自动生成器1

来源:互联网 发布:小学文化伪装硕士知乎 编辑:程序博客网 时间:2024/04/30 05:19

本软件基于C#,SQL Server,功能,用户注册,登录,输入希望生成试题的总数n点击“生成试题”按钮便可随机生成n道加减乘除的算式。答题过程总可点击“当前得分”查看已答题目是否正确。中途可退出。下次登录后点击“继续答题”按钮便可继续上次的答题。

注册面板对应的代码如下:

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8.  
  9. using System.Data.SqlClient;  
  10.  
  11. namespace BriansApplication1  
  12. {  
  13.     public partial class Register : Form  
  14.     {  
  15.         public Register()  
  16.         {  
  17.             InitializeComponent();  
  18.         }  
  19.  
  20.         private void tbROK_Click(object sender, EventArgs e)  
  21.         {  
  22.             string mysql, mystr;  
  23.             SqlConnection myconn = new SqlConnection();  
  24.             SqlCommand mycmd = new SqlCommand();  
  25.             mystr = "Data Source=.\\SQLEXPRESS;Initial Catalog=Student;Integrated Security=True";  
  26.             myconn.ConnectionString = mystr;  
  27.             myconn.Open();  
  28.  
  29.             mysql = string.Format("insert into student ([id],[name]) values('" +  tbRID.Text + "','" + tbRName.Text + "') ");  
  30.  
  31.             mycmd.CommandText = mysql;  
  32.             mycmd.Connection = myconn;  
  33.  
  34.                 SqlDataReader myreader = mycmd.ExecuteReader();  
  35.                 if (!myreader.Read())  
  36.                 {  
  37.                     MessageBox.Show("注册成功!");  
  38.                 }  
  39.                 else 
  40.                 {  
  41.                     MessageBox.Show("注册失败,再次尝试!");  
  42.                 }  
  43.           
  44.               
  45.  
  46.               
  47.             myconn.Close();  
  48.  
  49.             Login login = new Login();  
  50.             login.tbID.Text = this.tbRID.Text;  
  51.             login.tbName.Text = this.tbRName.Text;  
  52.             login.Show();  
  53.  
  54.             this.Dispose();  
  55.         }  
  56.  
  57.         private void Register_Load(object sender, EventArgs e)  
  58.         {  
  59.  
  60.         }  
  61.  
  62.         private void btRCancel_Click(object sender, EventArgs e)  
  63.         {  
  64.             this.Dispose();  
  65.             Login login = new Login();  
  66.             login.Visible = true;  
  67.               
  68.         }  
  69.     }  

登录界面对应的代码如下:

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. using System.Threading;  
  9.  
  10. using System.Data.SqlClient;  
  11. using System.Data.OleDb;  
  12.  
  13. namespace BriansApplication1  
  14. {  
  15.     public partial class Login : Form  
  16.     {  
  17.        
  18.         public Login()  
  19.         {  
  20.             InitializeComponent();  
  21.         }  
  22.  
  23.         private void btLogin_Click(object sender, EventArgs e)  
  24.         {  
  25.  
  26.             if (tbID.Text == "")  
  27.             {  
  28.                 MessageBox.Show("学号不能为空,请再次输入!");  
  29.             }  
  30.             else if (tbName.Text == "")  
  31.             {  
  32.                 MessageBox.Show("密码不能为空,请再次输入!");  
  33.             }  
  34.             else 
  35.             {  
  36.                 string mysql, mystr;  
  37.                 SqlConnection myconn = new SqlConnection();  
  38.                 SqlCommand mycmd = new SqlCommand();  
  39.                 mystr = "Data Source=.\\SQLEXPRESS;Initial Catalog=Student;Integrated Security=True";  
  40.                 myconn.ConnectionString = mystr;  
  41.                 myconn.Open();  
  42.                 mysql = string.Format("select test from student where student.id='{0}' and student.name='{1}'", tbID.Text.Trim(), tbName.Text.Trim());  
  43.                 mycmd.CommandText = mysql;  
  44.                 mycmd.Connection = myconn;  
  45.                 SqlDataReader myreader = mycmd.ExecuteReader();  
  46.                 if (myreader.Read())  
  47.                 {  
  48.                     TestPaper test = new TestPaper(tbID.Text);  
  49.                     try 
  50.                     {  
  51.                         string temp = myreader.GetString(0);  
  52.                         if(temp != null)  
  53.                         {  
  54.                             test.btCreate.Hide();  
  55.                             test.tbCount.Enabled = false;  
  56.                         }  
  57.                     }  
  58.                     catch 
  59.                     {  
  60.                         test.btContinue.Hide();  
  61.                     }  
  62.                       
  63.                     test.Show();  
  64.                 }  
  65.                 else 
  66.                 {  
  67.                     MessageBox.Show("用户不存在,请注册!");  
  68.                 }  
  69.                 myreader.Close();  
  70.                 myconn.Close();  
  71.             }  
  72.               
  73.  
  74.         }  
  75.  
  76.         private void btClose_Click(object sender, EventArgs e)  
  77.         {  
  78.             Application.Exit();  
  79.         }  
  80.  
  81.         private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)//注册  
  82.         {  
  83.               
  84.             this.Visible = false;  
  85.             Register register = new Register();  
  86.             register.Show();  
  87.  
  88.               
  89.         }  
  90.         private void Form1_Load(object sender, EventArgs e)  
  91.         {  
  92.         }  
  93.     }  

 

本文出自 “年少的风” 博客,请务必保留此出处http://huamm.blog.51cto.com/5646020/1049977

0 0