⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multiplephotoupload.aspx.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.WebSite.User.Accessories
{
    using PowerEasy.Accessories;
    using PowerEasy.Common;
    using PowerEasy.CommonModel;
    using PowerEasy.Components;
    using PowerEasy.Contents;
    using PowerEasy.Model.Accessories;
    using PowerEasy.Model.CommonModel;
    using PowerEasy.Model.Contents;
    using PowerEasy.Web.UI;
    using System;
    using System.Collections.ObjectModel;
    using System.IO;
    using System.Text;
    using System.Web;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class MultiplePhotoUpload : BasePage
    {
        protected Button BtnUpload;
        protected System.Web.UI.WebControls.FileUpload FileUpload0;
        protected System.Web.UI.WebControls.FileUpload FileUpload1;
        protected System.Web.UI.WebControls.FileUpload FileUpload2;
        protected System.Web.UI.WebControls.FileUpload FileUpload3;
        protected System.Web.UI.WebControls.FileUpload FileUpload4;
        protected System.Web.UI.WebControls.FileUpload FileUpload5;
        protected System.Web.UI.WebControls.FileUpload FileUpload6;
        protected System.Web.UI.WebControls.FileUpload FileUpload7;
        protected System.Web.UI.WebControls.FileUpload FileUpload8;
        protected System.Web.UI.WebControls.FileUpload FileUpload9;
        protected HtmlForm form1;
        protected Label LblMessage;
        private string m_FieldName;
        private string m_FileExtArr;
        private bool m_IsSaveThumb;
        private int m_ModelId;
        private ModelInfo m_ModelInfo;
        private int m_NodeId;
        private NodeInfo m_NodeInfo;
        private string m_PhotoSize;
        private string m_ShowPath;
        private bool m_Watermark;

        protected void BtnUpload_Click(object sender, EventArgs e)
        {
            if (!SiteConfig.SiteOption.EnableUploadFiles)
            {
                this.LblMessage.Text = "权限错误:你当前的网站没有开启上传功能,请检查你的网站配置。";
            }
            else
            {
                string str = BasePage.RequestString("ReturnJSFunction");
                int num = DataConverter.CLng(base.Request.Form["ThumbIndex"]);
                if (string.IsNullOrEmpty(str))
                {
                    str = "DealwithUpload";
                }
                StringBuilder builder = new StringBuilder();
                builder.Append("<script language=\"javascript\" type=\"text/javascript\">");
                int num2 = 0;
                StringBuilder builder2 = new StringBuilder();
                for (int i = 0; i < 10; i++)
                {
                    num2++;
                    System.Web.UI.WebControls.FileUpload upload = (System.Web.UI.WebControls.FileUpload) this.FindControl("FileUpload" + i.ToString());
                    if (upload.HasFile)
                    {
                        string str2 = Path.GetExtension(upload.FileName).ToLower();
                        if (!this.CheckFilePostfix(str2.Replace(".", "")))
                        {
                            builder2.Append("文件" + upload.FileName + "上传文件类型不对!必须上传" + this.m_FileExtArr + @"的后缀名!\n");
                        }
                        else if (((int) upload.FileContent.Length) > (DataConverter.CLng(this.m_PhotoSize) * 0x400))
                        {
                            builder2.Append("文件" + upload.FileName + "请上传小于" + this.m_PhotoSize + @"KB的文件!\n");
                        }
                        else
                        {
                            string str3 = DataSecurity.MakeFileRndName() + i.ToString();
                            string filename = FileSystemObject.CreateFileFolder((VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.UploadDir) + this.FileSavePath(upload.FileName)).Replace("//", "/"), HttpContext.Current) + str3 + str2;
                            upload.SaveAs(filename);
                            if (this.m_Watermark)
                            {
                                WaterMark.AddWaterMark(this.m_ShowPath + str3 + str2);
                            }
                            if ((i == num) && this.m_IsSaveThumb)
                            {
                                Thumbs.GetThumbsPath(this.m_ShowPath + str3 + str2, this.m_ShowPath + str3 + "_S" + str2);
                            }
                            PowerEasy.Model.Accessories.FileInfo fileInfo = new PowerEasy.Model.Accessories.FileInfo();
                            fileInfo.Name = upload.FileName;
                            fileInfo.Path = this.m_ShowPath + str3 + str2;
                            fileInfo.Size = (int) upload.FileContent.Length;
                            fileInfo.Quote = 1;
                            Files.Add(fileInfo);
                            if ((i == num) && this.m_IsSaveThumb)
                            {
                                builder.Append("parent." + str + "ChangeThumbField(\"" + fileInfo.Path + "\",\"" + this.m_ShowPath + str3 + "_S" + str2 + "\");");
                            }
                            else
                            {
                                builder.Append("parent." + str + "DealwithUpload(\"" + fileInfo.Path + "\",\"" + fileInfo.Size.ToString() + "\",\"" + fileInfo.Id.ToString() + "\");");
                            }
                            builder2.Append("文件" + upload.FileName + @"上传成功!\n");
                        }
                    }
                }
                if (builder2.Length > 0)
                {
                    builder.Append("parent." + str + "ErrMessage(\"" + builder2.ToString() + "\");");
                }
                builder.Append("</script>");
                this.Page.ClientScript.RegisterStartupScript(base.GetType(), "UpdateParent", builder.ToString());
            }
        }

        private bool CheckFilePostfix(string fileExtension)
        {
            return StringHelper.FoundCharInArr(this.m_FileExtArr.ToLower(), fileExtension.ToLower(), "|");
        }

        private string FileSavePath(string fileName)
        {
            string str = "";
            if ((this.m_NodeInfo != null) && SiteConfig.SiteOption.EnableUploadFiles)
            {
                str = Nodes.UploadPathParse(this.m_NodeInfo, fileName);
                this.m_ShowPath = str;
            }
            return str;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["PowerEasy:NodeId"] != null)
            {
                this.m_NodeId = (int) this.Session["PowerEasy:NodeId"];
            }
            else
            {
                this.m_NodeId = DataConverter.CLng(base.Request["NodeId"]);
            }
            this.m_ModelId = DataConverter.CLng(base.Request["ModelId"]);
            this.m_FieldName = BasePage.RequestString("FieldName");
            if (this.m_NodeId > 0)
            {
                this.m_NodeInfo = Nodes.GetCacheNodeById(this.m_NodeId);
            }
            if (this.m_ModelId > 0)
            {
                this.m_ModelInfo = ModelManager.GetModelInfoById(this.m_ModelId);
            }
            if ((this.m_ModelInfo != null) && !string.IsNullOrEmpty(this.m_FieldName))
            {
                Collection<string> settings = Field.GetFieldInfoByFieldName(this.m_ModelId, this.m_FieldName).Settings;
                this.m_PhotoSize = settings[0];
                this.m_FileExtArr = settings[1];
                this.m_IsSaveThumb = DataConverter.CBool(settings[2]);
                if (settings.Count > 4)
                {
                    this.m_Watermark = DataConverter.CBool(settings[4]);
                }
            }
            if (string.IsNullOrEmpty(this.m_FileExtArr))
            {
                this.m_FileExtArr = "gif|png|jpeg|jpg|gif|bmp";
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -