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 System.Data.OleDb;

namespace baoge
{
	/// <summary>
	/// voteedit 的摘要说明。
	/// </summary>
	public class voteedit : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.TextBox txttitle;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.TextBox txtvote;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
		protected System.Web.UI.WebControls.Label Label3;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["AdminName"]==null)
			{
				Response.Redirect("admin/Admin_Login.aspx");
				
			}
			if(!this.IsPostBack)
			{
				this.bindto();
			}
		}


		private void bindto()
		{
			//			string content;
			//			content=content.Replace("|","/n");
			int ID=Convert.ToInt32(Request.QueryString["voteid"].Trim());
			string strConnection,strSQL;
			strConnection="provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath("vote.Mdb")+";";
			strSQL="select vote,votetitle,iscmd from vote where voteid="+ID;
			OleDbConnection objConnection=new OleDbConnection (strConnection);
			OleDbCommand objCommand = new OleDbCommand (strSQL,objConnection);
			OleDbDataReader objDataReader = null;
			objConnection.Open ();
			
			objDataReader=objCommand.ExecuteReader();
			string xiang="";
			string title="";
			while(objDataReader.Read())
			{

				title=objDataReader["votetitle"].ToString();
				xiang=objDataReader["vote"].ToString();
				if((bool)objDataReader["iscmd"])
				{
					RadioButtonList1.Items[0].Selected=true;
				}
				else
				{
					RadioButtonList1.Items[1].Selected=true;
				}
			}
			this.txttitle.Text=title;
			this.txtvote.Text=xiang.Replace("|","\n");
			//			objDataReader.Close();
			//			objConnection.Close();
		}

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

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			int ID=Convert.ToInt32(Request.QueryString["voteid"].Trim());
			string strConnection,strSQL;
			string suyuan=this.txtvote.Text.Replace("\n","|");
			strConnection="provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath("vote.Mdb")+";";
			strSQL="update vote set votetitle='"+this.txttitle.Text+"',vote='"+suyuan+"',iscmd="+this.RadioButtonList1.SelectedItem.Value+" where voteid="+ID;
			OleDbConnection objConnection=new OleDbConnection (strConnection);
			objConnection.Open();
			OleDbCommand objCommand = new OleDbCommand (strSQL,objConnection);
			objCommand.ExecuteNonQuery();
			Response.Write("<script>alert('公告成功更新');</script>");
		}

		private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int iscmd;
			if(RadioButtonList1.SelectedItem.Value=="1")
			{
				iscmd=1;
			}
			else
			{
				iscmd=0;
			}
		}
	}
}
