投票系统
包含四个方面:投票主题添加/投票主题查询/投票/投票结果
关键代码:
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 VoteResult : System.Web.UI.Page
{
float poll1ratio = 0f;
float poll2ratio = 0f;
float poll3ratio = 0f;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string id = Session["id"].ToString();
int result = int.Parse(Request.QueryString["result"].ToString());
DataHandle handle = new DataHandle();
DataTable table = handle.GetVote(id).Tables[0];
lblTitle.InnerText = table.Rows[0][0].ToString();
lblItem1.InnerText = table.Rows[0][1].ToString();
lblItem2.InnerText = table.Rows[0][2].ToString();
lblItem3.InnerText = table.Rows[0][3].ToString();
DataTable tableResult = handle.GetVoteResult(id).Tables[0];
int poll1 = int.Parse(tableResult.Rows[0][0].ToString());
int poll2 = int.Parse(tableResult.Rows[0][1].ToString());
int poll3 = int.Parse(tableResult.Rows[0][2].ToString());
switch (result)
{
case 0:
poll1++;
handle.UpdataVoteResult(id, poll1, 0);
break;
case 1:
poll2++;
handle.UpdataVoteResult(id, poll2, 1);
break;
case 2:
poll3++;
handle.UpdataVoteResult(id, poll3, 2);
break;
}
int pollSum = poll1 + poll2 + poll3;
poll1ratio = Convert.ToSingle((float)poll1 / pollSum);
lblResult1.InnerText = Math.Round((poll1ratio * 100), 2).ToString() + "%";
poll2ratio = Convert.ToSingle((float)poll2 / pollSum);
lblResult2.InnerText = Math.Round((poll2ratio * 100), 2).ToString() + "%";
poll3ratio = Convert.ToSingle((float)poll3 / pollSum);
lblResult3.InnerText = Math.Round((poll3ratio * 100), 2).ToString() + "%";
img1.Width = (int)(poll1ratio * 100);
img2.Width = (int)(poll2ratio * 100);
img3.Width = (int)(poll3ratio * 100);
lblTotal.InnerText = pollSum.ToString();
}
}
}
投票结果效果图:
3375


&spm=1001.2101.3001.11974&articleId=49864715&d=1&t=3&u=cd6d440bdf324caa9300431a86caa722)

被折叠的 条评论
为什么被折叠?



