温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:唐唐企业管理网站源码
当前文件:
TangCompany/youhudianping.aspx.cs,打开代码结构图
TangCompany/youhudianping.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
using System.Text; 13
14
public partial class youhudianping : System.Web.UI.Page 15
{ 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
if (!Page.IsPostBack) { 19
20
BindVote(); 21
BindVotePerence(); 22
23
} 24
} 25
protected void BindVote() 26
{ 27
28
RadioVote.DataSource = SqlHelper.ExcuteRead("SelectVote", CommandType.StoredProcedure, null); 29
RadioVote.DataTextField = "Name"; 30
RadioVote.DataValueField = "Id"; 31
RadioVote.DataBind(); 32
33
34
} 35
protected void BindVotePerence() { 36
37
StringBuilder builder = new StringBuilder(); 38
SqlDataReader dr = SqlHelper.ExcuteRead("SelectVote", CommandType.StoredProcedure, null); 39
float txtTotal = float.Parse(SqlHelper.ExcuteSclare("SELECT SUM(Total) FROM [Vote] WHERE Vis=1", CommandType.Text, null).ToString()); 40
while (dr.Read()) { 41
42
builder.Append("<div id=\"VoteImg1\"><table width=\"40\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=\"9\" height=\"150\" align=\"center\" valign=\"bottom\"></td>"); 43
builder.Append("<td width=\"22\" align=\"center\" valign=\"bottom\" class=\"VoteImg_border\">"); 44
builder.Append("<img src=\"flpicture/VoteImg.gif\" width=\"20\" height=\""+Precent(int.Parse(dr["Total"].ToString())/txtTotal)+"\" border=\"0\" /></td><td width=\"9\" align=\"center\" valign=\"bottom\"></td>"); 45
builder.Append("</tr><tr><td height=\"25\" colspan=\"3\" align=\"center\">"+dr["Name"].ToString()+"</td></tr></table></div>"); 46
47
} 48
VoteImg.InnerHtml = builder.ToString(); 49
50
} 51
protected int Precent(float txtNum) { 52
53
int txtHeight; 54
55
if (txtNum <0.02) 56
{ 57
txtHeight = 1; 58
59
} 60
else { 61
62
txtHeight = Convert.ToInt32(txtNum * 120); 63
64
} 65
return txtHeight; 66
67
} 68
protected void ButtonVote_Click(object sender, EventArgs e) 69
{ 70
SqlParameter[] paras ={ new SqlParameter("@Id", SqlDbType.Int, 4) }; 71
paras[0].Value = int.Parse(RadioVote.SelectedValue.ToString()); 72
SqlHelper.ExcuteNonQurey("UserVote", CommandType.StoredProcedure, paras); 73
Response.Write("<script>alert('投票成功')</script>"); 74
Response.Redirect("Default.aspx"); 75
} 76
} 77





}
}