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

namespace MYAPP.Manage.Accessories
{
    public partial class File_Load : MyApp.Web.UI.PublicPage
    {
        string _Root_Dir = "/Accessories/";
        string _File_Dir = "";

        int _Info_ID = 0;
        int _Type_ID = 0;
        Dictionary_Info di;
        bool tf = true;
        override protected void AppInit()//程序基本信息初始化
        {
            try
            {

                _Type_ID = Convert.ToInt32(Request["Type_ID"]);
                _Info_ID = Convert.ToInt32(Request["Info_ID"]);
            }
            catch (Exception)
            {

            }

            di = new Dictionary_Info(db);
            if (di.Select("DI_Frame,DI_Value", String.Format("Dictionary_Class_ID={0} and Dictionary_Info_ID={1}", 102, _Type_ID)))
            {
                _File_Dir = String.Format("{0}{1}/{2}/{3}/", _Root_Dir, di.DI_Frame, di.DI_Value, _Info_ID);
            }
            db.Dispose();

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (tf)
            {
                Response.ContentType = "application/ms-download";
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
                string pte = Server.MapPath(_File_Dir + COE.Components.Encrypt.DecryptString(Request.QueryString["file_name"].Trim()));
                try
                {
                    FileInfo fi = new FileInfo(pte);
                    if (fi.Exists)
                    {
                        Response.AddHeader("Content-Length", fi.Length.ToString());
                        Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fi.Name, System.Text.Encoding.UTF8));
                        Response.TransmitFile(_File_Dir + COE.Components.Encrypt.DecryptString(Request.QueryString["file_name"].Trim()));
                    }
                }
                catch (Exception) { }
            }
            else
            {
                Response.Redirect(_File_Dir + "/" + COE.Components.Encrypt.DecryptString(Request.QueryString["file_name"].Trim()));
            }
        }
    }
}
