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;
using Dundas.Charting.WebControl;
using System.Data.OleDb;
namespace baoge
{
	/// <summary>
	/// voteview 的摘要说明。
	/// </summary>
	public class voteview : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button btnstart;
		protected System.Web.UI.WebControls.Button btnclose;
		protected Dundas.Charting.WebControl.Chart Chart1;
		private void Page_Load(object sender, System.EventArgs e)
		{
			string voteid=Request.QueryString["voteid"].ToString();
			string strconn="provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath("vote.Mdb")+";";
			string strsql="select votenum,vote,votetitle from vote where voteid="+voteid;
			OleDbConnection myConnection = new OleDbConnection(strconn);
			OleDbCommand myCommand = new OleDbCommand(strsql, myConnection);
			myConnection.Open();
			OleDbDataReader objDataReader = null;
			objDataReader=myCommand.ExecuteReader();
			objDataReader.Read();
			double[] data=new Double [50];
			string[] des=new String[50];
			string strvote=""; 
			strvote+=objDataReader["vote"]; 
			string strtitle="";
			strtitle+=objDataReader["votetitle"];
			string strvotenum=""; 
			strvotenum+=objDataReader["votenum"];
			string [] vote=strvote.Split('|');
			string [] votenum=strvotenum.Split('|');
			for(int i=0;i<vote.Length;i++)
			{
				data[i]=Convert.ToInt64(votenum[i]);
				des[i]=vote[i];
			}
			//			this.lbltitle.Text=strtitle;
			objDataReader.Close();
			myConnection.Close();
			
			// Add series to the chart
			Series series = Chart1.Series.Add("My series");

			// Set series visual attributes
			series.ChartType = "Pie";
			series.ShadowOffset = 2;
			series.BorderColor = Color.DarkGray;
			series.CustomAttributes = "LabelStyle=Outside";

			// Set series and legend tooltips
			series.ToolTip = "#VALX: #VAL{} 人投票";
			series.LegendToolTip = "#PERCENT";
			series.Href = "voteview.aspx?pointIndex=#INDEX";
			series.LegendHref = "voteview.aspx?pointIndex=#INDEX";
			//			Chart1.Title = "投票调查系统";
			Chart1.Title = strtitle;
			// Populate series data
			double[] yValues=data;
			string[] xValues=des;
			series.Points.DataBindXY(xValues, yValues);
			if(!this.IsPostBack)
			{
			   this.btnclose.Attributes.Add("onclick","window.close()");
			}

			// Explode selected slice
			if(this.Page.Request["pointIndex"] != null)
			{
				int pointIndex = int.Parse(this.Page.Request["pointIndex"]);
				if(pointIndex >= 0 && pointIndex < series.Points.Count)
				{
					series.Points[pointIndex].CustomAttributes += "Exploded=true";
				}
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnstart.Click += new System.EventHandler(this.btnstart_Click);
			this.btnclose.Click += new System.EventHandler(this.btnclose_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnstart_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("default.aspx");
		}

		private void btnclose_Click(object sender, System.EventArgs e)
		{
		
		}
	}
}
