using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.IO;
using System.Data;
using Fm.Bussiness;
namespace Fm.Tags
{
    public class Temp_Index:System.Web.UI.Page
    {
        //Temp_Tags tag = new Temp_Tags();
       // IOStream stream = new IOStream();
        public_select ps = new public_select();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ATL.IO.IOStream stream = new ATL.IO.IOStream();
                //判断是否已经安装
                string stall = stream.ReadFile(Server.MapPath("config/stall.txt"));
                if (stall.Contains("1"))
                {
                    string temp = Server.MapPath("./templates/");
                    //获取默认首页模板
                    Xml_work xml=new Xml_work();
                    DataTable dt = xml.Xml_Reader(Server.MapPath("config/templates.xml"),"templates");
                    string path="";
                    if (dt.Rows.Count > 0)
                    {
                        path = dt.Rows[0]["index"].ToString();
                    }
                    else
                    {
                        path = "default/index.htm";
                    }
                    Response.Write(Get_Index(temp,path));
                }
                else
                {
                    Response.Write("<script>alert('您还没有进行系统安装!系统将会自动跳转到安装页面!');window.location.href='install/Default.aspx'</script>");
                }
            }
        }

        public string Get_Index(string temp,string path)
        {
            Fm.Tags.GlobalTags gb = new GlobalTags();

            ATL.IO.IOStream stream = new ATL.IO.IOStream();
            string content = stream.ReadFile(temp+path);
            //解析页面导入标签
            content = gb.Analysis_Include(content, temp);
           // string content = index;
            //栏目标签解析
            content = gb.Analysis_Column(content,0);
            //获取头部三个标签(标题,关键字,描述)数据
            DataView dv = ps.Getps("Fm_webset", "title,keyword,intro","") as DataView;
            //导航解析
            string sitemap = gb.Analysis_Sitemap(0);
            //公共独立标签解析
             
            content =gb.Analysis_Global(dv[0]["title"].ToString(),dv[0]["keyword"].ToString(),dv[0]["intro"].ToString(),content,sitemap);
            content = gb.Analysis_Channels(content,0);
            content = gb.Analysis_Article(content,0);
            content = gb.Analysis_Link(content);
            content = gb.Analysis_Freedom(content);
            //广告标签
            Fm.Tags.AdTags ad=new AdTags();
            content = ad.Analysis_Ad(content);

            //友情连接标签解析
            //content = tag.Get_Link(content);
            //公告标签解析
            //content = tag.Get_Affiche_list(content);

            return content;
        }
    
    }
}
