码迷,mamicode.com
首页 > Web开发 > 详细

ASP.net封装

时间:2015-11-29 18:00:51      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

设计如下:

技术分享

代码:

using System;
using System.IO;

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

    }
    public static int right = 0;
    
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        int n1 = int.Parse(TextBox1.Text .Trim ());

        int n2 = int.Parse(TextBox3 .Text .Trim ());

        Char y = Convert.ToChar(TextBox2 .Text .Trim ());

       fengzhuang  con = new fengzhuang ();

        con.cl(n1, n2, y);

        if (con.result == int.Parse(TextBox4 .Text .Trim ()))
        {

            Response.Write("<script>alert(‘回答正确!‘)</script>");

            right++;

           

        }



        else
        {
            Response.Write("<script>alert(‘回答错误!‘)</script>");

          
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ListBox2.Items.Add(TextBox1.Text + TextBox2.Text + TextBox3.Text + Label1 .Text +TextBox4 .Text);


        TextBox1.Text="";

        TextBox2.Text = "";

        TextBox3.Text = "";

        TextBox4.Text = "";
    }
}

  技术分享

封装类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///fengzhuang 的摘要说明
/// </summary>
public class fengzhuang
{
	
		//
		//TODO: 在此处添加构造函数逻辑
		//
       public char ysf;

       public int result = 0;

       public void cl(int number1, int number2, char ysf)

        {          

            if(ysf==‘+‘)

            { 

                 result=number1+number2;

            }

            if (ysf == ‘-‘)

            {

               result=number1-number2;

            }

            if (ysf== ‘*‘)

            {

              result=number1*number2;

             }

           if (ysf == ‘/‘)

            {

              result=number1/number2;


             }

         }

 }

    

  测试:

技术分享技术分享技术分享

ASP.net封装

标签:

原文地址:http://www.cnblogs.com/64gong/p/5004891.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!