天天看點

ASP.net

ASP.net

      
背景代碼
 protected void Button1_Click(object sender, EventArgs e)
    {
        ric.X =double .Parse( TextBox1.Text);
        ric.Y =double .Parse( TextBox3.Text);
        ric.fuhao = DropDownList1.SelectedValue;
        ric.result = result;
        ric.Add();
        ric.Sub();
        ric.Mul();
        ric.Div();
        if (TextBox4.Text == ric.result.ToString())
        {
            Response.Write("<script>alert('回答正确')</script>");
        }
        else
        {
            Response.Write("<script>alert('回答錯誤')</script>");
        }
    }
    protected void DropDownList1_TextChanged(object sender, EventArgs e)
    {
        string fuhao = DropDownList1.SelectedValue;
        switch (fuhao)
        {
            case"+":
                DropDownList1.SelectedValue = "+";
                break;
            case"-":
                DropDownList1.SelectedValue = "-";
                break;
            case"*":
                DropDownList1.SelectedValue = "*";
                break;
            case"/":
                DropDownList1.SelectedValue = "/";
                break;
            default:
                break;
        }
    }      

添加一個新類Richnone

ASP.net
public class Richnone
{
    public string fuhao;//計算符号
    public double result;


    private double x;//第一個數
    public double X
    {
        get { return x; }
        set { x = value; }
    }
    private double y;//第二個數
    public double Y
    {
        get { return y; }
        set { y = value; }
    }
    public void Add()//加法
    {
        if (fuhao == "+")
        {
            result = X + Y;
        }
    }
    public void Sub()
    {
        if (fuhao == "-")
        {
            result = X - Y;
        }
    }
    public void Mul()
    {
        if (fuhao == "*")
        {
            result = X * Y;
        }
    }
    public void Div()
    {
        if (fuhao == "/")
        {
            result = X / Y;
        }
    }
       
}      
截圖      
ASP.net