<!--#include file="../Include/Const.Asp" -->
<!--#include file="../Include/ConnSiteData.Asp" -->
<!--#include file="../CheckAdmin.Asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../Images/Admin_style.css">
<script language="javascript" src="../JavaScript/Admin.js"></script>
<script language="javascript" src="../JavaScript/select_date.js"></script>
<script type="text/javascript">
//==========================================


</script>

<%
'获取参数
dim Realname
Types=Clng(Request.QueryString("Type"))

Select Case Types
	Case 1
		Call FileAdd() '执行删除联系人
	Case Else
	    Call showu() '
End Select
%>
<%
'==============================
'函 数 名：showu
'作    用：初始
'参    数：
'==============================
Sub showu()
%>
<br />
<table class="tableBorder" width="95%" border="0" align="center" cellpadding="5" cellspacing="1">
    <tr>
      <th height="22" sytle="line-height:150%">&nbsp;</th>
    </tr>
        <tr>
            <td height="30" colspan="6" style="padding-bottom:5px;">
     <form name="AddFile" id="AddFile" onsubmit="return false;">
           
&nbsp;&nbsp;&nbsp;&nbsp;联系人名单导入&nbsp;<input name="XlsFile" value="" type="hidden" id="XlsFile" />&nbsp;<iframe frameborder="0" width="290" height="30" scrolling="No" id="XlsFiles" name="XlsFiles" src="XlsUpLoad.asp?Form=AddFile&Input=XlsFile"></iframe>&nbsp;<input type="button" value="导入联系人" class="Button2" onclick="if(document.all.XlsFile.value!=''){window.location.href='?Type=1&XlsFile='+document.all.XlsFile.value;}else{alert('请先点浏览选择文件，再点上传，上传导入文件！');}" />
</form>
&nbsp;&nbsp; <a href="导入例子v1.csv" target="_blank">下载导入格式示例</a>
（<font color="#FF0000">注：请严格按格式填写，不得改变表格样式</font>）
            </td>
        </tr>

	<tr>
      
    </tr>
    	
    <tr>
      <td class="forumRowHighlight" align="center">&nbsp;</td>
    </tr>
</table>
<%
End Sub
%>


<%
'==============================
'函 数 名：FileAdd
'作    用：文件导入联系人
'参    数：
'==============================
Sub FileAdd()
    Realname=genjinText(session("UserName"))
	On Error Resume Next
	Dim Rs2,sql,XlsFile,Conn3,Sqlstr3
	XlsFile=Trim(Request.QueryString("XlsFile"))
	If XlsFile="" Then
		Response.Write("<div style=""margin:30px;""><a href=""?"">请先上传导入文件</a></div>")
		Response.End()
	End If
	Response.Write("<div style=""margin:30px;line-height:22px;"">")
	Response.Write("导入过程开始<br />")
	Response.Flush()
	Response.Clear()
	Set Rs2=Server.Createobject("Adodb.RecordSet")
	Set Conn3=CreateObject("ADODB.Connection")     
	Conn3.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended properties=Excel 8.0;Data Source="&Server.MapPath(""&XlsFile&"")
	Set Rs=Server.Createobject("Adodb.RecordSet")
	Sqlstr3="Select * From [联系人$]"
	Rs.Open Sqlstr3,Conn3,1,3
	If Err Then
		Response.Write("<span style=""color:red;"">未找到表名为联系人的Excel工作簿！</span><br />")
		Response.Write("<a href=""?"">返回</a></div>")
		Err.Clear
		Response.End()
	End If
	Application.Lock()
	While Not Rs.Eof
		If Trim(Rs(0))<>"" Then
			Sqlstr="Select * from Zqj_Contactperson Where Cp_name='"&trim(Rs(0))&"' and Memname='"&session("UserName")&"'"
			Rs2.Open Sqlstr,Conn,1,3
			If Rs2.Eof Then
				Rs2.AddNew()
				Rs2("Cp_name")=trim(Rs(0))
				   if Trim(Rs(2))="" then
				      Rs2("Co_ID")=0
				   else
				      Rs2("Co_ID")=getCo_name(trim(Rs(2)))
				   end if
				Rs2("Cp_position")=Rs(3)
				Rs2("Cp_tel")=Rs(4)
				Rs2("Cp_mobile")=Rs(5)
				Rs2("Cp_email")=Rs(6)
				Rs2("Cp_QQ")=Rs(7)
				Rs2("Cp_msn")=Rs(8)
				Rs2("Cp_homepage")=Rs(9)
				Rs2("Cp_address")=Rs(10)
				Rs2("Cp_zipcode")=Rs(11)
				Rs2("Cp_addtime")=now()
				Rs2("Cp_updatime")=now()
				Rs2("Memname")=session("UserName")
				Rs2("Realname")=Realname
				Rs2.Update()
				Response.Write("<span style=""color:green;"">"&server.HTMLEncode(Rs(0))&"成功导入！</span><br />")
				Response.Flush()
				Response.Clear()
			Else
				Response.Write("<span style=""color:red;"">"&server.HTMLEncode(Rs(0))&"已经存在！</span><br />")
				Response.Flush()
				Response.Clear()
			End If
			Rs2.Close
		End If
		Rs.MoveNext
	Wend
	Application.UnLock()
	Rs.Close
	Set Rs2=Nothing
	Conn3.Close
	Set Conn3=Nothing
	
	Response.Write("导入过程完成<br />")
	Response.Write("<a href=""My_people_KehuList.Asp"">返回联系人列表</a></div>")
End Sub

Function genjinText(MemName)
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "Select * From Zqj_Members where MemName='"&MemName&"'"
    rs.Open sql, conn, 1, 1
	if rs.bof and rs.eof then
	genjinText=""
	else
    genjinText = rs("RealName")
	end if
    rs.Close
    Set rs = Nothing
End Function

Function getCo_name(companyName)
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
	if trim(companyName)<>"" then
    sql = "Select * From Zqj_Company where Co_name='"&trim(companyName)&"' and MemName='"&session("UserName")&"'"
    rs.Open sql, conn, 1, 3
	if rs.bof and rs.eof then
	   '----公司不存在时创建公司记录开始----------------------------
	       rs.addnew
		   rs("Co_name")=trim(companyName)
		   rs("MemName") = session("UserName")
           rs("RealName") = Realname
		   rs("Co_AddTime")=now()
		   rs("Co_Updatime")=now()
		   getCo_name=rs.Fields("Co_ID")
	   '----公司不存在时创建公司记录结束----------------------------
	else
    getCo_name = rs("Co_ID")
	end if
	rs.update
	end if
    rs.Close
    Set rs = Nothing
End Function
%>