using System;
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 System.IO;

public partial class admin_temp_list :Fm.Bussiness.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //创建一个DATATABLE用来存储文件数据
            DataTable dt = new DataTable();
            DataColumn dc = new DataColumn();
            dc.ColumnName = "file";
            dt.Columns.Add(dc);
            DataColumn dc1 = new DataColumn();
            dc1.ColumnName = "intro";
            dt.Columns.Add(dc1);

            string temp = "templates";
            if (Request.QueryString["temp"] != null)
            {
                temp = Request.QueryString["temp"].ToString();
            }
            //首先获取文件夹

            DirectoryInfo info = new DirectoryInfo(Server.MapPath("../" + temp));

            DirectoryInfo[] dir = info.GetDirectories();

            foreach (DirectoryInfo d in dir)
            {
               // Label1.Text = Label1.Text +">"+ d.Name;
                DataRow row = dt.NewRow();
                row["file"] = "<img src='skin/fold.gif' /><a href='temp_list.aspx?temp=" + temp + "/" + d.Name + "&id=" + Request.QueryString["id"].ToString()+ "'>" + d.Name + "</a>";
                row["intro"] = "模板文件夹";
                dt.Rows.Add(row);

                
            }
            //导航
            Label1.Text = temp ;
            //获取所有文件
            FileInfo[] files = info.GetFiles();

            foreach (FileInfo file in files)
            {
                if (file.Name.Contains(".htm")||file.Name.Contains(".html")||file.Name.Contains(".inc")||file.Name.Contains(".shtml"))
                {
                   
                    DataRow row = dt.NewRow();
                    row["file"] = "<img src='skin/htm.gif' /><a href='#' onclick=ok('"+temp+"/"+file.Name+"','"+Request.QueryString["id"].ToString()+"') >" + file.Name + "</a>";

                    string path = Server.MapPath("../" + temp + "/templist.inc");
                    if (File.Exists(path))
                    {
                        System.Text.Encoding en = System.Text.Encoding.GetEncoding("gb2312");
                        StreamReader stream = new StreamReader(path,en);

                        string str = "";
                        while ((str = stream.ReadLine())!=null)
                        {
                            string[] sp = str.Split(',');
                            if (sp[0] == file.Name)
                            {
                                row["intro"] = sp[1];

                            }
                        }
                    }
                    else
                    {
                        row["intro"] = "未知模板";
                    }
                    dt.Rows.Add(row);
                }
            }
            Repeater1.DataSource = dt;
            Repeater1.DataBind();
        }
    }
}
