<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Option Explicit
Server.ScriptTimeOut = 9999999
Response.Buffer = True

Dim Action, PES_Now, PER_Now, ConnStrS, ConnStrR, ConnSource, ConnRemote
Dim SourceSys, SourceDbType, SourceDbFile, SourceDbServer, SourceDbName, SourceDbUser, SourceDbPass
Dim RemoteSys, RemoteDbType, RemoteDbFile, RemoteDbServer, RemoteDbName, RemoteDbUser, RemoteDbPass
Dim TotalNum, SuccessNum, JumpNum, DataConnected, SourceUserTable, RemoteUserTable
Dim CountRefresh
CountRefresh = 0
Const FileName = "UserSynchro"
Const FileVersion = "2.0.0"
Const FileType = ""
Const CheckUpdateUrl = "http://www.coders.cn/Works/update.asp"
Action = Trim(Request("action"))
TotalNum = 0
SuccessNum = 0
JumpNum = 0
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>动易2005整合专用用户资料同步程序</title>
<link href="Style.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="2" topmargin="2" marginwidth="0" marginheight="0">
<table width="98%"  border="0" align="center" cellpadding="2" cellspacing="0" class="border">
    <tr>
        <td align="center" class="topbg">&nbsp;&nbsp;&nbsp;&nbsp;<b>动易2005整合专用用户资料同步程序</b></td>
        <td align="center" class="topbg"><a href="http://bbs.asp163.net" class="Class" target=_blank>动易官方论坛</a></td>
    </tr>
<%
If Action = "DoTrans" Then
%>
    <tr>
        <td align="center" colspan="2">正在进行数据转换， 此过程视您服务器性能、网络环境以及站点规模，可能需要几分钟或更长的时间，在此过程中，请不要关闭或者刷新浏览器！</td>
    </tr>
<%
End If
%>
</table>
<%
Select Case Action
    Case "DbSet"
        Call DbSet
    Case "DoTrans"
        Call DoTrans
    Case "ShowResult"
        Call ShowResult
    Case Else
        Call readme
End Select
%>
<table width="100%"  border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
</table>
<table width="98%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="right">&nbsp;</td>
    <td height="10" align="center" valign="bottom">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td width="30%" align="right" valign="bottom"><a href="http://www.powereasy.cn" target=_blank><img src="logo.gif" height="31" border="0"></a></td>
    <td width="48%" align="center" valign="bottom">
    Powered by <a href="http://www.iiscn.net" target=_blank title="QQ:5930434">小李刀刀</a>[<a href="http://www.powereasy.cn" target="_blank">动易网络</a>]
    &nbsp;<a href="<%=CheckUpdateUrl%>?FileName=<%=FileName%>&FileVersion=<%=FileVersion%>&FileType=<%=FileType%>" target=_blank><img src="checkupdate.gif" border=0></a>
      <br>
    &copy;2004 - 2005 <a href="http://www.powereasy.cn" target=_blank><font
face="Verdana, arial, helvetica, sans-serif"><b>PowerEasy Inc. </b></font></a> All Rights Reserved. </td>
    <td width="22%" align=left valign=bottom></td>
  </tr>
</table>
</body>
</html>

<%
'定义程序中用到的过程
Private Sub readme()

%>
<table width="98%"  border="0" align="center" cellpadding="2" cellspacing="1" class="border">
    <tr>
      <td class="tdbg">
      <ul>
            <li>程序说明
                <ol>
                  <li>本程序当前版本为<font color=red><b><%=FileVersion%><%=FileType%></b></font>，请确保此版本号与官方网站上提供的最新版本号一致，否则，请先下载最新版本后再运行；</li>
                  <li>本程序适用于动易2005 SP2官方版、动网7.0SP2版、动网7.1版中<b>任意两个程序之间</b>的用户资料互相转换、合并；</li>
                  <li>本程序同时支持MS SQL、ACCESS两种数据库；</li>
                  <li>使用本程序前请先做好相关数据库文件的备份（主要是目标数据库），以免造成数据文件损坏或者数据丢失。</li>
                  <li>本程序为动易网络为便于网友使用作为程序辅助插件提供，由于站点数据库中可能存在错误资料，或者由于网络、操作等因素的存在，动易公司不保证操作过程一定能成功完成，如果因进行此操作导致数据文件损坏或者数据丢失，只能依靠您的备份资料进行恢复，动易公司不承担任何责任，不负责数据修复服务。</li>
                  <li>如果您对相关操作有任何疑问，或者需要提交意见、建议，请访问下面的网址提交回复：
                    <br>
                  <a href="http://bbs.asp163.net" target=_blank>http://bbs.asp163.net</a></li>
                </ol>
            </li>
        </ul></td>
    </tr>
    <form name="form1" method="post" action="UserSynchro.asp">
    <tr>
        <td align="center" valign="top" class="tdbg">
          <input name="action" type="hidden" id="action" value="DbSet"><input name="Submit" type="submit" class="button" value="我已仔细阅读以上说明">
        </td>
    </tr>
    </form>
</table>
<%

End Sub 'readme

Private Sub DbSet()

%>
<table width="98%"  border="0" align="center" cellpadding="2" cellspacing="1" class="border">
  <form name="actionform" id="actionform" action="UserSynchro.asp" method="post">
    <tr>
      <td colspan="2" class="tdbg"><ul><li>操作步骤：
            <ol>
              <li>备份目标数据库*；</li>
                <li>选择源数据库*的程序版本及数据类型，并填写数据库连接信息；</li>
                <li>选择目标数据库*的程序版本数据类型，并填写数据库连接信息；</li>
                <li>提交并等待页面提示操作完成（中途切勿刷新或者关闭浏览器）。</li>
            </ol>
            目标数据库：指要导入数据的数据库；源数据库：指要导出数据的数据库。
            <br>
            例如：进行用户资料从动网7.0SP2 SQL版到动易2005ACCESS版的同步，则源数据库为动网7.0SP2的SQL数据库，目标数据库为动易2005的ACCESS数据库。</li>
          </ul>
      </td>
    </tr>
    <tr align="center">
      <th height="22" colspan="2" class="topbg2"><b><font color="#FFFFFF">收集数据库信息</font></b></th>
    </tr>
    <tr>
      <td width="27%" rowspan="4" valign="top" class="tdbg"><strong>动易用户数据互转工具</strong><ul><li><font color="#FF0000">收集数据库信息</font></li>
          <li>正在进行数据同步</li>
          <li> 操作结果说明</li>
      </ul></td>
      <td width="73%" class="tdbg"><table width="100%"  border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
        <tr class="tdbg">
          <td width="22%"><strong>源数据库的程序版本&nbsp;&nbsp;：</strong></td>
          <td width="17%"><select name="SourceSys" size="1" id="SourceSys">
            <option value="Dvbbs70" selected>动网7.0</option>
            <option value="Dvbbs71">动网7.1</option>
            <option value="PE2005">动易2005SP2</option>
          </select></td>
          <td width="12%">源数据库类型：</td>
          <td width="49%"><p>
            <input type="radio" name="SourceDbType" value="SQL" onClick="tr_source_sql.style.display='block';tr_source_ac.style.display='none'"> MS SQL&nbsp;&nbsp;<input name="SourceDbType" type="radio" value="AC" checked onClick="tr_source_sql.style.display='none';tr_source_ac.style.display='block'"> ACCESS</label></td>
        </tr>
        <tr class="tdbg" name="tr_source_ac" id="tr_source_ac" style="display:block">
          <td><strong>源数据库文件的位置&nbsp;&nbsp;：</strong></td>
          <td colspan="3"><input name="SourceDbFile" type="text" id="SourceDbFile" size="40">&nbsp;例如：<font color="#0000FF">/bbs/data/dvbbs7.mdb</font></td>
        </tr>
        <tr class="tdbg" name="tr_source_sql" id="tr_source_sql" style="display:none">
          <td colspan="4" class="tdbg"><table width="100%"  border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
            <tr bgcolor="#FFFFFF" class="tdbg">
              <td width="22%" rowspan="4"><strong>源数据库的连接信息&nbsp;&nbsp;：</strong></td>
              <td>服务器地址：&nbsp;<input name="SourceDbServer" type="text" id="SourceDbServer" value="127.0.0.1"></td>
            </tr>
            <tr bgcolor="#FFFFFF" class="tdbg">
              <td>数据库名称：&nbsp;<input name="SourceDbName" type="text" id="SourceDbName" value="Dvbbs7"></td>
            </tr>
            <tr bgcolor="#FFFFFF" class="tdbg">
              <td>用　户　名：&nbsp;<input name="SourceDbUser" type="text" id="SourceDbUser" value="sa"></td>
            </tr>
            <tr bgcolor="#FFFFFF" class="tdbg">
              <td>密　　　码：&nbsp;<input name="SourceDbPass" type="password" id="SourceDbPass"></td>
            </tr>
          </table></td>
        </tr>
        <tr class="tdbg">
          <td colspan="4" class="tdbg2">&nbsp;</td>
          </tr>
        <tr class="tdbg">
          <td><strong>目标数据库的程序版本：</strong></td>
          <td><select name="RemoteSys" size="1" id="RemoteSys">
              <option value="Dvbbs70">动网7.0</option>
              <option value="Dvbbs71">动网7.1</option>
              <option value="PE2005" selected>动易2005SP2</option>
                    </select></td>
          <td>源数据库类型：</td>
          <td><p> <input type="radio" name="RemoteDbType" value="SQL" onClick="tr_remote_sql.style.display='block';tr_remote_ac.style.display='none'"> MS SQL&nbsp;&nbsp;<input name="RemoteDbType" type="radio" value="AC" checked onClick="tr_remote_sql.style.display='none';tr_remote_ac.style.display='block'"> ACCESS</td>
        </tr>
        <tr class="tdbg" name="tr_remote_ac" id="tr_remote_ac" style="display:block">
          <td><strong>目标数据库文件的位置：</strong></td>
          <td colspan="3"><input name="RemoteDbFile" type="text" id="RemoteDbFile" size="40">&nbsp;例如：<font color="#0000FF">/database/Powereasy5.mdb</font></td>
        </tr>
        <tr class="tdbg" id="tr_remote_sql" name="tr_remote_sql" style="display:none">
          <td colspan="4" class="tdbg"><table width="100%"  border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
              <tr bgcolor="#FFFFFF" class="tdbg">
                <td width="22%" rowspan="4"><strong>目标数据库的连接信息：</strong></td>
                <td>服务器地址：&nbsp;<input name="RemoteDbServer" type="text" id="RemoteDbServer" value="127.0.0.1"></td>
              </tr>
              <tr bgcolor="#FFFFFF" class="tdbg">
                <td>数据库名称：&nbsp;<input name="RemoteDbName" type="text" id="RemoteDbName" value="PowerEasy5"></td>
              </tr>
              <tr bgcolor="#FFFFFF" class="tdbg">
                <td>用　户　名：&nbsp;<input name="RemoteDbUser" type="text" id="RemoteDbUser" value="sa"></td>
              </tr>
              <tr bgcolor="#FFFFFF" class="tdbg">
                <td>密　　　码：&nbsp;<input name="RemoteDbPass" type="password" id="RemoteDbPass"></td>
              </tr>
          </table></td>
        </tr>
      </table></td>
    </tr>
      <td align="left" class="tdbg"><b>遇到同名用户时的处理方法：</b><input name="ActionType" type="radio" id="ActionType" value="0" checked> 跳过&nbsp;&nbsp;&nbsp;&nbsp;<input name="ActionType" type="radio" id="ActionType" value="1"> 覆盖</td>
    </tr>
    </tr>
      <td align="center" class="tdbg"><input name="action" type="hidden" id="action" value="DoTrans"><input name="button1" type="button" class="button" value="上一步" onClick="JavaScript:history.go(-1)">&nbsp;&nbsp;<input name="Submit" type="submit" class="button" value="下一步">&nbsp;&nbsp;<input name="button2" type="button" class="button" value="退　出" onClick="window.close()"></td>
    </tr>
  </form>
</table>
<%

End Sub 'DbSet

Private Sub DoTrans()
Call InitializeHtml
SourceSys = Trim(Request.Form("SourceSys"))
SourceDbType = Trim(Request.Form("SourceDbType"))
If SourceSys = "PE2005" Then
    SourceUserTable = "PE_User"
Else
    SourceUserTable = "Dv_User"
End If
If SourceDbType = "SQL" Then
    SourceDbServer = Trim(Request.Form("SourceDbServer"))
    SourceDbName = Trim(Request.Form("SourceDbName"))
    SourceDbUser = Trim(Request.Form("SourceDbUser"))
    SourceDbPass = Trim(Request.Form("SourceDbPass"))
Else
    SourceDbFile = Trim(Request.Form("SourceDbFile"))
End If

RemoteSys = Trim(Request.Form("RemoteSys"))
RemoteDbType = Trim(Request.Form("RemoteDbType"))
If RemoteSys = "PE2005" Then
    RemoteUserTable = "PE_User"
Else
    RemoteUserTable = "Dv_User"
End If
If RemoteDbType = "SQL" Then
    RemoteDbServer = Trim(Request.Form("RemoteDbServer"))
    RemoteDbName = Trim(Request.Form("RemoteDbName"))
    RemoteDbUser = Trim(Request.Form("RemoteDbUser"))
    RemoteDbPass = Trim(Request.Form("RemoteDbPass"))
Else
    RemoteDbFile = Trim(Request.Form("RemoteDbFile"))
End If

Call RefreshHtml("CheckSourceData", "<li>正在连接源数据库...")
Call OpenDatabase("Source")
If DataConnected Then
    Call RefreshHtml("CheckSourceData", "<li>从源数据库共读取到<font color=red>" & TotalNum & "</font>条记录,现在将对这些记录逐一进行转换。")
    Call RefreshHtml("CheckRemoteData", "<li>正在连接目标数据库...")
    Call OpenDatabase("Remote")
    If DataConnected And TotalNum > 0 Then
        Call RefreshHtml("CheckRemoteData", "<li>正在进行转换...如果进度出现暂时停顿，请耐心等候！")
        Call UserTrans
        Call CloseDatabase
    End If
End If

If Not DataConnected Then
    Call RefreshHtml("theResult", "<li><font color=red>由于数据库连接失败，操作无法继续进行，请返回上一步，输入正确的数据库连接信息重试</font>")
    Call RefreshHtml("NavButton", "<input class='button' type='button' name='button' onClick='JavaScript:history.go(-1);' value='上一步'>")
Else
    Call RefreshHtml("theResult", "<li><font color=red>操作已完成，请点击下一步察看操作结果说明</font>")
    Call RefreshHtml("SuccessNum", "<input type='hidden' name='SuccessNum' id='SuccessNum' value='" & SuccessNum & "'>")
    Call RefreshHtml("JumpNum", "<input type='hidden' name='JumpNum' id='JumpNum' value='" & JumpNum & "'>")
    Call RefreshHtml("TotalNum", "<input type='hidden' name='TotalNum' id='TotalNum' value='" & TotalNum & "'>")
    Call RefreshHtml("NavButton", "<input class='button' type='submit' name='submit' value='下一步'>")
End If
End Sub 'DoTrans

Private Sub ShowResult()
TotalNum = Trim(Request.Form("TotalNum"))
SuccessNum = Trim(Request.Form("SuccessNum"))
JumpNum = Trim(Request.Form("JumpNum"))
%>
<table width="98%"  border="0" align="center" cellpadding="2" cellspacing="1" class="border">
  <form name="actionform" id="actionform" action="UserSynchro.asp" method="post">
    <tr>
      <td colspan="2" class="tdbg">&nbsp;</td>
    </tr>
    <tr align="center">
      <th height="22" colspan="2" class="topbg2"><b><font color="#FFFFFF">操作结果说明</font></b></th>
    </tr>
    <tr>
      <td width="27%" rowspan="3" valign="top" class="tdbg"><strong>动易用户数据互转工具</strong>
          <ul>
            <li>收集数据库信息</li>
            <li>进行数据库操作</li>
            <li> <font color="#FF0000">操作结果说明</font></li>
        </ul></td>
      <td width="73%" class="tdbg">成功转换<font color=blue><b><%=SuccessNum%></b></font>条用户记录，<br>
        有<font color=blue><b><%=JumpNum%></b></font>条用户资料由于目标数据库中已经存在同名用户，没有进行转换，<br>
        有<font color=red><b><%=Clng(TotalNum) - (CLng(SuccessNum) + Clng(JumpNum))%></b></font>条用户记录转换失败！<br>
        <br>
        分析说明：<br>
        <%
        If SuccessNum = TotalNum Then
            Response.Write "恭喜您！您的这次数据转换或合并非常成功！所有的记录都已经得到了转换。<br><br>"
        ElseIf CLng(SuccessNum) + CLng(JumpNum) = CLng(TotalNum) Then
            Response.Write "祝贺您，您的用户资料已经成功完成转换或合并，有部分源数据库中的用户名在目标数据库中已经存在，因此没有对其进行转换，这是正常的。<br><br>"
        Else
            Response.Write "非常遗憾，在转换过程中，有" & TotalNum - (SuccessNum + JumpNum) & "个用户的资料没有得到成功转换。这很有可能由以下原因导致：<br>"
            Response.Write "<li>您的某些记录中的无法由本程序自动修复的关键字段（例如用户名、Email地址、密码等）出现空值。这种情况下，该用户资料已经损坏，只能手工修改或删除；<br>"
            Response.Write "<li>您的源数据库或者目标数据库被修改过，与标准数据库有不同字段，导致程序运行错误；<br>"
            Response.Write "<li>其它未知错误，请与本程序作者联系以报告bug，并获得相关技术指导。<br><br>"
        End If
        %>
        </td>
    <tr>
        <td class="tdbg" align=center><b><font color=blue>让梦想插上翅膀，</font>&nbsp;&nbsp;<font color=red>与动易一起飞翔！</font>&nbsp;&nbsp;动易2005新版热卖中……</b></td>
        <tr>
      <td align="center" class="tdbg"><input name="Submit" type="button" class="button" value="退　出" onClick="window.close()"></td>
    </tr>
  </form>
</table>
<%

End Sub 'ShowResult
Private Sub OpenDatabase(DataType)
    On Error Resume Next
    Dim strSql, rsCount
    If DataType = "Source" Then
        If SourceDbType = "AC" Then
            ConnStrS = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(SourceDbFile)
            PES_Now = "Now()"
        Else
            ConnStrS = "Provider = Sqloledb; User ID = " & SourceDbUser & "; Password = " & SourceDbPass & "; Initial Catalog = " & SourceDbName & "; Data Source = " & SourceDbServer & ";"
            PES_Now = "Getdate()"
        End If
        Set ConnSource = Server.CreateObject("Adodb.Connection")
        ConnSource.Open ConnStrS
        ConnSource.CommandTimeOut = 999
        If Err Then
            Err.Clear
            Set conn = Nothing
            Call RefreshHtml("CheckSourceData", "<li><font color=red>源数据库连接出错，请检查您提供的连接信息是否正确</font>")
            DataConnected = False
        Else
            strSql = "Select Count(*) From " & SourceUserTable
            Set rsCount = ConnSource.Execute(strSql)
            If Err Then
                Err.Clear
                Call RefreshHtml("CheckSourceData", "<li><font color=red>您的数据库结构与您所选择的系统版本不符，请确认您源数据程序版本与数据库设置正确")
                DataConnected = False
            Else
                TotalNum = rsCount(0)
                If IsNull(TotalNum) Then TotalNum = 0
                DataConnected = True
            End If
            Set rsCount = Nothing
        End If
    Else
        If RemoteDbType = "AC" Then
            ConnStrR = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(RemoteDbFile)
            PER_Now = "Now()"
        Else
            ConnStrR = "Provider = Sqloledb; User ID = " & RemoteDbUser & "; Password = " & RemoteDbPass & "; Initial Catalog = " & RemoteDbName & "; Data Source = " & RemoteDbServer & ";"
            PER_Now = "Getdate()"
        End If
        Set ConnRemote = Server.CreateObject("Adodb.Connection")
        ConnRemote.Open ConnStrR
        ConnRemote.CommandTimeOut = 999
        If Err Then
            Err.Clear
            Set conn = Nothing
            Call RefreshHtml("CheckRemoteData", "<li>目标数据库连接出错，请检查您提供的连接信息是否正确")
            DataConnected = False
        Else
            strSql = "Select * From " & RemoteUserTable
            Set rsCount = ConnRemote.Execute(strSql)
            If Err Then
                Err.Clear
                Call RefreshHtml("CheckRemoteData", "<li>您的数据库结构与您所选择的系统版本不符，请确认您目标数据程序版本与数据库设置正确")
                DataConnected = False
            Else
                DataConnected = True
            End If
            Set rsCount = Nothing
        End If
    End If
End Sub 'OpenDatabase

Private Sub UserTrans()
    '定义动易、动网都要用的字段变量
    Dim UserName, UserPassword, UserQuestion, UserAnswer, UserEmail, UserSex
    Dim UserRegDate, UserLastLoginTime, UserLogins
    '定义数据处理过程中的临时变量
    Dim strSql, RsSource, RsRemote, TempRs, Rs, UserGroupID
    Dim ActionType, NeedTrans, IsAddUser
    ActionType = Trim(Request("ActionType"))
    If IsNumeric(ActionType) Then
        ActionType = CLng(ActionType)
    Else
        ActionType = 0
    End If

    '如果目标数据库是动易，则先生成必要的默认值
    If RemoteSys = "PE2005" Then
        '获取默认用户权限和设置
        Set TempRs = ConnRemote.Execute("select GroupID,GroupSetting from PE_UserGroup where GroupType=2")
        Dim GroupID, GroupSetting
        GroupID = TempRs(0)
        GroupSetting = Split(TempRs(1), ",")
        '获得用户ID号初始值,判断目标数据库是否存在用户
        Dim MaxUserID, UserExist
        Set TempRs = ConnRemote.Execute("SELECT Max(UserID) FROM PE_User")
        If IsNull(TempRs(0)) Then
            MaxUserID = 0
            UserExist = False
        Else
            MaxUserID = TempRs(0)
            UserExist = True
        End If
        Set TempRs = Nothing
        '生成符合条件的随机验证码
        Dim CheckNum
        Randomize
        CheckNum = CStr(Int(7999 * Rnd + 2000)) & CStr(Int(7999 * Rnd + 2000)) '随机验证码
        '生成客户编号的前8位
        Dim v_ymd, v_hms, v_mmm, ClientNum
        v_ymd = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2)
    Else
        If RemoteSys = "Dvbbs70" Then
            Set Rs = ConnRemote.Execute("select UserGroupID,IsSetting,ParentGID from Dv_UserGroups where not MinArticle=-1 order by MinArticle")
            If Rs(1) = 1 Then
                UserGroupID = Rs(0)
            Else
                If Rs(2) = 0 Then
                    UserGroupID = Rs(0)
                Else
                    UserGroupID = Rs(2)
                End If
            End If
        Else
            Set Rs = ConnRemote.Execute("Select UserGroupID From Dv_UserGroups Where ParentGID=3 Order By MinArticle")
            UserGroupID = Rs("UserGroupID")
        End If
    End If  '完毕
    'On Error Resume Next
    '读取源数据库中的所有用户记录
    strSql = "SELECT * From " & SourceUserTable
    Set RsSource = ConnSource.Execute(strSql)
    If RsSource.EOF And RsSource.Bof Then
        Call RefreshHtml("RateOfProgress", "<li>源数据库中没有用户资料，无需进行同步")
    Else
        Do While Not RsSource.EOF
            UserName = RsSource("UserName")
            UserPassword = RsSource("UserPassword")
            '针对不同系统处理读取的字段
            If SourceSys = "PE2005" Then
                UserQuestion = CheckStr(RsSource("Question"))
                UserAnswer = CheckStr(RsSource("Answer"))
                UserSex = CheckInt(RsSource("Sex"))
                UserRegDate = CheckDateTime(RsSource("RegTime"))
                UserLastLoginTime = CheckDateTime(RsSource("LastLoginTime"))
                UserLogins = CheckInt(RsSource("LoginTimes"))
                UserEmail = CheckStr(RsSource("Email"))
            Else
                UserQuestion = CheckStr(RsSource("UserQuesion"))
                UserAnswer = CheckStr(RsSource("UserAnswer"))
                UserSex = RsSource("UserSex")
                UserRegDate = CheckDateTime(RsSource("JoinDate"))
                UserLastLoginTime = CheckDateTime(RsSource("LastLogin"))
                UserLogins = CheckInt(RsSource("UserLogins"))
                UserEmail = CheckStr(RsSource("UserEmail"))
            End If
            IsAddUser = True
            strSql = "Select * From " & RemoteUserTable & " Where UserName='" & UserName & "'"
            Set RsRemote = Server.CreateObject("Adodb.Recordset")
            RsRemote.Open strSql, ConnRemote, 1, 3
            If Not (RsRemote.Bof And RsRemote.EOF) Then
                If ActionType = 0 Then
                    NeedTrans = False
                    JumpNum = JumpNum + 1
                Else
                    NeedTrans = True
                End If
                IsAddUser = False
            Else
                NeedTrans = True
                RsRemote.AddNew
            End If
            If NeedTrans = True Then
                If RemoteSys = "PE2005" Then
                    RsRemote("UserPassword") = UserPassword
                    RsRemote("LastPassword") = GetRndPassword(16)
                    RsRemote("Question") = UserQuestion
                    RsRemote("Answer") = UserAnswer
                    If IsAddUser = True Then
                        '生成客户编号的中间6位
                        v_hms = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
                        '生成客户编号的后2位
                        Randomize
                        v_mmm = Right("0" & CStr(CInt(99 * Rnd) + 1), 2)
                        ClientNum = v_ymd & v_hms & v_mmm
                        MaxUserID = CLng(MaxUserID + 1)
                        RsRemote("UserID") = MaxUserID
                        RsRemote("NickName") = UserName
                        RsRemote("UserName") = UserName
                        RsRemote("Email") = UserEmail
                        RsRemote("Sex") = UserSex
                        RsRemote("ClientNum") = ClientNum
                        RsRemote("RegTime") = Now()
                        RsRemote("LoginTimes") = 0
                        RsRemote("IsLocked") = False
                        RsRemote("Balance") = 0
                        RsRemote("UserExp") = 0
                        RsRemote("Orders") = 0
                        RsRemote("PaidOrders") = 0
                        RsRemote("SentOrders") = 0
                        RsRemote("PostItems") = 0
                        RsRemote("PassedItems") = 0
                        RsRemote("DelItems") = 0
                        RsRemote("UnsignedItems") = ""
                        RsRemote("UnreadMsg") = 0
                        RsRemote("arrClass_Browse") = ""
                        RsRemote("arrClass_View") = ""
                        RsRemote("arrClass_Input") = ""
                        RsRemote("UserSetting") = ""
                        RsRemote("GroupID") = GroupID
                        RsRemote("ChargeType") = GroupSetting(14)
                        RsRemote("UserPoint") = 100
                        RsRemote("BeginTime") = FormatDateTime(Now(), 2)
                        RsRemote("ValidNum") = 100
                        RsRemote("ValidUnit") = 1
                        RsRemote("CheckNum") = CheckNum
                        RsRemote("SpecialPermission") = False
                    End If
                Else
                    RsRemote("UserPassword") = UserPassword
                    RsRemote("UserQuesion") = UserQuestion
                    RsRemote("UserAnswer") = UserAnswer
                    If IsAddUser = True Then
                        RsRemote("UserName") = UserName
                        RsRemote("UserEmail") = CheckStr(UserEmail)
                        RsRemote("UserSign") = ""
                        RsRemote("UserFace") = "images/userface/image1.gif"
                        RsRemote("LockUser") = 0
                        RsRemote("UserMsg") = 0
                        RsRemote("UserWealth") = 0
                        RsRemote("UserWidth") = 64
                        RsRemote("UserHeight") = 64
                        RsRemote("UserSex") = UserSex
                        RsRemote("JoinDate") = UserRegDate
                        RsRemote("LastLogin") = UserLastLoginTime
                        RsRemote("UserLastIP") = Replace(Request.ServerVariables("REMOTE_ADDR"), "'", "")
                        RsRemote("UserLogins") = UserLogins
                        RsRemote("UserIM") = "||||||||||||||||||"
                        RsRemote("UserPost") = 0
                        RsRemote("UserTopic") = 0
                        RsRemote("UserClass") = "新手上路"
                        RsRemote("UserGroup") = "注册用户"
                        RsRemote("UserEP") = 0
                        RsRemote("UserCP") = 0
                        RsRemote("UserPower") = 0
                        RsRemote("UserDel") = 0
                        RsRemote("UserIsBest") = 0
                        RsRemote("UserInfo") = "||||||||||||||||||||||||||||||||||||||||||"
                        RsRemote("UserFav") = "陌生人,我的好友,黑名单"
                        RsRemote("UserSetting") = "||||||"
                        RsRemote("UserGroupID") = UserGroupID
                        RsRemote("UserHidden") = 0
                        RsRemote("IsChallenge") = 0
                    End If
                End If
                RsRemote.Update
                If Not Err Then
                    SuccessNum = SuccessNum + 1
                Else
                    Err.Clear
                End If
                RsRemote.Close
                Set RsRemote = Nothing
                If CInt(CInt(SuccessNum / TotalNum * 100) - CountRefresh) = 5 Or CInt(CInt(JumpNum / TotalNum * 100) - CountRefresh) = 5 Or SuccessNum = TotalNum Or JumpNum = TotalNum Then
                    Call RefreshHtml("RateOfProgress", "<li>已成功完成：<font color=blue>" & SuccessNum & "/" & TotalNum & "</font>条记录，跳过<font color=blue>" & JumpNum & "</font>条")
                    CountRefresh = CInt(SuccessNum / TotalNum * 100)
                End If
            End If
            RsSource.MoveNext
        Loop
        RsSource.Close
        Set RsSource = Nothing
        Call RefreshHTML("RateOfProgress","<li>用户资料转换已完成：<font color=blue>100%</font>,共跳过"&JumpNum&"条记录")
    End If
End Sub 'UserTrans

Private Sub InitializeHtml()
%>
<table width="98%"  border="0" align="center" cellpadding="2" cellspacing="1" class="border">
    <form name="actionform" id="actionform" action="UserSynchro.asp" method="post">
        <tr>
            <td colspan="2" class="tdbg">&nbsp;
            </td>
        </tr>
        <tr align="center">
            <th height="22" colspan="2" class="topbg2">
                <b><font color="#FFFFFF">正在进行数据操作</font></b>
            </th>
        </tr>
        <tr>
            <td width="27%" rowspan="2" valign="top" class="tdbg">
                <strong>动易用户数据互转工具</strong>
                <ul>
                    <li>收集数据库信息</li>
                    <li><font color="#FF0000">进行数据操作</font></li>
                    <li> 操作结果说明</li>
                </ul>
            </td>
            <td width="73%" class="tdbg" style="margin-left:10px;margin-right:10px">
            <span name="CheckSourceData" id="CheckSourceData">&nbsp;&nbsp;</span>
            <span name="CheckRemoteData" id="CheckRemoteData">&nbsp;&nbsp;</span>
            <span name="RateOfProgress" id="RateOfProgress">&nbsp;&nbsp;</span>
            <span name="MsgProgress" id="MsgProgress">&nbsp;&nbsp;</span>
            <span name="theResult" id="theResult">&nbsp;&nbsp;</span>
            </td>
        </tr>
        <tr>
            <td align="center" class="tdbg">
                <input name="action" type="hidden" id="action" value="ShowResult">
                <span name="SuccessNum" id="SuccessNum">&nbsp;</span>
                <span name="JumpNum" id="JumpNum">&nbsp;</span>
                <span name="TotalNum" id="TotalNum">&nbsp;</span>
                <span name="NavButton" id="NavButton">&nbsp;</span>&nbsp;&nbsp;<input name="Submit" type="button" class="button" value="退　出" onClick="window.close()">
            </td>
        </tr>
    </form>
</table>
<%
End Sub

Private Sub RefreshHtml(SpanName, SpanValue)
    Response.Write "<script language='JavaScript'>" & vbCrLf
    Response.Write SpanName & ".innerHTML=""" & SpanValue & """;" & vbCrLf
    Response.Write "</script>" & vbCrLf
    Response.Flush
End Sub

Private Sub CloseDatabase()
    On Error Resume Next
    ConnSource.Close: Set ConnSource = Nothing
    ConnRemote.Close: Set ConnRemote = Nothing
End Sub 'CloseDatabase

'定义程序中用到的函数
Private Function CheckStr(StrToCheck)
    If IsNull(StrToCheck) Then
        CheckStr = ""
    Else
        CheckStr = StrToCheck
    End If
End Function 'CheckStr

Private Function CheckInt(ValueToCheck)
    If IsNull(ValueToCheck) Or IsNumeric(ValueToCheck) = False Then
        CheckInt = 0
    ElseIf ValueToCheck = 0 Then
        CheckInt = 0
    Else
        CheckInt = ValueToCheck
    End If
End Function 'CheckInt

Private Function CheckDateTime(ValueToCheck)
    If IsNull(ValueToCheck) Or IsDate(ValueToCheck) = False Then
        CheckDateTime = Now()
    Else
        CheckDateTime = CDate(ValueToCheck)
    End If
End Function 'CheckDateTime

Function GetRndPassword(PasswordLen)
    Dim Ran, i, strPassword
    strPassword = ""
    For i = 1 To PasswordLen
        Randomize
        Ran = CInt(Rnd * 2)
        Randomize
        If Ran = 0 Then
            Ran = CInt(Rnd * 25) + 97
            strPassword = strPassword & UCase(Chr(Ran))
        ElseIf Ran = 1 Then
            Ran = CInt(Rnd * 9)
            strPassword = strPassword & Ran
        ElseIf Ran = 2 Then
            Ran = CInt(Rnd * 25) + 97
            strPassword = strPassword & Chr(Ran)
        End If
    Next
    GetRndPassword = strPassword
End Function
%>