<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Admin/MasterPage.master" Title="重建标题索引进度"
  CodeBehind="ContentHashProgress.aspx.cs" Inherits="PowerEasy.Module.General.WebSite.Admin.Contents.ContentHashProgress" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CphNavigation" runat="Server"> 
<style type="text/css">    
    #ProgressBar
    {
	    border: 1px solid ButtonShadow;
	    border-color: #000;
	    height: 14px; 
	    width: 502px;
    }
    
    #ProgressBar span
    {
        height: 12px; 
        margin: 1px;
        width: 3px; 
        background:#00CC00; 
        float: left; 
        font-size: 1px;
    }
</style>
    <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
        <Services>
            <asp:ServiceReference Path="~/WebServices/GetHashKeyProgressService.asmx" />
        </Services>
    </asp:ScriptManager>
    <pe:ExtendedSiteMapPath ID="SmpNavigator" SiteMapProvider="AdminMapProvider" runat="server" />
    <div style="padding-top: 5px;"></div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CphContent" runat="Server">    
    <div id="ShowUpdayeHashKey" style="<%= IsShow()%>">
    <table cellpadding="2" cellspacing="1" border="0" width="100%" class="border" align="center">
       <tr class="tdbg"><td>
        <div>
            &nbsp;&nbsp;说明：此功能是为了重建内容信息的索引标题，为的是更快速更准确的查找重复内容。<br/>            
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;此功能执行比较长，但不会对数据造成损坏，尽量不要频繁执行此操作。<br/>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请在此功能执行过程中不要在此标签页执行其他操作，以免影响此操作！<br/>            
        </div>
       </td></tr>
       <tr class="tdbg"><td>
        <div id="Tips">
            <center>
                <br />
                <br />
                <label><input name="IsBeing" type="checkbox" id="IsBeing" value="true" />是否更新已存在索引标题的信息</label>&nbsp;&nbsp;
            <input id="btnYes" type="button" class="inputbutton" value="确  定" onclick="GetHashKey(0,0,false,1);" style="width:115px" />
            </center>
        </div>
      </td></tr>
      <tr class="tdbg"><td>
        <div id="Perform" style="display:none;">
            <div id="Progres">
                <center>
                    <br />
                    <br />
                    <div id="ProgresShop" style="display:none;">更新停止</div>
                    <div id="Success" style="display:none;">更新全部完成</div>
                    <div id="Char" style="display:none;">更新进度</div>
                    <br />
                    <div id="ProgressBar">
                    </div>
                </center>
            </div>
            <div id="NotAssignment" style="display: none;">
                <div>
                    <br />
                    <br />
                    <table cellpadding="2" cellspacing="1" border="0" width="400" class="border" align="center">
                        <tr align="center">
                            <td class="title">
                                <strong>提示信息</strong></td>
                        </tr>
                        <tr align="center" class="tdbg">
                            <td valign="top" style="height: 100px;">
                                <br />
                                当前没有要更新的标题索引！</td>
                        </tr>
                        <tr align="center" class="tdbg">
                            <td>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div id="DivError" style="display: none;">
                <div>
                    <br />
                    <br />
                    <table cellpadding="2" cellspacing="1" border="0" width="400" class="border" align="center">
                        <tr align="center">
                            <td class="title">
                            <strong>发生错误！</strong></td>
                        </tr>
                        <tr class="tdbg" align="center">
                            <td valign="top" style="height: 100px;">
                                <br />
                                <div id="lblError" style="margin-left: 5%;"></div>
                            </td>
                        </tr>
                        <tr align="center" class="tdbg">
                            <td>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <br />
            <div id="ParentMessage">
            <div id="MessageCount">
            </div>
            <div id="Message">
            </div>
            </div>
            <div id="Stop">
                <center>
                    <br />
                    <input id="Button4" type="button" class="inputbutton" value="停止更新" onclick="StopHash();" style="width:115px" />
                </center>
            </div>               
        </div>
      </td></tr>
    </table>
    </div>    
    <script language="javascript" type="text/javascript">
        var timeout, switching, isSleep = false;

        function BeforeSwitch() { switching = true; return true; }
        function SwitchInto() { switching = true; }
        function OnCloseTab() {
            if (confirm("你确定要关闭当前标签页吗？")) {
                if (document.getElementById("Char").style.display != 'none') {
                    isSleep = true;
                    StopHash();
                }
                return true;
            }
            return false;
        }
                
        window.onbeforeunload = function() {
            return ISLeave();
        }

        function ISLeave() {
            if (isSleep) {
                alert("标题索引已停止！");
            }                     
            if (!switching) {
                return true;
            }
            switching = false;
        }
        
        function SetParentMessage() {
            var clientWidth;
            if (window.opera) {
                clientWidth = document.documentElement.clientWidth;
            } else {
                clientWidth = document.body.clientWidth;
            }
            var parentMessage = document.getElementById("ParentMessage");
            parentMessage.style.marginLeft = ((clientWidth - 580) / 2) + 'px';
        }

        function CloseHash() {
            document.getElementById("Perform").style.display = 'none';
            document.getElementById("ProgresShop").style.display = 'none';
            document.getElementById("Success").style.display = 'none';
            document.getElementById("Char").style.display = '';
            document.getElementById("NotAssignment").style.display = 'none';
            document.getElementById("DivError").style.display = 'none';
            document.getElementById("Stop").style.display = '';
            document.getElementById("Tips").style.display = '';
            document.getElementById("Message").innerHTML = "";
            document.getElementById("ProgressBar").innerHTML = "";
            document.getElementById('ShowUpdayeHashKey').style.display = 'none';
        }
        
        function StopHash() {
            GetHashKey(0, 0, true, 0);
        }
        
        function GetHashKey(startRowIndexId, completed, isShop, count) {
            if (timeout != null) {
                clearTimeout(timeout);
            }
            $get("Char").style.display = '';
            $get("Tips").style.display = 'none';
            $get("Perform").style.display = '';
            var isBeingHase = $get("IsBeing").checked;
            PowerEasy.Module.General.WebSite.WebServices.GetHashKeyProgressService.UpdateProgress(startRowIndexId, completed, count, isShop, isBeingHase, onTaskHasKey);
        }

        function onTaskHasKey(value) {
            if (value.IsNull) {
                $get("NotAssignment").style.display = '';
                $get("Tips").style.display = 'none';
                $get("Stop").style.display = 'none';
                $get("Progres").style.display = 'none';
                $get("Success").style.display = 'none';
            }
            else if (value.Status == 1) {
                $get("Success").style.display = 'none';
                $get("Stop").style.display = 'none';
                $get("ProgresShop").style.display = 'none';
                $get("ProgressBar").innerHTML = "";
                $get("Message").innerHTML = "";
                $get("DivError").style.display = '';
                $get("lblError").innerHTML = value.ErrorMessage;
            }
            else {
                SetProgressBar(value.ProgressBar);
                if (value.Status == 2) {
                    $get("ProgresShop").style.display = 'none';
                    $get("Success").style.display = 'none';
                    $get("Char").style.display = '';
                    $get("DivError").style.display = 'none';
                    $get("lblError").innerHTML = "";
                    $get("MessageCount").innerHTML = "总共需要更新 <font style=\"font-weight:bold; color:#FF0000\">" +
                    value.Count + "</font> 条信息    已更新 <font style=\"font-weight:bold; color:#FF0000\">" + 
                    value.Completed + "</font> 条信息";
                    $get("Message").innerHTML = value.Message;
                    SetParentMessage();                  
                    timeout = setTimeout("GetHashKey('" + value.StartRowIndexId + "','" + value.Completed + "',false,'" + value.Count + "',false)", 1000);
                }
                else if (value.Status == 4) {
                    if (timeout != null) {
                        clearTimeout(timeout);
                    }
                    $get("ProgresShop").style.display = '';
                    $get("Char").style.display = 'none';
                    $get("Stop").style.display = 'none';
                }
                else {
                    if (timeout != null) {
                        clearTimeout(timeout);
                    }
                    $get("Stop").style.display = 'none';
                    $get("Char").style.display = 'none';
                    $get("ProgresShop").style.display = 'none';
                    $get("Success").style.display = '';
                    $get("Message").innerHTML = "";
                    $get("DivError").style.display = 'none';
                    $get("lblError").innerHTML = "";                  
                }
            }
        }

        function SetProgressBar(progressBar) {
            if (progressBar != 0) {
                $get("ProgressBar").innerHTML = "";
                for (var i = 0; i < progressBar; i++) {
                    $get("ProgressBar").innerHTML += "<span/>"
                }
            }
        }
    </script>
</asp:Content>