<!--#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 language="javascript">
var tID=0;
function ShowTabs(ID){
  if(ID!=tID){
    TabTitle[tID].className="title5";
    TabTitle[ID].className="title6";
    Tabs[tID].style.display="none";
    Tabs[ID].style.display="";
    tID=ID;
  }
}
</script>
<%
'If InStr(session("GroupPurview"), "|2,") = 0 Then
    'response.Write ("<br /><br /><div align=""center""><font style=""color:red; font-size:9pt; "")>您没有管理该模块的权限！</font></div>")
    'response.End
'End If
Dim Result
Result = request.QueryString("Result")
Dim ID,showid,mMemName, mRealName,mCp_name,mCo_ID,mCp_position,mCp_tel,mCp_mobile,mCp_code,mCp_education,mCp_msn
Dim mCp_email,mCp_QQ,mCp_HomePage,mCp_Address,mCp_ZipCode,mCp_AddTime,mCp_Updatime,mCp_Working
Dim kattribute1,kCompany
ID = request.QueryString("ID")
showid=request.QueryString("showid")
if Result = "Add" then
  kCompany=trim(request.QueryString("Company"))
end if
 response.Write "<script language='javascript' for='window' event='onload'>ShowTabs("&showid&");</script>"
  '生成联系人编号
 Y=year(now())
 M=month(now())
 D=Day(now())
 H=hour(now())
 mi=minute(now())
 s=second(now())
 if M<10 then M="0"&M
 if D<10 then D="0"&D
 if H<10 then H="0"&H
 if mi<10 then mi="0"&mi
 if s<10 then s="0"&s
 '生成1-100随机数 
 Randomize() 
 n=Int((100-1+1)*Rnd(now())+1)
 mCp_code="P"&Y&M&D&H&mi&s&n
 '生成联系人编号结束
Call MyKehuEdit()
%>
<br />
<table class="tableBorder" width="95%" border="0" align="center" cellpadding="5" cellspacing="1">
  <form name="editForm" method="post" action="?Action=SaveEdit&Result=<%=Result%>&ID=<%=ID%>&showid=<%=showid%>" onSubmit="return CheckpeopleKehuEdit()">
    <tr>
      <th height="22" sytle="line-height:150%">【<%If Result = "Add" then%>添加<%ElseIf Result = "Modify" then%>修改<%End If%>联系人<%if Result = "Add" Then%> <font color="#999999">或者</font> <a href="My_Companies_KehuEdit.Asp?Result=Add&showid=0"><font color="#4579b9">添加公司</font></a>
      <%end if%>】</th>
    </tr>
	<tr>
      <td class="forumRowHighlight">
	  
	  <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
        <tr align="center">
            <td id="TabTitle" class="title6" onclick="ShowTabs(0)">基本信息</td>
			<td id="TabTitle" class="title5" onclick="ShowTabs(1)">其它</td>
            
            
           
            <td>&nbsp;</td>
        </tr>
</table>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="1" class="border"><tr class="tdbg"><td valign="top">
  <table width="100%" align="center" cellpadding="2" cellspacing="1">
  <tbody id="Tabs" style="display:">
  <tr>
      <td width="20%" align="right" class="forumRow"></td>
      <td width="80%" class="forumRowHighlight"><input name="MemName" type="hidden" id="MemName" style="width: 120;background-color:#EBF2F9" value="<%=session("UserName")%>" maxlength="16" <%response.write ("readonly")%>>
	  <input name="RealName" type="hidden" id="RealName" style="width: 120;background-color:#EBF2F9" value="<%=genjinText(session("UserName"))%>" maxlength="16" <%response.write ("readonly")%>>
      <!--联系人code-->
      <input name="Cp_code" type="hidden" id="Cp_code" style="width: 120" value="<%=mCp_code%>" maxlength="18" readonly="readonly">
      </td>
    </tr>
	<tr>
      <td align="right" class="forumRow">姓 名：</td>
      <td class="forumRowHighlight"><input name="Cp_name" type="text" id="Cp_name" style="width:120" value="<%=mCp_name%>" maxlength="50">
      <font class="redy">*</font> 
	  &nbsp;</td>
	</tr>
    <tr>
      <td align="right" class="forumRow">学 历：</td>
      <td class="forumRowHighlight"><input name="Cp_education" type="text" id="Cp_education" style="width: 120" value="<%=mCp_education%>" maxlength="50"></td>
    </tr>
	<tr>
      <td align="right" class="forumRow">职 位：</td>
      <td class="forumRowHighlight"><input name="Cp_position" type="text" id="Cp_position" style="width: 120" value="<%=mCp_position%>" maxlength="50"></td>
    </tr>
	<tr>
      <td align="right" class="forumRow">公 司：</td>
      <td class="forumRowHighlight"><input name="Co_name" type="text" id="Co_name" style="width: 280" value="<%=kCompany%>" maxlength="249"></td>
    </tr>
        <tr>
      <td align="right" class="forumRow">电 话：</td>
      <td class="forumRowHighlight"><input name="Cp_tel" type="text" id="Cp_tel" style="width: 120" value="<%=mCp_tel%>" maxlength="50"></td>
    </tr>
	<tr>
      <td align="right" class="forumRow">手机号码：</td>
      <td class="forumRowHighlight"><input name="Cp_mobile" type="text" id="Cp_mobile" style="width: 120" value="<%=mCp_mobile%>" maxlength="16"></td>
    </tr>
    
	<tr>
      <td align="right" class="forumRow">电子信箱：</td>
      <td class="forumRowHighlight"><input name="Cp_email" type="text" id="Cp_email" style="width: 280" value="<%=mCp_email%>" maxlength="50"></td>
    </tr>
	<tr>
      <td align="right" class="forumRow">Q Q：</td>
      <td class="forumRowHighlight"><input name="Cp_QQ" type="text" id="Cp_QQ" style="width: 120" value="<%=mCp_QQ%>" maxlength="50"></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">MSN：</td>
      <td class="forumRowHighlight"><input name="Cp_msn" type="text" id="Cp_msn" style="width: 120" value="<%=mCp_msn%>" maxlength="50"></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">个人主页(微博)：</td>
      <td class="forumRowHighlight"><input name="Cp_homepage" type="text" id="Cp_homepage" style="width: 280" value="<%=mCp_homepage%>" maxlength="50"></td>
    </tr>
	<tr>
      <td align="right" class="forumRow">地 址：</td>
      <td class="forumRowHighlight"><input name="Cp_address" type="text" id="Cp_address" style="width: 280" value="<%=mCp_address%>" maxlength="100"></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">邮政编码：</td>
      <td class="forumRowHighlight"><input name="Cp_zipcode" type="text" id="Cp_zipcode" style="width: 120" value="<%=mCp_zipcode%>" maxlength="16"></td>
    </tr>
    
    
  </tbody>
  <tbody id="Tabs" style="display:none">
    <tr>
      <td width="20%" align="right" class="forumRow">&nbsp;</td>
      <td width="80%" class="forumRowHighlight">&nbsp;</td>
    </tr>
    <tr>
      <td width="20%" align="right" class="forumRow">&nbsp;</td>
      <td width="80%" class="forumRowHighlight">&nbsp;</td>
    </tr>
  </tbody>
  
  
  <tbody id="Tabs" style="display:none">
    <tr>
      <td width="20%" align="right" class="forumRow">&nbsp;</td>
      <td width="80%" class="forumRowHighlight">&nbsp;</td>
    </tr>
  </tbody>

  </table>
</td>
</tr>
</table>
	  </td>
    </tr>
    	
    <tr>
      <td class="forumRowHighlight" align="center"><input name="submitSaveEdit" type="submit" id="submitSaveEdit" value="保存"> <input type="button" value="返回上一页" onclick="history.back(-1)"></td>
    </tr>
  </form>
</table>

<%
Sub MyKehuEdit()
    Dim Action, rs, sql,rs2,sql2
    Action = request.QueryString("Action")
    If Action = "SaveEdit" Then
        Set rs = server.CreateObject("adodb.recordset")
		Set rs2 = server.CreateObject("adodb.recordset")
        If Result = "Add" Then
		    If Trim(Request.Form("Cp_code"))<>"" Then
			   If Not conn.Execute("select * from Zqj_Contactperson where Cp_code='" & Trim(Request.Form("Cp_code")) & "'").EOF Then
			    response.Write "<script language='javascript'>alert('添加失败！');history.back(-1);</script>"
				response.End
			   end if
			else
			    response.Write "<script language='javascript'>alert('联系人编号生成错误！');history.back(-1);</script>"
				response.End
			end if
            If Not conn.Execute("select * from Zqj_Contactperson where Cp_name='" & Trim(Request.Form("Cp_name")) & "' and Memname='"&session("UserName")&"'").EOF Then
                response.Write "<script language='javascript'>alert('联系人[" & Trim(Request.Form("Cp_name")) & "]已经存在！');history.back(-1);</script>"
                response.End
            End If
		'判断公司是否存在，不存在时创建公司开始====================
			if Trim(Request.Form("Co_name"))<>"" then
			'#创建或读取公司ID
			sql2 = "select * from Zqj_Company where Co_name='"&Trim(Request.Form("Co_name"))&"' and MemName='"&session("UserName")&"'"
            rs2.Open sql2, conn, 1, 3
			if rs2.bof and rs2.eof then
			   rs2.addnew
			   Co_Serialnumber=getCo_code()'公司编号
			   rs2("Co_Serialnumber")=Co_Serialnumber
			   rs2("Co_name") = StrReplace(Trim(Request.Form("Co_name")))
			   rs2("MemName") = Trim(Request.Form("MemName"))
               rs2("RealName") = Trim(Request.Form("RealName"))
			   rs2("Co_AddTime")=now()
			   Co_ID=rs2.Fields("Co_ID") '获取公司ID
			else
			   Co_ID=rs2("Co_ID")
			   Co_Serialnumber=rs2("Co_Serialnumber")
			end if
			rs2.update
            rs2.Close
            Set rs2 = Nothing
			'#创建或读取公司ID结束
			else
			    Co_ID=0
			end if
		'判断公司是否存在，不存在时创建公司结束====================
            sql = "select * from Zqj_Contactperson"
            rs.Open sql, conn, 1, 3
            rs.addnew
			rs("Cp_code")=Trim(Request.Form("Cp_code"))
            rs("Cp_name") = Trim(Request.Form("Cp_name"))
			rs("Cp_education") = Trim(Request.Form("Cp_education"))
            rs("Cp_position") = Trim(Request.Form("Cp_position"))
			rs("Cp_tel")=StrReplace(Trim(Request.Form("Cp_tel")))
			rs("Cp_mobile")=StrReplace(Trim(Request.Form("Cp_mobile")))
			rs("Cp_email")=Trim(Request.Form("Cp_email"))
			rs("Cp_QQ")=StrReplace(Trim(Request.Form("Cp_QQ")))
			rs("Cp_msn")=StrReplace(Trim(Request.Form("Cp_msn")))
			rs("Cp_homePage") = StrReplace(Trim(Request.Form("Cp_homePage")))
            rs("Cp_address") = StrReplace(Trim(Request.Form("Cp_address")))
            rs("Cp_zipcode")=StrReplace(Trim(Request.Form("Cp_zipcode")))
			rs("Cp_addtime")=now()
			rs("Cp_updatime")=now()
            rs("Co_ID")=Co_ID
			rs("Co_Serialnumber")=Co_Serialnumber
			rs("MemName") = Trim(Request.Form("MemName"))
            rs("RealName") = Trim(Request.Form("RealName"))
			ID=rs.Fields("Cp_ID")
            rs.update
            rs.Close
            Set rs = Nothing
		'====创建联系人履历
		if Trim(Request.Form("Co_name"))<>"" then
		   Set rs = server.CreateObject("adodb.recordset")
		   sql = "select * from Zqj_Career"
           rs.Open sql, conn, 1, 3
           rs.addnew
		   rs("Cp_ID")=ID
		   rs("Ca_company")=StrReplace(Trim(Request.Form("Co_name")))
		   rs("Ca_position")=Trim(Request.Form("Cp_position"))
		   rs("Ca_time")=now()
		   rs.update
		   rs.close
		   set rs=nothing
		end if
            response.Write "<script language='javascript'>alert('设置成功！');location.replace('My_people_KehuList.Asp');</script>"  
	
        End If
        If Result = "Modify" Then
		'判断公司是否存在，不存在时创建公司开始-----------------------
			if Trim(Request.Form("Co_name"))<>"" then
			'#创建或读取公司ID
			sql2 = "select * from Zqj_Company where Co_name='"&Trim(Request.Form("Co_name"))&"' and MemName='"&session("UserName")&"'"
            rs2.Open sql2, conn, 1, 3
			if rs2.bof and rs2.eof then
			   rs2.addnew
			   Co_Serialnumber=getCo_code()
			   rs2("Co_Serialnumber")=Co_Serialnumber
			   rs2("Co_name") = StrReplace(Trim(Request.Form("Co_name")))
			   rs2("MemName") = Trim(Request.Form("MemName"))
               rs2("RealName") = Trim(Request.Form("RealName"))
			   Co_ID=rs2.Fields("Co_ID")
			else
			   Co_ID=rs2("Co_ID")
			   Co_Serialnumber=rs2("Co_Serialnumber")
			end if
			rs2.update
            rs2.Close
            Set rs2 = Nothing
			'#创建或读取公司ID结束
			else
			      Co_ID=0
			end if
		'判断公司是否存在，不存在时创建公司结束---------------------
            sql = "select * from Zqj_Contactperson where Cp_ID="&ID
            rs.Open sql, conn, 1, 3
            rs("Cp_name") = Trim(Request.Form("Cp_name"))
			rs("Cp_education") = Trim(Request.Form("Cp_education"))
            rs("Cp_position") = Trim(Request.Form("Cp_position"))
			rs("Cp_tel")=StrReplace(Trim(Request.Form("Cp_tel")))
			rs("Cp_mobile")=StrReplace(Trim(Request.Form("Cp_mobile")))
			rs("Cp_email")=Trim(Request.Form("Cp_email"))
			rs("Cp_QQ")=StrReplace(Trim(Request.Form("Cp_QQ")))
			rs("Cp_msn")=StrReplace(Trim(Request.Form("Cp_msn")))
			rs("Cp_homePage") = StrReplace(Trim(Request.Form("Cp_homePage")))
            rs("Cp_address") = StrReplace(Trim(Request.Form("Cp_address")))
            rs("Cp_zipcode")=StrReplace(Trim(Request.Form("Cp_zipcode")))
			rs("Cp_updatime")=now()
            rs("Co_ID")=Co_ID
			rs("Co_Serialnumber")=Co_Serialnumber
			rs("MemName") = Trim(Request.Form("MemName"))
            rs("RealName") = Trim(Request.Form("RealName"))
            rs.update
           rs.Close
           Set rs = Nothing
		   '====创建联系人履历
		if Trim(Request.Form("Co_name"))<>"" then
		   Set rs = server.CreateObject("adodb.recordset")
		   sql = "select * from Zqj_Career where Ca_company='"&Trim(Request.Form("Co_name"))&"' and Cp_ID="&ID
           rs.Open sql, conn, 1, 3
		   if rs.bof and rs.eof then
              rs.addnew
		      rs("Cp_ID")=ID
		      rs("Ca_company")=StrReplace(Trim(Request.Form("Co_name")))
		      rs("Ca_position")=Trim(Request.Form("Cp_position"))
		      rs("Ca_time")=now()
		   else
		      rs("Ca_position")=Trim(Request.Form("Cp_position"))
		      rs("Ca_time")=now()
		   end if
		   rs.update
		   rs.close
		   set rs=nothing
		end if
		   response.Redirect("My_people_KehuView.Asp?Result=Modify&ID="&ID&"&showid="&showid)
           			
        End If

    Else
        If Result = "Modify" Then
            Set rs = server.CreateObject("adodb.recordset")
            sql = "select * from Zqj_Contactperson where MemName='"&session("UserName")&"' and Cp_ID="&ID
            rs.Open sql, conn, 1, 1
			if rs.bof and rs.eof then
			response.Write "<script language='javascript'>alert('参数错误！');history.back(-1);</script>"
			response.End
			else
			mCp_name=rs("Cp_name")
			mCp_code=rs("Cp_code")
			mCp_education=rs("Cp_education")
			mCo_ID=rs("Co_ID")
			call getCo_name(mCo_ID)
			mCp_position=rs("Cp_position")
			mCp_tel=rs("Cp_tel")
			mCp_mobile=rs("Cp_mobile")
			mCp_email=rs("Cp_email")
			mCp_QQ=rs("Cp_QQ")
			mCp_msn=rs("Cp_msn")
			mCp_homePage=rs("Cp_homePage")
			mCp_address=rs("Cp_address")
			mCp_ZipCode=rs("Cp_ZipCode")
			mCp_addTime=rs("Cp_addTime")
			mCp_updatime=rs("Cp_updatime")
			mCp_working=rs("Cp_working")
			mMemName=rs("MemName")
			mRealName=rs("RealName")
			end if
            rs.Close
            Set rs = Nothing
        End If
    End If
End Sub

Sub SelectGroup()
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "select GroupID,GroupName from Zqj_MemGroup order by ID DESC"
    rs.Open sql, conn, 1, 1
    If rs.bof And rs.EOF Then
        response.Write("未设组别")
    End If
    While Not rs.EOF
        response.Write("<option value='"&rs("GroupID")&"┎╂┚"&rs("GroupName")&"'")
        If mGroupID = rs("GroupID") Then response.Write ("selected")
        response.Write(">"&rs("GroupName")&"</option>")
        rs.movenext
    Wend
    rs.Close
    Set rs = Nothing
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(ID)
    if ID="" then
	ID=0
	end if
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "Select * From Zqj_Company where Co_ID="&ID
    rs.Open sql, conn, 1, 1
	if rs.bof and rs.eof then
	kCompany=""
	else
    kCompany = rs("Co_name")
	end if
    rs.Close
    Set rs = Nothing
End Function

Function getCo_code()
    Y=year(now())
    M=month(now())
    D=Day(now())
    H=hour(now())
    mi=minute(now())
    s=second(now())
    if M<10 then M="0"&M
    if D<10 then D="0"&D
    if H<10 then H="0"&H
    if mi<10 then mi="0"&mi
    if s<10 then s="0"&s
 '生成1-100随机数 
    Randomize() 
    n=Int((100-1+1)*Rnd(now())+1)
    getCo_code=Y&M&D&H&mi&s&n
    
End Function
%>