<%@ page language="C#" autoeventwireup="true" inherits="adminweb_Building_OrdersBuildingAnalyze, 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"/>
    <%--<script type="text/javascript" src="../../js/Format.js"></script>
    <script type="text/javascript" src="../../js/Func.js"></script>--%>
    <script type="text/javascript" src="../../js/jquery.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" src="../../js/thickbox/thickbox.js"></script>
    <link href="../../js/thickbox/thickbox.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    
        var provinceID = 0;
        var cityID = 0;
        var regionID = 0;
        var zoneID = 0;
        var startDate = 0;
        var endDate ="";
        var orderType = 0;
        var orderState = 0;
        var sortStr = "";
        var rw = null;
        var hiOrderCountText = "";
        var hiOrderMoneyText = "";
        var hiUserCountText = "";
        var hiOrderCount = null;
        var hiOrderMoney = null;
        var hiUserCount = null;
       var loadPage = function() 
        {     
            var txtStartDate = document.getElementById("txtStartDate");
            var txtEndDate = document.getElementById("txtEndDate");
            
           
            $("#txtStartDate").calendar();
            $("#txtEndDate").calendar();
//            var date = "<%=DateTime.Now.ToString("yyyy-MM-dd") %>";
//            txtStartDate.value = date;
//         
             hiOrderCount = document.getElementById("hiOrderCount");
             hiOrderMoney = document.getElementById("hiOrderMoney");
             hiUserCount =  document.getElementById("hiUserCount");
            hiOrderCountText = document.getElementById("hiOrderCount").innerHTML;
            hiOrderMoneyText = document.getElementById("hiOrderMoney").innerHTML;
            hiUserCountText = document.getElementById("hiUserCount").innerHTML;
               getProvinceList(); 
               getOrderBuildingList(1);    
        }
       $(document).ready( function(){ loadPage() } );
        function browseType()
        {
            var exp=navigator.userAgent.toLowerCase();
            if(exp.indexOf("msie")!=-1)
                return "ie";
            else if(exp.indexOf("firefox")!=-1)
                return "ff";
            else
                return "";
        }

        function ddlAdd(element,text,value)
        {
            var ddl;
            if (typeof element == 'string')
              ddl = document.getElementById(element);
            else
              ddl = element;
              
            if(browseType()=='ie')
            {
                ddl.options.add(new Option(text,value));
            }
            else
            {
                var node=document.createElement('option');
                node.id = 'opt';
                node.value = value;
                node.innerHTML = text;
                ddl.appendChild(node);
            }         
        }
        function ddlRemove(ddlName)
        {
	        var ddl = document.getElementById(ddlName); 
	        ddl.length=0; 
        }
        
         function getProvinceList()
        {
            ddlRemove("ddlProvince");
            var ret = adminweb_Building_OrdersBuildingAnalyze.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);
                }
            }
            getCityList();
        }
        
        function getCityList()
        {
            ddlRemove("ddlCity");
            var ProvinceId = parseInt($("#ddlProvince").val());
            var ret = adminweb_Building_OrdersBuildingAnalyze.cityLoad(ProvinceId).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);
                }
            }
            getRegionList();
        }
        
        function getRegionList()
        {
            ddlRemove("ddlRegion");
            ddlAdd("ddlRegion", "全部", "0");
            var CityId = parseInt($("#ddlCity").val());
            if (CityId > 0)
            {
                var ret = adminweb_Building_OrdersBuildingAnalyze.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_OrdersBuildingAnalyze.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 getOrderBuildingList(currPage)
    {
         provinceID = parseInt($("#ddlProvince").val());
         cityID = parseInt($("#ddlCity").val());
         regionID = parseInt($("#ddlRegion").val());
         zoneID = parseInt($("#ddlZone").val());
         startDate = $("#txtStartDate").val();
         endDate = $("#txtEndDate").val();
        var type = $("#ddlType").val();
     
        
         orderState = parseInt($("#ddlState").val());
           if (startDate!="" && endDate=="")
           {
                alert("请选择结束时间！");document.getElementById("txtEndDate").focus();return ;
           }
           if (startDate=="" && endDate!="")
           {
                alert("请选择开始时间！");document.getElementById("txtStartDate").focus();return;
           }   
           if (startDate!="" && endDate!="")
           {
                if(!isShortDate(startDate))
                {
                    alert("输入正确的起始时间格式！");
                    return;
                }
                 if(!isShortDate(endDate))
                {
                    alert("输入正确的结束时间格式！");
                    return;
                }
                if (date_compare(startDate,endDate)<0)
                {
                    alert("开始时间不能大于结束时间！");document.getElementById("txtstartDate").focus();return;
                }
            }
//         window.alert(orderState);
         //获得总的订单量
         getOrderBuildingTotal();
          var divMain = document.getElementById("divContent");
        var str = "<table id='tbOrderBuildList' class='NewTable'><tr><th>编号</th><th >楼宇名称</th><th id='orderCount' onclick ='sortByOrderCount()' style='cursor:pointer'>订单笔数<span id = 'sortOrderCount'>"+ hiOrderCountText +"</span></th><th  id ='orderMoney' onclick='sortByOrderMoney()' style='cursor:pointer'>订单金额<span id = 'sortOrderMoney'>"+ hiOrderMoneyText +"</span></th><th>占总金额</th><th>订单均价</th><th id='orderUserCount' onclick='sortByUserCount()' style='cursor:pointer'>注册人数<span id = 'sortUserCount'>"+ hiUserCountText +"</span></th><th>非注册人数</th><th>备注</th></tr>"

        var ret = adminweb_Building_OrdersBuildingAnalyze.GetOrderBuildingList(provinceID,cityID,regionID,zoneID,-1,orderType,orderState,startDate,endDate,10,currPage,sortStr,type).value;

         if (ret != null && typeof(ret) == "object")
                { 
               
                    var len =  ret.Data.Rows.length;
                  
                    var rowType ;
                   for (var i = 0; i < len; i++)
                    {
                       rowType = ret.Data.Rows[i].type;
                  
                       //标准的楼宇 #3DA229 绿色
                       if(rowType == 1)
                       {
                          str +="<tr style='color:#3DA229' >";
                          str += "<td>"+ (i+1) +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].areaName +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].orderCount +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].orderTotal +"</td>";
                          str += "<td>"+ roundNum((ret.Data.Rows[i].orderTotal/rw[1])*100) +"%</td>";
                          str += "<td>"+ roundNum(ret.Data.Rows[i].orderTotal/ret.Data.Rows[i].orderCount) +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].userCount +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].noRegCount +"</td>";
                          str +="<td><a href='javascript:getOrderBuildingDetail("+ ret.Data.Rows[i].areaID +")'>查看详细信息</a></td>";
                          str += "</tr>";
                      }
                      else if(rowType == 2)//未归标准的楼宇
                      {
                        str +="<tr>";
                          str += "<td>"+ (i+1) +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].areaName +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].orderCount +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].orderTotal +"</td>";
                          str += "<td>"+ roundNum((ret.Data.Rows[i].orderTotal/rw[1])*100) +"%</td>";
                          str += "<td>"+ roundNum(ret.Data.Rows[i].orderTotal/ret.Data.Rows[i].orderCount) +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].userCount +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].noRegCount +"</td>";
                          str +="<td>未归标准的楼宇</td>";
                          str += "</tr>";
                      }
                      else if(rowType == 3)//删除的楼宇 红色
                      {
                        str +="<tr style='color:red'>";
                          str += "<td>"+ (i+1) +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].areaName +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].orderCount +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].orderTotal +"</td>";
                          str += "<td>"+ roundNum((ret.Data.Rows[i].orderTotal/rw[1])*100) +"%</td>";
                          str += "<td>"+ roundNum(ret.Data.Rows[i].orderTotal/ret.Data.Rows[i].orderCount) +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].userCount +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].noRegCount +"</td>";
                          str +="<td>楼宇已删除</td>";
                          str += "</tr>";
                      }
                      else
                      {
                        str +="<tr>";
                          str += "<td>"+ (i+1) +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].areaName +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].orderCount +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].orderTotal +"</td>";
                          str += "<td>"+ roundNum((ret.Data.Rows[i].orderTotal/rw[1])*100) +"%</td>";
                          str += "<td>"+ roundNum(ret.Data.Rows[i].orderTotal/ret.Data.Rows[i].orderCount) +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].userCount +"</td>";
                          str += "<td>"+ ret.Data.Rows[i].noRegCount +"</td>";
                          str +="<td>楼宇已删除</td>";
                          str += "</tr>";
                      }
                    }
                 
                }
        str += "</table>";
        divMain.innerHTML = str;
         pageChange("tbOrderBuildList","PageNav",getOrderBuildingList,10,ret.RecordCount,currPage);
    }
    function getOrderBuildingDetail(parentID)
    {
      var str = "<table class='NewTable'><tr><th>编号</th><th>楼宇名称</th><th id='orderCount'>订单笔数</th><th id ='orderMoney'>订单金额</th><th>占总金额</th><th>订单均价</th><th >注册人数</th><th>非注册人数</th></tr>"
                 var ret = adminweb_Building_OrdersBuildingAnalyze.GetOrderBuildingList(provinceID,cityID,regionID,zoneID,parentID,orderType,orderState,startDate,endDate,20,1,"").value;
                
                 if (ret != null && typeof(ret) == "object")
                        {
                            var len = ret.Data.Rows.length;
                            for (var i = 0; i < len; i++)
                            {
                               
                              str +="<tr>";
                              str += "<td>"+ (i+1) +"</td>";
                              str += "<td>"+ ret.Data.Rows[i].areaName +"</td>";
                              str += "<td>"+ ret.Data.Rows[i].orderCount +"</td>";
                              str += "<td>"+ ret.Data.Rows[i].orderTotal +"</td>";
                              str += "<td>"+ roundNum((ret.Data.Rows[i].orderTotal/rw[1])*100) +"%</td>";
                              str += "<td>"+ roundNum(ret.Data.Rows[i].orderTotal/ret.Data.Rows[i].orderCount) +"</td>";
                              str += "<td>"+ ret.Data.Rows[i].userCount +"</td>";
                              str += "<td>"+ ret.Data.Rows[i].noRegCount +"</td>";
                              str += "</tr>";
                            }
                         
                        }
                str += "</table>";
               var divDe = document.getElementById("divDetail");
               divDe.innerHTML = str;
//                <input alt="#TB_inline?height=300&width=400&inlineId=myOnPageContent" title="add a caption to title attribute / or leave blank" class="thickbox" type="button" value="Show" /> 
                var url = "#TB_inline?height=200&width=500&inlineId=divDetail&modal=false";
                tb_show("查看详细信息", url); 
//                 <a href="#TB_inline?height=155&width=300&inlineId=hiddenModalContent&modal=true" class="thickbox">Show hidden modal content.</a>
//                window.alert(str);
               
        
    }
    //根据不同的字段进行排序
    var spOrderCount = "";
    var spOrderMoney = "";
    var spUserCount = "";
    function sortByOrderCount()
    {
         var spID = document.getElementById("sortOrderCount");
         spOrderCount = spID.innerHTML;
           if(spOrderCount =="↑")
           {
              hiOrderCountText ="↓";
              sortStr = "order by orderCount desc";
           }
           else
           {
                 hiOrderCountText ="↑";
                sortStr = "order by orderCount";
           }
           getOrderBuildingList(1);  
    }
     function sortByOrderMoney()
    {
         var spID = document.getElementById("sortOrderMoney");
         spOrderMoney = spID.innerHTML;
           if(spOrderMoney =="↑")
           {
              hiOrderMoneyText ="↓";
              sortStr = "order by orderTotal desc";
           }
           else
           {
                 hiOrderMoneyText ="↑";
                sortStr = "order by orderTotal";
           }
           getOrderBuildingList(1);  
    }
    function sortByUserCount()
    {
         var spID = document.getElementById("sortUserCount");
         spUserCount = spID.innerHTML;
           if(spUserCount =="↑")
           {
              hiUserCountText ="↓";
              sortStr = "order by userCount desc";
           }
           else
           {
                 hiUserCountText ="↑";
                sortStr = "order by userCount";
           }
           getOrderBuildingList(1); 
    }
    
    function getOrderBuildingTotal()
    {
        var orderCount =document.getElementById("spOrderCount");
        var orderTotal = document.getElementById("spOrderTotal");
        var orderAvg = document.getElementById("spOrderAvg");
        var buildCount = document.getElementById("buildCount");
        var standBuildCount = document.getElementById("standBuildCount");
        var type = $("#ddlType").val();
   
 
        rw  = adminweb_Building_OrdersBuildingAnalyze.GetOrderBuildingTotal(provinceID,cityID,regionID,zoneID,orderType,orderState,startDate,endDate,type).value;
        orderCount.innerHTML = rw[0] + "笔";

        if(rw[0] != 0)
        {
            orderTotal.innerHTML = roundNum(rw[1]) + "元";
            orderAvg.innerHTML = roundNum(rw[1] / rw[0]) + "元";
          
        }
        else
        {
            orderTotal.innerHTML = "0.00元";
             orderAvg.innerHTML = "0.00元";
        }
          buildCount.innerHTML = rw[2]+"个";
          standBuildCount.innerHTML = rw[3]+"个";
      
    }
    

//分页
    function pageChange(tbID,divID,methodName,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:getOrderBuildingList(1)'>首页</a>&nbsp;&nbsp;&nbsp;" 
                    str += "<a href='javaScript:getOrderBuildingList("+ (currPage-1) +")'>上一页</a>&nbsp;&nbsp;&nbsp;" 
                 }
                 if(currPage == pageCount)
                 {
                    str += "下一页&nbsp;&nbsp;&nbsp;";
                    str += "尾页";
                 }
                 else
                 {
                    str += "<a href='javaScript:getOrderBuildingList("+ (1+currPage) +")'>下一页</a>&nbsp;&nbsp;&nbsp;"
                     str += "<a href='javaScript:getOrderBuildingList("+ pageCount +")'>尾页</a>"
                }
            }
            else
            {
              str += "没有找到数据！";   
            }
           
            div.innerHTML = str;
            
       }
       //四舍五入保留2位小数
       function roundNum(number)
       {
         number = Math.round(number * 100)/100;
         return number;
       }
       
        var isShortDate = function( sDate ) {
            var r = sDate.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
            if ( r == null ) return false;
            try {
                var myDate = new Date( r[1], r[3], r[4] );
            } catch( e ) {
                return false;
            }
            return true; 
        }
        
        function date_compare(asstartdate,asenddate)
        {//计算两个字符(yyyy-mm-dd)的日期相隔天数
            var mistart = Date.parse(asstartdate.replace(/\-/g, '/'));
            var miend = Date.parse(asenddate.replace(/\-/g, '/'));
            result = (miend-mistart)/(1000*24*3600);
            return result;
        }
        
</script>
</head>
<body >
    <form id="form1" runat="server">
    <div id="divTitle"  style="background-color:#039; margin:5px; font-size:14px; font-weight:bold;  padding:5px;color:#fff;">
        订单楼宇分布表
    </div>
    <div id="divBar" style="padding:5px;text-align:left;background-color:#eaf7ff;border-bottom:2px solid #369;">
        地区选择：<span>省份：</span>
                <select id="ddlProvince">
                    <option value="0">全部</option>
                </select>
                <span>城市：</span>
                <select id="ddlCity" onchange="getRegionList();">
                    <option value="0">全部</option>
                </select>
                <span>地区：</span>
                <select id="ddlRegion" onchange="getZoneList();" >
                    <option value="0">全部</option>
                </select>
               
                <span>片区：</span>
                <select id="ddlZone" >
                    <option value="0">全部</option>
                </select>
        <br />
                <%--<span>小区：</span>
                <select id="ddlArea" onchange="getZoneList();">
                    <option value="0">全部</option>
                </select>--%><br/>
        开始日期：<input id="txtStartDate" type="text" style="width: 92px" value="<%=DateTime.Now.Year.ToString()+'-'+DateTime.Now.Month+'-'+ '1' %>"/>结束日期：<input id="txtEndDate" type="text" value="<%=DateTime.Now.ToString("yyyy-MM-d") %>" style="width: 107px"  />
        楼宇统计数据类型选择：
        <select id="ddlType">
                    <option value="0">全部</option>
                    <option value="1">标准楼宇及子楼宇</option>
                    <option value="2">未归标准的楼宇</option>
                    <option value="3">删除的有订单的楼宇</option>
                   
        </select><br />
        <br/>
        订单状态： <select id="ddlState">
                    <option value="-3">全部</option>
                    <option value="-2">虚假</option>
                    <option value="-1">作废</option>
                    <option value="0">待处理</option>
                    <option value="1" selected="selected">已完成</option>
        </select>
        &nbsp;
        <input id="btnSub" type="button" value="统计" style="width: 54px"  onclick="getOrderBuildingList(1);"/>&nbsp;<span style="color:Red">说明：绿色代表标准楼宇，红色代表有订单已删除的楼宇</span></div>
        <div id="divTotal" style="background-color:#f5f7ff; margin:5px;">
            <br />
            订单总笔数：<span id="spOrderCount"   style="color:#f00">0笔</span>订单总金额：<span id="spOrderTotal"  style="color:#f00">0.00元</span>订单均价：<span id="spOrderAvg"  style="color:#f00">0.00元</span>
            楼宇总数：<span id="buildCount"  style="color:#f00">0个</span> 标准楼宇总数：<span id="standBuildCount"  style="color:#f00">0个</span>
            </div>
    <div id="divContent" style="text-align:left;margin:5px;">
<%--    <table id="ListTable" class="NewTable">
                <tr>
                    <th>编号</th>
                    <th>楼宇名称</th>
                    <th>订单笔数</th>
                    <th>订单金额</th>
                    <th>占总金额</th>
                    <th>订单均价</th>
                    <th>注册人数</th>
                    <th>非注册人数</th>
                </tr>
            </table>--%>
        <span id="hiOrderCount" style="display:none">↓</span>
        <span id="hiOrderMoney" style="display:none">↓</span>
        <span id="hiUserCount" style="display:none">↓</span>
      </div>
            <div id="PageNav">
            </div>
            <div id ="divDetail"  style="overflow:auto;background-color:#f5f7ff; margin:5px; display:none;"></div>
            
    </form>
</body>
</html>
