<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" -->
<!--#include file="../Inc/SK.Md5.asp"-->
<%if Not (Getconfig("SK_Client")="0" AND (Session("Manager")="1" OR (JudgePopedomTF(Session("UserName"),"SK200000000") AND JudgePopedomTF(Session("UserName"),"SK200000100") AND JudgePopedomTF(Session("UserName"),"SK200000101")))) then Call ReturnError()%>
<%
Dim Aid:Aid=conn.execute("select count(*) from SK_Client")(0)
Dim CNN:CNN=Aid+1
'AddNew
if RQ("Action")="Add" and F("S_Area")<>"" and F("S_Num")<>"" and F("S_Wname")<>"" then
Call ChkIsOuter()
set rs=server.createobject("adodb.recordset")
sql="select * from SK_Client where SK_Wname='"&F("S_Wname")&"'"
rs.open sql,conn,1,3
if not rs.eof or not rs.bof then
Response.Write("<script LANGUAGE='javascript'>alert('对不起,存在相同的编号或名称！');history.go(-1);</script>")
Response.End
end if
rs.AddNew
rs("SK_Di")=NoCSSHackInput(F("S_Di"))
rs("SK_No")=NoCSSHackInput(F("S_Num"))
rs("SK_Wname")=NoCSSHackInput(F("S_Wname"))
rs("SK_Jname")=NoCSSHackInput(F("S_Jname"))
rs("SK_Pass")=md5(NoCSSHackInput(F("S_Pass")),16)
rs("SK_AreaID")=NoCSSHackInput(F("S_AreaID"))
rs("SK_Content")=NoCSSHackContent(F("S_Content"))
rs("SK_Status")=NoCSSHackContent(F("S_Status"))
rs("SK_Prospect")=NoCSSHackContent(F("S_Prospect"))
rs("SK_Plot")=NoCSSHackContent(F("S_Plot"))
rs("SK_Locked")="0"
rs("SK_Share")="0"

'自定义字段部分开始
set RsField=Server.createobject("adodb.recordset")
sqlField="SELECT * from SK_ClientFields where SK_Di=0 and SK_ShowOnForm=0"
RsField.Open sqlField,conn,1,1
A=0
while not RsField.eof
A=A+1
rs(""&RsField("SK_FieldName")&"")=NoCSSHackInput(F(""&RsField("SK_FieldName")&""))
RsField.movenext
wend
RsField.close
Set RsField=Nothing

set RsOption=Server.createobject("adodb.recordset")
sqlOption="SELECT * from SK_ClientOptions where SK_Di=0 and SK_ShowOnForm=0"
RsOption.Open sqlOption,conn,1,1
B=0
while not RsOption.eof
B=B+1
rs(""&RsOption("SK_FieldName")&"")=NoCSSHackInput(F(""&RsOption("SK_FieldName")&""))
RsOption.movenext
wend
RsOption.close
Set RsOption=Nothing
'自定义字段部分结束

if NoCSSHackInput(F("S_UserID"))<>"" then
rs("SK_SalesID")=NoCSSHackInput(F("S_UserID"))
rs("SK_Ftime")=Now()
rs("SK_UserID")=Session("UID")
end if
rs("SK_Addor")=Session("Oname")
rs("SK_ATime")=Now()
rs("SK_Del")="0"
rs("SK_Click")="0"
rs.Update

set rs=conn.execute("select @@IDENTITY")
GetNewID=rs(0)

rs.Close 
set rs=Nothing

if F("S_Name")<>"" and F("S_Sex")<>"" and (Session("Manager")="1" OR JudgePopedomTF(Session("UserName"),"SK200000201")) then
set rs1=server.createobject("adodb.recordset")
sql1="select * from SK_LinkMan"
rs1.open sql1,conn,1,3
rs1.AddNew
rs1("SK_ClientID")=GetNewID
rs1("SK_LName")=NoCSSHackInput(F("S_Name"))
rs1("Sex")=NoCSSHackInput(F("S_Sex"))
rs1("SK_Mobile")=NoCSSHackInput(F("S_Mobile"))
rs1("SK_Tel")=NoCSSHackInput(F("S_OfficeTel"))
rs1("SK_SalesID")=Session("UID")
rs1("SK_Addor")=Session("UserName")
rs1("SK_ATime")=Now()
rs1("SK_Del")="0"
rs1.Update
rs1.Close 
set rs1=Nothing
end if

'Event Begin
if getconfig("SK_Event")=0 then
set rsEvent=server.createobject("adodb.recordset")
sqlEvent="select * from SK_SystemEvent"
rsEvent.open sqlEvent,conn,1,3
rsEvent.AddNew
rsEvent("SK_Title")="新建客户："&NoCSSHackInput(F("S_Wname"))&" 的信息"
rsEvent("SK_User")=Session("UserName")
rsEvent("SK_Time")=Now()
rsEvent("SK_IP")=request.ServerVariables("Remote_Addr")
rsEvent.Update
rsEvent.Close 
set rsEvent=Nothing
end if
'Event End
Response.Write("<script>if (confirm(""恭喜您新建客户成功,是否继续新建?"")==false) window.close(); else history.go(-1);;window.opener.location.reload();</script>")
Response.End
end if
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>新建客户信息</title>
<META http-equiv=Page-Enter content=SKCRM>
<META http-equiv=Page-Exit content=SKCRM>
<META content="MSHTML 6.00.3790.2858" name=GENERATOR>
<LINK href="../images/style.css" type=text/css rel=stylesheet>
<script language="javascript" src="../Inc/Check.js"></script>
<script language="javascript" src="../Inc/Calendar.js"></script>
<script language="javascript" src="../Inc/jquery.js"></script>
<script language="javascript" src="../Inc/CheckClient.js"></script>
<SCRIPT language=javascript src="../inc/Openwin.js"></SCRIPT>
<script>
window.onbeforeunload = function()
{
if (document.body.offsetWidth-50 < event.clientX && event.clientY<0)
{
return "是否关闭当前窗口？关闭本窗口将放弃新建信息！";
}
}
</script>
<style type="text/css">
<!--
body {
margin: 5px 0px 5px 0px;
overflow-x: hidden;
}
-->
</style>
<SCRIPT language=JavaScript>
function Form1_Validator(theForm)
{
if(form1.S_Di.value ==""){
alert("对不起,请选择客户类型!");
form1.S_Di.focus();
return false;
}

if(form1.S_Area.value ==""){
alert("对不起,请选择所在区域!");
form1.S_Area.focus();
return false;
}

if(form1.S_Num.value ==""){
alert("对不起,客户编号不能为空!");
form1.S_Num.focus();
return false;
}

if(form1.S_Wname.value ==""){
alert("对不起,客户名称不能为空!");
form1.S_Wname.focus();
return false;
}

return true;
}
</SCRIPT>
</head>
<body>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
<TBODY>
<tr>
<td class="SK_Td_Top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="12" height="25"><img src="../images/tab_03.gif" width="12" height="25" /></td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="46%" valign="middle">新建客户信息</td>
<td width="54%"></td>
</tr>
</table></td>
<td width="16"><img src="../images/tab_07.gif" width="16" height="25" /></td>
</tr>
</table></td>
</tr>
<tr>
<td>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="8" background="../images/tab_12.gif"></td>
<td>

<form name="thisForm" id="form1" method="post" action="?Action=Add" onSubmit="return Form1_Validator(this)"> 
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6">
<tr>
  <td colspan="4" class="SK_Title1">基本资料</td>
</tr>

<tr>
  <td class="SK_Text2">客户类型</td>
  <td colspan="3" class="SK_Text1"><select name="S_Di">
<option value="" selected>---请选择---</option>
<option value="0">单位客户</option>
<option value="1">个人客户</option>
</select> <font color=red>*</font></td>
</tr>
<tr>
  <td class="SK_Text2">所在区域</td>
  <td colspan="3" class="SK_Text1"><input name="S_Area" type="text" size="20" readonly> 
  <input name="S_AreaID" type="hidden"> <a onClick="JavaScript:window.open('../Inc/SK.SArea.asp','SSales','directorys=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=820,height=400,top=176,left=161');" style="cursor:hand">选择</a> <font color=red>*</font></td>
</tr>

<tr>
<td width="16%" class="SK_Text2">客户编号</td>
<td colspan="3" class="SK_Text1"><input name="S_Num" type="text" size="20" maxlength="20" onblur= "this.value=this.value.toLocaleUpperCase()" onKeyUp="value=value.replace(/[^\w\.\/]/ig,'')" value="<%if F("Di")="0" OR F("Di")="" then%>DW<%else%>GR<%end if%><%=right(("000000"&CNN),12)%>" /> 
<font color=red>*</font></tr>
<tr>
  <td class="SK_Text2">客户名称</td>
  <td colspan="3" class="SK_Text1"><input type="text" size="30" name="S_Wname" autocomplete="off" id="txtSearch" onKeyUp="searchSuggest();"> <font color=red>*存在相同客户时将下拉显示</font> <br><div id="search_suggest" style="display:none"></div></td>
</tr>
<tr>
  <td class="SK_Text2">其他名称</td>
  <td colspan="3" class="SK_Text1"><input type="text" size="30" name="S_Jname"> </td>
</tr>

<%if Session("Manager")="1" OR JudgePopedomTF(Session("UserName"),"SK200000201") then%>
<tr>
  <td colspan="4" class="SK_Title1">联系人员</td>
</tr>
<tr>
  <td class="SK_Text2">姓名</td>
  <td class="SK_Text1"><input name="S_Name" type="text" size="20"></td>
  <td class="SK_Text2">性别</td>
  <td class="SK_Text1"><select name="S_Sex"><option value="" selected>请选择</option><option value="1">男</option><option value="0">女</option></select></td>
</tr>
<tr>
  <td class="SK_Text2">手机</td>
  <td class="SK_Text1"><input name="S_Mobile" type="text" size="20" onKeyUp="value=value.replace(/[^\d]/g,'')" /></td>
  <td class="SK_Text2">座机</td>
  <td class="SK_Text1"><input name="S_OfficeTel" type="text" size="20" onKeyUp="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" /></td>
</tr>
<%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
if RsOptions.bof and RsOptions.eof then
else
%>
<tr>
  <td colspan="4" class="SK_Title1">自定义选项</td>
</tr>
<tr>
  <td colspan="4" class="SK_Text1">
<%
Response.write"<table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""1"">"
for Optionsi=1 to RsOptions.recordCount '变量i从1循环到数据库中的全部记录数 
if (Optionsi mod 2 =1) then '每个tr即每行显示1个记录,可根据需要自行修改, 将左边的1修改为2即显示两行。
response.write "<tr>" 
end if
Response.write"<td class=""SK_Text2"" width=""16%"">"&RsOptions("SK_Title")&"</td><td class=""SK_Text1""><select name="&RsOptions("SK_FieldName")&">"

Set rsOptionsDetail=Server.CreateObject("ADODB.RecordSet") 
sqlOptionsDetail="SELECT * from SK_ClientOptionsDetail where SK_OptionsID="&RsOptions("FieldID")&"" 
rsOptionsDetail.Open sqlOptionsDetail,conn,1,1
Response.write"<option value="""" selected>--请选择--</option>"
do while not rsOptionsDetail.eof
Response.write"<option value="&rsOptionsDetail("OptionsDetailID")&">"&rsOptionsDetail("SK_OName")&"</option>"
rsOptionsDetail.movenext
loop
rsOptionsDetail.close
set rsOptionsDetail=Nothing

Response.write"</select></td>"
if (Optionsi mod 2 = 0) then '每个tr即每行显示1个记录,可根据需要自行修改, 将左边的1修改为2即显示两行。
response.write "</tr>" 
end if 
RsOptions.movenext
next 
Response.write"</table>"
%>
</td>
</tr>
<%
end if
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
if RsFields.bof and RsFields.eof then
else
%>
<tr>
  <td colspan="4" class="SK_Title1">自定义字段</td>
</tr>
<tr>
  <td colspan="4" class="SK_Text1">
<%
Response.write"<table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""1"">"
for Fieldsi=1 to RsFields.recordCount '变量i从1循环到数据库中的全部记录数 
if (Fieldsi mod 2 =1) then '每个tr即每行显示1个记录,可根据需要自行修改, 将左边的1修改为2即显示两行。
response.write "<tr>" 
end if
Response.write"<td class=""SK_Text2"" width=""16%"">"&RsFields("SK_Title")&"</td><td class=""SK_Text1""><input type=""text"" size=""20"" name="&RsFields("SK_FieldName")&" title="&RsFields("SK_Tips")&"></td>"
if (Fieldsi mod 2 = 0) then '每个tr即每行显示1个记录,可根据需要自行修改, 将左边的1修改为2即显示两行。
response.write "</tr>" 
end if 
RsFields.movenext 
next 
Response.write"</table>"
%>
</td>
</tr>
<%
end if
RsFields.close
set RsFields=Nothing
'自定义字段结束
%>
<tr>
  <td colspan="4" class="SK_Title1">备注与策略</td>
</tr>

<tr>
  <td valign="top" class="SK_Text2">客户备注</td>
  <td colspan="3" class="SK_Text1"><IFRAME ID="eWebEditor1" SRC="<%=getconfig("SK_EditorPath")%>/ewebeditor.htm?id=S_Content&style=mini" FRAMEBORDER="0" SCROLLING="no" WIDTH="500" HEIGHT="200"></IFRAME>
<input type="hidden" name="S_Content"></td>
</tr>

<tr>
  <td valign="top" class="SK_Text2">合作现状</td>
  <td colspan="3" class="SK_Text1"><IFRAME ID="eWebEditor1" SRC="<%=getconfig("SK_EditorPath")%>/ewebeditor.htm?id=S_Status&style=mini" FRAMEBORDER="0" SCROLLING="no" WIDTH="500" HEIGHT="200"></IFRAME>
  <input type="hidden" name="S_Status"></td>
</tr>
<tr>
  <td valign="top" class="SK_Text2">合作前景</td>
  <td colspan="3" class="SK_Text1"><IFRAME ID="eWebEditor1" SRC="<%=getconfig("SK_EditorPath")%>/ewebeditor.htm?id=S_Prospect&style=mini" FRAMEBORDER="0" SCROLLING="no" WIDTH="500" HEIGHT="200"></IFRAME>
  <input type="hidden" name="S_Prospect">  </td>
</tr>
<tr>
  <td valign="top" class="SK_Text2">跟进策略</td>
  <td colspan="3" class="SK_Text1"><IFRAME ID="eWebEditor1" SRC="<%=getconfig("SK_EditorPath")%>/ewebeditor.htm?id=S_Plot&style=mini" FRAMEBORDER="0" SCROLLING="no" WIDTH="500" HEIGHT="200"></IFRAME>
  <input type="hidden" name="S_Plot"></td>
</tr>
<tr>
  <td colspan="4" class="SK_Title1">客户领用</td>
</tr>
<tr>
  <td class="SK_Text2">业务人员</td>
  <td colspan="3" class="SK_Text1"><input name="S_User" type="text" size="20" value="<%=Session("OName")%>" readonly> <a onClick="JavaScript:window.open('../System/SK.SSales.asp','SSales','directorys=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=820,height=400,top=176,left=161');" style="cursor:hand"><img src="../images/SUser.gif" /></a>
<input name="S_UserID" type="hidden" value="<%=Session("UID")%>"></td>
</tr>

<tr>
<td colspan="4" class="SK_Text">
<INPUT class="button1" type="submit" value=" 保存 "> 
<input type="button" value=" 关闭 " onClick="window.opener.location.reload();window.close();" class="button1" /></td>
</tr>
</table>
</form>

</td>
<td width="8" background="../images/tab_15.gif"></td>
</tr>
</table></td>
</tr>
<tr>
<td class="SK_Td_Foot">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1%" height="20"><img src="../images/tab_18.gif" width="12" height="20" /></td>
<td width="98%" class="SK_Td_Page"></td>
<td width="1%"><img src="../images/tab_20.gif" width="16" height="20" /></td>
</tr>
</table>

</td>
</tr>
</TBODY>
</table>
</body>
<%
Call CloseDB()
%>
</html>