一、具体代码

Default2.aspx.cs

public partial class Chapter1_Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
int a = ;
private int t;
public static int Count=;
public static int right=;
protected void Button1_Click(object sender, EventArgs e)
{
int a = int.Parse(TextBox1.Text.Trim());
int b = int.Parse(TextBox3.Text.Trim());
Char c = Convert.ToChar(TextBox2.Text.Trim());
Lei con = new Lei();
con.Max(a, b, c);
if (con.Answer == int.Parse(TextBox4.Text.Trim()))
{
Label1.Text=("恭喜你,小朋友!回答正确!");
Label1.ForeColor=Color.Blue;
right++; } else
{ Label1.Text = ("回答错误,继续加油!小朋友");
Label1.ForeColor = Color.Red; } } protected void Button2_Click(object sender, EventArgs e)
{
Count++;
StreamWriter baocun1 = File.AppendText("C:\\baocun1.txt");
baocun1.WriteLine(TextBox1.Text);
baocun1.Close();
StreamWriter baocun2 = File.AppendText("C:\\baocun2.txt");
baocun2.WriteLine(TextBox2.Text);
baocun2.Close();
StreamWriter baocun3 = File.AppendText("C:\\baocun3.txt");
baocun3.WriteLine(TextBox3.Text);
baocun3.Close();
ListBox1.Items.Add(TextBox1.Text + TextBox2.Text + TextBox3.Text + "=");
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
protected void Button3_Click(object sender, EventArgs e)
{
TextBox1.BackColor = Color.Yellow;
TextBox2.BackColor = Color.Yellow;
TextBox3.BackColor = Color.Yellow;
TextBox4.BackColor = Color.Yellow;
TextBox1.Enabled = false;
TextBox2.Enabled = false;
TextBox3.Enabled = false;
string[] m = new string[];
m = File.ReadAllLines("C:\\baocun1.txt");
TextBox1.Text = m[a];
string[] n = new string[];
n = File.ReadAllLines("C:\\baocun2.txt");
TextBox2.Text = n[a];
string[] v = new string[];
v = File.ReadAllLines("C:\\baocun3.txt");
TextBox3.Text = v[a];
a++; } protected void Button4_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
Label1.Text = "";
}
protected void Button5_Click(object sender, EventArgs e)
{
Label6.Text = "总计";
Label7.Text = "正确";
Label8.Text = "正确率";
Label3.Text = Count.ToString();
Label4.Text = right.ToString();
Label5.Text = ((right / (double)(Count)) * ).ToString() + "%";
} }

封装代码:

类代码要写在App_Code里

public class Lei
{ public int Sum; public int Answer
{
get { return Sum; } }
public int Max(int n1,int n2,char yunsuanfu)
{
if (yunsuanfu == '+')
{
return Sum = n1 + n2;
}
else if (yunsuanfu == '-')
{ return Sum = n1 - n2; }
else if (yunsuanfu == '/')
{ return Sum = n1 / n2; }
else if (yunsuanfu == '*')
{
return Sum = n1 * n2; }
return Sum; } }

二、测试

在ASP.NET里实现计算器代码的封装的更多相关文章

  1. Asp.net mvc怎么在razor里写js代码

    我试图在Razor里写JS代码,但是不行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3 ...

  2. https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题

    一:什么是https SSL(Security   Socket   Layer)全称是加密套接字协议层,它位于HTTP协议层和TCP协议层之间,用于建立用户与服务器之间的加密通信,确保所传递信息的安 ...

  3. 【转】https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题

    正需要这个,写的很好,就转过来了 转自: http://www.cnblogs.com/naniannayue/ 一:什么是https SSL(Security   Socket   Layer)全称 ...

  4. 在WPF里实现计算器软件

    一.具体代码 类代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; us ...

  5. 利用ASP.NET里自带的站点地图工具制作网站站点地图

    站点地图很方便能快速给我们导航我们要去访问的地址,能按层级关系分门别类,给用户一个很好的用户体验,很好的看到自己当前所在的网站位置 站点地图,又称网站地图,它就是一个页面,上面放置了网站上所有页面的链 ...

  6. [Asp.net 5] DependencyInjection项目代码分析-目录

    微软DI文章系列如下所示: [Asp.net 5] DependencyInjection项目代码分析 [Asp.net 5] DependencyInjection项目代码分析2-Autofac [ ...

  7. [Asp.net 5] DependencyInjection项目代码分析4-微软的实现(5)(IEnumerable<>补充)

    Asp.net 5的依赖注入注入系列可以参考链接: [Asp.net 5] DependencyInjection项目代码分析-目录 我们在之前讲微软的实现时,对于OpenIEnumerableSer ...

  8. [Asp.net 5] DependencyInjection项目代码分析4-微软的实现(3)

    这个系列已经写了5篇,链接地址如下: [Asp.net 5] DependencyInjection项目代码分析 [Asp.net 5] DependencyInjection项目代码分析2-Auto ...

  9. [Asp.net 5] DependencyInjection项目代码分析4-微软的实现(4)

    这个系列已经写了6篇,链接地址如下: [Asp.net 5] DependencyInjection项目代码分析 [Asp.net 5] DependencyInjection项目代码分析2-Auto ...

随机推荐

  1. Windows 视频Directshow开发介绍

    在Windows平台上实现一个文件播放器有什么好的开发库和方案呢?方案有很多,比如基于FFmpeg,VLC的插件,mplayer,Directshow.用FFmpeg来实现文件格式解析.分离视频音频流 ...

  2. go 交叉编译,部署

    go web 部署 交叉编译 go 语言有个强大的地方就是 交叉编译 windows --cmd 设置环境变量-mac SET CGO_ENABLED=0 SET GOOS=darwin SET GO ...

  3. jQuery学习-属性选择器

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. 4569: [Scoi2016]萌萌哒

    4569: [Scoi2016]萌萌哒 链接 分析: 每次给出的两个区间长度是一样的,对应位置的数字也是一样的,那么可以将两两对应的数字用并查集合并,设最后有$cnt$个不同的集合,答案就是$9\ti ...

  5. [算法]用java实现0-1背包和部分背包问题

    问题描述: 0-1背包问题,部分背包问题(课本P229)实验要求: (1)实现0-1背包的动态规划算法求解 (2)实现部分背包的贪心算法求解 0-1背包问题代码: public static void ...

  6. JAVAWEB servlet验证登录时进行完全的非空判断防止空值登录

    如果不进行完全的非空判断,那么对 "" 这种类型的空值就会导致直接登录 所以需要用下面的字符串处理方法对其进行判断 这样就可以防止空值登录了 容易出现的混淆错误: 这里的空值登录容 ...

  7. mysql my.init

    CLIENT SECTION 端口默认是3306,可以修改为别的端口 编码格式默认是latin,要修改成utf8 注意是utf8,不是utf-8 SERVER SECTION 端口也是默认3306 编 ...

  8. Security1:登录和用户

    授予权限的思路,可以用一句话来概括,那就是:授予 Principal 操作 Securable 的 Permission,在多数文档中,把 Principal 翻译为安全主体,Securable翻译为 ...

  9. How to: Display a Non-Persistent Object's List View from the Navigation

    This example demonstrates how to display a non-persistent object's List View when a navigation item ...

  10. 用Metaclass实现一个精简的ORM框架

    存档: # -*- coding: utf-8 -*- class Field(object): def __init__(self, name, column_type): self.name = ...