首页 > 开发 > 综合 > 正文

从一个舆论调查的制作谈面向对象的编程思路(五)

2024-07-21 02:16:41
字体:
来源:转载
供稿:网友
好了,现在万事俱备,只欠东风了,让我们看看现在做一个舆论调查多么简单:

file : vote.aspx


<%@ page language="c#" codebehind="vote.cs" autoeventwireup="false" inherits="football.vote" %>

<html>
  <head>
  <title>532.com.cn --- 舆论调查 ---</title>
  <link rel="stylesheet" href="style/style.css" type="text/css">
    
  </head>
  <body>
    
    <form method="post" runat="server">
    <table width=400 height=300 align=center>
      <tr>
         <td class=cn valign=top align=center><b>调查题目:
            <asp:label id="lblsurveytitle" runat=server class=cn></asp:label>
         </td>
      </tr>
      <tr>
         <td alin=center>
            <asp:image id="imgsurvey" runat=server></asp:image>         
         </td>
      </tr>
      <tr>
         <td align=center>
          <input type=button onclick="window.close();" value="关闭此窗口">
          </td>
      </tr>
    </table>
     </form>
    
  </body>
</html>

file: vote.cs
namespace football
{
    using system;
    using system.collections;
    using system.componentmodel;
    using system.data;
    using system.drawing;
    using system.web;
    using system.web.sessionstate;
    using system.web.ui;
    using system.web.ui.webcontrols;
    using system.web.ui.htmlcontrols;



    /// <summary>
    ///    summary description for vote.
    /// </summary>
    public class vote : system.web.ui.page
    {
        protected system.web.ui.webcontrols.image imgsurvey;
        protected system.web.ui.webcontrols.label lblsurveytitle;

        private string m_strsurveyid ;
        private int m_intvoteid ;
        public vote()
        {
            page.init += new system.eventhandler(page_init);
        }

        protected void page_load(object sender, eventargs e)
        {
            if (!ispostback)
            {
                //
                // evals true first time browser hits the page
                //
            }
        }

        protected void page_init(object sender, eventargs e)
        {
            //
            // codegen: this call is required by the asp+ windows form designer.
            //
            initializecomponent();
            init() ;
        }

        /// <summary>
        ///    required method for designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void initializecomponent()
        {
            this.load += new system.eventhandler (this.page_load);
        }

        private void init()
        {
            m_strsurveyid = request["surveyid"].tostring() ;
            footballsurvey mysurvey = new footballsurvey() ;

            try
            {
                m_intvoteid = request["vote"].toint32() ;
                mysurvey.loadfromdatabase(m_strsurveyid) ;
                lblsurveytitle.text = mysurvey.title ;
                if (m_intvoteid < mysurvey.items.count)
                {
                    mysurvey.vote(m_intvoteid) ;
                }

                mysurvey.createresultimage(server.mappath("survey.jpg") ,
                                            myclass.util.mychart.charttype.pie ,
                                            300 ,300 , color.white) ;
                imgsurvey.imageurl = "survey.jpg" ;
            }
            catch(exception e)
            {
#if debug
                response.write ("初始化页面错误:" + e.tostring()) ;
                return ;
#endif
                page.navigate("error.aspx") ;
            }

        }
    }
}

    要看这个调查的效果,请到http://210.12.102.95/football 。怎么样,是不是觉得这种编程思路不错呢?什么?还不如直接在aspx文件里面做?不错,如果单做这么一个调查的确直接做要省事的多,但你知不知道,只要有编译好的这个类的dll,不管你怎么改页面,改数据结构,你都可以在15分钟内把你所需要的舆论调查做出来?这就是这两种编程方法最大的区别。希望通过这个例子你能学到一些编程思想把。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表