using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Text;
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 Fm.Tags;
using System.IO;
using System.Text.RegularExpressions;

public partial class model_article_add : Fm.Bussiness.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //获取栏目值
            Fm.Bussiness.public_select ps = new Fm.Bussiness.public_select();


            ColumnBind();

            
            //作者
            Drop_author.DataSource = ps.Getps("Fm_author", "*", "");
            Drop_author.DataTextField = "au_name";
            Drop_author.DataValueField = "au_name";
            Drop_author.DataBind();
            //来源
            Drop_source.DataSource = ps.Getps("Fm_source", "*", "");
            Drop_source.DataTextField = "so_name";
            Drop_source.DataValueField = "so_name";
            Drop_source.DataBind();

            if (Request.QueryString["cl_id"] != null)
            {
                foreach (ListItem item in Drop_column.Items)
                {
                    if(item.Value == Request.QueryString["cl_id"].ToString())
                    {
                        item.Selected = true;
                    }
                }
            }
        }
    }
    //绑定栏目的方法
    void ColumnBind()
    {
        //绑定栏目信息
        Fm.Bussiness.Column cn = new Fm.Bussiness.Column();
        cn.GetColumns(Drop_column);

        //添加第一个栏目
        ListItem item = new ListItem();
        item.Text = "请选择栏目";
        item.Value = "0";

        Drop_column.Items.Insert(0, item);
    }
    /// <summary>
    /// 文档数据的添加
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void bt_save_Click(object sender, ImageClickEventArgs e)
    {
       
           
            //主表数据的添加
            Fm.Bussiness.model_main buss = new Fm.Bussiness.model_main();
            //模型基表数据处理
            Fm.EntityClass.model_main model = new Fm.EntityClass.model_main();
            model.title = doctitle.Text;
            if (head.Checked)
            {
                model.head = true;
            }
            else
            {
                model.head = false;
            }
            if (map.Checked)
            { model.map = true; }
            else
            { model.map = false; }
            if (flash.Checked)
            { model.flash = true; }
            else
            { model.flash = false; }
            if (commend.Checked)
            { model.commend = true; }
            else
            {
                model.commend = false;
            }

            model.bold = false;
            model.colid = int.Parse(Drop_column.SelectedValue);
            //model.mid = 1;
            model.thumbnail = thumbnail.Value;
            model.writertime = DateTime.Now;
            if (Session["uname"] != null)
            {
                model.username = Session["uname"].ToString();
            }
            model.click = int.Parse(click.Text);
            model.audit = true;
            if (comment.Checked)
            { model.comment = true; }
            else
            {
                model.comment = false;
            }
            model.color = getcolor.Text;
            model.keyword = keywords.Text;
            model.intro = intro.Text;
            if (html_true.Checked)
            {
                model.html = true;
            }
            if (html_false.Checked)
            {
                model.html = false;
            }
            model.topclick = 0;
            model.tread = 0;


            int docid = buss.model_main_add(model);


            //内容处理
            Fm.EntityClass.model_article article = new Fm.EntityClass.model_article();
            article.docid = docid;
            article.content = FCKeditor1.Value;
            article.author = author.Text;
            article.source = source.Text;
            if (buss.model_article_add(article))
            {
                //判断是否选择了静态生成
                if (html_true.Checked == true)
                {
                    //实例化静态文档写入类
                    Fm.Tags.HtmlWrite html = new Fm.Tags.HtmlWrite();
                    html.WriteContent(docid);
                }
                Response.Redirect("Erro.aspx?eid=新文章发布成功!&url=model_article_add.aspx", true);
            }
  
    
          
    }
   
}
