<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="siteListBoard.aspx.cs" Inherits="WebApp.Wpdcc.siteListBoard" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>运行监控图</title>
    <meta name="description" content="运行监控图" />

	<!--#include file = "../assets/head.htm" -->
    <!-- page specific plugin styles 日历样式 -->
	<link rel="stylesheet" href="../assets/css/datepicker.css" />

</head>
<body class="no-skin">
    <form id="form1" runat="server" class="form-horizontal">
    <div class="main-content-inner">
					<!-- #section:basics/content.breadcrumbs -->
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								主页
							</li>
							<li>站点运行监控</li>
							<li class="active">运行监控图</li>
						</ul><!-- /.breadcrumb -->

						<!-- /section:basics/content.searchbox -->
					</div>
					<!-- /section:basics/content.breadcrumbs -->
					<div class="page-content">
						<!-- /section:settings.box -->
						<div class="page-header">
							<div class="row">
							    <div class="col-xs-3">
							        <asp:DropDownList ID="ddlServerList" runat="server"></asp:DropDownList>
							        &nbsp;
							        <asp:Button ID="btnQuery" CssClass="btn btn-sm btn-primary" runat="server" OnClick="btnQuery_Click" Text="查看" />
							    </div>
							    <div class="col-xs-3">
							        <div class="input-daterange input-group">
									    <input type="text" id="stime" class="input-sm form-control" name="start" />
									    <span class="input-group-addon">
										    <i class="fa fa-exchange"></i>
									    </span>
									    <input type="text" id="etime" class="input-sm form-control" name="end" />
								    </div>
								    <!-- /section:plugins/date-time.datepicker -->
						        </div>
						        <div>
						            <input type="button" id="btnSelect" class="btn btn-sm btn-primary" value="查询" />
						            &nbsp;&nbsp;
						            <%--<input type="button" id="btnSnapshot" class="btn btn-sm btn-primary" value="快照" />--%>
						        </div>
						    </div><!-- /.page-header -->
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
						            <asp:GridView ID="GridView1" runat="server" CssClass="table table-striped table-bordered table-hover" AutoGenerateColumns="false" CellSpacing="-1" GridLines="None" OnPreRender="GridView1_PreRender">
                                        <Columns>
                                            <asp:TemplateField HeaderText="序号" InsertVisible="False" HeaderStyle-CssClass="hidden-xs" ItemStyle-CssClass="hidden-xs">
                                                <ItemTemplate>
                                                    <%#Container.DataItemIndex+1%>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:HyperLinkField DataNavigateUrlFields="domainName" DataNavigateUrlFormatString="http://{0}" DataTextField="schoolName" HeaderText="站点名称" Target="_blank" />
                                            <asp:TemplateField HeaderText="发文量" HeaderStyle-CssClass="hidden-xs" ItemStyle-CssClass="hidden-xs col-xs-3"> 
                                                <ItemTemplate>
                                                    <div class="progress pos-rel progress-yellow" data-percent="NaN篇">
								                        <div class="progress-bar progress-bar-danger" style="width: 1%;"></div>
							                        </div>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="访问量" HeaderStyle-CssClass="hidden-480" ItemStyle-CssClass="hidden-480"> 
                                                <ItemTemplate>
                                                    <b class="blue">NaN</b>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="超管密码等级" HeaderStyle-CssClass="hidden-xs" ItemStyle-CssClass="hidden-xs"> 
                                                <ItemTemplate>
                                                    <span class="badge badge-success">N</span><span class="badge badge-warning">N</span><span class="badge badge-danger">N</span><span class="badge badge-grey">N</span>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="用户密码等级" HeaderStyle-CssClass="hidden-xs" ItemStyle-CssClass="hidden-xs"> 
                                                <ItemTemplate>
                                                    <span class="badge badge-success">N</span><span class="badge badge-warning">N</span><span class="badge badge-danger">N</span><span class="badge badge-grey">N</span>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="站点透视"> 
                                                <ItemTemplate>
                                                    <div class="action-buttons">
											            <a class="blue FBox" href='siteReview.aspx?pkId=<%# DataBinder.Eval(Container, "DataItem.pkId")%>' target="_blank" >
												            <i class="ace-icon fa fa-search-plus bigger-130"></i>
											            </a>
										            </div>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:BoundField DataField="pkId" HeaderText="ID号" HeaderStyle-CssClass="hide" ItemStyle-CssClass="hide" FooterStyle-CssClass="hide"></asp:BoundField>
                                            <asp:TemplateField HeaderText="关注" HeaderStyle-CssClass="hidden-480" ItemStyle-CssClass="hidden-480"> 
                                                <ItemTemplate>
                                                    <input name="form-field-checkbox" class="ace ace-checkbox-2" type="checkbox" value="join" <%# Convert.ToInt32(Eval("follow")) > 0 ? "checked=\"checked\"" : "" %> />
													<span class="lbl"></span>
													
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:BoundField DataField="ak" HeaderText="ak" HeaderStyle-CssClass="hidden" ItemStyle-CssClass="hidden" />
                                        </Columns>
                                        <PagerSettings Visible="False" />
                                    </asp:GridView>
                                <!-- PAGE CONTENT ENDS -->
                                <div class="clearfix">
				                    <div class="col-md-12">
                                        <asp:Label ID="lblPage" runat="server"></asp:Label>
                                    </div>
                                </div>
                            </div>
                        </div><!-- /.row -->
					</div><!-- /.page-content -->
					
	</div>
    <asp:HiddenField ID="HfFWCycle" runat="server" />
    <asp:HiddenField ID="HfFWStandard" runat="server" />
    <input id="Hidden1" runat="server" type="hidden" value="-1" />
    <!--#include file = "../assets/foot.htm" -->
    <!-- inline scripts related to this page -->
	<script type="text/javascript">
	
	//加载运行监控图
	function loadSiteBoard(stime,etime)
	{
	            //加载运行监控图
                $('#GridView1 tr').each(function(){
                    var t1 = $(this).find('td').eq(2);
                    var t2 = $(this).find('td').eq(3);
                    var t3 = $(this).find('td').eq(4);
                    var t4 = $(this).find('td').eq(5);
                    var t9 = $(this).find('td').eq(9);//ak码
                    var a = $(this).find('td').eq(1).find('a').attr('href');
                    if($(this).find('td').eq(1).find('a').attr('href') != undefined)
                    {
                    //加载访问量
                    $.ajax({
                         type: "GET",
                         url: a+"/service/sitedataex.ashx",
                             data: {ak:t9.text(),code:"pv"},
                             dataType: "json",
                             success: function(data){
                             
                                         if(data.ret>0)
                                         {
                                            t2.html("<b class=\"blue\">"+data.msg+"</b>");
                                            
                                         }
                                         else
                                         {
                                            t2.html("<b class=\"blue\">"+data.pv[0].pv+"</b>");
                                            
                                         }
                                         
                                      },
                              error: function ()
                              {
//                                 t2.empty();   //清空
//                                 t2.html("加载异常");
                              }
                     });
                     
                    //获取发文量
                    $.ajax({
                         type: "GET",
                         url: a+"/service/sitedataex.ashx",
                         data: {ak:t9.text(),code:"colpublish", dt1:stime, dt2:etime},
                         dataType: "json",
                         success: function(data){
                                     
                                     if(data.ret>0)
                                     {
                                        t1.html(data.msg);
                                     }
                                     else
                                     {
                                        var fws = $('#HfFWStandard').val();//获取标准值。
                                        var bfb = (Math.round(data.colpublish[0].colpublish / (fws * 2) * 10000) / 100.00);// 小数点后两位百分比，此处的“2”为长度系数。
                                        
                                        if(bfb >= 50)
                                        {
                                            t1.html("<div class=\"progress pos-rel\" data-percent=\""+data.colpublish[0].colpublish+"篇\"><div class=\"progress-bar\" style=\"width:"+bfb+"%;\"></div></div>");
                                        }
                                        else
                                        {
                                            t1.html("<div class=\"progress pos-rel progress-yellow\" data-percent=\""+data.colpublish[0].colpublish+"篇\"><div class=\"progress-bar progress-bar-yellow\" style=\"width:"+bfb+"%;\"></div></div>");
                                        }
                                     }
                                  },
                          error: function ()
                          {
                             t1.empty();   //清空
                             //t1.html("加载异常");
                             t1.html("<div class=\"progress pos-rel progress-yellow\" data-percent=\"获取中\"><div class=\"progress-bar progress-bar-danger\" style=\"width:1%;\"></div></div>");
                          }
                     });
                    //获取密码强弱等级
                    $.ajax({
                         type: "GET",
                         url: a+"/service/sitedataex.ashx",
                         data: {ak:t9.text(),code:"pwdlevel"},
                         dataType: "json",
                         success: function(data){
                                     
                                     if(data.ret>0)
                                     {
                                        t3.html(data.msg);
                                        t4.html(data.msg);
                                     }
                                     else
                                     {
                                        t3.html("<span class=\"badge badge-success\" title=\"高强度\">"+data.pwdlevel[0].admin_high+"</span><span class=\"badge badge-warning\" title=\"中强度\">"+data.pwdlevel[0].admin_middle+"</span><span class=\"badge badge-danger\" title=\"低强度\">"+data.pwdlevel[0].admin_low+"</span><span class=\"badge badge-grey\" title=\"无强度\">"+data.pwdlevel[0].admin_unknown+"</span>");
                                        t4.html("<span class=\"badge badge-success\" title=\"高强度\">"+data.pwdlevel[0].user_high+"</span><span class=\"badge badge-warning\" title=\"中强度\">"+data.pwdlevel[0].user_middle+"</span><span class=\"badge badge-danger\" title=\"低强度\">"+data.pwdlevel[0].user_low+"</span><span class=\"badge badge-grey\" title=\"无强度\">"+data.pwdlevel[0].user_unknown+"</span>");
                                     }
                                  },
                          error: function ()
                          {
//                             t3.empty();   
//                             t3.html("加载异常");
//                             t4.empty();
//                             t4.html("加载异常");
                          }
                     });
                    }
                    
                });
	}
	
	function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "/";
        
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }
    //根据当前的时间，获取某个周期之前的时间。
    function getCycleFormatDate(wcycle) {
        var today = new Date();
        var date = new Date(today.getTime()-wcycle * 24 * 3600 * 1000);
        var seperator1 = "/";
        
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }

			jQuery(function($) {
			
				//or change it into a date range picker 日历脚本
				$('.input-daterange').datepicker({autoclose:true});
				
				var wcycle = $('#HfFWCycle').val();//获取周期值。
				
				//加载运行监控图
				$("#stime").val(getCycleFormatDate(wcycle));
				$("#etime").val(getNowFormatDate());
				loadSiteBoard($("#stime").val(),$("#etime").val());
				//loadSiteBoard(getCycleFormatDate(wcycle),getNowFormatDate());
                
                //绑定收藏功能
                $("[name='form-field-checkbox']:checkbox").on('click', function(){
                    
                    if($(this).is(':checked')) {
                        //选中
                        //alert($(this).parent().parent().find('td:nth-child(8)').text());
                        //$(this).parent().parent().find('td:nth-child(2)').html("<b class=\"blue\">选中</b>");
                        //增加站点关注
                        $.ajax({
                             type: "POST",
                             url: "siteListBoard.aspx/sitefollow",
                             //data: {type:1,site:$(this).parent().parent().find('td:nth-child(8)').text()},
                             data: "{'type':'1','site':'" + $(this).parent().parent().find('td:nth-child(8)').text() + "'}",
                             contentType: "application/json; charset=utf-8",
                             dataType: "json",
                             success: function(data){
                             data = JSON.parse(data);//返回的为字符串，需要进行json格式转换。
                                         if(data.ret>0)
                                         {
                                            alert(data.msg);
                                         }
                                         else
                                         {
                                            alert("关注成功");
                                         }
                                      },
                              error: function ()
                              {
                                
                              }
                         });
                    }
                    else
                    {
                        //取消选中
                        //alert("取消选中");
                        //$(this).parent().parent().find('td:nth-child(2)').html("<b class=\"blue\">取消选中</b>");
                        $.ajax({
                             type: "POST",
                             url: "siteListBoard.aspx/sitefollow",
                             //data: {type:0,site:$(this).parent().parent().find('td:nth-child(8)').text()},
                             data: "{'type':'0','site':'" + $(this).parent().parent().find('td:nth-child(8)').text() + "'}",
                             contentType: "application/json; charset=utf-8",
                             dataType: "json",
                             success: function(data){
                             data = JSON.parse(data);//返回的为字符串，需要进行json格式转换。
                                         if(data.ret>0)
                                         {
                                            alert(data.msg);
                                         }
                                         else
                                         {
                                            //alert(data.follow);
                                            alert("取消关注成功");
                                         }
                                      },
                              error: function ()
                              {
                                
                              }
                         });
                    }
        
                });
                
                //绑定查询按钮
                $('#btnSelect').click(function(){
                    loadSiteBoard($("#stime").val(),$("#etime").val());
                });
                
                //绑定查询按钮
                $('#btnSnapshot').click(function(){
                    bootbox.dialog({
						message: "<span class='bigger-110'>敬请期待</span>",
						buttons: 			
						{
							"success" :
							 {
								"label" : "<i class='ace-icon fa fa-check'></i>确定",
								"className" : "btn-sm btn-success",
								"callback": function() {
									//Example.show("great success");
								}
							}
						}
					});
                });
                
			});
		</script>
		<script lang="javascript" type="text/javascript">
        jQuery(function ($) {
            //编辑：打开弹出层
            $(".FBox").click().fancybox({
                autoSize:false,
                'width': 800,
                'height': 630,
                'hideOnOverlayClick': false,
                'type': 'iframe',
                'padding': '0'
            });

        });
    </script>
    </form>
</body>
</html>
