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 SK.MemberBLL;

namespace SK.MemberWeb.admin
{
	/// <summary>
	/// CustomText_Edit 的摘要说明。
	/// </summary>
	public class CustomText_Edit : BasePage
	{
		protected System.Web.UI.WebControls.Button btnSave;
		protected System.Web.UI.WebControls.TextBox txtName;
		CustomTextSystem txt = new CustomTextSystem();
		WebLogSystem log = new WebLogSystem();
		protected CuteEditor.Editor Content;
		RightMemberSystem rightmember = new RightMemberSystem();
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			btnSave.Attributes["onclick"]="return Check_Input();";
			if(!IsPostBack)
			{
				if(!rightmember.Allow(0,"CustomText",this.CurrentMemberID))
					Response.Redirect("noright.aspx");

				ViewState["CustomTextID"] = Request.QueryString["id"];
				BindData();

				Content.ConfigurationPath = this.Root+"admin/images/BackGround.config";
				Content.SetSecurityGalleryPath("~/upload");
				Content.SetSecurityReadWriteAll();
			}
		}

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

		}
		#endregion
		private void BindData()
		{
			DataRow dr = txt.Info(ViewState["CustomTextID"]);
			txtName.Text = dr["CustomName"].ToString();
			Content.Text = dr["Content"].ToString();
			
		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			txt.Update(ViewState["CustomTextID"],txtName.Text,Content.Text);
			log.Add(this.CurrentMemberID,"编号[自定义文本]，编号为："+ViewState["CustomTextID"],WebLogType.Update);
			this.AlertAndRedir("保存成功，确认后返回自定义文本列表","CustomTexts.aspx");
		}
	}
}
