<!DOCTYPE html>
<html>
<head lang="zh">
    <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'>DO设置</a>
  </div>
  <div class='setbase' id="divDO" style='border: #B0B7BF 1px solid'>
    <table width='100%'>
      <tr id="trdo_set0" style="display:none">
      <th><span>DO1:</span></th>
      <th style='text-align: left'>
	   注:必须重启设备后生效！
      </th>
	  <th style='text-align: center' id="do_set0">
      </th>
      </tr>
	   <tr id="trdo_set1" style="display:none">
      <th><span>DO2:</span></th>
      <th style='text-align: left'>
	  注:必须重启设备后生效！
      </th>
	  <th style='text-align: center' id="do_set1">
		 
      </th>
      </tr>
	   <tr id="trdo_set2" style="display:none">
      <th><span>DO3:</span></th>
      <th style='text-align: left'>
	  注:必须重启设备后生效！
      </th>
	  <th style='text-align: center' id="do_set2">
		 
      </th>
      </tr>
    </table>
  </div>
</div>
<div style="display:none">
  <div class='list2' style='margin: 10px;'>
    <a class='you_p' href='#' style='color: #fff'>COM4设置</a>
  </div>
  <div class='setbase' style='border: #B0B7BF 1px solid'>
    <table width='100%'>
      <tr>
      <th><span>类型:</span></th>
      <th style='text-align: left'><select id="com4" style="width:180px">
        <option value="3">RS232
        <option value="4">RS485
      </select></th>
      <th><a id='abtn' href='javascript:savecom4()' class='back' style='color: #fff;background: #ffa225'>应用</a></th>
      </tr>
    </table>
  </div>
</div>

<div>
  <div class='list2' style='margin: 10px;'>
    <a class='you_p' href='#' style='color: #fff'>AI设置</a>
  </div>
  <div class='setbase' style='border: #B0B7BF 1px solid'>
    <table width='100%'>
      <tr>
      <th><span>类型:</span></th>
      <th style='text-align: left'><select id="aix" style="width:180px">
        <option value="0">电流输入（0~20mA）
        <option value="1">电压输入（0~12V）
        <option value="2">电压输入（0~3V）
      </select></th>
      <th><a id='abtn' href='javascript:saveai()' class='back' style='color: #fff;background: #ffa225'>应用</a></th>
      </tr>
    </table>
  </div>
</div>

<div>
  <table width='100%'><tr>
    <th><a href='javascript:history.back()' class='back' style='color: #fff'>返回</a></th>
  </tr></table>
</div>



<script>
<% db_Open("/NandFlash/dbCfg.db3"); %>
var jDOname = <% db_QryAdv("select Name from tbPort where Type=2",0); %>
<% db_Close(); %>


var DOCnt = jDOname.reccnt;



	  
list0(jDOname);
function list0(data){
	var tbX="";
	tbX+="<table width='100%'>\n";

    $.each(data.recs,function(i,n){		
		tbX+="<tr id=\"trdo_set";
		tbX+=i;
		tbX+="\" style=\"display:none\">\n";
		tbX+="<th><span>";
		tbX+=n.Name;
		tbX+=":</span></th>\n";
		tbX+="<th style='text-align: left'>\n  注:必须重启设备后生效！\n</th>\n";
		tbX+="<th style='text-align: center' id=\"do_set";
		tbX+=i;
		tbX+="\"></th>\n</tr>\n"
    })
	
	tbX+="</table>";
	document.getElementById("divDO").innerHTML = tbX;
	//console.log("tbX="+tbX);
}

var itype=3;
$(function(){
  $.ajax({
    type: "POST",
    url: "omdev/com4x.asp",
    data: "op=qry",
    dataType:"json",
    success: function(msg){
      if(msg.qry=="ok"){
        itype=msg.recs[0].Type;
        $("#com4").val(itype);
      }
    }
  });
  
  $.ajax({
    type: "POST",
    url: "omdev/smai.asp",
    data: "op=qry",
    dataType:"json",
    success: function(msg){
      if(msg.qry=="ok"){
        itype=msg.recs[0].Tag1;
        $("#aix").val(itype);
      }
    }
  });
  
  var s="";
   $.ajax({
    type: "POST",
    url: "omdev/doset.asp",
    data: "op=qry",
    dataType:"json",
    success: function(msg){
      if(msg.qry=="ok"){
	   $.each(msg.recs,function(i,n){
			s+="<a id='do_st"+i+"' href='javascript:doSt("+n.SID+","+i+")'>";
			if(n.State==0) s+="停用"; else s+="启用";
			s+="</a>";
			$("#do_set"+i).html(s);
			$("#trdo_set"+i).show();
			s="";
		})
		$("a:contains('启用')").addClass("red");
      }
    }
  });
});

function doSt(isid, itr){
  var s=$("#do_st"+itr).text()
  var ist=0;
  if(s=="停用"){
    s="启用"; ist=1;
  }
  else {
    s="停用"; ist=0;
  }
  $.ajax({
    type: "POST",
    url: "omdev/doset.asp",
    data: "op=st&sid="+isid+"&st="+ist,
    dataType:"json",
    success: function(msg){
      if(msg.op=="ok"){
        $("#do_st"+itr).html(s);
        $("a:contains('启用')").addClass("red");
        $("a:contains('停用')").removeClass("red");
      }
    }
  });
}


function savecom4(){
  var iv = $("#com4").val();
  if (iv==itype){
    alert("类型未更改!");
    return;
  }
  $.ajax({
    type: "POST",
    url: "omdev/com4x.asp",
    data: "op=upd"+iv,
    dataType:"json",
    success: function(msg){
      if(msg.op=="ok"){
        itype=iv;
        alert("COM4设置成功!");
      }
    }
  });
}

function saveai(){
  var iv = $("#aix").val();
  if (iv==itype){
    alert("类型未更改!");
    return;
  }
  $.ajax({
    type: "POST",
    url: "omdev/smai.asp",
    data: "op=upd&tag1="+iv,
    dataType:"json",
    success: function(msg){
      if(msg.op=="ok"){
        itype=iv;
        alert("AI类型设置成功!");
      }
    }
  });
}
</script>
</body>
</html>