Discussion on object-oriented programming ideas from the production of a public opinion survey (v)

Source: Internet
Author: User
Tags tostring
Programming | Objects Well, now everything is in the wind, let's see how simple it is to do a public opinion survey now:

File:vote.aspx


<%@ Page language= "C #" codebehind= "Vote.cs" autoeventwireup= "false" inherits= "Football.vote"%>

<title>532.com.cn---Public opinion survey---</title>
<link rel= "stylesheet" href= "Style/style.css" type= "Text/css" >

<body>

<form method= "POST" runat= "Server" >
<table width=400 height=300 align=center>
<tr>
&LT;TD CLASS=CN valign=top align=center><b> survey Topics:
<asp:label id= "Lblsurveytitle" Runat=server class=cn></asp:label>
</td>
</tr>
<tr>
&LT;TD alin=center>
<asp:image id= "Imgsurvey" runat=server></asp:image>
</td>
</tr>
<tr>
&LT;TD align=center>
<input Type=button onclick= "Window.close ();" value= "Close this window" >
</td>
</tr>
</table>
</form>

</body>

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 Browser hits the page
//
}
}

protected void Page_Init (object sender, EventArgs e)
{
//
Codegen:this the call are required by the asp+ Windows Form Designer.
//
InitializeComponent ();
Init ();
}

<summary>
Required to Designer support-do not modify
The contents is 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,
Color.White);
Imgsurvey.imageurl = "Survey.jpg";
}
catch (Exception e)
{
#if DEBUG
Response.Write ("Initialize page error:" + e.tostring ());
return;
#endif
Page.navigate ("error.aspx");
}

}
}
}

To see the effect of this survey, please go to Http://210.12.102.95/football. How do you think this is a good programming idea? What the? Why not just do it directly in the ASPX file? Yes, if the single do such a survey does directly to save more, but do you know, as long as there are compiled this class DLL, no matter how you change the page, change the data structure, you can in 15 minutes you need to make the public opinion survey? This is the biggest difference between the two programming methods. Hopefully you can learn some programming ideas from this example.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.