📄 showvote.cs
字号:
namespace Soholife.PageVote
{
//定义页面引用类
public class AddVote : System.Web.UI.Page
{
//所有页面用到的控件、需要在这里定义成为protect类型的变量
protected System.Web.UI.WebControls.RadioButton Radio1;
protected System.Web.UI.WebControls.RadioButton Radio2;
protected System.Web.UI.WebControls.RadioButton Radio3;
protected System.Web.UI.WebControls.RadioButton Radio4;
protected void SubmitBtn_Click(Object sender, EventArgs E)
{
Vote vote= new Vote();
string str ="";
if (Radio1.Checked)
{
str= "1";
}
else if (Radio2.Checked)
{
str= "2";
}
else if (Radio3.Checked)
{
str= "3";
}
else if (Radio4.Checked)
{
str= "4";
}
vote.AddVote(str,"");
//此处应该显示投票结果,并显示相应的感谢信息
StringBuilder sb=new StringBuilder();
sb.Append("<script language=javascript >");
sb.Append("window.open('showvote.aspx','_blank','400,100');");
sb.Append("</" + "script>");
Response.Write (sb.ToString());
}
}
//定义页面引用类
public class ShowVote : System.Web.UI.Page
{
//所有页面用到的控件、需要在这里定义成为protect类型的变量
protected System.Web.UI.WebControls.Label Showmsg;
protected void Page_Load(Object sender, EventArgs E)
{
Vote vote = new Vote();
if (vote.GetVote(""))
{
int total=vote.Item1+ vote.Item2 + vote.Item3+ vote.Item3;
if (total==0)
{
Response.Write ("当前投票箱为空,请梢后在来,谢谢!");
return;
}
else
{
int maxwidth=200; //定义最长的宽度
int max=vote.Item1;
//先得到当前最大的投票数
if(vote.Item2>max)
{
max=vote.Item2;
}
if(vote.Item3>max)
{
max=vote.Item3;
}
if(vote.Item4>max)
{
max=vote.Item4;
}
StringBuilder sb=new StringBuilder();
sb.Append("<table width=100% border=1>");
sb.Append("<tr><td>选项一:</td><td align=left><hr size=3 width=" + maxwidth*vote.Item1/max + " color=red></td><td>共" + vote.Item1 + "票 " + ((float)vote.Item1/(float)total)*100 + "%</td></tr>");
sb.Append("<tr><td>选项二:</td><Td align=left><hr size=3 width=" + maxwidth*vote.Item2/max + " color=blue></td><td>共" + vote.Item2 + "票 " + ((float)vote.Item2/(float)total)*100 + "%</td></tr>");
sb.Append("<tr><td>选项三:</td><td align=left><hr size=3 width=" + maxwidth*vote.Item3/max + " color=#006666></td><td>共" + vote.Item3 + "票 " +((float)vote.Item3/(float)total)*100 + "%</td></tr>");
sb.Append("<tr><td>选项四:</td><td align=left><hr size=3 width=" + maxwidth*vote.Item4/max + " color=#339900></td><td>共" + vote.Item4 + "票 " + ((float)vote.Item4/(float)total)*100 + "%</td></tr>");
sb.Append("</table>");
Showmsg.Text +=sb.ToString();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -