<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../../conn/conn.asp" -->
<!--#include file="../../Inc/Commoncode.asp" -->
<!--#include file="../checkvalid.asp"-->
<%
'************************************************************
'	Software name: Finereason HRCMS 7.0
'	软件名称:嘉缘人才网站内容管理系统 V7.0
'	Email: service@finereason.com . QQ:109530926
'	Web: http://www.finereason.com  http://www.yjys.net
'	Copyright (C) FineSincere Inc. All Rights Reserved.
'	版权所有 嘉挚科技 未经嘉挚公司授权不得用于任何商业用途
'************************************************************
If Not FRAdminLevel(401) Then Call ErrorMsg()
Buffer(True)
dim Action
Action=trim(request("Action"))
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta content="noindex,nofollow" name="robots" />
<title>Finereason HRCMS 7.0 后台管理系统</title>
<link href="../css/style<%=sk%>.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../inc/input.js"></script>
<script language="JavaScript" type="text/JavaScript">
function unSelectAll()
{
    if(document.myform.chkAll.checked){
	document.myform.chkAll.checked = document.myform.chkAll.checked&0;
    } 	
}
function SelectAll(form)
{
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.Name != "chkAll"&&e.disabled!=true&&e.zzz!=1)
       e.checked = form.chkAll.checked;
    }
}
</script></head>
<body>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableBorder">
  <tr class="topbg">
    <th height="22" align="center" class="tableHeaderText"><strong >模板方案管理</strong></th>
  </tr>
  <tr>
    <td height="22"><span class="bodytitle"><font color="ff6600"><b class="style1">　管理选项</b></font>：</span>&nbsp;<a href="Admin_TemplateProject.asp?Action=Add">添加模板方案</a> | <a href="Admin_TemplateProject.asp">管理模板方案</a> | <a href="Admin_TempDatabase.asp?Action=LeadOut">模板方案导出</a> | <a href="Admin_TempDatabase.asp?Action=LeadIn">模板方案导入</a> [<a href="javascript:location.reload()">刷新页面</a>]</td>
  </tr>
</table>
<% 
If Action="LeadOut" or Action="LeadOutData" then 
	call ShowLeadOut()
Elseif  Action="LeadIn" or Action="ShowLeadInData" or Action="LeadInData"  Then
    call  ShowLeadIn()
End If
%>
<!--#include file="../inc/copy.asp"--><!--</body>
</html>-->
<%Sub  ShowLeadOut
If  Action="LeadOut"  Then
%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="tableBorder mt6">
  <tr>
     <th colspan="5" align="center" class="tableHeaderText" height=22>模板方案导出</th>
  </tr>
<form method="post" name="myform" action="Admin_TempDatabase.asp?Action=LeadOutData">
   <tr>         
      <td width="5%" height="22" align="center"><strong>选择</strong></td>                 
      <td width="30%" align="center"><strong>方案名称</strong></td>
      <td width="10%" align="center"><strong>方案目录</strong></td> 
      <td width="45%" align="center"><strong>方案备注</strong></td>
      <td width="10%" align="center"><strong>是否默认</strong></td>      
   </tr>         
<%
   Set Rs=server.createobject("adodb.recordset")         
   Sql="select TemplateProjectID,TemplateProjectName,TemplateDir,Intro,IsDefault from JOB_TemplateProject order by TemplateProjectID desc"       
   Rs.open Sql,Conn,1,1
   If (Not Rs.Eof)  And (Not Rs.Bof) then
	Do While Not Rs.Eof
   %>
   <tr>         
      <td height="22" align="center"><input type="checkbox" value=<%=Rs("TemplateProjectID")%> name="TempID" onClick="unSelectAll(this.form)" style="border: 0px;background-color: #E1F4EE;" class="checkbox"></td>                 
      <td align="center"><%=Rs("TemplateProjectName")%></td>
      <td align="center"><%=Rs("TemplateDir")%></td>   
      <td align="center"><%=Rs("Intro")%></td>
      <td align="center"><%if Rs("IsDefault") then%>
		  √
            <%else%>
            ×
            <%end if%></td>      
   </tr>   
      <%Rs.MoveNext
      Loop
      %>
   <tr>
      <td colspan=8 height="52" align="center">
      <input name="chkAll" type="checkbox" id="chkAll" onClick="SelectAll(this.form)" value="checkbox"  class="checkbox">全选&nbsp;&nbsp;&nbsp;&nbsp;
      导出到数据库：<input type="text" name="LeadOutMdb" size="30" value="../../Templates/LeadOut.mdb">
      <input type="submit" name="submit" class="inputs" value="导出">      </td>
   </tr>
<%
   Else
%>
  <tr>
	<td colspan='10' align="center"><br>
	系统中暂无模板方案！</td>
  </tr>
<%End If
   Rs.Close
   Set Rs=Nothing
%>
</form>
</table>
<%
Else
   Call LeadOutData()
End If
%>
<%End Sub%>
<%Sub ShowLeadIn
If  Action="LeadIn" Then
%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="tableBorder mt6">
  <tr>
	<th colspan="6" align="center" class="tableHeaderText" height=22><b>模板方案导入</b></th>
  </tr>
<form method="post" name="myform" action="Admin_TempDatabase.asp?Action=ShowLeadInData">
   <tr>
      <td align="center" valign="middle" height="100">数据库位置：
	<input name="LeadInMdb" type="text" id="LeadInMdb" size="43" value="../../Templates/LeadOut.mdb">
      </td>
   </tr>
   <tr>
      <td align="center">
        <input name="submit" type=submit value=" 下&nbsp;一&nbsp;步 " class="inputs">
      </td>
   </tr>
</form>
</table>
<%
ElseIf Action="ShowLeadInData" Then
   Call ShowLeadInData()
Else
   Call LeadInData()
End if
End Sub
Sub LeadOutData
   LeadOutMdb=trim(request.form("LeadOutMdb"))
   TempID=trim(request.form("TempID"))
   If LeadOutMdb="" then
      FoundErr=True
      ErrMsg="<br><li>数据库地址不能为空！</li>"
   End If
   If TempID="" Then
      FoundErr=True
      ErrMsg=ErrMsg & "<br><li>请选择要导出的项目</li>"
   Else
      TempID=Replace(TempID," ","")
   End If

   If FoundErr<>True Then
      dim ConnstrLead,ConnLead
      Set ConnLead = Server.CreateObject("ADODB.Connection")
      connstrLead="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(LeadOutMdb)
      ConnLead.Open ConnstrLead
      If Err Then
         err.Clear
         FoundErr=True
	 ErrMsg=ErrMsg & "<br>数据库连接出错，请确认数据库是否存在。"
      End If

      If FoundErr<>True Then
         ConnLead.execute("Delete From JOB_Skin")
         ConnLead.execute("Delete From JOB_Template")
		 ConnLead.execute("Delete From JOB_TemplateProject")
		 ConnLead.execute("Delete From JOB_Ad")
		 ConnLead.execute("Delete From JOB_Adplace")
		 ConnLead.execute("Delete From JOB_Adsplace")
		 ConnLead.execute("Delete From JOB_Label")
		 
		 For t=0 to ubound(split(TempID,","))
		 Set Rspn=Conn.execute("select TemplateProjectName from JOB_TemplateProject where TemplateProjectID="&split(TempID,",")(t)&"")
		 If Not Rspn.Eof then
		 ProjectName=Rspn("TemplateProjectName")
		 End If
		 Set Rspn=Nothing
		 
		 '导出样式表   
		 Set Rs=server.createobject("adodb.recordset")
         Sql="select SkinName,Skin_CSS,IsDefaultInProject,ProjectName,filename,imgpath,IsDefault from JOB_Skin where ProjectName='"&ProjectName&"' order by SkinID desc"         
         Rs.open Sql,Conn,1,1
         If Not Rs.Eof then
            Do while Not Rs.Eof
               '打开数据库
               Set RsLead=server.createobject("adodb.recordset")         
               SqlLead="select * from JOB_Skin"         
               RsLead.open SqlLead,ConnLead,1,3
               RsLead.AddNew
               RsLead("SkinName")=Rs("SkinName")
               RsLead("Skin_CSS")=Rs("Skin_CSS")
               RsLead("IsDefaultInProject")=Rs("IsDefaultInProject")
			   RsLead("ProjectName")=Rs("ProjectName")
			   RsLead("filename")=Rs("filename")
			   RsLead("imgpath")=Rs("imgpath")
			   RsLead("IsDefault")=Rs("IsDefault")
               RsLead.Update
               RsLead.Close
               Set RsLead=Nothing
            Rs.MoveNext
            Loop
         End If
         Rs.Close
         Set Rs=Nothing
		 
		 '导出模板
		 Set Rs=server.createobject("adodb.recordset")     
         Sql="select ChannelID,TemplateName,TemplateContent,IsDefault,ProjectName,IsDefaultInProject,Deleted,typeid from JOB_Template where ProjectName='"&ProjectName&"' order by TemplateID desc"         
         Rs.open Sql,Conn,1,1
         If Not Rs.Eof then
            Do while Not Rs.Eof
               '打开数据库
               Set RsLead=server.createobject("adodb.recordset")         
               SqlLead="select * from JOB_Template"         
               RsLead.open SqlLead,ConnLead,1,3
               RsLead.AddNew
               RsLead("ChannelID")=Rs("ChannelID")
               RsLead("TemplateName")=Rs("TemplateName")
               RsLead("TemplateContent")=Rs("TemplateContent")
			   RsLead("IsDefault")=Rs("IsDefault")
			   RsLead("ProjectName")=Rs("ProjectName")
			   RsLead("IsDefaultInProject")=Rs("IsDefaultInProject")
			   RsLead("Deleted")=Rs("Deleted")
			   RsLead("typeid")=Rs("typeid")
               RsLead.Update
               RsLead.Close
               Set RsLead=Nothing
            Rs.MoveNext
            Loop
         End If
         Rs.Close
         Set Rs=Nothing
		 Next
		 
		 '导出方案
         Set Rs=server.createobject("adodb.recordset")     
         Sql="select TemplateProjectID,TemplateProjectName,TemplateDir,Intro,IsDefault from JOB_TemplateProject where TemplateProjectID In("&TempID&") order by TemplateProjectID desc"         
         Rs.open Sql,Conn,1,1
         If Not Rs.Eof then
            Do while Not Rs.Eof
               '打开数据库
               Set RsLead=server.createobject("adodb.recordset")         
               SqlLead="select * from JOB_TemplateProject"         
               RsLead.open SqlLead,ConnLead,1,3
               RsLead.AddNew
               RsLead("TemplateProjectName")=Rs("TemplateProjectName")
			   RsLead("TemplateDir")=Rs("TemplateDir")
               RsLead("Intro")=Rs("Intro")
               RsLead("IsDefault")=Rs("IsDefault")
			   '导出方案的旧方案的编号以便导入时用
			   RsLead("oldproid")=Rs("TemplateProjectID")
               RsLead.Update
               RsLead.Close
               Set RsLead=Nothing
            Rs.MoveNext
            Loop
		 End If
         Rs.Close
         Set Rs=Nothing
			
		  '导出标签
         Set Rs=server.createobject("adodb.recordset")     
         Sql="select LabelName,LabelType,LabelIntro,LabelContent,Labeladddate,Labeleditdate,Labelorder,projectid from JOB_Label where projectid In("&TempID&") order by LabelID desc"         
         Rs.open Sql,Conn,1,1
         If Not Rs.Eof then
            Do while Not Rs.Eof
               '打开数据库
               Set RsLead=server.createobject("adodb.recordset")         
               SqlLead="select * from JOB_Label"         
               RsLead.open SqlLead,ConnLead,1,3
               RsLead.AddNew			   
               RsLead("LabelName")=Rs("LabelName")
			   RsLead("LabelType")=Rs("LabelType")
               RsLead("LabelIntro")=Rs("LabelIntro")
               RsLead("LabelContent")=Rs("LabelContent")
			   RsLead("Labeladddate")=Rs("Labeladddate")
			   RsLead("Labeleditdate")=Rs("Labeleditdate")
               RsLead("Labelorder")=Rs("Labelorder")
               RsLead("projectid")=Rs("projectid")			   
               RsLead.Update
               RsLead.Close
               Set RsLead=Nothing
            Rs.MoveNext
            Loop
         End If
         Rs.Close
         Set Rs=Nothing
		 
		  '导出广告位种类
         Set Rs=server.createobject("adodb.recordset")     
         Sql="select adplace_name,projectid,adplace_id from JOB_Adplace where projectid In("&TempID&") order by adplace_id desc"         
         Rs.open Sql,Conn,1,1
         If Not Rs.Eof then
            Do while Not Rs.Eof
               '打开数据库
               Set RsLead=server.createobject("adodb.recordset")         
               SqlLead="select * from JOB_Adplace"         
               RsLead.open SqlLead,ConnLead,1,3
               RsLead.AddNew
			   '导出广告种类的旧广告种类的编号以便导入时用
			   RsLead("oldadplaceid")=Rs("adplace_id")	  
               RsLead("adplace_name")=Rs("adplace_name")
               RsLead("projectid")=Rs("projectid")			   
               RsLead.Update
               RsLead.Close
               Set RsLead=Nothing
            Rs.MoveNext
            Loop
         End If
         Rs.Close
         Set Rs=Nothing
		 
		  '导出广告位
         Set Rs=server.createobject("adodb.recordset") 
		 sql="select Adsplace_id,Adsplace_name,Adsplace_placeid,Adsplace_priceid,Adsplace_price,Adsplace_unit,Adsplace_row,Adsplace_width,projectid from JOB_Adsplace where projectid In("&TempID&") order by Adsplace_id desc"    
         Rs.open Sql,Conn,1,1
         If Not Rs.Eof then
            Do while Not Rs.Eof
               '打开数据库
               Set RsLead=server.createobject("adodb.recordset")         
               SqlLead="select * from JOB_Adsplace"         
               RsLead.open SqlLead,ConnLead,1,3
               RsLead.AddNew			   
               RsLead("Adsplace_name")=Rs("Adsplace_name")
			   RsLead("Adsplace_placeid")=Rs("Adsplace_placeid")
               RsLead("Adsplace_priceid")=Rs("Adsplace_priceid")
               RsLead("Adsplace_price")=Rs("Adsplace_price")
			   RsLead("Adsplace_unit")=Rs("Adsplace_unit")
			   RsLead("Adsplace_row")=Rs("Adsplace_row")
               RsLead("Adsplace_width")=Rs("Adsplace_width")
               RsLead("projectid")=Rs("projectid")		
			   '导出广告位的旧广告位的编号以便导入时用
			   RsLead("oldadsplaceid")=Rs("Adsplace_id")			   		   
               RsLead.Update
               RsLead.Close
               Set RsLead=Nothing
            Rs.MoveNext
            Loop
         End If
         Rs.Close
         Set Rs=Nothing
		 
		  '导出广告
         Set Rs=server.createobject("adodb.recordset")     
         Sql="select Ad_sitename,Ad_siteurl,Ad_contactman,Ad_tel,Ad_width,Ad_pic,Ad_target,Ad_type,Ad_act,Ad_show,Ad_enddate,Ad_click,Ad_clicks,Ad_shows,Ad_stop,Ad_other,Ad_priceid,Ad_placeid,Ad_addtime,Ad_showtime,Ad_lose,projectid from JOB_Ad where projectid In("&TempID&") order by Ad_id desc"         
         Rs.open Sql,Conn,1,1
         If Not Rs.Eof then
            Do while Not Rs.Eof
               '打开数据库
               Set RsLead=server.createobject("adodb.recordset")         
               SqlLead="select * from JOB_Ad"         
               RsLead.open SqlLead,ConnLead,1,3
               RsLead.AddNew			   
               RsLead("Ad_sitename")=Rs("Ad_sitename")
			   RsLead("Ad_siteurl")=Rs("Ad_siteurl")
               RsLead("Ad_contactman")=Rs("Ad_contactman")
               RsLead("Ad_tel")=Rs("Ad_tel")
			   RsLead("Ad_width")=Rs("Ad_width")
			   RsLead("Ad_pic")=Rs("Ad_pic")
               RsLead("Ad_target")=Rs("Ad_target")			   
			   RsLead("Ad_type")=Rs("Ad_type")
               RsLead("Ad_act")=Rs("Ad_act")
			   RsLead("Ad_click")=Rs("Ad_click")
               RsLead("Ad_show")=Rs("Ad_show")
			   RsLead("Ad_enddate")=Rs("Ad_enddate")
			   RsLead("Ad_clicks")=Rs("Ad_clicks")			   
			   RsLead("Ad_shows")=Rs("Ad_shows")
			   RsLead("Ad_stop")=Rs("Ad_stop")
               RsLead("Ad_other")=Rs("Ad_other")
			   RsLead("Ad_priceid")=Rs("Ad_priceid")
               RsLead("Ad_placeid")=Rs("Ad_placeid")
			   RsLead("Ad_addtime")=Rs("Ad_addtime")
			   RsLead("Ad_showtime")=Rs("Ad_showtime")
               RsLead("Ad_lose")=Rs("Ad_lose")	   
               RsLead("projectid")=Rs("projectid")			   
               RsLead.Update
               RsLead.Close
               Set RsLead=Nothing
            Rs.MoveNext
            Loop
         End If
         Rs.Close
         Set Rs=Nothing
		 
		 
      End If
      ConnLead.close
      set connlead=nothing

   End If
   If FoundErr<>True Then
      ErrMsg="<br>数据导出成功"
      ErrMsg=ErrMsg & "<br>数据导出为：" & LeadOutMdb
	  response.Write "<br>"
      Call Show_Suc(ErrMsg,"Admin_TempDatabase.asp")
   Else
      Call Show_Err()
   End If
End Sub

Sub ShowLeadInData
   Dim LeadInMdb,connstrLead,connLead,RsLead,SqlLead
   LeadInMdb=Trim(Request("LeadInMdb"))
   If LeadInMdb="" Then
      FoundErr=True 
      ErrMsg="<br><li>数据库地址不能为空！</li>"
   End If
   If FoundErr<>True Then
      Set connLead = Server.CreateObject("ADODB.Connection")
      connstrLead="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(LeadInMdb)
      connLead.Open connstrLead
      If Err Then
         err.Clear
         FoundErr=True
         ErrMsg=ErrMsg & "<br><li>数据库连接出错，请确认数据库是否存在。</li>"
      End If
      If FoundErr<>True Then
         Set RsLead=server.createobject("adodb.recordset")         
         SqlLead="select TemplateProjectID,TemplateProjectName,TemplateDir,Intro,IsDefault from JOB_TemplateProject order by TemplateProjectID desc"         
         RsLead.open SqlLead,ConnLead,1,1
         If Not RsLead.Eof then
%>
<br>

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="tableBorder">
  <tr>
	<th colspan="2" align="center" class="tableHeaderText" height=22><b>模板方案导入</b></th>
</tr>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="tableBorder">
<form method="post" name="myform"  action="Admin_TempDatabase.asp?Action=LeadInData">
   <tr>         
      <td width="5%" height="22" align="center"><strong>选择</strong></td>                 
      <td width="10%" align="center"><strong>方案名称</strong></td>
      <td width="5%" align="center"><strong>方案目录</strong></td> 
      <td width="5%" align="center"><strong>方案备注</strong></td>
      <td width="5%" align="center"><strong>是否默认</strong></td>      
   </tr>         
<%
Do While Not RsLead.Eof
%>
   <tr>         
      <td width="5%" height="22" align="center"><input type="checkbox" value=<%=RsLead("TemplateProjectID")%> name="TempID" onClick="unSelectAll(this.form)" style="border: 0px;background-color: #E1F4EE;" class="checkbox"></td>                 
      <td width="10%" align="center"><%=RsLead("TemplateProjectName")%></td>
      <td width="5%" align="center"><%=RsLead("TemplateDir")%></td>   
      <td width="5%" align="center"><%=RsLead("Intro")%></td>
      <td width="5%" align="center"><%if RsLead("IsDefault") then%>
		  √
            <%else%>
            ×
            <%end if%></td>      
   </tr>  
<%
RsLead.MoveNext
Loop
%>
   <tr>
     <td align="center" colspan="5">
	<input name="LeadInMdb" type="hidden" value="<%=LeadInMdb%>">
        <input name="chkAll" type="checkbox" class="checkbox" id="chkAll" onClick="SelectAll(this.form)" value="checkbox" >
        全选&nbsp;&nbsp;&nbsp;&nbsp;
	<input name="step" type="hidden" value="1">
	<input name="submit" type=submit class="inputs" style="cursor: hand;" value=" 确&nbsp;&nbsp;&nbsp;定 ">     </td>
   </tr>
  </form>
</table>
<%
	 Else
		FoundErr=True
		Errmsg=ErrMsg &  "<br>无任何记录！"
	 End If
	 RsLead.Close
	 Set RsLead=Nothing
  End If
  connLead.close
  set connlead=nothing
End If
If FoundErr=True Then
  Call Show_Err()
End If
End Sub


Sub LeadInData()
	Dim LeadInMdb
	LeadInMdb=trim(request.form("LeadInMdb"))
	TempID=trim(request.form("TempID"))
	If LeadInMdb="" Then
		FoundErr=True
		ErrMsg="<br><li>数据库地址不能为空！</li>"
	End If
	If TempID="" Then
		FoundErr=True
		ErrMsg= ErrMsg & "<br><li>请选择项目！</li>"
	Else
		TempID=Replace(TempID," ","")
	End If    
	If FoundErr<>True Then  
		dim connstrLead,connLead,RsLead,SqlLead,RsF,SqlF,TempIDTemp
		Set connLead = Server.CreateObject("ADODB.Connection")
		connstrLead="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(LeadInMdb)
		connLead.Open connstrLead
		If Err Then
			err.Clear
			ConnLead.Close
			Set ConnLead = Nothing
			FoundErr=True
			ErrMsg= ErrMsg & "<br><li>数据库连接出错，请确认数据库是否存在。</li>"
		End If
		If FoundErr<>True Then
			For t=0 to ubound(split(TempID,","))
				Set Rspn=ConnLead.execute("select TemplateProjectName,TemplateProjectID from JOB_TemplateProject where TemplateProjectID="&split(TempID,",")(t)&"")
				If Not Rspn.Eof then
				ProjectID=Rspn("TemplateProjectID")
				ProjectName=Rspn("TemplateProjectName")
				End If
				Set Rspn=Nothing
				'判断是否存在同名的方案
				Set Rspn=server.createobject("adodb.recordset")         
				Sqlpn="select TemplateProjectID from JOB_TemplateProject where TemplateProjectName='"&ProjectName&"'"         
				Rspn.open Sqlpn,Conn,1,3
				
				If Rspn.Eof And Rspn.Bof Then
					dim oldproid,newtpname,newproid
					'不存在同名开始导入方案
					Set RsLead=server.createobject("adodb.recordset")     
					SqlLead="select TemplateProjectID,TemplateProjectName,TemplateDir,Intro,IsDefault,oldproid from JOB_TemplateProject where TemplateProjectID="&ProjectID&" order by TemplateProjectID desc"         
					RsLead.open SqlLead,ConnLead,1,1
					If Not RsLead.Eof then
						'原来导出时的方案编号和导进的方案名称
						oldproid=RsLead("oldproid")
						newtpname=RsLead("TemplateProjectName")
						'打开数据库
						Set Rs=server.createobject("adodb.recordset")         
						Sql="select * from JOB_TemplateProject"     
						Rs.open Sql,Conn,1,3
						Rs.AddNew
						Rs("TemplateProjectName")=RsLead("TemplateProjectName")
						Rs("TemplateDir")=RsLead("TemplateDir")
						Rs("Intro")=RsLead("Intro")
						Rs("IsDefault")=FR_HR_False
						Rs.Update
					End If
					Rs.Close
					Set Rs=Nothing
					RsLead.Close
					Set RsLead=Nothing
						
					'读出新导入方案的编号
					Set RsNew=Server.CreateObject("ADODB.RecordSet")
					SqlNew="select TemplateProjectID from JOB_TemplateProject where TemplateProjectName='"&newtpname&"'"
					RsNew.open SqlNew,conn,1,1
					if not (RsNew.eof and RsNew.bof) then
						newproid=RsNew("TemplateProjectID")
					else
						response.Write("导入方案失败!")
						response.End()
					end if	
					
					'导入样式表   
					Set RsLead=server.createobject("adodb.recordset")
					SqlLead="select SkinName,Skin_CSS,IsDefaultInProject,ProjectName,filename,imgpath,IsDefault from JOB_Skin where ProjectName='"&ProjectName&"' order by SkinID desc"         
					RsLead.open SqlLead,ConnLead,1,1
					If Not RsLead.Eof then
					Do while Not RsLead.Eof
						'打开数据库
						Set Rs=server.createobject("adodb.recordset")         
						Sql="select * from JOB_Skin"         
						Rs.open Sql,Conn,1,3
						Rs.AddNew
						Rs("SkinName")=RsLead("SkinName")
						Rs("Skin_CSS")=RsLead("Skin_CSS")
						Rs("IsDefaultInProject")=FR_HR_False
						Rs("ProjectName")=ProjectName
						Rs("filename")=RsLead("filename")
						Rs("imgpath")=RsLead("imgpath")
						Rs("IsDefault")=RsLead("IsDefault")
						Rs.Update
						Rs.Close
						Set Rs=Nothing
					RsLead.MoveNext
					Loop
					End If
					RsLead.Close
					Set RsLead=Nothing
					
					'导入模板
					Set RsLead=server.createobject("adodb.recordset")     
					SqlLead="select ChannelID,TemplateName,TemplateContent,IsDefault,ProjectName,IsDefaultInProject,Deleted,typeid from JOB_Template where ProjectName='"&ProjectName&"' order by TemplateID desc"         
					RsLead.open SqlLead,ConnLead,1,1
					If Not RsLead.Eof then
						Do while Not RsLead.Eof
							'打开数据库
							Set Rs=server.createobject("adodb.recordset")         
							Sql="select * from JOB_Template"         
							Rs.open Sql,Conn,1,3
							Rs.AddNew
							Rs("ChannelID")=RsLead("ChannelID")
							Rs("TemplateName")=RsLead("TemplateName")
							Rs("TemplateContent")=RsLead("TemplateContent")
							Rs("IsDefault")=RsLead("IsDefault")
							Rs("ProjectName")=ProjectName
							Rs("IsDefaultInProject")=FR_HR_False
							Rs("Deleted")=RsLead("Deleted")
							Rs("typeid")=RsLead("typeid")
							Rs.Update
							Rs.Close
							Set Rs=Nothing
						RsLead.MoveNext
						Loop
					End If
					RsLead.Close
					Set RsLead=Nothing
					
					'导入标签
					'先读取要导入的方案标签中的系统标签，循环判断是否在库中已经存在，存在则不导入
					Set RsLead=server.createobject("adodb.recordset")     
					SqlLead="select LabelName,LabelType,LabelIntro,LabelContent,Labeladddate,Labeleditdate,Labelorder,projectid from JOB_Label where projectid="&oldproid&" and LabelType<5 order by LabelID desc"					      
					RsLead.open SqlLead,ConnLead,1,1
					If Not RsLead.Eof then
						Do while Not RsLead.Eof
							'打开数据库
							Set Rs=server.createobject("adodb.recordset")         
							Sql="select * from JOB_Label where LabelName='"&RsLead("LabelName")&"'"         
							Rs.open Sql,Conn,1,3
							'如果同名的系统标签不存在则添加
							if Rs.eof and Rs.bof then
								Rs.AddNew							
								Rs("LabelName")=RsLead("LabelName")
								Rs("LabelType")=RsLead("LabelType")
								Rs("LabelIntro")=RsLead("LabelIntro")
								Rs("LabelContent")=RsLead("LabelContent")
								Rs("Labeladddate")=RsLead("Labeladddate")
								Rs("Labeleditdate")=RsLead("Labeleditdate")
								Rs("Labelorder")=RsLead("Labelorder")
								Rs("projectid")=newproid								
								Rs.Update
							end if
							Rs.Close
							Set Rs=Nothing
						RsLead.MoveNext
						Loop
					End If
					RsLead.Close
					Set RsLead=Nothing
					
					'导入不是系统标签的标签
					Set RsLead=server.createobject("adodb.recordset")     
					SqlLead="select LabelName,LabelType,LabelIntro,LabelContent,Labeladddate,Labeleditdate,Labelorder,projectid from JOB_Label where projectid="&oldproid&" and LabelType>4 order by LabelID desc"					      
					RsLead.open SqlLead,ConnLead,1,1
					If Not RsLead.Eof then
						Do while Not RsLead.Eof
							'打开数据库
							Set Rs=server.createobject("adodb.recordset")         
							Sql="select * from JOB_Label"         
							Rs.open Sql,Conn,1,3
							Rs.AddNew								
							Rs("LabelName")=RsLead("LabelName")
							Rs("LabelType")=RsLead("LabelType")
							Rs("LabelIntro")=RsLead("LabelIntro")
							Rs("LabelContent")=RsLead("LabelContent")
							Rs("Labeladddate")=RsLead("Labeladddate")
							Rs("Labeleditdate")=RsLead("Labeleditdate")
							Rs("Labelorder")=RsLead("Labelorder")
							Rs("projectid")=newproid								
							Rs.Update
							Rs.Close
							Set Rs=Nothing
						RsLead.MoveNext
						Loop
					End If
					RsLead.Close
					Set RsLead=Nothing
					
					'导入广告种类表
					Set RsLead=server.createobject("adodb.recordset")     
					SqlLead="select adplace_name,oldadplaceid from JOB_Adplace where projectid="&oldproid&" order by adplace_id desc"					      
					RsLead.open SqlLead,ConnLead,1,1
					If Not RsLead.Eof then
						Do while Not RsLead.Eof
							'打开数据库
							'读出原来保存的广告位种类的自动编号以便导入时关联
							oldadplaceid=RsLead("oldadplaceid")
							oldadplacename=RsLead("adplace_name")
							Set Rs=server.createobject("adodb.recordset")         
							Sql="select * from JOB_Adplace"         
							Rs.open Sql,Conn,1,3
							Rs.AddNew								
							Rs("adplace_name")=RsLead("adplace_name")
							Rs("projectid")=newproid								
							Rs.Update
							Rs.Close
							Set Rs=Nothing
							
							'读出新添加的广告位种类的新编号
							Set Rsadplacenew=Server.CreateObject("ADODB.RecordSet")
							Sqladplacenew="Select adplace_id from JOB_Adplace where adplace_name='"&oldadplacename&"' and projectid="&newproid&""
							Rsadplacenew.open Sqladplacenew,conn,1,1
							if not (Rsadplacenew.eof and Rsadplacenew.bof) then
							newadplaceid=Rsadplacenew("adplace_id")
							else
							Response.Write("导入方案失败")
							Response.End()
							end if
							
							'读出该广告种类下的广告位
							Set RsLead1=server.createobject("adodb.recordset")     
							SqlLead1="select Adsplace_name,Adsplace_placeid,Adsplace_priceid,Adsplace_price,Adsplace_unit,Adsplace_row,Adsplace_width,projectid,oldadsplaceid from JOB_Adsplace where projectid="&oldproid&" and Adsplace_placeid="&oldadplaceid&" order by adsplace_id desc"
							RsLead1.open SqlLead1,ConnLead,1,1
							If Not RsLead1.Eof then
								Do while Not RsLead1.Eof
									'读出原来保存的广告位的自动编号以便导入时关联
									oldadsplaceid=RsLead1("oldadsplaceid")
									oldadsplacename=RsLead1("Adsplace_name")
									Set Rs1=server.createobject("adodb.recordset")         
									Sql1="select * from JOB_Adsplace"         
									Rs1.open Sql1,Conn,1,3
									Rs1.AddNew								
									Rs1("Adsplace_name")=RsLead1("Adsplace_name")
									Rs1("Adsplace_placeid")=newadplaceid	
									Rs1("Adsplace_priceid")=RsLead1("Adsplace_priceid")
									Rs1("Adsplace_price")=RsLead1("Adsplace_price")
									Rs1("Adsplace_unit")=RsLead1("Adsplace_unit")
									Rs1("Adsplace_row")=RsLead1("Adsplace_row")
									Rs1("Adsplace_width")=RsLead1("Adsplace_width")
									Rs1("projectid")=newproid																
									Rs1.Update
									Rs1.Close
									Set Rs1=Nothing	
									
									'读出新广告位的编号	
									Set Rsadsplacenew=Server.CreateObject("ADODB.RecordSet")
									Sqladsplacenew="Select Adsplace_id from JOB_Adsplace where adsplace_name='"&oldadsplacename&"' and projectid="&newproid&" and Adsplace_placeid="&newadplaceid&""
									Rsadsplacenew.open Sqladsplacenew,conn,1,1
									if not (Rsadsplacenew.eof and Rsadsplacenew.bof) then
									newadsplaceid=Rsadsplacenew("adsplace_id")
									else
									Response.Write("导入方案失败")
									Response.End()
									end if
									
									'添加该广告位种类和广告位的广告导进系统									
									Set RsLead2=server.createobject("adodb.recordset")     
									SqlLead2="select * from JOB_Ad where projectid="&oldproid&" and Ad_placeid="&oldadplaceid&" and Ad_priceid="&oldadsplaceid&" order by Ad_id desc"
									RsLead2.open SqlLead2,ConnLead,1,1
									If Not RsLead2.Eof then
										Do while Not RsLead2.Eof										
											Set Rs2=server.createobject("adodb.recordset")         
											Sql2="select * from JOB_Ad"         
											Rs2.open Sql2,Conn,1,3
											Rs2.AddNew								
											Rs2("Ad_sitename")=RsLead2("Ad_sitename")
											Rs2("Ad_siteurl")=RsLead2("Ad_siteurl")
											Rs2("Ad_contactman")=RsLead2("Ad_contactman")
											Rs2("Ad_tel")=RsLead2("Ad_tel")
											Rs2("Ad_width")=RsLead2("Ad_width")
											Rs2("Ad_pic")=RsLead2("Ad_pic")
											Rs2("Ad_target")=RsLead2("Ad_target")
											Rs2("Ad_type")=RsLead2("Ad_type")
											Rs2("Ad_act")=RsLead2("Ad_act")
											Rs2("Ad_click")=RsLead2("Ad_click")
											Rs2("Ad_show")=RsLead2("Ad_show")
											Rs2("Ad_enddate")=RsLead2("Ad_enddate")
											Rs2("Ad_clicks")=RsLead2("Ad_clicks")
											Rs2("Ad_shows")=RsLead2("Ad_shows")											
											Rs2("Ad_stop")=RsLead2("Ad_stop")
											Rs2("Ad_other")=RsLead2("Ad_other")
											Rs2("Ad_addtime")=RsLead2("Ad_addtime")
											Rs2("Ad_showtime")=RsLead2("Ad_showtime")
											Rs2("Ad_lose")=RsLead2("Ad_lose")											
											Rs2("Ad_placeid")=newadplaceid	
											Rs2("Ad_priceid")=newadsplaceid
											Rs2("projectid")=newproid																
											Rs2.Update
											Rs2.Close
											Set Rs2=Nothing																		
										RsLead2.MoveNext
										Loop
									End If
									RsLead2.Close
									Set RsLead2=Nothing					
									
																		
								RsLead1.MoveNext
								Loop
							End If
							RsLead1.Close
							Set RsLead1=Nothing							
						RsLead.MoveNext
						Loop
					End If
				RsLead.Close
				Set RsLead=Nothing
				else
					 FoundErr=True
     				 ErrMsg="<br><li>相同的方案已经存在!</li>"					
				End If				
			Next
		End If
		connlead.close
		set connlead=nothing
	End If
	If FoundErr<>True Then
		ErrMsg="<br>数据导入成功"
		Call Show_Suc(ErrMsg,"Admin_TempDatabase.asp")
	Else
		Call Show_Err()
	End If
End Sub
%>