• 大小: 178KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: C#
  • 标签: C#  ASP.NET  投票  

资源简介

说明: 用C#语言实现的ASP.NET在线投票系统的简单例子,可以显示投票人数,投票百分比例对比等,使用Cookie技术实现 ^_^

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender EventArgs e)
    {

    }
    protected void ImageButton1_Click(object sender ImageClickEventArgs e)
    {
        string userIP = Request.UserHostAddress.ToString();
        HttpCookie oldCookie = Request.Cookies[“userIP“];
        if (oldCookie == null)
        {
            int flag = RadioButtonList1.SelectedIndex;
            switch (flag)
            {
                case 0:
                    Component.WriteCount(Server.MapPath(“Result1.txt“));
                    break;
                case 1:
                    Component.WriteCount(Server.MapPath(“result2.txt“));
                    break;
                case 2:
                    Component.WriteCount(Server.MapPath(“Result3.txt“));
                    break;
            }
            Clientscript.RegisterStartupscript(this.GetType() ““ “alert(‘投票成功!‘)“ true);
            HttpCookie newCookie = new HttpCookie(“userIP“);
            newCookie.Expires = DateTime.MaxValue;
            newCookie.Values.Add(“IPAddress“ userIP);
            Response.AppendCookie(newCookie);
        }
        else
        {
            string userOldIP = oldCookie.Values[“IPAddress“];
            if (userIP.Trim() == userOldIP.Trim())
            {
                Clientscript.RegisterStartupscript(this.GetType() ““ “alert(‘一个IP地址只能投一次票,谢谢您的参与!‘)“ true);
            }
            else
            {
                HttpCookie newCookie = new HttpCookie(“userIP“);
                newCookie.Values.Add(“IPAddress“ userIP);
                newCookie.Expires = DateTime.MaxValue;
                Response.AppendCookie(newCookie);
                int flag = RadioButtonList1.SelectedIndex;
                switch (flag)
                {
                    case 0:
                        Component.WriteCount(Server.MapPath(“Result1.txt“));
                        break;
                    case 1:
                        Component.WriteCount(Server.MapPath(“result2.txt“));
                        break;
                    case 2:
                        Component.WriteCount(Server.MapPath(“Result3.txt“));
                        break;
                }
                Clientscript.RegisterStartupscript(this.GetType() ““ “alert(‘投票成功!‘)“ true);
            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-11-17 17:26  Vote\
     目录           0  2011-11-17 17:02  Vote\App_Code\
     文件         700  2011-11-17 17:05  Vote\App_Code\Component.cs
     文件        1622  2011-11-17 17:27  Vote\Default.aspx
     文件        2622  2011-11-17 17:26  Vote\Default.aspx.cs
     目录           0  2011-11-17 16:56  Vote\Images\
     文件      100734  2010-03-25 15:34  Vote\Images\1.jpg
     文件      111734  2010-03-25 15:32  Vote\Images\2.jpg
     文件        1848  2010-03-25 15:37  Vote\Images\dc_03.gif
     文件        1790  2010-03-25 15:37  Vote\Images\dc_05.gif
     文件        1539  2010-03-25 15:35  Vote\Images\fh_03.gif
     文件        4230  2011-11-17 17:33  Vote\Result.aspx
     文件        1323  2011-11-17 17:39  Vote\Result.aspx.cs
     文件           3  2011-11-17 17:26  Vote\Result1.txt
     文件           4  2011-11-17 17:25  Vote\Result2.txt
     文件           3  2011-11-17 17:39  Vote\Result3.txt
     文件         761  2011-11-17 17:28  Vote\styleSheet.css
     文件         292  2011-11-17 17:10  Vote\web.config

评论

共有 条评论