<% Option Explicit %>
<!--#include file="inc/Cls_DB.asp" -->
<!--#include file="../../Inc/Const.asp" -->
<!--#include file="inc/PublicFun.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,RelateFieldInfo,i
Submit = Request("Submit")
MainID = Request("MainID")
RelateFieldInfo = Request("RelateFieldInfo")
if MainID = "" then
	Set UpdateConn = Nothing
	Response.Write("<script>alert('参数传递出错');window.location.href='UpDateManage.asp'</script>")  
	Response.End
end if


if Submit = "Add" then
	Dim RelateInfoSql,RSRelateInfoObj,RelateInfoArray,TableCorrArray,RelateInfoLoopVar,AlreadyExistIDStr
	RelateInfoArray = Split(RelateFieldInfo,"$$$")
	RelateInfoSql = "Select * from RelateInfo where DBSOID='" & MainID & "'"
	Set RSRelateInfoObj = Server.CreateObject("ADODB.RecordSet")
	RSRelateInfoObj.Open RelateInfoSql,UpdateConn,3,3
	do while Not RSRelateInfoObj.Eof
		AlreadyExistIDStr = AlreadyExistIDStr & "$$$" & RSRelateInfoObj("ID") & "---" & RSRelateInfoObj("SRelate") & "---" & RSRelateInfoObj("ORelate")
		RSRelateInfoObj.MoveNext
	Loop
	RSRelateInfoObj.Close
	for RelateInfoLoopVar = LBound(RelateInfoArray) to UBound(RelateInfoArray)
		TableCorrArray = Split(RelateInfoArray(RelateInfoLoopVar),"---")
		if TableCorrArray(0) = "" then '添加
			RSRelateInfoObj.Open "Select * from RelateInfo where 1=0"
			RSRelateInfoObj.AddNew
			RSRelateInfoObj("DBSOID") = MainID
			RSRelateInfoObj("SRelate") = TableCorrArray(1)
			RSRelateInfoObj("ORelate") = TableCorrArray(2)
			RSRelateInfoObj.UpDate
			RSRelateInfoObj.Close
		else 
			if InStr(AlreadyExistIDStr,RelateInfoArray(RelateInfoLoopVar)) <> 0 then '修改
				RSRelateInfoObj.Open "Select * from RelateInfo where ID=" & TableCorrArray(0) & ""
				RSRelateInfoObj("DBSOID") = MainID
				RSRelateInfoObj("SRelate") = TableCorrArray(1)
				RSRelateInfoObj("ORelate") = TableCorrArray(2)
				RSRelateInfoObj.UpDate
				RSRelateInfoObj.Close
				AlreadyExistIDStr = Replace(AlreadyExistIDStr,"$$$" & RelateInfoArray(RelateInfoLoopVar),"")
			else '添加
				RSRelateInfoObj.Open "Select * from RelateInfo where 1=0"
				RSRelateInfoObj.AddNew
				RSRelateInfoObj("DBSOID") = MainID
				RSRelateInfoObj("SRelate") = TableCorrArray(1)
				RSRelateInfoObj("ORelate") = TableCorrArray(2)
				RSRelateInfoObj.UpDate
				RSRelateInfoObj.Close
			end if
		end if
	Next
	Set RSRelateInfoObj = Nothing
	if AlreadyExistIDStr <> "" then '删除
		Dim DeleteSql,TempExistIDArray,TempArray,TempLoopVar,TempExistIDStr
		TempExistIDStr = ""
		if Left(AlreadyExistIDStr,3) = "$$$" then '取掉头部
			AlreadyExistIDStr = Right(AlreadyExistIDStr,Len(AlreadyExistIDStr)-3)
		end if
		TempExistIDArray = Split(AlreadyExistIDStr,"$$$")
		for TempLoopVar = LBound(TempExistIDArray) to UBound(TempExistIDArray)
			TempArray = Split(TempExistIDArray(TempLoopVar),"---")
			if TempExistIDStr = "" then
				TempExistIDStr = TempArray(0)
			else
				TempExistIDStr = TempExistIDStr & "," & TempArray(0)
			end if
		Next
		DeleteSql = "Delete from RelateInfo where ID in (" & TempExistIDStr & ")"
		UpdateConn.Execute(DeleteSql) '删除RelateInfo表中的垃圾
	end if
	if Err.Number <> 0 then
		Response.Write("<script>alert('数据出错');window.location.href='UpdateAddFiveStep.asp?MainID=" & MainID & "';</script>")  
		Response.End
	end if
end if

Dim RSUpdateObj,RSTableObj,RSFieldObj
Dim SourceDBType,SServer,SourceDB,SUser,SPassWord,ObjectDBType,OServer,ObjectDB,OUser,OPassWord
Set RSUpdateObj = UpdateConn.Execute("Select * from DBSO where MainID='" & MainID & "'")
if RSUpdateObj.Eof then
	Response.Write("<script>alert('数据出错');window.location.href='UpdateAddFourStep.asp?MainID=" & MainID & "';</script>")  
	Response.End
else
	if RSUpdateObj("SourceDBType") = 1 then
		SourceDBType = "Sql Server"
	else
		SourceDBType = "Access"
	end if
	SServer = RSUpdateObj("SServer")
	if RSUpdateObj("SourceDBType") = 2 then
		 if RSUpdateObj("SourceDB") = "1" then
			SourceDB = "远程数据库"
		 else
			SourceDB = "本地数据库"
		 end if
	else
		SourceDB = RSUpdateObj("SourceDB")
	end if
	SUser = RSUpdateObj("SUser")
	SPassWord = RSUpdateObj("SPassWord")
	if RSUpdateObj("ObjectDBType") = 1 then
		ObjectDBType = "Sql Server"
	else
		ObjectDBType = "Access"
	end if
	OServer = RSUpdateObj("OServer")
	if RSUpdateObj("ObjectDBType") = 2 then
		 if RSUpdateObj("ObjectDB") = "1" then
			ObjectDB = "远程数据库"
		 else
			ObjectDB = "本地数据库"
		 end if
	else
		ObjectDB = RSUpdateObj("ObjectDB")
	end if
	OUser = RSUpdateObj("OUser")
	OPassWord = RSUpdateObj("OPassWord")
end if
Set RSUpdateObj = Nothing
%>
<!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">
    <tr bgcolor="#E4E4E4"> 
      
    <td height="30" background="images/Collect_bg.gif"><font color="#FF0000"><strong>数据转移规则---第七步---完成</strong></font></td>
    </tr>
    <tr> 
      <td bgcolor="#F3F3F3"><div align="center">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr> 
              <td><div align="center"> 
                  <input name="Submitttt" onClick="window.location.href='UpDateAddFiveStep.asp?MainID=<% = MainID %>';" type="button" id="Submitttt" value="上 一 步">
                </div></td>
              <td><div align="center"> 
                  <input name="Submit2dfsd" onClick="window.location.href='UpDateManage.asp';" type="button" id="Submit2dfsd" value=" 完 成 ">
                </div></td>
            </tr>
          </table>
        </div></td>
    </tr>
    <tr> 
      <td bgcolor="#F3F3F3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td height="30"> <div align="center">数据库对应关系</div></td>
        </tr>
        <tr> 
          <td><table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#cccccc">
              <tr bgcolor="#FFFFFF"> 
                <td nowrap><div align="center">类型</div></td>
                <td nowrap><div align="center">数据库类型</div></td>
                <td nowrap><div align="center">服务器</div></td>
                <td nowrap><div align="center">数据库名</div></td>
                <td nowrap><div align="center">用户名</div></td>
                <td nowrap><div align="center">密码</div></td>
              </tr>
              <tr bgcolor="#FFFFFF"> 
                <td width="200"> <div align="center">源数据库</div></td>
                <td> <div align="center"> 
                    <% = SourceDBType %>
                  </div></td>
                <td> <div align="center"> 
                    <% = SServer %>
                  </div></td>
                <td nowrap> <div align="center"> 
                    <% = SourceDB %>
                  </div></td>
                <td> <div align="center"> 
                    <% = SUser %>
                  </div></td>
                <td> <div align="center"> 
                    <% = SPassWord %>
                  </div></td>
              </tr>
              <tr bgcolor="#FFFFFF"> 
                <td> <div align="center">目标数据库</div></td>
                <td> <div align="center"> 
                    <% = ObjectDBType %>
                  </div></td>
                <td> <div align="center"> 
                    <% = OServer %>
                  </div></td>
                <td nowrap> <div align="center"> 
                    <% = ObjectDB %>
                  </div></td>
                <td> <div align="center"> 
                    <% = OUser %>
                  </div></td>
                <td> <div align="center"> 
                    <% = OPassWord %>
                  </div></td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td height="30"> <div align="center"> 
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr> 
                  <td width="200"> <div align="center">数据库表对应关系</div></td>
                  <td><div align="center">字段对应关系</div></td>
                </tr>
              </table>
            </div></td>
        </tr>
        <tr> 
          <td> <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#cccccc">
              <%
			  Set RSTableObj = UpdateConn.Execute("Select * from TableSO where DBSOID='" & MainID & "'")
			  do while Not RSTableObj.Eof
			  %>
              <tr bgcolor="#FFFFFF"> 
                <td width="200"> <div align="center"> 
                    <% = RSTableObj("STable") & "---" & RSTableObj("OTable") %>
                  </div></td>
                <td> <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <%
						  Set RSFieldObj = UpdateConn.Execute("Select * from FieldSO where TableSOID=" & RSTableObj("ID") & "")
						  do while Not RSFieldObj.Eof
						%>
                    <tr> 
                      <td><div align="center"> 
                          <% = RSFieldObj("SField") & "---" & RSFieldObj("OField") %>
                        </div></td>
                    </tr>
                    <%
					  	  RSFieldObj.MoveNext
					  Loop
					  Set RSFieldObj = Nothing	
					  %>
                  </table></td>
              </tr>
              <%
					  RSTableObj.MoveNext
				  Loop
				  Set RSTableObj = Nothing
				  %>
            </table></td>
        </tr>
        <tr>
          <td height="30"><div align="center">关联信息</div></td>
        </tr>
        <tr> 
          <td><table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#cccccc">
              <%
				Dim RSShowRelateInfoObj
				Set RSShowRelateInfoObj = UpdateConn.Execute("Select * from RelateInfo where DBSOID='" & MainID & "'")
				do while Not RSShowRelateInfoObj.Eof
			  %>
              <tr>
                <td bgcolor="#FFFFFF">
<div align="center"><% = RSShowRelateInfoObj("SRelate") & "---" & RSShowRelateInfoObj("ORelate") %></div></td>
              </tr>
			  <%
					RSShowRelateInfoObj.MoveNext
				Loop
				Set RSShowRelateInfoObj = Nothing
			  %>
            </table> </td>
        </tr>
      </table>
	   </td>
    </tr>
</table>
</body>
</html>
<%
Set UpdateConn = Nothing
%>