⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 show_t.aspx.cs

📁 实现投票 实现一个数据表多个投票系统 实现一个数据表多个投票系统实现一个数据表多个投票系统 实现一个数据表多个投票系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 show_t : System.Web.UI.Page
{
    string strtitle;
    string strcontent;
    string id;
    SCOM.fdataset fds;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie readcookie = Request.Cookies["drpCookie"];
        if (readcookie != null)
        {   Response.Write("你已投过票的例表项:"+readcookie.Values["VoteItem"].ToString());}
        else { Response.Write("请你选中满意的答案进行投票");}
        if (Request.QueryString["hlID"] == null)
        {
            Response.Write("你的页面有错");
        }
        else
        {
            id = Request["hlID"];
            fds = new SCOM.fdataset("SqlServer", ConfigurationManager.ConnectionStrings["ooofcudrpConnectionString"].ConnectionString);
            DataTable dv = fds.Ttable("select t_title,t_context from t_table where t_id=" + id);
            foreach (DataRow dr in dv.Rows)  //这里内存数据表中总共只有一行记录
            {
                strtitle = dr[0].ToString();   //得到标题
                strcontent = dr[1].ToString();  //得到所有内容
                
            }
            Label1.Text = strtitle;
            string[] redioArrContent = strcontent.Split('|');
            int intorder = 0;
            if (!Page.IsPostBack)  //页面有提交行为.不执行以下数据的重载 
            {
                foreach (string strContentIN in redioArrContent)
                {
                    string strContentOK = strContentIN.Split(',')[1];
                    RadioButtonList1.Items.Add(new ListItem(strContentOK,intorder.ToString()));
                    intorder++;
                }
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (RadioButtonList1.SelectedIndex != -1)  //如果RadioButtonList1选中过
        {
            HttpCookie makecookie = new HttpCookie("drpCookie");  //制造cookie
            HttpCookie readcookie = Request.Cookies["drpCookie"];  //读出cookie
            if (readcookie == null)
            {
                makecookie.Values.Add("VoteItem", "<" + id + ">");  //制造cookie记录
            }else
            {
                string strAllItem = readcookie.Values["VoteItem"].ToString();
                if(strAllItem.IndexOf("<"+id+">")==-1)  //没投过票
                {
                    makecookie.Values.Add("VoteItem",readcookie.Values["VoteItem"]+"<"+id+">");
                }else  //已投过票
                {
                    Response.Redirect("error.aspx");
                }
            }
            Response.AppendCookie(makecookie);  //写入cookie
            string selectvalve = strcontent.Split('|')[Convert.ToInt32(RadioButtonList1.SelectedValue.ToString())];
            int intVote = Convert.ToInt32(selectvalve.Split(',')[0]);  //当前票数
            int intVoteOK = intVote + 1;//当前票数+1
            string selectvlaueOK = selectvalve.Replace(intVote.ToString(), intVoteOK.ToString());
            string strupdata = strcontent.Replace(selectvalve, selectvlaueOK);
            fds.upData("update t_table set t_context='"+strupdata+"'where t_id="+id);
            Label2.Text = "成功投票";
        }
        else 
        {
            Label2.Text = "投票失败,有可能没有选择项!!请重选";
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("show_t_table.aspx?ID=" + id);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -