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

<%@ Register Src="AreaUpPhoto.ascx" TagName="AreaUpPhoto" TagPrefix="uc1" %>
<!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" />

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

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

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

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

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

    <script type="text/javascript">
     var vensonNav1; 
    var PageSize = 6;
     function getProvinceList()
        {
            ddlRemove("ddlProvince");
            ddlAdd("ddlProvince", "省份", "0");
            var ret =  adminweb_Building_AreaManage.ddlProvinceDatabind().value;
            if (ret != null && typeof(ret) == "object")
            {
                for (var i = 0; i < ret.Rows.length; i++)
                {
                    ddlAdd("ddlProvince", ret.Rows[i].name, ret.Rows[i].id);
                    
                }
            }
            getCityList();
        }
        function getCityList()
        {
            ddlRemove("ddlCity");
            ddlAdd("ddlCity", "城市", "0");
            var provinceId = $("#ddlProvince").val();
            var ret =  adminweb_Building_AreaManage.cityLoad(provinceId).value;
            if (ret != null && typeof(ret) == "object")
            {
                for (var i = 0; i < ret.Rows.length; i++)
                {
                    ddlAdd("ddlCity", ret.Rows[i].name, ret.Rows[i].id);
                    
                }
            }
            getRegionList();
        }
        function getRegionList()
        {
            ddlRemove("ddlRegion");
            ddlAdd("ddlRegion", "城区", "0");
            var cityId = $("#ddlCity").val();
            if($("#ddlCity").val()==0)
            {
                
            }
            else
            {
                var ret =  adminweb_Building_AreaManage.regionLoad(cityId).value;
                if (ret != null && typeof(ret) == "object")
                {
                    for (var i = 0; i < ret.Rows.length; i++)
                    {
                        ddlAdd("ddlRegion", ret.Rows[i].name, ret.Rows[i].id);
                        
                    }
                }
            }
            getZoneList();
        }
        function getZoneList()
        {
            ddlRemove("ddlZone");
            ddlAdd("ddlZone", "片区", "0");
            var RegionId = parseInt($("#ddlRegion").val());
            if (RegionId > 0)
            {
                var ret =  adminweb_Building_AreaManage.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 getResult(evt)
{
  if(evt.keyCode=='13')
  {
	 Query1();
  }
 return true;
}

         function Query1()
         { 
            getBuildingList(1);
         }
        function getBuildingList(pageIndex)
        {
       
            var regionId = $("#ddlRegion").val();
            var zoneId = $("#ddlZone").val();
            var provinceId = $("#ddlProvince").val();
            var cityId = $("#ddlCity").val();
            var keyName = $("#txtName").val();
            var state = $("#ddlState").val();
            if(pageIndex != null)
            {
                vensonNav1.pageIndex = pageIndex;
               
            }
            var ret = adminweb_Building_AreaManage.GetBuildingList(provinceId,cityId,regionId,zoneId,state,keyName,PageSize,vensonNav1.pageIndex).value;
            vensonNav1.render(ret.AreaPageInfo.PageIndex, ret.AreaPageInfo.TotalPage);
            if(ret != null && typeof(ret) == "object")
            {
                $("#<%=divList.ClientID %>").html(ret.HtmlStr);
                $("#spTotal").html(ret.AreaPageInfo.TotalCount);
            }
        }
        function updateName(id,zoneId,name)
        {
            var newName = window.prompt("请输入要更改的名称：",name);
            if(newName == null)
            {
                return;
            }
            if($.trim(newName) =="")
            {
                window.alert("请输入楼宇/小区的名称！");
                return;
            }
            var len = $.trim(newName).replace(/[^\x00-\xff]/g,"xx").length;
            if( len > 50)
            {
                window.alert("输入的楼宇/小区名称的长度在25个汉字以内！");
                return;
            }
            var ret = adminweb_Building_AreaManage.UpdateName(id,zoneId,$.trim(newName)).value;
            if(ret == 1)
            {
                window.alert("更名成功！");
                getBuildingList();
                return;
            }
            else if(ret == -1)
            {
                window.alert("片区中已经存在与此同名的标准楼宇，请重新更改名称！");
            }
            else
            {
                window.alert("更名失败！");
            }
           
            
        }
        function updateState(id,state)
        {
            var state1 = "0";
            if(state == 0)
            {
                 state1 ="1";
            }
            else if(state=="2")
            { 
              if(confirm("激活该楼宇后，其状态自动为［已开放］！"))
              {
                state1="1";
              }else{return;}
            }
            var ret = adminweb_Building_AreaManage.UpdateState(id,state1).value;
            if(ret == 1)
            {
                window.alert('修改状态成功！');
                getBuildingList();
                
            }
            else
            {
                window.alert("修改状态失败！");
            }
            
        }
        function updateAddress(id)
        {
            window.open("AreaEdit.aspx?id="+ id +"","","width=800, height=250, status=yes, scrollbars");
        }
        function upPhoto(id)
        {
            window.open("AreaUploadPhoto.aspx?id="+ id +"","","width=500, height=230, status=yes, scrollbars=no");
        }
        function addAddress()
        {
            window.open("AreaAppend.aspx?areacount="+$("#spTotal").html(),"","width=800, height=270, status=yes, scrollbars");
        }
        var load = function()
        {
             vensonNav1 = new vensonNav("divPage", "getBuildingList");
             vensonNav1.render(<%=CurrPage %>, <%=TotalPage %>);
        }
        $(document).ready(function(){
        load();
        getProvinceList();});
    </script>

    <style type="text/css">
     PopMessage
        {
            position:absolute; 
            height:500px;
            padding:5px;
            left:0px; top:0px;
            background-color:#F7FCF5;
            z-index:9999;
            border:2px solid #61BD33;
            /*margin:60px 0 0 0;*/
        }
     </style>
</head>
<body>
    <form id="form1" runat="server">
        <div style=" padding-left:5px">
         &nbsp;<span>省份：</span>
            <select id="ddlProvince" onchange="getCityList();">
                <option value="0">省份</option>
            </select>
         &nbsp;<span>城市：</span>
            <select id="ddlCity" onchange="getRegionList();">
                <option value="0">城市</option>
            </select>
            &nbsp;<span>城区：</span>
            <select id="ddlRegion" onchange="getZoneList();">
                <option value="0">城区</option>
            </select>
            <span>片区：</span>
            <select id="ddlZone">
                <option value="0">片区</option>
            </select><br/><br/>
            &nbsp;<span>状态：&nbsp;</span><select id="ddlState">
                <option value="1">开放</option>
                <option value="0">关闭</option>
                <option value="2">未激活</option>
                <option value="-1">所有</option>
            </select>
          <span>名称关键字：</span>
            <input type="text" value="" style="display: none; " />
            <input type="text" value="" onkeypress="getResult(event)" id="txtName" />
            <input type="button" value="搜索" onclick="Query1()" />&nbsp;&nbsp;
  <a href="javascript:addAddress();" style="text-decoration: underline">
                【新增楼宇/小区】</a> <span style="color: Red">标准楼宇/小区总数：<span id="spTotal"><%=TotalCount %></span></span>
        </div>
        <br />
        <div class="MainContent">
            <%-- <div style=" float:left; width:100%">
        <a href="javascript:addAddress();" style=" text-decoration:underline">新增楼宇/小区</a>
        <span style="color:Red">标准楼宇/小区总数：<span id="spTotal"><%=TotalCount %></span></span>
      
    </div>--%>
            <div id="divList" style="text-align: left; float: left; width: 100%;" runat="server">
            </div>
        </div>
        <div style="text-align: center; width: 100%">
            <div id="divPage" style="text-align: center;">
            </div>
        </div>
        <%--<div id="divPhoto" style=" display:;" class="PopMessage">
    <iframe src="AreaUploadPhoto.aspx?id="></iframe>
        </div>--%>
    </form>
</body>
</html>
