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_reply_edit :BaseAdminUI
    {
        HaTeam.Dd.BLL.Dd_Reply bll = new HaTeam.Dd.BLL.Dd_Reply();
        HaTeam.Dd.Model.Dd_Reply model = new HaTeam.Dd.Model.Dd_Reply();
        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["reply_id"].ToString()));
                    }
                }

            }
        }
        public void ShowInfo(int id)
        {
            model = bll.GetModel(id);
            txtName.Text = GetNameByID();
            txtContent.Text = model.Reply_Content;
            txtType.Text = GetTypeByValue();
            if (model.Reply_Verify == 0)
            {
                rbtVerity1.Checked = true;
            }
            else { rbtVerity2.Checked = true; }
            rbtdelete2.Checked = true;
        }
        /// <summary>
        /// 根据id获得博客名
        /// </summary>
        /// <returns></returns>
        public string GetNameByID()
        {
            string str = "select user_blogname from dd_user where user_id =" + int.Parse(Fetch.Get("reply_userid"));
            string idna = Convert.ToString(DbHelperSQL.GetSingle(str));
            return idna;
        }
        public string GetTypeByValue()
        {
            string name = "";
            string val = Fetch.Get("reply_type");
            if (val == "0")
            {
                name = "文章";
            }
            else if (val == "1")
            {
                name = "图片";
            }
            else if (val == "2")
            {
                name = "音乐";
            }
            else if (val == "3")
            {
                name = "链接";
            }
            else if (val == "4")
            {
                name = "视频";
            }
            return name;
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int delete;
            int verify;
            if (this.txtContent.Text == "")
            {
                Jscript.Alert("内容不能为空！");
                this.txtContent.Focus();
            }
            else
            {
                int replyid = int.Parse(Fetch.Get("reply_id"));
                string content = txtContent.Text;
               
                //model.Reply_UserID = int.Parse(Fetch.Get("reply_userid"));
                //model.Reply_ArticleID = Fetch.Get("reply_articleid");
                //model.Reply_Content = txtContent.Text;
                //model.Reply_Type = int.Parse(Fetch.Get("reply_type"));
                //model.Reply_ID = int.Parse(Fetch.Get("reply_id"));
                if (rbtdelete1.Checked == true)
                {
                    //model.Reply_Delete = 1;
                    delete = 1;
                }
                else {  delete = 0; }
                if (rbtVerity2.Checked == true)
                {
                //    model.Reply_Verify = 0;
                    verify = 0;
                }
                else { verify = 1; }
                string str = "update dd_reply set reply_content ='"+ content +"',reply_delete ="+ delete +",reply_verify ="+ verify +"where reply_id ="+ replyid;
                try
                {
                    DbHelperSQL.ExecuteSql(str);

                    //bll.Update(model);
                    Jscript.AlertAndRedirect("系统提示：修改成功！", "Admin_reply_manage.aspx");
                }
                catch (Exception ex)
                {

                    Response.Write(ex);
                }

            }
        }
    }
}