<%@ Page Language="C#" AutoEventWireup="true" Inherits="Control_upfile_Default" Title="上传文件"   Codebehind="Default.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>无标题页</title>
    <link href="Style/ProgressBar.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="myform" runat="server">
    <div id="root" style="left: 0px; top: 5px; display: none; width: 283px; height: 106px;" onselectstart="javascript:return false;">
        <div id="handle">
            &nbsp;</div>
        <div id="container">
            <div class="info">
                Status:&nbsp;&nbsp;Initializing</div>
            <div class="info">
                <nobr>File:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr>
            </div>
            <div class="progressBar">
                <div class="indicator" style="width: 0px">
            </div>
            </div>
            <div class="info">
                Transfer Rate:&nbsp;&nbsp;</div>
            <div class="info">
                Time Remaining:&nbsp;&nbsp;</div>
        </div>
        <div class="info">
            <a id="btn_cancel" href="javascript:cancelUpload()">Cancel</a></div>
    </div>
        <asp:Panel ID="Panelupfile" runat="server" Width="342px" >
            <input name="file1" type="file" /><asp:Button ID="btn_upload" Text="Upload..." runat="server" OnClick="btn_upload_Click" />
        </asp:Panel>
        <asp:Panel ID="Panelupfile_ok" runat="server" Visible="false" Width="416px" >
           成功上传 &nbsp;&nbsp;
            <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">重新上传</asp:LinkButton>
            <asp:CheckBox ID="ChkDelfile" runat="server" Text="删除刚上传文件" />
            </asp:Panel>
    </form>
    
</body>
</html>
    <script language="javascript" type="text/javascript">
		<!--
		
		//preload images
	//	var img1 = new Image();
	//	img1.src = "images/bar_bg.gif";
	//	var img2 = new Image();
	//	img2.src = "images/Indicatorbg.gif";
		
		var ProgressInfo = Class.create();
		
		ProgressInfo.prototype = {
			initialize:	function(status,percent,file,speed,leftTime,fileCount){
							this.Status = status;
							this.Percent =percent;
							this.File = file;
							this.Speed =speed;
							this.LeftTime = leftTime;
							this.FileCount = fileCount;
			},
			
			update:	function(){
						if(this.Status == "Error")
						{
							document.location.href = document.location.href;
						}
						else
						{
							var html = "<div class=\"info\">Status:&nbsp;&nbsp;"+(this.Status=="Uploading" ? this.Percent + "% Completed" :this.Status)+"</div>";
							html += "<div class=\"info\"><nobr>File:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+(this.Status=="Completed" ? this.FileCount + " fiel(s) uploaded successfully !" : this.File)+"</nobr></div>";
							html += "<div class=\"progressBar\"><div class=\"indicator\" style=\"width:"+(3*this.Percent)+"px\"></div></div>";
							html += "<div class=\"info\">Transfer Rate:&nbsp;&nbsp;"+(this.Status=="Initializing" ? "" : this.Speed)+"</div>";
							html += "<div class=\"info\">Time Remaining:&nbsp;&nbsp;"+(this.Status=="Initializing" ? "" : this.LeftTime)+"</div>";
							var container = $("container");
							container.innerHTML = html;						
						}
			}			
		};
		
		function getProgressInfo()
		{
			var url = "GetProgressInfo.aspx";
			var pars = "UploadID=<%=UploadID%>&cmd=Update&temp="+Math.random();
			var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: showResponse});			
		}
		
		function cancelUpload()		
		{
			var url = "GetProgressInfo.aspx";
			var pars = "UploadID=<%=UploadID%>&cmd=Cancel&temp="+Math.random();
			var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: showResponse});
			this.disabled = true;		
		}
		
		function showResponse(request)
		{
			eval(request.responseText);
		}
		
		function showProgressBar()
		{
			var ipts = document.getElementsByTagName('INPUT');
			var openBar = false;
			for(var i=0;i<ipts.length;i++)
			{
				var obj = ipts[i];
				if(obj.type  == 'file')
				{
					if(obj.value != '')
					{
						openBar = true;
						break;
					}
				}
			}
			if(openBar)
			{
				var theHandle = $("handle");
				var theRoot   = $("root");
				Drag.init(theHandle, theRoot);
				theRoot.style.display = "";
				var internalUpdate = new PeriodicalExecuter(getProgressInfo,1);
			}
		}
			
		//-->
    </script>


