?? pollresults.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace ASPNET.StarterKit.Communities.Admin.EditVoting
{
/// <summary>
/// Summary description for PollResults.
/// </summary>
public class PollResults : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel ResultsPanel;
#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
System.Drawing.Color barBackColor = System.Drawing.Color.LightGray;
System.Drawing.Color barForeColor = System.Drawing.Color.Blue;
int totalVotes=0;
//*******************************************************
//
// When page loads display the current results
// for a voting poll.
//
//*******************************************************
void Page_Load(Object s, EventArgs e) {
if (Request["Poll_ID"]==null) {
Response.Redirect("Default.aspx");
}
int Poll_ID = Int32.Parse(Request["Poll_ID"]);
PollDetails polldetails = VotingUtility.GetPollForWebBox(Poll_ID);
Table t = new Table();
TableRow questionRow = new TableRow();
TableRow resultsRow = new TableRow();
TableRow footerRow = new TableRow();
TableCell questionCell = new TableCell();
TableCell resultsCell = new TableCell();
TableCell footer = new TableCell();
// Format the table
//
t.BorderWidth = 0;
// Question
//
questionCell.Text = polldetails.Question;
questionCell.Attributes.Add("style","font-weight:bold;");
questionCell.ColumnSpan = 3;
// Add the question cell/row to the table
//
questionRow.Cells.Add(questionCell);
t.Rows.Add(questionRow);
// if (polldetails.DisplayResultsToPublic) {
Hashtable pollresults = VotingUtility.GetPollResults(polldetails.Poll_ID);
// Calculate the sum
//
int sum=0;
foreach (int key in pollresults.Keys)
sum = sum + (int)pollresults[key];
// Calculate percentage
//
foreach (int key in pollresults.Keys) {
// Internal variables/instances
//
double d = 0;
TableRow row = new TableRow();
TableCell progressCell = new TableCell();
TableCell percentageCell = new TableCell();
TableCell choiceCell = new TableCell();
ProgressBar bar = new ProgressBar();
// Percentage for this poll value
//
d = ((double)((int)pollresults[key]) / (double)sum) * 100;
// Display the choice in cell and format
//
choiceCell.Text = ((ChoiceInfo)polldetails.Choices[key]).Choice + ": ";
choiceCell.VerticalAlign = VerticalAlign.Top;
choiceCell.Wrap = false;
// Set properties for each bar
//
bar.PercentageOfProgress = (int)d;
bar.BackColor = barBackColor;
bar.ForeColor = barForeColor;
// Add the bar and set properties of the cell
//
progressCell.Controls.Add(bar);
progressCell.HorizontalAlign = HorizontalAlign.Right;
progressCell.VerticalAlign = VerticalAlign.Top;
progressCell.Width = 100;
// Special case 0
//
if ((double.IsNaN(d)) || (0 == d))
percentageCell.Text = "(0%)";
else
percentageCell.Text = "(" + d.ToString("##.#") + "%) (" + (int)pollresults[key] + " votes)";
// Format percentage cell
//
percentageCell.HorizontalAlign = HorizontalAlign.Left;
percentageCell.VerticalAlign = VerticalAlign.Top;
// Add the cells to the row
//
row.Cells.Add(choiceCell);
row.Cells.Add(progressCell);
row.Cells.Add(percentageCell);
// Add the row to the table
//
t.Rows.Add(row);
// Update total votes
totalVotes+=(int)pollresults[key];
// }
}
// Add results cell/row to table
//
resultsRow.Cells.Add(resultsCell);
t.Rows.Add(resultsRow);
// Display Total Votes
TableRow totalRow = new TableRow();
TableCell totalCell = new TableCell();
totalCell.Text="Total Votes: " + totalVotes;
totalRow.Cells.Add(totalCell);
t.Rows.Add(totalRow);
ResultsPanel.Controls.Add(t);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -