您目前尚未登陆,请选择【登陆】或【注册
首页->投票调查->大学生调查投票系统源码>>Result.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:大学生调查投票系统源码
当前文件:文件类型 StudentVote/Result.aspx.cs打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.Data.SqlClient; 12 13public partial class Result : System.Web.UI.Page 14{ 15 protected void Page_Load(object sender, EventArgs e) 16 { 17 SqlData da = new SqlData(); 18 SqlDataReader dr = da.ExceRead("select * from tb_Vote where ID="+Request["ID"]+""); 19 dr.Read(); 20 string strContent = dr["Content"].ToString(); 21 dr.Close(); 22 decimal decNumAll = GetNumAll(strContent);//得到所有票数,C#在除法运算中需用decimal类型,否则将会把小数点后的数去掉 23 Response.Write(GetResult(strContent, decNumAll)); 24 } 25 26 /// <summary> 27 /// 显示图象 28 /// </summary> 29 /// <param name="strContent">相关主题下的内容</param> 30 /// <param name="decNumAll">所有的票数</param> 31 /// <returns></returns> 32 public string GetResult(string strContent, decimal decNumAll) 33 { 34 string[] arrContent = strContent.Split('|'); 35 string strBody = "<table width=100% border=1>\n"; 36 foreach (string strContentIN in arrContent) 37 { 38 string strItemName = strContentIN.Split(',')[1].ToString();//得到选项名称 39 decimal decItemNum = Convert.ToDecimal(strContentIN.Split(',')[0]);//得到选项的投票数 40 decimal decPercent = GetPercent(decItemNum, decNumAll) * 100;//得到百分比 41 string strPercent = decPercent.ToString();//将百分比转为字符型 42 if (strPercent.Length > 5)//如果百分比结果长度超过5位 43 { 44 strPercent = strPercent.Substring(0, 5);//将百分比的余数截短为“00.00” 45 } 46 strBody += "<tr><td width=100>" + strItemName + "</td><td width=50>" + decItemNum.ToString() + "票</td><td><img src=Images/bar1.gif height=10 width=" + strPercent + "%>" + strPercent + "%</td></tr>\n"; 47 } 48 strBody += "</table>"; 49 return strBody; 50 } 51 52 53 /// <summary> 54 /// 票数求和 55 /// </summary> 56 /// <param name="strNum">当前所要操作的字串</param> 57 /// <returns></returns> 58 public decimal GetNumAll(string strNum) 59 { 60 decimal decNumAll = 0; 61 string[] arrNum = strNum.Split('|'); 62 foreach (string strNumIN in arrNum) 63 { 64 decNumAll += Convert.ToInt32(strNumIN.Split(',')[0].ToString());//截取第零位 65 } 66 return decNumAll; 67 } 68 69 /// <summary> 70 /// 百分比 71 /// </summary> 72 /// <param name="decItem">当前选项本身的票数</param> 73 /// <param name="decNumAll">所有的票数</param> 74 /// <returns></returns> 75 public decimal GetPercent(decimal decItem, decimal decNumAll) 76 { 77 if (decNumAll == 0)//如果总票数是零 78 { 79 decNumAll++;//加一,避免除0出错 80 } 81 decimal decPercent = decItem / decNumAll; 82 return decPercent; 83 } 84} 85
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:大学生调查投票系统源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号