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_AddSystemBase 的摘要说明。
	/// </summary>
	public class Admin_AddSystemBase : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox WebName;
		protected System.Web.UI.WebControls.TextBox WebUrl;
		protected System.Web.UI.WebControls.TextBox WebLogo;
		protected System.Web.UI.WebControls.TextBox WebEmail;
		protected System.Web.UI.WebControls.TextBox CAddress;
		protected System.Web.UI.WebControls.TextBox CTel;
		protected System.Web.UI.WebControls.TextBox CQQ;
		protected System.Web.UI.WebControls.Button Submit;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.TextBox Webcopyright;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面

			if(Session["AdminName"]==null)
			{
			Response.Redirect("Admin_Login.aspx");
			
			}

		}

		#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();
				//判断名称是否已存在
				string ACsql1="select ID from Config where WebName='"+WebName.Text+"'";
				OleDbCommand ACcomm1=new OleDbCommand(ACsql1,ACconn);
				OleDbDataReader ACdr1=ACcomm1.ExecuteReader();
				if(ACdr1.Read())
				{
					Response.Redirect("Admin_EditSystemBase.aspx");
				}
				else
				{
					
					ACdr1.Close();
					//定义所需SQL
					string ACsql="insert into Config (WebName,WebUrl,WebLogo,WebEmail,CAddress,CTel,CQQ,Webcopyright) values ('"+WebName.Text+"','"+WebUrl.Text+"','"+WebLogo.Text+"','"+WebEmail.Text+"','"+CAddress.Text+"','"+CTel.Text+"','"+CQQ.Text+"','"+Webcopyright.Text+"')";
					//创建Command对像
					OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
					ACcomm.ExecuteNonQuery();
					Response.Write("<script>alert('信息成功添加');</script>");
					
				}

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

		}
	}
}
