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_Addgs 的摘要说明。
	/// </summary>
	public class Admin_Addgs : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtwebname;
		protected System.Web.UI.WebControls.TextBox txtweburl;
		protected System.Web.UI.WebControls.TextBox txtweblogo;
		protected System.Web.UI.WebControls.TextBox txtmail;
		protected System.Web.UI.WebControls.TextBox txtadress;
		protected System.Web.UI.WebControls.TextBox txttel;
		protected System.Web.UI.WebControls.TextBox txtqq;
		protected System.Web.UI.WebControls.TextBox txtcopyright;
	    public string webname,weburl,weblogo,mail,address,tel,qq,copyright,jj;
		public string ACsql,bodystr;
		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.RequiredFieldValidator RequiredFieldValidator3;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator5;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator6;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator7;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator8;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator3;
		protected CuteEditor.Editor Editor1;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator4;

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


		private void CDataBind()
		{
			//取得数据库路径
			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

				//定义SQL语句
				string ACsql="select * from Config where ID=1";
				//创建Command对像
				OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
				//通过执行Command实例化DataReader类
				OleDbDataReader ACdr=ACcomm.ExecuteReader();
//				copyright = System.Text.RegularExpressions.Regex.Replace(copyright,@"\[url=(?<x>[^\]]*)\](?<y>[^\]]*)\[/url\]",@"<a href=$1 target=_blank>$2</a>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
				if(ACdr.Read())
				{
					//					Cjj.Text=ACdr["Cjj"].ToString();
//					suyuan="网站名称："+ACdr["WebName"].ToString()+"<br>"+"网站地址："+ACdr["WebUrl"].ToString()+"<br>"+"网站LOGO："+ACdr["WebLogo"].ToString()+"<br>"+"电子邮箱："+ACdr["WebEmail"].ToString()+"<br>"+"联系地址："+ACdr["CAddress"].ToString()+"<br>"+"联系电话："+ACdr["CTel"].ToString()+"<br>"+"ＯＩＣＱ："+ACdr["CQQ"].ToString()+"<br>"+"版权信息："+ACdr["WebCopyRight"].ToString()+"<br>"+"网站简介："+ACdr["Cjj"].ToString();
                     
					//          			ACdr.Close();
					webname=ACdr["WebName"].ToString();
					weburl=ACdr["WebUrl"].ToString();
					weblogo=ACdr["WebLogo"].ToString();
					mail=ACdr["WebEmail"].ToString();
					address=ACdr["CAddress"].ToString();
					tel=ACdr["CTel"].ToString();
                    qq=ACdr["CQQ"].ToString();
					copyright=ACdr["WebCopyRight"].ToString();
					jj=ACdr["Cjj"].ToString();
				}
				else
				{
					Response.Write("对不起，请先填加相关内容");
				}
			this.txtwebname.Text=webname;
			this.txtweburl.Text=weburl;
			this.txtweblogo.Text=weblogo;
			this.txtmail.Text=mail;
			this.txtadress.Text=address;
			this.txttel.Text=tel;
		    this.txtqq.Text=qq;
			this.txtcopyright.Text=copyright;
			this.Editor1.Text=jj;
			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();
				//定义所需SQL
				ACsql="Update  Config set  WebName='"+this.txtwebname.Text+"',WebUrl='"+this.txtweburl.Text+"',WebLogo='"+this.txtweblogo.Text+"',WebEmail='"+this.txtmail.Text+"',CAddress='"+this.txtadress.Text+"',CTel='"+this.txttel.Text+"',CQQ='"+this.txtqq.Text+"',WebCopyRight='"+this.txtcopyright.Text+"',Cjj='"+this.Editor1.Text+"' where ID=1";

				//创建Command对像
				OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
				ACcomm.ExecuteNonQuery();
				Response.Write("<script>alert('个人资料更新成功');</script>");
				//Response.Write(bodystr);


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