📄 result.aspx.cs
字号:
//-----------------------------------------------------------------------------
//
// WebExpert.NET 1.0
//
// (c) 2003, www.AspCool.com. All rights reserved.
// ASP酷技术网版权所有
//
// 该源码下载自:http://www.51aspx.com
// 邮箱:tim@aspcool.com
//
// 版权声明:本程序仅供学习使用,你也可以修改后在网站上使用,但使用时必
// 须保留ASP酷技术网(www.AspCool.com)的版权信息和链接。本程序随《ASP.NET
// 网站建设专家》一书赠送,未经作者同意,不得随意修改、传播。
//
// 描述:
// 此文件包含下面的类:
// result
//
// 作者: 王保健
// 时间: 2003/09/15
//
//-----------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace vote
{
/// <summary>
/// Summary description for result.
/// </summary>
public class result : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Repeater Repeater1;
private SqlConnection conn;
private void Page_Load(object sender, System.EventArgs e)
{
conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
conn.Open();
string strSQL="select Q.Question_id, Q.question_subject ,sum(A.got) as s ";
strSQL += "from questions Q inner join answers A ";
strSQL += "on Q.question_id=A.question_id group by Q.Question_id,Q.question_subject";
SqlCommand comm=new SqlCommand(strSQL,conn);
SqlDataReader dr=comm.ExecuteReader();
Hashtable ht=new Hashtable();
while (dr.Read())
{
ht.Add(dr.GetString(0),dr.GetString(1));
}
dr.Close();
PrintHashtable(ht);
conn.Close();
}
private void PrintHashtable(Hashtable myList)
{
IDictionaryEnumerator myEnumerator = myList.GetEnumerator();
while(myEnumerator.MoveNext())
{
Label1.Text += "<table width=\"350\" bgColor=\"#ffffcc\" cellSpacing=\"5\" cellPadding=\"5\" border=\"0\">";
Label1.Text += "<tr><td>";
Label1.Text += myEnumerator.Value ;
Label1.Text +="<table border=\"1\" cellSpacing=\"0\" cellPadding=\"0\" bordercolor=\"#ffcc33\">";
Label1.Text +="<tr bgcolor=\"#ffcc00\">";
Label1.Text +="<td width=\"150\" >选项</td>";
Label1.Text +="<td width=\"250\" >比例</td>";
Label1.Text +="</tr>";
Label1.Text += VoteResult(myEnumerator.Key.ToString());
Label1.Text += "</table></td></tr></table><br><br>";
}
}
private string VoteResult(string QuestionID)
{
string sResult="";
int iSum=GetSum(QuestionID);
string strAnswer="Select Answer_ID,Answer,Got from Answers where Question_ID='"+QuestionID+"'";
SqlCommand commA=new SqlCommand(strAnswer,conn);
SqlDataReader drA=commA.ExecuteReader();
while (drA.Read())
{
sResult +="<tr bgcolor=\"#ffffff\">";
sResult +="<td width=\"150\" >";
sResult += drA.GetString(1);
sResult +="</td>";
sResult +="<td width=\"250\" >";
double per = 100 * Convert.ToSingle(drA.GetInt32(2))/(iSum);
sResult += "<img src=14dc_bg.gif height=9 width="+Math.Round(per, 2).ToString()+">("+Math.Round(per, 2).ToString()+"%)";
sResult +="</td>";
sResult +="</tr>";
}
drA.Close();
return sResult;
}
private int GetSum(string QuestionID)
{
string strSum="Select sum(Got) as Total from Answers group by Question_ID having Question_ID='"+QuestionID+"'";
SqlCommand TotalCommand=new SqlCommand(strSum,conn);
SqlDataReader tdr=TotalCommand.ExecuteReader();
int iResult;
if (tdr.Read())
{
iResult = tdr.GetInt32(0);
}
else
{
iResult= 0;
}
tdr.Close();
return iResult;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -