<% @ Language="VBScript" Codepage="936" %>
<%
Option Explicit
Response.Buffer = True 
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache" 
Response.AddHeader "Pragma", "No-Cache"
Server.ScriptTimeout = 999999

Rem 全局变量
Dim Action
Dim SysType_Source,DbType_Source,AcFile_Source,SqlServer_Source,SqlDbName_Source,SqlUser_Source,SqlPass_Source
Dim SysType_Remote,DbType_Remote,AcFile_Remote,SqlServer_Remote,SqlDbName_Remote,SqlUser_Remote,SqlPass_Remote
Dim NeedOverwrite,NeedBatch,BatchNum
Dim TotalRecord,SkipRecord,OverwriteRecord,SuccessRecord,FailedRecord
Dim Conn_Source,Conn_Remote,ConnStr
Dim ServerMsg,SQL_Source
Dim oblogConfig,user_dir,user_group,isOblog4

Action = Trim(Request.QueryString("action"))
Select Case Action
    Case "TestConn"
        TestConn
    Case "start"
        Main
End Select

Sub TestConn()
    Dim TestType
    TestType = Trim(Request.form("testtype"))
    If TestType = "source" Then
        GetSourceInfo
        TestSource
        ServerMsg = "{0}源数据库连接测试成功。"
        WriteMsg
    Else
        GetRemoteInfo
        TestRemote
        ServerMsg = "{0}目标数据库连接测试成功。"
        WriteMsg
    End If
End Sub

Sub Main()
    GetSourceInfo
    GetRemoteInfo
    GetOptionInfo
    InitHTML
    CheckParam
    TestSource
    Dim tempRs
    Set tempRs = Conn_Source.Execute(GetSqlString)
    If tempRs.Eof And tempRs.Bof Then
        Set TempRs = Nothing
        ServerMsg = "源数据库中没有记录，不需要同步！"
        WriteMsg
    Else
        SQL_Source = tempRs.GetRows()
        Set TempRs = Nothing
    End If
    TotalRecord = UBound(SQL_Source,2)
    SuccessRecord = Trim(Request.Form("SucNum"))
    SkipRecord = Trim(Request.Form("SkipNum"))
    OverwriteRecord = Trim(Request.Form("OverNum"))
    FailedRecord = Trim(Request.Form("FailNum"))
    If IsNull(TotalRecord) Then TotalRecord = 0
    If SuccessRecord = "" Then SuccessRecord = 0
    If SkipRecord = "" Then SkipRecord = 0
    If OverwriteRecord = "" Then OverwriteRecord = 0
    If FailedRecord = "" Then FailedRecord = 0

    Dim StartID,EndID
    Dim Batch,Batchs
    If NeedBatch Then
        Batch = Request.QueryString("batch")
        If Batch = "" or IsNumeric(Batch) = False Then Batch = 1
        Batchs = Clng(TotalRecord \ BatchNum) + 1
        If CLng(Batch)-Clng(Batchs) > 0 Then Batch = 1
        StartID = (Batch-1) * BatchNum
        EndID = Batch * BatchNum - 1
    Else
        Batch = 1
        Batchs = 1
        StartID = 0
        BatchNum = TotalRecord
        EndID = TotalRecord
    End If

    If EndID > TotalRecord Then EndID = TotalRecord

    RefreshHTMLStart TotalRecord+1, Batchs, Batch, StartID+1, EndID+1
    If CLng(StartID - TotalRecord) <= 0 Then
        TestRemote
		If SysType_Remote = "oblog" Then
			Set oblogConfig = Conn_Remote.Execute("SELECT userdir FROM oblog_userdir WHERE is_default=1")
        	user_dir = oblogConfig(0)
			If isOblog4 Then
				Set oblogConfig = Conn_Remote.Execute("SELECT TOP 1 groupid FROM oblog_groups")
				user_group = oblogConfig(0)
			End If
			oblogConfig.Close
        	Set oblogConfig = Nothing
		End If
        Dim i
        For i = StartID To EndID
            AddNewUser SQL_Source(0,i),SQL_Source(1,i),SQL_Source(2,i),SQL_Source(3,i),SQL_Source(4,i),SysType_Remote,DbType_Remote
        Next
    End If
	If SysType_Remote = "oblog" Then
		If isOblog4 Then
			Conn_Remote.execute ("update oblog_groups set g_members=g_members+" & successRecord & " WHERE groupid = " &user_group)
		End If
		Conn_Remote.execute("UPDATE oblog_setup SET user_count=user_count+" & successRecord)
	End If
    If EndID = TotalRecord Then
        OutputSubmit True, Batch
    Else
        OutputSubmit False, Batch
    End If
End Sub

Function TestSource()
    If DbType_Source = "" Or ((DbType_Source = "access") And (AcFile_Source = "")) Or ((DbType_Source = "sql") And (SqlServer_Source = "" Or SqlDbName_Source = "" Or SqlUser_Source = "")) Then
        ServerMsg = "缺少连接源数据库的必须参数！"
        WriteMsg
    End If
    OpenDatabase "Source"
    Dim strSql_Test
    Select Case SysType_Source
        Case "powereasy"
            strSql_Test = "SELECT TOP 1 * FROM PE_User"
        Case "dvbbs"
            strSql_Test = "SELECT TOP 1 * FROM Dv_User"
        Case "oblog"
            strSql_Test = "SELECT TOP 1 * FROM oblog_User"
    End Select
    MyExecute "Source", strSql_Test, "所选程序类型与数据库结构不匹配！"
End Function

Function TestRemote
    If DbType_Remote = "" Or ((DbType_Remote = "access") And (AcFile_Remote = "")) Or ((DbType_Remote = "sql") And (SqlServer_Remote = "" Or SqlDbName_Remote = "" Or SqlUser_Remote = "")) Then
        ServerMsg = "缺少连接目标数据库的必须参数！"
        WriteMsg
    End If
    OpenDatabase "Remote"
    Dim strSql_Test
    Select Case SysType_Remote
        Case "powereasy"
            strSql_Test = "SELECT TOP 1 * FROM PE_User"
        Case "dvbbs"
            strSql_Test = "SELECT TOP 1 * FROM Dv_User"
        Case "oblog"
            strSql_Test = "SELECT TOP 1 * FROM oblog_User"
    End Select
    MyExecute "Remote",strSql_Test,"所选程序类型与数据库结构不匹配！"
End Function

Sub AddNewUser(UserName,UserPassword,UserEmail,UserQuestion,UserAnswer,SysType,DbType)
    Dim TempSql
    Set TempSql = Conn_Remote.Execute("SELECT * FROM " & GetUserTable(SysType) & " WHERE UserName='" & UserName & "'")
    If TempSql.Eof And TempSql.Bof Then
        If AddUser(UserName,UserPassword,UserEmail,UserQuestion,UserAnswer,SysType,DbType) Then
            SuccessRecord = SuccessRecord + 1
        Else
            FailedRecord = FailedRecord + 1
        End If
    Else
        If NeedOverwrite Then
            If UpdateUser(UserName,UserPassword,UserEmail,UserQuestion,UserAnswer,SysType,DbType) Then
                OverwriteRecord = OverWriteRecord + 1
            Else
                FailedRecord = FailedRecord + 1
            End If
        Else
            SkipRecord = SkipRecord + 1
        End If
    End If
    Set TempSql = Nothing
    RefreshHTMLEnd SuccessRecord, SkipRecord, OverwriteRecord, FailedRecord
End Sub

Function AddUser(UserName,UserPassword,UserEmail,UserQuestion,UserAnswer,SysType,DbType)
    On Error Resume Next
    Dim Trs
    Select Case SysType
        Case "powereasy"
            Dim rsConfig,PresentExp,PresentMoney,PresentPoint,PresentValidNum,PresentValidUnit
            Set rsConfig = Conn_Remote.Execute("select top 1 * from PE_Config")
            If rsConfig.BOF And rsConfig.EOF Then
                PresentExp = 0
                PresentMoney = 0
                PresentPoint = 0
                PresentValidNum = 0
                PresentValidNum = 1
            Else
                PresentExp = rsConfig("PresentExp")
                PresentMoney = rsConfig("PresentMoney")
                PresentPoint = rsConfig("PresentPoint")
                PresentValidNum = rsConfig("PresentValidNum")
                PresentValidUnit = rsConfig("PresentValidUnit")
            End If
            rsConfig.Close
            Set rsConfig = Nothing
            Dim UserID
            UserID = Conn_Remote.Execute("SELECT MAX(UserID) FROM PE_User")(0)
            If IsNull(UserID) Then
                UserID = 1
            Else
                UserID = UserID + 1
            End If
            Dim GroupID, GroupSetting
            Set Trs = Conn_Remote.Execute("select GroupID,GroupSetting from PE_UserGroup where GroupType=2")
            GroupID = Trs(0)
            GroupSetting = Split(trs(1), ",")
            Trs.Close
            Set Trs = Nothing
            Set Trs = Server.CreateObject("ADODB.RecordSet")
            Trs.Open "SELECT * FROM PE_User WHERE UserID=0",Conn_Remote,1,3
            Trs.AddNew
                    Trs("UserID") = UserID
                    Trs("ClientID") = 0
                    Trs("ContacterID") = 0
                    Trs("UserType") = 0
                    Trs("UserName") = UserName
                    Trs("UserPassword") = UserPassword
                    Trs("LastPassword") = UserPassword
                    Trs("Question") = UserQuestion
                    Trs("Answer") = UserAnswer
                    Trs("Email") = UserEmail
                    Trs("RegTime") = Now()
                    Trs("LoginTimes") = 0
                    Trs("IsLocked") = False
                    Trs("Balance") = PresentMoney
                    Trs("UserExp") = PresentExp
                    Trs("PostItems") = 0
                    Trs("PassedItems") = 0
                    Trs("DelItems") = 0
                    Trs("UnsignedItems") = ""
                    Trs("UnreadMsg") = 0
                    Trs("arrClass_Browse") = ""
                    Trs("arrClass_View") = ""
                    Trs("arrClass_Input") = ""
                    Trs("UserSetting") = ""
                    Trs("UserFriendGroup") = "黑名单$我的好友"
                    Trs("LoginTimes") = 1
                    Trs("LastLoginIP") = ""
                    Trs("LastLoginTime") = Now()
                    Trs("LastPresentTime") = Now()
                    Trs("GroupID") = GroupID
                    Trs("UserPoint") = PresentPoint
                    Trs("BeginTime") = FormatDateTime(Now(), 2)
                    Trs("ValidNum") = PresentValidNum
                    Trs("ValidUnit") = PresentValidUnit
                    Trs("CheckNum") = 9999
                    Trs("SpecialPermission") = False
                    Trs("Blog") = False
             Trs.Update
             Trs.Close
             Set Trs = Nothing
        Case "dvbbs"
            Set Trs = Server.CreateObject("ADODB.RecordSet")
            Trs.Open "SELECT * FROM Dv_User WHERE UserID=0",Conn_Remote,1,3
			Trs.Addnew
                Trs("Username") = UserName
                Trs("Userpassword") = UserPassword
                Trs("UserQuesion") = UserQuestion
                Trs("UserAnswer") = UserAnswer
                Trs("Userclass") = "新手上路"
                Trs("UserGroupID") = 4
                Trs("Titlepic") = "level0.gif"
                Trs("UserWealth") = 100
                Trs("Userep") = 30
                Trs("Usercp") = 30
                Trs("Userisbest") = 0
                Trs("Userdel") = 0
                Trs("Userpower") = 0
                Trs("Lockuser") = 0
                Trs("Usersex") = 1
                Trs("UserEmail") = UserEmail
                Trs("UserFace") = "Images/userface/image1.gif"
                Trs("UserWidth") = 32
                Trs("UserHeight") = 32
                Trs("UserIM") = "||||||||||||||||||"
                Trs("UserFav") = "陌生人,我的好友,黑名单"
                Trs("LastLogin") = Now()
                Trs("JoinDate") = Now()
                Trs("Userpost") = 0
                Trs("Usertopic") = 0
			Trs.Update
            Trs.Close
            Set Trs = Nothing
        Case "oblog"
            Set Trs = Server.CreateObject("ADODB.RecordSet")
            Trs.Open "SELECT * FROM oblog_User WHERE UserID=0",Conn_Remote,1,3
			Trs.Addnew
            	Trs("UserName")=UserName
                Trs("PassWord")=UserPassword
                Trs("Question")=UserQuestion
                Trs("Answer")=UserAnswer
                Trs("userEMail")=UserEmail
                Trs("user_level")=7
                Trs("user_isbest")=0
                Trs("province")=""
                Trs("city")=""
                Trs("Nickname")=UserName
                Trs("adddate")=Now()
                Trs("lastloginip")="0.0.0.0"
                Trs("lastlogintime")=Now()
                Trs("user_dir")=user_dir
				If isOblog4 Then
					Trs("user_group") = user_group
					Trs("newbie") = 1
				End If
		    Trs.update
            Trs.Close
            Set Trs = Nothing
			Conn_Remote.execute("UPDATE oblog_user SET user_folder=userid where UserName='" & UserName & "'")
    End Select
    If Err Then
        Err.Clear
        AddUser = False
    Else
        AddUser = True
    End If
End Function

Function UpdateUser(UserName,UserPassword,UserEmail,UserQuestion,UserAnswer,SysType,DbType)
    On Error Resume Next
    If IsNull(UserPassword) Or IsNull(UserName) Then
        UpdateUser = False
        Exit Function
    End If
    If IsNull(UserEmail) Then UserEmail = ""
    If IsNull(UserQuestion) Then UserQuestion = ""
    If IsNull(UserAnswer) Then UserAnswer = ""
    UserName = Replace(UserName,"'","''")
    UserQuestion = Replace(UserQuestion,"'","''")
    Dim tempSqlStr
    Select Case SysType
        Case "powereasy"
            tempSqlStr = "UPDATE PE_User SET UserPassword='" & UserPassword & "',Email='" & UserEmail & "',Question='" & UserQuestion & "',Answer='" & UserAnswer & "' WHERE UserName='" & UserName & "'"
        Case "dvbbs"
            tempSqlStr = "UPDATE Dv_User SET UserPassword='" & UserPassword & "',UserEmail='" & UserEmail & "',UserQuesion='" & UserQuestion & "',UserAnswer='" & UserAnswer & "' WHERE UserName='" & UserName & "'"
        Case "oblog"
            tempSqlStr = "UPDATE oblog_user SET PassWord='" & UserPassword & "',userEMail='" & UserEmail & "',Question='" & UserQuestion & "',Answer='" & UserAnswer & "' WHERE UserName='" & UserName & "'"
    End Select
    Conn_Remote.Execute(tempSqlStr)
    If Err Then
        Err.Clear
        UpdateUser = False
    Else
        UpdateUser = True
    End If
End Function

Function GetTrueString(DbType)
    If DbType = "access" Then
        GetTrueString = "True"
    Else
        GetTrueString = 1
    End If
End Function

Function GetFalseString(DbType)
    If DbType = "access" Then
        GetFalseString = "False"
    Else
        GetFalseString = "0"
    End If
End Function

Function GetNowString(DbType)
    If DbType = "access" Then
        GetNowString = "Now()"
    Else
        GetNowString = "GetDate()"
    End If
End Function

Sub GetSourceInfo()
    SysType_Source = Trim(Request.Form("source_systype"))
    DbType_Source = Trim(Request.Form("source_dbtype"))
    AcFile_Source = Trim(Request.Form("source_dbpath"))
    SqlServer_Source = Trim(Request.Form("source_servername"))
    SqlDbName_Source = Trim(Request.Form("source_dbname"))
    SqlUser_Source = Trim(Request.Form("source_username"))
    SqlPass_Source = Trim(Request.Form("source_password"))
End Sub

Sub GetRemoteInfo()
    SysType_Remote = Trim(Request.Form("remote_systype"))
    DbType_Remote = Trim(Request.Form("remote_dbtype"))
    AcFile_Remote = Trim(Request.Form("remote_dbpath"))
    SqlServer_Remote = Trim(Request.Form("remote_servername"))
    SqlDbName_Remote = Trim(Request.Form("remote_dbname"))
    SqlUser_Remote = Trim(Request.Form("remote_username"))
    SqlPass_Remote = Trim(Request.Form("remote_password"))
	If SysType_Remote = "oblog3" Then
		SysType_Remote = "oblog"
		isOblog4 = False
	ElseIf SysType_Remote = "oblog4" Then
		SysType_Remote = "oblog"
		isOblog4 = True
	End If
End Sub

Sub GetOptionInfo()
    NeedOverwrite = Trim(Request.Form("overwrite"))
    NeedBatch = Trim(Request.Form("batch"))
    BatchNum = Trim(Request.Form("batchnum"))
    If NeedOverwrite = "True" Then
        NeedOverwrite = True
    Else
        NeedOverwrite = False
    End If
    If NeedBatch = "True" Then
        NeedBatch = True
    Else
        NeedBatch = False
    End If
    If BatchNum = "" Or IsNumeric(BatchNum) = False Then
        BatchNum = 0
    End If
End Sub

Function GetUserTable(strSysType)
    Select Case strSysType
        Case "powereasy"
            GetUserTable = "PE_User"
        Case "dvbbs"
            GetUserTable = "Dv_User"
        Case "oblog"
            GetUserTable = "oblog_user"
    End Select
End Function

Function GetSqlString()
    Select Case SysType_Source
        Case "powereasy"
            GetSqlString = "SELECT UserName,UserPassword,Email,Question,Answer FROM PE_User ORDER BY UserID"
        Case "dvbbs"
            GetSqlString = "SELECT UserName,UserPassword,UserEmail,UserQuesion,UserAnswer FROM Dv_User ORDER BY UserID"
        Case "oblog"
            GetSqlString = "SELECT username,password,useremail,question,answer FROM oblog_user ORDER BY userid"
    End Select
End Function

Sub CheckParam
    Dim FoundErr,ServerMsg
    If DbType_Source = "" Or DbType_Remote = "" Then
        FoundErr = True
        ServerMsg = "缺少关键参数，程序无法继续运行"
        WriteMsg
    End If

    If DbType_Source = "access" And AcFile_Source = "" Then
        FoundErr = True
        ServerMsg = "源数据库选择为Access数据库，则数据库文件路径不能为空"
        WriteMsg
    End If

    If DbType_Source = "sql" And (SqlServer_Source = "" Or SqlDbName_Source = "" Or SqlUser_Source = "") Then
        FoundErr = True
        ServerMsg = "源数据库选择为SQL数据库，SQL服务器的相关信息不能为空"
        WriteMsg
    End If

    If DbType_Remote = "access" And AcFile_Remote = "" Then
        FoundErr = True
        ServerMsg = "目标数据库选择为Access数据库，则数据库文件路径不能为空"
        WriteMsg
    End If

    If DbType_Remote = "sql" And (SqlServer_Remote = "" Or SqlDbName_Remote = "" Or SqlUser_Remote = "") Then
        FoundErr = True
        ServerMsg = "目标数据库选择为SQL数据库，SQL服务器的相关信息不能为空"
        WriteMsg
    End If
End Sub

Sub InitHTML()
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>PDO_API统一接口数据同步程序</title>
<link href="Code/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="border" id="outbox">
    <div class="topbg center bold head">PDO_API统一接口数据同步程序</div>
    <div id="intro"> <span id="subtitle" class="bold">操作说明</span>：
        <p id="introcontent">正在进行用户数据同步操作，此过程视数据量大小、服务器性能和网络状况需要较长时间来完成，此过程中切勿刷新或者关闭当前浏览器窗口。</p>
        <hr style="width:100%;height:1px;color:#666" />
        <div id="body4">
            <div class="tdbg" id="bodymain">
                <div class="line">
					<strong>用户总数：</strong>&nbsp;共 <span id="totalnum">...</span> 条 分为 <span id="batchs">...</span> 批处理<br/>
				</div>
				<div class="line">
					<strong>当前处理：</strong>&nbsp;第 <span id="currentbatch">...</span> 批 <span id="processnum">...</span> 条
				</div>
				<div class="line">
					<strong>处理进度：</strong>&nbsp;新增 <span id="successnum">...</span> 条/覆盖 <span id="overwritenum">...</span> 条/跳过 <span id="skipnum">...</span> 条/失败 <span id="failnum">...</span> 条
				</div>
            </div>
        </div>
        <div id="wait" style="width:100%;color:red;font-weight:bold;line-height:18px;text-align:center;">正在处理您的请求，请稍候...</div>
        <hr style="width:100%;height:1px;color:#666" />
        <div class="center"><input type="button" id="btn_back" value="上一步" onclick="GoPreview()" disabled="disabled" />&nbsp;&nbsp;<input type="button" id="btn_go" value="完 成" onclick="window.close()" disabled="disabled" /></div>
		<div id="formdiv" style="display:none">
            <form name="myform" id="myform" action="UserSynchro.asp?action=start&batch=2" method="post">
                <input type="hidden" name="source_systype" id="source_systype" value="<%=SysType_Source%>" />
                <input name="source_dbtype" type="hidden" id="source_dbtype" value="<%=DbType_Source%>" />
                <input name="source_dbpath" type="hidden" id="source_dbpath" value="<%=AcFile_Source%>" />
                <input name="source_servername" type="hidden" id="source_servername" value="<%=SqlServer_Source%>" />
                <input name="source_dbname" type="hidden" id="source_dbname" value="<%=SqlDbName_Source%>" />
                <input name="source_username" type="hidden" id="source_username" value="<%=SqlUser_Source%>" />
                <input name="source_password" type="hidden" id="source_password" value="<%=SqlPass_Source%>" />
                <input name="remote_systype" type="hidden" id="remote_systype" value="<%=SysType_Remote%>" />
                <input name="remote_dbtype" type="hidden" id="remote_dbtype" value="<%=DbType_Remote%>" />
                <input name="remote_dbpath" type="hidden" id="remote_dbpath" value="<%=AcFile_Remote%>" />
                <input name="remote_servername" type="hidden" id="remote_servername" value="<%=SqlServer_Remote%>" />
                <input name="remote_dbname" type="hidden" id="remote_dbname" value="<%=SqlDbName_Remote%>" />
                <input name="remote_username" type="hidden" id="remote_username" value="<%=SqlUser_Remote%>" />
                <input name="remote_password" type="hidden" id="remote_password" value="<%=SqlPass_Remote%>" />
				<input name="overwrite" type="hidden" id="overwrite" value="<%=NeedOverwrite%>" />
                <input name="batch" type="hidden" id="batch" value="<%=NeedBatch%>" />
                <input name="batchnum" type="hidden" id="batchnum" value="<%=BatchNum%>" />
                <input name="SucNum" type="hidden" id="SucNum" value="0" />
                <input name="SkipNum" type="hidden" id="SkipNum" value="0" />
                <input name="OverNum" type="hidden" id="OverNum" value="0" />
                <input name="FailNum" type="hidden" id="FailNum" value="0" />
            </form>
        </div>
    </div>
</div>
<br/>
<div class="border center" id="copyright">Copyright &copy; 2004 - 2006 PowerEasy Inc. All Rights Reserved<br/>
    Powered By UserSynchro 2.0 Build 0514</div>
</body>
</html>
<%
Response.Flush
End Sub

Sub RefreshHTMLStart(iTotal,iBatchs,iBatch,iStart,iEnd)
    Response.Write "<script type=""text/javascript"" language=""javascript"">" & vbNewLine
    Response.Write vbTab & "document.getElementById(""totalnum"").innerHTML = """ & iTotal & """;" & vbNewLine
    Response.Write vbTab & "document.getElementById(""batchs"").innerHTML = """ & iBatchs & """;" & vbNewLine
    Response.Write vbTab & "document.getElementById(""currentbatch"").innerHTML = """ & iBatch & """;" & vbNewLine
    Response.Write vbTab & "document.getElementById(""processnum"").innerHTML = """ & iStart & " - " & iEnd & """;" & vbNewLine
    Response.Write "</script>" & vbNewLine
    Response.Flush
End Sub

Sub RefreshHTMLEnd(iSuccess,iSkip,iOverwrite,iFailed)
    Response.Write "<script type=""text/javascript"" language=""javascript"">" & vbNewLine
    Response.Write vbTab & "document.getElementById(""successnum"").innerHTML = """ & iSuccess & """;" & vbNewLine
    Response.Write vbTab & "document.getElementById(""overwritenum"").innerHTML = """ & iOverwrite & """;" & vbNewLine
    Response.Write vbTab & "document.getElementById(""skipnum"").innerHTML = """ & iSkip & """;" & vbNewLine
    Response.Write vbTab & "document.getElementById(""failnum"").innerHTML = """ & iFailed & """;" & vbNewLine
    Response.Write "</script>" & vbNewLine
    Response.Flush
End Sub

Sub OutputSubmit(blnFinished, Batch)
    CleanConns
    Response.Write "<script type=""text/javascript"" language=""javascript"">" & vbNewLine
    If blnFinished Then
        Response.Write vbTab & "document.getElementById(""wait"").innerHTML = ""操作已完成，感谢您对动易的信任与支持！"";" & vbNewLine
        Response.Write vbTab & "document.getElementById(""btn_go"").removeAttribute(""disabled"");" & vbNewLine
    Else
        Response.Write vbTab & "document.forms[0].SucNum.value = """ & SuccessRecord & """;" & vbNewLine
        Response.Write vbTab & "document.forms[0].SkipNum.value = """ & SkipRecord & """;" & vbNewLine
        Response.Write vbTab & "document.forms[0].OverNum.value = """ & OverwriteRecord & """;" & vbNewLine
        Response.Write vbTab & "document.forms[0].FailNum.value = """ & FailedRecord & """;" & vbNewLine
        Response.Write vbTab & "document.forms[0].action = ""UserSynchro.asp?action=start&batch=" & Batch+1 & """;" & vbNewLine
        Response.Write vbTab & "document.forms[0].submit();" & vbNewLine
    End If
    Response.Write "</script>" & vbNewLine
    Response.Flush
End Sub

Sub WriteMsg
    If action = "TestConn" Then
        Response.contentType = "text/html"
        Response.charset = "gb2312"
        Response.Write ServerMsg
        Response.End
    Else
        Response.Write "<script type=""text/javascript"" language=""javascript"">" & vbNewLine
        Response.Write vbTab & "document.getElementById(""wait"").innerHTML = """ & ServerMsg & """;" & vbNewLine
        Response.Write "</script>" & vbNewLine
        Response.End
    End If
End Sub

Sub CleanConns
    On Error Resume Next
    Conn_Source.Close
    Conn_Remote.Close
    Set Conn_Source = Nothing
    Set Conn_Remote = Nothing
End Sub

Sub OpenDatabase(OpenType)
    Dim strNameOfDb
    On Error Resume Next
    If OpenType = "Source" Then
        strNameOfDb = "源数据库"
        Set Conn_Source = Server.CreateObject("ADODB.Connection")
        If DbType_Source = "access" Then
            ConnStr = "Provider = Microsoft.JET.OleDb.4.0; Data Source = " & Server.MapPath(AcFile_Source) & ";"
        Else
            ConnStr = "Provider = Sqloledb; User ID = " & SqlUser_Source & "; Password = " & SqlPass_Source & "; Initial Catalog = " & SqlDbName_Source & "; Data Source = " & SqlServer_Source & ";"
        End If
        Conn_Source.Open ConnStr
    Else
        strNameOfDb = "目标数据库"
        Set Conn_Remote = Server.CreateObject("ADODB.Connection")
        If DbType_Remote = "access" Then
            ConnStr = "Provider = Microsoft.JET.OleDb.4.0; Data Source = " & Server.MapPath(AcFile_Remote) & ";"
        Else
            ConnStr = "Provider = Sqloledb; User ID = " & SqlUser_Remote & "; Password = " & SqlPass_Remote & "; Initial Catalog = " & SqlDbName_Remote & "; Data Source = " & SqlServer_Remote & ";"
        End If
        Conn_Remote.Open ConnStr
    End If
    If Err Then
        FoundErr = True
        ServerMsg = "创建" & strNameOfDb & "的连接失败，请检查所提交的信息。以下信息供参考： 连接代码：[" & ConnStr & "]"
        Err.Clear
        WriteMsg
    End If
End Sub

Sub MyExecute(ExecuteType,strToExecute,strErr)
    On Error Resume Next
    If ExecuteType = "Source" Then
        Conn_Source.Execute(strToExecute)
    Else
        Conn_Remote.Execute(strToExecute)
    End If
    If Err Then
        FoundErr = True
        ServerMsg = strErr & "以下信息供参考： SQL语句：[" & strToExecute & "]"
        Err.Clear
        WriteMsg
    End If
End Sub
%>