using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using LZBS.Common;
using LZBS.BLL;
using LZBS.Model;

namespace LZBS.Web.Admin
{
    public partial class UploadResource : System.Web.UI.Page
    {
        M_SysLog mLog = new M_SysLog();
        B_SysLog bLog = new B_SysLog();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Response.Redirect("Login.aspx", true);
            }
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            //FileUpload上传的文件超过Web.config里面配置的大小，就会出现该页无法显示的错误。
            //获取上传文件的大小单位为字节byte
            //int FileSize = FileUpload1.PostedFile.ContentLength;
            //int MaxSize = 10485760;//10M=10240*1024
            //if (FileSize <= MaxSize)
            //{
                if (FileUpload1.FileName != "")
                {
                    B_Download bll = new B_Download();
                    M_Download model = new M_Download();
                    //获取文件名
                    string Filename = FileUpload1.FileName;
                    //获取文件后缀
                    string Suffix = Filename.Substring(Filename.LastIndexOf("."));
                    string NewFileName = ReName.GetFilename() + Suffix;
                    FileUpload1.PostedFile.SaveAs(Server.MapPath("~/DownLoad/" + NewFileName));
                    model.FileName = Filename;
                    model.NewFileName = NewFileName;

                    mLog.UserIP = ClientInfo.GetUserIP();
                    mLog.URL = Request.Url.AbsoluteUri.ToString();
                    mLog.Account = Session["UserID"].ToString();
                    mLog.UserType = 0;

                    if (bll.UploadFile(model) > 0)
                    {
                        mLog.OPInfo = "上传文件 " + Filename + " 成功";
                        MyMessageBox.MessageBox("文件成功上传", this.Page);
                    }
                    else
                    {
                        mLog.OPInfo = "上传文件 " + Filename + " 失败";
                        MyMessageBox.MessageBox("文件上传失败", this.Page);
                    }
                    bLog.AddLog(mLog);
                }
                else
                {
                    MyMessageBox.MessageBox("请选择要上传的文件", this.Page);
                }
            //}
            //else
            //{
            //    MyMessageBox.MessageBox("对不起，你上传的文件太大，不能上传", this.Page);
            //}


        }
    }
}
