<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="GB2312">
    <title></title>
    <link href="css/style.css" title="style" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.6.3.min.js"></script>

</head>
<body style="background: #F3F3F3">
<div class="append1"></div>
<div class="append2"></div>
<a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
<script>
<%
db_Open("/NandFlash/tmp/dbDat0.db3");
var sql="select d.*,s.Name,s.Tag1,s.KName,s.TName,s.SerType,s.SerDef,s.SerAddr,b.Brief from tbSubSysDetail d left join tbSM s on s.SID=d.SID left join tbSMBrief b on b.SID=d.SID where SubSys="+subsys;
%>
  var isubsys=<%write(subsys);%>;
  var json= <%db_QryAdv(sql);%>;
<%
db_Close();
%>

<%
db_Open("/NandFlash/dbCfg.db3");
%>
  var jport=<% db_QryAdv("select * from tbPort where Type=1  order by Type,Name",0); %>;
<%
db_Close();
%>
var tescape= 5000,time;
list2(json);
$(function(){
    time=setInterval(ajax,tescape);
});
function ajax(){
    $.ajax({
        type: "POST",
        url: "omdev/smbysubsys.asp",
        data: "subsys="+isubsys,
        contentType:"application/x-www-form-urlencoded; charset=gb2312",
        dataType:"json",
        success: function(msg){
            list2(msg)
        }
    });
}

function subsysName(){
    switch(isubsys){
    case 1: return "市电监测";
    case 2: return "配电监测";
    case 3: return "UPS监测";
    case 4: return "电池监测";
    case 5: return "温度湿度";
    case 6: return "漏水监测";
    case 7: return "空调监测";
    case 8: return "精密空调";
    case 9: return "烟雾监测";
    case 10: return "红外监测";
    case 11: return "门禁门磁";
    }
    return "其他分类";
}

function subsysicon(st){
    switch(isubsys){
    case 1: return "ico-elec-small.png";
    case 2: return "ico-elecsw-small.png";
    case 3: return "ico-ups-small.png";
    case 4: return "ico-batt-small.png";
    case 5: return "ico-envir-small.png";
    case 6: return "ico-leak-small.png";
    case 7: return "ico-airc-small.png";
    case 8: return "ico-cyber-small.png";
    case 9: return "ico-smoke-small.png";
    case 10: return "ico-infrared-small.png";
    case 11: 
		if (st == 0)
			return "ico-card-small.png";
		else
			return "ico-card-small-1.png";
    case 12: return "ico-cam-small.png";
    }
    return "ico-unknow-small.png";
}

function doCfBf(cf)
{
    if (json.reccnt==0) return;
    var cfbf=16;
    if (cf==1) cfbf++;
    var dest=json.recs[0].SID;
    $.ajax({
        type: "POST",
        url: "action/doctrl",
        data: "op="+cfbf+"&value="+dest,
        dataType: "text",
        success: function(msg){
            alert("操作 "+msg+"!");
        }
    });
}

function list2(data){
  var q='';
  var w='';
  q+="<div class='list2' style='margin: 10px;'>";
  w+="<a class='you_p' href='#' style='color: #fff'>"+ subsysName()+"</a>";
  if (isubsys==10)
      w+="&nbsp;&nbsp;<input type='button' value='撤  防' onclick='doCfBf(1)' />&nbsp;&nbsp;<input type='button' id='btn_bf' value='布  防' onclick='doCfBf(0)' />";
  q+="<div style='border: #B0B7BF 1px solid'>";
  q+="<table  width='100%'>";
  q+= "<tr><th style='padding: 10px;background:#E5E9EC'></th><th style='padding: 10px;background:#E5E9EC'><span>监测项描述</span> </th><th style='padding: 10px;background:#E5E9EC'><span>传感器类型</span></th><th style='padding: 10px;background:#E5E9EC'><span>基本信息</span></th><th style='padding: 10px;background:#E5E9EC'><span>状态</span></th><th style='padding: 10px;background:#E5E9EC'><span>操作</span></th></tr>";
  var sname, snote;
  $.each(data.recs,function(i,n){
    if(n.State==0) {n.State="正常"}
    else if(n.State==1) {n.State="告警"}
    else {n.State="故障"}
	
	if (((n.Type & 0xff00) == 0x0C00))//相机，不经过采集程序
		n.State = "正常";
    sname=n.Name;
    //if(n.ANote!="") sname=n.ANote;
    //if(n.ANote2!="") sname=n.ANote2;
    if(n.SerDef=="")
	 {
	   var label = 0;
	   var Aid ="";
	  for(var i =0;i<jport.reccnt;i++)
	  {	    
		if(jport.recs[i].Val==n.SerType && n.Tag1==1)
		{ 
		    if(jport.recs[i].Type ==1)
			{
			  label = 1;
			  Aid =jport.recs[i].Val - jport.recs[i].SID*256;
			  break;
			}	 	
		}	
	  }	
	   if(label == 1)
		{
		  q+="<tr><th><img src='img/" + subsysicon(1) + "' style='width: 40px;text-align: center;'></th><th>"+sname+"</th><th style='text-align: left'>"+n.TName+"</th><th style='text-align: left'>SID:<span>"+n.SID+"</span>&nbsp;&nbsp;编址:<span>"+n.SerAddr+"</span>&nbsp;&nbsp;端口:<span>"+"AI"+Aid+"</span>&nbsp;&nbsp;更新时间:<span class='LastUpd'>"+ n.LastUpd+"</span>&nbsp;&nbsp;<br><span>"+ n.Brief+"</span></th><th><span class='State'>";
		  q+=n.State+"</span></th><th><a href='A3-AI";
		  q+=".asp?sid="+n.SID+"&tag1=" + n.Tag1 +"&type=" + n.Type +"&subsys="+isubsys+"' class='list_btn'  >详细</a> <a href='C2-0.asp?sid="+n.SID+"&itype="+n.Type+"'>属性</a></th></tr>";         
		}
		else
		{
		   q+="<tr><th><img src='img/" + subsysicon (1)+ "' style='width: 40px;text-align: center;'></th><th>"+sname+"</th><th style='text-align: left'>"+n.TName+"</th><th style='text-align: left'>SID:<span>"+n.SID+"</span>&nbsp;&nbsp;编址:<span>"+n.SerAddr+"</span>&nbsp;&nbsp;DIx:<span>"+n.Fld+"</span>&nbsp;&nbsp;更新时间:<span class='LastUpd'>"+ n.LastUpd+"</span>&nbsp;&nbsp;<br><span>"+ n.Brief+"</span></th><th><span class='State'>"+ n.State+"</span></th><th><span class='grey'>开关量</span></th></tr>";	
		}
     }
    else
	{
	  if(n.Type==1539)
		q+="<tr><th><img src='img/" + subsysicon(0) + "' style='width: 40px;text-align: center;'></th><th>"+sname+"</th><th style='text-align: left'>"+n.KName+" ("+n.TName+")</th><th style='text-align: left'>SID:<span>"+n.SID+"</span>&nbsp;&nbsp;数据端口:<span>"+"内置漏水传感器"+(n.Tag1+1)+"</span>&nbsp;&nbsp;更新时间:<span class='LastUpd'>"+ n.LastUpd+"</span>&nbsp;&nbsp;<br><span>"+ n.Brief+"</span></th><th><span class='State'>";
      else
	    q+="<tr><th><img src='img/" + subsysicon(0) + "' style='width: 40px;text-align: center;'></th><th>"+sname+"</th><th style='text-align: left'>"+n.KName+" ("+n.TName+")</th><th style='text-align: left'>SID:<span>"+n.SID+"</span>&nbsp;&nbsp;编址:<span>"+n.SerAddr+"</span>&nbsp;&nbsp;数据端口:<span>"+n.SerType%256+"</span>&nbsp;&nbsp;更新时间:<span class='LastUpd'>"+ n.LastUpd+"</span>&nbsp;&nbsp;<br><span>"+ n.Brief+"</span></th><th><span class='State'>";
      
	  if(n.Type==3327)
	  {
        q+="正常</span></th><th><a href='http://"+n.SerDef+"' target='_blank'>打开</a></th></tr>";
      }
      else
	  {
        q+=n.State+"</span></th><th><a href='A3-"+n.Type;
        if(n.Type==1792 && n.Tag1 == 1) 
			q+="-"+n.Tag1;
        if(n.Type==2056 && n.Tag1 == 1) 
			q+="-"+n.Tag1;
		if (n.Type == 2317)
			q+=".asp?sid="+n.SID+"&tag1=" + n.Tag1 + "' class='list_btn'  >详细</a> <a href='C2-0.asp?sid="+n.SID+"&itype="+n.Type+"'>属性</a></th></tr>";
		else
			q+=".asp?sid="+n.SID+"' class='list_btn'  >详细</a> <a href='C2-0.asp?sid="+n.SID+"&itype="+n.Type+"'>属性</a></th></tr>";
      }
    }
  });
  $(".append1").html(w);
  $(".append2").html(q);
  $("span:contains('正常')").addClass("ger").removeClass("red");
  $("span:contains('故障'),span:contains('告警'),span:contains('报警'),span:contains('闭合')").addClass("red").removeClass("ger");
}

</script>
</body>
</html>