⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voter.aspx

📁 J2ME核心类及MIDlet类 MIDP用户界面对象 图形处理及低级事件处理 多线程编程 I/O及网络编程 数据库RMS编程 浮点数编程 多媒体及GAME API编程 安全、加密及
💻 ASPX
字号:
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Text" %>
<Script Language="C#" Runat="Server">
public void Page_Load( Object src, EventArgs eventargs )
{
	if( Application["totalVotes"] == null )
		Application["totalVotes"] = (int)0;
	if( Application["average"] == null )
		Application["average"] = (double)0;
	if( Application["votes"] == null )
		Application["votes"] = new int[5];

	int totalVotes = (int)Application["totalVotes"];
	double average = (double)Application["average"];
	int[] votes =(int[])Application["votes"];

	String[] choices = new String[5];
	choices[0] = "差";
	choices[1] = "一般";
	choices[2] = "好";
	choices[3] = "很好";
	choices[4] = "特好";

	String sChoice = Request.Params["choice"];
	if ( sChoice != null && sChoice != "" )
	{
	   int iChoice = 0;
	   
	   try
	   {
	   	iChoice = int.Parse(sChoice);
	   	
	   	if ( iChoice < choices.Length)
	   	{
			// 将投票数加入
			votes[iChoice]++;
			totalVotes++;

			int sum = 0;

			for ( int i = 0; i < choices.Length; i++)
			{
			   sum = sum +  (i+1) * votes[i];
			}

			average = (1.0 * sum) / totalVotes;
		}
	   }
	   catch (FormatException nfe)
	   {
	   }
	}
	
	// 输出投票的结果
	StringBuilder voteResults = new StringBuilder();
	
	String sAverage = ""+ average;
	
	voteResults.Append("<vote-example>\n");
	voteResults.Append("	<votes>\n");
	voteResults.Append("		<number>"+ totalVotes +"</number>\n");
	voteResults.Append("		<average>"+ sAverage +"</average>\n");
	voteResults.Append("		<choices>\n");

	for ( int j = 0; j < choices.Length; j++)
	{
		voteResults.Append("			<choice>\n");
		voteResults.Append("				<name>"+ choices[j] +"</name>\n");
		voteResults.Append("				<number>"+ votes[j] +"</number>\n");
		voteResults.Append("				<value>"+ j +"</value>\n");
		voteResults.Append("			</choice>\n");
	}
	
	voteResults.Append("		</choices>\n");
	voteResults.Append("	</votes>\n");
	voteResults.Append("</vote-example>\n");
	
	Application["totalVotes"] = totalVotes;
	Application["average"] = average;
	Application["votes"] = votes;

	Response.ContentType = "text/xml";
	Response.Write(voteResults.ToString() );
	Response.End();
}
</Script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -