<!--#include file="../../fy.Function.asp"-->
<!--#include file="../../../fy_inc/cls_pageview.asp"-->
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>数据源</title>
<link rel="stylesheet" type="text/css" href="../../css/base.css">
<link rel="stylesheet" type="text/css" href="../../css/content.css">
</head>
<body>
<div class="content"> 
	<div class="breadnav">当前位置：<a href="#">后台首页</a> >> 模型管理</div>
    <div class="opers">
    	<a href="?Action=add" class="btn<%If Request("Action")="add" Then echo " btn_primary" %>">添加数据源</a>
		<a href="?"  class="btn<%If Request("Action")="" Then echo " btn_primary" %>">查看数据源</a>
    </div>
 
	
<% 
	'echo fycms.dbquery("1",2)
	Dim sql,OpenWay,sqlCount,Sqls,intPageSize, strPageInfo,arrinfo, i,pages,intPageNow,strLocalUrl,Action,MenuUrl,dbName
	Action=Request("Action")
	Dim ShowErr,dbtype,dbqueryContent
		IF Request.QueryString("Action") = "del" Then
		Dim ID:ID = Request("ID")
			IF ID = "" Then
			
				Call fycms.ActErr("请指定要删除的ID","","1")
				Response.end
			End IF
		If instr(ID,",")>0 then
			ID=replace(ID," ","")
			Sql="delete from dbquery_fy where ID in (" & ID & ")"
		Else
			Sql="delete from dbquery_fy where ID=" &  ChkNumeric(ID) & ""
		End if
		Conn.Execute sql:Set Conn=nothing
		 Call fycms.ActErr("删除成功","include/plus/dbquery.asp","")
 	  End IF
	  
	  Select Case Action
	  		Case "edit","add"
				call edit()
			Case "AddSave","EditSave"
				Call Saves()
			Case Else
				call main()
		end select
		sub main()
	 Dim ACT_TypeDiY,TypeDiY,Manage
	strLocalUrl = request.ServerVariables("SCRIPT_NAME")
	intPageNow = request.QueryString("page")
	intPageSize =20
	sql = "SELECT [ID], [dbName], [dbtype]" & _
		" FROM [dbquery_fy] " & _
		" ORDER BY [ID] DESC"
	sqlCount = "SELECT Count([ID])" & _
			" FROM [dbquery_fy]"
		Dim clsRecordInfo
		Set clsRecordInfo = New Cls_PageView
			clsRecordInfo.intRecordCount = 2816
			clsRecordInfo.strSqlCount = sqlCount
			clsRecordInfo.strSql = sql
			clsRecordInfo.intPageSize = intPageSize
			clsRecordInfo.intPageNow = intPageNow
			clsRecordInfo.strPageUrl = strLocalUrl
			clsRecordInfo.strPageVar = "page"
		clsRecordInfo.objConn = Conn		
		arrinfo = clsRecordInfo.arrinfo
		strPageInfo = clsRecordInfo.strPageInfo
		Set clsRecordInfo = nothing
	 %>
	
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
      <th>选中</th>
	  <th>调用ID</th>
	  <th>名称</th>
	  <th>数据源</th>
	  <th>管理操作</th>
	  </tr>
    </thead>	 <%
		If IsArray(arrinfo) Then
			For i = 0 to UBound(arrinfo, 2)
	%>

    <tr>
      <td>
	  <input type="checkbox" name="ID" value="<%= arrinfo(0,i) %>">	  </td>
      <td><%= arrinfo(0,i) %></td>
      <td><%= arrinfo(1,i) %></td>
      <td><%

			 Select Case arrinfo(2,i) 
				Case "0"
					echo "FYCMS主数据库"
				Case "1"
					echo "Access数据源"
				Case "2"
					echo "MSSQL数据源"
				Case "3"
					echo "ODBC数据源"
				Case "4"
					echo "Oracle数据源"
				Case "5"
					echo "Excel数据源"
				Case "6"
					echo "Dbase数据源"
				Case "7"
					echo "MYSQL数据源"
			 
			 End Select %>
				  
 	  </td>
      <td>
	  <a href="?Action=edit&id=<%= arrinfo(0,i) %>">修改</a>┆
	  <a href="?Action=del&ID=<%= arrinfo(0,i) %>" onClick="return confirm('确认删除此自定义属性吗?')">删除</a>	  </td>
    </tr>
	<% 
	Next
	End If
	%>    </table>
    <div class="pagelist">
    	<%= strPageInfo%>
   </div>
   </form>
     <script language="javascript">
function CheckAll(form)  
  {  
 for (var i=0;i<form.elements.length;i++)  
    {  
    var e = Article.elements[i];  
   if (e.name != 'chkall')  
      e.checked = Article.chkall.checked;  
   }  
  }
 function delpost(){
    document.Article.method="post";
    document.Article.action="?Action=del";
{
	if(confirm('确认要删除选中的Tags吗?')){
	this.document.Article.submit();
	return true;}return false;
}
	}
</script>
  <% end sub
Sub edit() 
	If Action ="edit" Then 
		Dim Rs,ID,A
		id = ChkNumeric(Request.QueryString("id"))
		Set Rs=fycms.actexe("select * from dbquery_fy Where id="&id&"")
		If rs.eof Then
			Call fycms.alert("未知错误","")
		Else
 			dbName=Rs("dbName")
			Id=Rs("Id")
			dbtype=rs("dbtype")
 			if dbtype="0" then 
				dbqueryContent="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={fy:dir}数据库.mdb"
			Else   
				dbqueryContent=rs("dbqueryContent")
			End  if
  		End If
		A="EditSave"
	Else
		dbtype=0
		dbqueryContent="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={fy:dir}数据库.mdb"
		A="AddSave"	
 	End If 

%>

<form name="ahhfchhs" id="ahhfchhs"  method="post" action="?action=<%= A %>&ID=<%= ID %>">
    <div class="divtable"> 
        <dl>
            <dt>菜单名称：</dt>
            <dd>
            <input name="dbName" type="text" class="Ainput" value="<%= dbName %>" size=50>      
            </dd>
         </dl>
        
        <dl>
            <dt>数 据 源：</dt>
            <dd>
                <select name="dbtype" id="dbtype" style="width:200px"  onChange="changeconnstr(this.options[this.selectedIndex].value);"  >
		   <option value="0" <% If dbtype="0" Then echo "selected" %>>FYCMS主数据库</option>
		   <option value="1" <% If dbtype="1" Then echo "selected" %>>Access数据源</option>
		   <option value="2" <% If dbtype="2" Then echo "selected" %>>MSSQL数据源</option>
		   <option value="3" <% If dbtype="3" Then echo "selected" %>>ODBC数据源</option>
		   <option value="4" <% If dbtype="4" Then echo "selected" %>>Oracle数据源</option>
		   <option value="5" <% If dbtype="5" Then echo "selected" %>>Excel数据源</option>
		   <option value="6" <% If dbtype="6" Then echo "selected" %>>Dbase数据源</option>
		   <option value="7" <% If dbtype="6" Then echo "selected" %>>MYSQL数据源(需支持mysql odbc 3.51 driver)</option>
 	     </select>
             </dd>
         </dl>
 
        <dl>
            <dt>连接字符串：</dt>
            <dd>
               <textarea  disabled name="dbqueryContent" id="dbqueryContent" cols="80" rows="5"><%=dbqueryContent  %></textarea>
		     &nbsp;<input class='btn btn_primary' name="testbutton"   id="testbutton" disabled type='button' value='测试' onclick='ajaxcheck();'>
			 <br><font color=green>说明:外部Access数据源支持相对路径,如Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库.mdb</font>
             </dd>
         </dl>
       


            <dl>
            <dt class="vhid">提交：</dt>
            <dd>
                <a class="btn btn_primary" href="javascript:void(0);" onclick="CheckForm()">提交</a>
				<input name="Submit2" type="reset" class="btn" value="  重置  ">
            </dd>
         </dl>
        
    </div>
    </form>

<%end sub 


sub saves()
		dim Rs,RsSql

 		 dbName=fycms.S("dbName")
		 dbtype=ChkNumeric(fycms.S("dbtype"))
		 dbqueryContent=fycms.S("dbqueryContent")
 		 ID=ChkNumeric(fycms.S("ID"))
		 IF fycms.S("dbName") = "" Then
			Call fycms.Alert("请输入数据源名称!",""):Exit Sub
		 End if
		 
		If Action="AddSave" Then 
			 Set Rs = Server.CreateObject("adodb.recordset")
			  RsSql = "select * from dbquery_fy"
			  Rs.Open RsSql, Conn, 1, 3
			  Rs.AddNew
		 	  Rs("dbName") = dbName
		 	  Rs("dbtype") = dbtype
		 	  Rs("dbqueryContent") = dbqueryContent
			  Rs("addtime") =now()
			  Rs.Update
			  Rs.Close:Set Rs = Nothing		
			  Application.Contents.RemoveAll
			  Call fycms.ActErr("添加成功","include/plus/dbquery.asp","")
 		Else
			 Set Rs = Server.CreateObject("adodb.recordset")
			  RsSql = "select * from dbquery_fy Where ID="&ID
			  Rs.Open RsSql, Conn, 1, 3
		 	  Rs("dbName") = dbName
		 	  Rs("dbtype") = dbtype
		 	  Rs("dbqueryContent") = dbqueryContent
			  Rs("Addtime") =now()
			  Rs.Update
			  Rs.Close:Set Rs = Nothing		
			  Application.Contents.RemoveAll
			  Call fycms.ActErr("修改成功","include/plus/dbquery.asp","")
 		End If 

end sub
CloseConn
%>
<script language="javascript">


	function ajaxcheck()
	{
  //	var url=lhgajax.send("ajaxcheck.asp?A=testsource&DataType="+document.ahhfchhs.dbtype.value+"&str="+document.ahhfchhs.dbqueryContent.value+"&m="+Math.random(),"GET");
  var text=document.ahhfchhs.dbtype.value;
  var dstr=document.ahhfchhs.dbqueryContent.value;
 			  if (text!=''){
 				  $.get("ajaxcheck.asp", { A: "testsource", DataType: text,str: dstr },
				  function(data){
 					var fArr=data.split('|');
							switch (fArr[0])
							{
								 case "0":
									 alert(fArr[1]);
									 break;
								 case "1":
									 alert('连接正常,可以使用');
									 break;
						 
									  default:
							}


				  });
			  }else{
			   alert('对不起,请先输入内容!');
			  }

	 }
   		  function changeconnstr(datatype)
		  {
 		    if (datatype==0)
			{
				document.ahhfchhs.dbqueryContent.disabled=true;
				document.ahhfchhs.testbutton.disabled=true;
   			 }
			else
			{
 			document.ahhfchhs.testbutton.disabled=false;
 			document.ahhfchhs.dbqueryContent.disabled=false;
 			} 
		    switch (Number(datatype))
		    {
			 case 1:
			  document.ahhfchhs.dbqueryContent.value='Provider=Microsoft.Jet.OLEDB.4.0;Data Source={fy:dir}数据库.mdb';
 			  break;
			  
			 case 2:
  			  document.ahhfchhs.dbqueryContent.value='Provider=Sqloledb; User ID=用户名; Password=密码; Initial Catalog=数据库名称; Data Source = (local);'
			  break;
			 case 3:
 		      document.ahhfchhs.dbqueryContent.value='DSN=数据源名;UID=用户名;PWD=密码';
			  break;
			 case 4:
 		      document.ahhfchhs.dbqueryContent.value='driver={microsoft odbc for oracle};uid=用户名;pwd=密码;server=服务器';
			  break;
			 case 5:
 		      document.ahhfchhs.dbqueryContent.value='driver={microsoft excel driver (*.xls)};dbq={fy:dir}数据库名称';
			  break;
			 case 6:
 		      document.ahhfchhs.dbqueryContent.value='driver={microsoft dbase driver (*.dbf)};dbq={fy:dir}数据库名称';
			  break;
			 case 7:
			    alert('连接mysql数据源,需要服务器支持mysql odbc 3.51 driver数据源');
  		      document.ahhfchhs.dbqueryContent.value='driver={mysql odbc 3.51 driver};server=服务器名称;database=数据库名称;user name=用户名;password=密码;';
			  break;
 			}
		
		  }	   
	   
function CheckForm()
{ var form=document.ahhfchhs;
	
	 if (form.dbName.value=='')
		{ alert("请输入菜单名称!");   
		  form.dbName.focus();    
		   return false;
		} 
	    form.submit();
        return true;
	}</script> 

        <% if dbtype<>0 and  action="Add" then   %>
   <script language="javascript">changeconnstr(<%= dbtype %>);</script>  
      <% end if  %>
       
        <% if dbtype<>0 and  action="edit" then   %>
      <script language="javascript">
 			document.ahhfchhs.testbutton.disabled=false;
 			document.ahhfchhs.dbqueryContent.disabled=false;
      
      </script>  
      <% end if  %>
</div>
<script type="text/javascript" src="../../../fy_inc/js/jquery.js"></script>
<script src="../../js/base.js"></script>

</body>
</html>
