<%@ Page Language="C#" EnableViewState="false" AutoEventWireup="true" CodeBehind="Show.aspx.cs" Inherits="HtmlWeb.Show" %>

<!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/style.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
#t1 {
	margin-top: 30px;
}

#select1 {
	width: 800px;
	background-color: #000000;
	color: #00FF00;
}
.ld {
	width: 600px;
	margin-right: auto;
	margin-left: auto;
	height: 8px;
	border: 1px solid #FFFFFF;
	overflow: hidden;
	text-align: left;
}
#div_in {
	background-image: url(images/bg0.gif);
	background-repeat: repeat-x;
}
body {
	color: #FFFFFF;
	background-color: #000000;
}
span {
	color: #00FF00;
	font-weight: bold;
}
#Button1 {
	font-weight: bold;
	color: #00FF00;
	background-color: #000000;
	border: 1px dashed #00FF00;
	cursor: hand;
	margin-bottom: 10px;
}
    </style>
</head>
<body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">
<noscript><iframe src=* width=0 height=0></iframe></noscript>
<form id="form1" runat="server">
      <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" id="t1">
        <tr>
          <td align="center">
              <input id="Button1" type="button" value="开始采集 [ 现在处于停止状态 ]" language="javascript" onclick="return Button1_onclick()"  /><br />
              现在正在采集的是：
          <asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label>
              共 <span id="coung_lsit_ye">0</span> 列表页,正在采第 <span id="indexpage">1</span> 页(本页共 <span id="ye_count">0</span> 条信息)第 <span id="indexshow">1</span> 条,已经成功采集 <span id="xcount">0</span> 条</td>
        </tr>
        <tr>
          <td height="35" align="center"><div class="ld"><div id="div_in"></div></div></td>
        </tr>
        <tr>
          <td height="25" align="center">采集进度：<span id="bfb">0%</span></td>
        </tr>
        <tr>
          <td height="390">
          <span style="border:1px solid #000000; position:absolute; overflow:hidden;">
          <select style="margin:-2px" name="select1" size="25"  id="select1">
          </select>
</span></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td height="40" align="center" id="ajax_ld"></td>
        </tr>
      </table>
<script type="text/javascript">
AjaxPro.timeoutPeriod =121000;
    function $(a)
    {
        return document.getElementById(a);
    }
    var ajax_ld= $('ajax_ld');
    
    //第三
    function Callback(res)
    {
       //alert('取得返回数据!');
       ajax_ld.innerHTML="";//+res.value;
       //alert('3');
       showlist(res.value);
    }
    
    function Callback2(res)
    {
       //alert('取得返回数据!');
       ajax_ld.innerHTML="";//+res.value;
       Sup(res.value);
    }
    
    //向服务器发送数据
    function Context()
    {
       //alert('返回数据!');
    }
    
    //第一
    function onLoading()
    {
       //alert('加载数据!');
       //stl.innerHTML="第一,加载数据!";
    }
    
    
    function onError()
    {
       Start();
       //alert('出错啦!');
    }
    
    function onTimeout()
    {
       //alert('请求超时,请重试!');
       Start();
//     Sup(1);
    }
    
    //第二
    function onStateChanged()
    {
       //alert('状态改变了,还在执行吗?');
       //stl.innerHTML="第二,状态改变了,还在执行吗?";
       ajax_ld.innerHTML='<img src="images/ajax.gif" />';
    }
    //Default13.abc(1,2,Callback,Context,onLoading,onError,onTimeout,onStateChanged);    
</script>

<script type="text/javascript">
var ID=<%=this.Context.Request.QueryString["id"]==null?"0":this.Context.Request.QueryString["id"] %>;
var tf_index=0;
var PageIndex=<%#PageIndex %>;
var PageListCount=<%#PageListCount %>;
var tf=PageIndex>PageListCount?true:false;
var pcoung_0=tf?PageIndex:PageListCount;

var s_start=false;//是否开始
var HrefList;
var ImgList;
var Index=0;//当前处于第几条
var count=0;//本页总条数
var xcount=0;

var s1=$("select1");
var bt1=$("Button1");

function showjd()
{
    var lod=Math.round(100*(Index+1)/count);
    if (lod>100)
    {
       lod=100;
    }
    
    $("div_in").style.width=lod+"%";
    $("bfb").innerHTML=lod+"%";
    $("indexpage").innerHTML=PageIndex;
    $("indexshow").innerHTML=Index+1;
    $("xcount").innerHTML=xcount;
    $("ye_count").innerHTML=count;
    $("coung_lsit_ye").innerHTML=pcoung_0;
    
}
function showlist(val)
{
     HrefList=val;
     if (HrefList.length>0)
     {
         Index=0;
         count=HrefList.length;
         
         s1.length=0;
         for(var i=0;i<HrefList.length;i++)
         {
             s1.options.add(new Option(HrefList[i],HrefList[i]));
         }
         s1.selectedIndex=Index;
         $("ye_count").innerHTML=count;
         showjd();
     }
     else
     {
         ajax_ld.innerHTML='<span><B>对不起！无法加载列表页，请检查列表页地址是否正确！</B> [ 列表页地址在采集项目的(第二步)里设置 ]</span>';
     }
     bt1.disabled=false;
}

function loadlist()//加载列表
{
   bt1.disabled=true;
   if (tf_index==0)
   {
       tf_index=1;
       HtmlWeb.Show.RList(ID,0,Callback,Context,onLoading,onError,onTimeout,onStateChanged);
   }
   else
   {
      HtmlWeb.Show.RList(ID,PageIndex,Callback,Context,onLoading,onError,onTimeout,onStateChanged);
   }
}
loadlist();
function up()
{
    if (Index<count-1)
    {
        Index++;
        s1.selectedIndex=Index;
        
        showjd();//显示进度
        
        Start();
    }
    else
    {
        if (tf)
        {
            if (PageIndex>PageListCount)
            {
                if (tf_index==1)
                {
                    tf_index=2;
                }
                else
                {
                   PageIndex--;
                }
                
                Index=0;
                
                loadlist();//加载列表
                Start();//开始采集
            }
            else
            {
                //alert("已经采集完成！");
                ajax_ld.innerHTML='<span><B>已经采集完成！</B></span>';
            }
        }
        else
        {
            if (PageIndex<PageListCount)
            {
                if (tf_index==1)
                {
                    tf_index=2;
                }
                else
                {
                   PageIndex++;
                }
                Index=0;
                
                loadlist();//加载列表
                Start();//开始采集
            }
            else
            {
                //alert("已经采集完成！");
                ajax_ld.innerHTML='<span><B>已经采集完成！</B></span>';
            }
        }
    }
}
function Sup(res)
{
   if (res==1)
   {
      xcount++;
   }
   up();//上一条信息采集成功,继续采下一条
}

var url;
function Start()
{ 
     url=s1.options[Index].value;
     if (s_start)
     {
        HtmlWeb.Show.AddData(url,ID,Callback2,Context,onLoading,onError,onTimeout,onStateChanged);
     }
}
function Button1_onclick() {
if (s_start==false){ 
       s_start=true;
       bt1.value='停止采集 [ 现在处于采集状态 ]';
   } 
   else 
   { 
       s_start=false;
       bt1.value='开始采集 [ 现在处于停止状态 ]';
   }

Start();
}

</script>
</form>
</body>
</html>
