從一個輿論調查的製作談物件導向的編程思路(五)

來源:互聯網
上載者:User
編程|對象 好了,現在萬事俱備,只欠東風了,讓我們看看現在做一個輿論調查多麼簡單:

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分鐘內把你所需要的輿論調查做出來?這就是這兩種編程方法最大的區別。希望通過這個例子你能學到一些編程思想把。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.