using System;
using TopWinCMS.BLL;
using TopWinCMS.Model;
using TopWinCMS.Model.Enum;
namespace TopWinCMS.WebUI.Admin
{
    /// <summary>
    /// ArticleGather_Add 的摘要说明。
    /// </summary>
    public partial class ArticleGather_Add : System.Web.UI.Page
    {
        ArticleGatherManage MyClassBLL = new ArticleGatherManage();
        protected ArticleGatherInfo model = new ArticleGatherInfo();

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                MyClassBLL.Copy(DDL_Gather);
                Bt_GatherAdd.Attributes.Add("onclick", "return CheckForm();");
                if (Request.QueryString["id"] != null)//修改界面
                {
                    RightsCheck.CheckWorkPower("GatherEdit");
                    new ClassManage().BindDDL(DDL_ArticleClass, Class_BindOption.NoLink, "<请选择栏目>", int.Parse(Request["ModelID"]));
                    Bind(int.Parse(Request.QueryString["id"]));
                }
                else
                {
                    RightsCheck.CheckWorkPower("GatherAdd");
                    new ClassManage().BindDDL(DDL_ArticleClass, Class_BindOption.NoLink, "<请选择栏目>", int.Parse(Request["ModelID"]));
                }
            }
        }
        protected void Bt_GatherAdd_Click(object sender, EventArgs e)
        {

            if (Request.QueryString["id"] == null)
            {
                model.Name = TB_GatherName.Text;
                model.StartUrl = TB_StartUrl.Text;
                model.ClassArea = TB_ClassArea.Text;
                model.ClassNextPage = TB_ClassNextPage.Text;
                model.ClassPrePage = TB_ClassPrePage.Text;
                model.ClassLastPage = TB_ClassLastPage.Text;
                model.IsLastPageUrl = CB_IsLastPageUrl.Checked == true ? 1 : 0;
                model.ShowArticleUrl = TB_ShowArticleUrl.Text;
                model.Title = TB_Title.Text;
                model.Content = TB_Content.Text;
                model.ShowArticleNextUrl = TB_ShowArticleNextUrl.Text;
                model.ComeFrom = TB_From.Text;
                model.Author = TB_Author.Text;
                model.UpdateTime = TB_Date.Text;
                model.Filter = TB_Filter.Text;
                model.GatherNum = int.Parse(NT_Num.Text);
                model.DownImg = RBL_DownImg.Items[0].Selected == true ? 1 : 0;
                model.ClassID = int.Parse(DDL_ArticleClass.SelectedValue);
                model.Pass = RBL_Pass.Items[0].Selected == true ? 1 : 0;
                model.Replace = TB_Replace.Text;
                model.GatherPicArticle = RBL_GatherPicArticle.Items[0].Selected == true ? 1 : 0;
                model.DrawWaterMark = RBL_DrawWaterMark.Items[0].Selected == true ? 1 : 0;
                model.IsExpert = CB_IsExpert.Checked == true ? 1 : 0;
                model.IsReverse = CB_IsReverse.Checked == true ? 1 : 0;

                MyClassBLL.Add(model, UpdatePanel1);
            }
            else
            {
                model.ID = int.Parse(Request.QueryString["ID"]);
                model.Name = TB_GatherName.Text;
                model.StartUrl = TB_StartUrl.Text;
                model.ClassArea = TB_ClassArea.Text;
                model.ClassNextPage = TB_ClassNextPage.Text;
                model.ClassPrePage = TB_ClassPrePage.Text;
                model.ClassLastPage = TB_ClassLastPage.Text;
                model.IsLastPageUrl = CB_IsLastPageUrl.Checked == true ? 1 : 0;
                model.ShowArticleUrl = TB_ShowArticleUrl.Text;
                model.Title = TB_Title.Text;
                model.Content = TB_Content.Text;
                model.ShowArticleNextUrl = TB_ShowArticleNextUrl.Text;
                model.ComeFrom = TB_From.Text;
                model.Author = TB_Author.Text;
                model.UpdateTime = TB_Date.Text;
                model.Filter = TB_Filter.Text;
                model.GatherNum = int.Parse(NT_Num.Text);
                model.DownImg = RBL_DownImg.Items[0].Selected == true ? 1 : 0;
                model.ClassID = int.Parse(DDL_ArticleClass.SelectedValue);
                model.Pass = RBL_Pass.Items[0].Selected == true ? 1 : 0;
                model.Replace = TB_Replace.Text;
                model.GatherPicArticle = RBL_GatherPicArticle.Items[0].Selected == true ? 1 : 0;
                model.DrawWaterMark = RBL_DrawWaterMark.Items[0].Selected == true ? 1 : 0;
                model.IsExpert = CB_IsExpert.Checked == true ? 1 : 0;
                model.IsReverse = CB_IsReverse.Checked == true ? 1 : 0;

                MyClassBLL.Edit(model, UpdatePanel1);
            }

        }


        private void Bind(int ID)
        {
            model = MyClassBLL.EditLoad(ID);

            TB_GatherName.Text = model.Name;
            TB_StartUrl.Text = model.StartUrl;
            TB_ClassArea.Text = model.ClassArea;
            TB_ClassNextPage.Text = model.ClassNextPage;
            TB_ClassPrePage.Text = model.ClassPrePage;
            TB_ClassLastPage.Text = model.ClassLastPage;
            CB_IsLastPageUrl.Checked = model.IsLastPageUrl == 1 ? true : false;
            TB_ShowArticleUrl.Text = model.ShowArticleUrl;
            TB_Title.Text = model.Title;
            TB_Content.Text = model.Content;
            TB_ShowArticleNextUrl.Text = model.ShowArticleNextUrl;
            TB_From.Text = model.ComeFrom;
            TB_Author.Text = model.Author;
            TB_Date.Text = model.UpdateTime;
            TB_Filter.Text = model.Filter;
            NT_Num.Text = model.GatherNum.ToString();
            RBL_DownImg.Items[0].Selected = model.DownImg == 1 ? true : false;
            RBL_DownImg.Items[1].Selected = !RBL_DownImg.Items[0].Selected;
            RBL_Pass.Items[0].Selected = model.Pass == 1 ? true : false;
            RBL_Pass.Items[1].Selected = !RBL_Pass.Items[0].Selected;
            RBL_GatherPicArticle.Items[0].Selected = model.GatherPicArticle == 1 ? true : false;
            RBL_GatherPicArticle.Items[1].Selected = !RBL_GatherPicArticle.Items[0].Selected;
            RBL_DrawWaterMark.Items[0].Selected = model.DrawWaterMark == 1 ? true : false;
            RBL_DrawWaterMark.Items[1].Selected = !RBL_DrawWaterMark.Items[0].Selected;
            CB_IsExpert.Checked = model.IsExpert == 1 ? true : false;
            DDL_ArticleClass.SelectedValue = model.ClassID.ToString();
            TB_Replace.Text = model.Replace + "\r\n";
            CB_IsReverse.Checked = model.IsReverse == 1 ? true : false;

        }


        protected void Ddl_Gather_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (int.Parse(DDL_Gather.SelectedValue) > 0)
            {
                Bind(int.Parse(DDL_Gather.SelectedValue));

                TB_GatherName.Text = string.Empty;
                TB_StartUrl.Text = string.Empty;
            }
        }
    }
}