<html xmlns="http://www.w3.org/1999/xhtml">
<!--#include file="../Inc/Conn.asp" -->
<!--#include file="../Inc/SK.Session.asp" -->
<!--#include file="../Inc/SK.Funtion.asp" -->
<%if Not (Getconfig("SK_Client")="0" AND (Session("Manager")="1" OR (JudgePopedomTF(Session("UserName"),"SK200000000") AND JudgePopedomTF(Session("UserName"),"SK200000104")))) then Call ReturnError()%>
<%
'导出客户信息到Excel开始
Response.Buffer = True 
Response.ContentType = "application/vnd.ms-excel" 
SaveFilename=replace(replace(replace(now,":","")," ",""),"/","")
Thead="Client_"
Response.AddHeader "content-disposition", "inline; filename = "&Thead&SaveFilename&".xls"

Response.Write("<table width=""100%"" align=""center"" cellpadding=""3"" cellspacing=""1"" border=""1"">"&VBCrlf)
Response.Write("<tr bgcolor=""#E8E8E8"">"&VBCrlf)
Response.Write("<td width=""4%""><b>一级区域</b></td>")
Response.Write("<td width=""12%""><b>二级区域</b></td>")
Response.Write("<td width=""9%""><b>三级区域</b></td>")
Response.Write("<td width=""9%""><b>类型</b></td>")
Response.Write("<td width=""9%""><b>客户编号</b></td>")
Response.Write("<td width=""9%""><b>客户名称</b></td>")
Response.Write("<td width=""9%""><b>其他名称</b></td>")
Response.Write("<td width=""6%""><b>客户简介</b></td>")
Response.Write("<td width=""6%""><b>合作现状</b></td>")
Response.Write("<td width=""6%""><b>合作前景</b></td>")
Response.Write("<td width=""6%""><b>跟进策略</b></td>")
set RsOptions=server.createobject("adodb.recordset")
sqlOptions="SELECT * from SK_ClientOptions where SK_Di=0 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsOptions.Open sqlOptions,conn,1,1
for Optionsi=1 to RsOptions.recordCount
Response.write"<td width=""6%""><b>"&RsOptions("SK_Title")&"</b></td>"
RsOptions.movenext 
next
RsOptions.close
set RsOptions=Nothing
set RsFields=server.createobject("adodb.recordset")
sqlFields="SELECT * from SK_ClientFields where SK_Di=0 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsFields.Open sqlFields,conn,1,1
for Fieldsi=1 to RsFields.recordCount
Response.write"<td width=""6%""><b>"&RsFields("SK_Title")&"</b></td>"
RsFields.movenext 
next 
RsFields.close
set RsFields=Nothing
Response.Write("</tr>"&VBCrlf)

if F("id")="" then
Set Rs=Server.CreateObject("ADODB.Recordset")
if Session("Manager")=1 or Session("Manager")=2 then
sql="select * from SK_Client where SK_Del=0"
elseif Session("Manager")=3 then
sql="select * from SK_Client INNER JOIN SK_SystemUsers ON SK_Client.SK_SalesID=SK_SystemUsers.UsersID where SK_Client.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&""
elseif Session("Manager")=4 then
sql="select * from SK_Client INNER JOIN SK_SystemUsers ON SK_Client.SK_SalesID=SK_SystemUsers.UsersID where SK_Client.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&""
elseif Session("Manager")=5 then
sql="select * from SK_Client INNER JOIN SK_SystemUsers ON SK_Client.SK_SalesID=SK_SystemUsers.UsersID where SK_Client.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_SystemUsers.SK_Dept3="&Session("Dept3")&""
elseif Session("Manager")=6 then
sql="select * from SK_Client where SK_Del=0 and SK_SalesID="&Session("UID")&""
end if
Rs.Open Sql,Conn,1,1
if rs.bof and rs.eof then Call ReturnError4()
K=0
while not Rs.eof
K=K+1
Response.Write("<tr bgcolor=FFFFFF>"&VBCrlf)
set RsDept1=server.createobject("adodb.recordset")
RsDept1.open "SELECT * from SK_SystemArea where Areaid="&Rs("SK_AreaID")&"",conn,1,1
set RsDept2=server.createobject("adodb.recordset")
RsDept2.open "SELECT * from SK_SystemArea where AreaID="&RsDept1("ParentID")&"",conn,1,1
set RsDept3=server.createobject("adodb.recordset")
RsDept3.open "SELECT * from SK_SystemArea where AreaID="&RsDept2("ParentID")&"",conn,1,1

if RsDept3.bof and RsDept3.eof then
Response.Write("<td align=left></td>")
else
Response.Write("<td align=left>"&RsDept3("AreaName")&"</td>")
end if

if RsDept2.bof and RsDept2.eof then
Response.Write("<td align=left></td>")
else
Response.Write("<td align=left>"&RsDept2("AreaName")&"</td>")
end if

if RsDept1.bof and RsDept1.eof then
Response.Write("<td align=left></td>")
else
Response.Write("<td align=left>"&RsDept1("AreaName")&"</td>")
end if

RsDept1.close
set RsDept1=Nothing
RsDept2.close
set RsDept2=Nothing
RsDept3.close
set RsDept3=Nothing

if Rs("SK_Di")=0 then
Response.Write("<td align=left>单位客户</td>")
else
Response.Write("<td align=left>个人客户</td>")
end if
Response.Write("<td align=left>"&Rs("SK_No")&"</td>")
Response.Write("<td align=left>"&Rs("SK_Wname")&"</td>")
if Rs("SK_Jname")<>"" then
Response.Write("<td align=left>"&Rs("SK_Jname")&"</td>")
else
Response.Write("<td align=left></td>")
end if

if Rs("SK_Content")<>"" then
Response.Write("<td align=left>"&Rs("SK_Content")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Status")<>"" then
Response.Write("<td align=left>"&Rs("SK_Status")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Prospect")<>"" then
Response.Write("<td align=left>"&Rs("SK_Prospect")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Plot")<>"" then
Response.Write("<td align=left>"&Rs("SK_Plot")&"</td>")
else
Response.Write("<td align=left></td>")
end if

set RsOptions=server.createobject("adodb.recordset")
sqlOptions="SELECT * from SK_ClientOptions where SK_Di=0 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsOptions.Open sqlOptions,conn,1,1
for Optionsi=1 to RsOptions.recordCount
Set rsOptionsDetail=Server.CreateObject("ADODB.RecordSet") 
sqlOptionsDetail="SELECT * from SK_ClientOptionsDetail where SK_OptionsID="&RsOptions("FieldID")&" and OptionsDetailID="&rs(""&RsOptions("SK_FieldName")&"")&"" 
rsOptionsDetail.Open sqlOptionsDetail,conn,1,1
if rsOptionsDetail.bof and rsOptionsDetail.eof then
Response.Write("<td align=left></td>")
else
Response.write"<td align=left>"&rsOptionsDetail("SK_OName")&"</td>"
end if
rsOptionsDetail.close
set rsOptionsDetail=Nothing
RsOptions.movenext 
next
RsOptions.close
set RsOptions=Nothing

set RsFields=server.createobject("adodb.recordset")
sqlFields="SELECT * from SK_ClientFields where SK_Di=0 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsFields.Open sqlFields,conn,1,1
for Fieldsi=1 to RsFields.recordCount
if Rs(""&RsFields("SK_FieldName")&"")<>"" then
Response.write"<td align=left>"&Rs(""&RsFields("SK_FieldName")&"")&"</td>"
else
Response.Write("<td align=left></td>")
end if
RsFields.movenext 
next 
RsFields.close
set RsFields=Nothing

Response.Write("</tr>"&VBCrlf)
rs.movenext
wend

elseif F("id")<>"" then '当选择有ID时输出数据开始
str2=split(F("id"),",")
for i=0 to ubound(str2)
Set Rs = Server.CreateObject("ADODB.Recordset")
if Session("Manager")=1 or Session("Manager")=2 then
sql="select * from SK_Client where SK_Del=0 and ClientID="&trim(str2(i))
elseif Session("Manager")=3 then
sql="select * from SK_Client INNER JOIN SK_SystemUsers ON SK_Client.SK_SalesID=SK_SystemUsers.UsersID where SK_Client.SK_Del=0 and  SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_Client.ClientID="&trim(str2(i))
elseif Session("Manager")=4 then
sql="select * from SK_Client INNER JOIN SK_SystemUsers ON SK_Client.SK_SalesID=SK_SystemUsers.UsersID where SK_Client.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_Client.ClientID="&trim(str2(i))
elseif Session("Manager")=5 then
sql="select * from SK_Client INNER JOIN SK_SystemUsers ON SK_Client.SK_SalesID=SK_SystemUsers.UsersID where SK_Client.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_SystemUsers.SK_Dept3="&Session("Dept3")&" and SK_Client.ClientID="&trim(str2(i))
elseif Session("Manager")=6 then
sql="select * from SK_Client where SK_Del=0 and SK_SalesID="&Session("UID")&" and ClientID="&trim(str2(i))
end if
RS.Open Sql,Conn,1,1

Response.Write("<tr bgcolor=FFFFFF>"&VBCrlf)
set RsDept1=server.createobject("adodb.recordset")
RsDept1.open "SELECT * from SK_SystemArea where Areaid="&Rs("SK_AreaID")&"",conn,1,1
set RsDept2=server.createobject("adodb.recordset")
RsDept2.open "SELECT * from SK_SystemArea where AreaID="&RsDept1("ParentID")&"",conn,1,1
set RsDept3=server.createobject("adodb.recordset")
RsDept3.open "SELECT * from SK_SystemArea where AreaID="&RsDept2("ParentID")&"",conn,1,1

if RsDept3.bof and RsDept3.eof then
Response.Write("<td align=left></td>")
else
Response.Write("<td align=left>"&RsDept3("AreaName")&"</td>")
end if

if RsDept2.bof and RsDept2.eof then
Response.Write("<td align=left></td>")
else
Response.Write("<td align=left>"&RsDept2("AreaName")&"</td>")
end if

if RsDept1.bof and RsDept1.eof then
Response.Write("<td align=left></td>")
else
Response.Write("<td align=left>"&RsDept1("AreaName")&"</td>")
end if

RsDept1.close
set RsDept1=Nothing
RsDept2.close
set RsDept2=Nothing
RsDept3.close
set RsDept3=Nothing

if Rs("SK_Di")=0 then
Response.Write("<td align=left>单位客户</td>")
else
Response.Write("<td align=left>个人客户</td>")
end if
Response.Write("<td align=left>"&Rs("SK_No")&"</td>")
Response.Write("<td align=left>"&Rs("SK_Wname")&"</td>")
if Rs("SK_Jname")<>"" then
Response.Write("<td align=left>"&Rs("SK_Jname")&"</td>")
else
Response.Write("<td align=left></td>")
end if

if Rs("SK_Content")<>"" then
Response.Write("<td align=left>"&Rs("SK_Content")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Status")<>"" then
Response.Write("<td align=left>"&Rs("SK_Status")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Prospect")<>"" then
Response.Write("<td align=left>"&Rs("SK_Prospect")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Plot")<>"" then
Response.Write("<td align=left>"&Rs("SK_Plot")&"</td>")
else
Response.Write("<td align=left></td>")
end if

set RsOptions=server.createobject("adodb.recordset")
sqlOptions="SELECT * from SK_ClientOptions where SK_Di=0 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsOptions.Open sqlOptions,conn,1,1
for Optionsi=1 to RsOptions.recordCount
Set rsOptionsDetail=Server.CreateObject("ADODB.RecordSet") 
sqlOptionsDetail="SELECT * from SK_ClientOptionsDetail where SK_OptionsID="&RsOptions("FieldID")&" and OptionsDetailID="&rs(""&RsOptions("SK_FieldName")&"")&"" 
rsOptionsDetail.Open sqlOptionsDetail,conn,1,1
if rsOptionsDetail.bof and rsOptionsDetail.eof then
Response.Write("<td align=left></td>")
else
Response.write"<td align=left>"&rsOptionsDetail("SK_OName")&"</td>"
end if
rsOptionsDetail.close
set rsOptionsDetail=Nothing
RsOptions.movenext 
next
RsOptions.close
set RsOptions=Nothing

set RsFields=server.createobject("adodb.recordset")
sqlFields="SELECT * from SK_ClientFields where SK_Di=0 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsFields.Open sqlFields,conn,1,1
for Fieldsi=1 to RsFields.recordCount
if Rs(""&RsFields("SK_FieldName")&"")<>"" then
Response.write"<td align=left>"&Rs(""&RsFields("SK_FieldName")&"")&"</td>"
else
Response.Write("<td align=left></td>")
end if
RsFields.movenext 
next 
RsFields.close
set RsFields=Nothing

Response.Write("</tr>"&VBCrlf)
next
end if '当选择有ID时输出数据结束

Response.Write("</table>")
Call CloseDB()
'导出客户到Excel结束
%>