using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using TopWinCMS.Model;
using TopWinCMS.BLL;
using TopWinCMS.Common;
namespace TopWinCMS.WebUI.Admin.Template
{
    public partial class HtmlTemplate_Add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                if (Request["Action"] == "Edit")
                {
                    RightsCheck.CheckWorkPower("T_3");
                    this.Title = "修改模板集";
                    TemplatesInfo model = new TemplatesManage().EditLoad(Request["ID"]);

                    TB_TemplateName.Text = model.TemplateName;
                    TB_TemplatePath.Text = model.TemplatePath;

                    TB_Style.Text = model.Style;
                    TB_Remark.Text = model.Remark;
                    TB_ArticleShow.Text = model.ArticleShow;
                    TB_ArticleClass.Text = model.ArticleClass;
                    TB_ArticleSpecial.Text = model.ArticleSpecial;
                    TB_ArticleChannelIndex.Text = model.ArticleChannelIndex;
                    TB_ArticleSpecialIndex.Text = model.ArticleSpecialIndex;

                    TB_SoftShow.Text = model.SoftShow;
                    TB_SoftClass.Text = model.SoftClass;
                    TB_SoftSpecial.Text = model.SoftSpecial;
                    TB_SoftChannelIndex.Text = model.SoftChannelIndex;
                    TB_SoftSpecialIndex.Text = model.SoftSpecialIndex;

                    TB_ProductShow.Text = model.ProductShow;
                    TB_ProductClass.Text = model.ProductClass;
                    TB_ProductSpecial.Text = model.ProductSpecial;
                    TB_ProductChannelIndex.Text = model.ProductChannelIndex;
                    TB_ProductSpecialIndex.Text = model.ProductSpecialIndex;

                    TB_ShopShow.Text = model.ShopShow;
                    TB_ShopClass.Text = model.ShopClass;
                    TB_ShopSpecial.Text = model.ShopSpecial;
                    TB_ShopChannelIndex.Text = model.ShopChannelIndex;
                    TB_ShopSpecialIndex.Text = model.ShopSpecialIndex;

                    TB_AskShow.Text = model.AskShow;
                    TB_AskClass.Text = model.AskClass;
                    TB_AskSpecial.Text = model.AskSpecial;
                    TB_AskChannelIndex.Text = model.AskChannelIndex;
                    TB_AskSpecialIndex.Text = model.AskSpecialIndex;


                    LB_Path2.Text = Config.SiteName + " → <A href=\"HtmlTemplateList.aspx\">模板集管理</A> → 修改模板集";
                }
                else
                {
                    RightsCheck.CheckWorkPower("T_1");

                    this.Title = "添加模板集";
                    LB_Path2.Text = Config.SiteName + " → <A href=\"HtmlTemplateList.aspx\">模板集管理</A> → 添加模板集";
                }

            }
        }
        private void Add()
        {

            TemplatesInfo model = new TemplatesInfo();
            model.TemplateName = TB_TemplateName.Text.Trim();
            model.TemplatePath = TB_TemplatePath.Text.Trim();

            model.Style = TB_Style.Text.Trim();
            model.Remark = TB_Remark.Text.Trim();
            model.ArticleShow = TB_ArticleShow.Text.Trim();
            model.ArticleClass = TB_ArticleClass.Text.Trim();
            model.ArticleSpecial = TB_ArticleSpecial.Text.Trim();
            model.ArticleChannelIndex = TB_ArticleChannelIndex.Text.Trim();
            model.ArticleSpecialIndex = TB_ArticleSpecialIndex.Text.Trim();

            model.SoftShow = TB_SoftShow.Text.Trim();
            model.SoftClass = TB_SoftClass.Text.Trim();
            model.SoftSpecial = TB_SoftSpecial.Text.Trim();
            model.SoftChannelIndex = TB_SoftChannelIndex.Text.Trim();
            model.SoftSpecialIndex = TB_SoftSpecialIndex.Text.Trim();

            model.ProductShow = TB_ProductShow.Text.Trim();
            model.ProductClass = TB_ProductClass.Text.Trim();
            model.ProductSpecial = TB_ProductSpecial.Text.Trim();
            model.ProductChannelIndex = TB_ProductChannelIndex.Text.Trim();
            model.ProductSpecialIndex = TB_ProductSpecialIndex.Text.Trim();

            model.ShopShow = TB_ShopShow.Text.Trim();
            model.ShopClass = TB_ShopClass.Text.Trim();
            model.ShopSpecial = TB_ShopSpecial.Text.Trim();
            model.ShopChannelIndex = TB_ShopChannelIndex.Text.Trim();
            model.ShopSpecialIndex = TB_ShopSpecialIndex.Text.Trim();

            model.AskShow = TB_AskShow.Text.Trim();
            model.AskClass = TB_AskClass.Text.Trim();
            model.AskSpecial = TB_AskSpecial.Text.Trim();
            model.AskChannelIndex = TB_AskChannelIndex.Text.Trim();
            model.AskSpecialIndex = TB_AskSpecialIndex.Text.Trim();


            if (Request["ID"] == null)
            {
                model.ID = "0";
            }
            else if (Request["ID"] != null && Request["Action"] == "Edit")
            {
                model.ID = Request["ID"];
            }
            string strErr = null;
            new TemplatesManage().Add(model, ref strErr);

            if (string.IsNullOrEmpty(strErr) == false)
            {
                MsgBox.Alert(strErr.ToString(), UpdatePanel1);

            }
            else
            {
                Response.Redirect("HtmlTemplateList.aspx");

            }
        }

        protected void BT_Add_Click(object sender, EventArgs e)
        {
            Add();
        }
    }
}
