求ASP.net计算器应用程序代码(用C#语言 Session对象)
答案:1 悬赏:0 手机版
解决时间 2021-02-20 07:34
- 提问者网友:遁入空寂
- 2021-02-19 19:37
求ASP.net计算器应用程序代码(用C#语言 Session对象)
最佳答案
- 五星知识达人网友:蕴藏春秋
- 2021-02-19 19:44
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"]
}
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"]
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯