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

using Security;
namespace Security
{
    public partial class TreeUpdate : PageBase
    {
		MysqlHelp mh = null;
		DataTable dt = null;
		protected void Page_Load(object sender, EventArgs e)
		{
			if(!IsPostBack)
            {
				string updateID = Request.QueryString["updateID"];
				string updateName = Request.QueryString["updateName"];
				if(updateID != null && updateName != null){			
					///获取数据源
					mh = new MysqlHelp();
					dt = mh.GetDatabysql("Select * From Class4DeepSoon Where ID="+updateID);
					///获取的栏目外链地址
					this.txtOutLinkHref.Text = dt.Rows[0]["OutLinkHref"].ToString();
					///获取的栏目菜单状态：可见/隐藏
					string isHidden = dt.Rows[0]["isHidden"].ToString();
					if(isHidden == "True")
						this.dropIsHidden.SelectedIndex = 1;
					else this.dropIsHidden.SelectedIndex = 0;
					///设定栏目链接的打开方式
					string linkTarget = dt.Rows[0]["linkTarget"].ToString();
					ListItem linkTargetItem=this.dropLinkTarget.Items.FindByValue(linkTarget);
					if(linkTargetItem != null)
					{
						linkTargetItem.Selected = true;
					}
					///设定栏目的维护权限
					string openArea = dt.Rows[0]["openArea"].ToString();
					ListItem opentAreaItem=this.dropOpenArea.Items.FindByValue(openArea);
					if(opentAreaItem != null)
					{
						opentAreaItem.Selected = true;
					}
					///获取栏目模板
					this.txtThemeFile.Text = dt.Rows[0]["ThemeFile"].ToString();
					///初始化表单数据
					this.labelUpdateInfor.Text = "修改【"+updateName+"】栏目信息";
					this.txtName.Text = updateName;
						this.txtID.Text = updateID;
				}///end if
            }			
        }
		

		protected void btnUpdate_Click(object sender, EventArgs e)
		{
			string menuName = this.txtName.Text.Replace("'", "").Replace("\"", "").Replace(" ", "");
			if(menuName.Length>20)menuName = menuName.Substring(0,20);			
			string menuID = this.txtID.Text;
			string outLinkHref = this.txtOutLinkHref.Text.Replace("'", "").Replace("\"", "").Replace(" ", "");
			if(outLinkHref.Length>250)outLinkHref = outLinkHref.Substring(0,250);
			string isHidden = this.dropIsHidden.SelectedItem.Value;
			string linkTarget = this.dropLinkTarget.SelectedItem.Value;
			string openArea = this.dropOpenArea.SelectedItem.Value;
			string themeFile = this.txtThemeFile.Text.Replace("'", "").Replace("\"", "").Replace(" ", "");
			
			if(menuName!="" && menuID!="")///如果用户输入的参数没有空项
			{
				///创建数据连接对象：
				MysqlHelp mh = new MysqlHelp();
				///修改参数：
				mh.Runsql("Update Class4DeepSoon Set Name='"+menuName+"',OutLinkHref='"+outLinkHref+"',isHidden="+isHidden+",ThemeFile='"+themeFile+"',linkTarget='"+linkTarget+"',openArea='"+openArea+"' Where ID="+menuID);
				this.labelUpdateInfor.Text="栏目信息已经更新!";
				Response.Redirect("deepSoonTreeUpdate.aspx?updateID="+menuID+"&updateName="+menuName);	
			}
			else {
					this.labelUpdateInfor.Text="请将必填项填写完整!";
			}
			
		}

	}//end class
}//end nameSpace