-
大小: 5.34MB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2023-09-16
- 語言: C#
- 標簽: 簡單??asp.net??投票系統(tǒng)??
資源簡介
使用vs2005開發(fā),數(shù)據(jù)庫為Access2003,使用時請將App_data下的vote.mdb拷貝到e盤下,當然你也可以通過修改源代碼來改變數(shù)據(jù)庫的位置,自己管理投票項目(ItemManager.aspx),進行投票(Default.aspx),圖形化顯示投票結(jié)果(ViewVote.aspx),使用Session來防止用戶反復(fù)投票,這個小項目是你學(xué)習(xí)asp.net的一個比較不錯的項目.

代碼片段和文件信息
using?System;
using?System.Data;
using?System.Configuration;
using?System.Web;
using?System.Web.Security;
using?System.Web.UI;
using?System.Web.UI.WebControls;
using?System.Web.UI.WebControls.WebParts;
using?System.Web.UI.HtmlControls;
public?partial?class?_Default?:?System.Web.UI.Page?
{
????protected?void?Page_Load(object?sender?EventArgs?e)
????{
????????if?(!Page.IsPostBack)
????????{
????????????gridView_DataBind();
????????}
????}
????///?
????///?數(shù)據(jù)綁定到控件
????///?
????private?void?gridView_DataBind()
????{?
????????//初始化投票項目操作類
????????ItemOperation?io?=?new?ItemOperation();
????????DataTable?dt?=?io.LoadVote();
????????GridView1.DataSource?=?dt;
????????GridView1.DataBind();
????}
????//我要投票按鈕的操作
????protected?void?Button1_Click(object?sender?EventArgs?e)
????{
????????//初始化投票項目操作類
????????ItemOperation?io?=?new?ItemOperation();
????????//獲取用戶的ip信息
????????string?strIp?=?Request.ServerVariables[“REMOTE_ADDR“];
????????Response.Write(“當前請求用戶的IP是:“?+?strIp+“
“);
????????//將地地址存入數(shù)據(jù)庫并進行驗證(應(yīng)該是先驗證有相同的IP給出提示
????????//沒有相同的IP則將當前的IP記入數(shù)據(jù)庫)
????????//使用cookie
????????HttpCookie?cookie=new?HttpCookie(“UserID“);
????????cookie.Value=“admin“;
????????cookie.
????????Response.Write(“當前的用戶是:“+cookie.Value);
????????//使用session
????????if?(Session[“IsVoted“].ToString()?==?“true“)
????????{
????????????Response.Write(“已經(jīng)投過票不能再次投票“);
????????????return;
????????}
????????else
????????{
????????????Session[“IsVoted“]?=?“true“;
????????}
????????//遍歷網(wǎng)絡(luò)控件中的每一行
????????foreach?(GridViewRow?rowView?in?GridView1.Rows)
????????{?
????????????//主要搜索模板列中的CheckBox控?件
????????????CheckBox?check?=?(CheckBox)rowView.Cells[2].FindControl(“checkbox1“);
????????????//如果被選中
????????????if?(check.Checked)
????????????{?
????????????????//更新數(shù)據(jù)庫中的被投的次數(shù)
????????????????io.UpdateVote(int.Parse(rowView.Cells[0].Text));
????????????????//Session[“IsVoted“]?=?“true“;
????????????????Label1.Text?=?“謝謝您的投票“;
????????????}
????????}
????}
????//查看投票按鈕的操作
????protected?void?Button2_Click(object?sender?EventArgs?e)
????{
????????Response.Redirect(“ViewVote.aspx“);
????}
????protected?void?Button3_Click(object?sender?EventArgs?e)
????{
????????Response.Redirect(“ItemManager.aspx“);
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1545??2009-10-28?14:28??web.config
?????文件???????7630??2009-11-04?13:01??App_Code\ItemOperation.cs
?????文件???10485760??2009-10-28?14:35??App_Data\ASPNETDB.MDF
?????文件?????516096??2009-10-28?14:35??App_Data\aspnetdb_log.ldf
?????文件?????217088??2009-10-27?13:50??App_Data\vote.mdb
?????文件???????2048??2009-11-04?14:47??Default.aspx
?????文件???????2660??2009-11-04?14:39??Default.aspx.cs
?????文件????????998??2009-11-04?14:04??Global.asax
?????文件???????1548??2009-11-04?13:10??ItemManager.aspx
?????文件???????2218??2009-11-04?13:09??ItemManager.aspx.cs
?????文件???????1586??2009-10-11?17:43??SimpleVote.sln
????..A..H.?????21504??2009-11-04?14:49??SimpleVote.suo
?????文件???????1889??2009-11-04?13:11??ViewVote.aspx
?????文件???????1768??2009-10-28?14:55??ViewVote.aspx.cs
?????文件???????4482??2006-08-31?16:38??vote.bmp
?????目錄??????????0??2009-11-04?13:01??App_Code
?????目錄??????????0??2009-10-28?14:24??App_Data
-----------?---------??----------?-----??----
?????????????11268820????????????????????17
評論
共有 條評論