<!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>
  <div class='list2' style='margin: 10px;'>
    <a class='you_p' href='#' style='color: #fff'>网络IP设备</a>
  </div>
  <div style='border: #B0B7BF 1px solid'>
    <table id='tbList' width='100%'>
    <tr bgcolor='#E5E9EC'><th style='padding: 10px'><span>SID</span> </th><th style='padding: 10px'><span>监测项描述</span></th><th style='padding: 10px'><span>传感器类型</span></th><th style='padding: 10px'><span>基本信息</span></th><th style='padding: 10px'><span>操作</span></th></tr>
    </table>
  </div>
</div>
<div>
  <table width='100%'>
    <tr>
    <td width="50%" style="border:none">传感器类型: <select id="lsType" style="width:350px"></select></td>
    <td style="border:none">&nbsp;</td>
    </tr>
    <tr>
    <td><a href='javascript:netAdd()' class='back' style='color: #fff;background: #ffa225'>+添加监测项</a></td>
    <td><a href='javascript:history.back()' class='back' style='color: #fff'>返回</a></td>
    </tr>
  </table>
</div>
<div  style="color:red">
  <br>温馨提示：
  <br>添加传感器的方法：选择需要添加的“传感器”后，
  <br>点击“+添加监测项”，即可完成对传感器的添加。
</div>
<script>
var devType = <% write(cfg_GetType()); %>;

<% db_Open("/NandFlash/dbCfg.db3"); %>
var jtype=<% db_QryAdv("select Type,t.Kind,t.Name,t.Note,Tag1,Port,k.Name as KName from tbSMType t left join tbSMKind k on k.Kind=t.Kind where Port=6 order by Type,Tag1",0); %>;
var ups_cyb_Cnt=<% write(db_QryInt("select count(*) from tbSM where Kind=768 or Kind=2048",1));%>;
<% db_Close(); %>

listT();
function listT(){
  if(jtype.reccnt==0) return;
  var s="";
  var ikind=0;
  var bShow = 1;
  $.each(jtype.recs, function(i,n){
    ikind = n.Type & 0xff00;
	bShow = 1;
    if ((0x0300==ikind) || (0x0800==ikind))
	{
		if ((1 == devType)) //设备类型 1-X100(不可接UPS及精密空调) 2-X300 3-T100 4-T300
		{
			bShow = 0;
			s+="<option value='"+((n.Type<<8)+n.Tag1)+"' style='display:none'>"+n.KName+" ("+n.Name+")&nbsp;&nbsp;&nbsp;"+n.Note;
		}
		else if ((2 == devType) && (ups_cyb_Cnt >= 2)) //设备类型 1-X100 2-X300(可接入2台UPS或精密空调) 3-T100 4-T300
		{
			bShow = 0;
			s+="<option value='"+((n.Type<<8)+n.Tag1)+"' style='display:none'>"+n.KName+" ("+n.Name+")&nbsp;&nbsp;&nbsp;"+n.Note;
		}
		else if ((3 == devType) && (ups_cyb_Cnt >= 4)) //设备类型 1-X100 2-X300 3-T100(可接入4台UPS或精密空调) 4-T300
		{
			bShow = 0;
			s+="<option value='"+((n.Type<<8)+n.Tag1)+"' style='display:none'>"+n.KName+" ("+n.Name+")&nbsp;&nbsp;&nbsp;"+n.Note;
		}
		else
		{
			s+="<option value='"+((n.Type<<8)+n.Tag1)+"'>"+n.KName+" ("+n.Name+")&nbsp;&nbsp;&nbsp;"+n.Note;
		}
	}
	else
	{
		s+="<option value='"+((n.Type<<8)+n.Tag1)+"'>"+n.KName+" ("+n.Name+")&nbsp;&nbsp;&nbsp;"+n.Note;
	}
  });
  $("#lsType").html(s);
}

$(function(){
    qryNet();
});

function qryNet(){
  $.ajax({
    type: "POST",
    url: "omdev/smbyport.asp",
    data: "port="+6,
    contentType:"application/x-www-form-urlencoded; charset=gb2312",
    dataType:"json",
    success: function(msg){
      listNet(msg)
    }
  });
}
function listNet(data){
  var s='';
  var kind = 0;
  
  s+="<tr bgcolor='#E5E9EC'><th style='padding: 10px'><span>SID</span> </th><th style='padding: 10px'><span>监测项描述</span></th><th style='padding: 10px'><span>传感器类型</span></th><th style='padding: 10px'><span>基本信息</span></th><th style='padding: 10px'><span>操作</span></th></tr>";
  $.each(data.recs,function(i,n){
    s+="<tr id='tr"+i+"'><th>"+n.SID+"</th><th style='text-align: left'>"+n.Name+"</th><th style='text-align: left'>"+n.KName+"("+n.TName+")</th><th style='text-align: left'>"+getNotes(n,i)+"</th><th>"+getOps(n,i)+"</th></tr>";
  })
  $("#tbList").html(s);
  $("a:contains('启用')").addClass("red");
}
function getNotes(n, i){
  var s="";
  s+="设置:"+n.SerDef;
  //s+="&nbsp;附注:"+n.Note;
  return s;
}
function getOps(n, i){
  var s="";
  s+="<a href='C0-6x.asp?sid="+n.SID+"&type="+n.Type+"&tag1="+n.Tag1+"'>编辑</a>";
  s+="&nbsp;&nbsp;<a id='sid_st"+i+"' href='javascript:sidSt("+n.SID+","+i+")'>";
  if(n.State==0) s+="停用"; else s+="启用";
  s+="</a>";
  s+="&nbsp;&nbsp;<a href='javascript:sidDel("+n.SID+","+i+")'>删除</a>";
  return s;
}
function sidSt(isid, itr){
  var s=$("#sid_st"+itr).text()
  var ist=0;
  if(s=="停用"){
    s="启用"; ist=1;
  }
  else {
    s="停用"; ist=0;
  }
  $.ajax({
    type: "POST",
    url: "omdev/smx.asp",
    data: "op=st&sid="+isid+"&st="+ist,
    dataType:"json",
    success: function(msg){
      if(msg.op=="ok"){
        $("#sid_st"+itr).html(s);
        $("a:contains('启用')").addClass("red");
        $("a:contains('停用')").removeClass("red");
      }
    }
  });
  //if(s=="停用")
  //  $("#sid_st"+itr).html("启用");
  //else
  //  $("#sid_st"+itr).html("停用");
}

function sidDel(isid, itr){
  var s="确定要删除 "+$("#tr"+itr+" th:eq(1)").text()+" SID="+isid+" 吗?";
  if(!confirm(s)) return;
  $.ajax({
    type: "POST",
    url: "omdev/smx.asp",
    data: "op=del&sid="+isid,
    dataType:"json",
    success: function(msg){
      if(msg.op=="ok")
        $("#tr"+itr).remove();
      else
        alert("删除 "+$("#tr"+itr+" th:eq(0)").text()+" 编号"+itype+"-"+itag+" 失败!");
    }
  });
}

function netAdd(){
    var s="";
    //s+="type+tag1="+$("#lsType").val();
    //s+="  ser="+$("#lsPort").val();
    //alert(s);
	var itype = ($("#lsType").val()>>8);
	var itag1 = ($("#lsType").val()) & 0xff;
    var kind = itype & 0xff00;
	//alert("添加类型："+kind+","+itype);
	if ((1 == devType) && ((0x0300==kind) || (0x0800==kind))) //设备类型 1-X100(不可接UPS及精密空调) 2-X300 3-T100 4-T300
	{
		alert("无操作权限！\n详情请与管理员联系。");
		return;
	}
	if ((2 == devType) && (ups_cyb_Cnt >= 2) && ((0x0300==kind) || (0x0800==kind))) //设备类型 1-X100 2-X300(可接入2台UPS或精密空调) 3-T100 4-T300
	{
		alert("UPS或精密空调接入数量不能超过2个！\n详情请与管理员联系。");
		return;
	}
	if ((3 == devType) && (ups_cyb_Cnt >= 4) && ((0x0300==kind) || (0x0800==kind))) //设备类型 1-X100 2-X300 3-T100(可接入4台UPS或精密空调 4-T300
	{
		alert("UPS或精密空调接入数量不能超过4个！\n详情请与管理员联系。");
		return;
	}
  
    s="C0-6x.asp?sid=0&type="+itype+"&tag1="+itag1;
    location.href=s;
}
</script>
</body>
</html>