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

namespace TopWinCMS.WebUI.Admin.Ask
{
    public partial class EditInfo : System.Web.UI.Page
    {

        private string UrlReferrer
        {
            set
            {
                ViewState["UrlReferrer"] = value;
            }
            get
            {
                return ViewState["UrlReferrer"].ToString();
            }
        }
        protected string AutoTitle;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                UrlReferrer = Request.UrlReferrer.ToString();
                if (Request.QueryString["AskID"] != null)
                {
                    AutoTitle = "修改问题";
                    new ClassManage().BindDDL(DDL_ClassID, Class_BindOption.NoLink, "<请选择>", int.Parse(Request["ModelID"]));

                    AskInfo model = new BLL.AskManage().EditLoad(int.Parse(Request.QueryString["AskID"]));
                    DDL_ClassID.SelectedValue = model.ClassID.ToString();
                    TB_Title.Text = model.Title;
                    DDL_FontStyle.SelectedValue = model.FontStyle;
                    TB_ColorStyle.Text = model.ColorStyle;
                    CB_ContentPass.Checked = model.Pass == 1 ? true : false; ;
                    CB_Elite.Checked = model.Elite == 1 ? true : false; ;
                    CB_OnTop.Checked = model.OnTop == 1 ? true : false; ;
                    CE_Content.Text = model.Content;
                }
                if (Request.QueryString["AnswerID"] != null)
                {
                    AutoTitle = "修改答案";
                    tr_1.Visible = false; tr_2.Visible = false; tr_3.Visible = false;

                    AnswerInfo model = new AnswerManage().EditLoad(Request.QueryString["AnswerID"]);
                    CE_Content.Text = model.Content;

                }
            }
        }

        protected void BT_Edit_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["AskID"] != null)
            {
                AskInfo model = new AskInfo();
                model.ID = int.Parse(Request.QueryString["AskID"]);
                model.ClassID = int.Parse(DDL_ClassID.SelectedValue);
                model.Title = TB_Title.Text;
                model.FontStyle = DDL_FontStyle.SelectedValue;
                model.ColorStyle = TB_ColorStyle.Text.Trim();
                model.Pass = CB_ContentPass.Checked == true ? 1 : 0; ;
                model.Elite = CB_Elite.Checked == true ? 1 : 0; ;
                model.OnTop = CB_OnTop.Checked == true ? 1 : 0; ;
                model.Content = CE_Content.Text.Trim();

                string Err = null;
                new BLL.AskManage().Add(model, new List<string>(), new List<object>(), ref Err);

                if (string.IsNullOrEmpty(Err) == false)
                {
                    MsgBox.Alert(Err, UpdatePanel1);
                }
                else
                {
                    MsgBox.Alert("操作完成", UrlReferrer, UpdatePanel1);
                }
            }
            if (Request.QueryString["AnswerID"] != null)
            {
                AnswerInfo model = new AnswerInfo();
                model.ID = int.Parse(Request.QueryString["AnswerID"]);
                model.Content = CE_Content.Text.Trim();

                string Err = null;
                new AnswerManage().Add(model, ref Err);

                if (string.IsNullOrEmpty(Err) == false)
                {
                    MsgBox.Alert(Err, UpdatePanel1);
                }
                else
                {
                    MsgBox.Alert("操作完成", UrlReferrer, UpdatePanel1);
                }
            }
        }


        protected void TB_CheckTitle_Click(object sender, EventArgs e)
        {

        }


    }
}
