一般处理程序的加法器

1.在vs2010 写的

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

namespace _0722
{
    /// <summary>
    /// C06Cul 的摘要说明
    /// </summary>
    public class C06Cul : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            DateTime serverTime = DateTime.Now;
            string strNum1 = context.Request.Form["txtNum1"];
            string strNum2 = context.Request.Form["txtNum2"];
            int x = 0;
            int y = 0;
            int z = 0;
          if(!string.IsNullOrEmpty(context.Request.Form["hidIsPostBack"]))
           {
            if (!string.IsNullOrEmpty(strNum1) && !string.IsNullOrEmpty(strNum2))
            {
               
               
                if (int.TryParse(strNum1, out x) && int.TryParse(strNum2, out y))
                {
                    z = x + y;
                }
                //context.Response.Write(z.ToString());
           
            }
          }
            System.Text.StringBuilder sbHTML = new System.Text.StringBuilder();
            sbHTML.Append("<html><head><title>计算器</title></head><body><form action=''method='post'>");
            sbHTML.Append("<input type='txt'name='txtNum1'value='" + x.ToString() + "'/>+<input type='txt'name='txtNum2'value='" + y.ToString() + "'/>=<input type='txt'name='txtSum'value='" + z.ToString() + "'/><br/>");
            sbHTML.Append("<input type='submit'value='计算'>");
            sbHTML.Append("<input type='hidden'name='hidIsPostBack'value='1'/></form></body></html>");
           
            context.Response.Write(sbHTML.ToString());
            context.Response.Write("<div>Hello World!"+serverTime.ToString()+"</div>");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

2.代码:https://files.cnblogs.com/hao1234/0722.rar

posted on 2011-07-22 19:23  smxlcs  阅读(265)  评论(0)    收藏  举报