using System;
using System.Collections;
using System.IO;
using Common;
using LogisticsSystem.Control;

namespace LogisticsSystem.SysMain.FileFlow
{
    public partial class uploadSrv : SrvBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var type = Request.QueryString["type"];

            if (!CheckUserLogin()) return;

            //根据类型 执行相关操作
            switch (type)
            {
                case "DelFiles":        //删除上传文件
                    DelFiles();
                    break;
                case "GetUploadFiles":      //获取上传的文件列表
                    Response.Write(new FileHelper().GetUploadfiles((Hashtable)Session["upload"]));
                    break;
                default:
                    Response.Write("");
                    break;
            }
        }

        private void DelFiles()
        {
            var hash = (Hashtable)Session["upload"];
            string[] delfiles = Request.QueryString["sT"].Split(',');
            foreach (string delfile in delfiles)
            {
                try
                {
                    if (File.Exists(hash[delfile].ToString()))
                    {
                        File.Delete(hash[delfile].ToString());
                    }
                    hash.Remove(delfile);
                }
                catch (Exception)
                {
                }
            }
            Session["upload"] = hash;
            Response.Write(new FileHelper().GetUploadfiles((Hashtable)Session["upload"]));
        }
    }
}