<% Option Explicit %>
<!--#include file="inc/Cls_DB.asp" -->
<!--#include file="../../Inc/Const.asp" -->
<%
'==============================================================================
'软件名称：风讯新闻采集系统V1.0
'最新更新：2004.12
'==============================================================================
'商业注册联系：028-85098980-601,602 技术支持：028-85098980-606、607,客户支持：608
'产品咨询QQ：159410,655071,66252421
'技术支持:所有程序使用问题，请提问到bbs.foosun.net我们将及时回答您
'程序开发：风讯开发组 & 风讯插件开发组
'论坛支持：风讯在线论坛(http://bbs.foosun.net)
'官方网站：www.Foosun.net  演示站点：test.cooin.com    
'网站建设专区：www.cooin.com
'==============================================================================
'免费版本请在新闻首页保留版权信息，并做上本站LOGO友情连接
'==============================================================================
Dim DBC,UpdateConn,Conn
Set DBC = New DataBaseClass
DBC.ConnStr = "DBQ=" + server.mappath("FooSunData/Update.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
Set UpdateConn = DBC.OpenConnection()
DBC.ConnStr = "DBQ=" + Server.MapPath(DataBaseConnectStr) + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
'判断权限
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
if Not JudgePopedomTF(Session("Name"),"P1405") then Call ReturnError1()
'判断权限结束
Dim Submit,MainID,DescriptionStr
Submit = Request("Submit")
MainID = Request("MainID")
if MainID = "" then
	Set UpdateConn = Nothing
	Response.Write("<script>alert('参数传递出错');window.location.href='UpDateManage.asp'</script>")  
	Response.End
end if

Dim RSUpdateObj,DataBaseType,SqlServer,SqlDataBase,SqlUser,SqlPassWord,AccessServer,AccessDB,AccessUser,AccessPassWord
Set RSUpdateObj = UpdateConn.Execute("Select * from DBSO where MainID='" & MainID & "'")
if RSUpdateObj.Eof then
	DataBaseType = 1
	SqlServer = ""
	SqlDataBase = ""
	SqlUser = ""
	SqlPassWord = ""
	AccessServer = ""
	AccessDB = ""
	AccessUser = ""
	AccessPassWord = ""
else
	DataBaseType = RSUpdateObj("SourceDBType")
	if DataBaseType = 1 then
		SqlServer = RSUpdateObj("SServer")
		SqlDataBase = RSUpdateObj("SourceDB")
		SqlUser = RSUpdateObj("SUser")
		SqlPassWord = RSUpdateObj("SPassWord")
		AccessServer = ""
		AccessDB = ""
		AccessUser = ""
		AccessPassWord = ""
	elseif DataBaseType = 2 then
		SqlServer = ""
		SqlDataBase = ""
		SqlUser = ""
		SqlPassWord = ""
		AccessServer = RSUpdateObj("SServer")
		AccessDB = RSUpdateObj("SourceDB")
		AccessUser = RSUpdateObj("SUser")
		AccessPassWord = RSUpdateObj("SPassWord")
	else
		DataBaseType = 1
		SqlServer = ""
		SqlDataBase = ""
		SqlUser = ""
		SqlPassWord = ""
		AccessServer = ""
		AccessDB = ""
		AccessUser = ""
		AccessPassWord = ""
	end if
end if
Set RSUpdateObj = Nothing

if Submit = "Add" then
	Dim RsDBSOObj
	DescriptionStr = Request("Description")
	On Error Resume Next
	Set RsDBSOObj = Server.CreateObject("ADODB.RecordSet")
	RsDBSOObj.Open "Select * from DBSO where MainID='" & MainID & "'",UpdateConn,3,3
	if RsDBSOObj.Eof then RsDBSOObj.AddNew
	RsDBSOObj("MainID") = MainID
	RsDBSOObj("Description") = DescriptionStr
	RsDBSOObj.UpDate
	Set RsDBSOObj = Nothing
	if Err.Number <> 0 then
		Response.Write("<script>alert('数据出错');window.location.href='UpdateAdd.asp?MainID=" & MainID & "'</script>")  
		Response.End
	end if
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>添加数据库转换规则</title>
</head>
<link href="inc/Collect.css" rel="stylesheet">
<body topmargin="0" leftmargin="0">
<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#cccccc">
  <form name="UpdateForm" method="get" action="UpdateAddTwoStep.asp">
  <tr bgcolor="#E4E4E4"> 
      <td height="30" background="images/Collect_bg.gif"><font color="#FF0000"><strong>数据转移规则---第二步---选择源数据库</strong></font></td>
  </tr>
  <tr bgcolor="#F3F3F3"> 
    <td>数据库类型 <select name="DataBaseType" onChange="ChangeView(this);">
        <option <% if DataBaseType = 1 then Response.Write("selected") %> value="1">Sql Server</option>
        <option <% if DataBaseType = 2 then Response.Write("selected") %> value="2">Access</option>
      </select></td>
  </tr>
  <tr id="Sql" style="display:<% if DataBaseType = 2 then Response.Write("none") %>;" bgcolor="#F3F3F3"> 
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="50%" height="30">服务器 
            <input name="SqlServer" type="text" size="40" value="<% = SqlServer %>"></td>
          <td height="30">数据库 
            <input name="SqlDataBase" type="text" size="40" value="<% = SqlDataBase %>"></td>
        </tr>
        <tr> 
          <td height="30">用户名 
            <input name="SqlUser" type="text" size="40" value="<% = SqlUser %>"></td>
          <td height="30">密&nbsp;&nbsp;码 
            <input name="SqlPassWord" type="password" size="40" value="<% = SqlPassWord %>"></td>
        </tr>
      </table></td>
  </tr>
  <tr style="display:<% if DataBaseType = 1 then Response.Write("none") %>;" id="Access" bgcolor="#F3F3F3"> 
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
            <td height="30" colspan="2">远程数据库 
              <input type="checkbox" <% if AccessDB = "1" then Response.Write("checked") %> name="AccessDB" value="1">
              服务器 
              <input name="AccessServer" type="text" size="77" value="<% = AccessServer %>"></td>
        </tr>
        <tr> 
          <td height="30">用户名 
            <input name="AccessUser" type="text" size="40" value="<% = AccessUser %>"></td>
          <td height="30">密&nbsp;&nbsp;&nbsp;&nbsp;码 
            <input name="AccessPassWord" type="password" size="40" value="<% = AccessPassWord %>"></td>
        </tr>
      </table></td>
  </tr>
  <tr bgcolor="#F3F3F3"> 
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td width="30%"> 
              <div align="center"> 
                <input name="BtnTest" onClick="TestConnection();" type="button" id="Submitaasss" value="测试链接">
                <input type="hidden" name="TestFlag" value="0">
                <input type="hidden" name="Submit" value="Add">
                <input type="hidden" name="MainID" value="<% = MainID %>">
              </div></td>
            <td><div align="center">
                <input name="BtnUp" onClick="window.location.href='UpDateAdd.asp?MainID=<% = MainID %>';" type="button" id="Submitatt" value="上 一 步">
              </div></td>
            <td width="30%">
<div align="center"> 
                <input name="BtnNext" type="button" onClick="SubmitData();" id="Submitaa" value="下一步">
              </div></td>
          </tr>
        </table></td>
  </tr>
  </form>
</table>
<iframe id="TestFrame" src="TestConnection.asp" width="0" height="0"></iframe>
</body>
</html>
<%
Set UpdateConn = Nothing
%>
<script language="JavaScript">
function ChangeView(Obj)
{
	switch (Obj.value)
	{
		case '1':
			document.all.Sql.style.display='';
			document.all.Access.style.display='none';
			break;
		case '2':
			document.all.Sql.style.display='none';
			document.all.Access.style.display='';
			break;
		default :
			document.all.Sql.style.display='';
			document.all.Access.style.display='none';
	}
}
function SetBtnStatus(Flag)
{
	document.UpdateForm.BtnTest.disabled=Flag;
	document.UpdateForm.BtnUp.disabled=Flag;
	document.UpdateForm.BtnNext.disabled=Flag;
}
function TestConnection()
{
	SetBtnStatus(true);
	var DBType=document.UpdateForm.DataBaseType.value;
	document.UpdateForm.TestFlag.value='1';
	var ParaList=GetParaList(DBType)+'&DataBaseType='+DBType+'&TestFlag='+document.UpdateForm.TestFlag.value;
	frames["TestFrame"].location='TestConnection.asp'+ParaList;
	document.UpdateForm.TestFlag.value='0';
}
function SubmitData()
{
	if (document.UpdateForm.DataBaseType.value=='1')
	{
		if (document.UpdateForm.SqlServer.value=='') {alert('数据库服务器没有填写');document.UpdateForm.SqlServer.focus();return;}
		if (document.UpdateForm.SqlDataBase.value=='') {alert('数据库名没有填写');document.UpdateForm.SqlDataBase.focus();return;}
	}
	if (document.UpdateForm.DataBaseType.value=='2')
	{
		if (document.UpdateForm.AccessServer.value=='') {alert('数据库服务器没有填写');document.UpdateForm.AccessServer.focus();return;}
	}
	document.UpdateForm.submit();
}
function GetParaList(Flag)
{
	var TempStr='';
	for (var i=0;i<document.all.length;i++)
	{
		var CurrObj=document.all(i);
		if (CurrObj.tagName.toLowerCase()=='input')
		{
			if (CurrObj.type.toLowerCase()=='text')
			{
				if (Flag=='1')
				{
					if (CurrObj.name.toLowerCase().indexOf('sql')!=-1) TempStr=TempStr+'&'+CurrObj.name+'='+CurrObj.value;
				}
				if (Flag=='2')
				{
					if (CurrObj.name.toLowerCase().indexOf('access')!=-1) TempStr=TempStr+'&'+CurrObj.name+'='+CurrObj.value;
				}
			}
			if (CurrObj.type.toLowerCase()=='password')
			{
				if (Flag=='1')
				{
					if (CurrObj.name.toLowerCase().indexOf('sql')!=-1) TempStr=TempStr+'&'+CurrObj.name+'='+CurrObj.value;
				}
				if (Flag=='2')
				{
					if (CurrObj.name.toLowerCase().indexOf('access')!=-1) TempStr=TempStr+'&'+CurrObj.name+'='+CurrObj.value;
				}
			}
			if (CurrObj.type.toLowerCase()=='checkbox')
			{
				if (Flag=='1')
				{
					if (CurrObj.name.toLowerCase().indexOf('sql')!=-1)
					{
						if (CurrObj.checked==true)	TempStr=TempStr+'&'+CurrObj.name+'='+CurrObj.value;
					}
				}
				if (Flag=='2')
				{
					if (CurrObj.name.toLowerCase().indexOf('access')!=-1)
					{
						if (CurrObj.checked==true)	TempStr=TempStr+'&'+CurrObj.name+'='+CurrObj.value;
					}
				}
			}
		}
	}
	if (TempStr.substr(0,1)=='&') TempStr=TempStr.replace('&','?');
	return TempStr;
}
</script>