<%@ Page Language="c#" %>
<%@ Import Namespace="Bestcomy.Web.Controls.Upload" %>
<HTML>
	<HEAD runat="server">
		<title>
			<%=Percentage%>
			% completed</title>
		<base target="_self">
		<style>
    BODY { MARGIN: 0px; OVERFLOW: hidden; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: buttonface; BORDER-BOTTOM-STYLE: none }
    TD { FONT-SIZE: 11pt; FONT-FAMILY: Arial }
    </style>
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<table border="0" cellpadding="5" width="100%">
				<tr>
					<td align="center" valign="middle" height="100%">
						<table border="0" width="340">
							<tr>
								<td nowrap>状态:&nbsp;<asp:Label ID="txt_progressinfo" Runat="server" /></td>
							</tr>
							<tr>
								<td nowrap>文件:&nbsp;<asp:Label ID="txt_filename" style="TEXT-OVERFLOW:ellipsis" Runat="server" Width="300" /></td>
							</tr>
						</table>
						<table border="0" cellspacing="1" cellpadding="0" style="BORDER-RIGHT:buttonhighlight 1px solid; BORDER-TOP:buttonshadow 1px solid; BORDER-LEFT:buttonshadow 1px solid; WIDTH:340px; BORDER-BOTTOM:buttonhighlight 1px solid; HEIGHT:22px">
							<tr>
								<td width="<%=Percentage%>%" bgcolor="highlight"></td>
								<td width="<%=100-Percentage%>%"></td>
							</tr>
						</table>
						<table border="0" cellspacing="0" cellpadding="1" width="340">
							<tr>
								<td nowrap>传输速率:&nbsp;<asp:Label ID="txt_speed" Runat="server" /></td>
							</tr>
							<tr>
								<td nowrap>剩余时间:&nbsp;<asp:Label ID="txt_leftTime" Runat="server" /></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td align="right" nowrap><asp:Button ID="btn_ok" Text="OK" Runat="server" Width="70" />&nbsp;&nbsp;<asp:Button ID="btn_cancle" Text="Cancel" OnClick="btn_cancle_Click" Runat="server" Width="70" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
				</tr>
			</table>
		</form>
	</body>
</HTML>
<script language="c#" runat="server">

		private double percentage = 0;

		public double Percentage
		{
			get
			{
				return percentage;
			}
		}
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			
			btn_ok.Enabled=false;
			Progress proc = new Progress(Request["UploadID"]);
			if(proc.get_UploadStatus()!=Progress.UploadStatusEnum.Error)
			{
                switch (proc.get_UploadStatus())
                {
                    case Progress.UploadStatusEnum.Completed:
                        txt_progressinfo.Text = "上传任务已完成!";
                        break;
                    case Progress.UploadStatusEnum.Error:
                        txt_progressinfo.Text = "有错误发生!";
                        break;
                    case Progress.UploadStatusEnum.Initializing:
                        txt_progressinfo.Text = "正在初始化上传任务...";
                        break;
                    case Progress.UploadStatusEnum.Moving:
                        txt_progressinfo.Text = "上传即将完成,正在进行文件转储.";
                        break;
                    case Progress.UploadStatusEnum.Uploaded:
                        txt_progressinfo.Text = "正在完成上传任务...";
                        break;
                    case Progress.UploadStatusEnum.Uploading:
                        txt_progressinfo.Text = "正在上传...";
                        break;
                    default:
                        txt_progressinfo.Text = proc.get_UploadStatus().ToString();
                        break;
                }				
				txt_filename.Text = proc.get_FileName();
				percentage = proc.get_Percent();
				if(proc.get_UploadStatus() == Progress.UploadStatusEnum.Initializing)
				{
					Response.AppendHeader("Refresh","3");
				}
				else if(proc.get_UploadStatus() == Progress.UploadStatusEnum.Completed)
				{
					txt_filename.Text = proc.get_FileCount().ToString()+"个文件已成功上传！";
					txt_speed.Text = proc.GetFormatString(proc.get_Speed())+" / 秒";
					txt_leftTime.Text = "上传已完成";
					proc.Dispose();
					btn_ok.Attributes.Add("onclick","javascript:window.opener=self;window.close();return false;");
					btn_ok.Enabled=true;
				}
				else
				{
                    txt_speed.Text = proc.GetFormatString(proc.get_Speed()) + " / 秒";
					txt_leftTime.Text = proc.get_LeftTime().ToString();
					Response.AppendHeader("Refresh","3");
				}
				if(proc.get_UploadStatus() == Progress.UploadStatusEnum.Completed)
					btn_cancle.Attributes.Add("onclick","javascript:window.opener=self;window.close();return false;");
				else
					btn_cancle.Attributes.Add("onclick","javascript:var win=null;if(window.dialogArguments==undefined){win=window.opener;}else{win=dialogArguments;}win.document.location.href=win.document.location.href;return true;");
			}
			else
			{
				proc.Dispose();
				if(!ClientScript.IsClientScriptBlockRegistered(this.GetType(),"closeScript"))
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "closeScript", System.Web.HttpUtility.HtmlDecode("&lt;script&gt;window.opener=self;window.close();&lt;/script&gt;"));
			}
		}
		
		protected void btn_cancle_Click(object sender, System.EventArgs e)
		{
			Progress proc = new Progress(Request["UploadID"]);
			proc.Abort();
			btn_cancle.Enabled = false;
		}
		
</script>
