• 大小: 5.34MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-16
  • 语言: C#
  • 标签: 简单  asp.net  投票系统  

资源简介

使用vs2005开发,数据库为Access2003,使用时请将App_data下的vote.mdb拷贝到e盘下,当然你也可以通过修改源代码来改变数据库的位置,自己管理投票项目(ItemManager.aspx),进行投票(Default.aspx),图形化显示投票结果(ViewVote.aspx),使用Session来防止用户反复投票,这个小项目是你学习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();
        }
    }

    /// 
    /// 数据绑定到控件
    /// 

    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+“
“);
        //将地地址存入数据库并进行验证(应该是先验证有相同的IP给出提示
        //没有相同的IP则将当前的IP记入数据库)

        //使用cookie
        HttpCookie cookie=new HttpCookie(“UserID“);
        cookie.Value=“admin“;
        cookie.
        Response.Write(“当前的用户是:“+cookie.Value);

        //使用session
        if (Session[“IsVoted“].ToString() == “true“)
        {
            Response.Write(“已经投过票不能再次投票“);
            return;
        }
        else
        {
            Session[“IsVoted“] = “true“;
        }


        //遍历网络控件中的每一行
        foreach (GridViewRow rowView in GridView1.Rows)
        { 
            //主要搜索模板列中的CheckBox控 件
            CheckBox check = (CheckBox)rowView.Cells[2].FindControl(“checkbox1“);
            //如果被选中
            if (check.Checked)
            { 
                //更新数据库中的被投的次数
                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


评论

共有 条评论