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.Admin
{
	/// <summary>
	/// Admin_EditClass 的摘要说明。
	/// </summary>
	public class Admin_EditClass : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox ClassName;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.TextBox ReadMe;
		protected System.Web.UI.WebControls.Label OpenType;
		protected System.Web.UI.WebControls.Label ModuleType;
		protected System.Web.UI.WebControls.Button Submit;
	    public int CID;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(Session["AdminName"]==null)
			{
				Response.Redirect("Admin_Login.aspx");
			}
			if(!IsPostBack)
			{
				EditClassDataBind();
			}
		}

		private void EditClassDataBind()
		{
			//取得数据库路径
			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
			//定义数据库连接字符串
			string ACconnStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(dbPath);
			//创建数据库对象
			OleDbConnection ACconn=new OleDbConnection(ACconnStr);
			try
			{
			ACconn.Open();
				//取得所需操作记录ID
				string ClassID=Request.QueryString["ClassID"].Trim();
				CID=Convert.ToInt32(ClassID);
				
				//定义SQL
				string ACsql="select ClassID,ClassName,ReadMe,ParentID,OpenType,ModuleType from Class where ClassID="+CID;
				//创建Command对像
				OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
				//通过执行Command对像实例化DataReader类
				OleDbDataReader ACdr=ACcomm.ExecuteReader();
				if(ACdr.Read())
				{
					ClassName.Text=ACdr["ClassName"].ToString();
					ReadMe.Text=ACdr["ReadMe"].ToString();
					
					if (ACdr["OpenType"].ToString()=="0")
					{
						OpenType.Text="原窗口打开";

					}
					else
					{
						OpenType.Text="新窗口打开";
					}
					
					if(ACdr["ModuleType"].ToString()=="1")
					{
						ModuleType.Text="信息";
					}
					else if(ACdr["ModuleType"].ToString()=="2")
					{
						ModuleType.Text="下载";
					}
					else
					{
						ModuleType.Text="产品";

					}
					ACdr.Close();

				}
				

			}
			catch(Exception ex)
			{
			Response.Write(ex.ToString());
			}
			finally
			{
			ACconn.Close();
			}
		
		
		}

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

		}
		#endregion

		private void Submit_Click(object sender, System.EventArgs e)
		{
			//取得数据库路径
			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
			//定义数据库连接字符串
			string ACconnStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(dbPath);
			//创建数据库对象
			OleDbConnection ACconn=new OleDbConnection(ACconnStr);
			try
			{
				ACconn.Open();
				//取得所需操作记录ID
				string ClassID=Request.QueryString["ClassID"].Trim();
				CID=Convert.ToInt32(ClassID);
				
				//定义SQL
				string ACsql="update Class set ClassName='"+ClassName.Text+"',ReadMe='"+ReadMe.Text+"' where ClassID="+CID;
				//创建Command对像
				OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
				ACcomm.ExecuteNonQuery();
				Response.Write("<script>alert('栏目修改成功');</script>");
				Response.Write("<script>history.go(-2);</script>");

				
			}
			catch(Exception ex)
			{
				Response.Write(ex.ToString());
			}
			finally
			{
				ACconn.Close();
			}
		}
	}
}
