using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using ptw.FileManager.Model;
//using ptw.FileManager.Web.Processor;
using ptw.FileManager.Processor;

public partial class wormadmin_filemanage : System.Web.UI.Page
{
    protected string backHtml;
    protected string folderPath = HttpContext.Current.Request.QueryString["path"];
    protected System.Text.StringBuilder currPath = new System.Text.StringBuilder("");

    protected int folderNum = 0;
    protected int fileNum = 0;

    protected System.Text.StringBuilder builder = new System.Text.StringBuilder("");

    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Session["superad"] == null || Session["superpw"] == null)
        {
            Response.Redirect("login.aspx");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

        // 操作处理
        FileManagerProcessor fileManage = new FileManagerProcessor(Request.QueryString["act"]);
        builder.Append(fileManage.Value);

        if (string.IsNullOrEmpty(folderPath))
        {
            folderPath = Server.MapPath(".");
        }

        // 组合路径, 快速导航
        string comePath = "";
        foreach (string q in folderPath.Split('\\'))
        {
            comePath += q;
            currPath.AppendFormat("<a href=\"filemanage.aspx?path={1}\">{0}</a>", q + "\\", comePath);
            comePath += "\\";
        }

        // 返回上级
        if (new DirectoryInfo(folderPath).Root.ToString().Replace("\\", "") != folderPath.ToUpper())
        {
            string previousFolder = folderPath.Substring(0, folderPath.LastIndexOf("\\"));
            backHtml = "<tr class=\"m-row2\"><td colspan=\"5\"><a href=\"filemanage.aspx?path=" + Server.UrlEncode(previousFolder) + "\"><img src=\"Images/IcoLeft.gif\" alt=\"返回上级\" align=\"absmiddle\" /> 返回上级</a></td></tr>";
        }
        else
        {
            folderPath += "\\";
        }

        // 绑定数据
        fileManage = new FileManagerProcessor();
        List<FileFolderInfo> files = fileManage.GetDirectories(folderPath);

        if (fileManage.Access)
        {
            folderNum = fileManage.FolderNum;
            fileNum = fileManage.FileNum;

            rptList.DataSource = files;
            rptList.DataBind();
        }
        else
        {
            builder.Append("无权限访问该目录. <a href='javascript:history.go(-1);' style='font-weight: normal'>后退</a>");
        }


        if (builder.ToString() != "")
        {
            string builderResult = builder.ToString();
            builder = new System.Text.StringBuilder("");
            builder.AppendFormat("<script type=\"text/javascript\">$(\"#tips\").show(); $(\"#tipsMsg\").html(\"{0}\"); </script>", builderResult.Replace(@"\", @"\\"));
        }
    }
}
