永发信息网

求ASP.net计算器应用程序代码(用C#语言 Session对象)

答案:1  悬赏:0  手机版
解决时间 2021-02-20 07:34
求ASP.net计算器应用程序代码(用C#语言 Session对象)
最佳答案
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

txtSum.Text = "0"; //先给计算器赋一个初始值0

}

//单击数字键

protected void btn0_Click(object sender, EventArgs e) {
if (txtSum.Text == "0")
{
txtSum.Text = "0";

}
else
{
txtSum.Text += "0";
}
}
protected void btn1_Click(object sender, EventArgs e)
{
if (txtSum.Text == "0")
{
txtSum.Text = "1";
}
else
{
txtSum.Text += "1";
}
}
protected void btn2_Click(object sender, EventArgs e)
{
if (txtSum.Text == "0")
{
txtSum.Text = "2";
}
else
{
txtSum.Text += "2";
}
}
protected void btn3_Click(object sender, EventArgs e)
{
if (txtSum.Text == "0")
{
txtSum.Text = "3";
}
else
{
txtSum.Text += "3";
}
}
protected void btn4_Click(object sender, EventArgs e)
{
if (txtSum.Text == "0")
{
txtSum.Text = "4";
}
else
{
txtSum.Text += "4";
}
}
protected void btn5_Click(object sender, EventArgs e)
{
if (txtSum.Text == "0")
{
txtSum.Text = "5";
}
else
{
txtSum.Text += "5";
}
}
protected void btn6_Click(object sender, EventArgs e)
{
if (txtSum.Text == "0")
{
txtSum.Text = "6";
}
else
{
txtSum.Text += "6";
}
}
protected void btn7_Click(object sender, EventArgs e)
{
if (txtSum.Text == "0")
{
txtSum.Text = "7";
}
else
{
txtSum.Text += "7";
}
}
protected void btn8_Click(object sender, EventArgs e)
{
if (txtSum.Text == "0")
{
txtSum.Text = "8";
}
else
{
txtSum.Text += "8";
}
}
protected void btn9_Click(object sender, EventArgs e)
{
if (txtSum.Text == "0")
{
txtSum.Text = "9";
}
else
{
txtSum.Text += "9";
}
}

//单击运算符号,先判断计算器值是否为0

protected void btnAdd_Click(object sender, EventArgs e)
{
if (txtSum.Text != "0")
{
string sum = txtSum.Text; //定义一个Sum保存第一个要运算的数
Session["Sum"] = sum; //使用Session对象将第一个数保存
string symbols = "+"; //定义一个运算符

Session["Symbols"] = symbols; //使用Session对象将运算符保存
txtSum.Text = "0"; //然后将计算器清空,输入第二个数

}
}

//单击运算符号,先判断计算器值是否为0
protected void btnReduce_Click(object sender, EventArgs e)
{
if (txtSum.Text != "0")
{
string sum = txtSum.Text; // 定义一个Sum保存第一个要运算的数
Session["Sum"] = sum;//使用Session对象将第一个数保存
string symbols = "-";//定义一个运算符
Session["Symbols"] = symbols; //使用Session对象将运算符保存
txtSum.Text = "0";//然后将计算器清空,输入第二个数

}
}

//下面的都是依次像上面解析
protected void btnBy_Click(object sender, EventArgs e)
{
if (txtSum.Text != "0")
{
string sum = txtSum.Text;
Session["Sum"] = sum;
string symbols = "*";
Session["Symbols"] = symbols;
txtSum.Text = "0";

}
}
protected void btnDesides_Click(object sender, EventArgs e)
{
if (txtSum.Text != "0")
{
string sum = txtSum.Text;
Session["Sum"] = sum;
string symbols = "/";
Session["Symbols"] = symbols;
txtSum.Text = "0";

}
}

protected void btnSum_Click(object sender, EventArgs e)
{
string sum = ""; //重新定义一个字符串,提取第一个数
string symbols =(string)Session["Symbols"];//重新定义一个运算符,提取Session里的运算符

int i; //定义一个变量 求和
switch (symbols)
{
case "+":
sum = (string)Session["Sum"];
i = Convert.ToInt32(sum) + Convert.ToInt32(txtSum.Text);
txtSum.Text = Convert.ToString(i);
break;
case "-":
sum = (string)Session["Sum"];
i = Convert.ToInt32(sum) - Convert.ToInt32(txtSum.Text);
txtSum.Text = Convert.ToString(i);
break;
case "*":
sum = (string)Session["Sum"];
i = Convert.ToInt32(sum) * Convert.ToInt32(txtSum.Text);
txtSum.Text = Convert.ToString(i);
break;
case "/":
sum = (string)Session["Sum"];
i = Convert.ToInt32(sum) / Convert.ToInt32(txtSum.Text);
txtSum.Text = Convert.ToString(i);
break;
default:
txtSum.Text = "0";
break;
}

}

//单击清空按钮

protected void btnC_Click(object sender, EventArgs e)
{
txtSum.Text = "0"; //清空计算器
Session["Sum"] = "0"; //清空Session["Sum]

Session["symbols"]="0"; //清空Session["symbols"]

}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
电脑跑分是鲁大师好,还是360好
新装的Win7,发现桌面上有个激活工具,我不知
设函数f(x)定义在R上,它的图像关于x=1对称,且
我已经结婚二年了,可还是没有孩子怎么办?
如何利用极限的严格定义证明limx^2=1 其中x
手机下载极简安全助手怎么打不开
(疯狂)近义词有哪些?
百盛生鲜超市怎么去啊,有知道地址的么
祥康推拿地址在什么地方,想过去办事
离美,国 离波士顿7分钟车程的是什么城市
如图表示淀粉、蛋白质、脂肪在消化道中各部位
C语言实训 猜数组下标游戏 急用!!!
135个0.45相加的和是多少
为什么发动机转速慢的时候电瓶灯会一闪一闪的
新买了个键盘QPAD MK_85但是不知道怎么开背光
推荐资讯
奇瑞汽车维修方便吗
深大北门到大剧院开车路线查询
My mother works in a hospital.的问句怎么问
海安市曲塘镇富民社区卫生服务站地址有知道的
电和光谁更快RT
六三机动车驾驶员技工学校第二训练基地这个地
五年级上册口算题 要难的
陈砦新区1号院我想知道这个在什么地方
水坝地址在什么地方,想过去办事
影视大全下载的电影怎么用蓝牙传到另一个手机
常熟市何市新丰纱厂这个地址在什么地方,我要
小明到学校有600米,小强离学校比小明家远20%,
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?