using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//必须引入命名空间
using DotNet.FrameWork.Utils;
using DotNet.FrameWork.Common.Web;
using DotNet.FrameWork.Page;
using DotNet.FrameWork.Data;
using GetCommand;

namespace HteamDd.Web.Admin
{
    public partial class Admin_text_editor :BaseAdminUI
    {
        HaTeam.Dd.Model.Dd_Text model = new HaTeam.Dd.Model.Dd_Text();
        HaTeam.Dd.BLL.Dd_Text bll = new HaTeam.Dd.BLL.Dd_Text();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Fetch.Get("action") != null && Fetch.Get("text_id") != null) 
                { 
                    if(Fetch.Get("action").ToString()=="edit")
                    {
                        ShowInfo(int.Parse(Request.QueryString["text_id"].ToString()));
                    }
                }
                 
            }
        }
        public void ShowInfo(int id)
        {
            model = bll.GetModel(id);
            txtName.Text = Fetch.Get("user_name");
            txtTitle.Text = model.Text_Title;
            txtContent.Text = model.Text_Content;
            txtTag.Text = model.Text_Tag;
            rbtdelete2.Checked = true;
            if (model.Text_Verify ==0)
            {
                rbtVerity2.Checked = true;
            }
            else { rbtVerity1.Checked = true; }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int delete;
            int verify;
            if (this.txtContent.Text == "")
            {
                Jscript.Alert("内容不能为空！");
                this.txtContent.Focus();
            }
            else
            {
                string content = txtContent.Text;
               string tag = txtTag.Text;
               int textID = int.Parse(Fetch.Get("text_id"));
                if (rbtdelete1.Checked == true)
                {
                   delete = 1;
                }
                else { delete = 0; }
                if (rbtVerity2.Checked == true)
                {
                   verify = 0;
                 
                }
                else { verify = 1; }
                string str = "update dd_text set text_content ='"+ content +"',text_tag ='"+ tag +"',text_delete="+ delete +",text_verify ="+ verify+"where text_id ="+textID;
                try {
                    DbHelperSQL.ExecuteSql(str);
                    Jscript.AlertAndRedirect("系统提示：修改成功！", "Admin_text_manage.aspx");
                }
                catch(Exception ex){
                    Response.Write(ex);
                }
              
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            ShowInfo(int.Parse(Request.QueryString["text_id"].ToString()));
        }
    }
}