【年少的风】C#小学生算式×××2
测试面板对应的代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace BriansApplication1
{
public partial class TestPaper : Form
{
int nTest = 0;
int NTEST = 0;
int page = -1;
int count = 0;
string id = null;
Login login = new Login();
int flagcount = 0;
int[] key = new int[1000];
string keys = null;
string question = null;
string answer = null;
Register register = new Register();
public TestPaper()
{
InitializeComponent();
}
public TestPaper(string id)
{
InitializeComponent();
this.id = id;
}
public void TestPaper_Load(object sender, EventArgs e)
{
#region label处理
Label[] label = new Label[10];
label[0] = label1;
label[1] = label2;
label[2] = label3;
label[3] = label4;
label[4] = label5;
label[5] = label6;
label[6] = label7;
label[7] = label8;
label[8] = label9;
label[9] = label10;
for (int i = 0; i < 10; i++)
{
label[i].Visible = false;
}
TextBox[] testbox = new TextBox[10];
testbox[0] = textBox1;
testbox[1] = textBox2;
testbox[2] = textBox3;
testbox[3] = textBox4;
testbox[4] = textBox5;
testbox[5] = textBox6;
testbox[6] = textBox7;
testbox[7] = textBox8;
testbox[8] = textBox9;
testbox[9] = textBox10;
for (int i = 0; i < 10; i++)
{
testbox[i].Visible = false;
}
#endregion
// MessageBox.Show("login.tbID.Text:" + id);
}
static int GetRandomSeed()
{
byte[] bytes = new byte[4];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(bytes);
return BitConverter.ToInt32(bytes, 0);
}
private void btExit_Click(object sender, EventArgs e)
{
#region label处理
Label[] label = new Label[10];
label[0] = label1;
label[1] = label2;
label[2] = label3;
label[3] = label4;
label[4] = label5;
label[5] = label6;
label[6] = label7;
label[7] = label8;
label[8] = label9;
label[9] = label10;
TextBox[] testbox = new TextBox[10];
testbox[0] = textBox1;
testbox[1] = textBox2;
testbox[2] = textBox3;
testbox[3] = textBox4;
testbox[4] = textBox5;
testbox[5] = textBox6;
testbox[6] = textBox7;
testbox[7] = textBox8;
testbox[8] = textBox9;
testbox[9] = textBox10;
#endregion
if (page >= 0)
{
for (int i = 0; i < 10 && i < nTest; i++)
{
answer += testbox[i].Text + "#";
}
MessageBox.Show(answer);
}
string mysqltest, mystr;
SqlConnection myconn = new SqlConnection();
SqlCommand mycmd = new SqlCommand();
mystr = "Data Source=.\\SQLEXPRESS;Initial Catalog=Student;Integrated Security=True";
myconn.ConnectionString = mystr;
myconn.Open();
mysqltest = string.Format("update student set answer='{0}' where id='{1}'", answer, id);
mycmd.CommandText = mysqltest;
mycmd.Connection = myconn;
try
{
mycmd.ExecuteReader();
}
catch
{
MessageBox.Show("插入失败1");
}
myconn.Close();
this.Dispose();
}
private void btPageDown_Click(object sender, EventArgs e)
{
#region label处理
Label[] label = new Label[10];
label[0] = label1;
label[1] = label2;
label[2] = label3;
label[3] = label4;
label[4] = label5;
label[5] = label6;
label[6] = label7;
label[7] = label8;
label[8] = label9;
label[9] = label10;
for (int i = 0; i < 10; i++)
{
label[i].Visible = false;
}
TextBox[] testbox = new TextBox[10];
testbox[0] = textBox1;
testbox[1] = textBox2;
testbox[2] = textBox3;
testbox[3] = textBox4;
testbox[4] = textBox5;
testbox[5] = textBox6;
testbox[6] = textBox7;
testbox[7] = textBox8;
testbox[8] = textBox9;
testbox[9] = textBox10;
for (int i = 0; i < 10; i++)
{
testbox[i].Visible = false;
}
#endregion
flagcount++;
nTest -= 10;
if (page >= 0)
{
for (int i = 0; i < 10 && i < nTest; i++)
{
answer += testbox[i].Text + "#";
}
MessageBox.Show(answer);
}
page++;
for (int i = 0; i < 10 && i < nTest; i++)
{
if (page == 0)
{
this.btPageUp.Enabled = false;
}
else
{
this.btPageUp.Enabled = true;
}
label[i].Visible = true;
testbox[i].Visible = true;
if (nTest < 10)
{
this.btPageDown.Enabled = false;
}
else
{
this.btPageDown.Enabled = true;
}
}
string testback = null;
string answerback = null;
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
string str = "Data Source=.\\SQLEXPRESS;Initial Catalog=Student;Integrated Security=True";
conn.ConnectionString = str;
conn.Open();
string temp = string.Format("select test from student where id='{0}'", id);
cmd.CommandText = temp;
cmd.Connection = conn;
try
{
SqlDataReader read1 = cmd.ExecuteReader();
// SqlDataReader read2 = cmd.ExecuteReader();
while (read1.Read())
{
try
{
testback += read1.GetString(0);
// answerback += read2.GetString(0);
}
catch
{
MessageBox.Show("CHUCUOWU 1");
}
}
}
catch (SqlException ea)
{
MessageBox.Show(ea.Message);
}
conn.Close();
MessageBox.Show("testback:" + testback);
conn.Open();
temp = string.Format("select answer from student where id='{0}'", id);
cmd.CommandText = temp;
cmd.Connection = conn;
try
{
//SqlDataReader read1 = cmd.ExecuteReader();
SqlDataReader read2 = cmd.ExecuteReader();
while (read2.Read())
{
try
{
//testback += read1.GetString(0);
answerback += read2.GetString(0);
}
catch
{
MessageBox.Show("CHUCUOWU 2");
}
}
}
catch (SqlException ea)
{
MessageBox.Show(ea.Message);
}
conn.Close();
try
{
string[] questionback = testback.Split('#');
string[] answer1 = answerback.Split('#');
for (int i = 1; i <= 10 && i <= nTest; i++)
{
count = page * 10 + i;
MessageBox.Show(count.ToString() + nTest.ToString() + i.ToString() + page.ToString());
label[i - 1].Text = count.ToString() + "、" + questionback[count-1];
testbox[i - 1].Text = answer1[count - 1];
}
}
catch
{
MessageBox.Show("answerback:" + answerback);
MessageBox.Show(count.ToString() + nTest.ToString() + page.ToString());
}
}
private void btCreate_Click(object sender, EventArgs e)
{
//this.btCreate.Enabled = false;
try
{
nTest = Convert.ToInt32(tbCount.Text);
NTEST = nTest;
nTest += 10;
lbAmount.Text = tbCount.Text;
}
catch
{
MessageBox.Show("请正确输入试题数量!");
return;
}
#region 生产试题
string[] str = new string[NTEST];
int[] countTest = new int[NTEST];
for (int i = 0; i < NTEST; i++)
{
countTest[i] = new Random(GetRandomSeed()).Next(2, 5);
}
for (int k = 0; k < NTEST; k++)
{
int[] num = new int[countTest[k]];
char[] ops = new char[countTest[k] - 1];
for (int i = 0; i < countTest[k]; i++)
{
num[i] = new Random(GetRandomSeed()).Next(1, 100);
}
for (int i = 0; i < countTest[k] - 1; i++)
{
int a = new Random(GetRandomSeed()).Next(1, 100);
switch (a % 4)
{
case 0: ops[i] = '+'; break;
case 1: ops[i] = '-'; break;
case 2: ops[i] = '*'; break;
case 3: ops[i] = '/';break;
default: ops[i] = '+'; break;
}
}
for (int i = 0; i < countTest[k] - 1; i++)
{
str[k] += num[i].ToString() + ops[i];
}
str[k] =str[k] + num[countTest[k] - 1];
question += str[k] + "#";
key[k] = Calculate(str[k]);
keys += key[k] + "#";
}
#endregion
// MessageBox.Show(question);
#region 存入数据库
string mysqltest, mystr;
SqlConnection myconn = new SqlConnection();
SqlCommand mycmd = new SqlCommand();
mystr = "Data Source=.\\SQLEXPRESS;Initial Catalog=Student;Integrated Security=True";
myconn.ConnectionString = mystr;
myconn.Open();
mysqltest = string.Format("update student set test='{0}',testcount='{1}',result='{2}' where id='{3}'", question, NTEST ,keys,ToString(), id);
mycmd.CommandText = mysqltest;
mycmd.Connection = myconn;
try
{
mycmd.ExecuteReader();
}
catch
{
MessageBox.Show("插入失败0");
}
myconn.Close();
#endregion
btPageDown_Click(sender, e);
}
private void btPageUp_Click(object sender, EventArgs e)
{
#region lable处理
Label[] label = new Label[10];
label[0] = label1;
label[1] = label2;
label[2] = label3;
label[3] = label4;
label[4] = label5;
label[5] = label6;
label[6] = label7;
label[7] = label8;
label[8] = label9;
label[9] = label10;
for (int i = 0; i < 10; i++)
{
label[i].Visible = false;
}
TextBox[] testbox = new TextBox[10];
testbox[0] = textBox1;
testbox[1] = textBox2;
testbox[2] = textBox3;
testbox[3] = textBox4;
testbox[4] = textBox5;
testbox[5] = textBox6;
testbox[6] = textBox7;
testbox[7] = textBox8;
testbox[8] = textBox9;
testbox[9] = textBox10;
for (int i = 0; i < 10; i++)
{
testbox[i].Visible = false;
}
#endregion
page--;
nTest += 10;
for (int i = 0; i < 10 && i <= nTest; i++)
{
if (page == 0)
{
this.btPageUp.Enabled = false;
}
else
{
this.btPageUp.Enabled = true;
}
label[i].Visible = true;
testbox[i].Visible = true;
if (nTest < 10)
{
this.btPageDown.Enabled = false;
}
else
{
this.btPageDown.Enabled = true;
}
}
string testback = null;
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
string str = "Data Source=.\\SQLEXPRESS;Initial Catalog=Student;Integrated Security=True";
conn.ConnectionString = str;
conn.Open();
string temp = string.Format("select test from student where id='{0}'", id);
cmd.CommandText = temp;
cmd.Connection = conn;
try
{
SqlDataReader read = cmd.ExecuteReader();
while (read.Read())
{
testback += read.GetString(0);
}
}
catch(SqlException ea)
{
MessageBox.Show(ea.Message);
}
string[] questionback = testback.Split('#');
for (int i = 1; i <= 10; i++)
{
count = page * 10 + i;
label[i - 1].Text = count.ToString() + "、" + questionback[count-1];
}
}
private void btCurrent_Click(object sender, EventArgs e)
{
}
private void btContinue_Click(object sender, EventArgs e)
{
tbCount.Enabled = false;
SqlConnection myconn = new SqlConnection();
SqlCommand mycmd = new SqlCommand();
string mystr = "Data Source=.\\SQLEXPRESS;Initial Catalog=Student;Integrated Security=True";
myconn.ConnectionString = mystr;
myconn.Open();
string mysqltest = string.Format("select testcount from student where id='{0}'",id);
mycmd.CommandText = mysqltest;
mycmd.Connection = myconn;
try
{
SqlDataReader read = mycmd.ExecuteReader();
while (read.Read())
{
nTest = read.GetInt32(0) + 10;
NTEST = nTest;
lbAmount.Text = (nTest - 10).ToString();
}
}
catch
{
MessageBox.Show("获取失败");
}
myconn.Close();
btPageDown_Click(sender, e);
}
static int Calculate(string Expression)
{
List<int> numList = new List<int>();//运算数字列表
List<char> OperatorList = new List<char>();//运行符列表
bool numState = true;//true:表示刚遇到符号
int num = 0;
char[] expression = Expression.ToCharArray();
for (int i = 0; i < expression.Length; i++)
{
if (Convert.ToInt16(expression[i]) > 58 || Convert.ToInt16(expression[i]) < 48)
{
switch (expression[i])
{
case '+':
numState = true;
numList.Add(num);
break;
case '-':
numState = true;
numList.Add(num);
break;
case '*':
numState = true;
numList.Add(num);
break;
case '/':
numState = true;
numList.Add(num);
break;
default: throw new Exception("表达式不正确,含有未知字符!");
}
OperatorList.Add(expression[i]);
}
else if (numState)
{
num = Convert.ToInt16(expression[i].ToString());
if (i == expression.Length - 1)
numList.Add(num);
numState = false;
}
else
{
num *= 10; num += Convert.ToInt16(expression[i].ToString());
if (i == expression.Length - 1)
numList.Add(num);
}
}
return getResults(numList, OperatorList);
}
static int getResults(List<int> numList, List<char> OperatorList)
{
if (numList.Count == 1)
return numList[0];
List<int> numList1 = new List<int>();
numList1.Add(numList[0]);
List<char> OperatorList1 = new List<char>();
for (int i = 0; i < OperatorList.Count; i++)
{
if (OperatorList[i] == '+' || OperatorList[i] == '-')
{
numList1.Add(numList[i + 1]);
OperatorList1.Add(OperatorList[i]);
}
else if (OperatorList[i] == '*')
{
numList1[numList1.Count - 1] *= numList[i + 1];
}
else if (OperatorList[i] == '/')
{
if (numList[i + 1] != 0)
{
numList1[numList1.Count - 1] /= numList[i + 1];
}
else
break;
}
}
int results = numList1[0];
for (int i = 0; i < OperatorList1.Count; i++)
{
if (OperatorList1[i] == '+')
results += numList1[i + 1];
else results -= numList1[i + 1];
}
return results;
}
}
}
转载于:https://blog.51cto.com/huamm/1049979
【年少的风】C#小学生算式×××2相关推荐
- 【年少的风】C#小学生算式自动生成器1
本软件基于C#,SQL Server,功能,用户注册,登录,输入希望生成试题的总数n点击"生成试题"按钮便可随机生成n道加减乘除的算式.答题过程总可点击"当前得分&quo ...
- 【年少的风】猜数小游戏
import javax.swing.JOptionPane; public class GuessNumber{ public static void main (String args[ ]) { ...
- NYOJ 27 大数阶乘
大数阶乘 时间限制:3000ms | 内存限制:65535KB 难度:3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数m(0< ...
- android 代码发adb,Android预安装软件adb命令编译源码
Android预安装软件&adb命令&编译源码 发布时间:2020-06-02 17:28:41 来源:51CTO 阅读:895 作者:年少的风 1.预安装软件: 将eclipse下的 ...
- EasyClick adb shell命令大全
EasyClick adb.shell命令大全目录 EasyClick adb.shell命令大全 ADB包安装步骤 使用教程 ADB高级命令 Android 常用的Linux命令 Android a ...
- 校园助手APP--简介及框架
最近没有怎么编码,就把断断续续做了半年的毕业设计拿出来回顾一下. 校园助手,分为服务器端与Android客户端,在此主要介绍客户端,服务器是一位大神用node.js写的. 主要实现的功能有:登陆,信息 ...
- 校园助手APP--登陆
延续大学时做课程设计的思路,首先就是登陆 当然,在登陆之前还是有其他界面的,比如第一次登陆时会有欢迎导航界面,,启动应用时会显示logo界面.下一篇再介绍. logo界面结束之后会进入登陆界面,当然, ...
- 口算助手--家长好帮手
email:imashufflez@gmx.de 口算助手自动生成,小学生算式. 可以打印出来当成作业来做. 省去了动脑筋编写题目的时间. 拯救了大量脑细胞.
- python输入随机的口算算式_小学生家长的福利来啦--利用EXCEL随机生成口算题目...
原标题:小学生家长的福利来啦--利用EXCEL随机生成口算题目 刚上一年级或者二年级的家长都会有这样的一个纠结:数学老师布置作业,要求家长给小孩出口算题目,并批阅.辛辛苦苦想了好久,总算把题目出完了, ...
最新文章
- R语言回归模型构建、回归模型基本假设(正态性、线性、独立性、方差齐性)、回归模型诊断、car包诊断回归模型、特殊观察样本分析、数据变换、模型比较、特征筛选、交叉验证、预测变量相对重要度
- 批量ping工具fping
- BindingException: Invalid bound statement (not found)问题排查:SpringBoot集成Mybatis重点分析...
- python中for循环语句格式_Python基础-10循环语句
- LevelDB 源码剖析(六)WAL模块:LOG 结构、读写流程、崩溃恢复
- oracle insert两个关联表
- goland环境配置_Goland辅助工具goimports和gomodules
- Impala查询 - HDFS缓存数据
- 什么是传感器? 传感器由哪几部分组成? 传感器分类?
- 【转】Google Maps Android API V2的使用及问题解决
- 看《墨攻》理解IoC—Spring底层核心
- 21. Magento 创建新闻模块(2)
- 某LINUX平台,管道open直接崩溃
- bp神经网络matlab feedfollownet,BP神经网络模型:Matlab
- LaTex制作中文简历模板_PART 1
- 内网地址(私有地址、私有IP地址空间)
- bzoj 3991 [SDOI2015]寻宝游戏
- nodejs addon
- (转)XShell的安装和使用
- .Net中Web增加加密狗管理
热门文章
- 剖析printf函数
- HTML如何做个播放器图表,Web绘图神器之ECharts-ts文件播放器
- word2003如何设置护眼模式_ERP系统上线,如何设置采购收货的模式,提升企业的采购效率...
- 关联式容器(map,set,multimap,multiset)
- C++笔记:select多路复用机制
- 通过编程解决问题的正确思路
- Linux 内核网络协议栈 ------sk_buff 结构体 以及 完全解释 (2.6.16)
- Python内置数据类型之Dict
- 熬夜肝完这份Framework笔记,已拿到offer
- JAVA List集合转Page(分页对象)