using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
using System.Web.Configuration;

using Security;
namespace Security
{
    public partial class AdAdmin : PageBase
    {
		protected void Page_Load(object sender, EventArgs e)
        {
		string AdName = Request.QueryString["AdName"];
		this.labelAdName.Text = AdName;
		if(!IsPostBack){
			///创建数据连接对象：
			MysqlHelp mh = new MysqlHelp();
			///查询数据库
			DataTable dt=new DataTable();
			string AdPos = Request.QueryString["AdPos"];
			dt = mh.GetDatabysql("Select * From AdList4DeepSoon Where AdPos = '"+AdPos+"'");
			string ContentStr = "";
			string PosStr = "";
			if(dt.Rows.Count > 0 ){
				ContentStr = dt.Rows[0]["AdContent"].ToString();
				PosStr = dt.Rows[0]["AdPos"].ToString();
			}
			else {
				string insertTopSQLStr = "insert into AdList4DeepSoon(AdContent,AdPos) Values('<img src=\"System_Img/allAd.jpg\" title=\"全站顶部广告\">','allTop')";
				mh.Runsql(insertTopSQLStr);
				string insertIndexSQLStr = "insert into AdList4DeepSoon(AdContent,AdPos) Values('<img src=\"System_Img/indexAd.jpg\" title=\"首页左栏广告\">','indexLeft')";
				mh.Runsql(insertIndexSQLStr);
				string insertViewSQLStr = "insert into AdList4DeepSoon(AdContent,AdPos) Values('<img src=\"System_Img/viewAd.jpg\" title=\"正文右栏广告\">','viewRight')";
				mh.Runsql(insertViewSQLStr);
				ContentStr = "<img src=\"System_Img/allAd.jpg\" title=\"全站顶部广告\">";
				PosStr = "allTop";
			}
			
			this.AdContent.Text = ContentStr;
			this.AdPos.Text = PosStr;
		}
        }
		
		protected void btnUpdate_Click(object sender, EventArgs e)
        {
			///获取用户输入的新的数据：
			string ContentStr = this.AdContent.Text.Replace("'", "").Replace("select", "").Replace("delete", "").Replace("update", "").Replace("insert", "");
			
			string PosStr = this.AdPos.Text.Replace("'", "").Replace("select", "").Replace("delete", "").Replace("update", "").Replace("insert", "");
			
			if(PosStr!="")///如果用户输入的参数没有空项
			{
				///创建数据连接对象：
				MysqlHelp mh = new MysqlHelp();
				///修改参数：
				mh.Runsql("Update AdList4DeepSoon Set AdContent='"+ContentStr+"' Where AdPos = '"+PosStr+"'");
				
				this.labelUpdateInfor.Text="广告设置成功!";
					
			}///end If
		}///end btnUpdate_Click
	}
}