快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

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

好了,现在万事俱备,只欠东风了,让我们看看现在做一个舆论调查多么简朴:

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分钟内把你所需要的舆论调查做出来?这就是这两种编程方式最大的区别。希望通过这个例子你能学到一些编程思想把。


返回类别: 教程
上一教程: ASP.NET可交互式位图窗体设计(7)
下一教程: .Net 下的Wondows窗体常用项目

您可以阅读与"从一个舆论调查的制作谈面向对象的编程思路(五)"相关的教程:
· 从一个舆论调查的制作谈面向对象的编程思路(二)
· 从一个舆论调查的制作谈面向对象的编程思路(一)
· ADO.NET对象的构造(3)_DataTable(续)
· asp+版本简朴的留言板的制作(一)
· ADO.NET对象的构造(4)_DataColumn(续)
    微笑服务 优质保证 索取样品