<%@ page language="C#" inherits="KnowledgeAdjunctUpload, App_Web_4plofzsr" stylesheettheme="Themes" theme="Themes" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head id="Head1" runat="server">
    <base target="_self"></base>
    <title>上传新增单个文件</title>
    <style>
        .progressBar
        {
            width: 420px;
            height: 20px;
        }
        .progressInfo
        {
            border-right: #000000 1px solid;
            border-top: #000000 1px solid;
            font-size: 9pt;
            overflow: hidden;
            border-left: #000000 1px solid;
            width: 420px;
            padding-top: 1px;
            border-bottom: #000000 1px solid;
            position: absolute;
            height: 20px;
            text-align: center;
        }
        .progress
        {
            overflow: hidden;
            width: 0%;
            height: 20px;
            background-color: LightGreen; /* #5fff3f;*/
        }
        .style1
        {
            height: 16px;
        }
    </style>

    <script type="text/javascript" src="../js/xmlLib.js"></script>

</head>
<body>

    <script>
		var r = "{0}";
		var s = "您的文件已经上传完成";
		var t = "上传失败";
		var runtime = 0;
		function progressBar()
		{
            runtime=0;//已经上传的时间秒
			this.totalSize = 100;
			this.sizeCompleted = 0;
			this.percentDone = "0%";
			var goneTime =0;
			var leftTime = 0;
			
			this.setSize = function(totalSize, size)
			{
			//alert(99);
				var oProgressInfo = document.getElementById("progressInfo");
				var oProgress = document.getElementById("progress");
				//显示上传速度
				var oSpeed = document.getElementById("speed");
				if (oProgress == null || oProgressInfo == null)
					return;

				if (totalSize <= 0)
					return;

				this.totalSize = totalSize;
				sSize.innerHTML = totalSize+"K";
				this.sizeCompleted = size;
				if (size < 0)
					this.sizeCompleted = 0;
				else if (size > this.totalSize)
					this.sizeCompleted = this.totalSize;

				var sizeLeft = 0;
				var progressInfoText = "";
				sizeLeft = this.totalSize - this.sizeCompleted;

				this.percentDone = Math.round(size / this.totalSize * 100) + "%";
				oProgress.style.width = this.percentDone;
				
				if (sizeLeft > 0)
				{
					progressInfoText = r.replace("{0}", " 完成:"+this.percentDone+" 剩余"+sizeLeft+"K");
					oSpeed.innerHTML = ((this.sizeCompleted/runtime)*2).toFixed(0)+"K/S"
					var UploadSpeed = ((this.sizeCompleted/runtime)*2).toFixed(0);//即时速度
					//计算逝去时间
					goneTime = (runtime/2).toFixed(0);
					if(goneTime>60)
					{
					    goneTime = (goneTime/60).toFixed(0)+"分"+(goneTime%60)+"秒";
					}
					else
					{
					    goneTime+="秒";
					}
					sgoneTime.innerHTML = goneTime;
					//计算估计剩余时间
					LeftTime = (sizeLeft/UploadSpeed).toFixed(0);
					if(LeftTime>60)
					{
					    LeftTime = (LeftTime/60).toFixed(0)+"分"+(LeftTime%60)+"秒";
					}
					else
					{
					    LeftTime+="秒";
					}
					sleftTime.innerHTML = LeftTime;
				}
				else
				{
					progressInfoText = s;
					}

				oProgressInfo.innerHTML = progressInfoText;
			}
			this.UploadError = function()
			{
				var oProgressInfo = document.getElementById("progressInfo");
				var oProgress = document.getElementById("progress");
				if (oProgressInfo != null)
					oProgressInfo.innerHTML = t;
				if (oProgress != null)
					oProgress.style.width = "0";
			}
			this.UploadComplete = function()
			{
			    //计数清0
			    speed.innerHTML = "0K/S";
				var oProgressInfo = document.getElementById("progressInfo");
				var oProgress = document.getElementById("progress");
				if (oProgressInfo != null)
					oProgressInfo.innerHTML = s;
				if (oProgress != null)
					oProgress.style.width = "100%";
			}
		}
		var iTimerID = null;
		var iTimeTime = null;//描述计时的timeout
		var xmlHttp = XmlHttpPool.pick();
		var url = "progress.aspx?UploadID=<%=Request.QueryString["UploadID"]%>";
		var pb = new progressBar();	
//		function CountTime()
//		{   
//		    iTimeTime =  window.setTimeout("CountTime()", 1000); 
//		    runtime+=1;
//		}
		function LoadProgressInfo()
		{
			try
			{
				xmlHttp.open("GET", url + "&t=" + Math.random(), true);
				xmlHttp.send(null);
				xmlHttp.onreadystatechange = function()
				{
				   
					LoadData(xmlHttp);
				}
			}
			catch(e)
			{
				alert(e)
			}
		}

		function LoadData(xmlhttp)
		{
			if (xmlhttp.readyState == 4)
			{
			
				iTimerID = window.setTimeout("LoadProgressInfo()", 500); 
				
				try{
				runtime+=1;
					eval(xmlhttp.responseText);
					//speed.innerHTML = xmlhttp.responseText;
				}
				catch(e)
				{
					alert(e)
				}
			}
		}
		
		function ClearTimer()
		{
			if (iTimerID != null)
			{
				window.clearTimeout(iTimerID);
				window.clearTimeout(iTimeTime);
				iTimerID = null;
				iTimeTime=null;
			}
		}
		
		function UploadCancel()
		{
			location.href = location.href;
		}

    </script>

    <form id="form1" runat="server" target="uploadData">
    <div class="box">
        <table class="table_1" cellpadding="6px" width="100%" border="1px">
            <tr class="td_1">
                <td colspan="2" class="style1">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;支持word文档和压缩文件格式的上传文件
                </td>
            </tr>
            <tr class="td_3">
                <td height="25" width="30%" align="right">
                    上传附件：
                </td>
                <td height="25" width="*" align="left">
                    <input id="uploadFile" type="file" runat="server" onchange="check(form1.uploadFile);" />&nbsp;&nbsp;
                    <asp:Button ID="btnUpload" runat="server" Text="  上传  " OnClick="btnUpload_Click"></asp:Button>
                    <div id="progressBar" class="progressBar" style="border: 1px solid #808080; font-size: 9pt;">
                        <div class="progressInfo" id="progressInfo" onselectstart="return false;">
                            &nbsp;
                        </div>
                        <div class="progress" id="progress">
                        </div>
                        <font style="font-size: 9pt">文件大小:<span id="sSize"></span></font>
                        <br>
                        <font style="font-size: 9pt">当前速度:<span id="speed"></span></font>
                        <br>
                        <font style="font-size: 9pt">逝去时间:<span id="sgoneTime"></span></font>
                        <br>
                        <font style="font-size: 9pt">估计剩余时间:<span id="sleftTime"></span></font>
                        <br>
                    </div>
                    <iframe name="uploadData" src="about:blank" height="0"></iframe>
                </td>
            </tr>
            </table>
    </div>
    </form>
</body>
<script language="javascript">
    function check(object) {
        var fileName = object.value;
        if (fileName.lastIndexOf(".") != -1) {
            var fileType = (fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length)).toLowerCase();
            var suppotFile = new Array();
            suppotFile[0] = "doc";
            suppotFile[1] = "rar";
            suppotFile[2] = "zip";
            suppotFile[3] = "docx";
//            suppotFile[4] = "flv";
//            suppotFile[5] = "txt";
//            suppotFile[6] = "pdf";
//            suppotFile[7] = "mht";
            for (var i = 0; i < suppotFile.length; i++) {
                if (suppotFile[i] == fileType) {
                    return true;
                }
                else {
                    continue;
                }
            }
            alert("不支持文件类型" + fileType + "！");
            form1.reset();
            return false;
        }
        else {
            alert("请选择正确的文件类型！");
            return;
        }
    }
</script>
</html>
