<%@ page language="C#" autoeventwireup="true" inherits="adminweb_Building_BuildingStandard, DoodiiShop" enableEventValidation="false" viewStateEncryptionMode="Never" %>

<!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 runat="server">
    <title> 楼宇标准化</title>
     <link  rel="stylesheet" type="text/css"  href="../css.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/table.css" />
     <script type="text/javascript" src="../../js/jquery.js"></script>
   

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

    <script type="text/javascript" src="../../js/Format.js"></script>
    <style type="text/css">@import url(../../js/jquery-calendar/jquery-calendar.css);</style>

    <script type="text/javascript" src="../../js/jquery-calendar/jquery-calendar.js"></script>

    <script type="text/javascript">
    
    
              var prov;
              var provID;
               var city ;
              var cityID ;
              var zone ;
               var zoneID ;
               var region;
               var regionID;
               var startTime ;
               var endTime ;
               var keyWord;
               var stand;
               var standID=0;
                var key = "" ;
                
        var loadPage = function() 
        {     
           
            $("#txtStartTime").calendar();
            $("#txtEndTime").calendar();
            
            
               ddlProLoad();   
//              isView();
        }
        
       $(document).ready( function(){ loadPage() } );
       function trimString(str)
        {   
            str = str.replace(/\s+$|^\s+/g,"");
            return str;
        }
       function isView()
       {
              var tdStandChild = document.getElementById("tdInStand");
            if(standID == 0)
               {
                    tdStandChild.style.display = "none";
               }
               else
               {
                     tdStandChild.style.display = "block";
               }     
       }
       function ddlProLoad()
       {
             var ret = null;
             ddlRemove("ddlProvince");
            var ret =  ret = adminweb_Building_BuildingStandard.ddlProvinceDatabind().value;
            if (ret != null && typeof(ret) == "object")
            {
                for (var i = 0; i < ret.Rows.length; i++)
                {
                    if (ret.Rows[i].id == 6) ddlAdd("ddlProvince", ret.Rows[i].name, ret.Rows[i].id);
                }
                
                ddlProChange();
            }
            
            
       }
       function ddlProChange()
       {
              prov  = document.getElementById("ddlProvince");
             ddlRemove("ddlCity");
            provID = parseInt($("#ddlProvince").val());
            var ret =  adminweb_Building_BuildingStandard.cityLoad(provID).value;
            if (ret != null && typeof(ret) == "object")
            {
                for (var i = 0; i < ret.Rows.length; i++)
                {
                    if (ret.Rows[i].id == 6) ddlAdd("ddlCity", ret.Rows[i].name, ret.Rows[i].id);
                }
                ddlCityChange();
            }
       }
       function ddlCityChange()
       {
              city  = document.getElementById("ddlCity");
             cityID = city.options[city.selectedIndex].value;
             var dt = adminweb_Building_BuildingStandard.regionLoad(cityID).value;
             if(dt != null)
             {
                ddlBind(dt,"ddlRegion","全部","name","id");
                ddlRegionChange();
             }
              else
             {
                return;
             }
       }
       function ddlRegionChange()
       {
             
             ddlRemove("ddlZone");
            ddlAdd("ddlZone", "全部", "0");
            regionID = parseInt($("#ddlRegion").val());
            if (regionID > 0)
            {
                var ret = adminweb_Building_BuildingStandard.zoneLoad(regionID).value;
                if (ret != null && typeof(ret) == "object")
                {
                    for (var i = 0; i < ret.Rows.length; i++)
                    {
                        ddlAdd("ddlZone", ret.Rows[i].name, ret.Rows[i].id);
                      
                    }
                }
            }
       }
       function ddlZoneChange()
       {
              zone  = document.getElementById("ddlZone");
               zoneID = zone.options[zone.selectedIndex].value;
               
       }
       
       function ddlStandChange()
       {
            stand = document.getElementById("ddlStand");
            standID = parseInt($("#ddlStand").val());
//            alert(standID);
            tbInStandarBind();
//             isView();
            
       }
          //标准楼宇的子集加载
       function tbInStandarBind(currPage)
       {
            deleteRow("tbInStandar");
            //获得标准楼宇的ID
            if (standID != 0)
            {
                 if(currPage==null)
                   {
                        currPage = 1;
                   }
                var dt = adminweb_Building_BuildingStandard.AreaParentIDSelect(0,standID,provID, cityID, 0,0,keyWord,'','',10,currPage,2).value;
                var dtChild = document.getElementById("tbInStandar");
                 
                 if (dt != null && typeof(dt) == "object")
                {
                       var len = dt.Data.Rows.length;
                       var row1;
                       for(var i=0;i< len;i++)
                       {
                            
                                 row1   =   dtChild.insertRow(-1);   
                                  var cell   =   row1.insertCell(-1);
                                   cell.innerHTML   = (i+1).toString();
                                  var cell =  row1.insertCell(-1);
                                   cell.innerHTML = dt.Data.Rows[i].regionName;
                                   var  cell =  row1.insertCell(-1);
                                   cell.innerHTML = dt.Data.Rows[i].name;
                                  var cell =row1.insertCell(-1);
                                   cell.innerHTML = "<a href='javascript:deleteArea(" + dt.Data.Rows[i].id + ")'>移除</a>";  
                       }
                       
                   }
                 pageChange2("tbInStandar","divPage2",10,dt.RecordCount,currPage);

           }
           else
           {
                  pageChange2("tbInStandar","divPage2",10,0,currPage);
           }
         
            
       }
      
       function query()
       {
      
            startTime = document.getElementById("txtStartTime").value;
            endTime = document.getElementById("txtEndTime").value;
            keyWord = document.getElementById("txtKeyWord").value;
            key = trimString(document.getElementById("txtStandKey").value);
            if (startTime!="" && endTime=="")
           {
                alert("请选择结束时间！");document.getElementById("txtEndTime").focus();return ;
           }
           if (startTime=="" && endTime!="")
           {
                alert("请选择开始时间！");document.getElementById("txtStartTime").focus();return;
           }   
           if (startTime!="" && endTime!="")
           {
                if(!isShortDate(startTime))
                {
                    alert("输入正确的起始时间格式！");
                    return;
                }
                 if(!isShortDate(endTime))
                {
                    alert("输入正确的结束时间格式！");
                    return;
                }
                if (date_compare(startTime,endTime)<0)
                {
                    alert("开始时间不能大于结束时间！");document.getElementById("txtStartTime").focus();return;
                }
            }
           
           
              if(trimString(key) != "")
                 {
                     queryStand();
                 }
                 else
                 {
                    ddlStandLoad();
                   
                 }
                 
                  tbToStandarBind(1);
              
           
       }
       function ddlStandLoad()
       {
            //标准楼宇加载
           var dt = adminweb_Building_BuildingStandard.AreaStandSelect(provID, cityID, regionID,zoneID,keyWord,startTime,endTime).value;
              if(dt != null)
             {
                ddlBind(dt,"ddlStand","--标准楼宇--","name","id");
             }
              else
             {
                return;
             }
       }
       
          //未归标准楼宇加载
       function tbToStandarBind(currPage)
       {
         
          if(currPage==null)
           {
                currPage = 1;
           }
         stand = document.getElementById("ddlStand");
         
            standID = parseInt($("#ddlStand").val());
            deleteRow("tbToStandar");
            
            //未归标准楼宇加载
            var dt = adminweb_Building_BuildingStandard.AreaParentIDSelect(0,0,provID, cityID, regionID,zoneID,keyWord,startTime,endTime,10,currPage,0).value;
            var dtChild = document.getElementById("tbToStandar");
            if (dt != null && typeof(dt) == "object")
            {
               var len = dt.Data.Rows.length; 
               var row1;
               for(var i=0;i< len;i++)
               {
                    
                    row1   =   dtChild.insertRow(-1);   
                          var cell   =   row1.insertCell(-1);
                           cell.innerHTML   = (i+1).toString();
                          var cell =  row1.insertCell(-1);
                           cell.innerHTML = dt.Data.Rows[i].regionName;
                           var  cell =  row1.insertCell(-1);
                           cell.innerHTML = dt.Data.Rows[i].name;
                           var  cell =  row1.insertCell(-1);
                           cell.innerHTML = dt.Data.Rows[i].postTime;
                          var  cell =row1.insertCell(-1);
                           cell.innerHTML = "<a href='javascript:toStandar(" + dt.Data.Rows[i].id +")'>作为标准</a>";
                           var cell =row1.insertCell(-1);
                           cell.innerHTML = "<a href='javascript:toChild(" + dt.Data.Rows[i].id + ")'>成为标准楼宇的子集</a>";
                     
               }
               
           }
           pageChange("tbToStandar","divPage1",10,dt.RecordCount,currPage);
       }
       function toStandar(id)
       {
          
                var result = adminweb_Building_BuildingStandard.AreaParentIDUpdate( id, id).value;
              
                if(result == 1)
                {   
                    tbToStandarBind();
                     if(trimString(key) != "")
                     {
                         queryStand();
                     }
                     else
                     {
                        ddlStandLoad();
                       
                     }
                   alert('添加成功，此楼宇已成为标准楼宇！');
                 
                }
                else
                {
                   alert('添加失败！');
                   return;
                }
              
           
       }
       function toChild(id)
       {
            if(standID != 0)
            {
                var result = adminweb_Building_BuildingStandard.AreaParentIDUpdate( id, standID).value;
                if(result == 1)
                {
                   alert('添加成功，此楼宇已成为标准楼宇的子楼宇！');
                    tbToStandarBind();
                    tbInStandarBind();
                    
                }
                else
                {
                   alert('添加失败！');
                   return;
                }
              
           }
           else
           {
                alert('请选择标准楼宇！')
           }
       }
       function deleteArea(Id)
       {
             var result = adminweb_Building_BuildingStandard.AreaParentIDUpdate( Id, 0).value;
            if(result == 1)
            {
                window.alert('移除成功！');
                tbInStandarBind();
                tbToStandarBind();
            }
            else
            {
                window.alert('移除失败！');
                return;
            }
       }
       function deleteStandar()
       {
//            alert(standID +" delet");
            if(standID != 0)
            {
                 var result = adminweb_Building_BuildingStandard.AreaParentIDUpdate(standID, 0).value;
                if(result == 1)
                {
                    window.alert('楼宇非标准设置成功！');
                    tbToStandarBind();
                     if(trimString(key) != "")
                     {
                         queryStand();
                     }
                     else
                     {
                        ddlStandLoad();
                     }
                      
                }
                else if(result == -1)
                {
                    window.alert('此标准楼宇中存在子楼宇，请移除子楼宇后再做此操作！');
                    return;
                }
                else
                {
                    window.alert('楼宇非标准设置失败！');
                    return;
                }
            }
            else
            {
                window.alert("请选择标准楼宇！");
            }
       }
       function deleteRow(tblId)
       {
            var tbl = document.getElementById(tblId);
            var len = tbl.rows.length;
            if(len>0)
            {
                for(var i = 1; i< len ; i++)
                {
                    tbl.deleteRow(1);
                
                }
            }
       }
       
       function pageChange(tbID,divID,pageSize,recordCount,currPage)
       {
         var tabl = document.getElementById(tbID);
                var div  = document.getElementById(divID);
           var str = "";
          if(recordCount > 0)
          {
               if(currPage==null)
               {
                    currPage = 1;
               }
                var pageCount = 0;
                if((recordCount % pageSize)> 0)
                {
                     pageCount = parseInt(recordCount/pageSize) + 1;
                     
                }
                else
                {
                    pageCount =  recordCount/pageSize;
                }
               
                if (currPage == 1)
                {
                    str += "首页&nbsp;&nbsp;&nbsp;";
                    str　+= "上一页&nbsp;&nbsp;&nbsp;";
                }
                else
                {
                    str += "<a href='javaScript:tbToStandarBind(1)'>首页</a>&nbsp;&nbsp;&nbsp;" 
                    str += "<a href='javaScript:tbToStandarBind("+ (currPage-1) +")'>上一页</a>&nbsp;&nbsp;&nbsp;" 
                 }
                 if(currPage == pageCount)
                 {
                    str += "下一页&nbsp;&nbsp;&nbsp;";
                    str += "尾页";
                 }
                 else
                 {
                    str += "<a href='javaScript:tbToStandarBind("+ (1+currPage) +")'>下一页</a>&nbsp;&nbsp;&nbsp;"
                     str += "<a href='javaScript:tbToStandarBind("+ pageCount +")'>尾页</a>"
                }
            }
            else
            {
              str += "没有找到数据！";   
            }
           
            div.innerHTML = str;
            
       }
       function pageChange2(tbID,divID,pageSize,recordCount,currPage)
       {
         var tabl = document.getElementById(tbID);
                var div  = document.getElementById(divID);
           var str = "";
          if(recordCount > 0)
          {
               if(currPage==null)
               {
                    currPage = 1;
               }
                var pageCount = 0;
                if((recordCount % pageSize)> 0)
                {
                     pageCount = parseInt(recordCount/pageSize) + 1;
                     
                }
                else
                {
                    pageCount =  recordCount/pageSize;
                }
               
                if (currPage == 1)
                {
                    str += "首页&nbsp;&nbsp;&nbsp;";
                    str　+= "上一页&nbsp;&nbsp;&nbsp;";
                }
                else
                {
                    str += "<a href='javaScript:tbInStandarBind(1)'>首页</a>&nbsp;&nbsp;&nbsp;" 
                    str += "<a href='javaScript:tbInStandarBind("+ (currPage-1) +")'>上一页</a>&nbsp;&nbsp;&nbsp;" 
                 }
                 if(currPage == pageCount)
                 {
                    str += "下一页&nbsp;&nbsp;&nbsp;";
                    str += "尾页";
                 }
                 else
                 {
                    str += "<a href='javaScript:tbInStandarBind("+ (1+currPage) +")'>下一页</a>&nbsp;&nbsp;&nbsp;"
                     str += "<a href='javaScript:tbInStandarBind("+ pageCount +")'>尾页</a>"
                }
            }
            else
            {
              str += "没有找到数据！";   
            }
           
            div.innerHTML = str;
            
       }
       function queryStand()
       {
       
            ddlRemove("ddlStand");
            key  = trimString(document.getElementById("txtStandKey").value);
            if(trimString(key)=="")
            {
                ddlAdd("ddlStand","--标准楼宇--","0");
                window.alert("请填写楼宇关键字！");
                
                return;
            }
             var dt = adminweb_Building_BuildingStandard.AreaStandSelect(6, 6, 0,0,key,"","").value;
            
             if(dt != null && typeof(dt) == "object")
             {
                    if(dt.Rows.length >0)
                    {
                        ddlBind(dt,"ddlStand","--选择标准楼宇--","name","id");
                    }
                 else
                 {
                    ddlAdd("ddlStand","--选择标准楼宇--","0");
                    alert("没有数据！");
                 }
             }
            
       }
       
//    function pageUp()
       
    </script>
    
    <%--<script type="text/javascript">
       function addressLoad()
       
    </script>--%>
</head>

   

<body>
     <form id="form2" runat="server">
     <div class="HeadTitle">
          楼宇标准化</div>
        <div class="ToolBar">
        日期：<input id="txtStartTime" type="text" style="width: 75px" maxlength="10"  value="<%=DateTime.Now.Year.ToString()+'-'+DateTime.Now.Month+'-'+ '1' %>"/>--<input id="txtEndTime" type="text" style="width: 81px" maxlength="10" value="<%=DateTime.Now.ToString("yyyy-MM-d") %>" />
            关键字：<input id="txtKeyWord" style="width: 121px" type="text" maxlength="15" value="" /><br />
            <br />
            <br />
            
           
            <table  style="left: 11px; position: absolute; top: 57px">
                <tr>
                    <td style="width: 62px; height: 24px; " >
                        
                        <select id="ddlProvince">
                            <option value="0">--选择省份--</option>
                        </select>
                    </td>
                    <td style="width: 60px; height: 24px">
                       
                        <select id="ddlCity">
                            <option value="0">--选择城市--</option>
                        </select>
                        </td>
                         <td style="width: 59px; height: 24px">
                        
                        <select id="ddlRegion" onchange="ddlRegionChange();">
                           <option value="0">--选择地区--</option>
                        </select></td>
                    <td style="width: 61px; height: 24px">
                        
                        <select id="ddlZone" onchange="ddlZoneChange();">
                       <option value="0">--选择片区--</option>
                        </select></td>
                   
                        <td style="width: 247px; height: 24px">
                            &nbsp; &nbsp;&nbsp;<input id="btnQuery" type="button" value="查询"  onclick="query();"/>
                             
                        </td>
                        
                </tr>
            </table>        
            <br />
        </div>
        <br />
    <div style="text-align:left;margin:5px;">
    
    
     <table class="NewTable">
        <tr valign="top">
            <td style="height: 54px;" id="tdInStand">
            <div style="background-color:#f5f7ff; padding:5px;">
        标准楼宇关键字：<input style="width: 92px" id="txtStandKey" type="text" />
        <input id="btnSelect" onclick="queryStand();" type="button" value="搜索"/><br/>
        <b>标准楼宇： &nbsp;&nbsp; </b>
        <select style="width: 142px;" id="ddlStand" onchange="ddlStandChange();">
            <option selected="selected" value="0">--标准楼宇--</option>
        </select><br/>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<input id="btnStandarDelete" onclick="deleteStandar();" type="button" value="设为非标准"/><br />
        &nbsp;</div>
                <table id="tbInStandar" class="NewTable">
                <caption>
                  
                    标准楼宇中的楼宇</caption>
                <tbody>
                    <tr>
                        <th style="height: 40px">编号</th>
                        <th style="width: 62px; height: 40px">所属片区</th>
                        <th style="height: 40px">楼宇名称</th>
                         <th style="height: 40px">管理</th>
                          
                    </tr>
                    </tbody>
                </table>
                <div id ="divPage2" style="margin:auto; text-align:center;"></div>
            </td>
             <td style="height: 54px">
                 <table  id="tbToStandar" class="NewTable">
                 <caption>未归标准的楼宇</caption>
                    <tr>
                    <th>编号</th>
                    <th>所属片区</th>
                    <th style="width: 63px">楼宇名称</th>
                     <th>添加日期</th>
                      <th></th>
                       <th></th>
                        
                           
                    </tr>
                </table>
                <div id ="divPage1" style="margin:auto; text-align:center;"></div>
             </td>
        </tr>
     </table> 
    </div>
    
    </form>
</body>
</html>
