using System;
using System.Text;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using TopWinCMS.BLL;
using TopWinCMS.BLL.Common;
using TopWinCMS.Common;
using TopWinCMS.Model.Enum;
using TopWinCMS.Model;

namespace TopWinCMS.WebUI.Admin.Ask
{
    public partial class Answer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            AskInfo ask = new BLL.AskManage().EditLoad(int.Parse(Request.QueryString["AskID"]));
            List<AskInfo> list = new List<AskInfo>();
            list.Add(ask);
            RP_Ask.DataSource = list;
            RP_Ask.DataBind();


            RP_Answer.DataSource = new AnswerManage().GetList(int.Parse(Request.QueryString["AskID"]));
            RP_Answer.DataBind();
        }

        protected void RP_Ask_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "DeleteAsk")
            {
                string ID = e.CommandArgument.ToString();
                new BLL.AskManage().DeleteAndUndelete(ID, 0, UpdatePanel1);

                Bind();
            }
        }

        protected void RP_Answer_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "CaiNa")
            {
                string ID = e.CommandArgument.ToString();
                new AnswerManage().CaiNaiAnswer(int.Parse(Request.QueryString["AskID"]), int.Parse(ID), UpdatePanel1);

                Bind();
            }
            if (e.CommandName == "DelAnswer")
            {
                string ID = e.CommandArgument.ToString();

                new AnswerManage().Delete(int.Parse( Request.QueryString["AskID"]),ID, UpdatePanel1);

                Bind();

            }
        }
    }
}