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

📄 uploadprogressbar.cs

📁 其他人不需帐号就可自由下载此源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
                "		    if (size < 0)\r\n",
                "			    this.sizeCompleted = 0;\r\n",
                "		    else if (size > this.totalSize)\r\n",
                "			    this.sizeCompleted = this.totalSize;\r\n",
                "\r\n",
                "		    var sizeLeft = 0;\r\n",
                "		    var progressInfoText = \"\";\r\n",
                "		    sizeLeft = this.totalSize - this.sizeCompleted;\r\n",
                "\r\n",
                "		    this.percentDone = Math.round(size / this.totalSize * 100) + \"%\";\r\n",
                "		    oProgress.style.width = this.percentDone;\r\n",
                "    		\r\n",
                "		    if (sizeLeft > 0)\r\n",
                "			    progressInfoText = r.replace(\"{0}\", sizeLeft);\r\n",
                "		    else\r\n",
                "			    progressInfoText = s;\r\n",
                "\r\n",
                "		    oProgressInfo.innerHTML = progressInfoText;\r\n",
                "	    }\r\n",
                "	    this.UploadError = function()\r\n",
                "	    {\r\n",
                "		    var oProgressInfo = document.getElementById(\"progressInfo\");\r\n",
                "		    var oProgress = document.getElementById(\"progress\");\r\n",
                "		    if (oProgressInfo != null)\r\n",
                "			    oProgressInfo.innerHTML = t;\r\n",
                "		    if (oProgress != null)\r\n",
                "			    oProgress.style.width = \"0\";\r\n",
                "	        " + (UploadErrorRedirectUrl.Trim().Length == 0 ? "" : string.Format("document.location = '{0}';", Page.Server.UrlEncode(UploadErrorRedirectUrl))) + "\r\n",
                "	    }\r\n",
                "	    this.UploadComplete = function()\r\n",
                "	    {\r\n",
                "		    var oProgressInfo = document.getElementById(\"progressInfo\");\r\n",
                "		    var oProgress = document.getElementById(\"progress\");\r\n",
                "		    if (oProgressInfo != null)\r\n",
                "			    oProgressInfo.innerHTML = s;\r\n",
                "		    if (oProgress != null)\r\n",
                "			    oProgress.style.width = \"100%\";\r\n",
                "	        " + (UploadCompleteRedirectUrl.Trim().Length == 0 ? "" : string.Format("document.location = '{0}';", Page.Server.UrlEncode(UploadCompleteRedirectUrl))) + "\r\n",
                "	    }\r\n",
                "    }\r\n",
                "    var iTimerID = null;\r\n",
                "    var pb = new progressBar();	\r\n",
                "    function LoadProgressInfo()\r\n",
                "    {\r\n",
                "	    try\r\n",
                "	    {\r\n",
                "		    " + Page.ClientScript.GetCallbackEventReference(this, string.Format("'UploadID={0}&t={1}'", Page.Request.QueryString["UploadID"], new Random().NextDouble()), "LoadData", "null") + ";\r\n",
                "	    }\r\n",
                "	    catch(e)\r\n",
                "	    {\r\n",
                "		    alert(e)\r\n",
                "	    }\r\n",
                "    }\r\n",
                "\r\n",
                "    function LoadData(result, context)\r\n",
                "    {\r\n",
                "		  iTimerID = window.setTimeout(\"LoadProgressInfo()\", 500); \r\n",
                "		  try{\r\n",
                "		    eval(result);\r\n",
                "		  }\r\n",
                "		  catch(e)\r\n",
                "		  {\r\n",
                "		    alert(e)\r\n",
                "		  }\r\n",
                "    }\r\n",
                "\r\n",
                "    function ClearTimer()\r\n",
                "    {\r\n",
                "	    if (iTimerID != null)\r\n",
                "	    {\r\n",
                "		    window.clearTimeout(iTimerID);\r\n",
                "		    iTimerID = null;\r\n",
                "	    }\r\n",
                "    }\r\n",
                "</script>\r\n",
                "");

            if (!Page.ClientScript.IsClientScriptBlockRegistered("UploadProgressBar"))
            {
                Page.ClientScript.RegisterClientScriptBlock(typeof(string), "UploadPorgressBar", script);
            }

            #endregion

            #region Bind Upload Button

            Control ctl = Page.FindControl(UploadButtonName);

            if (ctl == null)
            {
                return;
            }

            if (ctl is WebControl)
            {
                WebControl webCtl = (WebControl)ctl;
                webCtl.Attributes.Add("onclick", "document.forms.item(0).target='" + this.UniqueID + "_frame'; iTimerID = window.setTimeout('LoadProgressInfo()', 1000); " + webCtl.Attributes["onclick"]);
            }

            #endregion

            #region Handler For Setting Complete Status After Upload

            Page.SaveStateComplete += new EventHandler(Page_SaveStateComplete);

            #endregion
        }

        private void Page_SaveStateComplete(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                Page.Response.Write("<script language=javascript>if (parent.iTimerID != null) { parent.pb.UploadComplete();parent.ClearTimer(); }</script>");
            }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            string html = string.Concat(
                "<style type=\"text/css\"> \r\n",
                "	.progressBar { " + ProgressBarCssStyle + " } \r\n",
                "	.progressInfo { " + ProgressTextInfoCssStyle + " } \r\n",
                "	.progress { " + ProgressValueCssStyle + " } \r\n",
                "</style>\r\n",
                "<div id=\"progressBar\" class=\"progressBar\">\r\n",
                "    <div class=\"progressInfo\" id=\"progressInfo\" onselectstart=\"return false;\">\r\n",
                "        &nbsp;\r\n",
                "    </div>\r\n",
                "    <div class=\"progress\" id=\"progress\">\r\n",
                "    </div>\r\n",
                "</div>\r\n",
                "<iframe style=\"display:none\" name=\"" + this.UniqueID + "_frame\" src=\"about:blank\"></iframe>\r\n",
                "");
            writer.Write(html);
        }

        protected override void OnLoad(EventArgs e)
        {
            if (Page.Request.QueryString["UploadID"] == null)
            {
                Page.Response.Redirect(Page.Request.Path + (Page.Request.QueryString.Count == 0 ? "?" : "?" + Page.Request.QueryString.ToString() + "&") + "UploadID=" + Guid.NewGuid().ToString());
            }
        }

        #region ICallbackEventHandler Members

        private string uploadId = null;
        private string t = null;

        public string GetCallbackResult()
        {
            string uploadId = Page.Request.QueryString["UploadID"];
            string scriptText = "";
            string scriptUploading = "pb.setSize({0}, {1});";
            string scriptClearTimer = "ClearTimer();";
            string scriptUploadComplete = "pb.UploadComplete();" + scriptClearTimer;
            string scriptUploadError = "pb.UploadError();";

            string length = "";
            string read = "";

            Ilungasoft.Framework.Web.Modules.Progress progress = Ilungasoft.Framework.Web.Modules.UploadProgressModule.GetProgress(uploadId, Page.Application);
            if (progress != null)
            {
                // 如果正在接收数据,利用脚本来通知前端进度条
                //
                if (progress.State == Ilungasoft.Framework.Web.Modules.UploadState.ReceivingData)
                {
                    length = (progress.ContentLength / 1024).ToString();
                    read = (progress.BytesRead / 1024).ToString();
                    scriptText = string.Format(scriptUploading, length, read);
                }
                else if (progress.State == Ilungasoft.Framework.Web.Modules.UploadState.Complete)
                {
                    scriptText = scriptUploadComplete;
                }
                else
                {
                    scriptText = scriptUploadError;
                }
            }
            else
            {
                //scriptText = scriptUploadError;
            }
            return scriptText;
        }

        public void RaiseCallbackEvent(string eventArgument)
        {
            string[] args = eventArgument.Split('&');
            uploadId = args[0].Split('=')[1];
            t = args[1].Split('=')[1];
        }

        #endregion
    }
}

⌨️ 快捷键说明

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